From 7cfd20f4871e09e4e5af20b2a82408b164d04f14 Mon Sep 17 00:00:00 2001 From: Mike Wyatt Date: Sat, 9 Nov 2024 23:56:17 -0400 Subject: [PATCH] ugly refactor for golang platform builds --- src/go_ssh_ext/conn_unix.go | 12 ++++++++++++ src/go_ssh_ext/conn_windows.go | 14 ++++++++++++++ src/go_ssh_ext/main.go | 22 ++++------------------ 3 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 src/go_ssh_ext/conn_unix.go create mode 100644 src/go_ssh_ext/conn_windows.go diff --git a/src/go_ssh_ext/conn_unix.go b/src/go_ssh_ext/conn_unix.go new file mode 100644 index 0000000..09aa364 --- /dev/null +++ b/src/go_ssh_ext/conn_unix.go @@ -0,0 +1,12 @@ +//go:build !windows +// +build !windows + +package go_ssh_ext + +import ( + "net" +) + +func getConnectionForAgent(sshAuthSock string) (net.Conn, error) { + return net.Dial("unix", sshAuthSock) +} diff --git a/src/go_ssh_ext/conn_windows.go b/src/go_ssh_ext/conn_windows.go new file mode 100644 index 0000000..4359d77 --- /dev/null +++ b/src/go_ssh_ext/conn_windows.go @@ -0,0 +1,14 @@ +//go:build windows +// +build windows + +package go_ssh_ext + +import ( + "net" + + "github.com/Microsoft/go-winio" +) + +func getConnectionForAgent(sshAuthSock string) (net.Conn, error) { + return winio.DialPipe(sshAuthSock, nil) +} diff --git a/src/go_ssh_ext/main.go b/src/go_ssh_ext/main.go index 6b08ab4..8cb7143 100644 --- a/src/go_ssh_ext/main.go +++ b/src/go_ssh_ext/main.go @@ -9,7 +9,6 @@ import ( "runtime" "syscall" - "github.com/Microsoft/go-winio" "github.com/kevinburke/ssh_config" "github.com/skeema/knownhosts" "golang.org/x/crypto/ssh" @@ -182,23 +181,10 @@ func getSignersForIdentityAgent(hostname string) ([]ssh.Signer, error) { sshAuthSock = CleanupSshConfigValue(sshAuthSock) - var conn net.Conn - if runtime.GOOS == "windows" { - //inner_conn, err := namedpipe.DialContext(context.Background(), sshAuthSock) - // inner_conn, err := npipe.Dial(sshAuthSock) - inner_conn, err := winio.DialPipe(sshAuthSock, nil) - if err != nil { - slog.Error("Failed to open SSH auth socket", "err", err) - return nil, err - } - conn = inner_conn - } else { - inner_conn, err := net.Dial("unix", sshAuthSock) - if err != nil { - slog.Error("Failed to open SSH auth socket", "err", err) - return nil, err - } - conn = inner_conn + conn, err := getConnectionForAgent(sshAuthSock) + if err != nil { + slog.Error("Failed to open SSH auth socket", "err", err) + return nil, err } slog.Info("Using ssh agent", "socket", sshAuthSock)