diff options
Diffstat (limited to 'clients/ssh/auth_method.go')
-rw-r--r-- | clients/ssh/auth_method.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/clients/ssh/auth_method.go b/clients/ssh/auth_method.go index 4fe68ca..e55283e 100644 --- a/clients/ssh/auth_method.go +++ b/clients/ssh/auth_method.go @@ -2,8 +2,11 @@ package ssh import ( "fmt" + "net" + "os" "golang.org/x/crypto/ssh" + "golang.org/x/crypto/ssh/agent" "gopkg.in/src-d/go-git.v4/clients/common" ) @@ -134,3 +137,17 @@ func (a *PublicKeysCallback) clientConfig() *ssh.ClientConfig { Auth: []ssh.AuthMethod{ssh.PublicKeysCallback(a.Callback)}, } } + +// Opens a pipe with the ssh agent and uses the pipe +// as the implementer of the public key callback function. +func NewSSHAgentAuth() (*PublicKeysCallback, error) { + pipe, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK")) + if err != nil { + return nil, err + } + + return &PublicKeysCallback{ + User: "git", + Callback: agent.NewClient(pipe).Signers, + }, nil +} |