Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions socks5_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,28 @@ 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
logger *log.Logger
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,
Expand Down