aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/ssh/auth_method.go
diff options
context:
space:
mode:
authorEthan Young <ethankyoung@gmail.com>2017-05-28 09:46:54 -0600
committerSantiago M. Mola <santi@mola.io>2017-06-01 16:57:31 +0200
commitf9dc7b130fcd8fa1ff0f086de89744c8c194c1e5 (patch)
tree3e2f94bf00d04ec2d2610028ff531313b971b906 /plumbing/transport/ssh/auth_method.go
parent7e249dfcf28765939bde8f38784b3274b522f880 (diff)
downloadgo-git-f9dc7b130fcd8fa1ff0f086de89744c8c194c1e5.tar.gz
Use xanzy/ssh-agent to create the ssh agent correctly based on os.
Diffstat (limited to 'plumbing/transport/ssh/auth_method.go')
-rw-r--r--plumbing/transport/ssh/auth_method.go17
1 files changed, 4 insertions, 13 deletions
diff --git a/plumbing/transport/ssh/auth_method.go b/plumbing/transport/ssh/auth_method.go
index 84dfe14..f95235b 100644
--- a/plumbing/transport/ssh/auth_method.go
+++ b/plumbing/transport/ssh/auth_method.go
@@ -3,25 +3,21 @@ package ssh
import (
"crypto/x509"
"encoding/pem"
- "errors"
"fmt"
"io/ioutil"
- "net"
"os"
"os/user"
"path/filepath"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
+ "github.com/xanzy/ssh-agent"
"golang.org/x/crypto/ssh"
- "golang.org/x/crypto/ssh/agent"
"golang.org/x/crypto/ssh/knownhosts"
)
const DefaultUsername = "git"
-var ErrEmptySSHAgentAddr = errors.New("SSH_AUTH_SOCK env variable is required")
-
// AuthMethod is the interface all auth methods for the ssh client
// must implement. The clientConfig method returns the ssh client
// configuration needed to establish an ssh connection.
@@ -189,19 +185,14 @@ func NewSSHAgentAuth(u string) (AuthMethod, error) {
u = usr.Username
}
- sshAgentAddr := os.Getenv("SSH_AUTH_SOCK")
- if sshAgentAddr == "" {
- return nil, ErrEmptySSHAgentAddr
- }
-
- pipe, err := net.Dial("unix", sshAgentAddr)
+ a, _, err := sshagent.New()
if err != nil {
- return nil, fmt.Errorf("error connecting to SSH agent: %q", err)
+ return nil, fmt.Errorf("error creating SSH agent: %q", err)
}
return &PublicKeysCallback{
User: u,
- Callback: agent.NewClient(pipe).Signers,
+ Callback: a.Signers,
}, nil
}