Skip to content

Commit

Permalink
Add windows ssh named pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Feb 3, 2024
1 parent 1455cf9 commit 1e24bce
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 37 deletions.
37 changes: 0 additions & 37 deletions agent/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"crypto/rand"
"errors"
"fmt"
"net"
"os"
"time"

"github.com/quexten/goldwarden/agent/config"
Expand Down Expand Up @@ -184,38 +182,3 @@ func NewVaultAgent(vault *vault.Vault, config *config.Config, runtimeConfig *con
},
}
}

func (v SSHAgentServer) Serve() {
path := v.runtimeConfig.SSHAgentSocketPath
if _, err := os.Stat(path); err == nil {
if err := os.Remove(path); err != nil {
log.Error("Could not remove old socket file: %s", err)
return
}
}
listener, err := net.Listen("unix", path)
if err != nil {
panic(err)
}

log.Info("SSH Agent listening on %s", path)

for {
var conn, err = listener.Accept()
if err != nil {
panic(err)
}

callingContext := sockets.GetCallingContext(conn)

log.Info("SSH Agent connection from %s>%s>%s \nby user %s", callingContext.GrandParentProcessName, callingContext.ParentProcessName, callingContext.ProcessName, callingContext.UserName)
log.Info("SSH Agent connection accepted")

go agent.ServeAgent(vaultAgent{
vault: v.vault,
config: v.config,
unlockRequestAction: v.unlockRequestAction,
context: callingContext,
}, conn)
}
}
46 changes: 46 additions & 0 deletions agent/ssh/sshsocketunix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//go:build !windows

package ssh

import (
"net"
"os"

"github.com/quexten/goldwarden/agent/sockets"
"golang.org/x/crypto/ssh/agent"
)

func (v SSHAgentServer) Serve() {
path := v.runtimeConfig.SSHAgentSocketPath
if _, err := os.Stat(path); err == nil {
if err := os.Remove(path); err != nil {
log.Error("Could not remove old socket file: %s", err)
return
}
}
listener, err := net.Listen("unix", path)
if err != nil {
panic(err)
}

log.Info("SSH Agent listening on %s", path)

for {
var conn, err = listener.Accept()
if err != nil {
panic(err)
}

callingContext := sockets.GetCallingContext(conn)

log.Info("SSH Agent connection from %s>%s>%s \nby user %s", callingContext.GrandParentProcessName, callingContext.ParentProcessName, callingContext.ProcessName, callingContext.UserName)
log.Info("SSH Agent connection accepted")

go agent.ServeAgent(vaultAgent{
vault: v.vault,
config: v.config,
unlockRequestAction: v.unlockRequestAction,
context: callingContext,
}, conn)
}
}
38 changes: 38 additions & 0 deletions agent/ssh/sshsocketwindows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//go:build windows

package ssh

import (
"github.com/quexten/goldwarden/agent/sockets"
"golang.org/x/crypto/ssh/agent"
)

func (v SSHAgentServer) Serve() {
pipePath := `\\.\pipe\openssh-ssh-agent`

l, err := winio.ListenPipe(pipePath, nil)

Check failure on line 13 in agent/ssh/sshsocketwindows.go

View workflow job for this annotation

GitHub Actions / build_windows_x86_64

undefined: winio
if err != nil {
log.Fatal("listen error:", err)
}
defer l.Close()
log.Printf("Server listening on named pipe %v\n", pipePath)

Check failure on line 18 in agent/ssh/sshsocketwindows.go

View workflow job for this annotation

GitHub Actions / build_windows_x86_64

log.Printf undefined (type *llamalog.Logger has no field or method Printf)

for {
conn, err := l.Accept()
if err != nil {
log.Fatal("accept error:", err)
}

callingContext := sockets.GetCallingContext(conn)

log.Info("SSH Agent connection from %s>%s>%s \nby user %s", callingContext.GrandParentProcessName, callingContext.ParentProcessName, callingContext.ProcessName, callingContext.UserName)
log.Info("SSH Agent connection accepted")

go agent.ServeAgent(vaultAgent{
vault: v.vault,
config: v.config,
unlockRequestAction: v.unlockRequestAction,
context: callingContext,
}, conn)
}
}

0 comments on commit 1e24bce

Please sign in to comment.