-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ssh: fix RSA certificate and public key authentication with older cli…
…ents After adding support for rsa-sha2-256/512 on the server side some edge cases started to arise with old clients: 1) public key authentication with gpg-agent < 2.2.6 fails because we receive ssh-rsa as signature format and rsa-sha2-256 or rsa-sha2-512 as algorithm. This is a bug in gpg-agent fixed in this commit: gpg/gnupg@80b775b 2) certificate authentication fails with OpenSSH 7.2-7.7 because we receive [email protected] as algorithm and rsa-sha2-256 or rsa-sha2-512 as signature format. This patch is based on CL 412854 and has been tested with every version of OpenSSH from 7.1 to 7.9 and OpenSSH 9.3. Fixes golang/go#53391 Change-Id: Id71f596f73d84efb5c76d6d5388432cccad3e3b1 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/506835 Auto-Submit: Filippo Valsorda <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Run-TryBot: Filippo Valsorda <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]>
- Loading branch information
Showing
3 changed files
with
148 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,6 +370,25 @@ func gssExchangeToken(gssapiConfig *GSSAPIWithMICConfig, firstToken []byte, s *c | |
return authErr, perms, nil | ||
} | ||
|
||
// isAlgoCompatible checks if the signature format is compatible with the | ||
// selected algorithm taking into account edge cases that occur with old | ||
// clients. | ||
func isAlgoCompatible(algo, sigFormat string) bool { | ||
// Compatibility for old clients. | ||
// | ||
// For certificate authentication with OpenSSH 7.2-7.7 signature format can | ||
// be rsa-sha2-256 or rsa-sha2-512 for the algorithm | ||
// [email protected]. | ||
// | ||
// With gpg-agent < 2.2.6 the algorithm can be rsa-sha2-256 or rsa-sha2-512 | ||
// for signature format ssh-rsa. | ||
if isRSA(algo) && isRSA(sigFormat) { | ||
return true | ||
} | ||
// Standard case: the underlying algorithm must match the signature format. | ||
return underlyingAlgo(algo) == sigFormat | ||
} | ||
|
||
// ServerAuthError represents server authentication errors and is | ||
// sometimes returned by NewServerConn. It appends any authentication | ||
// errors that may occur, and is returned if all of the authentication | ||
|
@@ -567,7 +586,7 @@ userAuthLoop: | |
authErr = fmt.Errorf("ssh: algorithm %q not accepted", sig.Format) | ||
break | ||
} | ||
if underlyingAlgo(algo) != sig.Format { | ||
if !isAlgoCompatible(algo, sig.Format) { | ||
authErr = fmt.Errorf("ssh: signature %q not compatible with selected algorithm %q", sig.Format, algo) | ||
break | ||
} | ||
|