-
Notifications
You must be signed in to change notification settings - Fork 3
/
agent_windows.go
80 lines (63 loc) · 1.72 KB
/
agent_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"context"
"fmt"
"io"
"os"
"path/filepath"
"sync"
"github.com/buptczq/WinCryptSSHAgent/app"
"golang.org/x/crypto/ssh/agent"
)
var applications = []app.Application{
new(app.WSL),
new(app.Cygwin),
new(app.NamedPipe),
new(app.Pageant),
new(app.VSock),
}
func (s *SSHAgent) SSHAgentHandler(conn io.ReadWriteCloser) {
defer conn.Close()
if s.ExtendedAgent == nil {
return
}
agent.ServeAgent(s, conn)
}
func (s *SSHAgent) start() {
ctx := context.Background()
wg := new(sync.WaitGroup)
ctx = context.WithValue(ctx, "hv", false)
for _, app := range applications {
s.runApplication(ctx, app, wg)
}
wg.Wait()
}
func (s *SSHAgent) runApplication(ctx context.Context, myApp app.Application, wg *sync.WaitGroup) {
cwd, _ := os.Getwd()
fmt.Println("started", myApp.AppId().String())
switch myApp.AppId().String() {
case "Cygwin":
fmt.Println("set SSH_AUTH_SOCK=" + filepath.Join(cwd, app.CYGWIN_SOCK))
case "WinSSH":
fmt.Println("set SSH_AUTH_SOCK=" + app.NAMED_PIPE)
case "WSL":
fmt.Println("export SSH_AUTH_SOCK=" + filepath.Join(cwd, app.WSL_SOCK))
}
wg.Add(1)
go func(application app.Application) {
if application.AppId().String() == "Hyper-V" {
fmt.Println("WSL2 settings:")
fmt.Println(" socat UNIX-LISTEN:/tmp/" + agentName + ".sock,fork,mode=777 SOCKET-CONNECT:40:0:x0000x33332222x02000000x00000000,forever,interval=5 &")
fmt.Println(" export SSH_AUTH_SOCK=/tmp/" + agentName + ".sock")
}
err := application.Run(ctx, s.SSHAgentHandler)
if err != nil {
if application.AppId().String() == "Hyper-V" {
fmt.Printf("ERROR: wsl2: %s", err)
fmt.Println("you can ignore the wsl2 error if you don't have/use wsl2")
return
}
}
wg.Done()
}(myApp)
}