-
Notifications
You must be signed in to change notification settings - Fork 15
/
ssh.go
114 lines (101 loc) · 2.3 KB
/
ssh.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package terminal
import (
_ "net/http/pprof"
"os"
"strings"
"golang.org/x/crypto/ssh"
)
// SupportedCiphers xx
var SupportedCiphers = GetSupportedCiphers()
var SupportedKeyExchanges = GetKeyExchanges()
// GetSupportedCiphers xx
func GetSupportedCiphers() []string {
config := &ssh.ClientConfig{}
config.SetDefaults()
for _, cipher := range []string{
"aes128-cbc",
"aes128-ctr",
"aes192-ctr",
"aes256-ctr",
"arcfour256",
"arcfour128",
"arcfour",
"3des-cbc",
} {
found := false
for _, defaultCipher := range config.Ciphers {
if cipher == defaultCipher {
found = true
break
}
}
if !found {
config.Ciphers = append(config.Ciphers, cipher)
}
}
return config.Ciphers
}
func GetKeyExchanges() []string {
config := &ssh.ClientConfig{}
config.SetDefaults()
for _, keyAlg := range []string{
"diffie-hellman-group1-sha1",
"diffie-hellman-group14-sha1",
"ecdh-sha2-nistp256",
"ecdh-sha2-nistp384",
"ecdh-sha2-nistp521",
"diffie-hellman-group-exchange-sha1",
"diffie-hellman-group-exchange-sha256",
} {
found := false
for _, defaultKeyAlg := range config.KeyExchanges {
if keyAlg == defaultKeyAlg {
found = true
break
}
}
if !found {
config.KeyExchanges = append(config.KeyExchanges, keyAlg)
}
}
return config.KeyExchanges
}
func init() {
value := os.Getenv("ssh_key_exchanges")
// if value == "" {
// value = "diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,[email protected]"
// }
if value != "" {
SupportedKeyExchanges = GetKeyExchanges()
ss := strings.Split(value, ",")
var newKeyExchanges []string
for _, s := range ss {
found := false
for _, key := range SupportedKeyExchanges {
if s == key {
found = true
break
}
}
if found {
newKeyExchanges = append(newKeyExchanges, s)
}
}
for _, s := range SupportedKeyExchanges {
found := false
for _, key := range newKeyExchanges {
if s == key {
found = true
break
}
}
if !found {
newKeyExchanges = append(newKeyExchanges, s)
}
}
SupportedKeyExchanges = newKeyExchanges
}
}