From ad270c328b8b1dd3fa1503c30157161cb3faffb5 Mon Sep 17 00:00:00 2001 From: Jerry Jacobs Date: Fri, 26 Jul 2024 06:57:37 +0200 Subject: [PATCH] Initial work to make hostKey parameter interface public for extending by other packages or tools. Fixes cloudfoundry/socks5-proxy#21 --- socks5_proxy.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/socks5_proxy.go b/socks5_proxy.go index 8d9f3e95..8ccea931 100644 --- a/socks5_proxy.go +++ b/socks5_proxy.go @@ -18,14 +18,20 @@ import ( var netListen = net.Listen -type hostKey interface { +// SSHHostKeyFetcher is the interface to get the SSH server jumphost public key +// +// The username is the login username to the SSH server +// The privateKey is the client login private SSH key (PEM-encoded) +// The serverURL is the IP/hostname and port of the SSH server. +// NOTE: The port must always be specified and port 22 is not implicitly assumed. E.g "jumphost:22" +type SSHHostKeyFetcher interface { Get(username, privateKey, serverURL string) (ssh.PublicKey, error) } type DialFunc func(network, address string) (net.Conn, error) type Socks5Proxy struct { - hostKey hostKey + hostKey SSHHostKeyFetcher port int started bool keepAliveInterval time.Duration @@ -33,7 +39,7 @@ type Socks5Proxy struct { mtx sync.Mutex } -func NewSocks5Proxy(hostKey hostKey, logger *log.Logger, keepAliveInterval time.Duration) *Socks5Proxy { +func NewSocks5Proxy(hostKey SSHHostKeyFetcher, logger *log.Logger, keepAliveInterval time.Duration) *Socks5Proxy { return &Socks5Proxy{ hostKey: hostKey, started: false,