2 * ssl manipulation functions
3 * By Paolo Abeni <paolo.abeni@email.com>
5 * Copyright (c) 2013, Hauke Mehrtens <hauke@hauke-m.de>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
34 #include "packet-ssl-utils.h"
35 #include "packet-ssl.h"
37 #include <epan/emem.h>
38 #include <epan/strutil.h>
39 #include <epan/addr_resolv.h>
40 #include <epan/ipv6-utils.h>
41 #include <epan/expert.h>
42 #include <epan/asn1.h>
43 #include <epan/dissectors/packet-x509af.h>
44 #include "packet-x509if.h"
45 #include <wsutil/file_util.h>
46 #include <wsutil/str_util.h>
51 const value_string ssl_version_short_names[] = {
52 { SSL_VER_UNKNOWN, "SSL" },
53 { SSL_VER_SSLv2, "SSLv2" },
54 { SSL_VER_SSLv3, "SSLv3" },
55 { SSL_VER_TLS, "TLSv1" },
56 { SSL_VER_TLSv1DOT1, "TLSv1.1" },
57 { SSL_VER_DTLS, "DTLSv1.0" },
58 { SSL_VER_DTLS1DOT2, "DTLSv1.2" },
59 { SSL_VER_DTLS_OPENSSL, "DTLS 1.0 (OpenSSL pre 0.9.8f)" },
60 { SSL_VER_PCT, "PCT" },
61 { SSL_VER_TLSv1DOT2, "TLSv1.2" },
65 const value_string ssl_20_msg_types[] = {
66 { SSL2_HND_ERROR, "Error" },
67 { SSL2_HND_CLIENT_HELLO, "Client Hello" },
68 { SSL2_HND_CLIENT_MASTER_KEY, "Client Master Key" },
69 { SSL2_HND_CLIENT_FINISHED, "Client Finished" },
70 { SSL2_HND_SERVER_HELLO, "Server Hello" },
71 { SSL2_HND_SERVER_VERIFY, "Server Verify" },
72 { SSL2_HND_SERVER_FINISHED, "Server Finished" },
73 { SSL2_HND_REQUEST_CERTIFICATE, "Request Certificate" },
74 { SSL2_HND_CLIENT_CERTIFICATE, "Client Certificate" },
77 /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
78 /* Note: sorted by ascending value so value_string-ext can do a binary search */
79 static const value_string ssl_20_cipher_suites[] = {
80 { 0x000000, "TLS_NULL_WITH_NULL_NULL" },
81 { 0x000001, "TLS_RSA_WITH_NULL_MD5" },
82 { 0x000002, "TLS_RSA_WITH_NULL_SHA" },
83 { 0x000003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" },
84 { 0x000004, "TLS_RSA_WITH_RC4_128_MD5" },
85 { 0x000005, "TLS_RSA_WITH_RC4_128_SHA" },
86 { 0x000006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" },
87 { 0x000007, "TLS_RSA_WITH_IDEA_CBC_SHA" },
88 { 0x000008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" },
89 { 0x000009, "TLS_RSA_WITH_DES_CBC_SHA" },
90 { 0x00000a, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" },
91 { 0x00000b, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" },
92 { 0x00000c, "TLS_DH_DSS_WITH_DES_CBC_SHA" },
93 { 0x00000d, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" },
94 { 0x00000e, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" },
95 { 0x00000f, "TLS_DH_RSA_WITH_DES_CBC_SHA" },
96 { 0x000010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" },
97 { 0x000011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" },
98 { 0x000012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" },
99 { 0x000013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" },
100 { 0x000014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" },
101 { 0x000015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" },
102 { 0x000016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" },
103 { 0x000017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" },
104 { 0x000018, "TLS_DH_anon_WITH_RC4_128_MD5" },
105 { 0x000019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" },
106 { 0x00001a, "TLS_DH_anon_WITH_DES_CBC_SHA" },
107 { 0x00001b, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" },
108 { 0x00001c, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" },
109 { 0x00001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
111 { 0x00001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
114 { 0x00001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
115 { 0x00001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" },
116 { 0x000020, "TLS_KRB5_WITH_RC4_128_SHA" },
117 { 0x000021, "TLS_KRB5_WITH_IDEA_CBC_SHA" },
118 { 0x000022, "TLS_KRB5_WITH_DES_CBC_MD5" },
119 { 0x000023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" },
120 { 0x000024, "TLS_KRB5_WITH_RC4_128_MD5" },
121 { 0x000025, "TLS_KRB5_WITH_IDEA_CBC_MD5" },
122 { 0x000026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" },
123 { 0x000027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" },
124 { 0x000028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" },
125 { 0x000029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" },
126 { 0x00002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" },
127 { 0x00002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" },
129 { 0x00002C, "TLS_PSK_WITH_NULL_SHA" },
130 { 0x00002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
131 { 0x00002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
133 { 0x00002f, "TLS_RSA_WITH_AES_128_CBC_SHA" },
134 { 0x000030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
135 { 0x000031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" },
136 { 0x000032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" },
137 { 0x000033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" },
138 { 0x000034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" },
139 { 0x000035, "TLS_RSA_WITH_AES_256_CBC_SHA" },
140 { 0x000036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" },
141 { 0x000037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" },
142 { 0x000038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
143 { 0x000039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
144 { 0x00003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
145 { 0x00003B, "TLS_RSA_WITH_NULL_SHA256" },
146 { 0x00003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" },
147 { 0x00003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" },
148 { 0x00003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" },
149 { 0x00003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" },
150 { 0x000040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" },
151 { 0x000041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" },
152 { 0x000042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" },
153 { 0x000043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" },
154 { 0x000044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" },
155 { 0x000045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" },
156 { 0x000046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" },
157 { 0x000047, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
158 { 0x000048, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
159 { 0x000049, "TLS_ECDH_ECDSA_WITH_DES_CBC_SHA" },
160 { 0x00004A, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
161 { 0x00004B, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
162 { 0x00004C, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
163 { 0x000060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
164 { 0x000061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
165 { 0x000062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" },
166 { 0x000063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" },
167 { 0x000064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" },
168 { 0x000065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" },
169 { 0x000066, "TLS_DHE_DSS_WITH_RC4_128_SHA" },
170 { 0x000067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" },
171 { 0x000068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" },
172 { 0x000069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" },
173 { 0x00006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" },
174 { 0x00006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" },
175 { 0x00006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" },
176 { 0x00006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" },
177 /* 0x00,0x6E-83 Unassigned */
178 { 0x000084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" },
179 { 0x000085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" },
180 { 0x000086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" },
181 { 0x000087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
182 { 0x000088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
183 { 0x000089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
185 { 0x00008A, "TLS_PSK_WITH_RC4_128_SHA" },
186 { 0x00008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
187 { 0x00008C, "TLS_PSK_WITH_AES_128_CBC_SHA" },
188 { 0x00008D, "TLS_PSK_WITH_AES_256_CBC_SHA" },
189 { 0x00008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" },
190 { 0x00008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" },
191 { 0x000090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" },
192 { 0x000091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" },
193 { 0x000092, "TLS_RSA_PSK_WITH_RC4_128_SHA" },
194 { 0x000093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" },
195 { 0x000094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" },
196 { 0x000095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" },
198 { 0x000096, "TLS_RSA_WITH_SEED_CBC_SHA" },
199 { 0x000097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" },
200 { 0x000098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" },
201 { 0x000099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
202 { 0x00009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
203 { 0x00009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
205 { 0x00009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" },
206 { 0x00009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" },
207 { 0x00009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" },
208 { 0x00009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" },
209 { 0x0000A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" },
210 { 0x0000A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" },
211 { 0x0000A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" },
212 { 0x0000A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" },
213 { 0x0000A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" },
214 { 0x0000A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" },
215 { 0x0000A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" },
216 { 0x0000A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" },
218 { 0x0000A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" },
219 { 0x0000A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" },
220 { 0x0000AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" },
221 { 0x0000AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" },
222 { 0x0000AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" },
223 { 0x0000AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" },
224 { 0x0000AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" },
225 { 0x0000AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" },
226 { 0x0000B0, "TLS_PSK_WITH_NULL_SHA256" },
227 { 0x0000B1, "TLS_PSK_WITH_NULL_SHA384" },
228 { 0x0000B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" },
229 { 0x0000B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" },
230 { 0x0000B4, "TLS_DHE_PSK_WITH_NULL_SHA256" },
231 { 0x0000B5, "TLS_DHE_PSK_WITH_NULL_SHA384" },
232 { 0x0000B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" },
233 { 0x0000B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" },
234 { 0x0000B8, "TLS_RSA_PSK_WITH_NULL_SHA256" },
235 { 0x0000B9, "TLS_RSA_PSK_WITH_NULL_SHA384" },
237 { 0x0000BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
238 { 0x0000BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
239 { 0x0000BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
240 { 0x0000BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
241 { 0x0000BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
242 { 0x0000BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" },
243 { 0x0000C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
244 { 0x0000C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
245 { 0x0000C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
246 { 0x0000C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
247 { 0x0000C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
248 { 0x0000C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" },
249 /* 0x00,0xC6-FE Unassigned */
250 { 0x0000FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" },
251 /* 0x01-BF,* Unassigned */
253 { 0x00c001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
254 { 0x00c002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
255 { 0x00c003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
256 { 0x00c004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
257 { 0x00c005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
258 { 0x00c006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" },
259 { 0x00c007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" },
260 { 0x00c008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" },
261 { 0x00c009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
262 { 0x00c00a, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
263 { 0x00c00b, "TLS_ECDH_RSA_WITH_NULL_SHA" },
264 { 0x00c00c, "TLS_ECDH_RSA_WITH_RC4_128_SHA" },
265 { 0x00c00d, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" },
266 { 0x00c00e, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" },
267 { 0x00c00f, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" },
268 { 0x00c010, "TLS_ECDHE_RSA_WITH_NULL_SHA" },
269 { 0x00c011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" },
270 { 0x00c012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" },
271 { 0x00c013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
272 { 0x00c014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
273 { 0x00c015, "TLS_ECDH_anon_WITH_NULL_SHA" },
274 { 0x00c016, "TLS_ECDH_anon_WITH_RC4_128_SHA" },
275 { 0x00c017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" },
276 { 0x00c018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" },
277 { 0x00c019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" },
279 { 0x00C01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" },
280 { 0x00C01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" },
281 { 0x00C01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" },
282 { 0x00C01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" },
283 { 0x00C01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" },
284 { 0x00C01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" },
285 { 0x00C020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
286 { 0x00C021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
287 { 0x00C022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
289 { 0x00C023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" },
290 { 0x00C024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" },
291 { 0x00C025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" },
292 { 0x00C026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" },
293 { 0x00C027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" },
294 { 0x00C028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" },
295 { 0x00C029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" },
296 { 0x00C02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" },
297 { 0x00C02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
298 { 0x00C02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
299 { 0x00C02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" },
300 { 0x00C02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" },
301 { 0x00C02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
302 { 0x00C030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
303 { 0x00C031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" },
304 { 0x00C032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" },
306 { 0x00C033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" },
307 { 0x00C034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" },
308 { 0x00C035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" },
309 { 0x00C036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" },
310 { 0x00C037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" },
311 { 0x00C038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" },
312 { 0x00C039, "TLS_ECDHE_PSK_WITH_NULL_SHA" },
313 { 0x00C03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" },
314 { 0x00C03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" },
315 /* 0xC0,0x3C-FF Unassigned
317 0xFE,0x00-FD Unassigned
318 0xFE,0xFE-FF Reserved to avoid conflicts with widely deployed implementations [Pasi_Eronen]
319 0xFF,0x00-FF Reserved for Private Use [RFC5246]
322 /* http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 */
323 { 0x00CC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
324 { 0x00CC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
325 { 0x00CC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
327 /* http://tools.ietf.org/html/draft-josefsson-salsa20-tls */
328 { 0x00E410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" },
329 { 0x00E411, "TLS_RSA_WITH_SALSA20_SHA1" },
330 { 0x00E412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
331 { 0x00E413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" },
332 { 0x00E414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" },
333 { 0x00E415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" },
334 { 0x00E416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" },
335 { 0x00E417, "TLS_PSK_WITH_SALSA20_SHA1" },
336 { 0x00E418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
337 { 0x00E419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" },
338 { 0x00E41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" },
339 { 0x00E41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" },
340 { 0x00E41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
341 { 0x00E41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" },
342 { 0x00E41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
343 { 0x00E41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" },
345 /* these from http://www.mozilla.org/projects/
346 security/pki/nss/ssl/fips-ssl-ciphersuites.html */
347 { 0x00fefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
348 { 0x00feff, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
349 { 0x00ffe0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
350 { 0x00ffe1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
351 /* note that ciphersuites of {0x00????} are TLS cipher suites in
352 * a sslv2 client hello message; the ???? above is the two-byte
353 * tls cipher suite id
356 { 0x010080, "SSL2_RC4_128_WITH_MD5" },
357 { 0x020080, "SSL2_RC4_128_EXPORT40_WITH_MD5" },
358 { 0x030080, "SSL2_RC2_CBC_128_CBC_WITH_MD5" },
359 { 0x040080, "SSL2_RC2_CBC_128_CBC_WITH_MD5" },
360 { 0x050080, "SSL2_IDEA_128_CBC_WITH_MD5" },
361 { 0x060040, "SSL2_DES_64_CBC_WITH_MD5" },
362 { 0x0700c0, "SSL2_DES_192_EDE3_CBC_WITH_MD5" },
363 { 0x080080, "SSL2_RC4_64_WITH_MD5" },
365 /* Microsoft's old PCT protocol. These are from Eric Rescorla's
366 book "SSL and TLS" */
367 { 0x800001, "PCT_SSL_CERT_TYPE | PCT1_CERT_X509" },
368 { 0x800003, "PCT_SSL_CERT_TYPE | PCT1_CERT_X509_CHAIN" },
369 { 0x810001, "PCT_SSL_HASH_TYPE | PCT1_HASH_MD5" },
370 { 0x810003, "PCT_SSL_HASH_TYPE | PCT1_HASH_SHA" },
371 { 0x820001, "PCT_SSL_EXCH_TYPE | PCT1_EXCH_RSA_PKCS1" },
372 { 0x830004, "PCT_SSL_CIPHER_TYPE_1ST_HALF | PCT1_CIPHER_RC4" },
373 { 0x842840, "PCT_SSL_CIPHER_TYPE_2ND_HALF | PCT1_ENC_BITS_40 | PCT1_MAC_BITS_128" },
374 { 0x848040, "PCT_SSL_CIPHER_TYPE_2ND_HALF | PCT1_ENC_BITS_128 | PCT1_MAC_BITS_128" },
375 { 0x8f8001, "PCT_SSL_COMPAT | PCT_VERSION_1" },
379 value_string_ext ssl_20_cipher_suites_ext = VALUE_STRING_EXT_INIT(ssl_20_cipher_suites);
382 const value_string ssl_extension_curves[] = {
408 { 26, "brainpoolP256r1" }, /* RFC 7027 */
409 { 27, "brainpoolP384r1" }, /* RFC 7027 */
410 { 28, "brainpoolP512r1" }, /* RFC 7027 */
411 { 0xFF01, "arbitrary_explicit_prime_curves" },
412 { 0xFF02, "arbitrary_explicit_char2_curves" },
416 const value_string ssl_curve_types[] = {
417 { 1, "explicit_prime" },
418 { 2, "explicit_char2" },
419 { 3, "named_curve" },
423 const value_string ssl_extension_ec_point_formats[] = {
424 { 0, "uncompressed" },
425 { 1, "ansiX962_compressed_prime" },
426 { 2, "ansiX962_compressed_char2" },
430 const value_string ssl_20_certificate_type[] = {
432 { 0x01, "X.509 Certificate" },
436 const value_string ssl_31_content_type[] = {
437 { 20, "Change Cipher Spec" },
440 { 23, "Application Data" },
445 const value_string ssl_versions[] = {
446 { 0xfefd, "DTLS 1.2" },
447 { 0xfeff, "DTLS 1.0" },
448 { 0x0100, "DTLS 1.0 (OpenSSL pre 0.9.8f)" },
449 { 0x0303, "TLS 1.2" },
450 { 0x0302, "TLS 1.1" },
451 { 0x0301, "TLS 1.0" },
452 { 0x0300, "SSL 3.0" },
453 { 0x0002, "SSL 2.0" },
458 /* XXX - would be used if we dissected the body of a Change Cipher Spec
460 const value_string ssl_31_change_cipher_spec[] = {
461 { 1, "Change Cipher Spec" },
466 const value_string ssl_31_alert_level[] = {
472 const value_string ssl_31_alert_description[] = {
473 { 0, "Close Notify" },
474 { 10, "Unexpected Message" },
475 { 20, "Bad Record MAC" },
476 { 21, "Decryption Failed" },
477 { 22, "Record Overflow" },
478 { 30, "Decompression Failure" },
479 { 40, "Handshake Failure" },
480 { 41, "No Certificate" },
481 { 42, "Bad Certificate" },
482 { 43, "Unsupported Certificate" },
483 { 44, "Certificate Revoked" },
484 { 45, "Certificate Expired" },
485 { 46, "Certificate Unknown" },
486 { 47, "Illegal Parameter" },
487 { 48, "Unknown CA" },
488 { 49, "Access Denied" },
489 { 50, "Decode Error" },
490 { 51, "Decrypt Error" },
491 { 60, "Export Restriction" },
492 { 70, "Protocol Version" },
493 { 71, "Insufficient Security" },
494 { 80, "Internal Error" },
495 { 90, "User Canceled" },
496 { 100, "No Renegotiation" },
497 { 110, "Unsupported Extension" },
498 { 111, "Certificate Unobtainable" },
499 { 112, "Unrecognized Name" },
500 { 113, "Bad Certificate Status Response" },
501 { 114, "Bad Certificate Hash Value" },
502 { 115, "Unknown PSK Identity" },
506 const value_string ssl_31_handshake_type[] = {
507 { SSL_HND_HELLO_REQUEST, "Hello Request" },
508 { SSL_HND_CLIENT_HELLO, "Client Hello" },
509 { SSL_HND_SERVER_HELLO, "Server Hello" },
510 { SSL_HND_HELLO_VERIFY_REQUEST, "Hello Verify Request"},
511 { SSL_HND_NEWSESSION_TICKET, "New Session Ticket" },
512 { SSL_HND_CERTIFICATE, "Certificate" },
513 { SSL_HND_SERVER_KEY_EXCHG, "Server Key Exchange" },
514 { SSL_HND_CERT_REQUEST, "Certificate Request" },
515 { SSL_HND_SVR_HELLO_DONE, "Server Hello Done" },
516 { SSL_HND_CERT_VERIFY, "Certificate Verify" },
517 { SSL_HND_CLIENT_KEY_EXCHG, "Client Key Exchange" },
518 { SSL_HND_FINISHED, "Finished" },
519 { SSL_HND_CERT_URL, "Client Certificate URL" },
520 { SSL_HND_CERT_STATUS, "Certificate Status" },
521 { SSL_HND_SUPPLEMENTAL_DATA, "Supplemental Data" },
522 { SSL_HND_ENCRYPTED_EXTS, "Encrypted Extensions" },
526 const value_string tls_heartbeat_type[] = {
532 const value_string tls_heartbeat_mode[] = {
533 { 1, "Peer allowed to send requests" },
534 { 2, "Peer not allowed to send requests" },
538 const value_string ssl_31_compression_method[] = {
546 /* XXX - would be used if we dissected a Signature, as would be
547 seen in a server key exchange or certificate verify message. */
548 const value_string ssl_31_key_exchange_algorithm[] = {
550 { 1, "Diffie Hellman" },
554 const value_string ssl_31_signature_algorithm[] = {
562 const value_string ssl_31_client_certificate_type[] = {
565 { 3, "RSA Fixed DH" },
566 { 4, "DSS Fixed DH" },
567 /* GOST certificate types */
568 /* Section 3.5 of draft-chudov-cryptopro-cptls-04 */
569 { 21, "GOST R 34.10-94" },
570 { 22, "GOST R 34.10-2001" },
571 /* END GOST certificate types */
572 { 64, "ECDSA Sign" },
573 { 65, "RSA Fixed ECDH" },
574 { 66, "ECDSA Fixed ECDH" },
579 /* XXX - would be used if we dissected exchange keys, as would be
580 seen in a client key exchange message. */
581 const value_string ssl_31_public_value_encoding[] = {
588 /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
589 /* Note: sorted by ascending value so value_string_ext fcns can do a binary search */
590 static const value_string ssl_31_ciphersuite[] = {
591 /* RFC 2246, RFC 4346, RFC 5246 */
592 { 0x0000, "TLS_NULL_WITH_NULL_NULL" },
593 { 0x0001, "TLS_RSA_WITH_NULL_MD5" },
594 { 0x0002, "TLS_RSA_WITH_NULL_SHA" },
595 { 0x0003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" },
596 { 0x0004, "TLS_RSA_WITH_RC4_128_MD5" },
597 { 0x0005, "TLS_RSA_WITH_RC4_128_SHA" },
598 { 0x0006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" },
599 { 0x0007, "TLS_RSA_WITH_IDEA_CBC_SHA" },
600 { 0x0008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" },
601 { 0x0009, "TLS_RSA_WITH_DES_CBC_SHA" },
602 { 0x000a, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" },
603 { 0x000b, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" },
604 { 0x000c, "TLS_DH_DSS_WITH_DES_CBC_SHA" },
605 { 0x000d, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" },
606 { 0x000e, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" },
607 { 0x000f, "TLS_DH_RSA_WITH_DES_CBC_SHA" },
608 { 0x0010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" },
609 { 0x0011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" },
610 { 0x0012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" },
611 { 0x0013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" },
612 { 0x0014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" },
613 { 0x0015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" },
614 { 0x0016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" },
615 { 0x0017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" },
616 { 0x0018, "TLS_DH_anon_WITH_RC4_128_MD5" },
617 { 0x0019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" },
618 { 0x001a, "TLS_DH_anon_WITH_DES_CBC_SHA" },
619 { 0x001b, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" },
621 { 0x001c, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" },
622 { 0x001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
623 #if 0 /* Because it clashes with KRB5, is never used any more, and is safe
624 to remove according to David Hopwood <david.hopwood@zetnet.co.uk>
625 of the ietf-tls list */
626 { 0x001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
630 { 0x001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
631 { 0x001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" },
632 { 0x0020, "TLS_KRB5_WITH_RC4_128_SHA" },
633 { 0x0021, "TLS_KRB5_WITH_IDEA_CBC_SHA" },
634 { 0x0022, "TLS_KRB5_WITH_DES_CBC_MD5" },
635 { 0x0023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" },
636 { 0x0024, "TLS_KRB5_WITH_RC4_128_MD5" },
637 { 0x0025, "TLS_KRB5_WITH_IDEA_CBC_MD5" },
638 { 0x0026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" },
639 { 0x0027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" },
640 { 0x0028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" },
641 { 0x0029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" },
642 { 0x002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" },
643 { 0x002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" },
646 { 0x002C, "TLS_PSK_WITH_NULL_SHA" },
647 { 0x002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
648 { 0x002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
651 { 0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA" },
652 { 0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
653 { 0x0031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" },
654 { 0x0032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" },
655 { 0x0033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" },
656 { 0x0034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" },
657 { 0x0035, "TLS_RSA_WITH_AES_256_CBC_SHA" },
658 { 0x0036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" },
659 { 0x0037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" },
660 { 0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
661 { 0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
662 { 0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
663 { 0x003B, "TLS_RSA_WITH_NULL_SHA256" },
664 { 0x003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" },
665 { 0x003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" },
666 { 0x003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" },
667 { 0x003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" },
668 { 0x0040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" },
671 { 0x0041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" },
672 { 0x0042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" },
673 { 0x0043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" },
674 { 0x0044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" },
675 { 0x0045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" },
676 { 0x0046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" },
678 /* 0x00,0x60-66 Reserved to avoid conflicts with widely deployed implementations */
680 { 0x0060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
681 { 0x0061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
682 /* draft-ietf-tls-56-bit-ciphersuites-01.txt */
683 { 0x0062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" },
684 { 0x0063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" },
685 { 0x0064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" },
686 { 0x0065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" },
687 { 0x0066, "TLS_DHE_DSS_WITH_RC4_128_SHA" },
690 { 0x0067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" },
691 { 0x0068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" },
692 { 0x0069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" },
693 { 0x006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" },
694 { 0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" },
695 { 0x006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" },
696 { 0x006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" },
698 /* draft-chudov-cryptopro-cptls-04.txt */
699 { 0x0080, "TLS_GOSTR341094_WITH_28147_CNT_IMIT" },
700 { 0x0081, "TLS_GOSTR341001_WITH_28147_CNT_IMIT" },
701 { 0x0082, "TLS_GOSTR341094_WITH_NULL_GOSTR3411" },
702 { 0x0083, "TLS_GOSTR341001_WITH_NULL_GOSTR3411" },
705 { 0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" },
706 { 0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" },
707 { 0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" },
708 { 0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
709 { 0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
710 { 0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
713 { 0x008A, "TLS_PSK_WITH_RC4_128_SHA" },
714 { 0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
715 { 0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA" },
716 { 0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA" },
717 { 0x008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" },
718 { 0x008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" },
719 { 0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" },
720 { 0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" },
721 { 0x0092, "TLS_RSA_PSK_WITH_RC4_128_SHA" },
722 { 0x0093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" },
723 { 0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" },
724 { 0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" },
727 { 0x0096, "TLS_RSA_WITH_SEED_CBC_SHA" },
728 { 0x0097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" },
729 { 0x0098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" },
730 { 0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
731 { 0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
732 { 0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
735 { 0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" },
736 { 0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" },
737 { 0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" },
738 { 0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" },
739 { 0x00A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" },
740 { 0x00A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" },
741 { 0x00A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" },
742 { 0x00A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" },
743 { 0x00A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" },
744 { 0x00A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" },
745 { 0x00A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" },
746 { 0x00A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" },
749 { 0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" },
750 { 0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" },
751 { 0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" },
752 { 0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" },
753 { 0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" },
754 { 0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" },
755 { 0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" },
756 { 0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" },
757 { 0x00B0, "TLS_PSK_WITH_NULL_SHA256" },
758 { 0x00B1, "TLS_PSK_WITH_NULL_SHA384" },
759 { 0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" },
760 { 0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" },
761 { 0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256" },
762 { 0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384" },
763 { 0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" },
764 { 0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" },
765 { 0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256" },
766 { 0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384" },
769 { 0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
770 { 0x00BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
771 { 0x00BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
772 { 0x00BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
773 { 0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
774 { 0x00BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" },
775 { 0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
776 { 0x00C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
777 { 0x00C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
778 { 0x00C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
779 { 0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
780 { 0x00C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" },
781 /* 0x00,0xC6-FE Unassigned */
783 { 0x0000FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" },
784 /* 0x01-BF,* Unassigned */
786 { 0xc001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
787 { 0xc002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
788 { 0xc003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
789 { 0xc004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
790 { 0xc005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
791 { 0xc006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" },
792 { 0xc007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" },
793 { 0xc008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" },
794 { 0xc009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
795 { 0xc00a, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
796 { 0xc00b, "TLS_ECDH_RSA_WITH_NULL_SHA" },
797 { 0xc00c, "TLS_ECDH_RSA_WITH_RC4_128_SHA" },
798 { 0xc00d, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" },
799 { 0xc00e, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" },
800 { 0xc00f, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" },
801 { 0xc010, "TLS_ECDHE_RSA_WITH_NULL_SHA" },
802 { 0xc011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" },
803 { 0xc012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" },
804 { 0xc013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
805 { 0xc014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
806 { 0xc015, "TLS_ECDH_anon_WITH_NULL_SHA" },
807 { 0xc016, "TLS_ECDH_anon_WITH_RC4_128_SHA" },
808 { 0xc017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" },
809 { 0xc018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" },
810 { 0xc019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" },
813 { 0xC01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" },
814 { 0xC01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" },
815 { 0xC01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" },
816 { 0xC01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" },
817 { 0xC01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" },
818 { 0xC01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" },
819 { 0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
820 { 0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
821 { 0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
824 { 0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" },
825 { 0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" },
826 { 0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" },
827 { 0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" },
828 { 0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" },
829 { 0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" },
830 { 0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" },
831 { 0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" },
832 { 0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
833 { 0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
834 { 0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" },
835 { 0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" },
836 { 0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
837 { 0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
838 { 0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" },
839 { 0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" },
842 { 0xC033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" },
843 { 0xC034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" },
844 { 0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" },
845 { 0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" },
846 { 0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" },
847 { 0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" },
848 { 0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA" },
849 { 0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" },
850 { 0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" },
853 { 0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256" },
854 { 0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384" },
855 { 0xC03E, "TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256" },
856 { 0xC03F, "TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384" },
857 { 0xC040, "TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256" },
858 { 0xC041, "TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384" },
859 { 0xC042, "TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256" },
860 { 0xC043, "TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384" },
861 { 0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256" },
862 { 0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384" },
863 { 0xC046, "TLS_DH_anon_WITH_ARIA_128_CBC_SHA256" },
864 { 0xC047, "TLS_DH_anon_WITH_ARIA_256_CBC_SHA384" },
865 { 0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256" },
866 { 0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384" },
867 { 0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256" },
868 { 0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384" },
869 { 0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256" },
870 { 0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384" },
871 { 0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256" },
872 { 0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384" },
873 { 0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256" },
874 { 0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384" },
875 { 0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256" },
876 { 0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384" },
877 { 0xC054, "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256" },
878 { 0xC055, "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384" },
879 { 0xC056, "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256" },
880 { 0xC057, "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384" },
881 { 0xC058, "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256" },
882 { 0xC059, "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384" },
883 { 0xC05A, "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256" },
884 { 0xC05B, "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384" },
885 { 0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256" },
886 { 0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384" },
887 { 0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256" },
888 { 0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384" },
889 { 0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256" },
890 { 0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384" },
891 { 0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256" },
892 { 0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384" },
893 { 0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256" },
894 { 0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384" },
895 { 0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256" },
896 { 0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384" },
897 { 0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256" },
898 { 0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384" },
899 { 0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256" },
900 { 0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384" },
901 { 0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256" },
902 { 0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384" },
903 { 0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256" },
904 { 0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384" },
905 { 0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256" },
906 { 0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384" },
909 { 0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" },
910 { 0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" },
911 { 0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" },
912 { 0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" },
913 { 0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
914 { 0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384" },
915 { 0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
916 { 0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384" },
917 { 0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
918 { 0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
919 { 0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
920 { 0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
921 { 0xC07E, "TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
922 { 0xC07F, "TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
923 { 0xC080, "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256" },
924 { 0xC081, "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384" },
925 { 0xC082, "TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256" },
926 { 0xC083, "TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384" },
927 { 0xC084, "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256" },
928 { 0xC085, "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384" },
929 { 0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" },
930 { 0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" },
931 { 0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" },
932 { 0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" },
933 { 0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
934 { 0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
935 { 0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
936 { 0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
937 { 0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
938 { 0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
939 { 0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
940 { 0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
941 { 0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
942 { 0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
943 { 0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
944 { 0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
945 { 0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
946 { 0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
947 { 0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
948 { 0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
949 { 0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
950 { 0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
953 { 0xC09C, "TLS_RSA_WITH_AES_128_CCM" },
954 { 0xC09D, "TLS_RSA_WITH_AES_256_CCM" },
955 { 0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM" },
956 { 0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM" },
957 { 0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8" },
958 { 0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8" },
959 { 0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8" },
960 { 0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8" },
961 { 0xC0A4, "TLS_PSK_WITH_AES_128_CCM" },
962 { 0xC0A5, "TLS_PSK_WITH_AES_256_CCM" },
963 { 0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM" },
964 { 0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM" },
965 { 0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8" },
966 { 0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8" },
967 { 0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8" },
968 { 0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8" },
970 /* http://www.iana.org/go/draft-mcgrew-tls-aes-ccm-ecc-08 */
971 { 0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM" },
972 { 0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM" },
973 { 0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" },
974 { 0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8" },
976 0xC0,0xAB-FF Unassigned
978 0xFE,0x00-FD Unassigned
979 0xFE,0xFE-FF Reserved to avoid conflicts with widely deployed implementations [Pasi_Eronen]
980 0xFF,0x00-FF Reserved for Private Use [RFC5246]
983 /* http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 */
984 { 0xCC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
985 { 0xCC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
986 { 0xCC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
988 /* http://tools.ietf.org/html/draft-josefsson-salsa20-tls */
989 { 0xE410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" },
990 { 0xE411, "TLS_RSA_WITH_SALSA20_SHA1" },
991 { 0xE412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
992 { 0xE413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" },
993 { 0xE414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" },
994 { 0xE415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" },
995 { 0xE416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" },
996 { 0xE417, "TLS_PSK_WITH_SALSA20_SHA1" },
997 { 0xE418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
998 { 0xE419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" },
999 { 0xE41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1000 { 0xE41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" },
1001 { 0xE41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1002 { 0xE41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" },
1003 { 0xE41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1004 { 0xE41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" },
1006 /* these from http://www.mozilla.org/projects/
1007 security/pki/nss/ssl/fips-ssl-ciphersuites.html */
1008 { 0xfefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
1009 { 0xfeff, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
1010 { 0xffe0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
1011 { 0xffe1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
1012 /* note that ciphersuites 0xff00 - 0xffff are private */
1016 value_string_ext ssl_31_ciphersuite_ext = VALUE_STRING_EXT_INIT(ssl_31_ciphersuite);
1019 const value_string pct_msg_types[] = {
1020 { PCT_MSG_CLIENT_HELLO, "Client Hello" },
1021 { PCT_MSG_SERVER_HELLO, "Server Hello" },
1022 { PCT_MSG_CLIENT_MASTER_KEY, "Client Master Key" },
1023 { PCT_MSG_SERVER_VERIFY, "Server Verify" },
1024 { PCT_MSG_ERROR, "Error" },
1028 const value_string pct_cipher_type[] = {
1029 { PCT_CIPHER_DES, "DES" },
1030 { PCT_CIPHER_IDEA, "IDEA" },
1031 { PCT_CIPHER_RC2, "RC2" },
1032 { PCT_CIPHER_RC4, "RC4" },
1033 { PCT_CIPHER_DES_112, "DES 112 bit" },
1034 { PCT_CIPHER_DES_168, "DES 168 bit" },
1038 const value_string pct_hash_type[] = {
1039 { PCT_HASH_MD5, "MD5" },
1040 { PCT_HASH_MD5_TRUNC_64, "MD5_TRUNC_64"},
1041 { PCT_HASH_SHA, "SHA"},
1042 { PCT_HASH_SHA_TRUNC_80, "SHA_TRUNC_80"},
1043 { PCT_HASH_DES_DM, "DES_DM"},
1047 const value_string pct_cert_type[] = {
1048 { PCT_CERT_NONE, "None" },
1049 { PCT_CERT_X509, "X.509" },
1050 { PCT_CERT_PKCS7, "PKCS #7" },
1053 const value_string pct_sig_type[] = {
1054 { PCT_SIG_NONE, "None" },
1055 { PCT_SIG_RSA_MD5, "MD5" },
1056 { PCT_SIG_RSA_SHA, "RSA SHA" },
1057 { PCT_SIG_DSA_SHA, "DSA SHA" },
1061 const value_string pct_exch_type[] = {
1062 { PCT_EXCH_RSA_PKCS1, "RSA PKCS#1" },
1063 { PCT_EXCH_RSA_PKCS1_TOKEN_DES, "RSA PKCS#1 Token DES" },
1064 { PCT_EXCH_RSA_PKCS1_TOKEN_DES3, "RSA PKCS#1 Token 3DES" },
1065 { PCT_EXCH_RSA_PKCS1_TOKEN_RC2, "RSA PKCS#1 Token RC-2" },
1066 { PCT_EXCH_RSA_PKCS1_TOKEN_RC4, "RSA PKCS#1 Token RC-4" },
1067 { PCT_EXCH_DH_PKCS3, "DH PKCS#3" },
1068 { PCT_EXCH_DH_PKCS3_TOKEN_DES, "DH PKCS#3 Token DES" },
1069 { PCT_EXCH_DH_PKCS3_TOKEN_DES3, "DH PKCS#3 Token 3DES" },
1070 { PCT_EXCH_FORTEZZA_TOKEN, "Fortezza" },
1074 const value_string pct_error_code[] = {
1075 { PCT_ERR_BAD_CERTIFICATE, "PCT_ERR_BAD_CERTIFICATE" },
1076 { PCT_ERR_CLIENT_AUTH_FAILED, "PCT_ERR_CLIENT_AUTH_FAILE" },
1077 { PCT_ERR_ILLEGAL_MESSAGE, "PCT_ERR_ILLEGAL_MESSAGE" },
1078 { PCT_ERR_INTEGRITY_CHECK_FAILED, "PCT_ERR_INTEGRITY_CHECK_FAILED" },
1079 { PCT_ERR_SERVER_AUTH_FAILED, "PCT_ERR_SERVER_AUTH_FAILED" },
1080 { PCT_ERR_SPECS_MISMATCH, "PCT_ERR_SPECS_MISMATCH" },
1084 /* http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#tls-extensiontype-values-1 */
1085 const value_string tls_hello_extension_types[] = {
1086 { SSL_HND_HELLO_EXT_SERVER_NAME, "server_name" }, /* RFC 3546 */
1087 { 1, "max_fragment_length" },
1088 { 2, "client_certificate_url" },
1089 { 3, "trusted_ca_keys" },
1090 { 4, "truncated_hmac" },
1091 { SSL_HND_HELLO_EXT_STATUS_REQUEST, "status_request" }, /* RFC 6066 */
1092 { 6, "user_mapping" }, /* RFC 4681 */
1093 { 7, "client_authz" },
1094 { 8, "server_authz" },
1095 { SSL_HND_HELLO_EXT_CERT_TYPE, "cert_type" }, /* RFC 5081 */
1096 { SSL_HND_HELLO_EXT_ELLIPTIC_CURVES, "elliptic_curves" }, /* RFC 4492 */
1097 { SSL_HND_HELLO_EXT_EC_POINT_FORMATS, "ec_point_formats" }, /* RFC 4492 */
1098 { 12, "srp" }, /* RFC 5054 */
1099 { 13, "signature_algorithms" }, /* RFC 5246 */
1101 { SSL_HND_HELLO_EXT_HEARTBEAT, "Heartbeat" }, /* RFC 6520 */
1102 { SSL_HND_HELLO_EXT_ALPN, "Application Layer Protocol Negotiation" }, /* draft-ietf-tls-applayerprotoneg-01 */
1103 { SSL_HND_HELLO_EXT_STATUS_REQUEST_V2, "status_request_v2" }, /* RFC 6961 */
1104 { 18, "signed_certificate_timestamp" }, /* RFC 6962 */
1105 { SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE, "client_certificate_type" }, /* http://tools.ietf.org/html/draft-ietf-tls-oob-pubkey-11 */
1106 { SSL_HND_HELLO_EXT_SERVER_CERT_TYPE, "server_certificate_type" }, /* http://tools.ietf.org/html/draft-ietf-tls-oob-pubkey-11 */
1107 { SSL_HND_HELLO_EXT_PADDING, "Padding" }, /* http://tools.ietf.org/html/draft-agl-tls-padding */
1108 { SSL_HND_HELLO_EXT_SESSION_TICKET, "SessionTicket TLS" }, /* RFC 4507 */
1109 { SSL_HND_HELLO_EXT_NPN, "next_protocol_negotiation"}, /* http://technotes.googlecode.com/git/nextprotoneg.html */
1110 { SSL_HND_HELLO_EXT_RENEG_INFO, "renegotiation_info" }, /* RFC 5746 */
1111 /* http://tools.ietf.org/html/draft-balfanz-tls-channelid-00
1112 https://twitter.com/ericlaw/status/274237352531083264 */
1113 { SSL_HND_HELLO_EXT_CHANNEL_ID_OLD, "channel_id_old" },
1114 /* http://tools.ietf.org/html/draft-balfanz-tls-channelid-01
1115 https://code.google.com/p/chromium/codesearch#chromium/src/net/third_party/nss/ssl/sslt.h&l=209 */
1116 { SSL_HND_HELLO_EXT_CHANNEL_ID, "channel_id" },
1120 const value_string tls_hello_ext_server_name_type_vs[] = {
1125 /* RFC 5246 7.4.1.4.1 */
1126 const value_string tls_hash_algorithm[] = {
1137 const value_string tls_signature_algorithm[] = {
1146 const value_string tls_certificate_type[] = {
1149 { SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY, "Raw Public Key" }, /* http://tools.ietf.org/html/draft-ietf-tls-oob-pubkey-11 */
1153 const value_string tls_cert_chain_type[] = {
1154 { SSL_HND_CERT_URL_TYPE_INDIVIDUAL_CERT, "Individual Certificates" },
1155 { SSL_HND_CERT_URL_TYPE_PKIPATH, "PKI Path" },
1159 const value_string tls_cert_status_type[] = {
1160 { SSL_HND_CERT_STATUS_TYPE_OCSP, "OCSP" },
1161 { SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI, "OCSP Multi" },
1165 /* we keep this internal to packet-ssl-utils, as there should be
1166 no need to access it any other way.
1168 This also allows us to hide the dependency on zlib.
1170 struct _SslDecompress {
1177 /* To assist in parsing client/server key exchange messages
1178 0 indicates unknown */
1179 gint ssl_get_keyex_alg(gint cipher)
1412 ssl_data_alloc(StringInfo* str, size_t len)
1414 str->data = (guchar *)g_malloc(len);
1415 /* the allocator can return a null pointer for a size equal to 0,
1416 * and that must be allowed */
1417 if (len > 0 && !str->data)
1419 str->data_len = (guint) len;
1424 ssl_data_set(StringInfo* str, const guchar* data, guint len)
1426 DISSECTOR_ASSERT(data);
1427 memcpy(str->data, data, len);
1428 str->data_len = len;
1433 from_hex_char(gchar c) {
1434 /* XXX, ws_xton() */
1435 if ((c >= '0') && (c <= '9'))
1437 if ((c >= 'A') && (c <= 'F'))
1438 return c - 'A' + 10;
1439 if ((c >= 'a') && (c <= 'f'))
1440 return c - 'a' + 10;
1444 /* from_hex converts |hex_len| bytes of hex data from |in| and sets |*out| to
1445 * the result. |out->data| will be allocated using se_alloc. Returns TRUE on
1447 static gboolean from_hex(StringInfo* out, const char* in, gsize hex_len) {
1453 out->data_len = (guint)hex_len/2;
1454 out->data = (guchar *)wmem_alloc(wmem_file_scope(), out->data_len);
1455 for (i = 0; i < out->data_len; i++) {
1456 int a = ws_xton(in[i*2]);
1457 int b = ws_xton(in[i*2 + 1]);
1458 if (a == -1 || b == -1)
1460 out->data[i] = a << 4 | b;
1466 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
1468 /* hmac abstraction layer */
1469 #define SSL_HMAC gcry_md_hd_t
1472 ssl_hmac_init(SSL_HMAC* md, const void * key, gint len, gint algo)
1475 const char *err_str, *err_src;
1477 err = gcry_md_open(md,algo, GCRY_MD_FLAG_HMAC);
1479 err_str = gcry_strerror(err);
1480 err_src = gcry_strsource(err);
1481 ssl_debug_printf("ssl_hmac_init(): gcry_md_open failed %s/%s", err_str, err_src);
1484 gcry_md_setkey (*(md), key, len);
1488 ssl_hmac_update(SSL_HMAC* md, const void* data, gint len)
1490 gcry_md_write(*(md), data, len);
1493 ssl_hmac_final(SSL_HMAC* md, guchar* data, guint* datalen)
1498 algo = gcry_md_get_algo (*(md));
1499 len = gcry_md_get_algo_dlen(algo);
1500 DISSECTOR_ASSERT(len <= *datalen);
1501 memcpy(data, gcry_md_read(*(md), algo), len);
1505 ssl_hmac_cleanup(SSL_HMAC* md)
1507 gcry_md_close(*(md));
1510 /* memory digest abstraction layer*/
1511 #define SSL_MD gcry_md_hd_t
1514 ssl_md_init(SSL_MD* md, gint algo)
1517 const char *err_str, *err_src;
1518 err = gcry_md_open(md,algo, 0);
1520 err_str = gcry_strerror(err);
1521 err_src = gcry_strsource(err);
1522 ssl_debug_printf("ssl_md_init(): gcry_md_open failed %s/%s", err_str, err_src);
1528 ssl_md_update(SSL_MD* md, guchar* data, gint len)
1530 gcry_md_write(*(md), data, len);
1533 ssl_md_final(SSL_MD* md, guchar* data, guint* datalen)
1537 algo = gcry_md_get_algo (*(md));
1538 len = gcry_md_get_algo_dlen (algo);
1539 memcpy(data, gcry_md_read(*(md), algo), len);
1543 ssl_md_cleanup(SSL_MD* md)
1545 gcry_md_close(*(md));
1548 /* md5 /sha abstraction layer */
1549 #define SSL_SHA_CTX gcry_md_hd_t
1550 #define SSL_MD5_CTX gcry_md_hd_t
1553 ssl_sha_init(SSL_SHA_CTX* md)
1555 gcry_md_open(md,GCRY_MD_SHA1, 0);
1558 ssl_sha_update(SSL_SHA_CTX* md, guchar* data, gint len)
1560 gcry_md_write(*(md), data, len);
1563 ssl_sha_final(guchar* buf, SSL_SHA_CTX* md)
1565 memcpy(buf, gcry_md_read(*(md), GCRY_MD_SHA1),
1566 gcry_md_get_algo_dlen(GCRY_MD_SHA1));
1569 ssl_sha_cleanup(SSL_SHA_CTX* md)
1571 gcry_md_close(*(md));
1575 ssl_md5_init(SSL_MD5_CTX* md)
1577 return gcry_md_open(md,GCRY_MD_MD5, 0);
1580 ssl_md5_update(SSL_MD5_CTX* md, guchar* data, gint len)
1582 gcry_md_write(*(md), data, len);
1585 ssl_md5_final(guchar* buf, SSL_MD5_CTX* md)
1587 memcpy(buf, gcry_md_read(*(md), GCRY_MD_MD5),
1588 gcry_md_get_algo_dlen(GCRY_MD_MD5));
1591 ssl_md5_cleanup(SSL_MD5_CTX* md)
1593 gcry_md_close(*(md));
1597 ssl_cipher_setiv(SSL_CIPHER_CTX *cipher, guchar* iv, gint iv_len)
1604 c=(gcry_cipher_hd_t)*cipher;
1606 ssl_debug_printf("--------------------------------------------------------------------");
1608 for(ivp=c->iv,i=0; i < iv_len; i++ )
1610 ssl_debug_printf("%d ",ivp[i]);
1614 ssl_debug_printf("--------------------------------------------------------------------");
1615 ret = gcry_cipher_setiv(*(cipher), iv, iv_len);
1617 for(ivp=c->iv,i=0; i < iv_len; i++ )
1619 ssl_debug_printf("%d ",ivp[i]);
1623 ssl_debug_printf("--------------------------------------------------------------------");
1626 /* stream cipher abstraction layer*/
1628 ssl_cipher_init(gcry_cipher_hd_t *cipher, gint algo, guchar* sk,
1629 guchar* iv, gint mode)
1631 gint gcry_modes[]={GCRY_CIPHER_MODE_STREAM,GCRY_CIPHER_MODE_CBC,GCRY_CIPHER_MODE_CTR,GCRY_CIPHER_MODE_CTR,GCRY_CIPHER_MODE_CTR};
1635 *(cipher) = (gcry_cipher_hd_t)-1;
1638 err = gcry_cipher_open(cipher, algo, gcry_modes[mode], 0);
1641 err = gcry_cipher_setkey(*(cipher), sk, gcry_cipher_get_algo_keylen (algo));
1644 err = gcry_cipher_setiv(*(cipher), iv, gcry_cipher_get_algo_blklen (algo));
1650 ssl_cipher_decrypt(gcry_cipher_hd_t *cipher, guchar * out, gint outl,
1651 const guchar * in, gint inl)
1653 if ((*cipher) == (gcry_cipher_hd_t)-1)
1656 memcpy(out, in, outl < inl ? outl : inl);
1659 return gcry_cipher_decrypt ( *(cipher), out, outl, in, inl);
1662 ssl_get_digest_by_name(const gchar*name)
1664 return gcry_md_map_name(name);
1667 ssl_get_cipher_by_name(const gchar* name)
1669 return gcry_cipher_map_name(name);
1673 ssl_cipher_cleanup(gcry_cipher_hd_t *cipher)
1675 if ((*cipher) != (gcry_cipher_hd_t)-1)
1676 gcry_cipher_close(*cipher);
1681 _gcry_rsa_decrypt (int algo, gcry_mpi_t *result, gcry_mpi_t *data,
1682 gcry_mpi_t *skey, gint flags);
1684 /* decrypt data with private key. Store decrypted data directly into input
1687 ssl_private_decrypt(const guint len, guchar* data, SSL_PRIVATE_KEY* pk)
1690 size_t decr_len = 0, i = 0;
1691 gcry_sexp_t s_data = NULL, s_plain = NULL;
1692 gcry_mpi_t encr_mpi = NULL, text = NULL;
1694 /* create mpi representation of encrypted data */
1695 rc = gcry_mpi_scan(&encr_mpi, GCRYMPI_FMT_USG, data, len, NULL);
1697 ssl_debug_printf("pcry_private_decrypt: can't convert data to mpi (size %d):%s\n",
1698 len, gcry_strerror(rc));
1703 /* put the data into a simple list */
1704 rc = gcry_sexp_build(&s_data, NULL, "(enc-val(rsa(a%m)))", encr_mpi);
1706 ssl_debug_printf("pcry_private_decrypt: can't build encr_sexp:%s\n",
1712 /* pass it to libgcrypt */
1713 rc = gcry_pk_decrypt(&s_plain, s_data, pk);
1716 ssl_debug_printf("pcry_private_decrypt: can't decrypt key:%s\n",
1722 /* convert plain text sexp to mpi format */
1723 text = gcry_sexp_nth_mpi(s_plain, 0, 0);
1725 ssl_debug_printf("pcry_private_decrypt: can't convert sexp to mpi\n");
1730 /* compute size requested for plaintext buffer */
1731 rc = gcry_mpi_print(GCRYMPI_FMT_USG, NULL, 0, &decr_len, text);
1733 ssl_debug_printf("pcry_private_decrypt: can't compute decr size:%s\n",
1739 #else /* SSL_FAST */
1740 rc = _gcry_rsa_decrypt(0, &text, &encr_mpi, pk,0);
1741 gcry_mpi_print( GCRYMPI_FMT_USG, 0, 0, &decr_len, text);
1742 #endif /* SSL_FAST */
1744 /* sanity check on out buffer */
1745 if (decr_len > len) {
1746 ssl_debug_printf("pcry_private_decrypt: decrypted data is too long ?!? (%" G_GSIZE_MODIFIER "u max %d)\n", decr_len, len);
1751 /* write plain text to newly allocated buffer */
1752 rc = gcry_mpi_print(GCRYMPI_FMT_USG, data, len, &decr_len, text);
1754 ssl_debug_printf("pcry_private_decrypt: can't print decr data to mpi (size %" G_GSIZE_MODIFIER "u):%s\n", decr_len, gcry_strerror(rc));
1759 ssl_print_data("decrypted_unstrip_pre_master", data, decr_len);
1761 /* strip the padding*/
1763 for (i = 1; i < decr_len; i++) {
1770 ssl_debug_printf("pcry_private_decrypt: stripping %d bytes, decr_len %" G_GSIZE_MODIFIER "u\n", rc, decr_len);
1772 memmove(data, data+rc, decr_len);
1775 gcry_sexp_release(s_data);
1776 gcry_sexp_release(s_plain);
1777 gcry_mpi_release(encr_mpi);
1778 gcry_mpi_release(text);
1779 return (int) decr_len;
1782 /* stringinfo interface */
1784 ssl_data_realloc(StringInfo* str, guint len)
1786 str->data = (guchar *)g_realloc(str->data, len);
1789 str->data_len = len;
1794 ssl_data_copy(StringInfo* dst, StringInfo* src)
1796 if (dst->data_len < src->data_len) {
1797 if (ssl_data_realloc(dst, src->data_len))
1800 memcpy(dst->data, src->data, src->data_len);
1801 dst->data_len = src->data_len;
1805 static const SslDigestAlgo digests[]={
1810 {"Not Applicable", 0},
1813 #define DIGEST_MAX_SIZE 48
1815 /* get index digest index */
1816 static const SslDigestAlgo *
1817 ssl_cipher_suite_dig(SslCipherSuite *cs) {
1818 return &digests[cs->dig - DIG_MD5];
1821 static const gchar *ciphers[]={
1824 "ARCFOUR", /* libgcrypt does not support rc4, but this should be 100% compatible*/
1825 "RFC2268_128", /* libgcrypt name for RC2 with a 128-bit key */
1835 static SslCipherSuite cipher_suites[]={
1836 {0x0001,KEX_RSA, ENC_NULL, 1, 0, 0,DIG_MD5, MODE_STREAM}, /* TLS_RSA_WITH_NULL_MD5 */
1837 {0x0002,KEX_RSA, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_RSA_WITH_NULL_SHA */
1838 {0x0003,KEX_RSA, ENC_RC4, 1,128, 40,DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT_WITH_RC4_40_MD5 */
1839 {0x0004,KEX_RSA, ENC_RC4, 1,128,128,DIG_MD5, MODE_STREAM}, /* TLS_RSA_WITH_RC4_128_MD5 */
1840 {0x0005,KEX_RSA, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_RSA_WITH_RC4_128_SHA */
1841 {0x0006,KEX_RSA, ENC_RC2, 8,128, 40,DIG_MD5, MODE_CBC }, /* TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 */
1842 {0x0007,KEX_RSA, ENC_IDEA, 8,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_IDEA_CBC_SHA */
1843 {0x0008,KEX_RSA, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_RSA_EXPORT_WITH_DES40_CBC_SHA */
1844 {0x0009,KEX_RSA, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_DES_CBC_SHA */
1845 {0x000A,KEX_RSA, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_3DES_EDE_CBC_SHA */
1846 {0x000B,KEX_DH, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA */
1847 {0x000C,KEX_DH, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_DES_CBC_SHA */
1848 {0x000D,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA */
1849 {0x000E,KEX_DH, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA */
1850 {0x000F,KEX_DH, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_DES_CBC_SHA */
1851 {0x0010,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA */
1852 {0x0011,KEX_DH, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA */
1853 {0x0012,KEX_DH, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_DES_CBC_SHA */
1854 {0x0013,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA */
1855 {0x0014,KEX_DH, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA */
1856 {0x0015,KEX_DH, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_DES_CBC_SHA */
1857 {0x0016,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */
1858 {0x0017,KEX_DH, ENC_RC4, 1,128, 40,DIG_MD5, MODE_STREAM}, /* TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 */
1859 {0x0018,KEX_DH, ENC_RC4, 1,128,128,DIG_MD5, MODE_STREAM}, /* TLS_DH_anon_WITH_RC4_128_MD5 */
1860 {0x0019,KEX_DH, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA */
1861 {0x001A,KEX_DH, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_DES_CBC_SHA */
1862 {0x001B,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_3DES_EDE_CBC_SHA */
1863 {0x002C,KEX_PSK, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA */
1864 {0x002D,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA */
1865 {0x002E,KEX_RSA_PSK,ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA */
1866 {0x002F,KEX_RSA, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_AES_128_CBC_SHA */
1867 {0x0030,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_128_CBC_SHA */
1868 {0x0031,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_128_CBC_SHA */
1869 {0x0032,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_128_CBC_SHA */
1870 {0x0033,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
1871 {0x0034,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_AES_128_CBC_SHA */
1872 {0x0035,KEX_RSA, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_AES_256_CBC_SHA */
1873 {0x0036,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_256_CBC_SHA */
1874 {0x0037,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_256_CBC_SHA */
1875 {0x0038,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_256_CBC_SHA */
1876 {0x0039,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */
1877 {0x003A,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_AES_256_CBC_SHA */
1878 {0x003B,KEX_RSA, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_RSA_WITH_NULL_SHA256 */
1879 {0x003C,KEX_RSA, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_AES_128_CBC_SHA256 */
1880 {0x003D,KEX_RSA, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_AES_256_CBC_SHA256 */
1881 {0x003E,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_128_CBC_SHA256 */
1882 {0x003F,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_128_CBC_SHA256 */
1883 {0x0040,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 */
1884 {0x0041,KEX_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */
1885 {0x0042,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA */
1886 {0x0043,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA */
1887 {0x0044,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA */
1888 {0x0045,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */
1889 {0x0046,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA */
1890 {0x0060,KEX_RSA, ENC_RC4, 1,128, 56,DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC4_56_MD5 */
1891 {0x0061,KEX_RSA, ENC_RC2, 1,128, 56,DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 */
1892 {0x0062,KEX_RSA, ENC_DES, 8, 64, 56,DIG_SHA, MODE_CBC }, /* TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA */
1893 {0x0063,KEX_DH, ENC_DES, 8, 64, 56,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA */
1894 {0x0064,KEX_RSA, ENC_RC4, 1,128, 56,DIG_SHA, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC4_56_SHA */
1895 {0x0065,KEX_DH, ENC_RC4, 1,128, 56,DIG_SHA, MODE_STREAM}, /* TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA */
1896 {0x0066,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_DHE_DSS_WITH_RC4_128_SHA */
1897 {0x0067,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */
1898 {0x0068,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_256_CBC_SHA256 */
1899 {0x0069,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_256_CBC_SHA256 */
1900 {0x006A,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 */
1901 {0x006B,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */
1902 {0x006C,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_AES_128_CBC_SHA256 */
1903 {0x006D,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_AES_256_CBC_SHA256 */
1904 {0x0084,KEX_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */
1905 {0x0085,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA */
1906 {0x0086,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA */
1907 {0x0087,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA */
1908 {0x0088,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */
1909 {0x0089,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA */
1910 {0x008A,KEX_PSK, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_PSK_WITH_RC4_128_SHA */
1911 {0x008B,KEX_PSK, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_3DES_EDE_CBC_SHA */
1912 {0x008C,KEX_PSK, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_AES_128_CBC_SHA */
1913 {0x008D,KEX_PSK, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_AES_256_CBC_SHA */
1914 {0x008E,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_DHE_PSK_WITH_RC4_128_SHA */
1915 {0x008F,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA */
1916 {0x0090,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA */
1917 {0x0091,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA */
1918 {0x0092,KEX_RSA_PSK,ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_RSA_PSK_WITH_RC4_128_SHA */
1919 {0x0093,KEX_RSA_PSK,ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA */
1920 {0x0094,KEX_RSA_PSK,ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_128_CBC_SHA */
1921 {0x0095,KEX_RSA_PSK,ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_256_CBC_SHA */
1922 {0x0096,KEX_RSA, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_SEED_CBC_SHA */
1923 {0x0097,KEX_DH, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_SEED_CBC_SHA */
1924 {0x0098,KEX_DH, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_SEED_CBC_SHA */
1925 {0x0099,KEX_DH, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_SEED_CBC_SHA */
1926 {0x009A,KEX_DH, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_SEED_CBC_SHA */
1927 {0x009B,KEX_DH, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_SEED_CBC_SHA */
1928 {0x009C,KEX_RSA, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_WITH_AES_128_GCM_SHA256 */
1929 {0x009D,KEX_RSA, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_WITH_AES_256_GCM_SHA384 */
1930 {0x009E,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */
1931 {0x009F,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */
1932 {0x00A0,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_RSA_WITH_AES_128_GCM_SHA256 */
1933 {0x00A1,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_RSA_WITH_AES_256_GCM_SHA384 */
1934 {0x00A2,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 */
1935 {0x00A3,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 */
1936 {0x00A4,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_DSS_WITH_AES_128_GCM_SHA256 */
1937 {0x00A5,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_DSS_WITH_AES_256_GCM_SHA384 */
1938 {0x00A6,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_anon_WITH_AES_128_GCM_SHA256 */
1939 {0x00A7,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */
1940 {0x00A8,KEX_PSK, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_PSK_WITH_AES_128_GCM_SHA256 */
1941 {0x00A9,KEX_PSK, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_PSK_WITH_AES_256_GCM_SHA384 */
1942 {0x00AA,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */
1943 {0x00AB,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */
1944 {0x00AC,KEX_RSA_PSK,ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 */
1945 {0x00AD,KEX_RSA_PSK,ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 */
1946 {0x00AE,KEX_PSK, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_PSK_WITH_AES_128_CBC_SHA256 */
1947 {0x00AF,KEX_PSK, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_PSK_WITH_AES_256_CBC_SHA384 */
1948 {0x00B0,KEX_PSK, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA256 */
1949 {0x00B1,KEX_PSK, ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA384 */
1950 {0x00B2,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */
1951 {0x00B3,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */
1952 {0x00B4,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA256 */
1953 {0x00B5,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA384 */
1954 {0x00B6,KEX_RSA_PSK,ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 */
1955 {0x00B7,KEX_RSA_PSK,ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 */
1956 {0x00B8,KEX_RSA_PSK,ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA256 */
1957 {0x00B9,KEX_RSA_PSK,ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA384 */
1958 {0x00BA,KEX_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
1959 {0x00BB,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 */
1960 {0x00BC,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
1961 {0x00BD,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 */
1962 {0x00BE,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
1963 {0x00BF,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256 */
1964 {0x00C0,KEX_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
1965 {0x00C1,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 */
1966 {0x00C2,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
1967 {0x00C3,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 */
1968 {0x00C4,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
1969 {0x00C5,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 */
1970 {0xC001,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_ECDSA_WITH_NULL_SHA */
1971 {0xC002,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */
1972 {0xC003,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */
1973 {0xC004,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */
1974 {0xC005,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */
1975 {0xC006,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */
1976 {0xC007,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */
1977 {0xC008,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */
1978 {0xC009,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */
1979 {0xC00A,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */
1980 {0xC00B,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_RSA_WITH_NULL_SHA */
1981 {0xC00C,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_RSA_WITH_RC4_128_SHA */
1982 {0xC00D,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */
1983 {0xC00E,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */
1984 {0xC00F,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */
1985 {0xC010,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_RSA_WITH_NULL_SHA */
1986 {0xC011,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */
1987 {0xC012,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */
1988 {0xC013,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */
1989 {0xC014,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */
1990 {0xC015,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_anon_WITH_NULL_SHA */
1991 {0xC016,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_anon_WITH_RC4_128_SHA */
1992 {0xC017,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA */
1993 {0xC018,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_AES_128_CBC_SHA */
1994 {0xC019,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_AES_256_CBC_SHA */
1995 {0xC023,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 */
1996 {0xC024,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 */
1997 {0xC025,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */
1998 {0xC026,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */
1999 {0xC027,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */
2000 {0xC028,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */
2001 {0xC029,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */
2002 {0xC02A,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */
2003 {0xC02B,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */
2004 {0xC02C,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */
2005 {0xC02D,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */
2006 {0xC02E,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */
2007 {0xC02F,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */
2008 {0xC030,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */
2009 {0xC031,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */
2010 {0xC032,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */
2011 {0xC033,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_RC4_128_SHA */
2012 {0xC034,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA */
2013 {0xC035,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA */
2014 {0xC036,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA */
2015 {0xC037,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */
2016 {0xC038,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 */
2017 {0xC039,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA */
2018 {0xC03A,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */
2019 {0xC03B,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA384 */
2020 {0xC072,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */
2021 {0xC073,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 */
2022 {0xC074,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */
2023 {0xC075,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 */
2024 {0xC076,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2025 {0xC077,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 */
2026 {0xC078,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2027 {0xC079,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 */
2028 {0xC07A,KEX_RSA, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2029 {0xC07B,KEX_RSA, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2030 {0xC07C,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2031 {0xC07D,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2032 {0xC07E,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2033 {0xC07F,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2034 {0xC080,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256 */
2035 {0xC081,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384 */
2036 {0xC082,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256 */
2037 {0xC083,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384 */
2038 {0xC084,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256 */
2039 {0xC085,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384 */
2040 {0xC086,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 */
2041 {0xC087,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */
2042 {0xC088,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 */
2043 {0xC089,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */
2044 {0xC08A,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2045 {0xC08B,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2046 {0xC08C,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2047 {0xC08D,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2048 {0xC08E,KEX_PSK, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2049 {0xC08F,KEX_PSK, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2050 {0xC090,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2051 {0xC091,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2052 {0xC092,KEX_RSA_PSK,ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2053 {0xC093,KEX_RSA_PSK,ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2054 {0xC094,KEX_PSK, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2055 {0xC095,KEX_PSK, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2056 {0xC096,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2057 {0xC097,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2058 {0xC098,KEX_RSA_PSK,ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2059 {0xC099,KEX_RSA_PSK,ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2060 {0xC09A,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2061 {0xC09B,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2062 {0xC09C,KEX_RSA, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_RSA_WITH_AES_128_CCM */
2063 {0xC09D,KEX_RSA, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_RSA_WITH_AES_256_CCM */
2064 {0xC09E,KEX_DH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_DHE_RSA_WITH_AES_128_CCM */
2065 {0xC09F,KEX_DH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_DHE_RSA_WITH_AES_256_CCM */
2066 {0xC0A0,KEX_RSA, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_RSA_WITH_AES_128_CCM_8 */
2067 {0xC0A1,KEX_RSA, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_RSA_WITH_AES_256_CCM_8 */
2068 {0xC0A2,KEX_DH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_DHE_RSA_WITH_AES_128_CCM_8 */
2069 {0xC0A3,KEX_DH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_DHE_RSA_WITH_AES_256_CCM_8 */
2070 {0xC0A4,KEX_PSK, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_PSK_WITH_AES_128_CCM */
2071 {0xC0A5,KEX_PSK, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_PSK_WITH_AES_256_CCM */
2072 {0xC0A6,KEX_DH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_DHE_PSK_WITH_AES_128_CCM */
2073 {0xC0A7,KEX_DH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_DHE_PSK_WITH_AES_256_CCM */
2074 {0xC0A8,KEX_PSK, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_WITH_AES_128_CCM_8 */
2075 {0xC0A9,KEX_PSK, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_WITH_AES_256_CCM_8 */
2076 {0xC0AA,KEX_DH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_DHE_WITH_AES_128_CCM_8 */
2077 {0xC0AB,KEX_DH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_DHE_WITH_AES_256_CCM_8 */
2078 {0xC0AC,KEX_ECDH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */
2079 {0xC0AD,KEX_ECDH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM */
2080 {0xC0AE,KEX_ECDH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */
2081 {0xC0AF,KEX_ECDH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */
2082 {-1, 0, 0, 0, 0, 0,0, MODE_STREAM}
2085 #define MAX_BLOCK_SIZE 16
2086 #define MAX_KEY_SIZE 32
2089 ssl_find_cipher(int num,SslCipherSuite* cs)
2093 for(c=cipher_suites;c->number!=-1;c++){
2104 tls_hash(StringInfo* secret, StringInfo* seed, gint md, StringInfo* out)
2110 guint8 _A[DIGEST_MAX_SIZE],tmp[DIGEST_MAX_SIZE];
2114 left = out->data_len;
2117 ssl_print_string("tls_hash: hash secret", secret);
2118 ssl_print_string("tls_hash: hash seed", seed);
2123 ssl_hmac_init(&hm,secret->data,secret->data_len,md);
2124 ssl_hmac_update(&hm,A,A_l);
2126 ssl_hmac_final(&hm,_A,&A_l);
2127 ssl_hmac_cleanup(&hm);
2130 ssl_hmac_init(&hm,secret->data,secret->data_len,md);
2131 ssl_hmac_update(&hm,A,A_l);
2132 ssl_hmac_update(&hm,seed->data,seed->data_len);
2133 tmp_l = sizeof(tmp);
2134 ssl_hmac_final(&hm,tmp,&tmp_l);
2135 ssl_hmac_cleanup(&hm);
2137 tocpy=MIN(left,tmp_l);
2138 memcpy(ptr,tmp,tocpy);
2143 ssl_print_string("hash out", out);
2148 tls_prf(StringInfo* secret, const gchar *usage,
2149 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out)
2151 StringInfo seed, sha_out, md5_out;
2157 usage_len = strlen(usage);
2159 /* initalize buffer for sha, md5 random seed*/
2160 if (ssl_data_alloc(&sha_out, MAX(out->data_len,20)) < 0) {
2161 ssl_debug_printf("tls_prf: can't allocate sha out\n");
2164 if (ssl_data_alloc(&md5_out, MAX(out->data_len,16)) < 0) {
2165 ssl_debug_printf("tls_prf: can't allocate md5 out\n");
2168 if (ssl_data_alloc(&seed, usage_len+rnd1->data_len+rnd2->data_len) < 0) {
2169 ssl_debug_printf("tls_prf: can't allocate rnd %d\n",
2170 (int) (usage_len+rnd1->data_len+rnd2->data_len));
2175 memcpy(ptr,usage,usage_len);
2177 memcpy(ptr,rnd1->data,rnd1->data_len);
2178 ptr+=rnd1->data_len;
2179 memcpy(ptr,rnd2->data,rnd2->data_len);
2180 /*ptr+=rnd2->data_len;*/
2182 /* initalize buffer for client/server seeds*/
2183 s_l=secret->data_len/2 + secret->data_len%2;
2184 if (ssl_data_alloc(&s1, s_l) < 0) {
2185 ssl_debug_printf("tls_prf: can't allocate secret %d\n", s_l);
2188 if (ssl_data_alloc(&s2, s_l) < 0) {
2189 ssl_debug_printf("tls_prf: can't allocate secret(2) %d\n", s_l);
2193 memcpy(s1.data,secret->data,s_l);
2194 memcpy(s2.data,secret->data + (secret->data_len - s_l),s_l);
2196 ssl_debug_printf("tls_prf: tls_hash(md5 secret_len %d seed_len %d )\n", s1.data_len, seed.data_len);
2197 if(tls_hash(&s1,&seed,ssl_get_digest_by_name("MD5"),&md5_out) != 0)
2199 ssl_debug_printf("tls_prf: tls_hash(sha)\n");
2200 if(tls_hash(&s2,&seed,ssl_get_digest_by_name("SHA1"),&sha_out) != 0)
2203 for(i=0;i<out->data_len;i++)
2204 out->data[i]=md5_out.data[i] ^ sha_out.data[i];
2207 ssl_print_string("PRF out",out);
2215 g_free(md5_out.data);
2217 g_free(sha_out.data);
2222 tls12_prf(gint md, StringInfo* secret, const gchar* usage, StringInfo* rnd1, StringInfo* rnd2, StringInfo* out)
2224 StringInfo label_seed;
2227 usage_len = strlen(usage);
2228 if (ssl_data_alloc(&label_seed, usage_len+rnd1->data_len+rnd2->data_len) < 0) {
2229 ssl_debug_printf("tls12_prf: can't allocate label_seed\n");
2232 memcpy(label_seed.data, usage, usage_len);
2233 memcpy(label_seed.data+usage_len, rnd1->data, rnd1->data_len);
2234 memcpy(label_seed.data+usage_len+rnd1->data_len, rnd2->data, rnd2->data_len);
2236 ssl_debug_printf("tls12_prf: tls_hash(hash_alg %s secret_len %d seed_len %d )\n", gcry_md_algo_name(md), secret->data_len, label_seed.data_len);
2237 if (tls_hash(secret, &label_seed, md, out) != 0){
2238 g_free(label_seed.data);
2241 ssl_print_string("PRF out", out);
2246 ssl3_generate_export_iv(StringInfo* r1,
2247 StringInfo* r2, StringInfo* out)
2253 ssl_md5_update(&md5,r1->data,r1->data_len);
2254 ssl_md5_update(&md5,r2->data,r2->data_len);
2255 ssl_md5_final(tmp,&md5);
2256 ssl_md5_cleanup(&md5);
2258 memcpy(out->data,tmp,out->data_len);
2259 ssl_print_string("export iv", out);
2265 ssl3_prf(StringInfo* secret, const gchar* usage,
2267 StringInfo* r2,StringInfo* out)
2271 StringInfo *rnd1,*rnd2;
2278 for(off=0;off<out->data_len;off+=16){
2283 ssl_debug_printf("ssl3_prf: sha1_hash(%d)\n",i);
2284 /* A, BB, CCC, ... */
2290 ssl_sha_update(&sha,buf,i);
2291 ssl_sha_update(&sha,secret->data,secret->data_len);
2293 if(!strcmp(usage,"client write key") || !strcmp(usage,"server write key")){
2294 ssl_sha_update(&sha,rnd2->data,rnd2->data_len);
2295 ssl_sha_update(&sha,rnd1->data,rnd1->data_len);
2298 ssl_sha_update(&sha,rnd1->data,rnd1->data_len);
2299 ssl_sha_update(&sha,rnd2->data,rnd2->data_len);
2302 ssl_sha_final(buf,&sha);
2303 ssl_sha_cleanup(&sha);
2305 ssl_debug_printf("ssl3_prf: md5_hash(%d) datalen %d\n",i,
2308 ssl_md5_update(&md5,secret->data,secret->data_len);
2309 ssl_md5_update(&md5,buf,20);
2310 ssl_md5_final(outbuf,&md5);
2311 ssl_md5_cleanup(&md5);
2313 tocpy=MIN(out->data_len-off,16);
2314 memcpy(out->data+off,outbuf,tocpy);
2320 static gint prf(SslDecryptSession* ssl,StringInfo* secret,const gchar* usage,StringInfo* rnd1,StringInfo* rnd2,StringInfo* out)
2323 if (ssl->version_netorder==SSLV3_VERSION){
2324 ret = ssl3_prf(secret,usage,rnd1,rnd2,out);
2325 }else if (ssl->version_netorder==TLSV1_VERSION || ssl->version_netorder==TLSV1DOT1_VERSION ||
2326 ssl->version_netorder==DTLSV1DOT0_VERSION || ssl->version_netorder==DTLSV1DOT0_VERSION_NOT){
2327 ret = tls_prf(secret,usage,rnd1,rnd2,out);
2329 if (ssl->cipher_suite.dig == DIG_SHA384){
2330 ret = tls12_prf(GCRY_MD_SHA384, secret, usage, rnd1, rnd2, out);
2332 ret = tls12_prf(GCRY_MD_SHA256, secret, usage, rnd1, rnd2, out);
2339 ssl_create_flow(void)
2343 flow = (SslFlow *)wmem_alloc(wmem_file_scope(), sizeof(SslFlow));
2346 flow->multisegment_pdus = wmem_tree_new(wmem_file_scope());
2351 /* memory allocation functions for zlib initialization */
2352 static void* ssl_zalloc(void* opaque _U_, unsigned int no, unsigned int size)
2354 return g_malloc0(no*size);
2356 static void ssl_zfree(void* opaque _U_, void* addr)
2362 static SslDecompress*
2363 ssl_create_decompressor(gint compression)
2365 SslDecompress *decomp;
2370 if (compression == 0) return NULL;
2371 ssl_debug_printf("ssl_create_decompressor: compression method %d\n", compression);
2372 decomp = (SslDecompress *)wmem_alloc(wmem_file_scope(), sizeof(SslDecompress));
2373 decomp->compression = compression;
2374 switch (decomp->compression) {
2376 case 1: /* DEFLATE */
2377 decomp->istream.zalloc = ssl_zalloc;
2378 decomp->istream.zfree = ssl_zfree;
2379 decomp->istream.opaque = Z_NULL;
2380 decomp->istream.next_in = Z_NULL;
2381 decomp->istream.next_out = Z_NULL;
2382 decomp->istream.avail_in = 0;
2383 decomp->istream.avail_out = 0;
2384 err = inflateInit_(&decomp->istream, ZLIB_VERSION, sizeof(z_stream));
2386 ssl_debug_printf("ssl_create_decompressor: inflateInit_() failed - %d\n", err);
2392 ssl_debug_printf("ssl_create_decompressor: unsupported compression method %d\n", decomp->compression);
2399 ssl_create_decoder(SslCipherSuite *cipher_suite, gint compression,
2400 guint8 *mk, guint8 *sk, guint8 *iv)
2405 dec = (SslDecoder *)wmem_alloc0(wmem_file_scope(), sizeof(SslDecoder));
2406 /* Find the SSLeay cipher */
2407 if(cipher_suite->enc!=ENC_NULL) {
2408 ssl_debug_printf("ssl_create_decoder CIPHER: %s\n", ciphers[cipher_suite->enc-0x30]);
2409 ciph=ssl_get_cipher_by_name(ciphers[cipher_suite->enc-0x30]);
2411 ssl_debug_printf("ssl_create_decoder CIPHER: %s\n", "NULL");
2415 ssl_debug_printf("ssl_create_decoder can't find cipher %s\n",
2416 ciphers[cipher_suite->enc > ENC_NULL ? ENC_NULL-0x30 : (cipher_suite->enc-0x30)]);
2420 /* init mac buffer: mac storage is embedded into decoder struct to save a
2421 memory allocation and waste samo more memory*/
2422 dec->cipher_suite=cipher_suite;
2423 dec->compression = compression;
2424 /* AEED ciphers don't have a MAC but need to keep the write IV instead */
2426 dec->write_iv.data = dec->_mac_key_or_write_iv;
2427 ssl_data_set(&dec->write_iv, iv, cipher_suite->block);
2429 dec->mac_key.data = dec->_mac_key_or_write_iv;
2430 ssl_data_set(&dec->mac_key, mk, ssl_cipher_suite_dig(cipher_suite)->len);
2433 dec->decomp = ssl_create_decompressor(compression);
2434 dec->flow = ssl_create_flow();
2437 ssl_cipher_cleanup(&dec->evp);
2439 if (ssl_cipher_init(&dec->evp,ciph,sk,iv,cipher_suite->mode) < 0) {
2440 ssl_debug_printf("ssl_create_decoder: can't create cipher id:%d mode:%d\n",
2441 ciph, cipher_suite->mode);
2445 ssl_debug_printf("decoder initialized (digest len %d)\n", ssl_cipher_suite_dig(cipher_suite)->len);
2451 ssl_generate_pre_master_secret(SslDecryptSession *ssl_session,
2452 guint32 length, tvbuff_t *tvb, guint32 offset,
2453 const gchar *ssl_psk, const gchar *keylog_filename)
2455 /* check for required session data */
2456 ssl_debug_printf("ssl_generate_pre_master_secret: found SSL_HND_CLIENT_KEY_EXCHG, state %X\n",
2457 ssl_session->state);
2458 if ((ssl_session->state & (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION)) !=
2459 (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION)) {
2460 ssl_debug_printf("ssl_generate_pre_master_secret: not enough data to generate key (required state %X)\n",
2461 (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION));
2465 if (ssl_session->cipher_suite.kex == KEX_PSK)
2467 /* calculate pre master secret*/
2468 StringInfo pre_master_secret;
2469 guint psk_len, pre_master_len;
2471 if (!ssl_psk || (ssl_psk[0] == 0)) {
2472 ssl_debug_printf("ssl_generate_pre_master_secret: can't find pre-shared-key\n");
2476 /* convert hex string into char*/
2477 if (!from_hex(&ssl_session->psk, ssl_psk, strlen(ssl_psk))) {
2478 ssl_debug_printf("ssl_generate_pre_master_secret: ssl.psk/dtls.psk contains invalid hex\n");
2482 psk_len = ssl_session->psk.data_len;
2483 if (psk_len >= (2 << 15)) {
2484 ssl_debug_printf("ssl_generate_pre_master_secret: ssl.psk/dtls.psk must not be larger than 2^15 - 1\n");
2489 pre_master_len = psk_len * 2 + 4;
2491 pre_master_secret.data = (guchar *)wmem_alloc(wmem_file_scope(), pre_master_len);
2492 pre_master_secret.data_len = pre_master_len;
2493 /* 2 bytes psk_len*/
2494 pre_master_secret.data[0] = psk_len >> 8;
2495 pre_master_secret.data[1] = psk_len & 0xFF;
2496 /* psk_len bytes times 0*/
2497 memset(&pre_master_secret.data[2], 0, psk_len);
2498 /* 2 bytes psk_len*/
2499 pre_master_secret.data[psk_len + 2] = psk_len >> 8;
2500 pre_master_secret.data[psk_len + 3] = psk_len & 0xFF;
2502 memcpy(&pre_master_secret.data[psk_len + 4], ssl_session->psk.data, psk_len);
2504 ssl_session->pre_master_secret.data = pre_master_secret.data;
2505 ssl_session->pre_master_secret.data_len = pre_master_len;
2506 /*ssl_debug_printf("pre master secret",&ssl->pre_master_secret);*/
2508 /* Remove the master secret if it was there.
2509 This forces keying material regeneration in
2510 case we're renegotiating */
2511 ssl_session->state &= ~(SSL_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
2512 ssl_session->state |= SSL_PRE_MASTER_SECRET;
2517 StringInfo encrypted_pre_master;
2519 guint encrlen, skip;
2523 /* get encrypted data, on tls1 we have to skip two bytes
2524 * (it's the encrypted len and should be equal to record len - 2)
2525 * in case of rsa1024 that would be 128 + 2 = 130; for psk not necessary
2527 if (ssl_session->cipher_suite.kex == KEX_RSA &&
2528 (ssl_session->session.version == SSL_VER_TLS || ssl_session->session.version == SSL_VER_TLSv1DOT1 ||
2529 ssl_session->session.version == SSL_VER_TLSv1DOT2 || ssl_session->session.version == SSL_VER_DTLS ||
2530 ssl_session->session.version == SSL_VER_DTLS1DOT2))
2532 encrlen = tvb_get_ntohs(tvb, offset);
2534 if (encrlen > length - 2)
2536 ssl_debug_printf("ssl_generate_pre_master_secret: wrong encrypted length (%d max %d)\n",
2541 encrypted_pre_master.data = (guchar *)wmem_alloc(wmem_file_scope(), encrlen);
2542 encrypted_pre_master.data_len = encrlen;
2543 tvb_memcpy(tvb, encrypted_pre_master.data, offset+skip, encrlen);
2545 if (ssl_session->private_key) {
2546 /* go with ssl key processessing; encrypted_pre_master
2547 * will be used for master secret store*/
2548 ret = ssl_decrypt_pre_master_secret(ssl_session, &encrypted_pre_master, ssl_session->private_key);
2552 ssl_debug_printf("ssl_generate_pre_master_secret: can't decrypt pre master secret\n");
2555 if (keylog_filename != NULL) {
2556 /* try to find the key in the key log */
2557 ret = ssl_keylog_lookup(ssl_session, keylog_filename, &encrypted_pre_master);
2566 ssl_generate_keyring_material(SslDecryptSession*ssl_session)
2568 StringInfo key_block;
2569 guint8 _iv_c[MAX_BLOCK_SIZE],_iv_s[MAX_BLOCK_SIZE];
2570 guint8 _key_c[MAX_KEY_SIZE],_key_s[MAX_KEY_SIZE];
2572 guint8 *ptr,*c_wk,*s_wk,*c_mk,*s_mk,*c_iv = _iv_c,*s_iv = _iv_s;
2574 /* check for enough info to proced */
2575 guint need_all = SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION;
2576 guint need_any = SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET;
2577 if (((ssl_session->state & need_all) != need_all) || ((ssl_session->state & need_any) == 0)) {
2578 ssl_debug_printf("ssl_generate_keyring_material not enough data to generate key "
2579 "(0x%02X required 0x%02X or 0x%02X)\n", ssl_session->state,
2580 need_all|SSL_MASTER_SECRET, need_all|SSL_PRE_MASTER_SECRET);
2584 /* if master_key is not yet generate, create it now*/
2585 if (!(ssl_session->state & SSL_MASTER_SECRET)) {
2586 ssl_debug_printf("ssl_generate_keyring_material:PRF(pre_master_secret)\n");
2587 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
2588 ssl_print_string("client random",&ssl_session->client_random);
2589 ssl_print_string("server random",&ssl_session->server_random);
2590 if (prf(ssl_session,&ssl_session->pre_master_secret,"master secret",
2591 &ssl_session->client_random,
2592 &ssl_session->server_random, &ssl_session->master_secret)) {
2593 ssl_debug_printf("ssl_generate_keyring_material can't generate master_secret\n");
2596 ssl_print_string("master secret",&ssl_session->master_secret);
2598 /* the pre-master secret has been 'consumend' so we must clear it now */
2599 ssl_session->state &= ~SSL_PRE_MASTER_SECRET;
2600 ssl_session->state |= SSL_MASTER_SECRET;
2603 /* Compute the key block. First figure out how much data we need*/
2604 needed=ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len*2;
2605 needed+=ssl_session->cipher_suite.bits / 4;
2606 if(ssl_session->cipher_suite.block>1)
2607 needed+=ssl_session->cipher_suite.block*2;
2609 key_block.data_len = needed;
2610 key_block.data = (guchar *)g_malloc(needed);
2611 ssl_debug_printf("ssl_generate_keyring_material sess key generation\n");
2612 if (prf(ssl_session,&ssl_session->master_secret,"key expansion",
2613 &ssl_session->server_random,&ssl_session->client_random,
2615 ssl_debug_printf("ssl_generate_keyring_material can't generate key_block\n");
2618 ssl_print_string("key expansion", &key_block);
2621 /* AEAD ciphers do not have a separate MAC */
2622 if (ssl_session->cipher_suite.mode == MODE_GCM ||
2623 ssl_session->cipher_suite.mode == MODE_CCM ||
2624 ssl_session->cipher_suite.mode == MODE_CCM_8) {
2627 c_mk=ptr; ptr+=ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len;
2628 s_mk=ptr; ptr+=ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len;
2631 c_wk=ptr; ptr+=ssl_session->cipher_suite.eff_bits/8;
2632 s_wk=ptr; ptr+=ssl_session->cipher_suite.eff_bits/8;
2634 if(ssl_session->cipher_suite.block>1){
2635 c_iv=ptr; ptr+=ssl_session->cipher_suite.block;
2636 s_iv=ptr; /*ptr+=ssl_session->cipher_suite.block;*/
2639 /* export ciphers work with a smaller key length */
2640 if (ssl_session->cipher_suite.eff_bits < ssl_session->cipher_suite.bits) {
2641 StringInfo iv_c,iv_s;
2642 StringInfo key_c,key_s;
2645 if(ssl_session->cipher_suite.block>1){
2647 /* We only have room for MAX_BLOCK_SIZE bytes IVs, but that's
2648 all we should need. This is a sanity check */
2649 if(ssl_session->cipher_suite.block>MAX_BLOCK_SIZE) {
2650 ssl_debug_printf("ssl_generate_keyring_material cipher suite block must be at most %d nut is %d\n",
2651 MAX_BLOCK_SIZE, ssl_session->cipher_suite.block);
2656 iv_c.data_len = ssl_session->cipher_suite.block;
2658 iv_s.data_len = ssl_session->cipher_suite.block;
2660 if(ssl_session->version_netorder==SSLV3_VERSION){
2661 ssl_debug_printf("ssl_generate_keyring_material ssl3_generate_export_iv\n");
2662 if (ssl3_generate_export_iv(&ssl_session->client_random,
2663 &ssl_session->server_random,&iv_c)) {
2664 ssl_debug_printf("ssl_generate_keyring_material can't generate sslv3 client iv\n");
2667 ssl_debug_printf("ssl_generate_keyring_material ssl3_generate_export_iv(2)\n");
2668 if (ssl3_generate_export_iv(&ssl_session->server_random,
2669 &ssl_session->client_random,&iv_s)) {
2670 ssl_debug_printf("ssl_generate_keyring_material can't generate sslv3 server iv\n");
2675 guint8 _iv_block[MAX_BLOCK_SIZE * 2];
2676 StringInfo iv_block;
2677 StringInfo key_null;
2680 key_null.data = &_key_null;
2681 key_null.data_len = 0;
2683 iv_block.data = _iv_block;
2684 iv_block.data_len = ssl_session->cipher_suite.block*2;
2686 ssl_debug_printf("ssl_generate_keyring_material prf(iv_block)\n");
2687 if(prf(ssl_session,&key_null, "IV block",
2688 &ssl_session->client_random,
2689 &ssl_session->server_random,&iv_block)) {
2690 ssl_debug_printf("ssl_generate_keyring_material can't generate tls31 iv block\n");
2694 memcpy(_iv_c,iv_block.data,ssl_session->cipher_suite.block);
2695 memcpy(_iv_s,iv_block.data+ssl_session->cipher_suite.block,
2696 ssl_session->cipher_suite.block);
2703 if (ssl_session->version_netorder==SSLV3_VERSION){
2706 ssl_debug_printf("ssl_generate_keyring_material MD5(client_random)\n");
2709 ssl_md5_update(&md5,c_wk,ssl_session->cipher_suite.eff_bits/8);
2710 ssl_md5_update(&md5,ssl_session->client_random.data,
2711 ssl_session->client_random.data_len);
2712 ssl_md5_update(&md5,ssl_session->server_random.data,
2713 ssl_session->server_random.data_len);
2714 ssl_md5_final(_key_c,&md5);
2715 ssl_md5_cleanup(&md5);
2719 ssl_debug_printf("ssl_generate_keyring_material MD5(server_random)\n");
2720 ssl_md5_update(&md5,s_wk,ssl_session->cipher_suite.eff_bits/8);
2721 ssl_md5_update(&md5,ssl_session->server_random.data,
2722 ssl_session->server_random.data_len);
2723 ssl_md5_update(&md5,ssl_session->client_random.data,
2724 ssl_session->client_random.data_len);
2725 ssl_md5_final(_key_s,&md5);
2726 ssl_md5_cleanup(&md5);
2730 key_c.data = _key_c;
2731 key_c.data_len = sizeof(_key_c);
2732 key_s.data = _key_s;
2733 key_s.data_len = sizeof(_key_s);
2736 k.data_len = ssl_session->cipher_suite.eff_bits/8;
2737 ssl_debug_printf("ssl_generate_keyring_material PRF(key_c)\n");
2738 if (prf(ssl_session,&k,"client write key",
2739 &ssl_session->client_random,
2740 &ssl_session->server_random, &key_c)) {
2741 ssl_debug_printf("ssl_generate_keyring_material can't generate tll31 server key \n");
2747 k.data_len = ssl_session->cipher_suite.eff_bits/8;
2748 ssl_debug_printf("ssl_generate_keyring_material PRF(key_s)\n");
2749 if(prf(ssl_session,&k,"server write key",
2750 &ssl_session->client_random,
2751 &ssl_session->server_random, &key_s)) {
2752 ssl_debug_printf("ssl_generate_keyring_material can't generate tll31 client key \n");
2759 /* show key material info */
2761 ssl_print_data("Client MAC key",c_mk,ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len);
2762 ssl_print_data("Server MAC key",s_mk,ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len);
2764 ssl_print_data("Client Write key",c_wk,ssl_session->cipher_suite.bits/8);
2765 ssl_print_data("Server Write key",s_wk,ssl_session->cipher_suite.bits/8);
2767 if(ssl_session->cipher_suite.block>1) {
2768 ssl_print_data("Client Write IV",c_iv,ssl_session->cipher_suite.block);
2769 ssl_print_data("Server Write IV",s_iv,ssl_session->cipher_suite.block);
2772 ssl_print_data("Client Write IV",c_iv,8);
2773 ssl_print_data("Server Write IV",s_iv,8);
2776 /* create both client and server ciphers*/
2777 ssl_debug_printf("ssl_generate_keyring_material ssl_create_decoder(client)\n");
2778 ssl_session->client_new = ssl_create_decoder(&ssl_session->cipher_suite, ssl_session->session.compression, c_mk, c_wk, c_iv);
2779 if (!ssl_session->client_new) {
2780 ssl_debug_printf("ssl_generate_keyring_material can't init client decoder\n");
2783 ssl_debug_printf("ssl_generate_keyring_material ssl_create_decoder(server)\n");
2784 ssl_session->server_new = ssl_create_decoder(&ssl_session->cipher_suite, ssl_session->session.compression, s_mk, s_wk, s_iv);
2785 if (!ssl_session->server_new) {
2786 ssl_debug_printf("ssl_generate_keyring_material can't init client decoder\n");
2790 ssl_debug_printf("ssl_generate_keyring_material: client seq %d, server seq %d\n",
2791 ssl_session->client_new->seq, ssl_session->server_new->seq);
2792 g_free(key_block.data);
2793 ssl_session->state |= SSL_HAVE_SESSION_KEY;
2797 g_free(key_block.data);
2802 ssl_change_cipher(SslDecryptSession *ssl_session, gboolean server)
2804 ssl_debug_printf("ssl_change_cipher %s\n", (server)?"SERVER":"CLIENT");
2806 ssl_session->server = ssl_session->server_new;
2807 ssl_session->server_new = NULL;
2809 ssl_session->client = ssl_session->client_new;
2810 ssl_session->client_new = NULL;
2815 ssl_decrypt_pre_master_secret(SslDecryptSession*ssl_session,
2816 StringInfo* encrypted_pre_master, SSL_PRIVATE_KEY *pk)
2820 if (!encrypted_pre_master)
2823 if(ssl_session->cipher_suite.kex == KEX_DH) {
2824 ssl_debug_printf("ssl_decrypt_pre_master_secret session uses DH (%d) key exchange, which is impossible to decrypt\n",
2827 } else if(ssl_session->cipher_suite.kex != KEX_RSA) {
2828 ssl_debug_printf("ssl_decrypt_pre_master_secret key exchange %d different from KEX_RSA (%d)\n",
2829 ssl_session->cipher_suite.kex, KEX_RSA);
2833 /* with tls key loading will fail if not rsa type, so no need to check*/
2834 ssl_print_string("pre master encrypted",encrypted_pre_master);
2835 ssl_debug_printf("ssl_decrypt_pre_master_secret:RSA_private_decrypt\n");
2836 i=ssl_private_decrypt(encrypted_pre_master->data_len,
2837 encrypted_pre_master->data, pk);
2840 ssl_debug_printf("ssl_decrypt_pre_master_secret wrong "
2841 "pre_master_secret length (%d, expected %d)\n", i, 48);
2845 /* the decrypted data has been written into the pre_master key buffer */
2846 ssl_session->pre_master_secret.data = encrypted_pre_master->data;
2847 ssl_session->pre_master_secret.data_len=48;
2848 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
2850 /* Remove the master secret if it was there.
2851 This forces keying material regeneration in
2852 case we're renegotiating */
2853 ssl_session->state &= ~(SSL_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
2854 ssl_session->state |= SSL_PRE_MASTER_SECRET;
2858 /* convert network byte order 32 byte number to right-aligned host byte order *
2860 static gint fmt_seq(guint32 num, guint8* buf)
2865 netnum=g_htonl(num);
2866 memcpy(buf+4,&netnum,4);
2872 tls_check_mac(SslDecoder*decoder, gint ct, gint ver, guint8* data,
2873 guint32 datalen, guint8* mac)
2878 guint8 buf[DIGEST_MAX_SIZE];
2881 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
2882 ssl_debug_printf("tls_check_mac mac type:%s md %d\n",
2883 ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
2885 if (ssl_hmac_init(&hm,decoder->mac_key.data,decoder->mac_key.data_len,md) != 0)
2888 /* hash sequence number */
2889 fmt_seq(decoder->seq,buf);
2893 ssl_hmac_update(&hm,buf,8);
2895 /* hash content type */
2897 ssl_hmac_update(&hm,buf,1);
2899 /* hash version,data length and data*/
2900 /* *((gint16*)buf) = g_htons(ver); */
2901 temp = g_htons(ver);
2902 memcpy(buf, &temp, 2);
2903 ssl_hmac_update(&hm,buf,2);
2905 /* *((gint16*)buf) = g_htons(datalen); */
2906 temp = g_htons(datalen);
2907 memcpy(buf, &temp, 2);
2908 ssl_hmac_update(&hm,buf,2);
2909 ssl_hmac_update(&hm,data,datalen);
2911 /* get digest and digest len*/
2913 ssl_hmac_final(&hm,buf,&len);
2914 ssl_hmac_cleanup(&hm);
2915 ssl_print_data("Mac", buf, len);
2916 if(memcmp(mac,buf,len))
2923 ssl3_check_mac(SslDecoder*decoder,int ct,guint8* data,
2924 guint32 datalen, guint8* mac)
2929 guint8 buf[64],dgst[20];
2933 pad_ct=(decoder->cipher_suite->dig==DIG_SHA)?40:48;
2935 /* get cipher used for digest comptuation */
2936 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
2937 if (ssl_md_init(&mc,md) !=0)
2940 /* do hash computation on data && padding */
2941 ssl_md_update(&mc,decoder->mac_key.data,decoder->mac_key.data_len);
2944 memset(buf,0x36,pad_ct);
2945 ssl_md_update(&mc,buf,pad_ct);
2947 /* hash sequence number */
2948 fmt_seq(decoder->seq,buf);
2950 ssl_md_update(&mc,buf,8);
2952 /* hash content type */
2954 ssl_md_update(&mc,buf,1);
2956 /* hash data length in network byte order and data*/
2957 /* *((gint16* )buf) = g_htons(datalen); */
2958 temp = g_htons(datalen);
2959 memcpy(buf, &temp, 2);
2960 ssl_md_update(&mc,buf,2);
2961 ssl_md_update(&mc,data,datalen);
2963 /* get partial digest */
2964 ssl_md_final(&mc,dgst,&len);
2965 ssl_md_cleanup(&mc);
2967 ssl_md_init(&mc,md);
2970 ssl_md_update(&mc,decoder->mac_key.data,decoder->mac_key.data_len);
2972 /* hash padding and partial digest*/
2973 memset(buf,0x5c,pad_ct);
2974 ssl_md_update(&mc,buf,pad_ct);
2975 ssl_md_update(&mc,dgst,len);
2977 ssl_md_final(&mc,dgst,&len);
2978 ssl_md_cleanup(&mc);
2980 if(memcmp(mac,dgst,len))
2987 dtls_check_mac(SslDecoder*decoder, gint ct,int ver, guint8* data,
2988 guint32 datalen, guint8* mac)
2993 guint8 buf[DIGEST_MAX_SIZE];
2996 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
2997 ssl_debug_printf("dtls_check_mac mac type:%s md %d\n",
2998 ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
3000 if (ssl_hmac_init(&hm,decoder->mac_key.data,decoder->mac_key.data_len,md) != 0)
3002 ssl_debug_printf("dtls_check_mac seq: %d epoch: %d\n",decoder->seq,decoder->epoch);
3003 /* hash sequence number */
3004 fmt_seq(decoder->seq,buf);
3005 buf[0]=decoder->epoch>>8;
3006 buf[1]=(guint8)decoder->epoch;
3008 ssl_hmac_update(&hm,buf,8);
3010 /* hash content type */
3012 ssl_hmac_update(&hm,buf,1);
3014 /* hash version,data length and data */
3015 temp = g_htons(ver);
3016 memcpy(buf, &temp, 2);
3017 ssl_hmac_update(&hm,buf,2);
3019 temp = g_htons(datalen);
3020 memcpy(buf, &temp, 2);
3021 ssl_hmac_update(&hm,buf,2);
3022 ssl_hmac_update(&hm,data,datalen);
3023 /* get digest and digest len */
3025 ssl_hmac_final(&hm,buf,&len);
3026 ssl_hmac_cleanup(&hm);
3027 ssl_print_data("Mac", buf, len);
3028 if(memcmp(mac,buf,len))
3036 ssl_decompress_record(SslDecompress* decomp, const guchar* in, guint inl, StringInfo* out_str, guint* outl)
3040 switch (decomp->compression) {
3041 case 1: /* DEFLATE */
3043 if (out_str->data_len < 16384) { /* maximal plain length */
3044 ssl_data_realloc(out_str, 16384);
3046 decomp->istream.next_in = (guchar*)in;
3047 decomp->istream.avail_in = inl;
3048 decomp->istream.next_out = out_str->data;
3049 decomp->istream.avail_out = out_str->data_len;
3051 err = inflate(&decomp->istream, Z_SYNC_FLUSH);
3053 ssl_debug_printf("ssl_decompress_record: inflate() failed - %d\n", err);
3056 *outl = out_str->data_len - decomp->istream.avail_out;
3059 ssl_debug_printf("ssl_decompress_record: unsupported compression method %d\n", decomp->compression);
3066 ssl_decompress_record(SslDecompress* decomp _U_, const guchar* in _U_, guint inl _U_, StringInfo* out_str _U_, guint* outl _U_)
3068 ssl_debug_printf("ssl_decompress_record: unsupported compression method %d\n", decomp->compression);
3074 ssl_decrypt_record(SslDecryptSession*ssl,SslDecoder* decoder, gint ct,
3075 const guchar* in, guint inl, StringInfo* comp_str, StringInfo* out_str, guint* outl)
3077 guint pad, worklen, uncomplen;
3080 ssl_debug_printf("ssl_decrypt_record ciphertext len %d\n", inl);
3081 ssl_print_data("Ciphertext",in, inl);
3083 /* ensure we have enough storage space for decrypted data */
3084 if (inl > out_str->data_len)
3086 ssl_debug_printf("ssl_decrypt_record: allocating %d bytes for decrypt data (old len %d)\n",
3087 inl + 32, out_str->data_len);
3088 ssl_data_realloc(out_str, inl + 32);
3091 /* RFC 6101/2246: SSLCipherText/TLSCipherText has two structures for types:
3092 * (notation: { unencrypted, [ encrypted ] })
3093 * GenericStreamCipher: { [content, mac] }
3094 * GenericBlockCipher: { IV (TLS 1.1+), [content, mac, padding, padding_len] }
3095 * RFC 5426 (TLS 1.2): TLSCipherText has additionally:
3096 * GenericAEADCipher: { nonce_explicit, [content] }
3097 * RFC 4347 (DTLS): based on TLS 1.1, only GenericBlockCipher is supported.
3098 * RFC 6347 (DTLS 1.2): based on TLS 1.2, includes GenericAEADCipher too.
3101 /* (TLS 1.1 and later, DTLS) Extract explicit IV for GenericBlockCipher */
3102 if (decoder->cipher_suite->mode == MODE_CBC) {
3103 switch (ssl->version_netorder) {
3104 case TLSV1DOT1_VERSION:
3105 case TLSV1DOT2_VERSION:
3106 case DTLSV1DOT0_VERSION:
3107 case DTLSV1DOT2_VERSION:
3108 case DTLSV1DOT0_VERSION_NOT:
3109 if ((gint)inl < decoder->cipher_suite->block) {
3110 ssl_debug_printf("ssl_decrypt_record failed: input %d has no space for IV %d\n",
3111 inl, decoder->cipher_suite->block);
3114 pad = gcry_cipher_setiv(decoder->evp, in, decoder->cipher_suite->block);
3116 ssl_debug_printf("ssl_decrypt_record failed: failed to set IV: %s %s\n",
3117 gcry_strsource (pad), gcry_strerror (pad));
3120 inl -= decoder->cipher_suite->block;
3121 in += decoder->cipher_suite->block;
3126 /* Nonce for GenericAEADCipher */
3127 if (decoder->cipher_suite->mode == MODE_GCM ||
3128 decoder->cipher_suite->mode == MODE_CCM ||
3129 decoder->cipher_suite->mode == MODE_CCM_8) {
3130 /* 4 bytes write_iv, 8 bytes explicit_nonce, 4 bytes counter */
3131 guchar gcm_nonce[16] = { 0 };
3133 if ((gint)inl < SSL_EX_NONCE_LEN_GCM) {
3134 ssl_debug_printf("ssl_decrypt_record failed: input %d has no space for nonce %d\n",
3135 inl, SSL_EX_NONCE_LEN_GCM);
3139 if (decoder->cipher_suite->mode == MODE_GCM) {
3140 memcpy(gcm_nonce, decoder->write_iv.data, decoder->write_iv.data_len); /* salt */
3141 memcpy(gcm_nonce + decoder->write_iv.data_len, in, SSL_EX_NONCE_LEN_GCM);
3142 /* NIST SP 800-38D, sect. 7.2 says that the 32-bit counter part starts
3143 * at 1, and gets incremented before passing to the block cipher. */
3144 gcm_nonce[4 + SSL_EX_NONCE_LEN_GCM + 3] = 2;
3145 } else { /* MODE_CCM and MODE_CCM_8 */
3146 /* The nonce for CCM and GCM are the same, but the nonce is used as input
3147 * in the CCM algorithm described in RFC 3610. The nonce generated here is
3148 * the one from RFC 3610 sect 2.3. Encryption. */
3149 /* Flags: (L-1) ; L = 16 - 1 - nonceSize */
3150 gcm_nonce[0] = 3 - 1;
3152 memcpy(gcm_nonce + 1, decoder->write_iv.data, decoder->write_iv.data_len); /* salt */
3153 memcpy(gcm_nonce + 1 + decoder->write_iv.data_len, in, SSL_EX_NONCE_LEN_GCM);
3154 gcm_nonce[4 + SSL_EX_NONCE_LEN_GCM + 3] = 1;
3157 pad = gcry_cipher_setctr (decoder->evp, gcm_nonce, sizeof (gcm_nonce));
3159 ssl_debug_printf("ssl_decrypt_record failed: failed to set CTR: %s %s\n",
3160 gcry_strsource (pad), gcry_strerror (pad));
3163 inl -= SSL_EX_NONCE_LEN_GCM;
3164 in += SSL_EX_NONCE_LEN_GCM;
3168 if ((pad = ssl_cipher_decrypt(&decoder->evp, out_str->data, out_str->data_len, in, inl))!= 0) {
3169 ssl_debug_printf("ssl_decrypt_record failed: ssl_cipher_decrypt: %s %s\n", gcry_strsource (pad),
3170 gcry_strerror (pad));
3174 ssl_print_data("Plaintext", out_str->data, inl);
3177 /* RFC 5116 sect 5.1/5.3: AES128/256 GCM/CCM uses 16 bytes for auth tag
3178 * RFC 6655 sect 6.1: AEAD_AES_128_CCM uses 16 bytes for auth tag */
3179 if (decoder->cipher_suite->mode == MODE_GCM ||
3180 decoder->cipher_suite->mode == MODE_CCM) {
3182 ssl_debug_printf("ssl_decrypt_record failed: missing tag, work %d\n", worklen);
3185 /* XXX - validate auth tag */
3188 /* RFC 6655 sect 6.1: AEAD_AES_128_CCM_8 uses 8 bytes for auth tag */
3189 if (decoder->cipher_suite->mode == MODE_CCM_8) {
3191 ssl_debug_printf("ssl_decrypt_record failed: missing tag, work %d\n", worklen);
3194 /* XXX - validate auth tag */
3198 /* strip padding for GenericBlockCipher */
3199 if (decoder->cipher_suite->mode == MODE_CBC) {
3200 pad=out_str->data[inl-1];
3201 if (worklen <= pad) {
3202 ssl_debug_printf("ssl_decrypt_record failed: padding %d too large for work %d\n",
3207 ssl_debug_printf("ssl_decrypt_record found padding %d final len %d\n",
3211 /* MAC for GenericStreamCipher and GenericBlockCipher */
3212 if (decoder->cipher_suite->mode == MODE_STREAM ||
3213 decoder->cipher_suite->mode == MODE_CBC) {
3214 if (ssl_cipher_suite_dig(decoder->cipher_suite)->len > (gint)worklen) {
3215 ssl_debug_printf("ssl_decrypt_record wrong record len/padding outlen %d\n work %d\n",*outl, worklen);
3218 worklen-=ssl_cipher_suite_dig(decoder->cipher_suite)->len;
3219 mac = out_str->data + worklen;
3220 } else /* if (decoder->cipher_suite->mode == MODE_GCM) */ {
3221 /* GenericAEADCipher has no MAC */
3225 /* Now check the MAC */
3226 ssl_debug_printf("checking mac (len %d, version %X, ct %d seq %d)\n",
3227 worklen, ssl->version_netorder, ct, decoder->seq);
3228 if(ssl->version_netorder==SSLV3_VERSION){
3229 if(ssl3_check_mac(decoder,ct,out_str->data,worklen,mac) < 0) {
3230 if(ssl_ignore_mac_failed) {
3231 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
3234 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
3239 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
3242 else if(ssl->version_netorder==TLSV1_VERSION || ssl->version_netorder==TLSV1DOT1_VERSION || ssl->version_netorder==TLSV1DOT2_VERSION){
3243 if(tls_check_mac(decoder,ct,ssl->version_netorder,out_str->data,worklen,mac)< 0) {
3244 if(ssl_ignore_mac_failed) {
3245 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
3248 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
3253 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
3256 else if(ssl->version_netorder==DTLSV1DOT0_VERSION ||
3257 ssl->version_netorder==DTLSV1DOT2_VERSION ||
3258 ssl->version_netorder==DTLSV1DOT0_VERSION_NOT){
3259 /* Try rfc-compliant mac first, and if failed, try old openssl's non-rfc-compliant mac */
3260 if(dtls_check_mac(decoder,ct,ssl->version_netorder,out_str->data,worklen,mac)>= 0) {
3261 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
3263 else if(tls_check_mac(decoder,ct,TLSV1_VERSION,out_str->data,worklen,mac)>= 0) {
3264 ssl_debug_printf("ssl_decrypt_record: dtls rfc-compliant mac failed, but old openssl's non-rfc-compliant mac ok\n");
3266 else if(ssl_ignore_mac_failed) {
3267 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
3270 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
3278 if (decoder->compression > 0) {
3279 ssl_debug_printf("ssl_decrypt_record: compression method %d\n", decoder->compression);
3280 ssl_data_copy(comp_str, out_str);
3281 ssl_print_data("Plaintext compressed", comp_str->data, worklen);
3282 if (!decoder->decomp) {
3283 ssl_debug_printf("decrypt_ssl3_record: no decoder available\n");
3286 if (ssl_decompress_record(decoder->decomp, comp_str->data, worklen, out_str, &uncomplen) < 0) return -1;
3287 ssl_print_data("Plaintext uncompressed", out_str->data, uncomplen);
3295 static SSL_PRIVATE_KEY*
3296 ssl_privkey_to_sexp(struct gnutls_x509_privkey_int* priv_key)
3298 gnutls_datum_t rsa_datum[RSA_PARS]; /* m, e, d, p, q, u */
3300 gcry_sexp_t rsa_priv_key = NULL;
3304 unsigned char buf_keyid[32];
3307 gcry_mpi_t* rsa_params = g_malloc(sizeof(gcry_mpi_t)*RSA_PARS);
3309 gcry_mpi_t rsa_params[RSA_PARS];
3312 buf_len = sizeof(buf_keyid);
3313 ret = gnutls_x509_privkey_get_key_id(priv_key, 0, buf_keyid, &buf_len);
3315 ssl_debug_printf( "gnutls_x509_privkey_get_key_id(ssl_pkey, 0, buf_keyid, &buf_len) - %s\n", gnutls_strerror(ret));
3317 ssl_debug_printf( "Private key imported: KeyID %s\n", bytes_to_ep_str_punct(buf_keyid, (int) buf_len, ':'));
3320 /* RSA get parameter */
3321 if (gnutls_x509_privkey_export_rsa_raw(priv_key,
3327 &rsa_datum[5]) != 0) {
3328 ssl_debug_printf("ssl_load_key: can't export rsa param (is a rsa private key file ?!?)\n");
3335 /* convert each rsa parameter to mpi format*/
3336 for(i=0; i<RSA_PARS; i++) {
3337 if (gcry_mpi_scan(&rsa_params[i], GCRYMPI_FMT_USG, rsa_datum[i].data, rsa_datum[i].size,&tmp_size) != 0) {
3338 ssl_debug_printf("ssl_load_key: can't convert m rsa param to int (size %d)\n", rsa_datum[i].size);
3346 /* libgcrypt expects p < q, and gnutls might not return it as such, depending on gnutls version and its crypto backend */
3347 if (gcry_mpi_cmp(rsa_params[3], rsa_params[4]) > 0)
3349 ssl_debug_printf("ssl_load_key: swapping p and q parameters and recomputing u\n");
3350 gcry_mpi_swap(rsa_params[3], rsa_params[4]);
3351 gcry_mpi_invm(rsa_params[5], rsa_params[3], rsa_params[4]);
3354 if (gcry_sexp_build( &rsa_priv_key, NULL,
3355 "(private-key(rsa((n%m)(e%m)(d%m)(p%m)(q%m)(u%m))))", rsa_params[0],
3356 rsa_params[1], rsa_params[2], rsa_params[3], rsa_params[4],
3357 rsa_params[5]) != 0) {
3358 ssl_debug_printf("ssl_load_key: can't build rsa private key s-exp\n");
3368 for (i=0; i< 6; i++)
3369 gcry_mpi_release(rsa_params[i]);
3370 return rsa_priv_key;
3376 ssl_load_key(FILE* fp)
3378 /* gnutls makes our work much harder, since we have to work internally with
3379 * s-exp formatted data, but PEM loader exports only in "gnutls_datum_t"
3380 * format, and a datum -> s-exp convertion function does not exist.
3382 gnutls_x509_privkey_t priv_key;
3388 Ssl_private_key_t *private_key = (Ssl_private_key_t *)g_malloc0(sizeof(Ssl_private_key_t));
3390 /* init private key data*/
3391 gnutls_x509_privkey_init(&priv_key);
3393 /* compute file size and load all file contents into a datum buffer*/
3394 if (fseek(fp, 0, SEEK_END) < 0) {
3395 ssl_debug_printf("ssl_load_key: can't fseek file\n");
3396 g_free(private_key);
3399 if ((size = ftell(fp)) < 0) {
3400 ssl_debug_printf("ssl_load_key: can't ftell file\n");
3401 g_free(private_key);
3404 if (fseek(fp, 0, SEEK_SET) < 0) {
3405 ssl_debug_printf("ssl_load_key: can't re-fseek file\n");
3406 g_free(private_key);
3409 key.data = (unsigned char *)g_malloc(size);
3410 key.size = (int)size;
3411 bytes = (guint) fread(key.data, 1, key.size, fp);
3412 if (bytes < key.size) {
3413 ssl_debug_printf("ssl_load_key: can't read from file %d bytes, got %d\n",
3415 g_free(private_key);
3420 /* import PEM data*/
3421 if ((ret = gnutls_x509_privkey_import(priv_key, &key, GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS) {
3422 ssl_debug_printf("ssl_load_key: can't import pem data: %s\n", gnutls_strerror(ret));
3423 g_free(private_key);
3428 if (gnutls_x509_privkey_get_pk_algorithm(priv_key) != GNUTLS_PK_RSA) {
3429 ssl_debug_printf("ssl_load_key: private key public key algorithm isn't RSA\n");
3430 g_free(private_key);
3437 private_key->x509_pkey = priv_key;
3438 private_key->sexp_pkey = ssl_privkey_to_sexp(priv_key);
3439 if ( !private_key->sexp_pkey ) {
3440 g_free(private_key);
3447 BAGTYPE(gnutls_pkcs12_bag_type_t x) {
3449 case GNUTLS_BAG_EMPTY: return "Empty";
3450 case GNUTLS_BAG_PKCS8_ENCRYPTED_KEY: return "PKCS#8 Encrypted key";
3451 case GNUTLS_BAG_PKCS8_KEY: return "PKCS#8 Key";
3452 case GNUTLS_BAG_CERTIFICATE: return "Certificate";
3453 case GNUTLS_BAG_CRL: return "CRL";
3454 case GNUTLS_BAG_ENCRYPTED: return "Encrypted";
3455 case GNUTLS_BAG_UNKNOWN: return "Unknown";
3456 default: return "<undefined>";
3461 * Load a RSA private key from a PKCS#12 file.
3462 * @param fp the file that contains the key data.
3463 * @param cert_passwd password to decrypt the PKCS#12 file.
3464 * @param[out] err error message upon failure; NULL upon success.
3465 * @return a pointer to the loaded key on success; NULL upon failure.
3467 static Ssl_private_key_t *
3468 ssl_load_pkcs12(FILE* fp, const gchar *cert_passwd, char** err) {
3473 gnutls_datum_t data;
3474 gnutls_pkcs12_bag_t bag = NULL;
3475 gnutls_pkcs12_bag_type_t bag_type;
3476 size_t len, buf_len;
3477 static char buf_name[256];
3478 static char buf_email[128];
3479 unsigned char buf_keyid[32];
3481 gnutls_pkcs12_t ssl_p12 = NULL;
3482 gnutls_x509_crt_t ssl_cert = NULL;
3483 gnutls_x509_privkey_t ssl_pkey = NULL;
3485 Ssl_private_key_t *private_key = (Ssl_private_key_t *)g_malloc0(sizeof(Ssl_private_key_t));
3489 data.data = (unsigned char *)g_malloc(rest);
3492 while ((len = fread(p, 1, rest, fp)) > 0) {
3497 data.data = (unsigned char *)g_realloc(data.data, data.size + rest);
3498 p = data.data + data.size;
3503 ssl_debug_printf("%d bytes read\n", data.size);
3505 *err = g_strdup("Error during certificate reading.");
3506 ssl_debug_printf("%s\n", *err);
3507 g_free(private_key);
3512 ret = gnutls_pkcs12_init(&ssl_p12);
3514 *err = g_strdup_printf("gnutls_pkcs12_init(&st_p12) - %s", gnutls_strerror(ret));
3515 ssl_debug_printf("%s\n", *err);
3516 g_free(private_key);
3521 /* load PKCS#12 in DER or PEM format */
3522 ret = gnutls_pkcs12_import(ssl_p12, &data, GNUTLS_X509_FMT_DER, 0);
3524 *err = g_strdup_printf("could not load PKCS#12 in DER format: %s", gnutls_strerror(ret));
3525 ssl_debug_printf("%s\n", *err);
3528 ret = gnutls_pkcs12_import(ssl_p12, &data, GNUTLS_X509_FMT_PEM, 0);
3530 *err = g_strdup_printf("could not load PKCS#12 in PEM format: %s", gnutls_strerror(ret));
3531 ssl_debug_printf("%s\n", *err);
3538 g_free(private_key);
3542 ssl_debug_printf( "PKCS#12 imported\n");
3544 for (i=0; ret==0; i++) {
3546 if (bag) { gnutls_pkcs12_bag_deinit(bag); bag = NULL; }
3548 ret = gnutls_pkcs12_bag_init(&bag);
3549 if (ret < 0) continue;
3551 ret = gnutls_pkcs12_get_bag(ssl_p12, i, bag);
3552 if (ret < 0) continue;
3554 for (j=0; ret==0 && j<gnutls_pkcs12_bag_get_count(bag); j++) {
3556 bag_type = gnutls_pkcs12_bag_get_type(bag, j);
3557 if (bag_type >= GNUTLS_BAG_UNKNOWN) continue;
3558 ssl_debug_printf( "Bag %d/%d: %s\n", i, j, BAGTYPE(bag_type));
3559 if (bag_type == GNUTLS_BAG_ENCRYPTED) {
3560 ret = gnutls_pkcs12_bag_decrypt(bag, cert_passwd);
3562 bag_type = gnutls_pkcs12_bag_get_type(bag, j);
3563 if (bag_type >= GNUTLS_BAG_UNKNOWN) continue;
3564 ssl_debug_printf( "Bag %d/%d decrypted: %s\n", i, j, BAGTYPE(bag_type));
3568 ret = gnutls_pkcs12_bag_get_data(bag, j, &data);
3569 if (ret < 0) continue;
3573 case GNUTLS_BAG_CERTIFICATE:
3575 ret = gnutls_x509_crt_init(&ssl_cert);
3577 *err = g_strdup_printf("gnutls_x509_crt_init(&ssl_cert) - %s", gnutls_strerror(ret));
3578 ssl_debug_printf("%s\n", *err);
3579 g_free(private_key);
3583 ret = gnutls_x509_crt_import(ssl_cert, &data, GNUTLS_X509_FMT_DER);
3585 *err = g_strdup_printf("gnutls_x509_crt_import(ssl_cert, &data, GNUTLS_X509_FMT_DER) - %s", gnutls_strerror(ret));
3586 ssl_debug_printf("%s\n", *err);
3587 g_free(private_key);
3591 buf_len = sizeof(buf_name);
3592 ret = gnutls_x509_crt_get_dn_by_oid(ssl_cert, GNUTLS_OID_X520_COMMON_NAME, 0, 0, buf_name, &buf_len);
3593 if (ret < 0) { g_strlcpy(buf_name, "<ERROR>", 256); }
3594 buf_len = sizeof(buf_email);
3595 ret = gnutls_x509_crt_get_dn_by_oid(ssl_cert, GNUTLS_OID_PKCS9_EMAIL, 0, 0, buf_email, &buf_len);
3596 if (ret < 0) { g_strlcpy(buf_email, "<ERROR>", 128); }
3598 buf_len = sizeof(buf_keyid);
3599 ret = gnutls_x509_crt_get_key_id(ssl_cert, 0, buf_keyid, &buf_len);
3600 if (ret < 0) { g_strlcpy(buf_keyid, "<ERROR>", 32); }
3602 private_key->x509_cert = ssl_cert;
3603 ssl_debug_printf( "Certificate imported: %s <%s>, KeyID %s\n", buf_name, buf_email, bytes_to_ep_str(buf_keyid, (int) buf_len));
3606 case GNUTLS_BAG_PKCS8_KEY:
3607 case GNUTLS_BAG_PKCS8_ENCRYPTED_KEY:
3609 ret = gnutls_x509_privkey_init(&ssl_pkey);
3611 *err = g_strdup_printf("gnutls_x509_privkey_init(&ssl_pkey) - %s", gnutls_strerror(ret));
3612 ssl_debug_printf("%s\n", *err);
3613 g_free(private_key);
3616 ret = gnutls_x509_privkey_import_pkcs8(ssl_pkey, &data, GNUTLS_X509_FMT_DER, cert_passwd,
3617 (bag_type==GNUTLS_BAG_PKCS8_KEY) ? GNUTLS_PKCS_PLAIN : 0);
3619 *err = g_strdup_printf("Can not decrypt private key - %s", gnutls_strerror(ret));
3620 ssl_debug_printf("%s\n", *err);
3621 g_free(private_key);
3625 if (gnutls_x509_privkey_get_pk_algorithm(ssl_pkey) != GNUTLS_PK_RSA) {
3626 *err = g_strdup("ssl_load_pkcs12: private key public key algorithm isn't RSA");
3627 ssl_debug_printf("%s\n", *err);
3628 g_free(private_key);
3632 private_key->x509_pkey = ssl_pkey;
3633 private_key->sexp_pkey = ssl_privkey_to_sexp(ssl_pkey);
3634 if ( !private_key->sexp_pkey ) {
3635 *err = g_strdup("ssl_load_pkcs12: could not create sexp_pkey");
3636 ssl_debug_printf("%s\n", *err);
3637 g_free(private_key);
3651 void ssl_free_key(Ssl_private_key_t* key)
3655 for (i=0; i< 6; i++)
3656 gcry_mpi_release(key->sexp_pkey[i]);
3658 gcry_sexp_release(key->sexp_pkey);
3661 if (!key->x509_cert)
3662 gnutls_x509_crt_deinit (key->x509_cert);
3664 if (!key->x509_pkey)
3665 gnutls_x509_privkey_deinit(key->x509_pkey);
3667 g_free((Ssl_private_key_t*)key);
3671 ssl_find_private_key(SslDecryptSession *ssl_session, GHashTable *key_hash, GTree* associations, packet_info *pinfo) {
3673 char ip_addr_any[] = {0,0,0,0};
3676 Ssl_private_key_t * private_key;
3682 /* we need to know which side of the conversation is speaking */
3683 if (ssl_packet_from_server(ssl_session, associations, pinfo)) {
3684 dummy.addr = pinfo->src;
3685 dummy.port = port = pinfo->srcport;
3687 dummy.addr = pinfo->dst;
3688 dummy.port = port = pinfo->destport;
3690 addr_string = address_to_str(NULL, &dummy.addr);
3691 ssl_debug_printf("ssl_find_private_key server %s:%u\n",
3692 addr_string, dummy.port);
3693 wmem_free(NULL, addr_string);
3695 if (g_hash_table_size(key_hash) == 0) {
3696 ssl_debug_printf("ssl_find_private_key: no keys found\n");
3699 ssl_debug_printf("ssl_find_private_key: testing %i keys\n",
3700 g_hash_table_size(key_hash));
3703 /* try to retrieve private key for this service. Do it now 'cause pinfo
3704 * is not always available
3705 * Note that with HAVE_LIBGNUTLS undefined private_key is allways 0
3706 * and thus decryption never engaged*/
3709 ssl_session->private_key = 0;
3710 private_key = (Ssl_private_key_t *)g_hash_table_lookup(key_hash, &dummy);
3713 ssl_debug_printf("ssl_find_private_key can't find private key for this server! Try it again with universal port 0\n");
3716 private_key = (Ssl_private_key_t *)g_hash_table_lookup(key_hash, &dummy);
3720 ssl_debug_printf("ssl_find_private_key can't find private key for this server (universal port)! Try it again with universal address 0.0.0.0\n");
3722 dummy.addr.type = AT_IPv4;
3724 dummy.addr.data = ip_addr_any;
3727 private_key = (Ssl_private_key_t *)g_hash_table_lookup(key_hash, &dummy);
3731 ssl_debug_printf("ssl_find_private_key can't find private key for this server! Try it again with universal address 0.0.0.0 and universal port 0\n");
3734 private_key = (Ssl_private_key_t *)g_hash_table_lookup(key_hash, &dummy);
3738 ssl_debug_printf("ssl_find_private_key can't find any private key!\n");
3740 ssl_session->private_key = private_key->sexp_pkey;
3747 ssl_debug_printf("gnutls version: %s\n", gnutls_check_version(NULL));
3750 #else /* defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT) */
3751 /* no libgnutl: dummy operation to keep interface consistent*/
3758 ssl_load_key(FILE* fp)
3760 ssl_debug_printf("ssl_load_key: impossible without gnutls. fp %p\n",fp);
3765 ssl_load_pkcs12(FILE* fp, const gchar *cert_passwd _U_, char** err) {
3767 ssl_debug_printf("ssl_load_pkcs12: impossible without gnutls. fp %p\n",fp);
3772 ssl_free_key(Ssl_private_key_t* key _U_)
3777 ssl_find_private_key(SslDecryptSession *ssl_session _U_, GHashTable *key_hash _U_, GTree* associations _U_, packet_info *pinfo _U_)
3782 ssl_find_cipher(int num,SslCipherSuite* cs)
3784 ssl_debug_printf("ssl_find_cipher: dummy without gnutls. num %d cs %p\n",
3789 ssl_generate_pre_master_secret(SslDecryptSession *ssl_session _U_,
3790 guint32 length _U_, tvbuff_t *tvb _U_, guint32 offset _U_,
3791 const gchar *ssl_psk _U_, const gchar *keylog_filename _U_)
3793 ssl_debug_printf("ssl_generate_pre_master_secret: impossible without gnutls.\n");
3797 ssl_generate_keyring_material(SslDecryptSession*ssl)
3799 ssl_debug_printf("ssl_generate_keyring_material: impossible without gnutls. ssl %p\n",
3804 ssl_change_cipher(SslDecryptSession *ssl_session, gboolean server)
3806 ssl_debug_printf("ssl_change_cipher %s: makes no sense without gnutls. ssl %p\n",
3807 (server)?"SERVER":"CLIENT", ssl_session);
3811 ssl_decrypt_pre_master_secret(SslDecryptSession* ssl_session,
3812 StringInfo* encrypted_pre_master, SSL_PRIVATE_KEY *pk)
3814 ssl_debug_printf("ssl_decrypt_pre_master_secret: impossible without gnutls."
3815 " ssl %p encrypted_pre_master %p pk %p\n", ssl_session,
3816 encrypted_pre_master, pk);
3821 ssl_decrypt_record(SslDecryptSession*ssl, SslDecoder* decoder, gint ct,
3822 const guchar* in, guint inl, StringInfo* comp_str _U_, StringInfo* out, guint* outl)
3824 ssl_debug_printf("ssl_decrypt_record: impossible without gnutls. ssl %p"
3825 "decoder %p ct %d, in %p inl %d out %p outl %p\n", ssl, decoder, ct,
3826 in, inl, out, outl);
3831 ssl_cipher_setiv(SSL_CIPHER_CTX *cipher _U_, guchar* iv _U_, gint iv_len _U_)
3833 ssl_debug_printf("ssl_cipher_setiv: impossible without gnutls.\n");
3837 #endif /* defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT) */
3839 /* get ssl data for this session. if no ssl data is found allocate a new one*/
3841 ssl_session_init(SslDecryptSession* ssl_session)
3843 ssl_debug_printf("ssl_session_init: initializing ptr %p size %" G_GSIZE_MODIFIER "u\n",
3844 (void *)ssl_session, sizeof(SslDecryptSession));
3846 ssl_session->master_secret.data = ssl_session->_master_secret;
3847 ssl_session->session_id.data = ssl_session->_session_id;
3848 ssl_session->client_random.data = ssl_session->_client_random;
3849 ssl_session->server_random.data = ssl_session->_server_random;
3850 ssl_session->session_ticket.data = NULL;
3851 ssl_session->session_ticket.data_len = 0;
3852 ssl_session->master_secret.data_len = 48;
3853 ssl_session->server_data_for_iv.data_len = 0;
3854 ssl_session->server_data_for_iv.data = ssl_session->_server_data_for_iv;
3855 ssl_session->client_data_for_iv.data_len = 0;
3856 ssl_session->client_data_for_iv.data = ssl_session->_client_data_for_iv;
3857 ssl_session->app_data_segment.data=NULL;
3858 ssl_session->app_data_segment.data_len=0;
3859 SET_ADDRESS(&ssl_session->srv_addr, AT_NONE, 0, NULL);
3860 ssl_session->srv_ptype = PT_NONE;
3861 ssl_session->srv_port = 0;
3865 ssl_set_server(SslDecryptSession* ssl, address *addr, port_type ptype, guint32 port)
3867 SE_COPY_ADDRESS(&ssl->srv_addr, addr);
3868 ssl->srv_ptype = ptype;
3869 ssl->srv_port = port;
3872 /* Hash Functions for TLS/DTLS sessions table and private keys table*/
3874 ssl_equal (gconstpointer v, gconstpointer v2)
3876 const StringInfo *val1;
3877 const StringInfo *val2;
3878 val1 = (const StringInfo *)v;
3879 val2 = (const StringInfo *)v2;
3881 if (val1->data_len == val2->data_len &&
3882 !memcmp(val1->data, val2->data, val2->data_len)) {
3889 ssl_hash (gconstpointer v)
3892 const StringInfo* id;
3895 id = (const StringInfo*) v;
3897 /* id and id->data are mallocated in ssl_save_session(). As such 'data'
3898 * should be aligned for any kind of access (for example as a guint as
3899 * is done below). The intermediate void* cast is to prevent "cast
3900 * increases required alignment of target type" warnings on CPUs (such
3901 * as SPARCs) that do not allow misaligned memory accesses.
3903 cur = (const guint*)(void*) id->data;
3905 for (l=4; (l < id->data_len); l+=4, cur++)
3906 hash = hash ^ (*cur);
3912 ssl_private_key_equal (gconstpointer v, gconstpointer v2)
3914 const SslService *val1;
3915 const SslService *val2;
3916 val1 = (const SslService *)v;
3917 val2 = (const SslService *)v2;
3919 if ((val1->port == val2->port) &&
3920 ! CMP_ADDRESS(&val1->addr, &val2->addr)) {
3927 ssl_private_key_hash (gconstpointer v)
3929 const SslService *key;
3930 guint l, hash, len ;
3933 key = (const SslService *)v;
3935 len = key->addr.len;
3937 cur = (const guint*) key->addr.data;
3939 for (l=4; (l<len); l+=4, cur++)
3940 hash = hash ^ (*cur);
3945 /* private key table entries have a scope 'larger' then packet capture,
3946 * so we can't relay on se_alloc** function */
3948 ssl_private_key_free(gpointer id, gpointer key, gpointer dummy _U_)
3952 ssl_free_key((Ssl_private_key_t*) key);
3956 /* handling of association between tls/dtls ports and clear text protocol */
3958 ssl_association_add(GTree* associations, dissector_handle_t handle, guint port, const gchar *protocol, gboolean tcp, gboolean from_key_list)
3961 SslAssociation* assoc;
3962 assoc = (SslAssociation *)g_malloc(sizeof(SslAssociation));
3965 assoc->ssl_port = port;
3966 assoc->info=g_strdup(protocol);
3967 assoc->handle = find_dissector(protocol);
3968 assoc->from_key_list = from_key_list;
3970 ssl_debug_printf("association_add %s port %d protocol %s handle %p\n",
3971 (assoc->tcp)?"TCP":"UDP", port, protocol, (void *)(assoc->handle));
3974 if (!assoc->handle) {
3975 ssl_debug_printf("association_add could not find handle for protocol '%s', try to find 'data' dissector\n", protocol);
3976 assoc->handle = find_dissector("data");
3979 if (!assoc->handle) {
3980 fprintf(stderr, "association_add() could not find handle for protocol:%s\n",protocol);
3984 dissector_add_uint("tcp.port", port, handle);
3986 dissector_add_uint("udp.port", port, handle);
3988 g_tree_insert(associations, assoc, assoc);
3990 dissector_add_uint("sctp.port", port, handle);
3995 ssl_association_remove(GTree* associations, SslAssociation *assoc)
3997 ssl_debug_printf("ssl_association_remove removing %s %u - %s handle %p\n",
3998 (assoc->tcp)?"TCP":"UDP", assoc->ssl_port, assoc->info, (void *)(assoc->handle));
4000 dissector_delete_uint((assoc->tcp)?"tcp.port":"udp.port", assoc->ssl_port, assoc->handle);
4002 g_free(assoc->info);
4004 g_tree_remove(associations, assoc);
4009 ssl_association_cmp(gconstpointer a, gconstpointer b)
4011 const SslAssociation *assoc_a=(const SslAssociation *)a, *assoc_b=(const SslAssociation *)b;
4012 if (assoc_a->tcp != assoc_b->tcp) return (assoc_a->tcp)?1:-1;
4013 return assoc_a->ssl_port - assoc_b->ssl_port;
4017 ssl_association_find(GTree * associations, guint port, gboolean tcp)
4019 register SslAssociation* ret;
4020 SslAssociation assoc_tmp;
4022 assoc_tmp.tcp = tcp;
4023 assoc_tmp.ssl_port = port;
4024 ret = (SslAssociation *)g_tree_lookup(associations, &assoc_tmp);
4026 ssl_debug_printf("association_find: %s port %d found %p\n", (tcp)?"TCP":"UDP", port, (void *)ret);
4031 ssl_assoc_from_key_list(gpointer key _U_, gpointer data, gpointer user_data)
4033 if (((SslAssociation*)data)->from_key_list)
4034 wmem_stack_push((wmem_stack_t*)user_data, data);
4039 ssl_packet_from_server(SslDecryptSession* ssl, GTree* associations, packet_info *pinfo)
4042 if (ssl && (ssl->srv_ptype != PT_NONE)) {
4043 ret = (ssl->srv_ptype == pinfo->ptype) && (ssl->srv_port == pinfo->srcport) && ADDRESSES_EQUAL(&ssl->srv_addr, &pinfo->src);
4045 ret = ssl_association_find(associations, pinfo->srcport, pinfo->ptype == PT_TCP) != 0;
4048 ssl_debug_printf("packet_from_server: is from server - %s\n", (ret)?"TRUE":"FALSE");
4052 /* add to packet data a copy of the specified real data */
4054 ssl_add_record_info(gint proto, packet_info *pinfo, guchar* data, gint data_len, gint record_id)
4060 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4063 pi = (SslPacketInfo *)wmem_alloc0(wmem_file_scope(), sizeof(SslPacketInfo));
4064 p_add_proto_data(wmem_file_scope(), pinfo, proto, 0, pi);
4067 real_data = (guchar *)wmem_alloc(wmem_file_scope(), data_len);
4068 memcpy(real_data, data, data_len);
4070 rec = (SslRecordInfo *)wmem_alloc(wmem_file_scope(), sizeof(SslRecordInfo));
4071 rec->id = record_id;
4072 rec->real_data = real_data;
4073 rec->data_len = data_len;
4075 /* head insertion */
4076 rec->next= pi->handshake_data;
4077 pi->handshake_data = rec;
4080 /* search in packet data for the specified id; return a newly created tvb for the associated data */
4082 ssl_get_record_info(tvbuff_t *parent_tvb, int proto, packet_info *pinfo, gint record_id)
4086 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4091 for (rec = pi->handshake_data; rec; rec = rec->next)
4092 if (rec->id == record_id)
4093 /* link new real_data_tvb with a parent tvb so it is freed when frame dissection is complete */
4094 return tvb_new_child_real_data(parent_tvb, rec->real_data, rec->data_len, rec->data_len);
4100 ssl_add_data_info(gint proto, packet_info *pinfo, guchar* data, gint data_len, gint key, SslFlow *flow)
4102 SslDataInfo *rec, **prec;
4105 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4108 pi = (SslPacketInfo *)wmem_alloc0(wmem_file_scope(), sizeof(SslPacketInfo));
4109 p_add_proto_data(wmem_file_scope(), pinfo, proto, 0, pi);
4112 rec = (SslDataInfo *)wmem_alloc(wmem_file_scope(), sizeof(SslDataInfo)+data_len);
4114 rec->plain_data.data = (guchar*)(rec + 1);
4115 memcpy(rec->plain_data.data, data, data_len);
4116 rec->plain_data.data_len = data_len;
4119 rec->seq = flow->byte_seq;
4120 rec->nxtseq = flow->byte_seq + data_len;
4122 flow->byte_seq += data_len;
4127 prec = &pi->appl_data;
4128 while (*prec) prec = &(*prec)->next;
4131 ssl_debug_printf("ssl_add_data_info: new data inserted data_len = %d, seq = %u, nxtseq = %u\n",
4132 rec->plain_data.data_len, rec->seq, rec->nxtseq);
4136 ssl_get_data_info(int proto, packet_info *pinfo, gint key)
4140 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4142 if (!pi) return NULL;
4144 rec = pi->appl_data;
4146 if (rec->key == key) return rec;
4153 /* initialize/reset per capture state data (ssl sessions cache) */
4155 ssl_common_init(GHashTable **session_hash, StringInfo *decrypted_data, StringInfo *compressed_data)
4158 g_hash_table_destroy(*session_hash);
4159 *session_hash = g_hash_table_new(ssl_hash, ssl_equal);
4161 g_free(decrypted_data->data);
4162 ssl_data_alloc(decrypted_data, 32);
4164 g_free(compressed_data->data);
4165 ssl_data_alloc(compressed_data, 32);
4168 /* parse ssl related preferences (private keys and ports association strings) */
4170 ssl_parse_key_list(const ssldecrypt_assoc_t * uats, GHashTable *key_hash, GTree* associations, dissector_handle_t handle, gboolean tcp)
4172 SslService* service;
4173 Ssl_private_key_t* private_key, *tmp_private_key;
4175 guint32 addr_data[4];
4177 address_type addr_type[2] = { AT_IPv4, AT_IPv6 };
4178 gchar* address_string;
4180 /* try to load keys file first */
4181 fp = ws_fopen(uats->keyfile, "rb");
4183 fprintf(stderr, "Can't open file %s\n",uats->keyfile);
4187 for (at = 0; at < 2; at++) {
4188 memset(addr_data, 0, sizeof(addr_data));
4191 /* any: IPv4 or IPv6 wildcard */
4192 /* anyipv4: IPv4 wildcard */
4193 /* anyipv6: IPv6 wildcard */
4195 if(addr_type[at] == AT_IPv4) {
4196 if (strcmp(uats->ipaddr, "any") == 0 || strcmp(uats->ipaddr, "anyipv4") == 0 ||
4197 get_host_ipaddr(uats->ipaddr, &addr_data[0])) {
4200 } else { /* AT_IPv6 */
4201 if(strcmp(uats->ipaddr, "any") == 0 || strcmp(uats->ipaddr, "anyipv6") == 0 ||
4202 get_host_ipaddr6(uats->ipaddr, (struct e_in6_addr *) addr_data)) {
4211 /* reset the data pointer for the second iteration */
4214 if ((gint)strlen(uats->password) == 0) {
4215 private_key = ssl_load_key(fp);
4218 private_key = ssl_load_pkcs12(fp, uats->password, &err);
4220 fprintf(stderr, "%s\n", err);
4226 fprintf(stderr,"Can't load private key from %s\n", uats->keyfile);
4231 service = (SslService *)g_malloc(sizeof(SslService) + addr_len);
4232 service->addr.type = addr_type[at];
4233 service->addr.len = addr_len;
4234 service->addr.data = ((guchar*)service) + sizeof(SslService);
4235 memcpy((void*)service->addr.data, addr_data, addr_len);
4237 if(strcmp(uats->port,"start_tls")==0) {
4240 service->port = atoi(uats->port);
4244 * This gets called outside any dissection scope, so we have to
4245 * use a NULL scope and free it ourselves.
4247 address_string = address_to_str(NULL, &service->addr);
4248 ssl_debug_printf("ssl_init %s addr '%s' (%s) port '%d' filename '%s' password(only for p12 file) '%s'\n",
4249 (addr_type[at] == AT_IPv4) ? "IPv4" : "IPv6", uats->ipaddr, address_string,
4250 service->port, uats->keyfile, uats->password);
4251 wmem_free(NULL, address_string);
4253 ssl_debug_printf("ssl_init private key file %s successfully loaded.\n", uats->keyfile);
4255 /* if item exists, remove first */
4256 tmp_private_key = (Ssl_private_key_t *)g_hash_table_lookup(key_hash, service);
4257 if (tmp_private_key) {
4258 g_hash_table_remove(key_hash, service);
4259 ssl_free_key(tmp_private_key);
4262 g_hash_table_insert(key_hash, service, private_key);
4264 ssl_association_add(associations, handle, service->port, uats->protocol, tcp, TRUE);
4270 /* store master secret into session data cache */
4272 ssl_save_session(SslDecryptSession* ssl, GHashTable *session_hash)
4274 /* allocate stringinfo chunks for session id and master secret data*/
4275 StringInfo* session_id;
4276 StringInfo* master_secret;
4279 if (ssl->session_id.data_len == 0) {
4280 ssl_debug_printf("ssl_save_session SessionID is empty!\n");
4285 for (i = 0; i < ssl->master_secret.data_len; i++)
4286 ms |= ssl->master_secret.data[i];
4288 ssl_debug_printf("%s master secret is empty!\n", __func__);
4292 session_id = (StringInfo *)wmem_alloc0(wmem_file_scope(), sizeof(StringInfo) + ssl->session_id.data_len);
4293 master_secret = (StringInfo *)wmem_alloc0(wmem_file_scope(), 48 + sizeof(StringInfo));
4295 master_secret->data = ((guchar*)master_secret+sizeof(StringInfo));
4297 /* ssl_hash() depends on session_id->data being aligned for guint access
4298 * so be careful in changing how it is allocated.
4300 session_id->data = ((guchar*)session_id+sizeof(StringInfo));
4302 ssl_data_set(session_id, ssl->session_id.data, ssl->session_id.data_len);
4303 ssl_data_set(master_secret, ssl->master_secret.data, ssl->master_secret.data_len);
4304 g_hash_table_insert(session_hash, session_id, master_secret);
4305 ssl_print_string("ssl_save_session stored session id", session_id);
4306 ssl_print_string("ssl_save_session stored master secret", master_secret);
4310 ssl_restore_session(SslDecryptSession* ssl, GHashTable *session_hash)
4314 if (ssl->session_id.data_len == 0) {
4315 ssl_debug_printf("ssl_restore_session Cannot restore using an empty SessionID\n");
4319 ms = (StringInfo *)g_hash_table_lookup(session_hash, &ssl->session_id);
4322 ssl_debug_printf("ssl_restore_session can't find stored session\n");
4325 ssl_data_set(&ssl->master_secret, ms->data, ms->data_len);
4326 ssl->state |= SSL_MASTER_SECRET;
4327 ssl_debug_printf("ssl_restore_session master key retrieved\n");
4331 /* store master secret into session data cache */
4333 ssl_save_session_ticket(SslDecryptSession* ssl, GHashTable *session_hash)
4335 /* allocate stringinfo chunks for session id and master secret data*/
4336 StringInfo* session_ticket;
4337 StringInfo* master_secret;
4340 if (ssl->session_ticket.data_len == 0) {
4341 ssl_debug_printf("ssl_save_session_ticket - session ticket is empty!\n");
4346 for (i = 0; i < ssl->master_secret.data_len; i++)
4347 ms |= ssl->master_secret.data[i];
4349 ssl_debug_printf("%s master secret is empty!\n", __func__);
4353 session_ticket = (StringInfo *)wmem_alloc0(wmem_file_scope(), sizeof(StringInfo) + ssl->session_ticket.data_len);
4354 master_secret = (StringInfo *)wmem_alloc0(wmem_file_scope(), 48 + sizeof(StringInfo));
4356 master_secret->data = ((guchar*)master_secret+sizeof(StringInfo));
4358 /* ssl_hash() depends on session_id->data being aligned for guint access
4359 * so be careful in changing how it is allocated.
4361 session_ticket->data = ((guchar*)session_ticket+sizeof(StringInfo));
4363 ssl_data_set(session_ticket, ssl->session_ticket.data, ssl->session_ticket.data_len);
4364 ssl_data_set(master_secret, ssl->master_secret.data, ssl->master_secret.data_len);
4365 g_hash_table_insert(session_hash, session_ticket, master_secret);
4366 ssl_print_string("ssl_save_session_ticket stored session_ticket", session_ticket);
4367 ssl_print_string("ssl_save_session_ticket stored master secret", master_secret);
4371 ssl_restore_session_ticket(SslDecryptSession* ssl, GHashTable *session_hash)
4375 if (ssl->session_ticket.data_len == 0) {
4376 ssl_debug_printf("ssl_restore_session_ticket Cannot restore using an empty session ticket\n");
4380 ms = (StringInfo *)g_hash_table_lookup(session_hash, &ssl->session_ticket);
4383 ssl_debug_printf("ssl_restore_session_ticket can't find stored session ticket\n");
4386 ssl_data_set(&ssl->master_secret, ms->data, ms->data_len);
4387 ssl->state |= SSL_MASTER_SECRET;
4388 ssl_debug_printf("ssl_restore_session_ticket master key retrieved\n");
4392 /* Should be called when all parameters are ready (after ChangeCipherSpec), and
4393 * the decoder should be attempted to be initialized. */
4395 ssl_finalize_decryption(SslDecryptSession *ssl, GHashTable *session_hash,
4396 const char *keylog_filename)
4398 ssl_debug_printf("%s state = 0x%02X\n", __func__, ssl->state);
4399 if (ssl->state & SSL_HAVE_SESSION_KEY) {
4400 ssl_debug_printf(" session key already available, nothing to do.\n");
4404 /* for decryption, there needs to be a master secret (which can be derived
4405 * from pre-master secret). If missing, try to pick a master key from cache
4406 * (an earlier packet in the capture). If that fails, try to find the master
4407 * key in the keylog file. */
4408 if (!(ssl->state & (SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET)) &&
4409 !ssl_restore_session(ssl, session_hash) &&
4410 !ssl_restore_session_ticket(ssl, session_hash)) {
4411 /* If we failed to find the previous session, we may still
4412 * have the master secret in the key log. */
4413 ssl_debug_printf("Cannot restore session, trying key file\n");
4414 if (ssl_keylog_lookup(ssl, keylog_filename, NULL) < 0) {
4415 ssl_debug_printf(" cannot find master secret in keylog file either\n");
4418 ssl_debug_printf(" found master secret in keylog file\n");
4422 if (ssl_generate_keyring_material(ssl) < 0) {
4423 ssl_debug_printf("%s can't generate keyring material\n", __func__);
4426 ssl_save_session(ssl, session_hash);
4427 ssl_debug_printf("%s session keys successfully generated\n", __func__);
4431 ssl_is_valid_content_type(guint8 type)
4433 switch ((ContentType) type) {
4434 case SSL_ID_CHG_CIPHER_SPEC:
4436 case SSL_ID_HANDSHAKE:
4437 case SSL_ID_APP_DATA:
4438 case SSL_ID_HEARTBEAT:
4445 ssl_is_valid_handshake_type(guint8 hs_type, gboolean is_dtls)
4447 switch ((HandshakeType) hs_type) {
4448 case SSL_HND_HELLO_VERIFY_REQUEST:
4449 /* hello_verify_request is DTLS-only */
4452 case SSL_HND_HELLO_REQUEST:
4453 case SSL_HND_CLIENT_HELLO:
4454 case SSL_HND_SERVER_HELLO:
4455 case SSL_HND_NEWSESSION_TICKET:
4456 case SSL_HND_CERTIFICATE:
4457 case SSL_HND_SERVER_KEY_EXCHG:
4458 case SSL_HND_CERT_REQUEST:
4459 case SSL_HND_SVR_HELLO_DONE:
4460 case SSL_HND_CERT_VERIFY:
4461 case SSL_HND_CLIENT_KEY_EXCHG:
4462 case SSL_HND_FINISHED:
4463 case SSL_HND_CERT_URL:
4464 case SSL_HND_CERT_STATUS:
4465 case SSL_HND_SUPPLEMENTAL_DATA:
4466 case SSL_HND_ENCRYPTED_EXTS:
4472 static const unsigned int kRSAMasterSecretLength = 48; /* RFC5246 8.1 */
4474 /* ssl_keylog_parse_session_id parses, from |line|, a string that looks like:
4475 * RSA Session-ID:<hex session id> Master-Key:<hex TLS master secret>.
4477 * It returns TRUE iff the session id matches |ssl_session| and the master
4478 * secret is correctly extracted. */
4480 ssl_keylog_parse_session_id(const char* line,
4481 SslDecryptSession* ssl_session)
4483 gsize len = strlen(line);
4486 if (ssl_session->session_id.data_len == 0)
4489 if (len < 15 || memcmp(line, "RSA Session-ID:", 15) != 0)
4494 if (len < ssl_session->session_id.data_len*2)
4497 for (i = 0; i < ssl_session->session_id.data_len; i++) {
4498 if (from_hex_char(line[2*i]) != (ssl_session->session_id.data[i] >> 4) ||
4499 from_hex_char(line[2*i+1]) != (ssl_session->session_id.data[i] & 15)) {
4500 ssl_debug_printf(" line does not match session id\n");
4508 if (len != 12 + kRSAMasterSecretLength*2 ||
4509 memcmp(line, " Master-Key:", 12) != 0) {
4515 if (!from_hex(&ssl_session->master_secret, line, len))
4517 ssl_session->state &= ~(SSL_PRE_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
4518 ssl_session->state |= SSL_MASTER_SECRET;
4519 ssl_debug_printf("found master secret in key log via RSA Session-ID\n");
4523 /* ssl_keylog_parse_client_random parses, from |line|, a string that looks like:
4524 * CLIENT_RANDOM <hex client_random> <hex TLS master secret>.
4526 * It returns TRUE iff the client_random matches |ssl_session| and the master
4527 * secret is correctly extracted. */
4529 ssl_keylog_parse_client_random(const char* line,
4530 SslDecryptSession* ssl_session)
4532 static const unsigned int kTLSRandomSize = 32; /* RFC5246 A.6 */
4533 gsize len = strlen(line);
4536 if (len < 14 || memcmp(line, "CLIENT_RANDOM ", 14) != 0)
4541 if (len < kTLSRandomSize*2 ||
4542 ssl_session->client_random.data_len != kTLSRandomSize) {
4546 for (i = 0; i < kTLSRandomSize; i++) {
4547 if (from_hex_char(line[2*i]) != (ssl_session->client_random.data[i] >> 4) ||
4548 from_hex_char(line[2*i+1]) != (ssl_session->client_random.data[i] & 15)) {
4549 ssl_debug_printf(" line does not match client random\n");
4554 line += 2*kTLSRandomSize;
4555 len -= 2*kTLSRandomSize;
4557 if (len != 1 + kRSAMasterSecretLength*2 || line[0] != ' ')
4562 if (!from_hex(&ssl_session->master_secret, line, len))
4564 ssl_session->state &= ~(SSL_PRE_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
4565 ssl_session->state |= SSL_MASTER_SECRET;
4566 ssl_debug_printf("found master secret in key log via CLIENT_RANDOM\n");
4570 /* ssl_keylog_parse_session_id parses, from |line|, a string that looks like:
4571 * RSA <hex, 8-bytes of encrypted pre-master secret> <hex pre-master secret>.
4573 * It returns TRUE iff the session id matches |ssl_session| and the master
4574 * secret is correctly extracted. */
4576 ssl_keylog_parse_rsa_premaster(const char* line,
4577 SslDecryptSession* ssl_session,
4578 StringInfo* encrypted_pre_master)
4580 static const unsigned int kRSAPremasterLength = 48; /* RFC5246 7.4.7.1 */
4581 gsize len = strlen(line);
4584 if (encrypted_pre_master == NULL)
4587 if (encrypted_pre_master->data_len < 8)
4590 if (len < 4 || memcmp(line, "RSA ", 4) != 0)
4598 for (i = 0; i < 8; i++) {
4599 if (from_hex_char(line[2*i]) != (encrypted_pre_master->data[i] >> 4) ||
4600 from_hex_char(line[2*i+1]) != (encrypted_pre_master->data[i] & 15)) {
4601 ssl_debug_printf(" line does not match encrypted pre-master secret");
4609 if (len != 1 + kRSAPremasterLength*2 || line[0] != ' ')
4614 if (!from_hex(&ssl_session->pre_master_secret, line, len))
4616 ssl_session->state &= ~(SSL_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
4617 ssl_session->state |= SSL_PRE_MASTER_SECRET;
4618 ssl_debug_printf("found pre-master secret in key log\n");
4624 ssl_keylog_lookup(SslDecryptSession* ssl_session,
4625 const gchar* ssl_keylog_filename,
4626 StringInfo* encrypted_pre_master) {
4630 if (!ssl_keylog_filename)
4633 ssl_debug_printf("trying to use SSL keylog in %s\n", ssl_keylog_filename);
4635 ssl_keylog = ws_fopen(ssl_keylog_filename, "r");
4637 ssl_debug_printf("failed to open SSL keylog\n");
4641 /* The format of the file is a series of records with one of the following formats:
4643 * Where xxxx are the first 8 bytes of the encrypted pre-master secret (hex-encoded)
4644 * Where yyyy is the cleartext pre-master secret (hex-encoded)
4645 * (this is the original format introduced with bug 4349)
4647 * - "RSA Session-ID:xxxx Master-Key:yyyy"
4648 * Where xxxx is the SSL session ID (hex-encoded)
4649 * Where yyyy is the cleartext master secret (hex-encoded)
4650 * (added to support openssl s_client Master-Key output)
4651 * This is somewhat is a misnomer because there's nothing RSA specific
4654 * - "CLIENT_RANDOM xxxx yyyy"
4655 * Where xxxx is the client_random from the ClientHello (hex-encoded)
4656 * Where yyy is the cleartext master secret (hex-encoded)
4657 * (This format allows non-RSA SSL connections to be decrypted, i.e.
4661 char buf[512], *line;
4664 line = fgets(buf, sizeof(buf), ssl_keylog);
4668 bytes_read = strlen(line);
4669 /* fgets includes the \n at the end of the line. */
4670 if (bytes_read > 0) {
4671 line[bytes_read - 1] = 0;
4674 if (bytes_read > 0 && line[bytes_read - 1] == '\r') {
4675 line[bytes_read - 1] = 0;
4679 ssl_debug_printf(" checking keylog line: %s\n", line);
4681 if (ssl_keylog_parse_session_id(line, ssl_session) ||
4682 ssl_keylog_parse_rsa_premaster(line, ssl_session,
4683 encrypted_pre_master) ||
4684 ssl_keylog_parse_client_random(line, ssl_session)) {
4688 ssl_debug_printf(" line does not match\n");
4696 #ifdef SSL_DECRYPT_DEBUG
4698 static FILE* ssl_debug_file=NULL;
4701 ssl_set_debug(const gchar* name)
4703 static gint debug_file_must_be_closed;
4706 debug_file_must_be_closed = 0;
4707 use_stderr = name?(strcmp(name, SSL_DEBUG_USE_STDERR) == 0):0;
4709 if (debug_file_must_be_closed)
4710 fclose(ssl_debug_file);
4712 ssl_debug_file = stderr;
4713 else if (!name || (strcmp(name, "") ==0))
4714 ssl_debug_file = NULL;
4716 ssl_debug_file = ws_fopen(name, "w");
4717 if (!use_stderr && ssl_debug_file)
4718 debug_file_must_be_closed = 1;
4720 ssl_debug_printf("Wireshark SSL debug log \n\n");
4724 ssl_debug_flush(void)
4727 fflush(ssl_debug_file);
4731 ssl_debug_printf(const gchar* fmt, ...)
4735 if (!ssl_debug_file)
4739 vfprintf(ssl_debug_file, fmt, ap);
4744 ssl_print_data(const gchar* name, const guchar* data, size_t len)
4747 if (!ssl_debug_file)
4749 fprintf(ssl_debug_file,"%s[%d]:\n",name, (int) len);
4750 for (i=0; i<len; i+=16) {
4751 fprintf(ssl_debug_file,"| ");
4752 for (j=i, k=0; k<16 && j<len; ++j, ++k)
4753 fprintf(ssl_debug_file,"%.2x ",data[j]);
4755 fprintf(ssl_debug_file," ");
4756 fputc('|', ssl_debug_file);
4757 for (j=i, k=0; k<16 && j<len; ++j, ++k) {
4759 if (!g_ascii_isprint(c) || (c=='\t')) c = '.';
4760 fputc(c, ssl_debug_file);
4763 fputc(' ', ssl_debug_file);
4764 fprintf(ssl_debug_file,"|\n");
4769 ssl_print_string(const gchar* name, const StringInfo* data)
4771 ssl_print_data(name, data->data, data->data_len);
4773 #endif /* SSL_DECRYPT_DEBUG */
4775 /* checks for SSL and DTLS UAT key list fields */
4778 ssldecrypt_uat_fld_ip_chk_cb(void* r _U_, const char* p, guint len _U_, const void* u1 _U_, const void* u2 _U_, const char** err)
4780 if (!p || strlen(p) == 0u) {
4781 *err = ep_strdup_printf("No IP address given.");
4790 ssldecrypt_uat_fld_port_chk_cb(void* r _U_, const char* p, guint len _U_, const void* u1 _U_, const void* u2 _U_, const char** err)
4792 if (!p || strlen(p) == 0u) {
4793 *err = ep_strdup_printf("No Port given.");
4797 if (strcmp(p, "start_tls") != 0){
4798 const gint i = atoi(p);
4799 if (i < 0 || i > 65535) {
4800 *err = ep_strdup_printf("Invalid port given.");
4810 ssldecrypt_uat_fld_protocol_chk_cb(void* r _U_, const char* p, guint len _U_, const void* u1 _U_, const void* u2 _U_, const char** err)
4812 if (!p || strlen(p) == 0u) {
4813 *err = ep_strdup_printf("No protocol given.");
4817 if (!find_dissector(p)) {
4818 *err = ep_strdup_printf("Could not find dissector for: '%s'\nValid dissectors are:\n%s", p, ssl_association_info());
4827 ssldecrypt_uat_fld_fileopen_chk_cb(void* r _U_, const char* p, guint len _U_, const void* u1 _U_, const void* u2 _U_, const char** err)
4831 if (!p || strlen(p) == 0u) {
4832 *err = ep_strdup_printf("No filename given.");
4835 if (ws_stat64(p, &st) != 0) {
4836 *err = ep_strdup_printf("File '%s' does not exist or access is denied.", p);
4846 ssldecrypt_uat_fld_password_chk_cb(void* r _U_, const char* p, guint len _U_, const void* u1 _U_, const void* u2 _U_, const char ** err)
4848 ssldecrypt_assoc_t* f = (ssldecrypt_assoc_t *)r;
4851 if (p && (strlen(p) > 0u)) {
4852 fp = ws_fopen(f->keyfile, "rb");
4855 if (!ssl_load_pkcs12(fp, p, &msg)) {
4857 *err = ep_strdup_printf("Could not load PKCS#12 key file: %s", msg);
4864 *err = ep_strdup_printf("Leave this field blank if the keyfile is not PKCS#12.");
4874 /* dissect a list of hash algorithms, return the number of bytes dissected
4875 this is used for the signature algorithms extension and for the
4876 TLS1.2 certificate request */
4878 ssl_dissect_hash_alg_list(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
4879 guint32 offset, guint16 len)
4881 guint32 offset_start;
4882 proto_tree *subtree, *alg_tree;
4885 offset_start = offset;
4889 ti = proto_tree_add_none_format(tree, hf->hf.hs_sig_hash_algs, tvb,
4891 "Signature Hash Algorithms (%u algorithm%s)",
4892 len / 2, plurality(len / 2, "", "s"));
4893 subtree = proto_item_add_subtree(ti, hf->ett.hs_sig_hash_algs);
4896 proto_tree_add_text(tree, tvb, offset, 2,
4897 "Invalid Signature Hash Algorithm length: %d", len);
4898 return offset-offset_start;
4902 ti = proto_tree_add_item(subtree, hf->hf.hs_sig_hash_alg,
4903 tvb, offset, 2, ENC_BIG_ENDIAN);
4904 alg_tree = proto_item_add_subtree(ti, hf->ett.hs_sig_hash_alg);
4906 proto_tree_add_item(alg_tree, hf->hf.hs_sig_hash_hash,
4907 tvb, offset, 1, ENC_BIG_ENDIAN);
4908 proto_tree_add_item(alg_tree, hf->hf.hs_sig_hash_sig,
4909 tvb, offset+1, 1, ENC_BIG_ENDIAN);
4914 return offset-offset_start;
4918 ssl_dissect_hnd_hello_ext_sig_hash_algs(ssl_common_dissect_t *hf, tvbuff_t *tvb,
4919 proto_tree *tree, guint32 offset, guint32 ext_len)
4921 guint16 sh_alg_length;
4924 sh_alg_length = tvb_get_ntohs(tvb, offset);
4925 proto_tree_add_uint(tree, hf->hf.hs_sig_hash_alg_len,
4926 tvb, offset, 2, sh_alg_length);
4928 if (ext_len < 2 || sh_alg_length != ext_len - 2) {
4929 /* ERROR: sh_alg_length must be 2 less than ext_len */
4933 ret = ssl_dissect_hash_alg_list(hf, tvb, tree, offset, sh_alg_length);
4941 ssl_dissect_hnd_hello_ext_alpn(ssl_common_dissect_t *hf, tvbuff_t *tvb,
4942 proto_tree *tree, guint32 offset, guint32 ext_len)
4944 guint16 alpn_length;
4946 proto_tree *alpn_tree;
4949 alpn_length = tvb_get_ntohs(tvb, offset);
4950 if (ext_len < 2 || alpn_length != ext_len - 2) {
4951 /* ERROR: alpn_length must be 2 less than ext_len */
4954 proto_tree_add_item(tree, hf->hf.hs_ext_alpn_len,
4955 tvb, offset, 2, ENC_BIG_ENDIAN);
4958 ti = proto_tree_add_item(tree, hf->hf.hs_ext_alpn_list,
4959 tvb, offset, alpn_length, ENC_NA);
4960 alpn_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_alpn);
4962 while (alpn_length > 0) {
4963 name_length = tvb_get_guint8(tvb, offset);
4964 proto_tree_add_item(alpn_tree, hf->hf.hs_ext_alpn_str_len,
4965 tvb, offset, 1, ENC_NA);
4968 proto_tree_add_item(alpn_tree, hf->hf.hs_ext_alpn_str,
4969 tvb, offset, name_length, ENC_ASCII|ENC_NA);
4970 offset += name_length;
4971 alpn_length -= name_length;
4978 ssl_dissect_hnd_hello_ext_npn(ssl_common_dissect_t *hf, tvbuff_t *tvb,
4979 proto_tree *tree, guint32 offset, guint32 ext_len)
4982 proto_tree *npn_tree;
4988 npn_tree = proto_tree_add_subtree(tree, tvb, offset, ext_len, hf->ett.hs_ext_npn, NULL, "Next Protocol Negotiation");
4990 while (ext_len > 0) {
4991 npn_length = tvb_get_guint8(tvb, offset);
4992 proto_tree_add_item(npn_tree, hf->hf.hs_ext_npn_str_len,
4993 tvb, offset, 1, ENC_NA);
4997 if (npn_length > 0) {
4998 tvb_ensure_bytes_exist(tvb, offset, npn_length);
4999 proto_tree_add_item(npn_tree, hf->hf.hs_ext_npn_str,
5000 tvb, offset, npn_length, ENC_ASCII|ENC_NA);
5001 offset += npn_length;
5002 ext_len -= npn_length;
5010 ssl_dissect_hnd_hello_ext_reneg_info(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5011 proto_tree *tree, guint32 offset, guint32 ext_len)
5013 guint8 reneg_info_length;
5014 proto_tree *reneg_info_tree;
5020 reneg_info_tree = proto_tree_add_subtree(tree, tvb, offset, ext_len, hf->ett.hs_ext_reneg_info, NULL, "Renegotiation Info extension");
5022 reneg_info_length = tvb_get_guint8(tvb, offset);
5023 proto_tree_add_item(reneg_info_tree, hf->hf.hs_ext_reneg_info_len,
5024 tvb, offset, 1, ENC_NA);
5027 if (reneg_info_length > 0) {
5028 tvb_ensure_bytes_exist(tvb, offset, reneg_info_length);
5029 proto_tree_add_text(reneg_info_tree, tvb, offset, reneg_info_length, "Renegotiation Info");
5030 offset += reneg_info_length;
5037 ssl_dissect_hnd_hello_ext_server_name(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5038 proto_tree *tree, guint32 offset, guint32 ext_len)
5040 guint16 server_name_length;
5041 proto_tree *server_name_tree;
5048 server_name_tree = proto_tree_add_subtree(tree, tvb, offset, ext_len, hf->ett.hs_ext_server_name, NULL, "Server Name Indication extension");
5050 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name_list_len,
5051 tvb, offset, 2, ENC_BIG_ENDIAN);
5055 while (ext_len > 0) {
5056 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name_type,
5057 tvb, offset, 1, ENC_NA);
5061 server_name_length = tvb_get_ntohs(tvb, offset);
5062 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name_len,
5063 tvb, offset, 2, ENC_BIG_ENDIAN);
5067 if (server_name_length > 0) {
5068 tvb_ensure_bytes_exist(tvb, offset, server_name_length);
5069 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name,
5070 tvb, offset, server_name_length, ENC_ASCII|ENC_NA);
5071 offset += server_name_length;
5072 ext_len -= server_name_length;
5079 ssl_dissect_hnd_hello_ext_padding(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5080 proto_tree *tree, guint32 offset, guint32 ext_len)
5082 guint8 padding_length;
5083 proto_tree *padding_tree;
5090 ti = proto_tree_add_item(tree, hf->hf.hs_ext_padding_data, tvb, offset, ext_len, ENC_NA);
5091 padding_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_padding);
5094 proto_tree_add_item(padding_tree, hf->hf.hs_ext_padding_len, tvb, offset, 2, ENC_NA);
5095 padding_length = tvb_get_guint8(tvb, offset);
5098 proto_tree_add_item(padding_tree, hf->hf.hs_ext_padding_data, tvb, offset, padding_length, ENC_NA);
5099 offset += padding_length;
5105 ssl_dissect_hnd_hello_ext_session_ticket(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5106 proto_tree *tree, guint32 offset, guint32 ext_len, gboolean is_client, SslDecryptSession *ssl)
5108 if(is_client && ssl && ext_len != 0)
5110 /*save the ticket on the ssl opaque so that we can use it as key on server hello */
5111 ssl->session_ticket.data = (guchar*)wmem_realloc(wmem_file_scope(),
5112 ssl->session_ticket.data, ext_len);
5113 tvb_memcpy(tvb,ssl->session_ticket.data, offset, ext_len);
5114 ssl->session_ticket.data_len = ext_len;
5116 proto_tree_add_bytes_format(tree, hf->hf.hs_ext_data,
5117 tvb, offset, ext_len, NULL,
5119 ext_len, plurality(ext_len, "", "s"));
5120 return offset + ext_len;
5124 ssl_dissect_hnd_hello_ext_cert_type(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5125 proto_tree *tree, guint32 offset, guint32 ext_len,
5126 gboolean is_client, guint16 ext_type, SslSession *session)
5128 guint8 cert_list_length;
5130 proto_tree *cert_list_tree;
5134 cert_list_length = tvb_get_guint8(tvb, offset);
5135 proto_tree_add_item(tree, hf->hf.hs_ext_cert_types_len,
5136 tvb, offset, 1, ENC_BIG_ENDIAN);
5138 if (ext_len != (guint32)cert_list_length + 1)
5141 ti = proto_tree_add_item(tree, hf->hf.hs_ext_cert_types, tvb, offset,
5142 cert_list_length, cert_list_length);
5143 proto_item_append_text(ti, " (%d)", cert_list_length);
5145 /* make this a subtree */
5146 cert_list_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_cert_types);
5148 /* loop over all point formats */
5149 while (cert_list_length > 0)
5151 proto_tree_add_item(cert_list_tree, hf->hf.hs_ext_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN);
5156 cert_type = tvb_get_guint8(tvb, offset);
5157 proto_tree_add_item(tree, hf->hf.hs_ext_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN);
5159 if (ext_type == SSL_HND_HELLO_EXT_CERT_TYPE || ext_type == SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE) {
5160 session->client_cert_type = cert_type;
5162 if (ext_type == SSL_HND_HELLO_EXT_CERT_TYPE || ext_type == SSL_HND_HELLO_EXT_SERVER_CERT_TYPE) {
5163 session->server_cert_type = cert_type;
5171 ssl_dissect_hnd_hello_common(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5172 proto_tree *tree, guint32 offset,
5173 SslDecryptSession *ssl, gboolean from_server)
5175 nstime_t gmt_unix_time;
5176 guint8 sessid_length;
5177 proto_tree *rnd_tree;
5183 rnd = &ssl->server_random;
5185 rnd = &ssl->client_random;
5187 /* save provided random for later keyring generation */
5188 tvb_memcpy(tvb, rnd->data, offset, 32);
5191 ssl->state |= SSL_SERVER_RANDOM;
5193 ssl->state |= SSL_CLIENT_RANDOM;
5194 ssl_debug_printf("%s found %s RANDOM -> state 0x%02X\n", __func__,
5195 from_server ? "SERVER" : "CLIENT", ssl->state);
5198 rnd_tree = proto_tree_add_subtree(tree, tvb, offset, 32,
5199 hf->ett.hs_random, NULL, "Random");
5202 gmt_unix_time.secs = tvb_get_ntohl(tvb, offset);
5203 gmt_unix_time.nsecs = 0;
5204 proto_tree_add_time(rnd_tree, hf->hf.hs_random_time,
5205 tvb, offset, 4, &gmt_unix_time);
5208 /* show the random bytes */
5209 proto_tree_add_item(rnd_tree, hf->hf.hs_random_bytes,
5210 tvb, offset, 28, ENC_NA);
5213 /* show the session id (length followed by actual Session ID) */
5214 sessid_length = tvb_get_guint8(tvb, offset);
5215 proto_tree_add_item(tree, hf->hf.hs_session_id_len,
5216 tvb, offset, 1, ENC_BIG_ENDIAN);
5220 /* save the authorative SID for later use in ChangeCipherSpec.
5221 * (D)TLS restricts the SID to 32 chars, it does not make sense to
5222 * save more, so ignore larger ones. */
5223 if (from_server && sessid_length <= 32) {
5224 tvb_memcpy(tvb, ssl->session_id.data, offset, sessid_length);
5225 ssl->session_id.data_len = sessid_length;
5228 if (sessid_length > 0) {
5229 proto_tree_add_item(tree, hf->hf.hs_session_id,
5230 tvb, offset, sessid_length, ENC_NA);
5231 offset += sessid_length;
5239 ssl_dissect_hnd_cert(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5240 guint32 offset, packet_info *pinfo,
5241 const SslSession *session, gint is_from_server)
5243 /* opaque ASN.1Cert<2^24-1>;
5246 * ASN.1Cert certificate_list<1..2^24-1>;
5249 guint32 certificate_list_length;
5251 proto_tree *subtree;
5252 asn1_ctx_t asn1_ctx;
5257 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
5259 certificate_list_length = tvb_get_ntoh24(tvb, offset);
5260 proto_tree_add_uint(tree, hf->hf.hs_certificates_len,
5261 tvb, offset, 3, certificate_list_length);
5262 offset += 3; /* 24-bit length value */
5264 if (certificate_list_length > 0) {
5265 ti = proto_tree_add_none_format(tree,
5266 hf->hf.hs_certificates,
5267 tvb, offset, certificate_list_length,
5268 "Certificates (%u bytes)",
5269 certificate_list_length);
5271 /* make it a subtree */
5272 subtree = proto_item_add_subtree(ti, hf->ett.certificates);
5274 /* iterate through each certificate */
5275 while (certificate_list_length > 0) {
5276 /* get the length of the current certificate */
5277 guint32 cert_length;
5278 cert_length = tvb_get_ntoh24(tvb, offset);
5279 certificate_list_length -= 3 + cert_length;
5281 proto_tree_add_item(subtree, hf->hf.hs_certificate_len,
5282 tvb, offset, 3, ENC_BIG_ENDIAN);
5285 if ((is_from_server && session->server_cert_type == SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY) ||
5286 (!is_from_server && session->client_cert_type == SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY)) {
5287 dissect_x509af_SubjectPublicKeyInfo(FALSE, tvb, offset, &asn1_ctx, subtree, hf->hf.hs_certificate);
5289 dissect_x509af_Certificate(FALSE, tvb, offset, &asn1_ctx, subtree, hf->hf.hs_certificate);
5292 offset += cert_length;
5298 ssl_dissect_hnd_cert_req(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5299 proto_tree *tree, guint32 offset, packet_info *pinfo,
5300 const SslSession *session)
5304 * rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
5306 * } ClientCertificateType;
5308 * opaque DistinguishedName<1..2^16-1>;
5311 * ClientCertificateType certificate_types<1..2^8-1>;
5312 * DistinguishedName certificate_authorities<3..2^16-1>;
5313 * } CertificateRequest;
5316 * As per TLSv1.2 (RFC 5246) the format has changed to:
5319 * rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
5320 * rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
5321 * fortezza_dms_RESERVED(20), (255)
5322 * } ClientCertificateType;
5325 * none(0), md5(1), sha1(2), sha224(3), sha256(4), sha384(5),
5329 * enum { anonymous(0), rsa(1), dsa(2), ecdsa(3), (255) }
5330 * SignatureAlgorithm;
5333 * HashAlgorithm hash;
5334 * SignatureAlgorithm signature;
5335 * } SignatureAndHashAlgorithm;
5337 * SignatureAndHashAlgorithm
5338 * supported_signature_algorithms<2..2^16-2>;
5340 * opaque DistinguishedName<1..2^16-1>;
5343 * ClientCertificateType certificate_types<1..2^8-1>;
5344 * SignatureAndHashAlgorithm
5345 * supported_signature_algorithms<2^16-1>;
5346 * DistinguishedName certificate_authorities<0..2^16-1>;
5347 * } CertificateRequest;
5351 proto_tree *subtree;
5352 guint8 cert_types_count;
5355 asn1_ctx_t asn1_ctx;
5361 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
5363 cert_types_count = tvb_get_guint8(tvb, offset);
5364 proto_tree_add_uint(tree, hf->hf.hs_cert_types_count,
5365 tvb, offset, 1, cert_types_count);
5368 if (cert_types_count > 0) {
5369 ti = proto_tree_add_none_format(tree,
5370 hf->hf.hs_cert_types,
5371 tvb, offset, cert_types_count,
5372 "Certificate types (%u type%s)",
5374 plurality(cert_types_count, "", "s"));
5375 subtree = proto_item_add_subtree(ti, hf->ett.cert_types);
5377 while (cert_types_count > 0) {
5378 proto_tree_add_item(subtree, hf->hf.hs_cert_type,
5379 tvb, offset, 1, ENC_BIG_ENDIAN);
5385 switch (session->version) {
5386 case SSL_VER_TLSv1DOT2:
5387 case SSL_VER_DTLS1DOT2:
5388 sh_alg_length = tvb_get_ntohs(tvb, offset);
5389 if (sh_alg_length % 2) {
5390 expert_add_info_format(pinfo, NULL,
5391 &hf->ei.hs_sig_hash_alg_len_bad,
5392 "Signature Hash Algorithm length (%d) must be a multiple of 2",
5397 proto_tree_add_uint(tree, hf->hf.hs_sig_hash_alg_len,
5398 tvb, offset, 2, sh_alg_length);
5401 ret = ssl_dissect_hash_alg_list(hf, tvb, tree, offset, sh_alg_length);
5410 dnames_length = tvb_get_ntohs(tvb, offset);
5411 proto_tree_add_uint(tree, hf->hf.hs_dnames_len,
5412 tvb, offset, 2, dnames_length);
5415 if (dnames_length > 0) {
5416 ti = proto_tree_add_none_format(tree,
5418 tvb, offset, dnames_length,
5419 "Distinguished Names (%d byte%s)",
5421 plurality(dnames_length, "", "s"));
5422 subtree = proto_item_add_subtree(ti, hf->ett.dnames);
5424 while (dnames_length > 0) {
5425 /* get the length of the current certificate */
5426 guint16 name_length;
5427 name_length = tvb_get_ntohs(tvb, offset);
5428 dnames_length -= 2 + name_length;
5430 proto_tree_add_item(subtree, hf->hf.hs_dname_len,
5431 tvb, offset, 2, ENC_BIG_ENDIAN);
5434 dissect_x509if_DistinguishedName(FALSE, tvb, offset, &asn1_ctx,
5435 subtree, hf->hf.hs_dname);
5436 offset += name_length;
5443 ssl_dissect_hnd_cert_url(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree, guint32 offset)
5445 guint16 url_hash_len;
5448 * individual_certs(0), pkipath(1), (255)
5452 * CertChainType type;
5453 * URLAndHash url_and_hash_list<1..2^16-1>;
5457 * opaque url<1..2^16-1>;
5459 * opaque SHA1Hash[20];
5463 proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_type,
5464 tvb, offset, 1, ENC_NA);
5467 url_hash_len = tvb_get_ntohs(tvb, offset);
5468 proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_url_hash_list_len,
5469 tvb, offset, 2, ENC_BIG_ENDIAN);
5471 while (url_hash_len-- > 0) {
5472 proto_item *urlhash_item;
5473 proto_tree *urlhash_tree;
5476 urlhash_item = proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_item,
5477 tvb, offset, -1, ENC_NA);
5478 urlhash_tree = proto_item_add_subtree(urlhash_item, hf->ett.urlhash);
5480 url_len = tvb_get_ntohs(tvb, offset);
5481 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_url_len,
5482 tvb, offset, 2, ENC_BIG_ENDIAN);
5485 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_url,
5486 tvb, offset, url_len, ENC_ASCII|ENC_NA);
5489 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_padding,
5490 tvb, offset, 1, ENC_NA);
5492 /* Note: RFC 6066 says that padding must be 0x01 */
5494 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_sha1,
5495 tvb, offset, 20, ENC_NA);
5501 ssl_dissect_hnd_hello_ext_status_request(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5502 guint32 offset, gboolean has_length)
5504 guint cert_status_type;
5506 cert_status_type = tvb_get_guint8(tvb, offset);
5507 proto_tree_add_item(tree, hf->hf.hs_ext_cert_status_type,
5508 tvb, offset, 1, ENC_NA);
5512 proto_tree_add_item(tree, hf->hf.hs_ext_cert_status_request_len,
5513 tvb, offset, 2, ENC_BIG_ENDIAN);
5517 switch (cert_status_type) {
5518 case SSL_HND_CERT_STATUS_TYPE_OCSP:
5519 case SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI:
5521 guint16 responder_id_list_len;
5522 guint16 request_extensions_len;
5523 proto_item *responder_id;
5524 proto_item *request_extensions;
5526 responder_id_list_len = tvb_get_ntohs(tvb, offset);
5528 proto_tree_add_item(tree,
5529 hf->hf.hs_ext_cert_status_responder_id_list_len,
5530 tvb, offset, 2, ENC_BIG_ENDIAN);
5532 if (responder_id_list_len != 0) {
5533 expert_add_info_format(NULL, responder_id,
5534 &hf->ei.hs_ext_cert_status_undecoded,
5535 "Responder ID list is not implemented, contact Wireshark"
5536 " developers if you want this to be supported");
5537 /* Non-empty responder ID list would mess with extensions. */
5541 request_extensions_len = tvb_get_ntohs(tvb, offset);
5542 request_extensions =
5543 proto_tree_add_item(tree,
5544 hf->hf.hs_ext_cert_status_request_extensions_len, tvb, offset,
5547 if (request_extensions_len != 0)
5548 expert_add_info_format(NULL, request_extensions,
5549 &hf->ei.hs_ext_cert_status_undecoded,
5550 "Request Extensions are not implemented, contact"
5551 " Wireshark developers if you want this to be supported");
5560 ssl_dissect_hnd_hello_ext_status_request_v2(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5565 list_len = tvb_get_ntoh24(tvb, offset);
5568 while (list_len-- > 0)
5569 offset = ssl_dissect_hnd_hello_ext_status_request(hf, tvb, tree, offset, TRUE);
5575 ssl_dissect_hnd_hello_ext_elliptic_curves(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5576 proto_tree *tree, guint32 offset)
5578 guint16 curves_length;
5579 proto_tree *curves_tree;
5582 curves_length = tvb_get_ntohs(tvb, offset);
5583 proto_tree_add_item(tree, hf->hf.hs_ext_elliptic_curves_len,
5584 tvb, offset, 2, ENC_BIG_ENDIAN);
5587 tvb_ensure_bytes_exist(tvb, offset, curves_length);
5588 ti = proto_tree_add_none_format(tree,
5589 hf->hf.hs_ext_elliptic_curves,
5590 tvb, offset, curves_length,
5591 "Elliptic curves (%d curve%s)",
5593 plurality(curves_length/2, "", "s"));
5595 /* make this a subtree */
5596 curves_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_curves);
5598 /* loop over all curves */
5599 while (curves_length > 0)
5601 proto_tree_add_item(curves_tree, hf->hf.hs_ext_elliptic_curve, tvb, offset, 2, ENC_BIG_ENDIAN);
5610 ssl_dissect_hnd_hello_ext_ec_point_formats(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5611 proto_tree *tree, guint32 offset)
5614 proto_tree *ecpf_tree;
5617 ecpf_length = tvb_get_guint8(tvb, offset);
5618 proto_tree_add_item(tree, hf->hf.hs_ext_ec_point_formats_len,
5619 tvb, offset, 1, ENC_BIG_ENDIAN);
5622 tvb_ensure_bytes_exist(tvb, offset, ecpf_length);
5623 ti = proto_tree_add_none_format(tree,
5624 hf->hf.hs_ext_elliptic_curves,
5625 tvb, offset, ecpf_length,
5626 "Elliptic curves point formats (%d)",
5629 /* make this a subtree */
5630 ecpf_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_curves_point_formats);
5632 /* loop over all point formats */
5633 while (ecpf_length > 0)
5635 proto_tree_add_item(ecpf_tree, hf->hf.hs_ext_ec_point_format, tvb, offset, 1, ENC_BIG_ENDIAN);
5644 ssl_dissect_hnd_hello_ext(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5645 guint32 offset, guint32 left, gboolean is_client,
5646 SslSession *session, SslDecryptSession *ssl)
5648 guint16 extension_length;
5651 proto_tree *ext_tree;
5656 extension_length = tvb_get_ntohs(tvb, offset);
5657 proto_tree_add_uint(tree, hf->hf.hs_exts_len,
5658 tvb, offset, 2, extension_length);
5664 ext_type = tvb_get_ntohs(tvb, offset);
5665 ext_len = tvb_get_ntohs(tvb, offset + 2);
5667 ext_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4 + ext_len, hf->ett.hs_ext, NULL,
5668 "Extension: %s", val_to_str(ext_type,
5669 tls_hello_extension_types,
5672 proto_tree_add_uint(ext_tree, hf->hf.hs_ext_type,
5673 tvb, offset, 2, ext_type);
5676 proto_tree_add_uint(ext_tree, hf->hf.hs_ext_len,
5677 tvb, offset, 2, ext_len);
5681 case SSL_HND_HELLO_EXT_STATUS_REQUEST:
5683 offset = ssl_dissect_hnd_hello_ext_status_request(hf, tvb, ext_tree, offset, FALSE);
5685 offset += ext_len; /* server must return empty extension_data */
5687 case SSL_HND_HELLO_EXT_STATUS_REQUEST_V2:
5689 offset = ssl_dissect_hnd_hello_ext_status_request_v2(hf, tvb, ext_tree, offset);
5691 offset += ext_len; /* server must return empty extension_data */
5693 case SSL_HND_HELLO_EXT_ELLIPTIC_CURVES:
5694 offset = ssl_dissect_hnd_hello_ext_elliptic_curves(hf, tvb, ext_tree, offset);
5696 case SSL_HND_HELLO_EXT_EC_POINT_FORMATS:
5697 offset = ssl_dissect_hnd_hello_ext_ec_point_formats(hf, tvb, ext_tree, offset);
5699 case SSL_HND_HELLO_EXT_SIG_HASH_ALGS:
5700 offset = ssl_dissect_hnd_hello_ext_sig_hash_algs(hf, tvb, ext_tree, offset, ext_len);
5702 case SSL_HND_HELLO_EXT_ALPN:
5703 offset = ssl_dissect_hnd_hello_ext_alpn(hf, tvb, ext_tree, offset, ext_len);
5705 case SSL_HND_HELLO_EXT_NPN:
5706 offset = ssl_dissect_hnd_hello_ext_npn(hf, tvb, ext_tree, offset, ext_len);
5708 case SSL_HND_HELLO_EXT_RENEG_INFO:
5709 offset = ssl_dissect_hnd_hello_ext_reneg_info(hf, tvb, ext_tree, offset, ext_len);
5711 case SSL_HND_HELLO_EXT_SERVER_NAME:
5712 offset = ssl_dissect_hnd_hello_ext_server_name(hf, tvb, ext_tree, offset, ext_len);
5714 case SSL_HND_HELLO_EXT_HEARTBEAT:
5715 proto_tree_add_item(ext_tree, hf->hf.hs_ext_heartbeat_mode,
5716 tvb, offset, 1, ENC_BIG_ENDIAN);
5719 case SSL_HND_HELLO_EXT_PADDING:
5720 offset = ssl_dissect_hnd_hello_ext_padding(hf, tvb, ext_tree, offset, ext_len);
5722 case SSL_HND_HELLO_EXT_SESSION_TICKET:
5723 offset = ssl_dissect_hnd_hello_ext_session_ticket(hf, tvb, ext_tree, offset, ext_len, is_client, ssl);
5725 case SSL_HND_HELLO_EXT_CERT_TYPE:
5726 case SSL_HND_HELLO_EXT_SERVER_CERT_TYPE:
5727 case SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE:
5728 offset = ssl_dissect_hnd_hello_ext_cert_type(hf, tvb, ext_tree, offset, ext_len, is_client, ext_type, session);
5731 proto_tree_add_bytes_format(ext_tree, hf->hf.hs_ext_data,
5732 tvb, offset, ext_len, NULL,
5734 ext_len, plurality(ext_len, "", "s"));
5739 left -= 2 + 2 + ext_len;
5746 /* ClientKeyExchange algo-specific dissectors */
5749 dissect_ssl3_hnd_cli_keyex_ecdh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5750 proto_tree *tree, guint32 offset,
5754 proto_tree *ssl_ecdh_tree;
5756 ssl_ecdh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
5757 hf->ett.keyex_params, NULL, "EC Diffie-Hellman Client Params");
5760 point_len = tvb_get_guint8(tvb, offset);
5761 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_client_keyex_point_len, tvb,
5762 offset, 1, ENC_BIG_ENDIAN);
5763 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_client_keyex_point, tvb,
5764 offset + 1, point_len, ENC_NA);
5768 dissect_ssl3_hnd_cli_keyex_dh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5769 proto_tree *tree, guint32 offset, guint32 length)
5772 proto_tree *ssl_dh_tree;
5774 ssl_dh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
5775 hf->ett.keyex_params, NULL, "Diffie-Hellman Client Params");
5777 /* ClientDiffieHellmanPublic.dh_public (explicit) */
5778 yc_len = tvb_get_ntohs(tvb, offset);
5779 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_client_keyex_yc_len, tvb,
5780 offset, 2, ENC_BIG_ENDIAN);
5781 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_client_keyex_yc, tvb,
5782 offset + 2, yc_len, ENC_NA);
5786 dissect_ssl3_hnd_cli_keyex_rsa(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5787 proto_tree *tree, guint32 offset,
5788 guint32 length, const SslSession *session)
5791 proto_tree *ssl_rsa_tree;
5793 ssl_rsa_tree = proto_tree_add_subtree(tree, tvb, offset, length,
5794 hf->ett.keyex_params, NULL, "RSA Encrypted PreMaster Secret");
5796 /* EncryptedPreMasterSecret.pre_master_secret */
5797 switch (session->version) {
5800 case SSL_VER_DTLS_OPENSSL:
5801 /* OpenSSL pre-0.9.8f DTLS and pre-TLS quirk: 2-octet length vector is
5802 * not present. The handshake contents represents the EPMS, see:
5803 * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10222 */
5808 /* TLS and DTLS include vector length before EPMS */
5809 epms_len = tvb_get_ntohs(tvb, offset);
5810 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_client_keyex_epms_len, tvb,
5811 offset, 2, ENC_BIG_ENDIAN);
5815 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_client_keyex_epms, tvb,
5816 offset, epms_len, ENC_NA);
5819 /* Used in PSK cipher suites */
5821 dissect_ssl3_hnd_cli_keyex_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5822 proto_tree *tree, guint32 offset, guint32 length)
5825 proto_tree *ssl_psk_tree;
5827 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
5828 hf->ett.keyex_params, NULL, "PSK Client Params");
5830 identity_len = tvb_get_ntohs(tvb, offset);
5831 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity_len, tvb,
5832 offset, 2, ENC_BIG_ENDIAN);
5833 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity, tvb,
5834 offset + 2, identity_len, ENC_NA);
5837 /* Used in RSA PSK cipher suites */
5839 dissect_ssl3_hnd_cli_keyex_rsa_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5840 proto_tree *tree, guint32 offset,
5843 gint identity_len, epms_len;
5844 proto_tree *ssl_psk_tree;
5846 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
5847 hf->ett.keyex_params, NULL, "RSA PSK Client Params");
5850 identity_len = tvb_get_ntohs(tvb, offset);
5851 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity_len,
5852 tvb, offset, 2, ENC_BIG_ENDIAN);
5853 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity,
5854 tvb, offset + 2, identity_len, ENC_NA);
5855 offset += 2 + identity_len;
5858 epms_len = tvb_get_ntohs(tvb, offset);
5859 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_epms_len, tvb,
5860 offset, 2, ENC_BIG_ENDIAN);
5861 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_epms, tvb,
5862 offset + 2, epms_len, ENC_NA);
5866 /* ServerKeyExchange algo-specific dissectors */
5868 /* dissects signed_params inside a ServerKeyExchange for some keyex algos */
5870 dissect_ssl3_hnd_srv_keyex_sig(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5871 proto_tree *tree, guint32 offset,
5872 const SslSession *session)
5875 proto_item *ti_algo;
5876 proto_tree *ssl_algo_tree;
5878 switch (session->version) {
5879 case SSL_VER_TLSv1DOT2:
5880 case SSL_VER_DTLS1DOT2:
5881 ti_algo = proto_tree_add_item(tree, hf->hf.hs_sig_hash_alg, tvb,
5882 offset, 2, ENC_BIG_ENDIAN);
5883 ssl_algo_tree = proto_item_add_subtree(ti_algo, hf->ett.hs_sig_hash_alg);
5885 /* SignatureAndHashAlgorithm { hash, signature } */
5886 proto_tree_add_item(ssl_algo_tree, hf->hf.hs_sig_hash_hash, tvb,
5887 offset, 1, ENC_BIG_ENDIAN);
5888 proto_tree_add_item(ssl_algo_tree, hf->hf.hs_sig_hash_sig, tvb,
5889 offset + 1, 1, ENC_BIG_ENDIAN);
5898 sig_len = tvb_get_ntohs(tvb, offset);
5899 proto_tree_add_item(tree, hf->hf.hs_server_keyex_sig_len, tvb,
5900 offset, 2, ENC_BIG_ENDIAN);
5901 proto_tree_add_item(tree, hf->hf.hs_server_keyex_sig, tvb,
5902 offset + 2, sig_len, ENC_NA);
5906 dissect_ssl3_hnd_srv_keyex_ecdh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5907 proto_tree *tree, guint32 offset,
5908 guint32 length, const SslSession *session)
5911 * RFC 4492 ECC cipher suites for TLS
5914 * ECCurveType curve_type;
5915 * select (curve_type) {
5916 * case explicit_prime:
5918 * case explicit_char2:
5921 * NamedCurve namedcurve;
5926 * opaque point <1..2^8-1>;
5930 * ECParameters curve_params;
5932 * } ServerECDHParams;
5934 * select (KeyExchangeAlgorithm) {
5935 * case ec_diffie_hellman:
5936 * ServerECDHParams params;
5937 * Signature signed_params;
5938 * } ServerKeyExchange;
5943 proto_tree *ssl_ecdh_tree;
5945 ssl_ecdh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
5946 hf->ett.keyex_params, NULL, "EC Diffie-Hellman Server Params");
5948 /* ECParameters.curve_type */
5949 curve_type = tvb_get_guint8(tvb, offset);
5950 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_curve_type, tvb,
5951 offset, 1, ENC_BIG_ENDIAN);
5953 if (curve_type != 3)
5954 return; /* only named_curves are supported */
5956 /* case curve_type == named_curve; ECParameters.namedcurve */
5957 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_named_curve, tvb,
5958 offset, 2, ENC_BIG_ENDIAN);
5962 point_len = tvb_get_guint8(tvb, offset);
5963 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_point_len, tvb,
5964 offset, 1, ENC_BIG_ENDIAN);
5965 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_point, tvb,
5966 offset + 1, point_len, ENC_NA);
5967 offset += 1 + point_len;
5970 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_ecdh_tree, offset, session);
5974 dissect_ssl3_hnd_srv_keyex_dhe(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5975 proto_tree *tree, guint32 offset, guint32 length,
5976 const SslSession *session)
5978 gint p_len, g_len, ys_len;
5979 proto_tree *ssl_dh_tree;
5981 ssl_dh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
5982 hf->ett.keyex_params, NULL, "Diffie-Hellman Server Params");
5985 p_len = tvb_get_ntohs(tvb, offset);
5986 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_p_len, tvb,
5987 offset, 2, ENC_BIG_ENDIAN);
5988 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_p, tvb,
5989 offset + 2, p_len, ENC_NA);
5990 offset += 2 + p_len;
5993 g_len = tvb_get_ntohs(tvb, offset);
5994 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_g_len, tvb,
5995 offset, 2, ENC_BIG_ENDIAN);
5996 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_g, tvb,
5997 offset + 2, g_len, ENC_NA);
5998 offset += 2 + g_len;
6001 ys_len = tvb_get_ntohs(tvb, offset);
6002 proto_tree_add_uint(ssl_dh_tree, hf->hf.hs_server_keyex_ys_len, tvb,
6004 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_ys, tvb,
6005 offset + 2, ys_len, ENC_NA);
6006 offset += 2 + ys_len;
6009 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_dh_tree, offset, session);
6012 /* Only used in RSA-EXPORT cipher suites */
6014 dissect_ssl3_hnd_srv_keyex_rsa(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6015 proto_tree *tree, guint32 offset, guint32 length,
6016 const SslSession *session)
6018 gint modulus_len, exponent_len;
6019 proto_tree *ssl_rsa_tree;
6021 ssl_rsa_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6022 hf->ett.keyex_params, NULL, "RSA-EXPORT Server Params");
6025 modulus_len = tvb_get_ntohs(tvb, offset);
6026 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_modulus_len, tvb,
6027 offset, 2, ENC_BIG_ENDIAN);
6028 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_modulus, tvb,
6029 offset + 2, modulus_len, ENC_NA);
6030 offset += 2 + modulus_len;
6033 exponent_len = tvb_get_ntohs(tvb, offset);
6034 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_exponent_len,
6035 tvb, offset, 2, ENC_BIG_ENDIAN);
6036 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_exponent,
6037 tvb, offset + 2, exponent_len, ENC_NA);
6038 offset += 2 + exponent_len;
6041 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_rsa_tree, offset, session);
6044 /* Used in RSA PSK and PSK cipher suites */
6046 dissect_ssl3_hnd_srv_keyex_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6047 proto_tree *tree, guint32 offset, guint32 length)
6050 proto_tree *ssl_psk_tree;
6052 hint_len = tvb_get_ntohs(tvb, offset);
6053 if ((2 + hint_len) != length) {
6054 /* Lengths don't line up (wasn't what we expected?) */
6058 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6059 hf->ett.keyex_params, NULL, "PSK Server Params");
6062 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_server_keyex_hint_len, tvb,
6063 offset, 2, ENC_BIG_ENDIAN);
6064 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_server_keyex_hint, tvb,
6065 offset + 2, hint_len, ENC_NA);
6070 ssl_dissect_hnd_cli_keyex(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6071 proto_tree *tree, guint32 offset, guint32 length,
6072 const SslSession *session)
6074 switch (ssl_get_keyex_alg(session->cipher)) {
6075 case KEX_RSA: /* rsa: EncryptedPreMasterSecret */
6076 dissect_ssl3_hnd_cli_keyex_rsa(hf, tvb, tree, offset, length, session);
6078 case KEX_DH: /* DHE_RSA: ClientDiffieHellmanPublic */
6079 /* XXX: DHE_DSS, DH_DSS, DH_RSA, DH_ANON; same format */
6080 dissect_ssl3_hnd_cli_keyex_dh(hf, tvb, tree, offset, length);
6082 case KEX_ECDH: /* ec_diffie_hellman: ClientECDiffieHellmanPublic */
6083 dissect_ssl3_hnd_cli_keyex_ecdh(hf, tvb, tree, offset, length);
6086 dissect_ssl3_hnd_cli_keyex_psk(hf, tvb, tree, offset, length);
6089 dissect_ssl3_hnd_cli_keyex_rsa_psk(hf, tvb, tree, offset, length);
6095 ssl_dissect_hnd_srv_keyex(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6096 proto_tree *tree, guint32 offset, guint32 length,
6097 const SslSession *session)
6099 switch (ssl_get_keyex_alg(session->cipher)) {
6100 case KEX_DH: /* DHE_RSA: ServerDHParams + signature */
6101 /* XXX: DHE_DSS, same format */
6102 /* XXX: DHE_ANON, almost the same, but without signed_params */
6103 dissect_ssl3_hnd_srv_keyex_dhe(hf, tvb, tree, offset, length, session);
6105 case KEX_RSA: /* TLSv1.0 and older: RSA_EXPORT cipher suites */
6106 dissect_ssl3_hnd_srv_keyex_rsa(hf, tvb, tree, offset, length, session);
6108 case KEX_ECDH: /* ec_diffie_hellman: ServerECDHParams + signature */
6109 dissect_ssl3_hnd_srv_keyex_ecdh(hf, tvb, tree, offset, length, session);
6113 dissect_ssl3_hnd_srv_keyex_psk(hf, tvb, tree, offset, length);
6118 #ifdef HAVE_LIBGNUTLS
6120 ssl_common_register_options(module_t *module, ssl_common_options_t *options)
6122 prefs_register_string_preference(module, "psk", "Pre-Shared-Key",
6123 "Pre-Shared-Key as HEX string, should be 0 to 16 bytes",
6126 prefs_register_filename_preference(module, "keylog_file", "(Pre)-Master-Secret log filename",
6127 "The filename of a file which contains a list of \n"
6128 "(pre-)master secrets in one of the following formats:\n"
6130 "RSA <EPMS> <PMS>\n"
6131 "RSA Session-ID:<SSLID> Master-Key:<MS>\n"
6132 "CLIENT_RANDOM <CRAND> <MS>\n"
6135 "<EPMS> = First 8 bytes of the Encrypted PMS\n"
6136 "<PMS> = The Pre-Master-Secret (PMS)\n"
6137 "<SSLID> = The SSL Session ID\n"
6138 "<MS> = The Master-Secret (MS)\n"
6139 "<CRAND> = The Client's random number from the ClientHello message\n"
6141 "(All fields are in hex notation)",
6142 &(options->keylog_filename));
6146 ssl_common_register_options(module_t *module _U_, ssl_common_options_t *options _U_)
6152 * Editor modelines - http://www.wireshark.org/tools/modelines.html
6157 * indent-tabs-mode: nil
6160 * vi: set shiftwidth=4 tabstop=8 expandtab:
6161 * :indentSize=4:tabSize=8:noTabs=true: