Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
add support for windows ssh-agent
Browse files Browse the repository at this point in the history
Windows 10 has the optional feature for an ssh client.
This package comes with a backed in ssh-agent which
utilizes windows named pipes instead of unix sockets.
This CL adds support to communicate which such ssh-agent.
This is mainly needed to enable ssh agents which do
not support the pageant established "protocol".

Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
  • Loading branch information
tobiaskohlbau committed May 18, 2020
1 parent 0d53826 commit cfb1ff2
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"syscall"
"unsafe"

"github.com/Microsoft/go-winio"
"github.com/apenwarr/fixconsole"
"github.com/lxn/win"
"golang.org/x/sys/windows"
Expand All @@ -38,6 +39,7 @@ var (
verbose = flag.Bool("verbose", false, "Enable verbose logging")
logFile = flag.String("logfile", "wsl2-gpg-ssh.log", "Path to logfile")
gpg = flag.String("gpg", "", "gpg mode")
ssh = flag.String("ssh", "", "windows ssh mode")

failureMessage = [...]byte{0, 0, 0, 1, 5}
)
Expand Down Expand Up @@ -152,10 +154,13 @@ func main() {
}
basePath := filepath.Join(homeDir, "AppData", "Roaming", "gnupg")
handleGPG(filepath.Join(basePath, *gpg))
} else {
handleSSH()
return
}

if *ssh != "" {
handlePipedSSH()
return
}
handleSSH()
}

func handleGPG(path string) {
Expand Down Expand Up @@ -220,6 +225,26 @@ func handleGPG(path string) {
}
}

func handlePipedSSH() {
conn, err := winio.DialPipe(*ssh, nil)
if err != nil {
log.Printf("failed to dial ssh pipe at %s: %s\n", *ssh, err)
return
}
go func() {
_, err := io.Copy(os.Stdout, conn)
if err != nil && err != io.EOF {
log.Printf("failed to copy from pipe to stdout: %s\n", err)
os.Exit(1)
}
}()
_, err = io.Copy(conn, os.Stdin)
if err != nil && err != io.EOF {
log.Printf("failed to copy from stdin to pipe: %s\n", err)
os.Exit(1)
}
}

func handleSSH() {
reader := bufio.NewReader(os.Stdin)
for {
Expand Down

0 comments on commit cfb1ff2

Please # to comment.