diff --git a/cmd/cmd.go b/cmd/cmd.go index 7a34f6ac83..94f3af1a8f 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -186,7 +186,7 @@ func tryInitSSHDockerClient() (dockerClient.CommonAPIClient, error) { dockerClientOpts := []dockerClient.Opt{ dockerClient.WithVersion("1.38"), dockerClient.WithHTTPClient(httpClient), - dockerClient.WithHost("http://example.com/"), + dockerClient.WithHost("http://dummy/"), dockerClient.WithDialContext(dialContext), } return dockerClient.NewClientWithOpts(dockerClientOpts...) @@ -235,7 +235,7 @@ func readSecret(prompt string) (pw []byte, err error) { } } -func newPasswordCbk() sshdialer.PasswordCallback { +func newPasswordCbk() sshdialer.SecretCallback { var pwdSet bool var pwd string return func() (string, error) { @@ -254,7 +254,7 @@ func newPasswordCbk() sshdialer.PasswordCallback { } } -func newPassPhraseCbk() sshdialer.PassPhraseCallback { +func newPassPhraseCbk() sshdialer.SecretCallback { var pwdSet bool var pwd string return func() (string, error) { diff --git a/internal/sshdialer/ssh_dialer.go b/internal/sshdialer/ssh_dialer.go index a54765dcf0..a053ae5556 100644 --- a/internal/sshdialer/ssh_dialer.go +++ b/internal/sshdialer/ssh_dialer.go @@ -24,18 +24,19 @@ import ( "golang.org/x/crypto/ssh/knownhosts" ) -type PasswordCallback func() (string, error) -type PassPhraseCallback func() (string, error) +type SecretCallback func() (string, error) type HostKeyCallback func(hostPort string, pubKey ssh.PublicKey) error type Config struct { Identity string PassPhrase string - PasswordCallback PasswordCallback - PassPhraseCallback PassPhraseCallback + PasswordCallback SecretCallback + PassPhraseCallback SecretCallback HostKeyCallback HostKeyCallback } +const defaultSSHPort = "22" + func NewDialContext(url *urlPkg.URL, config Config) (func(ctx context.Context, network, addr string) (net.Conn, error), error) { sshConfig, err := NewSSHClientConfig(url, config) if err != nil { @@ -44,7 +45,7 @@ func NewDialContext(url *urlPkg.URL, config Config) (func(ctx context.Context, n port := url.Port() if port == "" { - port = "22" + port = defaultSSHPort } host := url.Hostname() @@ -319,7 +320,7 @@ func NewSSHClientConfig(url *urlPkg.URL, credentialsConfig Config) (*ssh.ClientC return clientConfig, nil } -func publicKey(path string, passphrase []byte, passPhraseCallback PassPhraseCallback) (ssh.Signer, error) { +func publicKey(path string, passphrase []byte, passPhraseCallback SecretCallback) (ssh.Signer, error) { key, err := ioutil.ReadFile(path) if err != nil { return nil, fmt.Errorf("failed to read key file: %w", err) @@ -348,7 +349,7 @@ func publicKey(path string, passphrase []byte, passPhraseCallback PassPhraseCall func createHostKeyCallback(hostKeyCallback HostKeyCallback) func(hostPort string, remote net.Addr, key ssh.PublicKey) error { return func(hostPort string, remote net.Addr, pubKey ssh.PublicKey) error { - host, port := hostPort, "22" + host, port := hostPort, defaultSSHPort if _h, _p, err := net.SplitHostPort(host); err == nil { host, port = _h, _p } @@ -381,7 +382,7 @@ func createHostKeyCallback(hostKeyCallback HostKeyCallback) func(hostPort string } for _, hp := range hostPorts { - h, p := hp, "22" + h, p := hp, defaultSSHPort if _h, _p, err := net.SplitHostPort(hp); err == nil { h, p = _h, _p }