Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common configuration parameters #18

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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
64 changes: 45 additions & 19 deletions sshtun.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@ import (

// SSHTun represents a SSH tunnel
type SSHTun struct {
mutex *sync.Mutex
ctx context.Context
cancel context.CancelFunc
started bool
user string
authType AuthType
authKeyFile string
authKeyReader io.Reader
authPassword string
server *Endpoint
local *Endpoint
remote *Endpoint
forwardType ForwardType
timeout time.Duration
connState func(*SSHTun, ConnState)
tunneledConnState func(*SSHTun, *TunneledConnState)
active int
sshClient *ssh.Client
sshConfig *ssh.ClientConfig
mutex *sync.Mutex
ctx context.Context
cancel context.CancelFunc
started bool
user string
authType AuthType
authKeyFile string
authKeyReader io.Reader
authPassword string
server *Endpoint
local *Endpoint
remote *Endpoint
forwardType ForwardType
timeout time.Duration
connState func(*SSHTun, ConnState)
tunneledConnState func(*SSHTun, *TunneledConnState)
active int
sshClient *ssh.Client
sshConfig *ssh.ClientConfig
sshConfigKeyExchanges []string
sshConfigCiphers []string
sshConfigMACs []string
}

// ForwardType is the type of port forwarding.
Expand Down Expand Up @@ -117,6 +120,24 @@ func (tun *SSHTun) SetPort(port int) {
tun.server.port = port
}

// Set KeyExchanges
// supported, forbidden and preferred algos are in https://pkg.go.dev/golang.org/x/crypto/ssh#Config
func (tun *SSHTun) SetKeyExchanges(keyExchanges []string) {
tun.sshConfigKeyExchanges = keyExchanges
}

// Set ssh Ciphers
// preferred and supported ciphers are in https://pkg.go.dev/golang.org/x/crypto/ssh#Config
func (tun *SSHTun) SetCiphers(ciphers []string) {
tun.sshConfigCiphers = ciphers
}

// Set MACs
// supported MACs are in https://pkg.go.dev/golang.org/x/crypto/ssh#Config
func (tun *SSHTun) SetMACs(MACs []string) {
tun.sshConfigMACs = MACs
}

// SetUser changes the user used to make the SSH connection.
func (tun *SSHTun) SetUser(user string) {
tun.user = user
Expand Down Expand Up @@ -274,6 +295,11 @@ func (tun *SSHTun) Stop() {

func (tun *SSHTun) initSSHConfig() (*ssh.ClientConfig, error) {
config := &ssh.ClientConfig{
Config: ssh.Config{
KeyExchanges: tun.sshConfigKeyExchanges,
Ciphers: tun.sshConfigCiphers,
MACs: tun.sshConfigMACs,
},
User: tun.user,
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
return nil
Expand Down
Loading