go.crypto/ssh: implement ECDH.
Implement elliptic-curve Diffie-Hellman, including host key signature verification. Moves host key cryptographic verification to ClientConn.handshake(), so RSA host keys are also verified. Fixes golang/go#6158. R=dave, agl CC=golang-dev https://golang.org/cl/13021045
This commit is contained in:
committed by
Adam Langley
parent
b725ff72eb
commit
d7d50b0a7c
@@ -0,0 +1,90 @@
|
||||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package ssh
|
||||
|
||||
// Key exchange tests.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func pipe() (net.Conn, net.Conn, error) {
|
||||
l, err := net.Listen("tcp", ":0")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
conn1, err := net.Dial("tcp", l.Addr().String())
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
conn2, err := l.Accept()
|
||||
if err != nil {
|
||||
conn1.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
l.Close()
|
||||
return conn1, conn2, nil
|
||||
}
|
||||
|
||||
func testKexAlgorithm(algo string) error {
|
||||
crypto := CryptoConfig{
|
||||
KeyExchanges: []string{algo},
|
||||
}
|
||||
serverConfig := ServerConfig{
|
||||
PasswordCallback: func(conn *ServerConn, user, password string) bool {
|
||||
return password == "password"
|
||||
},
|
||||
Crypto: crypto,
|
||||
}
|
||||
|
||||
if err := serverConfig.SetRSAPrivateKey([]byte(testServerPrivateKey)); err != nil {
|
||||
return fmt.Errorf("SetRSAPrivateKey: %v", err)
|
||||
}
|
||||
|
||||
clientConfig := ClientConfig{
|
||||
User: "user",
|
||||
Auth: []ClientAuth{ClientAuthPassword(password("password"))},
|
||||
Crypto: crypto,
|
||||
}
|
||||
|
||||
conn1, conn2, err := pipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer conn1.Close()
|
||||
defer conn2.Close()
|
||||
|
||||
server := Server(conn2, &serverConfig)
|
||||
serverHS := make(chan error, 1)
|
||||
go func() {
|
||||
serverHS <- server.Handshake()
|
||||
}()
|
||||
|
||||
// Client runs the handshake.
|
||||
_, err = Client(conn1, &clientConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Client: %v", err)
|
||||
}
|
||||
|
||||
if err := <-serverHS; err != nil {
|
||||
return fmt.Errorf("server.Handshake: %v", err)
|
||||
}
|
||||
|
||||
// Here we could check that we now can send data between client &
|
||||
// server.
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestKexAlgorithms(t *testing.T) {
|
||||
for _, algo := range []string{kexAlgoECDH256, kexAlgoECDH384, kexAlgoECDH521, kexAlgoDH1SHA1, kexAlgoDH14SHA1} {
|
||||
if err := testKexAlgorithm(algo); err != nil {
|
||||
t.Errorf("algorithm %s: %v", algo, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user