aboutsummaryrefslogtreecommitdiff
path: root/ssh/common_test.go
diff options
context:
space:
mode:
authorNicola Murino <nicola.murino@gmail.com>2025-08-12 07:59:34 +0200
committerNicola Murino <nicola.murino@gmail.com>2025-09-15 23:32:56 -0700
commitf4d47b0db5875e61dd52acdb63be800177ab48bb (patch)
tree0c974606cbfd3f715128a0173fc6a599dd22efe9 /ssh/common_test.go
parent96dc232fbd7928e9c23da42e770c8b79a2348d86 (diff)
downloadgo-x-crypto-f4d47b0db5875e61dd52acdb63be800177ab48bb.tar.xz
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>
Diffstat (limited to 'ssh/common_test.go')
-rw-r--r--ssh/common_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/ssh/common_test.go b/ssh/common_test.go
index 67cf1f4..80aa2df 100644
--- a/ssh/common_test.go
+++ b/ssh/common_test.go
@@ -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)
+ }
+
+ }
+}