Skip to content

Commit

Permalink
support using putty pageant as ssh agent
Browse files Browse the repository at this point in the history
Based on #111 by abakum <koka.abakum@gmail.com>
  • Loading branch information
lonnywong committed May 26, 2024
1 parent 8f27cf3 commit b518f22
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/trzsz/go-arg v1.5.3
github.com/trzsz/iterm2 v0.1.2
github.com/trzsz/pageant v0.1.0
github.com/trzsz/promptui v0.10.7
github.com/trzsz/ssh_config v1.3.6
github.com/trzsz/trzsz-go v1.1.8-0.20240525015006-6424386a6738
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ github.com/trzsz/go-arg v1.5.3 h1:eIDwDEmvSahtr5HpQOLrSa+YMqWQQ0H20xx60XgXQJw=
github.com/trzsz/go-arg v1.5.3/go.mod h1:IC6Z/FiVH7uYvcbp1/gJhDYCFPS/GkL0APYakVvgY4I=
github.com/trzsz/iterm2 v0.1.2 h1:VwfLzr2fKeaLf+p4tS0ms+kqdiQQxVLbTJUoyuQXmK8=
github.com/trzsz/iterm2 v0.1.2/go.mod h1:PMI+3JcT7J9D0T6e3mOWv8ICYdrrNZwuge3Tm7zDLws=
github.com/trzsz/pageant v0.1.0 h1:Ux5VSA6IMwahrMQ+8BeCnDKh3lO/OPkCQgBEpsQ379s=
github.com/trzsz/pageant v0.1.0/go.mod h1:OMX42Kisk5o8eVDR/UCHmNPaeRf8MnJ33muUTqSwDO4=
github.com/trzsz/promptui v0.10.7 h1:77uBrmsIPYYJS/9n+zwFRhwOz82EKXkkdjOiWSEUPpk=
github.com/trzsz/promptui v0.10.7/go.mod h1:9dp59ixe32qBV9GjDxQ1PDWwbzHjTzveZenQwEoVHbg=
github.com/trzsz/ssh_config v1.3.6 h1:+LBCg2uzhAgw2s19yqeUdD4YwW2z4kvlsXtKB6zDjmQ=
Expand Down
5 changes: 1 addition & 4 deletions tssh/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ func getAgentAddr(args *sshArgs, param *sshParam) (string, error) {
if addr := os.Getenv("SSH_AUTH_SOCK"); addr != "" {
return resolveHomeDir(addr), nil
}
if addr := defaultAgentAddr; addr != "" && isFileExist(addr) {
return addr, nil
}
return "", nil
return getDefaultAgentAddr()
}

func getAgentClient(args *sshArgs, param *sshParam) agent.ExtendedAgent {
Expand Down
4 changes: 3 additions & 1 deletion tssh/agent_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
"time"
)

const defaultAgentAddr = ""
func getDefaultAgentAddr() (string, error) {
return "", nil
}

func dialAgent(addr string) (net.Conn, error) {
return net.DialTimeout("unix", addr, time.Second)
Expand Down
18 changes: 17 additions & 1 deletion tssh/agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,27 @@ import (
"time"

"github.com/Microsoft/go-winio"
"github.com/trzsz/pageant"
)

const defaultAgentAddr = `\\.\pipe\openssh-ssh-agent`
const kSshAgentAddr = `\\.\pipe\openssh-ssh-agent`

const kPageantFakeAddr = "using_pageant_as_ssh_agent"

func getDefaultAgentAddr() (string, error) {
if isFileExist(kSshAgentAddr) {
return kSshAgentAddr, nil
}
if pageant.PageantAvailable() {
return kPageantFakeAddr, nil
}
return "", nil
}

func dialAgent(addr string) (net.Conn, error) {
if addr == kPageantFakeAddr {
return pageant.NewPageantConn()
}
timeout := time.Second
return winio.DialPipe(addr, &timeout)
}

0 comments on commit b518f22

Please sign in to comment.