The x/crypto/ssh client fails to connect to servers that present more than 255 bytes before providing the complete SSH-2.0 version string. This is at odds with OpenSSH, which is more forgiving, and handles these servers today.
This limit is defined in ssh/transport.go:
// maxVersionStringBytes is the maximum number of bytes that we'll
// accept as a version string. RFC 4253 section 4.2 limits this at 255
// chars
const maxVersionStringBytes = 255
An example of a semi-common Dropbear configuration that triggers this issue:
% nc funky-dropbear-system 22
Will output 1024 bit rsa secret key to '/tmp/dropbear_rsa_host_key.1921'
Generating key, this may take a while...
Public key portion is:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgwCIMhjuaUs3uwh+c/eK73qeBQ09G450f/9bOlRB4nVoZPzJfxf2ss6wCddwdta0mamv+uJgUPjWXbE7XGzRRUshtLq3yy8y62XlPDSyP9KOnLNsUTioyGKMHYJJ1JG0plLPAbaotc7VE8ZZ8exv/8JaA8hQnixDBlIiOY9w89tMeQp/
Fingerprint: sha1 d7:aa:67:8d:7d:55:4e:13:d9:68:8e:4d:2a:88:b3:51:4d:87:42:ef
SSH-2.0-dropbear_2016.74
What did you see happen?
The SSH client fails to connect and returns a "version overflow" handshake error.
What did you expect to see?
A completed handshake without the overflow error.
A simple fix is to increase the number of bytes read in the version exchange:
Go version
go version go1.22.2 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
The x/crypto/ssh client fails to connect to servers that present more than 255 bytes before providing the complete SSH-2.0 version string. This is at odds with OpenSSH, which is more forgiving, and handles these servers today.
This limit is defined in
ssh/transport.go
:An example of a semi-common Dropbear configuration that triggers this issue:
What did you see happen?
The SSH client fails to connect and returns a "version overflow" handshake error.
What did you expect to see?
A completed handshake without the overflow error.
A simple fix is to increase the number of bytes read in the version exchange:
const maxVersionStringBytes = 1024