1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/base/ssl_cipher_suite_names.h"
6
7 #include <stdlib.h>
8
9 #include "base/logging.h"
10 #include "net/base/ssl_connection_status_flags.h"
11
12 // Rather than storing the names of all the ciphersuites we eliminate the
13 // redundancy and break each cipher suite into a key exchange method, cipher
14 // and mac. For all the ciphersuites in the IANA registry, we extract each of
15 // those components from the name, number them and pack the result into a
16 // 16-bit number thus:
17 // (MSB to LSB)
18 // <4 bits> unused
19 // <5 bits> key exchange
20 // <4 bits> cipher
21 // <3 bits> mac
22
23 // The following tables were generated by ssl_cipher_suite_names_generate.go,
24 // found in the same directory as this file.
25
26 struct CipherSuite {
27 uint16 cipher_suite, encoded;
28 };
29
30 static const struct CipherSuite kCipherSuites[] = {
31 {0x0, 0x0}, // TLS_NULL_WITH_NULL_NULL
32 {0x1, 0x81}, // TLS_RSA_WITH_NULL_MD5
33 {0x2, 0x82}, // TLS_RSA_WITH_NULL_SHA
34 {0x3, 0x109}, // TLS_RSA_EXPORT_WITH_RC4_40_MD5
35 {0x4, 0x91}, // TLS_RSA_WITH_RC4_128_MD5
36 {0x5, 0x92}, // TLS_RSA_WITH_RC4_128_SHA
37 {0x6, 0x119}, // TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5
38 {0x7, 0xa2}, // TLS_RSA_WITH_IDEA_CBC_SHA
39 {0x8, 0x12a}, // TLS_RSA_EXPORT_WITH_DES40_CBC_SHA
40 {0x9, 0xb2}, // TLS_RSA_WITH_DES_CBC_SHA
41 {0xa, 0xba}, // TLS_RSA_WITH_3DES_EDE_CBC_SHA
42 {0xb, 0x1aa}, // TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA
43 {0xc, 0x232}, // TLS_DH_DSS_WITH_DES_CBC_SHA
44 {0xd, 0x23a}, // TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA
45 {0xe, 0x2aa}, // TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA
46 {0xf, 0x332}, // TLS_DH_RSA_WITH_DES_CBC_SHA
47 {0x10, 0x33a}, // TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA
48 {0x11, 0x3aa}, // TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA
49 {0x12, 0x432}, // TLS_DHE_DSS_WITH_DES_CBC_SHA
50 {0x13, 0x43a}, // TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA
51 {0x14, 0x4aa}, // TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA
52 {0x15, 0x532}, // TLS_DHE_RSA_WITH_DES_CBC_SHA
53 {0x16, 0x53a}, // TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA
54 {0x17, 0x589}, // TLS_DH_anon_EXPORT_WITH_RC4_40_MD5
55 {0x18, 0x611}, // TLS_DH_anon_WITH_RC4_128_MD5
56 {0x19, 0x5aa}, // TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA
57 {0x1a, 0x632}, // TLS_DH_anon_WITH_DES_CBC_SHA
58 {0x1b, 0x63a}, // TLS_DH_anon_WITH_3DES_EDE_CBC_SHA
59 {0x1e, 0x6b2}, // TLS_KRB5_WITH_DES_CBC_SHA
60 {0x1f, 0x6ba}, // TLS_KRB5_WITH_3DES_EDE_CBC_SHA
61 {0x20, 0x692}, // TLS_KRB5_WITH_RC4_128_SHA
62 {0x21, 0x6a2}, // TLS_KRB5_WITH_IDEA_CBC_SHA
63 {0x22, 0x6b1}, // TLS_KRB5_WITH_DES_CBC_MD5
64 {0x23, 0x6b9}, // TLS_KRB5_WITH_3DES_EDE_CBC_MD5
65 {0x24, 0x691}, // TLS_KRB5_WITH_RC4_128_MD5
66 {0x25, 0x6a1}, // TLS_KRB5_WITH_IDEA_CBC_MD5
67 {0x26, 0x742}, // TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA
68 {0x27, 0x71a}, // TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA
69 {0x28, 0x70a}, // TLS_KRB5_EXPORT_WITH_RC4_40_SHA
70 {0x29, 0x741}, // TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5
71 {0x2a, 0x719}, // TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5
72 {0x2b, 0x709}, // TLS_KRB5_EXPORT_WITH_RC4_40_MD5
73 {0x2c, 0x782}, // TLS_PSK_WITH_NULL_SHA
74 {0x2d, 0x802}, // TLS_DHE_PSK_WITH_NULL_SHA
75 {0x2e, 0x882}, // TLS_RSA_PSK_WITH_NULL_SHA
76 {0x2f, 0xca}, // TLS_RSA_WITH_AES_128_CBC_SHA
77 {0x30, 0x24a}, // TLS_DH_DSS_WITH_AES_128_CBC_SHA
78 {0x31, 0x34a}, // TLS_DH_RSA_WITH_AES_128_CBC_SHA
79 {0x32, 0x44a}, // TLS_DHE_DSS_WITH_AES_128_CBC_SHA
80 {0x33, 0x54a}, // TLS_DHE_RSA_WITH_AES_128_CBC_SHA
81 {0x34, 0x64a}, // TLS_DH_anon_WITH_AES_128_CBC_SHA
82 {0x35, 0xd2}, // TLS_RSA_WITH_AES_256_CBC_SHA
83 {0x36, 0x252}, // TLS_DH_DSS_WITH_AES_256_CBC_SHA
84 {0x37, 0x352}, // TLS_DH_RSA_WITH_AES_256_CBC_SHA
85 {0x38, 0x452}, // TLS_DHE_DSS_WITH_AES_256_CBC_SHA
86 {0x39, 0x552}, // TLS_DHE_RSA_WITH_AES_256_CBC_SHA
87 {0x3a, 0x652}, // TLS_DH_anon_WITH_AES_256_CBC_SHA
88 {0x3b, 0x83}, // TLS_RSA_WITH_NULL_SHA256
89 {0x3c, 0xcb}, // TLS_RSA_WITH_AES_128_CBC_SHA256
90 {0x3d, 0xd3}, // TLS_RSA_WITH_AES_256_CBC_SHA256
91 {0x3e, 0x24b}, // TLS_DH_DSS_WITH_AES_128_CBC_SHA256
92 {0x3f, 0x34b}, // TLS_DH_RSA_WITH_AES_128_CBC_SHA256
93 {0x40, 0x44b}, // TLS_DHE_DSS_WITH_AES_128_CBC_SHA256
94 {0x41, 0xda}, // TLS_RSA_WITH_CAMELLIA_128_CBC_SHA
95 {0x42, 0x25a}, // TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA
96 {0x43, 0x35a}, // TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA
97 {0x44, 0x45a}, // TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA
98 {0x45, 0x55a}, // TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA
99 {0x46, 0x65a}, // TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA
100 {0x67, 0x54b}, // TLS_DHE_RSA_WITH_AES_128_CBC_SHA256
101 {0x68, 0x253}, // TLS_DH_DSS_WITH_AES_256_CBC_SHA256
102 {0x69, 0x353}, // TLS_DH_RSA_WITH_AES_256_CBC_SHA256
103 {0x6a, 0x453}, // TLS_DHE_DSS_WITH_AES_256_CBC_SHA256
104 {0x6b, 0x553}, // TLS_DHE_RSA_WITH_AES_256_CBC_SHA256
105 {0x6c, 0x64b}, // TLS_DH_anon_WITH_AES_128_CBC_SHA256
106 {0x6d, 0x653}, // TLS_DH_anon_WITH_AES_256_CBC_SHA256
107 {0x84, 0xe2}, // TLS_RSA_WITH_CAMELLIA_256_CBC_SHA
108 {0x85, 0x262}, // TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA
109 {0x86, 0x362}, // TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA
110 {0x87, 0x462}, // TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA
111 {0x88, 0x562}, // TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA
112 {0x89, 0x662}, // TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA
113 {0x8a, 0x792}, // TLS_PSK_WITH_RC4_128_SHA
114 {0x8b, 0x7ba}, // TLS_PSK_WITH_3DES_EDE_CBC_SHA
115 {0x8c, 0x7ca}, // TLS_PSK_WITH_AES_128_CBC_SHA
116 {0x8d, 0x7d2}, // TLS_PSK_WITH_AES_256_CBC_SHA
117 {0x8e, 0x812}, // TLS_DHE_PSK_WITH_RC4_128_SHA
118 {0x8f, 0x83a}, // TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA
119 {0x90, 0x84a}, // TLS_DHE_PSK_WITH_AES_128_CBC_SHA
120 {0x91, 0x852}, // TLS_DHE_PSK_WITH_AES_256_CBC_SHA
121 {0x92, 0x892}, // TLS_RSA_PSK_WITH_RC4_128_SHA
122 {0x93, 0x8ba}, // TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA
123 {0x94, 0x8ca}, // TLS_RSA_PSK_WITH_AES_128_CBC_SHA
124 {0x95, 0x8d2}, // TLS_RSA_PSK_WITH_AES_256_CBC_SHA
125 {0x96, 0xea}, // TLS_RSA_WITH_SEED_CBC_SHA
126 {0x97, 0x26a}, // TLS_DH_DSS_WITH_SEED_CBC_SHA
127 {0x98, 0x36a}, // TLS_DH_RSA_WITH_SEED_CBC_SHA
128 {0x99, 0x46a}, // TLS_DHE_DSS_WITH_SEED_CBC_SHA
129 {0x9a, 0x56a}, // TLS_DHE_RSA_WITH_SEED_CBC_SHA
130 {0x9b, 0x66a}, // TLS_DH_anon_WITH_SEED_CBC_SHA
131 {0x9c, 0xf3}, // TLS_RSA_WITH_AES_128_GCM_SHA256
132 {0x9d, 0xfc}, // TLS_RSA_WITH_AES_256_GCM_SHA384
133 {0x9e, 0x573}, // TLS_DHE_RSA_WITH_AES_128_GCM_SHA256
134 {0x9f, 0x57c}, // TLS_DHE_RSA_WITH_AES_256_GCM_SHA384
135 {0xa0, 0x373}, // TLS_DH_RSA_WITH_AES_128_GCM_SHA256
136 {0xa1, 0x37c}, // TLS_DH_RSA_WITH_AES_256_GCM_SHA384
137 {0xa2, 0x473}, // TLS_DHE_DSS_WITH_AES_128_GCM_SHA256
138 {0xa3, 0x47c}, // TLS_DHE_DSS_WITH_AES_256_GCM_SHA384
139 {0xa4, 0x273}, // TLS_DH_DSS_WITH_AES_128_GCM_SHA256
140 {0xa5, 0x27c}, // TLS_DH_DSS_WITH_AES_256_GCM_SHA384
141 {0xa6, 0x673}, // TLS_DH_anon_WITH_AES_128_GCM_SHA256
142 {0xa7, 0x67c}, // TLS_DH_anon_WITH_AES_256_GCM_SHA384
143 {0xa8, 0x7f3}, // TLS_PSK_WITH_AES_128_GCM_SHA256
144 {0xa9, 0x7fc}, // TLS_PSK_WITH_AES_256_GCM_SHA384
145 {0xaa, 0x873}, // TLS_DHE_PSK_WITH_AES_128_GCM_SHA256
146 {0xab, 0x87c}, // TLS_DHE_PSK_WITH_AES_256_GCM_SHA384
147 {0xac, 0x8f3}, // TLS_RSA_PSK_WITH_AES_128_GCM_SHA256
148 {0xad, 0x8fc}, // TLS_RSA_PSK_WITH_AES_256_GCM_SHA384
149 {0xae, 0x7cb}, // TLS_PSK_WITH_AES_128_CBC_SHA256
150 {0xaf, 0x7d4}, // TLS_PSK_WITH_AES_256_CBC_SHA384
151 {0xb0, 0x783}, // TLS_PSK_WITH_NULL_SHA256
152 {0xb1, 0x784}, // TLS_PSK_WITH_NULL_SHA384
153 {0xb2, 0x84b}, // TLS_DHE_PSK_WITH_AES_128_CBC_SHA256
154 {0xb3, 0x854}, // TLS_DHE_PSK_WITH_AES_256_CBC_SHA384
155 {0xb4, 0x803}, // TLS_DHE_PSK_WITH_NULL_SHA256
156 {0xb5, 0x804}, // TLS_DHE_PSK_WITH_NULL_SHA384
157 {0xb6, 0x8cb}, // TLS_RSA_PSK_WITH_AES_128_CBC_SHA256
158 {0xb7, 0x8d4}, // TLS_RSA_PSK_WITH_AES_256_CBC_SHA384
159 {0xb8, 0x883}, // TLS_RSA_PSK_WITH_NULL_SHA256
160 {0xb9, 0x884}, // TLS_RSA_PSK_WITH_NULL_SHA384
161 {0xba, 0xdb}, // TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256
162 {0xbb, 0x25b}, // TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256
163 {0xbc, 0x35b}, // TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256
164 {0xbd, 0x45b}, // TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256
165 {0xbe, 0x55b}, // TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256
166 {0xbf, 0x65b}, // TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256
167 {0xc0, 0xe3}, // TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256
168 {0xc1, 0x263}, // TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256
169 {0xc2, 0x363}, // TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256
170 {0xc3, 0x463}, // TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256
171 {0xc4, 0x563}, // TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256
172 {0xc5, 0x663}, // TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256
173 {0xc001, 0x902}, // TLS_ECDH_ECDSA_WITH_NULL_SHA
174 {0xc002, 0x912}, // TLS_ECDH_ECDSA_WITH_RC4_128_SHA
175 {0xc003, 0x93a}, // TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA
176 {0xc004, 0x94a}, // TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA
177 {0xc005, 0x952}, // TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA
178 {0xc006, 0x982}, // TLS_ECDHE_ECDSA_WITH_NULL_SHA
179 {0xc007, 0x992}, // TLS_ECDHE_ECDSA_WITH_RC4_128_SHA
180 {0xc008, 0x9ba}, // TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA
181 {0xc009, 0x9ca}, // TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
182 {0xc00a, 0x9d2}, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
183 {0xc00b, 0xa02}, // TLS_ECDH_RSA_WITH_NULL_SHA
184 {0xc00c, 0xa12}, // TLS_ECDH_RSA_WITH_RC4_128_SHA
185 {0xc00d, 0xa3a}, // TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA
186 {0xc00e, 0xa4a}, // TLS_ECDH_RSA_WITH_AES_128_CBC_SHA
187 {0xc00f, 0xa52}, // TLS_ECDH_RSA_WITH_AES_256_CBC_SHA
188 {0xc010, 0xa82}, // TLS_ECDHE_RSA_WITH_NULL_SHA
189 {0xc011, 0xa92}, // TLS_ECDHE_RSA_WITH_RC4_128_SHA
190 {0xc012, 0xaba}, // TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
191 {0xc013, 0xaca}, // TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
192 {0xc014, 0xad2}, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
193 {0xc015, 0xb02}, // TLS_ECDH_anon_WITH_NULL_SHA
194 {0xc016, 0xb12}, // TLS_ECDH_anon_WITH_RC4_128_SHA
195 {0xc017, 0xb3a}, // TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA
196 {0xc018, 0xb4a}, // TLS_ECDH_anon_WITH_AES_128_CBC_SHA
197 {0xc019, 0xb52}, // TLS_ECDH_anon_WITH_AES_256_CBC_SHA
198 {0xc01a, 0xbba}, // TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA
199 {0xc01b, 0xc3a}, // TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA
200 {0xc01c, 0xcba}, // TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA
201 {0xc01d, 0xbca}, // TLS_SRP_SHA_WITH_AES_128_CBC_SHA
202 {0xc01e, 0xc4a}, // TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA
203 {0xc01f, 0xcca}, // TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA
204 {0xc020, 0xbd2}, // TLS_SRP_SHA_WITH_AES_256_CBC_SHA
205 {0xc021, 0xc52}, // TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA
206 {0xc022, 0xcd2}, // TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA
207 {0xc023, 0x9cb}, // TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
208 {0xc024, 0x9d4}, // TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384
209 {0xc025, 0x94b}, // TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256
210 {0xc026, 0x954}, // TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384
211 {0xc027, 0xacb}, // TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
212 {0xc028, 0xad4}, // TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384
213 {0xc029, 0xa4b}, // TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256
214 {0xc02a, 0xa54}, // TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384
215 {0xc02b, 0x9f3}, // TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
216 {0xc02c, 0x9fc}, // TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
217 {0xc02d, 0x973}, // TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256
218 {0xc02e, 0x97c}, // TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384
219 {0xc02f, 0xaf3}, // TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
220 {0xc030, 0xafc}, // TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
221 {0xc031, 0xa73}, // TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256
222 {0xc032, 0xa7c}, // TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384
223 {0xc033, 0xd12}, // TLS_ECDHE_PSK_WITH_RC4_128_SHA
224 {0xc034, 0xd3a}, // TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA
225 {0xc035, 0xd4a}, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA
226 {0xc036, 0xd52}, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA
227 {0xc037, 0xd4b}, // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256
228 {0xc038, 0xd54}, // TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384
229 {0xc039, 0xd02}, // TLS_ECDHE_PSK_WITH_NULL_SHA
230 {0xc03a, 0xd03}, // TLS_ECDHE_PSK_WITH_NULL_SHA256
231 {0xc03b, 0xd04}, // TLS_ECDHE_PSK_WITH_NULL_SHA384
232 };
233
234 static const struct {
235 char name[15];
236 } kKeyExchangeNames[27] = {
237 {"NULL"}, // 0
238 {"RSA"}, // 1
239 {"RSA_EXPORT"}, // 2
240 {"DH_DSS_EXPORT"}, // 3
241 {"DH_DSS"}, // 4
242 {"DH_RSA_EXPORT"}, // 5
243 {"DH_RSA"}, // 6
244 {"DHE_DSS_EXPORT"}, // 7
245 {"DHE_DSS"}, // 8
246 {"DHE_RSA_EXPORT"}, // 9
247 {"DHE_RSA"}, // 10
248 {"DH_anon_EXPORT"}, // 11
249 {"DH_anon"}, // 12
250 {"KRB5"}, // 13
251 {"KRB5_EXPORT"}, // 14
252 {"PSK"}, // 15
253 {"DHE_PSK"}, // 16
254 {"RSA_PSK"}, // 17
255 {"ECDH_ECDSA"}, // 18
256 {"ECDHE_ECDSA"}, // 19
257 {"ECDH_RSA"}, // 20
258 {"ECDHE_RSA"}, // 21
259 {"ECDH_anon"}, // 22
260 {"SRP_SHA"}, // 23
261 {"SRP_SHA_RSA"}, // 24
262 {"SRP_SHA_DSS"}, // 25
263 {"ECDHE_PSK"}, // 26
264 };
265
266 static const struct {
267 char name[17];
268 } kCipherNames[16] = {
269 {"NULL"}, // 0
270 {"RC4_40"}, // 1
271 {"RC4_128"}, // 2
272 {"RC2_CBC_40"}, // 3
273 {"IDEA_CBC"}, // 4
274 {"DES40_CBC"}, // 5
275 {"DES_CBC"}, // 6
276 {"3DES_EDE_CBC"}, // 7
277 {"DES_CBC_40"}, // 8
278 {"AES_128_CBC"}, // 9
279 {"AES_256_CBC"}, // 10
280 {"CAMELLIA_128_CBC"}, // 11
281 {"CAMELLIA_256_CBC"}, // 12
282 {"SEED_CBC"}, // 13
283 {"AES_128_GCM"}, // 14
284 {"AES_256_GCM"}, // 15
285 };
286
287 static const struct {
288 char name[7];
289 } kMacNames[5] = {
290 {"NULL"}, // 0
291 {"MD5"}, // 1
292 {"SHA1"}, // 2
293 {"SHA256"}, // 3
294 {"SHA384"}, // 4
295 };
296
297
298 namespace net {
299
CipherSuiteCmp(const void * ia,const void * ib)300 static int CipherSuiteCmp(const void* ia, const void* ib) {
301 const CipherSuite* a = static_cast<const CipherSuite*>(ia);
302 const CipherSuite* b = static_cast<const CipherSuite*>(ib);
303
304 if (a->cipher_suite < b->cipher_suite) {
305 return -1;
306 } else if (a->cipher_suite == b->cipher_suite) {
307 return 0;
308 } else {
309 return 1;
310 }
311 }
312
SSLCipherSuiteToStrings(const char ** key_exchange_str,const char ** cipher_str,const char ** mac_str,uint16 cipher_suite)313 void SSLCipherSuiteToStrings(const char** key_exchange_str,
314 const char** cipher_str,
315 const char** mac_str, uint16 cipher_suite) {
316 *key_exchange_str = *cipher_str = *mac_str = "???";
317
318 struct CipherSuite desired = {0};
319 desired.cipher_suite = cipher_suite;
320
321 void* r = bsearch(&desired, kCipherSuites,
322 arraysize(kCipherSuites), sizeof(kCipherSuites[0]),
323 CipherSuiteCmp);
324
325 if (!r)
326 return;
327
328 const CipherSuite* cs = static_cast<CipherSuite*>(r);
329
330 const int key_exchange = cs->encoded >> 7;
331 const int cipher = (cs->encoded >> 3) & 0xf;
332 const int mac = cs->encoded & 0x7;
333
334 *key_exchange_str = kKeyExchangeNames[key_exchange].name;
335 *cipher_str = kCipherNames[cipher].name;
336 *mac_str = kMacNames[mac].name;
337 }
338
SSLCompressionToString(const char ** name,uint8 compresssion)339 void SSLCompressionToString(const char** name, uint8 compresssion) {
340 if (compresssion == 0) {
341 *name = "NONE";
342 } else if (compresssion == 1) {
343 *name = "DEFLATE";
344 } else if (compresssion == 64) {
345 *name = "LZS";
346 } else {
347 *name = "???";
348 }
349 }
350
SSLVersionToString(const char ** name,int ssl_version)351 void SSLVersionToString(const char** name, int ssl_version) {
352 switch (ssl_version) {
353 case SSL_CONNECTION_VERSION_SSL2:
354 *name = "SSL 2.0";
355 break;
356 case SSL_CONNECTION_VERSION_SSL3:
357 *name = "SSL 3.0";
358 break;
359 case SSL_CONNECTION_VERSION_TLS1:
360 *name = "TLS 1.0";
361 break;
362 case SSL_CONNECTION_VERSION_TLS1_1:
363 *name = "TLS 1.1";
364 break;
365 case SSL_CONNECTION_VERSION_TLS1_2:
366 *name = "TLS 1.2";
367 break;
368 default:
369 NOTREACHED() << ssl_version;
370 *name = "???";
371 break;
372 }
373 }
374
375 } // namespace net
376