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: Client chokes after first key exchange against OpenSSH 7.4p1 server #51808

Closed
peterverraedt opened this issue Mar 19, 2022 · 2 comments

Comments

@peterverraedt
Copy link

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

$ go version
go version go1.16.14 linux/amd64

Does this issue reproduce with the latest release?

Tested with latest commits regarding RFC8308 support for client.

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

go env Output
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOVERSION="go1.16.14"

What did you do?

I'm running a ssh client (similar to https://github.com/helloyi/go-sshclient) against an OpenSSH 7.4p1 server, with client authentication using certificates, and running a command for a while (longer than 30 seconds) remotely, piping stdin/stdout through ssh.

What did you expect to see?

The command being completed successfully.

What did you see instead?

After RFC8308 was implemented client-side in the x/crypto/ssh package, the ssh client closes its connection suddenly after the first key reexchange, returning the error "remote command exited without exit status or exit signal".

The reason, at it seems, is that an OpenSSH 7.4p1 server receiving ext-info-c, sends msgExtInfo after every key exchange rather than only the first one, breaking RFC8308. The first one is correctly handled in https://github.com/golang/crypto/blob/master/ssh/client_auth.go#L33-L59, but the key reexchange happens when the mux is already set up and results in the connection being closed client-side.

The following patch works to circumvent the issue:

diff --git a/ssh/mux.go b/ssh/mux.go
index 9654c01869..7d3fd28dd4 100644
--- a/ssh/mux.go
+++ b/ssh/mux.go
@@ -227,6 +227,9 @@ func (m *mux) onePacket() error {
 	}
 
 	switch packet[0] {
+	case msgExtInfo:
+		// OpenSSH 7.4p1 sends msgExtInfo at the wrong time, breaking RFC8308. We simply ignore the packet.
+		return nil
 	case msgChannelOpen:
 		return m.handleChannelOpen(packet)
 	case msgGlobalRequest, msgRequestSuccess, msgRequestFailure:

The issue is not present against OpenSSH 8.

@gopherbot gopherbot added this to the Unreleased milestone Mar 19, 2022
@peterverraedt
Copy link
Author

peterverraedt added a commit to kuleuven/crypto that referenced this issue Mar 21, 2022
In accordance to RFC8308, send ext-info-c only during the first key
exchange. Some server implementations such as OpenSSH 7 will send an
extInfoMsg message each time when ext-info-c is received. This results
in a closed connection, as our client does not expect this message while
handling the mux.

See <https://bugzilla.mindrot.org/show_bug.cgi?id=2929> regarding the
behaviour of OpenSSH if it sees ext-info-c in later key exchanges.

Fixes: golang/go#51808

Signed-off-by: Peter Verraedt <[email protected]>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/394134 mentions this issue: ssh: send ext-info-c only once

bradfitz added a commit to tailscale/tailscale that referenced this issue Mar 23, 2022
(for golang/go#51808)

Updates #3802

Change-Id: Ifbd483c0144b4c86da69143b23b2a06da7672c92
Signed-off-by: Brad Fitzpatrick <[email protected]>
bradfitz added a commit to tailscale/tailscale that referenced this issue Mar 23, 2022
(for golang/go#51808)

Updates #3802

Change-Id: Ifbd483c0144b4c86da69143b23b2a06da7672c92
Signed-off-by: Brad Fitzpatrick <[email protected]>
LewiGoddard pushed a commit to LewiGoddard/crypto that referenced this issue Feb 16, 2023
In accordance to RFC8308, send ext-info-c only during the first key
exchange. Some server implementations such as OpenSSH 7 will send an
extInfoMsg message each time when ext-info-c is received. This results
in a closed connection, as our client does not expect this message while
handling the mux.

See https://bugzilla.mindrot.org/show_bug.cgi?id=2929 regarding the
behaviour of OpenSSH if it sees ext-info-c in later key exchanges.

Fixes golang/go#51808

Change-Id: Id94f1ef73cec6147136246b0b6048b57db92660d
GitHub-Last-Rev: fcfe5ed37306136219854031abc809e0dc9b3124
GitHub-Pull-Request: golang/crypto#208
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/394134
Reviewed-by: Filippo Valsorda <[email protected]>
Run-TryBot: Filippo Valsorda <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Trust: Roland Shoemaker <[email protected]>
@golang golang locked and limited conversation to collaborators Mar 21, 2023
BiiChris pushed a commit to BiiChris/crypto that referenced this issue Sep 15, 2023
In accordance to RFC8308, send ext-info-c only during the first key
exchange. Some server implementations such as OpenSSH 7 will send an
extInfoMsg message each time when ext-info-c is received. This results
in a closed connection, as our client does not expect this message while
handling the mux.

See https://bugzilla.mindrot.org/show_bug.cgi?id=2929 regarding the
behaviour of OpenSSH if it sees ext-info-c in later key exchanges.

Fixes golang/go#51808

Change-Id: Id94f1ef73cec6147136246b0b6048b57db92660d
GitHub-Last-Rev: fcfe5ed
GitHub-Pull-Request: golang#208
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/394134
Reviewed-by: Filippo Valsorda <[email protected]>
Run-TryBot: Filippo Valsorda <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Trust: Roland Shoemaker <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants