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.
36 #include <epan/packet.h>
37 #include <epan/strutil.h>
38 #include <epan/addr_resolv.h>
39 #include <epan/ipv6-utils.h>
40 #include <epan/expert.h>
41 #include <epan/asn1.h>
42 #include <wsutil/filesystem.h>
43 #include <wsutil/file_util.h>
44 #include <wsutil/str_util.h>
45 #include <wsutil/report_err.h>
46 #include <wsutil/pint.h>
47 #include "packet-x509af.h"
48 #include "packet-x509if.h"
49 #include "packet-ssl-utils.h"
50 #include "packet-ssl.h"
55 const value_string ssl_version_short_names[] = {
56 { SSL_VER_UNKNOWN, "SSL" },
57 { SSL_VER_SSLv2, "SSLv2" },
58 { SSL_VER_SSLv3, "SSLv3" },
59 { SSL_VER_TLS, "TLSv1" },
60 { SSL_VER_TLSv1DOT1, "TLSv1.1" },
61 { SSL_VER_DTLS, "DTLSv1.0" },
62 { SSL_VER_DTLS1DOT2, "DTLSv1.2" },
63 { SSL_VER_DTLS_OPENSSL, "DTLS 1.0 (OpenSSL pre 0.9.8f)" },
64 { SSL_VER_PCT, "PCT" },
65 { SSL_VER_TLSv1DOT2, "TLSv1.2" },
69 const value_string ssl_20_msg_types[] = {
70 { SSL2_HND_ERROR, "Error" },
71 { SSL2_HND_CLIENT_HELLO, "Client Hello" },
72 { SSL2_HND_CLIENT_MASTER_KEY, "Client Master Key" },
73 { SSL2_HND_CLIENT_FINISHED, "Client Finished" },
74 { SSL2_HND_SERVER_HELLO, "Server Hello" },
75 { SSL2_HND_SERVER_VERIFY, "Server Verify" },
76 { SSL2_HND_SERVER_FINISHED, "Server Finished" },
77 { SSL2_HND_REQUEST_CERTIFICATE, "Request Certificate" },
78 { SSL2_HND_CLIENT_CERTIFICATE, "Client Certificate" },
81 /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
82 /* Note: sorted by ascending value so value_string-ext can do a binary search */
83 static const value_string ssl_20_cipher_suites[] = {
84 { 0x000000, "TLS_NULL_WITH_NULL_NULL" },
85 { 0x000001, "TLS_RSA_WITH_NULL_MD5" },
86 { 0x000002, "TLS_RSA_WITH_NULL_SHA" },
87 { 0x000003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" },
88 { 0x000004, "TLS_RSA_WITH_RC4_128_MD5" },
89 { 0x000005, "TLS_RSA_WITH_RC4_128_SHA" },
90 { 0x000006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" },
91 { 0x000007, "TLS_RSA_WITH_IDEA_CBC_SHA" },
92 { 0x000008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" },
93 { 0x000009, "TLS_RSA_WITH_DES_CBC_SHA" },
94 { 0x00000a, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" },
95 { 0x00000b, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" },
96 { 0x00000c, "TLS_DH_DSS_WITH_DES_CBC_SHA" },
97 { 0x00000d, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" },
98 { 0x00000e, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" },
99 { 0x00000f, "TLS_DH_RSA_WITH_DES_CBC_SHA" },
100 { 0x000010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" },
101 { 0x000011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" },
102 { 0x000012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" },
103 { 0x000013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" },
104 { 0x000014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" },
105 { 0x000015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" },
106 { 0x000016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" },
107 { 0x000017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" },
108 { 0x000018, "TLS_DH_anon_WITH_RC4_128_MD5" },
109 { 0x000019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" },
110 { 0x00001a, "TLS_DH_anon_WITH_DES_CBC_SHA" },
111 { 0x00001b, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" },
112 { 0x00001c, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" },
113 { 0x00001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
115 { 0x00001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
118 { 0x00001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
119 { 0x00001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" },
120 { 0x000020, "TLS_KRB5_WITH_RC4_128_SHA" },
121 { 0x000021, "TLS_KRB5_WITH_IDEA_CBC_SHA" },
122 { 0x000022, "TLS_KRB5_WITH_DES_CBC_MD5" },
123 { 0x000023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" },
124 { 0x000024, "TLS_KRB5_WITH_RC4_128_MD5" },
125 { 0x000025, "TLS_KRB5_WITH_IDEA_CBC_MD5" },
126 { 0x000026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" },
127 { 0x000027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" },
128 { 0x000028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" },
129 { 0x000029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" },
130 { 0x00002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" },
131 { 0x00002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" },
133 { 0x00002C, "TLS_PSK_WITH_NULL_SHA" },
134 { 0x00002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
135 { 0x00002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
137 { 0x00002f, "TLS_RSA_WITH_AES_128_CBC_SHA" },
138 { 0x000030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
139 { 0x000031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" },
140 { 0x000032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" },
141 { 0x000033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" },
142 { 0x000034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" },
143 { 0x000035, "TLS_RSA_WITH_AES_256_CBC_SHA" },
144 { 0x000036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" },
145 { 0x000037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" },
146 { 0x000038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
147 { 0x000039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
148 { 0x00003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
149 { 0x00003B, "TLS_RSA_WITH_NULL_SHA256" },
150 { 0x00003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" },
151 { 0x00003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" },
152 { 0x00003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" },
153 { 0x00003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" },
154 { 0x000040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" },
155 { 0x000041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" },
156 { 0x000042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" },
157 { 0x000043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" },
158 { 0x000044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" },
159 { 0x000045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" },
160 { 0x000046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" },
161 { 0x000047, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
162 { 0x000048, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
163 { 0x000049, "TLS_ECDH_ECDSA_WITH_DES_CBC_SHA" },
164 { 0x00004A, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
165 { 0x00004B, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
166 { 0x00004C, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
167 { 0x000060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
168 { 0x000061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
169 { 0x000062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" },
170 { 0x000063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" },
171 { 0x000064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" },
172 { 0x000065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" },
173 { 0x000066, "TLS_DHE_DSS_WITH_RC4_128_SHA" },
174 { 0x000067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" },
175 { 0x000068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" },
176 { 0x000069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" },
177 { 0x00006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" },
178 { 0x00006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" },
179 { 0x00006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" },
180 { 0x00006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" },
181 /* 0x00,0x6E-83 Unassigned */
182 { 0x000084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" },
183 { 0x000085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" },
184 { 0x000086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" },
185 { 0x000087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
186 { 0x000088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
187 { 0x000089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
189 { 0x00008A, "TLS_PSK_WITH_RC4_128_SHA" },
190 { 0x00008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
191 { 0x00008C, "TLS_PSK_WITH_AES_128_CBC_SHA" },
192 { 0x00008D, "TLS_PSK_WITH_AES_256_CBC_SHA" },
193 { 0x00008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" },
194 { 0x00008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" },
195 { 0x000090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" },
196 { 0x000091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" },
197 { 0x000092, "TLS_RSA_PSK_WITH_RC4_128_SHA" },
198 { 0x000093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" },
199 { 0x000094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" },
200 { 0x000095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" },
202 { 0x000096, "TLS_RSA_WITH_SEED_CBC_SHA" },
203 { 0x000097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" },
204 { 0x000098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" },
205 { 0x000099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
206 { 0x00009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
207 { 0x00009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
209 { 0x00009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" },
210 { 0x00009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" },
211 { 0x00009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" },
212 { 0x00009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" },
213 { 0x0000A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" },
214 { 0x0000A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" },
215 { 0x0000A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" },
216 { 0x0000A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" },
217 { 0x0000A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" },
218 { 0x0000A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" },
219 { 0x0000A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" },
220 { 0x0000A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" },
222 { 0x0000A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" },
223 { 0x0000A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" },
224 { 0x0000AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" },
225 { 0x0000AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" },
226 { 0x0000AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" },
227 { 0x0000AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" },
228 { 0x0000AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" },
229 { 0x0000AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" },
230 { 0x0000B0, "TLS_PSK_WITH_NULL_SHA256" },
231 { 0x0000B1, "TLS_PSK_WITH_NULL_SHA384" },
232 { 0x0000B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" },
233 { 0x0000B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" },
234 { 0x0000B4, "TLS_DHE_PSK_WITH_NULL_SHA256" },
235 { 0x0000B5, "TLS_DHE_PSK_WITH_NULL_SHA384" },
236 { 0x0000B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" },
237 { 0x0000B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" },
238 { 0x0000B8, "TLS_RSA_PSK_WITH_NULL_SHA256" },
239 { 0x0000B9, "TLS_RSA_PSK_WITH_NULL_SHA384" },
241 { 0x0000BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
242 { 0x0000BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
243 { 0x0000BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
244 { 0x0000BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
245 { 0x0000BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
246 { 0x0000BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" },
247 { 0x0000C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
248 { 0x0000C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
249 { 0x0000C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
250 { 0x0000C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
251 { 0x0000C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
252 { 0x0000C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" },
253 /* 0x00,0xC6-FE Unassigned */
254 { 0x0000FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" },
255 /* 0x01-BF,* Unassigned */
257 { 0x00c001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
258 { 0x00c002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
259 { 0x00c003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
260 { 0x00c004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
261 { 0x00c005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
262 { 0x00c006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" },
263 { 0x00c007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" },
264 { 0x00c008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" },
265 { 0x00c009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
266 { 0x00c00a, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
267 { 0x00c00b, "TLS_ECDH_RSA_WITH_NULL_SHA" },
268 { 0x00c00c, "TLS_ECDH_RSA_WITH_RC4_128_SHA" },
269 { 0x00c00d, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" },
270 { 0x00c00e, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" },
271 { 0x00c00f, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" },
272 { 0x00c010, "TLS_ECDHE_RSA_WITH_NULL_SHA" },
273 { 0x00c011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" },
274 { 0x00c012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" },
275 { 0x00c013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
276 { 0x00c014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
277 { 0x00c015, "TLS_ECDH_anon_WITH_NULL_SHA" },
278 { 0x00c016, "TLS_ECDH_anon_WITH_RC4_128_SHA" },
279 { 0x00c017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" },
280 { 0x00c018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" },
281 { 0x00c019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" },
283 { 0x00C01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" },
284 { 0x00C01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" },
285 { 0x00C01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" },
286 { 0x00C01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" },
287 { 0x00C01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" },
288 { 0x00C01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" },
289 { 0x00C020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
290 { 0x00C021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
291 { 0x00C022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
293 { 0x00C023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" },
294 { 0x00C024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" },
295 { 0x00C025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" },
296 { 0x00C026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" },
297 { 0x00C027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" },
298 { 0x00C028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" },
299 { 0x00C029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" },
300 { 0x00C02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" },
301 { 0x00C02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
302 { 0x00C02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
303 { 0x00C02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" },
304 { 0x00C02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" },
305 { 0x00C02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
306 { 0x00C030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
307 { 0x00C031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" },
308 { 0x00C032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" },
310 { 0x00C033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" },
311 { 0x00C034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" },
312 { 0x00C035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" },
313 { 0x00C036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" },
314 { 0x00C037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" },
315 { 0x00C038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" },
316 { 0x00C039, "TLS_ECDHE_PSK_WITH_NULL_SHA" },
317 { 0x00C03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" },
318 { 0x00C03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" },
319 /* 0xC0,0x3C-FF Unassigned
321 0xFE,0x00-FD Unassigned
322 0xFE,0xFE-FF Reserved to avoid conflicts with widely deployed implementations [Pasi_Eronen]
323 0xFF,0x00-FF Reserved for Private Use [RFC5246]
326 /* http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 */
327 { 0x00CC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
328 { 0x00CC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
329 { 0x00CC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
331 /* http://tools.ietf.org/html/draft-josefsson-salsa20-tls */
332 { 0x00E410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" },
333 { 0x00E411, "TLS_RSA_WITH_SALSA20_SHA1" },
334 { 0x00E412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
335 { 0x00E413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" },
336 { 0x00E414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" },
337 { 0x00E415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" },
338 { 0x00E416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" },
339 { 0x00E417, "TLS_PSK_WITH_SALSA20_SHA1" },
340 { 0x00E418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
341 { 0x00E419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" },
342 { 0x00E41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" },
343 { 0x00E41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" },
344 { 0x00E41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
345 { 0x00E41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" },
346 { 0x00E41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
347 { 0x00E41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" },
349 /* these from http://www.mozilla.org/projects/
350 security/pki/nss/ssl/fips-ssl-ciphersuites.html */
351 { 0x00fefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
352 { 0x00feff, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
353 { 0x00ffe0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
354 { 0x00ffe1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
355 /* note that ciphersuites of {0x00????} are TLS cipher suites in
356 * a sslv2 client hello message; the ???? above is the two-byte
357 * tls cipher suite id
360 { 0x010080, "SSL2_RC4_128_WITH_MD5" },
361 { 0x020080, "SSL2_RC4_128_EXPORT40_WITH_MD5" },
362 { 0x030080, "SSL2_RC2_CBC_128_CBC_WITH_MD5" },
363 { 0x040080, "SSL2_RC2_CBC_128_CBC_WITH_MD5" },
364 { 0x050080, "SSL2_IDEA_128_CBC_WITH_MD5" },
365 { 0x060040, "SSL2_DES_64_CBC_WITH_MD5" },
366 { 0x0700c0, "SSL2_DES_192_EDE3_CBC_WITH_MD5" },
367 { 0x080080, "SSL2_RC4_64_WITH_MD5" },
369 /* Microsoft's old PCT protocol. These are from Eric Rescorla's
370 book "SSL and TLS" */
371 { 0x800001, "PCT_SSL_CERT_TYPE | PCT1_CERT_X509" },
372 { 0x800003, "PCT_SSL_CERT_TYPE | PCT1_CERT_X509_CHAIN" },
373 { 0x810001, "PCT_SSL_HASH_TYPE | PCT1_HASH_MD5" },
374 { 0x810003, "PCT_SSL_HASH_TYPE | PCT1_HASH_SHA" },
375 { 0x820001, "PCT_SSL_EXCH_TYPE | PCT1_EXCH_RSA_PKCS1" },
376 { 0x830004, "PCT_SSL_CIPHER_TYPE_1ST_HALF | PCT1_CIPHER_RC4" },
377 { 0x842840, "PCT_SSL_CIPHER_TYPE_2ND_HALF | PCT1_ENC_BITS_40 | PCT1_MAC_BITS_128" },
378 { 0x848040, "PCT_SSL_CIPHER_TYPE_2ND_HALF | PCT1_ENC_BITS_128 | PCT1_MAC_BITS_128" },
379 { 0x8f8001, "PCT_SSL_COMPAT | PCT_VERSION_1" },
383 value_string_ext ssl_20_cipher_suites_ext = VALUE_STRING_EXT_INIT(ssl_20_cipher_suites);
386 const value_string ssl_extension_curves[] = {
412 { 26, "brainpoolP256r1" }, /* RFC 7027 */
413 { 27, "brainpoolP384r1" }, /* RFC 7027 */
414 { 28, "brainpoolP512r1" }, /* RFC 7027 */
415 { 0xFF01, "arbitrary_explicit_prime_curves" },
416 { 0xFF02, "arbitrary_explicit_char2_curves" },
420 const value_string ssl_curve_types[] = {
421 { 1, "explicit_prime" },
422 { 2, "explicit_char2" },
423 { 3, "named_curve" },
427 const value_string ssl_extension_ec_point_formats[] = {
428 { 0, "uncompressed" },
429 { 1, "ansiX962_compressed_prime" },
430 { 2, "ansiX962_compressed_char2" },
434 const value_string ssl_20_certificate_type[] = {
436 { 0x01, "X.509 Certificate" },
440 const value_string ssl_31_content_type[] = {
441 { 20, "Change Cipher Spec" },
444 { 23, "Application Data" },
449 const value_string ssl_versions[] = {
450 { 0xfefd, "DTLS 1.2" },
451 { 0xfeff, "DTLS 1.0" },
452 { 0x0100, "DTLS 1.0 (OpenSSL pre 0.9.8f)" },
453 { 0x0303, "TLS 1.2" },
454 { 0x0302, "TLS 1.1" },
455 { 0x0301, "TLS 1.0" },
456 { 0x0300, "SSL 3.0" },
457 { 0x0002, "SSL 2.0" },
462 /* XXX - would be used if we dissected the body of a Change Cipher Spec
464 const value_string ssl_31_change_cipher_spec[] = {
465 { 1, "Change Cipher Spec" },
470 const value_string ssl_31_alert_level[] = {
476 const value_string ssl_31_alert_description[] = {
477 { 0, "Close Notify" },
478 { 10, "Unexpected Message" },
479 { 20, "Bad Record MAC" },
480 { 21, "Decryption Failed" },
481 { 22, "Record Overflow" },
482 { 30, "Decompression Failure" },
483 { 40, "Handshake Failure" },
484 { 41, "No Certificate" },
485 { 42, "Bad Certificate" },
486 { 43, "Unsupported Certificate" },
487 { 44, "Certificate Revoked" },
488 { 45, "Certificate Expired" },
489 { 46, "Certificate Unknown" },
490 { 47, "Illegal Parameter" },
491 { 48, "Unknown CA" },
492 { 49, "Access Denied" },
493 { 50, "Decode Error" },
494 { 51, "Decrypt Error" },
495 { 60, "Export Restriction" },
496 { 70, "Protocol Version" },
497 { 71, "Insufficient Security" },
498 { 80, "Internal Error" },
499 { 86, "Inappropriate Fallback" },
500 { 90, "User Canceled" },
501 { 100, "No Renegotiation" },
502 { 110, "Unsupported Extension" },
503 { 111, "Certificate Unobtainable" },
504 { 112, "Unrecognized Name" },
505 { 113, "Bad Certificate Status Response" },
506 { 114, "Bad Certificate Hash Value" },
507 { 115, "Unknown PSK Identity" },
508 { 120, "No application Protocol" },
512 const value_string ssl_31_handshake_type[] = {
513 { SSL_HND_HELLO_REQUEST, "Hello Request" },
514 { SSL_HND_CLIENT_HELLO, "Client Hello" },
515 { SSL_HND_SERVER_HELLO, "Server Hello" },
516 { SSL_HND_HELLO_VERIFY_REQUEST, "Hello Verify Request"},
517 { SSL_HND_NEWSESSION_TICKET, "New Session Ticket" },
518 { SSL_HND_CERTIFICATE, "Certificate" },
519 { SSL_HND_SERVER_KEY_EXCHG, "Server Key Exchange" },
520 { SSL_HND_CERT_REQUEST, "Certificate Request" },
521 { SSL_HND_SVR_HELLO_DONE, "Server Hello Done" },
522 { SSL_HND_CERT_VERIFY, "Certificate Verify" },
523 { SSL_HND_CLIENT_KEY_EXCHG, "Client Key Exchange" },
524 { SSL_HND_FINISHED, "Finished" },
525 { SSL_HND_CERT_URL, "Client Certificate URL" },
526 { SSL_HND_CERT_STATUS, "Certificate Status" },
527 { SSL_HND_SUPPLEMENTAL_DATA, "Supplemental Data" },
528 { SSL_HND_ENCRYPTED_EXTS, "Encrypted Extensions" },
532 const value_string tls_heartbeat_type[] = {
538 const value_string tls_heartbeat_mode[] = {
539 { 1, "Peer allowed to send requests" },
540 { 2, "Peer not allowed to send requests" },
544 const value_string ssl_31_compression_method[] = {
552 /* XXX - would be used if we dissected a Signature, as would be
553 seen in a server key exchange or certificate verify message. */
554 const value_string ssl_31_key_exchange_algorithm[] = {
556 { 1, "Diffie Hellman" },
560 const value_string ssl_31_signature_algorithm[] = {
568 const value_string ssl_31_client_certificate_type[] = {
571 { 3, "RSA Fixed DH" },
572 { 4, "DSS Fixed DH" },
573 /* GOST certificate types */
574 /* Section 3.5 of draft-chudov-cryptopro-cptls-04 */
575 { 21, "GOST R 34.10-94" },
576 { 22, "GOST R 34.10-2001" },
577 /* END GOST certificate types */
578 { 64, "ECDSA Sign" },
579 { 65, "RSA Fixed ECDH" },
580 { 66, "ECDSA Fixed ECDH" },
585 /* XXX - would be used if we dissected exchange keys, as would be
586 seen in a client key exchange message. */
587 const value_string ssl_31_public_value_encoding[] = {
594 /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
595 /* Note: sorted by ascending value so value_string_ext fcns can do a binary search */
596 static const value_string ssl_31_ciphersuite[] = {
597 /* RFC 2246, RFC 4346, RFC 5246 */
598 { 0x0000, "TLS_NULL_WITH_NULL_NULL" },
599 { 0x0001, "TLS_RSA_WITH_NULL_MD5" },
600 { 0x0002, "TLS_RSA_WITH_NULL_SHA" },
601 { 0x0003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" },
602 { 0x0004, "TLS_RSA_WITH_RC4_128_MD5" },
603 { 0x0005, "TLS_RSA_WITH_RC4_128_SHA" },
604 { 0x0006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" },
605 { 0x0007, "TLS_RSA_WITH_IDEA_CBC_SHA" },
606 { 0x0008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" },
607 { 0x0009, "TLS_RSA_WITH_DES_CBC_SHA" },
608 { 0x000a, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" },
609 { 0x000b, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" },
610 { 0x000c, "TLS_DH_DSS_WITH_DES_CBC_SHA" },
611 { 0x000d, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" },
612 { 0x000e, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" },
613 { 0x000f, "TLS_DH_RSA_WITH_DES_CBC_SHA" },
614 { 0x0010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" },
615 { 0x0011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" },
616 { 0x0012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" },
617 { 0x0013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" },
618 { 0x0014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" },
619 { 0x0015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" },
620 { 0x0016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" },
621 { 0x0017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" },
622 { 0x0018, "TLS_DH_anon_WITH_RC4_128_MD5" },
623 { 0x0019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" },
624 { 0x001a, "TLS_DH_anon_WITH_DES_CBC_SHA" },
625 { 0x001b, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" },
627 { 0x001c, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" },
628 { 0x001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
629 #if 0 /* Because it clashes with KRB5, is never used any more, and is safe
630 to remove according to David Hopwood <david.hopwood@zetnet.co.uk>
631 of the ietf-tls list */
632 { 0x001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
636 { 0x001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
637 { 0x001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" },
638 { 0x0020, "TLS_KRB5_WITH_RC4_128_SHA" },
639 { 0x0021, "TLS_KRB5_WITH_IDEA_CBC_SHA" },
640 { 0x0022, "TLS_KRB5_WITH_DES_CBC_MD5" },
641 { 0x0023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" },
642 { 0x0024, "TLS_KRB5_WITH_RC4_128_MD5" },
643 { 0x0025, "TLS_KRB5_WITH_IDEA_CBC_MD5" },
644 { 0x0026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" },
645 { 0x0027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" },
646 { 0x0028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" },
647 { 0x0029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" },
648 { 0x002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" },
649 { 0x002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" },
652 { 0x002C, "TLS_PSK_WITH_NULL_SHA" },
653 { 0x002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
654 { 0x002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
657 { 0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA" },
658 { 0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
659 { 0x0031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" },
660 { 0x0032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" },
661 { 0x0033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" },
662 { 0x0034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" },
663 { 0x0035, "TLS_RSA_WITH_AES_256_CBC_SHA" },
664 { 0x0036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" },
665 { 0x0037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" },
666 { 0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
667 { 0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
668 { 0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
669 { 0x003B, "TLS_RSA_WITH_NULL_SHA256" },
670 { 0x003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" },
671 { 0x003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" },
672 { 0x003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" },
673 { 0x003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" },
674 { 0x0040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" },
677 { 0x0041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" },
678 { 0x0042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" },
679 { 0x0043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" },
680 { 0x0044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" },
681 { 0x0045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" },
682 { 0x0046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" },
684 /* 0x00,0x60-66 Reserved to avoid conflicts with widely deployed implementations */
686 { 0x0060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
687 { 0x0061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
688 /* draft-ietf-tls-56-bit-ciphersuites-01.txt */
689 { 0x0062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" },
690 { 0x0063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" },
691 { 0x0064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" },
692 { 0x0065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" },
693 { 0x0066, "TLS_DHE_DSS_WITH_RC4_128_SHA" },
696 { 0x0067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" },
697 { 0x0068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" },
698 { 0x0069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" },
699 { 0x006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" },
700 { 0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" },
701 { 0x006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" },
702 { 0x006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" },
704 /* draft-chudov-cryptopro-cptls-04.txt */
705 { 0x0080, "TLS_GOSTR341094_WITH_28147_CNT_IMIT" },
706 { 0x0081, "TLS_GOSTR341001_WITH_28147_CNT_IMIT" },
707 { 0x0082, "TLS_GOSTR341094_WITH_NULL_GOSTR3411" },
708 { 0x0083, "TLS_GOSTR341001_WITH_NULL_GOSTR3411" },
711 { 0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" },
712 { 0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" },
713 { 0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" },
714 { 0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
715 { 0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
716 { 0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
719 { 0x008A, "TLS_PSK_WITH_RC4_128_SHA" },
720 { 0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
721 { 0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA" },
722 { 0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA" },
723 { 0x008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" },
724 { 0x008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" },
725 { 0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" },
726 { 0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" },
727 { 0x0092, "TLS_RSA_PSK_WITH_RC4_128_SHA" },
728 { 0x0093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" },
729 { 0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" },
730 { 0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" },
733 { 0x0096, "TLS_RSA_WITH_SEED_CBC_SHA" },
734 { 0x0097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" },
735 { 0x0098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" },
736 { 0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
737 { 0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
738 { 0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
741 { 0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" },
742 { 0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" },
743 { 0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" },
744 { 0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" },
745 { 0x00A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" },
746 { 0x00A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" },
747 { 0x00A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" },
748 { 0x00A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" },
749 { 0x00A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" },
750 { 0x00A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" },
751 { 0x00A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" },
752 { 0x00A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" },
755 { 0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" },
756 { 0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" },
757 { 0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" },
758 { 0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" },
759 { 0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" },
760 { 0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" },
761 { 0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" },
762 { 0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" },
763 { 0x00B0, "TLS_PSK_WITH_NULL_SHA256" },
764 { 0x00B1, "TLS_PSK_WITH_NULL_SHA384" },
765 { 0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" },
766 { 0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" },
767 { 0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256" },
768 { 0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384" },
769 { 0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" },
770 { 0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" },
771 { 0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256" },
772 { 0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384" },
775 { 0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
776 { 0x00BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
777 { 0x00BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
778 { 0x00BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
779 { 0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
780 { 0x00BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" },
781 { 0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
782 { 0x00C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
783 { 0x00C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
784 { 0x00C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
785 { 0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
786 { 0x00C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" },
787 /* 0x00,0xC6-FE Unassigned */
789 { 0x00FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" },
791 { 0x5600, "TLS_FALLBACK_SCSV" },
793 { 0xc001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
794 { 0xc002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
795 { 0xc003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
796 { 0xc004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
797 { 0xc005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
798 { 0xc006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" },
799 { 0xc007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" },
800 { 0xc008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" },
801 { 0xc009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
802 { 0xc00a, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
803 { 0xc00b, "TLS_ECDH_RSA_WITH_NULL_SHA" },
804 { 0xc00c, "TLS_ECDH_RSA_WITH_RC4_128_SHA" },
805 { 0xc00d, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" },
806 { 0xc00e, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" },
807 { 0xc00f, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" },
808 { 0xc010, "TLS_ECDHE_RSA_WITH_NULL_SHA" },
809 { 0xc011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" },
810 { 0xc012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" },
811 { 0xc013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
812 { 0xc014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
813 { 0xc015, "TLS_ECDH_anon_WITH_NULL_SHA" },
814 { 0xc016, "TLS_ECDH_anon_WITH_RC4_128_SHA" },
815 { 0xc017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" },
816 { 0xc018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" },
817 { 0xc019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" },
820 { 0xC01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" },
821 { 0xC01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" },
822 { 0xC01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" },
823 { 0xC01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" },
824 { 0xC01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" },
825 { 0xC01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" },
826 { 0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
827 { 0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
828 { 0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
831 { 0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" },
832 { 0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" },
833 { 0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" },
834 { 0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" },
835 { 0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" },
836 { 0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" },
837 { 0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" },
838 { 0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" },
839 { 0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
840 { 0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
841 { 0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" },
842 { 0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" },
843 { 0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
844 { 0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
845 { 0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" },
846 { 0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" },
849 { 0xC033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" },
850 { 0xC034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" },
851 { 0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" },
852 { 0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" },
853 { 0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" },
854 { 0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" },
855 { 0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA" },
856 { 0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" },
857 { 0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" },
860 { 0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256" },
861 { 0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384" },
862 { 0xC03E, "TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256" },
863 { 0xC03F, "TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384" },
864 { 0xC040, "TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256" },
865 { 0xC041, "TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384" },
866 { 0xC042, "TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256" },
867 { 0xC043, "TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384" },
868 { 0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256" },
869 { 0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384" },
870 { 0xC046, "TLS_DH_anon_WITH_ARIA_128_CBC_SHA256" },
871 { 0xC047, "TLS_DH_anon_WITH_ARIA_256_CBC_SHA384" },
872 { 0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256" },
873 { 0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384" },
874 { 0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256" },
875 { 0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384" },
876 { 0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256" },
877 { 0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384" },
878 { 0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256" },
879 { 0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384" },
880 { 0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256" },
881 { 0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384" },
882 { 0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256" },
883 { 0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384" },
884 { 0xC054, "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256" },
885 { 0xC055, "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384" },
886 { 0xC056, "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256" },
887 { 0xC057, "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384" },
888 { 0xC058, "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256" },
889 { 0xC059, "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384" },
890 { 0xC05A, "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256" },
891 { 0xC05B, "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384" },
892 { 0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256" },
893 { 0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384" },
894 { 0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256" },
895 { 0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384" },
896 { 0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256" },
897 { 0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384" },
898 { 0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256" },
899 { 0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384" },
900 { 0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256" },
901 { 0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384" },
902 { 0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256" },
903 { 0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384" },
904 { 0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256" },
905 { 0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384" },
906 { 0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256" },
907 { 0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384" },
908 { 0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256" },
909 { 0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384" },
910 { 0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256" },
911 { 0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384" },
912 { 0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256" },
913 { 0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384" },
916 { 0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" },
917 { 0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" },
918 { 0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" },
919 { 0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" },
920 { 0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
921 { 0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384" },
922 { 0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
923 { 0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384" },
924 { 0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
925 { 0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
926 { 0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
927 { 0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
928 { 0xC07E, "TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
929 { 0xC07F, "TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
930 { 0xC080, "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256" },
931 { 0xC081, "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384" },
932 { 0xC082, "TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256" },
933 { 0xC083, "TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384" },
934 { 0xC084, "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256" },
935 { 0xC085, "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384" },
936 { 0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" },
937 { 0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" },
938 { 0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" },
939 { 0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" },
940 { 0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
941 { 0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
942 { 0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
943 { 0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
944 { 0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
945 { 0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
946 { 0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
947 { 0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
948 { 0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
949 { 0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
950 { 0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
951 { 0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
952 { 0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
953 { 0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
954 { 0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
955 { 0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
956 { 0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
957 { 0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
960 { 0xC09C, "TLS_RSA_WITH_AES_128_CCM" },
961 { 0xC09D, "TLS_RSA_WITH_AES_256_CCM" },
962 { 0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM" },
963 { 0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM" },
964 { 0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8" },
965 { 0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8" },
966 { 0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8" },
967 { 0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8" },
968 { 0xC0A4, "TLS_PSK_WITH_AES_128_CCM" },
969 { 0xC0A5, "TLS_PSK_WITH_AES_256_CCM" },
970 { 0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM" },
971 { 0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM" },
972 { 0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8" },
973 { 0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8" },
974 { 0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8" },
975 { 0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8" },
978 { 0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM" },
979 { 0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM" },
980 { 0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" },
981 { 0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8" },
983 0xC0,0xAB-FF Unassigned
985 0xFE,0x00-FD Unassigned
986 0xFE,0xFE-FF Reserved to avoid conflicts with widely deployed implementations [Pasi_Eronen]
987 0xFF,0x00-FF Reserved for Private Use [RFC5246]
990 /* http://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 */
991 { 0xCC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
992 { 0xCC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
993 { 0xCC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
995 /* http://tools.ietf.org/html/draft-josefsson-salsa20-tls */
996 { 0xE410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" },
997 { 0xE411, "TLS_RSA_WITH_SALSA20_SHA1" },
998 { 0xE412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
999 { 0xE413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" },
1000 { 0xE414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" },
1001 { 0xE415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" },
1002 { 0xE416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1003 { 0xE417, "TLS_PSK_WITH_SALSA20_SHA1" },
1004 { 0xE418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1005 { 0xE419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" },
1006 { 0xE41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1007 { 0xE41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" },
1008 { 0xE41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1009 { 0xE41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" },
1010 { 0xE41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1011 { 0xE41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" },
1013 /* these from http://www.mozilla.org/projects/
1014 security/pki/nss/ssl/fips-ssl-ciphersuites.html */
1015 { 0xfefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
1016 { 0xfeff, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
1017 { 0xffe0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
1018 { 0xffe1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
1019 /* note that ciphersuites 0xff00 - 0xffff are private */
1023 value_string_ext ssl_31_ciphersuite_ext = VALUE_STRING_EXT_INIT(ssl_31_ciphersuite);
1026 const value_string pct_msg_types[] = {
1027 { PCT_MSG_CLIENT_HELLO, "Client Hello" },
1028 { PCT_MSG_SERVER_HELLO, "Server Hello" },
1029 { PCT_MSG_CLIENT_MASTER_KEY, "Client Master Key" },
1030 { PCT_MSG_SERVER_VERIFY, "Server Verify" },
1031 { PCT_MSG_ERROR, "Error" },
1035 const value_string pct_cipher_type[] = {
1036 { PCT_CIPHER_DES, "DES" },
1037 { PCT_CIPHER_IDEA, "IDEA" },
1038 { PCT_CIPHER_RC2, "RC2" },
1039 { PCT_CIPHER_RC4, "RC4" },
1040 { PCT_CIPHER_DES_112, "DES 112 bit" },
1041 { PCT_CIPHER_DES_168, "DES 168 bit" },
1045 const value_string pct_hash_type[] = {
1046 { PCT_HASH_MD5, "MD5" },
1047 { PCT_HASH_MD5_TRUNC_64, "MD5_TRUNC_64"},
1048 { PCT_HASH_SHA, "SHA"},
1049 { PCT_HASH_SHA_TRUNC_80, "SHA_TRUNC_80"},
1050 { PCT_HASH_DES_DM, "DES_DM"},
1054 const value_string pct_cert_type[] = {
1055 { PCT_CERT_NONE, "None" },
1056 { PCT_CERT_X509, "X.509" },
1057 { PCT_CERT_PKCS7, "PKCS #7" },
1060 const value_string pct_sig_type[] = {
1061 { PCT_SIG_NONE, "None" },
1062 { PCT_SIG_RSA_MD5, "MD5" },
1063 { PCT_SIG_RSA_SHA, "RSA SHA" },
1064 { PCT_SIG_DSA_SHA, "DSA SHA" },
1068 const value_string pct_exch_type[] = {
1069 { PCT_EXCH_RSA_PKCS1, "RSA PKCS#1" },
1070 { PCT_EXCH_RSA_PKCS1_TOKEN_DES, "RSA PKCS#1 Token DES" },
1071 { PCT_EXCH_RSA_PKCS1_TOKEN_DES3, "RSA PKCS#1 Token 3DES" },
1072 { PCT_EXCH_RSA_PKCS1_TOKEN_RC2, "RSA PKCS#1 Token RC-2" },
1073 { PCT_EXCH_RSA_PKCS1_TOKEN_RC4, "RSA PKCS#1 Token RC-4" },
1074 { PCT_EXCH_DH_PKCS3, "DH PKCS#3" },
1075 { PCT_EXCH_DH_PKCS3_TOKEN_DES, "DH PKCS#3 Token DES" },
1076 { PCT_EXCH_DH_PKCS3_TOKEN_DES3, "DH PKCS#3 Token 3DES" },
1077 { PCT_EXCH_FORTEZZA_TOKEN, "Fortezza" },
1081 const value_string pct_error_code[] = {
1082 { PCT_ERR_BAD_CERTIFICATE, "PCT_ERR_BAD_CERTIFICATE" },
1083 { PCT_ERR_CLIENT_AUTH_FAILED, "PCT_ERR_CLIENT_AUTH_FAILE" },
1084 { PCT_ERR_ILLEGAL_MESSAGE, "PCT_ERR_ILLEGAL_MESSAGE" },
1085 { PCT_ERR_INTEGRITY_CHECK_FAILED, "PCT_ERR_INTEGRITY_CHECK_FAILED" },
1086 { PCT_ERR_SERVER_AUTH_FAILED, "PCT_ERR_SERVER_AUTH_FAILED" },
1087 { PCT_ERR_SPECS_MISMATCH, "PCT_ERR_SPECS_MISMATCH" },
1091 /* http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#tls-extensiontype-values-1 */
1092 const value_string tls_hello_extension_types[] = {
1093 { SSL_HND_HELLO_EXT_SERVER_NAME, "server_name" }, /* RFC 3546 */
1094 { 1, "max_fragment_length" },
1095 { 2, "client_certificate_url" },
1096 { 3, "trusted_ca_keys" },
1097 { 4, "truncated_hmac" },
1098 { SSL_HND_HELLO_EXT_STATUS_REQUEST, "status_request" }, /* RFC 6066 */
1099 { 6, "user_mapping" }, /* RFC 4681 */
1100 { 7, "client_authz" },
1101 { 8, "server_authz" },
1102 { SSL_HND_HELLO_EXT_CERT_TYPE, "cert_type" }, /* RFC 5081 */
1103 { SSL_HND_HELLO_EXT_ELLIPTIC_CURVES, "elliptic_curves" }, /* RFC 4492 */
1104 { SSL_HND_HELLO_EXT_EC_POINT_FORMATS, "ec_point_formats" }, /* RFC 4492 */
1105 { 12, "srp" }, /* RFC 5054 */
1106 { 13, "signature_algorithms" }, /* RFC 5246 */
1108 { SSL_HND_HELLO_EXT_HEARTBEAT, "Heartbeat" }, /* RFC 6520 */
1109 { SSL_HND_HELLO_EXT_ALPN, "Application Layer Protocol Negotiation" }, /* RFC 7301 */
1110 { SSL_HND_HELLO_EXT_STATUS_REQUEST_V2, "status_request_v2" }, /* RFC 6961 */
1111 { 18, "signed_certificate_timestamp" }, /* RFC 6962 */
1112 { SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE, "client_certificate_type" }, /* RFC 7250 */
1113 { SSL_HND_HELLO_EXT_SERVER_CERT_TYPE, "server_certificate_type" }, /* RFC 7250 */
1114 { SSL_HND_HELLO_EXT_PADDING, "Padding" }, /* http://tools.ietf.org/html/draft-agl-tls-padding */
1115 { SSL_HND_HELLO_EXT_EXTENDED_MASTER_SECRET_TYPE, "Extended Master Secret" }, /* https://tools.ietf.org/html/draft-ietf-tls-session-hash-01 */
1116 { SSL_HND_HELLO_EXT_SESSION_TICKET, "SessionTicket TLS" }, /* RFC 4507 */
1117 { SSL_HND_HELLO_EXT_NPN, "next_protocol_negotiation"}, /* http://technotes.googlecode.com/git/nextprotoneg.html */
1118 { SSL_HND_HELLO_EXT_RENEG_INFO, "renegotiation_info" }, /* RFC 5746 */
1119 /* http://tools.ietf.org/html/draft-balfanz-tls-channelid-00
1120 https://twitter.com/ericlaw/status/274237352531083264 */
1121 { SSL_HND_HELLO_EXT_CHANNEL_ID_OLD, "channel_id_old" },
1122 /* http://tools.ietf.org/html/draft-balfanz-tls-channelid-01
1123 https://code.google.com/p/chromium/codesearch#chromium/src/net/third_party/nss/ssl/sslt.h&l=209 */
1124 { SSL_HND_HELLO_EXT_CHANNEL_ID, "channel_id" },
1128 const value_string tls_hello_ext_server_name_type_vs[] = {
1133 /* RFC 5246 7.4.1.4.1 */
1134 const value_string tls_hash_algorithm[] = {
1145 const value_string tls_signature_algorithm[] = {
1154 const value_string tls_certificate_type[] = {
1157 { SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY, "Raw Public Key" }, /* RFC 7250 */
1161 const value_string tls_cert_chain_type[] = {
1162 { SSL_HND_CERT_URL_TYPE_INDIVIDUAL_CERT, "Individual Certificates" },
1163 { SSL_HND_CERT_URL_TYPE_PKIPATH, "PKI Path" },
1167 const value_string tls_cert_status_type[] = {
1168 { SSL_HND_CERT_STATUS_TYPE_OCSP, "OCSP" },
1169 { SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI, "OCSP Multi" },
1173 /* string_string is inappropriate as it compares strings while
1174 * "byte strings MUST NOT be truncated" (RFC 7301) */
1175 typedef struct ssl_alpn_protocol {
1176 const guint8 *proto_name;
1177 size_t proto_name_len;
1178 const char *dissector_name;
1179 } ssl_alpn_protocol_t;
1180 /* http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids */
1181 static const ssl_alpn_protocol_t ssl_alpn_protocols[] = {
1182 { "http/1.1", sizeof("http/1.1"), "http" },
1183 /* SPDY moves so fast, just 1, 2 and 3 are registered with IANA but there
1184 * already exists 3.1 as of this writing... match the prefix. */
1185 { "spdy/", sizeof("spdy/") - 1, "spdy" },
1186 { "stun.turn", sizeof("stun.turn"), "turnchannel" },
1187 { "stun.nat-discovery", sizeof("stun.nat-discovery"), "stun" },
1188 /* draft-ietf-httpbis-http2-16 */
1189 { "h2-", sizeof("h2-") - 1, "http2" }, /* draft versions */
1190 { "h2", sizeof("h2"), "http2" }, /* final version */
1193 /* we keep this internal to packet-ssl-utils, as there should be
1194 no need to access it any other way.
1196 This also allows us to hide the dependency on zlib.
1198 struct _SslDecompress {
1205 /* To assist in parsing client/server key exchange messages
1206 0 indicates unknown */
1207 gint ssl_get_keyex_alg(gint cipher)
1440 ssl_data_alloc(StringInfo* str, size_t len)
1442 str->data = (guchar *)g_malloc(len);
1443 /* the allocator can return a null pointer for a size equal to 0,
1444 * and that must be allowed */
1445 if (len > 0 && !str->data)
1447 str->data_len = (guint) len;
1452 ssl_data_set(StringInfo* str, const guchar* data, guint len)
1454 DISSECTOR_ASSERT(data);
1455 memcpy(str->data, data, len);
1456 str->data_len = len;
1460 ssl_data_clone(StringInfo *str)
1462 StringInfo *cloned_str;
1463 cloned_str = (StringInfo *) wmem_alloc0(wmem_file_scope(),
1464 sizeof(StringInfo) + str->data_len);
1465 cloned_str->data = (guchar *) (cloned_str + 1);
1466 ssl_data_set(cloned_str, str->data, str->data_len);
1470 /* from_hex converts |hex_len| bytes of hex data from |in| and sets |*out| to
1471 * the result. |out->data| will be allocated using wmem_file_scope. Returns TRUE on
1473 static gboolean from_hex(StringInfo* out, const char* in, gsize hex_len) {
1479 out->data = (guchar *)wmem_alloc(wmem_file_scope(), hex_len / 2);
1480 for (i = 0; i < hex_len / 2; i++) {
1481 int a = ws_xton(in[i*2]);
1482 int b = ws_xton(in[i*2 + 1]);
1483 if (a == -1 || b == -1)
1485 out->data[i] = a << 4 | b;
1487 out->data_len = (guint)hex_len / 2;
1492 #if defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT)
1494 /* hmac abstraction layer */
1495 #define SSL_HMAC gcry_md_hd_t
1498 ssl_hmac_init(SSL_HMAC* md, const void * key, gint len, gint algo)
1501 const char *err_str, *err_src;
1503 err = gcry_md_open(md,algo, GCRY_MD_FLAG_HMAC);
1505 err_str = gcry_strerror(err);
1506 err_src = gcry_strsource(err);
1507 ssl_debug_printf("ssl_hmac_init(): gcry_md_open failed %s/%s", err_str, err_src);
1510 gcry_md_setkey (*(md), key, len);
1514 ssl_hmac_update(SSL_HMAC* md, const void* data, gint len)
1516 gcry_md_write(*(md), data, len);
1519 ssl_hmac_final(SSL_HMAC* md, guchar* data, guint* datalen)
1524 algo = gcry_md_get_algo (*(md));
1525 len = gcry_md_get_algo_dlen(algo);
1526 DISSECTOR_ASSERT(len <= *datalen);
1527 memcpy(data, gcry_md_read(*(md), algo), len);
1531 ssl_hmac_cleanup(SSL_HMAC* md)
1533 gcry_md_close(*(md));
1536 /* memory digest abstraction layer*/
1537 #define SSL_MD gcry_md_hd_t
1540 ssl_md_init(SSL_MD* md, gint algo)
1543 const char *err_str, *err_src;
1544 err = gcry_md_open(md,algo, 0);
1546 err_str = gcry_strerror(err);
1547 err_src = gcry_strsource(err);
1548 ssl_debug_printf("ssl_md_init(): gcry_md_open failed %s/%s", err_str, err_src);
1554 ssl_md_update(SSL_MD* md, guchar* data, gint len)
1556 gcry_md_write(*(md), data, len);
1559 ssl_md_final(SSL_MD* md, guchar* data, guint* datalen)
1563 algo = gcry_md_get_algo (*(md));
1564 len = gcry_md_get_algo_dlen (algo);
1565 memcpy(data, gcry_md_read(*(md), algo), len);
1569 ssl_md_cleanup(SSL_MD* md)
1571 gcry_md_close(*(md));
1574 /* md5 /sha abstraction layer */
1575 #define SSL_SHA_CTX gcry_md_hd_t
1576 #define SSL_MD5_CTX gcry_md_hd_t
1579 ssl_sha_init(SSL_SHA_CTX* md)
1581 gcry_md_open(md,GCRY_MD_SHA1, 0);
1584 ssl_sha_update(SSL_SHA_CTX* md, guchar* data, gint len)
1586 gcry_md_write(*(md), data, len);
1589 ssl_sha_final(guchar* buf, SSL_SHA_CTX* md)
1591 memcpy(buf, gcry_md_read(*(md), GCRY_MD_SHA1),
1592 gcry_md_get_algo_dlen(GCRY_MD_SHA1));
1595 ssl_sha_cleanup(SSL_SHA_CTX* md)
1597 gcry_md_close(*(md));
1601 ssl_md5_init(SSL_MD5_CTX* md)
1603 return gcry_md_open(md,GCRY_MD_MD5, 0);
1606 ssl_md5_update(SSL_MD5_CTX* md, guchar* data, gint len)
1608 gcry_md_write(*(md), data, len);
1611 ssl_md5_final(guchar* buf, SSL_MD5_CTX* md)
1613 memcpy(buf, gcry_md_read(*(md), GCRY_MD_MD5),
1614 gcry_md_get_algo_dlen(GCRY_MD_MD5));
1617 ssl_md5_cleanup(SSL_MD5_CTX* md)
1619 gcry_md_close(*(md));
1623 ssl_cipher_setiv(SSL_CIPHER_CTX *cipher, guchar* iv, gint iv_len)
1630 c=(gcry_cipher_hd_t)*cipher;
1632 ssl_debug_printf("--------------------------------------------------------------------");
1634 for(ivp=c->iv,i=0; i < iv_len; i++ )
1636 ssl_debug_printf("%d ",ivp[i]);
1640 ssl_debug_printf("--------------------------------------------------------------------");
1641 ret = gcry_cipher_setiv(*(cipher), iv, iv_len);
1643 for(ivp=c->iv,i=0; i < iv_len; i++ )
1645 ssl_debug_printf("%d ",ivp[i]);
1649 ssl_debug_printf("--------------------------------------------------------------------");
1652 /* stream cipher abstraction layer*/
1654 ssl_cipher_init(gcry_cipher_hd_t *cipher, gint algo, guchar* sk,
1655 guchar* iv, gint mode)
1657 gint gcry_modes[]={GCRY_CIPHER_MODE_STREAM,GCRY_CIPHER_MODE_CBC,GCRY_CIPHER_MODE_CTR,GCRY_CIPHER_MODE_CTR,GCRY_CIPHER_MODE_CTR};
1661 *(cipher) = (gcry_cipher_hd_t)-1;
1664 err = gcry_cipher_open(cipher, algo, gcry_modes[mode], 0);
1667 err = gcry_cipher_setkey(*(cipher), sk, gcry_cipher_get_algo_keylen (algo));
1670 err = gcry_cipher_setiv(*(cipher), iv, gcry_cipher_get_algo_blklen (algo));
1676 ssl_cipher_decrypt(gcry_cipher_hd_t *cipher, guchar * out, gint outl,
1677 const guchar * in, gint inl)
1679 if ((*cipher) == (gcry_cipher_hd_t)-1)
1682 memcpy(out, in, outl < inl ? outl : inl);
1685 return gcry_cipher_decrypt ( *(cipher), out, outl, in, inl);
1688 ssl_get_digest_by_name(const gchar*name)
1690 return gcry_md_map_name(name);
1693 ssl_get_cipher_by_name(const gchar* name)
1695 return gcry_cipher_map_name(name);
1699 ssl_cipher_cleanup(gcry_cipher_hd_t *cipher)
1701 if ((*cipher) != (gcry_cipher_hd_t)-1)
1702 gcry_cipher_close(*cipher);
1707 _gcry_rsa_decrypt (int algo, gcry_mpi_t *result, gcry_mpi_t *data,
1708 gcry_mpi_t *skey, gint flags);
1710 /* decrypt data with private key. Store decrypted data directly into input
1713 ssl_private_decrypt(const guint len, guchar* data, SSL_PRIVATE_KEY* pk)
1716 size_t decr_len = 0, i = 0;
1717 gcry_sexp_t s_data = NULL, s_plain = NULL;
1718 gcry_mpi_t encr_mpi = NULL, text = NULL;
1720 /* create mpi representation of encrypted data */
1721 rc = gcry_mpi_scan(&encr_mpi, GCRYMPI_FMT_USG, data, len, NULL);
1723 ssl_debug_printf("pcry_private_decrypt: can't convert data to mpi (size %d):%s\n",
1724 len, gcry_strerror(rc));
1729 /* put the data into a simple list */
1730 rc = gcry_sexp_build(&s_data, NULL, "(enc-val(rsa(a%m)))", encr_mpi);
1732 ssl_debug_printf("pcry_private_decrypt: can't build encr_sexp:%s\n",
1738 /* pass it to libgcrypt */
1739 rc = gcry_pk_decrypt(&s_plain, s_data, pk);
1742 ssl_debug_printf("pcry_private_decrypt: can't decrypt key:%s\n",
1748 /* convert plain text sexp to mpi format */
1749 text = gcry_sexp_nth_mpi(s_plain, 0, 0);
1751 ssl_debug_printf("pcry_private_decrypt: can't convert sexp to mpi\n");
1756 /* compute size requested for plaintext buffer */
1757 rc = gcry_mpi_print(GCRYMPI_FMT_USG, NULL, 0, &decr_len, text);
1759 ssl_debug_printf("pcry_private_decrypt: can't compute decr size:%s\n",
1765 #else /* SSL_FAST */
1766 rc = _gcry_rsa_decrypt(0, &text, &encr_mpi, pk,0);
1767 gcry_mpi_print( GCRYMPI_FMT_USG, 0, 0, &decr_len, text);
1768 #endif /* SSL_FAST */
1770 /* sanity check on out buffer */
1771 if (decr_len > len) {
1772 ssl_debug_printf("pcry_private_decrypt: decrypted data is too long ?!? (%" G_GSIZE_MODIFIER "u max %d)\n", decr_len, len);
1777 /* write plain text to newly allocated buffer */
1778 rc = gcry_mpi_print(GCRYMPI_FMT_USG, data, len, &decr_len, text);
1780 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));
1785 ssl_print_data("decrypted_unstrip_pre_master", data, decr_len);
1787 /* strip the padding*/
1789 for (i = 1; i < decr_len; i++) {
1796 ssl_debug_printf("pcry_private_decrypt: stripping %d bytes, decr_len %" G_GSIZE_MODIFIER "u\n", rc, decr_len);
1798 memmove(data, data+rc, decr_len);
1801 gcry_sexp_release(s_data);
1802 gcry_sexp_release(s_plain);
1803 gcry_mpi_release(encr_mpi);
1804 gcry_mpi_release(text);
1805 return (int) decr_len;
1808 /* stringinfo interface */
1810 ssl_data_realloc(StringInfo* str, guint len)
1812 str->data = (guchar *)g_realloc(str->data, len);
1815 str->data_len = len;
1820 ssl_data_copy(StringInfo* dst, StringInfo* src)
1822 if (dst->data_len < src->data_len) {
1823 if (ssl_data_realloc(dst, src->data_len))
1826 memcpy(dst->data, src->data, src->data_len);
1827 dst->data_len = src->data_len;
1831 static const SslDigestAlgo digests[]={
1836 {"Not Applicable", 0},
1839 #define DIGEST_MAX_SIZE 48
1841 /* get index digest index */
1842 static const SslDigestAlgo *
1843 ssl_cipher_suite_dig(SslCipherSuite *cs) {
1844 return &digests[cs->dig - DIG_MD5];
1847 static const gchar *ciphers[]={
1850 "ARCFOUR", /* libgcrypt does not support rc4, but this should be 100% compatible*/
1851 "RFC2268_128", /* libgcrypt name for RC2 with a 128-bit key */
1861 static SslCipherSuite cipher_suites[]={
1862 {0x0001,KEX_RSA, ENC_NULL, 1, 0, 0,DIG_MD5, MODE_STREAM}, /* TLS_RSA_WITH_NULL_MD5 */
1863 {0x0002,KEX_RSA, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_RSA_WITH_NULL_SHA */
1864 {0x0003,KEX_RSA, ENC_RC4, 1,128, 40,DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT_WITH_RC4_40_MD5 */
1865 {0x0004,KEX_RSA, ENC_RC4, 1,128,128,DIG_MD5, MODE_STREAM}, /* TLS_RSA_WITH_RC4_128_MD5 */
1866 {0x0005,KEX_RSA, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_RSA_WITH_RC4_128_SHA */
1867 {0x0006,KEX_RSA, ENC_RC2, 8,128, 40,DIG_MD5, MODE_CBC }, /* TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 */
1868 {0x0007,KEX_RSA, ENC_IDEA, 8,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_IDEA_CBC_SHA */
1869 {0x0008,KEX_RSA, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_RSA_EXPORT_WITH_DES40_CBC_SHA */
1870 {0x0009,KEX_RSA, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_DES_CBC_SHA */
1871 {0x000A,KEX_RSA, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_3DES_EDE_CBC_SHA */
1872 {0x000B,KEX_DH, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA */
1873 {0x000C,KEX_DH, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_DES_CBC_SHA */
1874 {0x000D,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA */
1875 {0x000E,KEX_DH, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA */
1876 {0x000F,KEX_DH, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_DES_CBC_SHA */
1877 {0x0010,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA */
1878 {0x0011,KEX_DH, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA */
1879 {0x0012,KEX_DH, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_DES_CBC_SHA */
1880 {0x0013,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA */
1881 {0x0014,KEX_DH, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA */
1882 {0x0015,KEX_DH, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_DES_CBC_SHA */
1883 {0x0016,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */
1884 {0x0017,KEX_DH, ENC_RC4, 1,128, 40,DIG_MD5, MODE_STREAM}, /* TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 */
1885 {0x0018,KEX_DH, ENC_RC4, 1,128,128,DIG_MD5, MODE_STREAM}, /* TLS_DH_anon_WITH_RC4_128_MD5 */
1886 {0x0019,KEX_DH, ENC_DES, 8, 64, 40,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA */
1887 {0x001A,KEX_DH, ENC_DES, 8, 64, 64,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_DES_CBC_SHA */
1888 {0x001B,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_3DES_EDE_CBC_SHA */
1889 {0x002C,KEX_PSK, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA */
1890 {0x002D,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA */
1891 {0x002E,KEX_RSA_PSK,ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA */
1892 {0x002F,KEX_RSA, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_AES_128_CBC_SHA */
1893 {0x0030,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_128_CBC_SHA */
1894 {0x0031,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_128_CBC_SHA */
1895 {0x0032,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_128_CBC_SHA */
1896 {0x0033,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
1897 {0x0034,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_AES_128_CBC_SHA */
1898 {0x0035,KEX_RSA, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_AES_256_CBC_SHA */
1899 {0x0036,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_256_CBC_SHA */
1900 {0x0037,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_256_CBC_SHA */
1901 {0x0038,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_256_CBC_SHA */
1902 {0x0039,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */
1903 {0x003A,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_AES_256_CBC_SHA */
1904 {0x003B,KEX_RSA, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_RSA_WITH_NULL_SHA256 */
1905 {0x003C,KEX_RSA, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_AES_128_CBC_SHA256 */
1906 {0x003D,KEX_RSA, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_AES_256_CBC_SHA256 */
1907 {0x003E,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_128_CBC_SHA256 */
1908 {0x003F,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_128_CBC_SHA256 */
1909 {0x0040,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 */
1910 {0x0041,KEX_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */
1911 {0x0042,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA */
1912 {0x0043,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA */
1913 {0x0044,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA */
1914 {0x0045,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */
1915 {0x0046,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA */
1916 {0x0060,KEX_RSA, ENC_RC4, 1,128, 56,DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC4_56_MD5 */
1917 {0x0061,KEX_RSA, ENC_RC2, 1,128, 56,DIG_MD5, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 */
1918 {0x0062,KEX_RSA, ENC_DES, 8, 64, 56,DIG_SHA, MODE_CBC }, /* TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA */
1919 {0x0063,KEX_DH, ENC_DES, 8, 64, 56,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA */
1920 {0x0064,KEX_RSA, ENC_RC4, 1,128, 56,DIG_SHA, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC4_56_SHA */
1921 {0x0065,KEX_DH, ENC_RC4, 1,128, 56,DIG_SHA, MODE_STREAM}, /* TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA */
1922 {0x0066,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_DHE_DSS_WITH_RC4_128_SHA */
1923 {0x0067,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */
1924 {0x0068,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_256_CBC_SHA256 */
1925 {0x0069,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_256_CBC_SHA256 */
1926 {0x006A,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 */
1927 {0x006B,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */
1928 {0x006C,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_AES_128_CBC_SHA256 */
1929 {0x006D,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_AES_256_CBC_SHA256 */
1930 {0x0084,KEX_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */
1931 {0x0085,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA */
1932 {0x0086,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA */
1933 {0x0087,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA */
1934 {0x0088,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */
1935 {0x0089,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA */
1936 {0x008A,KEX_PSK, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_PSK_WITH_RC4_128_SHA */
1937 {0x008B,KEX_PSK, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_3DES_EDE_CBC_SHA */
1938 {0x008C,KEX_PSK, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_AES_128_CBC_SHA */
1939 {0x008D,KEX_PSK, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_PSK_WITH_AES_256_CBC_SHA */
1940 {0x008E,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_DHE_PSK_WITH_RC4_128_SHA */
1941 {0x008F,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA */
1942 {0x0090,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA */
1943 {0x0091,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA */
1944 {0x0092,KEX_RSA_PSK,ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_RSA_PSK_WITH_RC4_128_SHA */
1945 {0x0093,KEX_RSA_PSK,ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA */
1946 {0x0094,KEX_RSA_PSK,ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_128_CBC_SHA */
1947 {0x0095,KEX_RSA_PSK,ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_256_CBC_SHA */
1948 {0x0096,KEX_RSA, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_RSA_WITH_SEED_CBC_SHA */
1949 {0x0097,KEX_DH, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_DSS_WITH_SEED_CBC_SHA */
1950 {0x0098,KEX_DH, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_RSA_WITH_SEED_CBC_SHA */
1951 {0x0099,KEX_DH, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_DSS_WITH_SEED_CBC_SHA */
1952 {0x009A,KEX_DH, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DHE_RSA_WITH_SEED_CBC_SHA */
1953 {0x009B,KEX_DH, ENC_SEED, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_DH_anon_WITH_SEED_CBC_SHA */
1954 {0x009C,KEX_RSA, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_WITH_AES_128_GCM_SHA256 */
1955 {0x009D,KEX_RSA, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_WITH_AES_256_GCM_SHA384 */
1956 {0x009E,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */
1957 {0x009F,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */
1958 {0x00A0,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_RSA_WITH_AES_128_GCM_SHA256 */
1959 {0x00A1,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_RSA_WITH_AES_256_GCM_SHA384 */
1960 {0x00A2,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 */
1961 {0x00A3,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 */
1962 {0x00A4,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_DSS_WITH_AES_128_GCM_SHA256 */
1963 {0x00A5,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_DSS_WITH_AES_256_GCM_SHA384 */
1964 {0x00A6,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_anon_WITH_AES_128_GCM_SHA256 */
1965 {0x00A7,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */
1966 {0x00A8,KEX_PSK, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_PSK_WITH_AES_128_GCM_SHA256 */
1967 {0x00A9,KEX_PSK, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_PSK_WITH_AES_256_GCM_SHA384 */
1968 {0x00AA,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */
1969 {0x00AB,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */
1970 {0x00AC,KEX_RSA_PSK,ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 */
1971 {0x00AD,KEX_RSA_PSK,ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 */
1972 {0x00AE,KEX_PSK, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_PSK_WITH_AES_128_CBC_SHA256 */
1973 {0x00AF,KEX_PSK, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_PSK_WITH_AES_256_CBC_SHA384 */
1974 {0x00B0,KEX_PSK, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA256 */
1975 {0x00B1,KEX_PSK, ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA384 */
1976 {0x00B2,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */
1977 {0x00B3,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */
1978 {0x00B4,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA256 */
1979 {0x00B5,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA384 */
1980 {0x00B6,KEX_RSA_PSK,ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 */
1981 {0x00B7,KEX_RSA_PSK,ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 */
1982 {0x00B8,KEX_RSA_PSK,ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA256 */
1983 {0x00B9,KEX_RSA_PSK,ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA384 */
1984 {0x00BA,KEX_RSA, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
1985 {0x00BB,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 */
1986 {0x00BC,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
1987 {0x00BD,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 */
1988 {0x00BE,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
1989 {0x00BF,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256 */
1990 {0x00C0,KEX_RSA, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
1991 {0x00C1,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 */
1992 {0x00C2,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
1993 {0x00C3,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 */
1994 {0x00C4,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
1995 {0x00C5,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA256, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 */
1996 {0xC001,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_ECDSA_WITH_NULL_SHA */
1997 {0xC002,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */
1998 {0xC003,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */
1999 {0xC004,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */
2000 {0xC005,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */
2001 {0xC006,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */
2002 {0xC007,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */
2003 {0xC008,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */
2004 {0xC009,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */
2005 {0xC00A,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */
2006 {0xC00B,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_RSA_WITH_NULL_SHA */
2007 {0xC00C,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_RSA_WITH_RC4_128_SHA */
2008 {0xC00D,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */
2009 {0xC00E,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */
2010 {0xC00F,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */
2011 {0xC010,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_RSA_WITH_NULL_SHA */
2012 {0xC011,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */
2013 {0xC012,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */
2014 {0xC013,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */
2015 {0xC014,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */
2016 {0xC015,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_anon_WITH_NULL_SHA */
2017 {0xC016,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDH_anon_WITH_RC4_128_SHA */
2018 {0xC017,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA */
2019 {0xC018,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_AES_128_CBC_SHA */
2020 {0xC019,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDH_anon_WITH_AES_256_CBC_SHA */
2021 {0xC023,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 */
2022 {0xC024,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 */
2023 {0xC025,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */
2024 {0xC026,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */
2025 {0xC027,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */
2026 {0xC028,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */
2027 {0xC029,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */
2028 {0xC02A,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */
2029 {0xC02B,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */
2030 {0xC02C,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */
2031 {0xC02D,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */
2032 {0xC02E,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */
2033 {0xC02F,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */
2034 {0xC030,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */
2035 {0xC031,KEX_DH, ENC_AES, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */
2036 {0xC032,KEX_DH, ENC_AES256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */
2037 {0xC033,KEX_DH, ENC_RC4, 1,128,128,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_RC4_128_SHA */
2038 {0xC034,KEX_DH, ENC_3DES, 8,192,192,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA */
2039 {0xC035,KEX_DH, ENC_AES, 16,128,128,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA */
2040 {0xC036,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA */
2041 {0xC037,KEX_DH, ENC_AES, 16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */
2042 {0xC038,KEX_DH, ENC_AES256, 16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 */
2043 {0xC039,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA */
2044 {0xC03A,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA256, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */
2045 {0xC03B,KEX_DH, ENC_NULL, 1, 0, 0,DIG_SHA384, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA384 */
2046 {0xC072,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */
2047 {0xC073,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 */
2048 {0xC074,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */
2049 {0xC075,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 */
2050 {0xC076,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2051 {0xC077,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 */
2052 {0xC078,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
2053 {0xC079,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 */
2054 {0xC07A,KEX_RSA, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2055 {0xC07B,KEX_RSA, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2056 {0xC07C,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2057 {0xC07D,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2058 {0xC07E,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2059 {0xC07F,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2060 {0xC080,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256 */
2061 {0xC081,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384 */
2062 {0xC082,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256 */
2063 {0xC083,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384 */
2064 {0xC084,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256 */
2065 {0xC085,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384 */
2066 {0xC086,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 */
2067 {0xC087,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */
2068 {0xC088,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 */
2069 {0xC089,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */
2070 {0xC08A,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2071 {0xC08B,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2072 {0xC08C,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
2073 {0xC08D,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
2074 {0xC08E,KEX_PSK, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2075 {0xC08F,KEX_PSK, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2076 {0xC090,KEX_DH, ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2077 {0xC091,KEX_DH, ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2078 {0xC092,KEX_RSA_PSK,ENC_CAMELLIA128, 4,128,128,DIG_SHA256, MODE_GCM }, /* TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
2079 {0xC093,KEX_RSA_PSK,ENC_CAMELLIA256, 4,256,256,DIG_SHA384, MODE_GCM }, /* TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
2080 {0xC094,KEX_PSK, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2081 {0xC095,KEX_PSK, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2082 {0xC096,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2083 {0xC097,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2084 {0xC098,KEX_RSA_PSK,ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2085 {0xC099,KEX_RSA_PSK,ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2086 {0xC09A,KEX_DH, ENC_CAMELLIA128,16,128,128,DIG_SHA256, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
2087 {0xC09B,KEX_DH, ENC_CAMELLIA256,16,256,256,DIG_SHA384, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
2088 {0xC09C,KEX_RSA, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_RSA_WITH_AES_128_CCM */
2089 {0xC09D,KEX_RSA, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_RSA_WITH_AES_256_CCM */
2090 {0xC09E,KEX_DH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_DHE_RSA_WITH_AES_128_CCM */
2091 {0xC09F,KEX_DH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_DHE_RSA_WITH_AES_256_CCM */
2092 {0xC0A0,KEX_RSA, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_RSA_WITH_AES_128_CCM_8 */
2093 {0xC0A1,KEX_RSA, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_RSA_WITH_AES_256_CCM_8 */
2094 {0xC0A2,KEX_DH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_DHE_RSA_WITH_AES_128_CCM_8 */
2095 {0xC0A3,KEX_DH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_DHE_RSA_WITH_AES_256_CCM_8 */
2096 {0xC0A4,KEX_PSK, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_PSK_WITH_AES_128_CCM */
2097 {0xC0A5,KEX_PSK, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_PSK_WITH_AES_256_CCM */
2098 {0xC0A6,KEX_DH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_DHE_PSK_WITH_AES_128_CCM */
2099 {0xC0A7,KEX_DH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_DHE_PSK_WITH_AES_256_CCM */
2100 {0xC0A8,KEX_PSK, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_WITH_AES_128_CCM_8 */
2101 {0xC0A9,KEX_PSK, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_WITH_AES_256_CCM_8 */
2102 {0xC0AA,KEX_DH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_DHE_WITH_AES_128_CCM_8 */
2103 {0xC0AB,KEX_DH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_PSK_DHE_WITH_AES_256_CCM_8 */
2104 {0xC0AC,KEX_ECDH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */
2105 {0xC0AD,KEX_ECDH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM */
2106 {0xC0AE,KEX_ECDH, ENC_AES, 4,128,128,DIG_NA, MODE_CCM_8 }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */
2107 {0xC0AF,KEX_ECDH, ENC_AES256, 4,256,256,DIG_NA, MODE_CCM_8 }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */
2108 {-1, 0, 0, 0, 0, 0,0, MODE_STREAM}
2111 #define MAX_BLOCK_SIZE 16
2112 #define MAX_KEY_SIZE 32
2115 ssl_find_cipher(int num,SslCipherSuite* cs)
2119 for(c=cipher_suites;c->number!=-1;c++){
2130 tls_hash(StringInfo *secret, StringInfo *seed, gint md,
2131 StringInfo *out, guint out_len)
2133 /* RFC 2246 5. HMAC and the pseudorandom function
2134 * '+' denotes concatenation.
2135 * P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
2136 * HMAC_hash(secret, A(2) + seed) + ...
2138 * A(i) = HMAC_hash(secret, A(i - 1))
2143 guint8 _A[DIGEST_MAX_SIZE], tmp[DIGEST_MAX_SIZE];
2150 ssl_print_string("tls_hash: hash secret", secret);
2151 ssl_print_string("tls_hash: hash seed", seed);
2154 A_l = seed->data_len;
2157 /* A(i) = HMAC_hash(secret, A(i-1)) */
2158 ssl_hmac_init(&hm, secret->data, secret->data_len, md);
2159 ssl_hmac_update(&hm, A, A_l);
2160 A_l = sizeof(_A); /* upper bound len for hash output */
2161 ssl_hmac_final(&hm, _A, &A_l);
2162 ssl_hmac_cleanup(&hm);
2165 /* HMAC_hash(secret, A(i) + seed) */
2166 ssl_hmac_init(&hm, secret->data, secret->data_len, md);
2167 ssl_hmac_update(&hm, A, A_l);
2168 ssl_hmac_update(&hm, seed->data, seed->data_len);
2169 tmp_l = sizeof(tmp); /* upper bound len for hash output */
2170 ssl_hmac_final(&hm, tmp, &tmp_l);
2171 ssl_hmac_cleanup(&hm);
2173 /* ssl_hmac_final puts the actual digest output size in tmp_l */
2174 tocpy = MIN(left, tmp_l);
2175 memcpy(ptr, tmp, tocpy);
2179 out->data_len = out_len;
2181 ssl_print_string("hash out", out);
2185 tls_prf(StringInfo* secret, const gchar *usage,
2186 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, guint out_len)
2188 StringInfo seed, sha_out, md5_out;
2192 size_t usage_len, rnd2_len;
2193 gboolean success = FALSE;
2194 usage_len = strlen(usage);
2195 rnd2_len = rnd2 ? rnd2->data_len : 0;
2197 /* initalize buffer for sha, md5 random seed*/
2198 if (ssl_data_alloc(&sha_out, MAX(out_len, 20)) < 0) {
2199 ssl_debug_printf("tls_prf: can't allocate sha out\n");
2202 if (ssl_data_alloc(&md5_out, MAX(out_len, 16)) < 0) {
2203 ssl_debug_printf("tls_prf: can't allocate md5 out\n");
2206 if (ssl_data_alloc(&seed, usage_len+rnd1->data_len+rnd2_len) < 0) {
2207 ssl_debug_printf("tls_prf: can't allocate rnd %d\n",
2208 (int) (usage_len+rnd1->data_len+rnd2_len));
2213 memcpy(ptr,usage,usage_len);
2215 memcpy(ptr,rnd1->data,rnd1->data_len);
2217 ptr+=rnd1->data_len;
2218 memcpy(ptr,rnd2->data,rnd2->data_len);
2219 /*ptr+=rnd2->data_len;*/
2222 /* initalize buffer for client/server seeds*/
2223 s_l=secret->data_len/2 + secret->data_len%2;
2224 if (ssl_data_alloc(&s1, s_l) < 0) {
2225 ssl_debug_printf("tls_prf: can't allocate secret %d\n", s_l);
2228 if (ssl_data_alloc(&s2, s_l) < 0) {
2229 ssl_debug_printf("tls_prf: can't allocate secret(2) %d\n", s_l);
2233 memcpy(s1.data,secret->data,s_l);
2234 memcpy(s2.data,secret->data + (secret->data_len - s_l),s_l);
2236 ssl_debug_printf("tls_prf: tls_hash(md5 secret_len %d seed_len %d )\n", s1.data_len, seed.data_len);
2237 tls_hash(&s1, &seed, ssl_get_digest_by_name("MD5"), &md5_out, out_len);
2238 ssl_debug_printf("tls_prf: tls_hash(sha)\n");
2239 tls_hash(&s2, &seed, ssl_get_digest_by_name("SHA1"), &sha_out, out_len);
2241 for (i = 0; i < out_len; i++)
2242 out->data[i] = md5_out.data[i] ^ sha_out.data[i];
2243 /* success, now store the new meaningful data length */
2244 out->data_len = out_len;
2247 ssl_print_string("PRF out",out);
2254 g_free(md5_out.data);
2256 g_free(sha_out.data);
2261 tls12_prf(gint md, StringInfo* secret, const gchar* usage,
2262 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, guint out_len)
2264 StringInfo label_seed;
2265 size_t usage_len, rnd2_len;
2266 rnd2_len = rnd2 ? rnd2->data_len : 0;
2268 usage_len = strlen(usage);
2269 if (ssl_data_alloc(&label_seed, usage_len+rnd1->data_len+rnd2_len) < 0) {
2270 ssl_debug_printf("tls12_prf: can't allocate label_seed\n");
2273 memcpy(label_seed.data, usage, usage_len);
2274 memcpy(label_seed.data+usage_len, rnd1->data, rnd1->data_len);
2276 memcpy(label_seed.data+usage_len+rnd1->data_len, rnd2->data, rnd2->data_len);
2278 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);
2279 tls_hash(secret, &label_seed, md, out, out_len);
2280 g_free(label_seed.data);
2281 ssl_print_string("PRF out", out);
2286 ssl3_generate_export_iv(StringInfo *r1, StringInfo *r2,
2287 StringInfo *out, guint out_len)
2293 ssl_md5_update(&md5,r1->data,r1->data_len);
2294 ssl_md5_update(&md5,r2->data,r2->data_len);
2295 ssl_md5_final(tmp,&md5);
2296 ssl_md5_cleanup(&md5);
2298 DISSECTOR_ASSERT(out_len <= sizeof(tmp));
2299 ssl_data_set(out, tmp, out_len);
2300 ssl_print_string("export iv", out);
2304 ssl3_prf(StringInfo* secret, const gchar* usage,
2305 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, guint out_len)
2313 for (off = 0; off < out_len; off += 16) {
2317 ssl_debug_printf("ssl3_prf: sha1_hash(%d)\n",i);
2318 /* A, BB, CCC, ... */
2324 ssl_sha_update(&sha,buf,i);
2325 ssl_sha_update(&sha,secret->data,secret->data_len);
2327 if(!strcmp(usage,"client write key") || !strcmp(usage,"server write key")){
2329 ssl_sha_update(&sha,rnd2->data,rnd2->data_len);
2330 ssl_sha_update(&sha,rnd1->data,rnd1->data_len);
2333 ssl_sha_update(&sha,rnd1->data,rnd1->data_len);
2335 ssl_sha_update(&sha,rnd2->data,rnd2->data_len);
2338 ssl_sha_final(buf,&sha);
2339 ssl_sha_cleanup(&sha);
2341 ssl_debug_printf("ssl3_prf: md5_hash(%d) datalen %d\n",i,
2344 ssl_md5_update(&md5,secret->data,secret->data_len);
2345 ssl_md5_update(&md5,buf,20);
2346 ssl_md5_final(outbuf,&md5);
2347 ssl_md5_cleanup(&md5);
2349 memcpy(out->data + off, outbuf, MIN(out_len - off, 16));
2351 out->data_len = out_len;
2356 /* out_len is the wanted output length for the pseudorandom function */
2358 prf(SslDecryptSession *ssl, StringInfo *secret, const gchar *usage,
2359 StringInfo *rnd1, StringInfo *rnd2, StringInfo *out, guint out_len)
2361 switch (ssl->version_netorder) {
2363 return ssl3_prf(secret, usage, rnd1, rnd2, out, out_len);
2366 case TLSV1DOT1_VERSION:
2367 case DTLSV1DOT0_VERSION:
2368 case DTLSV1DOT0_VERSION_NOT:
2369 return tls_prf(secret, usage, rnd1, rnd2, out, out_len);
2371 default: /* TLSv1.2 */
2372 switch (ssl->cipher_suite.dig) {
2374 return tls12_prf(GCRY_MD_SHA384, secret, usage, rnd1, rnd2,
2377 return tls12_prf(GCRY_MD_SHA256, secret, usage, rnd1, rnd2,
2383 static gint tls_handshake_hash(SslDecryptSession* ssl, StringInfo* out)
2388 if (ssl_data_alloc(out, 36) < 0)
2392 ssl_md5_update(&md5,ssl->handshake_data.data,ssl->handshake_data.data_len);
2393 ssl_md5_final(out->data,&md5);
2394 ssl_md5_cleanup(&md5);
2397 ssl_sha_update(&sha,ssl->handshake_data.data,ssl->handshake_data.data_len);
2398 ssl_sha_final(out->data+16,&sha);
2399 ssl_sha_cleanup(&sha);
2403 static gint tls12_handshake_hash(SslDecryptSession* ssl, gint md, StringInfo* out)
2409 ssl_md_init(&mc, md);
2410 ssl_md_update(&mc,ssl->handshake_data.data,ssl->handshake_data.data_len);
2411 ssl_md_final(&mc, tmp, &len);
2412 ssl_md_cleanup(&mc);
2414 if (ssl_data_alloc(out, len) < 0)
2416 memcpy(out->data, tmp, len);
2421 ssl_create_flow(void)
2425 flow = (SslFlow *)wmem_alloc(wmem_file_scope(), sizeof(SslFlow));
2428 flow->multisegment_pdus = wmem_tree_new(wmem_file_scope());
2433 /* memory allocation functions for zlib initialization */
2434 static void* ssl_zalloc(void* opaque _U_, unsigned int no, unsigned int size)
2436 return g_malloc0(no*size);
2438 static void ssl_zfree(void* opaque _U_, void* addr)
2444 static SslDecompress*
2445 ssl_create_decompressor(gint compression)
2447 SslDecompress *decomp;
2452 if (compression == 0) return NULL;
2453 ssl_debug_printf("ssl_create_decompressor: compression method %d\n", compression);
2454 decomp = (SslDecompress *)wmem_alloc(wmem_file_scope(), sizeof(SslDecompress));
2455 decomp->compression = compression;
2456 switch (decomp->compression) {
2458 case 1: /* DEFLATE */
2459 decomp->istream.zalloc = ssl_zalloc;
2460 decomp->istream.zfree = ssl_zfree;
2461 decomp->istream.opaque = Z_NULL;
2462 decomp->istream.next_in = Z_NULL;
2463 decomp->istream.next_out = Z_NULL;
2464 decomp->istream.avail_in = 0;
2465 decomp->istream.avail_out = 0;
2466 err = inflateInit_(&decomp->istream, ZLIB_VERSION, sizeof(z_stream));
2468 ssl_debug_printf("ssl_create_decompressor: inflateInit_() failed - %d\n", err);
2474 ssl_debug_printf("ssl_create_decompressor: unsupported compression method %d\n", decomp->compression);
2481 ssl_create_decoder(SslCipherSuite *cipher_suite, gint compression,
2482 guint8 *mk, guint8 *sk, guint8 *iv)
2487 dec = (SslDecoder *)wmem_alloc0(wmem_file_scope(), sizeof(SslDecoder));
2488 /* Find the SSLeay cipher */
2489 if(cipher_suite->enc!=ENC_NULL) {
2490 ssl_debug_printf("ssl_create_decoder CIPHER: %s\n", ciphers[cipher_suite->enc-0x30]);
2491 ciph=ssl_get_cipher_by_name(ciphers[cipher_suite->enc-0x30]);
2493 ssl_debug_printf("ssl_create_decoder CIPHER: %s\n", "NULL");
2497 ssl_debug_printf("ssl_create_decoder can't find cipher %s\n",
2498 ciphers[cipher_suite->enc > ENC_NULL ? ENC_NULL-0x30 : (cipher_suite->enc-0x30)]);
2502 /* init mac buffer: mac storage is embedded into decoder struct to save a
2503 memory allocation and waste samo more memory*/
2504 dec->cipher_suite=cipher_suite;
2505 dec->compression = compression;
2506 /* AEED ciphers don't have a MAC but need to keep the write IV instead */
2508 dec->write_iv.data = dec->_mac_key_or_write_iv;
2509 ssl_data_set(&dec->write_iv, iv, cipher_suite->block);
2511 dec->mac_key.data = dec->_mac_key_or_write_iv;
2512 ssl_data_set(&dec->mac_key, mk, ssl_cipher_suite_dig(cipher_suite)->len);
2515 dec->decomp = ssl_create_decompressor(compression);
2516 dec->flow = ssl_create_flow();
2519 ssl_cipher_cleanup(&dec->evp);
2521 if (ssl_cipher_init(&dec->evp,ciph,sk,iv,cipher_suite->mode) < 0) {
2522 ssl_debug_printf("ssl_create_decoder: can't create cipher id:%d mode:%d\n",
2523 ciph, cipher_suite->mode);
2527 ssl_debug_printf("decoder initialized (digest len %d)\n", ssl_cipher_suite_dig(cipher_suite)->len);
2532 ssl_decrypt_pre_master_secret(SslDecryptSession *ssl_session,
2533 StringInfo *encrypted_pre_master,
2534 SSL_PRIVATE_KEY *pk);
2536 ssl_restore_master_key(SslDecryptSession *ssl, const char *label,
2537 gboolean is_pre_master, GHashTable *ht, StringInfo *key);
2540 ssl_generate_pre_master_secret(SslDecryptSession *ssl_session,
2541 guint32 length, tvbuff_t *tvb, guint32 offset,
2542 const gchar *ssl_psk,
2543 const ssl_master_key_map_t *mk_map)
2545 /* check for required session data */
2546 ssl_debug_printf("%s: found SSL_HND_CLIENT_KEY_EXCHG, state %X\n",
2547 G_STRFUNC, ssl_session->state);
2548 if ((ssl_session->state & (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION)) !=
2549 (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION)) {
2550 ssl_debug_printf("%s: not enough data to generate key (required state %X)\n", G_STRFUNC,
2551 (SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION));
2555 /* check to see if the PMS was provided to us*/
2556 if (ssl_restore_master_key(ssl_session, "Unencrypted pre-master secret", TRUE,
2557 mk_map->pms, &ssl_session->client_random)) {
2561 if (ssl_session->cipher_suite.kex == KEX_PSK)
2563 /* calculate pre master secret*/
2564 StringInfo pre_master_secret;
2565 guint psk_len, pre_master_len;
2567 if (!ssl_psk || (ssl_psk[0] == 0)) {
2568 ssl_debug_printf("%s: can't find pre-shared-key\n", G_STRFUNC);
2572 /* convert hex string into char*/
2573 if (!from_hex(&ssl_session->psk, ssl_psk, strlen(ssl_psk))) {
2574 ssl_debug_printf("%s: ssl.psk/dtls.psk contains invalid hex\n",
2579 psk_len = ssl_session->psk.data_len;
2580 if (psk_len >= (2 << 15)) {
2581 ssl_debug_printf("%s: ssl.psk/dtls.psk must not be larger than 2^15 - 1\n",
2587 pre_master_len = psk_len * 2 + 4;
2589 pre_master_secret.data = (guchar *)wmem_alloc(wmem_file_scope(), pre_master_len);
2590 pre_master_secret.data_len = pre_master_len;
2591 /* 2 bytes psk_len*/
2592 pre_master_secret.data[0] = psk_len >> 8;
2593 pre_master_secret.data[1] = psk_len & 0xFF;
2594 /* psk_len bytes times 0*/
2595 memset(&pre_master_secret.data[2], 0, psk_len);
2596 /* 2 bytes psk_len*/
2597 pre_master_secret.data[psk_len + 2] = psk_len >> 8;
2598 pre_master_secret.data[psk_len + 3] = psk_len & 0xFF;
2600 memcpy(&pre_master_secret.data[psk_len + 4], ssl_session->psk.data, psk_len);
2602 ssl_session->pre_master_secret.data = pre_master_secret.data;
2603 ssl_session->pre_master_secret.data_len = pre_master_len;
2604 /*ssl_debug_printf("pre master secret",&ssl->pre_master_secret);*/
2606 /* Remove the master secret if it was there.
2607 This forces keying material regeneration in
2608 case we're renegotiating */
2609 ssl_session->state &= ~(SSL_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
2610 ssl_session->state |= SSL_PRE_MASTER_SECRET;
2615 StringInfo encrypted_pre_master;
2616 guint encrlen, skip;
2620 /* get encrypted data, on tls1 we have to skip two bytes
2621 * (it's the encrypted len and should be equal to record len - 2)
2622 * in case of rsa1024 that would be 128 + 2 = 130; for psk not necessary
2624 if (ssl_session->cipher_suite.kex == KEX_RSA &&
2625 (ssl_session->session.version == SSL_VER_TLS || ssl_session->session.version == SSL_VER_TLSv1DOT1 ||
2626 ssl_session->session.version == SSL_VER_TLSv1DOT2 || ssl_session->session.version == SSL_VER_DTLS ||
2627 ssl_session->session.version == SSL_VER_DTLS1DOT2))
2629 encrlen = tvb_get_ntohs(tvb, offset);
2631 if (encrlen > length - 2)
2633 ssl_debug_printf("%s: wrong encrypted length (%d max %d)\n",
2634 G_STRFUNC, encrlen, length);
2638 /* the valid lower bound is higher than 8, but it is sufficient for the
2639 * ssl keylog file below */
2641 ssl_debug_printf("%s: invalid encrypted pre-master key length %d\n",
2642 G_STRFUNC, encrlen);
2646 encrypted_pre_master.data = (guchar *)wmem_alloc(wmem_file_scope(), encrlen);
2647 encrypted_pre_master.data_len = encrlen;
2648 tvb_memcpy(tvb, encrypted_pre_master.data, offset+skip, encrlen);
2650 if (ssl_session->private_key) {
2651 /* try to decrypt encrypted pre-master with RSA key */
2652 if (ssl_decrypt_pre_master_secret(ssl_session,
2653 &encrypted_pre_master, ssl_session->private_key))
2656 ssl_debug_printf("%s: can't decrypt pre-master secret\n",
2660 /* try to find the pre-master secret from the encrypted one. The
2661 * ssl key logfile stores only the first 8 bytes, so truncate it */
2662 encrypted_pre_master.data_len = 8;
2663 if (ssl_restore_master_key(ssl_session, "Encrypted pre-master secret",
2664 TRUE, mk_map->pre_master, &encrypted_pre_master))
2671 ssl_generate_keyring_material(SslDecryptSession*ssl_session)
2673 StringInfo key_block;
2674 guint8 _iv_c[MAX_BLOCK_SIZE],_iv_s[MAX_BLOCK_SIZE];
2675 guint8 _key_c[MAX_KEY_SIZE],_key_s[MAX_KEY_SIZE];
2677 guint8 *ptr,*c_wk,*s_wk,*c_mk,*s_mk,*c_iv = _iv_c,*s_iv = _iv_s;
2679 /* check for enough info to proced */
2680 guint need_all = SSL_CIPHER|SSL_CLIENT_RANDOM|SSL_SERVER_RANDOM|SSL_VERSION;
2681 guint need_any = SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET;
2682 if (((ssl_session->state & need_all) != need_all) || ((ssl_session->state & need_any) == 0)) {
2683 ssl_debug_printf("ssl_generate_keyring_material not enough data to generate key "
2684 "(0x%02X required 0x%02X or 0x%02X)\n", ssl_session->state,
2685 need_all|SSL_MASTER_SECRET, need_all|SSL_PRE_MASTER_SECRET);
2689 /* if master key is not available, generate is from the pre-master secret */
2690 if (!(ssl_session->state & SSL_MASTER_SECRET)) {
2691 if ((ssl_session->state & SSL_EXTENDED_MASTER_SECRET_MASK) == SSL_EXTENDED_MASTER_SECRET_MASK) {
2692 StringInfo handshake_hashed_data;
2695 handshake_hashed_data.data = NULL;
2696 handshake_hashed_data.data_len = 0;
2698 ssl_debug_printf("%s:PRF(pre_master_secret_extended)\n", G_STRFUNC);
2699 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
2700 DISSECTOR_ASSERT(ssl_session->handshake_data.data_len > 0);
2702 switch(ssl_session->version_netorder) {
2704 case TLSV1DOT1_VERSION:
2705 case DTLSV1DOT0_VERSION:
2706 case DTLSV1DOT0_VERSION_NOT:
2707 ret = tls_handshake_hash(ssl_session, &handshake_hashed_data);
2710 switch (ssl_session->cipher_suite.dig) {
2712 ret = tls12_handshake_hash(ssl_session, GCRY_MD_SHA384, &handshake_hashed_data);
2715 ret = tls12_handshake_hash(ssl_session, GCRY_MD_SHA256, &handshake_hashed_data);
2721 ssl_debug_printf("%s can't generate handshake hash\n", G_STRFUNC);
2725 wmem_free(wmem_file_scope(), ssl_session->handshake_data.data);
2726 ssl_session->handshake_data.data = NULL;
2727 ssl_session->handshake_data.data_len = 0;
2729 if (!prf(ssl_session, &ssl_session->pre_master_secret, "extended master secret",
2730 &handshake_hashed_data,
2731 NULL, &ssl_session->master_secret,
2732 SSL_MASTER_SECRET_LENGTH)) {
2733 ssl_debug_printf("%s can't generate master_secret\n", G_STRFUNC);
2734 g_free(handshake_hashed_data.data);
2737 g_free(handshake_hashed_data.data);
2739 ssl_debug_printf("%s:PRF(pre_master_secret)\n", G_STRFUNC);
2740 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
2741 ssl_print_string("client random",&ssl_session->client_random);
2742 ssl_print_string("server random",&ssl_session->server_random);
2743 if (!prf(ssl_session, &ssl_session->pre_master_secret, "master secret",
2744 &ssl_session->client_random,
2745 &ssl_session->server_random, &ssl_session->master_secret,
2746 SSL_MASTER_SECRET_LENGTH)) {
2747 ssl_debug_printf("%s can't generate master_secret\n", G_STRFUNC);
2751 ssl_print_string("master secret",&ssl_session->master_secret);
2753 /* the pre-master secret has been 'consumend' so we must clear it now */
2754 ssl_session->state &= ~SSL_PRE_MASTER_SECRET;
2755 ssl_session->state |= SSL_MASTER_SECRET;
2758 /* Compute the key block. First figure out how much data we need*/
2759 needed=ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len*2;
2760 needed+=ssl_session->cipher_suite.bits / 4;
2761 if(ssl_session->cipher_suite.block>1)
2762 needed+=ssl_session->cipher_suite.block*2;
2764 key_block.data = (guchar *)g_malloc(needed);
2765 ssl_debug_printf("%s sess key generation\n", G_STRFUNC);
2766 if (!prf(ssl_session, &ssl_session->master_secret, "key expansion",
2767 &ssl_session->server_random,&ssl_session->client_random,
2768 &key_block, needed)) {
2769 ssl_debug_printf("%s can't generate key_block\n", G_STRFUNC);
2772 ssl_print_string("key expansion", &key_block);
2775 /* AEAD ciphers do not have a separate MAC */
2776 if (ssl_session->cipher_suite.mode == MODE_GCM ||
2777 ssl_session->cipher_suite.mode == MODE_CCM ||
2778 ssl_session->cipher_suite.mode == MODE_CCM_8) {
2781 c_mk=ptr; ptr+=ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len;
2782 s_mk=ptr; ptr+=ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len;
2785 c_wk=ptr; ptr+=ssl_session->cipher_suite.eff_bits/8;
2786 s_wk=ptr; ptr+=ssl_session->cipher_suite.eff_bits/8;
2788 if(ssl_session->cipher_suite.block>1){
2789 c_iv=ptr; ptr+=ssl_session->cipher_suite.block;
2790 s_iv=ptr; /*ptr+=ssl_session->cipher_suite.block;*/
2793 /* export ciphers work with a smaller key length */
2794 if (ssl_session->cipher_suite.eff_bits < ssl_session->cipher_suite.bits) {
2795 if(ssl_session->cipher_suite.block>1){
2797 /* We only have room for MAX_BLOCK_SIZE bytes IVs, but that's
2798 all we should need. This is a sanity check */
2799 if(ssl_session->cipher_suite.block>MAX_BLOCK_SIZE) {
2800 ssl_debug_printf("%s cipher suite block must be at most %d nut is %d\n",
2801 G_STRFUNC, MAX_BLOCK_SIZE, ssl_session->cipher_suite.block);
2805 if(ssl_session->version_netorder==SSLV3_VERSION){
2806 /* The length of these fields are ignored by this caller */
2807 StringInfo iv_c, iv_s;
2811 ssl_debug_printf("%s ssl3_generate_export_iv\n", G_STRFUNC);
2812 ssl3_generate_export_iv(&ssl_session->client_random,
2813 &ssl_session->server_random, &iv_c,
2814 ssl_session->cipher_suite.block);
2815 ssl_debug_printf("%s ssl3_generate_export_iv(2)\n", G_STRFUNC);
2816 ssl3_generate_export_iv(&ssl_session->server_random,
2817 &ssl_session->client_random, &iv_s,
2818 ssl_session->cipher_suite.block);
2821 guint8 _iv_block[MAX_BLOCK_SIZE * 2];
2822 StringInfo iv_block;
2823 StringInfo key_null;
2826 key_null.data = &_key_null;
2827 key_null.data_len = 0;
2829 iv_block.data = _iv_block;
2831 ssl_debug_printf("%s prf(iv_block)\n", G_STRFUNC);
2832 if (!prf(ssl_session, &key_null, "IV block",
2833 &ssl_session->client_random,
2834 &ssl_session->server_random, &iv_block,
2835 ssl_session->cipher_suite.block * 2)) {
2836 ssl_debug_printf("%s can't generate tls31 iv block\n", G_STRFUNC);
2840 memcpy(_iv_c,iv_block.data,ssl_session->cipher_suite.block);
2841 memcpy(_iv_s,iv_block.data+ssl_session->cipher_suite.block,
2842 ssl_session->cipher_suite.block);
2849 if (ssl_session->version_netorder==SSLV3_VERSION){
2852 ssl_debug_printf("%s MD5(client_random)\n", G_STRFUNC);
2855 ssl_md5_update(&md5,c_wk,ssl_session->cipher_suite.eff_bits/8);
2856 ssl_md5_update(&md5,ssl_session->client_random.data,
2857 ssl_session->client_random.data_len);
2858 ssl_md5_update(&md5,ssl_session->server_random.data,
2859 ssl_session->server_random.data_len);
2860 ssl_md5_final(_key_c,&md5);
2861 ssl_md5_cleanup(&md5);
2865 ssl_debug_printf("%s MD5(server_random)\n", G_STRFUNC);
2866 ssl_md5_update(&md5,s_wk,ssl_session->cipher_suite.eff_bits/8);
2867 ssl_md5_update(&md5,ssl_session->server_random.data,
2868 ssl_session->server_random.data_len);
2869 ssl_md5_update(&md5,ssl_session->client_random.data,
2870 ssl_session->client_random.data_len);
2871 ssl_md5_final(_key_s,&md5);
2872 ssl_md5_cleanup(&md5);
2876 StringInfo key_c, key_s, k;
2877 key_c.data = _key_c;
2878 key_s.data = _key_s;
2881 k.data_len = ssl_session->cipher_suite.eff_bits/8;
2882 ssl_debug_printf("%s PRF(key_c)\n", G_STRFUNC);
2883 if (!prf(ssl_session, &k, "client write key",
2884 &ssl_session->client_random,
2885 &ssl_session->server_random, &key_c, sizeof(_key_c))) {
2886 ssl_debug_printf("%s can't generate tll31 server key \n", G_STRFUNC);
2892 k.data_len = ssl_session->cipher_suite.eff_bits/8;
2893 ssl_debug_printf("%s PRF(key_s)\n", G_STRFUNC);
2894 if (!prf(ssl_session, &k, "server write key",
2895 &ssl_session->client_random,
2896 &ssl_session->server_random, &key_s, sizeof(_key_s))) {
2897 ssl_debug_printf("%s can't generate tll31 client key \n", G_STRFUNC);
2904 /* show key material info */
2906 ssl_print_data("Client MAC key",c_mk,ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len);
2907 ssl_print_data("Server MAC key",s_mk,ssl_cipher_suite_dig(&ssl_session->cipher_suite)->len);
2909 ssl_print_data("Client Write key",c_wk,ssl_session->cipher_suite.bits/8);
2910 ssl_print_data("Server Write key",s_wk,ssl_session->cipher_suite.bits/8);
2912 if(ssl_session->cipher_suite.block>1) {
2913 ssl_print_data("Client Write IV",c_iv,ssl_session->cipher_suite.block);
2914 ssl_print_data("Server Write IV",s_iv,ssl_session->cipher_suite.block);
2917 ssl_print_data("Client Write IV",c_iv,8);
2918 ssl_print_data("Server Write IV",s_iv,8);
2921 /* create both client and server ciphers*/
2922 ssl_debug_printf("%s ssl_create_decoder(client)\n", G_STRFUNC);
2923 ssl_session->client_new = ssl_create_decoder(&ssl_session->cipher_suite, ssl_session->session.compression, c_mk, c_wk, c_iv);
2924 if (!ssl_session->client_new) {
2925 ssl_debug_printf("%s can't init client decoder\n", G_STRFUNC);
2928 ssl_debug_printf("%s ssl_create_decoder(server)\n", G_STRFUNC);
2929 ssl_session->server_new = ssl_create_decoder(&ssl_session->cipher_suite, ssl_session->session.compression, s_mk, s_wk, s_iv);
2930 if (!ssl_session->server_new) {
2931 ssl_debug_printf("%s can't init client decoder\n", G_STRFUNC);
2935 ssl_debug_printf("%s: client seq %d, server seq %d\n",
2936 G_STRFUNC, ssl_session->client_new->seq, ssl_session->server_new->seq);
2937 g_free(key_block.data);
2938 ssl_session->state |= SSL_HAVE_SESSION_KEY;
2942 g_free(key_block.data);
2947 ssl_change_cipher(SslDecryptSession *ssl_session, gboolean server)
2949 ssl_debug_printf("ssl_change_cipher %s\n", (server)?"SERVER":"CLIENT");
2951 ssl_session->server = ssl_session->server_new;
2952 ssl_session->server_new = NULL;
2954 ssl_session->client = ssl_session->client_new;
2955 ssl_session->client_new = NULL;
2960 ssl_decrypt_pre_master_secret(SslDecryptSession*ssl_session,
2961 StringInfo* encrypted_pre_master, SSL_PRIVATE_KEY *pk)
2965 if (!encrypted_pre_master)
2968 if(ssl_session->cipher_suite.kex == KEX_DH) {
2969 ssl_debug_printf("%s: session uses DH (%d) key exchange, which is "
2970 "impossible to decrypt\n", G_STRFUNC, KEX_DH);
2972 } else if(ssl_session->cipher_suite.kex != KEX_RSA) {
2973 ssl_debug_printf("%s key exchange %d different from KEX_RSA (%d)\n",
2974 G_STRFUNC, ssl_session->cipher_suite.kex, KEX_RSA);
2978 /* with tls key loading will fail if not rsa type, so no need to check*/
2979 ssl_print_string("pre master encrypted",encrypted_pre_master);
2980 ssl_debug_printf("%s: RSA_private_decrypt\n", G_STRFUNC);
2981 i=ssl_private_decrypt(encrypted_pre_master->data_len,
2982 encrypted_pre_master->data, pk);
2985 ssl_debug_printf("%s wrong pre_master_secret length (%d, expected "
2986 "%d)\n", G_STRFUNC, i, 48);
2990 /* the decrypted data has been written into the pre_master key buffer */
2991 ssl_session->pre_master_secret.data = encrypted_pre_master->data;
2992 ssl_session->pre_master_secret.data_len=48;
2993 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
2995 /* Remove the master secret if it was there.
2996 This forces keying material regeneration in
2997 case we're renegotiating */
2998 ssl_session->state &= ~(SSL_MASTER_SECRET|SSL_HAVE_SESSION_KEY);
2999 ssl_session->state |= SSL_PRE_MASTER_SECRET;
3003 /* convert network byte order 32 byte number to right-aligned host byte order *
3005 static gint fmt_seq(guint32 num, guint8* buf)
3010 netnum=g_htonl(num);
3011 memcpy(buf+4,&netnum,4);
3017 tls_check_mac(SslDecoder*decoder, gint ct, gint ver, guint8* data,
3018 guint32 datalen, guint8* mac)
3023 guint8 buf[DIGEST_MAX_SIZE];
3026 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
3027 ssl_debug_printf("tls_check_mac mac type:%s md %d\n",
3028 ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
3030 if (ssl_hmac_init(&hm,decoder->mac_key.data,decoder->mac_key.data_len,md) != 0)
3033 /* hash sequence number */
3034 fmt_seq(decoder->seq,buf);
3038 ssl_hmac_update(&hm,buf,8);
3040 /* hash content type */
3042 ssl_hmac_update(&hm,buf,1);
3044 /* hash version,data length and data*/
3045 /* *((gint16*)buf) = g_htons(ver); */
3046 temp = g_htons(ver);
3047 memcpy(buf, &temp, 2);
3048 ssl_hmac_update(&hm,buf,2);
3050 /* *((gint16*)buf) = g_htons(datalen); */
3051 temp = g_htons(datalen);
3052 memcpy(buf, &temp, 2);
3053 ssl_hmac_update(&hm,buf,2);
3054 ssl_hmac_update(&hm,data,datalen);
3056 /* get digest and digest len*/
3058 ssl_hmac_final(&hm,buf,&len);
3059 ssl_hmac_cleanup(&hm);
3060 ssl_print_data("Mac", buf, len);
3061 if(memcmp(mac,buf,len))
3068 ssl3_check_mac(SslDecoder*decoder,int ct,guint8* data,
3069 guint32 datalen, guint8* mac)
3074 guint8 buf[64],dgst[20];
3078 pad_ct=(decoder->cipher_suite->dig==DIG_SHA)?40:48;
3080 /* get cipher used for digest comptuation */
3081 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
3082 if (ssl_md_init(&mc,md) !=0)
3085 /* do hash computation on data && padding */
3086 ssl_md_update(&mc,decoder->mac_key.data,decoder->mac_key.data_len);
3089 memset(buf,0x36,pad_ct);
3090 ssl_md_update(&mc,buf,pad_ct);
3092 /* hash sequence number */
3093 fmt_seq(decoder->seq,buf);
3095 ssl_md_update(&mc,buf,8);
3097 /* hash content type */
3099 ssl_md_update(&mc,buf,1);
3101 /* hash data length in network byte order and data*/
3102 /* *((gint16* )buf) = g_htons(datalen); */
3103 temp = g_htons(datalen);
3104 memcpy(buf, &temp, 2);
3105 ssl_md_update(&mc,buf,2);
3106 ssl_md_update(&mc,data,datalen);
3108 /* get partial digest */
3109 ssl_md_final(&mc,dgst,&len);
3110 ssl_md_cleanup(&mc);
3112 ssl_md_init(&mc,md);
3115 ssl_md_update(&mc,decoder->mac_key.data,decoder->mac_key.data_len);
3117 /* hash padding and partial digest*/
3118 memset(buf,0x5c,pad_ct);
3119 ssl_md_update(&mc,buf,pad_ct);
3120 ssl_md_update(&mc,dgst,len);
3122 ssl_md_final(&mc,dgst,&len);
3123 ssl_md_cleanup(&mc);
3125 if(memcmp(mac,dgst,len))
3132 dtls_check_mac(SslDecoder*decoder, gint ct,int ver, guint8* data,
3133 guint32 datalen, guint8* mac)
3138 guint8 buf[DIGEST_MAX_SIZE];
3141 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
3142 ssl_debug_printf("dtls_check_mac mac type:%s md %d\n",
3143 ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
3145 if (ssl_hmac_init(&hm,decoder->mac_key.data,decoder->mac_key.data_len,md) != 0)
3147 ssl_debug_printf("dtls_check_mac seq: %d epoch: %d\n",decoder->seq,decoder->epoch);
3148 /* hash sequence number */
3149 fmt_seq(decoder->seq,buf);
3150 buf[0]=decoder->epoch>>8;
3151 buf[1]=(guint8)decoder->epoch;
3153 ssl_hmac_update(&hm,buf,8);
3155 /* hash content type */
3157 ssl_hmac_update(&hm,buf,1);
3159 /* hash version,data length and data */
3160 temp = g_htons(ver);
3161 memcpy(buf, &temp, 2);
3162 ssl_hmac_update(&hm,buf,2);
3164 temp = g_htons(datalen);
3165 memcpy(buf, &temp, 2);
3166 ssl_hmac_update(&hm,buf,2);
3167 ssl_hmac_update(&hm,data,datalen);
3168 /* get digest and digest len */
3170 ssl_hmac_final(&hm,buf,&len);
3171 ssl_hmac_cleanup(&hm);
3172 ssl_print_data("Mac", buf, len);
3173 if(memcmp(mac,buf,len))
3181 ssl_decompress_record(SslDecompress* decomp, const guchar* in, guint inl, StringInfo* out_str, guint* outl)
3185 switch (decomp->compression) {
3186 case 1: /* DEFLATE */
3188 if (out_str->data_len < 16384) { /* maximal plain length */
3189 ssl_data_realloc(out_str, 16384);
3191 decomp->istream.next_in = (guchar*)in;
3192 decomp->istream.avail_in = inl;
3193 decomp->istream.next_out = out_str->data;
3194 decomp->istream.avail_out = out_str->data_len;
3196 err = inflate(&decomp->istream, Z_SYNC_FLUSH);
3198 ssl_debug_printf("ssl_decompress_record: inflate() failed - %d\n", err);
3201 *outl = out_str->data_len - decomp->istream.avail_out;
3204 ssl_debug_printf("ssl_decompress_record: unsupported compression method %d\n", decomp->compression);
3211 ssl_decompress_record(SslDecompress* decomp _U_, const guchar* in _U_, guint inl _U_, StringInfo* out_str _U_, guint* outl _U_)
3213 ssl_debug_printf("ssl_decompress_record: unsupported compression method %d\n", decomp->compression);
3219 ssl_decrypt_record(SslDecryptSession*ssl,SslDecoder* decoder, gint ct,
3220 const guchar* in, guint inl, StringInfo* comp_str, StringInfo* out_str, guint* outl)
3222 guint pad, worklen, uncomplen;
3225 ssl_debug_printf("ssl_decrypt_record ciphertext len %d\n", inl);
3226 ssl_print_data("Ciphertext",in, inl);
3228 /* ensure we have enough storage space for decrypted data */
3229 if (inl > out_str->data_len)
3231 ssl_debug_printf("ssl_decrypt_record: allocating %d bytes for decrypt data (old len %d)\n",
3232 inl + 32, out_str->data_len);
3233 ssl_data_realloc(out_str, inl + 32);
3236 /* RFC 6101/2246: SSLCipherText/TLSCipherText has two structures for types:
3237 * (notation: { unencrypted, [ encrypted ] })
3238 * GenericStreamCipher: { [content, mac] }
3239 * GenericBlockCipher: { IV (TLS 1.1+), [content, mac, padding, padding_len] }
3240 * RFC 5426 (TLS 1.2): TLSCipherText has additionally:
3241 * GenericAEADCipher: { nonce_explicit, [content] }
3242 * RFC 4347 (DTLS): based on TLS 1.1, only GenericBlockCipher is supported.
3243 * RFC 6347 (DTLS 1.2): based on TLS 1.2, includes GenericAEADCipher too.
3246 /* (TLS 1.1 and later, DTLS) Extract explicit IV for GenericBlockCipher */
3247 if (decoder->cipher_suite->mode == MODE_CBC) {
3248 switch (ssl->version_netorder) {
3249 case TLSV1DOT1_VERSION:
3250 case TLSV1DOT2_VERSION:
3251 case DTLSV1DOT0_VERSION:
3252 case DTLSV1DOT2_VERSION:
3253 case DTLSV1DOT0_VERSION_NOT:
3254 if ((gint)inl < decoder->cipher_suite->block) {
3255 ssl_debug_printf("ssl_decrypt_record failed: input %d has no space for IV %d\n",
3256 inl, decoder->cipher_suite->block);
3259 pad = gcry_cipher_setiv(decoder->evp, in, decoder->cipher_suite->block);
3261 ssl_debug_printf("ssl_decrypt_record failed: failed to set IV: %s %s\n",
3262 gcry_strsource (pad), gcry_strerror (pad));
3265 inl -= decoder->cipher_suite->block;
3266 in += decoder->cipher_suite->block;
3271 /* Nonce for GenericAEADCipher */
3272 if (decoder->cipher_suite->mode == MODE_GCM ||
3273 decoder->cipher_suite->mode == MODE_CCM ||
3274 decoder->cipher_suite->mode == MODE_CCM_8) {
3275 /* 4 bytes write_iv, 8 bytes explicit_nonce, 4 bytes counter */
3276 guchar gcm_nonce[16] = { 0 };
3278 if ((gint)inl < SSL_EX_NONCE_LEN_GCM) {
3279 ssl_debug_printf("ssl_decrypt_record failed: input %d has no space for nonce %d\n",
3280 inl, SSL_EX_NONCE_LEN_GCM);
3284 if (decoder->cipher_suite->mode == MODE_GCM) {
3285 memcpy(gcm_nonce, decoder->write_iv.data, decoder->write_iv.data_len); /* salt */
3286 memcpy(gcm_nonce + decoder->write_iv.data_len, in, SSL_EX_NONCE_LEN_GCM);
3287 /* NIST SP 800-38D, sect. 7.2 says that the 32-bit counter part starts
3288 * at 1, and gets incremented before passing to the block cipher. */
3289 gcm_nonce[4 + SSL_EX_NONCE_LEN_GCM + 3] = 2;
3290 } else { /* MODE_CCM and MODE_CCM_8 */
3291 /* The nonce for CCM and GCM are the same, but the nonce is used as input
3292 * in the CCM algorithm described in RFC 3610. The nonce generated here is
3293 * the one from RFC 3610 sect 2.3. Encryption. */
3294 /* Flags: (L-1) ; L = 16 - 1 - nonceSize */
3295 gcm_nonce[0] = 3 - 1;
3297 memcpy(gcm_nonce + 1, decoder->write_iv.data, decoder->write_iv.data_len); /* salt */
3298 memcpy(gcm_nonce + 1 + decoder->write_iv.data_len, in, SSL_EX_NONCE_LEN_GCM);
3299 gcm_nonce[4 + SSL_EX_NONCE_LEN_GCM + 3] = 1;
3302 pad = gcry_cipher_setctr (decoder->evp, gcm_nonce, sizeof (gcm_nonce));
3304 ssl_debug_printf("ssl_decrypt_record failed: failed to set CTR: %s %s\n",
3305 gcry_strsource (pad), gcry_strerror (pad));
3308 inl -= SSL_EX_NONCE_LEN_GCM;
3309 in += SSL_EX_NONCE_LEN_GCM;
3313 if ((pad = ssl_cipher_decrypt(&decoder->evp, out_str->data, out_str->data_len, in, inl))!= 0) {
3314 ssl_debug_printf("ssl_decrypt_record failed: ssl_cipher_decrypt: %s %s\n", gcry_strsource (pad),
3315 gcry_strerror (pad));
3319 ssl_print_data("Plaintext", out_str->data, inl);
3322 /* RFC 5116 sect 5.1/5.3: AES128/256 GCM/CCM uses 16 bytes for auth tag
3323 * RFC 6655 sect 6.1: AEAD_AES_128_CCM uses 16 bytes for auth tag */
3324 if (decoder->cipher_suite->mode == MODE_GCM ||
3325 decoder->cipher_suite->mode == MODE_CCM) {
3327 ssl_debug_printf("ssl_decrypt_record failed: missing tag, work %d\n", worklen);
3330 /* XXX - validate auth tag */
3333 /* RFC 6655 sect 6.1: AEAD_AES_128_CCM_8 uses 8 bytes for auth tag */
3334 if (decoder->cipher_suite->mode == MODE_CCM_8) {
3336 ssl_debug_printf("ssl_decrypt_record failed: missing tag, work %d\n", worklen);
3339 /* XXX - validate auth tag */
3343 /* strip padding for GenericBlockCipher */
3344 if (decoder->cipher_suite->mode == MODE_CBC) {
3345 if (inl < 1) { /* Should this check happen earlier? */
3346 ssl_debug_printf("ssl_decrypt_record failed: input length %d too small\n", inl);
3349 pad=out_str->data[inl-1];
3350 if (worklen <= pad) {
3351 ssl_debug_printf("ssl_decrypt_record failed: padding %d too large for work %d\n",
3356 ssl_debug_printf("ssl_decrypt_record found padding %d final len %d\n",
3360 /* MAC for GenericStreamCipher and GenericBlockCipher */
3361 if (decoder->cipher_suite->mode == MODE_STREAM ||
3362 decoder->cipher_suite->mode == MODE_CBC) {
3363 if (ssl_cipher_suite_dig(decoder->cipher_suite)->len > (gint)worklen) {
3364 ssl_debug_printf("ssl_decrypt_record wrong record len/padding outlen %d\n work %d\n",*outl, worklen);
3367 worklen-=ssl_cipher_suite_dig(decoder->cipher_suite)->len;
3368 mac = out_str->data + worklen;
3369 } else /* if (decoder->cipher_suite->mode == MODE_GCM) */ {
3370 /* GenericAEADCipher has no MAC */
3374 /* Now check the MAC */
3375 ssl_debug_printf("checking mac (len %d, version %X, ct %d seq %d)\n",
3376 worklen, ssl->version_netorder, ct, decoder->seq);
3377 if(ssl->version_netorder==SSLV3_VERSION){
3378 if(ssl3_check_mac(decoder,ct,out_str->data,worklen,mac) < 0) {
3379 if(ssl_ignore_mac_failed) {
3380 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
3383 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
3388 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
3391 else if(ssl->version_netorder==TLSV1_VERSION || ssl->version_netorder==TLSV1DOT1_VERSION || ssl->version_netorder==TLSV1DOT2_VERSION){
3392 if(tls_check_mac(decoder,ct,ssl->version_netorder,out_str->data,worklen,mac)< 0) {
3393 if(ssl_ignore_mac_failed) {
3394 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
3397 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
3402 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
3405 else if(ssl->version_netorder==DTLSV1DOT0_VERSION ||
3406 ssl->version_netorder==DTLSV1DOT2_VERSION ||
3407 ssl->version_netorder==DTLSV1DOT0_VERSION_NOT){
3408 /* Try rfc-compliant mac first, and if failed, try old openssl's non-rfc-compliant mac */
3409 if(dtls_check_mac(decoder,ct,ssl->version_netorder,out_str->data,worklen,mac)>= 0) {
3410 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
3412 else if(tls_check_mac(decoder,ct,TLSV1_VERSION,out_str->data,worklen,mac)>= 0) {
3413 ssl_debug_printf("ssl_decrypt_record: dtls rfc-compliant mac failed, but old openssl's non-rfc-compliant mac ok\n");
3415 else if(ssl_ignore_mac_failed) {
3416 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
3419 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
3427 if (decoder->compression > 0) {
3428 ssl_debug_printf("ssl_decrypt_record: compression method %d\n", decoder->compression);
3429 ssl_data_copy(comp_str, out_str);
3430 ssl_print_data("Plaintext compressed", comp_str->data, worklen);
3431 if (!decoder->decomp) {
3432 ssl_debug_printf("decrypt_ssl3_record: no decoder available\n");
3435 if (ssl_decompress_record(decoder->decomp, comp_str->data, worklen, out_str, &uncomplen) < 0) return -1;
3436 ssl_print_data("Plaintext uncompressed", out_str->data, uncomplen);
3444 static SSL_PRIVATE_KEY*
3445 ssl_privkey_to_sexp(struct gnutls_x509_privkey_int* priv_key)
3447 gnutls_datum_t rsa_datum[RSA_PARS]; /* m, e, d, p, q, u */
3450 gcry_sexp_t rsa_priv_key = NULL;
3454 unsigned char buf_keyid[32];
3457 gcry_mpi_t* rsa_params = g_malloc(sizeof(gcry_mpi_t)*RSA_PARS);
3459 gcry_mpi_t rsa_params[RSA_PARS];
3462 buf_len = sizeof(buf_keyid);
3463 ret = gnutls_x509_privkey_get_key_id(priv_key, 0, buf_keyid, &buf_len);
3465 ssl_debug_printf( "gnutls_x509_privkey_get_key_id(ssl_pkey, 0, buf_keyid, &buf_len) - %s\n", gnutls_strerror(ret));
3467 char* keyid = (char*)bytestring_to_str(NULL, buf_keyid, (int) buf_len, ':');
3468 ssl_debug_printf( "Private key imported: KeyID %s\n", keyid);
3469 wmem_free(NULL, keyid);
3472 /* RSA get parameter */
3473 if (gnutls_x509_privkey_export_rsa_raw(priv_key,
3479 &rsa_datum[5]) != 0) {
3480 ssl_debug_printf("ssl_load_key: can't export rsa param (is a rsa private key file ?!?)\n");
3487 /* convert each rsa parameter to mpi format*/
3488 for(i=0; i<RSA_PARS; i++) {
3489 gret = gcry_mpi_scan(&rsa_params[i], GCRYMPI_FMT_USG, rsa_datum[i].data, rsa_datum[i].size,&tmp_size);
3490 /* these buffers were allocated by gnutls_x509_privkey_export_rsa_raw() */
3491 g_free(rsa_datum[i].data);
3493 ssl_debug_printf("ssl_load_key: can't convert m rsa param to int (size %d)\n", rsa_datum[i].size);
3501 /* libgcrypt expects p < q, and gnutls might not return it as such, depending on gnutls version and its crypto backend */
3502 if (gcry_mpi_cmp(rsa_params[3], rsa_params[4]) > 0)
3504 ssl_debug_printf("ssl_load_key: swapping p and q parameters and recomputing u\n");
3505 gcry_mpi_swap(rsa_params[3], rsa_params[4]);
3506 gcry_mpi_invm(rsa_params[5], rsa_params[3], rsa_params[4]);
3509 if (gcry_sexp_build( &rsa_priv_key, NULL,
3510 "(private-key(rsa((n%m)(e%m)(d%m)(p%m)(q%m)(u%m))))", rsa_params[0],
3511 rsa_params[1], rsa_params[2], rsa_params[3], rsa_params[4],
3512 rsa_params[5]) != 0) {
3513 ssl_debug_printf("ssl_load_key: can't build rsa private key s-exp\n");
3523 for (i=0; i< 6; i++)
3524 gcry_mpi_release(rsa_params[i]);
3525 return rsa_priv_key;
3531 ssl_load_key(FILE* fp)
3533 /* gnutls makes our work much harder, since we have to work internally with
3534 * s-exp formatted data, but PEM loader exports only in "gnutls_datum_t"
3535 * format, and a datum -> s-exp convertion function does not exist.
3537 gnutls_x509_privkey_t priv_key;
3543 Ssl_private_key_t *private_key = (Ssl_private_key_t *)g_malloc0(sizeof(Ssl_private_key_t));
3545 /* init private key data*/
3546 gnutls_x509_privkey_init(&priv_key);
3548 if (ws_fstat64(fileno(fp), &statbuf) == -1) {
3549 ssl_debug_printf("ssl_load_key: can't ws_fstat64 file\n");
3550 g_free(private_key);
3553 if (S_ISDIR(statbuf.st_mode)) {
3554 ssl_debug_printf("ssl_load_key: file is a directory\n");
3555 g_free(private_key);
3559 if (S_ISFIFO(statbuf.st_mode)) {
3560 ssl_debug_printf("ssl_load_key: file is a named pipe\n");
3561 g_free(private_key);
3565 if (!S_ISREG(statbuf.st_mode)) {
3566 ssl_debug_printf("ssl_load_key: file is not a regular file\n");
3567 g_free(private_key);
3571 /* XXX - check for a too-big size */
3572 /* load all file contents into a datum buffer*/
3573 key.data = (unsigned char *)g_malloc((size_t)statbuf.st_size);
3574 key.size = (int)statbuf.st_size;
3575 bytes = (guint) fread(key.data, 1, key.size, fp);
3576 if (bytes < key.size) {
3577 ssl_debug_printf("ssl_load_key: can't read from file %d bytes, got %d\n",
3579 g_free(private_key);
3584 /* import PEM data*/
3585 if ((ret = gnutls_x509_privkey_import(priv_key, &key, GNUTLS_X509_FMT_PEM)) != GNUTLS_E_SUCCESS) {
3586 ssl_debug_printf("ssl_load_key: can't import pem data: %s\n", gnutls_strerror(ret));
3587 g_free(private_key);
3592 if (gnutls_x509_privkey_get_pk_algorithm(priv_key) != GNUTLS_PK_RSA) {
3593 ssl_debug_printf("ssl_load_key: private key public key algorithm isn't RSA\n");
3594 g_free(private_key);
3601 private_key->x509_pkey = priv_key;
3602 private_key->sexp_pkey = ssl_privkey_to_sexp(priv_key);
3603 if ( !private_key->sexp_pkey ) {
3604 g_free(private_key);
3611 BAGTYPE(gnutls_pkcs12_bag_type_t x) {
3613 case GNUTLS_BAG_EMPTY: return "Empty";
3614 case GNUTLS_BAG_PKCS8_ENCRYPTED_KEY: return "PKCS#8 Encrypted key";
3615 case GNUTLS_BAG_PKCS8_KEY: return "PKCS#8 Key";
3616 case GNUTLS_BAG_CERTIFICATE: return "Certificate";
3617 case GNUTLS_BAG_CRL: return "CRL";
3618 case GNUTLS_BAG_ENCRYPTED: return "Encrypted";
3619 case GNUTLS_BAG_UNKNOWN: return "Unknown";
3620 default: return "<undefined>";
3625 * Load a RSA private key from a PKCS#12 file.
3626 * @param fp the file that contains the key data.
3627 * @param cert_passwd password to decrypt the PKCS#12 file.
3628 * @param[out] err error message upon failure; NULL upon success.
3629 * @return a pointer to the loaded key on success; NULL upon failure.
3631 static Ssl_private_key_t *
3632 ssl_load_pkcs12(FILE* fp, const gchar *cert_passwd, char** err) {
3637 gnutls_datum_t data;
3638 gnutls_pkcs12_bag_t bag = NULL;
3639 gnutls_pkcs12_bag_type_t bag_type;
3640 size_t len, buf_len;
3641 static char buf_name[256];
3642 static char buf_email[128];
3643 unsigned char buf_keyid[32];
3646 gnutls_pkcs12_t ssl_p12 = NULL;
3647 gnutls_x509_crt_t ssl_cert = NULL;
3648 gnutls_x509_privkey_t ssl_pkey = NULL;
3650 Ssl_private_key_t *private_key = (Ssl_private_key_t *)g_malloc0(sizeof(Ssl_private_key_t));
3654 data.data = (unsigned char *)g_malloc(rest);
3657 while ((len = fread(p, 1, rest, fp)) > 0) {
3662 data.data = (unsigned char *)g_realloc(data.data, data.size + rest);
3663 p = data.data + data.size;
3668 ssl_debug_printf("%d bytes read\n", data.size);
3670 *err = g_strdup("Error during certificate reading.");
3671 ssl_debug_printf("%s\n", *err);
3672 g_free(private_key);
3677 ret = gnutls_pkcs12_init(&ssl_p12);
3679 *err = g_strdup_printf("gnutls_pkcs12_init(&st_p12) - %s", gnutls_strerror(ret));
3680 ssl_debug_printf("%s\n", *err);
3681 g_free(private_key);
3686 /* load PKCS#12 in DER or PEM format */
3687 ret = gnutls_pkcs12_import(ssl_p12, &data, GNUTLS_X509_FMT_DER, 0);
3689 *err = g_strdup_printf("could not load PKCS#12 in DER format: %s", gnutls_strerror(ret));
3690 ssl_debug_printf("%s\n", *err);
3693 ret = gnutls_pkcs12_import(ssl_p12, &data, GNUTLS_X509_FMT_PEM, 0);
3695 *err = g_strdup_printf("could not load PKCS#12 in PEM format: %s", gnutls_strerror(ret));
3696 ssl_debug_printf("%s\n", *err);
3703 g_free(private_key);
3707 ssl_debug_printf( "PKCS#12 imported\n");
3709 for (i=0; ret==0; i++) {
3711 if (bag) { gnutls_pkcs12_bag_deinit(bag); bag = NULL; }
3713 ret = gnutls_pkcs12_bag_init(&bag);
3714 if (ret < 0) continue;
3716 ret = gnutls_pkcs12_get_bag(ssl_p12, i, bag);
3717 if (ret < 0) continue;
3719 for (j=0; ret==0 && j<gnutls_pkcs12_bag_get_count(bag); j++) {
3721 bag_type = gnutls_pkcs12_bag_get_type(bag, j);
3722 if (bag_type >= GNUTLS_BAG_UNKNOWN) continue;
3723 ssl_debug_printf( "Bag %d/%d: %s\n", i, j, BAGTYPE(bag_type));
3724 if (bag_type == GNUTLS_BAG_ENCRYPTED) {
3725 ret = gnutls_pkcs12_bag_decrypt(bag, cert_passwd);
3727 bag_type = gnutls_pkcs12_bag_get_type(bag, j);
3728 if (bag_type >= GNUTLS_BAG_UNKNOWN) continue;
3729 ssl_debug_printf( "Bag %d/%d decrypted: %s\n", i, j, BAGTYPE(bag_type));
3733 ret = gnutls_pkcs12_bag_get_data(bag, j, &data);
3734 if (ret < 0) continue;
3738 case GNUTLS_BAG_CERTIFICATE:
3740 ret = gnutls_x509_crt_init(&ssl_cert);
3742 *err = g_strdup_printf("gnutls_x509_crt_init(&ssl_cert) - %s", gnutls_strerror(ret));
3743 ssl_debug_printf("%s\n", *err);
3744 g_free(private_key);
3748 ret = gnutls_x509_crt_import(ssl_cert, &data, GNUTLS_X509_FMT_DER);
3750 *err = g_strdup_printf("gnutls_x509_crt_import(ssl_cert, &data, GNUTLS_X509_FMT_DER) - %s", gnutls_strerror(ret));
3751 ssl_debug_printf("%s\n", *err);
3752 g_free(private_key);
3756 buf_len = sizeof(buf_name);
3757 ret = gnutls_x509_crt_get_dn_by_oid(ssl_cert, GNUTLS_OID_X520_COMMON_NAME, 0, 0, buf_name, &buf_len);
3758 if (ret < 0) { g_strlcpy(buf_name, "<ERROR>", 256); }
3759 buf_len = sizeof(buf_email);
3760 ret = gnutls_x509_crt_get_dn_by_oid(ssl_cert, GNUTLS_OID_PKCS9_EMAIL, 0, 0, buf_email, &buf_len);
3761 if (ret < 0) { g_strlcpy(buf_email, "<ERROR>", 128); }
3763 buf_len = sizeof(buf_keyid);
3764 ret = gnutls_x509_crt_get_key_id(ssl_cert, 0, buf_keyid, &buf_len);
3765 if (ret < 0) { g_strlcpy(buf_keyid, "<ERROR>", 32); }
3767 private_key->x509_cert = ssl_cert;
3768 tmp_str = bytes_to_str(NULL, buf_keyid, (int) buf_len);
3769 ssl_debug_printf( "Certificate imported: %s <%s>, KeyID %s\n", buf_name, buf_email, tmp_str);
3770 wmem_free(NULL, tmp_str);
3773 case GNUTLS_BAG_PKCS8_KEY:
3774 case GNUTLS_BAG_PKCS8_ENCRYPTED_KEY:
3776 ret = gnutls_x509_privkey_init(&ssl_pkey);
3778 *err = g_strdup_printf("gnutls_x509_privkey_init(&ssl_pkey) - %s", gnutls_strerror(ret));
3779 ssl_debug_printf("%s\n", *err);
3780 g_free(private_key);
3783 ret = gnutls_x509_privkey_import_pkcs8(ssl_pkey, &data, GNUTLS_X509_FMT_DER, cert_passwd,
3784 (bag_type==GNUTLS_BAG_PKCS8_KEY) ? GNUTLS_PKCS_PLAIN : 0);
3786 *err = g_strdup_printf("Can not decrypt private key - %s", gnutls_strerror(ret));
3787 ssl_debug_printf("%s\n", *err);
3788 g_free(private_key);
3792 if (gnutls_x509_privkey_get_pk_algorithm(ssl_pkey) != GNUTLS_PK_RSA) {
3793 *err = g_strdup("ssl_load_pkcs12: private key public key algorithm isn't RSA");
3794 ssl_debug_printf("%s\n", *err);
3795 g_free(private_key);
3799 private_key->x509_pkey = ssl_pkey;
3800 private_key->sexp_pkey = ssl_privkey_to_sexp(ssl_pkey);
3801 if ( !private_key->sexp_pkey ) {
3802 *err = g_strdup("ssl_load_pkcs12: could not create sexp_pkey");
3803 ssl_debug_printf("%s\n", *err);
3804 g_free(private_key);
3818 void ssl_free_key(Ssl_private_key_t* key)
3822 for (i=0; i< 6; i++)
3823 gcry_mpi_release(key->sexp_pkey[i]);
3825 gcry_sexp_release(key->sexp_pkey);
3828 if (!key->x509_cert)
3829 gnutls_x509_crt_deinit (key->x509_cert);
3831 if (!key->x509_pkey)
3832 gnutls_x509_privkey_deinit(key->x509_pkey);
3834 g_free((Ssl_private_key_t*)key);
3838 ssl_find_private_key(SslDecryptSession *ssl_session, GHashTable *key_hash, GTree* associations, packet_info *pinfo) {
3840 char ip_addr_any[] = {0,0,0,0};
3843 Ssl_private_key_t * private_key;
3849 /* we need to know which side of the conversation is speaking */
3850 if (ssl_packet_from_server(&ssl_session->session, associations, pinfo)) {
3851 dummy.addr = pinfo->src;
3852 dummy.port = port = pinfo->srcport;
3854 dummy.addr = pinfo->dst;
3855 dummy.port = port = pinfo->destport;
3857 addr_string = address_to_str(NULL, &dummy.addr);
3858 ssl_debug_printf("ssl_find_private_key server %s:%u\n",
3859 addr_string, dummy.port);
3860 wmem_free(NULL, addr_string);
3862 if (g_hash_table_size(key_hash) == 0) {
3863 ssl_debug_printf("ssl_find_private_key: no keys found\n");
3866 ssl_debug_printf("ssl_find_private_key: testing %i keys\n",
3867 g_hash_table_size(key_hash));
3870 /* try to retrieve private key for this service. Do it now 'cause pinfo
3871 * is not always available
3872 * Note that with HAVE_LIBGNUTLS undefined private_key is allways 0
3873 * and thus decryption never engaged*/
3876 ssl_session->private_key = 0;
3877 private_key = (Ssl_private_key_t *)g_hash_table_lookup(key_hash, &dummy);
3880 ssl_debug_printf("ssl_find_private_key can't find private key for this server! Try it again with universal port 0\n");
3883 private_key = (Ssl_private_key_t *)g_hash_table_lookup(key_hash, &dummy);
3887 ssl_debug_printf("ssl_find_private_key can't find private key for this server (universal port)! Try it again with universal address 0.0.0.0\n");
3889 dummy.addr.type = AT_IPv4;
3891 dummy.addr.data = ip_addr_any;
3894 private_key = (Ssl_private_key_t *)g_hash_table_lookup(key_hash, &dummy);
3898 ssl_debug_printf("ssl_find_private_key can't find private key for this server! Try it again with universal address 0.0.0.0 and universal port 0\n");
3901 private_key = (Ssl_private_key_t *)g_hash_table_lookup(key_hash, &dummy);
3905 ssl_debug_printf("ssl_find_private_key can't find any private key!\n");
3907 ssl_session->private_key = private_key->sexp_pkey;
3914 ssl_debug_printf("gnutls version: %s\n", gnutls_check_version(NULL));
3917 #else /* defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT) */
3918 /* no libgnutl: dummy operation to keep interface consistent*/
3925 ssl_load_key(FILE* fp)
3927 ssl_debug_printf("ssl_load_key: impossible without gnutls. fp %p\n",fp);
3932 ssl_load_pkcs12(FILE* fp, const gchar *cert_passwd _U_, char** err) {
3934 ssl_debug_printf("ssl_load_pkcs12: impossible without gnutls. fp %p\n",fp);
3939 ssl_free_key(Ssl_private_key_t* key _U_)
3944 ssl_find_private_key(SslDecryptSession *ssl_session _U_, GHashTable *key_hash _U_, GTree* associations _U_, packet_info *pinfo _U_)
3949 ssl_find_cipher(int num,SslCipherSuite* cs)
3951 ssl_debug_printf("ssl_find_cipher: dummy without gnutls. num %d cs %p\n",
3956 ssl_generate_pre_master_secret(SslDecryptSession *ssl_session _U_,
3957 guint32 length _U_, tvbuff_t *tvb _U_, guint32 offset _U_,
3958 const gchar *ssl_psk _U_, const ssl_master_key_map_t *mk_map _U_)
3960 ssl_debug_printf("%s: impossible without gnutls.\n", G_STRFUNC);
3964 ssl_generate_keyring_material(SslDecryptSession*ssl)
3966 ssl_debug_printf("ssl_generate_keyring_material: impossible without gnutls. ssl %p\n",
3971 ssl_change_cipher(SslDecryptSession *ssl_session, gboolean server)
3973 ssl_debug_printf("ssl_change_cipher %s: makes no sense without gnutls. ssl %p\n",
3974 (server)?"SERVER":"CLIENT", ssl_session);
3978 ssl_decrypt_record(SslDecryptSession*ssl, SslDecoder* decoder, gint ct,
3979 const guchar* in, guint inl, StringInfo* comp_str _U_, StringInfo* out, guint* outl)
3981 ssl_debug_printf("ssl_decrypt_record: impossible without gnutls. ssl %p"
3982 "decoder %p ct %d, in %p inl %d out %p outl %p\n", ssl, decoder, ct,
3983 in, inl, out, outl);
3988 ssl_cipher_setiv(SSL_CIPHER_CTX *cipher _U_, guchar* iv _U_, gint iv_len _U_)
3990 ssl_debug_printf("ssl_cipher_setiv: impossible without gnutls.\n");
3994 #endif /* defined(HAVE_LIBGNUTLS) && defined(HAVE_LIBGCRYPT) */
3996 /* get ssl data for this session. if no ssl data is found allocate a new one*/
3998 ssl_get_session(conversation_t *conversation, dissector_handle_t ssl_handle)
4001 SslDecryptSession *ssl_session;
4004 proto_ssl = dissector_handle_get_protocol_index(ssl_handle);
4005 conv_data = conversation_get_proto_data(conversation, proto_ssl);
4006 if (conv_data != NULL)
4007 return (SslDecryptSession *)conv_data;
4009 /* no previous SSL conversation info, initialize it. */
4010 ssl_session = wmem_new0(wmem_file_scope(), SslDecryptSession);
4012 /* data_len is the part that is meaningful, not the allocated length */
4013 ssl_session->master_secret.data_len = 0;
4014 ssl_session->master_secret.data = ssl_session->_master_secret;
4015 ssl_session->session_id.data_len = 0;
4016 ssl_session->session_id.data = ssl_session->_session_id;
4017 ssl_session->client_random.data_len = 0;
4018 ssl_session->client_random.data = ssl_session->_client_random;
4019 ssl_session->server_random.data_len = 0;
4020 ssl_session->server_random.data = ssl_session->_server_random;
4021 ssl_session->session_ticket.data_len = 0;
4022 ssl_session->session_ticket.data = NULL; /* will be re-alloced as needed */
4023 ssl_session->server_data_for_iv.data_len = 0;
4024 ssl_session->server_data_for_iv.data = ssl_session->_server_data_for_iv;
4025 ssl_session->client_data_for_iv.data_len = 0;
4026 ssl_session->client_data_for_iv.data = ssl_session->_client_data_for_iv;
4027 ssl_session->app_data_segment.data = NULL;
4028 ssl_session->app_data_segment.data_len = 0;
4029 ssl_session->handshake_data.data=NULL;
4030 ssl_session->handshake_data.data_len=0;
4032 /* Initialize parameters which are not necessary specific to decryption. */
4033 ssl_session->session.version = SSL_VER_UNKNOWN;
4034 SET_ADDRESS(&ssl_session->session.srv_addr, AT_NONE, 0, NULL);
4035 ssl_session->session.srv_ptype = PT_NONE;
4036 ssl_session->session.srv_port = 0;
4038 conversation_add_proto_data(conversation, proto_ssl, ssl_session);
4043 ssl_set_server(SslSession *session, address *addr, port_type ptype, guint32 port)
4045 WMEM_COPY_ADDRESS(wmem_file_scope(), &session->srv_addr, addr);
4046 session->srv_ptype = ptype;
4047 session->srv_port = port;
4051 ssl_starttls_ack(dissector_handle_t ssl_handle, packet_info *pinfo,
4052 dissector_handle_t app_handle)
4054 conversation_t *conversation;
4055 SslSession *session;
4057 /* Ignore if the SSL dissector is disabled. */
4060 /* The caller should always pass a valid handle to its own dissector. */
4061 DISSECTOR_ASSERT(app_handle);
4063 conversation = find_or_create_conversation(pinfo);
4064 session = &ssl_get_session(conversation, ssl_handle)->session;
4066 ssl_debug_printf("%s: old frame %d, app_handle=%p (%s)\n", G_STRFUNC,
4067 session->last_nontls_frame,
4068 (void *)session->app_handle,
4069 dissector_handle_get_dissector_name(session->app_handle));
4070 ssl_debug_printf("%s: current frame %d, app_handle=%p (%s)\n", G_STRFUNC,
4071 pinfo->fd->num, (void *)app_handle,
4072 dissector_handle_get_dissector_name(app_handle));
4074 /* Do not switch again if a dissector did it before. */
4075 if (session->last_nontls_frame) {
4076 ssl_debug_printf("%s: not overriding previous app handle!\n", G_STRFUNC);
4077 return session->last_nontls_frame;
4080 session->app_handle = app_handle;
4081 /* The SSL dissector should be called first for this conversation. */
4082 conversation_set_dissector(conversation, ssl_handle);
4083 /* SSL starts after this frame. */
4084 session->last_nontls_frame = pinfo->fd->num;
4088 /* Hash Functions for TLS/DTLS sessions table and private keys table*/
4090 ssl_equal (gconstpointer v, gconstpointer v2)
4092 const StringInfo *val1;
4093 const StringInfo *val2;
4094 val1 = (const StringInfo *)v;
4095 val2 = (const StringInfo *)v2;
4097 if (val1->data_len == val2->data_len &&
4098 !memcmp(val1->data, val2->data, val2->data_len)) {
4105 ssl_hash (gconstpointer v)
4108 const StringInfo* id;
4111 id = (const StringInfo*) v;
4113 /* id and id->data are mallocated in ssl_save_master_key(). As such 'data'
4114 * should be aligned for any kind of access (for example as a guint as
4115 * is done below). The intermediate void* cast is to prevent "cast
4116 * increases required alignment of target type" warnings on CPUs (such
4117 * as SPARCs) that do not allow misaligned memory accesses.
4119 cur = (const guint*)(void*) id->data;
4121 for (l=4; (l < id->data_len); l+=4, cur++)
4122 hash = hash ^ (*cur);
4128 ssl_private_key_equal (gconstpointer v, gconstpointer v2)
4130 const SslService *val1;
4131 const SslService *val2;
4132 val1 = (const SslService *)v;
4133 val2 = (const SslService *)v2;
4135 if ((val1->port == val2->port) &&
4136 ! CMP_ADDRESS(&val1->addr, &val2->addr)) {
4143 ssl_private_key_hash (gconstpointer v)
4145 const SslService *key;
4146 guint l, hash, len ;
4149 key = (const SslService *)v;
4151 len = key->addr.len;
4153 cur = (const guint8 *) key->addr.data;
4155 for (l=4; (l<len); l+=4, cur+=4)
4156 hash = hash ^ pntoh32(cur);
4161 /* private key table entries have a scope 'larger' then packet capture,
4162 * so we can't rely on wmem_file_scope function */
4164 ssl_private_key_free(gpointer id, gpointer key, gpointer dummy _U_)
4168 ssl_free_key((Ssl_private_key_t*) key);
4172 /* handling of association between tls/dtls ports and clear text protocol */
4174 ssl_association_add(GTree* associations, dissector_handle_t handle, guint port, const gchar *protocol, gboolean tcp, gboolean from_key_list)
4177 SslAssociation* assoc;
4178 assoc = (SslAssociation *)g_malloc(sizeof(SslAssociation));
4181 assoc->ssl_port = port;
4182 assoc->info=g_strdup(protocol);
4183 assoc->handle = find_dissector(protocol);
4184 assoc->from_key_list = from_key_list;
4186 ssl_debug_printf("association_add %s port %d protocol %s handle %p\n",
4187 (assoc->tcp)?"TCP":"UDP", port, protocol, (void *)(assoc->handle));
4190 if (!assoc->handle) {
4191 ssl_debug_printf("association_add could not find handle for protocol '%s', try to find 'data' dissector\n", protocol);
4192 assoc->handle = find_dissector("data");
4195 DISSECTOR_ASSERT(assoc->handle != NULL);
4198 dissector_add_uint("tcp.port", port, handle);
4200 dissector_add_uint("udp.port", port, handle);
4202 g_tree_insert(associations, assoc, assoc);
4204 dissector_add_uint("sctp.port", port, handle);
4208 ssl_association_remove(GTree* associations, SslAssociation *assoc)
4210 ssl_debug_printf("ssl_association_remove removing %s %u - %s handle %p\n",
4211 (assoc->tcp)?"TCP":"UDP", assoc->ssl_port, assoc->info, (void *)(assoc->handle));
4213 dissector_delete_uint((assoc->tcp)?"tcp.port":"udp.port", assoc->ssl_port, assoc->handle);
4215 g_free(assoc->info);
4217 g_tree_remove(associations, assoc);
4222 ssl_association_cmp(gconstpointer a, gconstpointer b)
4224 const SslAssociation *assoc_a=(const SslAssociation *)a, *assoc_b=(const SslAssociation *)b;
4225 if (assoc_a->tcp != assoc_b->tcp) return (assoc_a->tcp)?1:-1;
4226 return assoc_a->ssl_port - assoc_b->ssl_port;
4230 ssl_association_find(GTree * associations, guint port, gboolean tcp)
4232 register SslAssociation* ret;
4233 SslAssociation assoc_tmp;
4235 assoc_tmp.tcp = tcp;
4236 assoc_tmp.ssl_port = port;
4237 ret = (SslAssociation *)g_tree_lookup(associations, &assoc_tmp);
4239 ssl_debug_printf("association_find: %s port %d found %p\n", (tcp)?"TCP":"UDP", port, (void *)ret);
4244 ssl_assoc_from_key_list(gpointer key _U_, gpointer data, gpointer user_data)
4246 if (((SslAssociation*)data)->from_key_list)
4247 wmem_stack_push((wmem_stack_t*)user_data, data);
4252 ssl_packet_from_server(SslSession *session, GTree *associations, packet_info *pinfo)
4255 if (session->srv_ptype != PT_NONE) {
4256 ret = (session->srv_ptype == pinfo->ptype) &&
4257 (session->srv_port == pinfo->srcport) &&
4258 ADDRESSES_EQUAL(&session->srv_addr, &pinfo->src);
4260 ret = ssl_association_find(associations, pinfo->srcport, pinfo->ptype == PT_TCP) != 0;
4263 ssl_debug_printf("packet_from_server: is from server - %s\n", (ret)?"TRUE":"FALSE");
4267 /* add to packet data a copy of the specified real data */
4269 ssl_add_record_info(gint proto, packet_info *pinfo, guchar* data, gint data_len, gint record_id)
4275 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4278 pi = (SslPacketInfo *)wmem_alloc0(wmem_file_scope(), sizeof(SslPacketInfo));
4279 p_add_proto_data(wmem_file_scope(), pinfo, proto, 0, pi);
4282 real_data = (guchar *)wmem_alloc(wmem_file_scope(), data_len);
4283 memcpy(real_data, data, data_len);
4285 rec = (SslRecordInfo *)wmem_alloc(wmem_file_scope(), sizeof(SslRecordInfo));
4286 rec->id = record_id;
4287 rec->real_data = real_data;
4288 rec->data_len = data_len;
4290 /* head insertion */
4291 rec->next= pi->handshake_data;
4292 pi->handshake_data = rec;
4295 /* search in packet data for the specified id; return a newly created tvb for the associated data */
4297 ssl_get_record_info(tvbuff_t *parent_tvb, int proto, packet_info *pinfo, gint record_id)
4301 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4306 for (rec = pi->handshake_data; rec; rec = rec->next)
4307 if (rec->id == record_id)
4308 /* link new real_data_tvb with a parent tvb so it is freed when frame dissection is complete */
4309 return tvb_new_child_real_data(parent_tvb, rec->real_data, rec->data_len, rec->data_len);
4315 ssl_add_data_info(gint proto, packet_info *pinfo, guchar* data, gint data_len, gint key, SslFlow *flow)
4317 SslDataInfo *rec, **prec;
4320 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4323 pi = (SslPacketInfo *)wmem_alloc0(wmem_file_scope(), sizeof(SslPacketInfo));
4324 p_add_proto_data(wmem_file_scope(), pinfo, proto, 0, pi);
4327 rec = (SslDataInfo *)wmem_alloc(wmem_file_scope(), sizeof(SslDataInfo)+data_len);
4329 rec->plain_data.data = (guchar*)(rec + 1);
4330 memcpy(rec->plain_data.data, data, data_len);
4331 rec->plain_data.data_len = data_len;
4334 rec->seq = flow->byte_seq;
4335 rec->nxtseq = flow->byte_seq + data_len;
4337 flow->byte_seq += data_len;
4342 prec = &pi->appl_data;
4343 while (*prec) prec = &(*prec)->next;
4346 ssl_debug_printf("ssl_add_data_info: new data inserted data_len = %d, seq = %u, nxtseq = %u\n",
4347 rec->plain_data.data_len, rec->seq, rec->nxtseq);
4351 ssl_get_data_info(int proto, packet_info *pinfo, gint key)
4355 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, 0);
4357 if (!pi) return NULL;
4359 rec = pi->appl_data;
4361 if (rec->key == key) return rec;
4368 /* initialize/reset per capture state data (ssl sessions cache) */
4370 ssl_common_init(ssl_master_key_map_t *mk_map,
4371 StringInfo *decrypted_data, StringInfo *compressed_data)
4373 mk_map->session = g_hash_table_new(ssl_hash, ssl_equal);
4374 mk_map->crandom = g_hash_table_new(ssl_hash, ssl_equal);
4375 mk_map->pre_master = g_hash_table_new(ssl_hash, ssl_equal);
4376 mk_map->pms = g_hash_table_new(ssl_hash, ssl_equal);
4377 ssl_data_alloc(decrypted_data, 32);
4378 ssl_data_alloc(compressed_data, 32);
4382 ssl_common_cleanup(ssl_master_key_map_t *mk_map, FILE **ssl_keylog_file,
4383 StringInfo *decrypted_data, StringInfo *compressed_data)
4385 g_hash_table_destroy(mk_map->session);
4386 g_hash_table_destroy(mk_map->crandom);
4387 g_hash_table_destroy(mk_map->pre_master);
4388 g_hash_table_destroy(mk_map->pms);
4390 g_free(decrypted_data->data);
4391 g_free(compressed_data->data);
4393 /* close the previous keylog file now that the cache are cleared, this
4394 * allows the cache to be filled with the full keylog file contents. */
4395 if (*ssl_keylog_file) {
4396 fclose(*ssl_keylog_file);
4397 *ssl_keylog_file = NULL;
4401 /* parse ssl related preferences (private keys and ports association strings) */
4403 ssl_parse_key_list(const ssldecrypt_assoc_t * uats, GHashTable *key_hash, GTree* associations, dissector_handle_t handle, gboolean tcp)
4405 SslService* service;
4406 Ssl_private_key_t* private_key, *tmp_private_key;
4408 guint32 addr_data[4];
4410 address_type addr_type[2] = { AT_IPv4, AT_IPv6 };
4411 gchar* address_string;
4413 /* try to load keys file first */
4414 fp = ws_fopen(uats->keyfile, "rb");
4416 report_open_failure(uats->keyfile, errno, FALSE);
4420 for (at = 0; at < 2; at++) {
4421 memset(addr_data, 0, sizeof(addr_data));
4424 /* any: IPv4 or IPv6 wildcard */
4425 /* anyipv4: IPv4 wildcard */
4426 /* anyipv6: IPv6 wildcard */
4428 if(addr_type[at] == AT_IPv4) {
4429 if (strcmp(uats->ipaddr, "any") == 0 || strcmp(uats->ipaddr, "anyipv4") == 0 ||
4430 get_host_ipaddr(uats->ipaddr, &addr_data[0])) {
4433 } else { /* AT_IPv6 */
4434 if(strcmp(uats->ipaddr, "any") == 0 || strcmp(uats->ipaddr, "anyipv6") == 0 ||
4435 get_host_ipaddr6(uats->ipaddr, (struct e_in6_addr *) addr_data)) {
4444 /* reset the data pointer for the second iteration */
4447 if ((gint)strlen(uats->password) == 0) {
4448 private_key = ssl_load_key(fp);
4451 private_key = ssl_load_pkcs12(fp, uats->password, &err);
4453 report_failure("%s\n", err);
4459 report_failure("Can't load private key from %s\n", uats->keyfile);
4464 service = (SslService *)g_malloc(sizeof(SslService) + addr_len);
4465 service->addr.type = addr_type[at];
4466 service->addr.len = addr_len;
4467 service->addr.data = ((guchar*)service) + sizeof(SslService);
4468 memcpy((void*)service->addr.data, addr_data, addr_len);
4470 if(strcmp(uats->port,"start_tls")==0) {
4473 service->port = atoi(uats->port);
4477 * This gets called outside any dissection scope, so we have to
4478 * use a NULL scope and free it ourselves.
4480 address_string = address_to_str(NULL, &service->addr);
4481 ssl_debug_printf("ssl_init %s addr '%s' (%s) port '%d' filename '%s' password(only for p12 file) '%s'\n",
4482 (addr_type[at] == AT_IPv4) ? "IPv4" : "IPv6", uats->ipaddr, address_string,
4483 service->port, uats->keyfile, uats->password);
4484 wmem_free(NULL, address_string);
4486 ssl_debug_printf("ssl_init private key file %s successfully loaded.\n", uats->keyfile);
4488 /* if item exists, remove first */
4489 tmp_private_key = (Ssl_private_key_t *)g_hash_table_lookup(key_hash, service);
4490 if (tmp_private_key) {
4491 g_hash_table_remove(key_hash, service);
4492 ssl_free_key(tmp_private_key);
4495 g_hash_table_insert(key_hash, service, private_key);
4497 ssl_association_add(associations, handle, service->port, uats->protocol, tcp, TRUE);
4503 /** store a known (pre-)master secret into cache */
4505 ssl_save_master_key(const char *label, GHashTable *ht, StringInfo *key,
4508 StringInfo *ht_key, *master_secret;
4510 if (key->data_len == 0) {
4511 ssl_debug_printf("%s: not saving empty %s!\n", G_STRFUNC, label);
4515 if (mk->data_len == 0) {
4516 ssl_debug_printf("%s not saving empty (pre-)master secret for %s!\n",
4521 /* ssl_hash() depends on session_ticket->data being aligned for guint access
4522 * so be careful in changing how it is allocated. */
4523 ht_key = ssl_data_clone(key);
4524 master_secret = ssl_data_clone(mk);
4525 g_hash_table_insert(ht, ht_key, master_secret);
4527 ssl_debug_printf("%s inserted (pre-)master secret for %s\n", G_STRFUNC, label);
4528 ssl_print_string("stored key", ht_key);
4529 ssl_print_string("stored (pre-)master secret", master_secret);
4532 /** restore a (pre-)master secret given some key in the cache */
4534 ssl_restore_master_key(SslDecryptSession *ssl, const char *label,
4535 gboolean is_pre_master, GHashTable *ht, StringInfo *key)
4539 if (key->data_len == 0) {
4540 ssl_debug_printf("%s can't restore %smaster secret using an empty %s\n",
4541 G_STRFUNC, is_pre_master ? "pre-" : "", label);
4545 ms = (StringInfo *)g_hash_table_lookup(ht, key);
4547 ssl_debug_printf("%s can't find %smaster secret by %s\n", G_STRFUNC,
4548 is_pre_master ? "pre-" : "", label);
4552 /* (pre)master secret found, clear knowledge of other keys and set it in the
4553 * current conversation */
4554 ssl->state &= ~(SSL_MASTER_SECRET | SSL_PRE_MASTER_SECRET |
4555 SSL_HAVE_SESSION_KEY);
4556 if (is_pre_master) {
4557 /* unlike master secret, pre-master secret has a variable size (48 for
4558 * RSA, varying for PSK) and is therefore not statically allocated */
4559 ssl->pre_master_secret.data = (guchar *) wmem_alloc(wmem_file_scope(),
4561 ssl_data_set(&ssl->pre_master_secret, ms->data, ms->data_len);
4562 ssl->state |= SSL_PRE_MASTER_SECRET;
4564 ssl_data_set(&ssl->master_secret, ms->data, ms->data_len);
4565 ssl->state |= SSL_MASTER_SECRET;
4567 ssl_debug_printf("%s %smaster secret retrieved using %s\n", G_STRFUNC,
4568 is_pre_master ? "pre-" : "", label);
4569 ssl_print_string(label, key);
4570 ssl_print_string("(pre-)master secret", ms);
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_restore_master_key(ssl, "Session Ticket", FALSE,
4592 mk_map->session, &ssl->session_ticket) &&
4593 !ssl_restore_master_key(ssl, "Client Random", FALSE,
4594 mk_map->crandom, &ssl->client_random)) {
4595 /* how unfortunate, the master secret could not be found */
4596 ssl_debug_printf(" Cannot find master secret\n");
4600 if (ssl_generate_keyring_material(ssl) < 0) {
4601 ssl_debug_printf("%s can't generate keyring material\n", G_STRFUNC);
4604 /* Save Client Random/ Session ID for "SSL Export Session keys" */
4605 ssl_save_master_key("Client Random", mk_map->crandom,
4606 &ssl->client_random, &ssl->master_secret);
4607 ssl_save_master_key("Session ID", mk_map->session,
4608 &ssl->session_id, &ssl->master_secret);
4609 ssl_save_master_key("Session Ticket", mk_map->session,
4610 &ssl->session_ticket, &ssl->master_secret);
4614 ssl_is_valid_content_type(guint8 type)
4616 switch ((ContentType) type) {
4617 case SSL_ID_CHG_CIPHER_SPEC:
4619 case SSL_ID_HANDSHAKE:
4620 case SSL_ID_APP_DATA:
4621 case SSL_ID_HEARTBEAT:
4628 ssl_is_valid_handshake_type(guint8 hs_type, gboolean is_dtls)
4630 switch ((HandshakeType) hs_type) {
4631 case SSL_HND_HELLO_VERIFY_REQUEST:
4632 /* hello_verify_request is DTLS-only */
4635 case SSL_HND_HELLO_REQUEST:
4636 case SSL_HND_CLIENT_HELLO:
4637 case SSL_HND_SERVER_HELLO:
4638 case SSL_HND_NEWSESSION_TICKET:
4639 case SSL_HND_CERTIFICATE:
4640 case SSL_HND_SERVER_KEY_EXCHG:
4641 case SSL_HND_CERT_REQUEST:
4642 case SSL_HND_SVR_HELLO_DONE:
4643 case SSL_HND_CERT_VERIFY:
4644 case SSL_HND_CLIENT_KEY_EXCHG:
4645 case SSL_HND_FINISHED:
4646 case SSL_HND_CERT_URL:
4647 case SSL_HND_CERT_STATUS:
4648 case SSL_HND_SUPPLEMENTAL_DATA:
4649 case SSL_HND_ENCRYPTED_EXTS:
4656 /** keyfile handling */
4659 ssl_compile_keyfile_regex(void)
4661 #define OCTET "(?:[[:xdigit:]]{2})"
4662 const gchar *pattern =
4663 "(?:PMS_CLIENT_RANDOM (?<client_random_pms>" OCTET "{32}) (?<pms>" OCTET "{32}))"
4665 /* First part of encrypted RSA pre-master secret */
4666 "RSA (?<encrypted_pmk>" OCTET "{8}) "
4667 /* Matches Server Hellos having a Session ID */
4668 "|RSA Session-ID:(?<session_id>" OCTET "+) Master-Key:"
4669 /* Matches Client Hellos having this Client.Random */
4670 "|CLIENT_RANDOM (?<client_random>" OCTET "{32}) "
4671 ")(?<master_secret>" OCTET "{" G_STRINGIFY(SSL_MASTER_SECRET_LENGTH) "})";
4673 static GRegex *regex = NULL;
4674 GError *gerr = NULL;
4677 regex = g_regex_new(pattern, G_REGEX_OPTIMIZE,
4678 G_REGEX_MATCH_ANCHORED, &gerr);
4680 ssl_debug_printf("%s failed to compile regex: %s\n", G_STRFUNC,
4691 file_needs_reopen(FILE *fp, const char *filename)
4693 ws_statb64 open_stat, current_stat;
4695 /* consider a file deleted when stat fails for either file,
4696 * or when the residing device / inode has changed. */
4697 if (0 != ws_fstat64(fileno(fp), &open_stat))
4699 if (0 != ws_stat64(filename, ¤t_stat))
4702 /* Note: on Windows, ino may be 0. Existing files cannot be deleted on
4703 * Windows, but hopefully the size is a good indicator when a file got
4704 * removed and recreated */
4705 return open_stat.st_dev != current_stat.st_dev ||
4706 open_stat.st_ino != current_stat.st_ino ||
4707 open_stat.st_size > current_stat.st_size;
4710 typedef struct ssl_master_key_match_group {
4711 const char *re_group_name;
4712 GHashTable *master_key_ht;
4713 } ssl_master_key_match_group_t;
4716 ssl_load_keyfile(const gchar *ssl_keylog_filename, FILE **keylog_file,
4717 const ssl_master_key_map_t *mk_map)
4721 ssl_master_key_match_group_t mk_groups[] = {
4722 { "encrypted_pmk", mk_map->pre_master },
4723 { "session_id", mk_map->session },
4724 { "client_random", mk_map->crandom },
4725 { "client_random_pms", mk_map->pms},
4727 /* no need to try if no key log file is configured. */
4728 if (!ssl_keylog_filename) {
4729 ssl_debug_printf("%s dtls/ssl.keylog_file is not configured!\n",
4734 /* The format of the file is a series of records with one of the following formats:
4736 * Where xxxx are the first 8 bytes of the encrypted pre-master secret (hex-encoded)
4737 * Where yyyy is the cleartext pre-master secret (hex-encoded)
4738 * (this is the original format introduced with bug 4349)
4740 * - "RSA Session-ID:xxxx Master-Key:yyyy"
4741 * Where xxxx is the SSL session ID (hex-encoded)
4742 * Where yyyy is the cleartext master secret (hex-encoded)
4743 * (added to support openssl s_client Master-Key output)
4744 * This is somewhat is a misnomer because there's nothing RSA specific
4747 * - "PMS_CLIENT_RANDOM xxxx yyyy"
4748 * Where xxxx is the client_random from the ClientHello (hex-encoded)
4749 * Where yyyy is the cleartext pre-master secret (hex-encoded)
4750 * (This format allows SSL connections to be decrypted, if a user can
4751 * capture the PMS but could not recover the MS for a specific session
4752 * with a SSL Server.)
4754 * - "CLIENT_RANDOM xxxx yyyy"
4755 * Where xxxx is the client_random from the ClientHello (hex-encoded)
4756 * Where yyyy is the cleartext master secret (hex-encoded)
4757 * (This format allows non-RSA SSL connections to be decrypted, i.e.
4760 regex = ssl_compile_keyfile_regex();
4764 ssl_debug_printf("trying to use SSL keylog in %s\n", ssl_keylog_filename);
4766 /* if the keylog file was deleted, re-open it */
4767 if (*keylog_file && file_needs_reopen(*keylog_file, ssl_keylog_filename)) {
4768 ssl_debug_printf("%s file got deleted, trying to re-open\n", G_STRFUNC);
4769 fclose(*keylog_file);
4770 *keylog_file = NULL;
4773 if (*keylog_file == NULL) {
4774 *keylog_file = ws_fopen(ssl_keylog_filename, "r");
4775 if (!*keylog_file) {
4776 ssl_debug_printf("%s failed to open SSL keylog\n", G_STRFUNC);
4782 char buf[512], *line;
4786 line = fgets(buf, sizeof(buf), *keylog_file);
4790 bytes_read = strlen(line);
4791 /* fgets includes the \n at the end of the line. */
4792 if (bytes_read > 0 && line[bytes_read - 1] == '\n') {
4793 line[bytes_read - 1] = 0;
4796 if (bytes_read > 0 && line[bytes_read - 1] == '\r') {
4797 line[bytes_read - 1] = 0;
4801 ssl_debug_printf(" checking keylog line: %s\n", line);
4802 if (g_regex_match(regex, line, G_REGEX_MATCH_ANCHORED, &mi)) {
4803 gchar *hex_key, *hex_pre_ms_or_ms;
4804 StringInfo *key = wmem_new(wmem_file_scope(), StringInfo);
4805 StringInfo *pre_ms_or_ms = NULL;
4806 GHashTable *ht = NULL;
4808 /* Is the PMS being supplied with the PMS_CLIENT_RANDOM
4809 * otherwise we will use the Master Secret
4811 hex_pre_ms_or_ms = g_match_info_fetch_named(mi, "master_secret");
4812 if (hex_pre_ms_or_ms == NULL || strlen(hex_pre_ms_or_ms) == 0){
4813 g_free(hex_pre_ms_or_ms);
4814 hex_pre_ms_or_ms = g_match_info_fetch_named(mi, "pms");
4816 /* There is always a match, otherwise the regex is wrong. */
4817 DISSECTOR_ASSERT(hex_pre_ms_or_ms && strlen(hex_pre_ms_or_ms));
4819 /* convert from hex to bytes and save to hashtable */
4820 pre_ms_or_ms = wmem_new(wmem_file_scope(), StringInfo);
4821 from_hex(pre_ms_or_ms, hex_pre_ms_or_ms, strlen(hex_pre_ms_or_ms));
4822 g_free(hex_pre_ms_or_ms);
4824 /* Find a master key from any format (CLIENT_RANDOM, SID, ...) */
4825 for (i = 0; i < G_N_ELEMENTS(mk_groups); i++) {
4826 ssl_master_key_match_group_t *g = &mk_groups[i];
4827 hex_key = g_match_info_fetch_named(mi, g->re_group_name);
4828 if (hex_key && *hex_key) {
4829 ssl_debug_printf(" matched %s\n", g->re_group_name);
4830 ht = g->master_key_ht;
4831 from_hex(key, hex_key, strlen(hex_key));
4837 DISSECTOR_ASSERT(ht); /* Cannot be reached, or regex is wrong. */
4839 g_hash_table_insert(ht, key, pre_ms_or_ms);
4842 ssl_debug_printf(" unrecognized line\n");
4844 /* always free match info even if there is no match. */
4845 g_match_info_free(mi);
4849 #ifdef SSL_DECRYPT_DEBUG
4851 static FILE* ssl_debug_file=NULL;
4854 ssl_set_debug(const gchar* name)
4856 static gint debug_file_must_be_closed;
4859 debug_file_must_be_closed = 0;
4860 use_stderr = name?(strcmp(name, SSL_DEBUG_USE_STDERR) == 0):0;
4862 if (debug_file_must_be_closed)
4863 fclose(ssl_debug_file);
4865 ssl_debug_file = stderr;
4866 else if (!name || (strcmp(name, "") ==0))
4867 ssl_debug_file = NULL;
4869 ssl_debug_file = ws_fopen(name, "w");
4870 if (!use_stderr && ssl_debug_file)
4871 debug_file_must_be_closed = 1;
4873 ssl_debug_printf("Wireshark SSL debug log \n\n");
4877 ssl_debug_flush(void)
4880 fflush(ssl_debug_file);
4884 ssl_debug_printf(const gchar* fmt, ...)
4888 if (!ssl_debug_file)
4892 vfprintf(ssl_debug_file, fmt, ap);
4897 ssl_print_data(const gchar* name, const guchar* data, size_t len)
4900 if (!ssl_debug_file)
4902 fprintf(ssl_debug_file,"%s[%d]:\n",name, (int) len);
4903 for (i=0; i<len; i+=16) {
4904 fprintf(ssl_debug_file,"| ");
4905 for (j=i, k=0; k<16 && j<len; ++j, ++k)
4906 fprintf(ssl_debug_file,"%.2x ",data[j]);
4908 fprintf(ssl_debug_file," ");
4909 fputc('|', ssl_debug_file);
4910 for (j=i, k=0; k<16 && j<len; ++j, ++k) {
4912 if (!g_ascii_isprint(c) || (c=='\t')) c = '.';
4913 fputc(c, ssl_debug_file);
4916 fputc(' ', ssl_debug_file);
4917 fprintf(ssl_debug_file,"|\n");
4922 ssl_print_string(const gchar* name, const StringInfo* data)
4924 ssl_print_data(name, data->data, data->data_len);
4926 #endif /* SSL_DECRYPT_DEBUG */
4928 /* checks for SSL and DTLS UAT key list fields */
4931 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)
4933 if (!p || strlen(p) == 0u) {
4934 *err = g_strdup_printf("No IP address given.");
4943 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)
4945 if (!p || strlen(p) == 0u) {
4946 *err = g_strdup_printf("No Port given.");
4950 if (strcmp(p, "start_tls") != 0){
4951 const gint i = atoi(p);
4952 if (i < 0 || i > 65535) {
4953 *err = g_strdup_printf("Invalid port given.");
4963 ssldecrypt_uat_fld_protocol_chk_cb(void* r _U_, const char* p, guint len _U_, const void* u1 _U_, const void* u2 _U_, char** err)
4965 if (!p || strlen(p) == 0u) {
4966 *err = g_strdup_printf("No protocol given.");
4970 if (!find_dissector(p)) {
4971 if (proto_get_id_by_filter_name(p) != -1) {
4972 *err = g_strdup_printf("While '%s' is a valid dissector filter name, that dissector is not configured"
4973 " to support SSL decryption.\n\n"
4974 "If you need to decrypt '%s' over SSL, please contact the Wireshark development team.", p, p);
4976 char* ssl_str = ssl_association_info();
4977 *err = g_strdup_printf("Could not find dissector for: '%s'\nCommonly used SSL dissectors include:\n%s", p, ssl_str);
4988 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)
4992 if (!p || strlen(p) == 0u) {
4993 *err = g_strdup_printf("No filename given.");
4996 if (ws_stat64(p, &st) != 0) {
4997 *err = g_strdup_printf("File '%s' does not exist or access is denied.", p);
5007 ssldecrypt_uat_fld_password_chk_cb(void* r _U_, const char* p, guint len _U_, const void* u1 _U_, const void* u2 _U_, char ** err)
5009 ssldecrypt_assoc_t* f = (ssldecrypt_assoc_t *)r;
5012 if (p && (strlen(p) > 0u)) {
5013 fp = ws_fopen(f->keyfile, "rb");
5016 if (!ssl_load_pkcs12(fp, p, &msg)) {
5018 *err = g_strdup_printf("Could not load PKCS#12 key file: %s", msg);
5025 *err = g_strdup_printf("Leave this field blank if the keyfile is not PKCS#12.");
5035 /* dissect a list of hash algorithms, return the number of bytes dissected
5036 this is used for the signature algorithms extension and for the
5037 TLS1.2 certificate request */
5039 ssl_dissect_hash_alg_list(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5040 packet_info* pinfo, guint32 offset, guint16 len)
5042 guint32 offset_start;
5043 proto_tree *subtree, *alg_tree;
5046 offset_start = offset;
5050 ti = proto_tree_add_none_format(tree, hf->hf.hs_sig_hash_algs, tvb,
5052 "Signature Hash Algorithms (%u algorithm%s)",
5053 len / 2, plurality(len / 2, "", "s"));
5054 subtree = proto_item_add_subtree(ti, hf->ett.hs_sig_hash_algs);
5057 expert_add_info_format(pinfo, ti, &hf->ei.hs_sig_hash_algs_bad,
5058 "Invalid Signature Hash Algorithm length: %d", len);
5059 return offset-offset_start;
5063 ti = proto_tree_add_item(subtree, hf->hf.hs_sig_hash_alg,
5064 tvb, offset, 2, ENC_BIG_ENDIAN);
5065 alg_tree = proto_item_add_subtree(ti, hf->ett.hs_sig_hash_alg);
5067 proto_tree_add_item(alg_tree, hf->hf.hs_sig_hash_hash,
5068 tvb, offset, 1, ENC_BIG_ENDIAN);
5069 proto_tree_add_item(alg_tree, hf->hf.hs_sig_hash_sig,
5070 tvb, offset+1, 1, ENC_BIG_ENDIAN);
5075 return offset-offset_start;
5079 ssl_dissect_hnd_hello_ext_sig_hash_algs(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5080 proto_tree *tree, packet_info* pinfo, guint32 offset, guint32 ext_len)
5082 guint16 sh_alg_length;
5085 sh_alg_length = tvb_get_ntohs(tvb, offset);
5086 proto_tree_add_uint(tree, hf->hf.hs_sig_hash_alg_len,
5087 tvb, offset, 2, sh_alg_length);
5089 if (ext_len < 2 || sh_alg_length != ext_len - 2) {
5090 /* ERROR: sh_alg_length must be 2 less than ext_len */
5094 ret = ssl_dissect_hash_alg_list(hf, tvb, tree, pinfo, offset, sh_alg_length);
5102 ssl_dissect_hnd_hello_ext_alpn(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5103 proto_tree *tree, guint32 offset, guint32 ext_len,
5104 gboolean is_client, SslSession *session)
5106 guint16 alpn_length;
5108 proto_tree *alpn_tree;
5111 alpn_length = tvb_get_ntohs(tvb, offset);
5112 if (ext_len < 2 || alpn_length != ext_len - 2) {
5113 /* ERROR: alpn_length must be 2 less than ext_len */
5116 proto_tree_add_item(tree, hf->hf.hs_ext_alpn_len,
5117 tvb, offset, 2, ENC_BIG_ENDIAN);
5120 ti = proto_tree_add_item(tree, hf->hf.hs_ext_alpn_list,
5121 tvb, offset, alpn_length, ENC_NA);
5122 alpn_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_alpn);
5124 /* If ALPN is given in ServerHello, then ProtocolNameList MUST contain
5125 * exactly one "ProtocolName". */
5130 name_length = tvb_get_guint8(tvb, offset);
5131 /* '\0'-terminated string for prefix/full string comparison purposes. */
5132 proto_name = tvb_get_string_enc(wmem_packet_scope(), tvb, offset + 1,
5133 name_length, ENC_ASCII);
5134 for (i = 0; i < G_N_ELEMENTS(ssl_alpn_protocols); i++) {
5135 const ssl_alpn_protocol_t *alpn_proto = &ssl_alpn_protocols[i];
5137 if (name_length >= alpn_proto->proto_name_len &&
5138 (memcmp(proto_name, alpn_proto->proto_name,
5139 alpn_proto->proto_name_len) == 0)) {
5141 dissector_handle_t handle;
5142 /* ProtocolName match, so set the App data dissector handle.
5143 * This may override protocols given via the UAT dialog, but
5144 * since the ALPN hint is precise, do it anyway. */
5145 handle = find_dissector(alpn_proto->dissector_name);
5146 ssl_debug_printf("%s: changing handle %p to %p (%s)", G_STRFUNC,
5147 (void *)session->app_handle,
5148 (void *)handle, alpn_proto->dissector_name);
5149 /* if dissector is disabled, do not overwrite previous one */
5151 session->app_handle = handle;
5157 while (alpn_length > 0) {
5158 name_length = tvb_get_guint8(tvb, offset);
5159 proto_tree_add_item(alpn_tree, hf->hf.hs_ext_alpn_str_len,
5160 tvb, offset, 1, ENC_NA);
5163 proto_tree_add_item(alpn_tree, hf->hf.hs_ext_alpn_str,
5164 tvb, offset, name_length, ENC_ASCII|ENC_NA);
5165 offset += name_length;
5166 alpn_length -= name_length;
5173 ssl_dissect_hnd_hello_ext_npn(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5174 proto_tree *tree, guint32 offset, guint32 ext_len)
5177 proto_tree *npn_tree;
5183 npn_tree = proto_tree_add_subtree(tree, tvb, offset, ext_len, hf->ett.hs_ext_npn, NULL, "Next Protocol Negotiation");
5185 while (ext_len > 0) {
5186 npn_length = tvb_get_guint8(tvb, offset);
5187 proto_tree_add_item(npn_tree, hf->hf.hs_ext_npn_str_len,
5188 tvb, offset, 1, ENC_NA);
5192 if (npn_length > 0) {
5193 proto_tree_add_item(npn_tree, hf->hf.hs_ext_npn_str,
5194 tvb, offset, npn_length, ENC_ASCII|ENC_NA);
5195 offset += npn_length;
5196 ext_len -= npn_length;
5204 ssl_dissect_hnd_hello_ext_reneg_info(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5205 proto_tree *tree, guint32 offset, guint32 ext_len)
5207 guint8 reneg_info_length;
5208 proto_tree *reneg_info_tree;
5214 reneg_info_tree = proto_tree_add_subtree(tree, tvb, offset, ext_len, hf->ett.hs_ext_reneg_info, NULL, "Renegotiation Info extension");
5216 reneg_info_length = tvb_get_guint8(tvb, offset);
5217 proto_tree_add_item(reneg_info_tree, hf->hf.hs_ext_reneg_info_len,
5218 tvb, offset, 1, ENC_NA);
5221 if (reneg_info_length > 0) {
5222 proto_tree_add_item(reneg_info_tree, hf->hf.hs_ext_reneg_info, tvb, offset, reneg_info_length, ENC_NA);
5223 offset += reneg_info_length;
5230 ssl_dissect_hnd_hello_ext_server_name(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5231 proto_tree *tree, guint32 offset, guint32 ext_len)
5233 guint16 server_name_length;
5234 proto_tree *server_name_tree;
5241 server_name_tree = proto_tree_add_subtree(tree, tvb, offset, ext_len, hf->ett.hs_ext_server_name, NULL, "Server Name Indication extension");
5243 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name_list_len,
5244 tvb, offset, 2, ENC_BIG_ENDIAN);
5248 while (ext_len > 0) {
5249 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name_type,
5250 tvb, offset, 1, ENC_NA);
5254 server_name_length = tvb_get_ntohs(tvb, offset);
5255 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name_len,
5256 tvb, offset, 2, ENC_BIG_ENDIAN);
5260 if (server_name_length > 0) {
5261 proto_tree_add_item(server_name_tree, hf->hf.hs_ext_server_name,
5262 tvb, offset, server_name_length, ENC_ASCII|ENC_NA);
5263 offset += server_name_length;
5264 ext_len -= server_name_length;
5271 ssl_dissect_hnd_hello_ext_padding(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5272 proto_tree *tree, guint32 offset, guint32 ext_len)
5274 guint8 padding_length;
5275 proto_tree *padding_tree;
5282 ti = proto_tree_add_item(tree, hf->hf.hs_ext_padding_data, tvb, offset, ext_len, ENC_NA);
5283 padding_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_padding);
5286 proto_tree_add_item(padding_tree, hf->hf.hs_ext_padding_len, tvb, offset, 2, ENC_NA);
5287 padding_length = tvb_get_guint8(tvb, offset);
5290 proto_tree_add_item(padding_tree, hf->hf.hs_ext_padding_data, tvb, offset, padding_length, ENC_NA);
5291 offset += padding_length;
5297 ssl_dissect_hnd_hello_ext_session_ticket(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5298 proto_tree *tree, guint32 offset, guint32 ext_len, gboolean is_client, SslDecryptSession *ssl)
5300 if (is_client && ssl && ext_len != 0) {
5301 tvb_ensure_bytes_exist(tvb, offset, ext_len);
5302 /* Save the Session Ticket such that it can be used as identifier for
5303 * restoring a previous Master Secret (in ChangeCipherSpec) */
5304 ssl->session_ticket.data = (guchar*)wmem_realloc(wmem_file_scope(),
5305 ssl->session_ticket.data, ext_len);
5306 ssl->session_ticket.data_len = ext_len;
5307 tvb_memcpy(tvb,ssl->session_ticket.data, offset, ext_len);
5309 proto_tree_add_bytes_format(tree, hf->hf.hs_ext_data,
5310 tvb, offset, ext_len, NULL,
5312 ext_len, plurality(ext_len, "", "s"));
5313 return offset + ext_len;
5317 ssl_dissect_hnd_hello_ext_cert_type(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5318 proto_tree *tree, guint32 offset, guint32 ext_len,
5319 gboolean is_client, guint16 ext_type, SslSession *session)
5321 guint8 cert_list_length;
5323 proto_tree *cert_list_tree;
5327 cert_list_length = tvb_get_guint8(tvb, offset);
5328 proto_tree_add_item(tree, hf->hf.hs_ext_cert_types_len,
5329 tvb, offset, 1, ENC_BIG_ENDIAN);
5331 if (ext_len != (guint32)cert_list_length + 1)
5334 ti = proto_tree_add_item(tree, hf->hf.hs_ext_cert_types, tvb, offset,
5335 cert_list_length, cert_list_length);
5336 proto_item_append_text(ti, " (%d)", cert_list_length);
5338 /* make this a subtree */
5339 cert_list_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_cert_types);
5341 /* loop over all point formats */
5342 while (cert_list_length > 0)
5344 proto_tree_add_item(cert_list_tree, hf->hf.hs_ext_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN);
5349 cert_type = tvb_get_guint8(tvb, offset);
5350 proto_tree_add_item(tree, hf->hf.hs_ext_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN);
5352 if (ext_type == SSL_HND_HELLO_EXT_CERT_TYPE || ext_type == SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE) {
5353 session->client_cert_type = cert_type;
5355 if (ext_type == SSL_HND_HELLO_EXT_CERT_TYPE || ext_type == SSL_HND_HELLO_EXT_SERVER_CERT_TYPE) {
5356 session->server_cert_type = cert_type;
5364 ssl_dissect_hnd_hello_common(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5365 proto_tree *tree, guint32 offset,
5366 SslDecryptSession *ssl, gboolean from_server)
5368 nstime_t gmt_unix_time;
5369 guint8 sessid_length;
5370 proto_tree *rnd_tree;
5376 rnd = &ssl->server_random;
5378 rnd = &ssl->client_random;
5380 /* save provided random for later keyring generation */
5381 tvb_memcpy(tvb, rnd->data, offset, 32);
5384 ssl->state |= SSL_SERVER_RANDOM;
5386 ssl->state |= SSL_CLIENT_RANDOM;
5387 ssl_debug_printf("%s found %s RANDOM -> state 0x%02X\n", G_STRFUNC,
5388 from_server ? "SERVER" : "CLIENT", ssl->state);
5391 rnd_tree = proto_tree_add_subtree(tree, tvb, offset, 32,
5392 hf->ett.hs_random, NULL, "Random");
5395 gmt_unix_time.secs = tvb_get_ntohl(tvb, offset);
5396 gmt_unix_time.nsecs = 0;
5397 proto_tree_add_time(rnd_tree, hf->hf.hs_random_time,
5398 tvb, offset, 4, &gmt_unix_time);
5401 /* show the random bytes */
5402 proto_tree_add_item(rnd_tree, hf->hf.hs_random_bytes,
5403 tvb, offset, 28, ENC_NA);
5406 /* show the session id (length followed by actual Session ID) */
5407 sessid_length = tvb_get_guint8(tvb, offset);
5408 proto_tree_add_item(tree, hf->hf.hs_session_id_len,
5409 tvb, offset, 1, ENC_BIG_ENDIAN);
5413 /* save the authorative SID for later use in ChangeCipherSpec.
5414 * (D)TLS restricts the SID to 32 chars, it does not make sense to
5415 * save more, so ignore larger ones. */
5416 if (from_server && sessid_length <= 32) {
5417 tvb_memcpy(tvb, ssl->session_id.data, offset, sessid_length);
5418 ssl->session_id.data_len = sessid_length;
5421 if (sessid_length > 0) {
5422 proto_tree_add_item(tree, hf->hf.hs_session_id,
5423 tvb, offset, sessid_length, ENC_NA);
5424 offset += sessid_length;
5432 ssl_dissect_hnd_hello_ext(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5433 packet_info* pinfo, guint32 offset, guint32 left, gboolean is_client,
5434 SslSession *session, SslDecryptSession *ssl);
5437 ssl_dissect_hnd_cli_hello(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5438 packet_info *pinfo, proto_tree *tree, guint32 offset,
5439 guint32 length, SslSession *session,
5440 SslDecryptSession *ssl, dtls_hfs_t *dtls_hfs)
5443 * ProtocolVersion client_version;
5445 * SessionID session_id;
5446 * opaque cookie<0..32>; //new field for DTLS
5447 * CipherSuite cipher_suites<2..2^16-1>;
5448 * CompressionMethod compression_methods<1..2^8-1>;
5449 * Extension client_hello_extension_list<0..2^16-1>;
5454 proto_tree *cs_tree;
5455 guint16 cipher_suite_length;
5456 guint8 compression_methods_length;
5457 guint8 compression_method;
5458 guint16 start_offset = offset;
5460 /* show the client version */
5461 proto_tree_add_item(tree, hf->hf.hs_client_version, tvb,
5462 offset, 2, ENC_BIG_ENDIAN);
5465 /* dissect fields that are also present in ClientHello */
5466 offset = ssl_dissect_hnd_hello_common(hf, tvb, tree, offset, ssl, FALSE);
5468 /* fields specific for DTLS (cookie_len, cookie) */
5469 if (dtls_hfs != NULL) {
5470 /* look for a cookie */
5471 guint8 cookie_length = tvb_get_guint8(tvb, offset);
5473 proto_tree_add_uint(tree, dtls_hfs->hf_dtls_handshake_cookie_len,
5474 tvb, offset, 1, cookie_length);
5476 if (cookie_length > 0) {
5477 proto_tree_add_item(tree, dtls_hfs->hf_dtls_handshake_cookie,
5478 tvb, offset, cookie_length, ENC_NA);
5479 offset += cookie_length;
5483 /* tell the user how many cipher suites there are */
5484 cipher_suite_length = tvb_get_ntohs(tvb, offset);
5485 ti = proto_tree_add_item(tree, hf->hf.hs_cipher_suites_len,
5486 tvb, offset, 2, ENC_BIG_ENDIAN);
5488 if (cipher_suite_length > 0) {
5489 if (cipher_suite_length % 2) {
5490 expert_add_info_format(pinfo, ti, &hf->ei.hs_cipher_suites_len_bad,
5491 "Cipher suite length (%d) must be a multiple of 2",
5492 cipher_suite_length);
5495 ti = proto_tree_add_none_format(tree,
5496 hf->hf.hs_cipher_suites,
5497 tvb, offset, cipher_suite_length,
5498 "Cipher Suites (%d suite%s)",
5499 cipher_suite_length / 2,
5500 plurality(cipher_suite_length/2, "", "s"));
5502 /* make this a subtree */
5503 cs_tree = proto_item_add_subtree(ti, hf->ett.cipher_suites);
5505 while (cipher_suite_length > 0) {
5506 proto_tree_add_item(cs_tree, hf->hf.hs_cipher_suite,
5507 tvb, offset, 2, ENC_BIG_ENDIAN);
5509 cipher_suite_length -= 2;
5512 /* tell the user how many compression methods there are */
5513 compression_methods_length = tvb_get_guint8(tvb, offset);
5514 proto_tree_add_uint(tree, hf->hf.hs_comp_methods_len,
5515 tvb, offset, 1, compression_methods_length);
5517 if (compression_methods_length > 0) {
5518 ti = proto_tree_add_none_format(tree,
5519 hf->hf.hs_comp_methods,
5520 tvb, offset, compression_methods_length,
5521 "Compression Methods (%u method%s)",
5522 compression_methods_length,
5523 plurality(compression_methods_length,
5526 /* make this a subtree */
5527 cs_tree = proto_item_add_subtree(ti, hf->ett.comp_methods);
5529 while (compression_methods_length > 0) {
5530 compression_method = tvb_get_guint8(tvb, offset);
5531 /* TODO: make reserved/private comp meth. fields selectable */
5532 if (compression_method < 64)
5533 proto_tree_add_uint(cs_tree, hf->hf.hs_comp_method,
5534 tvb, offset, 1, compression_method);
5535 else if (compression_method > 63 && compression_method < 193)
5536 proto_tree_add_uint_format_value(cs_tree, hf->hf.hs_comp_method, tvb, offset, 1,
5537 compression_method, "Reserved - to be assigned by IANA (%u)",
5538 compression_method);
5540 proto_tree_add_uint_format_value(cs_tree, hf->hf.hs_comp_method, tvb, offset, 1,
5541 compression_method, "Private use range (%u)",
5542 compression_method);
5544 compression_methods_length--;
5547 if (length > offset - start_offset) {
5548 ssl_dissect_hnd_hello_ext(hf, tvb, tree, pinfo, offset,
5549 length - (offset - start_offset), TRUE,
5555 ssl_dissect_hnd_srv_hello(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5556 packet_info* pinfo, proto_tree *tree, guint32 offset, guint32 length,
5557 SslSession *session, SslDecryptSession *ssl)
5560 * ProtocolVersion server_version;
5562 * SessionID session_id;
5563 * CipherSuite cipher_suite;
5564 * CompressionMethod compression_method;
5565 * Extension server_hello_extension_list<0..2^16-1>;
5568 guint16 start_offset = offset;
5570 /* show the server version */
5571 proto_tree_add_item(tree, hf->hf.hs_server_version, tvb,
5572 offset, 2, ENC_BIG_ENDIAN);
5575 /* dissect fields that are also present in ClientHello */
5576 offset = ssl_dissect_hnd_hello_common(hf, tvb, tree, offset, ssl, TRUE);
5579 /* store selected cipher suite for decryption */
5580 ssl->session.cipher = tvb_get_ntohs(tvb, offset);
5582 if (ssl_find_cipher(ssl->session.cipher, &ssl->cipher_suite) < 0) {
5583 ssl_debug_printf("%s can't find cipher suite 0x%04X\n",
5584 G_STRFUNC, ssl->session.cipher);
5586 /* Cipher found, save this for the delayed decoder init */
5587 ssl->state |= SSL_CIPHER;
5588 ssl_debug_printf("%s found CIPHER 0x%04X -> state 0x%02X\n",
5589 G_STRFUNC, ssl->session.cipher, ssl->state);
5593 /* now the server-selected cipher suite */
5594 proto_tree_add_item(tree, hf->hf.hs_cipher_suite,
5595 tvb, offset, 2, ENC_BIG_ENDIAN);
5599 /* store selected compression method for decryption */
5600 ssl->session.compression = tvb_get_guint8(tvb, offset);
5602 /* and the server-selected compression method */
5603 proto_tree_add_item(tree, hf->hf.hs_comp_method,
5604 tvb, offset, 1, ENC_BIG_ENDIAN);
5607 /* remaining data are extensions */
5608 if (length > offset - start_offset) {
5609 ssl_dissect_hnd_hello_ext(hf, tvb, tree, pinfo, offset,
5610 length - (offset - start_offset), FALSE,
5616 ssl_dissect_hnd_new_ses_ticket(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5617 proto_tree *tree, guint32 offset,
5618 SslDecryptSession *ssl,
5619 GHashTable *session_hash)
5621 proto_tree *subtree;
5624 /* length of session ticket, may be 0 if the server has sent the
5625 * SessionTicket extension, but decides not to use one. */
5626 ticket_len = tvb_get_ntohs(tvb, offset + 4);
5627 subtree = proto_tree_add_subtree(tree, tvb, offset, 6 + ticket_len,
5628 hf->ett.session_ticket, NULL,
5629 "TLS Session Ticket");
5631 /* ticket lifetime hint */
5632 proto_tree_add_item(subtree, hf->hf.hs_session_ticket_lifetime_hint,
5633 tvb, offset, 4, ENC_BIG_ENDIAN);
5636 /* opaque ticket (length, data) */
5637 proto_tree_add_item(subtree, hf->hf.hs_session_ticket_len,
5638 tvb, offset, 2, ENC_BIG_ENDIAN);
5640 /* Content depends on implementation, so just show data! */
5641 proto_tree_add_item(subtree, hf->hf.hs_session_ticket,
5642 tvb, offset, ticket_len, ENC_NA);
5643 /* save the session ticket to cache for ssl_finalize_decryption */
5645 tvb_ensure_bytes_exist(tvb, offset, ticket_len);
5646 ssl->session_ticket.data = (guchar*)wmem_realloc(wmem_file_scope(),
5647 ssl->session_ticket.data, ticket_len);
5648 ssl->session_ticket.data_len = ticket_len;
5649 tvb_memcpy(tvb, ssl->session_ticket.data, offset, ticket_len);
5650 /* NewSessionTicket is received after the first (client)
5651 * ChangeCipherSpec, and before the second (server) ChangeCipherSpec.
5652 * Since the second CCS has already the session key available it will
5653 * just return. To ensure that the session ticket is mapped to a
5654 * master key (from the first CCS), save the ticket here too. */
5655 ssl_save_master_key("Session Ticket", session_hash,
5656 &ssl->session_ticket, &ssl->master_secret);
5661 ssl_dissect_hnd_cert(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5662 guint32 offset, packet_info *pinfo,
5663 const SslSession *session, gint is_from_server)
5665 /* opaque ASN.1Cert<2^24-1>;
5668 * ASN.1Cert certificate_list<1..2^24-1>;
5671 guint32 certificate_list_length;
5673 proto_tree *subtree;
5674 asn1_ctx_t asn1_ctx;
5679 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
5681 certificate_list_length = tvb_get_ntoh24(tvb, offset);
5682 proto_tree_add_uint(tree, hf->hf.hs_certificates_len,
5683 tvb, offset, 3, certificate_list_length);
5684 offset += 3; /* 24-bit length value */
5686 if (certificate_list_length > 0) {
5687 ti = proto_tree_add_none_format(tree,
5688 hf->hf.hs_certificates,
5689 tvb, offset, certificate_list_length,
5690 "Certificates (%u bytes)",
5691 certificate_list_length);
5693 /* make it a subtree */
5694 subtree = proto_item_add_subtree(ti, hf->ett.certificates);
5696 /* iterate through each certificate */
5697 while (certificate_list_length > 0) {
5698 /* get the length of the current certificate */
5699 guint32 cert_length;
5700 cert_length = tvb_get_ntoh24(tvb, offset);
5701 certificate_list_length -= 3 + cert_length;
5703 proto_tree_add_item(subtree, hf->hf.hs_certificate_len,
5704 tvb, offset, 3, ENC_BIG_ENDIAN);
5707 if ((is_from_server && session->server_cert_type == SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY) ||
5708 (!is_from_server && session->client_cert_type == SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY)) {
5709 dissect_x509af_SubjectPublicKeyInfo(FALSE, tvb, offset, &asn1_ctx, subtree, hf->hf.hs_certificate);
5711 dissect_x509af_Certificate(FALSE, tvb, offset, &asn1_ctx, subtree, hf->hf.hs_certificate);
5714 offset += cert_length;
5720 ssl_dissect_hnd_cert_req(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5721 proto_tree *tree, guint32 offset, packet_info *pinfo,
5722 const SslSession *session)
5726 * rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
5728 * } ClientCertificateType;
5730 * opaque DistinguishedName<1..2^16-1>;
5733 * ClientCertificateType certificate_types<1..2^8-1>;
5734 * DistinguishedName certificate_authorities<3..2^16-1>;
5735 * } CertificateRequest;
5738 * As per TLSv1.2 (RFC 5246) the format has changed to:
5741 * rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
5742 * rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
5743 * fortezza_dms_RESERVED(20), (255)
5744 * } ClientCertificateType;
5747 * none(0), md5(1), sha1(2), sha224(3), sha256(4), sha384(5),
5751 * enum { anonymous(0), rsa(1), dsa(2), ecdsa(3), (255) }
5752 * SignatureAlgorithm;
5755 * HashAlgorithm hash;
5756 * SignatureAlgorithm signature;
5757 * } SignatureAndHashAlgorithm;
5759 * SignatureAndHashAlgorithm
5760 * supported_signature_algorithms<2..2^16-2>;
5762 * opaque DistinguishedName<1..2^16-1>;
5765 * ClientCertificateType certificate_types<1..2^8-1>;
5766 * SignatureAndHashAlgorithm
5767 * supported_signature_algorithms<2^16-1>;
5768 * DistinguishedName certificate_authorities<0..2^16-1>;
5769 * } CertificateRequest;
5773 proto_tree *subtree;
5774 guint8 cert_types_count;
5777 asn1_ctx_t asn1_ctx;
5783 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
5785 cert_types_count = tvb_get_guint8(tvb, offset);
5786 proto_tree_add_uint(tree, hf->hf.hs_cert_types_count,
5787 tvb, offset, 1, cert_types_count);
5790 if (cert_types_count > 0) {
5791 ti = proto_tree_add_none_format(tree,
5792 hf->hf.hs_cert_types,
5793 tvb, offset, cert_types_count,
5794 "Certificate types (%u type%s)",
5796 plurality(cert_types_count, "", "s"));
5797 subtree = proto_item_add_subtree(ti, hf->ett.cert_types);
5799 while (cert_types_count > 0) {
5800 proto_tree_add_item(subtree, hf->hf.hs_cert_type,
5801 tvb, offset, 1, ENC_BIG_ENDIAN);
5807 switch (session->version) {
5808 case SSL_VER_TLSv1DOT2:
5809 case SSL_VER_DTLS1DOT2:
5810 sh_alg_length = tvb_get_ntohs(tvb, offset);
5811 if (sh_alg_length % 2) {
5812 expert_add_info_format(pinfo, NULL,
5813 &hf->ei.hs_sig_hash_alg_len_bad,
5814 "Signature Hash Algorithm length (%d) must be a multiple of 2",
5819 proto_tree_add_uint(tree, hf->hf.hs_sig_hash_alg_len,
5820 tvb, offset, 2, sh_alg_length);
5823 ret = ssl_dissect_hash_alg_list(hf, tvb, tree, pinfo, offset, sh_alg_length);
5832 dnames_length = tvb_get_ntohs(tvb, offset);
5833 proto_tree_add_uint(tree, hf->hf.hs_dnames_len,
5834 tvb, offset, 2, dnames_length);
5837 if (dnames_length > 0) {
5838 ti = proto_tree_add_none_format(tree,
5840 tvb, offset, dnames_length,
5841 "Distinguished Names (%d byte%s)",
5843 plurality(dnames_length, "", "s"));
5844 subtree = proto_item_add_subtree(ti, hf->ett.dnames);
5846 while (dnames_length > 0) {
5847 /* get the length of the current certificate */
5848 guint16 name_length;
5849 name_length = tvb_get_ntohs(tvb, offset);
5850 dnames_length -= 2 + name_length;
5852 proto_tree_add_item(subtree, hf->hf.hs_dname_len,
5853 tvb, offset, 2, ENC_BIG_ENDIAN);
5856 dissect_x509if_DistinguishedName(FALSE, tvb, offset, &asn1_ctx,
5857 subtree, hf->hf.hs_dname);
5858 offset += name_length;
5864 ssl_dissect_digitally_signed(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5865 proto_tree *tree, guint32 offset,
5866 const SslSession *session,
5867 gint hf_sig_len, gint hf_sig);
5870 ssl_dissect_hnd_cli_cert_verify(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5871 proto_tree *tree, guint32 offset,
5872 const SslSession *session)
5874 ssl_dissect_digitally_signed(hf, tvb, tree, offset, session,
5875 hf->hf.hs_client_cert_vrfy_sig_len,
5876 hf->hf.hs_client_cert_vrfy_sig);
5880 ssl_dissect_hnd_finished(ssl_common_dissect_t *hf, tvbuff_t *tvb,
5881 proto_tree *tree, guint32 offset,
5882 const SslSession *session, ssl_hfs_t *ssl_hfs)
5886 * opaque md5_hash[16];
5887 * opaque sha_hash[20];
5892 * opaque verify_data[12];
5898 if (session->version == SSL_VER_SSLv3) {
5899 if (ssl_hfs != NULL) {
5900 proto_tree_add_item(tree, ssl_hfs->hs_md5_hash,
5901 tvb, offset, 16, ENC_NA);
5902 proto_tree_add_item(tree, ssl_hfs->hs_sha_hash,
5903 tvb, offset + 16, 20, ENC_NA);
5906 proto_tree_add_item(tree, hf->hf.hs_finished,
5907 tvb, offset, 12, ENC_NA);
5912 ssl_dissect_hnd_cert_url(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree, guint32 offset)
5914 guint16 url_hash_len;
5917 * individual_certs(0), pkipath(1), (255)
5921 * CertChainType type;
5922 * URLAndHash url_and_hash_list<1..2^16-1>;
5926 * opaque url<1..2^16-1>;
5928 * opaque SHA1Hash[20];
5932 proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_type,
5933 tvb, offset, 1, ENC_NA);
5936 url_hash_len = tvb_get_ntohs(tvb, offset);
5937 proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_url_hash_list_len,
5938 tvb, offset, 2, ENC_BIG_ENDIAN);
5940 while (url_hash_len-- > 0) {
5941 proto_item *urlhash_item;
5942 proto_tree *urlhash_tree;
5945 urlhash_item = proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_item,
5946 tvb, offset, -1, ENC_NA);
5947 urlhash_tree = proto_item_add_subtree(urlhash_item, hf->ett.urlhash);
5949 url_len = tvb_get_ntohs(tvb, offset);
5950 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_url_len,
5951 tvb, offset, 2, ENC_BIG_ENDIAN);
5954 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_url,
5955 tvb, offset, url_len, ENC_ASCII|ENC_NA);
5958 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_padding,
5959 tvb, offset, 1, ENC_NA);
5961 /* Note: RFC 6066 says that padding must be 0x01 */
5963 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_sha1,
5964 tvb, offset, 20, ENC_NA);
5970 ssl_dissect_hnd_hello_ext_status_request(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
5971 guint32 offset, gboolean has_length)
5973 guint cert_status_type;
5975 cert_status_type = tvb_get_guint8(tvb, offset);
5976 proto_tree_add_item(tree, hf->hf.hs_ext_cert_status_type,
5977 tvb, offset, 1, ENC_NA);
5981 proto_tree_add_item(tree, hf->hf.hs_ext_cert_status_request_len,
5982 tvb, offset, 2, ENC_BIG_ENDIAN);
5986 switch (cert_status_type) {
5987 case SSL_HND_CERT_STATUS_TYPE_OCSP:
5988 case SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI:
5990 guint16 responder_id_list_len;
5991 guint16 request_extensions_len;
5992 proto_item *responder_id;
5993 proto_item *request_extensions;
5995 responder_id_list_len = tvb_get_ntohs(tvb, offset);
5997 proto_tree_add_item(tree,
5998 hf->hf.hs_ext_cert_status_responder_id_list_len,
5999 tvb, offset, 2, ENC_BIG_ENDIAN);
6001 if (responder_id_list_len != 0) {
6002 expert_add_info_format(NULL, responder_id,
6003 &hf->ei.hs_ext_cert_status_undecoded,
6004 "Responder ID list is not implemented, contact Wireshark"
6005 " developers if you want this to be supported");
6006 /* Non-empty responder ID list would mess with extensions. */
6010 request_extensions_len = tvb_get_ntohs(tvb, offset);
6011 request_extensions =
6012 proto_tree_add_item(tree,
6013 hf->hf.hs_ext_cert_status_request_extensions_len, tvb, offset,
6016 if (request_extensions_len != 0)
6017 expert_add_info_format(NULL, request_extensions,
6018 &hf->ei.hs_ext_cert_status_undecoded,
6019 "Request Extensions are not implemented, contact"
6020 " Wireshark developers if you want this to be supported");
6029 ssl_dissect_hnd_hello_ext_status_request_v2(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
6034 list_len = tvb_get_ntohs(tvb, offset);
6037 while (list_len > 0) {
6038 guint32 prev_offset = offset;
6039 offset = ssl_dissect_hnd_hello_ext_status_request(hf, tvb, tree, offset, TRUE);
6040 list_len -= (offset - prev_offset);
6047 ssl_dissect_hnd_hello_ext_elliptic_curves(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6048 proto_tree *tree, guint32 offset)
6050 guint16 curves_length;
6051 proto_tree *curves_tree;
6054 curves_length = tvb_get_ntohs(tvb, offset);
6055 proto_tree_add_item(tree, hf->hf.hs_ext_elliptic_curves_len,
6056 tvb, offset, 2, ENC_BIG_ENDIAN);
6059 ti = proto_tree_add_none_format(tree,
6060 hf->hf.hs_ext_elliptic_curves,
6061 tvb, offset, curves_length,
6062 "Elliptic curves (%d curve%s)",
6064 plurality(curves_length/2, "", "s"));
6066 /* make this a subtree */
6067 curves_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_curves);
6069 /* loop over all curves */
6070 while (curves_length > 0)
6072 proto_tree_add_item(curves_tree, hf->hf.hs_ext_elliptic_curve, tvb, offset, 2, ENC_BIG_ENDIAN);
6081 ssl_dissect_hnd_hello_ext_ec_point_formats(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6082 proto_tree *tree, guint32 offset)
6085 proto_tree *ecpf_tree;
6088 ecpf_length = tvb_get_guint8(tvb, offset);
6089 proto_tree_add_item(tree, hf->hf.hs_ext_ec_point_formats_len,
6090 tvb, offset, 1, ENC_BIG_ENDIAN);
6093 ti = proto_tree_add_none_format(tree,
6094 hf->hf.hs_ext_elliptic_curves,
6095 tvb, offset, ecpf_length,
6096 "Elliptic curves point formats (%d)",
6099 /* make this a subtree */
6100 ecpf_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_curves_point_formats);
6102 /* loop over all point formats */
6103 while (ecpf_length > 0)
6105 proto_tree_add_item(ecpf_tree, hf->hf.hs_ext_ec_point_format, tvb, offset, 1, ENC_BIG_ENDIAN);
6114 ssl_dissect_hnd_hello_ext(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
6115 packet_info* pinfo, guint32 offset, guint32 left, gboolean is_client,
6116 SslSession *session, SslDecryptSession *ssl)
6118 guint16 extension_length;
6121 proto_tree *ext_tree;
6126 extension_length = tvb_get_ntohs(tvb, offset);
6127 proto_tree_add_uint(tree, hf->hf.hs_exts_len,
6128 tvb, offset, 2, extension_length);
6134 ext_type = tvb_get_ntohs(tvb, offset);
6135 ext_len = tvb_get_ntohs(tvb, offset + 2);
6137 ext_tree = proto_tree_add_subtree_format(tree, tvb, offset, 4 + ext_len, hf->ett.hs_ext, NULL,
6138 "Extension: %s", val_to_str(ext_type,
6139 tls_hello_extension_types,
6142 proto_tree_add_uint(ext_tree, hf->hf.hs_ext_type,
6143 tvb, offset, 2, ext_type);
6146 proto_tree_add_uint(ext_tree, hf->hf.hs_ext_len,
6147 tvb, offset, 2, ext_len);
6151 case SSL_HND_HELLO_EXT_STATUS_REQUEST:
6153 offset = ssl_dissect_hnd_hello_ext_status_request(hf, tvb, ext_tree, offset, FALSE);
6155 offset += ext_len; /* server must return empty extension_data */
6157 case SSL_HND_HELLO_EXT_STATUS_REQUEST_V2:
6159 offset = ssl_dissect_hnd_hello_ext_status_request_v2(hf, tvb, ext_tree, offset);
6161 offset += ext_len; /* server must return empty extension_data */
6163 case SSL_HND_HELLO_EXT_ELLIPTIC_CURVES:
6164 offset = ssl_dissect_hnd_hello_ext_elliptic_curves(hf, tvb, ext_tree, offset);
6166 case SSL_HND_HELLO_EXT_EC_POINT_FORMATS:
6167 offset = ssl_dissect_hnd_hello_ext_ec_point_formats(hf, tvb, ext_tree, offset);
6169 case SSL_HND_HELLO_EXT_SIG_HASH_ALGS:
6170 offset = ssl_dissect_hnd_hello_ext_sig_hash_algs(hf, tvb, ext_tree, pinfo, offset, ext_len);
6172 case SSL_HND_HELLO_EXT_ALPN:
6173 offset = ssl_dissect_hnd_hello_ext_alpn(hf, tvb, ext_tree, offset, ext_len, is_client, session);
6175 case SSL_HND_HELLO_EXT_NPN:
6176 offset = ssl_dissect_hnd_hello_ext_npn(hf, tvb, ext_tree, offset, ext_len);
6178 case SSL_HND_HELLO_EXT_RENEG_INFO:
6179 offset = ssl_dissect_hnd_hello_ext_reneg_info(hf, tvb, ext_tree, offset, ext_len);
6181 case SSL_HND_HELLO_EXT_SERVER_NAME:
6182 offset = ssl_dissect_hnd_hello_ext_server_name(hf, tvb, ext_tree, offset, ext_len);
6184 case SSL_HND_HELLO_EXT_HEARTBEAT:
6185 proto_tree_add_item(ext_tree, hf->hf.hs_ext_heartbeat_mode,
6186 tvb, offset, 1, ENC_BIG_ENDIAN);
6189 case SSL_HND_HELLO_EXT_PADDING:
6190 offset = ssl_dissect_hnd_hello_ext_padding(hf, tvb, ext_tree, offset, ext_len);
6192 case SSL_HND_HELLO_EXT_SESSION_TICKET:
6193 offset = ssl_dissect_hnd_hello_ext_session_ticket(hf, tvb, ext_tree, offset, ext_len, is_client, ssl);
6195 case SSL_HND_HELLO_EXT_CERT_TYPE:
6196 case SSL_HND_HELLO_EXT_SERVER_CERT_TYPE:
6197 case SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE:
6198 offset = ssl_dissect_hnd_hello_ext_cert_type(hf, tvb, ext_tree,
6200 is_client, ext_type,
6203 case SSL_HND_HELLO_EXT_EXTENDED_MASTER_SECRET_TYPE:
6205 ssl->state |= (is_client ? SSL_CLIENT_EXTENDED_MASTER_SECRET : SSL_SERVER_EXTENDED_MASTER_SECRET);
6208 proto_tree_add_bytes_format(ext_tree, hf->hf.hs_ext_data,
6209 tvb, offset, ext_len, NULL,
6211 ext_len, plurality(ext_len, "", "s"));
6216 left -= 2 + 2 + ext_len;
6223 /* ClientKeyExchange algo-specific dissectors */
6226 dissect_ssl3_hnd_cli_keyex_ecdh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6227 proto_tree *tree, guint32 offset,
6231 proto_tree *ssl_ecdh_tree;
6233 ssl_ecdh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6234 hf->ett.keyex_params, NULL, "EC Diffie-Hellman Client Params");
6237 point_len = tvb_get_guint8(tvb, offset);
6238 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_client_keyex_point_len, tvb,
6239 offset, 1, ENC_BIG_ENDIAN);
6240 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_client_keyex_point, tvb,
6241 offset + 1, point_len, ENC_NA);
6245 dissect_ssl3_hnd_cli_keyex_dh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6246 proto_tree *tree, guint32 offset, guint32 length)
6249 proto_tree *ssl_dh_tree;
6251 ssl_dh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6252 hf->ett.keyex_params, NULL, "Diffie-Hellman Client Params");
6254 /* ClientDiffieHellmanPublic.dh_public (explicit) */
6255 yc_len = tvb_get_ntohs(tvb, offset);
6256 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_client_keyex_yc_len, tvb,
6257 offset, 2, ENC_BIG_ENDIAN);
6258 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_client_keyex_yc, tvb,
6259 offset + 2, yc_len, ENC_NA);
6263 dissect_ssl3_hnd_cli_keyex_rsa(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6264 proto_tree *tree, guint32 offset,
6265 guint32 length, const SslSession *session)
6268 proto_tree *ssl_rsa_tree;
6270 ssl_rsa_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6271 hf->ett.keyex_params, NULL, "RSA Encrypted PreMaster Secret");
6273 /* EncryptedPreMasterSecret.pre_master_secret */
6274 switch (session->version) {
6277 case SSL_VER_DTLS_OPENSSL:
6278 /* OpenSSL pre-0.9.8f DTLS and pre-TLS quirk: 2-octet length vector is
6279 * not present. The handshake contents represents the EPMS, see:
6280 * https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10222 */
6285 /* TLS and DTLS include vector length before EPMS */
6286 epms_len = tvb_get_ntohs(tvb, offset);
6287 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_client_keyex_epms_len, tvb,
6288 offset, 2, ENC_BIG_ENDIAN);
6292 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_client_keyex_epms, tvb,
6293 offset, epms_len, ENC_NA);
6296 /* Used in PSK cipher suites */
6298 dissect_ssl3_hnd_cli_keyex_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6299 proto_tree *tree, guint32 offset, guint32 length)
6302 proto_tree *ssl_psk_tree;
6304 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6305 hf->ett.keyex_params, NULL, "PSK Client Params");
6307 identity_len = tvb_get_ntohs(tvb, offset);
6308 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity_len, tvb,
6309 offset, 2, ENC_BIG_ENDIAN);
6310 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity, tvb,
6311 offset + 2, identity_len, ENC_NA);
6314 /* Used in RSA PSK cipher suites */
6316 dissect_ssl3_hnd_cli_keyex_rsa_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6317 proto_tree *tree, guint32 offset,
6320 gint identity_len, epms_len;
6321 proto_tree *ssl_psk_tree;
6323 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6324 hf->ett.keyex_params, NULL, "RSA PSK Client Params");
6327 identity_len = tvb_get_ntohs(tvb, offset);
6328 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity_len,
6329 tvb, offset, 2, ENC_BIG_ENDIAN);
6330 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity,
6331 tvb, offset + 2, identity_len, ENC_NA);
6332 offset += 2 + identity_len;
6335 epms_len = tvb_get_ntohs(tvb, offset);
6336 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_epms_len, tvb,
6337 offset, 2, ENC_BIG_ENDIAN);
6338 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_epms, tvb,
6339 offset + 2, epms_len, ENC_NA);
6343 /* Dissects DigitallySigned (see RFC 5246 4.7 Cryptographic Attributes). */
6345 ssl_dissect_digitally_signed(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6346 proto_tree *tree, guint32 offset,
6347 const SslSession *session,
6348 gint hf_sig_len, gint hf_sig)
6351 proto_item *ti_algo;
6352 proto_tree *ssl_algo_tree;
6354 switch (session->version) {
6355 case SSL_VER_TLSv1DOT2:
6356 case SSL_VER_DTLS1DOT2:
6357 ti_algo = proto_tree_add_item(tree, hf->hf.hs_sig_hash_alg, tvb,
6358 offset, 2, ENC_BIG_ENDIAN);
6359 ssl_algo_tree = proto_item_add_subtree(ti_algo, hf->ett.hs_sig_hash_alg);
6361 /* SignatureAndHashAlgorithm { hash, signature } */
6362 proto_tree_add_item(ssl_algo_tree, hf->hf.hs_sig_hash_hash, tvb,
6363 offset, 1, ENC_BIG_ENDIAN);
6364 proto_tree_add_item(ssl_algo_tree, hf->hf.hs_sig_hash_sig, tvb,
6365 offset + 1, 1, ENC_BIG_ENDIAN);
6374 sig_len = tvb_get_ntohs(tvb, offset);
6375 proto_tree_add_item(tree, hf_sig_len, tvb, offset, 2, ENC_BIG_ENDIAN);
6376 proto_tree_add_item(tree, hf_sig, tvb, offset + 2, sig_len, ENC_NA);
6379 /* ServerKeyExchange algo-specific dissectors */
6381 /* dissects signed_params inside a ServerKeyExchange for some keyex algos */
6383 dissect_ssl3_hnd_srv_keyex_sig(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6384 proto_tree *tree, guint32 offset,
6385 const SslSession *session)
6388 * TLSv1.2 (RFC 5246 sec 7.4.8)
6390 * digitally-signed struct {
6391 * opaque handshake_messages[handshake_messages_length];
6393 * } CertificateVerify;
6395 * TLSv1.0/TLSv1.1 (RFC 5436 sec 7.4.8 and 7.4.3) works essentially the same
6396 * as TLSv1.2, but the hash algorithms are not explicit in digitally-signed.
6398 * SSLv3 (RFC 6101 sec 5.6.8) esseentially works the same as TLSv1.0 but it
6399 * does more hashing including the master secret and padding.
6401 ssl_dissect_digitally_signed(hf, tvb, tree, offset, session,
6402 hf->hf.hs_server_keyex_sig_len,
6403 hf->hf.hs_server_keyex_sig);
6407 dissect_ssl3_hnd_srv_keyex_ecdh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6408 proto_tree *tree, guint32 offset,
6409 guint32 length, const SslSession *session)
6412 * RFC 4492 ECC cipher suites for TLS
6415 * ECCurveType curve_type;
6416 * select (curve_type) {
6417 * case explicit_prime:
6419 * case explicit_char2:
6422 * NamedCurve namedcurve;
6427 * opaque point <1..2^8-1>;
6431 * ECParameters curve_params;
6433 * } ServerECDHParams;
6435 * select (KeyExchangeAlgorithm) {
6436 * case ec_diffie_hellman:
6437 * ServerECDHParams params;
6438 * Signature signed_params;
6439 * } ServerKeyExchange;
6444 proto_tree *ssl_ecdh_tree;
6446 ssl_ecdh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6447 hf->ett.keyex_params, NULL, "EC Diffie-Hellman Server Params");
6449 /* ECParameters.curve_type */
6450 curve_type = tvb_get_guint8(tvb, offset);
6451 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_curve_type, tvb,
6452 offset, 1, ENC_BIG_ENDIAN);
6454 if (curve_type != 3)
6455 return; /* only named_curves are supported */
6457 /* case curve_type == named_curve; ECParameters.namedcurve */
6458 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_named_curve, tvb,
6459 offset, 2, ENC_BIG_ENDIAN);
6463 point_len = tvb_get_guint8(tvb, offset);
6464 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_point_len, tvb,
6465 offset, 1, ENC_BIG_ENDIAN);
6466 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_point, tvb,
6467 offset + 1, point_len, ENC_NA);
6468 offset += 1 + point_len;
6471 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_ecdh_tree, offset, session);
6475 dissect_ssl3_hnd_srv_keyex_dhe(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6476 proto_tree *tree, guint32 offset, guint32 length,
6477 const SslSession *session)
6479 gint p_len, g_len, ys_len;
6480 proto_tree *ssl_dh_tree;
6482 ssl_dh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6483 hf->ett.keyex_params, NULL, "Diffie-Hellman Server Params");
6486 p_len = tvb_get_ntohs(tvb, offset);
6487 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_p_len, tvb,
6488 offset, 2, ENC_BIG_ENDIAN);
6489 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_p, tvb,
6490 offset + 2, p_len, ENC_NA);
6491 offset += 2 + p_len;
6494 g_len = tvb_get_ntohs(tvb, offset);
6495 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_g_len, tvb,
6496 offset, 2, ENC_BIG_ENDIAN);
6497 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_g, tvb,
6498 offset + 2, g_len, ENC_NA);
6499 offset += 2 + g_len;
6502 ys_len = tvb_get_ntohs(tvb, offset);
6503 proto_tree_add_uint(ssl_dh_tree, hf->hf.hs_server_keyex_ys_len, tvb,
6505 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_ys, tvb,
6506 offset + 2, ys_len, ENC_NA);
6507 offset += 2 + ys_len;
6510 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_dh_tree, offset, session);
6513 /* Only used in RSA-EXPORT cipher suites */
6515 dissect_ssl3_hnd_srv_keyex_rsa(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6516 proto_tree *tree, guint32 offset, guint32 length,
6517 const SslSession *session)
6519 gint modulus_len, exponent_len;
6520 proto_tree *ssl_rsa_tree;
6522 ssl_rsa_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6523 hf->ett.keyex_params, NULL, "RSA-EXPORT Server Params");
6526 modulus_len = tvb_get_ntohs(tvb, offset);
6527 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_modulus_len, tvb,
6528 offset, 2, ENC_BIG_ENDIAN);
6529 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_modulus, tvb,
6530 offset + 2, modulus_len, ENC_NA);
6531 offset += 2 + modulus_len;
6534 exponent_len = tvb_get_ntohs(tvb, offset);
6535 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_exponent_len,
6536 tvb, offset, 2, ENC_BIG_ENDIAN);
6537 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_exponent,
6538 tvb, offset + 2, exponent_len, ENC_NA);
6539 offset += 2 + exponent_len;
6542 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, ssl_rsa_tree, offset, session);
6545 /* Used in RSA PSK and PSK cipher suites */
6547 dissect_ssl3_hnd_srv_keyex_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6548 proto_tree *tree, guint32 offset, guint32 length)
6551 proto_tree *ssl_psk_tree;
6553 hint_len = tvb_get_ntohs(tvb, offset);
6554 if ((2 + hint_len) != length) {
6555 /* Lengths don't line up (wasn't what we expected?) */
6559 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
6560 hf->ett.keyex_params, NULL, "PSK Server Params");
6563 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_server_keyex_hint_len, tvb,
6564 offset, 2, ENC_BIG_ENDIAN);
6565 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_server_keyex_hint, tvb,
6566 offset + 2, hint_len, ENC_NA);
6571 ssl_dissect_hnd_cli_keyex(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6572 proto_tree *tree, guint32 offset, guint32 length,
6573 const SslSession *session)
6575 switch (ssl_get_keyex_alg(session->cipher)) {
6576 case KEX_RSA: /* rsa: EncryptedPreMasterSecret */
6577 dissect_ssl3_hnd_cli_keyex_rsa(hf, tvb, tree, offset, length, session);
6579 case KEX_DH: /* DHE_RSA: ClientDiffieHellmanPublic */
6580 /* XXX: DHE_DSS, DH_DSS, DH_RSA, DH_ANON; same format */
6581 dissect_ssl3_hnd_cli_keyex_dh(hf, tvb, tree, offset, length);
6583 case KEX_ECDH: /* ec_diffie_hellman: ClientECDiffieHellmanPublic */
6584 dissect_ssl3_hnd_cli_keyex_ecdh(hf, tvb, tree, offset, length);
6587 dissect_ssl3_hnd_cli_keyex_psk(hf, tvb, tree, offset, length);
6590 dissect_ssl3_hnd_cli_keyex_rsa_psk(hf, tvb, tree, offset, length);
6596 ssl_dissect_hnd_srv_keyex(ssl_common_dissect_t *hf, tvbuff_t *tvb,
6597 proto_tree *tree, guint32 offset, guint32 length,
6598 const SslSession *session)
6600 switch (ssl_get_keyex_alg(session->cipher)) {
6601 case KEX_DH: /* DHE_RSA: ServerDHParams + signature */
6602 /* XXX: DHE_DSS, same format */
6603 /* XXX: DHE_ANON, almost the same, but without signed_params */
6604 dissect_ssl3_hnd_srv_keyex_dhe(hf, tvb, tree, offset, length, session);
6606 case KEX_RSA: /* TLSv1.0 and older: RSA_EXPORT cipher suites */
6607 dissect_ssl3_hnd_srv_keyex_rsa(hf, tvb, tree, offset, length, session);
6609 case KEX_ECDH: /* ec_diffie_hellman: ServerECDHParams + signature */
6610 dissect_ssl3_hnd_srv_keyex_ecdh(hf, tvb, tree, offset, length, session);
6614 dissect_ssl3_hnd_srv_keyex_psk(hf, tvb, tree, offset, length);
6619 #ifdef HAVE_LIBGNUTLS
6621 ssl_common_register_options(module_t *module, ssl_common_options_t *options)
6623 prefs_register_string_preference(module, "psk", "Pre-Shared-Key",
6624 "Pre-Shared-Key as HEX string. Should be 0 to 16 bytes.",
6627 prefs_register_filename_preference(module, "keylog_file", "(Pre)-Master-Secret log filename",
6628 "The name of a file which contains a list of \n"
6629 "(pre-)master secrets in one of the following formats:\n"
6631 "RSA <EPMS> <PMS>\n"
6632 "RSA Session-ID:<SSLID> Master-Key:<MS>\n"
6633 "CLIENT_RANDOM <CRAND> <MS>\n"
6634 "PMS_CLIENT_RANDOM <CRAND> <PMS>\n"
6637 "<EPMS> = First 8 bytes of the Encrypted PMS\n"
6638 "<PMS> = The Pre-Master-Secret (PMS) used to derive the MS\n"
6639 "<SSLID> = The SSL Session ID\n"
6640 "<MS> = The Master-Secret (MS)\n"
6641 "<CRAND> = The Client's random number from the ClientHello message\n"
6643 "(All fields are in hex notation)",
6644 &(options->keylog_filename));
6648 ssl_common_register_options(module_t *module _U_, ssl_common_options_t *options _U_)
6654 ssl_calculate_handshake_hash(SslDecryptSession *ssl_session, tvbuff_t *tvb, guint32 offset, guint32 length)
6656 if (ssl_session && !(ssl_session->state & SSL_MASTER_SECRET)) {
6657 guint32 old_length = ssl_session->handshake_data.data_len;
6658 ssl_debug_printf("Calculating hash with offset %d %d\n", offset, length);
6659 ssl_session->handshake_data.data = (guchar *)wmem_realloc(wmem_file_scope(), ssl_session->handshake_data.data, old_length + length);
6660 tvb_memcpy(tvb, ssl_session->handshake_data.data + old_length, offset, length);
6661 ssl_session->handshake_data.data_len += length;
6667 * Editor modelines - http://www.wireshark.org/tools/modelines.html
6672 * indent-tabs-mode: nil
6675 * vi: set shiftwidth=4 tabstop=8 expandtab:
6676 * :indentSize=4:tabSize=8:noTabs=true: