-
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: ignore invalid MACs and KEXs just like we do for ciphers
Tighter validation could cause backwards incompatibility issues, eg configurations with valid and invalid MACs, KEXs, ciphers currently work if a supported algorithm is negotiated and that's also the scenario of removing support for an existing algorithm. Fixes golang/go#39397 Change-Id: If90253ba89e1d8f732cc1e1c3d24fe0a1e2dac71 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/512175 Run-TryBot: Han-Wen Nienhuys <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Han-Wen Nienhuys <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]> Reviewed-by: David Chase <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
Showing
2 changed files
with
113 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,3 +254,93 @@ func TestNewClientConn(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func TestUnsupportedAlgorithm(t *testing.T) { | ||
for _, tt := range []struct { | ||
name string | ||
config Config | ||
wantError string | ||
}{ | ||
{ | ||
"unsupported KEX", | ||
Config{ | ||
KeyExchanges: []string{"unsupported"}, | ||
}, | ||
"no common algorithm", | ||
}, | ||
{ | ||
"unsupported and supported KEXs", | ||
Config{ | ||
KeyExchanges: []string{"unsupported", kexAlgoCurve25519SHA256}, | ||
}, | ||
"", | ||
}, | ||
{ | ||
"unsupported cipher", | ||
Config{ | ||
Ciphers: []string{"unsupported"}, | ||
}, | ||
"no common algorithm", | ||
}, | ||
{ | ||
"unsupported and supported ciphers", | ||
Config{ | ||
Ciphers: []string{"unsupported", chacha20Poly1305ID}, | ||
}, | ||
"", | ||
}, | ||
{ | ||
"unsupported MAC", | ||
Config{ | ||
MACs: []string{"unsupported"}, | ||
// MAC is used for non AAED ciphers. | ||
Ciphers: []string{"aes256-ctr"}, | ||
}, | ||
"no common algorithm", | ||
}, | ||
{ | ||
"unsupported and supported MACs", | ||
Config{ | ||
MACs: []string{"unsupported", "[email protected]"}, | ||
// MAC is used for non AAED ciphers. | ||
Ciphers: []string{"aes256-ctr"}, | ||
}, | ||
"", | ||
}, | ||
} { | ||
t.Run(tt.name, func(t *testing.T) { | ||
c1, c2, err := netPipe() | ||
if err != nil { | ||
t.Fatalf("netPipe: %v", err) | ||
} | ||
defer c1.Close() | ||
defer c2.Close() | ||
|
||
serverConf := &ServerConfig{ | ||
Config: tt.config, | ||
PasswordCallback: func(conn ConnMetadata, password []byte) (*Permissions, error) { | ||
return &Permissions{}, nil | ||
}, | ||
} | ||
serverConf.AddHostKey(testSigners["rsa"]) | ||
go NewServerConn(c1, serverConf) | ||
|
||
clientConf := &ClientConfig{ | ||
User: "testuser", | ||
Config: tt.config, | ||
Auth: []AuthMethod{ | ||
Password("testpw"), | ||
}, | ||
HostKeyCallback: InsecureIgnoreHostKey(), | ||
} | ||
_, _, _, err = NewClientConn(c2, "", clientConf) | ||
if err != nil { | ||
if tt.wantError == "" || !strings.Contains(err.Error(), tt.wantError) { | ||
t.Errorf("%s: got error %q, missing %q", tt.name, err.Error(), tt.wantError) | ||
} | ||
} else if tt.wantError != "" { | ||
t.Errorf("%s: succeeded, but want error string %q", tt.name, tt.wantError) | ||
} | ||
}) | ||
} | ||
} |
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