aboutsummaryrefslogtreecommitdiff
path: root/ssh/client_auth.go
diff options
context:
space:
mode:
authorNicola Murino <nicola.murino@gmail.com>2026-02-16 10:38:19 +0100
committerGopher Robot <gobot@golang.org>2026-03-23 08:34:51 -0700
commit8400f4a938077a7a7817ab7d163d148e371b320b (patch)
treedf6915b759ea07d0c031b981c6c0d17843703e7b /ssh/client_auth.go
parent81c6cb34a8fc386ed53293cd79e3c0c232ee7366 (diff)
downloadgo-x-crypto-8400f4a938077a7a7817ab7d163d148e371b320b.tar.xz
ssh: respect signer's algorithm preference in pickSignatureAlgorithm
Previously, pickSignatureAlgorithm constructed the list of candidate algorithms by iterating over the static list returned by algorithmsForKeyFormat. This caused the Signer's preference order to be ignored in favor of the library's default internal order. This change inverts the filtering logic to iterate over the signer's supported algorithms first. This ensures that if a MultiAlgorithmSigner explicitly prefers a specific algorithm (e.g., rsa-sha2-512 over rsa-sha2-256), that preference is preserved and respected during the handshake negotiation. Fixes golang/go#78248 Change-Id: I48a0aac720be7f973963342b82047ce32fc96699 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/746020 Reviewed-by: Lonny Wong <lonnywang.cn@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Nicola Murino <nicola.murino@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org>
Diffstat (limited to 'ssh/client_auth.go')
-rw-r--r--ssh/client_auth.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/ssh/client_auth.go b/ssh/client_auth.go
index 3127e49..4f2f75c 100644
--- a/ssh/client_auth.go
+++ b/ssh/client_auth.go
@@ -274,10 +274,14 @@ func pickSignatureAlgorithm(signer Signer, extensions map[string][]byte) (MultiA
}
// Filter algorithms based on those supported by MultiAlgorithmSigner.
+ // Iterate over the signer's algorithms first to preserve its preference order.
+ supportedKeyAlgos := algorithmsForKeyFormat(keyFormat)
var keyAlgos []string
- for _, algo := range algorithmsForKeyFormat(keyFormat) {
- if slices.Contains(as.Algorithms(), underlyingAlgo(algo)) {
- keyAlgos = append(keyAlgos, algo)
+ for _, signerAlgo := range as.Algorithms() {
+ if idx := slices.IndexFunc(supportedKeyAlgos, func(algo string) bool {
+ return underlyingAlgo(algo) == signerAlgo
+ }); idx >= 0 {
+ keyAlgos = append(keyAlgos, supportedKeyAlgos[idx])
}
}