aboutsummaryrefslogtreecommitdiff
path: root/ssh/handshake_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'ssh/handshake_test.go')
-rw-r--r--ssh/handshake_test.go90
1 files changed, 90 insertions, 0 deletions
diff --git a/ssh/handshake_test.go b/ssh/handshake_test.go
index 879143a..65afc20 100644
--- a/ssh/handshake_test.go
+++ b/ssh/handshake_test.go
@@ -620,3 +620,93 @@ func TestNoSHA2Support(t *testing.T) {
t.Fatal(err)
}
}
+
+func TestMultiAlgoSignerHandshake(t *testing.T) {
+ algorithmSigner, ok := testSigners["rsa"].(AlgorithmSigner)
+ if !ok {
+ t.Fatal("rsa test signer does not implement the AlgorithmSigner interface")
+ }
+ multiAlgoSigner, err := NewSignerWithAlgorithms(algorithmSigner, []string{KeyAlgoRSASHA256, KeyAlgoRSASHA512})
+ if err != nil {
+ t.Fatalf("unable to create multi algorithm signer: %v", err)
+ }
+ c1, c2, err := netPipe()
+ if err != nil {
+ t.Fatalf("netPipe: %v", err)
+ }
+ defer c1.Close()
+ defer c2.Close()
+
+ serverConf := &ServerConfig{
+ PasswordCallback: func(conn ConnMetadata, password []byte) (*Permissions, error) {
+ return &Permissions{}, nil
+ },
+ }
+ serverConf.AddHostKey(multiAlgoSigner)
+ go NewServerConn(c1, serverConf)
+
+ clientConf := &ClientConfig{
+ User: "test",
+ Auth: []AuthMethod{Password("testpw")},
+ HostKeyCallback: FixedHostKey(testSigners["rsa"].PublicKey()),
+ HostKeyAlgorithms: []string{KeyAlgoRSASHA512},
+ }
+
+ if _, _, _, err := NewClientConn(c2, "", clientConf); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestMultiAlgoSignerNoCommonHostKeyAlgo(t *testing.T) {
+ algorithmSigner, ok := testSigners["rsa"].(AlgorithmSigner)
+ if !ok {
+ t.Fatal("rsa test signer does not implement the AlgorithmSigner interface")
+ }
+ multiAlgoSigner, err := NewSignerWithAlgorithms(algorithmSigner, []string{KeyAlgoRSASHA256, KeyAlgoRSASHA512})
+ if err != nil {
+ t.Fatalf("unable to create multi algorithm signer: %v", err)
+ }
+ c1, c2, err := netPipe()
+ if err != nil {
+ t.Fatalf("netPipe: %v", err)
+ }
+ defer c1.Close()
+ defer c2.Close()
+
+ // ssh-rsa is disabled server side
+ serverConf := &ServerConfig{
+ PasswordCallback: func(conn ConnMetadata, password []byte) (*Permissions, error) {
+ return &Permissions{}, nil
+ },
+ }
+ serverConf.AddHostKey(multiAlgoSigner)
+ go NewServerConn(c1, serverConf)
+
+ // the client only supports ssh-rsa
+ clientConf := &ClientConfig{
+ User: "test",
+ Auth: []AuthMethod{Password("testpw")},
+ HostKeyCallback: FixedHostKey(testSigners["rsa"].PublicKey()),
+ HostKeyAlgorithms: []string{KeyAlgoRSA},
+ }
+
+ _, _, _, err = NewClientConn(c2, "", clientConf)
+ if err == nil {
+ t.Fatal("succeeded connecting with no common hostkey algorithm")
+ }
+}
+
+func TestPickIncompatibleHostKeyAlgo(t *testing.T) {
+ algorithmSigner, ok := testSigners["rsa"].(AlgorithmSigner)
+ if !ok {
+ t.Fatal("rsa test signer does not implement the AlgorithmSigner interface")
+ }
+ multiAlgoSigner, err := NewSignerWithAlgorithms(algorithmSigner, []string{KeyAlgoRSASHA256, KeyAlgoRSASHA512})
+ if err != nil {
+ t.Fatalf("unable to create multi algorithm signer: %v", err)
+ }
+ signer := pickHostKey([]Signer{multiAlgoSigner}, KeyAlgoRSA)
+ if signer != nil {
+ t.Fatal("incompatible signer returned")
+ }
+}