ssh: return clearer error when signature algorithm is used as key format

ParsePublicKey now returns a more specific error when a signature
algorithm like rsa-sha2-256 is mistakenly provided as a key format

Change-Id: Ic08286a5b2b326e99dd3e61594919203f0c36791
Reviewed-on: https://go-review.googlesource.com/c/crypto/+/695075
Reviewed-by: Filippo Valsorda <filippo@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Nicola Murino
2025-09-15 23:32:56 -07:00
parent 96dc232fbd
commit f4d47b0db5
4 changed files with 76 additions and 2 deletions
+20
View File
@@ -5,7 +5,9 @@
package ssh
import (
"maps"
"reflect"
"slices"
"testing"
)
@@ -174,3 +176,21 @@ func TestFindAgreedAlgorithms(t *testing.T) {
})
}
}
func TestKeyFormatAlgorithms(t *testing.T) {
supportedAlgos := SupportedAlgorithms()
insecureAlgos := InsecureAlgorithms()
algoritms := append(supportedAlgos.PublicKeyAuths, insecureAlgos.PublicKeyAuths...)
algoritms = append(algoritms, slices.Collect(maps.Keys(certKeyAlgoNames))...)
for _, algo := range algoritms {
keyFormat := keyFormatForAlgorithm(algo)
if keyFormat == "" {
t.Errorf("got empty key format for algorithm %q", algo)
}
if !slices.Contains(algorithmsForKeyFormat(keyFormat), algo) {
t.Errorf("algorithms for key format %q, does not contain %q", keyFormat, algo)
}
}
}