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

x/crypto/ssh/knownhosts: fails to find key when port = "ssh" #44668

Open
jackc opened this issue Feb 27, 2021 · 0 comments
Open

x/crypto/ssh/knownhosts: fails to find key when port = "ssh" #44668

jackc opened this issue Feb 27, 2021 · 0 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@jackc
Copy link

jackc commented Feb 27, 2021

What version of Go are you using (go version)?

go version go1.16 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jack/Library/Caches/go-build"
GOENV="/Users/jack/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/jack/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/jack/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/jack/dev/ccsalespro/isoamp/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/49/sq09r9hs3mlgyzk8r18zswfw0000gn/T/go-build464070472=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

net.Dial and ssh.Dial allow specifying ports by name. e.g. host.example.com:ssh. This fails in combination with knownhosts.

	sshConfig := &ssh.ClientConfig{
		// ...
	}

	if homeDir, err := os.UserHomeDir(); err == nil {
		if hostKeyCallback, err := knownhosts.New(fmt.Sprintf("%s/.ssh/known_hosts", homeDir)); err == nil {
			sshConfig.HostKeyCallback = hostKeyCallback
		}
	}

	return ssh.Dial("tcp", "host.example.com:ssh", sshConfig)

What did you expect to see?

I expect for the knownhost entry for host.example.com to be found.

What did you see instead?

ssh: handshake failed: knownhosts: key is unknown

If the port is specified numerically it succeeds. e.g. host.example.com:22

@gopherbot gopherbot added this to the Unreleased milestone Feb 27, 2021
@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 6, 2021
@dmitshur dmitshur changed the title x/crypto/ssh/knownhosts: Fails to find key when port = "ssh" x/crypto/ssh/knownhosts: fails to find key when port = "ssh" Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants