ssh: expose negotiated algorithms
Fixes golang/go#58523 Fixes golang/go#46638 Change-Id: Ic64bd2fdd6e9ec96acac3ed4be842e2fbb15231d Reviewed-on: https://go-review.googlesource.com/c/crypto/+/538235 Reviewed-by: Filippo Valsorda <filippo@golang.org> Auto-Submit: Nicola Murino <nicola.murino@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
committed by
Gopher Robot
parent
78a1fd7893
commit
e944286e33
+57
-2
@@ -367,7 +367,7 @@ type errorKeyingTransport struct {
|
||||
readLeft, writeLeft int
|
||||
}
|
||||
|
||||
func (n *errorKeyingTransport) prepareKeyChange(*algorithms, *kexResult) error {
|
||||
func (n *errorKeyingTransport) prepareKeyChange(*NegotiatedAlgorithms, *kexResult) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -545,7 +545,7 @@ type mockKeyingTransport struct {
|
||||
kexInitSent chan struct{}
|
||||
}
|
||||
|
||||
func (n *mockKeyingTransport) prepareKeyChange(*algorithms, *kexResult) error {
|
||||
func (n *mockKeyingTransport) prepareKeyChange(*NegotiatedAlgorithms, *kexResult) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1239,3 +1239,58 @@ func TestStrictKEXMixed(t *testing.T) {
|
||||
t.Fatalf("client.waitSession: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNegotiatedAlgorithms(t *testing.T) {
|
||||
c1, c2, err := netPipe()
|
||||
if err != nil {
|
||||
t.Fatalf("netPipe: %v", err)
|
||||
}
|
||||
defer c1.Close()
|
||||
defer c2.Close()
|
||||
|
||||
var serverAlgorithms NegotiatedAlgorithms
|
||||
|
||||
serverConf := &ServerConfig{
|
||||
PasswordCallback: func(conn ConnMetadata, password []byte) (*Permissions, error) {
|
||||
if algorithmConn, ok := conn.(AlgorithmsConnMetadata); ok {
|
||||
serverAlgorithms = algorithmConn.Algorithms()
|
||||
return &Permissions{}, nil
|
||||
}
|
||||
return nil, errors.New("server conn does not implement AlgorithmsConnMetadata")
|
||||
},
|
||||
}
|
||||
serverConf.AddHostKey(testSigners["rsa"])
|
||||
go NewServerConn(c1, serverConf)
|
||||
|
||||
clientConf := &ClientConfig{
|
||||
User: "test",
|
||||
Auth: []AuthMethod{Password("testpw")},
|
||||
HostKeyCallback: FixedHostKey(testSigners["rsa"].PublicKey()),
|
||||
}
|
||||
|
||||
if conn, _, _, err := NewClientConn(c2, "", clientConf); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if algorithmConn, ok := conn.(AlgorithmsConnMetadata); ok {
|
||||
clientAlgorithms := algorithmConn.Algorithms()
|
||||
if clientAlgorithms.HostKey == "" {
|
||||
t.Fatal("negotiated client host key is empty")
|
||||
}
|
||||
if clientAlgorithms.KeyExchange == "" {
|
||||
t.Fatal("negotiated client KEX is empty")
|
||||
}
|
||||
if clientAlgorithms.Read.Cipher == "" {
|
||||
t.Fatal("negotiated client read cipher is empty")
|
||||
}
|
||||
if clientAlgorithms.Write.Cipher == "" {
|
||||
t.Fatal("negotiated client write cipher is empty")
|
||||
}
|
||||
if !reflect.DeepEqual(clientAlgorithms, serverAlgorithms) {
|
||||
t.Fatalf("negotiated client algorithms: %+v differs from negotiated server algorithms: %+v",
|
||||
clientAlgorithms, serverAlgorithms)
|
||||
}
|
||||
} else {
|
||||
t.Fatal("client conn does not implement AlgorithmsConnMetadata")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user