-
Notifications
You must be signed in to change notification settings - Fork 4
/
ciphersuite.go
200 lines (173 loc) · 3.2 KB
/
ciphersuite.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package scanner
import (
"sort"
"github.com/empijei/cli/lg"
"github.com/empijei/go-sslscan/scanner/tls_dirty"
)
type ProtVersion uint16
//go:generate stringer -type ProtVersion
const (
SSL30 ProtVersion = tls_dirty.VersionSSL30
TLS10 ProtVersion = tls_dirty.VersionTLS10
TLS11 ProtVersion = tls_dirty.VersionTLS11
TLS12 ProtVersion = tls_dirty.VersionTLS12
)
var AllCiphersMap = make(map[uint16]CipherSuite)
var AllCiphers CipherSuites
func init() {
for _, c := range TLS_CipherSuites {
AllCiphersMap[c.ID] = c
}
for _, c := range IANA_CipherSuites {
AllCiphersMap[c.ID] = c
}
AllCiphers = make([]CipherSuite, len(AllCiphersMap))
i := 0
for _, c := range AllCiphersMap {
AllCiphers[i] = c
i++
}
sort.Sort(ByID(AllCiphers))
lg.Infof("Loaded ciphers: %d ciphers available\n", len(AllCiphers))
}
type CipherSuite struct {
ID uint16
Name string
Protocol Protocol
Kx KeyExchange
Au Authentication
Enc Encryption
Bits int
Mac Mac
}
type ByID CipherSuites
func (b ByID) Len() int {
return len(b)
}
func (b ByID) Less(i int, j int) bool {
return b[i].ID < b[j].ID
}
func (b ByID) Swap(i int, j int) {
b[i], b[j] = b[j], b[i]
}
type CipherSuites []CipherSuite
func (cs CipherSuites) IDsMap() CipherSuitesMap {
toret := make(CipherSuitesMap)
for _, c := range cs {
toret[c.ID] = c
}
return toret
}
func (cs CipherSuites) IDs() []uint16 {
toret := make([]uint16, len(cs))
for i, c := range cs {
toret[i] = c.ID
}
return toret
}
type CipherSuitesMap map[uint16]CipherSuite
func (csm CipherSuitesMap) Slice() []uint16 {
var cs []uint16
for c, _ := range csm {
cs = append(cs, c)
}
return cs
}
//The following definitions are enums to classify ciphers
type Protocol int
//go:generate stringer -type=Protocol
const (
PROT_SSL Protocol = iota
PROT_TLS
)
type KeyExchange int
//go:generate stringer -type=KeyExchange
const (
KX_DH KeyExchange = iota
KX_DHE
KX_ECCPWD
KX_ECDH
KX_ECDHE
KX_FORTEZZA
KX_KRB5
KX_KRB5_EXPORT
KX_NULL
KX_PSK
KX_RSA
KX_RSA_EXPORT
KX_RSA_EXPORT_1024
KX_RSA_FIPS
KX_SRP
KX_VKO_GOST_R_34_10_2001
KX_VKO_GOST_R_34_10_94
)
type Authentication int
//go:generate stringer -type=Authentication
const (
AU_ANON Authentication = iota
AU_DHE
AU_DSS
AU_ECCPWD
AU_ECDSA
AU_EXPORT
AU_KEA
AU_KRB5
AU_KRB5_EXPORT
AU_NULL
AU_PSK
AU_RSA
AU_RSA_EXPORT
AU_RSA_EXPORT_1024
AU_RSA_FIPS
AU_SHA
AU_VKO_GOST_R_34_10_2001
AU_VKO_GOST_R_34_10_94
)
type Encryption int
//go:generate stringer -type=Encryption
const (
ENC_3DES_EDE_CBC Encryption = iota
ENC_AES_128
ENC_AES_128_CBC
ENC_AES_128_CCM
ENC_AES_128_CCM_8
ENC_AES_128_GCM
ENC_AES_256
ENC_AES_256_CBC
ENC_AES_256_CCM
ENC_AES_256_GCM
ENC_ARIA_128_CBC
ENC_ARIA_128_GCM
ENC_ARIA_256_CBC
ENC_ARIA_256_GCM
ENC_CAMELLIA_128_CBC
ENC_CAMELLIA_128_GCM
ENC_CAMELLIA_256_CBC
ENC_CAMELLIA_256_GCM
ENC_CHACHA20_POLY1305
ENC_CHACHA20_POLY1305_256
ENC_DES40_CBC
ENC_DES_CBC
ENC_DES_CBC_40
ENC_FORTEZZA_CBC
ENC_GOST28147
ENC_IDEA_CBC
ENC_NULL
ENC_RC2_CBC_40
ENC_RC2_CBC_56
ENC_RC4_128
ENC_RC4_40
ENC_RC4_56
ENC_SEED_CBC
)
type Mac int
//go:generate stringer -type=Mac
const (
MAC_GOST28147 Mac = iota
MAC_GOSTR3411
MAC_MD5
MAC_NULL
MAC_SHA
MAC_SHA256
MAC_SHA384
)