pageant

package module
v0.0.0-...-179b607 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

README

Go Pageant client

This repository contains a library for Go that provides a native PuTTY Pageant SSH agent implementation compatible with the golang.org/x/crypto/ssh/agent package.

This package, rather unsuprisingly, only works with Windows. See below for alternatives on Unix/Linux platforms.

Usage

import (
	"golang.org/x/crypto/ssh"
	"golang.org/x/crypto/ssh/agent"
	"github.com/kbolino/pageant"
)

func main() {
	agentConn, err := pageant.NewConn()
	if err != nil {
		// failed to connect to Pageant
	}
	defer agentConn.Close()
	sshAgent := agent.NewClient(agentConn)
	signers, err := sshAgent.Signers()
	if err != nil {
		// failed to get signers from Pageant
	}
	config := ssh.ClientConfig{
		Auth:            []ssh.AuthMethod{ssh.PublicKeys(signers...)},
		HostKeyCallback: ssh.InsecureIgnoreHostKey(),
		User:            "somebody",
	}
	sshConn, err := ssh.Dial("tcp", "someserver:22", &config)
	if err != nil {
		// failed to connect to SSH
	}
	defer sshConn.Close()
	// now connected to SSH with public key auth from Pageant
	// ...
}

Unix/Linux Alternatives

The ssh-agent command implements the same SSH agent protocol as Pageant, but over a Unix domain socket instead of shared memory. The path to this socket is exposed through the environment variable SSH_AUTH_SOCK.

Replace the connection to Pageant with one to the socket:

	// instead of this:
	agentConn, err := pageant.NewConn()
	// do this:
	agentConn, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))

Testing

The standard tests require Pageant to be running and to have at least 1 key loaded. To test connecting to an SSH server, set the sshtest build flag and see the comments in pageant_ssh_test.go for how to set up the test.

Documentation

Overview

Package pageant provides native Go support for using PuTTY Pageant as an SSH agent with the golang.org/x/crypto/ssh/agent package. Based loosely on the Java JNA package jsch-agent-proxy-pageant.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a shared-memory connection to Pageant. Conn implements io.Reader, io.Writer, and io.Closer. It is not safe to use Conn in multiple concurrent goroutines.

func NewConn

func NewConn() (*Conn, error)

NewConn creates a new connection to Pageant. Ensure Close gets called on the returned Conn when it is no longer needed.

func (*Conn) Close

func (c *Conn) Close() error

Close frees resources used by Conn.

func (*Conn) Read

func (c *Conn) Read(p []byte) (n int, err error)

func (*Conn) Write

func (c *Conn) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL