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 <ws_version_info.h>
51 #include "packet-x509af.h"
52 #include "packet-x509if.h"
53 #include "packet-ssl-utils.h"
54 #include "packet-ssl.h"
55 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
56 #include <gnutls/abstract.h>
59 /* Lookup tables {{{ */
60 const value_string ssl_version_short_names[] = {
61 { SSL_VER_UNKNOWN, "SSL" },
62 { SSLV2_VERSION, "SSLv2" },
63 { SSLV3_VERSION, "SSLv3" },
64 { TLSV1_VERSION, "TLSv1" },
65 { TLSV1DOT1_VERSION, "TLSv1.1" },
66 { TLSV1DOT2_VERSION, "TLSv1.2" },
67 { DTLSV1DOT0_VERSION, "DTLSv1.0" },
68 { DTLSV1DOT2_VERSION, "DTLSv1.2" },
69 { DTLSV1DOT0_OPENSSL_VERSION, "DTLS 1.0 (OpenSSL pre 0.9.8f)" },
70 { PCT_VERSION, "PCT" },
74 const value_string ssl_20_msg_types[] = {
75 { SSL2_HND_ERROR, "Error" },
76 { SSL2_HND_CLIENT_HELLO, "Client Hello" },
77 { SSL2_HND_CLIENT_MASTER_KEY, "Client Master Key" },
78 { SSL2_HND_CLIENT_FINISHED, "Client Finished" },
79 { SSL2_HND_SERVER_HELLO, "Server Hello" },
80 { SSL2_HND_SERVER_VERIFY, "Server Verify" },
81 { SSL2_HND_SERVER_FINISHED, "Server Finished" },
82 { SSL2_HND_REQUEST_CERTIFICATE, "Request Certificate" },
83 { SSL2_HND_CLIENT_CERTIFICATE, "Client Certificate" },
86 /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
87 /* Note: sorted by ascending value so value_string-ext can do a binary search */
88 static const value_string ssl_20_cipher_suites[] = {
89 { 0x000000, "TLS_NULL_WITH_NULL_NULL" },
90 { 0x000001, "TLS_RSA_WITH_NULL_MD5" },
91 { 0x000002, "TLS_RSA_WITH_NULL_SHA" },
92 { 0x000003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" },
93 { 0x000004, "TLS_RSA_WITH_RC4_128_MD5" },
94 { 0x000005, "TLS_RSA_WITH_RC4_128_SHA" },
95 { 0x000006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" },
96 { 0x000007, "TLS_RSA_WITH_IDEA_CBC_SHA" },
97 { 0x000008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" },
98 { 0x000009, "TLS_RSA_WITH_DES_CBC_SHA" },
99 { 0x00000a, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" },
100 { 0x00000b, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" },
101 { 0x00000c, "TLS_DH_DSS_WITH_DES_CBC_SHA" },
102 { 0x00000d, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" },
103 { 0x00000e, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" },
104 { 0x00000f, "TLS_DH_RSA_WITH_DES_CBC_SHA" },
105 { 0x000010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" },
106 { 0x000011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" },
107 { 0x000012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" },
108 { 0x000013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" },
109 { 0x000014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" },
110 { 0x000015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" },
111 { 0x000016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" },
112 { 0x000017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" },
113 { 0x000018, "TLS_DH_anon_WITH_RC4_128_MD5" },
114 { 0x000019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" },
115 { 0x00001a, "TLS_DH_anon_WITH_DES_CBC_SHA" },
116 { 0x00001b, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" },
117 { 0x00001c, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" },
118 { 0x00001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
120 { 0x00001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
123 { 0x00001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
124 { 0x00001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" },
125 { 0x000020, "TLS_KRB5_WITH_RC4_128_SHA" },
126 { 0x000021, "TLS_KRB5_WITH_IDEA_CBC_SHA" },
127 { 0x000022, "TLS_KRB5_WITH_DES_CBC_MD5" },
128 { 0x000023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" },
129 { 0x000024, "TLS_KRB5_WITH_RC4_128_MD5" },
130 { 0x000025, "TLS_KRB5_WITH_IDEA_CBC_MD5" },
131 { 0x000026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" },
132 { 0x000027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" },
133 { 0x000028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" },
134 { 0x000029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" },
135 { 0x00002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" },
136 { 0x00002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" },
138 { 0x00002C, "TLS_PSK_WITH_NULL_SHA" },
139 { 0x00002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
140 { 0x00002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
142 { 0x00002f, "TLS_RSA_WITH_AES_128_CBC_SHA" },
143 { 0x000030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
144 { 0x000031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" },
145 { 0x000032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" },
146 { 0x000033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" },
147 { 0x000034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" },
148 { 0x000035, "TLS_RSA_WITH_AES_256_CBC_SHA" },
149 { 0x000036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" },
150 { 0x000037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" },
151 { 0x000038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
152 { 0x000039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
153 { 0x00003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
154 { 0x00003B, "TLS_RSA_WITH_NULL_SHA256" },
155 { 0x00003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" },
156 { 0x00003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" },
157 { 0x00003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" },
158 { 0x00003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" },
159 { 0x000040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" },
160 { 0x000041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" },
161 { 0x000042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" },
162 { 0x000043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" },
163 { 0x000044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" },
164 { 0x000045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" },
165 { 0x000046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" },
166 { 0x000047, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
167 { 0x000048, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
168 { 0x000049, "TLS_ECDH_ECDSA_WITH_DES_CBC_SHA" },
169 { 0x00004A, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
170 { 0x00004B, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
171 { 0x00004C, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
172 { 0x000060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
173 { 0x000061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
174 { 0x000062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" },
175 { 0x000063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" },
176 { 0x000064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" },
177 { 0x000065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" },
178 { 0x000066, "TLS_DHE_DSS_WITH_RC4_128_SHA" },
179 { 0x000067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" },
180 { 0x000068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" },
181 { 0x000069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" },
182 { 0x00006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" },
183 { 0x00006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" },
184 { 0x00006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" },
185 { 0x00006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" },
186 /* 0x00,0x6E-83 Unassigned */
187 { 0x000084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" },
188 { 0x000085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" },
189 { 0x000086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" },
190 { 0x000087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
191 { 0x000088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
192 { 0x000089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
194 { 0x00008A, "TLS_PSK_WITH_RC4_128_SHA" },
195 { 0x00008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
196 { 0x00008C, "TLS_PSK_WITH_AES_128_CBC_SHA" },
197 { 0x00008D, "TLS_PSK_WITH_AES_256_CBC_SHA" },
198 { 0x00008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" },
199 { 0x00008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" },
200 { 0x000090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" },
201 { 0x000091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" },
202 { 0x000092, "TLS_RSA_PSK_WITH_RC4_128_SHA" },
203 { 0x000093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" },
204 { 0x000094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" },
205 { 0x000095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" },
207 { 0x000096, "TLS_RSA_WITH_SEED_CBC_SHA" },
208 { 0x000097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" },
209 { 0x000098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" },
210 { 0x000099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
211 { 0x00009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
212 { 0x00009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
214 { 0x00009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" },
215 { 0x00009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" },
216 { 0x00009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" },
217 { 0x00009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" },
218 { 0x0000A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" },
219 { 0x0000A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" },
220 { 0x0000A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" },
221 { 0x0000A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" },
222 { 0x0000A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" },
223 { 0x0000A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" },
224 { 0x0000A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" },
225 { 0x0000A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" },
227 { 0x0000A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" },
228 { 0x0000A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" },
229 { 0x0000AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" },
230 { 0x0000AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" },
231 { 0x0000AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" },
232 { 0x0000AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" },
233 { 0x0000AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" },
234 { 0x0000AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" },
235 { 0x0000B0, "TLS_PSK_WITH_NULL_SHA256" },
236 { 0x0000B1, "TLS_PSK_WITH_NULL_SHA384" },
237 { 0x0000B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" },
238 { 0x0000B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" },
239 { 0x0000B4, "TLS_DHE_PSK_WITH_NULL_SHA256" },
240 { 0x0000B5, "TLS_DHE_PSK_WITH_NULL_SHA384" },
241 { 0x0000B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" },
242 { 0x0000B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" },
243 { 0x0000B8, "TLS_RSA_PSK_WITH_NULL_SHA256" },
244 { 0x0000B9, "TLS_RSA_PSK_WITH_NULL_SHA384" },
246 { 0x0000BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
247 { 0x0000BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
248 { 0x0000BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
249 { 0x0000BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
250 { 0x0000BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
251 { 0x0000BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" },
252 { 0x0000C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
253 { 0x0000C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
254 { 0x0000C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
255 { 0x0000C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
256 { 0x0000C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
257 { 0x0000C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" },
258 /* 0x00,0xC6-FE Unassigned */
259 { 0x0000FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" },
260 /* 0x01-BF,* Unassigned */
262 { 0x00c001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
263 { 0x00c002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
264 { 0x00c003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
265 { 0x00c004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
266 { 0x00c005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
267 { 0x00c006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" },
268 { 0x00c007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" },
269 { 0x00c008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" },
270 { 0x00c009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
271 { 0x00c00a, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
272 { 0x00c00b, "TLS_ECDH_RSA_WITH_NULL_SHA" },
273 { 0x00c00c, "TLS_ECDH_RSA_WITH_RC4_128_SHA" },
274 { 0x00c00d, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" },
275 { 0x00c00e, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" },
276 { 0x00c00f, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" },
277 { 0x00c010, "TLS_ECDHE_RSA_WITH_NULL_SHA" },
278 { 0x00c011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" },
279 { 0x00c012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" },
280 { 0x00c013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
281 { 0x00c014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
282 { 0x00c015, "TLS_ECDH_anon_WITH_NULL_SHA" },
283 { 0x00c016, "TLS_ECDH_anon_WITH_RC4_128_SHA" },
284 { 0x00c017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" },
285 { 0x00c018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" },
286 { 0x00c019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" },
288 { 0x00C01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" },
289 { 0x00C01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" },
290 { 0x00C01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" },
291 { 0x00C01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" },
292 { 0x00C01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" },
293 { 0x00C01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" },
294 { 0x00C020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
295 { 0x00C021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
296 { 0x00C022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
298 { 0x00C023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" },
299 { 0x00C024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" },
300 { 0x00C025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" },
301 { 0x00C026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" },
302 { 0x00C027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" },
303 { 0x00C028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" },
304 { 0x00C029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" },
305 { 0x00C02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" },
306 { 0x00C02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
307 { 0x00C02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
308 { 0x00C02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" },
309 { 0x00C02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" },
310 { 0x00C02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
311 { 0x00C030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
312 { 0x00C031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" },
313 { 0x00C032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" },
315 { 0x00C033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" },
316 { 0x00C034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" },
317 { 0x00C035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" },
318 { 0x00C036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" },
319 { 0x00C037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" },
320 { 0x00C038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" },
321 { 0x00C039, "TLS_ECDHE_PSK_WITH_NULL_SHA" },
322 { 0x00C03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" },
323 { 0x00C03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" },
324 /* 0xC0,0x3C-FF Unassigned
326 0xFE,0x00-FD Unassigned
327 0xFE,0xFE-FF Reserved to avoid conflicts with widely deployed implementations [Pasi_Eronen]
328 0xFF,0x00-FF Reserved for Private Use [RFC5246]
331 /* old numbers used in the beginning
332 * http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 */
333 { 0x00CC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
334 { 0x00CC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
335 { 0x00CC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
337 /* http://tools.ietf.org/html/draft-ietf-tls-chacha20-poly1305 */
338 { 0x00CCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
339 { 0x00CCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
340 { 0x00CCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
341 { 0x00CCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256" },
342 { 0x00CCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
343 { 0x00CCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
344 { 0x00CCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256" },
346 /* http://tools.ietf.org/html/draft-josefsson-salsa20-tls */
347 { 0x00E410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" },
348 { 0x00E411, "TLS_RSA_WITH_SALSA20_SHA1" },
349 { 0x00E412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
350 { 0x00E413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" },
351 { 0x00E414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" },
352 { 0x00E415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" },
353 { 0x00E416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" },
354 { 0x00E417, "TLS_PSK_WITH_SALSA20_SHA1" },
355 { 0x00E418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
356 { 0x00E419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" },
357 { 0x00E41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" },
358 { 0x00E41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" },
359 { 0x00E41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
360 { 0x00E41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" },
361 { 0x00E41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
362 { 0x00E41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" },
364 /* these from http://www.mozilla.org/projects/
365 security/pki/nss/ssl/fips-ssl-ciphersuites.html */
366 { 0x00fefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
367 { 0x00feff, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
368 { 0x00ffe0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
369 { 0x00ffe1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
370 /* note that ciphersuites of {0x00????} are TLS cipher suites in
371 * a sslv2 client hello message; the ???? above is the two-byte
372 * tls cipher suite id
375 { 0x010080, "SSL2_RC4_128_WITH_MD5" },
376 { 0x020080, "SSL2_RC4_128_EXPORT40_WITH_MD5" },
377 { 0x030080, "SSL2_RC2_128_CBC_WITH_MD5" },
378 { 0x040080, "SSL2_RC2_128_CBC_EXPORT40_WITH_MD5" },
379 { 0x050080, "SSL2_IDEA_128_CBC_WITH_MD5" },
380 { 0x060040, "SSL2_DES_64_CBC_WITH_MD5" },
381 { 0x0700c0, "SSL2_DES_192_EDE3_CBC_WITH_MD5" },
382 { 0x080080, "SSL2_RC4_64_WITH_MD5" },
384 /* Microsoft's old PCT protocol. These are from Eric Rescorla's
385 book "SSL and TLS" */
386 { 0x800001, "PCT_SSL_CERT_TYPE | PCT1_CERT_X509" },
387 { 0x800003, "PCT_SSL_CERT_TYPE | PCT1_CERT_X509_CHAIN" },
388 { 0x810001, "PCT_SSL_HASH_TYPE | PCT1_HASH_MD5" },
389 { 0x810003, "PCT_SSL_HASH_TYPE | PCT1_HASH_SHA" },
390 { 0x820001, "PCT_SSL_EXCH_TYPE | PCT1_EXCH_RSA_PKCS1" },
391 { 0x830004, "PCT_SSL_CIPHER_TYPE_1ST_HALF | PCT1_CIPHER_RC4" },
392 { 0x842840, "PCT_SSL_CIPHER_TYPE_2ND_HALF | PCT1_ENC_BITS_40 | PCT1_MAC_BITS_128" },
393 { 0x848040, "PCT_SSL_CIPHER_TYPE_2ND_HALF | PCT1_ENC_BITS_128 | PCT1_MAC_BITS_128" },
394 { 0x8f8001, "PCT_SSL_COMPAT | PCT_VERSION_1" },
398 value_string_ext ssl_20_cipher_suites_ext = VALUE_STRING_EXT_INIT(ssl_20_cipher_suites);
401 const value_string ssl_extension_curves[] = {
427 { 26, "brainpoolP256r1" }, /* RFC 7027 */
428 { 27, "brainpoolP384r1" }, /* RFC 7027 */
429 { 28, "brainpoolP512r1" }, /* RFC 7027 */
430 { 29, "ecdh_x25519" }, /* https://tools.ietf.org/html/draft-ietf-tls-rfc4492bis */
431 { 30, "ecdh_x448" }, /* https://tools.ietf.org/html/draft-ietf-tls-rfc4492bis */
432 { 256, "ffdhe2048" }, /* https://tools.ietf.org/html/draft-ietf-tls-negotiated-ff-dhe */
433 { 257, "ffdhe3072" }, /* https://tools.ietf.org/html/draft-ietf-tls-negotiated-ff-dhe */
434 { 258, "ffdhe4096" }, /* https://tools.ietf.org/html/draft-ietf-tls-negotiated-ff-dhe */
435 { 259, "ffdhe6144" }, /* https://tools.ietf.org/html/draft-ietf-tls-negotiated-ff-dhe */
436 { 260, "ffdhe8192" }, /* https://tools.ietf.org/html/draft-ietf-tls-negotiated-ff-dhe */
437 { 0xFF01, "arbitrary_explicit_prime_curves" },
438 { 0xFF02, "arbitrary_explicit_char2_curves" },
442 const value_string ssl_curve_types[] = {
443 { 1, "explicit_prime" },
444 { 2, "explicit_char2" },
445 { 3, "named_curve" },
449 const value_string ssl_extension_ec_point_formats[] = {
450 { 0, "uncompressed" },
451 { 1, "ansiX962_compressed_prime" },
452 { 2, "ansiX962_compressed_char2" },
456 const value_string ssl_20_certificate_type[] = {
458 { 0x01, "X.509 Certificate" },
462 const value_string ssl_31_content_type[] = {
463 { 20, "Change Cipher Spec" },
466 { 23, "Application Data" },
471 const value_string ssl_versions[] = {
472 { 0xfefd, "DTLS 1.2" },
473 { 0xfeff, "DTLS 1.0" },
474 { 0x0100, "DTLS 1.0 (OpenSSL pre 0.9.8f)" },
475 { 0x0303, "TLS 1.2" },
476 { 0x0302, "TLS 1.1" },
477 { 0x0301, "TLS 1.0" },
478 { 0x0300, "SSL 3.0" },
479 { 0x0002, "SSL 2.0" },
484 /* XXX - would be used if we dissected the body of a Change Cipher Spec
486 const value_string ssl_31_change_cipher_spec[] = {
487 { 1, "Change Cipher Spec" },
492 const value_string ssl_31_alert_level[] = {
498 const value_string ssl_31_alert_description[] = {
499 { 0, "Close Notify" },
500 { 10, "Unexpected Message" },
501 { 20, "Bad Record MAC" },
502 { 21, "Decryption Failed" },
503 { 22, "Record Overflow" },
504 { 30, "Decompression Failure" },
505 { 40, "Handshake Failure" },
506 { 41, "No Certificate" },
507 { 42, "Bad Certificate" },
508 { 43, "Unsupported Certificate" },
509 { 44, "Certificate Revoked" },
510 { 45, "Certificate Expired" },
511 { 46, "Certificate Unknown" },
512 { 47, "Illegal Parameter" },
513 { 48, "Unknown CA" },
514 { 49, "Access Denied" },
515 { 50, "Decode Error" },
516 { 51, "Decrypt Error" },
517 { 60, "Export Restriction" },
518 { 70, "Protocol Version" },
519 { 71, "Insufficient Security" },
520 { 80, "Internal Error" },
521 { 86, "Inappropriate Fallback" },
522 { 90, "User Canceled" },
523 { 100, "No Renegotiation" },
524 { 110, "Unsupported Extension" },
525 { 111, "Certificate Unobtainable" },
526 { 112, "Unrecognized Name" },
527 { 113, "Bad Certificate Status Response" },
528 { 114, "Bad Certificate Hash Value" },
529 { 115, "Unknown PSK Identity" },
530 { 120, "No application Protocol" },
534 const value_string ssl_31_handshake_type[] = {
535 { SSL_HND_HELLO_REQUEST, "Hello Request" },
536 { SSL_HND_CLIENT_HELLO, "Client Hello" },
537 { SSL_HND_SERVER_HELLO, "Server Hello" },
538 { SSL_HND_HELLO_VERIFY_REQUEST, "Hello Verify Request"},
539 { SSL_HND_NEWSESSION_TICKET, "New Session Ticket" },
540 { SSL_HND_CERTIFICATE, "Certificate" },
541 { SSL_HND_SERVER_KEY_EXCHG, "Server Key Exchange" },
542 { SSL_HND_CERT_REQUEST, "Certificate Request" },
543 { SSL_HND_SVR_HELLO_DONE, "Server Hello Done" },
544 { SSL_HND_CERT_VERIFY, "Certificate Verify" },
545 { SSL_HND_CLIENT_KEY_EXCHG, "Client Key Exchange" },
546 { SSL_HND_FINISHED, "Finished" },
547 { SSL_HND_CERT_URL, "Client Certificate URL" },
548 { SSL_HND_CERT_STATUS, "Certificate Status" },
549 { SSL_HND_SUPPLEMENTAL_DATA, "Supplemental Data" },
550 { SSL_HND_ENCRYPTED_EXTS, "Encrypted Extensions" },
554 const value_string tls_heartbeat_type[] = {
560 const value_string tls_heartbeat_mode[] = {
561 { 1, "Peer allowed to send requests" },
562 { 2, "Peer not allowed to send requests" },
566 const value_string ssl_31_compression_method[] = {
574 /* XXX - would be used if we dissected a Signature, as would be
575 seen in a server key exchange or certificate verify message. */
576 const value_string ssl_31_key_exchange_algorithm[] = {
578 { 1, "Diffie Hellman" },
582 const value_string ssl_31_signature_algorithm[] = {
590 const value_string ssl_31_client_certificate_type[] = {
593 { 3, "RSA Fixed DH" },
594 { 4, "DSS Fixed DH" },
595 /* GOST certificate types */
596 /* Section 3.5 of draft-chudov-cryptopro-cptls-04 */
597 { 21, "GOST R 34.10-94" },
598 { 22, "GOST R 34.10-2001" },
599 /* END GOST certificate types */
600 { 64, "ECDSA Sign" },
601 { 65, "RSA Fixed ECDH" },
602 { 66, "ECDSA Fixed ECDH" },
607 /* XXX - would be used if we dissected exchange keys, as would be
608 seen in a client key exchange message. */
609 const value_string ssl_31_public_value_encoding[] = {
616 /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
617 /* Note: sorted by ascending value so value_string_ext fcns can do a binary search */
618 static const value_string ssl_31_ciphersuite[] = {
619 /* RFC 2246, RFC 4346, RFC 5246 */
620 { 0x0000, "TLS_NULL_WITH_NULL_NULL" },
621 { 0x0001, "TLS_RSA_WITH_NULL_MD5" },
622 { 0x0002, "TLS_RSA_WITH_NULL_SHA" },
623 { 0x0003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" },
624 { 0x0004, "TLS_RSA_WITH_RC4_128_MD5" },
625 { 0x0005, "TLS_RSA_WITH_RC4_128_SHA" },
626 { 0x0006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" },
627 { 0x0007, "TLS_RSA_WITH_IDEA_CBC_SHA" },
628 { 0x0008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" },
629 { 0x0009, "TLS_RSA_WITH_DES_CBC_SHA" },
630 { 0x000a, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" },
631 { 0x000b, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" },
632 { 0x000c, "TLS_DH_DSS_WITH_DES_CBC_SHA" },
633 { 0x000d, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" },
634 { 0x000e, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" },
635 { 0x000f, "TLS_DH_RSA_WITH_DES_CBC_SHA" },
636 { 0x0010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" },
637 { 0x0011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" },
638 { 0x0012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" },
639 { 0x0013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" },
640 { 0x0014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" },
641 { 0x0015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" },
642 { 0x0016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" },
643 { 0x0017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" },
644 { 0x0018, "TLS_DH_anon_WITH_RC4_128_MD5" },
645 { 0x0019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" },
646 { 0x001a, "TLS_DH_anon_WITH_DES_CBC_SHA" },
647 { 0x001b, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" },
649 { 0x001c, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" },
650 { 0x001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
651 #if 0 /* Because it clashes with KRB5, is never used any more, and is safe
652 to remove according to David Hopwood <david.hopwood@zetnet.co.uk>
653 of the ietf-tls list */
654 { 0x001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
658 { 0x001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
659 { 0x001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" },
660 { 0x0020, "TLS_KRB5_WITH_RC4_128_SHA" },
661 { 0x0021, "TLS_KRB5_WITH_IDEA_CBC_SHA" },
662 { 0x0022, "TLS_KRB5_WITH_DES_CBC_MD5" },
663 { 0x0023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" },
664 { 0x0024, "TLS_KRB5_WITH_RC4_128_MD5" },
665 { 0x0025, "TLS_KRB5_WITH_IDEA_CBC_MD5" },
666 { 0x0026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" },
667 { 0x0027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" },
668 { 0x0028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" },
669 { 0x0029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" },
670 { 0x002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" },
671 { 0x002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" },
674 { 0x002C, "TLS_PSK_WITH_NULL_SHA" },
675 { 0x002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
676 { 0x002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
679 { 0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA" },
680 { 0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
681 { 0x0031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" },
682 { 0x0032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" },
683 { 0x0033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" },
684 { 0x0034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" },
685 { 0x0035, "TLS_RSA_WITH_AES_256_CBC_SHA" },
686 { 0x0036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" },
687 { 0x0037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" },
688 { 0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
689 { 0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
690 { 0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
691 { 0x003B, "TLS_RSA_WITH_NULL_SHA256" },
692 { 0x003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" },
693 { 0x003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" },
694 { 0x003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" },
695 { 0x003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" },
696 { 0x0040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" },
699 { 0x0041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" },
700 { 0x0042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" },
701 { 0x0043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" },
702 { 0x0044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" },
703 { 0x0045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" },
704 { 0x0046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" },
706 /* 0x00,0x60-66 Reserved to avoid conflicts with widely deployed implementations */
708 { 0x0060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
709 { 0x0061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
710 /* draft-ietf-tls-56-bit-ciphersuites-01.txt */
711 { 0x0062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" },
712 { 0x0063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" },
713 { 0x0064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" },
714 { 0x0065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" },
715 { 0x0066, "TLS_DHE_DSS_WITH_RC4_128_SHA" },
718 { 0x0067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" },
719 { 0x0068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" },
720 { 0x0069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" },
721 { 0x006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" },
722 { 0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" },
723 { 0x006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" },
724 { 0x006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" },
726 /* draft-chudov-cryptopro-cptls-04.txt */
727 { 0x0080, "TLS_GOSTR341094_WITH_28147_CNT_IMIT" },
728 { 0x0081, "TLS_GOSTR341001_WITH_28147_CNT_IMIT" },
729 { 0x0082, "TLS_GOSTR341094_WITH_NULL_GOSTR3411" },
730 { 0x0083, "TLS_GOSTR341001_WITH_NULL_GOSTR3411" },
733 { 0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" },
734 { 0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" },
735 { 0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" },
736 { 0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
737 { 0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
738 { 0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
741 { 0x008A, "TLS_PSK_WITH_RC4_128_SHA" },
742 { 0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
743 { 0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA" },
744 { 0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA" },
745 { 0x008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" },
746 { 0x008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" },
747 { 0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" },
748 { 0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" },
749 { 0x0092, "TLS_RSA_PSK_WITH_RC4_128_SHA" },
750 { 0x0093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" },
751 { 0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" },
752 { 0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" },
755 { 0x0096, "TLS_RSA_WITH_SEED_CBC_SHA" },
756 { 0x0097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" },
757 { 0x0098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" },
758 { 0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
759 { 0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
760 { 0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
763 { 0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" },
764 { 0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" },
765 { 0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" },
766 { 0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" },
767 { 0x00A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" },
768 { 0x00A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" },
769 { 0x00A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" },
770 { 0x00A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" },
771 { 0x00A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" },
772 { 0x00A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" },
773 { 0x00A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" },
774 { 0x00A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" },
777 { 0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" },
778 { 0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" },
779 { 0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" },
780 { 0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" },
781 { 0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" },
782 { 0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" },
783 { 0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" },
784 { 0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" },
785 { 0x00B0, "TLS_PSK_WITH_NULL_SHA256" },
786 { 0x00B1, "TLS_PSK_WITH_NULL_SHA384" },
787 { 0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" },
788 { 0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" },
789 { 0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256" },
790 { 0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384" },
791 { 0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" },
792 { 0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" },
793 { 0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256" },
794 { 0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384" },
797 { 0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
798 { 0x00BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
799 { 0x00BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
800 { 0x00BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
801 { 0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
802 { 0x00BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" },
803 { 0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
804 { 0x00C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
805 { 0x00C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
806 { 0x00C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
807 { 0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
808 { 0x00C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" },
809 /* 0x00,0xC6-FE Unassigned */
811 { 0x00FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" },
813 { 0x5600, "TLS_FALLBACK_SCSV" },
815 { 0xc001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
816 { 0xc002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
817 { 0xc003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
818 { 0xc004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
819 { 0xc005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
820 { 0xc006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" },
821 { 0xc007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" },
822 { 0xc008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" },
823 { 0xc009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
824 { 0xc00a, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
825 { 0xc00b, "TLS_ECDH_RSA_WITH_NULL_SHA" },
826 { 0xc00c, "TLS_ECDH_RSA_WITH_RC4_128_SHA" },
827 { 0xc00d, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" },
828 { 0xc00e, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" },
829 { 0xc00f, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" },
830 { 0xc010, "TLS_ECDHE_RSA_WITH_NULL_SHA" },
831 { 0xc011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" },
832 { 0xc012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" },
833 { 0xc013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
834 { 0xc014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
835 { 0xc015, "TLS_ECDH_anon_WITH_NULL_SHA" },
836 { 0xc016, "TLS_ECDH_anon_WITH_RC4_128_SHA" },
837 { 0xc017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" },
838 { 0xc018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" },
839 { 0xc019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" },
842 { 0xC01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" },
843 { 0xC01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" },
844 { 0xC01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" },
845 { 0xC01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" },
846 { 0xC01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" },
847 { 0xC01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" },
848 { 0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
849 { 0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
850 { 0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
853 { 0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" },
854 { 0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" },
855 { 0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" },
856 { 0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" },
857 { 0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" },
858 { 0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" },
859 { 0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" },
860 { 0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" },
861 { 0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
862 { 0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
863 { 0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" },
864 { 0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" },
865 { 0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
866 { 0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
867 { 0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" },
868 { 0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" },
871 { 0xC033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" },
872 { 0xC034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" },
873 { 0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" },
874 { 0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" },
875 { 0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" },
876 { 0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" },
877 { 0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA" },
878 { 0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" },
879 { 0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" },
882 { 0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256" },
883 { 0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384" },
884 { 0xC03E, "TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256" },
885 { 0xC03F, "TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384" },
886 { 0xC040, "TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256" },
887 { 0xC041, "TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384" },
888 { 0xC042, "TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256" },
889 { 0xC043, "TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384" },
890 { 0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256" },
891 { 0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384" },
892 { 0xC046, "TLS_DH_anon_WITH_ARIA_128_CBC_SHA256" },
893 { 0xC047, "TLS_DH_anon_WITH_ARIA_256_CBC_SHA384" },
894 { 0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256" },
895 { 0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384" },
896 { 0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256" },
897 { 0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384" },
898 { 0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256" },
899 { 0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384" },
900 { 0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256" },
901 { 0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384" },
902 { 0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256" },
903 { 0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384" },
904 { 0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256" },
905 { 0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384" },
906 { 0xC054, "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256" },
907 { 0xC055, "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384" },
908 { 0xC056, "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256" },
909 { 0xC057, "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384" },
910 { 0xC058, "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256" },
911 { 0xC059, "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384" },
912 { 0xC05A, "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256" },
913 { 0xC05B, "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384" },
914 { 0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256" },
915 { 0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384" },
916 { 0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256" },
917 { 0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384" },
918 { 0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256" },
919 { 0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384" },
920 { 0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256" },
921 { 0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384" },
922 { 0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256" },
923 { 0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384" },
924 { 0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256" },
925 { 0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384" },
926 { 0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256" },
927 { 0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384" },
928 { 0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256" },
929 { 0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384" },
930 { 0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256" },
931 { 0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384" },
932 { 0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256" },
933 { 0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384" },
934 { 0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256" },
935 { 0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384" },
938 { 0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" },
939 { 0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" },
940 { 0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" },
941 { 0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" },
942 { 0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
943 { 0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384" },
944 { 0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
945 { 0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384" },
946 { 0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
947 { 0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
948 { 0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
949 { 0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
950 { 0xC07E, "TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
951 { 0xC07F, "TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
952 { 0xC080, "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256" },
953 { 0xC081, "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384" },
954 { 0xC082, "TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256" },
955 { 0xC083, "TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384" },
956 { 0xC084, "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256" },
957 { 0xC085, "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384" },
958 { 0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" },
959 { 0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" },
960 { 0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" },
961 { 0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" },
962 { 0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
963 { 0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
964 { 0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
965 { 0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
966 { 0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
967 { 0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
968 { 0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
969 { 0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
970 { 0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
971 { 0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
972 { 0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
973 { 0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
974 { 0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
975 { 0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
976 { 0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
977 { 0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
978 { 0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
979 { 0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
982 { 0xC09C, "TLS_RSA_WITH_AES_128_CCM" },
983 { 0xC09D, "TLS_RSA_WITH_AES_256_CCM" },
984 { 0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM" },
985 { 0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM" },
986 { 0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8" },
987 { 0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8" },
988 { 0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8" },
989 { 0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8" },
990 { 0xC0A4, "TLS_PSK_WITH_AES_128_CCM" },
991 { 0xC0A5, "TLS_PSK_WITH_AES_256_CCM" },
992 { 0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM" },
993 { 0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM" },
994 { 0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8" },
995 { 0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8" },
996 { 0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8" },
997 { 0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8" },
1000 { 0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM" },
1001 { 0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM" },
1002 { 0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" },
1003 { 0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8" },
1005 0xC0,0xAB-FF Unassigned
1006 0xC1-FD,* Unassigned
1007 0xFE,0x00-FD Unassigned
1008 0xFE,0xFE-FF Reserved to avoid conflicts with widely deployed implementations [Pasi_Eronen]
1009 0xFF,0x00-FF Reserved for Private Use [RFC5246]
1012 /* old numbers used in the beginning
1013 * http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 */
1014 { 0xCC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1015 { 0xCC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
1016 { 0xCC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1018 /* http://tools.ietf.org/html/draft-ietf-tls-chacha20-poly1305 */
1019 { 0xCCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1020 { 0xCCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
1021 { 0xCCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1022 { 0xCCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1023 { 0xCCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1024 { 0xCCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1025 { 0xCCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1027 /* http://tools.ietf.org/html/draft-josefsson-salsa20-tls */
1028 { 0xE410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1029 { 0xE411, "TLS_RSA_WITH_SALSA20_SHA1" },
1030 { 0xE412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1031 { 0xE413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" },
1032 { 0xE414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" },
1033 { 0xE415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" },
1034 { 0xE416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1035 { 0xE417, "TLS_PSK_WITH_SALSA20_SHA1" },
1036 { 0xE418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1037 { 0xE419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" },
1038 { 0xE41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1039 { 0xE41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" },
1040 { 0xE41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1041 { 0xE41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" },
1042 { 0xE41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1043 { 0xE41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" },
1045 /* these from http://www.mozilla.org/projects/
1046 security/pki/nss/ssl/fips-ssl-ciphersuites.html */
1047 { 0xfefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
1048 { 0xfeff, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
1049 { 0xffe0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
1050 { 0xffe1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
1051 /* note that ciphersuites 0xff00 - 0xffff are private */
1055 value_string_ext ssl_31_ciphersuite_ext = VALUE_STRING_EXT_INIT(ssl_31_ciphersuite);
1058 const value_string pct_msg_types[] = {
1059 { PCT_MSG_CLIENT_HELLO, "Client Hello" },
1060 { PCT_MSG_SERVER_HELLO, "Server Hello" },
1061 { PCT_MSG_CLIENT_MASTER_KEY, "Client Master Key" },
1062 { PCT_MSG_SERVER_VERIFY, "Server Verify" },
1063 { PCT_MSG_ERROR, "Error" },
1067 const value_string pct_cipher_type[] = {
1068 { PCT_CIPHER_DES, "DES" },
1069 { PCT_CIPHER_IDEA, "IDEA" },
1070 { PCT_CIPHER_RC2, "RC2" },
1071 { PCT_CIPHER_RC4, "RC4" },
1072 { PCT_CIPHER_DES_112, "DES 112 bit" },
1073 { PCT_CIPHER_DES_168, "DES 168 bit" },
1077 const value_string pct_hash_type[] = {
1078 { PCT_HASH_MD5, "MD5" },
1079 { PCT_HASH_MD5_TRUNC_64, "MD5_TRUNC_64"},
1080 { PCT_HASH_SHA, "SHA"},
1081 { PCT_HASH_SHA_TRUNC_80, "SHA_TRUNC_80"},
1082 { PCT_HASH_DES_DM, "DES_DM"},
1086 const value_string pct_cert_type[] = {
1087 { PCT_CERT_NONE, "None" },
1088 { PCT_CERT_X509, "X.509" },
1089 { PCT_CERT_PKCS7, "PKCS #7" },
1092 const value_string pct_sig_type[] = {
1093 { PCT_SIG_NONE, "None" },
1094 { PCT_SIG_RSA_MD5, "MD5" },
1095 { PCT_SIG_RSA_SHA, "RSA SHA" },
1096 { PCT_SIG_DSA_SHA, "DSA SHA" },
1100 const value_string pct_exch_type[] = {
1101 { PCT_EXCH_RSA_PKCS1, "RSA PKCS#1" },
1102 { PCT_EXCH_RSA_PKCS1_TOKEN_DES, "RSA PKCS#1 Token DES" },
1103 { PCT_EXCH_RSA_PKCS1_TOKEN_DES3, "RSA PKCS#1 Token 3DES" },
1104 { PCT_EXCH_RSA_PKCS1_TOKEN_RC2, "RSA PKCS#1 Token RC-2" },
1105 { PCT_EXCH_RSA_PKCS1_TOKEN_RC4, "RSA PKCS#1 Token RC-4" },
1106 { PCT_EXCH_DH_PKCS3, "DH PKCS#3" },
1107 { PCT_EXCH_DH_PKCS3_TOKEN_DES, "DH PKCS#3 Token DES" },
1108 { PCT_EXCH_DH_PKCS3_TOKEN_DES3, "DH PKCS#3 Token 3DES" },
1109 { PCT_EXCH_FORTEZZA_TOKEN, "Fortezza" },
1113 const value_string pct_error_code[] = {
1114 { PCT_ERR_BAD_CERTIFICATE, "PCT_ERR_BAD_CERTIFICATE" },
1115 { PCT_ERR_CLIENT_AUTH_FAILED, "PCT_ERR_CLIENT_AUTH_FAILE" },
1116 { PCT_ERR_ILLEGAL_MESSAGE, "PCT_ERR_ILLEGAL_MESSAGE" },
1117 { PCT_ERR_INTEGRITY_CHECK_FAILED, "PCT_ERR_INTEGRITY_CHECK_FAILED" },
1118 { PCT_ERR_SERVER_AUTH_FAILED, "PCT_ERR_SERVER_AUTH_FAILED" },
1119 { PCT_ERR_SPECS_MISMATCH, "PCT_ERR_SPECS_MISMATCH" },
1123 /* http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#tls-extensiontype-values-1 */
1124 const value_string tls_hello_extension_types[] = {
1125 { SSL_HND_HELLO_EXT_SERVER_NAME, "server_name" }, /* RFC 3546 */
1126 { 1, "max_fragment_length" },
1127 { 2, "client_certificate_url" },
1128 { 3, "trusted_ca_keys" },
1129 { 4, "truncated_hmac" },
1130 { SSL_HND_HELLO_EXT_STATUS_REQUEST, "status_request" }, /* RFC 6066 */
1131 { 6, "user_mapping" }, /* RFC 4681 */
1132 { 7, "client_authz" },
1133 { 8, "server_authz" },
1134 { SSL_HND_HELLO_EXT_CERT_TYPE, "cert_type" }, /* RFC 5081 */
1135 { SSL_HND_HELLO_EXT_ELLIPTIC_CURVES, "elliptic_curves" }, /* RFC 4492 */
1136 { SSL_HND_HELLO_EXT_EC_POINT_FORMATS, "ec_point_formats" }, /* RFC 4492 */
1137 { 12, "srp" }, /* RFC 5054 */
1138 { 13, "signature_algorithms" }, /* RFC 5246 */
1140 { SSL_HND_HELLO_EXT_HEARTBEAT, "Heartbeat" }, /* RFC 6520 */
1141 { SSL_HND_HELLO_EXT_ALPN, "Application Layer Protocol Negotiation" }, /* RFC 7301 */
1142 { SSL_HND_HELLO_EXT_STATUS_REQUEST_V2, "status_request_v2" }, /* RFC 6961 */
1143 { 18, "signed_certificate_timestamp" }, /* RFC 6962 */
1144 { SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE, "client_certificate_type" }, /* RFC 7250 */
1145 { SSL_HND_HELLO_EXT_SERVER_CERT_TYPE, "server_certificate_type" }, /* RFC 7250 */
1146 { SSL_HND_HELLO_EXT_PADDING, "Padding" }, /* RFC7685 */
1147 { 22, "encrypt then mac" }, /* RFC7366 */
1148 { SSL_HND_HELLO_EXT_EXTENDED_MASTER_SECRET_TYPE, "Extended Master Secret" }, /* RFC7627 */
1149 { 24, "token binding" }, /* https://tools.ietf.org/html/draft-ietf-tokbind-negotiation */
1150 { SSL_HND_HELLO_EXT_SESSION_TICKET, "SessionTicket TLS" }, /* RFC 4507 */
1151 { SSL_HND_HELLO_EXT_NPN, "next_protocol_negotiation"}, /* http://technotes.googlecode.com/git/nextprotoneg.html */
1152 { SSL_HND_HELLO_EXT_RENEG_INFO, "renegotiation_info" }, /* RFC 5746 */
1153 /* http://tools.ietf.org/html/draft-balfanz-tls-channelid-00
1154 https://twitter.com/ericlaw/status/274237352531083264 */
1155 { SSL_HND_HELLO_EXT_CHANNEL_ID_OLD, "channel_id_old" },
1156 /* http://tools.ietf.org/html/draft-balfanz-tls-channelid-01
1157 https://code.google.com/p/chromium/codesearch#chromium/src/net/third_party/nss/ssl/sslt.h&l=209 */
1158 { SSL_HND_HELLO_EXT_CHANNEL_ID, "channel_id" },
1162 const value_string tls_hello_ext_server_name_type_vs[] = {
1167 /* RFC 5246 7.4.1.4.1 */
1168 const value_string tls_hash_algorithm[] = {
1179 const value_string tls_signature_algorithm[] = {
1188 const value_string tls_certificate_type[] = {
1191 { SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY, "Raw Public Key" }, /* RFC 7250 */
1195 const value_string tls_cert_chain_type[] = {
1196 { SSL_HND_CERT_URL_TYPE_INDIVIDUAL_CERT, "Individual Certificates" },
1197 { SSL_HND_CERT_URL_TYPE_PKIPATH, "PKI Path" },
1201 const value_string tls_cert_status_type[] = {
1202 { SSL_HND_CERT_STATUS_TYPE_OCSP, "OCSP" },
1203 { SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI, "OCSP Multi" },
1207 /* string_string is inappropriate as it compares strings while
1208 * "byte strings MUST NOT be truncated" (RFC 7301) */
1209 typedef struct ssl_alpn_protocol {
1210 const guint8 *proto_name;
1211 size_t proto_name_len;
1212 const char *dissector_name;
1213 } ssl_alpn_protocol_t;
1214 /* http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids */
1215 static const ssl_alpn_protocol_t ssl_alpn_protocols[] = {
1216 { "http/1.1", sizeof("http/1.1"), "http" },
1217 /* SPDY moves so fast, just 1, 2 and 3 are registered with IANA but there
1218 * already exists 3.1 as of this writing... match the prefix. */
1219 { "spdy/", sizeof("spdy/") - 1, "spdy" },
1220 { "stun.turn", sizeof("stun.turn"), "turnchannel" },
1221 { "stun.nat-discovery", sizeof("stun.nat-discovery"), "stun" },
1222 /* draft-ietf-httpbis-http2-16 */
1223 { "h2-", sizeof("h2-") - 1, "http2" }, /* draft versions */
1224 { "h2", sizeof("h2"), "http2" }, /* final version */
1227 /* Lookup tables }}} */
1229 /* we keep this internal to packet-ssl-utils, as there should be
1230 no need to access it any other way.
1232 This also allows us to hide the dependency on zlib.
1234 struct _SslDecompress {
1241 /* To assist in parsing client/server key exchange messages
1242 0 indicates unknown */
1243 gint ssl_get_keyex_alg(gint cipher)
1245 /* Map Cipher suite number to Key Exchange algorithm {{{ */
1370 return KEX_ECDH_ANON;
1384 return KEX_ECDH_ECDSA;
1398 return KEX_ECDH_RSA;
1418 return KEX_ECDHE_ECDSA;
1432 return KEX_ECDHE_PSK;
1448 return KEX_ECDHE_RSA;
1552 return KEX_SRP_SHA_DSS;
1556 return KEX_SRP_SHA_RSA;
1566 /* StringInfo structure (len + data) functions {{{ */
1569 ssl_data_alloc(StringInfo* str, size_t len)
1571 str->data = (guchar *)g_malloc(len);
1572 /* the allocator can return a null pointer for a size equal to 0,
1573 * and that must be allowed */
1574 if (len > 0 && !str->data)
1576 str->data_len = (guint) len;
1581 ssl_data_set(StringInfo* str, const guchar* data, guint len)
1583 DISSECTOR_ASSERT(data);
1584 memcpy(str->data, data, len);
1585 str->data_len = len;
1588 #ifdef HAVE_LIBGCRYPT
1590 ssl_data_realloc(StringInfo* str, guint len)
1592 str->data = (guchar *)g_realloc(str->data, len);
1595 str->data_len = len;
1600 ssl_data_clone(StringInfo *str)
1602 StringInfo *cloned_str;
1603 cloned_str = (StringInfo *) wmem_alloc0(wmem_file_scope(),
1604 sizeof(StringInfo) + str->data_len);
1605 cloned_str->data = (guchar *) (cloned_str + 1);
1606 ssl_data_set(cloned_str, str->data, str->data_len);
1611 ssl_data_copy(StringInfo* dst, StringInfo* src)
1613 if (dst->data_len < src->data_len) {
1614 if (ssl_data_realloc(dst, src->data_len))
1617 memcpy(dst->data, src->data, src->data_len);
1618 dst->data_len = src->data_len;
1623 /* from_hex converts |hex_len| bytes of hex data from |in| and sets |*out| to
1624 * the result. |out->data| will be allocated using wmem_file_scope. Returns TRUE on
1626 static gboolean from_hex(StringInfo* out, const char* in, gsize hex_len) {
1632 out->data = (guchar *)wmem_alloc(wmem_file_scope(), hex_len / 2);
1633 for (i = 0; i < hex_len / 2; i++) {
1634 int a = ws_xton(in[i*2]);
1635 int b = ws_xton(in[i*2 + 1]);
1636 if (a == -1 || b == -1)
1638 out->data[i] = a << 4 | b;
1640 out->data_len = (guint)hex_len / 2;
1643 /* StringInfo structure (len + data) functions }}} */
1646 #ifdef HAVE_LIBGCRYPT
1648 /* libgcrypt wrappers for HMAC/message digest operations {{{ */
1649 /* hmac abstraction layer */
1650 #define SSL_HMAC gcry_md_hd_t
1653 ssl_hmac_init(SSL_HMAC* md, const void * key, gint len, gint algo)
1656 const char *err_str, *err_src;
1658 err = gcry_md_open(md,algo, GCRY_MD_FLAG_HMAC);
1660 err_str = gcry_strerror(err);
1661 err_src = gcry_strsource(err);
1662 ssl_debug_printf("ssl_hmac_init(): gcry_md_open failed %s/%s", err_str, err_src);
1665 gcry_md_setkey (*(md), key, len);
1669 ssl_hmac_update(SSL_HMAC* md, const void* data, gint len)
1671 gcry_md_write(*(md), data, len);
1674 ssl_hmac_final(SSL_HMAC* md, guchar* data, guint* datalen)
1679 algo = gcry_md_get_algo (*(md));
1680 len = gcry_md_get_algo_dlen(algo);
1681 DISSECTOR_ASSERT(len <= *datalen);
1682 memcpy(data, gcry_md_read(*(md), algo), len);
1686 ssl_hmac_cleanup(SSL_HMAC* md)
1688 gcry_md_close(*(md));
1691 /* message digest abstraction layer*/
1692 #define SSL_MD gcry_md_hd_t
1695 ssl_md_init(SSL_MD* md, gint algo)
1698 const char *err_str, *err_src;
1699 err = gcry_md_open(md,algo, 0);
1701 err_str = gcry_strerror(err);
1702 err_src = gcry_strsource(err);
1703 ssl_debug_printf("ssl_md_init(): gcry_md_open failed %s/%s", err_str, err_src);
1709 ssl_md_update(SSL_MD* md, guchar* data, gint len)
1711 gcry_md_write(*(md), data, len);
1714 ssl_md_final(SSL_MD* md, guchar* data, guint* datalen)
1718 algo = gcry_md_get_algo (*(md));
1719 len = gcry_md_get_algo_dlen (algo);
1720 memcpy(data, gcry_md_read(*(md), algo), len);
1724 ssl_md_cleanup(SSL_MD* md)
1726 gcry_md_close(*(md));
1729 /* md5 /sha abstraction layer */
1730 #define SSL_SHA_CTX gcry_md_hd_t
1731 #define SSL_MD5_CTX gcry_md_hd_t
1734 ssl_sha_init(SSL_SHA_CTX* md)
1736 gcry_md_open(md,GCRY_MD_SHA1, 0);
1739 ssl_sha_update(SSL_SHA_CTX* md, guchar* data, gint len)
1741 gcry_md_write(*(md), data, len);
1744 ssl_sha_final(guchar* buf, SSL_SHA_CTX* md)
1746 memcpy(buf, gcry_md_read(*(md), GCRY_MD_SHA1),
1747 gcry_md_get_algo_dlen(GCRY_MD_SHA1));
1750 ssl_sha_cleanup(SSL_SHA_CTX* md)
1752 gcry_md_close(*(md));
1756 ssl_md5_init(SSL_MD5_CTX* md)
1758 return gcry_md_open(md,GCRY_MD_MD5, 0);
1761 ssl_md5_update(SSL_MD5_CTX* md, guchar* data, gint len)
1763 gcry_md_write(*(md), data, len);
1766 ssl_md5_final(guchar* buf, SSL_MD5_CTX* md)
1768 memcpy(buf, gcry_md_read(*(md), GCRY_MD_MD5),
1769 gcry_md_get_algo_dlen(GCRY_MD_MD5));
1772 ssl_md5_cleanup(SSL_MD5_CTX* md)
1774 gcry_md_close(*(md));
1776 /* libgcrypt wrappers for HMAC/message digest operations }}} */
1778 /* libgcrypt wrappers for Cipher state manipulation {{{ */
1780 ssl_cipher_setiv(SSL_CIPHER_CTX *cipher, guchar* iv, gint iv_len)
1787 c=(gcry_cipher_hd_t)*cipher;
1789 ssl_debug_printf("--------------------------------------------------------------------");
1791 for(ivp=c->iv,i=0; i < iv_len; i++ )
1793 ssl_debug_printf("%d ",ivp[i]);
1797 ssl_debug_printf("--------------------------------------------------------------------");
1798 ret = gcry_cipher_setiv(*(cipher), iv, iv_len);
1800 for(ivp=c->iv,i=0; i < iv_len; i++ )
1802 ssl_debug_printf("%d ",ivp[i]);
1806 ssl_debug_printf("--------------------------------------------------------------------");
1809 /* stream cipher abstraction layer*/
1811 ssl_cipher_init(gcry_cipher_hd_t *cipher, gint algo, guchar* sk,
1812 guchar* iv, gint mode)
1814 gint gcry_modes[]={GCRY_CIPHER_MODE_STREAM,GCRY_CIPHER_MODE_CBC,GCRY_CIPHER_MODE_CTR,GCRY_CIPHER_MODE_CTR,GCRY_CIPHER_MODE_CTR};
1818 *(cipher) = (gcry_cipher_hd_t)-1;
1821 err = gcry_cipher_open(cipher, algo, gcry_modes[mode], 0);
1824 err = gcry_cipher_setkey(*(cipher), sk, gcry_cipher_get_algo_keylen (algo));
1827 err = gcry_cipher_setiv(*(cipher), iv, gcry_cipher_get_algo_blklen (algo));
1833 ssl_cipher_decrypt(gcry_cipher_hd_t *cipher, guchar * out, gint outl,
1834 const guchar * in, gint inl)
1836 if ((*cipher) == (gcry_cipher_hd_t)-1)
1839 memcpy(out, in, outl < inl ? outl : inl);
1842 return gcry_cipher_decrypt ( *(cipher), out, outl, in, inl);
1845 ssl_get_digest_by_name(const gchar*name)
1847 return gcry_md_map_name(name);
1850 ssl_get_cipher_by_name(const gchar* name)
1852 return gcry_cipher_map_name(name);
1856 ssl_cipher_cleanup(gcry_cipher_hd_t *cipher)
1858 if ((*cipher) != (gcry_cipher_hd_t)-1)
1859 gcry_cipher_close(*cipher);
1862 /* libgcrypt wrappers for Cipher state manipulation }}} */
1864 #ifdef HAVE_LIBGNUTLS
1865 /* libgcrypt wrapper to decrypt using a RSA private key {{{ */
1866 /* decrypt data with private key. Store decrypted data directly into input
1869 ssl_private_decrypt(const guint len, guchar* data, gcry_sexp_t pk)
1872 size_t decr_len = 0, i = 0;
1873 gcry_sexp_t s_data = NULL, s_plain = NULL;
1874 gcry_mpi_t encr_mpi = NULL, text = NULL;
1876 /* create mpi representation of encrypted data */
1877 rc = gcry_mpi_scan(&encr_mpi, GCRYMPI_FMT_USG, data, len, NULL);
1879 ssl_debug_printf("pcry_private_decrypt: can't convert data to mpi (size %d):%s\n",
1880 len, gcry_strerror(rc));
1884 /* put the data into a simple list */
1885 rc = gcry_sexp_build(&s_data, NULL, "(enc-val(rsa(a%m)))", encr_mpi);
1887 ssl_debug_printf("pcry_private_decrypt: can't build encr_sexp:%s\n",
1893 /* pass it to libgcrypt */
1894 rc = gcry_pk_decrypt(&s_plain, s_data, pk);
1897 ssl_debug_printf("pcry_private_decrypt: can't decrypt key:%s\n",
1903 /* convert plain text sexp to mpi format */
1904 text = gcry_sexp_nth_mpi(s_plain, 0, 0);
1906 ssl_debug_printf("pcry_private_decrypt: can't convert sexp to mpi\n");
1911 /* compute size requested for plaintext buffer */
1912 rc = gcry_mpi_print(GCRYMPI_FMT_USG, NULL, 0, &decr_len, text);
1914 ssl_debug_printf("pcry_private_decrypt: can't compute decr size:%s\n",
1920 /* sanity check on out buffer */
1921 if (decr_len > len) {
1922 ssl_debug_printf("pcry_private_decrypt: decrypted data is too long ?!? (%" G_GSIZE_MODIFIER "u max %d)\n", decr_len, len);
1927 /* write plain text to newly allocated buffer */
1928 rc = gcry_mpi_print(GCRYMPI_FMT_USG, data, len, &decr_len, text);
1930 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));
1935 ssl_print_data("decrypted_unstrip_pre_master", data, decr_len);
1937 /* strip the padding*/
1939 for (i = 1; i < decr_len; i++) {
1946 ssl_debug_printf("pcry_private_decrypt: stripping %d bytes, decr_len %" G_GSIZE_MODIFIER "u\n", rc, decr_len);
1948 memmove(data, data+rc, decr_len);
1951 gcry_sexp_release(s_data);
1952 gcry_sexp_release(s_plain);
1953 gcry_mpi_release(encr_mpi);
1954 gcry_mpi_release(text);
1955 return (int) decr_len;
1957 #endif /* HAVE_LIBGNUTLS */
1959 #else /* ! HAVE_LIBGCRYPT */
1962 ssl_cipher_setiv(SSL_CIPHER_CTX *cipher _U_, guchar* iv _U_, gint iv_len _U_)
1964 ssl_debug_printf("ssl_cipher_setiv: impossible without gnutls.\n");
1967 #endif /* ! HAVE_LIBGCRYPT */
1970 #ifdef HAVE_LIBGCRYPT /* Save space if decryption is not enabled. */
1972 /* Digests, Ciphers and Cipher Suites registry {{{ */
1973 static const SslDigestAlgo digests[]={
1978 {"Not Applicable", 0},
1981 #define DIGEST_MAX_SIZE 48
1983 /* get index digest index */
1984 static const SslDigestAlgo *
1985 ssl_cipher_suite_dig(SslCipherSuite *cs) {
1986 return &digests[cs->dig - DIG_MD5];
1989 static const gchar *ciphers[]={
1992 "ARCFOUR", /* libgcrypt does not support rc4, but this should be 100% compatible*/
1993 "RFC2268_128", /* libgcrypt name for RC2 with a 128-bit key */
2003 static SslCipherSuite cipher_suites[]={
2004 {0x0001,KEX_RSA, ENC_NULL, 1, 0, 0,DIG_MD5, MODE_STREAM}, /* TLS_RSA_WITH_NULL_MD5 */
2005 {0x0002,KEX_RSA, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_RSA_WITH_NULL_SHA */
2006 {0x0003,KEX_RSA, ENC_RC4, 1,128, 40,DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT_WITH_RC4_40_MD5 */
2007 {0x0004,KEX_RSA, ENC_RC4, 1,128,128,DIG_MD5, MODE_STREAM}, /* TLS_RSA_WITH_RC4_128_MD5 */
2008 {0x0005,KEX_RSA, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_RSA_WITH_RC4_128_SHA */
2009 {0x0006,KEX_RSA, ENC_RC2, 8,128, 40,DIG_MD5, MODE_CBC }, /* TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 */
2010 {0x0007,KEX_RSA, ENC_IDEA, 8,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_IDEA_CBC_SHA */
2011 {0x0008,KEX_RSA, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_RSA_EXPORT_WITH_DES40_CBC_SHA */
2012 {0x0009,KEX_RSA, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_DES_CBC_SHA */
2013 {0x000A,KEX_RSA, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_3DES_EDE_CBC_SHA */
2014 {0x000B,KEX_DH_DSS, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA */
2015 {0x000C,KEX_DH_DSS, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_DES_CBC_SHA */
2016 {0x000D,KEX_DH_DSS, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA */
2017 {0x000E,KEX_DH_RSA, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA */
2018 {0x000F,KEX_DH_RSA, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_DES_CBC_SHA */
2019 {0x0010,KEX_DH_RSA, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA */
2020 {0x0011,KEX_DHE_DSS, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA */
2021 {0x0012,KEX_DHE_DSS, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_DES_CBC_SHA */
2022 {0x0013,KEX_DHE_DSS, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA */
2023 {0x0014,KEX_DHE_RSA, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA */
2024 {0x0015,KEX_DHE_RSA, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_DES_CBC_SHA */
2025 {0x0016,KEX_DHE_RSA, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */
2026 {0x0017,KEX_DH_ANON, ENC_RC4, 1,128, 40,DIG_MD5, MODE_STREAM}, /* TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 */
2027 {0x0018,KEX_DH_ANON, ENC_RC4, 1,128,128,DIG_MD5, MODE_STREAM}, /* TLS_DH_anon_WITH_RC4_128_MD5 */
2028 {0x0019,KEX_DH_ANON, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA */
2029 {0x001A,KEX_DH_ANON, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_DES_CBC_SHA */
2030 {0x001B,KEX_DH_ANON, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_3DES_EDE_CBC_SHA */
2031 {0x002C,KEX_PSK, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA */
2032 {0x002D,KEX_DHE_PSK, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA */
2033 {0x002E,KEX_RSA_PSK, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA */
2034 {0x002F,KEX_RSA, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_AES_128_CBC_SHA */
2035 {0x0030,KEX_DH_DSS, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_128_CBC_SHA */
2036 {0x0031,KEX_DH_RSA, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_128_CBC_SHA */
2037 {0x0032,KEX_DHE_DSS, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_128_CBC_SHA */
2038 {0x0033,KEX_DHE_RSA, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
2039 {0x0034,KEX_DH_ANON, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_AES_128_CBC_SHA */
2040 {0x0035,KEX_RSA, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_AES_256_CBC_SHA */
2041 {0x0036,KEX_DH_DSS, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_256_CBC_SHA */
2042 {0x0037,KEX_DH_RSA, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_256_CBC_SHA */
2043 {0x0038,KEX_DHE_DSS, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_256_CBC_SHA */
2044 {0x0039,KEX_DHE_RSA, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */
2045 {0x003A,KEX_DH_ANON, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_AES_256_CBC_SHA */
2046 {0x003B,KEX_RSA, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_RSA_WITH_NULL_SHA256 */
2047 {0x003C,KEX_RSA, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_AES_128_CBC_SHA256 */
2048 {0x003D,KEX_RSA, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_AES_256_CBC_SHA256 */
2049 {0x003E,KEX_DH_DSS, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_128_CBC_SHA256 */
2050 {0x003F,KEX_DH_RSA, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_128_CBC_SHA256 */
2051 {0x0040,KEX_DHE_DSS, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 */
2052 {0x0041,KEX_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */
2053 {0x0042,KEX_DH_DSS, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA */
2054 {0x0043,KEX_DH_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA */
2055 {0x0044,KEX_DHE_DSS, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA */
2056 {0x0045,KEX_DHE_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */
2057 {0x0046,KEX_DH_ANON, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA */
2058 {0x0060,KEX_RSA, ENC_RC4, 1,128, 56,DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC4_56_MD5 */
2059 {0x0061,KEX_RSA, ENC_RC2, 1,128, 56,DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 */
2060 {0x0062,KEX_RSA, ENC_DES, 8, 64, 56,DIG_SHA, MODE_CBC }, /* TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA */
2061 {0x0063,KEX_DHE_DSS, ENC_DES, 8, 64, 56,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA */
2062 {0x0064,KEX_RSA, ENC_RC4, 1,128, 56,DIG_SHA, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC4_56_SHA */
2063 {0x0065,KEX_DHE_DSS, ENC_RC4, 1,128, 56,DIG_SHA, MODE_STREAM}, /* TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA */
2064 {0x0066,KEX_DHE_DSS, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_DHE_DSS_WITH_RC4_128_SHA */
2065 {0x0067,KEX_DHE_RSA, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */
2066 {0x0068,KEX_DH_DSS, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_256_CBC_SHA256 */
2067 {0x0069,KEX_DH_RSA, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_256_CBC_SHA256 */
2068 {0x006A,KEX_DHE_DSS, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 */
2069 {0x006B,KEX_DHE_RSA, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */
2070 {0x006C,KEX_DH_ANON, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_AES_128_CBC_SHA256 */
2071 {0x006D,KEX_DH_ANON, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_AES_256_CBC_SHA256 */
2072 {0x0084,KEX_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */
2073 {0x0085,KEX_DH_DSS, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA */
2074 {0x0086,KEX_DH_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA */
2075 {0x0087,KEX_DHE_DSS, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA */
2076 {0x0088,KEX_DHE_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */
2077 {0x0089,KEX_DH_ANON, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA */
2078 {0x008A,KEX_PSK, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_PSK_WITH_RC4_128_SHA */
2079 {0x008B,KEX_PSK, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_3DES_EDE_CBC_SHA */
2080 {0x008C,KEX_PSK, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_AES_128_CBC_SHA */
2081 {0x008D,KEX_PSK, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_AES_256_CBC_SHA */
2082 {0x008E,KEX_DHE_PSK, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_DHE_PSK_WITH_RC4_128_SHA */
2083 {0x008F,KEX_DHE_PSK, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA */
2084 {0x0090,KEX_DHE_PSK, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA */
2085 {0x0091,KEX_DHE_PSK, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA */
2086 {0x0092,KEX_RSA_PSK, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_RSA_PSK_WITH_RC4_128_SHA */
2087 {0x0093,KEX_RSA_PSK, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA */
2088 {0x0094,KEX_RSA_PSK, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_128_CBC_SHA */
2089 {0x0095,KEX_RSA_PSK, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_256_CBC_SHA */
2090 {0x0096,KEX_RSA, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_SEED_CBC_SHA */
2091 {0x0097,KEX_DH_DSS, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_SEED_CBC_SHA */
2092 {0x0098,KEX_DH_RSA, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_SEED_CBC_SHA */
2093 {0x0099,KEX_DHE_DSS, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_SEED_CBC_SHA */
2094 {0x009A,KEX_DHE_RSA, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_SEED_CBC_SHA */
2095 {0x009B,KEX_DH_ANON, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_SEED_CBC_SHA */
2096 {0x009C,KEX_RSA, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_WITH_AES_128_GCM_SHA256 */
2097 {0x009D,KEX_RSA, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_WITH_AES_256_GCM_SHA384 */
2098 {0x009E,KEX_DHE_RSA, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */
2099 {0x009F,KEX_DHE_RSA, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */
2100 {0x00A0,KEX_DH_RSA, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_RSA_WITH_AES_128_GCM_SHA256 */
2101 {0x00A1,KEX_DH_RSA, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_RSA_WITH_AES_256_GCM_SHA384 */
2102 {0x00A2,KEX_DHE_DSS, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 */
2103 {0x00A3,KEX_DHE_DSS, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 */
2104 {0x00A4,KEX_DH_DSS, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_DSS_WITH_AES_128_GCM_SHA256 */
2105 {0x00A5,KEX_DH_DSS, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_DSS_WITH_AES_256_GCM_SHA384 */
2106 {0x00A6,KEX_DH_ANON, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_anon_WITH_AES_128_GCM_SHA256 */
2107 {0x00A7,KEX_DH_ANON, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */
2108 {0x00A8,KEX_PSK, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_PSK_WITH_AES_128_GCM_SHA256 */
2109 {0x00A9,KEX_PSK, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_PSK_WITH_AES_256_GCM_SHA384 */
2110 {0x00AA,KEX_DHE_PSK, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */
2111 {0x00AB,KEX_DHE_PSK, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */
2112 {0x00AC,KEX_RSA_PSK, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 */
2113 {0x00AD,KEX_RSA_PSK, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 */
2114 {0x00AE,KEX_PSK, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_PSK_WITH_AES_128_CBC_SHA256 */
2115 {0x00AF,KEX_PSK, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_PSK_WITH_AES_256_CBC_SHA384 */
2116 {0x00B0,KEX_PSK, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA256 */
2117 {0x00B1,KEX_PSK, ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA384 */
2118 {0x00B2,KEX_DHE_PSK, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */
2119 {0x00B3,KEX_DHE_PSK, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */
2120 {0x00B4,KEX_DHE_PSK, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA256 */
2121 {0x00B5,KEX_DHE_PSK, ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA384 */
2122 {0x00B6,KEX_RSA_PSK, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 */
2123 {0x00B7,KEX_RSA_PSK, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 */
2124 {0x00B8,KEX_RSA_PSK, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA256 */
2125 {0x00B9,KEX_RSA_PSK, ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA384 */
2126 {0x00BA,KEX_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2127 {0x00BB,KEX_DH_DSS, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 */
2128 {0x00BC,KEX_DH_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2129 {0x00BD,KEX_DHE_DSS, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 */
2130 {0x00BE,KEX_DHE_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2131 {0x00BF,KEX_DH_ANON, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256 */
2132 {0x00C0,KEX_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
2133 {0x00C1,KEX_DH_DSS, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 */
2134 {0x00C2,KEX_DH_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
2135 {0x00C3,KEX_DHE_DSS, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 */
2136 {0x00C4,KEX_DHE_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
2137 {0x00C5,KEX_DH_ANON, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 */
2138 {0xC001,KEX_ECDH_ECDSA, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_ECDSA_WITH_NULL_SHA */
2139 {0xC002,KEX_ECDH_ECDSA, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */
2140 {0xC003,KEX_ECDH_ECDSA, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */
2141 {0xC004,KEX_ECDH_ECDSA, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */
2142 {0xC005,KEX_ECDH_ECDSA, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */
2143 {0xC006,KEX_ECDHE_ECDSA, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */
2144 {0xC007,KEX_ECDHE_ECDSA, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */
2145 {0xC008,KEX_ECDHE_ECDSA, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */
2146 {0xC009,KEX_ECDHE_ECDSA, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */
2147 {0xC00A,KEX_ECDHE_ECDSA, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */
2148 {0xC00B,KEX_ECDH_RSA, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_RSA_WITH_NULL_SHA */
2149 {0xC00C,KEX_ECDH_RSA, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_RSA_WITH_RC4_128_SHA */
2150 {0xC00D,KEX_ECDH_RSA, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */
2151 {0xC00E,KEX_ECDH_RSA, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */
2152 {0xC00F,KEX_ECDH_RSA, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */
2153 {0xC010,KEX_ECDHE_RSA, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_RSA_WITH_NULL_SHA */
2154 {0xC011,KEX_ECDHE_RSA, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */
2155 {0xC012,KEX_ECDHE_RSA, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */
2156 {0xC013,KEX_ECDHE_RSA, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */
2157 {0xC014,KEX_ECDHE_RSA, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */
2158 {0xC015,KEX_ECDH_ANON, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_anon_WITH_NULL_SHA */
2159 {0xC016,KEX_ECDH_ANON, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_anon_WITH_RC4_128_SHA */
2160 {0xC017,KEX_ECDH_ANON, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA */
2161 {0xC018,KEX_ECDH_ANON, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_AES_128_CBC_SHA */
2162 {0xC019,KEX_ECDH_ANON, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_AES_256_CBC_SHA */
2163 {0xC023,KEX_ECDHE_ECDSA, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 */
2164 {0xC024,KEX_ECDHE_ECDSA, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 */
2165 {0xC025,KEX_ECDH_ECDSA, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */
2166 {0xC026,KEX_ECDH_ECDSA, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */
2167 {0xC027,KEX_ECDHE_RSA, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */
2168 {0xC028,KEX_ECDHE_RSA, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */
2169 {0xC029,KEX_ECDH_RSA, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */
2170 {0xC02A,KEX_ECDH_RSA, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */
2171 {0xC02B,KEX_ECDHE_ECDSA, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */
2172 {0xC02C,KEX_ECDHE_ECDSA, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */
2173 {0xC02D,KEX_ECDH_ECDSA, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */
2174 {0xC02E,KEX_ECDH_ECDSA, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */
2175 {0xC02F,KEX_ECDHE_RSA, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */
2176 {0xC030,KEX_ECDHE_RSA, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */
2177 {0xC031,KEX_ECDH_RSA, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */
2178 {0xC032,KEX_ECDH_RSA, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */
2179 {0xC033,KEX_ECDHE_PSK, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_RC4_128_SHA */
2180 {0xC034,KEX_ECDHE_PSK, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA */
2181 {0xC035,KEX_ECDHE_PSK, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA */
2182 {0xC036,KEX_ECDHE_PSK, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA */
2183 {0xC037,KEX_ECDHE_PSK, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */
2184 {0xC038,KEX_ECDHE_PSK, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 */
2185 {0xC039,KEX_ECDHE_PSK, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA */
2186 {0xC03A,KEX_ECDHE_PSK, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */
2187 {0xC03B,KEX_ECDHE_PSK, ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA384 */
2188 {0xC072,KEX_ECDHE_ECDSA, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */
2189 {0xC073,KEX_ECDHE_ECDSA, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 */
2190 {0xC074,KEX_ECDH_ECDSA, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */
2191 {0xC075,KEX_ECDH_ECDSA, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 */
2192 {0xC076,KEX_ECDHE_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2193 {0xC077,KEX_ECDHE_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 */
2194 {0xC078,KEX_ECDH_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2195 {0xC079,KEX_ECDH_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 */
2196 {0xC07A,KEX_RSA, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2197 {0xC07B,KEX_RSA, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2198 {0xC07C,KEX_DHE_RSA, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2199 {0xC07D,KEX_DHE_RSA, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2200 {0xC07E,KEX_DH_RSA, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2201 {0xC07F,KEX_DH_RSA, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2202 {0xC080,KEX_DHE_DSS, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256 */
2203 {0xC081,KEX_DHE_DSS, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384 */
2204 {0xC082,KEX_DH_DSS, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256 */
2205 {0xC083,KEX_DH_DSS, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384 */
2206 {0xC084,KEX_DH_ANON, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256 */
2207 {0xC085,KEX_DH_ANON, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384 */
2208 {0xC086,KEX_ECDHE_ECDSA, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 */
2209 {0xC087,KEX_ECDHE_ECDSA, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */
2210 {0xC088,KEX_ECDH_ECDSA, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 */
2211 {0xC089,KEX_ECDH_ECDSA, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */
2212 {0xC08A,KEX_ECDHE_RSA, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2213 {0xC08B,KEX_ECDHE_RSA, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2214 {0xC08C,KEX_ECDH_RSA, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2215 {0xC08D,KEX_ECDH_RSA, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2216 {0xC08E,KEX_PSK, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2217 {0xC08F,KEX_PSK, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2218 {0xC090,KEX_DHE_PSK, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2219 {0xC091,KEX_DHE_PSK, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2220 {0xC092,KEX_RSA_PSK, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2221 {0xC093,KEX_RSA_PSK, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2222 {0xC094,KEX_PSK, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2223 {0xC095,KEX_PSK, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2224 {0xC096,KEX_DHE_PSK, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2225 {0xC097,KEX_DHE_PSK, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2226 {0xC098,KEX_RSA_PSK, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2227 {0xC099,KEX_RSA_PSK, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2228 {0xC09A,KEX_ECDHE_PSK, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2229 {0xC09B,KEX_ECDHE_PSK, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2230 {0xC09C,KEX_RSA, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_RSA_WITH_AES_128_CCM */
2231 {0xC09D,KEX_RSA, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_RSA_WITH_AES_256_CCM */
2232 {0xC09E,KEX_DHE_RSA, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_DHE_RSA_WITH_AES_128_CCM */
2233 {0xC09F,KEX_DHE_RSA, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_DHE_RSA_WITH_AES_256_CCM */
2234 {0xC0A0,KEX_RSA, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_RSA_WITH_AES_128_CCM_8 */
2235 {0xC0A1,KEX_RSA, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_RSA_WITH_AES_256_CCM_8 */
2236 {0xC0A2,KEX_DHE_RSA, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_DHE_RSA_WITH_AES_128_CCM_8 */
2237 {0xC0A3,KEX_DHE_RSA, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_DHE_RSA_WITH_AES_256_CCM_8 */
2238 {0xC0A4,KEX_PSK, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_PSK_WITH_AES_128_CCM */
2239 {0xC0A5,KEX_PSK, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_PSK_WITH_AES_256_CCM */
2240 {0xC0A6,KEX_DHE_PSK, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_DHE_PSK_WITH_AES_128_CCM */
2241 {0xC0A7,KEX_DHE_PSK, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_DHE_PSK_WITH_AES_256_CCM */
2242 {0xC0A8,KEX_PSK, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_WITH_AES_128_CCM_8 */
2243 {0xC0A9,KEX_PSK, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_WITH_AES_256_CCM_8 */
2244 {0xC0AA,KEX_DHE_PSK, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_DHE_WITH_AES_128_CCM_8 */
2245 {0xC0AB,KEX_DHE_PSK, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_DHE_WITH_AES_256_CCM_8 */
2246 {0xC0AC,KEX_ECDHE_ECDSA, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */
2247 {0xC0AD,KEX_ECDHE_ECDSA, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM */
2248 {0xC0AE,KEX_ECDHE_ECDSA, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */
2249 {0xC0AF,KEX_ECDHE_ECDSA, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */
2250 {-1, 0, 0, 0, 0, 0,0, MODE_STREAM}
2253 #define MAX_BLOCK_SIZE 16
2254 #define MAX_KEY_SIZE 32
2257 ssl_find_cipher(int num,SslCipherSuite* cs)
2261 for(c=cipher_suites;c->number!=-1;c++){
2270 #else /* ! HAVE_LIBGCRYPT */
2272 ssl_find_cipher(int num,SslCipherSuite* cs)
2274 ssl_debug_printf("ssl_find_cipher: dummy without gnutls. num %d cs %p\n",
2278 #endif /* ! HAVE_LIBGCRYPT */
2280 /* Digests, Ciphers and Cipher Suites registry }}} */
2283 #ifdef HAVE_LIBGCRYPT
2285 /* HMAC and the Pseudorandom function {{{ */
2287 tls_hash(StringInfo *secret, StringInfo *seed, gint md,
2288 StringInfo *out, guint out_len)
2290 /* RFC 2246 5. HMAC and the pseudorandom function
2291 * '+' denotes concatenation.
2292 * P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
2293 * HMAC_hash(secret, A(2) + seed) + ...
2295 * A(i) = HMAC_hash(secret, A(i - 1))
2300 guint8 _A[DIGEST_MAX_SIZE], tmp[DIGEST_MAX_SIZE];
2307 ssl_print_string("tls_hash: hash secret", secret);
2308 ssl_print_string("tls_hash: hash seed", seed);
2311 A_l = seed->data_len;
2314 /* A(i) = HMAC_hash(secret, A(i-1)) */
2315 ssl_hmac_init(&hm, secret->data, secret->data_len, md);
2316 ssl_hmac_update(&hm, A, A_l);
2317 A_l = sizeof(_A); /* upper bound len for hash output */
2318 ssl_hmac_final(&hm, _A, &A_l);
2319 ssl_hmac_cleanup(&hm);
2322 /* HMAC_hash(secret, A(i) + seed) */
2323 ssl_hmac_init(&hm, secret->data, secret->data_len, md);
2324 ssl_hmac_update(&hm, A, A_l);
2325 ssl_hmac_update(&hm, seed->data, seed->data_len);
2326 tmp_l = sizeof(tmp); /* upper bound len for hash output */
2327 ssl_hmac_final(&hm, tmp, &tmp_l);
2328 ssl_hmac_cleanup(&hm);
2330 /* ssl_hmac_final puts the actual digest output size in tmp_l */
2331 tocpy = MIN(left, tmp_l);
2332 memcpy(ptr, tmp, tocpy);
2336 out->data_len = out_len;
2338 ssl_print_string("hash out", out);
2342 tls_prf(StringInfo* secret, const gchar *usage,
2343 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, guint out_len)
2345 StringInfo seed, sha_out, md5_out;
2349 size_t usage_len, rnd2_len;
2350 gboolean success = FALSE;
2351 usage_len = strlen(usage);
2352 rnd2_len = rnd2 ? rnd2->data_len : 0;
2354 /* initalize buffer for sha, md5 random seed*/
2355 if (ssl_data_alloc(&sha_out, MAX(out_len, 20)) < 0) {
2356 ssl_debug_printf("tls_prf: can't allocate sha out\n");
2359 if (ssl_data_alloc(&md5_out, MAX(out_len, 16)) < 0) {
2360 ssl_debug_printf("tls_prf: can't allocate md5 out\n");
2363 if (ssl_data_alloc(&seed, usage_len+rnd1->data_len+rnd2_len) < 0) {
2364 ssl_debug_printf("tls_prf: can't allocate rnd %d\n",
2365 (int) (usage_len+rnd1->data_len+rnd2_len));
2370 memcpy(ptr,usage,usage_len);
2372 memcpy(ptr,rnd1->data,rnd1->data_len);
2374 ptr+=rnd1->data_len;
2375 memcpy(ptr,rnd2->data,rnd2->data_len);
2376 /*ptr+=rnd2->data_len;*/
2379 /* initalize buffer for client/server seeds*/
2380 s_l=secret->data_len/2 + secret->data_len%2;
2381 if (ssl_data_alloc(&s1, s_l) < 0) {
2382 ssl_debug_printf("tls_prf: can't allocate secret %d\n", s_l);
2385 if (ssl_data_alloc(&s2, s_l) < 0) {
2386 ssl_debug_printf("tls_prf: can't allocate secret(2) %d\n", s_l);
2390 memcpy(s1.data,secret->data,s_l);
2391 memcpy(s2.data,secret->data + (secret->data_len - s_l),s_l);
2393 ssl_debug_printf("tls_prf: tls_hash(md5 secret_len %d seed_len %d )\n", s1.data_len, seed.data_len);
2394 tls_hash(&s1, &seed, ssl_get_digest_by_name("MD5"), &md5_out, out_len);
2395 ssl_debug_printf("tls_prf: tls_hash(sha)\n");
2396 tls_hash(&s2, &seed, ssl_get_digest_by_name("SHA1"), &sha_out, out_len);
2398 for (i = 0; i < out_len; i++)
2399 out->data[i] = md5_out.data[i] ^ sha_out.data[i];
2400 /* success, now store the new meaningful data length */
2401 out->data_len = out_len;
2404 ssl_print_string("PRF out",out);
2411 g_free(md5_out.data);
2413 g_free(sha_out.data);
2418 tls12_prf(gint md, StringInfo* secret, const gchar* usage,
2419 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, guint out_len)
2421 StringInfo label_seed;
2422 size_t usage_len, rnd2_len;
2423 rnd2_len = rnd2 ? rnd2->data_len : 0;
2425 usage_len = strlen(usage);
2426 if (ssl_data_alloc(&label_seed, usage_len+rnd1->data_len+rnd2_len) < 0) {
2427 ssl_debug_printf("tls12_prf: can't allocate label_seed\n");
2430 memcpy(label_seed.data, usage, usage_len);
2431 memcpy(label_seed.data+usage_len, rnd1->data, rnd1->data_len);
2433 memcpy(label_seed.data+usage_len+rnd1->data_len, rnd2->data, rnd2->data_len);
2435 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);
2436 tls_hash(secret, &label_seed, md, out, out_len);
2437 g_free(label_seed.data);
2438 ssl_print_string("PRF out", out);
2443 ssl3_generate_export_iv(StringInfo *r1, StringInfo *r2,
2444 StringInfo *out, guint out_len)
2450 ssl_md5_update(&md5,r1->data,r1->data_len);
2451 ssl_md5_update(&md5,r2->data,r2->data_len);
2452 ssl_md5_final(tmp,&md5);
2453 ssl_md5_cleanup(&md5);
2455 DISSECTOR_ASSERT(out_len <= sizeof(tmp));
2456 ssl_data_set(out, tmp, out_len);
2457 ssl_print_string("export iv", out);
2461 ssl3_prf(StringInfo* secret, const gchar* usage,
2462 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, guint out_len)
2470 for (off = 0; off < out_len; off += 16) {
2474 ssl_debug_printf("ssl3_prf: sha1_hash(%d)\n",i);
2475 /* A, BB, CCC, ... */
2481 ssl_sha_update(&sha,buf,i);
2482 ssl_sha_update(&sha,secret->data,secret->data_len);
2484 if(!strcmp(usage,"client write key") || !strcmp(usage,"server write key")){
2486 ssl_sha_update(&sha,rnd2->data,rnd2->data_len);
2487 ssl_sha_update(&sha,rnd1->data,rnd1->data_len);
2490 ssl_sha_update(&sha,rnd1->data,rnd1->data_len);
2492 ssl_sha_update(&sha,rnd2->data,rnd2->data_len);
2495 ssl_sha_final(buf,&sha);
2496 ssl_sha_cleanup(&sha);
2498 ssl_debug_printf("ssl3_prf: md5_hash(%d) datalen %d\n",i,
2501 ssl_md5_update(&md5,secret->data,secret->data_len);
2502 ssl_md5_update(&md5,buf,20);
2503 ssl_md5_final(outbuf,&md5);
2504 ssl_md5_cleanup(&md5);
2506 memcpy(out->data + off, outbuf, MIN(out_len - off, 16));
2508 out->data_len = out_len;
2513 /* out_len is the wanted output length for the pseudorandom function */
2515 prf(SslDecryptSession *ssl, StringInfo *secret, const gchar *usage,
2516 StringInfo *rnd1, StringInfo *rnd2, StringInfo *out, guint out_len)
2518 switch (ssl->session.version) {
2520 return ssl3_prf(secret, usage, rnd1, rnd2, out, out_len);
2523 case TLSV1DOT1_VERSION:
2524 case DTLSV1DOT0_VERSION:
2525 case DTLSV1DOT0_OPENSSL_VERSION:
2526 return tls_prf(secret, usage, rnd1, rnd2, out, out_len);
2528 default: /* TLSv1.2 */
2529 switch (ssl->cipher_suite.dig) {
2531 return tls12_prf(GCRY_MD_SHA384, secret, usage, rnd1, rnd2,
2534 return tls12_prf(GCRY_MD_SHA256, secret, usage, rnd1, rnd2,
2540 static gint tls_handshake_hash(SslDecryptSession* ssl, StringInfo* out)
2545 if (ssl_data_alloc(out, 36) < 0)
2549 ssl_md5_update(&md5,ssl->handshake_data.data,ssl->handshake_data.data_len);
2550 ssl_md5_final(out->data,&md5);
2551 ssl_md5_cleanup(&md5);
2554 ssl_sha_update(&sha,ssl->handshake_data.data,ssl->handshake_data.data_len);
2555 ssl_sha_final(out->data+16,&sha);
2556 ssl_sha_cleanup(&sha);
2560 static gint tls12_handshake_hash(SslDecryptSession* ssl, gint md, StringInfo* out)
2566 ssl_md_init(&mc, md);
2567 ssl_md_update(&mc,ssl->handshake_data.data,ssl->handshake_data.data_len);
2568 ssl_md_final(&mc, tmp, &len);
2569 ssl_md_cleanup(&mc);
2571 if (ssl_data_alloc(out, len) < 0)
2573 memcpy(out->data, tmp, len);
2576 /* HMAC and the Pseudorandom function }}} */
2578 #else /* ! HAVE_LIBGCRYPT */
2579 /* Stub code when decryption support is not available. {{{ */
2581 ssl_generate_pre_master_secret(SslDecryptSession *ssl_session _U_,
2582 guint32 length _U_, tvbuff_t *tvb _U_, guint32 offset _U_,
2583 const gchar *ssl_psk _U_, const ssl_master_key_map_t *mk_map _U_)
2585 ssl_debug_printf("%s: impossible without gnutls.\n", G_STRFUNC);
2589 ssl_generate_keyring_material(SslDecryptSession*ssl)
2591 ssl_debug_printf("ssl_generate_keyring_material: impossible without gnutls. ssl %p\n",
2596 ssl_change_cipher(SslDecryptSession *ssl_session, gboolean server)
2598 ssl_debug_printf("ssl_change_cipher %s: makes no sense without gnutls. ssl %p\n",
2599 (server)?"SERVER":"CLIENT", ssl_session);
2603 ssl_decrypt_record(SslDecryptSession*ssl, SslDecoder* decoder, gint ct,
2604 const guchar* in, guint inl, StringInfo* comp_str _U_, StringInfo* out, guint* outl)
2606 ssl_debug_printf("ssl_decrypt_record: impossible without gnutls. ssl %p"
2607 "decoder %p ct %d, in %p inl %d out %p outl %p\n", ssl, decoder, ct,
2608 in, inl, out, outl);
2612 #endif /* ! HAVE_LIBGCRYPT */
2614 #ifdef HAVE_LIBGCRYPT
2615 /* Record Decompression (after decryption) {{{ */
2617 /* memory allocation functions for zlib initialization */
2618 static void* ssl_zalloc(void* opaque _U_, unsigned int no, unsigned int size)
2620 return g_malloc0(no*size);
2622 static void ssl_zfree(void* opaque _U_, void* addr)
2628 static SslDecompress*
2629 ssl_create_decompressor(gint compression)
2631 SslDecompress *decomp;
2636 if (compression == 0) return NULL;
2637 ssl_debug_printf("ssl_create_decompressor: compression method %d\n", compression);
2638 decomp = (SslDecompress *)wmem_alloc(wmem_file_scope(), sizeof(SslDecompress));
2639 decomp->compression = compression;
2640 switch (decomp->compression) {
2642 case 1: /* DEFLATE */
2643 decomp->istream.zalloc = ssl_zalloc;
2644 decomp->istream.zfree = ssl_zfree;
2645 decomp->istream.opaque = Z_NULL;
2646 decomp->istream.next_in = Z_NULL;
2647 decomp->istream.next_out = Z_NULL;
2648 decomp->istream.avail_in = 0;
2649 decomp->istream.avail_out = 0;
2650 err = inflateInit_(&decomp->istream, ZLIB_VERSION, sizeof(z_stream));
2652 ssl_debug_printf("ssl_create_decompressor: inflateInit_() failed - %d\n", err);
2658 ssl_debug_printf("ssl_create_decompressor: unsupported compression method %d\n", decomp->compression);
2666 ssl_decompress_record(SslDecompress* decomp, const guchar* in, guint inl, StringInfo* out_str, guint* outl)
2670 switch (decomp->compression) {
2671 case 1: /* DEFLATE */
2673 if (out_str->data_len < 16384) { /* maximal plain length */
2674 ssl_data_realloc(out_str, 16384);
2677 decomp->istream.next_in = in;
2680 decomp->istream.next_in = (Bytef *)in;
2683 decomp->istream.avail_in = inl;
2684 decomp->istream.next_out = out_str->data;
2685 decomp->istream.avail_out = out_str->data_len;
2687 err = inflate(&decomp->istream, Z_SYNC_FLUSH);
2689 ssl_debug_printf("ssl_decompress_record: inflate() failed - %d\n", err);
2692 *outl = out_str->data_len - decomp->istream.avail_out;
2695 ssl_debug_printf("ssl_decompress_record: unsupported compression method %d\n", decomp->compression);
2702 ssl_decompress_record(SslDecompress* decomp _U_, const guchar* in _U_, guint inl _U_, StringInfo* out_str _U_, guint* outl _U_)
2704 ssl_debug_printf("ssl_decompress_record: unsupported compression method %d\n", decomp->compression);
2708 /* Record Decompression (after decryption) }}} */
2709 #endif /* HAVE_LIBGCRYPT */
2711 #ifdef HAVE_LIBGCRYPT
2712 /* Create a new structure to store decrypted chunks. {{{ */
2714 ssl_create_flow(void)
2718 flow = (SslFlow *)wmem_alloc(wmem_file_scope(), sizeof(SslFlow));
2721 flow->multisegment_pdus = wmem_tree_new(wmem_file_scope());
2726 /* Use the negotiated security parameters for decryption. {{{ */
2728 ssl_change_cipher(SslDecryptSession *ssl_session, gboolean server)
2730 ssl_debug_printf("ssl_change_cipher %s\n", (server)?"SERVER":"CLIENT");
2732 ssl_session->server = ssl_session->server_new;
2733 ssl_session->server_new = NULL;
2735 ssl_session->client = ssl_session->client_new;
2736 ssl_session->client_new = NULL;
2741 /* Init cipher state given some security parameters. {{{ */
2743 ssl_create_decoder(SslCipherSuite *cipher_suite, gint compression,
2744 guint8 *mk, guint8 *sk, guint8 *iv)
2749 dec = (SslDecoder *)wmem_alloc0(wmem_file_scope(), sizeof(SslDecoder));
2750 /* Find the SSLeay cipher */
2751 if(cipher_suite->enc!=ENC_NULL) {
2752 ssl_debug_printf("ssl_create_decoder CIPHER: %s\n", ciphers[cipher_suite->enc-0x30]);
2753 ciph=ssl_get_cipher_by_name(ciphers[cipher_suite->enc-0x30]);
2755 ssl_debug_printf("ssl_create_decoder CIPHER: %s\n", "NULL");
2759 ssl_debug_printf("ssl_create_decoder can't find cipher %s\n",
2760 ciphers[cipher_suite->enc > ENC_NULL ? ENC_NULL-0x30 : (cipher_suite->enc-0x30)]);
2764 /* init mac buffer: mac storage is embedded into decoder struct to save a
2765 memory allocation and waste samo more memory*/
2766 dec->cipher_suite=cipher_suite;
2767 dec->compression = compression;
2768 /* AEED ciphers require a write IV (iv) and do not use MAC keys (mk).
2769 * All other ciphers require a MAC key. As a special case, allow omission
2770 * for the NULL cipher such that record payloads can still be dissected. */
2772 dec->mac_key.data = dec->_mac_key_or_write_iv;
2773 ssl_data_set(&dec->mac_key, mk, ssl_cipher_suite_dig(cipher_suite)->len);
2774 } else if (iv != NULL) {
2775 dec->write_iv.data = dec->_mac_key_or_write_iv;
2776 ssl_data_set(&dec->write_iv, iv, cipher_suite->block);
2778 DISSECTOR_ASSERT(cipher_suite->enc == ENC_NULL);
2781 dec->decomp = ssl_create_decompressor(compression);
2782 dec->flow = ssl_create_flow();
2785 ssl_cipher_cleanup(&dec->evp);
2787 if (ssl_cipher_init(&dec->evp,ciph,sk,iv,cipher_suite->mode) < 0) {
2788 ssl_debug_printf("ssl_create_decoder: can't create cipher id:%d mode:%d\n",
2789 ciph, cipher_suite->mode);
2793 ssl_debug_printf("decoder initialized (digest len %d)\n", ssl_cipher_suite_dig(cipher_suite)->len);
2798 /* (Pre-)master secrets calculations {{{ */
2799 #ifdef HAVE_LIBGNUTLS
2801 ssl_decrypt_pre_master_secret(SslDecryptSession *ssl_session,
2802 StringInfo *encrypted_pre_master,
2804 #endif /* HAVE_LIBGNUTLS */
2807 ssl_restore_master_key(SslDecryptSession *ssl, const char *label,
2808 gboolean is_pre_master, GHashTable *ht, StringInfo *key);
2811 ssl_generate_pre_master_secret(SslDecryptSession *ssl_session,
2812 guint32 length, tvbuff_t *tvb, guint32 offset,
2813 const gchar *ssl_psk,
2814 const ssl_master_key_map_t *mk_map)
2816 /* check for required session data */
2817 ssl_debug_printf("%s: found SSL_HND_CLIENT_KEY_EXCHG, state %X\n",
2818 G_STRFUNC, ssl_session->state);
2819 if ((ssl_session->state & (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION)) !=
2820 (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION)) {
2821 ssl_debug_printf("%s: not enough data to generate key (required state %X)\n", G_STRFUNC,
2822 (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION));
2826 /* check to see if the PMS was provided to us*/
2827 if (ssl_restore_master_key(ssl_session, "Unencrypted pre-master secret", TRUE,
2828 mk_map->pms, &ssl_session->client_random)) {
2832 if (ssl_session->cipher_suite.kex == KEX_PSK)
2834 /* calculate pre master secret*/
2835 StringInfo pre_master_secret;
2836 guint psk_len, pre_master_len;
2838 if (!ssl_psk || (ssl_psk[0] == 0)) {
2839 ssl_debug_printf("%s: can't find pre-shared-key\n", G_STRFUNC);
2843 /* convert hex string into char*/
2844 if (!from_hex(&ssl_session->psk, ssl_psk, strlen(ssl_psk))) {
2845 ssl_debug_printf("%s: ssl.psk/dtls.psk contains invalid hex\n",
2850 psk_len = ssl_session->psk.data_len;
2851 if (psk_len >= (2 << 15)) {
2852 ssl_debug_printf("%s: ssl.psk/dtls.psk must not be larger than 2^15 - 1\n",
2858 pre_master_len = psk_len * 2 + 4;
2860 pre_master_secret.data = (guchar *)wmem_alloc(wmem_file_scope(), pre_master_len);
2861 pre_master_secret.data_len = pre_master_len;
2862 /* 2 bytes psk_len*/
2863 pre_master_secret.data[0] = psk_len >> 8;
2864 pre_master_secret.data[1] = psk_len & 0xFF;
2865 /* psk_len bytes times 0*/
2866 memset(&pre_master_secret.data[2], 0, psk_len);
2867 /* 2 bytes psk_len*/
2868 pre_master_secret.data[psk_len + 2] = psk_len >> 8;
2869 pre_master_secret.data[psk_len + 3] = psk_len & 0xFF;
2871 memcpy(&pre_master_secret.data[psk_len + 4], ssl_session->psk.data, psk_len);
2873 ssl_session->pre_master_secret.data = pre_master_secret.data;
2874 ssl_session->pre_master_secret.data_len = pre_master_len;
2875 /*ssl_debug_printf("pre master secret",&ssl->pre_master_secret);*/
2877 /* Remove the master secret if it was there.
2878 This forces keying material regeneration in
2879 case we're renegotiating */
2880 ssl_session->state &= ~(SSL_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
2881 ssl_session->state |= SSL_PRE_MASTER_SECRET;
2886 StringInfo encrypted_pre_master;
2887 guint encrlen, skip;
2891 /* get encrypted data, on tls1 we have to skip two bytes
2892 * (it's the encrypted len and should be equal to record len - 2)
2893 * in case of rsa1024 that would be 128 + 2 = 130; for psk not necessary
2895 if (ssl_session->cipher_suite.kex == KEX_RSA &&
2896 (ssl_session->session.version == TLSV1_VERSION ||
2897 ssl_session->session.version == TLSV1DOT1_VERSION ||
2898 ssl_session->session.version == TLSV1DOT2_VERSION ||
2899 ssl_session->session.version == DTLSV1DOT0_VERSION ||
2900 ssl_session->session.version == DTLSV1DOT2_VERSION))
2902 encrlen = tvb_get_ntohs(tvb, offset);
2904 if (encrlen > length - 2)
2906 ssl_debug_printf("%s: wrong encrypted length (%d max %d)\n",
2907 G_STRFUNC, encrlen, length);
2911 /* the valid lower bound is higher than 8, but it is sufficient for the
2912 * ssl keylog file below */
2914 ssl_debug_printf("%s: invalid encrypted pre-master key length %d\n",
2915 G_STRFUNC, encrlen);
2919 encrypted_pre_master.data = (guchar *)wmem_alloc(wmem_file_scope(), encrlen);
2920 encrypted_pre_master.data_len = encrlen;
2921 tvb_memcpy(tvb, encrypted_pre_master.data, offset+skip, encrlen);
2923 #ifdef HAVE_LIBGNUTLS
2924 if (ssl_session->private_key) {
2925 /* try to decrypt encrypted pre-master with RSA key */
2926 if (ssl_decrypt_pre_master_secret(ssl_session,
2927 &encrypted_pre_master, ssl_session->private_key))
2930 ssl_debug_printf("%s: can't decrypt pre-master secret\n",
2933 #endif /* HAVE_LIBGNUTLS */
2935 /* try to find the pre-master secret from the encrypted one. The
2936 * ssl key logfile stores only the first 8 bytes, so truncate it */
2937 encrypted_pre_master.data_len = 8;
2938 if (ssl_restore_master_key(ssl_session, "Encrypted pre-master secret",
2939 TRUE, mk_map->pre_master, &encrypted_pre_master))
2946 ssl_generate_keyring_material(SslDecryptSession*ssl_session)
2948 StringInfo key_block = { NULL, 0 };
2949 guint8 _iv_c[MAX_BLOCK_SIZE],_iv_s[MAX_BLOCK_SIZE];
2950 guint8 _key_c[MAX_KEY_SIZE],_key_s[MAX_KEY_SIZE];
2952 guint8 *ptr, *c_iv = _iv_c,*s_iv = _iv_s;
2953 guint8 *c_wk = NULL, *s_wk = NULL, *c_mk = NULL, *s_mk = NULL;
2955 /* check for enough info to proced */
2956 guint need_all = SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION;
2957 guint need_any = SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET;
2958 if (((ssl_session->state & need_all) != need_all) || ((ssl_session->state & need_any) == 0)) {
2959 ssl_debug_printf("ssl_generate_keyring_material not enough data to generate key "
2960 "(0x%02X required 0x%02X or 0x%02X)\n", ssl_session->state,
2961 need_all|SSL_MASTER_SECRET, need_all|SSL_PRE_MASTER_SECRET);
2962 /* Special case: for NULL encryption, allow dissection of data even if
2963 * the Client Hello is missing (MAC keys are now skipped though). */
2964 need_all = SSL_CIPHER|SSL_VERSION;
2965 if ((ssl_session->state & need_all) == need_all &&
2966 ssl_session->cipher_suite.enc == ENC_NULL) {
2967 ssl_debug_printf("%s NULL cipher found, will create a decoder but "
2968 "skip MAC validation as keys are missing.\n", G_STRFUNC);
2969 goto create_decoders;
2975 /* if master key is not available, generate is from the pre-master secret */
2976 if (!(ssl_session->state & SSL_MASTER_SECRET)) {
2977 if ((ssl_session->state & SSL_EXTENDED_MASTER_SECRET_MASK) == SSL_EXTENDED_MASTER_SECRET_MASK) {
2978 StringInfo handshake_hashed_data;
2981 handshake_hashed_data.data = NULL;
2982 handshake_hashed_data.data_len = 0;
2984 ssl_debug_printf("%s:PRF(pre_master_secret_extended)\n", G_STRFUNC);
2985 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
2986 DISSECTOR_ASSERT(ssl_session->handshake_data.data_len > 0);
2988 switch(ssl_session->session.version) {
2990 case TLSV1DOT1_VERSION:
2991 case DTLSV1DOT0_VERSION:
2992 case DTLSV1DOT0_OPENSSL_VERSION:
2993 ret = tls_handshake_hash(ssl_session, &handshake_hashed_data);
2996 switch (ssl_session->cipher_suite.dig) {
2998 ret = tls12_handshake_hash(ssl_session, GCRY_MD_SHA384, &handshake_hashed_data);
3001 ret = tls12_handshake_hash(ssl_session, GCRY_MD_SHA256, &handshake_hashed_data);
3007 ssl_debug_printf("%s can't generate handshake hash\n", G_STRFUNC);
3011 wmem_free(wmem_file_scope(), ssl_session->handshake_data.data);
3012 ssl_session->handshake_data.data = NULL;
3013 ssl_session->handshake_data.data_len = 0;
3015 if (!prf(ssl_session, &ssl_session->pre_master_secret, "extended master secret",
3016 &handshake_hashed_data,
3017 NULL, &ssl_session->master_secret,
3018 SSL_MASTER_SECRET_LENGTH)) {
3019 ssl_debug_printf("%s can't generate master_secret\n", G_STRFUNC);
3020 g_free(handshake_hashed_data.data);
3023 g_free(handshake_hashed_data.data);
3025 ssl_debug_printf("%s:PRF(pre_master_secret)\n", G_STRFUNC);
3026 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
3027 ssl_print_string("client random",&ssl_session->client_random);
3028 ssl_print_string("server random",&ssl_session->server_random);
3029 if (!prf(ssl_session, &ssl_session->pre_master_secret, "master secret",
3030 &ssl_session->client_random,
3031 &ssl_session->server_random, &ssl_session->master_secret,
3032 SSL_MASTER_SECRET_LENGTH)) {
3033 ssl_debug_printf("%s can't generate master_secret\n", G_STRFUNC);
3037 ssl_print_string("master secret",&ssl_session->master_secret);
3039 /* the pre-master secret has been 'consumend' so we must clear it now */
3040 ssl_session->state &= ~SSL_PRE_MASTER_SECRET;
3041 ssl_session->state |= SSL_MASTER_SECRET;
3044 /* Compute the key block. First figure out how much data we need*/
3045 needed=ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len*2;
3046 needed+=ssl_session->cipher_suite.bits / 4;
3047 if(ssl_session->cipher_suite.block>1)
3048 needed+=ssl_session->cipher_suite.block*2;
3050 key_block.data = (guchar *)g_malloc(needed);
3051 ssl_debug_printf("%s sess key generation\n", G_STRFUNC);
3052 if (!prf(ssl_session, &ssl_session->master_secret, "key expansion",
3053 &ssl_session->server_random,&ssl_session->client_random,
3054 &key_block, needed)) {
3055 ssl_debug_printf("%s can't generate key_block\n", G_STRFUNC);
3058 ssl_print_string("key expansion", &key_block);
3061 /* AEAD ciphers do not have a separate MAC */
3062 if (ssl_session->cipher_suite.mode == MODE_GCM ||
3063 ssl_session->cipher_suite.mode == MODE_CCM ||
3064 ssl_session->cipher_suite.mode == MODE_CCM_8) {
3067 c_mk=ptr; ptr+=ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len;
3068 s_mk=ptr; ptr+=ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len;
3071 c_wk=ptr; ptr+=ssl_session->cipher_suite.eff_bits/8;
3072 s_wk=ptr; ptr+=ssl_session->cipher_suite.eff_bits/8;
3074 if(ssl_session->cipher_suite.block>1){
3075 c_iv=ptr; ptr+=ssl_session->cipher_suite.block;
3076 s_iv=ptr; /*ptr+=ssl_session->cipher_suite.block;*/
3079 /* export ciphers work with a smaller key length */
3080 if (ssl_session->cipher_suite.eff_bits < ssl_session->cipher_suite.bits) {
3081 if(ssl_session->cipher_suite.block>1){
3083 /* We only have room for MAX_BLOCK_SIZE bytes IVs, but that's
3084 all we should need. This is a sanity check */
3085 if(ssl_session->cipher_suite.block>MAX_BLOCK_SIZE) {
3086 ssl_debug_printf("%s cipher suite block must be at most %d nut is %d\n",
3087 G_STRFUNC, MAX_BLOCK_SIZE, ssl_session->cipher_suite.block);
3091 if(ssl_session->session.version==SSLV3_VERSION){
3092 /* The length of these fields are ignored by this caller */
3093 StringInfo iv_c, iv_s;
3097 ssl_debug_printf("%s ssl3_generate_export_iv\n", G_STRFUNC);
3098 ssl3_generate_export_iv(&ssl_session->client_random,
3099 &ssl_session->server_random, &iv_c,
3100 ssl_session->cipher_suite.block);
3101 ssl_debug_printf("%s ssl3_generate_export_iv(2)\n", G_STRFUNC);
3102 ssl3_generate_export_iv(&ssl_session->server_random,
3103 &ssl_session->client_random, &iv_s,
3104 ssl_session->cipher_suite.block);
3107 guint8 _iv_block[MAX_BLOCK_SIZE * 2];
3108 StringInfo iv_block;
3109 StringInfo key_null;
3112 key_null.data = &_key_null;
3113 key_null.data_len = 0;
3115 iv_block.data = _iv_block;
3117 ssl_debug_printf("%s prf(iv_block)\n", G_STRFUNC);
3118 if (!prf(ssl_session, &key_null, "IV block",
3119 &ssl_session->client_random,
3120 &ssl_session->server_random, &iv_block,
3121 ssl_session->cipher_suite.block * 2)) {
3122 ssl_debug_printf("%s can't generate tls31 iv block\n", G_STRFUNC);
3126 memcpy(_iv_c,iv_block.data,ssl_session->cipher_suite.block);
3127 memcpy(_iv_s,iv_block.data+ssl_session->cipher_suite.block,
3128 ssl_session->cipher_suite.block);
3135 if (ssl_session->session.version==SSLV3_VERSION){
3138 ssl_debug_printf("%s MD5(client_random)\n", G_STRFUNC);
3141 ssl_md5_update(&md5,c_wk,ssl_session->cipher_suite.eff_bits/8);
3142 ssl_md5_update(&md5,ssl_session->client_random.data,
3143 ssl_session->client_random.data_len);
3144 ssl_md5_update(&md5,ssl_session->server_random.data,
3145 ssl_session->server_random.data_len);
3146 ssl_md5_final(_key_c,&md5);
3147 ssl_md5_cleanup(&md5);
3151 ssl_debug_printf("%s MD5(server_random)\n", G_STRFUNC);
3152 ssl_md5_update(&md5,s_wk,ssl_session->cipher_suite.eff_bits/8);
3153 ssl_md5_update(&md5,ssl_session->server_random.data,
3154 ssl_session->server_random.data_len);
3155 ssl_md5_update(&md5,ssl_session->client_random.data,
3156 ssl_session->client_random.data_len);
3157 ssl_md5_final(_key_s,&md5);
3158 ssl_md5_cleanup(&md5);
3162 StringInfo key_c, key_s, k;
3163 key_c.data = _key_c;
3164 key_s.data = _key_s;
3167 k.data_len = ssl_session->cipher_suite.eff_bits/8;
3168 ssl_debug_printf("%s PRF(key_c)\n", G_STRFUNC);
3169 if (!prf(ssl_session, &k, "client write key",
3170 &ssl_session->client_random,
3171 &ssl_session->server_random, &key_c, sizeof(_key_c))) {
3172 ssl_debug_printf("%s can't generate tll31 server key \n", G_STRFUNC);
3178 k.data_len = ssl_session->cipher_suite.eff_bits/8;
3179 ssl_debug_printf("%s PRF(key_s)\n", G_STRFUNC);
3180 if (!prf(ssl_session, &k, "server write key",
3181 &ssl_session->client_random,
3182 &ssl_session->server_random, &key_s, sizeof(_key_s))) {
3183 ssl_debug_printf("%s can't generate tll31 client key \n", G_STRFUNC);
3190 /* show key material info */
3192 ssl_print_data("Client MAC key",c_mk,ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len);
3193 ssl_print_data("Server MAC key",s_mk,ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len);
3195 ssl_print_data("Client Write key",c_wk,ssl_session->cipher_suite.bits/8);
3196 ssl_print_data("Server Write key",s_wk,ssl_session->cipher_suite.bits/8);
3198 if(ssl_session->cipher_suite.block>1) {
3199 ssl_print_data("Client Write IV",c_iv,ssl_session->cipher_suite.block);
3200 ssl_print_data("Server Write IV",s_iv,ssl_session->cipher_suite.block);
3203 ssl_print_data("Client Write IV",c_iv,8);
3204 ssl_print_data("Server Write IV",s_iv,8);
3208 /* create both client and server ciphers*/
3209 ssl_debug_printf("%s ssl_create_decoder(client)\n", G_STRFUNC);
3210 ssl_session->client_new = ssl_create_decoder(&ssl_session->cipher_suite, ssl_session->session.compression, c_mk, c_wk, c_iv);
3211 if (!ssl_session->client_new) {
3212 ssl_debug_printf("%s can't init client decoder\n", G_STRFUNC);
3215 ssl_debug_printf("%s ssl_create_decoder(server)\n", G_STRFUNC);
3216 ssl_session->server_new = ssl_create_decoder(&ssl_session->cipher_suite, ssl_session->session.compression, s_mk, s_wk, s_iv);
3217 if (!ssl_session->server_new) {
3218 ssl_debug_printf("%s can't init client decoder\n", G_STRFUNC);
3222 ssl_debug_printf("%s: client seq %d, server seq %d\n",
3223 G_STRFUNC, ssl_session->client_new->seq, ssl_session->server_new->seq);
3224 g_free(key_block.data);
3225 ssl_session->state |= SSL_HAVE_SESSION_KEY;
3229 g_free(key_block.data);
3232 /* (Pre-)master secrets calculations }}} */
3234 #ifdef HAVE_LIBGNUTLS
3235 /* Decrypt RSA pre-master secret using RSA private key. {{{ */
3237 ssl_decrypt_pre_master_secret(SslDecryptSession*ssl_session,
3238 StringInfo* encrypted_pre_master, gcry_sexp_t pk)
3242 if (!encrypted_pre_master)
3245 if (KEX_IS_DH(ssl_session->cipher_suite.kex)) {
3246 ssl_debug_printf("%s: session uses Diffie-Hellman key exchange "
3247 "(cipher suite 0x%04X %s) and cannot be decrypted "
3248 "using a RSA private key file.\n",
3249 G_STRFUNC, ssl_session->session.cipher,
3250 val_to_str_ext_const(ssl_session->session.cipher,
3251 &ssl_31_ciphersuite_ext, "unknown"));
3253 } else if(ssl_session->cipher_suite.kex != KEX_RSA) {
3254 ssl_debug_printf("%s key exchange %d different from KEX_RSA (%d)\n",
3255 G_STRFUNC, ssl_session->cipher_suite.kex, KEX_RSA);
3259 /* with tls key loading will fail if not rsa type, so no need to check*/
3260 ssl_print_string("pre master encrypted",encrypted_pre_master);
3261 ssl_debug_printf("%s: RSA_private_decrypt\n", G_STRFUNC);
3262 i=ssl_private_decrypt(encrypted_pre_master->data_len,
3263 encrypted_pre_master->data, pk);
3266 ssl_debug_printf("%s wrong pre_master_secret length (%d, expected "
3267 "%d)\n", G_STRFUNC, i, 48);
3271 /* the decrypted data has been written into the pre_master key buffer */
3272 ssl_session->pre_master_secret.data = encrypted_pre_master->data;
3273 ssl_session->pre_master_secret.data_len=48;
3274 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
3276 /* Remove the master secret if it was there.
3277 This forces keying material regeneration in
3278 case we're renegotiating */
3279 ssl_session->state &= ~(SSL_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
3280 ssl_session->state |= SSL_PRE_MASTER_SECRET;
3283 #endif /* HAVE_LIBGNUTLS */
3285 /* Decryption integrity check {{{ */
3286 /* convert network byte order 32 byte number to right-aligned host byte order *
3288 static gint fmt_seq(guint32 num, guint8* buf)
3293 netnum=g_htonl(num);
3294 memcpy(buf+4,&netnum,4);
3300 tls_check_mac(SslDecoder*decoder, gint ct, gint ver, guint8* data,
3301 guint32 datalen, guint8* mac)
3306 guint8 buf[DIGEST_MAX_SIZE];
3309 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
3310 ssl_debug_printf("tls_check_mac mac type:%s md %d\n",
3311 ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
3313 if (ssl_hmac_init(&hm,decoder->mac_key.data,decoder->mac_key.data_len,md) != 0)
3316 /* hash sequence number */
3317 fmt_seq(decoder->seq,buf);
3321 ssl_hmac_update(&hm,buf,8);
3323 /* hash content type */
3325 ssl_hmac_update(&hm,buf,1);
3327 /* hash version,data length and data*/
3328 /* *((gint16*)buf) = g_htons(ver); */
3329 temp = g_htons(ver);
3330 memcpy(buf, &temp, 2);
3331 ssl_hmac_update(&hm,buf,2);
3333 /* *((gint16*)buf) = g_htons(datalen); */
3334 temp = g_htons(datalen);
3335 memcpy(buf, &temp, 2);
3336 ssl_hmac_update(&hm,buf,2);
3337 ssl_hmac_update(&hm,data,datalen);
3339 /* get digest and digest len*/
3341 ssl_hmac_final(&hm,buf,&len);
3342 ssl_hmac_cleanup(&hm);
3343 ssl_print_data("Mac", buf, len);
3344 if(memcmp(mac,buf,len))
3351 ssl3_check_mac(SslDecoder*decoder,int ct,guint8* data,
3352 guint32 datalen, guint8* mac)
3357 guint8 buf[64],dgst[20];
3361 pad_ct=(decoder->cipher_suite->dig==DIG_SHA)?40:48;
3363 /* get cipher used for digest comptuation */
3364 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
3365 if (ssl_md_init(&mc,md) !=0)
3368 /* do hash computation on data && padding */
3369 ssl_md_update(&mc,decoder->mac_key.data,decoder->mac_key.data_len);
3372 memset(buf,0x36,pad_ct);
3373 ssl_md_update(&mc,buf,pad_ct);
3375 /* hash sequence number */
3376 fmt_seq(decoder->seq,buf);
3378 ssl_md_update(&mc,buf,8);
3380 /* hash content type */
3382 ssl_md_update(&mc,buf,1);
3384 /* hash data length in network byte order and data*/
3385 /* *((gint16* )buf) = g_htons(datalen); */
3386 temp = g_htons(datalen);
3387 memcpy(buf, &temp, 2);
3388 ssl_md_update(&mc,buf,2);
3389 ssl_md_update(&mc,data,datalen);
3391 /* get partial digest */
3392 ssl_md_final(&mc,dgst,&len);
3393 ssl_md_cleanup(&mc);
3395 ssl_md_init(&mc,md);
3398 ssl_md_update(&mc,decoder->mac_key.data,decoder->mac_key.data_len);
3400 /* hash padding and partial digest*/
3401 memset(buf,0x5c,pad_ct);
3402 ssl_md_update(&mc,buf,pad_ct);
3403 ssl_md_update(&mc,dgst,len);
3405 ssl_md_final(&mc,dgst,&len);
3406 ssl_md_cleanup(&mc);
3408 if(memcmp(mac,dgst,len))
3415 dtls_check_mac(SslDecoder*decoder, gint ct,int ver, guint8* data,
3416 guint32 datalen, guint8* mac)
3421 guint8 buf[DIGEST_MAX_SIZE];
3424 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
3425 ssl_debug_printf("dtls_check_mac mac type:%s md %d\n",
3426 ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
3428 if (ssl_hmac_init(&hm,decoder->mac_key.data,decoder->mac_key.data_len,md) != 0)
3430 ssl_debug_printf("dtls_check_mac seq: %d epoch: %d\n",decoder->seq,decoder->epoch);
3431 /* hash sequence number */
3432 fmt_seq(decoder->seq,buf);
3433 buf[0]=decoder->epoch>>8;
3434 buf[1]=(guint8)decoder->epoch;
3436 ssl_hmac_update(&hm,buf,8);
3438 /* hash content type */
3440 ssl_hmac_update(&hm,buf,1);
3442 /* hash version,data length and data */
3443 temp = g_htons(ver);
3444 memcpy(buf, &temp, 2);
3445 ssl_hmac_update(&hm,buf,2);
3447 temp = g_htons(datalen);
3448 memcpy(buf, &temp, 2);
3449 ssl_hmac_update(&hm,buf,2);
3450 ssl_hmac_update(&hm,data,datalen);
3451 /* get digest and digest len */
3453 ssl_hmac_final(&hm,buf,&len);
3454 ssl_hmac_cleanup(&hm);
3455 ssl_print_data("Mac", buf, len);
3456 if(memcmp(mac,buf,len))
3461 /* Decryption integrity check }}} */
3463 /* Record decryption glue based on security parameters {{{ */
3465 ssl_decrypt_record(SslDecryptSession*ssl,SslDecoder* decoder, gint ct,
3466 const guchar* in, guint inl, StringInfo* comp_str, StringInfo* out_str, guint* outl)
3468 guint pad, worklen, uncomplen;
3471 ssl_debug_printf("ssl_decrypt_record ciphertext len %d\n", inl);
3472 ssl_print_data("Ciphertext",in, inl);
3474 /* ensure we have enough storage space for decrypted data */
3475 if (inl > out_str->data_len)
3477 ssl_debug_printf("ssl_decrypt_record: allocating %d bytes for decrypt data (old len %d)\n",
3478 inl + 32, out_str->data_len);
3479 ssl_data_realloc(out_str, inl + 32);
3482 /* RFC 6101/2246: SSLCipherText/TLSCipherText has two structures for types:
3483 * (notation: { unencrypted, [ encrypted ] })
3484 * GenericStreamCipher: { [content, mac] }
3485 * GenericBlockCipher: { IV (TLS 1.1+), [content, mac, padding, padding_len] }
3486 * RFC 5426 (TLS 1.2): TLSCipherText has additionally:
3487 * GenericAEADCipher: { nonce_explicit, [content] }
3488 * RFC 4347 (DTLS): based on TLS 1.1, only GenericBlockCipher is supported.
3489 * RFC 6347 (DTLS 1.2): based on TLS 1.2, includes GenericAEADCipher too.
3492 /* (TLS 1.1 and later, DTLS) Extract explicit IV for GenericBlockCipher */
3493 if (decoder->cipher_suite->mode == MODE_CBC) {
3494 switch (ssl->session.version) {
3495 case TLSV1DOT1_VERSION:
3496 case TLSV1DOT2_VERSION:
3497 case DTLSV1DOT0_VERSION:
3498 case DTLSV1DOT2_VERSION:
3499 case DTLSV1DOT0_OPENSSL_VERSION:
3500 if ((gint)inl < decoder->cipher_suite->block) {
3501 ssl_debug_printf("ssl_decrypt_record failed: input %d has no space for IV %d\n",
3502 inl, decoder->cipher_suite->block);
3505 pad = gcry_cipher_setiv(decoder->evp, in, decoder->cipher_suite->block);
3507 ssl_debug_printf("ssl_decrypt_record failed: failed to set IV: %s %s\n",
3508 gcry_strsource (pad), gcry_strerror (pad));
3511 inl -= decoder->cipher_suite->block;
3512 in += decoder->cipher_suite->block;
3517 /* Nonce for GenericAEADCipher */
3518 if (decoder->cipher_suite->mode == MODE_GCM ||
3519 decoder->cipher_suite->mode == MODE_CCM ||
3520 decoder->cipher_suite->mode == MODE_CCM_8) {
3521 /* 4 bytes write_iv, 8 bytes explicit_nonce, 4 bytes counter */
3522 guchar gcm_nonce[16] = { 0 };
3524 if ((gint)inl < SSL_EX_NONCE_LEN_GCM) {
3525 ssl_debug_printf("ssl_decrypt_record failed: input %d has no space for nonce %d\n",
3526 inl, SSL_EX_NONCE_LEN_GCM);
3530 if (decoder->cipher_suite->mode == MODE_GCM) {
3531 memcpy(gcm_nonce, decoder->write_iv.data, decoder->write_iv.data_len); /* salt */
3532 memcpy(gcm_nonce + decoder->write_iv.data_len, in, SSL_EX_NONCE_LEN_GCM);
3533 /* NIST SP 800-38D, sect. 7.2 says that the 32-bit counter part starts
3534 * at 1, and gets incremented before passing to the block cipher. */
3535 gcm_nonce[4 + SSL_EX_NONCE_LEN_GCM + 3] = 2;
3536 } else { /* MODE_CCM and MODE_CCM_8 */
3537 /* The nonce for CCM and GCM are the same, but the nonce is used as input
3538 * in the CCM algorithm described in RFC 3610. The nonce generated here is
3539 * the one from RFC 3610 sect 2.3. Encryption. */
3540 /* Flags: (L-1) ; L = 16 - 1 - nonceSize */
3541 gcm_nonce[0] = 3 - 1;
3543 memcpy(gcm_nonce + 1, decoder->write_iv.data, decoder->write_iv.data_len); /* salt */
3544 memcpy(gcm_nonce + 1 + decoder->write_iv.data_len, in, SSL_EX_NONCE_LEN_GCM);
3545 gcm_nonce[4 + SSL_EX_NONCE_LEN_GCM + 3] = 1;
3548 pad = gcry_cipher_setctr (decoder->evp, gcm_nonce, sizeof (gcm_nonce));
3550 ssl_debug_printf("ssl_decrypt_record failed: failed to set CTR: %s %s\n",
3551 gcry_strsource (pad), gcry_strerror (pad));
3554 inl -= SSL_EX_NONCE_LEN_GCM;
3555 in += SSL_EX_NONCE_LEN_GCM;
3559 if ((pad = ssl_cipher_decrypt(&decoder->evp, out_str->data, out_str->data_len, in, inl))!= 0) {
3560 ssl_debug_printf("ssl_decrypt_record failed: ssl_cipher_decrypt: %s %s\n", gcry_strsource (pad),
3561 gcry_strerror (pad));
3565 ssl_print_data("Plaintext", out_str->data, inl);
3568 /* RFC 5116 sect 5.1/5.3: AES128/256 GCM/CCM uses 16 bytes for auth tag
3569 * RFC 6655 sect 6.1: AEAD_AES_128_CCM uses 16 bytes for auth tag */
3570 if (decoder->cipher_suite->mode == MODE_GCM ||
3571 decoder->cipher_suite->mode == MODE_CCM) {
3573 ssl_debug_printf("ssl_decrypt_record failed: missing tag, work %d\n", worklen);
3576 /* XXX - validate auth tag */
3579 /* RFC 6655 sect 6.1: AEAD_AES_128_CCM_8 uses 8 bytes for auth tag */
3580 if (decoder->cipher_suite->mode == MODE_CCM_8) {
3582 ssl_debug_printf("ssl_decrypt_record failed: missing tag, work %d\n", worklen);
3585 /* XXX - validate auth tag */
3589 /* strip padding for GenericBlockCipher */
3590 if (decoder->cipher_suite->mode == MODE_CBC) {
3591 if (inl < 1) { /* Should this check happen earlier? */
3592 ssl_debug_printf("ssl_decrypt_record failed: input length %d too small\n", inl);
3595 pad=out_str->data[inl-1];
3596 if (worklen <= pad) {
3597 ssl_debug_printf("ssl_decrypt_record failed: padding %d too large for work %d\n",
3602 ssl_debug_printf("ssl_decrypt_record found padding %d final len %d\n",
3606 /* MAC for GenericStreamCipher and GenericBlockCipher */
3607 if (decoder->cipher_suite->mode == MODE_STREAM ||
3608 decoder->cipher_suite->mode == MODE_CBC) {
3609 if (ssl_cipher_suite_dig(decoder->cipher_suite)->len > (gint)worklen) {
3610 ssl_debug_printf("ssl_decrypt_record wrong record len/padding outlen %d\n work %d\n",*outl, worklen);
3613 worklen-=ssl_cipher_suite_dig(decoder->cipher_suite)->len;
3614 mac = out_str->data + worklen;
3615 } else /* if (decoder->cipher_suite->mode == MODE_GCM) */ {
3616 /* GenericAEADCipher has no MAC */
3620 /* If NULL encryption active and no keys are available, do not bother
3621 * checking the MAC. We do not have keys for that. */
3622 if (decoder->cipher_suite->mode == MODE_STREAM &&
3623 decoder->cipher_suite->enc == ENC_NULL &&
3624 !(ssl->state & SSL_MASTER_SECRET)) {
3625 ssl_debug_printf("MAC check skipped due to missing keys\n");
3629 /* Now check the MAC */
3630 ssl_debug_printf("checking mac (len %d, version %X, ct %d seq %d)\n",
3631 worklen, ssl->session.version, ct, decoder->seq);
3632 if(ssl->session.version==SSLV3_VERSION){
3633 if(ssl3_check_mac(decoder,ct,out_str->data,worklen,mac) < 0) {
3634 if(ssl_ignore_mac_failed) {
3635 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
3638 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
3643 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
3646 else if(ssl->session.version==TLSV1_VERSION || ssl->session.version==TLSV1DOT1_VERSION || ssl->session.version==TLSV1DOT2_VERSION){
3647 if(tls_check_mac(decoder,ct,ssl->session.version,out_str->data,worklen,mac)< 0) {
3648 if(ssl_ignore_mac_failed) {
3649 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
3652 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
3657 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
3660 else if(ssl->session.version==DTLSV1DOT0_VERSION ||
3661 ssl->session.version==DTLSV1DOT2_VERSION ||
3662 ssl->session.version==DTLSV1DOT0_OPENSSL_VERSION){
3663 /* Try rfc-compliant mac first, and if failed, try old openssl's non-rfc-compliant mac */
3664 if(dtls_check_mac(decoder,ct,ssl->session.version,out_str->data,worklen,mac)>= 0) {
3665 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
3667 else if(tls_check_mac(decoder,ct,TLSV1_VERSION,out_str->data,worklen,mac)>= 0) {
3668 ssl_debug_printf("ssl_decrypt_record: dtls rfc-compliant mac failed, but old openssl's non-rfc-compliant mac ok\n");
3670 else if(ssl_ignore_mac_failed) {
3671 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
3674 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
3682 if (decoder->compression > 0) {
3683 ssl_debug_printf("ssl_decrypt_record: compression method %d\n", decoder->compression);
3684 ssl_data_copy(comp_str, out_str);
3685 ssl_print_data("Plaintext compressed", comp_str->data, worklen);
3686 if (!decoder->decomp) {
3687 ssl_debug_printf("decrypt_ssl3_record: no decoder available\n");
3690 if (ssl_decompress_record(decoder->decomp, comp_str->data, worklen, out_str, &uncomplen) < 0) return -1;
3691 ssl_print_data("Plaintext uncompressed", out_str->data, uncomplen);
3697 /* Record decryption glue based on security parameters }}} */
3699 #endif /* HAVE_LIBGCRYPT */
3702 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
3703 /* RSA private key file processing {{{ */
3706 ssl_privkey_to_sexp(gnutls_x509_privkey_t priv_key)
3708 gnutls_datum_t rsa_datum[RSA_PARS]; /* m, e, d, p, q, u */
3711 gcry_sexp_t rsa_priv_key = NULL;
3713 gcry_mpi_t rsa_params[RSA_PARS];
3715 /* RSA get parameter */
3716 if (gnutls_x509_privkey_export_rsa_raw(priv_key,
3722 &rsa_datum[5]) != 0) {
3723 ssl_debug_printf("ssl_load_key: can't export rsa param (is a rsa private key file ?!?)\n");
3727 /* convert each rsa parameter to mpi format*/
3728 for(i=0; i<RSA_PARS; i++) {
3729 gret = gcry_mpi_scan(&rsa_params[i], GCRYMPI_FMT_USG, rsa_datum[i].data, rsa_datum[i].size,&tmp_size);
3730 /* these buffers were allocated by gnutls_x509_privkey_export_rsa_raw() */
3731 g_free(rsa_datum[i].data);
3733 ssl_debug_printf("ssl_load_key: can't convert m rsa param to int (size %d)\n", rsa_datum[i].size);
3738 /* libgcrypt expects p < q, and gnutls might not return it as such, depending on gnutls version and its crypto backend */
3739 if (gcry_mpi_cmp(rsa_params[3], rsa_params[4]) > 0)
3741 ssl_debug_printf("ssl_load_key: swapping p and q parameters and recomputing u\n");
3743 gcry_mpi_swap(rsa_params[3], rsa_params[4]);
3744 /* due to swapping p and q, u = p^-1 mod p which happens to be needed. */
3746 /* libgcrypt expects u = p^-1 mod q (for OpenPGP), but the u parameter
3747 * says u = q^-1 mod p. Recompute u = p^-1 mod q. Do this unconditionally as
3748 * at least GnuTLS 2.12.23 computes an invalid value. */
3749 gcry_mpi_invm(rsa_params[5], rsa_params[3], rsa_params[4]);
3751 if (gcry_sexp_build( &rsa_priv_key, NULL,
3752 "(private-key(rsa((n%m)(e%m)(d%m)(p%m)(q%m)(u%m))))", rsa_params[0],
3753 rsa_params[1], rsa_params[2], rsa_params[3], rsa_params[4],
3754 rsa_params[5]) != 0) {
3755 ssl_debug_printf("ssl_load_key: can't build rsa private key s-exp\n");
3759 for (i=0; i< 6; i++)
3760 gcry_mpi_release(rsa_params[i]);
3761 return rsa_priv_key;
3764 /** Load an RSA private key from specified file
3765 @param fp the file that contain the key data
3766 @return a pointer to the loaded key on success, or NULL */
3767 static gnutls_x509_privkey_t
3768 ssl_load_key(FILE* fp)
3770 /* gnutls makes our work much harder, since we have to work internally with
3771 * s-exp formatted data, but PEM loader exports only in "gnutls_datum_t"
3772 * format, and a datum -> s-exp convertion function does not exist.
3774 gnutls_x509_privkey_t priv_key;
3780 if (ws_fstat64(ws_fileno(fp), &statbuf) == -1) {
3781 ssl_debug_printf("ssl_load_key: can't ws_fstat64 file\n");
3784 if (S_ISDIR(statbuf.st_mode)) {
3785 ssl_debug_printf("ssl_load_key: file is a directory\n");
3789 if (S_ISFIFO(statbuf.st_mode)) {
3790 ssl_debug_printf("ssl_load_key: file is a named pipe\n");
3794 if (!S_ISREG(statbuf.st_mode)) {
3795 ssl_debug_printf("ssl_load_key: file is not a regular file\n");
3799 /* XXX - check for a too-big size */
3800 /* load all file contents into a datum buffer*/
3801 key.data = (unsigned char *)g_malloc((size_t)statbuf.st_size);
3802 key.size = (int)statbuf.st_size;
3803 bytes = (guint) fread(key.data, 1, key.size, fp);
3804 if (bytes < key.size) {
3805 ssl_debug_printf("ssl_load_key: can't read from file %d bytes, got %d\n",
3811 /* init private key data*/
3812 gnutls_x509_privkey_init(&priv_key);
3814 /* import PEM data*/
3815 if ((ret = gnutls_x509_privkey_import(priv_key, &key, GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS) {
3816 ssl_debug_printf("ssl_load_key: can't import pem data: %s\n", gnutls_strerror(ret));
3821 if (gnutls_x509_privkey_get_pk_algorithm(priv_key) != GNUTLS_PK_RSA) {
3822 ssl_debug_printf("ssl_load_key: private key public key algorithm isn't RSA\n");
3833 BAGTYPE(gnutls_pkcs12_bag_type_t x) {
3835 case GNUTLS_BAG_EMPTY: return "Empty";
3836 case GNUTLS_BAG_PKCS8_ENCRYPTED_KEY: return "PKCS#8 Encrypted key";
3837 case GNUTLS_BAG_PKCS8_KEY: return "PKCS#8 Key";
3838 case GNUTLS_BAG_CERTIFICATE: return "Certificate";
3839 case GNUTLS_BAG_CRL: return "CRL";
3840 case GNUTLS_BAG_ENCRYPTED: return "Encrypted";
3841 case GNUTLS_BAG_UNKNOWN: return "Unknown";
3842 default: return "<undefined>";
3847 * Load a RSA private key from a PKCS#12 file.
3848 * @param fp the file that contains the key data.
3849 * @param cert_passwd password to decrypt the PKCS#12 file.
3850 * @param[out] err error message upon failure; NULL upon success.
3851 * @return a pointer to the loaded key on success; NULL upon failure.
3853 static gnutls_x509_privkey_t
3854 ssl_load_pkcs12(FILE* fp, const gchar *cert_passwd, char** err) {
3859 gnutls_datum_t data;
3860 gnutls_pkcs12_bag_t bag = NULL;
3861 gnutls_pkcs12_bag_type_t bag_type;
3864 gnutls_pkcs12_t ssl_p12 = NULL;
3865 gnutls_x509_privkey_t ssl_pkey = NULL;
3867 gnutls_x509_privkey_t priv_key = NULL;
3871 data.data = (unsigned char *)g_malloc(rest);
3874 while ((len = fread(p, 1, rest, fp)) > 0) {
3879 data.data = (unsigned char *)g_realloc(data.data, data.size + rest);
3880 p = data.data + data.size;
3885 ssl_debug_printf("%d bytes read\n", data.size);
3887 *err = g_strdup("Error during certificate reading.");
3888 ssl_debug_printf("%s\n", *err);
3893 ret = gnutls_pkcs12_init(&ssl_p12);
3895 *err = g_strdup_printf("gnutls_pkcs12_init(&st_p12) - %s", gnutls_strerror(ret));
3896 ssl_debug_printf("%s\n", *err);
3901 /* load PKCS#12 in DER or PEM format */
3902 ret = gnutls_pkcs12_import(ssl_p12, &data, GNUTLS_X509_FMT_DER, 0);
3904 *err = g_strdup_printf("could not load PKCS#12 in DER format: %s", gnutls_strerror(ret));
3905 ssl_debug_printf("%s\n", *err);
3908 ret = gnutls_pkcs12_import(ssl_p12, &data, GNUTLS_X509_FMT_PEM, 0);
3910 *err = g_strdup_printf("could not load PKCS#12 in PEM format: %s", gnutls_strerror(ret));
3911 ssl_debug_printf("%s\n", *err);
3921 ssl_debug_printf( "PKCS#12 imported\n");
3923 /* TODO: Use gnutls_pkcs12_simple_parse, since 3.1.0 (August 2012) */
3926 ret = gnutls_pkcs12_bag_init(&bag);
3929 ret = gnutls_pkcs12_get_bag(ssl_p12, i, bag);
3932 for (j=0; j<gnutls_pkcs12_bag_get_count(bag); j++) {
3934 bag_type = gnutls_pkcs12_bag_get_type(bag, j);
3935 if (bag_type >= GNUTLS_BAG_UNKNOWN) goto done;
3936 ssl_debug_printf( "Bag %d/%d: %s\n", i, j, BAGTYPE(bag_type));
3937 if (bag_type == GNUTLS_BAG_ENCRYPTED) {
3938 ret = gnutls_pkcs12_bag_decrypt(bag, cert_passwd);
3940 bag_type = gnutls_pkcs12_bag_get_type(bag, j);
3941 if (bag_type >= GNUTLS_BAG_UNKNOWN) goto done;
3942 ssl_debug_printf( "Bag %d/%d decrypted: %s\n", i, j, BAGTYPE(bag_type));
3946 ret = gnutls_pkcs12_bag_get_data(bag, j, &data);
3947 if (ret < 0) goto done;
3951 case GNUTLS_BAG_PKCS8_KEY:
3952 case GNUTLS_BAG_PKCS8_ENCRYPTED_KEY:
3954 ret = gnutls_x509_privkey_init(&ssl_pkey);
3956 *err = g_strdup_printf("gnutls_x509_privkey_init(&ssl_pkey) - %s", gnutls_strerror(ret));
3957 ssl_debug_printf("%s\n", *err);
3960 ret = gnutls_x509_privkey_import_pkcs8(ssl_pkey, &data, GNUTLS_X509_FMT_DER, cert_passwd,
3961 (bag_type==GNUTLS_BAG_PKCS8_KEY) ? GNUTLS_PKCS_PLAIN : 0);
3963 *err = g_strdup_printf("Can not decrypt private key - %s", gnutls_strerror(ret));
3964 ssl_debug_printf("%s\n", *err);
3968 if (gnutls_x509_privkey_get_pk_algorithm(ssl_pkey) != GNUTLS_PK_RSA) {
3969 *err = g_strdup("ssl_load_pkcs12: private key public key algorithm isn't RSA");
3970 ssl_debug_printf("%s\n", *err);
3974 /* Private key found, return it. */
3975 priv_key = ssl_pkey;
3982 if (bag) { gnutls_pkcs12_bag_deinit(bag); bag = NULL; }
3986 if (!priv_key && ssl_pkey)
3987 gnutls_x509_privkey_deinit(ssl_pkey);
3989 gnutls_pkcs12_bag_deinit(bag);
3996 ssl_private_key_free(gpointer key)
3998 gcry_sexp_release((gcry_sexp_t) key);
4002 ssl_find_private_key_by_pubkey(SslDecryptSession *ssl, GHashTable *key_hash,
4003 gnutls_datum_t *subjectPublicKeyInfo)
4005 gnutls_pubkey_t pubkey = NULL;
4007 size_t key_id_len = sizeof(key_id);
4010 if (!subjectPublicKeyInfo->size) {
4011 ssl_debug_printf("%s: could not find SubjectPublicKeyInfo\n", G_STRFUNC);
4015 r = gnutls_pubkey_init(&pubkey);
4017 ssl_debug_printf("%s: failed to init pubkey: %s\n",
4018 G_STRFUNC, gnutls_strerror(r));
4022 r = gnutls_pubkey_import(pubkey, subjectPublicKeyInfo, GNUTLS_X509_FMT_DER);
4024 ssl_debug_printf("%s: failed to import pubkey from handshake: %s\n",
4025 G_STRFUNC, gnutls_strerror(r));
4029 /* Generate a 20-byte SHA-1 hash. */
4030 r = gnutls_pubkey_get_key_id(pubkey, 0, key_id, &key_id_len);
4032 ssl_debug_printf("%s: failed to extract key id from pubkey: %s\n",
4033 G_STRFUNC, gnutls_strerror(r));
4037 ssl_print_data("lookup(KeyID)", key_id, key_id_len);
4038 ssl->private_key = (gcry_sexp_t)g_hash_table_lookup(key_hash, key_id);
4039 ssl_debug_printf("%s: lookup result: %p\n", G_STRFUNC, (void *) ssl->private_key);
4042 gnutls_pubkey_deinit(pubkey);
4045 /* RSA private key file processing }}} */
4047 #else /* ! (defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)) */
4049 ssl_private_key_free(gpointer key _U_)
4052 #endif /* ! (defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)) */
4055 /*--- Start of dissector-related code below ---*/
4057 /* get ssl data for this session. if no ssl data is found allocate a new one*/
4059 ssl_get_session(conversation_t *conversation, dissector_handle_t ssl_handle)
4062 SslDecryptSession *ssl_session;
4065 proto_ssl = dissector_handle_get_protocol_index(ssl_handle);
4066 conv_data = conversation_get_proto_data(conversation, proto_ssl);
4067 if (conv_data != NULL)
4068 return (SslDecryptSession *)conv_data;
4070 /* no previous SSL conversation info, initialize it. */
4071 ssl_session = wmem_new0(wmem_file_scope(), SslDecryptSession);
4073 /* data_len is the part that is meaningful, not the allocated length */
4074 ssl_session->master_secret.data_len = 0;
4075 ssl_session->master_secret.data = ssl_session->_master_secret;
4076 ssl_session->session_id.data_len = 0;
4077 ssl_session->session_id.data = ssl_session->_session_id;
4078 ssl_session->client_random.data_len = 0;
4079 ssl_session->client_random.data = ssl_session->_client_random;
4080 ssl_session->server_random.data_len = 0;
4081 ssl_session->server_random.data = ssl_session->_server_random;
4082 ssl_session->session_ticket.data_len = 0;
4083 ssl_session->session_ticket.data = NULL; /* will be re-alloced as needed */
4084 ssl_session->server_data_for_iv.data_len = 0;
4085 ssl_session->server_data_for_iv.data = ssl_session->_server_data_for_iv;
4086 ssl_session->client_data_for_iv.data_len = 0;
4087 ssl_session->client_data_for_iv.data = ssl_session->_client_data_for_iv;
4088 ssl_session->app_data_segment.data = NULL;
4089 ssl_session->app_data_segment.data_len = 0;
4090 ssl_session->handshake_data.data=NULL;
4091 ssl_session->handshake_data.data_len=0;
4093 /* Initialize parameters which are not necessary specific to decryption. */
4094 ssl_session->session.version = SSL_VER_UNKNOWN;
4095 clear_address(&ssl_session->session.srv_addr);
4096 ssl_session->session.srv_ptype = PT_NONE;
4097 ssl_session->session.srv_port = 0;
4099 conversation_add_proto_data(conversation, proto_ssl, ssl_session);
4104 ssl_starttls(dissector_handle_t ssl_handle, packet_info *pinfo,
4105 dissector_handle_t app_handle, guint32 last_nontls_frame)
4107 conversation_t *conversation;
4108 SslSession *session;
4110 /* Ignore if the SSL dissector is disabled. */
4113 /* The caller should always pass a valid handle to its own dissector. */
4114 DISSECTOR_ASSERT(app_handle);
4116 conversation = find_or_create_conversation(pinfo);
4117 session = &ssl_get_session(conversation, ssl_handle)->session;
4119 ssl_debug_printf("%s: old frame %d, app_handle=%p (%s)\n", G_STRFUNC,
4120 session->last_nontls_frame,
4121 (void *)session->app_handle,
4122 dissector_handle_get_dissector_name(session->app_handle));
4123 ssl_debug_printf("%s: current frame %d, app_handle=%p (%s)\n", G_STRFUNC,
4124 pinfo->num, (void *)app_handle,
4125 dissector_handle_get_dissector_name(app_handle));
4127 /* Do not switch again if a dissector did it before. */
4128 if (session->last_nontls_frame) {
4129 ssl_debug_printf("%s: not overriding previous app handle!\n", G_STRFUNC);
4130 return session->last_nontls_frame;
4133 session->app_handle = app_handle;
4134 /* The SSL dissector should be called first for this conversation. */
4135 conversation_set_dissector(conversation, ssl_handle);
4136 /* SSL starts after this frame. */
4137 session->last_nontls_frame = last_nontls_frame;
4141 /* ssl_starttls_ack: mark future frames as encrypted. {{{ */
4143 ssl_starttls_ack(dissector_handle_t ssl_handle, packet_info *pinfo,
4144 dissector_handle_t app_handle)
4146 return ssl_starttls(ssl_handle, pinfo, app_handle, pinfo->num);
4150 ssl_starttls_post_ack(dissector_handle_t ssl_handle, packet_info *pinfo,
4151 dissector_handle_t app_handle)
4153 return ssl_starttls(ssl_handle, pinfo, app_handle, pinfo->num - 1);
4156 /* Functions for TLS/DTLS sessions and RSA private keys hashtables. {{{ */
4158 ssl_equal (gconstpointer v, gconstpointer v2)
4160 const StringInfo *val1;
4161 const StringInfo *val2;
4162 val1 = (const StringInfo *)v;
4163 val2 = (const StringInfo *)v2;
4165 if (val1->data_len == val2->data_len &&
4166 !memcmp(val1->data, val2->data, val2->data_len)) {
4173 ssl_hash (gconstpointer v)
4176 const StringInfo* id;
4179 id = (const StringInfo*) v;
4181 /* id and id->data are mallocated in ssl_save_master_key(). As such 'data'
4182 * should be aligned for any kind of access (for example as a guint as
4183 * is done below). The intermediate void* cast is to prevent "cast
4184 * increases required alignment of target type" warnings on CPUs (such
4185 * as SPARCs) that do not allow misaligned memory accesses.
4187 cur = (const guint*)(void*) id->data;
4189 for (l=4; (l < id->data_len); l+=4, cur++)
4190 hash = hash ^ (*cur);
4196 ssl_private_key_equal (gconstpointer v, gconstpointer v2)
4198 /* key ID length (SHA-1 hash, per GNUTLS_KEYID_USE_SHA1) */
4199 return !memcmp(v, v2, 20);
4203 ssl_private_key_hash (gconstpointer v)
4206 const guint8 *cur = (const guint8 *)v;
4208 /* The public key' SHA-1 hash (which maps to a private key) has a uniform
4209 * distribution, hence simply xor'ing them should be sufficient. */
4210 for (l = 0; l < 20; l += 4, cur += 4)
4211 hash ^= pntoh32(cur);
4215 /* Functions for TLS/DTLS sessions and RSA private keys hashtables. }}} */
4217 /* Handling of association between tls/dtls ports and clear text protocol. {{{ */
4219 ssl_association_add(const char* dissector_table_name, dissector_handle_t main_handle, dissector_handle_t subdissector_handle, guint port, gboolean tcp)
4221 DISSECTOR_ASSERT(main_handle);
4222 DISSECTOR_ASSERT(subdissector_handle);
4223 /* Registration is required for Export PDU feature to work properly. */
4224 DISSECTOR_ASSERT_HINT(dissector_handle_get_dissector_name(subdissector_handle),
4225 "SSL appdata dissectors must register with register_dissector()!");
4226 ssl_debug_printf("association_add %s port %d handle %p\n", dissector_table_name, port, (void *)subdissector_handle);
4229 dissector_add_uint(dissector_table_name, port, subdissector_handle);
4231 dissector_add_uint("tcp.port", port, main_handle);
4233 dissector_add_uint("udp.port", port, main_handle);
4234 dissector_add_uint("sctp.port", port, main_handle);
4236 dissector_add_for_decode_as(dissector_table_name, subdissector_handle);
4241 ssl_association_remove(const char* dissector_table_name, dissector_handle_t main_handle, dissector_handle_t subdissector_handle, guint port, gboolean tcp)
4243 ssl_debug_printf("ssl_association_remove removing %s %u - handle %p\n",
4244 tcp?"TCP":"UDP", port, (void *)subdissector_handle);
4246 dissector_delete_uint(tcp?"tcp.port":"udp.port", port, main_handle);
4247 dissector_delete_uint("sctp.port", port, main_handle);
4251 dissector_delete_uint(dissector_table_name, port, subdissector_handle);
4256 ssl_set_server(SslSession *session, address *addr, port_type ptype, guint32 port)
4258 copy_address_wmem(wmem_file_scope(), &session->srv_addr, addr);
4259 session->srv_ptype = ptype;
4260 session->srv_port = port;
4264 ssl_packet_from_server(SslSession *session, dissector_table_t table, packet_info *pinfo)
4267 if (session->srv_ptype != PT_NONE) {
4268 ret = (session->srv_ptype == pinfo->ptype) &&
4269 (session->srv_port == pinfo->srcport) &&
4270 addresses_equal(&session->srv_addr, &pinfo->src);
4272 ret = (dissector_get_uint_handle(table, pinfo->srcport) != 0);
4275 ssl_debug_printf("packet_from_server: is from server - %s\n", (ret)?"TRUE":"FALSE");
4278 /* Handling of association between tls/dtls ports and clear text protocol. }}} */
4281 /* Links SSL records with the real packet data. {{{ */
4282 /* add to packet data a copy of the specified real data */
4284 ssl_add_record_info(gint proto, packet_info *pinfo, guchar* data, gint data_len, gint record_id)
4290 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4293 pi = (SslPacketInfo *)wmem_alloc0(wmem_file_scope(), sizeof(SslPacketInfo));
4294 p_add_proto_data(wmem_file_scope(), pinfo, proto, 0, pi);
4297 real_data = (guchar *)wmem_alloc(wmem_file_scope(), data_len);
4298 memcpy(real_data, data, data_len);
4300 rec = (SslRecordInfo *)wmem_alloc(wmem_file_scope(), sizeof(SslRecordInfo));
4301 rec->id = record_id;
4302 rec->real_data = real_data;
4303 rec->data_len = data_len;
4305 /* head insertion */
4306 rec->next= pi->handshake_data;
4307 pi->handshake_data = rec;
4310 /* search in packet data for the specified id; return a newly created tvb for the associated data */
4312 ssl_get_record_info(tvbuff_t *parent_tvb, int proto, packet_info *pinfo, gint record_id)
4316 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4321 for (rec = pi->handshake_data; rec; rec = rec->next)
4322 if (rec->id == record_id)
4323 /* link new real_data_tvb with a parent tvb so it is freed when frame dissection is complete */
4324 return tvb_new_child_real_data(parent_tvb, rec->real_data, rec->data_len, rec->data_len);
4330 ssl_add_data_info(gint proto, packet_info *pinfo, guchar* data, gint data_len, gint key, SslFlow *flow)
4332 SslDataInfo *rec, **prec;
4335 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4338 pi = (SslPacketInfo *)wmem_alloc0(wmem_file_scope(), sizeof(SslPacketInfo));
4339 p_add_proto_data(wmem_file_scope(), pinfo, proto, 0, pi);
4342 rec = (SslDataInfo *)wmem_alloc(wmem_file_scope(), sizeof(SslDataInfo)+data_len);
4344 rec->plain_data.data = (guchar*)(rec + 1);
4345 memcpy(rec->plain_data.data, data, data_len);
4346 rec->plain_data.data_len = data_len;
4349 rec->seq = flow->byte_seq;
4350 rec->nxtseq = flow->byte_seq + data_len;
4352 flow->byte_seq += data_len;
4357 prec = &pi->appl_data;
4358 while (*prec) prec = &(*prec)->next;
4361 ssl_debug_printf("ssl_add_data_info: new data inserted data_len = %d, seq = %u, nxtseq = %u\n",
4362 rec->plain_data.data_len, rec->seq, rec->nxtseq);
4366 ssl_get_data_info(int proto, packet_info *pinfo, gint key)
4370 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4372 if (!pi) return NULL;
4374 rec = pi->appl_data;
4376 if (rec->key == key) return rec;
4382 /* Links SSL records with the real packet data. }}} */
4384 /* initialize/reset per capture state data (ssl sessions cache). {{{ */
4386 ssl_common_init(ssl_master_key_map_t *mk_map,
4387 StringInfo *decrypted_data, StringInfo *compressed_data)
4389 mk_map->session = g_hash_table_new(ssl_hash, ssl_equal);
4390 mk_map->tickets = g_hash_table_new(ssl_hash, ssl_equal);
4391 mk_map->crandom = g_hash_table_new(ssl_hash, ssl_equal);
4392 mk_map->pre_master = g_hash_table_new(ssl_hash, ssl_equal);
4393 mk_map->pms = g_hash_table_new(ssl_hash, ssl_equal);
4394 ssl_data_alloc(decrypted_data, 32);
4395 ssl_data_alloc(compressed_data, 32);
4399 ssl_common_cleanup(ssl_master_key_map_t *mk_map, FILE **ssl_keylog_file,
4400 StringInfo *decrypted_data, StringInfo *compressed_data)
4402 g_hash_table_destroy(mk_map->session);
4403 g_hash_table_destroy(mk_map->tickets);
4404 g_hash_table_destroy(mk_map->crandom);
4405 g_hash_table_destroy(mk_map->pre_master);
4406 g_hash_table_destroy(mk_map->pms);
4408 g_free(decrypted_data->data);
4409 g_free(compressed_data->data);
4411 /* close the previous keylog file now that the cache are cleared, this
4412 * allows the cache to be filled with the full keylog file contents. */
4413 if (*ssl_keylog_file) {
4414 fclose(*ssl_keylog_file);
4415 *ssl_keylog_file = NULL;
4420 /* parse ssl related preferences (private keys and ports association strings) */
4421 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
4422 /* Load a single RSA key file item from preferences. {{{ */
4424 ssl_parse_key_list(const ssldecrypt_assoc_t *uats, GHashTable *key_hash, const char* dissector_table_name, dissector_handle_t main_handle, gboolean tcp)
4426 gnutls_x509_privkey_t priv_key;
4427 gcry_sexp_t private_key;
4430 size_t key_id_len = 20;
4431 guchar *key_id = NULL;
4432 dissector_handle_t handle;
4433 /* try to load keys file first */
4434 fp = ws_fopen(uats->keyfile, "rb");
4436 report_open_failure(uats->keyfile, errno, FALSE);
4440 if ((gint)strlen(uats->password) == 0) {
4441 priv_key = ssl_load_key(fp);
4444 priv_key = ssl_load_pkcs12(fp, uats->password, &err);
4446 report_failure("%s\n", err);
4453 report_failure("Can't load private key from %s\n", uats->keyfile);
4457 key_id = (guchar *) g_malloc0(key_id_len);
4458 ret = gnutls_x509_privkey_get_key_id(priv_key, 0, key_id, &key_id_len);
4460 report_failure("Can't calculate public key ID for %s: %s",
4461 uats->keyfile, gnutls_strerror(ret));
4464 ssl_print_data("KeyID", key_id, key_id_len);
4466 private_key = ssl_privkey_to_sexp(priv_key);
4468 report_failure("Can't extract private key parameters for %s", uats->keyfile);
4472 g_hash_table_replace(key_hash, key_id, private_key);
4473 key_id = NULL; /* used in key_hash, do not free. */
4474 ssl_debug_printf("ssl_init private key file %s successfully loaded.\n", uats->keyfile);
4477 /* Port to subprotocol mapping */
4478 int port = atoi(uats->port); /* Also maps "start_tls" -> 0 (wildcard) */
4479 ssl_debug_printf("ssl_init port '%d' filename '%s' password(only for p12 file) '%s'\n",
4480 port, uats->keyfile, uats->password);
4482 handle = find_dissector(uats->protocol);
4483 ssl_association_add(dissector_table_name, main_handle, handle, port, tcp);
4487 gnutls_x509_privkey_deinit(priv_key);
4493 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_)
4495 report_failure("Can't load private key files, support is not compiled in.");
4500 #ifdef HAVE_LIBGCRYPT /* useless without decryption support. */
4501 /* Store/load a known (pre-)master secret from/for this SSL session. {{{ */
4502 /** store a known (pre-)master secret into cache */
4504 ssl_save_master_key(const char *label, GHashTable *ht, StringInfo *key,
4507 StringInfo *ht_key, *master_secret;
4509 if (key->data_len == 0) {
4510 ssl_debug_printf("%s: not saving empty %s!\n", G_STRFUNC, label);
4514 if (mk->data_len == 0) {
4515 ssl_debug_printf("%s not saving empty (pre-)master secret for %s!\n",
4520 /* ssl_hash() depends on session_ticket->data being aligned for guint access
4521 * so be careful in changing how it is allocated. */
4522 ht_key = ssl_data_clone(key);
4523 master_secret = ssl_data_clone(mk);
4524 g_hash_table_insert(ht, ht_key, master_secret);
4526 ssl_debug_printf("%s inserted (pre-)master secret for %s\n", G_STRFUNC, label);
4527 ssl_print_string("stored key", ht_key);
4528 ssl_print_string("stored (pre-)master secret", master_secret);
4531 /** restore a (pre-)master secret given some key in the cache */
4533 ssl_restore_master_key(SslDecryptSession *ssl, const char *label,
4534 gboolean is_pre_master, GHashTable *ht, StringInfo *key)
4538 if (key->data_len == 0) {
4539 ssl_debug_printf("%s can't restore %smaster secret using an empty %s\n",
4540 G_STRFUNC, is_pre_master ? "pre-" : "", label);
4544 ms = (StringInfo *)g_hash_table_lookup(ht, key);
4546 ssl_debug_printf("%s can't find %smaster secret by %s\n", G_STRFUNC,
4547 is_pre_master ? "pre-" : "", label);
4551 /* (pre)master secret found, clear knowledge of other keys and set it in the
4552 * current conversation */
4553 ssl->state &= ~(SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET |
4554 SSL_HAVE_SESSION_KEY);
4555 if (is_pre_master) {
4556 /* unlike master secret, pre-master secret has a variable size (48 for
4557 * RSA, varying for PSK) and is therefore not statically allocated */
4558 ssl->pre_master_secret.data = (guchar *) wmem_alloc(wmem_file_scope(),
4560 ssl_data_set(&ssl->pre_master_secret, ms->data, ms->data_len);
4561 ssl->state |= SSL_PRE_MASTER_SECRET;
4563 ssl_data_set(&ssl->master_secret, ms->data, ms->data_len);
4564 ssl->state |= SSL_MASTER_SECRET;
4566 ssl_debug_printf("%s %smaster secret retrieved using %s\n", G_STRFUNC,
4567 is_pre_master ? "pre-" : "", label);
4568 ssl_print_string(label, key);
4569 ssl_print_string("(pre-)master secret", ms);
4572 /* Store/load a known (pre-)master secret from/for this SSL session. }}} */
4574 /* Should be called when all parameters are ready (after ChangeCipherSpec), and
4575 * the decoder should be attempted to be initialized. {{{*/
4577 ssl_finalize_decryption(SslDecryptSession *ssl, ssl_master_key_map_t *mk_map)
4579 ssl_debug_printf("%s state = 0x%02X\n", G_STRFUNC, ssl->state);
4580 if (ssl->state & SSL_HAVE_SESSION_KEY) {
4581 ssl_debug_printf(" session key already available, nothing to do.\n");
4585 /* for decryption, there needs to be a master secret (which can be derived
4586 * from pre-master secret). If missing, try to pick a master key from cache
4587 * (an earlier packet in the capture or key logfile). */
4588 if (!(ssl->state & (SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET)) &&
4589 !ssl_restore_master_key(ssl, "Session ID", FALSE,
4590 mk_map->session, &ssl->session_id) &&
4591 (!ssl->session.is_session_resumed ||
4592 !ssl_restore_master_key(ssl, "Session Ticket", FALSE,
4593 mk_map->tickets, &ssl->session_ticket)) &&
4594 !ssl_restore_master_key(ssl, "Client Random", FALSE,
4595 mk_map->crandom, &ssl->client_random)) {
4596 if (ssl->cipher_suite.enc != ENC_NULL) {
4597 /* how unfortunate, the master secret could not be found */
4598 ssl_debug_printf(" Cannot find master secret\n");
4601 ssl_debug_printf(" Cannot find master secret, continuing anyway "
4602 "because of a NULL cipher\n");
4606 if (ssl_generate_keyring_material(ssl) < 0) {
4607 ssl_debug_printf("%s can't generate keyring material\n", G_STRFUNC);
4610 /* Save Client Random/ Session ID for "SSL Export Session keys" */
4611 ssl_save_master_key("Client Random", mk_map->crandom,
4612 &ssl->client_random, &ssl->master_secret);
4613 ssl_save_master_key("Session ID", mk_map->session,
4614 &ssl->session_id, &ssl->master_secret);
4615 /* Only save the new secrets if the server sent the ticket. The client
4616 * ticket might have become stale. */
4617 if (ssl->state & SSL_NEW_SESSION_TICKET) {
4618 ssl_save_master_key("Session Ticket", mk_map->tickets,
4619 &ssl->session_ticket, &ssl->master_secret);
4622 #endif /* HAVE_LIBGCRYPT */
4624 /** SSL keylog file handling. {{{ */
4627 ssl_compile_keyfile_regex(void)
4629 #define OCTET "(?:[[:xdigit:]]{2})"
4630 const gchar *pattern =
4632 /* Matches Client Hellos having this Client Random */
4633 "PMS_CLIENT_RANDOM (?<client_random_pms>" OCTET "{32}) "
4634 /* Matches first part of encrypted RSA pre-master secret */
4635 "|RSA (?<encrypted_pmk>" OCTET "{8}) "
4636 /* Pre-Master-Secret is given, it is 48 bytes for RSA,
4637 but it can be of any length for DHE */
4638 ")(?<pms>" OCTET "+)"
4640 /* Matches Server Hellos having a Session ID */
4641 "RSA Session-ID:(?<session_id>" OCTET "+) Master-Key:"
4642 /* Matches Client Hellos having this Client Random */
4643 "|CLIENT_RANDOM (?<client_random>" OCTET "{32}) "
4644 /* Master-Secret is given, its length is fixed */
4645 ")(?<master_secret>" OCTET "{" G_STRINGIFY(SSL_MASTER_SECRET_LENGTH) "})";
4647 static GRegex *regex = NULL;
4648 GError *gerr = NULL;
4651 regex = g_regex_new(pattern,
4652 (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_ANCHORED),
4653 G_REGEX_MATCH_ANCHORED, &gerr);
4655 ssl_debug_printf("%s failed to compile regex: %s\n", G_STRFUNC,
4666 file_needs_reopen(FILE *fp, const char *filename)
4668 ws_statb64 open_stat, current_stat;
4670 /* consider a file deleted when stat fails for either file,
4671 * or when the residing device / inode has changed. */
4672 if (0 != ws_fstat64(ws_fileno(fp), &open_stat))
4674 if (0 != ws_stat64(filename, ¤t_stat))
4677 /* Note: on Windows, ino may be 0. Existing files cannot be deleted on
4678 * Windows, but hopefully the size is a good indicator when a file got
4679 * removed and recreated */
4680 return open_stat.st_dev != current_stat.st_dev ||
4681 open_stat.st_ino != current_stat.st_ino ||
4682 open_stat.st_size > current_stat.st_size;
4685 typedef struct ssl_master_key_match_group {
4686 const char *re_group_name;
4687 GHashTable *master_key_ht;
4688 } ssl_master_key_match_group_t;
4691 ssl_load_keyfile(const gchar *ssl_keylog_filename, FILE **keylog_file,
4692 const ssl_master_key_map_t *mk_map)
4696 ssl_master_key_match_group_t mk_groups[] = {
4697 { "encrypted_pmk", mk_map->pre_master },
4698 { "session_id", mk_map->session },
4699 { "client_random", mk_map->crandom },
4700 { "client_random_pms", mk_map->pms},
4702 /* no need to try if no key log file is configured. */
4703 if (!ssl_keylog_filename || !*ssl_keylog_filename) {
4704 ssl_debug_printf("%s dtls/ssl.keylog_file is not configured!\n",
4709 /* The format of the file is a series of records with one of the following formats:
4711 * Where xxxx are the first 8 bytes of the encrypted pre-master secret (hex-encoded)
4712 * Where yyyy is the cleartext pre-master secret (hex-encoded)
4713 * (this is the original format introduced with bug 4349)
4715 * - "RSA Session-ID:xxxx Master-Key:yyyy"
4716 * Where xxxx is the SSL session ID (hex-encoded)
4717 * Where yyyy is the cleartext master secret (hex-encoded)
4718 * (added to support openssl s_client Master-Key output)
4719 * This is somewhat is a misnomer because there's nothing RSA specific
4722 * - "PMS_CLIENT_RANDOM xxxx yyyy"
4723 * Where xxxx is the client_random from the ClientHello (hex-encoded)
4724 * Where yyyy is the cleartext pre-master secret (hex-encoded)
4725 * (This format allows SSL connections to be decrypted, if a user can
4726 * capture the PMS but could not recover the MS for a specific session
4727 * with a SSL Server.)
4729 * - "CLIENT_RANDOM xxxx yyyy"
4730 * Where xxxx is the client_random from the ClientHello (hex-encoded)
4731 * Where yyyy is the cleartext master secret (hex-encoded)
4732 * (This format allows non-RSA SSL connections to be decrypted, i.e.
4735 regex = ssl_compile_keyfile_regex();
4739 ssl_debug_printf("trying to use SSL keylog in %s\n", ssl_keylog_filename);
4741 /* if the keylog file was deleted, re-open it */
4742 if (*keylog_file && file_needs_reopen(*keylog_file, ssl_keylog_filename)) {
4743 ssl_debug_printf("%s file got deleted, trying to re-open\n", G_STRFUNC);
4744 fclose(*keylog_file);
4745 *keylog_file = NULL;
4748 if (*keylog_file == NULL) {
4749 *keylog_file = ws_fopen(ssl_keylog_filename, "r");
4750 if (!*keylog_file) {
4751 ssl_debug_printf("%s failed to open SSL keylog\n", G_STRFUNC);
4757 char buf[512], *line;
4761 line = fgets(buf, sizeof(buf), *keylog_file);
4765 bytes_read = strlen(line);
4766 /* fgets includes the \n at the end of the line. */
4767 if (bytes_read > 0 && line[bytes_read - 1] == '\n') {
4768 line[bytes_read - 1] = 0;
4771 if (bytes_read > 0 && line[bytes_read - 1] == '\r') {
4772 line[bytes_read - 1] = 0;
4776 ssl_debug_printf(" checking keylog line: %s\n", line);
4777 if (g_regex_match(regex, line, G_REGEX_MATCH_ANCHORED, &mi)) {
4778 gchar *hex_key, *hex_pre_ms_or_ms;
4779 StringInfo *key = wmem_new(wmem_file_scope(), StringInfo);
4780 StringInfo *pre_ms_or_ms = NULL;
4781 GHashTable *ht = NULL;
4783 /* Is the PMS being supplied with the PMS_CLIENT_RANDOM
4784 * otherwise we will use the Master Secret
4786 hex_pre_ms_or_ms = g_match_info_fetch_named(mi, "master_secret");
4787 if (hex_pre_ms_or_ms == NULL || strlen(hex_pre_ms_or_ms) == 0){
4788 g_free(hex_pre_ms_or_ms);
4789 hex_pre_ms_or_ms = g_match_info_fetch_named(mi, "pms");
4791 /* There is always a match, otherwise the regex is wrong. */
4792 DISSECTOR_ASSERT(hex_pre_ms_or_ms && strlen(hex_pre_ms_or_ms));
4794 /* convert from hex to bytes and save to hashtable */
4795 pre_ms_or_ms = wmem_new(wmem_file_scope(), StringInfo);
4796 from_hex(pre_ms_or_ms, hex_pre_ms_or_ms, strlen(hex_pre_ms_or_ms));
4797 g_free(hex_pre_ms_or_ms);
4799 /* Find a master key from any format (CLIENT_RANDOM, SID, ...) */
4800 for (i = 0; i < G_N_ELEMENTS(mk_groups); i++) {
4801 ssl_master_key_match_group_t *g = &mk_groups[i];
4802 hex_key = g_match_info_fetch_named(mi, g->re_group_name);
4803 if (hex_key && *hex_key) {
4804 ssl_debug_printf(" matched %s\n", g->re_group_name);
4805 ht = g->master_key_ht;
4806 from_hex(key, hex_key, strlen(hex_key));
4812 DISSECTOR_ASSERT(ht); /* Cannot be reached, or regex is wrong. */
4814 g_hash_table_insert(ht, key, pre_ms_or_ms);
4817 ssl_debug_printf(" unrecognized line\n");
4819 /* always free match info even if there is no match. */
4820 g_match_info_free(mi);
4823 /** SSL keylog file handling. }}} */
4825 #ifdef SSL_DECRYPT_DEBUG /* {{{ */
4827 static FILE* ssl_debug_file=NULL;
4830 ssl_set_debug(const gchar* name)
4832 static gint debug_file_must_be_closed;
4835 debug_file_must_be_closed = 0;
4836 use_stderr = name?(strcmp(name, SSL_DEBUG_USE_STDERR) == 0):0;
4838 if (debug_file_must_be_closed)
4839 fclose(ssl_debug_file);
4841 ssl_debug_file = stderr;
4842 else if (!name || (strcmp(name, "") ==0))
4843 ssl_debug_file = NULL;
4845 ssl_debug_file = ws_fopen(name, "w");
4846 if (!use_stderr && ssl_debug_file)
4847 debug_file_must_be_closed = 1;
4849 ssl_debug_printf("Wireshark SSL debug log \n\n");
4850 ssl_debug_printf("Wireshark version: %s\n", get_ws_vcs_version_info());
4851 #ifdef HAVE_LIBGNUTLS
4852 ssl_debug_printf("GnuTLS version: %s\n", gnutls_check_version(NULL));
4854 #ifdef HAVE_LIBGCRYPT
4855 ssl_debug_printf("Libgcrypt version: %s\n", gcry_check_version(NULL));
4857 ssl_debug_printf("\n");
4861 ssl_debug_flush(void)
4864 fflush(ssl_debug_file);
4868 ssl_debug_printf(const gchar* fmt, ...)
4872 if (!ssl_debug_file)
4876 vfprintf(ssl_debug_file, fmt, ap);
4881 ssl_print_data(const gchar* name, const guchar* data, size_t len)
4884 if (!ssl_debug_file)
4886 fprintf(ssl_debug_file,"%s[%d]:\n",name, (int) len);
4887 for (i=0; i<len; i+=16) {
4888 fprintf(ssl_debug_file,"| ");
4889 for (j=i, k=0; k<16 && j<len; ++j, ++k)
4890 fprintf(ssl_debug_file,"%.2x ",data[j]);
4892 fprintf(ssl_debug_file," ");
4893 fputc('|', ssl_debug_file);
4894 for (j=i, k=0; k<16 && j<len; ++j, ++k) {
4896 if (!g_ascii_isprint(c) || (c=='\t')) c = '.';
4897 fputc(c, ssl_debug_file);
4900 fputc(' ', ssl_debug_file);
4901 fprintf(ssl_debug_file,"|\n");
4906 ssl_print_string(const gchar* name, const StringInfo* data)
4908 ssl_print_data(name, data->data, data->data_len);
4910 #endif /* SSL_DECRYPT_DEBUG }}} */
4912 /* UAT preferences callbacks. {{{ */
4913 /* checks for SSL and DTLS UAT key list fields */
4916 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)
4918 if (!p || strlen(p) == 0u) {
4919 *err = g_strdup("No IP address given.");
4928 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)
4930 if (!p || strlen(p) == 0u) {
4931 *err = g_strdup("No Port given.");
4935 if (strcmp(p, "start_tls") != 0){
4936 const gint i = atoi(p);
4937 if (i < 0 || i > 65535) {
4938 *err = g_strdup("Invalid port given.");
4948 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)
4952 if (!p || strlen(p) == 0u) {
4953 *err = g_strdup("No filename given.");
4956 if (ws_stat64(p, &st) != 0) {
4957 *err = g_strdup_printf("File '%s' does not exist or access is denied.", p);
4967 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)
4969 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
4970 ssldecrypt_assoc_t* f = (ssldecrypt_assoc_t *)r;
4973 if (p && (strlen(p) > 0u)) {
4974 fp = ws_fopen(f->keyfile, "rb");
4977 gnutls_x509_privkey_t priv_key = ssl_load_pkcs12(fp, p, &msg);
4980 *err = g_strdup_printf("Could not load PKCS#12 key file: %s", msg);
4985 gnutls_x509_privkey_deinit(priv_key);
4988 *err = g_strdup_printf("Leave this field blank if the keyfile is not PKCS#12.");
4996 *err = g_strdup("Cannot load key files, support is not compiled in.");
5000 /* UAT preferences callbacks. }}} */
5002 /** maximum size of ssl_association_info() string */
5003 #define SSL_ASSOC_MAX_LEN 8192
5005 typedef struct ssl_association_info_callback_data
5008 const char *table_protocol;
5009 } ssl_association_info_callback_data_t;
5012 * callback function used by ssl_association_info() to traverse the SSL associations.
5015 ssl_association_info_(const gchar *table _U_, gpointer handle, gpointer user_data)
5017 ssl_association_info_callback_data_t* data = (ssl_association_info_callback_data_t*)user_data;
5018 const int l = (const int)strlen(data->str);
5019 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);
5023 * @return an information string on the SSL protocol associations. The string has ephemeral lifetime/scope.
5026 ssl_association_info(const char* dissector_table_name, const char* table_protocol)
5028 ssl_association_info_callback_data_t data;
5030 data.str = (gchar *)g_malloc0(SSL_ASSOC_MAX_LEN);
5031 data.table_protocol = table_protocol;
5032 dissector_table_foreach_handle(dissector_table_name, ssl_association_info_, &data);
5037 /** Begin of code related to dissection of wire data. */
5039 /* change_cipher_spec(20) dissection */
5041 ssl_dissect_change_cipher_spec(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5042 packet_info *pinfo, proto_tree *tree,
5043 guint32 offset, SslSession *session,
5044 gboolean is_from_server,
5045 const SslDecryptSession *ssl)
5049 * enum { change_cipher_spec(1), (255) } type;
5050 * } ChangeCipherSpec;
5053 proto_item_set_text(tree,
5054 "%s Record Layer: %s Protocol: Change Cipher Spec",
5055 val_to_str_const(session->version, ssl_version_short_names, "SSL"),
5056 val_to_str_const(SSL_ID_CHG_CIPHER_SPEC, ssl_31_content_type, "unknown"));
5057 ti = proto_tree_add_item(tree, hf->hf.change_cipher_spec, tvb, offset, 1, ENC_NA);
5059 /* Use heuristics to detect an abbreviated handshake, assume that missing
5060 * ServerHelloDone implies reusing previously negotiating keys. Then when
5061 * a Session ID or ticket is present, it must be a resumed session.
5062 * Normally this should be done at the Finished message, but that may be
5063 * encrypted so we do it here, at the last cleartext message. */
5064 if (is_from_server && ssl) {
5065 if (!(ssl->state & SSL_SERVER_HELLO_DONE)) {
5066 const char *resumed = NULL;
5067 if (ssl->session_ticket.data_len) {
5068 resumed = "Session Ticket";
5069 } else if (ssl->session_id.data_len) {
5070 resumed = "Session ID";
5073 ssl_debug_printf("%s Session resumption using %s\n", G_STRFUNC, resumed);
5074 session->is_session_resumed = TRUE;
5076 /* Can happen if the capture somehow starts in the middle */
5077 ssl_debug_printf("%s No Session resumption, missing packets?\n", G_STRFUNC);
5080 ssl_debug_printf("%s Not using Session resumption\n", G_STRFUNC);
5083 if (is_from_server && session->is_session_resumed)
5084 expert_add_info(pinfo, ti, &hf->ei.resumed);
5087 /** Begin of handshake(22) record dissections */
5088 /* dissect a list of hash algorithms, return the number of bytes dissected
5089 this is used for the signature algorithms extension and for the
5090 TLS1.2 certificate request. {{{ */
5092 ssl_dissect_hash_alg_list(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5093 packet_info* pinfo, guint32 offset, guint16 len)
5095 guint32 offset_start;
5096 proto_tree *subtree, *alg_tree;
5099 offset_start = offset;
5103 ti = proto_tree_add_none_format(tree, hf->hf.hs_sig_hash_algs, tvb,
5105 "Signature Hash Algorithms (%u algorithm%s)",
5106 len / 2, plurality(len / 2, "", "s"));
5107 subtree = proto_item_add_subtree(ti, hf->ett.hs_sig_hash_algs);
5110 expert_add_info_format(pinfo, ti, &hf->ei.hs_sig_hash_algs_bad,
5111 "Invalid Signature Hash Algorithm length: %d", len);
5112 return offset-offset_start;
5116 ti = proto_tree_add_item(subtree, hf->hf.hs_sig_hash_alg,
5117 tvb, offset, 2, ENC_BIG_ENDIAN);
5118 alg_tree = proto_item_add_subtree(ti, hf->ett.hs_sig_hash_alg);
5120 proto_tree_add_item(alg_tree, hf->hf.hs_sig_hash_hash,
5121 tvb, offset, 1, ENC_BIG_ENDIAN);
5122 proto_tree_add_item(alg_tree, hf->hf.hs_sig_hash_sig,
5123 tvb, offset+1, 1, ENC_BIG_ENDIAN);
5128 return offset-offset_start;
5131 /** TLS Extensions (in Client Hello and Server Hello). {{{ */
5133 ssl_dissect_hnd_hello_ext_sig_hash_algs(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5134 proto_tree *tree, packet_info* pinfo, guint32 offset, guint32 ext_len)
5136 guint16 sh_alg_length;
5139 sh_alg_length = tvb_get_ntohs(tvb, offset);
5140 proto_tree_add_uint(tree, hf->hf.hs_sig_hash_alg_len,
5141 tvb, offset, 2, sh_alg_length);
5143 if (ext_len < 2 || sh_alg_length != ext_len - 2) {
5144 /* ERROR: sh_alg_length must be 2 less than ext_len */
5148 ret = ssl_dissect_hash_alg_list(hf, tvb, tree, pinfo, offset, sh_alg_length);
5156 ssl_dissect_hnd_hello_ext_alpn(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5157 proto_tree *tree, guint32 offset, guint32 ext_len,
5158 gboolean is_client, SslSession *session)
5160 guint16 alpn_length;
5162 proto_tree *alpn_tree;
5165 alpn_length = tvb_get_ntohs(tvb, offset);
5166 if (ext_len < 2 || alpn_length != ext_len - 2) {
5167 /* ERROR: alpn_length must be 2 less than ext_len */
5170 proto_tree_add_item(tree, hf->hf.hs_ext_alpn_len,
5171 tvb, offset, 2, ENC_BIG_ENDIAN);
5174 ti = proto_tree_add_item(tree, hf->hf.hs_ext_alpn_list,
5175 tvb, offset, alpn_length, ENC_NA);
5176 alpn_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_alpn);
5178 /* If ALPN is given in ServerHello, then ProtocolNameList MUST contain
5179 * exactly one "ProtocolName". */
5184 name_length = tvb_get_guint8(tvb, offset);
5185 /* '\0'-terminated string for prefix/full string comparison purposes. */
5186 proto_name = tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 1,
5187 name_length, ENC_ASCII);
5188 for (i = 0; i < G_N_ELEMENTS(ssl_alpn_protocols); i++) {
5189 const ssl_alpn_protocol_t *alpn_proto = &ssl_alpn_protocols[i];
5191 if (name_length >= alpn_proto->proto_name_len &&
5192 (memcmp(proto_name, alpn_proto->proto_name,
5193 alpn_proto->proto_name_len) == 0)) {
5195 dissector_handle_t handle;
5196 /* ProtocolName match, so set the App data dissector handle.
5197 * This may override protocols given via the UAT dialog, but
5198 * since the ALPN hint is precise, do it anyway. */
5199 handle = find_dissector(alpn_proto->dissector_name);
5200 ssl_debug_printf("%s: changing handle %p to %p (%s)", G_STRFUNC,
5201 (void *)session->app_handle,
5202 (void *)handle, alpn_proto->dissector_name);
5203 /* if dissector is disabled, do not overwrite previous one */
5205 session->app_handle = handle;
5211 while (alpn_length > 0) {
5212 name_length = tvb_get_guint8(tvb, offset);
5213 proto_tree_add_item(alpn_tree, hf->hf.hs_ext_alpn_str_len,
5214 tvb, offset, 1, ENC_NA);
5217 proto_tree_add_item(alpn_tree, hf->hf.hs_ext_alpn_str,
5218 tvb, offset, name_length, ENC_ASCII|ENC_NA);
5219 offset += name_length;
5220 alpn_length -= name_length;
5227 ssl_dissect_hnd_hello_ext_npn(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5228 proto_tree *tree, guint32 offset, guint32 ext_len)
5231 proto_tree *npn_tree;
5237 npn_tree = proto_tree_add_subtree(tree, tvb, offset, ext_len, hf->ett.hs_ext_npn, NULL, "Next Protocol Negotiation");
5239 while (ext_len > 0) {
5240 npn_length = tvb_get_guint8(tvb, offset);
5241 proto_tree_add_item(npn_tree, hf->hf.hs_ext_npn_str_len,
5242 tvb, offset, 1, ENC_NA);
5246 if (npn_length > 0) {
5247 proto_tree_add_item(npn_tree, hf->hf.hs_ext_npn_str,
5248 tvb, offset, npn_length, ENC_ASCII|ENC_NA);
5249 offset += npn_length;
5250 ext_len -= npn_length;
5258 ssl_dissect_hnd_hello_ext_reneg_info(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5259 proto_tree *tree, guint32 offset, guint32 ext_len)
5261 guint8 reneg_info_length;
5262 proto_tree *reneg_info_tree;
5268 reneg_info_tree = proto_tree_add_subtree(tree, tvb, offset, ext_len, hf->ett.hs_ext_reneg_info, NULL, "Renegotiation Info extension");
5270 reneg_info_length = tvb_get_guint8(tvb, offset);
5271 proto_tree_add_item(reneg_info_tree, hf->hf.hs_ext_reneg_info_len,
5272 tvb, offset, 1, ENC_NA);
5275 if (reneg_info_length > 0) {
5276 proto_tree_add_item(reneg_info_tree, hf->hf.hs_ext_reneg_info, tvb, offset, reneg_info_length, ENC_NA);
5277 offset += reneg_info_length;
5284 ssl_dissect_hnd_hello_ext_server_name(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5285 proto_tree *tree, guint32 offset, guint32 ext_len)
5287 guint16 server_name_length;
5288 proto_tree *server_name_tree;
5295 server_name_tree = proto_tree_add_subtree(tree, tvb, offset, ext_len, hf->ett.hs_ext_server_name, NULL, "Server Name Indication extension");
5297 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name_list_len,
5298 tvb, offset, 2, ENC_BIG_ENDIAN);
5302 while (ext_len > 0) {
5303 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name_type,
5304 tvb, offset, 1, ENC_NA);
5308 server_name_length = tvb_get_ntohs(tvb, offset);
5309 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name_len,
5310 tvb, offset, 2, ENC_BIG_ENDIAN);
5314 if (server_name_length > 0) {
5315 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name,
5316 tvb, offset, server_name_length, ENC_ASCII|ENC_NA);
5317 offset += server_name_length;
5318 ext_len -= server_name_length;
5325 ssl_dissect_hnd_hello_ext_padding(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5326 proto_tree *tree, guint32 offset, guint32 ext_len)
5328 guint8 padding_length;
5329 proto_tree *padding_tree;
5336 ti = proto_tree_add_item(tree, hf->hf.hs_ext_padding_data, tvb, offset, ext_len, ENC_NA);
5337 padding_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_padding);
5340 proto_tree_add_item(padding_tree, hf->hf.hs_ext_padding_len, tvb, offset, 2, ENC_NA);
5341 padding_length = tvb_get_guint8(tvb, offset);
5344 proto_tree_add_item(padding_tree, hf->hf.hs_ext_padding_data, tvb, offset, padding_length, ENC_NA);
5345 offset += padding_length;
5351 ssl_dissect_hnd_hello_ext_session_ticket(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5352 proto_tree *tree, guint32 offset, guint32 ext_len, gboolean is_client, SslDecryptSession *ssl)
5354 if (is_client && ssl && ext_len != 0) {
5355 tvb_ensure_bytes_exist(tvb, offset, ext_len);
5356 /* Save the Session Ticket such that it can be used as identifier for
5357 * restoring a previous Master Secret (in ChangeCipherSpec) */
5358 ssl->session_ticket.data = (guchar*)wmem_realloc(wmem_file_scope(),
5359 ssl->session_ticket.data, ext_len);
5360 ssl->session_ticket.data_len = ext_len;
5361 tvb_memcpy(tvb,ssl->session_ticket.data, offset, ext_len);
5363 proto_tree_add_bytes_format(tree, hf->hf.hs_ext_data,
5364 tvb, offset, ext_len, NULL,
5366 ext_len, plurality(ext_len, "", "s"));
5367 return offset + ext_len;
5371 ssl_dissect_hnd_hello_ext_cert_type(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5372 proto_tree *tree, guint32 offset, guint32 ext_len,
5373 gboolean is_client, guint16 ext_type, SslSession *session)
5375 guint8 cert_list_length;
5377 proto_tree *cert_list_tree;
5381 cert_list_length = tvb_get_guint8(tvb, offset);
5382 proto_tree_add_item(tree, hf->hf.hs_ext_cert_types_len,
5383 tvb, offset, 1, ENC_BIG_ENDIAN);
5385 if (ext_len != (guint32)cert_list_length + 1)
5388 ti = proto_tree_add_item(tree, hf->hf.hs_ext_cert_types, tvb, offset,
5389 cert_list_length, cert_list_length);
5390 proto_item_append_text(ti, " (%d)", cert_list_length);
5392 /* make this a subtree */
5393 cert_list_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_cert_types);
5395 /* loop over all point formats */
5396 while (cert_list_length > 0)
5398 proto_tree_add_item(cert_list_tree, hf->hf.hs_ext_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN);
5403 cert_type = tvb_get_guint8(tvb, offset);
5404 proto_tree_add_item(tree, hf->hf.hs_ext_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN);
5406 if (ext_type == SSL_HND_HELLO_EXT_CERT_TYPE || ext_type == SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE) {
5407 session->client_cert_type = cert_type;
5409 if (ext_type == SSL_HND_HELLO_EXT_CERT_TYPE || ext_type == SSL_HND_HELLO_EXT_SERVER_CERT_TYPE) {
5410 session->server_cert_type = cert_type;
5418 ssl_dissect_hnd_hello_common(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5419 proto_tree *tree, guint32 offset,
5420 SslDecryptSession *ssl, gboolean from_server)
5422 nstime_t gmt_unix_time;
5423 guint8 sessid_length;
5424 proto_tree *rnd_tree;
5429 rnd = &ssl->server_random;
5431 rnd = &ssl->client_random;
5433 /* save provided random for later keyring generation */
5434 tvb_memcpy(tvb, rnd->data, offset, 32);
5437 ssl->state |= SSL_SERVER_RANDOM;
5439 ssl->state |= SSL_CLIENT_RANDOM;
5440 ssl_debug_printf("%s found %s RANDOM -> state 0x%02X\n", G_STRFUNC,
5441 from_server ? "SERVER" : "CLIENT", ssl->state);
5444 rnd_tree = proto_tree_add_subtree(tree, tvb, offset, 32,
5445 hf->ett.hs_random, NULL, "Random");
5448 gmt_unix_time.secs = tvb_get_ntohl(tvb, offset);
5449 gmt_unix_time.nsecs = 0;
5450 proto_tree_add_time(rnd_tree, hf->hf.hs_random_time,
5451 tvb, offset, 4, &gmt_unix_time);
5454 /* show the random bytes */
5455 proto_tree_add_item(rnd_tree, hf->hf.hs_random_bytes,
5456 tvb, offset, 28, ENC_NA);
5459 /* show the session id (length followed by actual Session ID) */
5460 sessid_length = tvb_get_guint8(tvb, offset);
5461 proto_tree_add_item(tree, hf->hf.hs_session_id_len,
5462 tvb, offset, 1, ENC_BIG_ENDIAN);
5466 /* save the authorative SID for later use in ChangeCipherSpec.
5467 * (D)TLS restricts the SID to 32 chars, it does not make sense to
5468 * save more, so ignore larger ones. */
5469 if (from_server && sessid_length <= 32) {
5470 tvb_memcpy(tvb, ssl->session_id.data, offset, sessid_length);
5471 ssl->session_id.data_len = sessid_length;
5474 if (sessid_length > 0) {
5475 proto_tree_add_item(tree, hf->hf.hs_session_id,
5476 tvb, offset, sessid_length, ENC_NA);
5477 offset += sessid_length;
5484 ssl_dissect_hnd_hello_ext_status_request(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5485 guint32 offset, gboolean has_length)
5487 guint cert_status_type;
5489 cert_status_type = tvb_get_guint8(tvb, offset);
5490 proto_tree_add_item(tree, hf->hf.hs_ext_cert_status_type,
5491 tvb, offset, 1, ENC_NA);
5495 proto_tree_add_item(tree, hf->hf.hs_ext_cert_status_request_len,
5496 tvb, offset, 2, ENC_BIG_ENDIAN);
5500 switch (cert_status_type) {
5501 case SSL_HND_CERT_STATUS_TYPE_OCSP:
5502 case SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI:
5504 guint16 responder_id_list_len;
5505 guint16 request_extensions_len;
5506 proto_item *responder_id;
5507 proto_item *request_extensions;
5509 responder_id_list_len = tvb_get_ntohs(tvb, offset);
5511 proto_tree_add_item(tree,
5512 hf->hf.hs_ext_cert_status_responder_id_list_len,
5513 tvb, offset, 2, ENC_BIG_ENDIAN);
5515 if (responder_id_list_len != 0) {
5516 expert_add_info_format(NULL, responder_id,
5517 &hf->ei.hs_ext_cert_status_undecoded,
5518 "Responder ID list is not implemented, contact Wireshark"
5519 " developers if you want this to be supported");
5520 /* Non-empty responder ID list would mess with extensions. */
5524 request_extensions_len = tvb_get_ntohs(tvb, offset);
5525 request_extensions =
5526 proto_tree_add_item(tree,
5527 hf->hf.hs_ext_cert_status_request_extensions_len, tvb, offset,
5530 if (request_extensions_len != 0)
5531 expert_add_info_format(NULL, request_extensions,
5532 &hf->ei.hs_ext_cert_status_undecoded,
5533 "Request Extensions are not implemented, contact"
5534 " Wireshark developers if you want this to be supported");
5543 ssl_dissect_hnd_hello_ext_status_request_v2(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5548 list_len = tvb_get_ntohs(tvb, offset);
5551 while (list_len > 0) {
5552 guint32 prev_offset = offset;
5553 offset = ssl_dissect_hnd_hello_ext_status_request(hf, tvb, tree, offset, TRUE);
5554 list_len -= (offset - prev_offset);
5561 ssl_dissect_hnd_hello_ext_elliptic_curves(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5562 proto_tree *tree, guint32 offset)
5564 guint16 curves_length;
5565 proto_tree *curves_tree;
5568 curves_length = tvb_get_ntohs(tvb, offset);
5569 proto_tree_add_item(tree, hf->hf.hs_ext_elliptic_curves_len,
5570 tvb, offset, 2, ENC_BIG_ENDIAN);
5573 ti = proto_tree_add_none_format(tree,
5574 hf->hf.hs_ext_elliptic_curves,
5575 tvb, offset, curves_length,
5576 "Elliptic curves (%d curve%s)",
5578 plurality(curves_length/2, "", "s"));
5580 /* make this a subtree */
5581 curves_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_curves);
5583 /* loop over all curves */
5584 while (curves_length > 0)
5586 proto_tree_add_item(curves_tree, hf->hf.hs_ext_elliptic_curve, tvb, offset, 2, ENC_BIG_ENDIAN);
5595 ssl_dissect_hnd_hello_ext_ec_point_formats(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5596 proto_tree *tree, guint32 offset)
5599 proto_tree *ecpf_tree;
5602 ecpf_length = tvb_get_guint8(tvb, offset);
5603 proto_tree_add_item(tree, hf->hf.hs_ext_ec_point_formats_len,
5604 tvb, offset, 1, ENC_BIG_ENDIAN);
5607 ti = proto_tree_add_none_format(tree,
5608 hf->hf.hs_ext_elliptic_curves,
5609 tvb, offset, ecpf_length,
5610 "Elliptic curves point formats (%d)",
5613 /* make this a subtree */
5614 ecpf_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_curves_point_formats);
5616 /* loop over all point formats */
5617 while (ecpf_length > 0)
5619 proto_tree_add_item(ecpf_tree, hf->hf.hs_ext_ec_point_format, tvb, offset, 1, ENC_BIG_ENDIAN);
5626 /** TLS Extensions (in Client Hello and Server Hello). }}} */
5628 /* Whether the Content and Handshake Types are valid; handle Protocol Version. {{{ */
5630 ssl_is_valid_content_type(guint8 type)
5632 switch ((ContentType) type) {
5633 case SSL_ID_CHG_CIPHER_SPEC:
5635 case SSL_ID_HANDSHAKE:
5636 case SSL_ID_APP_DATA:
5637 case SSL_ID_HEARTBEAT:
5644 ssl_is_valid_handshake_type(guint8 hs_type, gboolean is_dtls)
5646 switch ((HandshakeType) hs_type) {
5647 case SSL_HND_HELLO_VERIFY_REQUEST:
5648 /* hello_verify_request is DTLS-only */
5651 case SSL_HND_HELLO_REQUEST:
5652 case SSL_HND_CLIENT_HELLO:
5653 case SSL_HND_SERVER_HELLO:
5654 case SSL_HND_NEWSESSION_TICKET:
5655 case SSL_HND_CERTIFICATE:
5656 case SSL_HND_SERVER_KEY_EXCHG:
5657 case SSL_HND_CERT_REQUEST:
5658 case SSL_HND_SVR_HELLO_DONE:
5659 case SSL_HND_CERT_VERIFY:
5660 case SSL_HND_CLIENT_KEY_EXCHG:
5661 case SSL_HND_FINISHED:
5662 case SSL_HND_CERT_URL:
5663 case SSL_HND_CERT_STATUS:
5664 case SSL_HND_SUPPLEMENTAL_DATA:
5665 case SSL_HND_ENCRYPTED_EXTS:
5672 ssl_is_authoritative_version_message(guint8 content_type, guint8 handshake_type,
5675 /* Consider all valid Handshake messages (except for Client Hello) and
5676 * all other valid record types (other than Handshake) */
5677 return (content_type == SSL_ID_HANDSHAKE &&
5678 ssl_is_valid_handshake_type(handshake_type, is_dtls) &&
5679 handshake_type != SSL_HND_CLIENT_HELLO) ||
5680 (content_type != SSL_ID_HANDSHAKE &&
5681 ssl_is_valid_content_type(content_type));
5685 ssl_try_set_version(SslSession *session, SslDecryptSession *ssl,
5686 guint8 content_type, guint8 handshake_type,
5687 gboolean is_dtls, guint16 version)
5689 if (!ssl_is_authoritative_version_message(content_type, handshake_type,
5696 case TLSV1DOT1_VERSION:
5697 case TLSV1DOT2_VERSION:
5702 case DTLSV1DOT0_VERSION:
5703 case DTLSV1DOT0_OPENSSL_VERSION:
5704 case DTLSV1DOT2_VERSION:
5709 default: /* invalid version number */
5713 session->version = version;
5715 ssl->state |= SSL_VERSION;
5716 ssl_debug_printf("%s found version 0x%04X -> state 0x%02X\n", G_STRFUNC, version, ssl->state);
5722 /* Client Hello and Server Hello dissections. {{{ */
5724 ssl_dissect_hnd_hello_ext(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5725 packet_info* pinfo, guint32 offset, guint32 left, gboolean is_client,
5726 SslSession *session, SslDecryptSession *ssl);
5728 ssl_dissect_hnd_cli_hello(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5729 packet_info *pinfo, proto_tree *tree, guint32 offset,
5730 guint32 length, SslSession *session,
5731 SslDecryptSession *ssl, dtls_hfs_t *dtls_hfs)
5734 * ProtocolVersion client_version;
5736 * SessionID session_id;
5737 * opaque cookie<0..32>; //new field for DTLS
5738 * CipherSuite cipher_suites<2..2^16-1>;
5739 * CompressionMethod compression_methods<1..2^8-1>;
5740 * Extension client_hello_extension_list<0..2^16-1>;
5745 proto_tree *cs_tree;
5746 guint16 cipher_suite_length;
5747 guint8 compression_methods_length;
5748 guint8 compression_method;
5749 guint16 start_offset = offset;
5751 /* show the client version */
5752 proto_tree_add_item(tree, hf->hf.hs_client_version, tvb,
5753 offset, 2, ENC_BIG_ENDIAN);
5756 /* dissect fields that are also present in ClientHello */
5757 offset = ssl_dissect_hnd_hello_common(hf, tvb, tree, offset, ssl, FALSE);
5759 /* fields specific for DTLS (cookie_len, cookie) */
5760 if (dtls_hfs != NULL) {
5761 /* look for a cookie */
5762 guint8 cookie_length = tvb_get_guint8(tvb, offset);
5764 proto_tree_add_uint(tree, dtls_hfs->hf_dtls_handshake_cookie_len,
5765 tvb, offset, 1, cookie_length);
5767 if (cookie_length > 0) {
5768 proto_tree_add_item(tree, dtls_hfs->hf_dtls_handshake_cookie,
5769 tvb, offset, cookie_length, ENC_NA);
5770 offset += cookie_length;
5774 /* tell the user how many cipher suites there are */
5775 cipher_suite_length = tvb_get_ntohs(tvb, offset);
5776 ti = proto_tree_add_item(tree, hf->hf.hs_cipher_suites_len,
5777 tvb, offset, 2, ENC_BIG_ENDIAN);
5779 if (cipher_suite_length > 0) {
5780 if (cipher_suite_length % 2) {
5781 expert_add_info_format(pinfo, ti, &hf->ei.hs_cipher_suites_len_bad,
5782 "Cipher suite length (%d) must be a multiple of 2",
5783 cipher_suite_length);
5786 ti = proto_tree_add_none_format(tree,
5787 hf->hf.hs_cipher_suites,
5788 tvb, offset, cipher_suite_length,
5789 "Cipher Suites (%d suite%s)",
5790 cipher_suite_length / 2,
5791 plurality(cipher_suite_length/2, "", "s"));
5793 /* make this a subtree */
5794 cs_tree = proto_item_add_subtree(ti, hf->ett.cipher_suites);
5796 while (cipher_suite_length > 0) {
5797 proto_tree_add_item(cs_tree, hf->hf.hs_cipher_suite,
5798 tvb, offset, 2, ENC_BIG_ENDIAN);
5800 cipher_suite_length -= 2;
5803 /* tell the user how many compression methods there are */
5804 compression_methods_length = tvb_get_guint8(tvb, offset);
5805 proto_tree_add_uint(tree, hf->hf.hs_comp_methods_len,
5806 tvb, offset, 1, compression_methods_length);
5808 if (compression_methods_length > 0) {
5809 ti = proto_tree_add_none_format(tree,
5810 hf->hf.hs_comp_methods,
5811 tvb, offset, compression_methods_length,
5812 "Compression Methods (%u method%s)",
5813 compression_methods_length,
5814 plurality(compression_methods_length,
5817 /* make this a subtree */
5818 cs_tree = proto_item_add_subtree(ti, hf->ett.comp_methods);
5820 while (compression_methods_length > 0) {
5821 compression_method = tvb_get_guint8(tvb, offset);
5822 /* TODO: make reserved/private comp meth. fields selectable */
5823 if (compression_method < 64)
5824 proto_tree_add_uint(cs_tree, hf->hf.hs_comp_method,
5825 tvb, offset, 1, compression_method);
5826 else if (compression_method > 63 && compression_method < 193)
5827 proto_tree_add_uint_format_value(cs_tree, hf->hf.hs_comp_method, tvb, offset, 1,
5828 compression_method, "Reserved - to be assigned by IANA (%u)",
5829 compression_method);
5831 proto_tree_add_uint_format_value(cs_tree, hf->hf.hs_comp_method, tvb, offset, 1,
5832 compression_method, "Private use range (%u)",
5833 compression_method);
5835 compression_methods_length--;
5838 if (length > offset - start_offset) {
5839 ssl_dissect_hnd_hello_ext(hf, tvb, tree, pinfo, offset,
5840 length - (offset - start_offset), TRUE,
5846 ssl_dissect_hnd_srv_hello(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5847 packet_info* pinfo, proto_tree *tree, guint32 offset, guint32 length,
5848 SslSession *session, SslDecryptSession *ssl,
5852 * ProtocolVersion server_version;
5854 * SessionID session_id;
5855 * CipherSuite cipher_suite;
5856 * CompressionMethod compression_method;
5857 * Extension server_hello_extension_list<0..2^16-1>;
5860 guint16 start_offset = offset;
5862 /* This version is always better than the guess at the Record Layer */
5863 ssl_try_set_version(session, ssl, SSL_ID_HANDSHAKE, SSL_HND_SERVER_HELLO,
5864 is_dtls, tvb_get_ntohs(tvb, offset));
5866 /* show the server version */
5867 proto_tree_add_item(tree, hf->hf.hs_server_version, tvb,
5868 offset, 2, ENC_BIG_ENDIAN);
5871 /* dissect fields that are also present in ClientHello */
5872 offset = ssl_dissect_hnd_hello_common(hf, tvb, tree, offset, ssl, TRUE);
5875 /* store selected cipher suite for decryption */
5876 ssl->session.cipher = tvb_get_ntohs(tvb, offset);
5878 if (ssl_find_cipher(ssl->session.cipher, &ssl->cipher_suite) < 0) {
5879 ssl_debug_printf("%s can't find cipher suite 0x%04X\n",
5880 G_STRFUNC, ssl->session.cipher);
5882 /* Cipher found, save this for the delayed decoder init */
5883 ssl->state |= SSL_CIPHER;
5884 ssl_debug_printf("%s found CIPHER 0x%04X %s -> state 0x%02X\n",
5885 G_STRFUNC, ssl->session.cipher,
5886 val_to_str_ext_const(ssl->session.cipher,
5887 &ssl_31_ciphersuite_ext, "unknown"),
5892 /* now the server-selected cipher suite */
5893 proto_tree_add_item(tree, hf->hf.hs_cipher_suite,
5894 tvb, offset, 2, ENC_BIG_ENDIAN);
5898 /* store selected compression method for decryption */
5899 ssl->session.compression = tvb_get_guint8(tvb, offset);
5901 /* and the server-selected compression method */
5902 proto_tree_add_item(tree, hf->hf.hs_comp_method,
5903 tvb, offset, 1, ENC_BIG_ENDIAN);
5906 /* remaining data are extensions */
5907 if (length > offset - start_offset) {
5908 ssl_dissect_hnd_hello_ext(hf, tvb, tree, pinfo, offset,
5909 length - (offset - start_offset), FALSE,
5913 /* Client Hello and Server Hello dissections. }}} */
5915 /* New Session Ticket dissection. {{{ */
5917 ssl_dissect_hnd_new_ses_ticket(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5918 proto_tree *tree, guint32 offset,
5919 SslDecryptSession *ssl _U_,
5920 GHashTable *session_hash _U_)
5922 proto_tree *subtree;
5925 /* length of session ticket, may be 0 if the server has sent the
5926 * SessionTicket extension, but decides not to use one. */
5927 ticket_len = tvb_get_ntohs(tvb, offset + 4);
5928 subtree = proto_tree_add_subtree(tree, tvb, offset, 6 + ticket_len,
5929 hf->ett.session_ticket, NULL,
5930 "TLS Session Ticket");
5932 /* ticket lifetime hint */
5933 proto_tree_add_item(subtree, hf->hf.hs_session_ticket_lifetime_hint,
5934 tvb, offset, 4, ENC_BIG_ENDIAN);
5937 /* opaque ticket (length, data) */
5938 proto_tree_add_item(subtree, hf->hf.hs_session_ticket_len,
5939 tvb, offset, 2, ENC_BIG_ENDIAN);
5941 /* Content depends on implementation, so just show data! */
5942 proto_tree_add_item(subtree, hf->hf.hs_session_ticket,
5943 tvb, offset, ticket_len, ENC_NA);
5944 /* save the session ticket to cache for ssl_finalize_decryption */
5945 #ifdef HAVE_LIBGCRYPT
5947 tvb_ensure_bytes_exist(tvb, offset, ticket_len);
5948 ssl->session_ticket.data = (guchar*)wmem_realloc(wmem_file_scope(),
5949 ssl->session_ticket.data, ticket_len);
5950 ssl->session_ticket.data_len = ticket_len;
5951 tvb_memcpy(tvb, ssl->session_ticket.data, offset, ticket_len);
5952 /* NewSessionTicket is received after the first (client)
5953 * ChangeCipherSpec, and before the second (server) ChangeCipherSpec.
5954 * Since the second CCS has already the session key available it will
5955 * just return. To ensure that the session ticket is mapped to a
5956 * master key (from the first CCS), save the ticket here too. */
5957 ssl_save_master_key("Session Ticket", session_hash,
5958 &ssl->session_ticket, &ssl->master_secret);
5959 ssl->state |= SSL_NEW_SESSION_TICKET;
5964 /* Certificate and Certificate Request dissections. {{{ */
5966 ssl_dissect_hnd_cert(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5967 guint32 offset, packet_info *pinfo,
5968 const SslSession *session, SslDecryptSession *ssl _U_,
5969 GHashTable *key_hash _U_, gint is_from_server)
5971 /* opaque ASN.1Cert<1..2^24-1>;
5974 * select(certificate_type) {
5976 * // certificate type defined in RFC 7250
5977 * case RawPublicKey:
5978 * opaque ASN.1_subjectPublicKeyInfo<1..2^24-1>;
5980 * // X.509 certificate defined in RFC 5246
5982 * ASN.1Cert certificate_list<0..2^24-1>;
5986 enum { CERT_X509, CERT_RPK } cert_type;
5987 asn1_ctx_t asn1_ctx;
5988 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
5989 gnutls_datum_t subjectPublicKeyInfo = { NULL, 0 };
5992 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
5994 if ((is_from_server && session->server_cert_type == SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY) ||
5995 (!is_from_server && session->client_cert_type == SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY)) {
5996 cert_type = CERT_RPK;
5998 cert_type = CERT_X509;
6001 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
6002 /* Ask the pkcs1 dissector to return the public key details */
6004 asn1_ctx.private_data = &subjectPublicKeyInfo;
6007 switch (cert_type) {
6010 proto_tree_add_item(tree, hf->hf.hs_certificate_len,
6011 tvb, offset, 3, ENC_BIG_ENDIAN);
6014 dissect_x509af_SubjectPublicKeyInfo(FALSE, tvb, offset, &asn1_ctx, tree, hf->hf.hs_certificate);
6020 guint32 certificate_list_length;
6022 proto_tree *subtree;
6024 certificate_list_length = tvb_get_ntoh24(tvb, offset);
6026 proto_tree_add_uint(tree, hf->hf.hs_certificates_len,
6027 tvb, offset, 3, certificate_list_length);
6028 offset += 3; /* 24-bit length value */
6030 if (certificate_list_length > 0) {
6031 ti = proto_tree_add_none_format(tree,
6032 hf->hf.hs_certificates,
6033 tvb, offset, certificate_list_length,
6034 "Certificates (%u bytes)",
6035 certificate_list_length);
6037 /* make it a subtree */
6038 subtree = proto_item_add_subtree(ti, hf->ett.certificates);
6040 /* iterate through each certificate */
6041 while (certificate_list_length > 0) {
6042 /* get the length of the current certificate */
6043 guint32 cert_length;
6044 cert_length = tvb_get_ntoh24(tvb, offset);
6045 certificate_list_length -= 3 + cert_length;
6047 proto_tree_add_item(subtree, hf->hf.hs_certificate_len,
6048 tvb, offset, 3, ENC_BIG_ENDIAN);
6051 dissect_x509af_Certificate(FALSE, tvb, offset, &asn1_ctx, subtree, hf->hf.hs_certificate);
6052 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
6053 /* Only attempt to get the RSA modulus for the first cert. */
6054 asn1_ctx.private_data = NULL;
6057 offset += cert_length;
6064 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
6065 if (is_from_server && ssl)
6066 ssl_find_private_key_by_pubkey(ssl, key_hash, &subjectPublicKeyInfo);
6071 ssl_dissect_hnd_cert_req(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6072 proto_tree *tree, guint32 offset, packet_info *pinfo,
6073 const SslSession *session)
6077 * rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
6079 * } ClientCertificateType;
6081 * opaque DistinguishedName<1..2^16-1>;
6084 * ClientCertificateType certificate_types<1..2^8-1>;
6085 * DistinguishedName certificate_authorities<3..2^16-1>;
6086 * } CertificateRequest;
6089 * As per TLSv1.2 (RFC 5246) the format has changed to:
6092 * rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
6093 * rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
6094 * fortezza_dms_RESERVED(20), (255)
6095 * } ClientCertificateType;
6098 * none(0), md5(1), sha1(2), sha224(3), sha256(4), sha384(5),
6102 * enum { anonymous(0), rsa(1), dsa(2), ecdsa(3), (255) }
6103 * SignatureAlgorithm;
6106 * HashAlgorithm hash;
6107 * SignatureAlgorithm signature;
6108 * } SignatureAndHashAlgorithm;
6110 * SignatureAndHashAlgorithm
6111 * supported_signature_algorithms<2..2^16-2>;
6113 * opaque DistinguishedName<1..2^16-1>;
6116 * ClientCertificateType certificate_types<1..2^8-1>;
6117 * SignatureAndHashAlgorithm
6118 * supported_signature_algorithms<2^16-1>;
6119 * DistinguishedName certificate_authorities<0..2^16-1>;
6120 * } CertificateRequest;
6124 proto_tree *subtree;
6125 guint8 cert_types_count;
6128 asn1_ctx_t asn1_ctx;
6134 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
6136 cert_types_count = tvb_get_guint8(tvb, offset);
6137 proto_tree_add_uint(tree, hf->hf.hs_cert_types_count,
6138 tvb, offset, 1, cert_types_count);
6141 if (cert_types_count > 0) {
6142 ti = proto_tree_add_none_format(tree,
6143 hf->hf.hs_cert_types,
6144 tvb, offset, cert_types_count,
6145 "Certificate types (%u type%s)",
6147 plurality(cert_types_count, "", "s"));
6148 subtree = proto_item_add_subtree(ti, hf->ett.cert_types);
6150 while (cert_types_count > 0) {
6151 proto_tree_add_item(subtree, hf->hf.hs_cert_type,
6152 tvb, offset, 1, ENC_BIG_ENDIAN);
6158 switch (session->version) {
6159 case TLSV1DOT2_VERSION:
6160 case DTLSV1DOT2_VERSION:
6161 sh_alg_length = tvb_get_ntohs(tvb, offset);
6162 if (sh_alg_length % 2) {
6163 expert_add_info_format(pinfo, NULL,
6164 &hf->ei.hs_sig_hash_alg_len_bad,
6165 "Signature Hash Algorithm length (%d) must be a multiple of 2",
6170 proto_tree_add_uint(tree, hf->hf.hs_sig_hash_alg_len,
6171 tvb, offset, 2, sh_alg_length);
6174 ret = ssl_dissect_hash_alg_list(hf, tvb, tree, pinfo, offset, sh_alg_length);
6183 dnames_length = tvb_get_ntohs(tvb, offset);
6184 proto_tree_add_uint(tree, hf->hf.hs_dnames_len,
6185 tvb, offset, 2, dnames_length);
6188 if (dnames_length > 0) {
6189 ti = proto_tree_add_none_format(tree,
6191 tvb, offset, dnames_length,
6192 "Distinguished Names (%d byte%s)",
6194 plurality(dnames_length, "", "s"));
6195 subtree = proto_item_add_subtree(ti, hf->ett.dnames);
6197 while (dnames_length > 0) {
6198 /* get the length of the current certificate */
6199 guint16 name_length;
6200 name_length = tvb_get_ntohs(tvb, offset);
6201 dnames_length -= 2 + name_length;
6203 proto_tree_add_item(subtree, hf->hf.hs_dname_len,
6204 tvb, offset, 2, ENC_BIG_ENDIAN);
6207 dissect_x509if_DistinguishedName(FALSE, tvb, offset, &asn1_ctx,
6208 subtree, hf->hf.hs_dname);
6209 offset += name_length;
6213 /* Certificate and Certificate Request dissections. }}} */
6216 ssl_dissect_digitally_signed(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6217 proto_tree *tree, guint32 offset,
6218 const SslSession *session,
6219 gint hf_sig_len, gint hf_sig);
6222 ssl_dissect_hnd_cli_cert_verify(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6223 proto_tree *tree, guint32 offset,
6224 const SslSession *session)
6226 ssl_dissect_digitally_signed(hf, tvb, tree, offset, session,
6227 hf->hf.hs_client_cert_vrfy_sig_len,
6228 hf->hf.hs_client_cert_vrfy_sig);
6231 /* Finished dissection. {{{ */
6233 ssl_dissect_hnd_finished(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6234 proto_tree *tree, guint32 offset,
6235 const SslSession *session, ssl_hfs_t *ssl_hfs)
6239 * opaque md5_hash[16];
6240 * opaque sha_hash[20];
6245 * opaque verify_data[12];
6251 if (session->version == SSLV3_VERSION) {
6252 if (ssl_hfs != NULL) {
6253 proto_tree_add_item(tree, ssl_hfs->hs_md5_hash,
6254 tvb, offset, 16, ENC_NA);
6255 proto_tree_add_item(tree, ssl_hfs->hs_sha_hash,
6256 tvb, offset + 16, 20, ENC_NA);
6259 proto_tree_add_item(tree, hf->hf.hs_finished,
6260 tvb, offset, 12, ENC_NA);
6264 /* RFC 6066 Certificate URL handshake message dissection. {{{ */
6266 ssl_dissect_hnd_cert_url(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree, guint32 offset)
6268 guint16 url_hash_len;
6271 * individual_certs(0), pkipath(1), (255)
6275 * CertChainType type;
6276 * URLAndHash url_and_hash_list<1..2^16-1>;
6280 * opaque url<1..2^16-1>;
6282 * opaque SHA1Hash[20];
6286 proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_type,
6287 tvb, offset, 1, ENC_NA);
6290 url_hash_len = tvb_get_ntohs(tvb, offset);
6291 proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_url_hash_list_len,
6292 tvb, offset, 2, ENC_BIG_ENDIAN);
6294 while (url_hash_len-- > 0) {
6295 proto_item *urlhash_item;
6296 proto_tree *urlhash_tree;
6299 urlhash_item = proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_item,
6300 tvb, offset, -1, ENC_NA);
6301 urlhash_tree = proto_item_add_subtree(urlhash_item, hf->ett.urlhash);
6303 url_len = tvb_get_ntohs(tvb, offset);
6304 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_url_len,
6305 tvb, offset, 2, ENC_BIG_ENDIAN);
6308 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_url,
6309 tvb, offset, url_len, ENC_ASCII|ENC_NA);
6312 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_padding,
6313 tvb, offset, 1, ENC_NA);
6315 /* Note: RFC 6066 says that padding must be 0x01 */
6317 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_sha1,
6318 tvb, offset, 20, ENC_NA);
6323 /* Client Hello and Server Hello TLS extensions dissection. {{{ */
6325 ssl_dissect_hnd_hello_ext(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
6326 packet_info* pinfo, guint32 offset, guint32 left, gboolean is_client,
6327 SslSession *session, SslDecryptSession *ssl)
6329 guint16 extension_length;
6332 proto_tree *ext_tree;
6337 extension_length = tvb_get_ntohs(tvb, offset);
6338 proto_tree_add_uint(tree, hf->hf.hs_exts_len,
6339 tvb, offset, 2, extension_length);
6345 ext_type = tvb_get_ntohs(tvb, offset);
6346 ext_len = tvb_get_ntohs(tvb, offset + 2);
6348 ext_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4 + ext_len, hf->ett.hs_ext, NULL,
6349 "Extension: %s", val_to_str(ext_type,
6350 tls_hello_extension_types,
6353 proto_tree_add_uint(ext_tree, hf->hf.hs_ext_type,
6354 tvb, offset, 2, ext_type);
6357 proto_tree_add_uint(ext_tree, hf->hf.hs_ext_len,
6358 tvb, offset, 2, ext_len);
6362 case SSL_HND_HELLO_EXT_STATUS_REQUEST:
6364 offset = ssl_dissect_hnd_hello_ext_status_request(hf, tvb, ext_tree, offset, FALSE);
6366 offset += ext_len; /* server must return empty extension_data */
6368 case SSL_HND_HELLO_EXT_STATUS_REQUEST_V2:
6370 offset = ssl_dissect_hnd_hello_ext_status_request_v2(hf, tvb, ext_tree, offset);
6372 offset += ext_len; /* server must return empty extension_data */
6374 case SSL_HND_HELLO_EXT_ELLIPTIC_CURVES:
6375 offset = ssl_dissect_hnd_hello_ext_elliptic_curves(hf, tvb, ext_tree, offset);
6377 case SSL_HND_HELLO_EXT_EC_POINT_FORMATS:
6378 offset = ssl_dissect_hnd_hello_ext_ec_point_formats(hf, tvb, ext_tree, offset);
6380 case SSL_HND_HELLO_EXT_SIG_HASH_ALGS:
6381 offset = ssl_dissect_hnd_hello_ext_sig_hash_algs(hf, tvb, ext_tree, pinfo, offset, ext_len);
6383 case SSL_HND_HELLO_EXT_ALPN:
6384 offset = ssl_dissect_hnd_hello_ext_alpn(hf, tvb, ext_tree, offset, ext_len, is_client, session);
6386 case SSL_HND_HELLO_EXT_NPN:
6387 offset = ssl_dissect_hnd_hello_ext_npn(hf, tvb, ext_tree, offset, ext_len);
6389 case SSL_HND_HELLO_EXT_RENEG_INFO:
6390 offset = ssl_dissect_hnd_hello_ext_reneg_info(hf, tvb, ext_tree, offset, ext_len);
6392 case SSL_HND_HELLO_EXT_SERVER_NAME:
6393 offset = ssl_dissect_hnd_hello_ext_server_name(hf, tvb, ext_tree, offset, ext_len);
6395 case SSL_HND_HELLO_EXT_HEARTBEAT:
6396 proto_tree_add_item(ext_tree, hf->hf.hs_ext_heartbeat_mode,
6397 tvb, offset, 1, ENC_BIG_ENDIAN);
6400 case SSL_HND_HELLO_EXT_PADDING:
6401 offset = ssl_dissect_hnd_hello_ext_padding(hf, tvb, ext_tree, offset, ext_len);
6403 case SSL_HND_HELLO_EXT_SESSION_TICKET:
6404 offset = ssl_dissect_hnd_hello_ext_session_ticket(hf, tvb, ext_tree, offset, ext_len, is_client, ssl);
6406 case SSL_HND_HELLO_EXT_CERT_TYPE:
6407 case SSL_HND_HELLO_EXT_SERVER_CERT_TYPE:
6408 case SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE:
6409 offset = ssl_dissect_hnd_hello_ext_cert_type(hf, tvb, ext_tree,
6411 is_client, ext_type,
6414 case SSL_HND_HELLO_EXT_EXTENDED_MASTER_SECRET_TYPE:
6416 ssl->state |= (is_client ? SSL_CLIENT_EXTENDED_MASTER_SECRET : SSL_SERVER_EXTENDED_MASTER_SECRET);
6419 proto_tree_add_bytes_format(ext_tree, hf->hf.hs_ext_data,
6420 tvb, offset, ext_len, NULL,
6422 ext_len, plurality(ext_len, "", "s"));
6427 left -= 2 + 2 + ext_len;
6434 /* ClientKeyExchange algo-specific dissectors. {{{ */
6437 dissect_ssl3_hnd_cli_keyex_ecdh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6438 proto_tree *tree, guint32 offset,
6442 proto_tree *ssl_ecdh_tree;
6444 ssl_ecdh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6445 hf->ett.keyex_params, NULL, "EC Diffie-Hellman Client Params");
6448 point_len = tvb_get_guint8(tvb, offset);
6449 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_client_keyex_point_len, tvb,
6450 offset, 1, ENC_BIG_ENDIAN);
6451 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_client_keyex_point, tvb,
6452 offset + 1, point_len, ENC_NA);
6456 dissect_ssl3_hnd_cli_keyex_dh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6457 proto_tree *tree, guint32 offset, guint32 length)
6460 proto_tree *ssl_dh_tree;
6462 ssl_dh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6463 hf->ett.keyex_params, NULL, "Diffie-Hellman Client Params");
6465 /* ClientDiffieHellmanPublic.dh_public (explicit) */
6466 yc_len = tvb_get_ntohs(tvb, offset);
6467 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_client_keyex_yc_len, tvb,
6468 offset, 2, ENC_BIG_ENDIAN);
6469 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_client_keyex_yc, tvb,
6470 offset + 2, yc_len, ENC_NA);
6474 dissect_ssl3_hnd_cli_keyex_rsa(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6475 proto_tree *tree, guint32 offset,
6476 guint32 length, const SslSession *session)
6479 proto_tree *ssl_rsa_tree;
6481 ssl_rsa_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6482 hf->ett.keyex_params, NULL, "RSA Encrypted PreMaster Secret");
6484 /* EncryptedPreMasterSecret.pre_master_secret */
6485 switch (session->version) {
6488 case DTLSV1DOT0_OPENSSL_VERSION:
6489 /* OpenSSL pre-0.9.8f DTLS and pre-TLS quirk: 2-octet length vector is
6490 * not present. The handshake contents represents the EPMS, see:
6491 * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10222 */
6496 /* TLS and DTLS include vector length before EPMS */
6497 epms_len = tvb_get_ntohs(tvb, offset);
6498 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_client_keyex_epms_len, tvb,
6499 offset, 2, ENC_BIG_ENDIAN);
6503 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_client_keyex_epms, tvb,
6504 offset, epms_len, ENC_NA);
6507 /* Used in PSK cipher suites */
6509 dissect_ssl3_hnd_cli_keyex_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6510 proto_tree *tree, guint32 offset, guint32 length)
6513 proto_tree *ssl_psk_tree;
6515 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6516 hf->ett.keyex_params, NULL, "PSK Client Params");
6518 identity_len = tvb_get_ntohs(tvb, offset);
6519 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity_len, tvb,
6520 offset, 2, ENC_BIG_ENDIAN);
6521 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity, tvb,
6522 offset + 2, identity_len, ENC_NA);
6525 /* Used in RSA PSK cipher suites */
6527 dissect_ssl3_hnd_cli_keyex_rsa_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6528 proto_tree *tree, guint32 offset,
6531 gint identity_len, epms_len;
6532 proto_tree *ssl_psk_tree;
6534 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6535 hf->ett.keyex_params, NULL, "RSA PSK Client Params");
6538 identity_len = tvb_get_ntohs(tvb, offset);
6539 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity_len,
6540 tvb, offset, 2, ENC_BIG_ENDIAN);
6541 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity,
6542 tvb, offset + 2, identity_len, ENC_NA);
6543 offset += 2 + identity_len;
6546 epms_len = tvb_get_ntohs(tvb, offset);
6547 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_epms_len, tvb,
6548 offset, 2, ENC_BIG_ENDIAN);
6549 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_epms, tvb,
6550 offset + 2, epms_len, ENC_NA);
6552 /* ClientKeyExchange algo-specific dissectors. }}} */
6555 /* Dissects DigitallySigned (see RFC 5246 4.7 Cryptographic Attributes). {{{ */
6557 ssl_dissect_digitally_signed(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6558 proto_tree *tree, guint32 offset,
6559 const SslSession *session,
6560 gint hf_sig_len, gint hf_sig)
6563 proto_item *ti_algo;
6564 proto_tree *ssl_algo_tree;
6566 switch (session->version) {
6567 case TLSV1DOT2_VERSION:
6568 case DTLSV1DOT2_VERSION:
6569 ti_algo = proto_tree_add_item(tree, hf->hf.hs_sig_hash_alg, tvb,
6570 offset, 2, ENC_BIG_ENDIAN);
6571 ssl_algo_tree = proto_item_add_subtree(ti_algo, hf->ett.hs_sig_hash_alg);
6573 /* SignatureAndHashAlgorithm { hash, signature } */
6574 proto_tree_add_item(ssl_algo_tree, hf->hf.hs_sig_hash_hash, tvb,
6575 offset, 1, ENC_BIG_ENDIAN);
6576 proto_tree_add_item(ssl_algo_tree, hf->hf.hs_sig_hash_sig, tvb,
6577 offset + 1, 1, ENC_BIG_ENDIAN);
6586 sig_len = tvb_get_ntohs(tvb, offset);
6587 proto_tree_add_item(tree, hf_sig_len, tvb, offset, 2, ENC_BIG_ENDIAN);
6588 proto_tree_add_item(tree, hf_sig, tvb, offset + 2, sig_len, ENC_NA);
6591 /* ServerKeyExchange algo-specific dissectors. {{{ */
6593 /* dissects signed_params inside a ServerKeyExchange for some keyex algos */
6595 dissect_ssl3_hnd_srv_keyex_sig(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6596 proto_tree *tree, guint32 offset,
6597 const SslSession *session)
6600 * TLSv1.2 (RFC 5246 sec 7.4.8)
6602 * digitally-signed struct {
6603 * opaque handshake_messages[handshake_messages_length];
6605 * } CertificateVerify;
6607 * TLSv1.0/TLSv1.1 (RFC 5436 sec 7.4.8 and 7.4.3) works essentially the same
6608 * as TLSv1.2, but the hash algorithms are not explicit in digitally-signed.
6610 * SSLv3 (RFC 6101 sec 5.6.8) esseentially works the same as TLSv1.0 but it
6611 * does more hashing including the master secret and padding.
6613 ssl_dissect_digitally_signed(hf, tvb, tree, offset, session,
6614 hf->hf.hs_server_keyex_sig_len,
6615 hf->hf.hs_server_keyex_sig);
6619 dissect_ssl3_hnd_srv_keyex_ecdh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6620 proto_tree *tree, guint32 offset,
6621 guint32 length, const SslSession *session,
6625 * RFC 4492 ECC cipher suites for TLS
6628 * ECCurveType curve_type;
6629 * select (curve_type) {
6630 * case explicit_prime:
6632 * case explicit_char2:
6635 * NamedCurve namedcurve;
6640 * opaque point <1..2^8-1>;
6644 * ECParameters curve_params;
6646 * } ServerECDHParams;
6648 * select (KeyExchangeAlgorithm) {
6649 * case ec_diffie_hellman:
6650 * ServerECDHParams params;
6651 * Signature signed_params;
6652 * } ServerKeyExchange;
6657 proto_tree *ssl_ecdh_tree;
6659 ssl_ecdh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6660 hf->ett.keyex_params, NULL, "EC Diffie-Hellman Server Params");
6662 /* ECParameters.curve_type */
6663 curve_type = tvb_get_guint8(tvb, offset);
6664 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_curve_type, tvb,
6665 offset, 1, ENC_BIG_ENDIAN);
6667 if (curve_type != 3)
6668 return; /* only named_curves are supported */
6670 /* case curve_type == named_curve; ECParameters.namedcurve */
6671 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_named_curve, tvb,
6672 offset, 2, ENC_BIG_ENDIAN);
6676 point_len = tvb_get_guint8(tvb, offset);
6677 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_point_len, tvb,
6678 offset, 1, ENC_BIG_ENDIAN);
6679 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_point, tvb,
6680 offset + 1, point_len, ENC_NA);
6681 offset += 1 + point_len;
6683 /* Signature (if non-anonymous KEX) */
6685 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_ecdh_tree, offset, session);
6690 dissect_ssl3_hnd_srv_keyex_dhe(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6691 proto_tree *tree, guint32 offset, guint32 length,
6692 const SslSession *session, gboolean anon)
6694 gint p_len, g_len, ys_len;
6695 proto_tree *ssl_dh_tree;
6697 ssl_dh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6698 hf->ett.keyex_params, NULL, "Diffie-Hellman Server Params");
6701 p_len = tvb_get_ntohs(tvb, offset);
6702 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_p_len, tvb,
6703 offset, 2, ENC_BIG_ENDIAN);
6704 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_p, tvb,
6705 offset + 2, p_len, ENC_NA);
6706 offset += 2 + p_len;
6709 g_len = tvb_get_ntohs(tvb, offset);
6710 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_g_len, tvb,
6711 offset, 2, ENC_BIG_ENDIAN);
6712 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_g, tvb,
6713 offset + 2, g_len, ENC_NA);
6714 offset += 2 + g_len;
6717 ys_len = tvb_get_ntohs(tvb, offset);
6718 proto_tree_add_uint(ssl_dh_tree, hf->hf.hs_server_keyex_ys_len, tvb,
6720 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_ys, tvb,
6721 offset + 2, ys_len, ENC_NA);
6722 offset += 2 + ys_len;
6724 /* Signature (if non-anonymous KEX) */
6726 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_dh_tree, offset, session);
6730 /* Only used in RSA-EXPORT cipher suites */
6732 dissect_ssl3_hnd_srv_keyex_rsa(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6733 proto_tree *tree, guint32 offset, guint32 length,
6734 const SslSession *session)
6736 gint modulus_len, exponent_len;
6737 proto_tree *ssl_rsa_tree;
6739 ssl_rsa_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6740 hf->ett.keyex_params, NULL, "RSA-EXPORT Server Params");
6743 modulus_len = tvb_get_ntohs(tvb, offset);
6744 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_modulus_len, tvb,
6745 offset, 2, ENC_BIG_ENDIAN);
6746 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_modulus, tvb,
6747 offset + 2, modulus_len, ENC_NA);
6748 offset += 2 + modulus_len;
6751 exponent_len = tvb_get_ntohs(tvb, offset);
6752 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_exponent_len,
6753 tvb, offset, 2, ENC_BIG_ENDIAN);
6754 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_exponent,
6755 tvb, offset + 2, exponent_len, ENC_NA);
6756 offset += 2 + exponent_len;
6759 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_rsa_tree, offset, session);
6762 /* Used in RSA PSK and PSK cipher suites */
6764 dissect_ssl3_hnd_srv_keyex_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6765 proto_tree *tree, guint32 offset, guint32 length)
6768 proto_tree *ssl_psk_tree;
6770 hint_len = tvb_get_ntohs(tvb, offset);
6771 if ((2 + hint_len) != length) {
6772 /* Lengths don't line up (wasn't what we expected?) */
6776 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6777 hf->ett.keyex_params, NULL, "PSK Server Params");
6780 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_server_keyex_hint_len, tvb,
6781 offset, 2, ENC_BIG_ENDIAN);
6782 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_server_keyex_hint, tvb,
6783 offset + 2, hint_len, ENC_NA);
6785 /* ServerKeyExchange algo-specific dissectors. }}} */
6787 /* Client Key Exchange and Server Key Exchange handshake dissections. {{{ */
6789 ssl_dissect_hnd_cli_keyex(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6790 proto_tree *tree, guint32 offset, guint32 length,
6791 const SslSession *session)
6793 switch (ssl_get_keyex_alg(session->cipher)) {
6794 case KEX_DH_ANON: /* RFC 5246; DHE_DSS, DHE_RSA, DH_DSS, DH_RSA, DH_ANON: ClientDiffieHellmanPublic */
6799 dissect_ssl3_hnd_cli_keyex_dh(hf, tvb, tree, offset, length);
6801 case KEX_DHE_PSK: /* RFC 4279; diffie_hellman_psk: psk_identity, ClientDiffieHellmanPublic */
6802 /* XXX: implement support for DHE_PSK */
6804 case KEX_ECDH_ANON: /* RFC 4492; ec_diffie_hellman: ClientECDiffieHellmanPublic */
6805 case KEX_ECDH_ECDSA:
6807 case KEX_ECDHE_ECDSA:
6809 dissect_ssl3_hnd_cli_keyex_ecdh(hf, tvb, tree, offset, length);
6811 case KEX_ECDHE_PSK: /* RFC 5489; ec_diffie_hellman_psk: psk_identity, ClientECDiffieHellmanPublic */
6812 /* XXX: implement support for ECDHE_PSK */
6814 case KEX_KRB5: /* RFC 2712; krb5: KerberosWrapper */
6815 /* XXX: implement support for KRB5 */
6817 case KEX_PSK: /* RFC 4279; psk: psk_identity */
6818 dissect_ssl3_hnd_cli_keyex_psk(hf, tvb, tree, offset, length);
6820 case KEX_RSA: /* RFC 5246; rsa: EncryptedPreMasterSecret */
6821 dissect_ssl3_hnd_cli_keyex_rsa(hf, tvb, tree, offset, length, session);
6823 case KEX_RSA_PSK: /* RFC 4279; rsa_psk: psk_identity, EncryptedPreMasterSecret */
6824 dissect_ssl3_hnd_cli_keyex_rsa_psk(hf, tvb, tree, offset, length);
6826 case KEX_SRP_SHA: /* RFC 5054; srp: ClientSRPPublic */
6827 case KEX_SRP_SHA_DSS:
6828 case KEX_SRP_SHA_RSA:
6829 /* XXX: implement support for SRP_SHA* */
6832 /* XXX: add info message for not supported KEX algo */
6838 ssl_dissect_hnd_srv_keyex(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6839 proto_tree *tree, guint32 offset, guint32 length,
6840 const SslSession *session)
6842 switch (ssl_get_keyex_alg(session->cipher)) {
6843 case KEX_DH_ANON: /* RFC 5246; ServerDHParams */
6844 dissect_ssl3_hnd_srv_keyex_dhe(hf, tvb, tree, offset, length, session, TRUE);
6846 case KEX_DH_DSS: /* RFC 5246; not allowed */
6848 /* XXX: add error on not allowed KEX */
6850 case KEX_DHE_DSS: /* RFC 5246; dhe_dss, dhe_rsa: ServerDHParams, Signature */
6852 dissect_ssl3_hnd_srv_keyex_dhe(hf, tvb, tree, offset, length, session, FALSE);
6854 case KEX_DHE_PSK: /* RFC 4279; diffie_hellman_psk: psk_identity_hint, ServerDHParams */
6855 /* XXX: implement support for DHE_PSK */
6857 case KEX_ECDH_ANON: /* RFC 4492; ec_diffie_hellman: ServerECDHParams (without signature for anon) */
6858 dissect_ssl3_hnd_srv_keyex_ecdh(hf, tvb, tree, offset, length, session, TRUE);
6860 case KEX_ECDHE_PSK: /* RFC 5489; psk_identity_hint, ServerECDHParams */
6861 /* XXX: implement support for ECDHE_PSK */
6863 case KEX_ECDH_ECDSA: /* RFC 4492; ec_diffie_hellman: ServerECDHParams, Signature */
6865 case KEX_ECDHE_ECDSA:
6867 dissect_ssl3_hnd_srv_keyex_ecdh(hf, tvb, tree, offset, length, session, FALSE);
6869 case KEX_KRB5: /* RFC 2712; not allowed */
6870 /* XXX: add error on not allowed KEX */
6872 case KEX_PSK: /* RFC 4279; psk, rsa: psk_identity*/
6874 dissect_ssl3_hnd_srv_keyex_psk(hf, tvb, tree, offset, length);
6876 case KEX_RSA: /* only allowed if the public key in the server certificate is longer than 512 bits*/
6877 dissect_ssl3_hnd_srv_keyex_rsa(hf, tvb, tree, offset, length, session);
6879 case KEX_SRP_SHA: /* RFC 5054; srp: ServerSRPParams, Signature */
6880 case KEX_SRP_SHA_DSS:
6881 case KEX_SRP_SHA_RSA:
6882 /* XXX: implement support for SRP_SHA* */
6885 /* XXX: add info message for not supported KEX algo */
6889 /* Client Key Exchange and Server Key Exchange handshake dissections. }}} */
6891 #ifdef HAVE_LIBGCRYPT
6893 ssl_common_register_options(module_t *module, ssl_common_options_t *options)
6895 prefs_register_string_preference(module, "psk", "Pre-Shared-Key",
6896 "Pre-Shared-Key as HEX string. Should be 0 to 16 bytes.",
6899 prefs_register_filename_preference(module, "keylog_file", "(Pre)-Master-Secret log filename",
6900 "The name of a file which contains a list of \n"
6901 "(pre-)master secrets in one of the following formats:\n"
6903 "RSA <EPMS> <PMS>\n"
6904 "RSA Session-ID:<SSLID> Master-Key:<MS>\n"
6905 "CLIENT_RANDOM <CRAND> <MS>\n"
6906 "PMS_CLIENT_RANDOM <CRAND> <PMS>\n"
6909 "<EPMS> = First 8 bytes of the Encrypted PMS\n"
6910 "<PMS> = The Pre-Master-Secret (PMS) used to derive the MS\n"
6911 "<SSLID> = The SSL Session ID\n"
6912 "<MS> = The Master-Secret (MS)\n"
6913 "<CRAND> = The Client's random number from the ClientHello message\n"
6915 "(All fields are in hex notation)",
6916 &(options->keylog_filename));
6920 ssl_common_register_options(module_t *module _U_, ssl_common_options_t *options _U_)
6926 ssl_calculate_handshake_hash(SslDecryptSession *ssl_session, tvbuff_t *tvb, guint32 offset, guint32 length)
6928 if (ssl_session && !(ssl_session->state & SSL_MASTER_SECRET)) {
6929 guint32 old_length = ssl_session->handshake_data.data_len;
6930 ssl_debug_printf("Calculating hash with offset %d %d\n", offset, length);
6931 ssl_session->handshake_data.data = (guchar *)wmem_realloc(wmem_file_scope(), ssl_session->handshake_data.data, old_length + length);
6932 tvb_memcpy(tvb, ssl_session->handshake_data.data + old_length, offset, length);
6933 ssl_session->handshake_data.data_len += length;
6939 * Editor modelines - http://www.wireshark.org/tools/modelines.html
6944 * indent-tabs-mode: nil
6947 * vi: set shiftwidth=4 tabstop=8 expandtab:
6948 * :indentSize=4:tabSize=8:noTabs=true: