2 * ssl manipulation functions
3 * By Paolo Abeni <paolo.abeni@email.com>
5 * Copyright (c) 2013, Hauke Mehrtens <hauke@hauke-m.de>
6 * Copyright (c) 2014, Peter Wu <peter@lekensteyn.nl>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
37 #include <epan/packet.h>
38 #include <epan/strutil.h>
39 #include <epan/addr_resolv.h>
40 #include <epan/ipv6.h>
41 #include <epan/expert.h>
42 #include <epan/asn1.h>
43 #include <epan/proto_data.h>
45 #include <wsutil/filesystem.h>
46 #include <wsutil/file_util.h>
47 #include <wsutil/str_util.h>
48 #include <wsutil/report_err.h>
49 #include <wsutil/pint.h>
50 #include <wsutil/strtoi.h>
51 #include <ws_version_info.h>
52 #include "packet-x509af.h"
53 #include "packet-x509if.h"
54 #include "packet-ssl-utils.h"
55 #include "packet-ssl.h"
56 #include "packet-dtls.h"
57 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
58 #include <gnutls/abstract.h>
60 #if GCRYPT_VERSION_NUMBER >= 0x010600 /* 1.6.0 */
61 /* Whether to provide support for authentication in addition to decryption. */
62 #define HAVE_LIBGCRYPT_AEAD
65 /* Lookup tables {{{ */
66 const value_string ssl_version_short_names[] = {
67 { SSL_VER_UNKNOWN, "SSL" },
68 { SSLV2_VERSION, "SSLv2" },
69 { SSLV3_VERSION, "SSLv3" },
70 { TLSV1_VERSION, "TLSv1" },
71 { TLSV1DOT1_VERSION, "TLSv1.1" },
72 { TLSV1DOT2_VERSION, "TLSv1.2" },
73 { TLSV1DOT3_VERSION, "TLSv1.3" },
74 { DTLSV1DOT0_VERSION, "DTLSv1.0" },
75 { DTLSV1DOT2_VERSION, "DTLSv1.2" },
76 { DTLSV1DOT0_OPENSSL_VERSION, "DTLS 1.0 (OpenSSL pre 0.9.8f)" },
77 { PCT_VERSION, "PCT" },
81 const value_string ssl_versions[] = {
82 { SSLV2_VERSION, "SSL 2.0" },
83 { SSLV3_VERSION, "SSL 3.0" },
84 { TLSV1_VERSION, "TLS 1.0" },
85 { TLSV1DOT1_VERSION, "TLS 1.1" },
86 { TLSV1DOT2_VERSION, "TLS 1.2" },
87 { TLSV1DOT3_VERSION, "TLS 1.3" },
88 { 0x7F0E, "TLS 1.3 (draft 14)" },
89 { 0x7F0F, "TLS 1.3 (draft 15)" },
90 { 0x7F10, "TLS 1.3 (draft 16)" },
91 { 0x7F11, "TLS 1.3 (draft 17)" },
92 { 0x7F12, "TLS 1.3 (draft 18)" },
93 { DTLSV1DOT0_OPENSSL_VERSION, "DTLS 1.0 (OpenSSL pre 0.9.8f)" },
94 { DTLSV1DOT0_VERSION, "DTLS 1.0" },
95 { DTLSV1DOT2_VERSION, "DTLS 1.2" },
99 const value_string ssl_20_msg_types[] = {
100 { SSL2_HND_ERROR, "Error" },
101 { SSL2_HND_CLIENT_HELLO, "Client Hello" },
102 { SSL2_HND_CLIENT_MASTER_KEY, "Client Master Key" },
103 { SSL2_HND_CLIENT_FINISHED, "Client Finished" },
104 { SSL2_HND_SERVER_HELLO, "Server Hello" },
105 { SSL2_HND_SERVER_VERIFY, "Server Verify" },
106 { SSL2_HND_SERVER_FINISHED, "Server Finished" },
107 { SSL2_HND_REQUEST_CERTIFICATE, "Request Certificate" },
108 { SSL2_HND_CLIENT_CERTIFICATE, "Client Certificate" },
111 /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
112 /* Note: sorted by ascending value so value_string-ext can do a binary search */
113 static const value_string ssl_20_cipher_suites[] = {
114 { 0x000000, "TLS_NULL_WITH_NULL_NULL" },
115 { 0x000001, "TLS_RSA_WITH_NULL_MD5" },
116 { 0x000002, "TLS_RSA_WITH_NULL_SHA" },
117 { 0x000003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" },
118 { 0x000004, "TLS_RSA_WITH_RC4_128_MD5" },
119 { 0x000005, "TLS_RSA_WITH_RC4_128_SHA" },
120 { 0x000006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" },
121 { 0x000007, "TLS_RSA_WITH_IDEA_CBC_SHA" },
122 { 0x000008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" },
123 { 0x000009, "TLS_RSA_WITH_DES_CBC_SHA" },
124 { 0x00000a, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" },
125 { 0x00000b, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" },
126 { 0x00000c, "TLS_DH_DSS_WITH_DES_CBC_SHA" },
127 { 0x00000d, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" },
128 { 0x00000e, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" },
129 { 0x00000f, "TLS_DH_RSA_WITH_DES_CBC_SHA" },
130 { 0x000010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" },
131 { 0x000011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" },
132 { 0x000012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" },
133 { 0x000013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" },
134 { 0x000014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" },
135 { 0x000015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" },
136 { 0x000016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" },
137 { 0x000017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" },
138 { 0x000018, "TLS_DH_anon_WITH_RC4_128_MD5" },
139 { 0x000019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" },
140 { 0x00001a, "TLS_DH_anon_WITH_DES_CBC_SHA" },
141 { 0x00001b, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" },
142 { 0x00001c, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" },
143 { 0x00001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
145 { 0x00001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
148 { 0x00001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
149 { 0x00001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" },
150 { 0x000020, "TLS_KRB5_WITH_RC4_128_SHA" },
151 { 0x000021, "TLS_KRB5_WITH_IDEA_CBC_SHA" },
152 { 0x000022, "TLS_KRB5_WITH_DES_CBC_MD5" },
153 { 0x000023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" },
154 { 0x000024, "TLS_KRB5_WITH_RC4_128_MD5" },
155 { 0x000025, "TLS_KRB5_WITH_IDEA_CBC_MD5" },
156 { 0x000026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" },
157 { 0x000027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" },
158 { 0x000028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" },
159 { 0x000029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" },
160 { 0x00002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" },
161 { 0x00002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" },
163 { 0x00002C, "TLS_PSK_WITH_NULL_SHA" },
164 { 0x00002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
165 { 0x00002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
167 { 0x00002f, "TLS_RSA_WITH_AES_128_CBC_SHA" },
168 { 0x000030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
169 { 0x000031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" },
170 { 0x000032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" },
171 { 0x000033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" },
172 { 0x000034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" },
173 { 0x000035, "TLS_RSA_WITH_AES_256_CBC_SHA" },
174 { 0x000036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" },
175 { 0x000037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" },
176 { 0x000038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
177 { 0x000039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
178 { 0x00003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
179 { 0x00003B, "TLS_RSA_WITH_NULL_SHA256" },
180 { 0x00003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" },
181 { 0x00003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" },
182 { 0x00003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" },
183 { 0x00003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" },
184 { 0x000040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" },
185 { 0x000041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" },
186 { 0x000042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" },
187 { 0x000043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" },
188 { 0x000044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" },
189 { 0x000045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" },
190 { 0x000046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" },
191 { 0x000047, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
192 { 0x000048, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
193 { 0x000049, "TLS_ECDH_ECDSA_WITH_DES_CBC_SHA" },
194 { 0x00004A, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
195 { 0x00004B, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
196 { 0x00004C, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
197 { 0x000060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
198 { 0x000061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
199 { 0x000062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" },
200 { 0x000063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" },
201 { 0x000064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" },
202 { 0x000065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" },
203 { 0x000066, "TLS_DHE_DSS_WITH_RC4_128_SHA" },
204 { 0x000067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" },
205 { 0x000068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" },
206 { 0x000069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" },
207 { 0x00006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" },
208 { 0x00006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" },
209 { 0x00006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" },
210 { 0x00006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" },
211 /* 0x00,0x6E-83 Unassigned */
212 { 0x000084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" },
213 { 0x000085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" },
214 { 0x000086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" },
215 { 0x000087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
216 { 0x000088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
217 { 0x000089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
219 { 0x00008A, "TLS_PSK_WITH_RC4_128_SHA" },
220 { 0x00008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
221 { 0x00008C, "TLS_PSK_WITH_AES_128_CBC_SHA" },
222 { 0x00008D, "TLS_PSK_WITH_AES_256_CBC_SHA" },
223 { 0x00008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" },
224 { 0x00008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" },
225 { 0x000090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" },
226 { 0x000091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" },
227 { 0x000092, "TLS_RSA_PSK_WITH_RC4_128_SHA" },
228 { 0x000093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" },
229 { 0x000094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" },
230 { 0x000095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" },
232 { 0x000096, "TLS_RSA_WITH_SEED_CBC_SHA" },
233 { 0x000097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" },
234 { 0x000098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" },
235 { 0x000099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
236 { 0x00009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
237 { 0x00009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
239 { 0x00009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" },
240 { 0x00009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" },
241 { 0x00009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" },
242 { 0x00009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" },
243 { 0x0000A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" },
244 { 0x0000A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" },
245 { 0x0000A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" },
246 { 0x0000A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" },
247 { 0x0000A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" },
248 { 0x0000A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" },
249 { 0x0000A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" },
250 { 0x0000A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" },
252 { 0x0000A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" },
253 { 0x0000A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" },
254 { 0x0000AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" },
255 { 0x0000AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" },
256 { 0x0000AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" },
257 { 0x0000AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" },
258 { 0x0000AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" },
259 { 0x0000AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" },
260 { 0x0000B0, "TLS_PSK_WITH_NULL_SHA256" },
261 { 0x0000B1, "TLS_PSK_WITH_NULL_SHA384" },
262 { 0x0000B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" },
263 { 0x0000B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" },
264 { 0x0000B4, "TLS_DHE_PSK_WITH_NULL_SHA256" },
265 { 0x0000B5, "TLS_DHE_PSK_WITH_NULL_SHA384" },
266 { 0x0000B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" },
267 { 0x0000B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" },
268 { 0x0000B8, "TLS_RSA_PSK_WITH_NULL_SHA256" },
269 { 0x0000B9, "TLS_RSA_PSK_WITH_NULL_SHA384" },
271 { 0x0000BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
272 { 0x0000BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
273 { 0x0000BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
274 { 0x0000BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
275 { 0x0000BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
276 { 0x0000BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" },
277 { 0x0000C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
278 { 0x0000C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
279 { 0x0000C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
280 { 0x0000C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
281 { 0x0000C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
282 { 0x0000C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" },
283 /* 0x00,0xC6-FE Unassigned */
284 { 0x0000FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" },
285 /* 0x01-BF,* Unassigned */
287 { 0x00c001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
288 { 0x00c002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
289 { 0x00c003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
290 { 0x00c004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
291 { 0x00c005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
292 { 0x00c006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" },
293 { 0x00c007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" },
294 { 0x00c008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" },
295 { 0x00c009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
296 { 0x00c00a, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
297 { 0x00c00b, "TLS_ECDH_RSA_WITH_NULL_SHA" },
298 { 0x00c00c, "TLS_ECDH_RSA_WITH_RC4_128_SHA" },
299 { 0x00c00d, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" },
300 { 0x00c00e, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" },
301 { 0x00c00f, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" },
302 { 0x00c010, "TLS_ECDHE_RSA_WITH_NULL_SHA" },
303 { 0x00c011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" },
304 { 0x00c012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" },
305 { 0x00c013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
306 { 0x00c014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
307 { 0x00c015, "TLS_ECDH_anon_WITH_NULL_SHA" },
308 { 0x00c016, "TLS_ECDH_anon_WITH_RC4_128_SHA" },
309 { 0x00c017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" },
310 { 0x00c018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" },
311 { 0x00c019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" },
313 { 0x00C01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" },
314 { 0x00C01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" },
315 { 0x00C01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" },
316 { 0x00C01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" },
317 { 0x00C01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" },
318 { 0x00C01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" },
319 { 0x00C020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
320 { 0x00C021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
321 { 0x00C022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
323 { 0x00C023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" },
324 { 0x00C024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" },
325 { 0x00C025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" },
326 { 0x00C026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" },
327 { 0x00C027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" },
328 { 0x00C028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" },
329 { 0x00C029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" },
330 { 0x00C02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" },
331 { 0x00C02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
332 { 0x00C02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
333 { 0x00C02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" },
334 { 0x00C02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" },
335 { 0x00C02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
336 { 0x00C030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
337 { 0x00C031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" },
338 { 0x00C032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" },
340 { 0x00C033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" },
341 { 0x00C034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" },
342 { 0x00C035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" },
343 { 0x00C036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" },
344 { 0x00C037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" },
345 { 0x00C038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" },
346 { 0x00C039, "TLS_ECDHE_PSK_WITH_NULL_SHA" },
347 { 0x00C03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" },
348 { 0x00C03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" },
349 /* 0xC0,0x3C-FF Unassigned
351 0xFE,0x00-FD Unassigned
352 0xFE,0xFE-FF Reserved to avoid conflicts with widely deployed implementations [Pasi_Eronen]
353 0xFF,0x00-FF Reserved for Private Use [RFC5246]
356 /* old numbers used in the beginning
357 * http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 */
358 { 0x00CC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
359 { 0x00CC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
360 { 0x00CC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
362 /* http://tools.ietf.org/html/draft-ietf-tls-chacha20-poly1305 */
363 { 0x00CCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
364 { 0x00CCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
365 { 0x00CCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
366 { 0x00CCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256" },
367 { 0x00CCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
368 { 0x00CCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
369 { 0x00CCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256" },
371 /* http://tools.ietf.org/html/draft-josefsson-salsa20-tls */
372 { 0x00E410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" },
373 { 0x00E411, "TLS_RSA_WITH_SALSA20_SHA1" },
374 { 0x00E412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
375 { 0x00E413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" },
376 { 0x00E414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" },
377 { 0x00E415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" },
378 { 0x00E416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" },
379 { 0x00E417, "TLS_PSK_WITH_SALSA20_SHA1" },
380 { 0x00E418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
381 { 0x00E419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" },
382 { 0x00E41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" },
383 { 0x00E41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" },
384 { 0x00E41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
385 { 0x00E41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" },
386 { 0x00E41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
387 { 0x00E41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" },
389 /* these from http://www.mozilla.org/projects/
390 security/pki/nss/ssl/fips-ssl-ciphersuites.html */
391 { 0x00fefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
392 { 0x00feff, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
393 { 0x00ffe0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
394 { 0x00ffe1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
395 /* note that ciphersuites of {0x00????} are TLS cipher suites in
396 * a sslv2 client hello message; the ???? above is the two-byte
397 * tls cipher suite id
400 { 0x010080, "SSL2_RC4_128_WITH_MD5" },
401 { 0x020080, "SSL2_RC4_128_EXPORT40_WITH_MD5" },
402 { 0x030080, "SSL2_RC2_128_CBC_WITH_MD5" },
403 { 0x040080, "SSL2_RC2_128_CBC_EXPORT40_WITH_MD5" },
404 { 0x050080, "SSL2_IDEA_128_CBC_WITH_MD5" },
405 { 0x060040, "SSL2_DES_64_CBC_WITH_MD5" },
406 { 0x0700c0, "SSL2_DES_192_EDE3_CBC_WITH_MD5" },
407 { 0x080080, "SSL2_RC4_64_WITH_MD5" },
409 /* Microsoft's old PCT protocol. These are from Eric Rescorla's
410 book "SSL and TLS" */
411 { 0x800001, "PCT_SSL_CERT_TYPE | PCT1_CERT_X509" },
412 { 0x800003, "PCT_SSL_CERT_TYPE | PCT1_CERT_X509_CHAIN" },
413 { 0x810001, "PCT_SSL_HASH_TYPE | PCT1_HASH_MD5" },
414 { 0x810003, "PCT_SSL_HASH_TYPE | PCT1_HASH_SHA" },
415 { 0x820001, "PCT_SSL_EXCH_TYPE | PCT1_EXCH_RSA_PKCS1" },
416 { 0x830004, "PCT_SSL_CIPHER_TYPE_1ST_HALF | PCT1_CIPHER_RC4" },
417 { 0x842840, "PCT_SSL_CIPHER_TYPE_2ND_HALF | PCT1_ENC_BITS_40 | PCT1_MAC_BITS_128" },
418 { 0x848040, "PCT_SSL_CIPHER_TYPE_2ND_HALF | PCT1_ENC_BITS_128 | PCT1_MAC_BITS_128" },
419 { 0x8f8001, "PCT_SSL_COMPAT | PCT_VERSION_1" },
423 value_string_ext ssl_20_cipher_suites_ext = VALUE_STRING_EXT_INIT(ssl_20_cipher_suites);
427 * Supported Groups (formerly named "EC Named Curve").
428 * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8
430 const value_string ssl_extension_curves[] = {
456 { 26, "brainpoolP256r1" }, /* RFC 7027 */
457 { 27, "brainpoolP384r1" }, /* RFC 7027 */
458 { 28, "brainpoolP512r1" }, /* RFC 7027 */
459 { 29, "ecdh_x25519" }, /* https://tools.ietf.org/html/draft-ietf-tls-rfc4492bis */
460 { 30, "ecdh_x448" }, /* https://tools.ietf.org/html/draft-ietf-tls-rfc4492bis */
461 { 256, "ffdhe2048" }, /* RFC 7919 */
462 { 257, "ffdhe3072" }, /* RFC 7919 */
463 { 258, "ffdhe4096" }, /* RFC 7919 */
464 { 259, "ffdhe6144" }, /* RFC 7919 */
465 { 260, "ffdhe8192" }, /* RFC 7919 */
466 { 0xFF01, "arbitrary_explicit_prime_curves" },
467 { 0xFF02, "arbitrary_explicit_char2_curves" },
471 const value_string ssl_curve_types[] = {
472 { 1, "explicit_prime" },
473 { 2, "explicit_char2" },
474 { 3, "named_curve" },
478 const value_string ssl_extension_ec_point_formats[] = {
479 { 0, "uncompressed" },
480 { 1, "ansiX962_compressed_prime" },
481 { 2, "ansiX962_compressed_char2" },
485 const value_string ssl_20_certificate_type[] = {
487 { 0x01, "X.509 Certificate" },
491 const value_string ssl_31_content_type[] = {
492 { 20, "Change Cipher Spec" },
495 { 23, "Application Data" },
501 /* XXX - would be used if we dissected the body of a Change Cipher Spec
503 const value_string ssl_31_change_cipher_spec[] = {
504 { 1, "Change Cipher Spec" },
509 const value_string ssl_31_alert_level[] = {
515 const value_string ssl_31_alert_description[] = {
516 { 0, "Close Notify" },
517 { 1, "End of Early Data" },
518 { 10, "Unexpected Message" },
519 { 20, "Bad Record MAC" },
520 { 21, "Decryption Failed" },
521 { 22, "Record Overflow" },
522 { 30, "Decompression Failure" },
523 { 40, "Handshake Failure" },
524 { 41, "No Certificate" },
525 { 42, "Bad Certificate" },
526 { 43, "Unsupported Certificate" },
527 { 44, "Certificate Revoked" },
528 { 45, "Certificate Expired" },
529 { 46, "Certificate Unknown" },
530 { 47, "Illegal Parameter" },
531 { 48, "Unknown CA" },
532 { 49, "Access Denied" },
533 { 50, "Decode Error" },
534 { 51, "Decrypt Error" },
535 { 60, "Export Restriction" },
536 { 70, "Protocol Version" },
537 { 71, "Insufficient Security" },
538 { 80, "Internal Error" },
539 { 86, "Inappropriate Fallback" },
540 { 90, "User Canceled" },
541 { 100, "No Renegotiation" },
542 { 109, "Missing Extension" },
543 { 110, "Unsupported Extension" },
544 { 111, "Certificate Unobtainable" },
545 { 112, "Unrecognized Name" },
546 { 113, "Bad Certificate Status Response" },
547 { 114, "Bad Certificate Hash Value" },
548 { 115, "Unknown PSK Identity" },
549 { 116, "Certificate Required" },
550 { 120, "No application Protocol" },
554 const value_string ssl_31_handshake_type[] = {
555 { SSL_HND_HELLO_REQUEST, "Hello Request" },
556 { SSL_HND_CLIENT_HELLO, "Client Hello" },
557 { SSL_HND_SERVER_HELLO, "Server Hello" },
558 { SSL_HND_HELLO_VERIFY_REQUEST, "Hello Verify Request"},
559 { SSL_HND_NEWSESSION_TICKET, "New Session Ticket" },
560 { SSL_HND_HELLO_RETRY_REQUEST, "Hello Retry Request" },
561 { SSL_HND_ENCRYPTED_EXTENSIONS, "Encrypted Extensions" },
562 { SSL_HND_CERTIFICATE, "Certificate" },
563 { SSL_HND_SERVER_KEY_EXCHG, "Server Key Exchange" },
564 { SSL_HND_CERT_REQUEST, "Certificate Request" },
565 { SSL_HND_SVR_HELLO_DONE, "Server Hello Done" },
566 { SSL_HND_CERT_VERIFY, "Certificate Verify" },
567 { SSL_HND_CLIENT_KEY_EXCHG, "Client Key Exchange" },
568 { SSL_HND_FINISHED, "Finished" },
569 { SSL_HND_CERT_URL, "Client Certificate URL" },
570 { SSL_HND_CERT_STATUS, "Certificate Status" },
571 { SSL_HND_SUPPLEMENTAL_DATA, "Supplemental Data" },
572 { SSL_HND_ENCRYPTED_EXTS, "Encrypted Extensions" },
576 const value_string tls_heartbeat_type[] = {
582 const value_string tls_heartbeat_mode[] = {
583 { 1, "Peer allowed to send requests" },
584 { 2, "Peer not allowed to send requests" },
588 const value_string ssl_31_compression_method[] = {
596 /* XXX - would be used if we dissected a Signature, as would be
597 seen in a server key exchange or certificate verify message. */
598 const value_string ssl_31_key_exchange_algorithm[] = {
600 { 1, "Diffie Hellman" },
604 const value_string ssl_31_signature_algorithm[] = {
612 const value_string ssl_31_client_certificate_type[] = {
615 { 3, "RSA Fixed DH" },
616 { 4, "DSS Fixed DH" },
617 /* GOST certificate types */
618 /* Section 3.5 of draft-chudov-cryptopro-cptls-04 */
619 { 21, "GOST R 34.10-94" },
620 { 22, "GOST R 34.10-2001" },
621 /* END GOST certificate types */
622 { 64, "ECDSA Sign" },
623 { 65, "RSA Fixed ECDH" },
624 { 66, "ECDSA Fixed ECDH" },
629 /* XXX - would be used if we dissected exchange keys, as would be
630 seen in a client key exchange message. */
631 const value_string ssl_31_public_value_encoding[] = {
638 /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
639 /* Note: sorted by ascending value so value_string_ext fcns can do a binary search */
640 static const value_string ssl_31_ciphersuite[] = {
641 /* RFC 2246, RFC 4346, RFC 5246 */
642 { 0x0000, "TLS_NULL_WITH_NULL_NULL" },
643 { 0x0001, "TLS_RSA_WITH_NULL_MD5" },
644 { 0x0002, "TLS_RSA_WITH_NULL_SHA" },
645 { 0x0003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" },
646 { 0x0004, "TLS_RSA_WITH_RC4_128_MD5" },
647 { 0x0005, "TLS_RSA_WITH_RC4_128_SHA" },
648 { 0x0006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" },
649 { 0x0007, "TLS_RSA_WITH_IDEA_CBC_SHA" },
650 { 0x0008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" },
651 { 0x0009, "TLS_RSA_WITH_DES_CBC_SHA" },
652 { 0x000a, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" },
653 { 0x000b, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" },
654 { 0x000c, "TLS_DH_DSS_WITH_DES_CBC_SHA" },
655 { 0x000d, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" },
656 { 0x000e, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" },
657 { 0x000f, "TLS_DH_RSA_WITH_DES_CBC_SHA" },
658 { 0x0010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" },
659 { 0x0011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" },
660 { 0x0012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" },
661 { 0x0013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" },
662 { 0x0014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" },
663 { 0x0015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" },
664 { 0x0016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" },
665 { 0x0017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" },
666 { 0x0018, "TLS_DH_anon_WITH_RC4_128_MD5" },
667 { 0x0019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" },
668 { 0x001a, "TLS_DH_anon_WITH_DES_CBC_SHA" },
669 { 0x001b, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" },
671 { 0x001c, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" },
672 { 0x001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
673 #if 0 /* Because it clashes with KRB5, is never used any more, and is safe
674 to remove according to David Hopwood <david.hopwood@zetnet.co.uk>
675 of the ietf-tls list */
676 { 0x001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
680 { 0x001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
681 { 0x001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" },
682 { 0x0020, "TLS_KRB5_WITH_RC4_128_SHA" },
683 { 0x0021, "TLS_KRB5_WITH_IDEA_CBC_SHA" },
684 { 0x0022, "TLS_KRB5_WITH_DES_CBC_MD5" },
685 { 0x0023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" },
686 { 0x0024, "TLS_KRB5_WITH_RC4_128_MD5" },
687 { 0x0025, "TLS_KRB5_WITH_IDEA_CBC_MD5" },
688 { 0x0026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" },
689 { 0x0027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" },
690 { 0x0028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" },
691 { 0x0029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" },
692 { 0x002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" },
693 { 0x002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" },
696 { 0x002C, "TLS_PSK_WITH_NULL_SHA" },
697 { 0x002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
698 { 0x002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
701 { 0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA" },
702 { 0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
703 { 0x0031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" },
704 { 0x0032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" },
705 { 0x0033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" },
706 { 0x0034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" },
707 { 0x0035, "TLS_RSA_WITH_AES_256_CBC_SHA" },
708 { 0x0036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" },
709 { 0x0037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" },
710 { 0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
711 { 0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
712 { 0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
713 { 0x003B, "TLS_RSA_WITH_NULL_SHA256" },
714 { 0x003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" },
715 { 0x003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" },
716 { 0x003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" },
717 { 0x003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" },
718 { 0x0040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" },
721 { 0x0041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" },
722 { 0x0042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" },
723 { 0x0043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" },
724 { 0x0044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" },
725 { 0x0045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" },
726 { 0x0046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" },
728 /* 0x00,0x60-66 Reserved to avoid conflicts with widely deployed implementations */
730 { 0x0060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
731 { 0x0061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
732 /* draft-ietf-tls-56-bit-ciphersuites-01.txt */
733 { 0x0062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" },
734 { 0x0063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" },
735 { 0x0064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" },
736 { 0x0065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" },
737 { 0x0066, "TLS_DHE_DSS_WITH_RC4_128_SHA" },
740 { 0x0067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" },
741 { 0x0068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" },
742 { 0x0069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" },
743 { 0x006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" },
744 { 0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" },
745 { 0x006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" },
746 { 0x006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" },
748 /* draft-chudov-cryptopro-cptls-04.txt */
749 { 0x0080, "TLS_GOSTR341094_WITH_28147_CNT_IMIT" },
750 { 0x0081, "TLS_GOSTR341001_WITH_28147_CNT_IMIT" },
751 { 0x0082, "TLS_GOSTR341094_WITH_NULL_GOSTR3411" },
752 { 0x0083, "TLS_GOSTR341001_WITH_NULL_GOSTR3411" },
755 { 0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" },
756 { 0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" },
757 { 0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" },
758 { 0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
759 { 0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
760 { 0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
763 { 0x008A, "TLS_PSK_WITH_RC4_128_SHA" },
764 { 0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
765 { 0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA" },
766 { 0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA" },
767 { 0x008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" },
768 { 0x008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" },
769 { 0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" },
770 { 0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" },
771 { 0x0092, "TLS_RSA_PSK_WITH_RC4_128_SHA" },
772 { 0x0093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" },
773 { 0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" },
774 { 0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" },
777 { 0x0096, "TLS_RSA_WITH_SEED_CBC_SHA" },
778 { 0x0097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" },
779 { 0x0098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" },
780 { 0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
781 { 0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
782 { 0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
785 { 0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" },
786 { 0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" },
787 { 0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" },
788 { 0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" },
789 { 0x00A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" },
790 { 0x00A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" },
791 { 0x00A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" },
792 { 0x00A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" },
793 { 0x00A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" },
794 { 0x00A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" },
795 { 0x00A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" },
796 { 0x00A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" },
799 { 0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" },
800 { 0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" },
801 { 0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" },
802 { 0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" },
803 { 0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" },
804 { 0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" },
805 { 0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" },
806 { 0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" },
807 { 0x00B0, "TLS_PSK_WITH_NULL_SHA256" },
808 { 0x00B1, "TLS_PSK_WITH_NULL_SHA384" },
809 { 0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" },
810 { 0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" },
811 { 0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256" },
812 { 0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384" },
813 { 0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" },
814 { 0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" },
815 { 0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256" },
816 { 0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384" },
819 { 0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
820 { 0x00BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
821 { 0x00BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
822 { 0x00BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
823 { 0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
824 { 0x00BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" },
825 { 0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
826 { 0x00C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
827 { 0x00C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
828 { 0x00C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
829 { 0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
830 { 0x00C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" },
831 /* 0x00,0xC6-FE Unassigned */
833 { 0x00FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" },
834 /* https://tools.ietf.org/html/draft-ietf-tls-tls13 */
835 { 0x1301, "TLS_AES_128_GCM_SHA256" },
836 { 0x1302, "TLS_AES_256_GCM_SHA384" },
837 { 0x1303, "TLS_CHACHA20_POLY1305_SHA256" },
838 { 0x1304, "TLS_AES_128_CCM_SHA256" },
839 { 0x1305, "TLS_AES_128_CCM_8_SHA256" },
841 { 0x5600, "TLS_FALLBACK_SCSV" },
843 { 0xc001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
844 { 0xc002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
845 { 0xc003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
846 { 0xc004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
847 { 0xc005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
848 { 0xc006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" },
849 { 0xc007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" },
850 { 0xc008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" },
851 { 0xc009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
852 { 0xc00a, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
853 { 0xc00b, "TLS_ECDH_RSA_WITH_NULL_SHA" },
854 { 0xc00c, "TLS_ECDH_RSA_WITH_RC4_128_SHA" },
855 { 0xc00d, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" },
856 { 0xc00e, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" },
857 { 0xc00f, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" },
858 { 0xc010, "TLS_ECDHE_RSA_WITH_NULL_SHA" },
859 { 0xc011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" },
860 { 0xc012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" },
861 { 0xc013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
862 { 0xc014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
863 { 0xc015, "TLS_ECDH_anon_WITH_NULL_SHA" },
864 { 0xc016, "TLS_ECDH_anon_WITH_RC4_128_SHA" },
865 { 0xc017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" },
866 { 0xc018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" },
867 { 0xc019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" },
870 { 0xC01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" },
871 { 0xC01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" },
872 { 0xC01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" },
873 { 0xC01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" },
874 { 0xC01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" },
875 { 0xC01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" },
876 { 0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
877 { 0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
878 { 0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
881 { 0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" },
882 { 0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" },
883 { 0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" },
884 { 0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" },
885 { 0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" },
886 { 0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" },
887 { 0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" },
888 { 0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" },
889 { 0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
890 { 0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
891 { 0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" },
892 { 0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" },
893 { 0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
894 { 0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
895 { 0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" },
896 { 0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" },
899 { 0xC033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" },
900 { 0xC034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" },
901 { 0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" },
902 { 0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" },
903 { 0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" },
904 { 0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" },
905 { 0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA" },
906 { 0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" },
907 { 0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" },
910 { 0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256" },
911 { 0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384" },
912 { 0xC03E, "TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256" },
913 { 0xC03F, "TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384" },
914 { 0xC040, "TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256" },
915 { 0xC041, "TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384" },
916 { 0xC042, "TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256" },
917 { 0xC043, "TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384" },
918 { 0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256" },
919 { 0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384" },
920 { 0xC046, "TLS_DH_anon_WITH_ARIA_128_CBC_SHA256" },
921 { 0xC047, "TLS_DH_anon_WITH_ARIA_256_CBC_SHA384" },
922 { 0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256" },
923 { 0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384" },
924 { 0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256" },
925 { 0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384" },
926 { 0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256" },
927 { 0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384" },
928 { 0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256" },
929 { 0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384" },
930 { 0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256" },
931 { 0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384" },
932 { 0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256" },
933 { 0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384" },
934 { 0xC054, "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256" },
935 { 0xC055, "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384" },
936 { 0xC056, "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256" },
937 { 0xC057, "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384" },
938 { 0xC058, "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256" },
939 { 0xC059, "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384" },
940 { 0xC05A, "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256" },
941 { 0xC05B, "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384" },
942 { 0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256" },
943 { 0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384" },
944 { 0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256" },
945 { 0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384" },
946 { 0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256" },
947 { 0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384" },
948 { 0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256" },
949 { 0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384" },
950 { 0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256" },
951 { 0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384" },
952 { 0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256" },
953 { 0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384" },
954 { 0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256" },
955 { 0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384" },
956 { 0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256" },
957 { 0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384" },
958 { 0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256" },
959 { 0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384" },
960 { 0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256" },
961 { 0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384" },
962 { 0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256" },
963 { 0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384" },
966 { 0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" },
967 { 0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" },
968 { 0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" },
969 { 0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" },
970 { 0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
971 { 0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384" },
972 { 0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
973 { 0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384" },
974 { 0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
975 { 0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
976 { 0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
977 { 0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
978 { 0xC07E, "TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
979 { 0xC07F, "TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
980 { 0xC080, "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256" },
981 { 0xC081, "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384" },
982 { 0xC082, "TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256" },
983 { 0xC083, "TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384" },
984 { 0xC084, "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256" },
985 { 0xC085, "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384" },
986 { 0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" },
987 { 0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" },
988 { 0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" },
989 { 0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" },
990 { 0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
991 { 0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
992 { 0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
993 { 0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
994 { 0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
995 { 0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
996 { 0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
997 { 0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
998 { 0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
999 { 0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
1000 { 0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
1001 { 0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
1002 { 0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
1003 { 0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
1004 { 0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
1005 { 0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
1006 { 0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
1007 { 0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
1010 { 0xC09C, "TLS_RSA_WITH_AES_128_CCM" },
1011 { 0xC09D, "TLS_RSA_WITH_AES_256_CCM" },
1012 { 0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM" },
1013 { 0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM" },
1014 { 0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8" },
1015 { 0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8" },
1016 { 0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8" },
1017 { 0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8" },
1018 { 0xC0A4, "TLS_PSK_WITH_AES_128_CCM" },
1019 { 0xC0A5, "TLS_PSK_WITH_AES_256_CCM" },
1020 { 0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM" },
1021 { 0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM" },
1022 { 0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8" },
1023 { 0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8" },
1024 { 0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8" },
1025 { 0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8" },
1028 { 0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM" },
1029 { 0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM" },
1030 { 0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" },
1031 { 0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8" },
1033 0xC0,0xAB-FF Unassigned
1034 0xC1-FD,* Unassigned
1035 0xFE,0x00-FD Unassigned
1036 0xFE,0xFE-FF Reserved to avoid conflicts with widely deployed implementations [Pasi_Eronen]
1037 0xFF,0x00-FF Reserved for Private Use [RFC5246]
1040 /* old numbers used in the beginning
1041 * http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 */
1042 { 0xCC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1043 { 0xCC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
1044 { 0xCC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1046 /* http://tools.ietf.org/html/draft-ietf-tls-chacha20-poly1305 */
1047 { 0xCCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1048 { 0xCCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
1049 { 0xCCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1050 { 0xCCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1051 { 0xCCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1052 { 0xCCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1053 { 0xCCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1055 /* http://tools.ietf.org/html/draft-josefsson-salsa20-tls */
1056 { 0xE410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1057 { 0xE411, "TLS_RSA_WITH_SALSA20_SHA1" },
1058 { 0xE412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1059 { 0xE413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" },
1060 { 0xE414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" },
1061 { 0xE415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" },
1062 { 0xE416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1063 { 0xE417, "TLS_PSK_WITH_SALSA20_SHA1" },
1064 { 0xE418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1065 { 0xE419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" },
1066 { 0xE41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1067 { 0xE41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" },
1068 { 0xE41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1069 { 0xE41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" },
1070 { 0xE41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1071 { 0xE41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" },
1073 /* these from http://www.mozilla.org/projects/
1074 security/pki/nss/ssl/fips-ssl-ciphersuites.html */
1075 { 0xfefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
1076 { 0xfeff, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
1077 { 0xffe0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
1078 { 0xffe1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
1079 /* note that ciphersuites 0xff00 - 0xffff are private */
1083 value_string_ext ssl_31_ciphersuite_ext = VALUE_STRING_EXT_INIT(ssl_31_ciphersuite);
1086 const value_string pct_msg_types[] = {
1087 { PCT_MSG_CLIENT_HELLO, "Client Hello" },
1088 { PCT_MSG_SERVER_HELLO, "Server Hello" },
1089 { PCT_MSG_CLIENT_MASTER_KEY, "Client Master Key" },
1090 { PCT_MSG_SERVER_VERIFY, "Server Verify" },
1091 { PCT_MSG_ERROR, "Error" },
1095 const value_string pct_cipher_type[] = {
1096 { PCT_CIPHER_DES, "DES" },
1097 { PCT_CIPHER_IDEA, "IDEA" },
1098 { PCT_CIPHER_RC2, "RC2" },
1099 { PCT_CIPHER_RC4, "RC4" },
1100 { PCT_CIPHER_DES_112, "DES 112 bit" },
1101 { PCT_CIPHER_DES_168, "DES 168 bit" },
1105 const value_string pct_hash_type[] = {
1106 { PCT_HASH_MD5, "MD5" },
1107 { PCT_HASH_MD5_TRUNC_64, "MD5_TRUNC_64"},
1108 { PCT_HASH_SHA, "SHA"},
1109 { PCT_HASH_SHA_TRUNC_80, "SHA_TRUNC_80"},
1110 { PCT_HASH_DES_DM, "DES_DM"},
1114 const value_string pct_cert_type[] = {
1115 { PCT_CERT_NONE, "None" },
1116 { PCT_CERT_X509, "X.509" },
1117 { PCT_CERT_PKCS7, "PKCS #7" },
1120 const value_string pct_sig_type[] = {
1121 { PCT_SIG_NONE, "None" },
1122 { PCT_SIG_RSA_MD5, "MD5" },
1123 { PCT_SIG_RSA_SHA, "RSA SHA" },
1124 { PCT_SIG_DSA_SHA, "DSA SHA" },
1128 const value_string pct_exch_type[] = {
1129 { PCT_EXCH_RSA_PKCS1, "RSA PKCS#1" },
1130 { PCT_EXCH_RSA_PKCS1_TOKEN_DES, "RSA PKCS#1 Token DES" },
1131 { PCT_EXCH_RSA_PKCS1_TOKEN_DES3, "RSA PKCS#1 Token 3DES" },
1132 { PCT_EXCH_RSA_PKCS1_TOKEN_RC2, "RSA PKCS#1 Token RC-2" },
1133 { PCT_EXCH_RSA_PKCS1_TOKEN_RC4, "RSA PKCS#1 Token RC-4" },
1134 { PCT_EXCH_DH_PKCS3, "DH PKCS#3" },
1135 { PCT_EXCH_DH_PKCS3_TOKEN_DES, "DH PKCS#3 Token DES" },
1136 { PCT_EXCH_DH_PKCS3_TOKEN_DES3, "DH PKCS#3 Token 3DES" },
1137 { PCT_EXCH_FORTEZZA_TOKEN, "Fortezza" },
1141 const value_string pct_error_code[] = {
1142 { PCT_ERR_BAD_CERTIFICATE, "PCT_ERR_BAD_CERTIFICATE" },
1143 { PCT_ERR_CLIENT_AUTH_FAILED, "PCT_ERR_CLIENT_AUTH_FAILE" },
1144 { PCT_ERR_ILLEGAL_MESSAGE, "PCT_ERR_ILLEGAL_MESSAGE" },
1145 { PCT_ERR_INTEGRITY_CHECK_FAILED, "PCT_ERR_INTEGRITY_CHECK_FAILED" },
1146 { PCT_ERR_SERVER_AUTH_FAILED, "PCT_ERR_SERVER_AUTH_FAILED" },
1147 { PCT_ERR_SPECS_MISMATCH, "PCT_ERR_SPECS_MISMATCH" },
1151 /* http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#tls-extensiontype-values-1 */
1152 const value_string tls_hello_extension_types[] = {
1153 { SSL_HND_HELLO_EXT_SERVER_NAME, "server_name" }, /* RFC 6066 */
1154 { SSL_HND_HELLO_EXT_MAX_FRAGMENT_LENGTH, "max_fragment_length" },/* RFC 6066 */
1155 { SSL_HND_HELLO_EXT_CLIENT_CERTIFICATE_URL, "client_certificate_url" }, /* RFC 6066 */
1156 { SSL_HND_HELLO_EXT_TRUSTED_CA_KEYS, "trusted_ca_keys" }, /* RFC 6066 */
1157 { SSL_HND_HELLO_EXT_TRUNCATED_HMAC, "truncated_hmac" }, /* RFC 6066 */
1158 { SSL_HND_HELLO_EXT_STATUS_REQUEST, "status_request" }, /* RFC 6066 */
1159 { SSL_HND_HELLO_EXT_USER_MAPPING, "user_mapping" }, /* RFC 4681 */
1160 { SSL_HND_HELLO_EXT_CLIENT_AUTHZ, "client_authz" }, /* RFC 5878 */
1161 { SSL_HND_HELLO_EXT_SERVER_AUTHZ, "server_authz" }, /* RFC 5878 */
1162 { SSL_HND_HELLO_EXT_CERT_TYPE, "cert_type" }, /* RFC 6091 */
1163 { SSL_HND_HELLO_EXT_SUPPORTED_GROUPS, "supported_groups" }, /* RFC 4492, RFC 7919 */
1164 { SSL_HND_HELLO_EXT_EC_POINT_FORMATS, "ec_point_formats" }, /* RFC 4492 */
1165 { SSL_HND_HELLO_EXT_SRP, "srp" }, /* RFC 5054 */
1166 { SSL_HND_HELLO_EXT_SIGNATURE_ALGORITHMS, "signature_algorithms" }, /* RFC 5246 */
1167 { SSL_HND_HELLO_EXT_USE_SRTP, "use_srtp" }, /* RFC 5764 */
1168 { SSL_HND_HELLO_EXT_HEARTBEAT, "heartbeat" }, /* RFC 6520 */
1169 { SSL_HND_HELLO_EXT_ALPN, "application_layer_protocol_negotiation" }, /* RFC 7301 */
1170 { SSL_HND_HELLO_EXT_STATUS_REQUEST_V2, "status_request_v2" }, /* RFC 6961 */
1171 { SSL_HND_HELLO_EXT_SIGNED_CERTIFICATE_TIMESTAMP, "signed_certificate_timestamp" }, /* RFC 6962 */
1172 { SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE, "client_certificate_type" }, /* RFC 7250 */
1173 { SSL_HND_HELLO_EXT_SERVER_CERT_TYPE, "server_certificate_type" }, /* RFC 7250 */
1174 { SSL_HND_HELLO_EXT_PADDING, "padding" }, /* RFC 7685 */
1175 { SSL_HND_HELLO_EXT_ENCRYPT_THEN_MAC, "encrypt_then_mac" }, /* RFC 7366 */
1176 { SSL_HND_HELLO_EXT_EXTENDED_MASTER_SECRET, "extended_master_secret" }, /* RFC 7627 */
1177 { SSL_HND_HELLO_EXT_TOKEN_BINDING, "token_binding" }, /* https://tools.ietf.org/html/draft-ietf-tokbind-negotiation */
1178 { SSL_HND_HELLO_EXT_CACHED_INFO, "cached_info" }, /* RFC 7924 */
1179 { SSL_HND_HELLO_EXT_SESSION_TICKET_TLS, "SessionTicket TLS" }, /* RFC 4507 */
1180 { SSL_HND_HELLO_EXT_KEY_SHARE, "key_share" }, /* TLS 1.3 https://tools.ietf.org/html/draft-ietf-tls-tls13 */
1181 { SSL_HND_HELLO_EXT_PRE_SHARED_KEY, "pre_shared_key" }, /* TLS 1.3 https://tools.ietf.org/html/draft-ietf-tls-tls13 */
1182 { SSL_HND_HELLO_EXT_EARLY_DATA, "early_data" }, /* TLS 1.3 https://tools.ietf.org/html/draft-ietf-tls-tls13 */
1183 { SSL_HND_HELLO_EXT_SUPPORTED_VERSIONS, "supported_versions" }, /* TLS 1.3 https://tools.ietf.org/html/draft-ietf-tls-tls13 */
1184 { SSL_HND_HELLO_EXT_COOKIE, "cookie" }, /* TLS 1.3 https://tools.ietf.org/html/draft-ietf-tls-tls13 */
1185 { SSL_HND_HELLO_EXT_PSK_KEY_EXCHANGE_MODES, "psk_key_exchange_modes" }, /* TLS 1.3 https://tools.ietf.org/html/draft-ietf-tls-tls13 */
1186 { SSL_HND_HELLO_EXT_NPN, "next_protocol_negotiation"}, /* https://tools.ietf.org/id/draft-agl-tls-nextprotoneg-03.html */
1187 { SSL_HND_HELLO_EXT_CHANNEL_ID_OLD, "channel_id_old" }, /* http://tools.ietf.org/html/draft-balfanz-tls-channelid-00
1188 https://twitter.com/ericlaw/status/274237352531083264 */
1189 { SSL_HND_HELLO_EXT_CHANNEL_ID, "channel_id" }, /* http://tools.ietf.org/html/draft-balfanz-tls-channelid-01
1190 https://code.google.com/p/chromium/codesearch#chromium/src/net/third_party/nss/ssl/sslt.h&l=209 */
1191 { SSL_HND_HELLO_EXT_RENEGOTIATION_INFO, "renegotiation_info" }, /* RFC 5746 */
1192 { SSL_HND_HELLO_EXT_DRAFT_VERSION_TLS13, "Draft version of TLS 1.3" }, /* for experimentation only https://www.ietf.org/mail-archive/web/tls/current/msg20853.html */
1196 const value_string tls_hello_ext_server_name_type_vs[] = {
1201 /* draft-ietf-tls-tls13-18 4.2.7 */
1202 const value_string tls_hello_ext_psk_ke_mode[] = {
1203 { 0, "PSK-only key establishment (psk_ke)" },
1204 { 1, "PSK key establishment with (EC)DHE key establishment (psk_dhe_ke)" },
1208 /* RFC 5246 7.4.1.4.1 */
1209 const value_string tls_hash_algorithm[] = {
1220 const value_string tls_signature_algorithm[] = {
1229 const value_string tls_certificate_type[] = {
1232 { SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY, "Raw Public Key" }, /* RFC 7250 */
1236 const value_string tls_cert_chain_type[] = {
1237 { SSL_HND_CERT_URL_TYPE_INDIVIDUAL_CERT, "Individual Certificates" },
1238 { SSL_HND_CERT_URL_TYPE_PKIPATH, "PKI Path" },
1242 const value_string tls_cert_status_type[] = {
1243 { SSL_HND_CERT_STATUS_TYPE_OCSP, "OCSP" },
1244 { SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI, "OCSP Multi" },
1248 /* string_string is inappropriate as it compares strings while
1249 * "byte strings MUST NOT be truncated" (RFC 7301) */
1250 typedef struct ssl_alpn_protocol {
1251 const char *proto_name;
1252 gboolean match_exact;
1253 const char *dissector_name;
1254 } ssl_alpn_protocol_t;
1255 /* http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids */
1256 static const ssl_alpn_protocol_t ssl_alpn_protocols[] = {
1257 { "http/1.1", TRUE, "http" },
1258 /* SPDY moves so fast, just 1, 2 and 3 are registered with IANA but there
1259 * already exists 3.1 as of this writing... match the prefix. */
1260 { "spdy/", FALSE, "spdy" },
1261 { "stun.turn", TRUE, "turnchannel" },
1262 { "stun.nat-discovery", TRUE, "stun" },
1263 /* draft-ietf-httpbis-http2-16 */
1264 { "h2-", FALSE, "http2" }, /* draft versions */
1265 { "h2", TRUE, "http2" }, /* final version */
1268 /* Lookup tables }}} */
1270 /* we keep this internal to packet-ssl-utils, as there should be
1271 no need to access it any other way.
1273 This also allows us to hide the dependency on zlib.
1275 struct _SslDecompress {
1282 /* To assist in parsing client/server key exchange messages
1283 0 indicates unknown */
1284 gint ssl_get_keyex_alg(gint cipher)
1286 /* Map Cipher suite number to Key Exchange algorithm {{{ */
1411 return KEX_ECDH_ANON;
1425 return KEX_ECDH_ECDSA;
1439 return KEX_ECDH_RSA;
1459 return KEX_ECDHE_ECDSA;
1473 return KEX_ECDHE_PSK;
1489 return KEX_ECDHE_RSA;
1593 return KEX_SRP_SHA_DSS;
1597 return KEX_SRP_SHA_RSA;
1607 /* StringInfo structure (len + data) functions {{{ */
1610 ssl_data_alloc(StringInfo* str, size_t len)
1612 str->data = (guchar *)g_malloc(len);
1613 /* the allocator can return a null pointer for a size equal to 0,
1614 * and that must be allowed */
1615 if (len > 0 && !str->data)
1617 str->data_len = (guint) len;
1622 ssl_data_set(StringInfo* str, const guchar* data, guint len)
1624 DISSECTOR_ASSERT(data);
1625 memcpy(str->data, data, len);
1626 str->data_len = len;
1629 #ifdef HAVE_LIBGCRYPT
1631 ssl_data_realloc(StringInfo* str, guint len)
1633 str->data = (guchar *)g_realloc(str->data, len);
1636 str->data_len = len;
1641 ssl_data_clone(StringInfo *str)
1643 StringInfo *cloned_str;
1644 cloned_str = (StringInfo *) wmem_alloc0(wmem_file_scope(),
1645 sizeof(StringInfo) + str->data_len);
1646 cloned_str->data = (guchar *) (cloned_str + 1);
1647 ssl_data_set(cloned_str, str->data, str->data_len);
1652 ssl_data_copy(StringInfo* dst, StringInfo* src)
1654 if (dst->data_len < src->data_len) {
1655 if (ssl_data_realloc(dst, src->data_len))
1658 memcpy(dst->data, src->data, src->data_len);
1659 dst->data_len = src->data_len;
1664 /* from_hex converts |hex_len| bytes of hex data from |in| and sets |*out| to
1665 * the result. |out->data| will be allocated using wmem_file_scope. Returns TRUE on
1667 static gboolean from_hex(StringInfo* out, const char* in, gsize hex_len) {
1673 out->data = (guchar *)wmem_alloc(wmem_file_scope(), hex_len / 2);
1674 for (i = 0; i < hex_len / 2; i++) {
1675 int a = ws_xton(in[i*2]);
1676 int b = ws_xton(in[i*2 + 1]);
1677 if (a == -1 || b == -1)
1679 out->data[i] = a << 4 | b;
1681 out->data_len = (guint)hex_len / 2;
1684 /* StringInfo structure (len + data) functions }}} */
1687 #ifdef HAVE_LIBGCRYPT
1689 /* libgcrypt wrappers for HMAC/message digest operations {{{ */
1690 /* hmac abstraction layer */
1691 #define SSL_HMAC gcry_md_hd_t
1694 ssl_hmac_init(SSL_HMAC* md, const void * key, gint len, gint algo)
1697 const char *err_str, *err_src;
1699 err = gcry_md_open(md,algo, GCRY_MD_FLAG_HMAC);
1701 err_str = gcry_strerror(err);
1702 err_src = gcry_strsource(err);
1703 ssl_debug_printf("ssl_hmac_init(): gcry_md_open failed %s/%s", err_str, err_src);
1706 gcry_md_setkey (*(md), key, len);
1710 ssl_hmac_update(SSL_HMAC* md, const void* data, gint len)
1712 gcry_md_write(*(md), data, len);
1715 ssl_hmac_final(SSL_HMAC* md, guchar* data, guint* datalen)
1720 algo = gcry_md_get_algo (*(md));
1721 len = gcry_md_get_algo_dlen(algo);
1722 DISSECTOR_ASSERT(len <= *datalen);
1723 memcpy(data, gcry_md_read(*(md), algo), len);
1727 ssl_hmac_cleanup(SSL_HMAC* md)
1729 gcry_md_close(*(md));
1732 /* message digest abstraction layer*/
1733 #define SSL_MD gcry_md_hd_t
1736 ssl_md_init(SSL_MD* md, gint algo)
1739 const char *err_str, *err_src;
1740 err = gcry_md_open(md,algo, 0);
1742 err_str = gcry_strerror(err);
1743 err_src = gcry_strsource(err);
1744 ssl_debug_printf("ssl_md_init(): gcry_md_open failed %s/%s", err_str, err_src);
1750 ssl_md_update(SSL_MD* md, guchar* data, gint len)
1752 gcry_md_write(*(md), data, len);
1755 ssl_md_final(SSL_MD* md, guchar* data, guint* datalen)
1759 algo = gcry_md_get_algo (*(md));
1760 len = gcry_md_get_algo_dlen (algo);
1761 memcpy(data, gcry_md_read(*(md), algo), len);
1765 ssl_md_cleanup(SSL_MD* md)
1767 gcry_md_close(*(md));
1770 /* md5 /sha abstraction layer */
1771 #define SSL_SHA_CTX gcry_md_hd_t
1772 #define SSL_MD5_CTX gcry_md_hd_t
1775 ssl_sha_init(SSL_SHA_CTX* md)
1777 gcry_md_open(md,GCRY_MD_SHA1, 0);
1780 ssl_sha_update(SSL_SHA_CTX* md, guchar* data, gint len)
1782 gcry_md_write(*(md), data, len);
1785 ssl_sha_final(guchar* buf, SSL_SHA_CTX* md)
1787 memcpy(buf, gcry_md_read(*(md), GCRY_MD_SHA1),
1788 gcry_md_get_algo_dlen(GCRY_MD_SHA1));
1791 ssl_sha_cleanup(SSL_SHA_CTX* md)
1793 gcry_md_close(*(md));
1797 ssl_md5_init(SSL_MD5_CTX* md)
1799 return gcry_md_open(md,GCRY_MD_MD5, 0);
1802 ssl_md5_update(SSL_MD5_CTX* md, guchar* data, gint len)
1804 gcry_md_write(*(md), data, len);
1807 ssl_md5_final(guchar* buf, SSL_MD5_CTX* md)
1809 memcpy(buf, gcry_md_read(*(md), GCRY_MD_MD5),
1810 gcry_md_get_algo_dlen(GCRY_MD_MD5));
1813 ssl_md5_cleanup(SSL_MD5_CTX* md)
1815 gcry_md_close(*(md));
1817 /* libgcrypt wrappers for HMAC/message digest operations }}} */
1819 /* libgcrypt wrappers for Cipher state manipulation {{{ */
1821 ssl_cipher_setiv(SSL_CIPHER_CTX *cipher, guchar* iv, gint iv_len)
1828 c=(gcry_cipher_hd_t)*cipher;
1830 ssl_debug_printf("--------------------------------------------------------------------");
1832 for(ivp=c->iv,i=0; i < iv_len; i++ )
1834 ssl_debug_printf("%d ",ivp[i]);
1838 ssl_debug_printf("--------------------------------------------------------------------");
1839 ret = gcry_cipher_setiv(*(cipher), iv, iv_len);
1841 for(ivp=c->iv,i=0; i < iv_len; i++ )
1843 ssl_debug_printf("%d ",ivp[i]);
1847 ssl_debug_printf("--------------------------------------------------------------------");
1850 /* stream cipher abstraction layer*/
1852 ssl_cipher_init(gcry_cipher_hd_t *cipher, gint algo, guchar* sk,
1853 guchar* iv, gint mode)
1855 gint gcry_modes[] = {
1856 GCRY_CIPHER_MODE_STREAM,
1857 GCRY_CIPHER_MODE_CBC,
1858 #ifdef HAVE_LIBGCRYPT_AEAD
1859 GCRY_CIPHER_MODE_GCM,
1860 GCRY_CIPHER_MODE_CCM,
1861 GCRY_CIPHER_MODE_CCM
1863 GCRY_CIPHER_MODE_CTR,
1864 GCRY_CIPHER_MODE_CTR,
1865 GCRY_CIPHER_MODE_CTR,
1871 *(cipher) = (gcry_cipher_hd_t)-1;
1874 err = gcry_cipher_open(cipher, algo, gcry_modes[mode], 0);
1877 err = gcry_cipher_setkey(*(cipher), sk, gcry_cipher_get_algo_keylen (algo));
1880 /* AEAD cipher suites will set the nonce later. */
1881 if (mode == MODE_CBC) {
1882 err = gcry_cipher_setiv(*(cipher), iv, gcry_cipher_get_algo_blklen(algo));
1889 ssl_cipher_decrypt(gcry_cipher_hd_t *cipher, guchar * out, gint outl,
1890 const guchar * in, gint inl)
1892 if ((*cipher) == (gcry_cipher_hd_t)-1)
1895 memcpy(out, in, outl < inl ? outl : inl);
1898 return gcry_cipher_decrypt ( *(cipher), out, outl, in, inl);
1901 ssl_get_digest_by_name(const gchar*name)
1903 return gcry_md_map_name(name);
1906 ssl_get_cipher_by_name(const gchar* name)
1908 return gcry_cipher_map_name(name);
1912 ssl_cipher_cleanup(gcry_cipher_hd_t *cipher)
1914 if ((*cipher) != (gcry_cipher_hd_t)-1)
1915 gcry_cipher_close(*cipher);
1918 /* libgcrypt wrappers for Cipher state manipulation }}} */
1920 #ifdef HAVE_LIBGNUTLS
1921 /* libgcrypt wrapper to decrypt using a RSA private key {{{ */
1922 /* decrypt data with private key. Store decrypted data directly into input
1925 ssl_private_decrypt(const guint len, guchar* data, gcry_sexp_t pk)
1928 size_t decr_len = 0, i = 0;
1929 gcry_sexp_t s_data = NULL, s_plain = NULL;
1930 gcry_mpi_t encr_mpi = NULL, text = NULL;
1932 /* create mpi representation of encrypted data */
1933 rc = gcry_mpi_scan(&encr_mpi, GCRYMPI_FMT_USG, data, len, NULL);
1935 ssl_debug_printf("pcry_private_decrypt: can't convert data to mpi (size %d):%s\n",
1936 len, gcry_strerror(rc));
1940 /* put the data into a simple list */
1941 rc = gcry_sexp_build(&s_data, NULL, "(enc-val(rsa(a%m)))", encr_mpi);
1943 ssl_debug_printf("pcry_private_decrypt: can't build encr_sexp:%s\n",
1949 /* pass it to libgcrypt */
1950 rc = gcry_pk_decrypt(&s_plain, s_data, pk);
1953 ssl_debug_printf("pcry_private_decrypt: can't decrypt key:%s\n",
1959 /* convert plain text sexp to mpi format */
1960 text = gcry_sexp_nth_mpi(s_plain, 0, 0);
1962 ssl_debug_printf("pcry_private_decrypt: can't convert sexp to mpi\n");
1967 /* compute size requested for plaintext buffer */
1968 rc = gcry_mpi_print(GCRYMPI_FMT_USG, NULL, 0, &decr_len, text);
1970 ssl_debug_printf("pcry_private_decrypt: can't compute decr size:%s\n",
1976 /* sanity check on out buffer */
1977 if (decr_len > len) {
1978 ssl_debug_printf("pcry_private_decrypt: decrypted data is too long ?!? (%" G_GSIZE_MODIFIER "u max %d)\n", decr_len, len);
1983 /* write plain text to newly allocated buffer */
1984 rc = gcry_mpi_print(GCRYMPI_FMT_USG, data, len, &decr_len, text);
1986 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));
1991 ssl_print_data("decrypted_unstrip_pre_master", data, decr_len);
1993 /* strip the padding*/
1995 for (i = 1; i < decr_len; i++) {
2002 ssl_debug_printf("pcry_private_decrypt: stripping %d bytes, decr_len %" G_GSIZE_MODIFIER "u\n", rc, decr_len);
2004 memmove(data, data+rc, decr_len);
2007 gcry_sexp_release(s_data);
2008 gcry_sexp_release(s_plain);
2009 gcry_mpi_release(encr_mpi);
2010 gcry_mpi_release(text);
2011 return (int) decr_len;
2013 #endif /* HAVE_LIBGNUTLS */
2015 #else /* ! HAVE_LIBGCRYPT */
2018 ssl_cipher_setiv(SSL_CIPHER_CTX *cipher _U_, guchar* iv _U_, gint iv_len _U_)
2020 ssl_debug_printf("ssl_cipher_setiv: impossible without gnutls.\n");
2023 #endif /* ! HAVE_LIBGCRYPT */
2026 #ifdef HAVE_LIBGCRYPT /* Save space if decryption is not enabled. */
2028 /* Digests, Ciphers and Cipher Suites registry {{{ */
2029 static const SslDigestAlgo digests[]={
2034 {"Not Applicable", 0},
2037 #define DIGEST_MAX_SIZE 48
2039 /* get index digest index */
2040 static const SslDigestAlgo *
2041 ssl_cipher_suite_dig(const SslCipherSuite *cs) {
2042 return &digests[cs->dig - DIG_MD5];
2045 static const gchar *ciphers[]={
2048 "ARCFOUR", /* libgcrypt does not support rc4, but this should be 100% compatible*/
2049 "RFC2268_128", /* libgcrypt name for RC2 with a 128-bit key */
2059 static const SslCipherSuite cipher_suites[]={
2060 {0x0001,KEX_RSA, ENC_NULL, DIG_MD5, MODE_STREAM}, /* TLS_RSA_WITH_NULL_MD5 */
2061 {0x0002,KEX_RSA, ENC_NULL, DIG_SHA, MODE_STREAM}, /* TLS_RSA_WITH_NULL_SHA */
2062 {0x0003,KEX_RSA, ENC_RC4, DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT_WITH_RC4_40_MD5 */
2063 {0x0004,KEX_RSA, ENC_RC4, DIG_MD5, MODE_STREAM}, /* TLS_RSA_WITH_RC4_128_MD5 */
2064 {0x0005,KEX_RSA, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_RSA_WITH_RC4_128_SHA */
2065 {0x0006,KEX_RSA, ENC_RC2, DIG_MD5, MODE_CBC }, /* TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 */
2066 {0x0007,KEX_RSA, ENC_IDEA, DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_IDEA_CBC_SHA */
2067 {0x0008,KEX_RSA, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_RSA_EXPORT_WITH_DES40_CBC_SHA */
2068 {0x0009,KEX_RSA, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_DES_CBC_SHA */
2069 {0x000A,KEX_RSA, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_3DES_EDE_CBC_SHA */
2070 {0x000B,KEX_DH_DSS, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA */
2071 {0x000C,KEX_DH_DSS, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_DES_CBC_SHA */
2072 {0x000D,KEX_DH_DSS, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA */
2073 {0x000E,KEX_DH_RSA, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA */
2074 {0x000F,KEX_DH_RSA, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_DES_CBC_SHA */
2075 {0x0010,KEX_DH_RSA, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA */
2076 {0x0011,KEX_DHE_DSS, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA */
2077 {0x0012,KEX_DHE_DSS, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_DES_CBC_SHA */
2078 {0x0013,KEX_DHE_DSS, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA */
2079 {0x0014,KEX_DHE_RSA, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA */
2080 {0x0015,KEX_DHE_RSA, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_DES_CBC_SHA */
2081 {0x0016,KEX_DHE_RSA, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */
2082 {0x0017,KEX_DH_ANON, ENC_RC4, DIG_MD5, MODE_STREAM}, /* TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 */
2083 {0x0018,KEX_DH_ANON, ENC_RC4, DIG_MD5, MODE_STREAM}, /* TLS_DH_anon_WITH_RC4_128_MD5 */
2084 {0x0019,KEX_DH_ANON, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA */
2085 {0x001A,KEX_DH_ANON, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_DES_CBC_SHA */
2086 {0x001B,KEX_DH_ANON, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_3DES_EDE_CBC_SHA */
2087 {0x002C,KEX_PSK, ENC_NULL, DIG_SHA, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA */
2088 {0x002D,KEX_DHE_PSK, ENC_NULL, DIG_SHA, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA */
2089 {0x002E,KEX_RSA_PSK, ENC_NULL, DIG_SHA, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA */
2090 {0x002F,KEX_RSA, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_AES_128_CBC_SHA */
2091 {0x0030,KEX_DH_DSS, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_128_CBC_SHA */
2092 {0x0031,KEX_DH_RSA, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_128_CBC_SHA */
2093 {0x0032,KEX_DHE_DSS, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_128_CBC_SHA */
2094 {0x0033,KEX_DHE_RSA, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
2095 {0x0034,KEX_DH_ANON, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_AES_128_CBC_SHA */
2096 {0x0035,KEX_RSA, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_AES_256_CBC_SHA */
2097 {0x0036,KEX_DH_DSS, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_256_CBC_SHA */
2098 {0x0037,KEX_DH_RSA, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_256_CBC_SHA */
2099 {0x0038,KEX_DHE_DSS, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_256_CBC_SHA */
2100 {0x0039,KEX_DHE_RSA, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */
2101 {0x003A,KEX_DH_ANON, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_AES_256_CBC_SHA */
2102 {0x003B,KEX_RSA, ENC_NULL, DIG_SHA256, MODE_STREAM}, /* TLS_RSA_WITH_NULL_SHA256 */
2103 {0x003C,KEX_RSA, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_AES_128_CBC_SHA256 */
2104 {0x003D,KEX_RSA, ENC_AES256, DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_AES_256_CBC_SHA256 */
2105 {0x003E,KEX_DH_DSS, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_128_CBC_SHA256 */
2106 {0x003F,KEX_DH_RSA, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_128_CBC_SHA256 */
2107 {0x0040,KEX_DHE_DSS, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 */
2108 {0x0041,KEX_RSA, ENC_CAMELLIA128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */
2109 {0x0042,KEX_DH_DSS, ENC_CAMELLIA128,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA */
2110 {0x0043,KEX_DH_RSA, ENC_CAMELLIA128,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA */
2111 {0x0044,KEX_DHE_DSS, ENC_CAMELLIA128,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA */
2112 {0x0045,KEX_DHE_RSA, ENC_CAMELLIA128,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */
2113 {0x0046,KEX_DH_ANON, ENC_CAMELLIA128,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA */
2114 {0x0060,KEX_RSA, ENC_RC4, DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC4_56_MD5 */
2115 {0x0061,KEX_RSA, ENC_RC2, DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 */
2116 {0x0062,KEX_RSA, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA */
2117 {0x0063,KEX_DHE_DSS, ENC_DES, DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA */
2118 {0x0064,KEX_RSA, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC4_56_SHA */
2119 {0x0065,KEX_DHE_DSS, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA */
2120 {0x0066,KEX_DHE_DSS, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_DHE_DSS_WITH_RC4_128_SHA */
2121 {0x0067,KEX_DHE_RSA, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */
2122 {0x0068,KEX_DH_DSS, ENC_AES256, DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_256_CBC_SHA256 */
2123 {0x0069,KEX_DH_RSA, ENC_AES256, DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_256_CBC_SHA256 */
2124 {0x006A,KEX_DHE_DSS, ENC_AES256, DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 */
2125 {0x006B,KEX_DHE_RSA, ENC_AES256, DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */
2126 {0x006C,KEX_DH_ANON, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_AES_128_CBC_SHA256 */
2127 {0x006D,KEX_DH_ANON, ENC_AES256, DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_AES_256_CBC_SHA256 */
2128 {0x0084,KEX_RSA, ENC_CAMELLIA256,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */
2129 {0x0085,KEX_DH_DSS, ENC_CAMELLIA256,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA */
2130 {0x0086,KEX_DH_RSA, ENC_CAMELLIA256,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA */
2131 {0x0087,KEX_DHE_DSS, ENC_CAMELLIA256,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA */
2132 {0x0088,KEX_DHE_RSA, ENC_CAMELLIA256,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */
2133 {0x0089,KEX_DH_ANON, ENC_CAMELLIA256,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA */
2134 {0x008A,KEX_PSK, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_PSK_WITH_RC4_128_SHA */
2135 {0x008B,KEX_PSK, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_3DES_EDE_CBC_SHA */
2136 {0x008C,KEX_PSK, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_AES_128_CBC_SHA */
2137 {0x008D,KEX_PSK, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_AES_256_CBC_SHA */
2138 {0x008E,KEX_DHE_PSK, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_DHE_PSK_WITH_RC4_128_SHA */
2139 {0x008F,KEX_DHE_PSK, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA */
2140 {0x0090,KEX_DHE_PSK, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA */
2141 {0x0091,KEX_DHE_PSK, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA */
2142 {0x0092,KEX_RSA_PSK, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_RSA_PSK_WITH_RC4_128_SHA */
2143 {0x0093,KEX_RSA_PSK, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA */
2144 {0x0094,KEX_RSA_PSK, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_128_CBC_SHA */
2145 {0x0095,KEX_RSA_PSK, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_256_CBC_SHA */
2146 {0x0096,KEX_RSA, ENC_SEED, DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_SEED_CBC_SHA */
2147 {0x0097,KEX_DH_DSS, ENC_SEED, DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_SEED_CBC_SHA */
2148 {0x0098,KEX_DH_RSA, ENC_SEED, DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_SEED_CBC_SHA */
2149 {0x0099,KEX_DHE_DSS, ENC_SEED, DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_SEED_CBC_SHA */
2150 {0x009A,KEX_DHE_RSA, ENC_SEED, DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_SEED_CBC_SHA */
2151 {0x009B,KEX_DH_ANON, ENC_SEED, DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_SEED_CBC_SHA */
2152 {0x009C,KEX_RSA, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_RSA_WITH_AES_128_GCM_SHA256 */
2153 {0x009D,KEX_RSA, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_RSA_WITH_AES_256_GCM_SHA384 */
2154 {0x009E,KEX_DHE_RSA, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */
2155 {0x009F,KEX_DHE_RSA, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */
2156 {0x00A0,KEX_DH_RSA, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_DH_RSA_WITH_AES_128_GCM_SHA256 */
2157 {0x00A1,KEX_DH_RSA, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_DH_RSA_WITH_AES_256_GCM_SHA384 */
2158 {0x00A2,KEX_DHE_DSS, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 */
2159 {0x00A3,KEX_DHE_DSS, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 */
2160 {0x00A4,KEX_DH_DSS, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_DH_DSS_WITH_AES_128_GCM_SHA256 */
2161 {0x00A5,KEX_DH_DSS, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_DH_DSS_WITH_AES_256_GCM_SHA384 */
2162 {0x00A6,KEX_DH_ANON, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_DH_anon_WITH_AES_128_GCM_SHA256 */
2163 {0x00A7,KEX_DH_ANON, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */
2164 {0x00A8,KEX_PSK, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_PSK_WITH_AES_128_GCM_SHA256 */
2165 {0x00A9,KEX_PSK, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_PSK_WITH_AES_256_GCM_SHA384 */
2166 {0x00AA,KEX_DHE_PSK, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */
2167 {0x00AB,KEX_DHE_PSK, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */
2168 {0x00AC,KEX_RSA_PSK, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 */
2169 {0x00AD,KEX_RSA_PSK, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 */
2170 {0x00AE,KEX_PSK, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_PSK_WITH_AES_128_CBC_SHA256 */
2171 {0x00AF,KEX_PSK, ENC_AES256, DIG_SHA384, MODE_CBC }, /* TLS_PSK_WITH_AES_256_CBC_SHA384 */
2172 {0x00B0,KEX_PSK, ENC_NULL, DIG_SHA256, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA256 */
2173 {0x00B1,KEX_PSK, ENC_NULL, DIG_SHA384, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA384 */
2174 {0x00B2,KEX_DHE_PSK, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */
2175 {0x00B3,KEX_DHE_PSK, ENC_AES256, DIG_SHA384, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */
2176 {0x00B4,KEX_DHE_PSK, ENC_NULL, DIG_SHA256, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA256 */
2177 {0x00B5,KEX_DHE_PSK, ENC_NULL, DIG_SHA384, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA384 */
2178 {0x00B6,KEX_RSA_PSK, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 */
2179 {0x00B7,KEX_RSA_PSK, ENC_AES256, DIG_SHA384, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 */
2180 {0x00B8,KEX_RSA_PSK, ENC_NULL, DIG_SHA256, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA256 */
2181 {0x00B9,KEX_RSA_PSK, ENC_NULL, DIG_SHA384, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA384 */
2182 {0x00BA,KEX_RSA, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2183 {0x00BB,KEX_DH_DSS, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 */
2184 {0x00BC,KEX_DH_RSA, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2185 {0x00BD,KEX_DHE_DSS, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 */
2186 {0x00BE,KEX_DHE_RSA, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2187 {0x00BF,KEX_DH_ANON, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256 */
2188 {0x00C0,KEX_RSA, ENC_CAMELLIA256,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
2189 {0x00C1,KEX_DH_DSS, ENC_CAMELLIA256,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 */
2190 {0x00C2,KEX_DH_RSA, ENC_CAMELLIA256,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
2191 {0x00C3,KEX_DHE_DSS, ENC_CAMELLIA256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 */
2192 {0x00C4,KEX_DHE_RSA, ENC_CAMELLIA256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
2193 {0x00C5,KEX_DH_ANON, ENC_CAMELLIA256,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 */
2195 /* NOTE: TLS 1.3 cipher suites are incompatible with TLS 1.2. */
2196 {0x1301,KEX_TLS13, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_AES_128_GCM_SHA256 */
2197 {0x1302,KEX_TLS13, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_AES_256_GCM_SHA384 */
2198 /* TODO TLS_CHACHA20_POLY1305_SHA256 */
2199 {0x1304,KEX_TLS13, ENC_AES, DIG_SHA256, MODE_CCM }, /* TLS_AES_128_CCM_SHA256 */
2200 {0x1305,KEX_TLS13, ENC_AES, DIG_SHA256, MODE_CCM_8 }, /* TLS_AES_128_CCM_8_SHA256 */
2202 {0xC001,KEX_ECDH_ECDSA, ENC_NULL, DIG_SHA, MODE_STREAM}, /* TLS_ECDH_ECDSA_WITH_NULL_SHA */
2203 {0xC002,KEX_ECDH_ECDSA, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */
2204 {0xC003,KEX_ECDH_ECDSA, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */
2205 {0xC004,KEX_ECDH_ECDSA, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */
2206 {0xC005,KEX_ECDH_ECDSA, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */
2207 {0xC006,KEX_ECDHE_ECDSA, ENC_NULL, DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */
2208 {0xC007,KEX_ECDHE_ECDSA, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */
2209 {0xC008,KEX_ECDHE_ECDSA, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */
2210 {0xC009,KEX_ECDHE_ECDSA, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */
2211 {0xC00A,KEX_ECDHE_ECDSA, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */
2212 {0xC00B,KEX_ECDH_RSA, ENC_NULL, DIG_SHA, MODE_STREAM}, /* TLS_ECDH_RSA_WITH_NULL_SHA */
2213 {0xC00C,KEX_ECDH_RSA, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_ECDH_RSA_WITH_RC4_128_SHA */
2214 {0xC00D,KEX_ECDH_RSA, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */
2215 {0xC00E,KEX_ECDH_RSA, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */
2216 {0xC00F,KEX_ECDH_RSA, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */
2217 {0xC010,KEX_ECDHE_RSA, ENC_NULL, DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_RSA_WITH_NULL_SHA */
2218 {0xC011,KEX_ECDHE_RSA, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */
2219 {0xC012,KEX_ECDHE_RSA, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */
2220 {0xC013,KEX_ECDHE_RSA, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */
2221 {0xC014,KEX_ECDHE_RSA, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */
2222 {0xC015,KEX_ECDH_ANON, ENC_NULL, DIG_SHA, MODE_STREAM}, /* TLS_ECDH_anon_WITH_NULL_SHA */
2223 {0xC016,KEX_ECDH_ANON, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_ECDH_anon_WITH_RC4_128_SHA */
2224 {0xC017,KEX_ECDH_ANON, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA */
2225 {0xC018,KEX_ECDH_ANON, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_AES_128_CBC_SHA */
2226 {0xC019,KEX_ECDH_ANON, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_AES_256_CBC_SHA */
2227 {0xC023,KEX_ECDHE_ECDSA, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 */
2228 {0xC024,KEX_ECDHE_ECDSA, ENC_AES256, DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 */
2229 {0xC025,KEX_ECDH_ECDSA, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */
2230 {0xC026,KEX_ECDH_ECDSA, ENC_AES256, DIG_SHA384, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */
2231 {0xC027,KEX_ECDHE_RSA, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */
2232 {0xC028,KEX_ECDHE_RSA, ENC_AES256, DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */
2233 {0xC029,KEX_ECDH_RSA, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */
2234 {0xC02A,KEX_ECDH_RSA, ENC_AES256, DIG_SHA384, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */
2235 {0xC02B,KEX_ECDHE_ECDSA, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */
2236 {0xC02C,KEX_ECDHE_ECDSA, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */
2237 {0xC02D,KEX_ECDH_ECDSA, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */
2238 {0xC02E,KEX_ECDH_ECDSA, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */
2239 {0xC02F,KEX_ECDHE_RSA, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */
2240 {0xC030,KEX_ECDHE_RSA, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */
2241 {0xC031,KEX_ECDH_RSA, ENC_AES, DIG_SHA256, MODE_GCM }, /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */
2242 {0xC032,KEX_ECDH_RSA, ENC_AES256, DIG_SHA384, MODE_GCM }, /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */
2243 {0xC033,KEX_ECDHE_PSK, ENC_RC4, DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_RC4_128_SHA */
2244 {0xC034,KEX_ECDHE_PSK, ENC_3DES, DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA */
2245 {0xC035,KEX_ECDHE_PSK, ENC_AES, DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA */
2246 {0xC036,KEX_ECDHE_PSK, ENC_AES256, DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA */
2247 {0xC037,KEX_ECDHE_PSK, ENC_AES, DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */
2248 {0xC038,KEX_ECDHE_PSK, ENC_AES256, DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 */
2249 {0xC039,KEX_ECDHE_PSK, ENC_NULL, DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA */
2250 {0xC03A,KEX_ECDHE_PSK, ENC_NULL, DIG_SHA256, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */
2251 {0xC03B,KEX_ECDHE_PSK, ENC_NULL, DIG_SHA384, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA384 */
2252 {0xC072,KEX_ECDHE_ECDSA, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */
2253 {0xC073,KEX_ECDHE_ECDSA, ENC_CAMELLIA256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 */
2254 {0xC074,KEX_ECDH_ECDSA, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */
2255 {0xC075,KEX_ECDH_ECDSA, ENC_CAMELLIA256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 */
2256 {0xC076,KEX_ECDHE_RSA, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2257 {0xC077,KEX_ECDHE_RSA, ENC_CAMELLIA256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 */
2258 {0xC078,KEX_ECDH_RSA, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2259 {0xC079,KEX_ECDH_RSA, ENC_CAMELLIA256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 */
2260 {0xC07A,KEX_RSA, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2261 {0xC07B,KEX_RSA, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2262 {0xC07C,KEX_DHE_RSA, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2263 {0xC07D,KEX_DHE_RSA, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2264 {0xC07E,KEX_DH_RSA, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2265 {0xC07F,KEX_DH_RSA, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2266 {0xC080,KEX_DHE_DSS, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256 */
2267 {0xC081,KEX_DHE_DSS, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384 */
2268 {0xC082,KEX_DH_DSS, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256 */
2269 {0xC083,KEX_DH_DSS, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384 */
2270 {0xC084,KEX_DH_ANON, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256 */
2271 {0xC085,KEX_DH_ANON, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384 */
2272 {0xC086,KEX_ECDHE_ECDSA, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 */
2273 {0xC087,KEX_ECDHE_ECDSA, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */
2274 {0xC088,KEX_ECDH_ECDSA, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 */
2275 {0xC089,KEX_ECDH_ECDSA, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */
2276 {0xC08A,KEX_ECDHE_RSA, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2277 {0xC08B,KEX_ECDHE_RSA, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2278 {0xC08C,KEX_ECDH_RSA, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2279 {0xC08D,KEX_ECDH_RSA, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2280 {0xC08E,KEX_PSK, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2281 {0xC08F,KEX_PSK, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2282 {0xC090,KEX_DHE_PSK, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2283 {0xC091,KEX_DHE_PSK, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2284 {0xC092,KEX_RSA_PSK, ENC_CAMELLIA128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2285 {0xC093,KEX_RSA_PSK, ENC_CAMELLIA256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2286 {0xC094,KEX_PSK, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2287 {0xC095,KEX_PSK, ENC_CAMELLIA256,DIG_SHA384, MODE_CBC }, /* TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2288 {0xC096,KEX_DHE_PSK, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2289 {0xC097,KEX_DHE_PSK, ENC_CAMELLIA256,DIG_SHA384, MODE_CBC }, /* TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2290 {0xC098,KEX_RSA_PSK, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2291 {0xC099,KEX_RSA_PSK, ENC_CAMELLIA256,DIG_SHA384, MODE_CBC }, /* TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2292 {0xC09A,KEX_ECDHE_PSK, ENC_CAMELLIA128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2293 {0xC09B,KEX_ECDHE_PSK, ENC_CAMELLIA256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2294 {0xC09C,KEX_RSA, ENC_AES, DIG_NA, MODE_CCM }, /* TLS_RSA_WITH_AES_128_CCM */
2295 {0xC09D,KEX_RSA, ENC_AES256, DIG_NA, MODE_CCM }, /* TLS_RSA_WITH_AES_256_CCM */
2296 {0xC09E,KEX_DHE_RSA, ENC_AES, DIG_NA, MODE_CCM }, /* TLS_DHE_RSA_WITH_AES_128_CCM */
2297 {0xC09F,KEX_DHE_RSA, ENC_AES256, DIG_NA, MODE_CCM }, /* TLS_DHE_RSA_WITH_AES_256_CCM */
2298 {0xC0A0,KEX_RSA, ENC_AES, DIG_NA, MODE_CCM_8 }, /* TLS_RSA_WITH_AES_128_CCM_8 */
2299 {0xC0A1,KEX_RSA, ENC_AES256, DIG_NA, MODE_CCM_8 }, /* TLS_RSA_WITH_AES_256_CCM_8 */
2300 {0xC0A2,KEX_DHE_RSA, ENC_AES, DIG_NA, MODE_CCM_8 }, /* TLS_DHE_RSA_WITH_AES_128_CCM_8 */
2301 {0xC0A3,KEX_DHE_RSA, ENC_AES256, DIG_NA, MODE_CCM_8 }, /* TLS_DHE_RSA_WITH_AES_256_CCM_8 */
2302 {0xC0A4,KEX_PSK, ENC_AES, DIG_NA, MODE_CCM }, /* TLS_PSK_WITH_AES_128_CCM */
2303 {0xC0A5,KEX_PSK, ENC_AES256, DIG_NA, MODE_CCM }, /* TLS_PSK_WITH_AES_256_CCM */
2304 {0xC0A6,KEX_DHE_PSK, ENC_AES, DIG_NA, MODE_CCM }, /* TLS_DHE_PSK_WITH_AES_128_CCM */
2305 {0xC0A7,KEX_DHE_PSK, ENC_AES256, DIG_NA, MODE_CCM }, /* TLS_DHE_PSK_WITH_AES_256_CCM */
2306 {0xC0A8,KEX_PSK, ENC_AES, DIG_NA, MODE_CCM_8 }, /* TLS_PSK_WITH_AES_128_CCM_8 */
2307 {0xC0A9,KEX_PSK, ENC_AES256, DIG_NA, MODE_CCM_8 }, /* TLS_PSK_WITH_AES_256_CCM_8 */
2308 {0xC0AA,KEX_DHE_PSK, ENC_AES, DIG_NA, MODE_CCM_8 }, /* TLS_PSK_DHE_WITH_AES_128_CCM_8 */
2309 {0xC0AB,KEX_DHE_PSK, ENC_AES256, DIG_NA, MODE_CCM_8 }, /* TLS_PSK_DHE_WITH_AES_256_CCM_8 */
2310 {0xC0AC,KEX_ECDHE_ECDSA, ENC_AES, DIG_NA, MODE_CCM }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */
2311 {0xC0AD,KEX_ECDHE_ECDSA, ENC_AES256, DIG_NA, MODE_CCM }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM */
2312 {0xC0AE,KEX_ECDHE_ECDSA, ENC_AES, DIG_NA, MODE_CCM_8 }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */
2313 {0xC0AF,KEX_ECDHE_ECDSA, ENC_AES256, DIG_NA, MODE_CCM_8 }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */
2314 {-1, 0, 0, 0, MODE_STREAM}
2317 #define MAX_BLOCK_SIZE 16
2318 #define MAX_KEY_SIZE 32
2320 const SslCipherSuite *
2321 ssl_find_cipher(int num)
2323 const SslCipherSuite *c;
2324 for(c=cipher_suites;c->number!=-1;c++){
2334 ssl_get_cipher_blocksize(const SslCipherSuite *cipher_suite)
2337 if (cipher_suite->mode != MODE_CBC) return 0;
2338 cipher_algo = ssl_get_cipher_by_name(ciphers[cipher_suite->enc - 0x30]);
2339 return (guint)gcry_cipher_get_algo_blklen(cipher_algo);
2343 ssl_get_cipher_export_keymat_size(int cipher_suite_num)
2345 switch (cipher_suite_num) {
2346 /* See RFC 6101 (SSL 3.0), Table 2, column Key Material. */
2347 case 0x0003: /* TLS_RSA_EXPORT_WITH_RC4_40_MD5 */
2348 case 0x0006: /* TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 */
2349 case 0x0008: /* TLS_RSA_EXPORT_WITH_DES40_CBC_SHA */
2350 case 0x000B: /* TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA */
2351 case 0x000E: /* TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA */
2352 case 0x0011: /* TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA */
2353 case 0x0014: /* TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA */
2354 case 0x0017: /* TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 */
2355 case 0x0019: /* TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA */
2358 /* not defined in below draft, but "implemented by several vendors",
2359 * https://www.ietf.org/mail-archive/web/tls/current/msg00036.html */
2360 case 0x0060: /* TLS_RSA_EXPORT1024_WITH_RC4_56_MD5 */
2361 case 0x0061: /* TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 */
2364 /* Note: the draft states that DES_CBC needs 8 bytes, but Wireshark always
2365 * used 7. Until a pcap proves 8, let's use the old value. Link:
2366 * https://tools.ietf.org/html/draft-ietf-tls-56-bit-ciphersuites-01 */
2367 case 0x0062: /* TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA */
2368 case 0x0063: /* TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA */
2369 case 0x0064: /* TLS_RSA_EXPORT1024_WITH_RC4_56_SHA */
2370 case 0x0065: /* TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA */
2377 #else /* ! HAVE_LIBGCRYPT */
2378 const SslCipherSuite *
2379 ssl_find_cipher(int num)
2381 ssl_debug_printf("ssl_find_cipher: dummy without gnutls. num %d\n",
2387 ssl_get_cipher_blocksize(const SslCipherSuite *cipher_suite _U_)
2391 #endif /* ! HAVE_LIBGCRYPT */
2393 /* Digests, Ciphers and Cipher Suites registry }}} */
2396 #ifdef HAVE_LIBGCRYPT
2398 /* HMAC and the Pseudorandom function {{{ */
2400 tls_hash(StringInfo *secret, StringInfo *seed, gint md,
2401 StringInfo *out, guint out_len)
2403 /* RFC 2246 5. HMAC and the pseudorandom function
2404 * '+' denotes concatenation.
2405 * P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
2406 * HMAC_hash(secret, A(2) + seed) + ...
2408 * A(i) = HMAC_hash(secret, A(i - 1))
2413 guint8 _A[DIGEST_MAX_SIZE], tmp[DIGEST_MAX_SIZE];
2420 ssl_print_string("tls_hash: hash secret", secret);
2421 ssl_print_string("tls_hash: hash seed", seed);
2424 A_l = seed->data_len;
2427 /* A(i) = HMAC_hash(secret, A(i-1)) */
2428 ssl_hmac_init(&hm, secret->data, secret->data_len, md);
2429 ssl_hmac_update(&hm, A, A_l);
2430 A_l = sizeof(_A); /* upper bound len for hash output */
2431 ssl_hmac_final(&hm, _A, &A_l);
2432 ssl_hmac_cleanup(&hm);
2435 /* HMAC_hash(secret, A(i) + seed) */
2436 ssl_hmac_init(&hm, secret->data, secret->data_len, md);
2437 ssl_hmac_update(&hm, A, A_l);
2438 ssl_hmac_update(&hm, seed->data, seed->data_len);
2439 tmp_l = sizeof(tmp); /* upper bound len for hash output */
2440 ssl_hmac_final(&hm, tmp, &tmp_l);
2441 ssl_hmac_cleanup(&hm);
2443 /* ssl_hmac_final puts the actual digest output size in tmp_l */
2444 tocpy = MIN(left, tmp_l);
2445 memcpy(ptr, tmp, tocpy);
2449 out->data_len = out_len;
2451 ssl_print_string("hash out", out);
2455 tls_prf(StringInfo* secret, const gchar *usage,
2456 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, guint out_len)
2458 StringInfo seed, sha_out, md5_out;
2462 size_t usage_len, rnd2_len;
2463 gboolean success = FALSE;
2464 usage_len = strlen(usage);
2465 rnd2_len = rnd2 ? rnd2->data_len : 0;
2467 /* initalize buffer for sha, md5 random seed*/
2468 if (ssl_data_alloc(&sha_out, MAX(out_len, 20)) < 0) {
2469 ssl_debug_printf("tls_prf: can't allocate sha out\n");
2472 if (ssl_data_alloc(&md5_out, MAX(out_len, 16)) < 0) {
2473 ssl_debug_printf("tls_prf: can't allocate md5 out\n");
2476 if (ssl_data_alloc(&seed, usage_len+rnd1->data_len+rnd2_len) < 0) {
2477 ssl_debug_printf("tls_prf: can't allocate rnd %d\n",
2478 (int) (usage_len+rnd1->data_len+rnd2_len));
2483 memcpy(ptr,usage,usage_len);
2485 memcpy(ptr,rnd1->data,rnd1->data_len);
2487 ptr+=rnd1->data_len;
2488 memcpy(ptr,rnd2->data,rnd2->data_len);
2489 /*ptr+=rnd2->data_len;*/
2492 /* initalize buffer for client/server seeds*/
2493 s_l=secret->data_len/2 + secret->data_len%2;
2494 if (ssl_data_alloc(&s1, s_l) < 0) {
2495 ssl_debug_printf("tls_prf: can't allocate secret %d\n", s_l);
2498 if (ssl_data_alloc(&s2, s_l) < 0) {
2499 ssl_debug_printf("tls_prf: can't allocate secret(2) %d\n", s_l);
2503 memcpy(s1.data,secret->data,s_l);
2504 memcpy(s2.data,secret->data + (secret->data_len - s_l),s_l);
2506 ssl_debug_printf("tls_prf: tls_hash(md5 secret_len %d seed_len %d )\n", s1.data_len, seed.data_len);
2507 tls_hash(&s1, &seed, ssl_get_digest_by_name("MD5"), &md5_out, out_len);
2508 ssl_debug_printf("tls_prf: tls_hash(sha)\n");
2509 tls_hash(&s2, &seed, ssl_get_digest_by_name("SHA1"), &sha_out, out_len);
2511 for (i = 0; i < out_len; i++)
2512 out->data[i] = md5_out.data[i] ^ sha_out.data[i];
2513 /* success, now store the new meaningful data length */
2514 out->data_len = out_len;
2517 ssl_print_string("PRF out",out);
2524 g_free(md5_out.data);
2526 g_free(sha_out.data);
2531 tls12_prf(gint md, StringInfo* secret, const gchar* usage,
2532 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, guint out_len)
2534 StringInfo label_seed;
2535 size_t usage_len, rnd2_len;
2536 rnd2_len = rnd2 ? rnd2->data_len : 0;
2538 usage_len = strlen(usage);
2539 if (ssl_data_alloc(&label_seed, usage_len+rnd1->data_len+rnd2_len) < 0) {
2540 ssl_debug_printf("tls12_prf: can't allocate label_seed\n");
2543 memcpy(label_seed.data, usage, usage_len);
2544 memcpy(label_seed.data+usage_len, rnd1->data, rnd1->data_len);
2546 memcpy(label_seed.data+usage_len+rnd1->data_len, rnd2->data, rnd2->data_len);
2548 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);
2549 tls_hash(secret, &label_seed, md, out, out_len);
2550 g_free(label_seed.data);
2551 ssl_print_string("PRF out", out);
2556 ssl3_generate_export_iv(StringInfo *r1, StringInfo *r2,
2557 StringInfo *out, guint out_len)
2563 ssl_md5_update(&md5,r1->data,r1->data_len);
2564 ssl_md5_update(&md5,r2->data,r2->data_len);
2565 ssl_md5_final(tmp,&md5);
2566 ssl_md5_cleanup(&md5);
2568 DISSECTOR_ASSERT(out_len <= sizeof(tmp));
2569 ssl_data_set(out, tmp, out_len);
2570 ssl_print_string("export iv", out);
2574 ssl3_prf(StringInfo* secret, const gchar* usage,
2575 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, guint out_len)
2583 for (off = 0; off < out_len; off += 16) {
2587 ssl_debug_printf("ssl3_prf: sha1_hash(%d)\n",i);
2588 /* A, BB, CCC, ... */
2594 ssl_sha_update(&sha,buf,i);
2595 ssl_sha_update(&sha,secret->data,secret->data_len);
2597 if(!strcmp(usage,"client write key") || !strcmp(usage,"server write key")){
2599 ssl_sha_update(&sha,rnd2->data,rnd2->data_len);
2600 ssl_sha_update(&sha,rnd1->data,rnd1->data_len);
2603 ssl_sha_update(&sha,rnd1->data,rnd1->data_len);
2605 ssl_sha_update(&sha,rnd2->data,rnd2->data_len);
2608 ssl_sha_final(buf,&sha);
2609 ssl_sha_cleanup(&sha);
2611 ssl_debug_printf("ssl3_prf: md5_hash(%d) datalen %d\n",i,
2614 ssl_md5_update(&md5,secret->data,secret->data_len);
2615 ssl_md5_update(&md5,buf,20);
2616 ssl_md5_final(outbuf,&md5);
2617 ssl_md5_cleanup(&md5);
2619 memcpy(out->data + off, outbuf, MIN(out_len - off, 16));
2621 out->data_len = out_len;
2626 /* out_len is the wanted output length for the pseudorandom function.
2627 * Ensure that ssl->cipher_suite is set. */
2629 prf(SslDecryptSession *ssl, StringInfo *secret, const gchar *usage,
2630 StringInfo *rnd1, StringInfo *rnd2, StringInfo *out, guint out_len)
2632 switch (ssl->session.version) {
2634 return ssl3_prf(secret, usage, rnd1, rnd2, out, out_len);
2637 case TLSV1DOT1_VERSION:
2638 case DTLSV1DOT0_VERSION:
2639 case DTLSV1DOT0_OPENSSL_VERSION:
2640 return tls_prf(secret, usage, rnd1, rnd2, out, out_len);
2642 default: /* TLSv1.2 */
2643 switch (ssl->cipher_suite->dig) {
2645 return tls12_prf(GCRY_MD_SHA384, secret, usage, rnd1, rnd2,
2648 return tls12_prf(GCRY_MD_SHA256, secret, usage, rnd1, rnd2,
2654 static gint tls_handshake_hash(SslDecryptSession* ssl, StringInfo* out)
2659 if (ssl_data_alloc(out, 36) < 0)
2663 ssl_md5_update(&md5,ssl->handshake_data.data,ssl->handshake_data.data_len);
2664 ssl_md5_final(out->data,&md5);
2665 ssl_md5_cleanup(&md5);
2668 ssl_sha_update(&sha,ssl->handshake_data.data,ssl->handshake_data.data_len);
2669 ssl_sha_final(out->data+16,&sha);
2670 ssl_sha_cleanup(&sha);
2674 static gint tls12_handshake_hash(SslDecryptSession* ssl, gint md, StringInfo* out)
2680 ssl_md_init(&mc, md);
2681 ssl_md_update(&mc,ssl->handshake_data.data,ssl->handshake_data.data_len);
2682 ssl_md_final(&mc, tmp, &len);
2683 ssl_md_cleanup(&mc);
2685 if (ssl_data_alloc(out, len) < 0)
2687 memcpy(out->data, tmp, len);
2692 tls13_hkdf_expand_label(int md, const StringInfo *secret, const char *label, const char *hash_value,
2693 guint16 out_len, guchar **out)
2695 /* draft-ietf-tls-tls13-18:
2696 * HKDF-Expand-Label(Secret, Label, HashValue, Length) =
2697 * HKDF-Expand(Secret, HkdfLabel, Length)
2699 * uint16 length = Length;
2700 * opaque label<9..255> = "TLS 1.3, " + Label;
2701 * opaque hash_value<0..255> = HashValue;
2704 * RFC 5869 HMAC-based Extract-and-Expand Key Derivation Function (HKDF):
2705 * HKDF-Expand(PRK, info, L) -> OKM
2707 guchar lastoutput[DIGEST_MAX_SIZE];
2710 const guint label_length = (guint) strlen(label);
2711 const guint hash_value_length = (guint) strlen(hash_value);
2712 const guint hash_len = gcry_md_get_algo_dlen(md);
2714 /* Some sanity checks */
2715 DISSECTOR_ASSERT(out_len > 0 && out_len <= 255 * hash_len);
2716 DISSECTOR_ASSERT(label_length <= 255 - 9);
2717 DISSECTOR_ASSERT(hash_value_length <= 255);
2718 DISSECTOR_ASSERT(hash_len > 0 && hash_len <= DIGEST_MAX_SIZE);
2720 err = gcry_md_open(&h, md, GCRY_MD_FLAG_HMAC);
2722 ssl_debug_printf("%s failed to invoke hash func %d: %s\n", G_STRFUNC, md, gcry_strerror(err));
2726 *out = (guchar *)wmem_alloc(NULL, out_len);
2728 for (guint offset = 0; offset < out_len; offset += hash_len) {
2730 gcry_md_setkey(h, secret->data, secret->data_len); /* Set PRK */
2733 gcry_md_write(h, lastoutput, hash_len); /* T(1..N) */
2736 /* info = HkdfLabel { length, label, hash_value } */
2737 gcry_md_putc(h, out_len >> 8); /* length */
2738 gcry_md_putc(h, (guint8) out_len);
2739 gcry_md_putc(h, 9 + label_length); /* label */
2740 gcry_md_write(h, "TLS 1.3, ", 9);
2741 gcry_md_write(h, label, label_length);
2742 gcry_md_putc(h, hash_value_length); /* hash_value */
2743 gcry_md_write(h, hash_value, hash_value_length);
2745 gcry_md_putc(h, (guint8) (offset / hash_len + 1)); /* constant 0x01..N */
2747 memcpy(lastoutput, gcry_md_read(h, md), hash_len);
2748 memcpy(*out + offset, lastoutput, MIN(hash_len, out_len - offset));
2754 /* HMAC and the Pseudorandom function }}} */
2756 #else /* ! HAVE_LIBGCRYPT */
2757 /* Stub code when decryption support is not available. {{{ */
2759 ssl_generate_pre_master_secret(SslDecryptSession *ssl_session _U_,
2760 guint32 length _U_, tvbuff_t *tvb _U_, guint32 offset _U_,
2761 const gchar *ssl_psk _U_, const ssl_master_key_map_t *mk_map _U_)
2763 ssl_debug_printf("%s: impossible without gnutls.\n", G_STRFUNC);
2767 ssl_generate_keyring_material(SslDecryptSession*ssl)
2769 ssl_debug_printf("ssl_generate_keyring_material: impossible without gnutls. ssl %p\n",
2771 /* We cannot determine whether the cipher suite is valid. Fail such that
2772 * ssl_set_master_secret bails out. */
2776 ssl_change_cipher(SslDecryptSession *ssl_session, gboolean server)
2778 ssl_debug_printf("ssl_change_cipher %s: makes no sense without gnutls. ssl %p\n",
2779 (server)?"SERVER":"CLIENT", ssl_session);
2783 ssl_decrypt_record(SslDecryptSession *ssl, SslDecoder *decoder, guint8 ct, guint16 record_version,
2784 const guchar *in, guint16 inl, StringInfo *comp_str _U_, StringInfo *out_str, guint *outl)
2786 ssl_debug_printf("ssl_decrypt_record: impossible without gnutls. ssl %p"
2787 "decoder %p ct %d version %d in %p inl %d out %p outl %p\n", ssl, decoder, ct,
2788 record_version, in, inl, out_str, outl);
2792 #endif /* ! HAVE_LIBGCRYPT */
2794 #ifdef HAVE_LIBGCRYPT
2795 /* Record Decompression (after decryption) {{{ */
2797 /* memory allocation functions for zlib initialization */
2798 static void* ssl_zalloc(void* opaque _U_, unsigned int no, unsigned int size)
2800 return g_malloc0(no*size);
2802 static void ssl_zfree(void* opaque _U_, void* addr)
2808 static SslDecompress*
2809 ssl_create_decompressor(gint compression)
2811 SslDecompress *decomp;
2816 if (compression == 0) return NULL;
2817 ssl_debug_printf("ssl_create_decompressor: compression method %d\n", compression);
2818 decomp = (SslDecompress *)wmem_alloc(wmem_file_scope(), sizeof(SslDecompress));
2819 decomp->compression = compression;
2820 switch (decomp->compression) {
2822 case 1: /* DEFLATE */
2823 decomp->istream.zalloc = ssl_zalloc;
2824 decomp->istream.zfree = ssl_zfree;
2825 decomp->istream.opaque = Z_NULL;
2826 decomp->istream.next_in = Z_NULL;
2827 decomp->istream.next_out = Z_NULL;
2828 decomp->istream.avail_in = 0;
2829 decomp->istream.avail_out = 0;
2830 err = inflateInit(&decomp->istream);
2832 ssl_debug_printf("ssl_create_decompressor: inflateInit_() failed - %d\n", err);
2838 ssl_debug_printf("ssl_create_decompressor: unsupported compression method %d\n", decomp->compression);
2846 ssl_decompress_record(SslDecompress* decomp, const guchar* in, guint inl, StringInfo* out_str, guint* outl)
2850 switch (decomp->compression) {
2851 case 1: /* DEFLATE */
2853 if (out_str->data_len < 16384) { /* maximal plain length */
2854 ssl_data_realloc(out_str, 16384);
2857 decomp->istream.next_in = in;
2860 decomp->istream.next_in = (Bytef *)in;
2863 decomp->istream.avail_in = inl;
2864 decomp->istream.next_out = out_str->data;
2865 decomp->istream.avail_out = out_str->data_len;
2867 err = inflate(&decomp->istream, Z_SYNC_FLUSH);
2869 ssl_debug_printf("ssl_decompress_record: inflate() failed - %d\n", err);
2872 *outl = out_str->data_len - decomp->istream.avail_out;
2875 ssl_debug_printf("ssl_decompress_record: unsupported compression method %d\n", decomp->compression);
2882 ssl_decompress_record(SslDecompress* decomp _U_, const guchar* in _U_, guint inl _U_, StringInfo* out_str _U_, guint* outl _U_)
2884 ssl_debug_printf("ssl_decompress_record: unsupported compression method %d\n", decomp->compression);
2888 /* Record Decompression (after decryption) }}} */
2889 #endif /* HAVE_LIBGCRYPT */
2891 #ifdef HAVE_LIBGCRYPT
2892 /* Create a new structure to store decrypted chunks. {{{ */
2894 ssl_create_flow(void)
2898 flow = (SslFlow *)wmem_alloc(wmem_file_scope(), sizeof(SslFlow));
2901 flow->multisegment_pdus = wmem_tree_new(wmem_file_scope());
2906 /* Use the negotiated security parameters for decryption. {{{ */
2908 ssl_change_cipher(SslDecryptSession *ssl_session, gboolean server)
2910 ssl_debug_printf("ssl_change_cipher %s\n", (server)?"SERVER":"CLIENT");
2912 ssl_session->server = ssl_session->server_new;
2913 ssl_session->server_new = NULL;
2915 ssl_session->client = ssl_session->client_new;
2916 ssl_session->client_new = NULL;
2921 /* Init cipher state given some security parameters. {{{ */
2923 ssl_decoder_destroy_cb(wmem_allocator_t *, wmem_cb_event_t, void *);
2926 ssl_create_decoder(const SslCipherSuite *cipher_suite, gint cipher_algo,
2927 gint compression, guint8 *mk, guint8 *sk, guint8 *iv, guint iv_length)
2930 ssl_cipher_mode_t mode = cipher_suite->mode;
2932 dec = (SslDecoder *)wmem_alloc0(wmem_file_scope(), sizeof(SslDecoder));
2933 /* init mac buffer: mac storage is embedded into decoder struct to save a
2934 memory allocation and waste samo more memory*/
2935 dec->cipher_suite=cipher_suite;
2936 dec->compression = compression;
2937 if ((mode == MODE_STREAM && mk != NULL) || mode == MODE_CBC) {
2938 // AEAD ciphers use no MAC key, but stream and block ciphers do. Note
2939 // the special case for NULL ciphers, even if there is insufficieny
2940 // keying material (including MAC key), we will can still create
2941 // decoders since "decryption" is easy for such ciphers.
2942 dec->mac_key.data = dec->_mac_key_or_write_iv;
2943 ssl_data_set(&dec->mac_key, mk, ssl_cipher_suite_dig(cipher_suite)->len);
2944 } else if (mode == MODE_GCM || mode == MODE_CCM || mode == MODE_CCM_8) {
2945 // Input for the nonce, to be used with AEAD ciphers.
2946 DISSECTOR_ASSERT(iv_length <= sizeof(dec->_mac_key_or_write_iv));
2947 dec->write_iv.data = dec->_mac_key_or_write_iv;
2948 ssl_data_set(&dec->write_iv, iv, iv_length);
2951 dec->decomp = ssl_create_decompressor(compression);
2952 wmem_register_callback(wmem_file_scope(), ssl_decoder_destroy_cb, dec);
2954 if (ssl_cipher_init(&dec->evp,cipher_algo,sk,iv,cipher_suite->mode) < 0) {
2955 ssl_debug_printf("%s: can't create cipher id:%d mode:%d\n", G_STRFUNC,
2956 cipher_algo, cipher_suite->mode);
2960 ssl_debug_printf("decoder initialized (digest len %d)\n", ssl_cipher_suite_dig(cipher_suite)->len);
2965 ssl_decoder_destroy_cb(wmem_allocator_t *allocator _U_, wmem_cb_event_t event _U_, void *user_data)
2967 SslDecoder *dec = (SslDecoder *) user_data;
2970 ssl_cipher_cleanup(&dec->evp);
2973 if (dec->decomp != NULL && dec->decomp->compression == 1 /* DEFLATE */)
2974 inflateEnd(&dec->decomp->istream);
2981 /* (Pre-)master secrets calculations {{{ */
2982 #ifdef HAVE_LIBGNUTLS
2984 ssl_decrypt_pre_master_secret(SslDecryptSession *ssl_session,
2985 StringInfo *encrypted_pre_master,
2987 #endif /* HAVE_LIBGNUTLS */
2990 ssl_restore_master_key(SslDecryptSession *ssl, const char *label,
2991 gboolean is_pre_master, GHashTable *ht, StringInfo *key);
2994 ssl_generate_pre_master_secret(SslDecryptSession *ssl_session,
2995 guint32 length, tvbuff_t *tvb, guint32 offset,
2996 const gchar *ssl_psk,
2997 const ssl_master_key_map_t *mk_map)
2999 /* check for required session data */
3000 ssl_debug_printf("%s: found SSL_HND_CLIENT_KEY_EXCHG, state %X\n",
3001 G_STRFUNC, ssl_session->state);
3002 if ((ssl_session->state & (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION)) !=
3003 (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION)) {
3004 ssl_debug_printf("%s: not enough data to generate key (required state %X)\n", G_STRFUNC,
3005 (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION));
3009 if (ssl_session->session.version == TLSV1DOT3_VERSION) {
3010 ssl_debug_printf("%s: detected TLS 1.3 which has no pre-master secrets\n", G_STRFUNC);
3014 /* check to see if the PMS was provided to us*/
3015 if (ssl_restore_master_key(ssl_session, "Unencrypted pre-master secret", TRUE,
3016 mk_map->pms, &ssl_session->client_random)) {
3020 if (ssl_session->cipher_suite->kex == KEX_PSK)
3022 /* calculate pre master secret*/
3023 StringInfo pre_master_secret;
3024 guint psk_len, pre_master_len;
3026 if (!ssl_psk || (ssl_psk[0] == 0)) {
3027 ssl_debug_printf("%s: can't find pre-shared-key\n", G_STRFUNC);
3031 /* convert hex string into char*/
3032 if (!from_hex(&ssl_session->psk, ssl_psk, strlen(ssl_psk))) {
3033 ssl_debug_printf("%s: ssl.psk/dtls.psk contains invalid hex\n",
3038 psk_len = ssl_session->psk.data_len;
3039 if (psk_len >= (2 << 15)) {
3040 ssl_debug_printf("%s: ssl.psk/dtls.psk must not be larger than 2^15 - 1\n",
3046 pre_master_len = psk_len * 2 + 4;
3048 pre_master_secret.data = (guchar *)wmem_alloc(wmem_file_scope(), pre_master_len);
3049 pre_master_secret.data_len = pre_master_len;
3050 /* 2 bytes psk_len*/
3051 pre_master_secret.data[0] = psk_len >> 8;
3052 pre_master_secret.data[1] = psk_len & 0xFF;
3053 /* psk_len bytes times 0*/
3054 memset(&pre_master_secret.data[2], 0, psk_len);
3055 /* 2 bytes psk_len*/
3056 pre_master_secret.data[psk_len + 2] = psk_len >> 8;
3057 pre_master_secret.data[psk_len + 3] = psk_len & 0xFF;
3059 memcpy(&pre_master_secret.data[psk_len + 4], ssl_session->psk.data, psk_len);
3061 ssl_session->pre_master_secret.data = pre_master_secret.data;
3062 ssl_session->pre_master_secret.data_len = pre_master_len;
3063 /*ssl_debug_printf("pre master secret",&ssl->pre_master_secret);*/
3065 /* Remove the master secret if it was there.
3066 This forces keying material regeneration in
3067 case we're renegotiating */
3068 ssl_session->state &= ~(SSL_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
3069 ssl_session->state |= SSL_PRE_MASTER_SECRET;
3074 StringInfo encrypted_pre_master;
3075 guint encrlen, skip;
3079 /* get encrypted data, on tls1 we have to skip two bytes
3080 * (it's the encrypted len and should be equal to record len - 2)
3081 * in case of rsa1024 that would be 128 + 2 = 130; for psk not necessary
3083 if (ssl_session->cipher_suite->kex == KEX_RSA &&
3084 (ssl_session->session.version == TLSV1_VERSION ||
3085 ssl_session->session.version == TLSV1DOT1_VERSION ||
3086 ssl_session->session.version == TLSV1DOT2_VERSION ||
3087 ssl_session->session.version == DTLSV1DOT0_VERSION ||
3088 ssl_session->session.version == DTLSV1DOT2_VERSION))
3090 encrlen = tvb_get_ntohs(tvb, offset);
3092 if (encrlen > length - 2)
3094 ssl_debug_printf("%s: wrong encrypted length (%d max %d)\n",
3095 G_STRFUNC, encrlen, length);
3099 /* the valid lower bound is higher than 8, but it is sufficient for the
3100 * ssl keylog file below */
3102 ssl_debug_printf("%s: invalid encrypted pre-master key length %d\n",
3103 G_STRFUNC, encrlen);
3107 encrypted_pre_master.data = (guchar *)wmem_alloc(wmem_file_scope(), encrlen);
3108 encrypted_pre_master.data_len = encrlen;
3109 tvb_memcpy(tvb, encrypted_pre_master.data, offset+skip, encrlen);
3111 #ifdef HAVE_LIBGNUTLS
3112 if (ssl_session->private_key) {
3113 /* try to decrypt encrypted pre-master with RSA key */
3114 if (ssl_decrypt_pre_master_secret(ssl_session,
3115 &encrypted_pre_master, ssl_session->private_key))
3118 ssl_debug_printf("%s: can't decrypt pre-master secret\n",
3121 #endif /* HAVE_LIBGNUTLS */
3123 /* try to find the pre-master secret from the encrypted one. The
3124 * ssl key logfile stores only the first 8 bytes, so truncate it */
3125 encrypted_pre_master.data_len = 8;
3126 if (ssl_restore_master_key(ssl_session, "Encrypted pre-master secret",
3127 TRUE, mk_map->pre_master, &encrypted_pre_master))
3133 /* Used for (D)TLS 1.2 and earlier versions (not with TLS 1.3). */
3135 ssl_generate_keyring_material(SslDecryptSession*ssl_session)
3137 StringInfo key_block = { NULL, 0 };
3138 guint8 _iv_c[MAX_BLOCK_SIZE],_iv_s[MAX_BLOCK_SIZE];
3139 guint8 _key_c[MAX_KEY_SIZE],_key_s[MAX_KEY_SIZE];
3141 gint cipher_algo = -1; /* special value (-1) for NULL encryption */
3142 guint encr_key_len, write_iv_len = 0;
3143 gboolean is_export_cipher;
3144 guint8 *ptr, *c_iv = NULL, *s_iv = NULL;
3145 guint8 *c_wk = NULL, *s_wk = NULL, *c_mk = NULL, *s_mk = NULL;
3146 const SslCipherSuite *cipher_suite = ssl_session->cipher_suite;
3148 /* TLS 1.3 is handled directly in tls13_change_key. */
3149 if (ssl_session->session.version == TLSV1DOT3_VERSION) {
3150 ssl_debug_printf("%s: detected TLS 1.3. Should not have been called!\n", G_STRFUNC);
3154 /* check for enough info to proced */
3155 guint need_all = SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION;
3156 guint need_any = SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET;
3157 if (((ssl_session->state & need_all) != need_all) || ((ssl_session->state & need_any) == 0)) {
3158 ssl_debug_printf("ssl_generate_keyring_material not enough data to generate key "
3159 "(0x%02X required 0x%02X or 0x%02X)\n", ssl_session->state,
3160 need_all|SSL_MASTER_SECRET, need_all|SSL_PRE_MASTER_SECRET);
3161 /* Special case: for NULL encryption, allow dissection of data even if
3162 * the Client Hello is missing (MAC keys are now skipped though). */
3163 need_all = SSL_CIPHER|SSL_VERSION;
3164 if ((ssl_session->state & need_all) == need_all &&
3165 cipher_suite->enc == ENC_NULL) {
3166 ssl_debug_printf("%s NULL cipher found, will create a decoder but "
3167 "skip MAC validation as keys are missing.\n", G_STRFUNC);
3168 goto create_decoders;
3174 /* if master key is not available, generate is from the pre-master secret */
3175 if (!(ssl_session->state & SSL_MASTER_SECRET)) {
3176 if ((ssl_session->state & SSL_EXTENDED_MASTER_SECRET_MASK) == SSL_EXTENDED_MASTER_SECRET_MASK) {
3177 StringInfo handshake_hashed_data;
3180 handshake_hashed_data.data = NULL;
3181 handshake_hashed_data.data_len = 0;
3183 ssl_debug_printf("%s:PRF(pre_master_secret_extended)\n", G_STRFUNC);
3184 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
3185 DISSECTOR_ASSERT(ssl_session->handshake_data.data_len > 0);
3187 switch(ssl_session->session.version) {
3189 case TLSV1DOT1_VERSION:
3190 case DTLSV1DOT0_VERSION:
3191 case DTLSV1DOT0_OPENSSL_VERSION:
3192 ret = tls_handshake_hash(ssl_session, &handshake_hashed_data);
3195 switch (cipher_suite->dig) {
3197 ret = tls12_handshake_hash(ssl_session, GCRY_MD_SHA384, &handshake_hashed_data);
3200 ret = tls12_handshake_hash(ssl_session, GCRY_MD_SHA256, &handshake_hashed_data);
3206 ssl_debug_printf("%s can't generate handshake hash\n", G_STRFUNC);
3210 wmem_free(wmem_file_scope(), ssl_session->handshake_data.data);
3211 ssl_session->handshake_data.data = NULL;
3212 ssl_session->handshake_data.data_len = 0;
3214 if (!prf(ssl_session, &ssl_session->pre_master_secret, "extended master secret",
3215 &handshake_hashed_data,
3216 NULL, &ssl_session->master_secret,
3217 SSL_MASTER_SECRET_LENGTH)) {
3218 ssl_debug_printf("%s can't generate master_secret\n", G_STRFUNC);
3219 g_free(handshake_hashed_data.data);
3222 g_free(handshake_hashed_data.data);
3224 ssl_debug_printf("%s:PRF(pre_master_secret)\n", G_STRFUNC);
3225 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
3226 ssl_print_string("client random",&ssl_session->client_random);
3227 ssl_print_string("server random",&ssl_session->server_random);
3228 if (!prf(ssl_session, &ssl_session->pre_master_secret, "master secret",
3229 &ssl_session->client_random,
3230 &ssl_session->server_random, &ssl_session->master_secret,
3231 SSL_MASTER_SECRET_LENGTH)) {
3232 ssl_debug_printf("%s can't generate master_secret\n", G_STRFUNC);
3236 ssl_print_string("master secret",&ssl_session->master_secret);
3238 /* the pre-master secret has been 'consumend' so we must clear it now */
3239 ssl_session->state &= ~SSL_PRE_MASTER_SECRET;
3240 ssl_session->state |= SSL_MASTER_SECRET;
3243 /* Find the Libgcrypt cipher algorithm for the given SSL cipher suite ID */
3244 if (cipher_suite->enc != ENC_NULL) {
3245 const char *cipher_name = ciphers[cipher_suite->enc-0x30];
3246 ssl_debug_printf("%s CIPHER: %s\n", G_STRFUNC, cipher_name);
3247 cipher_algo = ssl_get_cipher_by_name(cipher_name);
3248 if (cipher_algo == 0) {
3249 ssl_debug_printf("%s can't find cipher %s\n", G_STRFUNC, cipher_name);
3254 /* Export ciphers consume less material from the key block. */
3255 encr_key_len = ssl_get_cipher_export_keymat_size(cipher_suite->number);
3256 is_export_cipher = encr_key_len > 0;
3257 if (!is_export_cipher && cipher_suite->enc != ENC_NULL) {
3258 encr_key_len = (guint)gcry_cipher_get_algo_keylen(cipher_algo);
3261 if (cipher_suite->mode == MODE_CBC) {
3262 write_iv_len = (guint)gcry_cipher_get_algo_blklen(cipher_algo);
3263 } else if (cipher_suite->mode == MODE_GCM || cipher_suite->mode == MODE_CCM || cipher_suite->mode == MODE_CCM_8) {
3264 /* account for a four-byte salt for client and server side (from
3265 * client_write_IV and server_write_IV), see GCMNonce (RFC 5288) */
3269 /* Compute the key block. First figure out how much data we need */
3270 needed = ssl_cipher_suite_dig(cipher_suite)->len*2; /* MAC key */
3271 needed += 2 * encr_key_len; /* encryption key */
3272 needed += 2 * write_iv_len; /* write IV */
3274 key_block.data = (guchar *)g_malloc(needed);
3275 ssl_debug_printf("%s sess key generation\n", G_STRFUNC);
3276 if (!prf(ssl_session, &ssl_session->master_secret, "key expansion",
3277 &ssl_session->server_random,&ssl_session->client_random,
3278 &key_block, needed)) {
3279 ssl_debug_printf("%s can't generate key_block\n", G_STRFUNC);
3282 ssl_print_string("key expansion", &key_block);
3285 /* client/server write MAC key (for non-AEAD ciphers) */
3286 if (cipher_suite->mode == MODE_STREAM || cipher_suite->mode == MODE_CBC) {
3287 c_mk=ptr; ptr+=ssl_cipher_suite_dig(cipher_suite)->len;
3288 s_mk=ptr; ptr+=ssl_cipher_suite_dig(cipher_suite)->len;
3290 /* client/server write encryption key */
3291 c_wk=ptr; ptr += encr_key_len;
3292 s_wk=ptr; ptr += encr_key_len;
3293 /* client/server write IV (used as IV (for CBC) or salt (for AEAD)) */
3294 if (write_iv_len > 0) {
3295 c_iv=ptr; ptr += write_iv_len;
3296 s_iv=ptr; /* ptr += write_iv_len; */
3299 /* export ciphers work with a smaller key length */
3300 if (is_export_cipher) {
3301 if (cipher_suite->mode == MODE_CBC) {
3303 /* We only have room for MAX_BLOCK_SIZE bytes IVs, but that's
3304 all we should need. This is a sanity check */
3305 if (write_iv_len > MAX_BLOCK_SIZE) {
3306 ssl_debug_printf("%s cipher suite block must be at most %d nut is %d\n",
3307 G_STRFUNC, MAX_BLOCK_SIZE, write_iv_len);
3311 if(ssl_session->session.version==SSLV3_VERSION){
3312 /* The length of these fields are ignored by this caller */
3313 StringInfo iv_c, iv_s;
3317 ssl_debug_printf("%s ssl3_generate_export_iv\n", G_STRFUNC);
3318 ssl3_generate_export_iv(&ssl_session->client_random,
3319 &ssl_session->server_random, &iv_c, write_iv_len);
3320 ssl_debug_printf("%s ssl3_generate_export_iv(2)\n", G_STRFUNC);
3321 ssl3_generate_export_iv(&ssl_session->server_random,
3322 &ssl_session->client_random, &iv_s, write_iv_len);
3325 guint8 _iv_block[MAX_BLOCK_SIZE * 2];
3326 StringInfo iv_block;
3327 StringInfo key_null;
3330 key_null.data = &_key_null;
3331 key_null.data_len = 0;
3333 iv_block.data = _iv_block;
3335 ssl_debug_printf("%s prf(iv_block)\n", G_STRFUNC);
3336 if (!prf(ssl_session, &key_null, "IV block",
3337 &ssl_session->client_random,
3338 &ssl_session->server_random, &iv_block,
3339 write_iv_len * 2)) {
3340 ssl_debug_printf("%s can't generate tls31 iv block\n", G_STRFUNC);
3344 memcpy(_iv_c, iv_block.data, write_iv_len);
3345 memcpy(_iv_s, iv_block.data + write_iv_len, write_iv_len);
3352 if (ssl_session->session.version==SSLV3_VERSION){
3355 ssl_debug_printf("%s MD5(client_random)\n", G_STRFUNC);
3358 ssl_md5_update(&md5,c_wk,encr_key_len);
3359 ssl_md5_update(&md5,ssl_session->client_random.data,
3360 ssl_session->client_random.data_len);
3361 ssl_md5_update(&md5,ssl_session->server_random.data,
3362 ssl_session->server_random.data_len);
3363 ssl_md5_final(_key_c,&md5);
3364 ssl_md5_cleanup(&md5);
3368 ssl_debug_printf("%s MD5(server_random)\n", G_STRFUNC);
3369 ssl_md5_update(&md5,s_wk,encr_key_len);
3370 ssl_md5_update(&md5,ssl_session->server_random.data,
3371 ssl_session->server_random.data_len);
3372 ssl_md5_update(&md5,ssl_session->client_random.data,
3373 ssl_session->client_random.data_len);
3374 ssl_md5_final(_key_s,&md5);
3375 ssl_md5_cleanup(&md5);
3379 StringInfo key_c, key_s, k;
3380 key_c.data = _key_c;
3381 key_s.data = _key_s;
3384 k.data_len = encr_key_len;
3385 ssl_debug_printf("%s PRF(key_c)\n", G_STRFUNC);
3386 if (!prf(ssl_session, &k, "client write key",
3387 &ssl_session->client_random,
3388 &ssl_session->server_random, &key_c, sizeof(_key_c))) {
3389 ssl_debug_printf("%s can't generate tll31 server key \n", G_STRFUNC);
3395 k.data_len = encr_key_len;
3396 ssl_debug_printf("%s PRF(key_s)\n", G_STRFUNC);
3397 if (!prf(ssl_session, &k, "server write key",
3398 &ssl_session->client_random,
3399 &ssl_session->server_random, &key_s, sizeof(_key_s))) {
3400 ssl_debug_printf("%s can't generate tll31 client key \n", G_STRFUNC);
3407 /* show key material info */
3409 ssl_print_data("Client MAC key",c_mk,ssl_cipher_suite_dig(cipher_suite)->len);
3410 ssl_print_data("Server MAC key",s_mk,ssl_cipher_suite_dig(cipher_suite)->len);
3412 ssl_print_data("Client Write key", c_wk, encr_key_len);
3413 ssl_print_data("Server Write key", s_wk, encr_key_len);
3414 /* used as IV for CBC mode and the AEAD implicit nonce (salt) */
3415 if (write_iv_len > 0) {
3416 ssl_print_data("Client Write IV", c_iv, write_iv_len);
3417 ssl_print_data("Server Write IV", s_iv, write_iv_len);
3421 /* create both client and server ciphers*/
3422 ssl_debug_printf("%s ssl_create_decoder(client)\n", G_STRFUNC);
3423 ssl_session->client_new = ssl_create_decoder(cipher_suite, cipher_algo, ssl_session->session.compression, c_mk, c_wk, c_iv, write_iv_len);
3424 if (!ssl_session->client_new) {
3425 ssl_debug_printf("%s can't init client decoder\n", G_STRFUNC);
3428 ssl_debug_printf("%s ssl_create_decoder(server)\n", G_STRFUNC);
3429 ssl_session->server_new = ssl_create_decoder(cipher_suite, cipher_algo, ssl_session->session.compression, s_mk, s_wk, s_iv, write_iv_len);
3430 if (!ssl_session->server_new) {
3431 ssl_debug_printf("%s can't init client decoder\n", G_STRFUNC);
3435 /* Continue the SSL stream after renegotiation with new keys. */
3436 ssl_session->client_new->flow = ssl_session->client ? ssl_session->client->flow : ssl_create_flow();
3437 ssl_session->server_new->flow = ssl_session->server ? ssl_session->server->flow : ssl_create_flow();
3439 ssl_debug_printf("%s: client seq %" G_GUINT64_FORMAT ", server seq %" G_GUINT64_FORMAT "\n",
3440 G_STRFUNC, ssl_session->client_new->seq, ssl_session->server_new->seq);
3441 g_free(key_block.data);
3442 ssl_session->state |= SSL_HAVE_SESSION_KEY;
3446 g_free(key_block.data);
3450 /* Generated the key material based on the given secret. */
3452 tls13_generate_keys(SslDecryptSession *ssl_session, const StringInfo *secret, gboolean is_from_server)
3454 gboolean success = FALSE;
3455 guchar *write_key = NULL, *write_iv = NULL;
3456 SslDecoder *decoder;
3457 guint key_length, iv_length;
3459 const SslCipherSuite *cipher_suite = ssl_session->cipher_suite;
3462 if (ssl_session->session.version != TLSV1DOT3_VERSION) {
3463 ssl_debug_printf("%s only usable for TLS 1.3, not %#x!\n", G_STRFUNC,
3464 ssl_session->session.version);
3468 if (cipher_suite == NULL) {
3469 ssl_debug_printf("%s Unknown cipher\n", G_STRFUNC);
3473 if (cipher_suite->kex != KEX_TLS13) {
3474 ssl_debug_printf("%s Invalid cipher suite 0x%04x spotted!\n", G_STRFUNC, cipher_suite->number);
3478 /* Find the Libgcrypt cipher algorithm for the given SSL cipher suite ID */
3479 const char *cipher_name = ciphers[cipher_suite->enc-0x30];
3480 ssl_debug_printf("%s CIPHER: %s\n", G_STRFUNC, cipher_name);
3481 cipher_algo = ssl_get_cipher_by_name(cipher_name);
3482 if (cipher_algo == 0) {
3483 ssl_debug_printf("%s can't find cipher %s\n", G_STRFUNC, cipher_name);
3487 const char *hash_name = ssl_cipher_suite_dig(cipher_suite)->name;
3488 hash_algo = ssl_get_digest_by_name(hash_name);
3490 ssl_debug_printf("%s can't find hash function %s\n", G_STRFUNC, hash_name);
3494 key_length = (guint) gcry_cipher_get_algo_blklen(cipher_algo);
3495 /* AES-GCM/AES-CCM/Poly1305-ChaCha20 all have N_MIN=N_MAX = 12. */
3497 ssl_debug_printf("%s key_length %u iv_length %u\n", G_STRFUNC, key_length, iv_length);
3499 if (!tls13_hkdf_expand_label(hash_algo, secret, "key", "", key_length, &write_key)) {
3500 ssl_debug_printf("%s write_key expansion failed\n", G_STRFUNC);
3503 if (!tls13_hkdf_expand_label(hash_algo, secret, "iv", "", iv_length, &write_iv)) {
3504 ssl_debug_printf("%s write_iv expansion failed\n", G_STRFUNC);
3508 ssl_print_data(is_from_server ? "Server Write Key" : "Client Write Key", write_key, key_length);
3509 ssl_print_data(is_from_server ? "Server Write IV" : "Client Write IV", write_iv, iv_length);
3511 ssl_debug_printf("%s ssl_create_decoder(%s)\n", G_STRFUNC, is_from_server ? "server" : "client");
3512 decoder = ssl_create_decoder(cipher_suite, cipher_algo, 0, NULL, write_key, write_iv, iv_length);
3514 ssl_debug_printf("%s can't init %s decoder\n", G_STRFUNC, is_from_server ? "server" : "client");
3518 /* Continue the TLS session with new keys, but reuse old flow to keep things
3519 * like "Follow SSL" working (by linking application data records). */
3520 if (is_from_server) {
3521 decoder->flow = ssl_session->server ? ssl_session->server->flow : ssl_create_flow();
3522 ssl_session->server = decoder;
3524 decoder->flow = ssl_session->client ? ssl_session->client->flow : ssl_create_flow();
3525 ssl_session->client = decoder;
3527 ssl_debug_printf("%s %s ready using cipher suite 0x%04x (cipher %s hash %s)\n", G_STRFUNC,
3528 is_from_server ? "Server" : "Client", cipher_suite->number, cipher_name, hash_name);
3532 wmem_free(NULL, write_key);
3533 wmem_free(NULL, write_iv);
3536 /* (Pre-)master secrets calculations }}} */
3538 #ifdef HAVE_LIBGNUTLS
3539 /* Decrypt RSA pre-master secret using RSA private key. {{{ */
3541 ssl_decrypt_pre_master_secret(SslDecryptSession*ssl_session,
3542 StringInfo* encrypted_pre_master, gcry_sexp_t pk)
3546 if (!encrypted_pre_master)
3549 if (KEX_IS_DH(ssl_session->cipher_suite->kex)) {
3550 ssl_debug_printf("%s: session uses Diffie-Hellman key exchange "
3551 "(cipher suite 0x%04X %s) and cannot be decrypted "
3552 "using a RSA private key file.\n",
3553 G_STRFUNC, ssl_session->session.cipher,
3554 val_to_str_ext_const(ssl_session->session.cipher,
3555 &ssl_31_ciphersuite_ext, "unknown"));
3557 } else if(ssl_session->cipher_suite->kex != KEX_RSA) {
3558 ssl_debug_printf("%s key exchange %d different from KEX_RSA (%d)\n",
3559 G_STRFUNC, ssl_session->cipher_suite->kex, KEX_RSA);
3563 /* with tls key loading will fail if not rsa type, so no need to check*/
3564 ssl_print_string("pre master encrypted",encrypted_pre_master);
3565 ssl_debug_printf("%s: RSA_private_decrypt\n", G_STRFUNC);
3566 i=ssl_private_decrypt(encrypted_pre_master->data_len,
3567 encrypted_pre_master->data, pk);
3570 ssl_debug_printf("%s wrong pre_master_secret length (%d, expected "
3571 "%d)\n", G_STRFUNC, i, 48);
3575 /* the decrypted data has been written into the pre_master key buffer */
3576 ssl_session->pre_master_secret.data = encrypted_pre_master->data;
3577 ssl_session->pre_master_secret.data_len=48;
3578 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
3580 /* Remove the master secret if it was there.
3581 This forces keying material regeneration in
3582 case we're renegotiating */
3583 ssl_session->state &= ~(SSL_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
3584 ssl_session->state |= SSL_PRE_MASTER_SECRET;
3587 #endif /* HAVE_LIBGNUTLS */
3589 /* Decryption integrity check {{{ */
3592 tls_check_mac(SslDecoder*decoder, gint ct, gint ver, guint8* data,
3593 guint32 datalen, guint8* mac)
3598 guint8 buf[DIGEST_MAX_SIZE];
3601 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
3602 ssl_debug_printf("tls_check_mac mac type:%s md %d\n",
3603 ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
3605 if (ssl_hmac_init(&hm,decoder->mac_key.data,decoder->mac_key.data_len,md) != 0)
3608 /* hash sequence number */
3609 phton64(buf, decoder->seq);
3613 ssl_hmac_update(&hm,buf,8);
3615 /* hash content type */
3617 ssl_hmac_update(&hm,buf,1);
3619 /* hash version,data length and data*/
3620 /* *((gint16*)buf) = g_htons(ver); */
3621 temp = g_htons(ver);
3622 memcpy(buf, &temp, 2);
3623 ssl_hmac_update(&hm,buf,2);
3625 /* *((gint16*)buf) = g_htons(datalen); */
3626 temp = g_htons(datalen);
3627 memcpy(buf, &temp, 2);
3628 ssl_hmac_update(&hm,buf,2);
3629 ssl_hmac_update(&hm,data,datalen);
3631 /* get digest and digest len*/
3633 ssl_hmac_final(&hm,buf,&len);
3634 ssl_hmac_cleanup(&hm);
3635 ssl_print_data("Mac", buf, len);
3636 if(memcmp(mac,buf,len))
3643 ssl3_check_mac(SslDecoder*decoder,int ct,guint8* data,
3644 guint32 datalen, guint8* mac)
3649 guint8 buf[64],dgst[20];
3653 pad_ct=(decoder->cipher_suite->dig==DIG_SHA)?40:48;
3655 /* get cipher used for digest comptuation */
3656 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
3657 if (ssl_md_init(&mc,md) !=0)
3660 /* do hash computation on data && padding */
3661 ssl_md_update(&mc,decoder->mac_key.data,decoder->mac_key.data_len);
3664 memset(buf,0x36,pad_ct);
3665 ssl_md_update(&mc,buf,pad_ct);
3667 /* hash sequence number */
3668 phton64(buf, decoder->seq);
3670 ssl_md_update(&mc,buf,8);
3672 /* hash content type */
3674 ssl_md_update(&mc,buf,1);
3676 /* hash data length in network byte order and data*/
3677 /* *((gint16* )buf) = g_htons(datalen); */
3678 temp = g_htons(datalen);
3679 memcpy(buf, &temp, 2);
3680 ssl_md_update(&mc,buf,2);
3681 ssl_md_update(&mc,data,datalen);
3683 /* get partial digest */
3684 ssl_md_final(&mc,dgst,&len);
3685 ssl_md_cleanup(&mc);
3687 ssl_md_init(&mc,md);
3690 ssl_md_update(&mc,decoder->mac_key.data,decoder->mac_key.data_len);
3692 /* hash padding and partial digest*/
3693 memset(buf,0x5c,pad_ct);
3694 ssl_md_update(&mc,buf,pad_ct);
3695 ssl_md_update(&mc,dgst,len);
3697 ssl_md_final(&mc,dgst,&len);
3698 ssl_md_cleanup(&mc);
3700 if(memcmp(mac,dgst,len))
3707 dtls_check_mac(SslDecoder*decoder, gint ct,int ver, guint8* data,
3708 guint32 datalen, guint8* mac)
3713 guint8 buf[DIGEST_MAX_SIZE];
3716 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
3717 ssl_debug_printf("dtls_check_mac mac type:%s md %d\n",
3718 ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
3720 if (ssl_hmac_init(&hm,decoder->mac_key.data,decoder->mac_key.data_len,md) != 0)
3722 ssl_debug_printf("dtls_check_mac seq: %" G_GUINT64_FORMAT " epoch: %d\n",decoder->seq,decoder->epoch);
3723 /* hash sequence number */
3724 phton64(buf, decoder->seq);
3725 buf[0]=decoder->epoch>>8;
3726 buf[1]=(guint8)decoder->epoch;
3728 ssl_hmac_update(&hm,buf,8);
3730 /* hash content type */
3732 ssl_hmac_update(&hm,buf,1);
3734 /* hash version,data length and data */
3735 temp = g_htons(ver);
3736 memcpy(buf, &temp, 2);
3737 ssl_hmac_update(&hm,buf,2);
3739 temp = g_htons(datalen);
3740 memcpy(buf, &temp, 2);
3741 ssl_hmac_update(&hm,buf,2);
3742 ssl_hmac_update(&hm,data,datalen);
3743 /* get digest and digest len */
3745 ssl_hmac_final(&hm,buf,&len);
3746 ssl_hmac_cleanup(&hm);
3747 ssl_print_data("Mac", buf, len);
3748 if(memcmp(mac,buf,len))
3753 /* Decryption integrity check }}} */
3757 tls_decrypt_aead_record(SslDecryptSession *ssl, SslDecoder *decoder,
3758 #ifdef HAVE_LIBGCRYPT_AEAD
3759 guint8 ct, guint16 record_version,
3761 guint8 ct _U_, guint16 record_version _U_,
3763 const guchar *in, guint16 inl, StringInfo *out_str, guint *outl)
3765 /* RFC 5246 (TLS 1.2) 6.2.3.3 defines the TLSCipherText.fragment as:
3766 * GenericAEADCipher: { nonce_explicit, [content] }
3767 * In TLS 1.3 this explicit nonce is gone.
3768 * With AES GCM/CCM, "[content]" is actually the concatenation of the
3769 * ciphertext and authentication tag.
3771 const guint16 version = ssl->session.version;
3772 const gboolean is_v12 = version == TLSV1DOT2_VERSION || version == DTLSV1DOT2_VERSION;
3774 const guchar *explicit_nonce = NULL, *ciphertext;
3775 guint ciphertext_len, auth_tag_len;
3777 #ifdef HAVE_LIBGCRYPT_AEAD
3778 const guchar *auth_tag_wire;
3779 guchar auth_tag_calc[16];
3781 guchar nonce_with_counter[16] = { 0 };
3784 switch (decoder->cipher_suite->mode) {
3793 ssl_debug_printf("%s unsupported cipher!\n", G_STRFUNC);
3797 /* Parse input into explicit nonce (TLS 1.2 only), ciphertext and tag. */
3799 if (inl < EXPLICIT_NONCE_LEN + auth_tag_len) {
3800 ssl_debug_printf("%s input %d is too small for explicit nonce %d and auth tag %d\n",
3801 G_STRFUNC, inl, EXPLICIT_NONCE_LEN, auth_tag_len);
3804 explicit_nonce = in;
3805 ciphertext = explicit_nonce + EXPLICIT_NONCE_LEN;
3806 ciphertext_len = inl - EXPLICIT_NONCE_LEN - auth_tag_len;
3807 } else if (version == TLSV1DOT3_VERSION) {
3808 if (inl < auth_tag_len) {
3809 ssl_debug_printf("%s input %d has no space for auth tag %d\n", G_STRFUNC, inl, auth_tag_len);
3813 ciphertext_len = inl - auth_tag_len;
3815 ssl_debug_printf("%s Unexpected TLS version %#x\n", G_STRFUNC, version);
3818 #ifdef HAVE_LIBGCRYPT_AEAD
3819 auth_tag_wire = ciphertext + ciphertext_len;
3822 /* Nonce construction is version-specific. */
3824 DISSECTOR_ASSERT(decoder->write_iv.data_len == IMPLICIT_NONCE_LEN);
3825 /* Implicit (4) and explicit (8) part of nonce. */
3826 memcpy(nonce, decoder->write_iv.data, IMPLICIT_NONCE_LEN);
3827 memcpy(nonce + IMPLICIT_NONCE_LEN, explicit_nonce, EXPLICIT_NONCE_LEN);
3829 #ifndef HAVE_LIBGCRYPT_AEAD
3830 if (decoder->cipher_suite->mode == MODE_GCM) {
3831 /* NIST SP 800-38D, sect. 7.2 says that the 32-bit counter part starts
3832 * at 1, and gets incremented before passing to the block cipher. */
3833 memcpy(nonce_with_counter, nonce, IMPLICIT_NONCE_LEN + EXPLICIT_NONCE_LEN);
3834 nonce_with_counter[IMPLICIT_NONCE_LEN + EXPLICIT_NONCE_LEN + 3] = 2;
3835 } else { /* MODE_CCM and MODE_CCM_8 */
3836 /* The nonce for CCM and GCM are the same, but the nonce is used as input
3837 * in the CCM algorithm described in RFC 3610. The nonce generated here is
3838 * the one from RFC 3610 sect 2.3. Encryption. */
3839 /* Flags: (L-1) ; L = 16 - 1 - nonceSize */
3840 nonce_with_counter[0] = 3 - 1;
3841 memcpy(nonce_with_counter + 1, nonce, IMPLICIT_NONCE_LEN + EXPLICIT_NONCE_LEN);
3842 /* struct { opaque salt[4]; opaque nonce_explicit[8] } CCMNonce (RFC 6655) */
3843 nonce_with_counter[IMPLICIT_NONCE_LEN + EXPLICIT_NONCE_LEN + 3] = 1;
3846 } else if (version == TLSV1DOT3_VERSION) {
3848 * Technically the nonce length must be at least 8 bytes, but for
3849 * AES-GCM, AES-CCM and Poly1305-ChaCha20 the nonce length is exact 12.
3851 const guint nonce_len = 12;
3852 DISSECTOR_ASSERT(decoder->write_iv.data_len == nonce_len);
3853 memcpy(nonce, decoder->write_iv.data, decoder->write_iv.data_len);
3854 /* Sequence number is left-padded with zeroes and XORed with write_iv */
3855 phton64(nonce + nonce_len - 8, pntoh64(nonce + nonce_len - 8) ^ decoder->seq);
3856 ssl_debug_printf("%s seq %" G_GUINT64_FORMAT "\n", G_STRFUNC, decoder->seq);
3857 decoder->seq++; /* Implicit sequence number for TLS 1.3. */
3860 /* Set nonce and additional authentication data */
3861 #ifdef HAVE_LIBGCRYPT_AEAD
3862 gcry_cipher_reset(decoder->evp);
3863 ssl_print_data("nonce", nonce, 12);
3864 err = gcry_cipher_setiv(decoder->evp, nonce, 12);
3866 ssl_debug_printf("%s failed to set nonce: %s\n", G_STRFUNC, gcry_strerror(err));
3870 if (decoder->cipher_suite->mode == MODE_CCM || decoder->cipher_suite->mode == MODE_CCM_8) {
3871 /* size of plaintext, additional authenticated data and auth tag. */
3872 guint64 lengths[3] = { ciphertext_len, is_v12 ? 13 : 0, auth_tag_len };
3873 gcry_cipher_ctl(decoder->evp, GCRYCTL_SET_CCM_LENGTHS, lengths, sizeof(lengths));
3876 /* (D)TLS 1.2 needs specific AAD, TLS 1.3 uses empty AAD. */
3879 phton64(aad, decoder->seq); /* record sequence number */
3880 if (version == TLSV1DOT2_VERSION) {
3881 decoder->seq++; /* Implicit sequence number for TLS 1.2. */
3883 phton16(aad, decoder->epoch); /* DTLS 1.2 includes epoch. */
3885 aad[8] = ct; /* TLSCompressed.type */
3886 phton16(aad + 9, record_version); /* TLSCompressed.version */
3887 phton16(aad + 11, ciphertext_len); /* TLSCompressed.length */
3888 ssl_print_data("AAD", aad, sizeof(aad));
3889 err = gcry_cipher_authenticate(decoder->evp, aad, sizeof(aad));
3891 ssl_debug_printf("%s failed to set AAD: %s\n", G_STRFUNC, gcry_strerror(err));
3896 err = gcry_cipher_setctr(decoder->evp, nonce_with_counter, 16);
3898 ssl_debug_printf("%s failed: failed to set CTR: %s\n", G_STRFUNC, gcry_strerror(err));
3903 /* Decrypt now that nonce and AAD are set. */
3904 err = gcry_cipher_decrypt(decoder->evp, out_str->data, out_str->data_len, ciphertext, ciphertext_len);
3906 ssl_debug_printf("%s decrypt failed: %s\n", G_STRFUNC, gcry_strerror(err));
3910 /* Check authentication tag for authenticity (replaces MAC) */
3911 #ifdef HAVE_LIBGCRYPT_AEAD
3912 err = gcry_cipher_gettag(decoder->evp, auth_tag_calc, auth_tag_len);
3913 if (err == 0 && !memcmp(auth_tag_calc, auth_tag_wire, auth_tag_len)) {
3914 ssl_print_data("auth_tag(OK)", auth_tag_calc, auth_tag_len);
3917 ssl_debug_printf("%s cannot obtain tag: %s\n", G_STRFUNC, gcry_strerror(err));
3919 ssl_debug_printf("%s auth tag mismatch\n", G_STRFUNC);
3920 ssl_print_data("auth_tag(expect)", auth_tag_calc, auth_tag_len);
3921 ssl_print_data("auth_tag(actual)", auth_tag_wire, auth_tag_len);
3923 if (ssl_ignore_mac_failed) {
3924 ssl_debug_printf("%s: auth check failed, but ignored for troubleshooting ;-)\n", G_STRFUNC);
3930 ssl_debug_printf("Libgcrypt is older than 1.6, unable to verify auth tag!\n");
3933 ssl_print_data("Plaintext", out_str->data, ciphertext_len);
3934 *outl = ciphertext_len;
3938 /* Record decryption glue based on security parameters {{{ */
3939 /* Assume that we are called only for a non-NULL decoder which also means that
3940 * we have a non-NULL decoder->cipher_suite. */
3942 ssl_decrypt_record(SslDecryptSession *ssl, SslDecoder *decoder, guint8 ct, guint16 record_version,
3943 const guchar *in, guint16 inl, StringInfo *comp_str, StringInfo *out_str, guint *outl)
3945 guint pad, worklen, uncomplen;
3948 ssl_debug_printf("ssl_decrypt_record ciphertext len %d\n", inl);
3949 ssl_print_data("Ciphertext",in, inl);
3951 if ((ssl->session.version == TLSV1DOT3_VERSION) != (decoder->cipher_suite->kex == KEX_TLS13)) {
3952 ssl_debug_printf("%s Invalid cipher suite for the protocol version!\n", G_STRFUNC);
3956 /* ensure we have enough storage space for decrypted data */
3957 if (inl > out_str->data_len)
3959 ssl_debug_printf("ssl_decrypt_record: allocating %d bytes for decrypt data (old len %d)\n",
3960 inl + 32, out_str->data_len);
3961 ssl_data_realloc(out_str, inl + 32);
3964 /* AEAD ciphers (GenericAEADCipher in TLS 1.2; TLS 1.3) have no padding nor
3965 * a separate MAC, so use a different routine for simplicity. */
3966 if (decoder->cipher_suite->mode == MODE_GCM ||
3967 decoder->cipher_suite->mode == MODE_CCM ||
3968 decoder->cipher_suite->mode == MODE_CCM_8 ||
3969 ssl->session.version == TLSV1DOT3_VERSION) {
3971 if (!tls_decrypt_aead_record(ssl, decoder, ct, record_version, in, inl, out_str, &worklen)) {
3972 /* decryption failed */
3979 /* RFC 6101/2246: SSLCipherText/TLSCipherText has two structures for types:
3980 * (notation: { unencrypted, [ encrypted ] })
3981 * GenericStreamCipher: { [content, mac] }
3982 * GenericBlockCipher: { IV (TLS 1.1+), [content, mac, padding, padding_len] }
3983 * RFC 5426 (TLS 1.2): TLSCipherText has additionally:
3984 * GenericAEADCipher: { nonce_explicit, [content] }
3985 * RFC 4347 (DTLS): based on TLS 1.1, only GenericBlockCipher is supported.
3986 * RFC 6347 (DTLS 1.2): based on TLS 1.2, includes GenericAEADCipher too.
3989 /* (TLS 1.1 and later, DTLS) Extract explicit IV for GenericBlockCipher */
3990 if (decoder->cipher_suite->mode == MODE_CBC) {
3993 switch (ssl->session.version) {
3994 case TLSV1DOT1_VERSION:
3995 case TLSV1DOT2_VERSION:
3996 case DTLSV1DOT0_VERSION:
3997 case DTLSV1DOT2_VERSION:
3998 case DTLSV1DOT0_OPENSSL_VERSION:
3999 blocksize = ssl_get_cipher_blocksize(decoder->cipher_suite);
4000 if (inl < blocksize) {
4001 ssl_debug_printf("ssl_decrypt_record failed: input %d has no space for IV %d\n",
4005 pad = gcry_cipher_setiv(decoder->evp, in, blocksize);
4007 ssl_debug_printf("ssl_decrypt_record failed: failed to set IV: %s %s\n",
4008 gcry_strsource (pad), gcry_strerror (pad));
4018 if ((pad = ssl_cipher_decrypt(&decoder->evp, out_str->data, out_str->data_len, in, inl)) != 0) {
4019 ssl_debug_printf("ssl_decrypt_record failed: ssl_cipher_decrypt: %s %s\n", gcry_strsource (pad),
4020 gcry_strerror (pad));
4024 ssl_print_data("Plaintext", out_str->data, inl);
4028 /* strip padding for GenericBlockCipher */
4029 if (decoder->cipher_suite->mode == MODE_CBC) {
4030 if (inl < 1) { /* Should this check happen earlier? */
4031 ssl_debug_printf("ssl_decrypt_record failed: input length %d too small\n", inl);
4034 pad=out_str->data[inl-1];
4035 if (worklen <= pad) {
4036 ssl_debug_printf("ssl_decrypt_record failed: padding %d too large for work %d\n",
4041 ssl_debug_printf("ssl_decrypt_record found padding %d final len %d\n",
4045 /* MAC for GenericStreamCipher and GenericBlockCipher */
4046 if (ssl_cipher_suite_dig(decoder->cipher_suite)->len > (gint)worklen) {
4047 ssl_debug_printf("ssl_decrypt_record wrong record len/padding outlen %d\n work %d\n",*outl, worklen);
4050 worklen -= ssl_cipher_suite_dig(decoder->cipher_suite)->len;
4051 mac = out_str->data + worklen;
4053 /* If NULL encryption active and no keys are available, do not bother
4054 * checking the MAC. We do not have keys for that. */
4055 if (decoder->cipher_suite->mode == MODE_STREAM &&
4056 decoder->cipher_suite->enc == ENC_NULL &&
4057 !(ssl->state & SSL_MASTER_SECRET)) {
4058 ssl_debug_printf("MAC check skipped due to missing keys\n");
4062 /* Now check the MAC */
4063 ssl_debug_printf("checking mac (len %d, version %X, ct %d seq %" G_GUINT64_FORMAT ")\n",
4064 worklen, ssl->session.version, ct, decoder->seq);
4065 if(ssl->session.version==SSLV3_VERSION){
4066 if(ssl3_check_mac(decoder,ct,out_str->data,worklen,mac) < 0) {
4067 if(ssl_ignore_mac_failed) {
4068 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
4071 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
4076 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
4079 else if(ssl->session.version==TLSV1_VERSION || ssl->session.version==TLSV1DOT1_VERSION || ssl->session.version==TLSV1DOT2_VERSION){
4080 if(tls_check_mac(decoder,ct,ssl->session.version,out_str->data,worklen,mac)< 0) {
4081 if(ssl_ignore_mac_failed) {
4082 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
4085 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
4090 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
4093 else if(ssl->session.version==DTLSV1DOT0_VERSION ||
4094 ssl->session.version==DTLSV1DOT2_VERSION ||
4095 ssl->session.version==DTLSV1DOT0_OPENSSL_VERSION){
4096 /* Try rfc-compliant mac first, and if failed, try old openssl's non-rfc-compliant mac */
4097 if(dtls_check_mac(decoder,ct,ssl->session.version,out_str->data,worklen,mac)>= 0) {
4098 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
4100 else if(tls_check_mac(decoder,ct,TLSV1_VERSION,out_str->data,worklen,mac)>= 0) {
4101 ssl_debug_printf("ssl_decrypt_record: dtls rfc-compliant mac failed, but old openssl's non-rfc-compliant mac ok\n");
4103 else if(ssl_ignore_mac_failed) {
4104 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
4107 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
4115 if (decoder->compression > 0) {
4116 ssl_debug_printf("ssl_decrypt_record: compression method %d\n", decoder->compression);
4117 ssl_data_copy(comp_str, out_str);
4118 ssl_print_data("Plaintext compressed", comp_str->data, worklen);
4119 if (!decoder->decomp) {
4120 ssl_debug_printf("decrypt_ssl3_record: no decoder available\n");
4123 if (ssl_decompress_record(decoder->decomp, comp_str->data, worklen, out_str, &uncomplen) < 0) return -1;
4124 ssl_print_data("Plaintext uncompressed", out_str->data, uncomplen);
4130 /* Record decryption glue based on security parameters }}} */
4132 #endif /* HAVE_LIBGCRYPT */
4135 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
4136 /* RSA private key file processing {{{ */
4139 ssl_privkey_to_sexp(gnutls_x509_privkey_t priv_key)
4141 gnutls_datum_t rsa_datum[RSA_PARS]; /* m, e, d, p, q, u */
4144 gcry_sexp_t rsa_priv_key = NULL;
4146 gcry_mpi_t rsa_params[RSA_PARS];
4148 /* RSA get parameter */
4149 if (gnutls_x509_privkey_export_rsa_raw(priv_key,
4155 &rsa_datum[5]) != 0) {
4156 ssl_debug_printf("ssl_load_key: can't export rsa param (is a rsa private key file ?!?)\n");
4160 /* convert each rsa parameter to mpi format*/
4161 for(i=0; i<RSA_PARS; i++) {
4162 gret = gcry_mpi_scan(&rsa_params[i], GCRYMPI_FMT_USG, rsa_datum[i].data, rsa_datum[i].size,&tmp_size);
4163 /* these buffers were allocated by gnutls_x509_privkey_export_rsa_raw() */
4164 g_free(rsa_datum[i].data);
4166 ssl_debug_printf("ssl_load_key: can't convert m rsa param to int (size %d)\n", rsa_datum[i].size);
4171 /* libgcrypt expects p < q, and gnutls might not return it as such, depending on gnutls version and its crypto backend */
4172 if (gcry_mpi_cmp(rsa_params[3], rsa_params[4]) > 0)
4174 ssl_debug_printf("ssl_load_key: swapping p and q parameters and recomputing u\n");
4176 gcry_mpi_swap(rsa_params[3], rsa_params[4]);
4177 /* due to swapping p and q, u = p^-1 mod p which happens to be needed. */
4179 /* libgcrypt expects u = p^-1 mod q (for OpenPGP), but the u parameter
4180 * says u = q^-1 mod p. Recompute u = p^-1 mod q. Do this unconditionally as
4181 * at least GnuTLS 2.12.23 computes an invalid value. */
4182 gcry_mpi_invm(rsa_params[5], rsa_params[3], rsa_params[4]);
4184 if (gcry_sexp_build( &rsa_priv_key, NULL,
4185 "(private-key(rsa((n%m)(e%m)(d%m)(p%m)(q%m)(u%m))))", rsa_params[0],
4186 rsa_params[1], rsa_params[2], rsa_params[3], rsa_params[4],
4187 rsa_params[5]) != 0) {
4188 ssl_debug_printf("ssl_load_key: can't build rsa private key s-exp\n");
4192 for (i=0; i< 6; i++)
4193 gcry_mpi_release(rsa_params[i]);
4194 return rsa_priv_key;
4197 /** Load an RSA private key from specified file
4198 @param fp the file that contain the key data
4199 @return a pointer to the loaded key on success, or NULL */
4200 static gnutls_x509_privkey_t
4201 ssl_load_key(FILE* fp)
4203 /* gnutls makes our work much harder, since we have to work internally with
4204 * s-exp formatted data, but PEM loader exports only in "gnutls_datum_t"
4205 * format, and a datum -> s-exp convertion function does not exist.
4207 gnutls_x509_privkey_t priv_key;
4213 if (ws_fstat64(ws_fileno(fp), &statbuf) == -1) {
4214 ssl_debug_printf("ssl_load_key: can't ws_fstat64 file\n");
4217 if (S_ISDIR(statbuf.st_mode)) {
4218 ssl_debug_printf("ssl_load_key: file is a directory\n");
4222 if (S_ISFIFO(statbuf.st_mode)) {
4223 ssl_debug_printf("ssl_load_key: file is a named pipe\n");
4227 if (!S_ISREG(statbuf.st_mode)) {
4228 ssl_debug_printf("ssl_load_key: file is not a regular file\n");
4232 /* XXX - check for a too-big size */
4233 /* load all file contents into a datum buffer*/
4234 key.data = (unsigned char *)g_malloc((size_t)statbuf.st_size);
4235 key.size = (int)statbuf.st_size;
4236 bytes = (guint) fread(key.data, 1, key.size, fp);
4237 if (bytes < key.size) {
4238 ssl_debug_printf("ssl_load_key: can't read from file %d bytes, got %d\n",
4244 /* init private key data*/
4245 gnutls_x509_privkey_init(&priv_key);
4247 /* import PEM data*/
4248 if ((ret = gnutls_x509_privkey_import(priv_key, &key, GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS) {
4249 ssl_debug_printf("ssl_load_key: can't import pem data: %s\n", gnutls_strerror(ret));
4254 if (gnutls_x509_privkey_get_pk_algorithm(priv_key) != GNUTLS_PK_RSA) {
4255 ssl_debug_printf("ssl_load_key: private key public key algorithm isn't RSA\n");
4266 BAGTYPE(gnutls_pkcs12_bag_type_t x) {
4268 case GNUTLS_BAG_EMPTY: return "Empty";
4269 case GNUTLS_BAG_PKCS8_ENCRYPTED_KEY: return "PKCS#8 Encrypted key";
4270 case GNUTLS_BAG_PKCS8_KEY: return "PKCS#8 Key";
4271 case GNUTLS_BAG_CERTIFICATE: return "Certificate";
4272 case GNUTLS_BAG_CRL: return "CRL";
4273 case GNUTLS_BAG_ENCRYPTED: return "Encrypted";
4274 case GNUTLS_BAG_UNKNOWN: return "Unknown";
4275 default: return "<undefined>";
4280 * Load a RSA private key from a PKCS#12 file.
4281 * @param fp the file that contains the key data.
4282 * @param cert_passwd password to decrypt the PKCS#12 file.
4283 * @param[out] err error message upon failure; NULL upon success.
4284 * @return a pointer to the loaded key on success; NULL upon failure.
4286 static gnutls_x509_privkey_t
4287 ssl_load_pkcs12(FILE* fp, const gchar *cert_passwd, char** err) {
4292 gnutls_datum_t data;
4293 gnutls_pkcs12_bag_t bag = NULL;
4294 gnutls_pkcs12_bag_type_t bag_type;
4297 gnutls_pkcs12_t ssl_p12 = NULL;
4298 gnutls_x509_privkey_t ssl_pkey = NULL;
4300 gnutls_x509_privkey_t priv_key = NULL;
4304 data.data = (unsigned char *)g_malloc(rest);
4307 while ((len = fread(p, 1, rest, fp)) > 0) {
4312 data.data = (unsigned char *)g_realloc(data.data, data.size + rest);
4313 p = data.data + data.size;
4318 ssl_debug_printf("%d bytes read\n", data.size);
4320 *err = g_strdup("Error during certificate reading.");
4321 ssl_debug_printf("%s\n", *err);
4326 ret = gnutls_pkcs12_init(&ssl_p12);
4328 *err = g_strdup_printf("gnutls_pkcs12_init(&st_p12) - %s", gnutls_strerror(ret));
4329 ssl_debug_printf("%s\n", *err);
4334 /* load PKCS#12 in DER or PEM format */
4335 ret = gnutls_pkcs12_import(ssl_p12, &data, GNUTLS_X509_FMT_DER, 0);
4337 *err = g_strdup_printf("could not load PKCS#12 in DER format: %s", gnutls_strerror(ret));
4338 ssl_debug_printf("%s\n", *err);
4341 ret = gnutls_pkcs12_import(ssl_p12, &data, GNUTLS_X509_FMT_PEM, 0);
4343 *err = g_strdup_printf("could not load PKCS#12 in PEM format: %s", gnutls_strerror(ret));
4344 ssl_debug_printf("%s\n", *err);
4354 ssl_debug_printf( "PKCS#12 imported\n");
4356 /* TODO: Use gnutls_pkcs12_simple_parse, since 3.1.0 (August 2012) */
4359 ret = gnutls_pkcs12_bag_init(&bag);
4362 ret = gnutls_pkcs12_get_bag(ssl_p12, i, bag);
4365 for (j=0; j<gnutls_pkcs12_bag_get_count(bag); j++) {
4367 ret = gnutls_pkcs12_bag_get_type(bag, j);
4368 if (ret < 0) goto done;
4369 bag_type = (gnutls_pkcs12_bag_type_t)ret;
4370 if (bag_type >= GNUTLS_BAG_UNKNOWN) goto done;
4371 ssl_debug_printf( "Bag %d/%d: %s\n", i, j, BAGTYPE(bag_type));
4372 if (bag_type == GNUTLS_BAG_ENCRYPTED) {
4373 ret = gnutls_pkcs12_bag_decrypt(bag, cert_passwd);
4375 ret = gnutls_pkcs12_bag_get_type(bag, j);
4376 if (ret < 0) goto done;
4377 bag_type = (gnutls_pkcs12_bag_type_t)ret;
4378 if (bag_type >= GNUTLS_BAG_UNKNOWN) goto done;
4379 ssl_debug_printf( "Bag %d/%d decrypted: %s\n", i, j, BAGTYPE(bag_type));
4383 ret = gnutls_pkcs12_bag_get_data(bag, j, &data);
4384 if (ret < 0) goto done;
4388 case GNUTLS_BAG_PKCS8_KEY:
4389 case GNUTLS_BAG_PKCS8_ENCRYPTED_KEY:
4391 ret = gnutls_x509_privkey_init(&ssl_pkey);
4393 *err = g_strdup_printf("gnutls_x509_privkey_init(&ssl_pkey) - %s", gnutls_strerror(ret));
4394 ssl_debug_printf("%s\n", *err);
4397 ret = gnutls_x509_privkey_import_pkcs8(ssl_pkey, &data, GNUTLS_X509_FMT_DER, cert_passwd,
4398 (bag_type==GNUTLS_BAG_PKCS8_KEY) ? GNUTLS_PKCS_PLAIN : 0);
4400 *err = g_strdup_printf("Can not decrypt private key - %s", gnutls_strerror(ret));
4401 ssl_debug_printf("%s\n", *err);
4405 if (gnutls_x509_privkey_get_pk_algorithm(ssl_pkey) != GNUTLS_PK_RSA) {
4406 *err = g_strdup("ssl_load_pkcs12: private key public key algorithm isn't RSA");
4407 ssl_debug_printf("%s\n", *err);
4411 /* Private key found, return it. */
4412 priv_key = ssl_pkey;
4418 if (bag) { gnutls_pkcs12_bag_deinit(bag); bag = NULL; }
4422 if (!priv_key && ssl_pkey)
4423 gnutls_x509_privkey_deinit(ssl_pkey);
4425 gnutls_pkcs12_bag_deinit(bag);
4432 ssl_private_key_free(gpointer key)
4434 gcry_sexp_release((gcry_sexp_t) key);
4438 ssl_find_private_key_by_pubkey(SslDecryptSession *ssl, GHashTable *key_hash,
4439 gnutls_datum_t *subjectPublicKeyInfo)
4441 gnutls_pubkey_t pubkey = NULL;
4443 size_t key_id_len = sizeof(key_id);
4446 if (!subjectPublicKeyInfo->size) {
4447 ssl_debug_printf("%s: could not find SubjectPublicKeyInfo\n", G_STRFUNC);
4451 r = gnutls_pubkey_init(&pubkey);
4453 ssl_debug_printf("%s: failed to init pubkey: %s\n",
4454 G_STRFUNC, gnutls_strerror(r));
4458 r = gnutls_pubkey_import(pubkey, subjectPublicKeyInfo, GNUTLS_X509_FMT_DER);
4460 ssl_debug_printf("%s: failed to import pubkey from handshake: %s\n",
4461 G_STRFUNC, gnutls_strerror(r));
4465 /* Generate a 20-byte SHA-1 hash. */
4466 r = gnutls_pubkey_get_key_id(pubkey, 0, key_id, &key_id_len);
4468 ssl_debug_printf("%s: failed to extract key id from pubkey: %s\n",
4469 G_STRFUNC, gnutls_strerror(r));
4473 ssl_print_data("lookup(KeyID)", key_id, key_id_len);
4474 ssl->private_key = (gcry_sexp_t)g_hash_table_lookup(key_hash, key_id);
4475 ssl_debug_printf("%s: lookup result: %p\n", G_STRFUNC, (void *) ssl->private_key);
4478 gnutls_pubkey_deinit(pubkey);
4481 /* RSA private key file processing }}} */
4483 #else /* ! (defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)) */
4485 ssl_private_key_free(gpointer key _U_)
4488 #endif /* ! (defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)) */
4491 /*--- Start of dissector-related code below ---*/
4493 /* get ssl data for this session. if no ssl data is found allocate a new one*/
4495 ssl_get_session(conversation_t *conversation, dissector_handle_t ssl_handle)
4498 SslDecryptSession *ssl_session;
4501 proto_ssl = dissector_handle_get_protocol_index(ssl_handle);
4502 conv_data = conversation_get_proto_data(conversation, proto_ssl);
4503 if (conv_data != NULL)
4504 return (SslDecryptSession *)conv_data;
4506 /* no previous SSL conversation info, initialize it. */
4507 ssl_session = wmem_new0(wmem_file_scope(), SslDecryptSession);
4509 /* data_len is the part that is meaningful, not the allocated length */
4510 ssl_session->master_secret.data_len = 0;
4511 ssl_session->master_secret.data = ssl_session->_master_secret;
4512 ssl_session->session_id.data_len = 0;
4513 ssl_session->session_id.data = ssl_session->_session_id;
4514 ssl_session->client_random.data_len = 0;
4515 ssl_session->client_random.data = ssl_session->_client_random;
4516 ssl_session->server_random.data_len = 0;
4517 ssl_session->server_random.data = ssl_session->_server_random;
4518 ssl_session->session_ticket.data_len = 0;
4519 ssl_session->session_ticket.data = NULL; /* will be re-alloced as needed */
4520 ssl_session->server_data_for_iv.data_len = 0;
4521 ssl_session->server_data_for_iv.data = ssl_session->_server_data_for_iv;
4522 ssl_session->client_data_for_iv.data_len = 0;
4523 ssl_session->client_data_for_iv.data = ssl_session->_client_data_for_iv;
4524 ssl_session->app_data_segment.data = NULL;
4525 ssl_session->app_data_segment.data_len = 0;
4526 ssl_session->handshake_data.data=NULL;
4527 ssl_session->handshake_data.data_len=0;
4529 /* Initialize parameters which are not necessary specific to decryption. */
4530 ssl_session->session.version = SSL_VER_UNKNOWN;
4531 clear_address(&ssl_session->session.srv_addr);
4532 ssl_session->session.srv_ptype = PT_NONE;
4533 ssl_session->session.srv_port = 0;
4535 conversation_add_proto_data(conversation, proto_ssl, ssl_session);
4539 /* Resets the decryption parameters for the next decoder. */
4540 static void ssl_reset_session(SslSession *session, SslDecryptSession *ssl, gboolean is_client)
4543 /* Ensure that secrets are not restored using stale identifiers. Split
4544 * between client and server in case the packets somehow got out of order. */
4545 gint clear_flags = SSL_HAVE_SESSION_KEY | SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET;
4548 clear_flags |= SSL_CLIENT_EXTENDED_MASTER_SECRET;
4549 ssl->session_id.data_len = 0;
4550 ssl->session_ticket.data_len = 0;
4551 ssl->master_secret.data_len = 0;
4552 ssl->client_random.data_len = 0;
4553 ssl->has_early_data = FALSE;
4555 clear_flags |= SSL_SERVER_EXTENDED_MASTER_SECRET | SSL_NEW_SESSION_TICKET;
4556 ssl->server_random.data_len = 0;
4557 ssl->pre_master_secret.data_len = 0;
4558 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
4559 ssl->private_key = NULL;
4561 ssl->psk.data_len = 0;
4564 if (ssl->state & clear_flags) {
4565 ssl_debug_printf("%s detected renegotiation, clearing 0x%02x (%s side)\n",
4566 G_STRFUNC, ssl->state & clear_flags, is_client ? "client" : "server");
4567 ssl->state &= ~clear_flags;
4571 /* These flags might be used for non-decryption purposes and may affect the
4572 * dissection, so reset them as well. */
4574 session->client_cert_type = 0;
4576 session->compression = 0;
4577 session->server_cert_type = 0;
4578 /* session->is_session_resumed is already handled in the ServerHello dissection. */
4583 ssl_starttls(dissector_handle_t ssl_handle, packet_info *pinfo,
4584 dissector_handle_t app_handle, guint32 last_nontls_frame)
4586 conversation_t *conversation;
4587 SslSession *session;
4589 /* Ignore if the SSL dissector is disabled. */
4592 /* The caller should always pass a valid handle to its own dissector. */
4593 DISSECTOR_ASSERT(app_handle);
4595 conversation = find_or_create_conversation(pinfo);
4596 session = &ssl_get_session(conversation, ssl_handle)->session;
4598 ssl_debug_printf("%s: old frame %d, app_handle=%p (%s)\n", G_STRFUNC,
4599 session->last_nontls_frame,
4600 (void *)session->app_handle,
4601 dissector_handle_get_dissector_name(session->app_handle));
4602 ssl_debug_printf("%s: current frame %d, app_handle=%p (%s)\n", G_STRFUNC,
4603 pinfo->num, (void *)app_handle,
4604 dissector_handle_get_dissector_name(app_handle));
4606 /* Do not switch again if a dissector did it before. */
4607 if (session->last_nontls_frame) {
4608 ssl_debug_printf("%s: not overriding previous app handle!\n", G_STRFUNC);
4609 return session->last_nontls_frame;
4612 session->app_handle = app_handle;
4613 /* The SSL dissector should be called first for this conversation. */
4614 conversation_set_dissector(conversation, ssl_handle);
4615 /* SSL starts after this frame. */
4616 session->last_nontls_frame = last_nontls_frame;
4620 /* ssl_starttls_ack: mark future frames as encrypted. {{{ */
4622 ssl_starttls_ack(dissector_handle_t ssl_handle, packet_info *pinfo,
4623 dissector_handle_t app_handle)
4625 return ssl_starttls(ssl_handle, pinfo, app_handle, pinfo->num);
4629 ssl_starttls_post_ack(dissector_handle_t ssl_handle, packet_info *pinfo,
4630 dissector_handle_t app_handle)
4632 return ssl_starttls(ssl_handle, pinfo, app_handle, pinfo->num - 1);
4636 ssl_find_appdata_dissector(const char *name)
4638 /* Accept 'http' for backwards compatibility and sanity. */
4639 if (!strcmp(name, "http"))
4640 name = "http-over-tls";
4641 return find_dissector(name);
4644 /* Functions for TLS/DTLS sessions and RSA private keys hashtables. {{{ */
4646 ssl_equal (gconstpointer v, gconstpointer v2)
4648 const StringInfo *val1;
4649 const StringInfo *val2;
4650 val1 = (const StringInfo *)v;
4651 val2 = (const StringInfo *)v2;
4653 if (val1->data_len == val2->data_len &&
4654 !memcmp(val1->data, val2->data, val2->data_len)) {
4661 ssl_hash (gconstpointer v)
4664 const StringInfo* id;
4667 id = (const StringInfo*) v;
4669 /* id and id->data are mallocated in ssl_save_master_key(). As such 'data'
4670 * should be aligned for any kind of access (for example as a guint as
4671 * is done below). The intermediate void* cast is to prevent "cast
4672 * increases required alignment of target type" warnings on CPUs (such
4673 * as SPARCs) that do not allow misaligned memory accesses.
4675 cur = (const guint*)(void*) id->data;
4677 for (l=4; (l < id->data_len); l+=4, cur++)
4678 hash = hash ^ (*cur);
4684 ssl_private_key_equal (gconstpointer v, gconstpointer v2)
4686 /* key ID length (SHA-1 hash, per GNUTLS_KEYID_USE_SHA1) */
4687 return !memcmp(v, v2, 20);
4691 ssl_private_key_hash (gconstpointer v)
4694 const guint8 *cur = (const guint8 *)v;
4696 /* The public key' SHA-1 hash (which maps to a private key) has a uniform
4697 * distribution, hence simply xor'ing them should be sufficient. */
4698 for (l = 0; l < 20; l += 4, cur += 4)
4699 hash ^= pntoh32(cur);
4703 /* Functions for TLS/DTLS sessions and RSA private keys hashtables. }}} */
4705 /* Handling of association between tls/dtls ports and clear text protocol. {{{ */
4707 ssl_association_add(const char* dissector_table_name, dissector_handle_t main_handle, dissector_handle_t subdissector_handle, guint port, gboolean tcp)
4709 DISSECTOR_ASSERT(main_handle);
4710 DISSECTOR_ASSERT(subdissector_handle);
4711 /* Registration is required for Export PDU feature to work properly. */
4712 DISSECTOR_ASSERT_HINT(dissector_handle_get_dissector_name(subdissector_handle),
4713 "SSL appdata dissectors must register with register_dissector()!");
4714 ssl_debug_printf("association_add %s port %d handle %p\n", dissector_table_name, port, (void *)subdissector_handle);
4717 dissector_add_uint(dissector_table_name, port, subdissector_handle);
4719 dissector_add_uint("tcp.port", port, main_handle);
4721 dissector_add_uint("udp.port", port, main_handle);
4722 dissector_add_uint("sctp.port", port, main_handle);
4724 dissector_add_for_decode_as(dissector_table_name, subdissector_handle);
4729 ssl_association_remove(const char* dissector_table_name, dissector_handle_t main_handle, dissector_handle_t subdissector_handle, guint port, gboolean tcp)
4731 ssl_debug_printf("ssl_association_remove removing %s %u - handle %p\n",
4732 tcp?"TCP":"UDP", port, (void *)subdissector_handle);
4734 dissector_delete_uint(tcp?"tcp.port":"udp.port", port, main_handle);
4735 dissector_delete_uint("sctp.port", port, main_handle);
4739 dissector_delete_uint(dissector_table_name, port, subdissector_handle);
4744 ssl_set_server(SslSession *session, address *addr, port_type ptype, guint32 port)
4746 copy_address_wmem(wmem_file_scope(), &session->srv_addr, addr);
4747 session->srv_ptype = ptype;
4748 session->srv_port = port;
4752 ssl_packet_from_server(SslSession *session, dissector_table_t table, packet_info *pinfo)
4755 if (session->srv_addr.type != AT_NONE) {
4756 ret = (session->srv_ptype == pinfo->ptype) &&
4757 (session->srv_port == pinfo->srcport) &&
4758 addresses_equal(&session->srv_addr, &pinfo->src);
4760 ret = (dissector_get_uint_handle(table, pinfo->srcport) != 0);
4763 ssl_debug_printf("packet_from_server: is from server - %s\n", (ret)?"TRUE":"FALSE");
4766 /* Handling of association between tls/dtls ports and clear text protocol. }}} */
4769 /* Links SSL records with the real packet data. {{{ */
4771 * Remembers the decrypted TLS record fragment (TLSInnerPlaintext in TLS 1.3) to
4772 * avoid the need for a decoder in the second pass. Additionally, it remembers
4773 * sequence numbers (for reassembly and Follow SSL Stream).
4775 * @param proto The protocol identifier (proto_ssl or proto_dtls).
4776 * @param pinfo The packet where the record originates from.
4777 * @param data Decrypted data to store in the record.
4778 * @param data_len Length of decrypted record data.
4779 * @param record_id The identifier for this record within the current packet.
4780 * @param flow Information about sequence numbers, etc.
4781 * @param type TLS Content Type (such as handshake or application_data).
4784 ssl_add_record_info(gint proto, packet_info *pinfo, const guchar *data, gint data_len, gint record_id, SslFlow *flow, ContentType type)
4786 SslRecordInfo* rec, **prec;
4789 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4792 pi = wmem_new0(wmem_file_scope(), SslPacketInfo);
4793 p_add_proto_data(wmem_file_scope(), pinfo, proto, 0, pi);
4796 rec = wmem_new(wmem_file_scope(), SslRecordInfo);
4797 rec->plain_data = (guchar *)wmem_memdup(wmem_file_scope(), data, data_len);
4798 rec->data_len = data_len;
4799 rec->id = record_id;
4803 /* TODO allow Handshake records also to be reassembled. There needs to be
4804 * one "flow" for each record type (appdata, handshake). "seq" for the
4805 * record should then be relative within this flow. */
4806 if (flow && type == SSL_ID_APP_DATA) {
4807 rec->seq = flow->byte_seq;
4809 flow->byte_seq += data_len;
4810 ssl_debug_printf("%s stored decrypted record seq=%d nxtseq=%d flow=%p\n",
4811 G_STRFUNC, rec->seq, rec->seq + data_len, (void*)flow);
4814 /* Remember decrypted records. */
4815 prec = &pi->records;
4816 while (*prec) prec = &(*prec)->next;
4820 /* search in packet data for the specified id; return a newly created tvb for the associated data */
4822 ssl_get_record_info(tvbuff_t *parent_tvb, int proto, packet_info *pinfo, gint record_id, SslRecordInfo **matched_record)
4826 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4831 for (rec = pi->records; rec; rec = rec->next)
4832 if (rec->id == record_id) {
4833 *matched_record = rec;
4834 /* link new real_data_tvb with a parent tvb so it is freed when frame dissection is complete */
4835 return tvb_new_child_real_data(parent_tvb, rec->plain_data, rec->data_len, rec->data_len);
4840 /* Links SSL records with the real packet data. }}} */
4842 /* initialize/reset per capture state data (ssl sessions cache). {{{ */
4844 ssl_common_init(ssl_master_key_map_t *mk_map,
4845 StringInfo *decrypted_data, StringInfo *compressed_data)
4847 mk_map->session = g_hash_table_new(ssl_hash, ssl_equal);
4848 mk_map->tickets = g_hash_table_new(ssl_hash, ssl_equal);
4849 mk_map->crandom = g_hash_table_new(ssl_hash, ssl_equal);
4850 mk_map->pre_master = g_hash_table_new(ssl_hash, ssl_equal);
4851 mk_map->pms = g_hash_table_new(ssl_hash, ssl_equal);
4852 mk_map->tls13_client_early = g_hash_table_new(ssl_hash, ssl_equal);
4853 mk_map->tls13_client_handshake = g_hash_table_new(ssl_hash, ssl_equal);
4854 mk_map->tls13_server_handshake = g_hash_table_new(ssl_hash, ssl_equal);
4855 mk_map->tls13_client_appdata = g_hash_table_new(ssl_hash, ssl_equal);
4856 mk_map->tls13_server_appdata = g_hash_table_new(ssl_hash, ssl_equal);
4857 ssl_data_alloc(decrypted_data, 32);
4858 ssl_data_alloc(compressed_data, 32);
4862 ssl_common_cleanup(ssl_master_key_map_t *mk_map, FILE **ssl_keylog_file,
4863 StringInfo *decrypted_data, StringInfo *compressed_data)
4865 g_hash_table_destroy(mk_map->session);
4866 g_hash_table_destroy(mk_map->tickets);
4867 g_hash_table_destroy(mk_map->crandom);
4868 g_hash_table_destroy(mk_map->pre_master);
4869 g_hash_table_destroy(mk_map->pms);
4870 g_hash_table_destroy(mk_map->tls13_client_early);
4871 g_hash_table_destroy(mk_map->tls13_client_handshake);
4872 g_hash_table_destroy(mk_map->tls13_server_handshake);
4873 g_hash_table_destroy(mk_map->tls13_client_appdata);
4874 g_hash_table_destroy(mk_map->tls13_server_appdata);
4876 g_free(decrypted_data->data);
4877 g_free(compressed_data->data);
4879 /* close the previous keylog file now that the cache are cleared, this
4880 * allows the cache to be filled with the full keylog file contents. */
4881 if (*ssl_keylog_file) {
4882 fclose(*ssl_keylog_file);
4883 *ssl_keylog_file = NULL;
4888 /* parse ssl related preferences (private keys and ports association strings) */
4889 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
4890 /* Load a single RSA key file item from preferences. {{{ */
4892 ssl_parse_key_list(const ssldecrypt_assoc_t *uats, GHashTable *key_hash, const char* dissector_table_name, dissector_handle_t main_handle, gboolean tcp)
4894 gnutls_x509_privkey_t priv_key;
4895 gcry_sexp_t private_key;
4898 size_t key_id_len = 20;
4899 guchar *key_id = NULL;
4900 dissector_handle_t handle;
4901 /* try to load keys file first */
4902 fp = ws_fopen(uats->keyfile, "rb");
4904 report_open_failure(uats->keyfile, errno, FALSE);
4908 if ((gint)strlen(uats->password) == 0) {
4909 priv_key = ssl_load_key(fp);
4912 priv_key = ssl_load_pkcs12(fp, uats->password, &err);
4914 report_failure("%s\n", err);
4921 report_failure("Can't load private key from %s\n", uats->keyfile);
4925 key_id = (guchar *) g_malloc0(key_id_len);
4926 ret = gnutls_x509_privkey_get_key_id(priv_key, 0, key_id, &key_id_len);
4928 report_failure("Can't calculate public key ID for %s: %s",
4929 uats->keyfile, gnutls_strerror(ret));
4932 ssl_print_data("KeyID", key_id, key_id_len);
4934 private_key = ssl_privkey_to_sexp(priv_key);
4936 report_failure("Can't extract private key parameters for %s", uats->keyfile);
4940 g_hash_table_replace(key_hash, key_id, private_key);
4941 key_id = NULL; /* used in key_hash, do not free. */
4942 ssl_debug_printf("ssl_init private key file %s successfully loaded.\n", uats->keyfile);
4944 handle = ssl_find_appdata_dissector(uats->protocol);
4946 /* Port to subprotocol mapping */
4948 if (ws_strtou16(uats->port, NULL, &port)) {
4950 ssl_debug_printf("ssl_init port '%d' filename '%s' password(only for p12 file) '%s'\n",
4951 port, uats->keyfile, uats->password);
4953 ssl_association_add(dissector_table_name, main_handle, handle, port, tcp);
4956 if (strcmp(uats->port, "start_tls"))
4957 ssl_debug_printf("invalid ssl_init_port: %s\n", uats->port);
4962 gnutls_x509_privkey_deinit(priv_key);
4968 ssl_parse_key_list(const ssldecrypt_assoc_t *uats _U_, GHashTable *key_hash _U_, const char* dissector_table_name _U_, dissector_handle_t main_handle _U_, gboolean tcp _U_)
4970 report_failure("Can't load private key files, support is not compiled in.");
4975 #ifdef HAVE_LIBGCRYPT /* useless without decryption support. */
4976 /* Store/load a known (pre-)master secret from/for this SSL session. {{{ */
4977 /** store a known (pre-)master secret into cache */
4979 ssl_save_master_key(const char *label, GHashTable *ht, StringInfo *key,
4982 StringInfo *ht_key, *master_secret;
4984 if (key->data_len == 0) {
4985 ssl_debug_printf("%s: not saving empty %s!\n", G_STRFUNC, label);
4989 if (mk->data_len == 0) {
4990 ssl_debug_printf("%s not saving empty (pre-)master secret for %s!\n",
4995 /* ssl_hash() depends on session_ticket->data being aligned for guint access
4996 * so be careful in changing how it is allocated. */
4997 ht_key = ssl_data_clone(key);
4998 master_secret = ssl_data_clone(mk);
4999 g_hash_table_insert(ht, ht_key, master_secret);
5001 ssl_debug_printf("%s inserted (pre-)master secret for %s\n", G_STRFUNC, label);
5002 ssl_print_string("stored key", ht_key);
5003 ssl_print_string("stored (pre-)master secret", master_secret);
5006 /** restore a (pre-)master secret given some key in the cache */
5008 ssl_restore_master_key(SslDecryptSession *ssl, const char *label,
5009 gboolean is_pre_master, GHashTable *ht, StringInfo *key)
5013 if (key->data_len == 0) {
5014 ssl_debug_printf("%s can't restore %smaster secret using an empty %s\n",
5015 G_STRFUNC, is_pre_master ? "pre-" : "", label);
5019 ms = (StringInfo *)g_hash_table_lookup(ht, key);
5021 ssl_debug_printf("%s can't find %smaster secret by %s\n", G_STRFUNC,
5022 is_pre_master ? "pre-" : "", label);
5026 /* (pre)master secret found, clear knowledge of other keys and set it in the
5027 * current conversation */
5028 ssl->state &= ~(SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET |
5029 SSL_HAVE_SESSION_KEY);
5030 if (is_pre_master) {
5031 /* unlike master secret, pre-master secret has a variable size (48 for
5032 * RSA, varying for PSK) and is therefore not statically allocated */
5033 ssl->pre_master_secret.data = (guchar *) wmem_alloc(wmem_file_scope(),
5035 ssl_data_set(&ssl->pre_master_secret, ms->data, ms->data_len);
5036 ssl->state |= SSL_PRE_MASTER_SECRET;
5038 ssl_data_set(&ssl->master_secret, ms->data, ms->data_len);
5039 ssl->state |= SSL_MASTER_SECRET;
5041 ssl_debug_printf("%s %smaster secret retrieved using %s\n", G_STRFUNC,
5042 is_pre_master ? "pre-" : "", label);
5043 ssl_print_string(label, key);
5044 ssl_print_string("(pre-)master secret", ms);
5047 /* Store/load a known (pre-)master secret from/for this SSL session. }}} */
5049 /* Should be called when all parameters are ready (after ChangeCipherSpec), and
5050 * the decoder should be attempted to be initialized. {{{*/
5052 ssl_finalize_decryption(SslDecryptSession *ssl, ssl_master_key_map_t *mk_map)
5054 if (ssl->session.version == TLSV1DOT3_VERSION) {
5055 /* TLS 1.3 implementations only provide secrets derived from the master
5056 * secret which are loaded in tls13_change_key. No master secrets can be
5057 * loaded here, so just return. */
5060 ssl_debug_printf("%s state = 0x%02X\n", G_STRFUNC, ssl->state);
5061 if (ssl->state & SSL_HAVE_SESSION_KEY) {
5062 ssl_debug_printf(" session key already available, nothing to do.\n");
5065 if (!(ssl->state & SSL_CIPHER)) {
5066 ssl_debug_printf(" Cipher suite (Server Hello) is missing!\n");
5070 /* for decryption, there needs to be a master secret (which can be derived
5071 * from pre-master secret). If missing, try to pick a master key from cache
5072 * (an earlier packet in the capture or key logfile). */
5073 if (!(ssl->state & (SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET)) &&
5074 !ssl_restore_master_key(ssl, "Session ID", FALSE,
5075 mk_map->session, &ssl->session_id) &&
5076 (!ssl->session.is_session_resumed ||
5077 !ssl_restore_master_key(ssl, "Session Ticket", FALSE,
5078 mk_map->tickets, &ssl->session_ticket)) &&
5079 !ssl_restore_master_key(ssl, "Client Random", FALSE,
5080 mk_map->crandom, &ssl->client_random)) {
5081 if (ssl->cipher_suite->enc != ENC_NULL) {
5082 /* how unfortunate, the master secret could not be found */
5083 ssl_debug_printf(" Cannot find master secret\n");
5086 ssl_debug_printf(" Cannot find master secret, continuing anyway "
5087 "because of a NULL cipher\n");
5091 if (ssl_generate_keyring_material(ssl) < 0) {
5092 ssl_debug_printf("%s can't generate keyring material\n", G_STRFUNC);
5095 /* Save Client Random/ Session ID for "SSL Export Session keys" */
5096 ssl_save_master_key("Client Random", mk_map->crandom,
5097 &ssl->client_random, &ssl->master_secret);
5098 ssl_save_master_key("Session ID", mk_map->session,
5099 &ssl->session_id, &ssl->master_secret);
5100 /* Only save the new secrets if the server sent the ticket. The client
5101 * ticket might have become stale. */
5102 if (ssl->state & SSL_NEW_SESSION_TICKET) {
5103 ssl_save_master_key("Session Ticket", mk_map->tickets,
5104 &ssl->session_ticket, &ssl->master_secret);
5108 /* Load the new key. */
5110 tls13_change_key(SslDecryptSession *ssl, ssl_master_key_map_t *mk_map,
5111 gboolean is_from_server, TLSRecordType type)
5113 GHashTable *key_map;
5116 if (ssl->session.version != TLSV1DOT3_VERSION) {
5117 ssl_debug_printf("%s TLS version %#x is not 1.3\n", G_STRFUNC, ssl->session.version);
5121 if (ssl->client_random.data_len == 0) {
5122 /* May happen if Hello message is missing and Finished is found. */
5123 ssl_debug_printf("%s missing Client Random\n", G_STRFUNC);
5128 case TLS_SECRET_0RTT_APP:
5129 DISSECTOR_ASSERT(!is_from_server);
5130 label = "CLIENT_EARLY_TRAFFIC_SECRET";
5131 key_map = mk_map->tls13_client_early;
5133 case TLS_SECRET_HANDSHAKE:
5134 if (is_from_server) {
5135 label = "SERVER_HANDSHAKE_TRAFFIC_SECRET";
5136 key_map = mk_map->tls13_server_handshake;
5138 label = "CLIENT_HANDSHAKE_TRAFFIC_SECRET";
5139 key_map = mk_map->tls13_client_handshake;
5142 case TLS_SECRET_APP:
5143 if (is_from_server) {
5144 label = "SERVER_TRAFFIC_SECRET_0";
5145 key_map = mk_map->tls13_server_appdata;
5147 label = "CLIENT_TRAFFIC_SECRET_0";
5148 key_map = mk_map->tls13_client_appdata;
5152 g_assert_not_reached();
5155 /* Transitioning to new keys, mark old ones as unusable. */
5156 ssl_debug_printf("%s transitioning to new key, old state 0x%02x\n", G_STRFUNC, ssl->state);
5157 ssl->state &= ~(SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET | SSL_HAVE_SESSION_KEY);
5159 StringInfo *secret = (StringInfo *)g_hash_table_lookup(key_map, &ssl->client_random);
5161 ssl_debug_printf("%s Cannot find %s, decryption impossible\n", G_STRFUNC, label);
5162 /* Disable decryption, the keys are invalid. */
5163 if (is_from_server) {
5171 /* TLS 1.3 secret found, set new keys. */
5172 ssl->traffic_secret.data = (guchar *) wmem_realloc(wmem_file_scope(),
5173 ssl->traffic_secret.data, secret->data_len);
5174 ssl_data_set(&ssl->traffic_secret, secret->data, secret->data_len);
5175 ssl_debug_printf("%s Retrieved TLS 1.3 traffic secret.\n", G_STRFUNC);
5176 ssl_print_string("Client Random", &ssl->client_random);
5177 ssl_print_string(label, secret);
5178 tls13_generate_keys(ssl, secret, is_from_server);
5180 #endif /* HAVE_LIBGCRYPT */
5182 /** SSL keylog file handling. {{{ */
5185 ssl_compile_keyfile_regex(void)
5187 #define OCTET "(?:[[:xdigit:]]{2})"
5188 const gchar *pattern =
5190 /* Matches Client Hellos having this Client Random */
5191 "PMS_CLIENT_RANDOM (?<client_random_pms>" OCTET "{32}) "
5192 /* Matches first part of encrypted RSA pre-master secret */
5193 "|RSA (?<encrypted_pmk>" OCTET "{8}) "
5194 /* Pre-Master-Secret is given, it is 48 bytes for RSA,
5195 but it can be of any length for DHE */
5196 ")(?<pms>" OCTET "+)"
5198 /* Matches Server Hellos having a Session ID */
5199 "RSA Session-ID:(?<session_id>" OCTET "+) Master-Key:"
5200 /* Matches Client Hellos having this Client Random */
5201 "|CLIENT_RANDOM (?<client_random>" OCTET "{32}) "
5202 /* Master-Secret is given, its length is fixed */
5203 ")(?<master_secret>" OCTET "{" G_STRINGIFY(SSL_MASTER_SECRET_LENGTH) "})"
5205 /* TLS 1.3 Client Random to Derived Secrets mapping. */
5206 ":CLIENT_EARLY_TRAFFIC_SECRET (?<client_early>" OCTET "{32})"
5207 "|CLIENT_HANDSHAKE_TRAFFIC_SECRET (?<client_handshake>" OCTET "{32})"
5208 "|SERVER_HANDSHAKE_TRAFFIC_SECRET (?<server_handshake>" OCTET "{32})"
5209 "|CLIENT_TRAFFIC_SECRET_0 (?<client_appdata>" OCTET "{32})"
5210 "|SERVER_TRAFFIC_SECRET_0 (?<server_appdata>" OCTET "{32})"
5211 ") (?<derived_secret>" OCTET "+)";
5213 static GRegex *regex = NULL;
5214 GError *gerr = NULL;
5217 regex = g_regex_new(pattern,
5218 (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_ANCHORED),
5219 G_REGEX_MATCH_ANCHORED, &gerr);
5221 ssl_debug_printf("%s failed to compile regex: %s\n", G_STRFUNC,
5232 file_needs_reopen(FILE *fp, const char *filename)
5234 ws_statb64 open_stat, current_stat;
5236 /* consider a file deleted when stat fails for either file,
5237 * or when the residing device / inode has changed. */
5238 if (0 != ws_fstat64(ws_fileno(fp), &open_stat))
5240 if (0 != ws_stat64(filename, ¤t_stat))
5243 /* Note: on Windows, ino may be 0. Existing files cannot be deleted on
5244 * Windows, but hopefully the size is a good indicator when a file got
5245 * removed and recreated */
5246 return open_stat.st_dev != current_stat.st_dev ||
5247 open_stat.st_ino != current_stat.st_ino ||
5248 open_stat.st_size > current_stat.st_size;
5251 typedef struct ssl_master_key_match_group {
5252 const char *re_group_name;
5253 GHashTable *master_key_ht;
5254 } ssl_master_key_match_group_t;
5257 ssl_load_keyfile(const gchar *ssl_keylog_filename, FILE **keylog_file,
5258 const ssl_master_key_map_t *mk_map)
5262 ssl_master_key_match_group_t mk_groups[] = {
5263 { "encrypted_pmk", mk_map->pre_master },
5264 { "session_id", mk_map->session },
5265 { "client_random", mk_map->crandom },
5266 { "client_random_pms", mk_map->pms },
5267 /* TLS 1.3 map from Client Random to derived secret. */
5268 { "client_early", mk_map->tls13_client_early },
5269 { "client_handshake", mk_map->tls13_client_handshake },
5270 { "server_handshake", mk_map->tls13_server_handshake },
5271 { "client_appdata", mk_map->tls13_client_appdata },
5272 { "server_appdata", mk_map->tls13_server_appdata },
5274 /* no need to try if no key log file is configured. */
5275 if (!ssl_keylog_filename || !*ssl_keylog_filename) {
5276 ssl_debug_printf("%s dtls/ssl.keylog_file is not configured!\n",
5281 /* The format of the file is a series of records with one of the following formats:
5283 * Where xxxx are the first 8 bytes of the encrypted pre-master secret (hex-encoded)
5284 * Where yyyy is the cleartext pre-master secret (hex-encoded)
5285 * (this is the original format introduced with bug 4349)
5287 * - "RSA Session-ID:xxxx Master-Key:yyyy"
5288 * Where xxxx is the SSL session ID (hex-encoded)
5289 * Where yyyy is the cleartext master secret (hex-encoded)
5290 * (added to support openssl s_client Master-Key output)
5291 * This is somewhat is a misnomer because there's nothing RSA specific
5294 * - "PMS_CLIENT_RANDOM xxxx yyyy"
5295 * Where xxxx is the client_random from the ClientHello (hex-encoded)
5296 * Where yyyy is the cleartext pre-master secret (hex-encoded)
5297 * (This format allows SSL connections to be decrypted, if a user can
5298 * capture the PMS but could not recover the MS for a specific session
5299 * with a SSL Server.)
5301 * - "CLIENT_RANDOM xxxx yyyy"
5302 * Where xxxx is the client_random from the ClientHello (hex-encoded)
5303 * Where yyyy is the cleartext master secret (hex-encoded)
5304 * (This format allows non-RSA SSL connections to be decrypted, i.e.
5307 * - "CLIENT_EARLY_TRAFFIC_SECRET xxxx yyyy"
5308 * - "CLIENT_HANDSHAKE_TRAFFIC_SECRET xxxx yyyy"
5309 * - "SERVER_HANDSHAKE_TRAFFIC_SECRET xxxx yyyy"
5310 * - "CLIENT_TRAFFIC_SECRET_0 xxxx yyyy"
5311 * - "SERVER_TRAFFIC_SECRET_0 xxxx yyyy"
5312 * Where xxxx is the client_random from the ClientHello (hex-encoded)
5313 * Where yyyy is the secret (hex-encoded) derived from the early,
5314 * handshake or master secrets. (This format is introduced with TLS 1.3
5315 * and supported by BoringSSL, OpenSSL, etc. See bug 12779.)
5317 regex = ssl_compile_keyfile_regex();
5321 ssl_debug_printf("trying to use SSL keylog in %s\n", ssl_keylog_filename);
5323 /* if the keylog file was deleted, re-open it */
5324 if (*keylog_file && file_needs_reopen(*keylog_file, ssl_keylog_filename)) {
5325 ssl_debug_printf("%s file got deleted, trying to re-open\n", G_STRFUNC);
5326 fclose(*keylog_file);
5327 *keylog_file = NULL;
5330 if (*keylog_file == NULL) {
5331 *keylog_file = ws_fopen(ssl_keylog_filename, "r");
5332 if (!*keylog_file) {
5333 ssl_debug_printf("%s failed to open SSL keylog\n", G_STRFUNC);
5339 char buf[512], *line;
5343 line = fgets(buf, sizeof(buf), *keylog_file);
5347 bytes_read = strlen(line);
5348 /* fgets includes the \n at the end of the line. */
5349 if (bytes_read > 0 && line[bytes_read - 1] == '\n') {
5350 line[bytes_read - 1] = 0;
5353 if (bytes_read > 0 && line[bytes_read - 1] == '\r') {
5354 line[bytes_read - 1] = 0;
5358 ssl_debug_printf(" checking keylog line: %s\n", line);
5359 if (g_regex_match(regex, line, G_REGEX_MATCH_ANCHORED, &mi)) {
5360 gchar *hex_key, *hex_pre_ms_or_ms;
5361 StringInfo *key = wmem_new(wmem_file_scope(), StringInfo);
5362 StringInfo *pre_ms_or_ms = NULL;
5363 GHashTable *ht = NULL;
5365 /* Is the PMS being supplied with the PMS_CLIENT_RANDOM
5366 * otherwise we will use the Master Secret
5368 hex_pre_ms_or_ms = g_match_info_fetch_named(mi, "master_secret");
5369 if (hex_pre_ms_or_ms == NULL || !*hex_pre_ms_or_ms) {
5370 g_free(hex_pre_ms_or_ms);
5371 hex_pre_ms_or_ms = g_match_info_fetch_named(mi, "pms");
5373 if (hex_pre_ms_or_ms == NULL || !*hex_pre_ms_or_ms) {
5374 g_free(hex_pre_ms_or_ms);
5375 hex_pre_ms_or_ms = g_match_info_fetch_named(mi, "derived_secret");
5377 /* There is always a match, otherwise the regex is wrong. */
5378 DISSECTOR_ASSERT(hex_pre_ms_or_ms && strlen(hex_pre_ms_or_ms));
5380 /* convert from hex to bytes and save to hashtable */
5381 pre_ms_or_ms = wmem_new(wmem_file_scope(), StringInfo);
5382 from_hex(pre_ms_or_ms, hex_pre_ms_or_ms, strlen(hex_pre_ms_or_ms));
5383 g_free(hex_pre_ms_or_ms);
5385 /* Find a master key from any format (CLIENT_RANDOM, SID, ...) */
5386 for (i = 0; i < G_N_ELEMENTS(mk_groups); i++) {
5387 ssl_master_key_match_group_t *g = &mk_groups[i];
5388 hex_key = g_match_info_fetch_named(mi, g->re_group_name);
5389 if (hex_key && *hex_key) {
5390 ssl_debug_printf(" matched %s\n", g->re_group_name);
5391 ht = g->master_key_ht;
5392 from_hex(key, hex_key, strlen(hex_key));
5398 DISSECTOR_ASSERT(ht); /* Cannot be reached, or regex is wrong. */
5400 g_hash_table_insert(ht, key, pre_ms_or_ms);
5403 ssl_debug_printf(" unrecognized line\n");
5405 /* always free match info even if there is no match. */
5406 g_match_info_free(mi);
5409 /** SSL keylog file handling. }}} */
5411 #ifdef SSL_DECRYPT_DEBUG /* {{{ */
5413 static FILE* ssl_debug_file=NULL;
5416 ssl_set_debug(const gchar* name)
5418 static gint debug_file_must_be_closed;
5421 use_stderr = name?(strcmp(name, SSL_DEBUG_USE_STDERR) == 0):0;
5423 if (debug_file_must_be_closed)
5424 fclose(ssl_debug_file);
5427 ssl_debug_file = stderr;
5428 else if (!name || (strcmp(name, "") ==0))
5429 ssl_debug_file = NULL;
5431 ssl_debug_file = ws_fopen(name, "w");
5433 if (!use_stderr && ssl_debug_file)
5434 debug_file_must_be_closed = 1;
5436 debug_file_must_be_closed = 0;
5438 ssl_debug_printf("Wireshark SSL debug log \n\n");
5439 ssl_debug_printf("Wireshark version: %s\n", get_ws_vcs_version_info());
5440 #ifdef HAVE_LIBGNUTLS
5441 ssl_debug_printf("GnuTLS version: %s\n", gnutls_check_version(NULL));
5443 #ifdef HAVE_LIBGCRYPT
5444 ssl_debug_printf("Libgcrypt version: %s\n", gcry_check_version(NULL));
5446 ssl_debug_printf("\n");
5450 ssl_debug_flush(void)
5453 fflush(ssl_debug_file);
5457 ssl_debug_printf(const gchar* fmt, ...)
5461 if (!ssl_debug_file)
5465 vfprintf(ssl_debug_file, fmt, ap);
5470 ssl_print_data(const gchar* name, const guchar* data, size_t len)
5473 if (!ssl_debug_file)
5475 fprintf(ssl_debug_file,"%s[%d]:\n",name, (int) len);
5476 for (i=0; i<len; i+=16) {
5477 fprintf(ssl_debug_file,"| ");
5478 for (j=i, k=0; k<16 && j<len; ++j, ++k)
5479 fprintf(ssl_debug_file,"%.2x ",data[j]);
5481 fprintf(ssl_debug_file," ");
5482 fputc('|', ssl_debug_file);
5483 for (j=i, k=0; k<16 && j<len; ++j, ++k) {
5485 if (!g_ascii_isprint(c) || (c=='\t')) c = '.';
5486 fputc(c, ssl_debug_file);
5489 fputc(' ', ssl_debug_file);
5490 fprintf(ssl_debug_file,"|\n");
5495 ssl_print_string(const gchar* name, const StringInfo* data)
5497 ssl_print_data(name, data->data, data->data_len);
5499 #endif /* SSL_DECRYPT_DEBUG }}} */
5501 /* UAT preferences callbacks. {{{ */
5502 /* checks for SSL and DTLS UAT key list fields */
5505 ssldecrypt_uat_fld_ip_chk_cb(void* r _U_, const char* p, guint len _U_, const void* u1 _U_, const void* u2 _U_, char** err)
5507 if (!p || strlen(p) == 0u) {
5508 *err = g_strdup("No IP address given.");
5517 ssldecrypt_uat_fld_port_chk_cb(void* r _U_, const char* p, guint len _U_, const void* u1 _U_, const void* u2 _U_, char** err)
5519 if (!p || strlen(p) == 0u) {
5520 *err = g_strdup("No Port given.");
5524 if (strcmp(p, "start_tls") != 0){
5526 if (!ws_strtou16(p, NULL, &port)) {
5527 *err = g_strdup("Invalid port given.");
5537 ssldecrypt_uat_fld_fileopen_chk_cb(void* r _U_, const char* p, guint len _U_, const void* u1 _U_, const void* u2 _U_, char** err)
5541 if (!p || strlen(p) == 0u) {
5542 *err = g_strdup("No filename given.");
5545 if (ws_stat64(p, &st) != 0) {
5546 *err = g_strdup_printf("File '%s' does not exist or access is denied.", p);
5556 ssldecrypt_uat_fld_password_chk_cb(void *r _U_, const char *p _U_, guint len _U_, const void *u1 _U_, const void *u2 _U_, char **err)
5558 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
5559 ssldecrypt_assoc_t* f = (ssldecrypt_assoc_t *)r;
5562 if (p && (strlen(p) > 0u)) {
5563 fp = ws_fopen(f->keyfile, "rb");
5566 gnutls_x509_privkey_t priv_key = ssl_load_pkcs12(fp, p, &msg);
5569 *err = g_strdup_printf("Could not load PKCS#12 key file: %s", msg);
5574 gnutls_x509_privkey_deinit(priv_key);
5577 *err = g_strdup_printf("Leave this field blank if the keyfile is not PKCS#12.");
5585 *err = g_strdup("Cannot load key files, support is not compiled in.");
5589 /* UAT preferences callbacks. }}} */
5591 /** maximum size of ssl_association_info() string */
5592 #define SSL_ASSOC_MAX_LEN 8192
5594 typedef struct ssl_association_info_callback_data
5597 const char *table_protocol;
5598 } ssl_association_info_callback_data_t;
5601 * callback function used by ssl_association_info() to traverse the SSL associations.
5604 ssl_association_info_(const gchar *table _U_, gpointer handle, gpointer user_data)
5606 ssl_association_info_callback_data_t* data = (ssl_association_info_callback_data_t*)user_data;
5607 const int l = (const int)strlen(data->str);
5608 g_snprintf(data->str+l, SSL_ASSOC_MAX_LEN-l, "'%s' %s\n", dissector_handle_get_short_name((dissector_handle_t)handle), data->table_protocol);
5612 * @return an information string on the SSL protocol associations. The string has ephemeral lifetime/scope.
5615 ssl_association_info(const char* dissector_table_name, const char* table_protocol)
5617 ssl_association_info_callback_data_t data;
5619 data.str = (gchar *)g_malloc0(SSL_ASSOC_MAX_LEN);
5620 data.table_protocol = table_protocol;
5621 dissector_table_foreach_handle(dissector_table_name, ssl_association_info_, &data);
5626 /** Begin of code related to dissection of wire data. */
5628 /* Helpers for dissecting Variable-Length Vectors. {{{ */
5630 ssl_add_vector(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
5631 guint offset, guint offset_end, guint32 *ret_length,
5632 int hf_length, guint32 min_value, guint32 max_value)
5635 guint32 veclen_value;
5638 DISSECTOR_ASSERT(offset <= offset_end);
5639 DISSECTOR_ASSERT(min_value <= max_value);
5641 if (max_value > 0xffffff) {
5643 } else if (max_value > 0xffff) {
5645 } else if (max_value > 0xff) {
5651 if (offset_end - offset < veclen_size) {
5652 proto_tree_add_expert_format(tree, pinfo, &hf->ei.malformed_buffer_too_small,
5653 tvb, offset, offset_end - offset,
5654 "No more room for vector of length %u",
5657 return FALSE; /* Cannot read length. */
5660 pi = proto_tree_add_item_ret_uint(tree, hf_length, tvb, offset, veclen_size, ENC_BIG_ENDIAN, &veclen_value);
5661 offset += veclen_size;
5663 if (veclen_value < min_value) {
5664 expert_add_info_format(pinfo, pi, &hf->ei.malformed_vector_length,
5665 "Vector length %u is smaller than minimum %u",
5666 veclen_value, min_value);
5667 } else if (veclen_value > max_value) {
5668 expert_add_info_format(pinfo, pi, &hf->ei.malformed_vector_length,
5669 "Vector length %u is larger than maximum %u",
5670 veclen_value, max_value);
5673 if (offset_end - offset < veclen_value) {
5674 expert_add_info_format(pinfo, pi, &hf->ei.malformed_buffer_too_small,
5675 "Vector length %u is too large, truncating it to %u",
5676 veclen_value, offset_end - offset);
5677 *ret_length = offset_end - offset;
5678 return FALSE; /* Length is truncated to avoid overflow. */
5681 *ret_length = veclen_value;
5682 return TRUE; /* Length is OK. */
5686 ssl_end_vector(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
5687 guint offset, guint offset_end)
5689 if (offset < offset_end) {
5690 guint trailing = offset_end - offset;
5691 proto_tree_add_expert_format(tree, pinfo, &hf->ei.malformed_trailing_data,
5692 tvb, offset, trailing,
5693 "%u trailing byte%s unprocessed",
5694 trailing, plurality(trailing, " was", "s were"));
5695 return FALSE; /* unprocessed data warning */
5696 } else if (offset > offset_end) {
5698 * Returned offset runs past the end. This should not happen and is
5699 * possibly a dissector bug.
5701 guint excess = offset - offset_end;
5702 proto_tree_add_expert_format(tree, pinfo, &hf->ei.malformed_buffer_too_small,
5703 tvb, offset_end, excess,
5704 "Dissector processed too much data (%u byte%s)",
5705 excess, plurality(excess, "", "s"));
5706 return FALSE; /* overflow error */
5709 return TRUE; /* OK, offset matches. */
5714 /* change_cipher_spec(20) dissection */
5716 ssl_dissect_change_cipher_spec(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5717 packet_info *pinfo, proto_tree *tree,
5718 guint32 offset, SslSession *session,
5719 gboolean is_from_server,
5720 const SslDecryptSession *ssl)
5724 * enum { change_cipher_spec(1), (255) } type;
5725 * } ChangeCipherSpec;
5728 proto_item_set_text(tree,
5729 "%s Record Layer: %s Protocol: Change Cipher Spec",
5730 val_to_str_const(session->version, ssl_version_short_names, "SSL"),
5731 val_to_str_const(SSL_ID_CHG_CIPHER_SPEC, ssl_31_content_type, "unknown"));
5732 ti = proto_tree_add_item(tree, hf->hf.change_cipher_spec, tvb, offset, 1, ENC_NA);
5734 /* Use heuristics to detect an abbreviated handshake, assume that missing
5735 * ServerHelloDone implies reusing previously negotiating keys. Then when
5736 * a Session ID or ticket is present, it must be a resumed session.
5737 * Normally this should be done at the Finished message, but that may be
5738 * encrypted so we do it here, at the last cleartext message. */
5739 if (is_from_server && ssl) {
5740 if (session->is_session_resumed) {
5741 const char *resumed = NULL;
5742 if (ssl->session_ticket.data_len) {
5743 resumed = "Session Ticket";
5744 } else if (ssl->session_id.data_len) {
5745 resumed = "Session ID";
5748 ssl_debug_printf("%s Session resumption using %s\n", G_STRFUNC, resumed);
5750 /* Can happen if the capture somehow starts in the middle */
5751 ssl_debug_printf("%s No Session resumption, missing packets?\n", G_STRFUNC);
5754 ssl_debug_printf("%s Not using Session resumption\n", G_STRFUNC);
5757 if (is_from_server && session->is_session_resumed)
5758 expert_add_info(pinfo, ti, &hf->ei.resumed);
5761 /** Begin of handshake(22) record dissections */
5762 /* dissect a list of hash algorithms, return the number of bytes dissected
5763 this is used for the signature algorithms extension and for the
5764 TLS1.2 certificate request. {{{ */
5766 ssl_dissect_hash_alg_list(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5767 packet_info* pinfo, guint32 offset, guint32 offset_end)
5769 /* https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1
5771 * HashAlgorithm hash;
5772 * SignatureAlgorithm signature;
5773 * } SignatureAndHashAlgorithm;
5774 * SignatureAndHashAlgorithm supported_signature_algorithms<2..2^16-2>;
5776 proto_tree *subtree, *alg_tree;
5778 guint sh_alg_length;
5779 guint32 next_offset;
5781 /* SignatureAndHashAlgorithm supported_signature_algorithms<2..2^16-2> */
5782 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &sh_alg_length,
5783 hf->hf.hs_sig_hash_alg_len, 2, G_MAXUINT16 - 1)) {
5787 next_offset = offset + sh_alg_length;
5789 ti = proto_tree_add_none_format(tree, hf->hf.hs_sig_hash_algs, tvb, offset, sh_alg_length,
5790 "Signature Hash Algorithms (%u algorithm%s)",
5791 sh_alg_length / 2, plurality(sh_alg_length / 2, "", "s"));
5792 subtree = proto_item_add_subtree(ti, hf->ett.hs_sig_hash_algs);
5794 while (offset + 2 <= next_offset) {
5795 ti = proto_tree_add_item(subtree, hf->hf.hs_sig_hash_alg,
5796 tvb, offset, 2, ENC_BIG_ENDIAN);
5797 alg_tree = proto_item_add_subtree(ti, hf->ett.hs_sig_hash_alg);
5799 proto_tree_add_item(alg_tree, hf->hf.hs_sig_hash_hash,
5800 tvb, offset, 1, ENC_BIG_ENDIAN);
5801 proto_tree_add_item(alg_tree, hf->hf.hs_sig_hash_sig,
5802 tvb, offset+1, 1, ENC_BIG_ENDIAN);
5807 if (!ssl_end_vector(hf, tvb, pinfo, subtree, offset, next_offset)) {
5808 offset = next_offset;
5814 /** TLS Extensions (in Client Hello and Server Hello). {{{ */
5816 ssl_dissect_hnd_hello_ext_sig_hash_algs(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5817 proto_tree *tree, packet_info* pinfo, guint32 offset, guint32 offset_end)
5819 return ssl_dissect_hash_alg_list(hf, tvb, tree, pinfo, offset, offset_end);
5823 ssl_dissect_hnd_hello_ext_alpn(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5824 packet_info *pinfo, proto_tree *tree,
5825 guint32 offset, guint32 offset_end,
5826 guint8 hnd_type, SslSession *session)
5829 /* https://tools.ietf.org/html/rfc7301#section-3.1
5830 * opaque ProtocolName<1..2^8-1>;
5832 * ProtocolName protocol_name_list<2..2^16-1>
5833 * } ProtocolNameList;
5835 proto_tree *alpn_tree;
5837 guint32 next_offset, alpn_length, name_length;
5838 guint8 *proto_name = NULL;
5839 guint32 proto_name_length = 0;
5841 /* ProtocolName protocol_name_list<2..2^16-1> */
5842 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &alpn_length,
5843 hf->hf.hs_ext_alpn_len, 2, G_MAXUINT16)) {
5847 next_offset = offset + alpn_length;
5849 ti = proto_tree_add_item(tree, hf->hf.hs_ext_alpn_list,
5850 tvb, offset, alpn_length, ENC_NA);
5851 alpn_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_alpn);
5853 /* Parse list (note missing check for end of vector, ssl_add_vector below
5854 * ensures that data is always available.) */
5855 while (offset < next_offset) {
5856 /* opaque ProtocolName<1..2^8-1> */
5857 if (!ssl_add_vector(hf, tvb, pinfo, alpn_tree, offset, next_offset, &name_length,
5858 hf->hf.hs_ext_alpn_str_len, 1, G_MAXUINT8)) {
5863 proto_tree_add_item(alpn_tree, hf->hf.hs_ext_alpn_str,
5864 tvb, offset, name_length, ENC_ASCII|ENC_NA);
5865 /* Remember first ALPN ProtocolName entry for server. */
5866 if (hnd_type == SSL_HND_SERVER_HELLO) {
5867 proto_name_length = name_length;
5868 proto_name = tvb_get_string_enc(wmem_packet_scope(), tvb, offset,
5869 proto_name_length, ENC_ASCII);
5871 offset += name_length;
5874 /* If ALPN is given in ServerHello, then ProtocolNameList MUST contain
5875 * exactly one "ProtocolName". */
5876 if (hnd_type == SSL_HND_SERVER_HELLO && proto_name) {
5877 /* '\0'-terminated string for prefix/full string comparison purposes. */
5878 for (size_t i = 0; i < G_N_ELEMENTS(ssl_alpn_protocols); i++) {
5879 const ssl_alpn_protocol_t *alpn_proto = &ssl_alpn_protocols[i];
5881 if ((alpn_proto->match_exact &&
5882 proto_name_length == strlen(alpn_proto->proto_name) &&
5883 !strcmp(proto_name, alpn_proto->proto_name)) ||
5884 (!alpn_proto->match_exact && g_str_has_prefix(proto_name, alpn_proto->proto_name))) {
5886 dissector_handle_t handle;
5887 /* ProtocolName match, so set the App data dissector handle.
5888 * This may override protocols given via the UAT dialog, but
5889 * since the ALPN hint is precise, do it anyway. */
5890 handle = ssl_find_appdata_dissector(alpn_proto->dissector_name);
5891 ssl_debug_printf("%s: changing handle %p to %p (%s)", G_STRFUNC,
5892 (void *)session->app_handle,
5893 (void *)handle, alpn_proto->dissector_name);
5894 /* if dissector is disabled, do not overwrite previous one */
5896 session->app_handle = handle;
5906 ssl_dissect_hnd_hello_ext_npn(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5907 packet_info *pinfo, proto_tree *tree,
5908 guint32 offset, guint32 offset_end)
5910 /* https://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-3
5911 * The "extension_data" field of a "next_protocol_negotiation" extension
5912 * in a "ServerHello" contains an optional list of protocols advertised
5913 * by the server. Protocols are named by opaque, non-empty byte strings
5914 * and the list of protocols is serialized as a concatenation of 8-bit,
5915 * length prefixed byte strings. Implementations MUST ensure that the
5916 * empty string is not included and that no byte strings are truncated.
5919 proto_tree *npn_tree;
5921 /* List is optional, do not add tree if there are no entries. */
5922 if (offset == offset_end) {
5926 npn_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset, hf->ett.hs_ext_npn, NULL, "Next Protocol Negotiation");
5928 while (offset < offset_end) {
5929 /* non-empty, 8-bit length prefixed strings means range 1..255 */
5930 if (!ssl_add_vector(hf, tvb, pinfo, npn_tree, offset, offset_end, &npn_length,
5931 hf->hf.hs_ext_npn_str_len, 1, G_MAXUINT8)) {
5936 proto_tree_add_item(npn_tree, hf->hf.hs_ext_npn_str,
5937 tvb, offset, npn_length, ENC_ASCII|ENC_NA);
5938 offset += npn_length;
5945 ssl_dissect_hnd_hello_ext_reneg_info(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5946 packet_info *pinfo, proto_tree *tree,
5947 guint32 offset, guint32 offset_end)
5949 /* https://tools.ietf.org/html/rfc5746#section-3.2
5951 * opaque renegotiated_connection<0..255>;
5952 * } RenegotiationInfo;
5955 proto_tree *reneg_info_tree;
5956 guint32 reneg_info_length;
5958 reneg_info_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset, hf->ett.hs_ext_reneg_info, NULL, "Renegotiation Info extension");
5960 /* opaque renegotiated_connection<0..255> */
5961 if (!ssl_add_vector(hf, tvb, pinfo, reneg_info_tree, offset, offset_end, &reneg_info_length,
5962 hf->hf.hs_ext_reneg_info_len, 0, 255)) {
5967 if (reneg_info_length > 0) {
5968 proto_tree_add_item(reneg_info_tree, hf->hf.hs_ext_reneg_info, tvb, offset, reneg_info_length, ENC_NA);
5969 offset += reneg_info_length;
5976 ssl_dissect_hnd_hello_ext_key_share_entry(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
5977 proto_tree *tree, guint32 offset, guint32 offset_end)
5979 /* https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.2.5
5982 * opaque key_exchange<1..2^16-1>;
5985 guint32 key_exchange_length, group;
5986 proto_tree *ks_tree;
5988 ks_tree = proto_tree_add_subtree(tree, tvb, offset, 4, hf->ett.hs_ext_key_share_ks, NULL, "Key Share Entry");
5990 proto_tree_add_item_ret_uint(ks_tree, hf->hf.hs_ext_key_share_group, tvb, offset, 2, ENC_BIG_ENDIAN, &group);
5992 proto_item_append_text(ks_tree, ": Group: %s", val_to_str(group, ssl_extension_curves, "Unknown (%u)"));
5994 /* opaque key_exchange<1..2^16-1> */
5995 if (!ssl_add_vector(hf, tvb, pinfo, ks_tree, offset, offset_end, &key_exchange_length,
5996 hf->hf.hs_ext_key_share_key_exchange_length, 1, G_MAXUINT16)) {
5997 return offset_end; /* Bad (possible truncated) length, skip to end of KeyShare extension. */
6000 proto_item_set_len(ks_tree, 2 + 2 + key_exchange_length);
6001 proto_item_append_text(ks_tree, ", Key Exchange length: %u", key_exchange_length);
6003 proto_tree_add_item(ks_tree, hf->hf.hs_ext_key_share_key_exchange, tvb, offset, key_exchange_length, ENC_NA);
6004 offset += key_exchange_length;
6010 ssl_dissect_hnd_hello_ext_key_share(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
6011 proto_tree *tree, guint32 offset, guint32 offset_end,
6014 proto_tree *key_share_tree;
6015 guint32 next_offset;
6016 guint32 client_shares_length;
6018 if (offset_end <= offset) { /* Check if ext_len == 0 and "overflow" (offset + ext_len) > guint32) */
6022 key_share_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset, hf->ett.hs_ext_key_share, NULL, "Key Share extension");
6025 case SSL_HND_CLIENT_HELLO:
6026 /* KeyShareEntry client_shares<0..2^16-1> */
6027 if (!ssl_add_vector(hf, tvb, pinfo, key_share_tree, offset, offset_end, &client_shares_length,
6028 hf->hf.hs_ext_key_share_client_length, 0, G_MAXUINT16)) {
6032 next_offset = offset + client_shares_length;
6033 while (offset + 4 <= next_offset) { /* (NamedGroup (2 bytes), key_exchange (1 byte for length, 1 byte minimum data) */
6034 offset = ssl_dissect_hnd_hello_ext_key_share_entry(hf, tvb, pinfo, key_share_tree, offset, next_offset);
6036 if (!ssl_end_vector(hf, tvb, pinfo, key_share_tree, offset, next_offset)) {
6040 case SSL_HND_SERVER_HELLO:
6041 offset = ssl_dissect_hnd_hello_ext_key_share_entry(hf, tvb, pinfo, key_share_tree, offset, offset_end);
6043 case SSL_HND_HELLO_RETRY_REQUEST:
6044 proto_tree_add_item(key_share_tree, hf->hf.hs_ext_key_share_selected_group, tvb, offset, 2, ENC_BIG_ENDIAN );
6047 default: /* no default */
6055 ssl_dissect_hnd_hello_ext_pre_shared_key(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
6056 proto_tree *tree, guint32 offset, guint32 offset_end,
6059 /* https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.2.6
6061 * opaque identity<0..2^16-1>;
6062 * uint32 obfuscated_ticket_age;
6064 * opaque PskBinderEntry<32..255>;
6066 * select (Handshake.msg_type) {
6067 * case client_hello:
6068 * PskIdentity identities<6..2^16-1>;
6069 * PskBinderEntry binders<33..2^16-1>;
6070 * case server_hello:
6071 * uint16 selected_identity;
6073 * } PreSharedKeyExtension;
6076 proto_tree *psk_tree;
6078 psk_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset, hf->ett.hs_ext_pre_shared_key, NULL, "Pre-Shared Key extension");
6081 case SSL_HND_CLIENT_HELLO: {
6082 guint32 identities_length, identities_end, binders_length;
6084 /* PskIdentity identities<6..2^16-1> */
6085 if (!ssl_add_vector(hf, tvb, pinfo, psk_tree, offset, offset_end, &identities_length,
6086 hf->hf.hs_ext_psk_identities_length, 6, G_MAXUINT16)) {
6090 identities_end = offset + identities_length;
6092 while (offset < identities_end) {
6093 guint32 identity_length;
6094 proto_tree *identity_tree;
6096 identity_tree = proto_tree_add_subtree(psk_tree, tvb, offset, 4, hf->ett.hs_ext_psk_identity, NULL, "PSK Identity (");
6098 /* opaque identity<0..2^16-1> */
6099 if (!ssl_add_vector(hf, tvb, pinfo, identity_tree, offset, identities_end, &identity_length,
6100 hf->hf.hs_ext_psk_identity_identity_length, 0, G_MAXUINT16)) {
6101 return identities_end;
6104 proto_item_append_text(identity_tree, "length: %u)", identity_length);
6106 proto_tree_add_item(identity_tree, hf->hf.hs_ext_psk_identity_identity, tvb, offset, identity_length, ENC_BIG_ENDIAN);
6107 offset += identity_length;
6109 proto_tree_add_item(identity_tree, hf->hf.hs_ext_psk_identity_obfuscated_ticket_age, tvb, offset, 4, ENC_BIG_ENDIAN);
6112 proto_item_set_len(identity_tree, 2 + identity_length + 4);
6114 if (!ssl_end_vector(hf, tvb, pinfo, psk_tree, offset, identities_end)) {
6115 offset = identities_end;
6118 /* PskBinderEntry binders<33..2^16-1> */
6119 if (!ssl_add_vector(hf, tvb, pinfo, psk_tree, offset, offset_end, &binders_length,
6120 hf->hf.hs_ext_psk_binders_length, 33, G_MAXUINT16)) {
6125 proto_tree_add_item(psk_tree, hf->hf.hs_ext_psk_binders, tvb, offset, binders_length, ENC_NA);
6126 offset += binders_length;
6129 case SSL_HND_SERVER_HELLO: {
6130 proto_tree_add_item(psk_tree, hf->hf.hs_ext_psk_identity_selected, tvb, offset, 2, ENC_BIG_ENDIAN);
6142 ssl_dissect_hnd_hello_ext_supported_versions(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
6143 proto_tree *tree, guint32 offset, guint32 offset_end)
6146 /* https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.2.1
6148 * ProtocolVersion versions<2..254>;
6149 * } SupportedVersions;
6151 guint32 versions_length, next_offset;
6152 /* ProtocolVersion versions<2..254> */
6153 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &versions_length,
6154 hf->hf.hs_ext_supported_versions_len, 2, 254)) {
6158 next_offset = offset + versions_length;
6160 while (offset + 2 <= next_offset) {
6161 proto_tree_add_item(tree, hf->hf.hs_ext_supported_versions, tvb, offset, 2, ENC_BIG_ENDIAN);
6164 if (!ssl_end_vector(hf, tvb, pinfo, tree, offset, next_offset)) {
6165 offset = next_offset;
6172 ssl_dissect_hnd_hello_ext_cookie(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6173 packet_info *pinfo, proto_tree *tree,
6174 guint32 offset, guint32 offset_end)
6176 /* https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.2.2
6178 * opaque cookie<1..2^16-1>;
6181 guint32 cookie_length;
6182 /* opaque cookie<1..2^16-1> */
6183 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &cookie_length,
6184 hf->hf.hs_ext_cookie_len, 1, G_MAXUINT16)) {
6189 proto_tree_add_item(tree, hf->hf.hs_ext_cookie, tvb, offset, cookie_length, ENC_NA);
6190 offset += cookie_length;
6196 ssl_dissect_hnd_hello_ext_psk_key_exchange_modes(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
6197 proto_tree *tree, guint32 offset, guint32 offset_end)
6199 /* https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.2.7
6200 * enum { psk_ke(0), psk_dhe_ke(1), (255) } PskKeyExchangeMode;
6203 * PskKeyExchangeMode ke_modes<1..255>;
6204 * } PskKeyExchangeModes;
6206 guint32 ke_modes_length, next_offset;
6208 /* PskKeyExchangeMode ke_modes<1..255> */
6209 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &ke_modes_length,
6210 hf->hf.hs_ext_psk_ke_modes_len, 1, 255)) {
6214 next_offset = offset + ke_modes_length;
6216 while (offset < next_offset) {
6217 proto_tree_add_item(tree, hf->hf.hs_ext_psk_ke_mode, tvb, offset, 1, ENC_NA);
6225 ssl_dissect_hnd_hello_ext_server_name(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6226 packet_info *pinfo, proto_tree *tree,
6227 guint32 offset, guint32 offset_end)
6229 /* https://tools.ietf.org/html/rfc6066#section-3
6232 * NameType name_type;
6233 * select (name_type) {
6234 * case host_name: HostName;
6239 * host_name(0), (255)
6242 * opaque HostName<1..2^16-1>;
6245 * ServerName server_name_list<1..2^16-1>
6248 proto_tree *server_name_tree;
6249 guint32 list_length, server_name_length, next_offset;
6251 /* The server SHALL include "server_name" extension with empty data. */
6252 if (offset == offset_end) {
6256 server_name_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset, hf->ett.hs_ext_server_name, NULL, "Server Name Indication extension");
6258 /* ServerName server_name_list<1..2^16-1> */
6259 if (!ssl_add_vector(hf, tvb, pinfo, server_name_tree, offset, offset_end, &list_length,
6260 hf->hf.hs_ext_server_name_list_len, 1, G_MAXUINT16)) {
6264 next_offset = offset + list_length;
6266 while (offset < next_offset) {
6267 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name_type,
6268 tvb, offset, 1, ENC_NA);
6271 /* opaque HostName<1..2^16-1> */
6272 if (!ssl_add_vector(hf, tvb, pinfo, server_name_tree, offset, next_offset, &server_name_length,
6273 hf->hf.hs_ext_server_name_len, 1, G_MAXUINT16)) {
6278 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name,
6279 tvb, offset, server_name_length, ENC_ASCII|ENC_NA);
6280 offset += server_name_length;
6286 ssl_dissect_hnd_hello_ext_session_ticket(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6287 proto_tree *tree, guint32 offset, guint32 offset_end, guint8 hnd_type, SslDecryptSession *ssl)
6289 guint ext_len = offset_end - offset;
6290 if (hnd_type == SSL_HND_CLIENT_HELLO && ssl && ext_len != 0) {
6291 tvb_ensure_bytes_exist(tvb, offset, ext_len);
6292 /* Save the Session Ticket such that it can be used as identifier for
6293 * restoring a previous Master Secret (in ChangeCipherSpec) */
6294 ssl->session_ticket.data = (guchar*)wmem_realloc(wmem_file_scope(),
6295 ssl->session_ticket.data, ext_len);
6296 ssl->session_ticket.data_len = ext_len;
6297 tvb_memcpy(tvb,ssl->session_ticket.data, offset, ext_len);
6299 proto_tree_add_bytes_format(tree, hf->hf.hs_ext_data,
6300 tvb, offset, ext_len, NULL,
6302 ext_len, plurality(ext_len, "", "s"));
6303 return offset + ext_len;
6307 ssl_dissect_hnd_hello_ext_cert_type(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6308 proto_tree *tree, guint32 offset, guint32 offset_end,
6309 guint8 hnd_type, guint16 ext_type, SslSession *session)
6311 guint8 cert_list_length;
6313 proto_tree *cert_list_tree;
6317 case SSL_HND_CLIENT_HELLO:
6318 cert_list_length = tvb_get_guint8(tvb, offset);
6319 proto_tree_add_item(tree, hf->hf.hs_ext_cert_types_len,
6320 tvb, offset, 1, ENC_BIG_ENDIAN);
6322 if (offset_end - offset != (guint32)cert_list_length)
6325 ti = proto_tree_add_item(tree, hf->hf.hs_ext_cert_types, tvb, offset,
6326 cert_list_length, cert_list_length);
6327 proto_item_append_text(ti, " (%d)", cert_list_length);
6329 /* make this a subtree */
6330 cert_list_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_cert_types);
6332 /* loop over all point formats */
6333 while (cert_list_length > 0)
6335 proto_tree_add_item(cert_list_tree, hf->hf.hs_ext_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN);
6340 case SSL_HND_SERVER_HELLO:
6341 cert_type = tvb_get_guint8(tvb, offset);
6342 proto_tree_add_item(tree, hf->hf.hs_ext_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN);
6344 if (ext_type == SSL_HND_HELLO_EXT_CERT_TYPE || ext_type == SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE) {
6345 session->client_cert_type = cert_type;
6347 if (ext_type == SSL_HND_HELLO_EXT_CERT_TYPE || ext_type == SSL_HND_HELLO_EXT_SERVER_CERT_TYPE) {
6348 session->server_cert_type = cert_type;
6351 default: /* no default */
6359 ssl_dissect_hnd_hello_common(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6360 proto_tree *tree, guint32 offset,
6361 SslSession *session, SslDecryptSession *ssl,
6362 gboolean from_server)
6364 nstime_t gmt_unix_time;
6365 guint8 sessid_length;
6366 proto_tree *rnd_tree;
6369 /* Prepare for renegotiation by resetting the state. */
6370 ssl_reset_session(session, ssl, !from_server);
6375 rnd = &ssl->server_random;
6377 rnd = &ssl->client_random;
6379 /* save provided random for later keyring generation */
6380 tvb_memcpy(tvb, rnd->data, offset, 32);
6383 ssl->state |= SSL_SERVER_RANDOM;
6385 ssl->state |= SSL_CLIENT_RANDOM;
6386 ssl_debug_printf("%s found %s RANDOM -> state 0x%02X\n", G_STRFUNC,
6387 from_server ? "SERVER" : "CLIENT", ssl->state);
6390 ti_rnd = proto_tree_add_item(tree, hf->hf.hs_random, tvb, offset, 32, ENC_NA);
6392 if (session->version != TLSV1DOT3_VERSION) { /* No time on first bytes random with TLS 1.3 */
6394 rnd_tree = proto_item_add_subtree(ti_rnd, hf->ett.hs_random);
6396 gmt_unix_time.secs = tvb_get_ntohl(tvb, offset);
6397 gmt_unix_time.nsecs = 0;
6398 proto_tree_add_time(rnd_tree, hf->hf.hs_random_time,
6399 tvb, offset, 4, &gmt_unix_time);
6402 /* show the random bytes */
6403 proto_tree_add_item(rnd_tree, hf->hf.hs_random_bytes,
6404 tvb, offset, 28, ENC_NA);
6410 if (from_server == 0 || session->version != TLSV1DOT3_VERSION) { /* No Session ID with TLS 1.3 on Server Hello */
6411 /* show the session id (length followed by actual Session ID) */
6412 sessid_length = tvb_get_guint8(tvb, offset);
6413 proto_tree_add_item(tree, hf->hf.hs_session_id_len,
6414 tvb, offset, 1, ENC_BIG_ENDIAN);
6418 /* save the authorative SID for later use in ChangeCipherSpec.
6419 * (D)TLS restricts the SID to 32 chars, it does not make sense to
6420 * save more, so ignore larger ones. */
6421 if (from_server && sessid_length <= 32) {
6422 tvb_memcpy(tvb, ssl->session_id.data, offset, sessid_length);
6423 ssl->session_id.data_len = sessid_length;
6426 if (sessid_length > 0) {
6427 proto_tree_add_item(tree, hf->hf.hs_session_id,
6428 tvb, offset, sessid_length, ENC_NA);
6429 offset += sessid_length;
6437 ssl_dissect_hnd_hello_ext_status_request(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
6438 guint32 offset, gboolean has_length)
6440 guint cert_status_type;
6442 cert_status_type = tvb_get_guint8(tvb, offset);
6443 proto_tree_add_item(tree, hf->hf.hs_ext_cert_status_type,
6444 tvb, offset, 1, ENC_NA);
6448 proto_tree_add_item(tree, hf->hf.hs_ext_cert_status_request_len,
6449 tvb, offset, 2, ENC_BIG_ENDIAN);
6453 switch (cert_status_type) {
6454 case SSL_HND_CERT_STATUS_TYPE_OCSP:
6455 case SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI:
6457 guint16 responder_id_list_len;
6458 guint16 request_extensions_len;
6459 proto_item *responder_id;
6460 proto_item *request_extensions;
6462 responder_id_list_len = tvb_get_ntohs(tvb, offset);
6464 proto_tree_add_item(tree,
6465 hf->hf.hs_ext_cert_status_responder_id_list_len,
6466 tvb, offset, 2, ENC_BIG_ENDIAN);
6468 if (responder_id_list_len != 0) {
6469 expert_add_info_format(NULL, responder_id,
6470 &hf->ei.hs_ext_cert_status_undecoded,
6471 "Responder ID list is not implemented, contact Wireshark"
6472 " developers if you want this to be supported");
6473 /* Non-empty responder ID list would mess with extensions. */
6477 request_extensions_len = tvb_get_ntohs(tvb, offset);
6478 request_extensions =
6479 proto_tree_add_item(tree,
6480 hf->hf.hs_ext_cert_status_request_extensions_len, tvb, offset,
6483 if (request_extensions_len != 0)
6484 expert_add_info_format(NULL, request_extensions,
6485 &hf->ei.hs_ext_cert_status_undecoded,
6486 "Request Extensions are not implemented, contact"
6487 " Wireshark developers if you want this to be supported");
6496 ssl_dissect_hnd_hello_ext_status_request_v2(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
6501 list_len = tvb_get_ntohs(tvb, offset);
6504 while (list_len > 0) {
6505 guint32 prev_offset = offset;
6506 offset = ssl_dissect_hnd_hello_ext_status_request(hf, tvb, tree, offset, TRUE);
6507 list_len -= (offset - prev_offset);
6514 ssl_dissect_hnd_hello_ext_supported_groups(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
6515 proto_tree *tree, guint32 offset, guint32 offset_end)
6517 /* https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.2.4
6518 * enum { ..., (0xFFFF) } NamedGroup;
6520 * NamedGroup named_group_list<2..2^16-1>
6523 * NOTE: "NamedCurve" (RFC 4492) is renamed to "NamedGroup" (RFC 7919) and
6524 * the extension itself from "elliptic_curves" to "supported_groups".
6526 guint32 groups_length, next_offset;
6527 proto_tree *groups_tree;
6530 /* NamedGroup named_group_list<2..2^16-1> */
6531 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &groups_length,
6532 hf->hf.hs_ext_supported_groups_len, 2, G_MAXUINT16)) {
6536 next_offset = offset + groups_length;
6538 ti = proto_tree_add_none_format(tree,
6539 hf->hf.hs_ext_supported_groups,
6540 tvb, offset, groups_length,
6541 "Supported Groups (%d group%s)",
6543 plurality(groups_length/2, "", "s"));
6545 /* make this a subtree */
6546 groups_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_groups);
6548 /* loop over all groups */
6549 while (offset + 2 <= offset_end) {
6550 proto_tree_add_item(groups_tree, hf->hf.hs_ext_supported_group, tvb, offset, 2, ENC_BIG_ENDIAN);
6553 if (!ssl_end_vector(hf, tvb, pinfo, groups_tree, offset, next_offset)) {
6554 offset = next_offset;
6561 ssl_dissect_hnd_hello_ext_ec_point_formats(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6562 proto_tree *tree, guint32 offset)
6565 proto_tree *ecpf_tree;
6568 ecpf_length = tvb_get_guint8(tvb, offset);
6569 proto_tree_add_item(tree, hf->hf.hs_ext_ec_point_formats_len,
6570 tvb, offset, 1, ENC_BIG_ENDIAN);
6573 ti = proto_tree_add_none_format(tree,
6574 hf->hf.hs_ext_ec_point_formats,
6575 tvb, offset, ecpf_length,
6576 "Elliptic curves point formats (%d)",
6579 /* make this a subtree */
6580 ecpf_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_curves_point_formats);
6582 /* loop over all point formats */
6583 while (ecpf_length > 0)
6585 proto_tree_add_item(ecpf_tree, hf->hf.hs_ext_ec_point_format, tvb, offset, 1, ENC_BIG_ENDIAN);
6592 /** TLS Extensions (in Client Hello and Server Hello). }}} */
6594 /* Whether the Content and Handshake Types are valid; handle Protocol Version. {{{ */
6596 ssl_is_valid_content_type(guint8 type)
6598 switch ((ContentType) type) {
6599 case SSL_ID_CHG_CIPHER_SPEC:
6601 case SSL_ID_HANDSHAKE:
6602 case SSL_ID_APP_DATA:
6603 case SSL_ID_HEARTBEAT:
6610 ssl_is_valid_handshake_type(guint8 hs_type, gboolean is_dtls)
6612 switch ((HandshakeType) hs_type) {
6613 case SSL_HND_HELLO_VERIFY_REQUEST:
6614 /* hello_verify_request is DTLS-only */
6617 case SSL_HND_HELLO_REQUEST:
6618 case SSL_HND_CLIENT_HELLO:
6619 case SSL_HND_SERVER_HELLO:
6620 case SSL_HND_NEWSESSION_TICKET:
6621 case SSL_HND_HELLO_RETRY_REQUEST:
6622 case SSL_HND_ENCRYPTED_EXTENSIONS:
6623 case SSL_HND_CERTIFICATE:
6624 case SSL_HND_SERVER_KEY_EXCHG:
6625 case SSL_HND_CERT_REQUEST:
6626 case SSL_HND_SVR_HELLO_DONE:
6627 case SSL_HND_CERT_VERIFY:
6628 case SSL_HND_CLIENT_KEY_EXCHG:
6629 case SSL_HND_FINISHED:
6630 case SSL_HND_CERT_URL:
6631 case SSL_HND_CERT_STATUS:
6632 case SSL_HND_SUPPLEMENTAL_DATA:
6633 case SSL_HND_ENCRYPTED_EXTS:
6640 ssl_is_authoritative_version_message(guint8 content_type, guint8 handshake_type,
6643 /* Consider all valid Handshake messages (except for Client Hello) and
6644 * all other valid record types (other than Handshake) */
6645 return (content_type == SSL_ID_HANDSHAKE &&
6646 ssl_is_valid_handshake_type(handshake_type, is_dtls) &&
6647 handshake_type != SSL_HND_CLIENT_HELLO) ||
6648 (content_type != SSL_ID_HANDSHAKE &&
6649 ssl_is_valid_content_type(content_type));
6653 ssl_try_set_version(SslSession *session, SslDecryptSession *ssl,
6654 guint8 content_type, guint8 handshake_type,
6655 gboolean is_dtls, guint16 version)
6657 if (!ssl_is_authoritative_version_message(content_type, handshake_type,
6664 case TLSV1DOT1_VERSION:
6665 case TLSV1DOT2_VERSION:
6666 case TLSV1DOT3_VERSION:
6671 case DTLSV1DOT0_VERSION:
6672 case DTLSV1DOT0_OPENSSL_VERSION:
6673 case DTLSV1DOT2_VERSION:
6678 default: /* invalid version number */
6682 session->version = version;
6684 ssl->state |= SSL_VERSION;
6685 ssl_debug_printf("%s found version 0x%04X -> state 0x%02X\n", G_STRFUNC, version, ssl->state);
6690 ssl_set_cipher(SslDecryptSession *ssl, guint16 cipher)
6692 /* store selected cipher suite for decryption */
6693 ssl->session.cipher = cipher;
6695 if (!(ssl->cipher_suite = ssl_find_cipher(cipher))) {
6696 ssl->state &= ~SSL_CIPHER;
6697 ssl_debug_printf("%s can't find cipher suite 0x%04X\n", G_STRFUNC, cipher);
6699 /* Cipher found, save this for the delayed decoder init */
6700 ssl->state |= SSL_CIPHER;
6701 ssl_debug_printf("%s found CIPHER 0x%04X %s -> state 0x%02X\n", G_STRFUNC, cipher,
6702 val_to_str_ext_const(cipher, &ssl_31_ciphersuite_ext, "unknown"),
6709 /* Client Hello and Server Hello dissections. {{{ */
6711 ssl_dissect_hnd_hello_ext(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
6712 packet_info* pinfo, guint32 offset, guint32 offset_end, guint8 hnd_type,
6713 SslSession *session, SslDecryptSession *ssl,
6716 ssl_dissect_hnd_cli_hello(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6717 packet_info *pinfo, proto_tree *tree, guint32 offset,
6718 guint32 offset_end, SslSession *session,
6719 SslDecryptSession *ssl, dtls_hfs_t *dtls_hfs)
6722 * ProtocolVersion client_version;
6724 * SessionID session_id;
6725 * opaque cookie<0..32>; //new field for DTLS
6726 * CipherSuite cipher_suites<2..2^16-1>;
6727 * CompressionMethod compression_methods<1..2^8-1>;
6728 * Extension client_hello_extension_list<0..2^16-1>;
6732 proto_tree *cs_tree;
6733 guint32 cipher_suite_length;
6734 guint32 compression_methods_length;
6735 guint8 compression_method;
6736 guint32 next_offset;
6738 /* show the client version */
6739 proto_tree_add_item(tree, hf->hf.hs_client_version, tvb,
6740 offset, 2, ENC_BIG_ENDIAN);
6743 /* dissect fields that are also present in ClientHello */
6744 offset = ssl_dissect_hnd_hello_common(hf, tvb, tree, offset, session, ssl, FALSE);
6746 /* fields specific for DTLS (cookie_len, cookie) */
6747 if (dtls_hfs != NULL) {
6748 guint32 cookie_length;
6749 /* opaque cookie<0..32> (for DTLS only) */
6750 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &cookie_length,
6751 dtls_hfs->hf_dtls_handshake_cookie_len, 0, 32)) {
6755 if (cookie_length > 0) {
6756 proto_tree_add_item(tree, dtls_hfs->hf_dtls_handshake_cookie,
6757 tvb, offset, cookie_length, ENC_NA);
6758 offset += cookie_length;
6762 /* CipherSuite cipher_suites<2..2^16-1> */
6763 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &cipher_suite_length,
6764 hf->hf.hs_cipher_suites_len, 2, G_MAXUINT16)) {
6768 next_offset = offset + cipher_suite_length;
6769 if (ssl && cipher_suite_length == 2) {
6771 * If there is only a single cipher, assume that this will be used
6772 * (needed for 0-RTT decryption support in TLS 1.3).
6774 ssl_set_cipher(ssl, tvb_get_ntohs(tvb, offset));
6776 ti = proto_tree_add_none_format(tree,
6777 hf->hf.hs_cipher_suites,
6778 tvb, offset, cipher_suite_length,
6779 "Cipher Suites (%d suite%s)",
6780 cipher_suite_length / 2,
6781 plurality(cipher_suite_length/2, "", "s"));
6782 cs_tree = proto_item_add_subtree(ti, hf->ett.cipher_suites);
6783 while (offset + 2 <= next_offset) {
6784 proto_tree_add_item(cs_tree, hf->hf.hs_cipher_suite, tvb, offset, 2, ENC_BIG_ENDIAN);
6787 if (!ssl_end_vector(hf, tvb, pinfo, cs_tree, offset, next_offset)) {
6788 offset = next_offset;
6791 /* CompressionMethod compression_methods<1..2^8-1> */
6792 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &compression_methods_length,
6793 hf->hf.hs_comp_methods_len, 1, G_MAXUINT8)) {
6797 next_offset = offset + compression_methods_length;
6798 ti = proto_tree_add_none_format(tree,
6799 hf->hf.hs_comp_methods,
6800 tvb, offset, compression_methods_length,
6801 "Compression Methods (%u method%s)",
6802 compression_methods_length,
6803 plurality(compression_methods_length,
6805 cs_tree = proto_item_add_subtree(ti, hf->ett.comp_methods);
6806 while (offset < next_offset) {
6807 compression_method = tvb_get_guint8(tvb, offset);
6808 /* TODO: make reserved/private comp meth. fields selectable */
6809 if (compression_method < 64)
6810 proto_tree_add_uint(cs_tree, hf->hf.hs_comp_method,
6811 tvb, offset, 1, compression_method);
6812 else if (compression_method > 63 && compression_method < 193)
6813 proto_tree_add_uint_format_value(cs_tree, hf->hf.hs_comp_method, tvb, offset, 1,
6814 compression_method, "Reserved - to be assigned by IANA (%u)",
6815 compression_method);
6817 proto_tree_add_uint_format_value(cs_tree, hf->hf.hs_comp_method, tvb, offset, 1,
6818 compression_method, "Private use range (%u)",
6819 compression_method);
6823 /* SSL v3.0 has no extensions, so length field can indeed be missing. */
6824 if (offset < offset_end) {
6825 ssl_dissect_hnd_hello_ext(hf, tvb, tree, pinfo, offset,
6826 offset_end, SSL_HND_CLIENT_HELLO,
6827 session, ssl, dtls_hfs != NULL);
6832 ssl_dissect_hnd_srv_hello(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6833 packet_info* pinfo, proto_tree *tree, guint32 offset, guint32 offset_end,
6834 SslSession *session, SslDecryptSession *ssl,
6838 * ProtocolVersion server_version;
6840 * SessionID session_id; // TLS 1.2 and before
6841 * CipherSuite cipher_suite;
6842 * CompressionMethod compression_method; // TLS 1.2 and before
6843 * Extension server_hello_extension_list<0..2^16-1>;
6846 guint16 server_version;
6848 /* This version is always better than the guess at the Record Layer */
6849 server_version = tvb_get_ntohs(tvb, offset);
6850 if((server_version & 0xFF00) == 0x7f00) { /* if server_version start with 0x7f, it is (and force) TLS 1.3 */
6851 server_version = TLSV1DOT3_VERSION;
6853 ssl_try_set_version(session, ssl, SSL_ID_HANDSHAKE, SSL_HND_SERVER_HELLO,
6854 is_dtls, server_version);
6855 col_set_str(pinfo->cinfo, COL_PROTOCOL,
6856 val_to_str_const(server_version, ssl_version_short_names, "SSL"));
6858 /* Initially assume that the session is resumed. If this is not the case, a
6859 * ServerHelloDone will be observed before the ChangeCipherSpec message
6860 * which will reset this flag. */
6861 session->is_session_resumed = TRUE;
6863 /* show the server version */
6864 proto_tree_add_item(tree, hf->hf.hs_server_version, tvb,
6865 offset, 2, ENC_BIG_ENDIAN);
6868 /* dissect fields that are also present in ClientHello */
6869 offset = ssl_dissect_hnd_hello_common(hf, tvb, tree, offset, session, ssl, TRUE);
6872 /* store selected cipher suite for decryption */
6873 ssl_set_cipher(ssl, tvb_get_ntohs(tvb, offset));
6876 /* now the server-selected cipher suite */
6877 proto_tree_add_item(tree, hf->hf.hs_cipher_suite,
6878 tvb, offset, 2, ENC_BIG_ENDIAN);
6881 if (session->version != TLSV1DOT3_VERSION) { /* No compression with TLS 1.3 */
6883 /* store selected compression method for decryption */
6884 ssl->session.compression = tvb_get_guint8(tvb, offset);
6886 /* and the server-selected compression method */
6887 proto_tree_add_item(tree, hf->hf.hs_comp_method,
6888 tvb, offset, 1, ENC_BIG_ENDIAN);
6892 /* SSL v3.0 has no extensions, so length field can indeed be missing. */
6893 if (offset < offset_end) {
6894 ssl_dissect_hnd_hello_ext(hf, tvb, tree, pinfo, offset,
6895 offset_end, SSL_HND_SERVER_HELLO,
6896 session, ssl, is_dtls);
6899 /* Client Hello and Server Hello dissections. }}} */
6901 /* New Session Ticket dissection. {{{ */
6903 ssl_dissect_hnd_new_ses_ticket(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
6904 proto_tree *tree, guint32 offset, guint32 offset_end,
6905 const SslSession *session, SslDecryptSession *ssl _U_,
6906 GHashTable *session_hash _U_)
6908 /* https://tools.ietf.org/html/rfc5077#section-3.3 (TLS >= 1.0):
6910 * uint32 ticket_lifetime_hint;
6911 * opaque ticket<0..2^16-1>;
6912 * } NewSessionTicket;
6914 * https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.5.1
6916 * uint32 ticket_lifetime;
6917 * uint32 ticket_age_add;
6918 * opaque ticket<1..2^16-1>;
6919 * Extension extensions<0..2^16-2>;
6920 * } NewSessionTicket;
6922 proto_tree *subtree;
6924 gboolean is_tls13 = session->version == TLSV1DOT3_VERSION;
6926 subtree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset,
6927 hf->ett.session_ticket, NULL,
6928 "TLS Session Ticket");
6930 /* ticket lifetime hint */
6931 proto_tree_add_item(subtree, hf->hf.hs_session_ticket_lifetime_hint,
6932 tvb, offset, 4, ENC_BIG_ENDIAN);
6936 /* for TLS 1.3: ticket_age_add */
6937 proto_tree_add_item(subtree, hf->hf.hs_session_ticket_age_add,
6938 tvb, offset, 4, ENC_BIG_ENDIAN);
6942 /* opaque ticket<0..2^16-1> (with TLS 1.3 the minimum is 1) */
6943 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, offset_end, &ticket_len,
6944 hf->hf.hs_session_ticket_len, is_tls13 ? 1 : 0, G_MAXUINT16)) {
6949 /* Content depends on implementation, so just show data! */
6950 proto_tree_add_item(subtree, hf->hf.hs_session_ticket,
6951 tvb, offset, ticket_len, ENC_NA);
6952 /* save the session ticket to cache for ssl_finalize_decryption */
6953 #ifdef HAVE_LIBGCRYPT
6954 if (ssl && !is_tls13) {
6955 tvb_ensure_bytes_exist(tvb, offset, ticket_len);
6956 ssl->session_ticket.data = (guchar*)wmem_realloc(wmem_file_scope(),
6957 ssl->session_ticket.data, ticket_len);
6958 ssl->session_ticket.data_len = ticket_len;
6959 tvb_memcpy(tvb, ssl->session_ticket.data, offset, ticket_len);
6960 /* NewSessionTicket is received after the first (client)
6961 * ChangeCipherSpec, and before the second (server) ChangeCipherSpec.
6962 * Since the second CCS has already the session key available it will
6963 * just return. To ensure that the session ticket is mapped to a
6964 * master key (from the first CCS), save the ticket here too. */
6965 ssl_save_master_key("Session Ticket", session_hash,
6966 &ssl->session_ticket, &ssl->master_secret);
6967 ssl->state |= SSL_NEW_SESSION_TICKET;
6970 offset += ticket_len;
6975 /* Extension extensions<0..2^16-2> */
6976 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, offset_end, &exts_len,
6977 hf->hf.hs_exts_len, 0, G_MAXUINT16)) {
6980 /* TODO handle ticket extensions (only early_data at the moment) */
6985 ssl_dissect_hnd_hello_retry_request(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6986 packet_info* pinfo, proto_tree *tree, guint32 offset, guint32 offset_end,
6987 SslSession *session, SslDecryptSession *ssl,
6990 /* https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.1.4
6992 * ProtocolVersion server_version;
6993 * Extension extensions<2..2^16-1>;
6994 * } HelloRetryRequest;
6996 proto_tree_add_item(tree, hf->hf.hs_server_version, tvb,
6997 offset, 2, ENC_BIG_ENDIAN);
7000 /* remaining data are extensions */
7001 ssl_dissect_hnd_hello_ext(hf, tvb, tree, pinfo, offset,
7002 offset_end, SSL_HND_HELLO_RETRY_REQUEST,
7003 session, ssl, is_dtls);
7007 ssl_dissect_hnd_encrypted_extensions(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7008 packet_info* pinfo, proto_tree *tree, guint32 offset, guint32 length,
7009 SslSession *session, SslDecryptSession *ssl,
7013 * Extension extensions<0..2^16-1>;
7014 * } EncryptedExtensions;
7016 ssl_dissect_hnd_hello_ext(hf, tvb, tree, pinfo, offset,
7017 offset + length, SSL_HND_ENCRYPTED_EXTENSIONS,
7018 session, ssl, is_dtls);
7021 /* Certificate and Certificate Request dissections. {{{ */
7023 ssl_dissect_hnd_cert(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
7024 guint32 offset, packet_info *pinfo,
7025 const SslSession *session, SslDecryptSession *ssl _U_,
7026 GHashTable *key_hash _U_, gint is_from_server)
7028 /* opaque ASN.1Cert<1..2^24-1>;
7031 * select(certificate_type) {
7033 * // certificate type defined in RFC 7250
7034 * case RawPublicKey:
7035 * opaque ASN.1_subjectPublicKeyInfo<1..2^24-1>;
7037 * // X.509 certificate defined in RFC 5246
7039 * ASN.1Cert certificate_list<0..2^24-1>;
7043 * draft-ietf-tls-tls13-18:
7044 * opaque ASN1Cert<1..2^24-1>;
7046 * ASN1Cert cert_data;
7047 * Extension extensions<0..2^16-1>;
7048 * } CertificateEntry;
7050 * opaque certificate_request_context<0..2^8-1>;
7051 * CertificateEntry certificate_list<0..2^24-1>;
7054 enum { CERT_X509, CERT_RPK } cert_type;
7055 asn1_ctx_t asn1_ctx;
7056 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
7057 gnutls_datum_t subjectPublicKeyInfo = { NULL, 0 };
7060 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
7062 if ((is_from_server && session->server_cert_type == SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY) ||
7063 (!is_from_server && session->client_cert_type == SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY)) {
7064 cert_type = CERT_RPK;
7066 cert_type = CERT_X509;
7069 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
7070 /* Ask the pkcs1 dissector to return the public key details */
7072 asn1_ctx.private_data = &subjectPublicKeyInfo;
7075 switch (cert_type) {
7078 proto_tree_add_item(tree, hf->hf.hs_certificate_len,
7079 tvb, offset, 3, ENC_BIG_ENDIAN);
7082 dissect_x509af_SubjectPublicKeyInfo(FALSE, tvb, offset, &asn1_ctx, tree, hf->hf.hs_certificate);
7088 guint32 certificate_list_length;
7090 proto_tree *subtree;
7092 /* TLS 1.3: opaque certificate_request_context<0..2^8-1> */
7093 if (session->version == TLSV1DOT3_VERSION) {
7094 guint32 context_length;
7095 proto_tree_add_item_ret_uint(tree, hf->hf.hs_certificate_request_context_length,
7096 tvb, offset, 1, ENC_NA, &context_length);
7098 if (context_length > 0) {
7099 proto_tree_add_item(tree, hf->hf.hs_certificate_request_context,
7100 tvb, offset, context_length, ENC_NA);
7101 offset += context_length;
7105 proto_tree_add_item_ret_uint(tree, hf->hf.hs_certificates_len,
7106 tvb, offset, 3, ENC_BIG_ENDIAN, &certificate_list_length);
7107 offset += 3; /* 24-bit length value */
7109 if (certificate_list_length > 0) {
7110 ti = proto_tree_add_none_format(tree,
7111 hf->hf.hs_certificates,
7112 tvb, offset, certificate_list_length,
7113 "Certificates (%u bytes)",
7114 certificate_list_length);
7116 /* make it a subtree */
7117 subtree = proto_item_add_subtree(ti, hf->ett.certificates);
7119 /* iterate through each certificate */
7120 while (certificate_list_length > 0) {
7121 /* get the length of the current certificate */
7122 guint32 cert_length;
7123 proto_tree_add_item_ret_uint(subtree, hf->hf.hs_certificate_len,
7124 tvb, offset, 3, ENC_BIG_ENDIAN, &cert_length);
7126 certificate_list_length -= 3 + cert_length;
7128 dissect_x509af_Certificate(FALSE, tvb, offset, &asn1_ctx, subtree, hf->hf.hs_certificate);
7129 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
7130 /* Only attempt to get the RSA modulus for the first cert. */
7131 asn1_ctx.private_data = NULL;
7134 offset += cert_length;
7136 /* TLS 1.3: Extension extensions<0..2^16-1> */
7137 if (session->version == TLSV1DOT3_VERSION) {
7138 guint32 extensions_length;
7139 proto_tree_add_item_ret_uint(subtree, hf->hf.hs_exts_len,
7140 tvb, offset, 2, ENC_BIG_ENDIAN, &extensions_length);
7143 // XXX dissect OCSP and SCT extensions
7144 // https://tools.ietf.org/html/draft-ietf-tls-tls13-18#section-4.4.1.1
7145 offset += extensions_length;
7146 certificate_list_length -= 2 + extensions_length;
7154 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
7155 if (is_from_server && ssl)
7156 ssl_find_private_key_by_pubkey(ssl, key_hash, &subjectPublicKeyInfo);
7161 ssl_dissect_hnd_cert_req(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
7162 proto_tree *tree, guint32 offset, guint32 offset_end,
7163 const SslSession *session)
7165 /* From SSL 3.0 and up (note that since TLS 1.1 certificate_authorities can be empty):
7167 * rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
7169 * } ClientCertificateType;
7171 * opaque DistinguishedName<1..2^16-1>;
7174 * ClientCertificateType certificate_types<1..2^8-1>;
7175 * DistinguishedName certificate_authorities<3..2^16-1>;
7176 * } CertificateRequest;
7179 * As per TLSv1.2 (RFC 5246) the format has changed to:
7182 * rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
7183 * rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
7184 * fortezza_dms_RESERVED(20), (255)
7185 * } ClientCertificateType;
7188 * none(0), md5(1), sha1(2), sha224(3), sha256(4), sha384(5),
7192 * enum { anonymous(0), rsa(1), dsa(2), ecdsa(3), (255) }
7193 * SignatureAlgorithm;
7196 * HashAlgorithm hash;
7197 * SignatureAlgorithm signature;
7198 * } SignatureAndHashAlgorithm;
7200 * SignatureAndHashAlgorithm
7201 * supported_signature_algorithms<2..2^16-2>;
7203 * opaque DistinguishedName<1..2^16-1>;
7206 * ClientCertificateType certificate_types<1..2^8-1>;
7207 * SignatureAndHashAlgorithm supported_signature_algorithms<2^16-1>;
7208 * DistinguishedName certificate_authorities<0..2^16-1>;
7209 * } CertificateRequest;
7211 * draft-ietf-tls-tls13-18 (soon obsolete!):
7212 * Note: certificate_extensions is not dissected since it is removed in next
7216 * opaque certificate_request_context<0..2^8-1>;
7217 * SignatureScheme supported_signature_algorithms<2..2^16-2>;
7218 * DistinguishedName certificate_authorities<0..2^16-1>;
7219 * CertificateExtension certificate_extensions<0..2^16-1>;
7220 * } CertificateRequest;
7222 * draft-ietf-tls-tls13 (between -18 and -19, 2017-01-30):
7225 * opaque certificate_request_context<0..2^8-1>;
7226 * Extension extensions<2..2^16-1>;
7227 * } CertificateRequest;
7230 proto_tree *subtree;
7231 guint32 dnames_length = 0, next_offset;
7232 asn1_ctx_t asn1_ctx;
7237 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
7239 if (session->version == TLSV1DOT3_VERSION) {
7240 guint32 context_length;
7241 /* opaque certificate_request_context<0..2^8-1> */
7242 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &context_length,
7243 hf->hf.hs_certificate_request_context_length, 0, G_MAXUINT8)) {
7247 if (context_length > 0) {
7248 proto_tree_add_item(tree, hf->hf.hs_certificate_request_context,
7249 tvb, offset, context_length, ENC_NA);
7250 offset += context_length;
7253 guint32 cert_types_count;
7254 /* ClientCertificateType certificate_types<1..2^8-1> */
7255 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &cert_types_count,
7256 hf->hf.hs_cert_types_count, 1, G_MAXUINT8)) {
7260 next_offset = offset + cert_types_count;
7262 ti = proto_tree_add_none_format(tree,
7263 hf->hf.hs_cert_types,
7264 tvb, offset, cert_types_count,
7265 "Certificate types (%u type%s)",
7267 plurality(cert_types_count, "", "s"));
7268 subtree = proto_item_add_subtree(ti, hf->ett.cert_types);
7270 while (offset < next_offset) {
7271 proto_tree_add_item(subtree, hf->hf.hs_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN);
7276 switch (session->version) {
7277 case TLSV1DOT2_VERSION:
7278 case DTLSV1DOT2_VERSION:
7279 case TLSV1DOT3_VERSION: /* XXX draft -18 only, remove for next version */
7280 offset = ssl_dissect_hash_alg_list(hf, tvb, tree, pinfo, offset, offset_end);
7287 /* DistinguishedName certificate_authorities<0..2^16-1> */
7288 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &dnames_length,
7289 hf->hf.hs_dnames_len, 0, G_MAXUINT16)) {
7293 next_offset = offset + dnames_length;
7295 if (dnames_length > 0) {
7296 ti = proto_tree_add_none_format(tree,
7298 tvb, offset, dnames_length,
7299 "Distinguished Names (%d byte%s)",
7301 plurality(dnames_length, "", "s"));
7302 subtree = proto_item_add_subtree(ti, hf->ett.dnames);
7304 while (offset < next_offset) {
7305 /* get the length of the current certificate */
7306 guint32 name_length;
7307 /* opaque DistinguishedName<1..2^16-1> */
7308 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, next_offset, &name_length,
7309 hf->hf.hs_dname_len, 1, G_MAXUINT16)) {
7314 dissect_x509if_DistinguishedName(FALSE, tvb, offset, &asn1_ctx,
7315 subtree, hf->hf.hs_dname);
7316 offset += name_length;
7320 /* TODO Extensions specific to certificates (TLS 1.3). */
7322 /* Certificate and Certificate Request dissections. }}} */
7325 ssl_dissect_digitally_signed(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7326 proto_tree *tree, guint32 offset,
7327 const SslSession *session,
7328 gint hf_sig_len, gint hf_sig);
7331 ssl_dissect_hnd_cli_cert_verify(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7332 proto_tree *tree, guint32 offset,
7333 const SslSession *session)
7335 ssl_dissect_digitally_signed(hf, tvb, tree, offset, session,
7336 hf->hf.hs_client_cert_vrfy_sig_len,
7337 hf->hf.hs_client_cert_vrfy_sig);
7340 /* Finished dissection. {{{ */
7342 ssl_dissect_hnd_finished(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7343 proto_tree *tree, guint32 offset, guint32 offset_end,
7344 const SslSession *session, ssl_hfs_t *ssl_hfs)
7348 * opaque md5_hash[16];
7349 * opaque sha_hash[20];
7354 * opaque verify_data[12];
7359 * opaque verify_data[Hash.length];
7365 if (session->version == SSLV3_VERSION) {
7366 if (ssl_hfs != NULL) {
7367 proto_tree_add_item(tree, ssl_hfs->hs_md5_hash,
7368 tvb, offset, 16, ENC_NA);
7369 proto_tree_add_item(tree, ssl_hfs->hs_sha_hash,
7370 tvb, offset + 16, 20, ENC_NA);
7373 /* Length should be 12 for TLS before 1.3, assume this is the case. */
7374 proto_tree_add_item(tree, hf->hf.hs_finished,
7375 tvb, offset, offset_end - offset, ENC_NA);
7379 /* RFC 6066 Certificate URL handshake message dissection. {{{ */
7381 ssl_dissect_hnd_cert_url(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree, guint32 offset)
7383 guint16 url_hash_len;
7386 * individual_certs(0), pkipath(1), (255)
7390 * CertChainType type;
7391 * URLAndHash url_and_hash_list<1..2^16-1>;
7395 * opaque url<1..2^16-1>;
7397 * opaque SHA1Hash[20];
7401 proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_type,
7402 tvb, offset, 1, ENC_NA);
7405 url_hash_len = tvb_get_ntohs(tvb, offset);
7406 proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_url_hash_list_len,
7407 tvb, offset, 2, ENC_BIG_ENDIAN);
7409 while (url_hash_len-- > 0) {
7410 proto_item *urlhash_item;
7411 proto_tree *urlhash_tree;
7414 urlhash_item = proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_item,
7415 tvb, offset, -1, ENC_NA);
7416 urlhash_tree = proto_item_add_subtree(urlhash_item, hf->ett.urlhash);
7418 url_len = tvb_get_ntohs(tvb, offset);
7419 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_url_len,
7420 tvb, offset, 2, ENC_BIG_ENDIAN);
7423 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_url,
7424 tvb, offset, url_len, ENC_ASCII|ENC_NA);
7427 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_padding,
7428 tvb, offset, 1, ENC_NA);
7430 /* Note: RFC 6066 says that padding must be 0x01 */
7432 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_sha1,
7433 tvb, offset, 20, ENC_NA);
7438 /* Client Hello and Server Hello TLS extensions dissection. {{{ */
7440 ssl_dissect_hnd_hello_ext(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
7441 packet_info* pinfo, guint32 offset, guint32 offset_end, guint8 hnd_type,
7442 SslSession *session, SslDecryptSession *ssl,
7445 guint16 extension_length;
7448 guint32 next_offset;
7449 proto_tree *ext_tree;
7451 if (offset_end - offset < 2)
7454 extension_length = tvb_get_ntohs(tvb, offset);
7455 proto_tree_add_uint(tree, hf->hf.hs_exts_len,
7456 tvb, offset, 2, extension_length);
7459 while (offset_end - offset >= 4)
7461 ext_type = tvb_get_ntohs(tvb, offset);
7462 ext_len = tvb_get_ntohs(tvb, offset + 2);
7464 ext_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4 + ext_len, hf->ett.hs_ext, NULL,
7465 "Extension: %s (len=%u)", val_to_str(ext_type,
7466 tls_hello_extension_types,
7467 "Unknown type %u"), ext_len);
7469 proto_tree_add_uint(ext_tree, hf->hf.hs_ext_type,
7470 tvb, offset, 2, ext_type);
7473 /* opaque extension_data<0..2^16-1> */
7474 if (!ssl_add_vector(hf, tvb, pinfo, ext_tree, offset, offset_end, &ext_len,
7475 hf->hf.hs_ext_len, 0, G_MAXUINT16)) {
7479 next_offset = offset + ext_len;
7482 case SSL_HND_HELLO_EXT_STATUS_REQUEST:
7483 if (hnd_type == SSL_HND_CLIENT_HELLO)
7484 offset = ssl_dissect_hnd_hello_ext_status_request(hf, tvb, ext_tree, offset, FALSE);
7486 case SSL_HND_HELLO_EXT_STATUS_REQUEST_V2:
7487 if (hnd_type == SSL_HND_CLIENT_HELLO)
7488 offset = ssl_dissect_hnd_hello_ext_status_request_v2(hf, tvb, ext_tree, offset);
7490 case SSL_HND_HELLO_EXT_SUPPORTED_GROUPS:
7491 offset = ssl_dissect_hnd_hello_ext_supported_groups(hf, tvb, pinfo, ext_tree, offset, next_offset);
7493 case SSL_HND_HELLO_EXT_EC_POINT_FORMATS:
7494 offset = ssl_dissect_hnd_hello_ext_ec_point_formats(hf, tvb, ext_tree, offset);
7496 case SSL_HND_HELLO_EXT_SIGNATURE_ALGORITHMS:
7497 offset = ssl_dissect_hnd_hello_ext_sig_hash_algs(hf, tvb, ext_tree, pinfo, offset, next_offset);
7499 case SSL_HND_HELLO_EXT_ALPN:
7500 offset = ssl_dissect_hnd_hello_ext_alpn(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type, session);
7502 case SSL_HND_HELLO_EXT_NPN:
7503 offset = ssl_dissect_hnd_hello_ext_npn(hf, tvb, pinfo, ext_tree, offset, next_offset);
7505 case SSL_HND_HELLO_EXT_RENEGOTIATION_INFO:
7506 offset = ssl_dissect_hnd_hello_ext_reneg_info(hf, tvb, pinfo, ext_tree, offset, next_offset);
7508 case SSL_HND_HELLO_EXT_KEY_SHARE:
7509 offset = ssl_dissect_hnd_hello_ext_key_share(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type);
7511 case SSL_HND_HELLO_EXT_PRE_SHARED_KEY:
7512 offset = ssl_dissect_hnd_hello_ext_pre_shared_key(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type);
7514 case SSL_HND_HELLO_EXT_EARLY_DATA:
7515 if (hnd_type == SSL_HND_CLIENT_HELLO && ssl) {
7516 ssl_debug_printf("%s found early_data extension\n", G_STRFUNC);
7517 ssl->has_early_data = TRUE;
7520 case SSL_HND_HELLO_EXT_SUPPORTED_VERSIONS:
7521 offset = ssl_dissect_hnd_hello_ext_supported_versions(hf, tvb, pinfo, ext_tree, offset, next_offset);
7523 case SSL_HND_HELLO_EXT_COOKIE:
7524 offset = ssl_dissect_hnd_hello_ext_cookie(hf, tvb, pinfo, ext_tree, offset, next_offset);
7526 case SSL_HND_HELLO_EXT_PSK_KEY_EXCHANGE_MODES:
7527 offset = ssl_dissect_hnd_hello_ext_psk_key_exchange_modes(hf, tvb, pinfo, ext_tree, offset, next_offset);
7529 case SSL_HND_HELLO_EXT_DRAFT_VERSION_TLS13:
7530 proto_tree_add_item(ext_tree, hf->hf.hs_ext_draft_version_tls13,
7531 tvb, offset, 2, ENC_BIG_ENDIAN);
7534 case SSL_HND_HELLO_EXT_SERVER_NAME:
7535 offset = ssl_dissect_hnd_hello_ext_server_name(hf, tvb, pinfo, ext_tree, offset, next_offset);
7537 case SSL_HND_HELLO_EXT_USE_SRTP:
7539 offset = dtls_dissect_hnd_hello_ext_use_srtp(tvb, ext_tree, offset, next_offset);
7541 // XXX expert info: This extension MUST only be used with DTLS, and not with TLS.
7544 case SSL_HND_HELLO_EXT_HEARTBEAT:
7545 proto_tree_add_item(ext_tree, hf->hf.hs_ext_heartbeat_mode,
7546 tvb, offset, 1, ENC_BIG_ENDIAN);
7549 case SSL_HND_HELLO_EXT_PADDING:
7550 proto_tree_add_item(ext_tree, hf->hf.hs_ext_padding_data, tvb, offset, ext_len, ENC_NA);
7553 case SSL_HND_HELLO_EXT_SESSION_TICKET_TLS:
7554 offset = ssl_dissect_hnd_hello_ext_session_ticket(hf, tvb, ext_tree, offset, next_offset, hnd_type, ssl);
7556 case SSL_HND_HELLO_EXT_CERT_TYPE:
7557 case SSL_HND_HELLO_EXT_SERVER_CERT_TYPE:
7558 case SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE:
7559 offset = ssl_dissect_hnd_hello_ext_cert_type(hf, tvb, ext_tree,
7560 offset, next_offset,
7564 case SSL_HND_HELLO_EXT_EXTENDED_MASTER_SECRET:
7567 case SSL_HND_CLIENT_HELLO:
7568 ssl->state |= SSL_CLIENT_EXTENDED_MASTER_SECRET;
7570 case SSL_HND_SERVER_HELLO:
7571 ssl->state |= SSL_SERVER_EXTENDED_MASTER_SECRET;
7573 default: /* no default */
7579 proto_tree_add_item(ext_tree, hf->hf.hs_ext_data,
7580 tvb, offset, ext_len, ENC_NA);
7585 if (!ssl_end_vector(hf, tvb, pinfo, ext_tree, offset, next_offset)) {
7586 /* Dissection did not end at expected location, fix it. */
7587 offset = next_offset;
7595 /* ClientKeyExchange algo-specific dissectors. {{{ */
7598 dissect_ssl3_hnd_cli_keyex_ecdh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7599 proto_tree *tree, guint32 offset,
7603 proto_tree *ssl_ecdh_tree;
7605 ssl_ecdh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
7606 hf->ett.keyex_params, NULL, "EC Diffie-Hellman Client Params");
7609 point_len = tvb_get_guint8(tvb, offset);
7610 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_client_keyex_point_len, tvb,
7611 offset, 1, ENC_BIG_ENDIAN);
7612 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_client_keyex_point, tvb,
7613 offset + 1, point_len, ENC_NA);
7617 dissect_ssl3_hnd_cli_keyex_dh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7618 proto_tree *tree, guint32 offset, guint32 length)
7621 proto_tree *ssl_dh_tree;
7623 ssl_dh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
7624 hf->ett.keyex_params, NULL, "Diffie-Hellman Client Params");
7626 /* ClientDiffieHellmanPublic.dh_public (explicit) */
7627 yc_len = tvb_get_ntohs(tvb, offset);
7628 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_client_keyex_yc_len, tvb,
7629 offset, 2, ENC_BIG_ENDIAN);
7630 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_client_keyex_yc, tvb,
7631 offset + 2, yc_len, ENC_NA);
7635 dissect_ssl3_hnd_cli_keyex_rsa(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7636 proto_tree *tree, guint32 offset,
7637 guint32 length, const SslSession *session)
7640 proto_tree *ssl_rsa_tree;
7642 ssl_rsa_tree = proto_tree_add_subtree(tree, tvb, offset, length,
7643 hf->ett.keyex_params, NULL, "RSA Encrypted PreMaster Secret");
7645 /* EncryptedPreMasterSecret.pre_master_secret */
7646 switch (session->version) {
7649 case DTLSV1DOT0_OPENSSL_VERSION:
7650 /* OpenSSL pre-0.9.8f DTLS and pre-TLS quirk: 2-octet length vector is
7651 * not present. The handshake contents represents the EPMS, see:
7652 * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10222 */
7657 /* TLS and DTLS include vector length before EPMS */
7658 epms_len = tvb_get_ntohs(tvb, offset);
7659 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_client_keyex_epms_len, tvb,
7660 offset, 2, ENC_BIG_ENDIAN);
7664 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_client_keyex_epms, tvb,
7665 offset, epms_len, ENC_NA);
7668 /* Used in PSK cipher suites */
7670 dissect_ssl3_hnd_cli_keyex_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7671 proto_tree *tree, guint32 offset, guint32 length)
7674 proto_tree *ssl_psk_tree;
7676 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
7677 hf->ett.keyex_params, NULL, "PSK Client Params");
7679 identity_len = tvb_get_ntohs(tvb, offset);
7680 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity_len, tvb,
7681 offset, 2, ENC_BIG_ENDIAN);
7682 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity, tvb,
7683 offset + 2, identity_len, ENC_NA);
7686 /* Used in RSA PSK cipher suites */
7688 dissect_ssl3_hnd_cli_keyex_rsa_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7689 proto_tree *tree, guint32 offset,
7692 gint identity_len, epms_len;
7693 proto_tree *ssl_psk_tree;
7695 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
7696 hf->ett.keyex_params, NULL, "RSA PSK Client Params");
7699 identity_len = tvb_get_ntohs(tvb, offset);
7700 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity_len,
7701 tvb, offset, 2, ENC_BIG_ENDIAN);
7702 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity,
7703 tvb, offset + 2, identity_len, ENC_NA);
7704 offset += 2 + identity_len;
7707 epms_len = tvb_get_ntohs(tvb, offset);
7708 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_epms_len, tvb,
7709 offset, 2, ENC_BIG_ENDIAN);
7710 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_epms, tvb,
7711 offset + 2, epms_len, ENC_NA);
7713 /* ClientKeyExchange algo-specific dissectors. }}} */
7716 /* Dissects DigitallySigned (see RFC 5246 4.7 Cryptographic Attributes). {{{ */
7718 ssl_dissect_digitally_signed(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7719 proto_tree *tree, guint32 offset,
7720 const SslSession *session,
7721 gint hf_sig_len, gint hf_sig)
7724 proto_item *ti_algo;
7725 proto_tree *ssl_algo_tree;
7727 switch (session->version) {
7728 case TLSV1DOT2_VERSION:
7729 case DTLSV1DOT2_VERSION:
7730 case TLSV1DOT3_VERSION: /* XXX merge both fields into one SignatureScheme? */
7731 ti_algo = proto_tree_add_item(tree, hf->hf.hs_sig_hash_alg, tvb,
7732 offset, 2, ENC_BIG_ENDIAN);
7733 ssl_algo_tree = proto_item_add_subtree(ti_algo, hf->ett.hs_sig_hash_alg);
7735 /* SignatureAndHashAlgorithm { hash, signature } */
7736 proto_tree_add_item(ssl_algo_tree, hf->hf.hs_sig_hash_hash, tvb,
7737 offset, 1, ENC_BIG_ENDIAN);
7738 proto_tree_add_item(ssl_algo_tree, hf->hf.hs_sig_hash_sig, tvb,
7739 offset + 1, 1, ENC_BIG_ENDIAN);
7748 sig_len = tvb_get_ntohs(tvb, offset);
7749 proto_tree_add_item(tree, hf_sig_len, tvb, offset, 2, ENC_BIG_ENDIAN);
7750 proto_tree_add_item(tree, hf_sig, tvb, offset + 2, sig_len, ENC_NA);
7753 /* ServerKeyExchange algo-specific dissectors. {{{ */
7755 /* dissects signed_params inside a ServerKeyExchange for some keyex algos */
7757 dissect_ssl3_hnd_srv_keyex_sig(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7758 proto_tree *tree, guint32 offset,
7759 const SslSession *session)
7762 * TLSv1.2 (RFC 5246 sec 7.4.8)
7764 * digitally-signed struct {
7765 * opaque handshake_messages[handshake_messages_length];
7767 * } CertificateVerify;
7769 * TLSv1.0/TLSv1.1 (RFC 5436 sec 7.4.8 and 7.4.3) works essentially the same
7770 * as TLSv1.2, but the hash algorithms are not explicit in digitally-signed.
7772 * SSLv3 (RFC 6101 sec 5.6.8) esseentially works the same as TLSv1.0 but it
7773 * does more hashing including the master secret and padding.
7775 ssl_dissect_digitally_signed(hf, tvb, tree, offset, session,
7776 hf->hf.hs_server_keyex_sig_len,
7777 hf->hf.hs_server_keyex_sig);
7781 dissect_ssl3_hnd_srv_keyex_ecdh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7782 proto_tree *tree, guint32 offset,
7783 guint32 length, const SslSession *session,
7787 * RFC 4492 ECC cipher suites for TLS
7790 * ECCurveType curve_type;
7791 * select (curve_type) {
7792 * case explicit_prime:
7794 * case explicit_char2:
7797 * NamedCurve namedcurve;
7802 * opaque point <1..2^8-1>;
7806 * ECParameters curve_params;
7808 * } ServerECDHParams;
7810 * select (KeyExchangeAlgorithm) {
7811 * case ec_diffie_hellman:
7812 * ServerECDHParams params;
7813 * Signature signed_params;
7814 * } ServerKeyExchange;
7819 proto_tree *ssl_ecdh_tree;
7821 ssl_ecdh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
7822 hf->ett.keyex_params, NULL, "EC Diffie-Hellman Server Params");
7824 /* ECParameters.curve_type */
7825 curve_type = tvb_get_guint8(tvb, offset);
7826 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_curve_type, tvb,
7827 offset, 1, ENC_BIG_ENDIAN);
7829 if (curve_type != 3)
7830 return; /* only named_curves are supported */
7832 /* case curve_type == named_curve; ECParameters.namedcurve */
7833 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_named_curve, tvb,
7834 offset, 2, ENC_BIG_ENDIAN);
7838 point_len = tvb_get_guint8(tvb, offset);
7839 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_point_len, tvb,
7840 offset, 1, ENC_BIG_ENDIAN);
7841 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_point, tvb,
7842 offset + 1, point_len, ENC_NA);
7843 offset += 1 + point_len;
7845 /* Signature (if non-anonymous KEX) */
7847 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_ecdh_tree, offset, session);
7852 dissect_ssl3_hnd_srv_keyex_dhe(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7853 proto_tree *tree, guint32 offset, guint32 length,
7854 const SslSession *session, gboolean anon)
7856 gint p_len, g_len, ys_len;
7857 proto_tree *ssl_dh_tree;
7859 ssl_dh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
7860 hf->ett.keyex_params, NULL, "Diffie-Hellman Server Params");
7863 p_len = tvb_get_ntohs(tvb, offset);
7864 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_p_len, tvb,
7865 offset, 2, ENC_BIG_ENDIAN);
7866 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_p, tvb,
7867 offset + 2, p_len, ENC_NA);
7868 offset += 2 + p_len;
7871 g_len = tvb_get_ntohs(tvb, offset);
7872 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_g_len, tvb,
7873 offset, 2, ENC_BIG_ENDIAN);
7874 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_g, tvb,
7875 offset + 2, g_len, ENC_NA);
7876 offset += 2 + g_len;
7879 ys_len = tvb_get_ntohs(tvb, offset);
7880 proto_tree_add_uint(ssl_dh_tree, hf->hf.hs_server_keyex_ys_len, tvb,
7882 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_ys, tvb,
7883 offset + 2, ys_len, ENC_NA);
7884 offset += 2 + ys_len;
7886 /* Signature (if non-anonymous KEX) */
7888 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_dh_tree, offset, session);
7892 /* Only used in RSA-EXPORT cipher suites */
7894 dissect_ssl3_hnd_srv_keyex_rsa(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7895 proto_tree *tree, guint32 offset, guint32 length,
7896 const SslSession *session)
7898 gint modulus_len, exponent_len;
7899 proto_tree *ssl_rsa_tree;
7901 ssl_rsa_tree = proto_tree_add_subtree(tree, tvb, offset, length,
7902 hf->ett.keyex_params, NULL, "RSA-EXPORT Server Params");
7905 modulus_len = tvb_get_ntohs(tvb, offset);
7906 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_modulus_len, tvb,
7907 offset, 2, ENC_BIG_ENDIAN);
7908 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_modulus, tvb,
7909 offset + 2, modulus_len, ENC_NA);
7910 offset += 2 + modulus_len;
7913 exponent_len = tvb_get_ntohs(tvb, offset);
7914 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_exponent_len,
7915 tvb, offset, 2, ENC_BIG_ENDIAN);
7916 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_exponent,
7917 tvb, offset + 2, exponent_len, ENC_NA);
7918 offset += 2 + exponent_len;
7921 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_rsa_tree, offset, session);
7924 /* Used in RSA PSK and PSK cipher suites */
7926 dissect_ssl3_hnd_srv_keyex_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7927 proto_tree *tree, guint32 offset, guint32 length)
7930 proto_tree *ssl_psk_tree;
7932 hint_len = tvb_get_ntohs(tvb, offset);
7933 if ((2 + hint_len) != length) {
7934 /* Lengths don't line up (wasn't what we expected?) */
7938 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
7939 hf->ett.keyex_params, NULL, "PSK Server Params");
7942 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_server_keyex_hint_len, tvb,
7943 offset, 2, ENC_BIG_ENDIAN);
7944 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_server_keyex_hint, tvb,
7945 offset + 2, hint_len, ENC_NA);
7947 /* ServerKeyExchange algo-specific dissectors. }}} */
7949 /* Client Key Exchange and Server Key Exchange handshake dissections. {{{ */
7951 ssl_dissect_hnd_cli_keyex(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7952 proto_tree *tree, guint32 offset, guint32 length,
7953 const SslSession *session)
7955 switch (ssl_get_keyex_alg(session->cipher)) {
7956 case KEX_DH_ANON: /* RFC 5246; DHE_DSS, DHE_RSA, DH_DSS, DH_RSA, DH_ANON: ClientDiffieHellmanPublic */
7961 dissect_ssl3_hnd_cli_keyex_dh(hf, tvb, tree, offset, length);
7963 case KEX_DHE_PSK: /* RFC 4279; diffie_hellman_psk: psk_identity, ClientDiffieHellmanPublic */
7964 /* XXX: implement support for DHE_PSK */
7966 case KEX_ECDH_ANON: /* RFC 4492; ec_diffie_hellman: ClientECDiffieHellmanPublic */
7967 case KEX_ECDH_ECDSA:
7969 case KEX_ECDHE_ECDSA:
7971 dissect_ssl3_hnd_cli_keyex_ecdh(hf, tvb, tree, offset, length);
7973 case KEX_ECDHE_PSK: /* RFC 5489; ec_diffie_hellman_psk: psk_identity, ClientECDiffieHellmanPublic */
7974 /* XXX: implement support for ECDHE_PSK */
7976 case KEX_KRB5: /* RFC 2712; krb5: KerberosWrapper */
7977 /* XXX: implement support for KRB5 */
7979 case KEX_PSK: /* RFC 4279; psk: psk_identity */
7980 dissect_ssl3_hnd_cli_keyex_psk(hf, tvb, tree, offset, length);
7982 case KEX_RSA: /* RFC 5246; rsa: EncryptedPreMasterSecret */
7983 dissect_ssl3_hnd_cli_keyex_rsa(hf, tvb, tree, offset, length, session);
7985 case KEX_RSA_PSK: /* RFC 4279; rsa_psk: psk_identity, EncryptedPreMasterSecret */
7986 dissect_ssl3_hnd_cli_keyex_rsa_psk(hf, tvb, tree, offset, length);
7988 case KEX_SRP_SHA: /* RFC 5054; srp: ClientSRPPublic */
7989 case KEX_SRP_SHA_DSS:
7990 case KEX_SRP_SHA_RSA:
7991 /* XXX: implement support for SRP_SHA* */
7994 /* XXX: add info message for not supported KEX algo */
8000 ssl_dissect_hnd_srv_keyex(ssl_common_dissect_t *hf, tvbuff_t *tvb,
8001 proto_tree *tree, guint32 offset, guint32 length,
8002 const SslSession *session)
8004 switch (ssl_get_keyex_alg(session->cipher)) {
8005 case KEX_DH_ANON: /* RFC 5246; ServerDHParams */
8006 dissect_ssl3_hnd_srv_keyex_dhe(hf, tvb, tree, offset, length, session, TRUE);
8008 case KEX_DH_DSS: /* RFC 5246; not allowed */
8010 /* XXX: add error on not allowed KEX */
8012 case KEX_DHE_DSS: /* RFC 5246; dhe_dss, dhe_rsa: ServerDHParams, Signature */
8014 dissect_ssl3_hnd_srv_keyex_dhe(hf, tvb, tree, offset, length, session, FALSE);
8016 case KEX_DHE_PSK: /* RFC 4279; diffie_hellman_psk: psk_identity_hint, ServerDHParams */
8017 /* XXX: implement support for DHE_PSK */
8019 case KEX_ECDH_ANON: /* RFC 4492; ec_diffie_hellman: ServerECDHParams (without signature for anon) */
8020 dissect_ssl3_hnd_srv_keyex_ecdh(hf, tvb, tree, offset, length, session, TRUE);
8022 case KEX_ECDHE_PSK: /* RFC 5489; psk_identity_hint, ServerECDHParams */
8023 /* XXX: implement support for ECDHE_PSK */
8025 case KEX_ECDH_ECDSA: /* RFC 4492; ec_diffie_hellman: ServerECDHParams, Signature */
8027 case KEX_ECDHE_ECDSA:
8029 dissect_ssl3_hnd_srv_keyex_ecdh(hf, tvb, tree, offset, length, session, FALSE);
8031 case KEX_KRB5: /* RFC 2712; not allowed */
8032 /* XXX: add error on not allowed KEX */
8034 case KEX_PSK: /* RFC 4279; psk, rsa: psk_identity*/
8036 dissect_ssl3_hnd_srv_keyex_psk(hf, tvb, tree, offset, length);
8038 case KEX_RSA: /* only allowed if the public key in the server certificate is longer than 512 bits*/
8039 dissect_ssl3_hnd_srv_keyex_rsa(hf, tvb, tree, offset, length, session);
8041 case KEX_SRP_SHA: /* RFC 5054; srp: ServerSRPParams, Signature */
8042 case KEX_SRP_SHA_DSS:
8043 case KEX_SRP_SHA_RSA:
8044 /* XXX: implement support for SRP_SHA* */
8047 /* XXX: add info message for not supported KEX algo */
8051 /* Client Key Exchange and Server Key Exchange handshake dissections. }}} */
8053 #ifdef HAVE_LIBGCRYPT
8055 ssl_common_register_options(module_t *module, ssl_common_options_t *options)
8057 prefs_register_string_preference(module, "psk", "Pre-Shared-Key",
8058 "Pre-Shared-Key as HEX string. Should be 0 to 16 bytes.",
8061 prefs_register_filename_preference(module, "keylog_file", "(Pre)-Master-Secret log filename",
8062 "The name of a file which contains a list of \n"
8063 "(pre-)master secrets in one of the following formats:\n"
8065 "RSA <EPMS> <PMS>\n"
8066 "RSA Session-ID:<SSLID> Master-Key:<MS>\n"
8067 "CLIENT_RANDOM <CRAND> <MS>\n"
8068 "PMS_CLIENT_RANDOM <CRAND> <PMS>\n"
8071 "<EPMS> = First 8 bytes of the Encrypted PMS\n"
8072 "<PMS> = The Pre-Master-Secret (PMS) used to derive the MS\n"
8073 "<SSLID> = The SSL Session ID\n"
8074 "<MS> = The Master-Secret (MS)\n"
8075 "<CRAND> = The Client's random number from the ClientHello message\n"
8077 "(All fields are in hex notation)",
8078 &(options->keylog_filename));
8082 ssl_common_register_options(module_t *module _U_, ssl_common_options_t *options _U_)
8088 ssl_calculate_handshake_hash(SslDecryptSession *ssl_session, tvbuff_t *tvb, guint32 offset, guint32 length)
8090 if (ssl_session && ssl_session->session.version != TLSV1DOT3_VERSION && !(ssl_session->state & SSL_MASTER_SECRET)) {
8091 guint32 old_length = ssl_session->handshake_data.data_len;
8092 ssl_debug_printf("Calculating hash with offset %d %d\n", offset, length);
8093 ssl_session->handshake_data.data = (guchar *)wmem_realloc(wmem_file_scope(), ssl_session->handshake_data.data, old_length + length);
8094 tvb_memcpy(tvb, ssl_session->handshake_data.data + old_length, offset, length);
8095 ssl_session->handshake_data.data_len += length;
8101 * Editor modelines - http://www.wireshark.org/tools/modelines.html
8106 * indent-tabs-mode: nil
8109 * vi: set shiftwidth=4 tabstop=8 expandtab:
8110 * :indentSize=4:tabSize=8:noTabs=true: