-
Notifications
You must be signed in to change notification settings - Fork 18k
x/crypto/ssh: SSH_MSG_USERAUTH_PK_OK handling differs from OpenSSH #64785
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
Comments
Change https://go.dev/cl/550716 mentions this issue: |
Thanks for the report. You mention that you are using Go 1.20 -- I assume the same problem exists in 1.21 and on tip? @drakkan @golang/security per owners. |
Hello @stephenm-stripe, thanks for the detailed info. So this is yet another egde case for RSA keys. Can you please confirm that the following patch works with your server? (also for certificates) |
Thanks for confirming. Can you please modify your CL like my proof of concept? I think it is more readable to have separate conditions for each case |
Change https://go.dev/cl/553035 mentions this issue: |
Yes. I meant to update the existing one, but have created https://go-review.googlesource.com/c/crypto/+/553035 instead. |
I'd like to push back a little on this. The We do add quirk workarounds when they are necessary for ecosystem reasons (i.e. if five OpenSSH versions in a row exhibited a broken behavior), but only after there was an attempt to fix the issue on the peer's side, and only if the broken peer is popular.
Can you share more about what implementation has this issue? Is there a fix? How common is it? |
Replying from my personal account (as mentioned in this comment).
I don't have details on the implementation, other than it was a third-party enterprise software suite for Windows. There is no known fix. We did inform the server owners of this limitation of the vendor software they are using, but they seemed unlikely to pursue alternative solutions given that we were their only client experiencing SSH issues (I suspect we were the only ones using Go to connect). On our side, of the many servers we connected to for SFTP purposes, this was the only remote server that had this issue. |
Change https://go.dev/cl/573360 mentions this issue: |
According to RFC 4252 Section 7 the algorithm in SSH_MSG_USERAUTH_PK_OK should match that of the request but some servers send the key type instead. OpenSSH checks for the key type, so we do the same. Fixes golang/go#66438 Fixes golang/go#64785 Fixes golang/go#56342 Fixes golang/go#54027 Change-Id: I2f733f0faece097e44ba7a97c868d30a53e21d79 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/573360 Auto-Submit: Nicola Murino <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Run-TryBot: Nicola Murino <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Joedian Reid <[email protected]>
Go version
go version go1.20.5 darwin/arm64
What operating system and processor architecture are you using (
go env
)?What did you do?
I was encountering the same error in #54027 for connecting to a remote server outside of my control. In this scenario, the remote server does not follow the RFC in creating SSH_MSG_USERAUTH_PK_OK packets.
The RFC specifies that SSH_MSG_USERAUTH_REQUEST packets include
string public key algorithm name
and the server would respond with a SSH_MSG_USERAUTH_PK_OK that includesstring public key algorithm name from the request
.In this case, I would see our SSH_MSG_USERAUTH_REQUEST include an algorithm like
rsa-sha2-256
, but the SSH_MSG_USERAUTH_PK_OK response would always containssh-rsa
for all RSA algorithms provided.What did you expect to see?
Go SSH handshakes have the same outcome as OpenSSH handshakes for the same parameters.
What did you see instead?
OpenSSH handshakes succeed with the remote SSH server while Go SSH handshakes do not.
The Go handshake fails because the handling here checks that the outbound algorithm string matches the one in the response. In our case, the remote server is not following the RFC and sending back the type rather than the algorithm string that was sent to it. So Go's implementation considers this a failed auth and returns an error to the application.
Yet, OpenSSH via
ssh
on the command line succeeds for this server. The OpenSSH implementation for handling SSH_MSG_USERAUTH_PK_OK doesn't check the exact string matches, rather, it converts the algorithm names into the key types and compares on that (code for the check, code for the struct).I admit, OpenSSH's handling here differs from the RFC, but it does result in a successful connection while Go's implementation does not. I also tried commenting out Go's logic around key validation that invokes these packets and the connection succeeded, so the broken invariant doesn't actually impact the connection overall.
I will put up a pull request to modify Go's implementation of SSH_MSG_USERAUTH_PK_OK checks to match OpenSSH's.
The text was updated successfully, but these errors were encountered: