Bug Summary

File:builds/wireshark/wireshark/epan/dissectors/packet-tls-utils.c
Warning:line 10661, column 17
Access to field 'dig' results in a dereference of a null pointer (loaded from field 'cipher_suite')

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name packet-tls-utils.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-22/lib/clang/22 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /builds/wireshark/wireshark/epan/dissectors -isystem /builds/wireshark/wireshark/build/epan/dissectors -isystem /usr/include/mit-krb5 -isystem /builds/wireshark/wireshark/epan -isystem /usr/include/libxml2 -D CARES_NO_DEPRECATED -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-22/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=gnu17 -ferror-limit 19 -fvisibility=hidden -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /builds/wireshark/wireshark/sbout/2026-11-30-100354-3660-1 -x c /builds/wireshark/wireshark/epan/dissectors/packet-tls-utils.c
1/* packet-tls-utils.c
2 * ssl manipulation functions
3 * By Paolo Abeni <[email protected]>
4 *
5 * Copyright (c) 2013, Hauke Mehrtens <[email protected]>
6 * Copyright (c) 2014, Peter Wu <[email protected]>
7 *
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <[email protected]>
10 * Copyright 1998 Gerald Combs
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 */
14
15#include "config.h"
16
17#include <stdlib.h>
18#include <errno(*__errno_location ()).h>
19
20#include <epan/packet.h>
21#include <epan/strutil.h>
22#include <epan/addr_resolv.h>
23#include <epan/expert.h>
24#include <epan/asn1.h>
25#include <epan/proto_data.h>
26#include <epan/oids.h>
27#include <epan/secrets.h>
28
29#include <wsutil/inet_cidr.h>
30#include <wsutil/filesystem.h>
31#include <wsutil/file_util.h>
32#include <wsutil/str_util.h>
33#include <wsutil/report_message.h>
34#include <wsutil/pint.h>
35#include <wsutil/strtoi.h>
36#include <wsutil/wsgcrypt.h>
37#include <wsutil/rsa.h>
38#include <wsutil/ws_assert.h>
39#include <wsutil/zlib_compat.h>
40#include "conversation.h"
41#include "packet-ber.h"
42#include "packet-x509af.h"
43#include "packet-x509if.h"
44#include "packet-tls-utils.h"
45#include "packet-ocsp.h"
46#include "packet-tls.h"
47#include "packet-dtls.h"
48#include "packet-quic.h"
49#if defined(HAVE_LIBGNUTLS1)
50#include <gnutls/abstract.h>
51#include <gnutls/x509.h>
52#include <gnutls/pkcs12.h>
53#endif
54
55/* JA3/JA3S calculations must ignore GREASE values
56 * as described in RFC 8701.
57 */
58#define IS_GREASE_TLS(x)((((x) & 0x0f0f) == 0x0a0a) && (((x) & 0xff) ==
(((x)>>8) & 0xff)))
((((x) & 0x0f0f) == 0x0a0a) && \
59 (((x) & 0xff) == (((x)>>8) & 0xff)))
60
61/* Section 22.3 of RFC 9000 (QUIC) reserves values of this
62 * form for a similar purpose as GREASE.
63 */
64#define IS_GREASE_QUIC(x)((x) > 27 ? ((((x) - 27) % 31) == 0) : 0) ((x) > 27 ? ((((x) - 27) % 31) == 0) : 0)
65
66#define DTLS13_MAX_EPOCH10 10
67
68/* Lookup tables {{{ */
69const value_string ssl_version_short_names[] = {
70 { SSLV2_VERSION0x0002, "SSLv2" },
71 { SSLV3_VERSION0x300, "SSLv3" },
72 { TLSV1_VERSION0x301, "TLSv1" },
73 { TLCPV1_VERSION0x101, "TLCP" },
74 { TLSV1DOT1_VERSION0x302, "TLSv1.1" },
75 { TLSV1DOT2_VERSION0x303, "TLSv1.2" },
76 { TLSV1DOT3_VERSION0x304, "TLSv1.3" },
77 { DTLSV1DOT0_VERSION0xfeff, "DTLSv1.0" },
78 { DTLSV1DOT2_VERSION0xfefd, "DTLSv1.2" },
79 { DTLSV1DOT3_VERSION0xfefc, "DTLSv1.3" },
80 { DTLSV1DOT0_OPENSSL_VERSION0x100, "DTLS 1.0 (OpenSSL pre 0.9.8f)" },
81 { 0x00, NULL((void*)0) }
82};
83
84const value_string ssl_versions[] = {
85 { SSLV2_VERSION0x0002, "SSL 2.0" },
86 { SSLV3_VERSION0x300, "SSL 3.0" },
87 { TLSV1_VERSION0x301, "TLS 1.0" },
88 { TLCPV1_VERSION0x101, "TLCP" },
89 { TLSV1DOT1_VERSION0x302, "TLS 1.1" },
90 { TLSV1DOT2_VERSION0x303, "TLS 1.2" },
91 { TLSV1DOT3_VERSION0x304, "TLS 1.3" },
92 { 0x7F0E, "TLS 1.3 (draft 14)" },
93 { 0x7F0F, "TLS 1.3 (draft 15)" },
94 { 0x7F10, "TLS 1.3 (draft 16)" },
95 { 0x7F11, "TLS 1.3 (draft 17)" },
96 { 0x7F12, "TLS 1.3 (draft 18)" },
97 { 0x7F13, "TLS 1.3 (draft 19)" },
98 { 0x7F14, "TLS 1.3 (draft 20)" },
99 { 0x7F15, "TLS 1.3 (draft 21)" },
100 { 0x7F16, "TLS 1.3 (draft 22)" },
101 { 0x7F17, "TLS 1.3 (draft 23)" },
102 { 0x7F18, "TLS 1.3 (draft 24)" },
103 { 0x7F19, "TLS 1.3 (draft 25)" },
104 { 0x7F1A, "TLS 1.3 (draft 26)" },
105 { 0x7F1B, "TLS 1.3 (draft 27)" },
106 { 0x7F1C, "TLS 1.3 (draft 28)" },
107 { 0xFB17, "TLS 1.3 (Facebook draft 23)" },
108 { 0xFB1A, "TLS 1.3 (Facebook draft 26)" },
109 { DTLSV1DOT0_OPENSSL_VERSION0x100, "DTLS 1.0 (OpenSSL pre 0.9.8f)" },
110 { DTLSV1DOT0_VERSION0xfeff, "DTLS 1.0" },
111 { DTLSV1DOT2_VERSION0xfefd, "DTLS 1.2" },
112 { DTLSV1DOT3_VERSION0xfefc, "DTLS 1.3" },
113 { 0x0A0A, "Reserved (GREASE)" }, /* RFC 8701 */
114 { 0x1A1A, "Reserved (GREASE)" }, /* RFC 8701 */
115 { 0x2A2A, "Reserved (GREASE)" }, /* RFC 8701 */
116 { 0x3A3A, "Reserved (GREASE)" }, /* RFC 8701 */
117 { 0x4A4A, "Reserved (GREASE)" }, /* RFC 8701 */
118 { 0x5A5A, "Reserved (GREASE)" }, /* RFC 8701 */
119 { 0x6A6A, "Reserved (GREASE)" }, /* RFC 8701 */
120 { 0x7A7A, "Reserved (GREASE)" }, /* RFC 8701 */
121 { 0x8A8A, "Reserved (GREASE)" }, /* RFC 8701 */
122 { 0x9A9A, "Reserved (GREASE)" }, /* RFC 8701 */
123 { 0xAAAA, "Reserved (GREASE)" }, /* RFC 8701 */
124 { 0xBABA, "Reserved (GREASE)" }, /* RFC 8701 */
125 { 0xCACA, "Reserved (GREASE)" }, /* RFC 8701 */
126 { 0xDADA, "Reserved (GREASE)" }, /* RFC 8701 */
127 { 0xEAEA, "Reserved (GREASE)" }, /* RFC 8701 */
128 { 0xFAFA, "Reserved (GREASE)" }, /* RFC 8701 */
129 { 0x00, NULL((void*)0) }
130};
131
132static const value_string ssl_version_ja4_names[] = {
133 { 0x0100, "s1" },
134 { SSLV2_VERSION0x0002, "s2" },
135 { SSLV3_VERSION0x300, "s3" },
136 { TLSV1_VERSION0x301, "10" },
137 { TLSV1DOT1_VERSION0x302, "11" },
138 { TLSV1DOT2_VERSION0x303, "12" },
139 { TLSV1DOT3_VERSION0x304, "13" },
140 { DTLSV1DOT0_VERSION0xfeff, "d1" },
141 { DTLSV1DOT2_VERSION0xfefd, "d2" },
142 { DTLSV1DOT3_VERSION0xfefc, "d3" },
143 { 0x00, NULL((void*)0) }
144};
145
146const value_string ssl_20_msg_types[] = {
147 { SSL2_HND_ERROR0x00, "Error" },
148 { SSL2_HND_CLIENT_HELLO0x01, "Client Hello" },
149 { SSL2_HND_CLIENT_MASTER_KEY0x02, "Client Master Key" },
150 { SSL2_HND_CLIENT_FINISHED0x03, "Client Finished" },
151 { SSL2_HND_SERVER_HELLO0x04, "Server Hello" },
152 { SSL2_HND_SERVER_VERIFY0x05, "Server Verify" },
153 { SSL2_HND_SERVER_FINISHED0x06, "Server Finished" },
154 { SSL2_HND_REQUEST_CERTIFICATE0x07, "Request Certificate" },
155 { SSL2_HND_CLIENT_CERTIFICATE0x08, "Client Certificate" },
156 { 0x00, NULL((void*)0) }
157};
158/* http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
159/* Note: sorted by ascending value so value_string-ext can do a binary search */
160static const value_string ssl_20_cipher_suites[] = {
161 { 0x000000, "TLS_NULL_WITH_NULL_NULL" },
162 { 0x000001, "TLS_RSA_WITH_NULL_MD5" },
163 { 0x000002, "TLS_RSA_WITH_NULL_SHA" },
164 { 0x000003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" },
165 { 0x000004, "TLS_RSA_WITH_RC4_128_MD5" },
166 { 0x000005, "TLS_RSA_WITH_RC4_128_SHA" },
167 { 0x000006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" },
168 { 0x000007, "TLS_RSA_WITH_IDEA_CBC_SHA" },
169 { 0x000008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" },
170 { 0x000009, "TLS_RSA_WITH_DES_CBC_SHA" },
171 { 0x00000a, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" },
172 { 0x00000b, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" },
173 { 0x00000c, "TLS_DH_DSS_WITH_DES_CBC_SHA" },
174 { 0x00000d, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" },
175 { 0x00000e, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" },
176 { 0x00000f, "TLS_DH_RSA_WITH_DES_CBC_SHA" },
177 { 0x000010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" },
178 { 0x000011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" },
179 { 0x000012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" },
180 { 0x000013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" },
181 { 0x000014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" },
182 { 0x000015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" },
183 { 0x000016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" },
184 { 0x000017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" },
185 { 0x000018, "TLS_DH_anon_WITH_RC4_128_MD5" },
186 { 0x000019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" },
187 { 0x00001a, "TLS_DH_anon_WITH_DES_CBC_SHA" },
188 { 0x00001b, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" },
189 { 0x00001c, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" },
190 { 0x00001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
191#if 0
192 { 0x00001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
193#endif
194 /* RFC 2712 */
195 { 0x00001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
196 { 0x00001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" },
197 { 0x000020, "TLS_KRB5_WITH_RC4_128_SHA" },
198 { 0x000021, "TLS_KRB5_WITH_IDEA_CBC_SHA" },
199 { 0x000022, "TLS_KRB5_WITH_DES_CBC_MD5" },
200 { 0x000023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" },
201 { 0x000024, "TLS_KRB5_WITH_RC4_128_MD5" },
202 { 0x000025, "TLS_KRB5_WITH_IDEA_CBC_MD5" },
203 { 0x000026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" },
204 { 0x000027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" },
205 { 0x000028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" },
206 { 0x000029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" },
207 { 0x00002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" },
208 { 0x00002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" },
209 /* RFC 4785 */
210 { 0x00002C, "TLS_PSK_WITH_NULL_SHA" },
211 { 0x00002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
212 { 0x00002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
213 /* RFC 5246 */
214 { 0x00002f, "TLS_RSA_WITH_AES_128_CBC_SHA" },
215 { 0x000030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
216 { 0x000031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" },
217 { 0x000032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" },
218 { 0x000033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" },
219 { 0x000034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" },
220 { 0x000035, "TLS_RSA_WITH_AES_256_CBC_SHA" },
221 { 0x000036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" },
222 { 0x000037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" },
223 { 0x000038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
224 { 0x000039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
225 { 0x00003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
226 { 0x00003B, "TLS_RSA_WITH_NULL_SHA256" },
227 { 0x00003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" },
228 { 0x00003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" },
229 { 0x00003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" },
230 { 0x00003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" },
231 { 0x000040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" },
232 { 0x000041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" },
233 { 0x000042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" },
234 { 0x000043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" },
235 { 0x000044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" },
236 { 0x000045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" },
237 { 0x000046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" },
238 { 0x000047, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
239 { 0x000048, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
240 { 0x000049, "TLS_ECDH_ECDSA_WITH_DES_CBC_SHA" },
241 { 0x00004A, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
242 { 0x00004B, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
243 { 0x00004C, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
244 { 0x000060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
245 { 0x000061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
246 { 0x000062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" },
247 { 0x000063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" },
248 { 0x000064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" },
249 { 0x000065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" },
250 { 0x000066, "TLS_DHE_DSS_WITH_RC4_128_SHA" },
251 { 0x000067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" },
252 { 0x000068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" },
253 { 0x000069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" },
254 { 0x00006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" },
255 { 0x00006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" },
256 { 0x00006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" },
257 { 0x00006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" },
258 /* 0x00,0x6E-83 Unassigned */
259 { 0x000084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" },
260 { 0x000085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" },
261 { 0x000086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" },
262 { 0x000087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
263 { 0x000088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
264 { 0x000089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
265 /* RFC 4279 */
266 { 0x00008A, "TLS_PSK_WITH_RC4_128_SHA" },
267 { 0x00008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
268 { 0x00008C, "TLS_PSK_WITH_AES_128_CBC_SHA" },
269 { 0x00008D, "TLS_PSK_WITH_AES_256_CBC_SHA" },
270 { 0x00008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" },
271 { 0x00008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" },
272 { 0x000090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" },
273 { 0x000091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" },
274 { 0x000092, "TLS_RSA_PSK_WITH_RC4_128_SHA" },
275 { 0x000093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" },
276 { 0x000094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" },
277 { 0x000095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" },
278 /* RFC 4162 */
279 { 0x000096, "TLS_RSA_WITH_SEED_CBC_SHA" },
280 { 0x000097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" },
281 { 0x000098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" },
282 { 0x000099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
283 { 0x00009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
284 { 0x00009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
285 /* RFC 5288 */
286 { 0x00009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" },
287 { 0x00009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" },
288 { 0x00009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" },
289 { 0x00009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" },
290 { 0x0000A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" },
291 { 0x0000A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" },
292 { 0x0000A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" },
293 { 0x0000A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" },
294 { 0x0000A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" },
295 { 0x0000A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" },
296 { 0x0000A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" },
297 { 0x0000A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" },
298 /* RFC 5487 */
299 { 0x0000A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" },
300 { 0x0000A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" },
301 { 0x0000AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" },
302 { 0x0000AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" },
303 { 0x0000AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" },
304 { 0x0000AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" },
305 { 0x0000AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" },
306 { 0x0000AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" },
307 { 0x0000B0, "TLS_PSK_WITH_NULL_SHA256" },
308 { 0x0000B1, "TLS_PSK_WITH_NULL_SHA384" },
309 { 0x0000B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" },
310 { 0x0000B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" },
311 { 0x0000B4, "TLS_DHE_PSK_WITH_NULL_SHA256" },
312 { 0x0000B5, "TLS_DHE_PSK_WITH_NULL_SHA384" },
313 { 0x0000B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" },
314 { 0x0000B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" },
315 { 0x0000B8, "TLS_RSA_PSK_WITH_NULL_SHA256" },
316 { 0x0000B9, "TLS_RSA_PSK_WITH_NULL_SHA384" },
317 /* From RFC 5932 */
318 { 0x0000BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
319 { 0x0000BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
320 { 0x0000BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
321 { 0x0000BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
322 { 0x0000BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
323 { 0x0000BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" },
324 { 0x0000C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
325 { 0x0000C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
326 { 0x0000C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
327 { 0x0000C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
328 { 0x0000C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
329 { 0x0000C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" },
330 /* 0x00,0xC6-FE Unassigned */
331 { 0x0000FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" },
332 /* 0x01-BF,* Unassigned */
333 /* From RFC 4492 */
334 { 0x00c001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
335 { 0x00c002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
336 { 0x00c003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
337 { 0x00c004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
338 { 0x00c005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
339 { 0x00c006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" },
340 { 0x00c007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" },
341 { 0x00c008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" },
342 { 0x00c009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
343 { 0x00c00a, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
344 { 0x00c00b, "TLS_ECDH_RSA_WITH_NULL_SHA" },
345 { 0x00c00c, "TLS_ECDH_RSA_WITH_RC4_128_SHA" },
346 { 0x00c00d, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" },
347 { 0x00c00e, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" },
348 { 0x00c00f, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" },
349 { 0x00c010, "TLS_ECDHE_RSA_WITH_NULL_SHA" },
350 { 0x00c011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" },
351 { 0x00c012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" },
352 { 0x00c013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
353 { 0x00c014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
354 { 0x00c015, "TLS_ECDH_anon_WITH_NULL_SHA" },
355 { 0x00c016, "TLS_ECDH_anon_WITH_RC4_128_SHA" },
356 { 0x00c017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" },
357 { 0x00c018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" },
358 { 0x00c019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" },
359 /* RFC 5054 */
360 { 0x00C01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" },
361 { 0x00C01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" },
362 { 0x00C01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" },
363 { 0x00C01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" },
364 { 0x00C01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" },
365 { 0x00C01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" },
366 { 0x00C020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
367 { 0x00C021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
368 { 0x00C022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
369 /* RFC 5589 */
370 { 0x00C023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" },
371 { 0x00C024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" },
372 { 0x00C025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" },
373 { 0x00C026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" },
374 { 0x00C027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" },
375 { 0x00C028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" },
376 { 0x00C029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" },
377 { 0x00C02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" },
378 { 0x00C02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
379 { 0x00C02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
380 { 0x00C02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" },
381 { 0x00C02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" },
382 { 0x00C02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
383 { 0x00C030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
384 { 0x00C031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" },
385 { 0x00C032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" },
386 /* RFC 5489 */
387 { 0x00C033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" },
388 { 0x00C034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" },
389 { 0x00C035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" },
390 { 0x00C036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" },
391 { 0x00C037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" },
392 { 0x00C038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" },
393 { 0x00C039, "TLS_ECDHE_PSK_WITH_NULL_SHA" },
394 { 0x00C03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" },
395 { 0x00C03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" },
396 /* 0xC0,0x3C-FF Unassigned
397 0xC1-FD,* Unassigned
398 0xFE,0x00-FD Unassigned
399 0xFE,0xFE-FF Reserved to avoid conflicts with widely deployed implementations [Pasi_Eronen]
400 0xFF,0x00-FF Reserved for Private Use [RFC5246]
401 */
402
403 /* old numbers used in the beginning
404 * https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 */
405 { 0x00CC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
406 { 0x00CC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
407 { 0x00CC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
408
409 /* https://tools.ietf.org/html/rfc7905 */
410 { 0x00CCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
411 { 0x00CCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
412 { 0x00CCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
413 { 0x00CCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256" },
414 { 0x00CCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
415 { 0x00CCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
416 { 0x00CCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256" },
417
418 /* GM/T 0024-2014 */
419 { 0x00e001, "ECDHE_SM1_SM3"},
420 { 0x00e003, "ECC_SM1_SM3"},
421 { 0x00e005, "IBSDH_SM1_SM3"},
422 { 0x00e007, "IBC_SM1_SM3"},
423 { 0x00e009, "RSA_SM1_SM3"},
424 { 0x00e00a, "RSA_SM1_SHA1"},
425 { 0x00e011, "ECDHE_SM4_CBC_SM3"},
426 { 0x00e013, "ECC_SM4_CBC_SM3"},
427 { 0x00e015, "IBSDH_SM4_CBC_SM3"},
428 { 0x00e017, "IBC_SM4_CBC_SM3"},
429 { 0x00e019, "RSA_SM4_CBC_SM3"},
430 { 0x00e01a, "RSA_SM4_CBC_SHA1"},
431 { 0x00e01c, "RSA_SM4_CBC_SHA256"},
432 { 0x00e051, "ECDHE_SM4_GCM_SM3"},
433 { 0x00e053, "ECC_SM4_GCM_SM3"},
434 { 0x00e055, "IBSDH_SM4_GCM_SM3"},
435 { 0x00e057, "IBC_SM4_GCM_SM3"},
436 { 0x00e059, "RSA_SM4_GCM_SM3"},
437 { 0x00e05a, "RSA_SM4_GCM_SHA256"},
438
439 /* https://tools.ietf.org/html/draft-josefsson-salsa20-tls */
440 { 0x00E410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" },
441 { 0x00E411, "TLS_RSA_WITH_SALSA20_SHA1" },
442 { 0x00E412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
443 { 0x00E413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" },
444 { 0x00E414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" },
445 { 0x00E415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" },
446 { 0x00E416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" },
447 { 0x00E417, "TLS_PSK_WITH_SALSA20_SHA1" },
448 { 0x00E418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
449 { 0x00E419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" },
450 { 0x00E41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" },
451 { 0x00E41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" },
452 { 0x00E41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
453 { 0x00E41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" },
454 { 0x00E41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
455 { 0x00E41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" },
456
457 /* these from http://www.mozilla.org/projects/
458 security/pki/nss/ssl/fips-ssl-ciphersuites.html */
459 { 0x00fefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
460 { 0x00feff, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
461 { 0x00ffe0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
462 { 0x00ffe1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
463 /* note that ciphersuites of {0x00????} are TLS cipher suites in
464 * a sslv2 client hello message; the ???? above is the two-byte
465 * tls cipher suite id
466 */
467
468 { 0x010080, "SSL2_RC4_128_WITH_MD5" },
469 { 0x020080, "SSL2_RC4_128_EXPORT40_WITH_MD5" },
470 { 0x030080, "SSL2_RC2_128_CBC_WITH_MD5" },
471 { 0x040080, "SSL2_RC2_128_CBC_EXPORT40_WITH_MD5" },
472 { 0x050080, "SSL2_IDEA_128_CBC_WITH_MD5" },
473 { 0x060040, "SSL2_DES_64_CBC_WITH_MD5" },
474 { 0x0700c0, "SSL2_DES_192_EDE3_CBC_WITH_MD5" },
475 { 0x080080, "SSL2_RC4_64_WITH_MD5" },
476
477 { 0x00, NULL((void*)0) }
478};
479
480value_string_ext ssl_20_cipher_suites_ext = VALUE_STRING_EXT_INIT(ssl_20_cipher_suites){ _try_val_to_str_ext_init, 0, (sizeof (ssl_20_cipher_suites)
/ sizeof ((ssl_20_cipher_suites)[0]))-1, ssl_20_cipher_suites
, "ssl_20_cipher_suites", ((void*)0) }
;
481
482
483/*
484 * Supported Groups (formerly named "EC Named Curve").
485 * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8
486 */
487const value_string ssl_extension_curves[] = {
488 { 1, "sect163k1" },
489 { 2, "sect163r1" },
490 { 3, "sect163r2" },
491 { 4, "sect193r1" },
492 { 5, "sect193r2" },
493 { 6, "sect233k1" },
494 { 7, "sect233r1" },
495 { 8, "sect239k1" },
496 { 9, "sect283k1" },
497 { 10, "sect283r1" },
498 { 11, "sect409k1" },
499 { 12, "sect409r1" },
500 { 13, "sect571k1" },
501 { 14, "sect571r1" },
502 { 15, "secp160k1" },
503 { 16, "secp160r1" },
504 { 17, "secp160r2" },
505 { 18, "secp192k1" },
506 { 19, "secp192r1" },
507 { 20, "secp224k1" },
508 { 21, "secp224r1" },
509 { 22, "secp256k1" },
510 { 23, "secp256r1" },
511 { 24, "secp384r1" },
512 { 25, "secp521r1" },
513 { 26, "brainpoolP256r1" }, /* RFC 7027 */
514 { 27, "brainpoolP384r1" }, /* RFC 7027 */
515 { 28, "brainpoolP512r1" }, /* RFC 7027 */
516 { 29, "x25519" }, /* RFC 8446 / RFC 8422 */
517 { 30, "x448" }, /* RFC 8446 / RFC 8422 */
518 { 31, "brainpoolP256r1tls13" }, /* RFC8734 */
519 { 32, "brainpoolP384r1tls13" }, /* RFC8734 */
520 { 33, "brainpoolP512r1tls13" }, /* RFC8734 */
521 { 34, "GC256A" }, /* RFC9189 */
522 { 35, "GC256B" }, /* RFC9189 */
523 { 36, "GC256C" }, /* RFC9189 */
524 { 37, "GC256D" }, /* RFC9189 */
525 { 38, "GC512A" }, /* RFC9189 */
526 { 39, "GC512B" }, /* RFC9189 */
527 { 40, "GC512C" }, /* RFC9189 */
528 { 41, "curveSM2" }, /* RFC 8998 */
529 { 256, "ffdhe2048" }, /* RFC 7919 */
530 { 257, "ffdhe3072" }, /* RFC 7919 */
531 { 258, "ffdhe4096" }, /* RFC 7919 */
532 { 259, "ffdhe6144" }, /* RFC 7919 */
533 { 260, "ffdhe8192" }, /* RFC 7919 */
534 { 512, "MLKEM512"}, /* draft-connolly-tls-mlkem-key-agreement-03 */
535 { 513, "MLKEM768"}, /* draft-connolly-tls-mlkem-key-agreement-03 */
536 { 514, "MLKEM1024"}, /* draft-connolly-tls-mlkem-key-agreement-03 */
537 { 2570, "Reserved (GREASE)" }, /* RFC 8701 */
538 { 4587, "SecP256r1MLKEM768" }, /* draft-kwiatkowski-tls-ecdhe-mlkem-02 */
539 { 4588, "X25519MLKEM768" }, /* draft-kwiatkowski-tls-ecdhe-mlkem-03 */
540 { 4589, "SecP384r1MLKEM1024" }, /* draft-kwiatkowski-tls-ecdhe-mlkem-03 */
541 { 6682, "Reserved (GREASE)" }, /* RFC 8701 */
542 { 10794, "Reserved (GREASE)" }, /* RFC 8701 */
543 { 14906, "Reserved (GREASE)" }, /* RFC 8701 */
544 { 19018, "Reserved (GREASE)" }, /* RFC 8701 */
545 { 23130, "Reserved (GREASE)" }, /* RFC 8701 */
546 { 25497, "X25519Kyber768Draft00 (OBSOLETE)" }, /* draft-tls-westerbaan-xyber768d00-02 */
547 { 25498, "SecP256r1Kyber768Draft00 (OBSOLETE)" }, /* draft-kwiatkowski-tls-ecdhe-kyber-01 */
548 { 27242, "Reserved (GREASE)" }, /* RFC 8701 */
549 { 31354, "Reserved (GREASE)" }, /* RFC 8701 */
550 { 35466, "Reserved (GREASE)" }, /* RFC 8701 */
551 { 39578, "Reserved (GREASE)" }, /* RFC 8701 */
552 { 43690, "Reserved (GREASE)" }, /* RFC 8701 */
553 { 47802, "Reserved (GREASE)" }, /* RFC 8701 */
554 { 51914, "Reserved (GREASE)" }, /* RFC 8701 */
555 { 56026, "Reserved (GREASE)" }, /* RFC 8701 */
556 { 60138, "Reserved (GREASE)" }, /* RFC 8701 */
557 { 64250, "Reserved (GREASE)" }, /* RFC 8701 */
558 { 0xFF01, "arbitrary_explicit_prime_curves" },
559 { 0xFF02, "arbitrary_explicit_char2_curves" },
560 /* Below are various unofficial values that have been used for testing. */
561 /* PQC key exchange algorithms from OQS-OpenSSL,
562 see https://github.com/open-quantum-safe/oqs-provider/blob/main/oqs-template/oqs-kem-info.md
563 These use IANA unassigned values and this list may be incomplete.
564 */
565 { 0x2F00, "p256_frodo640aes" },
566 { 0x2F01, "p256_frodo640shake" },
567 { 0x2F02, "p384_frodo976aes" },
568 { 0x0203, "frodo976shake" },
569 { 0x2F03, "p384_frodo976shake" },
570 { 0x0204, "frodo1344aes" },
571 { 0x2F04, "p521_frodo1344aes" },
572 { 0x0205, "frodo1344shake" },
573 { 0x2F05, "p521_frodo1344shake" },
574 { 0x023A, "kyber512" },
575 { 0x2F3A, "p256_kyber512" },
576 { 0x023C, "kyber768" },
577 { 0x2F3C, "p384_kyber768" },
578 { 0x023D, "kyber1024" },
579 { 0x2F3D, "p521_kyber1024" },
580 { 0x0214, "ntru_hps2048509" },
581 { 0x2F14, "p256_ntru_hps2048509" },
582 { 0x0215, "ntru_hps2048677" },
583 { 0x2F15, "p384_ntru_hps2048677" },
584 { 0x0216, "ntru_hps4096821" },
585 { 0x2F16, "p521_ntru_hps4096821" },
586 { 0x0245, "ntru_hps40961229" },
587 { 0x2F45, "p521_ntru_hps40961229" },
588 { 0x0217, "ntru_hrss701" },
589 { 0x2F17, "p384_ntru_hrss701" },
590 { 0x0246, "ntru_hrss1373" },
591 { 0x2F46, "p521_ntru_hrss1373" },
592 { 0x0218, "lightsaber" },
593 { 0x2F18, "p256_lightsaber" },
594 { 0x0219, "saber" },
595 { 0x2F19, "p384_saber" },
596 { 0x021A, "firesaber" },
597 { 0x2F1A, "p521_firesaber" },
598 { 0x021B, "sidhp434" },
599 { 0x2F1B, "p256_sidhp434" },
600 { 0x021C, "sidhp503" },
601 { 0x2F1C, "p256_sidhp503" },
602 { 0x021D, "sidhp610" },
603 { 0x2F1D, "p384_sidhp610" },
604 { 0x021E, "sidhp751" },
605 { 0x2F1E, "p521_sidhp751" },
606 { 0x021F, "sikep434" },
607 { 0x2F1F, "p256_sikep434" },
608 { 0x0220, "sikep503" },
609 { 0x2F20, "p256_sikep503" },
610 { 0x0221, "sikep610" },
611 { 0x2F21, "p384_sikep610" },
612 { 0x0222, "sikep751" },
613 { 0x2F22, "p521_sikep751" },
614 { 0x0238, "bikel1" },
615 { 0x2F38, "p256_bikel1" },
616 { 0x023B, "bikel3" },
617 { 0x2F3B, "p384_bikel3" },
618 { 0x023E, "kyber90s512" },
619 { 0x2F3E, "p256_kyber90s512" },
620 { 0x023F, "kyber90s768" },
621 { 0x2F3F, "p384_kyber90s768" },
622 { 0x0240, "kyber90s1024" },
623 { 0x2F40, "p521_kyber90s1024" },
624 { 0x022C, "hqc128" },
625 { 0x2F2C, "p256_hqc128" },
626 { 0x022D, "hqc192" },
627 { 0x2F2D, "p384_hqc192" },
628 { 0x022E, "hqc256" },
629 { 0x2F2E, "p521_hqc256" },
630 { 0x022F, "ntrulpr653" },
631 { 0x2F2F, "p256_ntrulpr653" },
632 { 0x0230, "ntrulpr761" },
633 { 0x2F43, "p256_ntrulpr761" },
634 { 0x0231, "ntrulpr857" },
635 { 0x2F31, "p384_ntrulpr857" },
636 { 0x0241, "ntrulpr1277" },
637 { 0x2F41, "p521_ntrulpr1277" },
638 { 0x0232, "sntrup653" },
639 { 0x2F32, "p256_sntrup653" },
640 { 0x0233, "sntrup761" },
641 { 0x2F44, "p256_sntrup761" },
642 { 0x0234, "sntrup857" },
643 { 0x2F34, "p384_sntrup857" },
644 { 0x0242, "sntrup1277" },
645 { 0x2F42, "p521_sntrup1277" },
646 /* Other PQ key exchange algorithms, using Reserved for Private Use values
647 https://blog.cloudflare.com/post-quantum-for-all
648 https://www.ietf.org/archive/id/draft-tls-westerbaan-xyber768d00-02.txt */
649 { 0xFE30, "X25519Kyber512Draft00 (OBSOLETE)" },
650 { 0xFE31, "X25519Kyber768Draft00 (OBSOLETE)" },
651 { 0x00, NULL((void*)0) }
652};
653
654const value_string ssl_curve_types[] = {
655 { 1, "explicit_prime" },
656 { 2, "explicit_char2" },
657 { 3, "named_curve" },
658 { 0x00, NULL((void*)0) }
659};
660
661const value_string ssl_extension_ec_point_formats[] = {
662 { 0, "uncompressed" },
663 { 1, "ansiX962_compressed_prime" },
664 { 2, "ansiX962_compressed_char2" },
665 { 0x00, NULL((void*)0) }
666};
667
668const value_string ssl_20_certificate_type[] = {
669 { 0x00, "N/A" },
670 { 0x01, "X.509 Certificate" },
671 { 0x00, NULL((void*)0) }
672};
673
674const value_string ssl_31_content_type[] = {
675 { 20, "Change Cipher Spec" },
676 { 21, "Alert" },
677 { 22, "Handshake" },
678 { 23, "Application Data" },
679 { 24, "Heartbeat" },
680 { 25, "Connection ID" },
681 { 0x00, NULL((void*)0) }
682};
683
684#if 0
685/* XXX - would be used if we dissected the body of a Change Cipher Spec
686 message. */
687const value_string ssl_31_change_cipher_spec[] = {
688 { 1, "Change Cipher Spec" },
689 { 0x00, NULL((void*)0) }
690};
691#endif
692
693const value_string ssl_31_alert_level[] = {
694 { 1, "Warning" },
695 { 2, "Fatal" },
696 { 0x00, NULL((void*)0) }
697};
698
699const value_string ssl_31_alert_description[] = {
700 { 0, "Close Notify" },
701 { 1, "End of Early Data" },
702 { 10, "Unexpected Message" },
703 { 20, "Bad Record MAC" },
704 { 21, "Decryption Failed" },
705 { 22, "Record Overflow" },
706 { 30, "Decompression Failure" },
707 { 40, "Handshake Failure" },
708 { 41, "No Certificate" },
709 { 42, "Bad Certificate" },
710 { 43, "Unsupported Certificate" },
711 { 44, "Certificate Revoked" },
712 { 45, "Certificate Expired" },
713 { 46, "Certificate Unknown" },
714 { 47, "Illegal Parameter" },
715 { 48, "Unknown CA" },
716 { 49, "Access Denied" },
717 { 50, "Decode Error" },
718 { 51, "Decrypt Error" },
719 { 60, "Export Restriction" },
720 { 70, "Protocol Version" },
721 { 71, "Insufficient Security" },
722 { 80, "Internal Error" },
723 { 86, "Inappropriate Fallback" },
724 { 90, "User Canceled" },
725 { 100, "No Renegotiation" },
726 { 109, "Missing Extension" },
727 { 110, "Unsupported Extension" },
728 { 111, "Certificate Unobtainable" },
729 { 112, "Unrecognized Name" },
730 { 113, "Bad Certificate Status Response" },
731 { 114, "Bad Certificate Hash Value" },
732 { 115, "Unknown PSK Identity" },
733 { 116, "Certificate Required" },
734 { 120, "No application Protocol" },
735 { 121, "ECH Required" },
736 { 0x00, NULL((void*)0) }
737};
738
739const value_string ssl_31_handshake_type[] = {
740 { SSL_HND_HELLO_REQUEST, "Hello Request" },
741 { SSL_HND_CLIENT_HELLO, "Client Hello" },
742 { SSL_HND_SERVER_HELLO, "Server Hello" },
743 { SSL_HND_HELLO_VERIFY_REQUEST, "Hello Verify Request"},
744 { SSL_HND_NEWSESSION_TICKET, "New Session Ticket" },
745 { SSL_HND_END_OF_EARLY_DATA, "End of Early Data" },
746 { SSL_HND_HELLO_RETRY_REQUEST, "Hello Retry Request" },
747 { SSL_HND_ENCRYPTED_EXTENSIONS, "Encrypted Extensions" },
748 { SSL_HND_CERTIFICATE, "Certificate" },
749 { SSL_HND_SERVER_KEY_EXCHG, "Server Key Exchange" },
750 { SSL_HND_CERT_REQUEST, "Certificate Request" },
751 { SSL_HND_SVR_HELLO_DONE, "Server Hello Done" },
752 { SSL_HND_CERT_VERIFY, "Certificate Verify" },
753 { SSL_HND_CLIENT_KEY_EXCHG, "Client Key Exchange" },
754 { SSL_HND_FINISHED, "Finished" },
755 { SSL_HND_CERT_URL, "Client Certificate URL" },
756 { SSL_HND_CERT_STATUS, "Certificate Status" },
757 { SSL_HND_SUPPLEMENTAL_DATA, "Supplemental Data" },
758 { SSL_HND_KEY_UPDATE, "Key Update" },
759 { SSL_HND_COMPRESSED_CERTIFICATE, "Compressed Certificate" },
760 { SSL_HND_ENCRYPTED_EXTS, "Encrypted Extensions" },
761 { 0x00, NULL((void*)0) }
762};
763
764const value_string tls_heartbeat_type[] = {
765 { 1, "Request" },
766 { 2, "Response" },
767 { 0x00, NULL((void*)0) }
768};
769
770const value_string tls_heartbeat_mode[] = {
771 { 1, "Peer allowed to send requests" },
772 { 2, "Peer not allowed to send requests" },
773 { 0x00, NULL((void*)0) }
774};
775
776const value_string ssl_31_compression_method[] = {
777 { 0, "null" },
778 { 1, "DEFLATE" },
779 { 64, "LZS" },
780 { 0x00, NULL((void*)0) }
781};
782
783#if 0
784/* XXX - would be used if we dissected a Signature, as would be
785 seen in a server key exchange or certificate verify message. */
786const value_string ssl_31_key_exchange_algorithm[] = {
787 { 0, "RSA" },
788 { 1, "Diffie Hellman" },
789 { 0x00, NULL((void*)0) }
790};
791
792const value_string ssl_31_signature_algorithm[] = {
793 { 0, "Anonymous" },
794 { 1, "RSA" },
795 { 2, "DSA" },
796 { 0x00, NULL((void*)0) }
797};
798#endif
799
800const value_string ssl_31_client_certificate_type[] = {
801 { 1, "RSA Sign" },
802 { 2, "DSS Sign" },
803 { 3, "RSA Fixed DH" },
804 { 4, "DSS Fixed DH" },
805 /* GOST certificate types */
806 /* Section 3.5 of draft-chudov-cryptopro-cptls-04 */
807 { 21, "GOST R 34.10-94" },
808 { 22, "GOST R 34.10-2001" },
809 /* END GOST certificate types */
810 { 64, "ECDSA Sign" },
811 { 65, "RSA Fixed ECDH" },
812 { 66, "ECDSA Fixed ECDH" },
813 { 80, "IBC Params" },
814 { 0x00, NULL((void*)0) }
815};
816
817#if 0
818/* XXX - would be used if we dissected exchange keys, as would be
819 seen in a client key exchange message. */
820const value_string ssl_31_public_value_encoding[] = {
821 { 0, "Implicit" },
822 { 1, "Explicit" },
823 { 0x00, NULL((void*)0) }
824};
825#endif
826
827/* http://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
828/* Note: sorted by ascending value so value_string_ext fcns can do a binary search */
829static const value_string ssl_31_ciphersuite[] = {
830 /* RFC 2246, RFC 4346, RFC 5246 */
831 { 0x0000, "TLS_NULL_WITH_NULL_NULL" },
832 { 0x0001, "TLS_RSA_WITH_NULL_MD5" },
833 { 0x0002, "TLS_RSA_WITH_NULL_SHA" },
834 { 0x0003, "TLS_RSA_EXPORT_WITH_RC4_40_MD5" },
835 { 0x0004, "TLS_RSA_WITH_RC4_128_MD5" },
836 { 0x0005, "TLS_RSA_WITH_RC4_128_SHA" },
837 { 0x0006, "TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5" },
838 { 0x0007, "TLS_RSA_WITH_IDEA_CBC_SHA" },
839 { 0x0008, "TLS_RSA_EXPORT_WITH_DES40_CBC_SHA" },
840 { 0x0009, "TLS_RSA_WITH_DES_CBC_SHA" },
841 { 0x000a, "TLS_RSA_WITH_3DES_EDE_CBC_SHA" },
842 { 0x000b, "TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA" },
843 { 0x000c, "TLS_DH_DSS_WITH_DES_CBC_SHA" },
844 { 0x000d, "TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA" },
845 { 0x000e, "TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA" },
846 { 0x000f, "TLS_DH_RSA_WITH_DES_CBC_SHA" },
847 { 0x0010, "TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA" },
848 { 0x0011, "TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA" },
849 { 0x0012, "TLS_DHE_DSS_WITH_DES_CBC_SHA" },
850 { 0x0013, "TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA" },
851 { 0x0014, "TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA" },
852 { 0x0015, "TLS_DHE_RSA_WITH_DES_CBC_SHA" },
853 { 0x0016, "TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA" },
854 { 0x0017, "TLS_DH_anon_EXPORT_WITH_RC4_40_MD5" },
855 { 0x0018, "TLS_DH_anon_WITH_RC4_128_MD5" },
856 { 0x0019, "TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA" },
857 { 0x001a, "TLS_DH_anon_WITH_DES_CBC_SHA" },
858 { 0x001b, "TLS_DH_anon_WITH_3DES_EDE_CBC_SHA" },
859
860 { 0x001c, "SSL_FORTEZZA_KEA_WITH_NULL_SHA" },
861 { 0x001d, "SSL_FORTEZZA_KEA_WITH_FORTEZZA_CBC_SHA" },
862#if 0 /* Because it clashes with KRB5, is never used any more, and is safe
863 to remove according to David Hopwood <[email protected]>
864 of the ietf-tls list */
865 { 0x001e, "SSL_FORTEZZA_KEA_WITH_RC4_128_SHA" },
866#endif
867 /* RFC 2712 */
868 { 0x001E, "TLS_KRB5_WITH_DES_CBC_SHA" },
869 { 0x001F, "TLS_KRB5_WITH_3DES_EDE_CBC_SHA" },
870 { 0x0020, "TLS_KRB5_WITH_RC4_128_SHA" },
871 { 0x0021, "TLS_KRB5_WITH_IDEA_CBC_SHA" },
872 { 0x0022, "TLS_KRB5_WITH_DES_CBC_MD5" },
873 { 0x0023, "TLS_KRB5_WITH_3DES_EDE_CBC_MD5" },
874 { 0x0024, "TLS_KRB5_WITH_RC4_128_MD5" },
875 { 0x0025, "TLS_KRB5_WITH_IDEA_CBC_MD5" },
876 { 0x0026, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_SHA" },
877 { 0x0027, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_SHA" },
878 { 0x0028, "TLS_KRB5_EXPORT_WITH_RC4_40_SHA" },
879 { 0x0029, "TLS_KRB5_EXPORT_WITH_DES_CBC_40_MD5" },
880 { 0x002A, "TLS_KRB5_EXPORT_WITH_RC2_CBC_40_MD5" },
881 { 0x002B, "TLS_KRB5_EXPORT_WITH_RC4_40_MD5" },
882 /* RFC 4785 */
883 { 0x002C, "TLS_PSK_WITH_NULL_SHA" },
884 { 0x002D, "TLS_DHE_PSK_WITH_NULL_SHA" },
885 { 0x002E, "TLS_RSA_PSK_WITH_NULL_SHA" },
886 /* RFC 5246 */
887 { 0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA" },
888 { 0x0030, "TLS_DH_DSS_WITH_AES_128_CBC_SHA" },
889 { 0x0031, "TLS_DH_RSA_WITH_AES_128_CBC_SHA" },
890 { 0x0032, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA" },
891 { 0x0033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA" },
892 { 0x0034, "TLS_DH_anon_WITH_AES_128_CBC_SHA" },
893 { 0x0035, "TLS_RSA_WITH_AES_256_CBC_SHA" },
894 { 0x0036, "TLS_DH_DSS_WITH_AES_256_CBC_SHA" },
895 { 0x0037, "TLS_DH_RSA_WITH_AES_256_CBC_SHA" },
896 { 0x0038, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA" },
897 { 0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA" },
898 { 0x003A, "TLS_DH_anon_WITH_AES_256_CBC_SHA" },
899 { 0x003B, "TLS_RSA_WITH_NULL_SHA256" },
900 { 0x003C, "TLS_RSA_WITH_AES_128_CBC_SHA256" },
901 { 0x003D, "TLS_RSA_WITH_AES_256_CBC_SHA256" },
902 { 0x003E, "TLS_DH_DSS_WITH_AES_128_CBC_SHA256" },
903 { 0x003F, "TLS_DH_RSA_WITH_AES_128_CBC_SHA256" },
904 { 0x0040, "TLS_DHE_DSS_WITH_AES_128_CBC_SHA256" },
905 /* RFC 4132 */
906 { 0x0041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA" },
907 { 0x0042, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA" },
908 { 0x0043, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA" },
909 { 0x0044, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA" },
910 { 0x0045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA" },
911 { 0x0046, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA" },
912 /* 0x00,0x60-66 Reserved to avoid conflicts with widely deployed implementations */
913 /* --- ??? --- */
914 { 0x0060, "TLS_RSA_EXPORT1024_WITH_RC4_56_MD5" },
915 { 0x0061, "TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5" },
916 /* draft-ietf-tls-56-bit-ciphersuites-01.txt */
917 { 0x0062, "TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA" },
918 { 0x0063, "TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA" },
919 { 0x0064, "TLS_RSA_EXPORT1024_WITH_RC4_56_SHA" },
920 { 0x0065, "TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA" },
921 { 0x0066, "TLS_DHE_DSS_WITH_RC4_128_SHA" },
922 /* --- ??? ---*/
923 { 0x0067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256" },
924 { 0x0068, "TLS_DH_DSS_WITH_AES_256_CBC_SHA256" },
925 { 0x0069, "TLS_DH_RSA_WITH_AES_256_CBC_SHA256" },
926 { 0x006A, "TLS_DHE_DSS_WITH_AES_256_CBC_SHA256" },
927 { 0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256" },
928 { 0x006C, "TLS_DH_anon_WITH_AES_128_CBC_SHA256" },
929 { 0x006D, "TLS_DH_anon_WITH_AES_256_CBC_SHA256" },
930 /* draft-chudov-cryptopro-cptls-04.txt */
931 { 0x0080, "TLS_GOSTR341094_WITH_28147_CNT_IMIT" },
932 { 0x0081, "TLS_GOSTR341001_WITH_28147_CNT_IMIT" },
933 { 0x0082, "TLS_GOSTR341094_WITH_NULL_GOSTR3411" },
934 { 0x0083, "TLS_GOSTR341001_WITH_NULL_GOSTR3411" },
935 /* RFC 4132 */
936 { 0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA" },
937 { 0x0085, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA" },
938 { 0x0086, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA" },
939 { 0x0087, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA" },
940 { 0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA" },
941 { 0x0089, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA" },
942 /* RFC 4279 */
943 { 0x008A, "TLS_PSK_WITH_RC4_128_SHA" },
944 { 0x008B, "TLS_PSK_WITH_3DES_EDE_CBC_SHA" },
945 { 0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA" },
946 { 0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA" },
947 { 0x008E, "TLS_DHE_PSK_WITH_RC4_128_SHA" },
948 { 0x008F, "TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA" },
949 { 0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA" },
950 { 0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA" },
951 { 0x0092, "TLS_RSA_PSK_WITH_RC4_128_SHA" },
952 { 0x0093, "TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA" },
953 { 0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA" },
954 { 0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA" },
955 /* RFC 4162 */
956 { 0x0096, "TLS_RSA_WITH_SEED_CBC_SHA" },
957 { 0x0097, "TLS_DH_DSS_WITH_SEED_CBC_SHA" },
958 { 0x0098, "TLS_DH_RSA_WITH_SEED_CBC_SHA" },
959 { 0x0099, "TLS_DHE_DSS_WITH_SEED_CBC_SHA" },
960 { 0x009A, "TLS_DHE_RSA_WITH_SEED_CBC_SHA" },
961 { 0x009B, "TLS_DH_anon_WITH_SEED_CBC_SHA" },
962 /* RFC 5288 */
963 { 0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256" },
964 { 0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384" },
965 { 0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256" },
966 { 0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" },
967 { 0x00A0, "TLS_DH_RSA_WITH_AES_128_GCM_SHA256" },
968 { 0x00A1, "TLS_DH_RSA_WITH_AES_256_GCM_SHA384" },
969 { 0x00A2, "TLS_DHE_DSS_WITH_AES_128_GCM_SHA256" },
970 { 0x00A3, "TLS_DHE_DSS_WITH_AES_256_GCM_SHA384" },
971 { 0x00A4, "TLS_DH_DSS_WITH_AES_128_GCM_SHA256" },
972 { 0x00A5, "TLS_DH_DSS_WITH_AES_256_GCM_SHA384" },
973 { 0x00A6, "TLS_DH_anon_WITH_AES_128_GCM_SHA256" },
974 { 0x00A7, "TLS_DH_anon_WITH_AES_256_GCM_SHA384" },
975 /* RFC 5487 */
976 { 0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256" },
977 { 0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384" },
978 { 0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256" },
979 { 0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384" },
980 { 0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256" },
981 { 0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384" },
982 { 0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256" },
983 { 0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384" },
984 { 0x00B0, "TLS_PSK_WITH_NULL_SHA256" },
985 { 0x00B1, "TLS_PSK_WITH_NULL_SHA384" },
986 { 0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256" },
987 { 0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384" },
988 { 0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256" },
989 { 0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384" },
990 { 0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256" },
991 { 0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384" },
992 { 0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256" },
993 { 0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384" },
994 /* From RFC 5932 */
995 { 0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
996 { 0x00BB, "TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
997 { 0x00BC, "TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
998 { 0x00BD, "TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256" },
999 { 0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
1000 { 0x00BF, "TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256" },
1001 { 0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
1002 { 0x00C1, "TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
1003 { 0x00C2, "TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
1004 { 0x00C3, "TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256" },
1005 { 0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256" },
1006 { 0x00C5, "TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256" },
1007 /* RFC 8998 */
1008 { 0x00C6, "TLS_SM4_GCM_SM3" },
1009 { 0x00C7, "TLS_SM4_CCM_SM3" },
1010 /* 0x00,0xC8-FE Unassigned */
1011 /* From RFC 5746 */
1012 { 0x00FF, "TLS_EMPTY_RENEGOTIATION_INFO_SCSV" },
1013 /* RFC 8701 */
1014 { 0x0A0A, "Reserved (GREASE)" },
1015 /* RFC 8446 */
1016 { 0x1301, "TLS_AES_128_GCM_SHA256" },
1017 { 0x1302, "TLS_AES_256_GCM_SHA384" },
1018 { 0x1303, "TLS_CHACHA20_POLY1305_SHA256" },
1019 { 0x1304, "TLS_AES_128_CCM_SHA256" },
1020 { 0x1305, "TLS_AES_128_CCM_8_SHA256" },
1021 /* RFC 8701 */
1022 { 0x1A1A, "Reserved (GREASE)" },
1023 { 0x2A2A, "Reserved (GREASE)" },
1024 { 0x3A3A, "Reserved (GREASE)" },
1025 { 0x4A4A, "Reserved (GREASE)" },
1026 /* From RFC 7507 */
1027 { 0x5600, "TLS_FALLBACK_SCSV" },
1028 /* RFC 8701 */
1029 { 0x5A5A, "Reserved (GREASE)" },
1030 { 0x6A6A, "Reserved (GREASE)" },
1031 { 0x7A7A, "Reserved (GREASE)" },
1032 { 0x8A8A, "Reserved (GREASE)" },
1033 { 0x9A9A, "Reserved (GREASE)" },
1034 { 0xAAAA, "Reserved (GREASE)" },
1035 { 0xBABA, "Reserved (GREASE)" },
1036 /* From RFC 4492 */
1037 { 0xc001, "TLS_ECDH_ECDSA_WITH_NULL_SHA" },
1038 { 0xc002, "TLS_ECDH_ECDSA_WITH_RC4_128_SHA" },
1039 { 0xc003, "TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA" },
1040 { 0xc004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA" },
1041 { 0xc005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA" },
1042 { 0xc006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA" },
1043 { 0xc007, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" },
1044 { 0xc008, "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA" },
1045 { 0xc009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" },
1046 { 0xc00a, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" },
1047 { 0xc00b, "TLS_ECDH_RSA_WITH_NULL_SHA" },
1048 { 0xc00c, "TLS_ECDH_RSA_WITH_RC4_128_SHA" },
1049 { 0xc00d, "TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA" },
1050 { 0xc00e, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA" },
1051 { 0xc00f, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA" },
1052 { 0xc010, "TLS_ECDHE_RSA_WITH_NULL_SHA" },
1053 { 0xc011, "TLS_ECDHE_RSA_WITH_RC4_128_SHA" },
1054 { 0xc012, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" },
1055 { 0xc013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" },
1056 { 0xc014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" },
1057 { 0xc015, "TLS_ECDH_anon_WITH_NULL_SHA" },
1058 { 0xc016, "TLS_ECDH_anon_WITH_RC4_128_SHA" },
1059 { 0xc017, "TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA" },
1060 { 0xc018, "TLS_ECDH_anon_WITH_AES_128_CBC_SHA" },
1061 { 0xc019, "TLS_ECDH_anon_WITH_AES_256_CBC_SHA" },
1062 /* RFC 5054 */
1063 { 0xC01A, "TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA" },
1064 { 0xC01B, "TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA" },
1065 { 0xC01C, "TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA" },
1066 { 0xC01D, "TLS_SRP_SHA_WITH_AES_128_CBC_SHA" },
1067 { 0xC01E, "TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA" },
1068 { 0xC01F, "TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA" },
1069 { 0xC020, "TLS_SRP_SHA_WITH_AES_256_CBC_SHA" },
1070 { 0xC021, "TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA" },
1071 { 0xC022, "TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA" },
1072 /* RFC 5589 */
1073 { 0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256" },
1074 { 0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384" },
1075 { 0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256" },
1076 { 0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384" },
1077 { 0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256" },
1078 { 0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384" },
1079 { 0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256" },
1080 { 0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384" },
1081 { 0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" },
1082 { 0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384" },
1083 { 0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256" },
1084 { 0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384" },
1085 { 0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" },
1086 { 0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384" },
1087 { 0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256" },
1088 { 0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384" },
1089 /* RFC 5489 */
1090 { 0xC033, "TLS_ECDHE_PSK_WITH_RC4_128_SHA" },
1091 { 0xC034, "TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA" },
1092 { 0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA" },
1093 { 0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA" },
1094 { 0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256" },
1095 { 0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384" },
1096 { 0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA" },
1097 { 0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256" },
1098 { 0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384" },
1099 /* RFC 6209 */
1100 { 0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256" },
1101 { 0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384" },
1102 { 0xC03E, "TLS_DH_DSS_WITH_ARIA_128_CBC_SHA256" },
1103 { 0xC03F, "TLS_DH_DSS_WITH_ARIA_256_CBC_SHA384" },
1104 { 0xC040, "TLS_DH_RSA_WITH_ARIA_128_CBC_SHA256" },
1105 { 0xC041, "TLS_DH_RSA_WITH_ARIA_256_CBC_SHA384" },
1106 { 0xC042, "TLS_DHE_DSS_WITH_ARIA_128_CBC_SHA256" },
1107 { 0xC043, "TLS_DHE_DSS_WITH_ARIA_256_CBC_SHA384" },
1108 { 0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256" },
1109 { 0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384" },
1110 { 0xC046, "TLS_DH_anon_WITH_ARIA_128_CBC_SHA256" },
1111 { 0xC047, "TLS_DH_anon_WITH_ARIA_256_CBC_SHA384" },
1112 { 0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256" },
1113 { 0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384" },
1114 { 0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256" },
1115 { 0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384" },
1116 { 0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256" },
1117 { 0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384" },
1118 { 0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256" },
1119 { 0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384" },
1120 { 0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256" },
1121 { 0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384" },
1122 { 0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256" },
1123 { 0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384" },
1124 { 0xC054, "TLS_DH_RSA_WITH_ARIA_128_GCM_SHA256" },
1125 { 0xC055, "TLS_DH_RSA_WITH_ARIA_256_GCM_SHA384" },
1126 { 0xC056, "TLS_DHE_DSS_WITH_ARIA_128_GCM_SHA256" },
1127 { 0xC057, "TLS_DHE_DSS_WITH_ARIA_256_GCM_SHA384" },
1128 { 0xC058, "TLS_DH_DSS_WITH_ARIA_128_GCM_SHA256" },
1129 { 0xC059, "TLS_DH_DSS_WITH_ARIA_256_GCM_SHA384" },
1130 { 0xC05A, "TLS_DH_anon_WITH_ARIA_128_GCM_SHA256" },
1131 { 0xC05B, "TLS_DH_anon_WITH_ARIA_256_GCM_SHA384" },
1132 { 0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256" },
1133 { 0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384" },
1134 { 0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256" },
1135 { 0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384" },
1136 { 0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256" },
1137 { 0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384" },
1138 { 0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256" },
1139 { 0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384" },
1140 { 0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256" },
1141 { 0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384" },
1142 { 0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256" },
1143 { 0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384" },
1144 { 0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256" },
1145 { 0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384" },
1146 { 0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256" },
1147 { 0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384" },
1148 { 0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256" },
1149 { 0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384" },
1150 { 0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256" },
1151 { 0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384" },
1152 { 0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256" },
1153 { 0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384" },
1154 /* RFC 6367 */
1155 { 0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" },
1156 { 0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" },
1157 { 0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256" },
1158 { 0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384" },
1159 { 0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
1160 { 0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384" },
1161 { 0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256" },
1162 { 0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384" },
1163 { 0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
1164 { 0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
1165 { 0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
1166 { 0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
1167 { 0xC07E, "TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
1168 { 0xC07F, "TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
1169 { 0xC080, "TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256" },
1170 { 0xC081, "TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384" },
1171 { 0xC082, "TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256" },
1172 { 0xC083, "TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384" },
1173 { 0xC084, "TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256" },
1174 { 0xC085, "TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384" },
1175 { 0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" },
1176 { 0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" },
1177 { 0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256" },
1178 { 0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384" },
1179 { 0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
1180 { 0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
1181 { 0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256" },
1182 { 0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384" },
1183 { 0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
1184 { 0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
1185 { 0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
1186 { 0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
1187 { 0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256" },
1188 { 0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384" },
1189 { 0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
1190 { 0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
1191 { 0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
1192 { 0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
1193 { 0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
1194 { 0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
1195 { 0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256" },
1196 { 0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384" },
1197 /* RFC 6655 */
1198 { 0xC09C, "TLS_RSA_WITH_AES_128_CCM" },
1199 { 0xC09D, "TLS_RSA_WITH_AES_256_CCM" },
1200 { 0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM" },
1201 { 0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM" },
1202 { 0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8" },
1203 { 0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8" },
1204 { 0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8" },
1205 { 0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8" },
1206 { 0xC0A4, "TLS_PSK_WITH_AES_128_CCM" },
1207 { 0xC0A5, "TLS_PSK_WITH_AES_256_CCM" },
1208 { 0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM" },
1209 { 0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM" },
1210 { 0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8" },
1211 { 0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8" },
1212 { 0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8" },
1213 { 0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8" },
1214 /* RFC 7251 */
1215 { 0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM" },
1216 { 0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM" },
1217 { 0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8" },
1218 { 0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8" },
1219 /* RFC 8492 */
1220 { 0xC0B0, "TLS_ECCPWD_WITH_AES_128_GCM_SHA256" },
1221 { 0xC0B1, "TLS_ECCPWD_WITH_AES_256_GCM_SHA384" },
1222 { 0xC0B2, "TLS_ECCPWD_WITH_AES_128_CCM_SHA256" },
1223 { 0xC0B3, "TLS_ECCPWD_WITH_AES_256_CCM_SHA384" },
1224 /* draft-camwinget-tls-ts13-macciphersuites */
1225 { 0xC0B4, "TLS_SHA256_SHA256" },
1226 { 0xC0B5, "TLS_SHA384_SHA384" },
1227 /* https://www.ietf.org/archive/id/draft-cragie-tls-ecjpake-01.txt */
1228 { 0xC0FF, "TLS_ECJPAKE_WITH_AES_128_CCM_8" },
1229 /* draft-smyshlyaev-tls12-gost-suites */
1230 { 0xC100, "TLS_GOSTR341112_256_WITH_KUZNYECHIK_CTR_OMAC" },
1231 { 0xC101, "TLS_GOSTR341112_256_WITH_MAGMA_CTR_OMAC" },
1232 { 0xC102, "TLS_GOSTR341112_256_WITH_28147_CNT_IMIT" },
1233 /* draft-smyshlyaev-tls13-gost-suites */
1234 { 0xC103, "TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_L" },
1235 { 0xC104, "TLS_GOSTR341112_256_WITH_MAGMA_MGM_L" },
1236 { 0xC105, "TLS_GOSTR341112_256_WITH_KUZNYECHIK_MGM_S" },
1237 { 0xC106, "TLS_GOSTR341112_256_WITH_MAGMA_MGM_S" },
1238 /* RFC 8701 */
1239 { 0xCACA, "Reserved (GREASE)" },
1240/*
12410xC0,0xAB-FF Unassigned
12420xC1,0x03-FD,* Unassigned
12430xFE,0x00-FD Unassigned
12440xFE,0xFE-FF Reserved to avoid conflicts with widely deployed implementations [Pasi_Eronen]
12450xFF,0x00-FF Reserved for Private Use [RFC5246]
1246*/
1247 /* old numbers used in the beginning
1248 * https://tools.ietf.org/html/draft-agl-tls-chacha20poly1305 */
1249 { 0xCC13, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1250 { 0xCC14, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
1251 { 0xCC15, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1252 /* RFC 7905 */
1253 { 0xCCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1254 { 0xCCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256" },
1255 { 0xCCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256" },
1256 { 0xCCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1257 { 0xCCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1258 { 0xCCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1259 { 0xCCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256" },
1260 /* RFC 8442 */
1261 { 0xD001, "TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256" },
1262 { 0xD002, "TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384" },
1263 { 0xD003, "TLS_ECDHE_PSK_WITH_AES_128_CCM_8_SHA256" },
1264 { 0xD005, "TLS_ECDHE_PSK_WITH_AES_128_CCM_SHA256" },
1265 /* RFC 8701 */
1266 { 0xDADA, "Reserved (GREASE)" },
1267 /* GM/T 0024-2014 */
1268 { 0xe001, "ECDHE_SM1_SM3"},
1269 { 0xe003, "ECC_SM1_SM3"},
1270 { 0xe005, "IBSDH_SM1_SM3"},
1271 { 0xe007, "IBC_SM1_SM3"},
1272 { 0xe009, "RSA_SM1_SM3"},
1273 { 0xe00a, "RSA_SM1_SHA1"},
1274 { 0xe011, "ECDHE_SM4_CBC_SM3"},
1275 { 0xe013, "ECC_SM4_CBC_SM3"},
1276 { 0xe015, "IBSDH_SM4_CBC_SM3"},
1277 { 0xe017, "IBC_SM4_CBC_SM3"},
1278 { 0xe019, "RSA_SM4_CBC_SM3"},
1279 { 0xe01a, "RSA_SM4_CBC_SHA1"},
1280 { 0xe01c, "RSA_SM4_CBC_SHA256"},
1281 { 0xe051, "ECDHE_SM4_GCM_SM3"},
1282 { 0xe053, "ECC_SM4_GCM_SM3"},
1283 { 0xe055, "IBSDH_SM4_GCM_SM3"},
1284 { 0xe057, "IBC_SM4_GCM_SM3"},
1285 { 0xe059, "RSA_SM4_GCM_SM3"},
1286 { 0xe05a, "RSA_SM4_GCM_SHA256"},
1287 /* https://tools.ietf.org/html/draft-josefsson-salsa20-tls */
1288 { 0xE410, "TLS_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1289 { 0xE411, "TLS_RSA_WITH_SALSA20_SHA1" },
1290 { 0xE412, "TLS_ECDHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1291 { 0xE413, "TLS_ECDHE_RSA_WITH_SALSA20_SHA1" },
1292 { 0xE414, "TLS_ECDHE_ECDSA_WITH_ESTREAM_SALSA20_SHA1" },
1293 { 0xE415, "TLS_ECDHE_ECDSA_WITH_SALSA20_SHA1" },
1294 { 0xE416, "TLS_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1295 { 0xE417, "TLS_PSK_WITH_SALSA20_SHA1" },
1296 { 0xE418, "TLS_ECDHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1297 { 0xE419, "TLS_ECDHE_PSK_WITH_SALSA20_SHA1" },
1298 { 0xE41A, "TLS_RSA_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1299 { 0xE41B, "TLS_RSA_PSK_WITH_SALSA20_SHA1" },
1300 { 0xE41C, "TLS_DHE_PSK_WITH_ESTREAM_SALSA20_SHA1" },
1301 { 0xE41D, "TLS_DHE_PSK_WITH_SALSA20_SHA1" },
1302 { 0xE41E, "TLS_DHE_RSA_WITH_ESTREAM_SALSA20_SHA1" },
1303 { 0xE41F, "TLS_DHE_RSA_WITH_SALSA20_SHA1" },
1304 /* RFC 8701 */
1305 { 0xEAEA, "Reserved (GREASE)" },
1306 { 0xFAFA, "Reserved (GREASE)" },
1307 /* these from http://www.mozilla.org/projects/
1308 security/pki/nss/ssl/fips-ssl-ciphersuites.html */
1309 { 0xfefe, "SSL_RSA_FIPS_WITH_DES_CBC_SHA"},
1310 { 0xfeff, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
1311 /* https://datatracker.ietf.org/doc/html/rfc9189 */
1312 { 0xff85, "TLS_GOSTR341112_256_WITH_28147_CNT_IMIT"},
1313 { 0xffe0, "SSL_RSA_FIPS_WITH_3DES_EDE_CBC_SHA" },
1314 { 0xffe1, "SSL_RSA_FIPS_WITH_DES_CBC_SHA" },
1315 /* note that ciphersuites 0xff00 - 0xffff are private */
1316 { 0x00, NULL((void*)0) }
1317};
1318
1319value_string_ext ssl_31_ciphersuite_ext = VALUE_STRING_EXT_INIT(ssl_31_ciphersuite){ _try_val_to_str_ext_init, 0, (sizeof (ssl_31_ciphersuite) /
sizeof ((ssl_31_ciphersuite)[0]))-1, ssl_31_ciphersuite, "ssl_31_ciphersuite"
, ((void*)0) }
;
1320
1321/* http://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#tls-extensiontype-values-1 */
1322const value_string tls_hello_extension_types[] = {
1323 { SSL_HND_HELLO_EXT_SERVER_NAME0, "server_name" }, /* RFC 6066 */
1324 { SSL_HND_HELLO_EXT_MAX_FRAGMENT_LENGTH1, "max_fragment_length" },/* RFC 6066 */
1325 { SSL_HND_HELLO_EXT_CLIENT_CERTIFICATE_URL2, "client_certificate_url" }, /* RFC 6066 */
1326 { SSL_HND_HELLO_EXT_TRUSTED_CA_KEYS3, "trusted_ca_keys" }, /* RFC 6066 */
1327 { SSL_HND_HELLO_EXT_TRUNCATED_HMAC4, "truncated_hmac" }, /* RFC 6066 */
1328 { SSL_HND_HELLO_EXT_STATUS_REQUEST5, "status_request" }, /* RFC 6066 */
1329 { SSL_HND_HELLO_EXT_USER_MAPPING6, "user_mapping" }, /* RFC 4681 */
1330 { SSL_HND_HELLO_EXT_CLIENT_AUTHZ7, "client_authz" }, /* RFC 5878 */
1331 { SSL_HND_HELLO_EXT_SERVER_AUTHZ8, "server_authz" }, /* RFC 5878 */
1332 { SSL_HND_HELLO_EXT_CERT_TYPE9, "cert_type" }, /* RFC 6091 */
1333 { SSL_HND_HELLO_EXT_SUPPORTED_GROUPS10, "supported_groups" }, /* RFC 4492, RFC 7919 */
1334 { SSL_HND_HELLO_EXT_EC_POINT_FORMATS11, "ec_point_formats" }, /* RFC 4492 */
1335 { SSL_HND_HELLO_EXT_SRP12, "srp" }, /* RFC 5054 */
1336 { SSL_HND_HELLO_EXT_SIGNATURE_ALGORITHMS13, "signature_algorithms" }, /* RFC 5246 */
1337 { SSL_HND_HELLO_EXT_USE_SRTP14, "use_srtp" }, /* RFC 5764 */
1338 { SSL_HND_HELLO_EXT_HEARTBEAT15, "heartbeat" }, /* RFC 6520 */
1339 { SSL_HND_HELLO_EXT_ALPN16, "application_layer_protocol_negotiation" }, /* RFC 7301 */
1340 { SSL_HND_HELLO_EXT_STATUS_REQUEST_V217, "status_request_v2" }, /* RFC 6961 */
1341 { SSL_HND_HELLO_EXT_SIGNED_CERTIFICATE_TIMESTAMP18, "signed_certificate_timestamp" }, /* RFC 6962 */
1342 { SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE19, "client_certificate_type" }, /* RFC 7250 */
1343 { SSL_HND_HELLO_EXT_SERVER_CERT_TYPE20, "server_certificate_type" }, /* RFC 7250 */
1344 { SSL_HND_HELLO_EXT_PADDING21, "padding" }, /* RFC 7685 */
1345 { SSL_HND_HELLO_EXT_ENCRYPT_THEN_MAC22, "encrypt_then_mac" }, /* RFC 7366 */
1346 { SSL_HND_HELLO_EXT_EXTENDED_MASTER_SECRET23, "extended_master_secret" }, /* RFC 7627 */
1347 { SSL_HND_HELLO_EXT_TOKEN_BINDING24, "token_binding" }, /* https://tools.ietf.org/html/draft-ietf-tokbind-negotiation */
1348 { SSL_HND_HELLO_EXT_CACHED_INFO25, "cached_info" }, /* RFC 7924 */
1349 { SSL_HND_HELLO_EXT_COMPRESS_CERTIFICATE27, "compress_certificate" }, /* https://tools.ietf.org/html/draft-ietf-tls-certificate-compression-03 */
1350 { SSL_HND_HELLO_EXT_RECORD_SIZE_LIMIT28, "record_size_limit" }, /* RFC 8449 */
1351 { SSL_HND_HELLO_EXT_DELEGATED_CREDENTIALS34, "delegated_credentials" }, /* draft-ietf-tls-subcerts-10.txt */
1352 { SSL_HND_HELLO_EXT_SESSION_TICKET_TLS35, "session_ticket" }, /* RFC 5077 / RFC 8447 */
1353 { SSL_HND_HELLO_EXT_KEY_SHARE_OLD40, "Reserved (key_share)" }, /* https://tools.ietf.org/html/draft-ietf-tls-tls13-22 (removed in -23) */
1354 { SSL_HND_HELLO_EXT_PRE_SHARED_KEY41, "pre_shared_key" }, /* RFC 8446 */
1355 { SSL_HND_HELLO_EXT_EARLY_DATA42, "early_data" }, /* RFC 8446 */
1356 { SSL_HND_HELLO_EXT_SUPPORTED_VERSIONS43, "supported_versions" }, /* RFC 8446 */
1357 { SSL_HND_HELLO_EXT_COOKIE44, "cookie" }, /* RFC 8446 */
1358 { SSL_HND_HELLO_EXT_PSK_KEY_EXCHANGE_MODES45, "psk_key_exchange_modes" }, /* RFC 8446 */
1359 { SSL_HND_HELLO_EXT_TICKET_EARLY_DATA_INFO46, "Reserved (ticket_early_data_info)" }, /* draft-ietf-tls-tls13-18 (removed in -19) */
1360 { SSL_HND_HELLO_EXT_CERTIFICATE_AUTHORITIES47, "certificate_authorities" }, /* RFC 8446 */
1361 { SSL_HND_HELLO_EXT_OID_FILTERS48, "oid_filters" }, /* RFC 8446 */
1362 { SSL_HND_HELLO_EXT_POST_HANDSHAKE_AUTH49, "post_handshake_auth" }, /* RFC 8446 */
1363 { SSL_HND_HELLO_EXT_SIGNATURE_ALGORITHMS_CERT50, "signature_algorithms_cert" }, /* RFC 8446 */
1364 { SSL_HND_HELLO_EXT_KEY_SHARE51, "key_share" }, /* RFC 8446 */
1365 { SSL_HND_HELLO_EXT_TRANSPARENCY_INFO52, "transparency_info" }, /* draft-ietf-trans-rfc6962-bis-41 */
1366 { SSL_HND_HELLO_EXT_CONNECTION_ID_DEPRECATED53, "connection_id (deprecated)" }, /* draft-ietf-tls-dtls-connection-id-07 */
1367 { SSL_HND_HELLO_EXT_CONNECTION_ID54, "connection_id" }, /* RFC 9146 */
1368 { SSL_HND_HELLO_EXT_EXTERNAL_ID_HASH55, "external_id_hash" }, /* RFC 8844 */
1369 { SSL_HND_HELLO_EXT_EXTERNAL_SESSION_ID56, "external_session_id" }, /* RFC 8844 */
1370 { SSL_HND_HELLO_EXT_QUIC_TRANSPORT_PARAMETERS_V157, "quic_transport_parameters" }, /* draft-ietf-quic-tls-33 */
1371 { SSL_HND_HELLO_EXT_TICKET_REQUEST58, "ticket_request" }, /* draft-ietf-tls-ticketrequests-07 */
1372 { SSL_HND_HELLO_EXT_DNSSEC_CHAIN59, "dnssec_chain" }, /* RFC 9102 */
1373 { SSL_HND_HELLO_EXT_GREASE_0A0A2570, "Reserved (GREASE)" }, /* RFC 8701 */
1374 { SSL_HND_HELLO_EXT_GREASE_1A1A6682, "Reserved (GREASE)" }, /* RFC 8701 */
1375 { SSL_HND_HELLO_EXT_GREASE_2A2A10794, "Reserved (GREASE)" }, /* RFC 8701 */
1376 { SSL_HND_HELLO_EXT_NPN13172, "next_protocol_negotiation"}, /* https://datatracker.ietf.org/doc/html/draft-agl-tls-nextprotoneg-03 */
1377 { SSL_HND_HELLO_EXT_GREASE_3A3A14906, "Reserved (GREASE)" }, /* RFC 8701 */
1378 { SSL_HND_HELLO_EXT_ALPS_OLD17513, "application_settings_old" }, /* draft-vvv-tls-alps-01 */
1379 { SSL_HND_HELLO_EXT_ALPS17613, "application_settings" }, /* draft-vvv-tls-alps-01 */ /* https://chromestatus.com/feature/5149147365900288 */
1380 { SSL_HND_HELLO_EXT_GREASE_4A4A19018, "Reserved (GREASE)" }, /* RFC 8701 */
1381 { SSL_HND_HELLO_EXT_GREASE_5A5A23130, "Reserved (GREASE)" }, /* RFC 8701 */
1382 { SSL_HND_HELLO_EXT_GREASE_6A6A27242, "Reserved (GREASE)" }, /* RFC 8701 */
1383 { SSL_HND_HELLO_EXT_CHANNEL_ID_OLD30031, "channel_id_old" }, /* https://tools.ietf.org/html/draft-balfanz-tls-channelid-00
1384 https://twitter.com/ericlaw/status/274237352531083264 */
1385 { SSL_HND_HELLO_EXT_CHANNEL_ID30032, "channel_id" }, /* https://tools.ietf.org/html/draft-balfanz-tls-channelid-01
1386 https://code.google.com/p/chromium/codesearch#chromium/src/net/third_party/nss/ssl/sslt.h&l=209 */
1387 { SSL_HND_HELLO_EXT_RENEGOTIATION_INFO65281, "renegotiation_info" }, /* RFC 5746 */
1388 { SSL_HND_HELLO_EXT_GREASE_7A7A31354, "Reserved (GREASE)" }, /* RFC 8701 */
1389 { SSL_HND_HELLO_EXT_GREASE_8A8A35466, "Reserved (GREASE)" }, /* RFC 8701 */
1390 { SSL_HND_HELLO_EXT_GREASE_9A9A39578, "Reserved (GREASE)" }, /* RFC 8701 */
1391 { SSL_HND_HELLO_EXT_GREASE_AAAA43690, "Reserved (GREASE)" }, /* RFC 8701 */
1392 { SSL_HND_HELLO_EXT_GREASE_BABA47802, "Reserved (GREASE)" }, /* RFC 8701 */
1393 { SSL_HND_HELLO_EXT_GREASE_CACA51914, "Reserved (GREASE)" }, /* RFC 8701 */
1394 { SSL_HND_HELLO_EXT_GREASE_DADA56026, "Reserved (GREASE)" }, /* RFC 8701 */
1395 { SSL_HND_HELLO_EXT_GREASE_EAEA60138, "Reserved (GREASE)" }, /* RFC 8701 */
1396 { SSL_HND_HELLO_EXT_GREASE_FAFA64250, "Reserved (GREASE)" }, /* RFC 8701 */
1397 { SSL_HND_HELLO_EXT_QUIC_TRANSPORT_PARAMETERS65445, "quic_transport_parameters (drafts version)" }, /* https://tools.ietf.org/html/draft-ietf-quic-tls */
1398 { SSL_HND_HELLO_EXT_ENCRYPTED_SERVER_NAME65486, "encrypted_server_name" }, /* https://tools.ietf.org/html/draft-ietf-tls-esni-01 */
1399 { SSL_HND_HELLO_EXT_ENCRYPTED_CLIENT_HELLO65037, "encrypted_client_hello" }, /* https://datatracker.ietf.org/doc/draft-ietf-tls-esni/17/ */
1400 { SSL_HND_HELLO_EXT_ECH_OUTER_EXTENSIONS64768, "ech_outer_extensions" }, /* https://datatracker.ietf.org/doc/draft-ietf-tls-esni/17/ */
1401 { 0, NULL((void*)0) }
1402};
1403
1404const value_string tls_hello_ext_server_name_type_vs[] = {
1405 { 0, "host_name" },
1406 { 0, NULL((void*)0) }
1407};
1408
1409/* RFC 6066 Section 4 */
1410const value_string tls_hello_ext_max_fragment_length[] = {
1411 { 1, "512" }, // 2^9
1412 { 2, "1024" }, // 2^10
1413 { 3, "2048" }, // 2^11
1414 { 4, "4096" }, // 2^12
1415 { 0, NULL((void*)0) }
1416};
1417
1418/* RFC 8446 Section 4.2.9 */
1419const value_string tls_hello_ext_psk_ke_mode[] = {
1420 { 0, "PSK-only key establishment (psk_ke)" },
1421 { 1, "PSK with (EC)DHE key establishment (psk_dhe_ke)" },
1422 { 0, NULL((void*)0) }
1423};
1424
1425/* RFC 6066 Section 6 */
1426const value_string tls_hello_ext_trusted_ca_key_type[] = {
1427 {0, "pre_agreed"},
1428 {1, "key_sha1_hash"},
1429 {2, "x509_name"},
1430 {3, "cert_sha1_hash"},
1431 {0, NULL((void*)0)}
1432};
1433
1434const value_string tls13_key_update_request[] = {
1435 { 0, "update_not_requested" },
1436 { 1, "update_requested" },
1437 { 0, NULL((void*)0) }
1438};
1439
1440/* RFC 5246 7.4.1.4.1 */
1441/* https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml */
1442/* Note that the TLS 1.3 SignatureScheme registry reserves all values
1443 * with first octet 0x00-0x06 and all values with second octet 0x00-0x03
1444 * for backwards compatibility with TLS 1.2 SignatureAndHashAlgorithm.
1445 *
1446 * RFC 8422 and RFC 9189 add official support in TLS 1.2 for some algorithms
1447 * originally defined for TLS 1.3, and extend the TLS SignatureAlgorithm
1448 * and TLS HashAlgorithm registries, but the new values are not compatible
1449 * with all of the TLS 1.3-only SignatureSchemes. Adding those values could
1450 * cause confusion if used to interpret one of those schemes in a
1451 * signature_algorithms extension offered in a TLS 1.3 ClientHello.
1452 */
1453const value_string tls_hash_algorithm[] = {
1454 { 0, "None" },
1455 { 1, "MD5" },
1456 { 2, "SHA1" },
1457 { 3, "SHA224" },
1458 { 4, "SHA256" },
1459 { 5, "SHA384" },
1460 { 6, "SHA512" },
1461#if 0
1462 /* RFC 8422 adds this to the HashAlgorithm registry, but it really
1463 * only applies to 0x0807 and 0x0808, not for other TLS 1.3
1464 * SignatureSchemes with 0x08 in the octet used for Hash in TLS 1.2.
1465 * E.g., we don't want to display this for 0x0806 rsa_pss_rsae_sha512.
1466 */
1467 { 8, "Intrinsic" },
1468#endif
1469 { 0, NULL((void*)0) }
1470};
1471
1472const value_string tls_signature_algorithm[] = {
1473 { 0, "Anonymous" },
1474 { 1, "RSA" },
1475 { 2, "DSA" },
1476 { 3, "ECDSA" },
1477#if 0
1478 /* As above. */
1479 { 7, "ED25519" },
1480 { 8, "ED448" },
1481 { 64, "GOSTR34102012_256" },
1482 { 65, "GOSTR34102012_512" },
1483#endif
1484 { 0, NULL((void*)0) }
1485};
1486
1487/* RFC 8446 Section 4.2.3 */
1488const value_string tls13_signature_algorithm[] = {
1489 { 0x0201, "rsa_pkcs1_sha1" },
1490 { 0x0203, "ecdsa_sha1" },
1491 { 0x0401, "rsa_pkcs1_sha256" },
1492 { 0x0403, "ecdsa_secp256r1_sha256" },
1493 { 0x0420, "rsa_pkcs1_sha256_legacy" }, /* draft-davidben-tls13-pkcs1-01 */
1494 { 0x0501, "rsa_pkcs1_sha384" },
1495 { 0x0503, "ecdsa_secp384r1_sha384" },
1496 { 0x0520, "rsa_pkcs1_sha384_legacy" }, /* draft-davidben-tls13-pkcs1-01 */
1497 { 0x0601, "rsa_pkcs1_sha512" },
1498 { 0x0603, "ecdsa_secp521r1_sha512" },
1499 { 0x0620, "rsa_pkcs1_sha512_legacy" }, /* draft-davidben-tls13-pkcs1-01 */
1500 { 0x0704, "eccsi_sha256" }, /* draft-wang-tls-raw-public-key-with-ibc-02 */
1501 { 0x0705, "iso_ibs1" }, /* draft-wang-tls-raw-public-key-with-ibc-02 */
1502 { 0x0706, "iso_ibs2" }, /* draft-wang-tls-raw-public-key-with-ibc-02 */
1503 { 0x0707, "iso_chinese_ibs" }, /* draft-wang-tls-raw-public-key-with-ibc-02 */
1504 { 0x0708, "sm2sig_sm3" },
1505 { 0x0709, "gostr34102012_256a" }, /* RFC9367 */
1506 { 0x070a, "gostr34102012_256b" }, /* RFC9367 */
1507 { 0x070b, "gostr34102012_256c" }, /* RFC9367 */
1508 { 0x070c, "gostr34102012_256d" }, /* RFC9367 */
1509 { 0x070d, "gostr34102012_512a" }, /* RFC9367 */
1510 { 0x070e, "gostr34102012_512b" }, /* RFC9367 */
1511 { 0x070f, "gostr34102012_512c" }, /* RFC9367 */
1512 { 0x0804, "rsa_pss_rsae_sha256" },
1513 { 0x0805, "rsa_pss_rsae_sha384" },
1514 { 0x0806, "rsa_pss_rsae_sha512" },
1515 { 0x0807, "ed25519" },
1516 { 0x0808, "ed448" },
1517 { 0x0809, "rsa_pss_pss_sha256" },
1518 { 0x080a, "rsa_pss_pss_sha384" },
1519 { 0x080b, "rsa_pss_pss_sha512" },
1520 { 0x081a, "ecdsa_brainpoolP256r1tls13_sha256" }, /* RFC8734 */
1521 { 0x081b, "ecdsa_brainpoolP384r1tls13_sha384" }, /* RFC8734 */
1522 { 0x081c, "ecdsa_brainpoolP512r1tls13_sha512" }, /* RFC8734 */
1523 { 0x0904, "mldsa44" }, /* draft-ietf-tls-mldsa-00 */
1524 { 0x0905, "mldsa65" }, /* draft-ietf-tls-mldsa-00 */
1525 { 0x0906, "mldsa87" }, /* draft-ietf-tls-mldsa-00 */
1526 { 0x0911, "slhdsa_sha2_128s" }, /* draft-reddy-tls-slhdsa-01 */
1527 { 0x0912, "slhdsa_sha2_128f" }, /* draft-reddy-tls-slhdsa-01 */
1528 { 0x0913, "slhdsa_sha2_192s" }, /* draft-reddy-tls-slhdsa-01 */
1529 { 0x0914, "slhdsa_sha2_192f" }, /* draft-reddy-tls-slhdsa-01 */
1530 { 0x0915, "slhdsa_sha2_256s" }, /* draft-reddy-tls-slhdsa-01 */
1531 { 0x0916, "slhdsa_sha2_256f" }, /* draft-reddy-tls-slhdsa-01 */
1532 { 0x0917, "slhdsa_shake_128s" }, /* draft-reddy-tls-slhdsa-01 */
1533 { 0x0918, "slhdsa_shake_128f" }, /* draft-reddy-tls-slhdsa-01 */
1534 { 0x0919, "slhdsa_shake_192s" }, /* draft-reddy-tls-slhdsa-01 */
1535 { 0x091a, "slhdsa_shake_192f" }, /* draft-reddy-tls-slhdsa-01 */
1536 { 0x091b, "slhdsa_shake_256s" }, /* draft-reddy-tls-slhdsa-01 */
1537 { 0x091c, "slhdsa_shake_256f" }, /* draft-reddy-tls-slhdsa-01 */
1538 { 0x0a0a, "GREASE" },
1539 { 0x1a1a, "GREASE" },
1540 { 0x2a2a, "GREASE" },
1541 { 0x3a3a, "GREASE" },
1542 { 0x4a4a, "GREASE" },
1543 { 0x5a5a, "GREASE" },
1544 { 0x6a6a, "GREASE" },
1545 { 0x7a7a, "GREASE" },
1546 { 0x8a8a, "GREASE" },
1547 { 0x9a9a, "GREASE" },
1548 { 0xaaaa, "GREASE" },
1549 { 0xbaba, "GREASE" },
1550 { 0xcaca, "GREASE" },
1551 { 0xdada, "GREASE" },
1552 { 0xeaea, "GREASE" },
1553 { 0xfafa, "GREASE" },
1554 /* PQC digital signature algorithms from OQS-OpenSSL,
1555 see https://github.com/open-quantum-safe/oqs-provider/blob/main/oqs-template/oqs-sig-info.md */
1556 { 0xfea0, "dilithium2" },
1557 { 0xfea1, "p256_dilithium2" },
1558 { 0xfea2, "rsa3072_dilithium2" },
1559 { 0xfea3, "dilithium3" },
1560 { 0xfea4, "p384_dilithium3" },
1561 { 0xfea5, "dilithium5" },
1562 { 0xfea6, "p521_dilithium5" },
1563 { 0xfea7, "dilithium2_aes" },
1564 { 0xfea8, "p256_dilithium2_aes" },
1565 { 0xfea9, "rsa3072_dilithium2_aes" },
1566 { 0xfeaa, "dilithium3_aes" },
1567 { 0xfeab, "p384_dilithium3_aes" },
1568 { 0xfeac, "dilithium5_aes" },
1569 { 0xfead, "p521_dilithium5_aes" },
1570 { 0xfe0b, "falcon512" },
1571 { 0xfe0c, "p256_falcon512" },
1572 { 0xfe0d, "rsa3072_falcon512" },
1573 { 0xfe0e, "falcon1024" },
1574 { 0xfe0f, "p521_falcon1024" },
1575 { 0xfe96, "picnicl1full" },
1576 { 0xfe97, "p256_picnicl1full" },
1577 { 0xfe98, "rsa3072_picnicl1full" },
1578 { 0xfe1b, "picnic3l1" },
1579 { 0xfe1c, "p256_picnic3l1" },
1580 { 0xfe1d, "rsa3072_picnic3l1" },
1581 { 0xfe27, "rainbowIclassic" },
1582 { 0xfe28, "p256_rainbowIclassic" },
1583 { 0xfe29, "rsa3072_rainbowIclassic" },
1584 { 0xfe3c, "rainbowVclassic" },
1585 { 0xfe3d, "p521_rainbowVclassic" },
1586 { 0xfe42, "sphincsharaka128frobust" },
1587 { 0xfe43, "p256_sphincsharaka128frobust" },
1588 { 0xfe44, "rsa3072_sphincsharaka128frobust" },
1589 { 0xfe5e, "sphincssha256128frobust" },
1590 { 0xfe5f, "p256_sphincssha256128frobust" },
1591 { 0xfe60, "rsa3072_sphincssha256128frobust" },
1592 { 0xfe7a, "sphincsshake256128frobust" },
1593 { 0xfe7b, "p256_sphincsshake256128frobust" },
1594 { 0xfe7c, "rsa3072_sphincsshake256128frobust" },
1595 { 0, NULL((void*)0) }
1596};
1597
1598/* RFC 6091 3.1 */
1599const value_string tls_certificate_type[] = {
1600 { 0, "X.509" },
1601 { 1, "OpenPGP" },
1602 { SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY2, "Raw Public Key" }, /* RFC 7250 */
1603 { 0, NULL((void*)0) }
1604};
1605
1606const value_string tls_cert_chain_type[] = {
1607 { SSL_HND_CERT_URL_TYPE_INDIVIDUAL_CERT1, "Individual Certificates" },
1608 { SSL_HND_CERT_URL_TYPE_PKIPATH2, "PKI Path" },
1609 { 0, NULL((void*)0) }
1610};
1611
1612const value_string tls_cert_status_type[] = {
1613 { SSL_HND_CERT_STATUS_TYPE_OCSP1, "OCSP" },
1614 { SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI2, "OCSP Multi" },
1615 { 0, NULL((void*)0) }
1616};
1617
1618/* Generated by tools/dissector_generators/generate-tls-ct-logids.py
1619 * Last-Modified Sat, 17 Oct 2026 14:08:00 GMT, 45 entries. */
1620static const bytes_string ct_logids[] = {
1621 { (const uint8_t[]){
1622 0x0e, 0x57, 0x94, 0xbc, 0xf3, 0xae, 0xa9, 0x3e, 0x33, 0x1b, 0x2c,
1623 0x99, 0x07, 0xb3, 0xf7, 0x90, 0xdf, 0x9b, 0xc2, 0x3d, 0x71, 0x32,
1624 0x25, 0xdd, 0x21, 0xa9, 0x25, 0xac, 0x61, 0xc5, 0x4e, 0x21,
1625 },
1626 32, "Google Argon2026h1" },
1627 { (const uint8_t[]){
1628 0xd7, 0x6d, 0x7d, 0x10, 0xd1, 0xa7, 0xf5, 0x77, 0xc2, 0xc7, 0xe9,
1629 0x5f, 0xd7, 0x00, 0xbf, 0xf9, 0x82, 0xc9, 0x33, 0x5a, 0x65, 0xe1,
1630 0xd0, 0xb3, 0x01, 0x73, 0x17, 0xc0, 0xc8, 0xc5, 0x69, 0x77,
1631 },
1632 32, "Google Argon2026h2" },
1633 { (const uint8_t[]){
1634 0xd6, 0xd5, 0x8d, 0xa9, 0xd0, 0x17, 0x53, 0xf3, 0x6a, 0x4a, 0xa0,
1635 0xc7, 0x57, 0x49, 0x02, 0xaf, 0xeb, 0xc7, 0xdc, 0x2c, 0xd3, 0x8c,
1636 0xd9, 0xf7, 0x64, 0xc8, 0x0c, 0x89, 0x19, 0x1e, 0x9f, 0x02,
1637 },
1638 32, "Google Argon2027h1" },
1639 { (const uint8_t[]){
1640 0x96, 0x97, 0x64, 0xbf, 0x55, 0x58, 0x97, 0xad, 0xf7, 0x43, 0x87,
1641 0x68, 0x37, 0x08, 0x42, 0x77, 0xe9, 0xf0, 0x3a, 0xd5, 0xf6, 0xa4,
1642 0xf3, 0x36, 0x6e, 0x46, 0xa4, 0x3f, 0x0f, 0xca, 0xa9, 0xc6,
1643 },
1644 32, "Google Xenon2026h1" },
1645 { (const uint8_t[]){
1646 0xd8, 0x09, 0x55, 0x3b, 0x94, 0x4f, 0x7a, 0xff, 0xc8, 0x16, 0x19,
1647 0x6f, 0x94, 0x4f, 0x85, 0xab, 0xb0, 0xf8, 0xfc, 0x5e, 0x87, 0x55,
1648 0x26, 0x0f, 0x15, 0xd1, 0x2e, 0x72, 0xbb, 0x45, 0x4b, 0x14,
1649 },
1650 32, "Google Xenon2026h2" },
1651 { (const uint8_t[]){
1652 0x44, 0xc2, 0xbd, 0x0c, 0xe9, 0x14, 0x0e, 0x64, 0xa5, 0xc9, 0x4a,
1653 0x01, 0x93, 0x0a, 0x5a, 0xa1, 0xbb, 0x35, 0x97, 0x0e, 0x00, 0xee,
1654 0x11, 0x16, 0x89, 0x68, 0x2a, 0x1c, 0x44, 0xd7, 0xb5, 0x66,
1655 },
1656 32, "Google Xenon2027h1" },
1657 { (const uint8_t[]){
1658 0xa8, 0x99, 0xd8, 0x78, 0x0c, 0x92, 0x90, 0xaa, 0xf4, 0x62, 0xf3,
1659 0x18, 0x80, 0xcc, 0xfb, 0xd5, 0x24, 0x51, 0xe9, 0x70, 0xd0, 0xfb,
1660 0xf5, 0x91, 0xef, 0x75, 0xb0, 0xd9, 0x9b, 0x64, 0x56, 0x81,
1661 },
1662 32, "Google Submariner" },
1663 { (const uint8_t[]){
1664 0x1d, 0x02, 0x4b, 0x8e, 0xb1, 0x49, 0x8b, 0x34, 0x4d, 0xfd, 0x87,
1665 0xea, 0x3e, 0xfc, 0x09, 0x96, 0xf7, 0x50, 0x6f, 0x23, 0x5d, 0x1d,
1666 0x49, 0x70, 0x61, 0xa4, 0x77, 0x3c, 0x43, 0x9c, 0x25, 0xfb,
1667 },
1668 32, "Google Daedalus" },
1669 { (const uint8_t[]){
1670 0xb0, 0xcc, 0x83, 0xe5, 0xa5, 0xf9, 0x7d, 0x6b, 0xaf, 0x7c, 0x09,
1671 0xcc, 0x28, 0x49, 0x04, 0x87, 0x2a, 0xc7, 0xe8, 0x8b, 0x13, 0x2c,
1672 0x63, 0x50, 0xb7, 0xc6, 0xfd, 0x26, 0xe1, 0x6c, 0x6c, 0x77,
1673 },
1674 32, "Google Testtube" },
1675 { (const uint8_t[]){
1676 0xc3, 0xbf, 0x03, 0xa7, 0xe1, 0xca, 0x88, 0x41, 0xc6, 0x07, 0xba,
1677 0xe3, 0xff, 0x42, 0x70, 0xfc, 0xa5, 0xec, 0x45, 0xb1, 0x86, 0xeb,
1678 0xbe, 0x4e, 0x2c, 0xf3, 0xfc, 0x77, 0x86, 0x30, 0xf5, 0xf6,
1679 },
1680 32, "Google Crucible" },
1681 { (const uint8_t[]){
1682 0xc8, 0x4b, 0x90, 0x7a, 0x07, 0xbe, 0xaa, 0x29, 0xa6, 0x14, 0xc2,
1683 0x45, 0x84, 0xb7, 0xa3, 0xf6, 0x62, 0x43, 0x94, 0x68, 0x7b, 0x25,
1684 0xfe, 0x62, 0x83, 0x8b, 0x71, 0xec, 0x42, 0x2a, 0xd2, 0xf9,
1685 },
1686 32, "Google Solera2026h1" },
1687 { (const uint8_t[]){
1688 0x62, 0xe9, 0x00, 0x60, 0x04, 0xa3, 0x07, 0x95, 0x5a, 0x75, 0x44,
1689 0xb4, 0xd5, 0x84, 0xa9, 0x62, 0x68, 0xca, 0x1d, 0x6e, 0x45, 0x85,
1690 0xad, 0xf0, 0x91, 0x6d, 0xfe, 0x5f, 0xdc, 0x1f, 0x04, 0xdb,
1691 },
1692 32, "Google Solera2026h2" },
1693 { (const uint8_t[]){
1694 0x3d, 0xe4, 0x92, 0xa8, 0x98, 0x93, 0xad, 0x70, 0x5e, 0x78, 0x46,
1695 0xed, 0x21, 0xd4, 0x8d, 0xca, 0xfb, 0xad, 0x13, 0x9e, 0xa6, 0x4e,
1696 0xd1, 0xe3, 0x49, 0xf9, 0x00, 0xb0, 0xa2, 0xcd, 0xa5, 0xe2,
1697 },
1698 32, "Google Solera2027h1" },
1699 { (const uint8_t[]){
1700 0xcb, 0x38, 0xf7, 0x15, 0x89, 0x7c, 0x84, 0xa1, 0x44, 0x5f, 0x5b,
1701 0xc1, 0xdd, 0xfb, 0xc9, 0x6e, 0xf2, 0x9a, 0x59, 0xcd, 0x47, 0x0a,
1702 0x69, 0x05, 0x85, 0xb0, 0xcb, 0x14, 0xc3, 0x14, 0x58, 0xe7,
1703 },
1704 32, "Cloudflare Nimbus2026" },
1705 { (const uint8_t[]){
1706 0x4c, 0x63, 0xdc, 0x98, 0xe5, 0x9c, 0x1d, 0xab, 0x88, 0xf6, 0x1e,
1707 0x8a, 0x3d, 0xde, 0xae, 0x8f, 0xab, 0x44, 0xa3, 0x37, 0x7b, 0x5f,
1708 0x9b, 0x94, 0xc3, 0xfb, 0xa1, 0x9c, 0xfc, 0xc1, 0xbe, 0x26,
1709 },
1710 32, "Cloudflare Nimbus2027" },
1711 { (const uint8_t[]){
1712 0x64, 0x11, 0xc4, 0x6c, 0xa4, 0x12, 0xec, 0xa7, 0x89, 0x1c, 0xa2,
1713 0x02, 0x2e, 0x00, 0xbc, 0xab, 0x4f, 0x28, 0x07, 0xd4, 0x1e, 0x35,
1714 0x27, 0xab, 0xea, 0xfe, 0xd5, 0x03, 0xc9, 0x7d, 0xcd, 0xf0,
1715 },
1716 32, "DigiCert Wyvern2026h1" },
1717 { (const uint8_t[]){
1718 0xc2, 0x31, 0x7e, 0x57, 0x45, 0x19, 0xa3, 0x45, 0xee, 0x7f, 0x38,
1719 0xde, 0xb2, 0x90, 0x41, 0xeb, 0xc7, 0xc2, 0x21, 0x5a, 0x22, 0xbf,
1720 0x7f, 0xd5, 0xb5, 0xad, 0x76, 0x9a, 0xd9, 0x0e, 0x52, 0xcd,
1721 },
1722 32, "DigiCert Wyvern2026h2" },
1723 { (const uint8_t[]){
1724 0x00, 0x1a, 0x5d, 0x1a, 0x1c, 0x2d, 0x93, 0x75, 0xb6, 0x48, 0x55,
1725 0x78, 0xf8, 0x2f, 0x71, 0xa1, 0xae, 0x6e, 0xef, 0x39, 0x7d, 0x29,
1726 0x7c, 0x8a, 0xe3, 0x15, 0x7b, 0xca, 0xde, 0xe1, 0xa0, 0x1e,
1727 },
1728 32, "DigiCert Wyvern2027h1" },
1729 { (const uint8_t[]){
1730 0x37, 0xaa, 0x07, 0xcc, 0x21, 0x6f, 0x2e, 0x6d, 0x91, 0x9c, 0x70,
1731 0x9d, 0x24, 0xd8, 0xf7, 0x31, 0xb0, 0x0f, 0x2b, 0x14, 0x7c, 0x62,
1732 0x1c, 0xc0, 0x91, 0xa5, 0xfa, 0x1a, 0x84, 0xd8, 0x16, 0xdd,
1733 },
1734 32, "DigiCert Wyvern2027h2" },
1735 { (const uint8_t[]){
1736 0x49, 0x9c, 0x9b, 0x69, 0xde, 0x1d, 0x7c, 0xec, 0xfc, 0x36, 0xde,
1737 0xcd, 0x87, 0x64, 0xa6, 0xb8, 0x5b, 0xaf, 0x0a, 0x87, 0x80, 0x19,
1738 0xd1, 0x55, 0x52, 0xfb, 0xe9, 0xeb, 0x29, 0xdd, 0xf8, 0xc3,
1739 },
1740 32, "DigiCert Sphinx2026h1" },
1741 { (const uint8_t[]){
1742 0x94, 0x4e, 0x43, 0x87, 0xfa, 0xec, 0xc1, 0xef, 0x81, 0xf3, 0x19,
1743 0x24, 0x26, 0xa8, 0x18, 0x65, 0x01, 0xc7, 0xd3, 0x5f, 0x38, 0x02,
1744 0x01, 0x3f, 0x72, 0x67, 0x7d, 0x55, 0x37, 0x2e, 0x19, 0xd8,
1745 },
1746 32, "DigiCert Sphinx2026h2" },
1747 { (const uint8_t[]){
1748 0x46, 0xa2, 0x39, 0x67, 0xc6, 0x0d, 0xb6, 0x46, 0x87, 0xc6, 0x6f,
1749 0x3d, 0xf9, 0x99, 0x94, 0x76, 0x93, 0xa6, 0xa6, 0x11, 0x20, 0x84,
1750 0x57, 0xd5, 0x55, 0xe7, 0xe3, 0xd0, 0xa1, 0xd9, 0xb6, 0x46,
1751 },
1752 32, "DigiCert Sphinx2027h1" },
1753 { (const uint8_t[]){
1754 0x1f, 0xb0, 0xf8, 0xa9, 0x2d, 0x8a, 0xdd, 0xa1, 0x21, 0x77, 0x6c,
1755 0x05, 0xe2, 0xaa, 0x2e, 0x15, 0xba, 0xcb, 0xc6, 0x2b, 0x65, 0x39,
1756 0x36, 0x95, 0x57, 0x6a, 0xaa, 0xb5, 0x2e, 0x11, 0xd1, 0x1d,
1757 },
1758 32, "DigiCert Sphinx2027h2" },
1759 { (const uint8_t[]){
1760 0x25, 0x2f, 0x94, 0xc2, 0x2b, 0x29, 0xe9, 0x6e, 0x9f, 0x41, 0x1a,
1761 0x72, 0x07, 0x2b, 0x69, 0x5c, 0x5b, 0x52, 0xff, 0x97, 0xa9, 0x0d,
1762 0x25, 0x40, 0xbb, 0xfc, 0xdc, 0x51, 0xec, 0x4d, 0xee, 0x0b,
1763 },
1764 32, "Sectigo Mammoth2026h1" },
1765 { (const uint8_t[]){
1766 0x94, 0xb1, 0xc1, 0x8a, 0xb0, 0xd0, 0x57, 0xc4, 0x7b, 0xe0, 0xac,
1767 0x04, 0x0e, 0x1f, 0x2c, 0xbc, 0x8d, 0xc3, 0x75, 0x72, 0x7b, 0xc9,
1768 0x51, 0xf2, 0x0a, 0x52, 0x61, 0x26, 0x86, 0x3b, 0xa7, 0x3c,
1769 },
1770 32, "Sectigo Mammoth2026h2" },
1771 { (const uint8_t[]){
1772 0x56, 0x6c, 0xd5, 0xa3, 0x76, 0xbe, 0x83, 0xdf, 0xe3, 0x42, 0xb6,
1773 0x75, 0xc4, 0x9c, 0x23, 0x24, 0x98, 0xa7, 0x69, 0xba, 0xc3, 0x82,
1774 0xcb, 0xab, 0x49, 0xa3, 0x87, 0x7d, 0x9a, 0xb3, 0x2d, 0x01,
1775 },
1776 32, "Sectigo Sabre2026h1" },
1777 { (const uint8_t[]){
1778 0x1f, 0x56, 0xd1, 0xab, 0x94, 0x70, 0x4a, 0x41, 0xdd, 0x3f, 0xea,
1779 0xfd, 0xf4, 0x69, 0x93, 0x55, 0x30, 0x2c, 0x14, 0x31, 0xbf, 0xe6,
1780 0x13, 0x46, 0x08, 0x9f, 0xff, 0xae, 0x79, 0x5d, 0xcc, 0x2f,
1781 },
1782 32, "Sectigo Sabre2026h2" },
1783 { (const uint8_t[]){
1784 0xd1, 0x6e, 0xa9, 0xa5, 0x68, 0x07, 0x7e, 0x66, 0x35, 0xa0, 0x3f,
1785 0x37, 0xa5, 0xdd, 0xbc, 0x03, 0xa5, 0x3c, 0x41, 0x12, 0x14, 0xd4,
1786 0x88, 0x18, 0xf5, 0xe9, 0x31, 0xb3, 0x23, 0xcb, 0x95, 0x04,
1787 },
1788 32, "Sectigo Elephant2026h1" },
1789 { (const uint8_t[]){
1790 0xaf, 0x67, 0x88, 0x3b, 0x57, 0xb0, 0x4e, 0xdd, 0x8f, 0xa6, 0xd9,
1791 0x7e, 0xf6, 0x2e, 0xa8, 0xeb, 0x81, 0x0a, 0xc7, 0x71, 0x60, 0xf0,
1792 0x24, 0x5e, 0x55, 0xd6, 0x0c, 0x2f, 0xe7, 0x85, 0x87, 0x3a,
1793 },
1794 32, "Sectigo Elephant2026h2" },
1795 { (const uint8_t[]){
1796 0x60, 0x4c, 0x9a, 0xaf, 0x7a, 0x7f, 0x77, 0x5f, 0x01, 0xd4, 0x06,
1797 0xfc, 0x92, 0x0d, 0xc8, 0x99, 0xeb, 0x0b, 0x1c, 0x7d, 0xf8, 0xc9,
1798 0x52, 0x1b, 0xfa, 0xfa, 0x17, 0x77, 0x3b, 0x97, 0x8b, 0xc9,
1799 },
1800 32, "Sectigo Elephant2027h1" },
1801 { (const uint8_t[]){
1802 0xa2, 0x49, 0x0c, 0xdc, 0xdb, 0x8e, 0x33, 0xa4, 0x00, 0x32, 0x17,
1803 0x60, 0xd6, 0xd4, 0xd5, 0x1a, 0x20, 0x36, 0x19, 0x1e, 0xa7, 0x7d,
1804 0x96, 0x8b, 0xe2, 0x6a, 0x8a, 0x00, 0xf6, 0xff, 0xff, 0xf7,
1805 },
1806 32, "Sectigo Elephant2027h2" },
1807 { (const uint8_t[]){
1808 0x16, 0x83, 0x2d, 0xab, 0xf0, 0xa9, 0x25, 0x0f, 0x0f, 0xf0, 0x3a,
1809 0xa5, 0x45, 0xff, 0xc8, 0xbf, 0xc8, 0x23, 0xd0, 0x87, 0x4b, 0xf6,
1810 0x04, 0x29, 0x27, 0xf8, 0xe7, 0x1f, 0x33, 0x13, 0xf5, 0xfa,
1811 },
1812 32, "Sectigo Tiger2026h1" },
1813 { (const uint8_t[]){
1814 0xc8, 0xa3, 0xc4, 0x7f, 0xc7, 0xb3, 0xad, 0xb9, 0x35, 0x6b, 0x01,
1815 0x3f, 0x6a, 0x7a, 0x12, 0x6d, 0xe3, 0x3a, 0x4e, 0x43, 0xa5, 0xc6,
1816 0x46, 0xf9, 0x97, 0xad, 0x39, 0x75, 0x99, 0x1d, 0xcf, 0x9a,
1817 },
1818 32, "Sectigo Tiger2026h2" },
1819 { (const uint8_t[]){
1820 0x1c, 0x9f, 0x68, 0x2c, 0xe9, 0xfa, 0xf0, 0x45, 0x69, 0x50, 0xf8,
1821 0x1b, 0x96, 0x8a, 0x87, 0xdd, 0xdb, 0x32, 0x10, 0xd8, 0x4c, 0xe6,
1822 0xc8, 0xb2, 0xe3, 0x82, 0x52, 0x4a, 0xc4, 0xcf, 0x59, 0x9f,
1823 },
1824 32, "Sectigo Tiger2027h1" },
1825 { (const uint8_t[]){
1826 0x03, 0x80, 0x2a, 0xc2, 0x62, 0xf6, 0xe0, 0x5e, 0x03, 0xf8, 0xbc,
1827 0x6f, 0x7b, 0x98, 0x51, 0x32, 0x4f, 0xd7, 0x6a, 0x3d, 0xf5, 0xb7,
1828 0x59, 0x51, 0x75, 0xe2, 0x22, 0xfb, 0x8e, 0x9b, 0xd5, 0xf6,
1829 },
1830 32, "Sectigo Tiger2027h2" },
1831 { (const uint8_t[]){
1832 0x61, 0xa3, 0x5d, 0xc3, 0x98, 0x06, 0x1b, 0x2a, 0x59, 0x5b, 0xfe,
1833 0x34, 0x46, 0x89, 0x95, 0x18, 0xf0, 0xfe, 0xac, 0x14, 0xb0, 0x1b,
1834 0xe0, 0x2a, 0x93, 0xbf, 0x05, 0x21, 0x46, 0x3a, 0x9d, 0xbd,
1835 },
1836 32, "Sectigo Dumbo" },
1837 { (const uint8_t[]){
1838 0xbe, 0x31, 0xd3, 0x65, 0x88, 0xdf, 0xd8, 0x05, 0xc8, 0x6d, 0x35,
1839 0x20, 0x29, 0x84, 0xac, 0xc9, 0xaa, 0x44, 0xae, 0xe3, 0x84, 0x08,
1840 0x0b, 0x9f, 0xcf, 0x42, 0xeb, 0xc8, 0x73, 0x55, 0xe4, 0x9b,
1841 },
1842 32, "Sectigo Tigger2026" },
1843 { (const uint8_t[]){
1844 0xfa, 0x63, 0x12, 0x74, 0x9a, 0xdc, 0xc8, 0x19, 0x95, 0x4e, 0x3e,
1845 0xf3, 0x01, 0x1d, 0x42, 0x67, 0x76, 0x88, 0xd4, 0x47, 0x1c, 0xfe,
1846 0xf6, 0x35, 0x3f, 0x89, 0x1d, 0xc8, 0x7c, 0x12, 0xac, 0xd4,
1847 },
1848 32, "Sectigo Tigger2027" },
1849 { (const uint8_t[]){
1850 0x19, 0x86, 0xd4, 0xc7, 0x28, 0xaa, 0x6f, 0xfe, 0xba, 0x03, 0x6f,
1851 0x78, 0x2a, 0x4d, 0x01, 0x91, 0xaa, 0xce, 0x2d, 0x72, 0x31, 0x0f,
1852 0xae, 0xce, 0x5d, 0x70, 0x41, 0x2d, 0x25, 0x4c, 0xc7, 0xd4,
1853 },
1854 32, "Let's Encrypt Oak2026h1" },
1855 { (const uint8_t[]){
1856 0xac, 0xab, 0x30, 0x70, 0x6c, 0xeb, 0xec, 0x84, 0x31, 0xf4, 0x13,
1857 0xd2, 0xf4, 0x91, 0x5f, 0x11, 0x1e, 0x42, 0x24, 0x43, 0xb1, 0xf2,
1858 0xa6, 0x8c, 0x4f, 0x3c, 0x2b, 0x3b, 0xa7, 0x1e, 0x02, 0xc3,
1859 },
1860 32, "Let's Encrypt Oak2026h2" },
1861 { (const uint8_t[]){
1862 0x74, 0xdb, 0x9d, 0x58, 0xf7, 0xd4, 0x7e, 0x9d, 0xfd, 0x78, 0x7a,
1863 0x16, 0x2a, 0x99, 0x1c, 0x18, 0xcf, 0x69, 0x8d, 0xa7, 0xc7, 0x29,
1864 0x91, 0x8c, 0x9a, 0x18, 0xb0, 0x45, 0x0d, 0xba, 0x44, 0xbc,
1865 },
1866 32, "TrustAsia log2026a" },
1867 { (const uint8_t[]){
1868 0x25, 0xb7, 0xef, 0xde, 0xa1, 0x13, 0x01, 0x93, 0xed, 0x93, 0x07,
1869 0x97, 0x70, 0xaa, 0x32, 0x2a, 0x26, 0x62, 0x0d, 0xe3, 0x5a, 0xc8,
1870 0xaa, 0x7c, 0x75, 0x19, 0x7d, 0xe0, 0xb1, 0xa9, 0xe0, 0x65,
1871 },
1872 32, "TrustAsia log2026b" },
1873 { (const uint8_t[]){
1874 0xed, 0xda, 0xeb, 0x81, 0x5c, 0x63, 0x21, 0x34, 0x49, 0xb4, 0x7b,
1875 0xe5, 0x07, 0x79, 0x05, 0xab, 0xd0, 0xd9, 0x31, 0x47, 0xc2, 0x7a,
1876 0xc5, 0x14, 0x6b, 0x3b, 0xc5, 0x8e, 0x43, 0xe9, 0xb6, 0xc7,
1877 },
1878 32, "TrustAsia HETU2027" },
1879 { (const uint8_t[]){
1880 0x2e, 0xd6, 0xa4, 0x4d, 0xeb, 0x8f, 0x0c, 0x86, 0x46, 0x67, 0x76,
1881 0x9c, 0x4e, 0xdd, 0x04, 0x1f, 0x84, 0x23, 0x67, 0x55, 0xfa, 0x3a,
1882 0xac, 0xa6, 0x34, 0xd0, 0x93, 0x5d, 0xfc, 0xd5, 0x9a, 0x70,
1883 },
1884 32, "Bogus placeholder log to unbreak misbehaving CT libraries" },
1885 { (const uint8_t[]){
1886 0xd2, 0xfc, 0x65, 0x2f, 0xa5, 0xf9, 0xb7, 0x38, 0xb8, 0x37, 0x55,
1887 0xfa, 0x5e, 0xb1, 0x5f, 0x0b, 0x45, 0x25, 0x3f, 0x4e, 0x8f, 0xa3,
1888 0xb9, 0xb6, 0x4f, 0xd4, 0xde, 0x56, 0x62, 0xd1, 0x87, 0x08,
1889 },
1890 32, "Bogus RFC6962 log to avoid breaking misbehaving CT libraries" },
1891 { NULL((void*)0), 0, NULL((void*)0) }
1892};
1893
1894/*
1895 * Application-Layer Protocol Negotiation (ALPN) dissector tables.
1896 */
1897static dissector_table_t ssl_alpn_dissector_table;
1898static dissector_table_t dtls_alpn_dissector_table;
1899
1900/*
1901 * Special cases for prefix matching of the ALPN, if the ALPN includes
1902 * a version number for a draft or protocol revision.
1903 */
1904typedef struct ssl_alpn_prefix_match_protocol {
1905 const char *proto_prefix;
1906 const char *dissector_name;
1907} ssl_alpn_prefix_match_protocol_t;
1908
1909static const ssl_alpn_prefix_match_protocol_t ssl_alpn_prefix_match_protocols[] = {
1910 /* SPDY moves so fast, just 1, 2 and 3 are registered with IANA but there
1911 * already exists 3.1 as of this writing... match the prefix. */
1912 { "spdy/", "spdy" },
1913 /* draft-ietf-httpbis-http2-16 */
1914 { "h2-", "http2" }, /* draft versions */
1915};
1916
1917const value_string compress_certificate_algorithm_vals[] = {
1918 { 1, "zlib" },
1919 { 2, "brotli" },
1920 { 3, "zstd" },
1921 { 0, NULL((void*)0) }
1922};
1923
1924
1925const val64_string quic_transport_parameter_id[] = {
1926 { SSL_HND_QUIC_TP_ORIGINAL_DESTINATION_CONNECTION_ID0x00, "original_destination_connection_id" },
1927 { SSL_HND_QUIC_TP_MAX_IDLE_TIMEOUT0x01, "max_idle_timeout" },
1928 { SSL_HND_QUIC_TP_STATELESS_RESET_TOKEN0x02, "stateless_reset_token" },
1929 { SSL_HND_QUIC_TP_MAX_UDP_PAYLOAD_SIZE0x03, "max_udp_payload_size" },
1930 { SSL_HND_QUIC_TP_INITIAL_MAX_DATA0x04, "initial_max_data" },
1931 { SSL_HND_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL0x05, "initial_max_stream_data_bidi_local" },
1932 { SSL_HND_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE0x06, "initial_max_stream_data_bidi_remote" },
1933 { SSL_HND_QUIC_TP_INITIAL_MAX_STREAM_DATA_UNI0x07, "initial_max_stream_data_uni" },
1934 { SSL_HND_QUIC_TP_INITIAL_MAX_STREAMS_UNI0x09, "initial_max_streams_uni" },
1935 { SSL_HND_QUIC_TP_INITIAL_MAX_STREAMS_BIDI0x08, "initial_max_streams_bidi" },
1936 { SSL_HND_QUIC_TP_ACK_DELAY_EXPONENT0x0a, "ack_delay_exponent" },
1937 { SSL_HND_QUIC_TP_MAX_ACK_DELAY0x0b, "max_ack_delay" },
1938 { SSL_HND_QUIC_TP_DISABLE_ACTIVE_MIGRATION0x0c, "disable_active_migration" },
1939 { SSL_HND_QUIC_TP_PREFERRED_ADDRESS0x0d, "preferred_address" },
1940 { SSL_HND_QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT0x0e, "active_connection_id_limit" },
1941 { SSL_HND_QUIC_TP_INITIAL_SOURCE_CONNECTION_ID0x0f, "initial_source_connection_id" },
1942 { SSL_HND_QUIC_TP_RETRY_SOURCE_CONNECTION_ID0x10, "retry_source_connection_id" },
1943 { SSL_HND_QUIC_TP_MAX_DATAGRAM_FRAME_SIZE0x20, "max_datagram_frame_size" },
1944 { SSL_HND_QUIC_TP_CIBIR_ENCODING0x1000, "cibir_encoding" },
1945 { SSL_HND_QUIC_TP_LOSS_BITS0x1057, "loss_bits" },
1946 { SSL_HND_QUIC_TP_GREASE_QUIC_BIT0x2ab2, "grease_quic_bit" },
1947 { SSL_HND_QUIC_TP_ENABLE_TIME_STAMP0x7157, "enable_time_stamp" },
1948 { SSL_HND_QUIC_TP_ENABLE_TIME_STAMP_V20x7158, "enable_time_stamp_v2" },
1949 { SSL_HND_QUIC_TP_VERSION_INFORMATION0x11, "version_information" },
1950 { SSL_HND_QUIC_TP_VERSION_INFORMATION_DRAFT0xff73db, "version_information_draft" },
1951 { SSL_HND_QUIC_TP_MIN_ACK_DELAY_OLD0xde1a, "min_ack_delay" },
1952 { SSL_HND_QUIC_TP_GOOGLE_USER_AGENT0x3129, "google_user_agent" },
1953 { SSL_HND_QUIC_TP_GOOGLE_KEY_UPDATE_NOT_YET_SUPPORTED0x312B, "google_key_update_not_yet_supported" },
1954 { SSL_HND_QUIC_TP_GOOGLE_QUIC_VERSION0x4752, "google_quic_version" },
1955 { SSL_HND_QUIC_TP_GOOGLE_INITIAL_RTT0x3127, "google_initial_rtt" },
1956 { SSL_HND_QUIC_TP_GOOGLE_SUPPORT_HANDSHAKE_DONE0x312A, "google_support_handshake_done" },
1957 { SSL_HND_QUIC_TP_GOOGLE_QUIC_PARAMS0x4751, "google_quic_params" },
1958 { SSL_HND_QUIC_TP_GOOGLE_CONNECTION_OPTIONS0x3128, "google_connection_options" },
1959 { SSL_HND_QUIC_TP_FACEBOOK_PARTIAL_RELIABILITY0xFF00, "facebook_partial_reliability" },
1960 { SSL_HND_QUIC_TP_ADDRESS_DISCOVERY0x9f81a176, "address_discovery" },
1961 { SSL_HND_QUIC_TP_MIN_ACK_DELAY_DRAFT_V10xFF03DE1A, "min_ack_delay (draft-01)" },
1962 { SSL_HND_QUIC_TP_MIN_ACK_DELAY_DRAFT050xff04de1a, "min_ack_delay (draft-05)" },
1963 { SSL_HND_QUIC_TP_MIN_ACK_DELAY0xff04de1b, "min_ack_delay" },
1964 { SSL_HND_QUIC_TP_ENABLE_MULTIPATH_DRAFT040x0f739bbc1b666d04, "enable_multipath (draft-04)" },
1965 { SSL_HND_QUIC_TP_ENABLE_MULTIPATH_DRAFT050x0f739bbc1b666d05, "enable_multipath (draft-05)" },
1966 { SSL_HND_QUIC_TP_ENABLE_MULTIPATH0x0f739bbc1b666d06, "enable_multipath (draft-06)" },
1967 { SSL_HND_QUIC_TP_INITIAL_MAX_PATHS0x0f739bbc1b666d07, "initial_max_paths (draft-07/08)" },
1968 { SSL_HND_QUIC_TP_INITIAL_MAX_PATH_ID_DRAFT090x0f739bbc1b666d09, "initial_max_path_id (draft-09/10)" },
1969 { SSL_HND_QUIC_TP_INITIAL_MAX_PATH_ID_DRAFT110x0f739bbc1b666d11, "initial_max_path_id (draft-11)" },
1970 { SSL_HND_QUIC_TP_INITIAL_MAX_PATH_ID_DRAFT120x0f739bbc1b666d0c, "initial_max_path_id (draft-12)" },
1971 { SSL_HND_QUIC_TP_INITIAL_MAX_PATH_ID_DRAFT130x0f739bbc1b666d0d, "initial_max_path_id (draft-13)" },
1972 { SSL_HND_QUIC_TP_INITIAL_MAX_PATH_ID0x3e, "initial_max_path_id" },
1973 { 0, NULL((void*)0) }
1974};
1975
1976/* https://tools.ietf.org/html/draft-ietf-quic-address-discovery-00 */
1977const val64_string quic_address_discovery_vals[] = {
1978 { 0, "The node is willing to provide address observations to its peer, but is not interested in receiving address observations itself" },
1979 { 1, "The node is interested in receiving address observations, but it is not willing to provide address observations" },
1980 { 2, "The node is interested in receiving address observations, and it is willing to provide address observations" },
1981 { 0, NULL((void*)0) }
1982};
1983
1984/* https://tools.ietf.org/html/draft-huitema-quic-ts-03 */
1985const val64_string quic_enable_time_stamp_v2_vals[] = {
1986 { 1, "I would like to receive TIME_STAMP frames" },
1987 { 2, "I am able to generate TIME_STAMP frames" },
1988 { 3, "I am able to generate TIME_STAMP frames and I would like to receive them" },
1989 { 0, NULL((void*)0) }
1990};
1991
1992/* https://datatracker.ietf.org/doc/draft-ietf-quic-multipath/04/ */
1993const val64_string quic_enable_multipath_vals[] = {
1994 { 0, "don't support multipath" },
1995 { 1, "support multipath as defined in this document" },
1996 { 0, NULL((void*)0) }
1997};
1998
1999/* https://www.ietf.org/archive/id/draft-ietf-tls-esni-16.txt */
2000const value_string tls_hello_ext_ech_clienthello_types[] = {
2001 { 0, "Outer Client Hello" },
2002 { 1, "Inner Client Hello" },
2003 { 0, NULL((void*)0) }
2004};
2005
2006/* RFC 9180 */
2007const value_string kem_id_type_vals[] = {
2008 { 0x0000, "Reserved" },
2009 { 0x0010, "DHKEM(P-256, HKDF-SHA256)" },
2010 { 0x0011, "DHKEM(P-384, HKDF-SHA384)" },
2011 { 0x0012, "DHKEM(P-521, HKDF-SHA512)" },
2012 { 0x0020, "DHKEM(X25519, HKDF-SHA256)" },
2013 { 0x0021, "DHKEM(X448, HKDF-SHA512)" },
2014 { 0, NULL((void*)0) }
2015};
2016const value_string kdf_id_type_vals[] = {
2017 { 0x0000, "Reserved" },
2018 { 0x0001, "HKDF-SHA256" },
2019 { 0x0002, "HKDF-SHA384" },
2020 { 0x0003, "HKDF-SHA512" },
2021 { 0, NULL((void*)0) }
2022};
2023const value_string aead_id_type_vals[] = {
2024 { 0x0000, "Reserved" },
2025 { 0x0001, "AES-128-GCM" },
2026 { 0x0002, "AES-256-GCM" },
2027 { 0x0003, "ChaCha20Poly1305" },
2028 { 0xFFFF, "Export-only" },
2029 { 0, NULL((void*)0) }
2030};
2031
2032const value_string token_binding_key_parameter_vals[] = {
2033 { 0, "rsa2048_pkcs1.5" },
2034 { 1, "rsa2048_pss" },
2035 { 2, "ecdsap256" },
2036 { 0, NULL((void*)0) }
2037};
2038
2039/* Lookup tables }}} */
2040
2041void
2042quic_transport_parameter_id_base_custom(char *result, uint64_t parameter_id)
2043{
2044 const char *label;
2045 if (IS_GREASE_QUIC(parameter_id)((parameter_id) > 27 ? ((((parameter_id) - 27) % 31) == 0)
: 0)
) {
2046 label = "GREASE";
2047 } else {
2048 label = val64_to_str_const(parameter_id, quic_transport_parameter_id, "Unknown");
2049 }
2050 snprintf(result, ITEM_LABEL_LENGTH240, "%s (0x%02" PRIx64"l" "x" ")", label, parameter_id);
2051}
2052
2053/* we keep this internal to packet-tls-utils, as there should be
2054 no need to access it any other way.
2055
2056 This also allows us to hide the dependency on zlib.
2057*/
2058struct _SslDecompress {
2059 int compression;
2060#ifdef USE_ZLIB_OR_ZLIBNG
2061 zlib_stream istream;
2062#endif
2063};
2064
2065/* To assist in parsing client/server key exchange messages
2066 0 indicates unknown */
2067int ssl_get_keyex_alg(int cipher)
2068{
2069 /* Map Cipher suite number to Key Exchange algorithm {{{ */
2070 switch(cipher) {
2071 case 0x0017:
2072 case 0x0018:
2073 case 0x0019:
2074 case 0x001a:
2075 case 0x001b:
2076 case 0x0034:
2077 case 0x003a:
2078 case 0x0046:
2079 case 0x006c:
2080 case 0x006d:
2081 case 0x0089:
2082 case 0x009b:
2083 case 0x00a6:
2084 case 0x00a7:
2085 case 0x00bf:
2086 case 0x00c5:
2087 case 0xc084:
2088 case 0xc085:
2089 return KEX_DH_ANON0x13;
2090 case 0x000b:
2091 case 0x000c:
2092 case 0x000d:
2093 case 0x0030:
2094 case 0x0036:
2095 case 0x003e:
2096 case 0x0042:
2097 case 0x0068:
2098 case 0x0085:
2099 case 0x0097:
2100 case 0x00a4:
2101 case 0x00a5:
2102 case 0x00bb:
2103 case 0x00c1:
2104 case 0xc082:
2105 case 0xc083:
2106 return KEX_DH_DSS0x14;
2107 case 0x000e:
2108 case 0x000f:
2109 case 0x0010:
2110 case 0x0031:
2111 case 0x0037:
2112 case 0x003f:
2113 case 0x0043:
2114 case 0x0069:
2115 case 0x0086:
2116 case 0x0098:
2117 case 0x00a0:
2118 case 0x00a1:
2119 case 0x00bc:
2120 case 0x00c2:
2121 case 0xc07e:
2122 case 0xc07f:
2123 return KEX_DH_RSA0x15;
2124 case 0x0011:
2125 case 0x0012:
2126 case 0x0013:
2127 case 0x0032:
2128 case 0x0038:
2129 case 0x0040:
2130 case 0x0044:
2131 case 0x0063:
2132 case 0x0065:
2133 case 0x0066:
2134 case 0x006a:
2135 case 0x0087:
2136 case 0x0099:
2137 case 0x00a2:
2138 case 0x00a3:
2139 case 0x00bd:
2140 case 0x00c3:
2141 case 0xc080:
2142 case 0xc081:
2143 return KEX_DHE_DSS0x10;
2144 case 0x002d:
2145 case 0x008e:
2146 case 0x008f:
2147 case 0x0090:
2148 case 0x0091:
2149 case 0x00aa:
2150 case 0x00ab:
2151 case 0x00b2:
2152 case 0x00b3:
2153 case 0x00b4:
2154 case 0x00b5:
2155 case 0xc090:
2156 case 0xc091:
2157 case 0xc096:
2158 case 0xc097:
2159 case 0xc0a6:
2160 case 0xc0a7:
2161 case 0xc0aa:
2162 case 0xc0ab:
2163 case 0xccad:
2164 case 0xe41c:
2165 case 0xe41d:
2166 return KEX_DHE_PSK0x11;
2167 case 0x0014:
2168 case 0x0015:
2169 case 0x0016:
2170 case 0x0033:
2171 case 0x0039:
2172 case 0x0045:
2173 case 0x0067:
2174 case 0x006b:
2175 case 0x0088:
2176 case 0x009a:
2177 case 0x009e:
2178 case 0x009f:
2179 case 0x00be:
2180 case 0x00c4:
2181 case 0xc07c:
2182 case 0xc07d:
2183 case 0xc09e:
2184 case 0xc09f:
2185 case 0xc0a2:
2186 case 0xc0a3:
2187 case 0xccaa:
2188 case 0xe41e:
2189 case 0xe41f:
2190 return KEX_DHE_RSA0x12;
2191 case 0xc015:
2192 case 0xc016:
2193 case 0xc017:
2194 case 0xc018:
2195 case 0xc019:
2196 return KEX_ECDH_ANON0x19;
2197 case 0xc001:
2198 case 0xc002:
2199 case 0xc003:
2200 case 0xc004:
2201 case 0xc005:
2202 case 0xc025:
2203 case 0xc026:
2204 case 0xc02d:
2205 case 0xc02e:
2206 case 0xc074:
2207 case 0xc075:
2208 case 0xc088:
2209 case 0xc089:
2210 return KEX_ECDH_ECDSA0x1a;
2211 case 0xc00b:
2212 case 0xc00c:
2213 case 0xc00d:
2214 case 0xc00e:
2215 case 0xc00f:
2216 case 0xc029:
2217 case 0xc02a:
2218 case 0xc031:
2219 case 0xc032:
2220 case 0xc078:
2221 case 0xc079:
2222 case 0xc08c:
2223 case 0xc08d:
2224 return KEX_ECDH_RSA0x1b;
2225 case 0xc006:
2226 case 0xc007:
2227 case 0xc008:
2228 case 0xc009:
2229 case 0xc00a:
2230 case 0xc023:
2231 case 0xc024:
2232 case 0xc02b:
2233 case 0xc02c:
2234 case 0xc072:
2235 case 0xc073:
2236 case 0xc086:
2237 case 0xc087:
2238 case 0xc0ac:
2239 case 0xc0ad:
2240 case 0xc0ae:
2241 case 0xc0af:
2242 case 0xcca9:
2243 case 0xe414:
2244 case 0xe415:
2245 return KEX_ECDHE_ECDSA0x16;
2246 case 0xc033:
2247 case 0xc034:
2248 case 0xc035:
2249 case 0xc036:
2250 case 0xc037:
2251 case 0xc038:
2252 case 0xc039:
2253 case 0xc03a:
2254 case 0xc03b:
2255 case 0xc09a:
2256 case 0xc09b:
2257 case 0xccac:
2258 case 0xe418:
2259 case 0xe419:
2260 case 0xd001:
2261 case 0xd002:
2262 case 0xd003:
2263 case 0xd005:
2264 return KEX_ECDHE_PSK0x17;
2265 case 0xc010:
2266 case 0xc011:
2267 case 0xc012:
2268 case 0xc013:
2269 case 0xc014:
2270 case 0xc027:
2271 case 0xc028:
2272 case 0xc02f:
2273 case 0xc030:
2274 case 0xc076:
2275 case 0xc077:
2276 case 0xc08a:
2277 case 0xc08b:
2278 case 0xcca8:
2279 case 0xe412:
2280 case 0xe413:
2281 return KEX_ECDHE_RSA0x18;
2282 case 0x001e:
2283 case 0x001f:
2284 case 0x0020:
2285 case 0x0021:
2286 case 0x0022:
2287 case 0x0023:
2288 case 0x0024:
2289 case 0x0025:
2290 case 0x0026:
2291 case 0x0027:
2292 case 0x0028:
2293 case 0x0029:
2294 case 0x002a:
2295 case 0x002b:
2296 return KEX_KRB50x1c;
2297 case 0x002c:
2298 case 0x008a:
2299 case 0x008b:
2300 case 0x008c:
2301 case 0x008d:
2302 case 0x00a8:
2303 case 0x00a9:
2304 case 0x00ae:
2305 case 0x00af:
2306 case 0x00b0:
2307 case 0x00b1:
2308 case 0xc064:
2309 case 0xc065:
2310 case 0xc08e:
2311 case 0xc08f:
2312 case 0xc094:
2313 case 0xc095:
2314 case 0xc0a4:
2315 case 0xc0a5:
2316 case 0xc0a8:
2317 case 0xc0a9:
2318 case 0xccab:
2319 case 0xe416:
2320 case 0xe417:
2321 return KEX_PSK0x1d;
2322 case 0x0001:
2323 case 0x0002:
2324 case 0x0003:
2325 case 0x0004:
2326 case 0x0005:
2327 case 0x0006:
2328 case 0x0007:
2329 case 0x0008:
2330 case 0x0009:
2331 case 0x000a:
2332 case 0x002f:
2333 case 0x0035:
2334 case 0x003b:
2335 case 0x003c:
2336 case 0x003d:
2337 case 0x0041:
2338 case 0x0060:
2339 case 0x0061:
2340 case 0x0062:
2341 case 0x0064:
2342 case 0x0084:
2343 case 0x0096:
2344 case 0x009c:
2345 case 0x009d:
2346 case 0x00ba:
2347 case 0x00c0:
2348 case 0xc07a:
2349 case 0xc07b:
2350 case 0xc09c:
2351 case 0xc09d:
2352 case 0xc0a0:
2353 case 0xc0a1:
2354 case 0xe410:
2355 case 0xe411:
2356 case 0xfefe:
2357 case 0xfeff:
2358 case 0xffe0:
2359 case 0xffe1:
2360 return KEX_RSA0x1e;
2361 case 0x002e:
2362 case 0x0092:
2363 case 0x0093:
2364 case 0x0094:
2365 case 0x0095:
2366 case 0x00ac:
2367 case 0x00ad:
2368 case 0x00b6:
2369 case 0x00b7:
2370 case 0x00b8:
2371 case 0x00b9:
2372 case 0xc092:
2373 case 0xc093:
2374 case 0xc098:
2375 case 0xc099:
2376 case 0xccae:
2377 case 0xe41a:
2378 case 0xe41b:
2379 return KEX_RSA_PSK0x1f;
2380 case 0xc01a:
2381 case 0xc01d:
2382 case 0xc020:
2383 return KEX_SRP_SHA0x20;
2384 case 0xc01c:
2385 case 0xc01f:
2386 case 0xc022:
2387 return KEX_SRP_SHA_DSS0x21;
2388 case 0xc01b:
2389 case 0xc01e:
2390 case 0xc021:
2391 return KEX_SRP_SHA_RSA0x22;
2392 case 0xc0ff:
2393 return KEX_ECJPAKE0x24;
2394 case 0xe003:
2395 case 0xe013:
2396 case 0xe053:
2397 return KEX_ECC_SM20x26;
2398 default:
2399 break;
2400 }
2401
2402 return 0;
2403 /* }}} */
2404}
2405
2406/* Sessions by connection ID. The key is one length byte followed by the CID
2407 * bytes. cid_lens_seen lists the distinct CID lengths in the map, so a
2408 * lookup costs one hash lookup per distinct length rather than a walk over
2409 * all sessions. */
2410static wmem_map_t *cid_session_map;
2411static uint8_t cid_lens_seen[256];
2412static unsigned n_cid_lens_seen;
2413
2414static unsigned
2415cid_key_hash(const void *key)
2416{
2417 const uint8_t *k = (const uint8_t *)key;
2418 return wmem_strong_hash(k, (size_t)k[0] + 1);
2419}
2420
2421static gboolean
2422cid_key_equal(const void *a, const void *b)
2423{
2424 const uint8_t *ka = (const uint8_t *)a;
2425 const uint8_t *kb = (const uint8_t *)b;
2426 return ka[0] == kb[0] && memcmp(ka, kb, (size_t)ka[0] + 1) == 0;
2427}
2428
2429void
2430ssl_init_cid_list(void) {
2431 cid_session_map = wmem_map_new(wmem_file_scope(), cid_key_hash, cid_key_equal);
2432 n_cid_lens_seen = 0;
2433}
2434
2435void
2436ssl_cleanup_cid_list(void) {
2437 /* The map lives in file scope and is freed with it. */
2438 cid_session_map = NULL((void*)0);
2439 n_cid_lens_seen = 0;
2440}
2441
2442static void
2443ssl_map_cid(SslDecryptSession *session, const uint8_t *cid, uint8_t cid_len)
2444{
2445 uint8_t *key;
2446 unsigned i;
2447
2448 if (cid == NULL((void*)0) || cid_len == 0)
2449 return;
2450 key = (uint8_t *)wmem_alloc(wmem_file_scope(), (size_t)cid_len + 1);
2451 key[0] = cid_len;
2452 memcpy(key + 1, cid, cid_len);
2453 if (wmem_map_lookup(cid_session_map, key) == session) {
2454 wmem_free(wmem_file_scope(), key);
2455 return;
2456 }
2457 /* A later session with the same CID replaces an earlier one. */
2458 wmem_map_insert(cid_session_map, key, session);
2459 for (i = 0; i < n_cid_lens_seen; i++) {
2460 if (cid_lens_seen[i] == cid_len)
2461 return;
2462 }
2463 cid_lens_seen[n_cid_lens_seen++] = cid_len;
2464}
2465
2466void
2467ssl_add_session_by_cid(SslDecryptSession *session)
2468{
2469 if (cid_session_map == NULL((void*)0))
2470 return;
2471 ssl_map_cid(session, session->session.client_cid, session->session.client_cid_len);
2472 ssl_map_cid(session, session->session.server_cid, session->session.server_cid_len);
2473 session->session.cid_listed = true1;
2474}
2475
2476SslDecryptSession *
2477ssl_get_session_by_cid(tvbuff_t *tvb, uint32_t offset)
2478{
2479 uint8_t key[256];
2480 unsigned i;
2481
2482 if (cid_session_map == NULL((void*)0))
2483 return NULL((void*)0);
2484
2485 for (i = 0; i < n_cid_lens_seen; i++) {
2486 uint8_t len = cid_lens_seen[i];
2487 SslDecryptSession *ssl;
2488
2489 if (!tvb_bytes_exist(tvb, offset, len))
2490 continue;
2491 key[0] = len;
2492 tvb_memcpy(tvb, key + 1, offset, len);
2493 ssl = (SslDecryptSession *)wmem_map_lookup(cid_session_map, key);
2494 if (ssl != NULL((void*)0))
2495 return ssl;
2496 }
2497
2498 return NULL((void*)0);
2499}
2500
2501/* StringInfo structure (len + data) functions {{{ */
2502
2503int
2504ssl_data_alloc(StringInfo* str, size_t len)
2505{
2506 str->data = (unsigned char *)g_malloc(len);
2507 /* the allocator can return a null pointer for a size equal to 0,
2508 * and that must be allowed */
2509 if (len > 0 && !str->data)
2510 return -1;
2511 str->data_len = (unsigned) len;
2512 return 0;
2513}
2514
2515void
2516ssl_data_set(StringInfo* str, const unsigned char* data, unsigned len)
2517{
2518 DISSECTOR_ASSERT(data)((void) ((data) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/dissectors/packet-tls-utils.c", 2518, "data"))))
;
2519 memcpy(str->data, data, len);
2520 str->data_len = len;
2521}
2522
2523static int
2524ssl_data_realloc(StringInfo* str, unsigned len)
2525{
2526 str->data = (unsigned char *)g_realloc(str->data, len);
2527 if (!str->data)
2528 return -1;
2529 str->data_len = len;
2530 return 0;
2531}
2532
2533static StringInfo *
2534ssl_data_clone(StringInfo *str)
2535{
2536 StringInfo *cloned_str;
2537 cloned_str = (StringInfo *) wmem_alloc0(wmem_file_scope(),
2538 sizeof(StringInfo) + str->data_len);
2539 cloned_str->data = (unsigned char *) (cloned_str + 1);
2540 ssl_data_set(cloned_str, str->data, str->data_len);
2541 return cloned_str;
2542}
2543
2544static int
2545ssl_data_copy(StringInfo* dst, StringInfo* src)
2546{
2547 if (dst->data_len < src->data_len) {
2548 if (ssl_data_realloc(dst, src->data_len))
2549 return -1;
2550 }
2551 memcpy(dst->data, src->data, src->data_len);
2552 dst->data_len = src->data_len;
2553 return 0;
2554}
2555
2556/* from_hex converts |hex_len| bytes of hex data from |in| and sets |*out| to
2557 * the result. |out->data| will be allocated using wmem_file_scope. Returns true on
2558 * success. */
2559static bool_Bool from_hex(StringInfo* out, const char* in, size_t hex_len) {
2560 size_t i;
2561
2562 if (hex_len & 1)
2563 return false0;
2564
2565 out->data = (unsigned char *)wmem_alloc(wmem_file_scope(), hex_len / 2);
2566 for (i = 0; i < hex_len / 2; i++) {
2567 int a = ws_xton(in[i*2]);
2568 int b = ws_xton(in[i*2 + 1]);
2569 if (a == -1 || b == -1)
2570 return false0;
2571 out->data[i] = a << 4 | b;
2572 }
2573 out->data_len = (unsigned)hex_len / 2;
2574 return true1;
2575}
2576/* StringInfo structure (len + data) functions }}} */
2577
2578
2579/* libgcrypt wrappers for HMAC/message digest operations {{{ */
2580/* hmac abstraction layer */
2581#define SSL_HMACgcry_md_hd_t gcry_md_hd_t
2582
2583static inline int
2584ssl_hmac_init(SSL_HMACgcry_md_hd_t* md, int algo)
2585{
2586 gcry_error_t err;
2587 const char *err_str, *err_src;
2588
2589 err = gcry_md_open(md,algo, GCRY_MD_FLAG_HMAC);
2590 if (err != 0) {
2591 err_str = gcry_strerror(err);
2592 err_src = gcry_strsource(err);
2593 ssl_debug_printf("ssl_hmac_init(): gcry_md_open failed %s/%s", err_str, err_src);
2594 return -1;
2595 }
2596 return 0;
2597}
2598
2599static inline int
2600ssl_hmac_setkey(SSL_HMACgcry_md_hd_t* md, const void * key, int len)
2601{
2602 gcry_error_t err;
2603 const char *err_str, *err_src;
2604
2605 err = gcry_md_setkey (*(md), key, len);
2606 if (err != 0) {
2607 err_str = gcry_strerror(err);
2608 err_src = gcry_strsource(err);
2609 ssl_debug_printf("ssl_hmac_setkey(): gcry_md_setkey failed %s/%s", err_str, err_src);
2610 return -1;
2611 }
2612 return 0;
2613}
2614
2615static inline int
2616ssl_hmac_reset(SSL_HMACgcry_md_hd_t* md)
2617{
2618 gcry_md_reset(*md);
2619 return 0;
2620}
2621
2622static inline void
2623ssl_hmac_update(SSL_HMACgcry_md_hd_t* md, const void* data, int len)
2624{
2625 gcry_md_write(*(md), data, len);
2626}
2627static inline void
2628ssl_hmac_final(SSL_HMACgcry_md_hd_t* md, unsigned char* data, unsigned* datalen)
2629{
2630 int algo;
2631 unsigned len;
2632
2633 algo = gcry_md_get_algo (*(md));
2634 len = gcry_md_get_algo_dlen(algo);
2635 DISSECTOR_ASSERT(len <= *datalen)((void) ((len <= *datalen) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-tls-utils.c"
, 2635, "len <= *datalen"))))
;
2636 memcpy(data, gcry_md_read(*(md), algo), len);
2637 *datalen = len;
2638}
2639static inline void
2640ssl_hmac_cleanup(SSL_HMACgcry_md_hd_t* md)
2641{
2642 gcry_md_close(*(md));
2643}
2644
2645/* message digest abstraction layer*/
2646#define SSL_MDgcry_md_hd_t gcry_md_hd_t
2647
2648static inline int
2649ssl_md_init(SSL_MDgcry_md_hd_t* md, int algo)
2650{
2651 gcry_error_t err;
2652 const char *err_str, *err_src;
2653 err = gcry_md_open(md,algo, 0);
2654 if (err != 0) {
2655 err_str = gcry_strerror(err);
2656 err_src = gcry_strsource(err);
2657 ssl_debug_printf("ssl_md_init(): gcry_md_open failed %s/%s", err_str, err_src);
2658 return -1;
2659 }
2660 return 0;
2661}
2662static inline void
2663ssl_md_update(SSL_MDgcry_md_hd_t* md, const unsigned char* data, unsigned len)
2664{
2665 gcry_md_write(*(md), data, len);
2666}
2667static inline void
2668ssl_md_final(SSL_MDgcry_md_hd_t* md, unsigned char* data, unsigned* datalen)
2669{
2670 int algo;
2671 int len;
2672 algo = gcry_md_get_algo (*(md));
2673 len = gcry_md_get_algo_dlen (algo);
2674 memcpy(data, gcry_md_read(*(md), algo), len);
2675 *datalen = len;
2676}
2677static inline void
2678ssl_md_cleanup(SSL_MDgcry_md_hd_t* md)
2679{
2680 gcry_md_close(*(md));
2681}
2682
2683static inline void
2684ssl_md_reset(SSL_MDgcry_md_hd_t* md)
2685{
2686 gcry_md_reset(*md);
2687}
2688
2689/* md5 /sha abstraction layer */
2690#define SSL_SHA_CTXgcry_md_hd_t gcry_md_hd_t
2691#define SSL_MD5_CTXgcry_md_hd_t gcry_md_hd_t
2692
2693static inline int
2694ssl_sha_init(SSL_SHA_CTXgcry_md_hd_t* md)
2695{
2696 gcry_error_t err;
2697 const char *err_str, *err_src;
2698 err = gcry_md_open(md, GCRY_MD_SHA1, 0);
2699 if (err != 0) {
2700 err_str = gcry_strerror(err);
2701 err_src = gcry_strsource(err);
2702 ssl_debug_printf("ssl_sha_init(): gcry_md_open failed %s/%s", err_str, err_src);
2703 return -1;
2704 }
2705 return 0;
2706}
2707static inline void
2708ssl_sha_update(SSL_SHA_CTXgcry_md_hd_t* md, unsigned char* data, int len)
2709{
2710 gcry_md_write(*(md), data, len);
2711}
2712static inline void
2713ssl_sha_final(unsigned char* buf, SSL_SHA_CTXgcry_md_hd_t* md)
2714{
2715 memcpy(buf, gcry_md_read(*(md), GCRY_MD_SHA1),
2716 gcry_md_get_algo_dlen(GCRY_MD_SHA1));
2717}
2718
2719static inline void
2720ssl_sha_reset(SSL_SHA_CTXgcry_md_hd_t* md)
2721{
2722 gcry_md_reset(*md);
2723}
2724
2725static inline void
2726ssl_sha_cleanup(SSL_SHA_CTXgcry_md_hd_t* md)
2727{
2728 gcry_md_close(*(md));
2729}
2730
2731static inline int
2732ssl_md5_init(SSL_MD5_CTXgcry_md_hd_t* md)
2733{
2734 gcry_error_t err;
2735 const char *err_str, *err_src;
2736 err = gcry_md_open(md,GCRY_MD_MD5, 0);
2737 if (err != 0) {
2738 err_str = gcry_strerror(err);
2739 err_src = gcry_strsource(err);
2740 ssl_debug_printf("ssl_md5_init(): gcry_md_open failed %s/%s", err_str, err_src);
2741 return -1;
2742 }
2743 return 0;
2744}
2745static inline void
2746ssl_md5_update(SSL_MD5_CTXgcry_md_hd_t* md, unsigned char* data, int len)
2747{
2748 gcry_md_write(*(md), data, len);
2749}
2750static inline void
2751ssl_md5_final(unsigned char* buf, SSL_MD5_CTXgcry_md_hd_t* md)
2752{
2753 memcpy(buf, gcry_md_read(*(md), GCRY_MD_MD5),
2754 gcry_md_get_algo_dlen(GCRY_MD_MD5));
2755}
2756
2757static inline void
2758ssl_md5_reset(SSL_MD5_CTXgcry_md_hd_t* md)
2759{
2760 gcry_md_reset(*md);
2761}
2762
2763static inline void
2764ssl_md5_cleanup(SSL_MD5_CTXgcry_md_hd_t* md)
2765{
2766 gcry_md_close(*(md));
2767}
2768/* libgcrypt wrappers for HMAC/message digest operations }}} */
2769
2770/* libgcrypt wrappers for Cipher state manipulation {{{ */
2771int
2772ssl_cipher_setiv(SSL_CIPHER_CTXgcry_cipher_hd_t *cipher, unsigned char* iv, int iv_len)
2773{
2774 int ret;
2775#if 0
2776 unsigned char *ivp;
2777 int i;
2778 gcry_cipher_hd_t c;
2779 c=(gcry_cipher_hd_t)*cipher;
2780#endif
2781 ssl_debug_printf("--------------------------------------------------------------------");
2782#if 0
2783 for(ivp=c->iv,i=0; i < iv_len; i++ )
2784 {
2785 ssl_debug_printf("%d ",ivp[i]);
2786 i++;
2787 }
2788#endif
2789 ssl_debug_printf("--------------------------------------------------------------------");
2790 ret = gcry_cipher_setiv(*(cipher), iv, iv_len);
2791#if 0
2792 for(ivp=c->iv,i=0; i < iv_len; i++ )
2793 {
2794 ssl_debug_printf("%d ",ivp[i]);
2795 i++;
2796 }
2797#endif
2798 ssl_debug_printf("--------------------------------------------------------------------");
2799 return ret;
2800}
2801/* stream cipher abstraction layer*/
2802static int
2803ssl_cipher_init(gcry_cipher_hd_t *cipher, int algo, unsigned char* sk,
2804 unsigned char* iv, int mode)
2805{
2806 int gcry_modes[] = {
2807 GCRY_CIPHER_MODE_STREAM,
2808 GCRY_CIPHER_MODE_CBC,
2809 GCRY_CIPHER_MODE_GCM,
2810 GCRY_CIPHER_MODE_CCM,
2811 GCRY_CIPHER_MODE_CCM,
2812 GCRY_CIPHER_MODE_POLY1305,
2813 GCRY_CIPHER_MODE_ECB, /* used for DTLSv1.3 seq number encryption */
2814 };
2815 int err;
2816 if (algo == -1) {
2817 /* NULL mode */
2818 *(cipher) = (gcry_cipher_hd_t)-1;
2819 return 0;
2820 }
2821 err = gcry_cipher_open(cipher, algo, gcry_modes[mode], 0);
2822 if (err !=0)
2823 return -1;
2824 err = gcry_cipher_setkey(*(cipher), sk, gcry_cipher_get_algo_keylen (algo));
2825 if (err != 0)
2826 return -1;
2827 /* AEAD cipher suites will set the nonce later. */
2828 if (mode == MODE_CBC) {
2829 err = gcry_cipher_setiv(*(cipher), iv, gcry_cipher_get_algo_blklen(algo));
2830 if (err != 0)
2831 return -1;
2832 }
2833 return 0;
2834}
2835static inline int
2836ssl_cipher_decrypt(gcry_cipher_hd_t *cipher, unsigned char * out, int outl,
2837 const unsigned char * in, int inl)
2838{
2839 if ((*cipher) == (gcry_cipher_hd_t)-1)
2840 {
2841 if (in && inl)
2842 memcpy(out, in, outl < inl ? outl : inl);
2843 return 0;
2844 }
2845 return gcry_cipher_decrypt ( *(cipher), out, outl, in, inl);
2846}
2847static inline int
2848ssl_get_digest_by_name(const char*name)
2849{
2850 return gcry_md_map_name(name);
2851}
2852static inline int
2853ssl_get_cipher_by_name(const char* name)
2854{
2855 return gcry_cipher_map_name(name);
2856}
2857
2858static inline void
2859ssl_cipher_cleanup(gcry_cipher_hd_t *cipher)
2860{
2861 if ((*cipher) != (gcry_cipher_hd_t)-1)
2862 gcry_cipher_close(*cipher);
2863 *cipher = NULL((void*)0);
2864}
2865/* }}} */
2866
2867/* Digests, Ciphers and Cipher Suites registry {{{ */
2868static const SslDigestAlgo digests[]={
2869 {"MD5", 16},
2870 {"SHA1", 20},
2871 {"SHA256", 32},
2872 {"SHA384", 48},
2873 {"SM3", 32},
2874 {"Not Applicable", 0},
2875};
2876
2877#define DIGEST_MAX_SIZE48 48
2878
2879/* get index digest index */
2880static const SslDigestAlgo *
2881ssl_cipher_suite_dig(const SslCipherSuite *cs) {
2882 if (!cs || cs->dig < DIG_MD50x40 || cs->dig > DIG_NA0x45) {
2883 return &digests[DIG_NA0x45 - DIG_MD50x40];
2884 }
2885 return &digests[cs->dig - DIG_MD50x40];
2886}
2887
2888static const char *ciphers[]={
2889 "DES",
2890 "3DES",
2891 "ARCFOUR", /* libgcrypt does not support rc4, but this should be 100% compatible*/
2892 "RFC2268_128", /* libgcrypt name for RC2 with a 128-bit key */
2893 "IDEA",
2894 "AES",
2895 "AES256",
2896 "CAMELLIA128",
2897 "CAMELLIA256",
2898 "SEED",
2899 "CHACHA20", /* since Libgcrypt 1.7.0 */
2900 "SM1",
2901 "SM4",
2902 "*UNKNOWN*"
2903};
2904
2905static const SslCipherSuite cipher_suites[]={
2906 {0x0001,KEX_RSA0x1e, ENC_NULL0x3D, DIG_MD50x40, MODE_STREAM}, /* TLS_RSA_WITH_NULL_MD5 */
2907 {0x0002,KEX_RSA0x1e, ENC_NULL0x3D, DIG_SHA0x41, MODE_STREAM}, /* TLS_RSA_WITH_NULL_SHA */
2908 {0x0003,KEX_RSA0x1e, ENC_RC40x32, DIG_MD50x40, MODE_STREAM}, /* TLS_RSA_EXPORT_WITH_RC4_40_MD5 */
2909 {0x0004,KEX_RSA0x1e, ENC_RC40x32, DIG_MD50x40, MODE_STREAM}, /* TLS_RSA_WITH_RC4_128_MD5 */
2910 {0x0005,KEX_RSA0x1e, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_RSA_WITH_RC4_128_SHA */
2911 {0x0006,KEX_RSA0x1e, ENC_RC20x33, DIG_MD50x40, MODE_CBC }, /* TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 */
2912 {0x0007,KEX_RSA0x1e, ENC_IDEA0x34, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_WITH_IDEA_CBC_SHA */
2913 {0x0008,KEX_RSA0x1e, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_EXPORT_WITH_DES40_CBC_SHA */
2914 {0x0009,KEX_RSA0x1e, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_WITH_DES_CBC_SHA */
2915 {0x000A,KEX_RSA0x1e, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_WITH_3DES_EDE_CBC_SHA */
2916 {0x000B,KEX_DH_DSS0x14, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA */
2917 {0x000C,KEX_DH_DSS0x14, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_DSS_WITH_DES_CBC_SHA */
2918 {0x000D,KEX_DH_DSS0x14, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_DSS_WITH_3DES_EDE_CBC_SHA */
2919 {0x000E,KEX_DH_RSA0x15, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA */
2920 {0x000F,KEX_DH_RSA0x15, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_RSA_WITH_DES_CBC_SHA */
2921 {0x0010,KEX_DH_RSA0x15, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_RSA_WITH_3DES_EDE_CBC_SHA */
2922 {0x0011,KEX_DHE_DSS0x10, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA */
2923 {0x0012,KEX_DHE_DSS0x10, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_DSS_WITH_DES_CBC_SHA */
2924 {0x0013,KEX_DHE_DSS0x10, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_DSS_WITH_3DES_EDE_CBC_SHA */
2925 {0x0014,KEX_DHE_RSA0x12, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA */
2926 {0x0015,KEX_DHE_RSA0x12, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_RSA_WITH_DES_CBC_SHA */
2927 {0x0016,KEX_DHE_RSA0x12, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_RSA_WITH_3DES_EDE_CBC_SHA */
2928 {0x0017,KEX_DH_ANON0x13, ENC_RC40x32, DIG_MD50x40, MODE_STREAM}, /* TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 */
2929 {0x0018,KEX_DH_ANON0x13, ENC_RC40x32, DIG_MD50x40, MODE_STREAM}, /* TLS_DH_anon_WITH_RC4_128_MD5 */
2930 {0x0019,KEX_DH_ANON0x13, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA */
2931 {0x001A,KEX_DH_ANON0x13, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_anon_WITH_DES_CBC_SHA */
2932 {0x001B,KEX_DH_ANON0x13, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_anon_WITH_3DES_EDE_CBC_SHA */
2933 {0x002C,KEX_PSK0x1d, ENC_NULL0x3D, DIG_SHA0x41, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA */
2934 {0x002D,KEX_DHE_PSK0x11, ENC_NULL0x3D, DIG_SHA0x41, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA */
2935 {0x002E,KEX_RSA_PSK0x1f, ENC_NULL0x3D, DIG_SHA0x41, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA */
2936 {0x002F,KEX_RSA0x1e, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_WITH_AES_128_CBC_SHA */
2937 {0x0030,KEX_DH_DSS0x14, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_128_CBC_SHA */
2938 {0x0031,KEX_DH_RSA0x15, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_128_CBC_SHA */
2939 {0x0032,KEX_DHE_DSS0x10, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_128_CBC_SHA */
2940 {0x0033,KEX_DHE_RSA0x12, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA */
2941 {0x0034,KEX_DH_ANON0x13, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_anon_WITH_AES_128_CBC_SHA */
2942 {0x0035,KEX_RSA0x1e, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_WITH_AES_256_CBC_SHA */
2943 {0x0036,KEX_DH_DSS0x14, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_256_CBC_SHA */
2944 {0x0037,KEX_DH_RSA0x15, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_256_CBC_SHA */
2945 {0x0038,KEX_DHE_DSS0x10, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_256_CBC_SHA */
2946 {0x0039,KEX_DHE_RSA0x12, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA */
2947 {0x003A,KEX_DH_ANON0x13, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_anon_WITH_AES_256_CBC_SHA */
2948 {0x003B,KEX_RSA0x1e, ENC_NULL0x3D, DIG_SHA2560x42, MODE_STREAM}, /* TLS_RSA_WITH_NULL_SHA256 */
2949 {0x003C,KEX_RSA0x1e, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_RSA_WITH_AES_128_CBC_SHA256 */
2950 {0x003D,KEX_RSA0x1e, ENC_AES2560x36, DIG_SHA2560x42, MODE_CBC }, /* TLS_RSA_WITH_AES_256_CBC_SHA256 */
2951 {0x003E,KEX_DH_DSS0x14, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_128_CBC_SHA256 */
2952 {0x003F,KEX_DH_RSA0x15, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_128_CBC_SHA256 */
2953 {0x0040,KEX_DHE_DSS0x10, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 */
2954 {0x0041,KEX_RSA0x1e, ENC_CAMELLIA1280x37,DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA */
2955 {0x0042,KEX_DH_DSS0x14, ENC_CAMELLIA1280x37,DIG_SHA0x41, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA */
2956 {0x0043,KEX_DH_RSA0x15, ENC_CAMELLIA1280x37,DIG_SHA0x41, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA */
2957 {0x0044,KEX_DHE_DSS0x10, ENC_CAMELLIA1280x37,DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA */
2958 {0x0045,KEX_DHE_RSA0x12, ENC_CAMELLIA1280x37,DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA */
2959 {0x0046,KEX_DH_ANON0x13, ENC_CAMELLIA1280x37,DIG_SHA0x41, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA */
2960 {0x0060,KEX_RSA0x1e, ENC_RC40x32, DIG_MD50x40, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC4_56_MD5 */
2961 {0x0061,KEX_RSA0x1e, ENC_RC20x33, DIG_MD50x40, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 */
2962 {0x0062,KEX_RSA0x1e, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA */
2963 {0x0063,KEX_DHE_DSS0x10, ENC_DES0x30, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA */
2964 {0x0064,KEX_RSA0x1e, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_RSA_EXPORT1024_WITH_RC4_56_SHA */
2965 {0x0065,KEX_DHE_DSS0x10, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA */
2966 {0x0066,KEX_DHE_DSS0x10, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_DHE_DSS_WITH_RC4_128_SHA */
2967 {0x0067,KEX_DHE_RSA0x12, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 */
2968 {0x0068,KEX_DH_DSS0x14, ENC_AES2560x36, DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_DSS_WITH_AES_256_CBC_SHA256 */
2969 {0x0069,KEX_DH_RSA0x15, ENC_AES2560x36, DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_RSA_WITH_AES_256_CBC_SHA256 */
2970 {0x006A,KEX_DHE_DSS0x10, ENC_AES2560x36, DIG_SHA2560x42, MODE_CBC }, /* TLS_DHE_DSS_WITH_AES_256_CBC_SHA256 */
2971 {0x006B,KEX_DHE_RSA0x12, ENC_AES2560x36, DIG_SHA2560x42, MODE_CBC }, /* TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 */
2972 {0x006C,KEX_DH_ANON0x13, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_anon_WITH_AES_128_CBC_SHA256 */
2973 {0x006D,KEX_DH_ANON0x13, ENC_AES2560x36, DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_anon_WITH_AES_256_CBC_SHA256 */
2974 {0x0084,KEX_RSA0x1e, ENC_CAMELLIA2560x38,DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA */
2975 {0x0085,KEX_DH_DSS0x14, ENC_CAMELLIA2560x38,DIG_SHA0x41, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA */
2976 {0x0086,KEX_DH_RSA0x15, ENC_CAMELLIA2560x38,DIG_SHA0x41, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA */
2977 {0x0087,KEX_DHE_DSS0x10, ENC_CAMELLIA2560x38,DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA */
2978 {0x0088,KEX_DHE_RSA0x12, ENC_CAMELLIA2560x38,DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA */
2979 {0x0089,KEX_DH_ANON0x13, ENC_CAMELLIA2560x38,DIG_SHA0x41, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA */
2980 {0x008A,KEX_PSK0x1d, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_PSK_WITH_RC4_128_SHA */
2981 {0x008B,KEX_PSK0x1d, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_PSK_WITH_3DES_EDE_CBC_SHA */
2982 {0x008C,KEX_PSK0x1d, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_PSK_WITH_AES_128_CBC_SHA */
2983 {0x008D,KEX_PSK0x1d, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_PSK_WITH_AES_256_CBC_SHA */
2984 {0x008E,KEX_DHE_PSK0x11, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_DHE_PSK_WITH_RC4_128_SHA */
2985 {0x008F,KEX_DHE_PSK0x11, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_PSK_WITH_3DES_EDE_CBC_SHA */
2986 {0x0090,KEX_DHE_PSK0x11, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA */
2987 {0x0091,KEX_DHE_PSK0x11, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA */
2988 {0x0092,KEX_RSA_PSK0x1f, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_RSA_PSK_WITH_RC4_128_SHA */
2989 {0x0093,KEX_RSA_PSK0x1f, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_PSK_WITH_3DES_EDE_CBC_SHA */
2990 {0x0094,KEX_RSA_PSK0x1f, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_128_CBC_SHA */
2991 {0x0095,KEX_RSA_PSK0x1f, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_256_CBC_SHA */
2992 {0x0096,KEX_RSA0x1e, ENC_SEED0x39, DIG_SHA0x41, MODE_CBC }, /* TLS_RSA_WITH_SEED_CBC_SHA */
2993 {0x0097,KEX_DH_DSS0x14, ENC_SEED0x39, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_DSS_WITH_SEED_CBC_SHA */
2994 {0x0098,KEX_DH_RSA0x15, ENC_SEED0x39, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_RSA_WITH_SEED_CBC_SHA */
2995 {0x0099,KEX_DHE_DSS0x10, ENC_SEED0x39, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_DSS_WITH_SEED_CBC_SHA */
2996 {0x009A,KEX_DHE_RSA0x12, ENC_SEED0x39, DIG_SHA0x41, MODE_CBC }, /* TLS_DHE_RSA_WITH_SEED_CBC_SHA */
2997 {0x009B,KEX_DH_ANON0x13, ENC_SEED0x39, DIG_SHA0x41, MODE_CBC }, /* TLS_DH_anon_WITH_SEED_CBC_SHA */
2998 {0x009C,KEX_RSA0x1e, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_RSA_WITH_AES_128_GCM_SHA256 */
2999 {0x009D,KEX_RSA0x1e, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_RSA_WITH_AES_256_GCM_SHA384 */
3000 {0x009E,KEX_DHE_RSA0x12, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 */
3001 {0x009F,KEX_DHE_RSA0x12, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 */
3002 {0x00A0,KEX_DH_RSA0x15, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_DH_RSA_WITH_AES_128_GCM_SHA256 */
3003 {0x00A1,KEX_DH_RSA0x15, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_DH_RSA_WITH_AES_256_GCM_SHA384 */
3004 {0x00A2,KEX_DHE_DSS0x10, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_DHE_DSS_WITH_AES_128_GCM_SHA256 */
3005 {0x00A3,KEX_DHE_DSS0x10, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_DHE_DSS_WITH_AES_256_GCM_SHA384 */
3006 {0x00A4,KEX_DH_DSS0x14, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_DH_DSS_WITH_AES_128_GCM_SHA256 */
3007 {0x00A5,KEX_DH_DSS0x14, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_DH_DSS_WITH_AES_256_GCM_SHA384 */
3008 {0x00A6,KEX_DH_ANON0x13, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_DH_anon_WITH_AES_128_GCM_SHA256 */
3009 {0x00A7,KEX_DH_ANON0x13, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_DH_anon_WITH_AES_256_GCM_SHA384 */
3010 {0x00A8,KEX_PSK0x1d, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_PSK_WITH_AES_128_GCM_SHA256 */
3011 {0x00A9,KEX_PSK0x1d, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_PSK_WITH_AES_256_GCM_SHA384 */
3012 {0x00AA,KEX_DHE_PSK0x11, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_DHE_PSK_WITH_AES_128_GCM_SHA256 */
3013 {0x00AB,KEX_DHE_PSK0x11, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_DHE_PSK_WITH_AES_256_GCM_SHA384 */
3014 {0x00AC,KEX_RSA_PSK0x1f, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_RSA_PSK_WITH_AES_128_GCM_SHA256 */
3015 {0x00AD,KEX_RSA_PSK0x1f, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_RSA_PSK_WITH_AES_256_GCM_SHA384 */
3016 {0x00AE,KEX_PSK0x1d, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_PSK_WITH_AES_128_CBC_SHA256 */
3017 {0x00AF,KEX_PSK0x1d, ENC_AES2560x36, DIG_SHA3840x43, MODE_CBC }, /* TLS_PSK_WITH_AES_256_CBC_SHA384 */
3018 {0x00B0,KEX_PSK0x1d, ENC_NULL0x3D, DIG_SHA2560x42, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA256 */
3019 {0x00B1,KEX_PSK0x1d, ENC_NULL0x3D, DIG_SHA3840x43, MODE_STREAM}, /* TLS_PSK_WITH_NULL_SHA384 */
3020 {0x00B2,KEX_DHE_PSK0x11, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_128_CBC_SHA256 */
3021 {0x00B3,KEX_DHE_PSK0x11, ENC_AES2560x36, DIG_SHA3840x43, MODE_CBC }, /* TLS_DHE_PSK_WITH_AES_256_CBC_SHA384 */
3022 {0x00B4,KEX_DHE_PSK0x11, ENC_NULL0x3D, DIG_SHA2560x42, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA256 */
3023 {0x00B5,KEX_DHE_PSK0x11, ENC_NULL0x3D, DIG_SHA3840x43, MODE_STREAM}, /* TLS_DHE_PSK_WITH_NULL_SHA384 */
3024 {0x00B6,KEX_RSA_PSK0x1f, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_128_CBC_SHA256 */
3025 {0x00B7,KEX_RSA_PSK0x1f, ENC_AES2560x36, DIG_SHA3840x43, MODE_CBC }, /* TLS_RSA_PSK_WITH_AES_256_CBC_SHA384 */
3026 {0x00B8,KEX_RSA_PSK0x1f, ENC_NULL0x3D, DIG_SHA2560x42, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA256 */
3027 {0x00B9,KEX_RSA_PSK0x1f, ENC_NULL0x3D, DIG_SHA3840x43, MODE_STREAM}, /* TLS_RSA_PSK_WITH_NULL_SHA384 */
3028 {0x00BA,KEX_RSA0x1e, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
3029 {0x00BB,KEX_DH_DSS0x14, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 */
3030 {0x00BC,KEX_DH_RSA0x15, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
3031 {0x00BD,KEX_DHE_DSS0x10, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 */
3032 {0x00BE,KEX_DHE_RSA0x12, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
3033 {0x00BF,KEX_DH_ANON0x13, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_128_CBC_SHA256 */
3034 {0x00C0,KEX_RSA0x1e, ENC_CAMELLIA2560x38,DIG_SHA2560x42, MODE_CBC }, /* TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
3035 {0x00C1,KEX_DH_DSS0x14, ENC_CAMELLIA2560x38,DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 */
3036 {0x00C2,KEX_DH_RSA0x15, ENC_CAMELLIA2560x38,DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
3037 {0x00C3,KEX_DHE_DSS0x10, ENC_CAMELLIA2560x38,DIG_SHA2560x42, MODE_CBC }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 */
3038 {0x00C4,KEX_DHE_RSA0x12, ENC_CAMELLIA2560x38,DIG_SHA2560x42, MODE_CBC }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 */
3039 {0x00C5,KEX_DH_ANON0x13, ENC_CAMELLIA2560x38,DIG_SHA2560x42, MODE_CBC }, /* TLS_DH_anon_WITH_CAMELLIA_256_CBC_SHA256 */
3040
3041 /* NOTE: TLS 1.3 cipher suites are incompatible with TLS 1.2. */
3042 {0x1301,KEX_TLS130x23, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_AES_128_GCM_SHA256 */
3043 {0x1302,KEX_TLS130x23, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_AES_256_GCM_SHA384 */
3044 {0x1303,KEX_TLS130x23, ENC_CHACHA200x3A, DIG_SHA2560x42, MODE_POLY1305 }, /* TLS_CHACHA20_POLY1305_SHA256 */
3045 {0x1304,KEX_TLS130x23, ENC_AES0x35, DIG_SHA2560x42, MODE_CCM }, /* TLS_AES_128_CCM_SHA256 */
3046 {0x1305,KEX_TLS130x23, ENC_AES0x35, DIG_SHA2560x42, MODE_CCM_8 }, /* TLS_AES_128_CCM_8_SHA256 */
3047 {0x00C6,KEX_TLS130x23, ENC_SM40x3C, DIG_SM30x44, MODE_GCM }, /* TLS_SM4_GCM_SM3 */
3048
3049 {0xC001,KEX_ECDH_ECDSA0x1a, ENC_NULL0x3D, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDH_ECDSA_WITH_NULL_SHA */
3050 {0xC002,KEX_ECDH_ECDSA0x1a, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDH_ECDSA_WITH_RC4_128_SHA */
3051 {0xC003,KEX_ECDH_ECDSA0x1a, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA */
3052 {0xC004,KEX_ECDH_ECDSA0x1a, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA */
3053 {0xC005,KEX_ECDH_ECDSA0x1a, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA */
3054 {0xC006,KEX_ECDHE_ECDSA0x16, ENC_NULL0x3D, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDHE_ECDSA_WITH_NULL_SHA */
3055 {0xC007,KEX_ECDHE_ECDSA0x16, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDHE_ECDSA_WITH_RC4_128_SHA */
3056 {0xC008,KEX_ECDHE_ECDSA0x16, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA */
3057 {0xC009,KEX_ECDHE_ECDSA0x16, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA */
3058 {0xC00A,KEX_ECDHE_ECDSA0x16, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA */
3059 {0xC00B,KEX_ECDH_RSA0x1b, ENC_NULL0x3D, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDH_RSA_WITH_NULL_SHA */
3060 {0xC00C,KEX_ECDH_RSA0x1b, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDH_RSA_WITH_RC4_128_SHA */
3061 {0xC00D,KEX_ECDH_RSA0x1b, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA */
3062 {0xC00E,KEX_ECDH_RSA0x1b, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA */
3063 {0xC00F,KEX_ECDH_RSA0x1b, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA */
3064 {0xC0FF,KEX_ECJPAKE0x24, ENC_AES0x35, DIG_NA0x45, MODE_CCM_8 }, /* TLS_ECJPAKE_WITH_AES_128_CCM_8 */
3065 {0xC010,KEX_ECDHE_RSA0x18, ENC_NULL0x3D, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDHE_RSA_WITH_NULL_SHA */
3066 {0xC011,KEX_ECDHE_RSA0x18, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDHE_RSA_WITH_RC4_128_SHA */
3067 {0xC012,KEX_ECDHE_RSA0x18, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA */
3068 {0xC013,KEX_ECDHE_RSA0x18, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA */
3069 {0xC014,KEX_ECDHE_RSA0x18, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA */
3070 {0xC015,KEX_ECDH_ANON0x19, ENC_NULL0x3D, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDH_anon_WITH_NULL_SHA */
3071 {0xC016,KEX_ECDH_ANON0x19, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDH_anon_WITH_RC4_128_SHA */
3072 {0xC017,KEX_ECDH_ANON0x19, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDH_anon_WITH_3DES_EDE_CBC_SHA */
3073 {0xC018,KEX_ECDH_ANON0x19, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDH_anon_WITH_AES_128_CBC_SHA */
3074 {0xC019,KEX_ECDH_ANON0x19, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDH_anon_WITH_AES_256_CBC_SHA */
3075 {0xC01A,KEX_SRP_SHA0x20, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_SRP_SHA_WITH_3DES_EDE_CBC_SHA */
3076 {0xC01B,KEX_SRP_SHA_RSA0x22, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA */
3077 {0xC01C,KEX_SRP_SHA_DSS0x21, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA */
3078 {0xC01D,KEX_SRP_SHA0x20, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_SRP_SHA_WITH_AES_128_CBC_SHA */
3079 {0xC01E,KEX_SRP_SHA_RSA0x22, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_SRP_SHA_RSA_WITH_AES_128_CBC_SHA */
3080 {0xC01F,KEX_SRP_SHA_DSS0x21, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_SRP_SHA_DSS_WITH_AES_128_CBC_SHA */
3081 {0xC020,KEX_SRP_SHA0x20, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_SRP_SHA_WITH_AES_256_CBC_SHA */
3082 {0xC021,KEX_SRP_SHA_RSA0x22, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_SRP_SHA_RSA_WITH_AES_256_CBC_SHA */
3083 {0xC022,KEX_SRP_SHA_DSS0x21, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_SRP_SHA_DSS_WITH_AES_256_CBC_SHA */
3084 {0xC023,KEX_ECDHE_ECDSA0x16, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 */
3085 {0xC024,KEX_ECDHE_ECDSA0x16, ENC_AES2560x36, DIG_SHA3840x43, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 */
3086 {0xC025,KEX_ECDH_ECDSA0x1a, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 */
3087 {0xC026,KEX_ECDH_ECDSA0x1a, ENC_AES2560x36, DIG_SHA3840x43, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384 */
3088 {0xC027,KEX_ECDHE_RSA0x18, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 */
3089 {0xC028,KEX_ECDHE_RSA0x18, ENC_AES2560x36, DIG_SHA3840x43, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 */
3090 {0xC029,KEX_ECDH_RSA0x1b, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 */
3091 {0xC02A,KEX_ECDH_RSA0x1b, ENC_AES2560x36, DIG_SHA3840x43, MODE_CBC }, /* TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384 */
3092 {0xC02B,KEX_ECDHE_ECDSA0x16, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 */
3093 {0xC02C,KEX_ECDHE_ECDSA0x16, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 */
3094 {0xC02D,KEX_ECDH_ECDSA0x1a, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 */
3095 {0xC02E,KEX_ECDH_ECDSA0x1a, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 */
3096 {0xC02F,KEX_ECDHE_RSA0x18, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 */
3097 {0xC030,KEX_ECDHE_RSA0x18, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 */
3098 {0xC031,KEX_ECDH_RSA0x1b, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM }, /* TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256 */
3099 {0xC032,KEX_ECDH_RSA0x1b, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM }, /* TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384 */
3100 {0xC033,KEX_ECDHE_PSK0x17, ENC_RC40x32, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_RC4_128_SHA */
3101 {0xC034,KEX_ECDHE_PSK0x17, ENC_3DES0x31, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_3DES_EDE_CBC_SHA */
3102 {0xC035,KEX_ECDHE_PSK0x17, ENC_AES0x35, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA */
3103 {0xC036,KEX_ECDHE_PSK0x17, ENC_AES2560x36, DIG_SHA0x41, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA */
3104 {0xC037,KEX_ECDHE_PSK0x17, ENC_AES0x35, DIG_SHA2560x42, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 */
3105 {0xC038,KEX_ECDHE_PSK0x17, ENC_AES2560x36, DIG_SHA3840x43, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384 */
3106 {0xC039,KEX_ECDHE_PSK0x17, ENC_NULL0x3D, DIG_SHA0x41, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA */
3107 {0xC03A,KEX_ECDHE_PSK0x17, ENC_NULL0x3D, DIG_SHA2560x42, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA256 */
3108 {0xC03B,KEX_ECDHE_PSK0x17, ENC_NULL0x3D, DIG_SHA3840x43, MODE_STREAM}, /* TLS_ECDHE_PSK_WITH_NULL_SHA384 */
3109 {0xC072,KEX_ECDHE_ECDSA0x16, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */
3110 {0xC073,KEX_ECDHE_ECDSA0x16, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_CBC }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 */
3111 {0xC074,KEX_ECDH_ECDSA0x1a, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256 */
3112 {0xC075,KEX_ECDH_ECDSA0x1a, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_CBC }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384 */
3113 {0xC076,KEX_ECDHE_RSA0x18, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
3114 {0xC077,KEX_ECDHE_RSA0x18, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_CBC }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384 */
3115 {0xC078,KEX_ECDH_RSA0x1b, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256 */
3116 {0xC079,KEX_ECDH_RSA0x1b, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_CBC }, /* TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384 */
3117 {0xC07A,KEX_RSA0x1e, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
3118 {0xC07B,KEX_RSA0x1e, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
3119 {0xC07C,KEX_DHE_RSA0x12, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
3120 {0xC07D,KEX_DHE_RSA0x12, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
3121 {0xC07E,KEX_DH_RSA0x15, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_DH_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
3122 {0xC07F,KEX_DH_RSA0x15, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_DH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
3123 {0xC080,KEX_DHE_DSS0x10, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_DHE_DSS_WITH_CAMELLIA_128_GCM_SHA256 */
3124 {0xC081,KEX_DHE_DSS0x10, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_DHE_DSS_WITH_CAMELLIA_256_GCM_SHA384 */
3125 {0xC082,KEX_DH_DSS0x14, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_DH_DSS_WITH_CAMELLIA_128_GCM_SHA256 */
3126 {0xC083,KEX_DH_DSS0x14, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_DH_DSS_WITH_CAMELLIA_256_GCM_SHA384 */
3127 {0xC084,KEX_DH_ANON0x13, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_DH_anon_WITH_CAMELLIA_128_GCM_SHA256 */
3128 {0xC085,KEX_DH_ANON0x13, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_DH_anon_WITH_CAMELLIA_256_GCM_SHA384 */
3129 {0xC086,KEX_ECDHE_ECDSA0x16, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 */
3130 {0xC087,KEX_ECDHE_ECDSA0x16, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */
3131 {0xC088,KEX_ECDH_ECDSA0x1a, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256 */
3132 {0xC089,KEX_ECDH_ECDSA0x1a, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384 */
3133 {0xC08A,KEX_ECDHE_RSA0x18, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
3134 {0xC08B,KEX_ECDHE_RSA0x18, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
3135 {0xC08C,KEX_ECDH_RSA0x1b, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256 */
3136 {0xC08D,KEX_ECDH_RSA0x1b, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384 */
3137 {0xC08E,KEX_PSK0x1d, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
3138 {0xC08F,KEX_PSK0x1d, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
3139 {0xC090,KEX_DHE_PSK0x11, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
3140 {0xC091,KEX_DHE_PSK0x11, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
3141 {0xC092,KEX_RSA_PSK0x1f, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_GCM }, /* TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256 */
3142 {0xC093,KEX_RSA_PSK0x1f, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_GCM }, /* TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384 */
3143 {0xC094,KEX_PSK0x1d, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
3144 {0xC095,KEX_PSK0x1d, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_CBC }, /* TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
3145 {0xC096,KEX_DHE_PSK0x11, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
3146 {0xC097,KEX_DHE_PSK0x11, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_CBC }, /* TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
3147 {0xC098,KEX_RSA_PSK0x1f, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
3148 {0xC099,KEX_RSA_PSK0x1f, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_CBC }, /* TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
3149 {0xC09A,KEX_ECDHE_PSK0x17, ENC_CAMELLIA1280x37,DIG_SHA2560x42, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256 */
3150 {0xC09B,KEX_ECDHE_PSK0x17, ENC_CAMELLIA2560x38,DIG_SHA3840x43, MODE_CBC }, /* TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384 */
3151 {0xC09C,KEX_RSA0x1e, ENC_AES0x35, DIG_NA0x45, MODE_CCM }, /* TLS_RSA_WITH_AES_128_CCM */
3152 {0xC09D,KEX_RSA0x1e, ENC_AES2560x36, DIG_NA0x45, MODE_CCM }, /* TLS_RSA_WITH_AES_256_CCM */
3153 {0xC09E,KEX_DHE_RSA0x12, ENC_AES0x35, DIG_NA0x45, MODE_CCM }, /* TLS_DHE_RSA_WITH_AES_128_CCM */
3154 {0xC09F,KEX_DHE_RSA0x12, ENC_AES2560x36, DIG_NA0x45, MODE_CCM }, /* TLS_DHE_RSA_WITH_AES_256_CCM */
3155 {0xC0A0,KEX_RSA0x1e, ENC_AES0x35, DIG_NA0x45, MODE_CCM_8 }, /* TLS_RSA_WITH_AES_128_CCM_8 */
3156 {0xC0A1,KEX_RSA0x1e, ENC_AES2560x36, DIG_NA0x45, MODE_CCM_8 }, /* TLS_RSA_WITH_AES_256_CCM_8 */
3157 {0xC0A2,KEX_DHE_RSA0x12, ENC_AES0x35, DIG_NA0x45, MODE_CCM_8 }, /* TLS_DHE_RSA_WITH_AES_128_CCM_8 */
3158 {0xC0A3,KEX_DHE_RSA0x12, ENC_AES2560x36, DIG_NA0x45, MODE_CCM_8 }, /* TLS_DHE_RSA_WITH_AES_256_CCM_8 */
3159 {0xC0A4,KEX_PSK0x1d, ENC_AES0x35, DIG_NA0x45, MODE_CCM }, /* TLS_PSK_WITH_AES_128_CCM */
3160 {0xC0A5,KEX_PSK0x1d, ENC_AES2560x36, DIG_NA0x45, MODE_CCM }, /* TLS_PSK_WITH_AES_256_CCM */
3161 {0xC0A6,KEX_DHE_PSK0x11, ENC_AES0x35, DIG_NA0x45, MODE_CCM }, /* TLS_DHE_PSK_WITH_AES_128_CCM */
3162 {0xC0A7,KEX_DHE_PSK0x11, ENC_AES2560x36, DIG_NA0x45, MODE_CCM }, /* TLS_DHE_PSK_WITH_AES_256_CCM */
3163 {0xC0A8,KEX_PSK0x1d, ENC_AES0x35, DIG_NA0x45, MODE_CCM_8 }, /* TLS_PSK_WITH_AES_128_CCM_8 */
3164 {0xC0A9,KEX_PSK0x1d, ENC_AES2560x36, DIG_NA0x45, MODE_CCM_8 }, /* TLS_PSK_WITH_AES_256_CCM_8 */
3165 {0xC0AA,KEX_DHE_PSK0x11, ENC_AES0x35, DIG_NA0x45, MODE_CCM_8 }, /* TLS_PSK_DHE_WITH_AES_128_CCM_8 */
3166 {0xC0AB,KEX_DHE_PSK0x11, ENC_AES2560x36, DIG_NA0x45, MODE_CCM_8 }, /* TLS_PSK_DHE_WITH_AES_256_CCM_8 */
3167 {0xC0AC,KEX_ECDHE_ECDSA0x16, ENC_AES0x35, DIG_NA0x45, MODE_CCM }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM */
3168 {0xC0AD,KEX_ECDHE_ECDSA0x16, ENC_AES2560x36, DIG_NA0x45, MODE_CCM }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM */
3169 {0xC0AE,KEX_ECDHE_ECDSA0x16, ENC_AES0x35, DIG_NA0x45, MODE_CCM_8 }, /* TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 */
3170 {0xC0AF,KEX_ECDHE_ECDSA0x16, ENC_AES2560x36, DIG_NA0x45, MODE_CCM_8 }, /* TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 */
3171 {0xCCA8,KEX_ECDHE_RSA0x18, ENC_CHACHA200x3A, DIG_SHA2560x42, MODE_POLY1305 }, /* TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */
3172 {0xCCA9,KEX_ECDHE_ECDSA0x16, ENC_CHACHA200x3A, DIG_SHA2560x42, MODE_POLY1305 }, /* TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 */
3173 {0xCCAA,KEX_DHE_RSA0x12, ENC_CHACHA200x3A, DIG_SHA2560x42, MODE_POLY1305 }, /* TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 */
3174 {0xCCAB,KEX_PSK0x1d, ENC_CHACHA200x3A, DIG_SHA2560x42, MODE_POLY1305 }, /* TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 */
3175 {0xCCAC,KEX_ECDHE_PSK0x17, ENC_CHACHA200x3A, DIG_SHA2560x42, MODE_POLY1305 }, /* TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */
3176 {0xCCAD,KEX_DHE_PSK0x11, ENC_CHACHA200x3A, DIG_SHA2560x42, MODE_POLY1305 }, /* TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256 */
3177 {0xCCAE,KEX_RSA_PSK0x1f, ENC_CHACHA200x3A, DIG_SHA2560x42, MODE_POLY1305 }, /* TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256 */
3178 {0xD001,KEX_ECDHE_PSK0x17, ENC_AES0x35, DIG_SHA2560x42, MODE_GCM}, /* TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256 */
3179 {0xD002,KEX_ECDHE_PSK0x17, ENC_AES2560x36, DIG_SHA3840x43, MODE_GCM}, /* TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384 */
3180 {0xD003,KEX_ECDHE_PSK0x17, ENC_AES0x35, DIG_SHA2560x42, MODE_CCM_8}, /* TLS_ECDHE_PSK_WITH_AES_128_CCM_8_SHA256 */
3181 {0xD005,KEX_ECDHE_PSK0x17, ENC_AES0x35, DIG_SHA2560x42, MODE_CCM}, /* TLS_ECDHE_PSK_WITH_AES_128_CCM_SHA256 */
3182 /* GM */
3183 {0xe001,KEX_ECDHE_SM20x25, ENC_SM10x3B, DIG_SM30x44, MODE_CBC}, /* ECDHE_SM1_SM3 */
3184 {0xe003,KEX_ECC_SM20x26, ENC_SM10x3B, DIG_SM30x44, MODE_CBC}, /* ECC_SM1_SM3 */
3185 {0xe005,KEX_IBSDH_SM90x27, ENC_SM10x3B, DIG_SM30x44, MODE_CBC}, /* IBSDH_SM1_SM3 */
3186 {0xe007,KEX_IBC_SM90x28, ENC_SM10x3B, DIG_SM30x44, MODE_CBC}, /* IBC_SM1_SM3 */
3187 {0xe009,KEX_RSA0x1e, ENC_SM10x3B, DIG_SM30x44, MODE_CBC}, /* RSA_SM1_SM3 */
3188 {0xe00a,KEX_RSA0x1e, ENC_SM10x3B, DIG_SHA0x41, MODE_CBC}, /* RSA_SM1_SHA1 */
3189 {0xe011,KEX_ECDHE_SM20x25, ENC_SM40x3C, DIG_SM30x44, MODE_CBC}, /* ECDHE_SM4_CBC_SM3 */
3190 {0xe013,KEX_ECC_SM20x26, ENC_SM40x3C, DIG_SM30x44, MODE_CBC}, /* ECC_SM4_CBC_SM3 */
3191 {0xe015,KEX_IBSDH_SM90x27, ENC_SM40x3C, DIG_SM30x44, MODE_CBC}, /* IBSDH_SM4_CBC_SM3 */
3192 {0xe017,KEX_IBC_SM90x28, ENC_SM40x3C, DIG_SM30x44, MODE_CBC}, /* IBC_SM4_CBC_SM3 */
3193 {0xe019,KEX_RSA0x1e, ENC_SM40x3C, DIG_SM30x44, MODE_CBC}, /* RSA_SM4_CBC_SM3 */
3194 {0xe01a,KEX_RSA0x1e, ENC_SM40x3C, DIG_SHA0x41, MODE_CBC}, /* RSA_SM4_CBC_SHA1 */
3195 {0xe01c,KEX_RSA0x1e, ENC_SM40x3C, DIG_SHA2560x42, MODE_CBC}, /* RSA_SM4_CBC_SHA256 */
3196 {0xe051,KEX_ECDHE_SM20x25, ENC_SM40x3C, DIG_SM30x44, MODE_GCM}, /* ECDHE_SM4_GCM_SM3 */
3197 {0xe053,KEX_ECC_SM20x26, ENC_SM40x3C, DIG_SM30x44, MODE_GCM}, /* ECC_SM4_GCM_SM3 */
3198 {0xe055,KEX_IBSDH_SM90x27, ENC_SM40x3C, DIG_SM30x44, MODE_GCM}, /* IBSDH_SM4_GCM_SM3 */
3199 {0xe057,KEX_IBC_SM90x28, ENC_SM40x3C, DIG_SM30x44, MODE_GCM}, /* IBC_SM4_GCM_SM3 */
3200 {0xe059,KEX_RSA0x1e, ENC_SM40x3C, DIG_SM30x44, MODE_GCM}, /* RSA_SM4_GCM_SM3 */
3201 {0xe05a,KEX_RSA0x1e, ENC_SM40x3C, DIG_SHA2560x42, MODE_GCM}, /* RSA_SM4_GCM_SHA256 */
3202 {-1, 0, 0, 0, MODE_STREAM}
3203};
3204
3205#define MAX_BLOCK_SIZE16 16
3206#define MAX_KEY_SIZE32 32
3207
3208const SslCipherSuite *
3209ssl_find_cipher(int num)
3210{
3211 const SslCipherSuite *c;
3212 for(c=cipher_suites;c->number!=-1;c++){
9
Assuming the condition is false
10
Loop condition is false. Execution continues on line 3218
3213 if(c->number==num){
3214 return c;
3215 }
3216 }
3217
3218 return NULL((void*)0);
11
Returning null pointer, which participates in a condition later
3219}
3220
3221int
3222ssl_get_cipher_algo(const SslCipherSuite *cipher_suite)
3223{
3224 return gcry_cipher_map_name(ciphers[cipher_suite->enc - ENC_START0x30]);
3225}
3226
3227unsigned
3228ssl_get_cipher_blocksize(const SslCipherSuite *cipher_suite)
3229{
3230 int cipher_algo;
3231 if (cipher_suite->mode != MODE_CBC) return 0;
3232 cipher_algo = ssl_get_cipher_by_name(ciphers[cipher_suite->enc - ENC_START0x30]);
3233 return (unsigned)gcry_cipher_get_algo_blklen(cipher_algo);
3234}
3235
3236static unsigned
3237ssl_get_cipher_export_keymat_size(int cipher_suite_num)
3238{
3239 switch (cipher_suite_num) {
3240 /* See RFC 6101 (SSL 3.0), Table 2, column Key Material. */
3241 case 0x0003: /* TLS_RSA_EXPORT_WITH_RC4_40_MD5 */
3242 case 0x0006: /* TLS_RSA_EXPORT_WITH_RC2_CBC_40_MD5 */
3243 case 0x0008: /* TLS_RSA_EXPORT_WITH_DES40_CBC_SHA */
3244 case 0x000B: /* TLS_DH_DSS_EXPORT_WITH_DES40_CBC_SHA */
3245 case 0x000E: /* TLS_DH_RSA_EXPORT_WITH_DES40_CBC_SHA */
3246 case 0x0011: /* TLS_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA */
3247 case 0x0014: /* TLS_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA */
3248 case 0x0017: /* TLS_DH_anon_EXPORT_WITH_RC4_40_MD5 */
3249 case 0x0019: /* TLS_DH_anon_EXPORT_WITH_DES40_CBC_SHA */
3250 return 5;
3251
3252 /* not defined in below draft, but "implemented by several vendors",
3253 * https://www.ietf.org/mail-archive/web/tls/current/msg00036.html */
3254 case 0x0060: /* TLS_RSA_EXPORT1024_WITH_RC4_56_MD5 */
3255 case 0x0061: /* TLS_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 */
3256 return 7;
3257
3258 /* Note: the draft states that DES_CBC needs 8 bytes, but Wireshark always
3259 * used 7. Until a pcap proves 8, let's use the old value. Link:
3260 * https://tools.ietf.org/html/draft-ietf-tls-56-bit-ciphersuites-01 */
3261 case 0x0062: /* TLS_RSA_EXPORT1024_WITH_DES_CBC_SHA */
3262 case 0x0063: /* TLS_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA */
3263 case 0x0064: /* TLS_RSA_EXPORT1024_WITH_RC4_56_SHA */
3264 case 0x0065: /* TLS_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA */
3265 return 7;
3266
3267 default:
3268 return 0;
3269 }
3270}
3271
3272/* Digests, Ciphers and Cipher Suites registry }}} */
3273
3274
3275/* HMAC and the Pseudorandom function {{{ */
3276static int
3277tls_hash(StringInfo *secret, StringInfo *seed, int md,
3278 StringInfo *out, unsigned out_len)
3279{
3280 /* RFC 2246 5. HMAC and the pseudorandom function
3281 * '+' denotes concatenation.
3282 * P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) +
3283 * HMAC_hash(secret, A(2) + seed) + ...
3284 * A(0) = seed
3285 * A(i) = HMAC_hash(secret, A(i - 1))
3286 */
3287 uint8_t *ptr;
3288 unsigned left, tocpy;
3289 uint8_t *A;
3290 uint8_t _A[DIGEST_MAX_SIZE48], tmp[DIGEST_MAX_SIZE48];
3291 unsigned A_l, tmp_l;
3292 SSL_HMACgcry_md_hd_t hm;
3293
3294 ptr = out->data;
3295 left = out_len;
3296
3297 ssl_print_string("tls_hash: hash secret", secret);
3298 ssl_print_string("tls_hash: hash seed", seed);
3299 /* A(0) = seed */
3300 A = seed->data;
3301 A_l = seed->data_len;
3302
3303 if (ssl_hmac_init(&hm, md) != 0) {
3304 return -1;
3305 }
3306 while (left) {
3307 /* A(i) = HMAC_hash(secret, A(i-1)) */
3308 ssl_hmac_setkey(&hm, secret->data, secret->data_len);
3309 ssl_hmac_update(&hm, A, A_l);
3310 A_l = sizeof(_A); /* upper bound len for hash output */
3311 ssl_hmac_final(&hm, _A, &A_l);
3312 A = _A;
3313
3314 /* HMAC_hash(secret, A(i) + seed) */
3315 ssl_hmac_reset(&hm);
3316 ssl_hmac_setkey(&hm, secret->data, secret->data_len);
3317 ssl_hmac_update(&hm, A, A_l);
3318 ssl_hmac_update(&hm, seed->data, seed->data_len);
3319 tmp_l = sizeof(tmp); /* upper bound len for hash output */
3320 ssl_hmac_final(&hm, tmp, &tmp_l);
3321 ssl_hmac_reset(&hm);
3322
3323 /* ssl_hmac_final puts the actual digest output size in tmp_l */
3324 tocpy = MIN(left, tmp_l)(((left) < (tmp_l)) ? (left) : (tmp_l));
3325 memcpy(ptr, tmp, tocpy);
3326 ptr += tocpy;
3327 left -= tocpy;
3328 }
3329 ssl_hmac_cleanup(&hm);
3330 out->data_len = out_len;
3331
3332 ssl_print_string("hash out", out);
3333 return 0;
3334}
3335
3336static bool_Bool
3337tls_prf(StringInfo* secret, const char *usage,
3338 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, unsigned out_len)
3339{
3340 StringInfo seed, sha_out, md5_out;
3341 uint8_t *ptr;
3342 StringInfo s1, s2;
3343 unsigned i,s_l;
3344 size_t usage_len, rnd2_len;
3345 bool_Bool success = false0;
3346 usage_len = strlen(usage);
3347 rnd2_len = rnd2 ? rnd2->data_len : 0;
3348
3349 /* initialize buffer for sha, md5 random seed*/
3350 if (ssl_data_alloc(&sha_out, MAX(out_len, 20)(((out_len) > (20)) ? (out_len) : (20))) < 0) {
3351 ssl_debug_printf("tls_prf: can't allocate sha out\n");
3352 return false0;
3353 }
3354 if (ssl_data_alloc(&md5_out, MAX(out_len, 16)(((out_len) > (16)) ? (out_len) : (16))) < 0) {
3355 ssl_debug_printf("tls_prf: can't allocate md5 out\n");
3356 goto free_sha;
3357 }
3358 if (ssl_data_alloc(&seed, usage_len+rnd1->data_len+rnd2_len) < 0) {
3359 ssl_debug_printf("tls_prf: can't allocate rnd %d\n",
3360 (int) (usage_len+rnd1->data_len+rnd2_len));
3361 goto free_md5;
3362 }
3363
3364 ptr=seed.data;
3365 memcpy(ptr,usage,usage_len);
3366 ptr+=usage_len;
3367 memcpy(ptr,rnd1->data,rnd1->data_len);
3368 if (rnd2_len > 0) {
3369 ptr+=rnd1->data_len;
3370 memcpy(ptr,rnd2->data,rnd2->data_len);
3371 /*ptr+=rnd2->data_len;*/
3372 }
3373
3374 /* initialize buffer for client/server seeds*/
3375 s_l=secret->data_len/2 + secret->data_len%2;
3376 if (ssl_data_alloc(&s1, s_l) < 0) {
3377 ssl_debug_printf("tls_prf: can't allocate secret %d\n", s_l);
3378 goto free_seed;
3379 }
3380 if (ssl_data_alloc(&s2, s_l) < 0) {
3381 ssl_debug_printf("tls_prf: can't allocate secret(2) %d\n", s_l);
3382 goto free_s1;
3383 }
3384
3385 memcpy(s1.data,secret->data,s_l);
3386 memcpy(s2.data,secret->data + (secret->data_len - s_l),s_l);
3387
3388 ssl_debug_printf("tls_prf: tls_hash(md5 secret_len %d seed_len %d )\n", s1.data_len, seed.data_len);
3389 if(tls_hash(&s1, &seed, ssl_get_digest_by_name("MD5"), &md5_out, out_len) != 0)
3390 goto free_s2;
3391 ssl_debug_printf("tls_prf: tls_hash(sha)\n");
3392 if(tls_hash(&s2, &seed, ssl_get_digest_by_name("SHA1"), &sha_out, out_len) != 0)
3393 goto free_s2;
3394
3395 for (i = 0; i < out_len; i++)
3396 out->data[i] = md5_out.data[i] ^ sha_out.data[i];
3397 /* success, now store the new meaningful data length */
3398 out->data_len = out_len;
3399 success = true1;
3400
3401 ssl_print_string("PRF out",out);
3402free_s2:
3403 g_free(s2.data)(__builtin_object_size ((s2.data), 0) != ((size_t) - 1)) ? g_free_sized
(s2.data, __builtin_object_size ((s2.data), 0)) : (g_free) (
s2.data)
;
3404free_s1:
3405 g_free(s1.data)(__builtin_object_size ((s1.data), 0) != ((size_t) - 1)) ? g_free_sized
(s1.data, __builtin_object_size ((s1.data), 0)) : (g_free) (
s1.data)
;
3406free_seed:
3407 g_free(seed.data)(__builtin_object_size ((seed.data), 0) != ((size_t) - 1)) ? g_free_sized
(seed.data, __builtin_object_size ((seed.data), 0)) : (g_free
) (seed.data)
;
3408free_md5:
3409 g_free(md5_out.data)(__builtin_object_size ((md5_out.data), 0) != ((size_t) - 1))
? g_free_sized (md5_out.data, __builtin_object_size ((md5_out
.data), 0)) : (g_free) (md5_out.data)
;
3410free_sha:
3411 g_free(sha_out.data)(__builtin_object_size ((sha_out.data), 0) != ((size_t) - 1))
? g_free_sized (sha_out.data, __builtin_object_size ((sha_out
.data), 0)) : (g_free) (sha_out.data)
;
3412 return success;
3413}
3414
3415static bool_Bool
3416tls12_prf(int md, StringInfo* secret, const char* usage,
3417 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, unsigned out_len)
3418{
3419 StringInfo label_seed;
3420 int success;
3421 size_t usage_len, rnd2_len;
3422 rnd2_len = rnd2 ? rnd2->data_len : 0;
3423
3424 usage_len = strlen(usage);
3425 if (ssl_data_alloc(&label_seed, usage_len+rnd1->data_len+rnd2_len) < 0) {
3426 ssl_debug_printf("tls12_prf: can't allocate label_seed\n");
3427 return false0;
3428 }
3429 memcpy(label_seed.data, usage, usage_len);
3430 memcpy(label_seed.data+usage_len, rnd1->data, rnd1->data_len);
3431 if (rnd2_len > 0)
3432 memcpy(label_seed.data+usage_len+rnd1->data_len, rnd2->data, rnd2->data_len);
3433
3434 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);
3435 success = tls_hash(secret, &label_seed, md, out, out_len);
3436 g_free(label_seed.data)(__builtin_object_size ((label_seed.data), 0) != ((size_t) - 1
)) ? g_free_sized (label_seed.data, __builtin_object_size ((label_seed
.data), 0)) : (g_free) (label_seed.data)
;
3437 if(success != -1){
3438 ssl_print_string("PRF out", out);
3439 return true1;
3440 }
3441 return false0;
3442}
3443
3444static bool_Bool
3445ssl3_generate_export_iv(StringInfo *r1, StringInfo *r2,
3446 StringInfo *out, unsigned out_len)
3447{
3448 SSL_MD5_CTXgcry_md_hd_t md5;
3449 uint8_t tmp[16];
3450
3451 if (ssl_md5_init(&md5) != 0) {
3452 return false0;
3453 }
3454 ssl_md5_update(&md5,r1->data,r1->data_len);
3455 ssl_md5_update(&md5,r2->data,r2->data_len);
3456 ssl_md5_final(tmp,&md5);
3457 ssl_md5_cleanup(&md5);
3458
3459 DISSECTOR_ASSERT(out_len <= sizeof(tmp))((void) ((out_len <= sizeof(tmp)) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-tls-utils.c"
, 3459, "out_len <= sizeof(tmp)"))))
;
3460 ssl_data_set(out, tmp, out_len);
3461 ssl_print_string("export iv", out);
3462 return true1;
3463}
3464
3465static bool_Bool
3466ssl3_prf(StringInfo* secret, const char* usage,
3467 StringInfo* rnd1, StringInfo* rnd2, StringInfo* out, unsigned out_len)
3468{
3469 SSL_MD5_CTXgcry_md_hd_t md5;
3470 SSL_SHA_CTXgcry_md_hd_t sha;
3471 unsigned off;
3472 int i = 0,j;
3473 uint8_t buf[20];
3474
3475 if (ssl_sha_init(&sha) != 0) {
3476 return false0;
3477 }
3478 if (ssl_md5_init(&md5) != 0) {
3479 ssl_sha_cleanup(&sha);
3480 return false0;
3481 }
3482 for (off = 0; off < out_len; off += 16) {
3483 unsigned char outbuf[16];
3484 i++;
3485
3486 ssl_debug_printf("ssl3_prf: sha1_hash(%d)\n",i);
3487 /* A, BB, CCC, ... */
3488 for(j=0;j<i;j++){
3489 buf[j]=64+i;
3490 }
3491
3492 ssl_sha_update(&sha,buf,i);
3493 ssl_sha_update(&sha,secret->data,secret->data_len);
3494
3495 if(!strcmp(usage,"client write key") || !strcmp(usage,"server write key")){
3496 if (rnd2)
3497 ssl_sha_update(&sha,rnd2->data,rnd2->data_len);
3498 ssl_sha_update(&sha,rnd1->data,rnd1->data_len);
3499 }
3500 else{
3501 ssl_sha_update(&sha,rnd1->data,rnd1->data_len);
3502 if (rnd2)
3503 ssl_sha_update(&sha,rnd2->data,rnd2->data_len);
3504 }
3505
3506 ssl_sha_final(buf,&sha);
3507 ssl_sha_reset(&sha);
3508
3509 ssl_debug_printf("ssl3_prf: md5_hash(%d) datalen %d\n",i,
3510 secret->data_len);
3511 ssl_md5_update(&md5,secret->data,secret->data_len);
3512 ssl_md5_update(&md5,buf,20);
3513 ssl_md5_final(outbuf,&md5);
3514 ssl_md5_reset(&md5);
3515
3516 memcpy(out->data + off, outbuf, MIN(out_len - off, 16)(((out_len - off) < (16)) ? (out_len - off) : (16)));
3517 }
3518 ssl_sha_cleanup(&sha);
3519 ssl_md5_cleanup(&md5);
3520 out->data_len = out_len;
3521
3522 return true1;
3523}
3524
3525/* out_len is the wanted output length for the pseudorandom function.
3526 * Ensure that ssl->cipher_suite is set. */
3527static bool_Bool
3528prf(SslDecryptSession *ssl, StringInfo *secret, const char *usage,
3529 StringInfo *rnd1, StringInfo *rnd2, StringInfo *out, unsigned out_len)
3530{
3531 switch (ssl->session.version) {
3532 case SSLV3_VERSION0x300:
3533 return ssl3_prf(secret, usage, rnd1, rnd2, out, out_len);
3534
3535 case TLSV1_VERSION0x301:
3536 case TLSV1DOT1_VERSION0x302:
3537 case DTLSV1DOT0_VERSION0xfeff:
3538 case DTLSV1DOT0_OPENSSL_VERSION0x100:
3539 return tls_prf(secret, usage, rnd1, rnd2, out, out_len);
3540
3541 default: /* TLSv1.2 */
3542 switch (ssl->cipher_suite->dig) {
3543 case DIG_SM30x44:
3544#if GCRYPT_VERSION_NUMBER0x010c00 >= 0x010900
3545 return tls12_prf(GCRY_MD_SM3, secret, usage, rnd1, rnd2,
3546 out, out_len);
3547#else
3548 return false0;
3549#endif
3550 case DIG_SHA3840x43:
3551 return tls12_prf(GCRY_MD_SHA384, secret, usage, rnd1, rnd2,
3552 out, out_len);
3553 default:
3554 return tls12_prf(GCRY_MD_SHA256, secret, usage, rnd1, rnd2,
3555 out, out_len);
3556 }
3557 }
3558}
3559
3560/* Handshake transcript {{{ */
3561
3562/* Only the messages before the hash function is known (the ClientHello and
3563 * the ServerHello or HelloRetryRequest, each at most 2^24 + 11 bytes) are
3564 * buffered, so this should only be reached with bogus messages, such as
3565 * repeated ClientHellos after a TLS 1.3 draft HelloRetryRequest. */
3566#define TLS_TRANSCRIPT_MAX_BUFFER(64 * 1024 * 1024) (64 * 1024 * 1024)
3567
3568static void
3569tls_transcript_close(tls_transcript_t *transcript)
3570{
3571 if (transcript->md) {
3572 gcry_md_close(transcript->md);
3573 transcript->md = NULL((void*)0);
3574 }
3575}
3576
3577void
3578tls_transcript_reset(tls_transcript_t *transcript)
3579{
3580 wmem_free(wmem_file_scope(), transcript->buffer.data);
3581 transcript->buffer.data = NULL((void*)0);
3582 transcript->buffer.data_len = 0;
3583 tls_transcript_close(transcript);
3584 transcript->failed = false0;
3585}
3586
3587/* Gives up on the transcript until it is reset. */
3588static void
3589tls_transcript_fail(tls_transcript_t *transcript)
3590{
3591 tls_transcript_reset(transcript);
3592 transcript->failed = true1;
3593}
3594
3595static bool_Bool
3596tls_transcript_is_empty(const tls_transcript_t *transcript)
3597{
3598 return transcript->md == NULL((void*)0) && transcript->buffer.data_len == 0;
3599}
3600
3601static void
3602tls_transcript_add(tls_transcript_t *transcript, const uint8_t *data, unsigned len)
3603{
3604 if (transcript->failed || len == 0)
3605 return;
3606
3607 if (transcript->md) {
3608 gcry_md_write(transcript->md, data, len);
3609 return;
3610 }
3611
3612 if (len > TLS_TRANSCRIPT_MAX_BUFFER(64 * 1024 * 1024) - transcript->buffer.data_len) {
3613 ssl_debug_printf("%s transcript too long before the hash is known\n", G_STRFUNC((const char*) (__func__)));
3614 tls_transcript_fail(transcript);
3615 return;
3616 }
3617 transcript->buffer.data = (unsigned char *)wmem_realloc(wmem_file_scope(), transcript->buffer.data,
3618 transcript->buffer.data_len + len);
3619 memcpy(transcript->buffer.data + transcript->buffer.data_len, data, len);
3620 transcript->buffer.data_len += len;
3621}
3622
3623/* Returns a new digest handle (which must be closed) with the transcript so
3624 * far for the given hash function(s), or NULL. algo2 is 0 or a second hash
3625 * function, for the concatenated MD5 and SHA-1 of TLS 1.0 and 1.1. */
3626static gcry_md_hd_t
3627tls_transcript_copy(const tls_transcript_t *transcript, int algo, int algo2)
3628{
3629 gcry_md_hd_t md = NULL((void*)0);
3630
3631 if (transcript->failed)
3632 return NULL((void*)0);
3633
3634 if (transcript->md) {
3635 if (!gcry_md_is_enabled(transcript->md, algo) ||
3636 (algo2 && !gcry_md_is_enabled(transcript->md, algo2))) {
3637 ssl_debug_printf("%s transcript uses a different hash\n", G_STRFUNC((const char*) (__func__)));
3638 return NULL((void*)0);
3639 }
3640 if (gcry_md_copy(&md, transcript->md) != 0)
3641 return NULL((void*)0);
3642 } else {
3643 if (gcry_md_open(&md, algo, 0) != 0)
3644 return NULL((void*)0);
3645 if (algo2 && gcry_md_enable(md, algo2) != 0) {
3646 gcry_md_close(md);
3647 return NULL((void*)0);
3648 }
3649 gcry_md_write(md, transcript->buffer.data, transcript->buffer.data_len);
3650 }
3651 return md;
3652}
3653
3654/* Gets the hash of the transcript so far, which can be continued. */
3655static bool_Bool
3656tls_transcript_hash(const tls_transcript_t *transcript, int algo,
3657 uint8_t *out, unsigned *out_len)
3658{
3659 gcry_md_hd_t md = tls_transcript_copy(transcript, algo, 0);
3660
3661 if (!md)
3662 return false0;
3663 *out_len = gcry_md_get_algo_dlen(algo);
3664 memcpy(out, gcry_md_read(md, algo), *out_len);
3665 gcry_md_close(md);
3666 return true1;
3667}
3668
3669/* Starts hashing the transcript with the given hash function(s) (see
3670 * tls_transcript_copy), keeping only the digest state from now on. */
3671static bool_Bool
3672tls_transcript_set_hash(tls_transcript_t *transcript, int algo, int algo2)
3673{
3674 if (transcript->failed)
3675 return false0;
3676
3677 if (transcript->md) {
3678 /* Already started, e.g. after a HelloRetryRequest. */
3679 if (gcry_md_is_enabled(transcript->md, algo) &&
3680 (!algo2 || gcry_md_is_enabled(transcript->md, algo2))) {
3681 return true1;
3682 }
3683 ssl_debug_printf("%s hash function changed\n", G_STRFUNC((const char*) (__func__)));
3684 tls_transcript_fail(transcript);
3685 return false0;
3686 }
3687
3688 gcry_md_hd_t md = tls_transcript_copy(transcript, algo, algo2);
3689 if (!md) {
3690 tls_transcript_fail(transcript);
3691 return false0;
3692 }
3693 tls_transcript_reset(transcript);
3694 transcript->md = md;
3695 return true1;
3696}
3697
3698/* RFC 8446 4.4.1: After a HelloRetryRequest, ClientHello1 is replaced in
3699 * the transcript by a message_hash message containing its hash. Everything
3700 * in the transcript except the last keep_len bytes (the HelloRetryRequest,
3701 * if it has already been added) is replaced. */
3702static bool_Bool
3703tls_transcript_hello_retry(tls_transcript_t *transcript, int algo, unsigned keep_len)
3704{
3705 uint8_t message_hash[4 + DIGEST_MAX_SIZE48];
3706 uint8_t *keep = NULL((void*)0);
3707 gcry_md_hd_t md;
3708
3709 if (transcript->failed)
3710 return false0;
3711
3712 if (keep_len > 0) {
3713 /* The start of the HelloRetryRequest isn't known after a previous one
3714 * (which isn't allowed anyway.) */
3715 if (transcript->md || keep_len > transcript->buffer.data_len) {
3716 tls_transcript_fail(transcript);
3717 return false0;
3718 }
3719 transcript->buffer.data_len -= keep_len;
3720 keep = transcript->buffer.data + transcript->buffer.data_len;
3721 }
3722
3723 md = tls_transcript_copy(transcript, algo, 0);
3724 if (!md) {
3725 tls_transcript_fail(transcript);
3726 return false0;
3727 }
3728 message_hash[0] = SSL_HND_MESSAGE_HASH;
3729 message_hash[1] = 0;
3730 message_hash[2] = 0;
3731 message_hash[3] = gcry_md_get_algo_dlen(algo);
3732 memcpy(message_hash + 4, gcry_md_read(md, algo), message_hash[3]);
3733 gcry_md_reset(md);
3734 gcry_md_write(md, message_hash, 4 + message_hash[3]);
3735 if (keep_len > 0)
3736 gcry_md_write(md, keep, keep_len);
3737
3738 tls_transcript_reset(transcript);
3739 transcript->md = md;
3740 return true1;
3741}
3742/* Handshake transcript }}} */
3743
3744static int tls_handshake_hash(SslDecryptSession* ssl, StringInfo* out)
3745{
3746 gcry_md_hd_t md;
3747
3748 md = tls_transcript_copy(&ssl->handshake_transcript, GCRY_MD_MD5, GCRY_MD_SHA1);
3749 if (!md)
3750 return -1;
3751 if (ssl_data_alloc(out, 36) < 0) {
3752 gcry_md_close(md);
3753 return -1;
3754 }
3755 memcpy(out->data, gcry_md_read(md, GCRY_MD_MD5), 16);
3756 memcpy(out->data + 16, gcry_md_read(md, GCRY_MD_SHA1), 20);
3757 gcry_md_close(md);
3758 return 0;
3759}
3760
3761static int tls12_handshake_hash(SslDecryptSession* ssl, int md, StringInfo* out)
3762{
3763 uint8_t tmp[DIGEST_MAX_SIZE48];
3764 unsigned len;
3765
3766 if (!tls_transcript_hash(&ssl->handshake_transcript, md, tmp, &len))
3767 return -1;
3768
3769 if (ssl_data_alloc(out, len) < 0)
3770 return -1;
3771 memcpy(out->data, tmp, len);
3772 return 0;
3773}
3774
3775bool_Bool
3776tls_load_psk(SslDecryptSession* tls_session, const char *tls_psk)
3777{
3778 if (!tls_psk || (tls_psk[0] == 0)) {
3779 ssl_debug_printf("%s: can't find pre-shared key\n", G_STRFUNC((const char*) (__func__)));
3780 return false0;
3781 }
3782
3783 wmem_free(wmem_file_scope(), tls_session->psk.data);
3784 /* convert hex string into char*/
3785 if (!from_hex(&tls_session->psk, tls_psk, strlen(tls_psk))) {
3786 ssl_debug_printf("%s: ssl.psk/dtls.psk contains invalid hex\n",
3787 G_STRFUNC((const char*) (__func__)));
3788 return false0;
3789 }
3790
3791 if (tls_session->psk.data_len >= (2 << 15)) {
3792 ssl_debug_printf("%s: ssl.psk/dtls.psk must not be larger than 2^15 - 1\n",
3793 G_STRFUNC((const char*) (__func__)));
3794 wmem_free(wmem_file_scope(), tls_session->psk.data);
3795 tls_session->psk.data = NULL((void*)0);
3796 tls_session->psk.data_len = 0;
3797 return false0;
3798 }
3799
3800 return true1;
3801}
3802
3803/**
3804 * Obtains the label prefix used in HKDF-Expand-Label. This function can be
3805 * inlined and removed once support for draft 19 and before is dropped.
3806 */
3807static inline const char *
3808tls13_hkdf_label_prefix(SslDecryptSession *ssl_session)
3809{
3810 if (ssl_session->session.tls13_draft_version && ssl_session->session.tls13_draft_version < 20) {
3811 return "TLS 1.3, ";
3812 } else if (ssl_session->session.version == DTLSV1DOT3_VERSION0xfefc) {
3813 return "dtls13";
3814 } else {
3815 return "tls13 ";
3816 }
3817}
3818
3819/*
3820 * Computes HKDF-Expand-Label(Secret, Label, Hash(context_value), Length) with a
3821 * custom label prefix. If "context_hash" is NULL, then an empty context is
3822 * used. Otherwise it must have the same length as the hash algorithm output.
3823 */
3824bool_Bool
3825tls13_hkdf_expand_label_context(int md, const StringInfo *secret,
3826 const char *label_prefix, const char *label,
3827 const uint8_t *context_hash, uint8_t context_length,
3828 uint16_t out_len, unsigned char **out)
3829{
3830 /* RFC 8446 Section 7.1:
3831 * HKDF-Expand-Label(Secret, Label, Context, Length) =
3832 * HKDF-Expand(Secret, HkdfLabel, Length)
3833 * struct {
3834 * uint16 length = Length;
3835 * opaque label<7..255> = "tls13 " + Label; // "tls13 " is label prefix.
3836 * opaque context<0..255> = Context;
3837 * } HkdfLabel;
3838 *
3839 * RFC 5869 HMAC-based Extract-and-Expand Key Derivation Function (HKDF):
3840 * HKDF-Expand(PRK, info, L) -> OKM
3841 */
3842 gcry_error_t err;
3843 const unsigned label_prefix_length = (unsigned) strlen(label_prefix);
3844 const unsigned label_length = (unsigned) strlen(label);
3845
3846 /* Some sanity checks */
3847 DISSECTOR_ASSERT(label_length > 0 && label_prefix_length + label_length <= 255)((void) ((label_length > 0 && label_prefix_length +
label_length <= 255) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-tls-utils.c"
, 3847, "label_length > 0 && label_prefix_length + label_length <= 255"
))))
;
3848
3849 /* info = HkdfLabel { length, label, context } */
3850 GByteArray *info = g_byte_array_new();
3851 const uint16_t length = g_htons(out_len)(((((guint16) ( (guint16) ((guint16) (out_len) >> 8) | (
guint16) ((guint16) (out_len) << 8))))))
;
3852 g_byte_array_append(info, (const uint8_t *)&length, sizeof(length));
3853
3854 const uint8_t label_vector_length = label_prefix_length + label_length;
3855 g_byte_array_append(info, &label_vector_length, 1);
3856 g_byte_array_append(info, (const uint8_t *)label_prefix, label_prefix_length);
3857 g_byte_array_append(info, (const uint8_t*)label, label_length);
3858
3859 g_byte_array_append(info, &context_length, 1);
3860 if (context_length) {
3861 g_byte_array_append(info, context_hash, context_length);
3862 }
3863
3864 *out = (unsigned char *)wmem_alloc(NULL((void*)0), out_len);
3865 err = hkdf_expand(md, secret->data, secret->data_len, info->data, info->len, *out, out_len);
3866 g_byte_array_free(info, true1);
3867
3868 if (err) {
3869 ssl_debug_printf("%s failed %d: %s\n", G_STRFUNC((const char*) (__func__)), md, gcry_strerror(err));
3870 wmem_free(NULL((void*)0), *out);
3871 *out = NULL((void*)0);
3872 return false0;
3873 }
3874
3875 return true1;
3876}
3877
3878bool_Bool
3879tls13_hkdf_expand_label(int md, const StringInfo *secret,
3880 const char *label_prefix, const char *label,
3881 uint16_t out_len, unsigned char **out)
3882{
3883 return tls13_hkdf_expand_label_context(md, secret, label_prefix, label, NULL((void*)0), 0, out_len, out);
3884}
3885
3886static bool_Bool
3887tls13_derive_secret(int md, const StringInfo *secret,
3888 const char *label_prefix, const char *label,
3889 const uint8_t *context, unsigned context_length,
3890 uint16_t out_len, unsigned char **out)
3891{
3892 SSL_MDgcry_md_hd_t mc;
3893 uint8_t context_hash[DIGEST_MAX_SIZE48];
3894 unsigned hash_len;
3895
3896 if (ssl_md_init(&mc, md) != 0)
3897 return false0;
3898 ssl_md_update(&mc, context, context_length);
3899 ssl_md_final(&mc, context_hash, &hash_len);
3900 ssl_md_cleanup(&mc);
3901
3902 return tls13_hkdf_expand_label_context(md, secret, label_prefix, label, context_hash, hash_len, out_len, out);
3903}
3904
3905/* HMAC and the Pseudorandom function }}} */
3906
3907/* Record Decompression (after decryption) {{{ */
3908#ifdef USE_ZLIB_OR_ZLIBNG
3909/* memory allocation functions for zlib initialization */
3910static void* ssl_zalloc(void* opaque _U___attribute__((unused)), unsigned int no, unsigned int size)
3911{
3912 return g_malloc0(no*size);
3913}
3914static void ssl_zfree(void* opaque _U___attribute__((unused)), void* addr)
3915{
3916 g_free(addr)(__builtin_object_size ((addr), 0) != ((size_t) - 1)) ? g_free_sized
(addr, __builtin_object_size ((addr), 0)) : (g_free) (addr)
;
3917}
3918#endif /* USE_ZLIB_OR_ZLIBNG */
3919
3920static SslDecompress*
3921ssl_create_decompressor(int compression)
3922{
3923 SslDecompress *decomp;
3924#ifdef USE_ZLIB_OR_ZLIBNG
3925 int err;
3926#endif
3927
3928 if (compression == 0) return NULL((void*)0);
3929 ssl_debug_printf("ssl_create_decompressor: compression method %d\n", compression);
3930 decomp = wmem_new(wmem_file_scope(), SslDecompress)((SslDecompress*)wmem_alloc((wmem_file_scope()), sizeof(SslDecompress
)))
;
3931 decomp->compression = compression;
3932 switch (decomp->compression) {
3933#ifdef USE_ZLIB_OR_ZLIBNG
3934 case 1: /* DEFLATE */
3935 decomp->istream.zalloc = ssl_zalloc;
3936 decomp->istream.zfree = ssl_zfree;
3937 decomp->istream.opaque = Z_NULL0;
3938 decomp->istream.next_in = Z_NULL0;
3939 decomp->istream.next_out = Z_NULL0;
3940 decomp->istream.avail_in = 0;
3941 decomp->istream.avail_out = 0;
3942 err = ZLIB_PREFIX(inflateInit)(&decomp->istream)inflateInit_((&decomp->istream), "1.3.1", (int)sizeof(
z_stream))
;
3943 if (err != Z_OK0) {
3944 ssl_debug_printf("ssl_create_decompressor: inflateInit_() failed - %d\n", err);
3945 return NULL((void*)0);
3946 }
3947 break;
3948#endif /* USE_ZLIB_OR_ZLIBNG */
3949 default:
3950 ssl_debug_printf("ssl_create_decompressor: unsupported compression method %d\n", decomp->compression);
3951 return NULL((void*)0);
3952 }
3953 return decomp;
3954}
3955
3956#ifdef USE_ZLIB_OR_ZLIBNG
3957static int
3958ssl_decompress_record(SslDecompress* decomp, const unsigned char* in, unsigned inl, StringInfo* out_str, unsigned* outl)
3959{
3960 int err;
3961
3962 switch (decomp->compression) {
3963 case 1: /* DEFLATE */
3964 err = Z_OK0;
3965 if (out_str->data_len < 16384) { /* maximal plain length */
3966 ssl_data_realloc(out_str, 16384);
3967 }
3968#ifdef z_constconst
3969 decomp->istream.next_in = in;
3970#else
3971DIAG_OFF(cast-qual)clang diagnostic push clang diagnostic ignored "-Wcast-qual"
3972 decomp->istream.next_in = (Bytef *)in;
3973DIAG_ON(cast-qual)clang diagnostic pop
3974#endif
3975 decomp->istream.avail_in = inl;
3976 decomp->istream.next_out = out_str->data;
3977 decomp->istream.avail_out = out_str->data_len;
3978 if (inl > 0)
3979 err = ZLIB_PREFIX(inflate)inflate(&decomp->istream, Z_SYNC_FLUSH2);
3980 if (err != Z_OK0) {
3981 ssl_debug_printf("ssl_decompress_record: inflate() failed - %d\n", err);
3982 return -1;
3983 }
3984 *outl = out_str->data_len - decomp->istream.avail_out;
3985 break;
3986 default:
3987 ssl_debug_printf("ssl_decompress_record: unsupported compression method %d\n", decomp->compression);
3988 return -1;
3989 }
3990 return 0;
3991}
3992#else /* USE_ZLIB_OR_ZLIBNG */
3993int
3994ssl_decompress_record(SslDecompress* decomp _U___attribute__((unused)), const unsigned char* in _U___attribute__((unused)), unsigned inl _U___attribute__((unused)), StringInfo* out_str _U___attribute__((unused)), unsigned* outl _U___attribute__((unused)))
3995{
3996 ssl_debug_printf("ssl_decompress_record: unsupported compression method %d\n", decomp->compression);
3997 return -1;
3998}
3999#endif /* USE_ZLIB_OR_ZLIBNG */
4000/* Record Decompression (after decryption) }}} */
4001
4002/* Create a new structure to store decrypted chunks. {{{ */
4003static SslFlow*
4004ssl_create_flow(void)
4005{
4006 SslFlow *flow;
4007
4008 flow = wmem_new(wmem_file_scope(), SslFlow)((SslFlow*)wmem_alloc((wmem_file_scope()), sizeof(SslFlow)));
4009 flow->byte_seq = 0;
4010 flow->flags = 0;
4011 flow->multisegment_pdus = wmem_tree_new(wmem_file_scope());
4012 return flow;
4013}
4014/* }}} */
4015
4016/* Use the negotiated security parameters for decryption. {{{ */
4017void
4018ssl_change_cipher(SslDecryptSession *ssl_session, bool_Bool server)
4019{
4020 SslDecoder **new_decoder = server ? &ssl_session->server_new : &ssl_session->client_new;
4021 SslDecoder **dest = server ? &ssl_session->server : &ssl_session->client;
4022 ssl_debug_printf("ssl_change_cipher %s%s\n", server ? "SERVER" : "CLIENT",
4023 *new_decoder ? "" : " (No decoder found - retransmission?)");
4024 if (*new_decoder) {
4025 *dest = *new_decoder;
4026 *new_decoder = NULL((void*)0);
4027 }
4028}
4029/* }}} */
4030
4031/* Init cipher state given some security parameters. {{{ */
4032static bool_Bool
4033ssl_decoder_destroy_cb(wmem_allocator_t *, wmem_cb_event_t, void *);
4034
4035static SslDecoder*
4036ssl_create_decoder(const SslCipherSuite *cipher_suite, int cipher_algo,
4037 int compression, uint8_t *mk, uint8_t *sk, uint8_t *sn_key, uint8_t *iv, unsigned iv_length)
4038{
4039 SslDecoder *dec;
4040 ssl_cipher_mode_t mode = cipher_suite->mode;
4041
4042 dec = wmem_new0(wmem_file_scope(), SslDecoder)((SslDecoder*)wmem_alloc0((wmem_file_scope()), sizeof(SslDecoder
)))
;
4043 /* init mac buffer: mac storage is embedded into decoder struct to save a
4044 memory allocation and waste samo more memory*/
4045 dec->cipher_suite=cipher_suite;
4046 dec->compression = compression;
4047 if ((mode == MODE_STREAM && mk != NULL((void*)0)) || mode == MODE_CBC) {
4048 // AEAD ciphers use no MAC key, but stream and block ciphers do. Note
4049 // the special case for NULL ciphers, even if there is insufficiency
4050 // keying material (including MAC key), we will can still create
4051 // decoders since "decryption" is easy for such ciphers.
4052 dec->mac_key.data = dec->_mac_key_or_write_iv;
4053 ssl_data_set(&dec->mac_key, mk, ssl_cipher_suite_dig(cipher_suite)->len);
4054 } else if (mode == MODE_GCM || mode == MODE_CCM || mode == MODE_CCM_8 || mode == MODE_POLY1305) {
4055 // Input for the nonce, to be used with AEAD ciphers.
4056 DISSECTOR_ASSERT(iv_length <= sizeof(dec->_mac_key_or_write_iv))((void) ((iv_length <= sizeof(dec->_mac_key_or_write_iv
)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/dissectors/packet-tls-utils.c", 4056, "iv_length <= sizeof(dec->_mac_key_or_write_iv)"
))))
;
4057 dec->write_iv.data = dec->_mac_key_or_write_iv;
4058 ssl_data_set(&dec->write_iv, iv, iv_length);
4059 }
4060 dec->seq = 0;
4061 dec->decomp = ssl_create_decompressor(compression);
4062 wmem_register_callback(wmem_file_scope(), ssl_decoder_destroy_cb, dec);
4063
4064 if (ssl_cipher_init(&dec->evp,cipher_algo,sk,iv,cipher_suite->mode) < 0) {
4065 ssl_debug_printf("%s: can't create cipher id:%d mode:%d\n", G_STRFUNC((const char*) (__func__)),
4066 cipher_algo, cipher_suite->mode);
4067 return NULL((void*)0);
4068 }
4069
4070 if (cipher_suite->enc != ENC_NULL0x3D && sn_key != NULL((void*)0)) {
4071 if (cipher_suite->enc == ENC_AES0x35 || cipher_suite->enc == ENC_AES2560x36) {
4072 mode = MODE_ECB;
4073 } else if (cipher_suite->enc == ENC_CHACHA200x3A) {
4074 mode = MODE_STREAM;
4075 } else {
4076 ssl_debug_printf("not supported encryption algorithm for DTLSv1.3\n");
4077 return NULL((void*)0);
4078 }
4079
4080 if (ssl_cipher_init(&dec->sn_evp, cipher_algo, sn_key, NULL((void*)0), mode) < 0) {
4081 ssl_debug_printf("%s: can't create cipher id:%d mode:%d for seq number decryption\n", G_STRFUNC((const char*) (__func__)),
4082 cipher_algo, MODE_ECB);
4083 ssl_cipher_cleanup(&dec->evp);
4084 dec->evp = NULL((void*)0);
4085 return NULL((void*)0);
4086 }
4087 } else {
4088 dec->sn_evp = NULL((void*)0);
4089 }
4090
4091 dec->dtls13_aad.data = NULL((void*)0);
4092 dec->dtls13_aad.data_len = 0;
4093 ssl_debug_printf("decoder initialized (digest len %d)\n", ssl_cipher_suite_dig(cipher_suite)->len);
4094 return dec;
4095}
4096
4097static bool_Bool
4098ssl_decoder_destroy_cb(wmem_allocator_t *allocator _U___attribute__((unused)), wmem_cb_event_t event _U___attribute__((unused)), void *user_data)
4099{
4100 SslDecoder *dec = (SslDecoder *) user_data;
4101
4102 if (dec->evp)
4103 ssl_cipher_cleanup(&dec->evp);
4104 if (dec->sn_evp)
4105 ssl_cipher_cleanup(&dec->sn_evp);
4106
4107#ifdef USE_ZLIB_OR_ZLIBNG
4108 if (dec->decomp != NULL((void*)0) && dec->decomp->compression == 1 /* DEFLATE */)
4109 ZLIB_PREFIX(inflateEnd)inflateEnd(&dec->decomp->istream);
4110#endif
4111
4112 return false0;
4113}
4114/* }}} */
4115
4116/* (Pre-)master secrets calculations {{{ */
4117#ifdef HAVE_LIBGNUTLS1
4118static bool_Bool
4119ssl_decrypt_pre_master_secret(SslDecryptSession *ssl_session,
4120 StringInfo *encrypted_pre_master,
4121 GHashTable *key_hash);
4122#endif /* HAVE_LIBGNUTLS */
4123
4124static bool_Bool
4125ssl_restore_master_key(SslDecryptSession *ssl, const char *label,
4126 bool_Bool is_pre_master, GHashTable *ht, StringInfo *key);
4127
4128bool_Bool
4129ssl_generate_pre_master_secret(SslDecryptSession *ssl_session,
4130 uint32_t length, tvbuff_t *tvb, uint32_t offset,
4131 const char *ssl_psk, packet_info *pinfo,
4132#ifdef HAVE_LIBGNUTLS1
4133 GHashTable *key_hash,
4134#endif
4135 const ssl_master_key_map_t *mk_map)
4136{
4137 /* check for required session data */
4138 ssl_debug_printf("%s: found SSL_HND_CLIENT_KEY_EXCHG, state %X\n",
4139 G_STRFUNC((const char*) (__func__)), ssl_session->state);
4140 if ((ssl_session->state & (SSL_CIPHER(1<<2)|SSL_CLIENT_RANDOM(1<<0)|SSL_SERVER_RANDOM(1<<1)|SSL_VERSION(1<<4))) !=
4141 (SSL_CIPHER(1<<2)|SSL_CLIENT_RANDOM(1<<0)|SSL_SERVER_RANDOM(1<<1)|SSL_VERSION(1<<4))) {
4142 ssl_debug_printf("%s: not enough data to generate key (required state %X)\n", G_STRFUNC((const char*) (__func__)),
4143 (SSL_CIPHER(1<<2)|SSL_CLIENT_RANDOM(1<<0)|SSL_SERVER_RANDOM(1<<1)|SSL_VERSION(1<<4)));
4144 return false0;
4145 }
4146
4147 if (ssl_session->session.version == TLSV1DOT3_VERSION0x304) {
4148 ssl_debug_printf("%s: detected TLS 1.3 which has no pre-master secrets\n", G_STRFUNC((const char*) (__func__)));
4149 return false0;
4150 }
4151
4152 /* check to see if the PMS was provided to us*/
4153 if (ssl_restore_master_key(ssl_session, "Unencrypted pre-master secret", true1,
4154 mk_map->pms, &ssl_session->client_random)) {
4155 return true1;
4156 }
4157
4158 if (ssl_session->cipher_suite->kex == KEX_PSK0x1d)
4159 {
4160 /* calculate pre master secret*/
4161 StringInfo pre_master_secret;
4162 unsigned psk_len, pre_master_len;
4163
4164 if (!tls_load_psk(ssl_session, ssl_psk)) {
4165 return false0;
4166 }
4167 psk_len = ssl_session->psk.data_len;
4168
4169 pre_master_len = psk_len * 2 + 4;
4170
4171 pre_master_secret.data = (unsigned char *)wmem_alloc(wmem_file_scope(), pre_master_len);
4172 pre_master_secret.data_len = pre_master_len;
4173 /* 2 bytes psk_len*/
4174 pre_master_secret.data[0] = psk_len >> 8;
4175 pre_master_secret.data[1] = psk_len & 0xFF;
4176 /* psk_len bytes times 0*/
4177 memset(&pre_master_secret.data[2], 0, psk_len);
4178 /* 2 bytes psk_len*/
4179 pre_master_secret.data[psk_len + 2] = psk_len >> 8;
4180 pre_master_secret.data[psk_len + 3] = psk_len & 0xFF;
4181 /* psk*/
4182 memcpy(&pre_master_secret.data[psk_len + 4], ssl_session->psk.data, psk_len);
4183
4184 ssl_session->pre_master_secret.data = pre_master_secret.data;
4185 ssl_session->pre_master_secret.data_len = pre_master_len;
4186 /*ssl_debug_printf("pre master secret",&ssl->pre_master_secret);*/
4187
4188 /* Remove the master secret if it was there.
4189 This forces keying material regeneration in
4190 case we're renegotiating */
4191 ssl_session->state &= ~(SSL_MASTER_SECRET(1<<5)|SSL_HAVE_SESSION_KEY(1<<3));
4192 ssl_session->state |= SSL_PRE_MASTER_SECRET(1<<6);
4193 return true1;
4194 }
4195 else
4196 {
4197 unsigned encrlen, skip;
4198 encrlen = length;
4199 skip = 0;
4200
4201 /* get encrypted data, on tls1 we have to skip two bytes
4202 * (it's the encrypted len and should be equal to record len - 2)
4203 * in case of rsa1024 that would be 128 + 2 = 130; for psk not necessary
4204 */
4205 if (ssl_session->cipher_suite->kex == KEX_RSA0x1e &&
4206 (ssl_session->session.version == TLSV1_VERSION0x301 ||
4207 ssl_session->session.version == TLSV1DOT1_VERSION0x302 ||
4208 ssl_session->session.version == TLSV1DOT2_VERSION0x303 ||
4209 ssl_session->session.version == DTLSV1DOT0_VERSION0xfeff ||
4210 ssl_session->session.version == DTLSV1DOT2_VERSION0xfefd ||
4211 ssl_session->session.version == TLCPV1_VERSION0x101 ))
4212 {
4213 encrlen = tvb_get_ntohs(tvb, offset);
4214 skip = 2;
4215 if (encrlen > length - 2)
4216 {
4217 ssl_debug_printf("%s: wrong encrypted length (%d max %d)\n",
4218 G_STRFUNC((const char*) (__func__)), encrlen, length);
4219 return false0;
4220 }
4221 }
4222 /* the valid lower bound is higher than 8, but it is sufficient for the
4223 * ssl keylog file below */
4224 if (encrlen < 8) {
4225 ssl_debug_printf("%s: invalid encrypted pre-master key length %d\n",
4226 G_STRFUNC((const char*) (__func__)), encrlen);
4227 return false0;
4228 }
4229
4230 StringInfo encrypted_pre_master = {
4231 .data = (unsigned char *)tvb_memdup(pinfo->pool, tvb, offset + skip, encrlen),
4232 .data_len = encrlen,
4233 };
4234
4235#ifdef HAVE_LIBGNUTLS1
4236 /* Try to lookup an appropriate RSA private key to decrypt the Encrypted Pre-Master Secret. */
4237 if (ssl_session->cert_key_id) {
4238 if (ssl_decrypt_pre_master_secret(ssl_session, &encrypted_pre_master, key_hash))
4239 return true1;
4240
4241 ssl_debug_printf("%s: can't decrypt pre-master secret\n",
4242 G_STRFUNC((const char*) (__func__)));
4243 }
4244#endif /* HAVE_LIBGNUTLS */
4245
4246 /* try to find the pre-master secret from the encrypted one. The
4247 * ssl key logfile stores only the first 8 bytes, so truncate it */
4248 encrypted_pre_master.data_len = 8;
4249 if (ssl_restore_master_key(ssl_session, "Encrypted pre-master secret",
4250 true1, mk_map->pre_master, &encrypted_pre_master))
4251 return true1;
4252 }
4253 return false0;
4254}
4255
4256/* Used for (D)TLS 1.2 and earlier versions (not with TLS 1.3). */
4257int
4258ssl_generate_keyring_material(SslDecryptSession*ssl_session)
4259{
4260 StringInfo key_block = { NULL((void*)0), 0 };
4261 uint8_t _iv_c[MAX_BLOCK_SIZE16],_iv_s[MAX_BLOCK_SIZE16];
4262 uint8_t _key_c[MAX_KEY_SIZE32],_key_s[MAX_KEY_SIZE32];
4263 int needed;
4264 int cipher_algo = -1; /* special value (-1) for NULL encryption */
4265 unsigned encr_key_len, write_iv_len = 0;
4266 bool_Bool is_export_cipher;
4267 uint8_t *ptr, *c_iv = NULL((void*)0), *s_iv = NULL((void*)0);
4268 uint8_t *c_wk = NULL((void*)0), *s_wk = NULL((void*)0), *c_mk = NULL((void*)0), *s_mk = NULL((void*)0);
4269 const SslCipherSuite *cipher_suite = ssl_session->cipher_suite;
4270
4271 /* (D)TLS 1.3 is handled directly in tls13_change_key. */
4272 if (ssl_session->session.version == TLSV1DOT3_VERSION0x304 || ssl_session->session.version == DTLSV1DOT3_VERSION0xfefc) {
4273 ssl_debug_printf("%s: detected TLS 1.3. Should not have been called!\n", G_STRFUNC((const char*) (__func__)));
4274 return -1;
4275 }
4276
4277 /* check for enough info to proceed */
4278 unsigned need_all = SSL_CIPHER(1<<2)|SSL_CLIENT_RANDOM(1<<0)|SSL_SERVER_RANDOM(1<<1)|SSL_VERSION(1<<4);
4279 unsigned need_any = SSL_MASTER_SECRET(1<<5) | SSL_PRE_MASTER_SECRET(1<<6);
4280 if (((ssl_session->state & need_all) != need_all) || ((ssl_session->state & need_any) == 0)) {
4281 ssl_debug_printf("ssl_generate_keyring_material not enough data to generate key "
4282 "(0x%02X required 0x%02X or 0x%02X)\n", ssl_session->state,
4283 need_all|SSL_MASTER_SECRET(1<<5), need_all|SSL_PRE_MASTER_SECRET(1<<6));
4284 /* Special case: for NULL encryption, allow dissection of data even if
4285 * the Client Hello is missing (MAC keys are now skipped though). */
4286 need_all = SSL_CIPHER(1<<2)|SSL_VERSION(1<<4);
4287 if ((ssl_session->state & need_all) == need_all &&
4288 cipher_suite->enc == ENC_NULL0x3D) {
4289 ssl_debug_printf("%s NULL cipher found, will create a decoder but "
4290 "skip MAC validation as keys are missing.\n", G_STRFUNC((const char*) (__func__)));
4291 goto create_decoders;
4292 }
4293
4294 return -1;
4295 }
4296
4297 /* if master key is not available, generate is from the pre-master secret */
4298 if (!(ssl_session->state & SSL_MASTER_SECRET(1<<5))) {
4299 if ((ssl_session->state & SSL_EXTENDED_MASTER_SECRET_MASK((1<<7)|(1<<8))) == SSL_EXTENDED_MASTER_SECRET_MASK((1<<7)|(1<<8))) {
4300 StringInfo handshake_hashed_data;
4301 int ret;
4302
4303 handshake_hashed_data.data = NULL((void*)0);
4304 handshake_hashed_data.data_len = 0;
4305
4306 ssl_debug_printf("%s:PRF(pre_master_secret_extended)\n", G_STRFUNC((const char*) (__func__)));
4307 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
4308
4309 switch(ssl_session->session.version) {
4310 case TLSV1_VERSION0x301:
4311 case TLSV1DOT1_VERSION0x302:
4312 case DTLSV1DOT0_VERSION0xfeff:
4313 case DTLSV1DOT0_OPENSSL_VERSION0x100:
4314 case TLCPV1_VERSION0x101:
4315 ret = tls_handshake_hash(ssl_session, &handshake_hashed_data);
4316 break;
4317 default:
4318 switch (cipher_suite->dig) {
4319 case DIG_SHA3840x43:
4320 ret = tls12_handshake_hash(ssl_session, GCRY_MD_SHA384, &handshake_hashed_data);
4321 break;
4322 default:
4323 ret = tls12_handshake_hash(ssl_session, GCRY_MD_SHA256, &handshake_hashed_data);
4324 break;
4325 }
4326 break;
4327 }
4328 if (ret) {
4329 ssl_debug_printf("%s can't generate handshake hash\n", G_STRFUNC((const char*) (__func__)));
4330 return -1;
4331 }
4332
4333 tls_transcript_reset(&ssl_session->handshake_transcript);
4334
4335 if (!prf(ssl_session, &ssl_session->pre_master_secret, "extended master secret",
4336 &handshake_hashed_data,
4337 NULL((void*)0), &ssl_session->master_secret,
4338 SSL_MASTER_SECRET_LENGTH48)) {
4339 ssl_debug_printf("%s can't generate master_secret\n", G_STRFUNC((const char*) (__func__)));
4340 g_free(handshake_hashed_data.data)(__builtin_object_size ((handshake_hashed_data.data), 0) != (
(size_t) - 1)) ? g_free_sized (handshake_hashed_data.data, __builtin_object_size
((handshake_hashed_data.data), 0)) : (g_free) (handshake_hashed_data
.data)
;
4341 return -1;
4342 }
4343 g_free(handshake_hashed_data.data)(__builtin_object_size ((handshake_hashed_data.data), 0) != (
(size_t) - 1)) ? g_free_sized (handshake_hashed_data.data, __builtin_object_size
((handshake_hashed_data.data), 0)) : (g_free) (handshake_hashed_data
.data)
;
4344 } else {
4345 ssl_debug_printf("%s:PRF(pre_master_secret)\n", G_STRFUNC((const char*) (__func__)));
4346 ssl_print_string("pre master secret",&ssl_session->pre_master_secret);
4347 ssl_print_string("client random",&ssl_session->client_random);
4348 ssl_print_string("server random",&ssl_session->server_random);
4349 if (!prf(ssl_session, &ssl_session->pre_master_secret, "master secret",
4350 &ssl_session->client_random,
4351 &ssl_session->server_random, &ssl_session->master_secret,
4352 SSL_MASTER_SECRET_LENGTH48)) {
4353 ssl_debug_printf("%s can't generate master_secret\n", G_STRFUNC((const char*) (__func__)));
4354 return -1;
4355 }
4356 }
4357 ssl_print_string("master secret",&ssl_session->master_secret);
4358
4359 /* the pre-master secret has been 'consumed' so we must clear it now */
4360 ssl_session->state &= ~SSL_PRE_MASTER_SECRET(1<<6);
4361 ssl_session->state |= SSL_MASTER_SECRET(1<<5);
4362 }
4363
4364 /* Find the Libgcrypt cipher algorithm for the given SSL cipher suite ID */
4365 if (cipher_suite->enc != ENC_NULL0x3D) {
4366 const char *cipher_name = ciphers[cipher_suite->enc-ENC_START0x30];
4367 ssl_debug_printf("%s CIPHER: %s\n", G_STRFUNC((const char*) (__func__)), cipher_name);
4368 cipher_algo = ssl_get_cipher_by_name(cipher_name);
4369 if (cipher_algo == 0) {
4370 ssl_debug_printf("%s can't find cipher %s\n", G_STRFUNC((const char*) (__func__)), cipher_name);
4371 return -1;
4372 }
4373 }
4374
4375 /* Export ciphers consume less material from the key block. */
4376 encr_key_len = ssl_get_cipher_export_keymat_size(cipher_suite->number);
4377 is_export_cipher = encr_key_len > 0;
4378 if (!is_export_cipher && cipher_suite->enc != ENC_NULL0x3D) {
4379 encr_key_len = (unsigned)gcry_cipher_get_algo_keylen(cipher_algo);
4380 }
4381
4382 if (cipher_suite->mode == MODE_CBC) {
4383 write_iv_len = (unsigned)gcry_cipher_get_algo_blklen(cipher_algo);
4384 } else if (cipher_suite->mode == MODE_GCM || cipher_suite->mode == MODE_CCM || cipher_suite->mode == MODE_CCM_8) {
4385 /* account for a four-byte salt for client and server side (from
4386 * client_write_IV and server_write_IV), see GCMNonce (RFC 5288) */
4387 write_iv_len = 4;
4388 } else if (cipher_suite->mode == MODE_POLY1305) {
4389 /* RFC 7905: SecurityParameters.fixed_iv_length is twelve bytes */
4390 write_iv_len = 12;
4391 }
4392
4393 /* Compute the key block. First figure out how much data we need */
4394 needed = ssl_cipher_suite_dig(cipher_suite)->len*2; /* MAC key */
4395 needed += 2 * encr_key_len; /* encryption key */
4396 needed += 2 * write_iv_len; /* write IV */
4397
4398 key_block.data = (unsigned char *)g_malloc(needed);
4399 ssl_debug_printf("%s sess key generation\n", G_STRFUNC((const char*) (__func__)));
4400 if (!prf(ssl_session, &ssl_session->master_secret, "key expansion",
4401 &ssl_session->server_random,&ssl_session->client_random,
4402 &key_block, needed)) {
4403 ssl_debug_printf("%s can't generate key_block\n", G_STRFUNC((const char*) (__func__)));
4404 goto fail;
4405 }
4406 ssl_print_string("key expansion", &key_block);
4407
4408 ptr=key_block.data;
4409 /* client/server write MAC key (for non-AEAD ciphers) */
4410 if (cipher_suite->mode == MODE_STREAM || cipher_suite->mode == MODE_CBC) {
4411 c_mk=ptr; ptr+=ssl_cipher_suite_dig(cipher_suite)->len;
4412 s_mk=ptr; ptr+=ssl_cipher_suite_dig(cipher_suite)->len;
4413 }
4414 /* client/server write encryption key */
4415 c_wk=ptr; ptr += encr_key_len;
4416 s_wk=ptr; ptr += encr_key_len;
4417 /* client/server write IV (used as IV (for CBC) or salt (for AEAD)) */
4418 if (write_iv_len > 0) {
4419 c_iv=ptr; ptr += write_iv_len;
4420 s_iv=ptr; /* ptr += write_iv_len; */
4421 }
4422
4423 /* export ciphers work with a smaller key length */
4424 if (is_export_cipher) {
4425 if (cipher_suite->mode == MODE_CBC) {
4426
4427 /* We only have room for MAX_BLOCK_SIZE bytes IVs, but that's
4428 all we should need. This is a sanity check */
4429 if (write_iv_len > MAX_BLOCK_SIZE16) {
4430 ssl_debug_printf("%s cipher suite block must be at most %d nut is %d\n",
4431 G_STRFUNC((const char*) (__func__)), MAX_BLOCK_SIZE16, write_iv_len);
4432 goto fail;
4433 }
4434
4435 if(ssl_session->session.version==SSLV3_VERSION0x300){
4436 /* The length of these fields are ignored by this caller */
4437 StringInfo iv_c, iv_s;
4438 iv_c.data = _iv_c;
4439 iv_s.data = _iv_s;
4440
4441 ssl_debug_printf("%s ssl3_generate_export_iv\n", G_STRFUNC((const char*) (__func__)));
4442 if (!ssl3_generate_export_iv(&ssl_session->client_random,
4443 &ssl_session->server_random, &iv_c, write_iv_len)) {
4444 goto fail;
4445 }
4446 ssl_debug_printf("%s ssl3_generate_export_iv(2)\n", G_STRFUNC((const char*) (__func__)));
4447 if (!ssl3_generate_export_iv(&ssl_session->server_random,
4448 &ssl_session->client_random, &iv_s, write_iv_len)) {
4449 goto fail;
4450 }
4451 }
4452 else{
4453 uint8_t _iv_block[MAX_BLOCK_SIZE16 * 2];
4454 StringInfo iv_block;
4455 StringInfo key_null;
4456 uint8_t _key_null;
4457
4458 key_null.data = &_key_null;
4459 key_null.data_len = 0;
4460
4461 iv_block.data = _iv_block;
4462
4463 ssl_debug_printf("%s prf(iv_block)\n", G_STRFUNC((const char*) (__func__)));
4464 if (!prf(ssl_session, &key_null, "IV block",
4465 &ssl_session->client_random,
4466 &ssl_session->server_random, &iv_block,
4467 write_iv_len * 2)) {
4468 ssl_debug_printf("%s can't generate tls31 iv block\n", G_STRFUNC((const char*) (__func__)));
4469 goto fail;
4470 }
4471
4472 memcpy(_iv_c, iv_block.data, write_iv_len);
4473 memcpy(_iv_s, iv_block.data + write_iv_len, write_iv_len);
4474 }
4475
4476 c_iv=_iv_c;
4477 s_iv=_iv_s;
4478 }
4479
4480 if (ssl_session->session.version==SSLV3_VERSION0x300){
4481
4482 SSL_MD5_CTXgcry_md_hd_t md5;
4483 ssl_debug_printf("%s MD5(client_random)\n", G_STRFUNC((const char*) (__func__)));
4484
4485 if (ssl_md5_init(&md5) != 0)
4486 goto fail;
4487 ssl_md5_update(&md5,c_wk,encr_key_len);
4488 ssl_md5_update(&md5,ssl_session->client_random.data,
4489 ssl_session->client_random.data_len);
4490 ssl_md5_update(&md5,ssl_session->server_random.data,
4491 ssl_session->server_random.data_len);
4492 ssl_md5_final(_key_c,&md5);
4493 ssl_md5_cleanup(&md5);
4494 c_wk=_key_c;
4495
4496 if (ssl_md5_init(&md5) != 0)
4497 goto fail;
4498 ssl_debug_printf("%s MD5(server_random)\n", G_STRFUNC((const char*) (__func__)));
4499 ssl_md5_update(&md5,s_wk,encr_key_len);
4500 ssl_md5_update(&md5,ssl_session->server_random.data,
4501 ssl_session->server_random.data_len);
4502 ssl_md5_update(&md5,ssl_session->client_random.data,
4503 ssl_session->client_random.data_len);
4504 ssl_md5_final(_key_s,&md5);
4505 ssl_md5_cleanup(&md5);
4506 s_wk=_key_s;
4507 }
4508 else{
4509 StringInfo key_c, key_s, k;
4510 key_c.data = _key_c;
4511 key_s.data = _key_s;
4512
4513 k.data = c_wk;
4514 k.data_len = encr_key_len;
4515 ssl_debug_printf("%s PRF(key_c)\n", G_STRFUNC((const char*) (__func__)));
4516 if (!prf(ssl_session, &k, "client write key",
4517 &ssl_session->client_random,
4518 &ssl_session->server_random, &key_c, sizeof(_key_c))) {
4519 ssl_debug_printf("%s can't generate tll31 server key \n", G_STRFUNC((const char*) (__func__)));
4520 goto fail;
4521 }
4522 c_wk=_key_c;
4523
4524 k.data = s_wk;
4525 k.data_len = encr_key_len;
4526 ssl_debug_printf("%s PRF(key_s)\n", G_STRFUNC((const char*) (__func__)));
4527 if (!prf(ssl_session, &k, "server write key",
4528 &ssl_session->client_random,
4529 &ssl_session->server_random, &key_s, sizeof(_key_s))) {
4530 ssl_debug_printf("%s can't generate tll31 client key \n", G_STRFUNC((const char*) (__func__)));
4531 goto fail;
4532 }
4533 s_wk=_key_s;
4534 }
4535 }
4536
4537 /* show key material info */
4538 if (c_mk != NULL((void*)0)) {
4539 ssl_print_data("Client MAC key",c_mk,ssl_cipher_suite_dig(cipher_suite)->len);
4540 ssl_print_data("Server MAC key",s_mk,ssl_cipher_suite_dig(cipher_suite)->len);
4541 }
4542 ssl_print_data("Client Write key", c_wk, encr_key_len);
4543 ssl_print_data("Server Write key", s_wk, encr_key_len);
4544 /* used as IV for CBC mode and the AEAD implicit nonce (salt) */
4545 if (write_iv_len > 0) {
4546 ssl_print_data("Client Write IV", c_iv, write_iv_len);
4547 ssl_print_data("Server Write IV", s_iv, write_iv_len);
4548 }
4549
4550create_decoders:
4551 /* create both client and server ciphers*/
4552 ssl_debug_printf("%s ssl_create_decoder(client)\n", G_STRFUNC((const char*) (__func__)));
4553 ssl_session->client_new = ssl_create_decoder(cipher_suite, cipher_algo, ssl_session->session.compression, c_mk, c_wk, NULL((void*)0), c_iv, write_iv_len);
4554 if (!ssl_session->client_new) {
4555 ssl_debug_printf("%s can't init client decoder\n", G_STRFUNC((const char*) (__func__)));
4556 goto fail;
4557 }
4558 ssl_debug_printf("%s ssl_create_decoder(server)\n", G_STRFUNC((const char*) (__func__)));
4559 ssl_session->server_new = ssl_create_decoder(cipher_suite, cipher_algo, ssl_session->session.compression, s_mk, s_wk, NULL((void*)0), s_iv, write_iv_len);
4560 if (!ssl_session->server_new) {
4561 ssl_debug_printf("%s can't init server decoder\n", G_STRFUNC((const char*) (__func__)));
4562 goto fail;
4563 }
4564
4565 /* Continue the SSL stream after renegotiation with new keys. */
4566 ssl_session->client_new->flow = ssl_session->client ? ssl_session->client->flow : ssl_create_flow();
4567 ssl_session->server_new->flow = ssl_session->server ? ssl_session->server->flow : ssl_create_flow();
4568
4569 ssl_debug_printf("%s: client seq %" PRIu64"l" "u" ", server seq %" PRIu64"l" "u" "\n",
4570 G_STRFUNC((const char*) (__func__)), ssl_session->client_new->seq, ssl_session->server_new->seq);
4571 g_free(key_block.data)(__builtin_object_size ((key_block.data), 0) != ((size_t) - 1
)) ? g_free_sized (key_block.data, __builtin_object_size ((key_block
.data), 0)) : (g_free) (key_block.data)
;
4572 ssl_session->state |= SSL_HAVE_SESSION_KEY(1<<3);
4573 return 0;
4574
4575fail:
4576 g_free(key_block.data)(__builtin_object_size ((key_block.data), 0) != ((size_t) - 1
)) ? g_free_sized (key_block.data, __builtin_object_size ((key_block
.data), 0)) : (g_free) (key_block.data)
;
4577 return -1;
4578}
4579
4580/* Generated the key material based on the given secret. */
4581bool_Bool
4582tls13_generate_keys(SslDecryptSession *ssl_session, const StringInfo *secret, bool_Bool is_from_server)
4583{
4584 bool_Bool success = false0;
4585 unsigned char *write_key = NULL((void*)0), *write_iv = NULL((void*)0);
4586 unsigned char *sn_key = NULL((void*)0);
4587 SslDecoder *decoder;
4588 unsigned key_length, iv_length;
4589 int hash_algo;
4590 const SslCipherSuite *cipher_suite = ssl_session->cipher_suite;
4591 int cipher_algo;
4592
4593 if ((ssl_session->session.version != TLSV1DOT3_VERSION0x304) && (ssl_session->session.version != DTLSV1DOT3_VERSION0xfefc)) {
4594 ssl_debug_printf("%s only usable for TLS 1.3, not %#x!\n", G_STRFUNC((const char*) (__func__)),
4595 ssl_session->session.version);
4596 return false0;
4597 }
4598
4599 if (cipher_suite == NULL((void*)0)) {
4600 ssl_debug_printf("%s Unknown cipher\n", G_STRFUNC((const char*) (__func__)));
4601 return false0;
4602 }
4603
4604 if (cipher_suite->kex != KEX_TLS130x23) {
4605 ssl_debug_printf("%s Invalid cipher suite 0x%04x spotted!\n", G_STRFUNC((const char*) (__func__)), cipher_suite->number);
4606 return false0;
4607 }
4608
4609 /* Find the Libgcrypt cipher algorithm for the given SSL cipher suite ID */
4610 const char *cipher_name = ciphers[cipher_suite->enc-ENC_START0x30];
4611 ssl_debug_printf("%s CIPHER: %s\n", G_STRFUNC((const char*) (__func__)), cipher_name);
4612 cipher_algo = ssl_get_cipher_by_name(cipher_name);
4613 if (cipher_algo == 0) {
4614 ssl_debug_printf("%s can't find cipher %s\n", G_STRFUNC((const char*) (__func__)), cipher_name);
4615 return false0;
4616 }
4617
4618 const char *hash_name = ssl_cipher_suite_dig(cipher_suite)->name;
4619 hash_algo = ssl_get_digest_by_name(hash_name);
4620 if (!hash_algo) {
4621 ssl_debug_printf("%s can't find hash function %s\n", G_STRFUNC((const char*) (__func__)), hash_name);
4622 return false0;
4623 }
4624
4625 key_length = (unsigned) gcry_cipher_get_algo_keylen(cipher_algo);
4626 /* AES-GCM/AES-CCM/Poly1305-ChaCha20 all have N_MIN=N_MAX = 12. */
4627 iv_length = 12;
4628 ssl_debug_printf("%s key_length %u iv_length %u\n", G_STRFUNC((const char*) (__func__)), key_length, iv_length);
4629
4630 const char *label_prefix = tls13_hkdf_label_prefix(ssl_session);
4631 if (!tls13_hkdf_expand_label(hash_algo, secret, label_prefix, "key", key_length, &write_key)) {
4632 ssl_debug_printf("%s write_key expansion failed\n", G_STRFUNC((const char*) (__func__)));
4633 return false0;
4634 }
4635 if (!tls13_hkdf_expand_label(hash_algo, secret, label_prefix, "iv", iv_length, &write_iv)) {
4636 ssl_debug_printf("%s write_iv expansion failed\n", G_STRFUNC((const char*) (__func__)));
4637 goto end;
4638 }
4639
4640 if (ssl_session->session.version == DTLSV1DOT3_VERSION0xfefc) {
4641 if (!tls13_hkdf_expand_label(hash_algo, secret, label_prefix, "sn", key_length, &sn_key)) {
4642 ssl_debug_printf("%s sn_key expansion failed\n", G_STRFUNC((const char*) (__func__)));
4643 goto end;
4644 }
4645 }
4646
4647 ssl_print_data(is_from_server ? "Server Write Key" : "Client Write Key", write_key, key_length);
4648 ssl_print_data(is_from_server ? "Server Write IV" : "Client Write IV", write_iv, iv_length);
4649 if (ssl_session->session.version == DTLSV1DOT3_VERSION0xfefc) {
4650 ssl_print_data(is_from_server ? "Server Write SN" : "Client Write SN", sn_key, key_length);
4651 }
4652
4653 ssl_debug_printf("%s ssl_create_decoder(%s)\n", G_STRFUNC((const char*) (__func__)), is_from_server ? "server" : "client");
4654 decoder = ssl_create_decoder(cipher_suite, cipher_algo, 0, NULL((void*)0), write_key, sn_key, write_iv, iv_length);
4655 if (!decoder) {
4656 ssl_debug_printf("%s can't init %s decoder\n", G_STRFUNC((const char*) (__func__)), is_from_server ? "server" : "client");
4657 goto end;
4658 }
4659
4660 /* Continue the TLS session with new keys, but reuse old flow to keep things
4661 * like "Follow TLS" working (by linking application data records). */
4662 if (is_from_server) {
4663 decoder->flow = ssl_session->server ? ssl_session->server->flow : ssl_create_flow();
4664 ssl_session->server = decoder;
4665 } else {
4666 decoder->flow = ssl_session->client ? ssl_session->client->flow : ssl_create_flow();
4667 ssl_session->client = decoder;
4668 }
4669 ssl_debug_printf("%s %s ready using cipher suite 0x%04x (cipher %s hash %s)\n", G_STRFUNC((const char*) (__func__)),
4670 is_from_server ? "Server" : "Client", cipher_suite->number, cipher_name, hash_name);
4671 success = true1;
4672
4673end:
4674 wmem_free(NULL((void*)0), write_key);
4675 wmem_free(NULL((void*)0), write_iv);
4676 if (sn_key)
4677 wmem_free(NULL((void*)0), sn_key);
4678 return success;
4679}
4680/* (Pre-)master secrets calculations }}} */
4681
4682#ifdef HAVE_LIBGNUTLS1
4683/* Decrypt RSA pre-master secret using RSA private key. {{{ */
4684static bool_Bool
4685ssl_decrypt_pre_master_secret(SslDecryptSession *ssl_session,
4686 StringInfo *encrypted_pre_master, GHashTable *key_hash)
4687{
4688 int ret;
4689
4690 if (!encrypted_pre_master)
4691 return false0;
4692
4693 if (KEX_IS_DH(ssl_session->cipher_suite->kex)((ssl_session->cipher_suite->kex) >= 0x10 &&
(ssl_session->cipher_suite->kex) <= 0x1b)
) {
4694 ssl_debug_printf("%s: session uses Diffie-Hellman key exchange "
4695 "(cipher suite 0x%04X %s) and cannot be decrypted "
4696 "using a RSA private key file.\n",
4697 G_STRFUNC((const char*) (__func__)), ssl_session->session.cipher,
4698 val_to_str_ext_const(ssl_session->session.cipher,
4699 &ssl_31_ciphersuite_ext, "unknown"));
4700 return false0;
4701 } else if (ssl_session->cipher_suite->kex != KEX_RSA0x1e) {
4702 ssl_debug_printf("%s key exchange %d different from KEX_RSA (%d)\n",
4703 G_STRFUNC((const char*) (__func__)), ssl_session->cipher_suite->kex, KEX_RSA0x1e);
4704 return false0;
4705 }
4706
4707 gnutls_privkey_t pk = (gnutls_privkey_t)g_hash_table_lookup(key_hash, ssl_session->cert_key_id);
4708
4709 ssl_print_string("pre master encrypted", encrypted_pre_master);
4710 ssl_debug_printf("%s: RSA_private_decrypt\n", G_STRFUNC((const char*) (__func__)));
4711 const gnutls_datum_t epms = { encrypted_pre_master->data, encrypted_pre_master->data_len };
4712 gnutls_datum_t pms = { 0 };
4713 if (pk) {
4714 // Try to decrypt using the RSA keys table from (D)TLS preferences.
4715 char *err = NULL((void*)0);
4716 gcry_sexp_t private_key = rsa_abstract_privkey_to_sexp(pk, &err);
4717 if (!private_key) {
4718 ssl_debug_printf("%s: decryption failed: Can't export private key: %s", G_STRFUNC((const char*) (__func__)), err);
4719 g_free(err)(__builtin_object_size ((err), 0) != ((size_t) - 1)) ? g_free_sized
(err, __builtin_object_size ((err), 0)) : (g_free) (err)
;
4720 return false0;
4721 }
4722
4723 pms.size = (int)rsa_decrypt(encrypted_pre_master->data_len, encrypted_pre_master->data, &pms.data, private_key, "pkcs1", &err);
4724 rsa_private_key_free(private_key);
4725 if (pms.size == 0) {
4726 ssl_debug_printf("%s: decryption failed: %s\n", G_STRFUNC((const char*) (__func__)), err);
4727 g_free(err)(__builtin_object_size ((err), 0) != ((size_t) - 1)) ? g_free_sized
(err, __builtin_object_size ((err), 0)) : (g_free) (err)
;
4728 return false0;
4729 }
4730 } else {
4731 // Try to decrypt using a hardware token.
4732 ret = secrets_rsa_decrypt(ssl_session->cert_key_id, epms.data, epms.size, &pms.data, &pms.size);
4733 if (ret < 0) {
4734 ssl_debug_printf("%s: decryption failed: %d (%s)\n", G_STRFUNC((const char*) (__func__)), ret, gnutls_strerror(ret));
4735 return false0;
4736 }
4737 }
4738
4739 if (pms.size != 48) {
4740 ssl_debug_printf("%s wrong pre_master_secret length (%d, expected %d)\n",
4741 G_STRFUNC((const char*) (__func__)), pms.size, 48);
4742 g_free(pms.data)(__builtin_object_size ((pms.data), 0) != ((size_t) - 1)) ? g_free_sized
(pms.data, __builtin_object_size ((pms.data), 0)) : (g_free)
(pms.data)
;
4743 return false0;
4744 }
4745
4746 ssl_session->pre_master_secret.data = (uint8_t *)wmem_memdup(wmem_file_scope(), pms.data, 48);
4747 ssl_session->pre_master_secret.data_len = 48;
4748 g_free(pms.data)(__builtin_object_size ((pms.data), 0) != ((size_t) - 1)) ? g_free_sized
(pms.data, __builtin_object_size ((pms.data), 0)) : (g_free)
(pms.data)
;
4749 ssl_print_string("pre master secret", &ssl_session->pre_master_secret);
4750
4751 /* Remove the master secret if it was there.
4752 This forces keying material regeneration in
4753 case we're renegotiating */
4754 ssl_session->state &= ~(SSL_MASTER_SECRET(1<<5)|SSL_HAVE_SESSION_KEY(1<<3));
4755 ssl_session->state |= SSL_PRE_MASTER_SECRET(1<<6);
4756 return true1;
4757} /* }}} */
4758#endif /* HAVE_LIBGNUTLS */
4759
4760/* Decryption integrity check {{{ */
4761
4762static int
4763tls_check_mac(SslDecoder*decoder, int ct, int ver, uint8_t* data,
4764 uint32_t datalen, uint8_t* mac)
4765{
4766 SSL_HMACgcry_md_hd_t hm;
4767 int md;
4768 uint32_t len;
4769 uint8_t buf[DIGEST_MAX_SIZE48];
4770 int16_t temp;
4771
4772 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
4773 ssl_debug_printf("tls_check_mac mac type:%s md %d\n",
4774 ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
4775
4776 if (ssl_hmac_init(&hm,md) != 0)
4777 return -1;
4778 if (ssl_hmac_setkey(&hm,decoder->mac_key.data,decoder->mac_key.data_len) != 0)
4779 return -1;
4780
4781 /* hash sequence number */
4782 phtonu64(buf, decoder->seq);
4783
4784 decoder->seq++;
4785
4786 ssl_hmac_update(&hm,buf,8);
4787
4788 /* hash content type */
4789 buf[0]=ct;
4790 ssl_hmac_update(&hm,buf,1);
4791
4792 /* hash version,data length and data*/
4793 /* *((int16_t*)buf) = g_htons(ver); */
4794 temp = g_htons(ver)(((((guint16) ( (guint16) ((guint16) (ver) >> 8) | (guint16
) ((guint16) (ver) << 8))))))
;
4795 memcpy(buf, &temp, 2);
4796 ssl_hmac_update(&hm,buf,2);
4797
4798 /* *((int16_t*)buf) = g_htons(datalen); */
4799 temp = g_htons(datalen)(((((guint16) ( (guint16) ((guint16) (datalen) >> 8) | (
guint16) ((guint16) (datalen) << 8))))))
;
4800 memcpy(buf, &temp, 2);
4801 ssl_hmac_update(&hm,buf,2);
4802 ssl_hmac_update(&hm,data,datalen);
4803
4804 /* get digest and digest len*/
4805 len = sizeof(buf);
4806 ssl_hmac_final(&hm,buf,&len);
4807 ssl_hmac_cleanup(&hm);
4808 ssl_print_data("Mac", buf, len);
4809 if(memcmp(mac,buf,len))
4810 return -1;
4811
4812 return 0;
4813}
4814
4815static int
4816ssl3_check_mac(SslDecoder*decoder,int ct,uint8_t* data,
4817 uint32_t datalen, uint8_t* mac)
4818{
4819 SSL_MDgcry_md_hd_t mc;
4820 int md;
4821 uint32_t len;
4822 uint8_t buf[64],dgst[20];
4823 int pad_ct;
4824 int16_t temp;
4825
4826 pad_ct=(decoder->cipher_suite->dig==DIG_SHA0x41)?40:48;
4827
4828 /* get cipher used for digest computation */
4829 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
4830 if (ssl_md_init(&mc,md) !=0)
4831 return -1;
4832
4833 /* do hash computation on data && padding */
4834 ssl_md_update(&mc,decoder->mac_key.data,decoder->mac_key.data_len);
4835
4836 /* hash padding*/
4837 memset(buf,0x36,pad_ct);
4838 ssl_md_update(&mc,buf,pad_ct);
4839
4840 /* hash sequence number */
4841 phtonu64(buf, decoder->seq);
4842 decoder->seq++;
4843 ssl_md_update(&mc,buf,8);
4844
4845 /* hash content type */
4846 buf[0]=ct;
4847 ssl_md_update(&mc,buf,1);
4848
4849 /* hash data length in network byte order and data*/
4850 /* *((int16_t* )buf) = g_htons(datalen); */
4851 temp = g_htons(datalen)(((((guint16) ( (guint16) ((guint16) (datalen) >> 8) | (
guint16) ((guint16) (datalen) << 8))))))
;
4852 memcpy(buf, &temp, 2);
4853 ssl_md_update(&mc,buf,2);
4854 ssl_md_update(&mc,data,datalen);
4855
4856 /* get partial digest */
4857 ssl_md_final(&mc,dgst,&len);
4858 ssl_md_reset(&mc);
4859
4860 /* hash mac key */
4861 ssl_md_update(&mc,decoder->mac_key.data,decoder->mac_key.data_len);
4862
4863 /* hash padding and partial digest*/
4864 memset(buf,0x5c,pad_ct);
4865 ssl_md_update(&mc,buf,pad_ct);
4866 ssl_md_update(&mc,dgst,len);
4867
4868 ssl_md_final(&mc,dgst,&len);
4869 ssl_md_cleanup(&mc);
4870
4871 if(memcmp(mac,dgst,len))
4872 return -1;
4873
4874 return 0;
4875}
4876
4877static int
4878dtls_check_mac(SslDecryptSession *ssl, SslDecoder*decoder, int ct, uint8_t* data,
4879 uint32_t datalen, uint8_t* mac, const unsigned char *cid, uint8_t cidl)
4880{
4881 SSL_HMACgcry_md_hd_t hm;
4882 int md;
4883 uint32_t len;
4884 uint8_t buf[DIGEST_MAX_SIZE48];
4885 int16_t temp;
4886
4887 int ver = ssl->session.version;
4888 bool_Bool is_cid = ((ct == SSL_ID_TLS12_CID) && (ver == DTLSV1DOT2_VERSION0xfefd));
4889
4890 md=ssl_get_digest_by_name(ssl_cipher_suite_dig(decoder->cipher_suite)->name);
4891 ssl_debug_printf("dtls_check_mac mac type:%s md %d\n",
4892 ssl_cipher_suite_dig(decoder->cipher_suite)->name, md);
4893
4894 if (ssl_hmac_init(&hm,md) != 0)
4895 return -1;
4896 if (ssl_hmac_setkey(&hm,decoder->mac_key.data,decoder->mac_key.data_len) != 0)
4897 return -1;
4898
4899 ssl_debug_printf("dtls_check_mac seq: %" PRIu64"l" "u" " epoch: %d\n",decoder->seq,decoder->epoch);
4900
4901 if (is_cid && !ssl->session.deprecated_cid) {
4902 /* hash seq num placeholder */
4903 memset(buf,0xFF,8);
4904 ssl_hmac_update(&hm,buf,8);
4905
4906 /* hash content type + cid length + content type */
4907 buf[0]=ct;
4908 buf[1]=cidl;
4909 buf[2]=ct;
4910 ssl_hmac_update(&hm,buf,3);
4911
4912 /* hash version */
4913 temp = g_htons(ver)(((((guint16) ( (guint16) ((guint16) (ver) >> 8) | (guint16
) ((guint16) (ver) << 8))))))
;
4914 memcpy(buf, &temp, 2);
4915 ssl_hmac_update(&hm,buf,2);
4916
4917 /* hash sequence number */
4918 phtonu64(buf, decoder->seq);
4919 buf[0]=decoder->epoch>>8;
4920 buf[1]=(uint8_t)decoder->epoch;
4921 ssl_hmac_update(&hm,buf,8);
4922
4923 /* hash cid */
4924 ssl_hmac_update(&hm,cid,cidl);
4925 } else {
4926 /* hash sequence number */
4927 phtonu64(buf, decoder->seq);
4928 buf[0]=decoder->epoch>>8;
4929 buf[1]=(uint8_t)decoder->epoch;
4930 ssl_hmac_update(&hm,buf,8);
4931
4932 /* hash content type */
4933 buf[0]=ct;
4934 ssl_hmac_update(&hm,buf,1);
4935
4936 /* hash version */
4937 temp = g_htons(ver)(((((guint16) ( (guint16) ((guint16) (ver) >> 8) | (guint16
) ((guint16) (ver) << 8))))))
;
4938 memcpy(buf, &temp, 2);
4939 ssl_hmac_update(&hm,buf,2);
4940
4941 if (is_cid && ssl->session.deprecated_cid) {
4942 /* hash cid */
4943 ssl_hmac_update(&hm,cid,cidl);
4944
4945 /* hash cid length */
4946 buf[0] = cidl;
4947 ssl_hmac_update(&hm,buf,1);
4948 }
4949 }
4950
4951 /* data length and data */
4952 temp = g_htons(datalen)(((((guint16) ( (guint16) ((guint16) (datalen) >> 8) | (
guint16) ((guint16) (datalen) << 8))))))
;
4953 memcpy(buf, &temp, 2);
4954 ssl_hmac_update(&hm,buf,2);
4955 ssl_hmac_update(&hm,data,datalen);
4956
4957 /* get digest and digest len */
4958 len = sizeof(buf);
4959 ssl_hmac_final(&hm,buf,&len);
4960 ssl_hmac_cleanup(&hm);
4961 ssl_print_data("Mac", buf, len);
4962 if(memcmp(mac,buf,len))
4963 return -1;
4964
4965 return 0;
4966}
4967/* Decryption integrity check }}} */
4968
4969
4970static bool_Bool
4971tls_decrypt_aead_record(wmem_allocator_t* allocator, SslDecryptSession *ssl, SslDecoder *decoder,
4972 uint8_t ct, uint16_t record_version,
4973 bool_Bool ignore_mac_failed,
4974 const unsigned char *in, uint16_t inl,
4975 const unsigned char *cid, uint8_t cidl,
4976 StringInfo *out_str, unsigned *outl)
4977{
4978 /* RFC 5246 (TLS 1.2) 6.2.3.3 defines the TLSCipherText.fragment as:
4979 * GenericAEADCipher: { nonce_explicit, [content] }
4980 * In TLS 1.3 this explicit nonce is gone.
4981 * With AES GCM/CCM, "[content]" is actually the concatenation of the
4982 * ciphertext and authentication tag.
4983 */
4984 const uint16_t version = ssl->session.version;
4985 const bool_Bool is_v12 = version == TLSV1DOT2_VERSION0x303 || version == DTLSV1DOT2_VERSION0xfefd || version == TLCPV1_VERSION0x101;
4986 gcry_error_t err;
4987 const unsigned char *explicit_nonce = NULL((void*)0), *ciphertext;
4988 unsigned ciphertext_len, auth_tag_len;
4989 unsigned char nonce[12];
4990 const ssl_cipher_mode_t cipher_mode = decoder->cipher_suite->mode;
4991 const bool_Bool is_cid = ct == SSL_ID_TLS12_CID && version == DTLSV1DOT2_VERSION0xfefd;
4992 const uint8_t draft_version = ssl->session.tls13_draft_version;
4993 const unsigned char *auth_tag_wire;
4994 unsigned char auth_tag_calc[16];
4995 unsigned char *aad = NULL((void*)0);
4996 unsigned aad_len = 0;
4997
4998 switch (cipher_mode) {
4999 case MODE_GCM:
5000 case MODE_CCM:
5001 case MODE_POLY1305:
5002 auth_tag_len = 16;
5003 break;
5004 case MODE_CCM_8:
5005 auth_tag_len = 8;
5006 break;
5007 default:
5008 ssl_debug_printf("%s unsupported cipher!\n", G_STRFUNC((const char*) (__func__)));
5009 return false0;
5010 }
5011
5012 /* Parse input into explicit nonce (TLS 1.2 only), ciphertext and tag. */
5013 if (is_v12 && cipher_mode != MODE_POLY1305) {
5014 if (inl < EXPLICIT_NONCE_LEN8 + auth_tag_len) {
5015 ssl_debug_printf("%s input %d is too small for explicit nonce %d and auth tag %d\n",
5016 G_STRFUNC((const char*) (__func__)), inl, EXPLICIT_NONCE_LEN8, auth_tag_len);
5017 return false0;
5018 }
5019 explicit_nonce = in;
5020 ciphertext = explicit_nonce + EXPLICIT_NONCE_LEN8;
5021 ciphertext_len = inl - EXPLICIT_NONCE_LEN8 - auth_tag_len;
5022 } else if (version == TLSV1DOT3_VERSION0x304 || version == DTLSV1DOT3_VERSION0xfefc || cipher_mode == MODE_POLY1305) {
5023 if (inl < auth_tag_len) {
5024 ssl_debug_printf("%s input %d has no space for auth tag %d\n", G_STRFUNC((const char*) (__func__)), inl, auth_tag_len);
5025 return false0;
5026 }
5027 ciphertext = in;
5028 ciphertext_len = inl - auth_tag_len;
5029 } else {
5030 ssl_debug_printf("%s Unexpected TLS version %#x\n", G_STRFUNC((const char*) (__func__)), version);
5031 return false0;
5032 }
5033 auth_tag_wire = ciphertext + ciphertext_len;
5034
5035 /*
5036 * Nonce construction is version-specific. Note that AEAD_CHACHA20_POLY1305
5037 * (RFC 7905) uses a nonce construction similar to TLS 1.3.
5038 */
5039 if (is_v12 && cipher_mode != MODE_POLY1305) {
5040 DISSECTOR_ASSERT(decoder->write_iv.data_len == IMPLICIT_NONCE_LEN)((void) ((decoder->write_iv.data_len == 4) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-tls-utils.c"
, 5040, "decoder->write_iv.data_len == 4"))))
;
5041 /* Implicit (4) and explicit (8) part of nonce. */
5042 memcpy(nonce, decoder->write_iv.data, IMPLICIT_NONCE_LEN4);
5043 memcpy(nonce + IMPLICIT_NONCE_LEN4, explicit_nonce, EXPLICIT_NONCE_LEN8);
5044
5045 } else if (version == TLSV1DOT3_VERSION0x304 || version == DTLSV1DOT3_VERSION0xfefc || cipher_mode == MODE_POLY1305) {
5046 /*
5047 * Technically the nonce length must be at least 8 bytes, but for
5048 * AES-GCM, AES-CCM and Poly1305-ChaCha20 the nonce length is exact 12.
5049 */
5050 const unsigned nonce_len = 12;
5051 DISSECTOR_ASSERT(decoder->write_iv.data_len == nonce_len)((void) ((decoder->write_iv.data_len == nonce_len) ? (void
)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/dissectors/packet-tls-utils.c", 5051, "decoder->write_iv.data_len == nonce_len"
))))
;
5052 memcpy(nonce, decoder->write_iv.data, decoder->write_iv.data_len);
5053 /* Sequence number is left-padded with zeroes and XORed with write_iv */
5054 phtonu64(nonce + nonce_len - 8, pntohu64(nonce + nonce_len - 8) ^ decoder->seq);
5055 ssl_debug_printf("%s seq %" PRIu64"l" "u" "\n", G_STRFUNC((const char*) (__func__)), decoder->seq);
5056 }
5057
5058 /* Set nonce and additional authentication data */
5059 gcry_cipher_reset(decoder->evp)gcry_cipher_ctl ((decoder->evp), GCRYCTL_RESET, ((void*)0)
, 0)
;
5060 ssl_print_data("nonce", nonce, 12);
5061 err = gcry_cipher_setiv(decoder->evp, nonce, 12);
5062 if (err) {
5063 ssl_debug_printf("%s failed to set nonce: %s\n", G_STRFUNC((const char*) (__func__)), gcry_strerror(err));
5064 return false0;
5065 }
5066
5067 /* (D)TLS 1.2 needs specific AAD, TLS 1.3 (before -25) uses empty AAD. */
5068 if (is_cid) { /* if connection ID */
5069 if (ssl->session.deprecated_cid) {
5070 aad_len = 14 + cidl;
5071 aad = wmem_alloc(allocator, aad_len);
5072 phtonu64(aad, decoder->seq); /* record sequence number */
5073 phtonu16(aad, decoder->epoch); /* DTLS 1.2 includes epoch. */
5074 aad[8] = ct; /* TLSCompressed.type */
5075 phtonu16(aad + 9, record_version); /* TLSCompressed.version */
5076 memcpy(aad + 11, cid, cidl); /* cid */
5077 aad[11 + cidl] = cidl; /* cid_length */
5078 phtonu16(aad + 12 + cidl, ciphertext_len); /* TLSCompressed.length */
5079 } else {
5080 aad_len = 23 + cidl;
5081 aad = wmem_alloc(allocator, aad_len);
5082 memset(aad, 0xFF, 8); /* seq_num_placeholder */
5083 aad[8] = ct; /* TLSCompressed.type */
5084 aad[9] = cidl; /* cid_length */
5085 aad[10] = ct; /* TLSCompressed.type */
5086 phtonu16(aad + 11, record_version); /* TLSCompressed.version */
5087 phtonu64(aad + 13, decoder->seq); /* record sequence number */
5088 phtonu16(aad + 13, decoder->epoch); /* DTLS 1.2 includes epoch. */
5089 memcpy(aad + 21, cid, cidl); /* cid */
5090 phtonu16(aad + 21 + cidl, ciphertext_len); /* TLSCompressed.length */
5091 }
5092 } else if (is_v12) {
5093 aad_len = 13;
5094 aad = wmem_alloc(allocator, aad_len);
5095 phtonu64(aad, decoder->seq); /* record sequence number */
5096 if (version == DTLSV1DOT2_VERSION0xfefd) {
5097 phtonu16(aad, decoder->epoch); /* DTLS 1.2 includes epoch. */
5098 }
5099 aad[8] = ct; /* TLSCompressed.type */
5100 phtonu16(aad + 9, record_version); /* TLSCompressed.version */
5101 phtonu16(aad + 11, ciphertext_len); /* TLSCompressed.length */
5102 } else if (version == DTLSV1DOT3_VERSION0xfefc) {
5103 aad_len = decoder->dtls13_aad.data_len;
5104 aad = decoder->dtls13_aad.data;
5105 } else if (draft_version >= 25 || draft_version == 0) {
5106 aad_len = 5;
5107 aad = wmem_alloc(allocator, aad_len);
5108 aad[0] = ct; /* TLSCiphertext.opaque_type (23) */
5109 phtonu16(aad + 1, record_version); /* TLSCiphertext.legacy_record_version (0x0303) */
5110 phtonu16(aad + 3, inl); /* TLSCiphertext.length */
5111 }
5112
5113 if (decoder->cipher_suite->mode == MODE_CCM || decoder->cipher_suite->mode == MODE_CCM_8) {
5114 /* size of plaintext, additional authenticated data and auth tag. */
5115 uint64_t lengths[3] = { ciphertext_len, aad_len, auth_tag_len };
5116
5117 gcry_cipher_ctl(decoder->evp, GCRYCTL_SET_CCM_LENGTHS, lengths, sizeof(lengths));
5118 }
5119
5120 if (aad && aad_len > 0) {
5121 ssl_print_data("AAD", aad, aad_len);
5122 err = gcry_cipher_authenticate(decoder->evp, aad, aad_len);
5123 if (err) {
5124 ssl_debug_printf("%s failed to set AAD: %s\n", G_STRFUNC((const char*) (__func__)), gcry_strerror(err));
5125 return false0;
5126 }
5127 }
5128
5129 /* Decrypt now that nonce and AAD are set. */
5130 err = gcry_cipher_decrypt(decoder->evp, out_str->data, out_str->data_len, ciphertext, ciphertext_len);
5131 if (err) {
5132 ssl_debug_printf("%s decrypt failed: %s\n", G_STRFUNC((const char*) (__func__)), gcry_strerror(err));
5133 return false0;
5134 }
5135
5136 /* Check authentication tag for authenticity (replaces MAC) */
5137 err = gcry_cipher_gettag(decoder->evp, auth_tag_calc, auth_tag_len);
5138 if (err == 0 && !memcmp(auth_tag_calc, auth_tag_wire, auth_tag_len)) {
5139 ssl_print_data("auth_tag(OK)", auth_tag_calc, auth_tag_len);
5140 } else {
5141 if (err) {
5142 ssl_debug_printf("%s cannot obtain tag: %s\n", G_STRFUNC((const char*) (__func__)), gcry_strerror(err));
5143 } else {
5144 ssl_debug_printf("%s auth tag mismatch\n", G_STRFUNC((const char*) (__func__)));
5145 ssl_print_data("auth_tag(expect)", auth_tag_calc, auth_tag_len);
5146 ssl_print_data("auth_tag(actual)", auth_tag_wire, auth_tag_len);
5147 }
5148 if (ignore_mac_failed) {
5149 ssl_debug_printf("%s: auth check failed, but ignored for troubleshooting ;-)\n", G_STRFUNC((const char*) (__func__)));
5150 } else {
5151 return false0;
5152 }
5153 }
5154
5155 /*
5156 * Increment the (implicit) sequence number for TLS 1.2/1.3 and TLCP 1.1. This is done
5157 * after successful authentication to ensure that early data is skipped when
5158 * CLIENT_EARLY_TRAFFIC_SECRET keys are unavailable.
5159 */
5160 if (version == TLSV1DOT2_VERSION0x303 || version == TLSV1DOT3_VERSION0x304 || version == TLCPV1_VERSION0x101) {
5161 decoder->seq++;
5162 }
5163
5164 ssl_print_data("Plaintext", out_str->data, ciphertext_len);
5165 *outl = ciphertext_len;
5166 return true1;
5167}
5168
5169/* Record decryption glue based on security parameters {{{ */
5170/* Assume that we are called only for a non-NULL decoder which also means that
5171 * we have a non-NULL decoder->cipher_suite. */
5172int
5173ssl_decrypt_record(wmem_allocator_t* allocator, SslDecryptSession *ssl, SslDecoder *decoder, uint8_t ct, uint16_t record_version,
5174 bool_Bool ignore_mac_failed,
5175 const unsigned char *in, uint16_t inl, const unsigned char *cid, uint8_t cidl,
5176 StringInfo *comp_str, StringInfo *out_str, unsigned *outl)
5177{
5178 unsigned pad, worklen, uncomplen, maclen, mac_fraglen = 0;
5179 uint8_t *mac = NULL((void*)0), *mac_frag = NULL((void*)0);
5180
5181 ssl_debug_printf("ssl_decrypt_record ciphertext len %d\n", inl);
5182 ssl_print_data("Ciphertext",in, inl);
5183
5184 if (((ssl->session.version == TLSV1DOT3_VERSION0x304 || ssl->session.version == DTLSV1DOT3_VERSION0xfefc))
5185 != (decoder->cipher_suite->kex == KEX_TLS130x23)) {
5186 ssl_debug_printf("%s Invalid cipher suite for the protocol version!\n", G_STRFUNC((const char*) (__func__)));
5187 return -1;
5188 }
5189
5190 /* ensure we have enough storage space for decrypted data */
5191 if (inl > out_str->data_len)
5192 {
5193 ssl_debug_printf("ssl_decrypt_record: allocating %d bytes for decrypt data (old len %d)\n",
5194 inl + 32, out_str->data_len);
5195 ssl_data_realloc(out_str, inl + 32);
5196 }
5197
5198 /* AEAD ciphers (GenericAEADCipher in TLS 1.2; TLS 1.3) have no padding nor
5199 * a separate MAC, so use a different routine for simplicity. */
5200 if (decoder->cipher_suite->mode == MODE_GCM ||
5201 decoder->cipher_suite->mode == MODE_CCM ||
5202 decoder->cipher_suite->mode == MODE_CCM_8 ||
5203 decoder->cipher_suite->mode == MODE_POLY1305 ||
5204 ssl->session.version == TLSV1DOT3_VERSION0x304 ||
5205 ssl->session.version == DTLSV1DOT3_VERSION0xfefc) {
5206
5207 if (!tls_decrypt_aead_record(allocator, ssl, decoder, ct, record_version, ignore_mac_failed, in, inl, cid, cidl, out_str, &worklen)) {
5208 /* decryption failed */
5209 return -1;
5210 }
5211
5212 goto skip_mac;
5213 }
5214
5215 /* RFC 6101/2246: SSLCipherText/TLSCipherText has two structures for types:
5216 * (notation: { unencrypted, [ encrypted ] })
5217 * GenericStreamCipher: { [content, mac] }
5218 * GenericBlockCipher: { IV (TLS 1.1+), [content, mac, padding, padding_len] }
5219 * RFC 5426 (TLS 1.2): TLSCipherText has additionally:
5220 * GenericAEADCipher: { nonce_explicit, [content] }
5221 * RFC 4347 (DTLS): based on TLS 1.1, only GenericBlockCipher is supported.
5222 * RFC 6347 (DTLS 1.2): based on TLS 1.2, includes GenericAEADCipher too.
5223 */
5224
5225 maclen = ssl_cipher_suite_dig(decoder->cipher_suite)->len;
5226
5227 /* (TLS 1.1 and later, DTLS) Extract explicit IV for GenericBlockCipher */
5228 if (decoder->cipher_suite->mode == MODE_CBC) {
5229 unsigned blocksize = 0;
5230
5231 switch (ssl->session.version) {
5232 case TLSV1DOT1_VERSION0x302:
5233 case TLSV1DOT2_VERSION0x303:
5234 case DTLSV1DOT0_VERSION0xfeff:
5235 case DTLSV1DOT2_VERSION0xfefd:
5236 case DTLSV1DOT3_VERSION0xfefc:
5237 case DTLSV1DOT0_OPENSSL_VERSION0x100:
5238 case TLCPV1_VERSION0x101:
5239 blocksize = ssl_get_cipher_blocksize(decoder->cipher_suite);
5240 if (inl < blocksize) {
5241 ssl_debug_printf("ssl_decrypt_record failed: input %d has no space for IV %d\n",
5242 inl, blocksize);
5243 return -1;
5244 }
5245 pad = gcry_cipher_setiv(decoder->evp, in, blocksize);
5246 if (pad != 0) {
5247 ssl_debug_printf("ssl_decrypt_record failed: failed to set IV: %s %s\n",
5248 gcry_strsource (pad), gcry_strerror (pad));
5249 }
5250
5251 inl -= blocksize;
5252 in += blocksize;
5253 break;
5254 }
5255
5256 /* Encrypt-then-MAC for (D)TLS (RFC 7366) */
5257 if (ssl->state & SSL_ENCRYPT_THEN_MAC(1<<11)) {
5258 /*
5259 * MAC is calculated over (IV + ) ENCRYPTED contents:
5260 *
5261 * MAC(MAC_write_key, ... +
5262 * IV + // for TLS 1.1 or greater
5263 * TLSCiphertext.enc_content);
5264 */
5265 if (inl < maclen) {
5266 ssl_debug_printf("%s failed: input %d has no space for MAC %d\n",
5267 G_STRFUNC((const char*) (__func__)), inl, maclen);
5268 return -1;
5269 }
5270 inl -= maclen;
5271 mac = (uint8_t *)in + inl;
5272 mac_frag = (uint8_t *)in - blocksize;
5273 mac_fraglen = blocksize + inl;
5274 }
5275 }
5276
5277 /* First decrypt*/
5278 if ((pad = ssl_cipher_decrypt(&decoder->evp, out_str->data, out_str->data_len, in, inl)) != 0) {
5279 ssl_debug_printf("ssl_decrypt_record failed: ssl_cipher_decrypt: %s %s\n", gcry_strsource (pad),
5280 gcry_strerror (pad));
5281 return -1;
5282 }
5283
5284 ssl_print_data("Plaintext", out_str->data, inl);
5285 worklen=inl;
5286
5287
5288 /* strip padding for GenericBlockCipher */
5289 if (decoder->cipher_suite->mode == MODE_CBC) {
5290 if (inl < 1) { /* Should this check happen earlier? */
5291 ssl_debug_printf("ssl_decrypt_record failed: input length %d too small\n", inl);
5292 return -1;
5293 }
5294 pad=out_str->data[inl-1];
5295 if (worklen <= pad) {
5296 ssl_debug_printf("ssl_decrypt_record failed: padding %d too large for work %d\n",
5297 pad, worklen);
5298 return -1;
5299 }
5300 worklen-=(pad+1);
5301 ssl_debug_printf("ssl_decrypt_record found padding %d final len %d\n",
5302 pad, worklen);
5303 }
5304
5305 /* MAC for GenericStreamCipher and GenericBlockCipher.
5306 * (normal case without Encrypt-then-MAC (RFC 7366) extension. */
5307 if (!mac) {
5308 /*
5309 * MAC is calculated over the DECRYPTED contents:
5310 *
5311 * MAC(MAC_write_key, ... + TLSCompressed.fragment);
5312 */
5313 if (worklen < maclen) {
5314 ssl_debug_printf("%s wrong record len/padding outlen %d\n work %d\n", G_STRFUNC((const char*) (__func__)), *outl, worklen);
5315 return -1;
5316 }
5317 worklen -= maclen;
5318 mac = out_str->data + worklen;
5319 mac_frag = out_str->data;
5320 mac_fraglen = worklen;
5321 }
5322
5323 /* If NULL encryption active and no keys are available, do not bother
5324 * checking the MAC. We do not have keys for that. */
5325 if (decoder->cipher_suite->mode == MODE_STREAM &&
5326 decoder->cipher_suite->enc == ENC_NULL0x3D &&
5327 !(ssl->state & SSL_MASTER_SECRET(1<<5))) {
5328 ssl_debug_printf("MAC check skipped due to missing keys\n");
5329 decoder->seq++; // Increment this for display
5330 goto skip_mac;
5331 }
5332
5333 /* Now check the MAC */
5334 ssl_debug_printf("checking mac (len %d, version %X, ct %d seq %" PRIu64"l" "u" ")\n",
5335 worklen, ssl->session.version, ct, decoder->seq);
5336 if(ssl->session.version==SSLV3_VERSION0x300){
5337 if(ssl3_check_mac(decoder,ct,mac_frag,mac_fraglen,mac) < 0) {
5338 if(ignore_mac_failed) {
5339 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
5340 }
5341 else{
5342 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
5343 return -1;
5344 }
5345 }
5346 else{
5347 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
5348 }
5349 }
5350 else if(ssl->session.version==TLSV1_VERSION0x301 || ssl->session.version==TLSV1DOT1_VERSION0x302 || ssl->session.version==TLSV1DOT2_VERSION0x303 || ssl->session.version==TLCPV1_VERSION0x101){
5351 if(tls_check_mac(decoder,ct,ssl->session.version,mac_frag,mac_fraglen,mac)< 0) {
5352 if(ignore_mac_failed) {
5353 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
5354 }
5355 else{
5356 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
5357 return -1;
5358 }
5359 }
5360 else{
5361 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
5362 }
5363 }
5364 else if(ssl->session.version==DTLSV1DOT0_VERSION0xfeff ||
5365 ssl->session.version==DTLSV1DOT2_VERSION0xfefd ||
5366 ssl->session.version==DTLSV1DOT0_OPENSSL_VERSION0x100){
5367 /* Try rfc-compliant mac first, and if failed, try old openssl's non-rfc-compliant mac */
5368 if(dtls_check_mac(ssl,decoder,ct,mac_frag,mac_fraglen,mac,cid,cidl)>= 0) {
5369 ssl_debug_printf("ssl_decrypt_record: mac ok\n");
5370 }
5371 else if(tls_check_mac(decoder,ct,TLSV1_VERSION0x301,mac_frag,mac_fraglen,mac)>= 0) {
5372 ssl_debug_printf("ssl_decrypt_record: dtls rfc-compliant mac failed, but old openssl's non-rfc-compliant mac ok\n");
5373 }
5374 else if(ignore_mac_failed) {
5375 ssl_debug_printf("ssl_decrypt_record: mac failed, but ignored for troubleshooting ;-)\n");
5376 }
5377 else{
5378 ssl_debug_printf("ssl_decrypt_record: mac failed\n");
5379 return -1;
5380 }
5381 }
5382skip_mac:
5383
5384 *outl = worklen;
5385
5386 if (decoder->compression > 0) {
5387 ssl_debug_printf("ssl_decrypt_record: compression method %d\n", decoder->compression);
5388 ssl_data_copy(comp_str, out_str);
5389 ssl_print_data("Plaintext compressed", comp_str->data, worklen);
5390 if (!decoder->decomp) {
5391 ssl_debug_printf("decrypt_ssl3_record: no decoder available\n");
5392 return -1;
5393 }
5394 if (ssl_decompress_record(decoder->decomp, comp_str->data, worklen, out_str, &uncomplen) < 0) return -1;
5395 ssl_print_data("Plaintext uncompressed", out_str->data, uncomplen);
5396 *outl = uncomplen;
5397 }
5398
5399 return 0;
5400}
5401/* Record decryption glue based on security parameters }}} */
5402
5403
5404
5405#ifdef HAVE_LIBGNUTLS1
5406
5407/* RSA private key file processing {{{ */
5408static void
5409ssl_find_private_key_by_pubkey(SslDecryptSession *ssl,
5410 const gnutls_datum_t *subjectPublicKeyInfo)
5411{
5412 gnutls_pubkey_t pubkey = NULL((void*)0);
5413 cert_key_id_t key_id;
5414 size_t key_id_len = sizeof(key_id);
5415 int r;
5416
5417 if (!subjectPublicKeyInfo->size) {
5418 ssl_debug_printf("%s: could not find SubjectPublicKeyInfo\n", G_STRFUNC((const char*) (__func__)));
5419 return;
5420 }
5421
5422 r = gnutls_pubkey_init(&pubkey);
5423 if (r < 0) {
5424 ssl_debug_printf("%s: failed to init pubkey: %s\n",
5425 G_STRFUNC((const char*) (__func__)), gnutls_strerror(r));
5426 return;
5427 }
5428
5429 r = gnutls_pubkey_import(pubkey, subjectPublicKeyInfo, GNUTLS_X509_FMT_DER);
5430 if (r < 0) {
5431 ssl_debug_printf("%s: failed to import pubkey from handshake: %s\n",
5432 G_STRFUNC((const char*) (__func__)), gnutls_strerror(r));
5433 goto end;
5434 }
5435
5436 if (gnutls_pubkey_get_pk_algorithm(pubkey, NULL((void*)0)) != GNUTLS_PK_RSA) {
5437 ssl_debug_printf("%s: Not a RSA public key - ignoring.\n", G_STRFUNC((const char*) (__func__)));
5438 goto end;
5439 }
5440
5441 /* Generate a 20-byte SHA-1 hash. */
5442 r = gnutls_pubkey_get_key_id(pubkey, 0, key_id.key_id, &key_id_len);
5443 if (r < 0) {
5444 ssl_debug_printf("%s: failed to extract key id from pubkey: %s\n",
5445 G_STRFUNC((const char*) (__func__)), gnutls_strerror(r));
5446 goto end;
5447 }
5448
5449 if (key_id_len != sizeof(key_id)) {
5450 ssl_debug_printf("%s: expected Key ID size %zu, got %zu\n",
5451 G_STRFUNC((const char*) (__func__)), sizeof(key_id), key_id_len);
5452 goto end;
5453 }
5454
5455 ssl_print_data("Certificate.KeyID", key_id.key_id, key_id_len);
5456 ssl->cert_key_id = wmem_new(wmem_file_scope(), cert_key_id_t)((cert_key_id_t*)wmem_alloc((wmem_file_scope()), sizeof(cert_key_id_t
)))
;
5457 *ssl->cert_key_id = key_id;
5458
5459end:
5460 gnutls_pubkey_deinit(pubkey);
5461}
5462
5463/* RSA private key file processing }}} */
5464#endif /* HAVE_LIBGNUTLS */
5465
5466/*--- Start of dissector-related code below ---*/
5467
5468/* This is not a "protocol" but ensures that this gets called during
5469 * the handoff stage. */
5470void proto_reg_handoff_tls_utils(void);
5471
5472static dissector_handle_t base_tls_handle;
5473static dissector_handle_t dtls_handle;
5474
5475void
5476proto_reg_handoff_tls_utils(void)
5477{
5478 base_tls_handle = find_dissector("tls");
5479 dtls_handle = find_dissector("dtls");
5480}
5481
5482/* Look up an existing SslDecryptSession without creating one. Returns NULL if
5483 * no session exists. */
5484SslDecryptSession *
5485tls_get_session(conversation_t *conversation, int proto_ssl, uint8_t curr_layer_num)
5486{
5487 void *conv_data;
5488 wmem_map_t *session_map;
5489
5490 if (!conversation)
5491 return NULL((void*)0);
5492
5493 conv_data = conversation_get_proto_data(conversation, proto_ssl);
5494 if (conv_data == NULL((void*)0))
5495 return NULL((void*)0);
5496
5497 session_map = (wmem_map_t *)conv_data;
5498
5499 return (SslDecryptSession *)wmem_map_lookup(session_map,
5500 GUINT_TO_POINTER((unsigned)curr_layer_num)((gpointer) (gulong) ((unsigned)curr_layer_num)));
5501
5502}
5503
5504static bool_Bool
5505ssl_session_destroy_cb(wmem_allocator_t *allocator _U___attribute__((unused)), wmem_cb_event_t event _U___attribute__((unused)), void *user_data)
5506{
5507 SslDecryptSession *ssl_session = (SslDecryptSession *) user_data;
5508
5509 tls_transcript_close(&ssl_session->handshake_transcript);
5510 tls_transcript_close(&ssl_session->ech_transcript);
5511
5512 return false0;
5513}
5514
5515/* get ssl data for this session. if no ssl data is found allocate a new one*/
5516SslDecryptSession *
5517ssl_get_session(conversation_t *conversation, dissector_handle_t tls_handle, uint8_t curr_layer_num)
5518{
5519 void *conv_data;
5520 SslDecryptSession *ssl_session;
5521 int proto_ssl;
5522 wmem_map_t *session_map;
5523
5524 /* Note proto_ssl is tls for either the main tls_handle or the
5525 * tls13_handshake handle used by QUIC. */
5526 proto_ssl = dissector_handle_get_protocol_index(tls_handle);
5527 conv_data = conversation_get_proto_data(conversation, proto_ssl);
5528
5529 /* For nested TLS support, we store a wmem map of sessions indexed by layer number.
5530 * Using wmem_file_scope ensures the map is freed when the capture file is closed,
5531 * preventing memory leaks on capture reload. */
5532 if (conv_data != NULL((void*)0)) {
5533 session_map = (wmem_map_t *)conv_data;
5534 ssl_session = (SslDecryptSession *)wmem_map_lookup(session_map, GUINT_TO_POINTER((unsigned)curr_layer_num)((gpointer) (gulong) ((unsigned)curr_layer_num)));
5535 if (ssl_session != NULL((void*)0)) {
5536 return ssl_session;
5537 }
5538 } else {
5539 /* Create a new wmem map to store sessions by layer number */
5540 session_map = wmem_map_new(wmem_file_scope(), g_direct_hash, g_direct_equal);
5541 conversation_add_proto_data(conversation, proto_ssl, session_map);
5542 }
5543
5544 /* no previous SSL conversation info for this layer, initialize it. */
5545 ssl_session = wmem_new0(wmem_file_scope(), SslDecryptSession)((SslDecryptSession*)wmem_alloc0((wmem_file_scope()), sizeof(
SslDecryptSession)))
;
5546
5547 /* data_len is the part that is meaningful, not the allocated length */
5548 ssl_session->master_secret.data_len = 0;
5549 ssl_session->master_secret.data = ssl_session->_master_secret;
5550 ssl_session->session_id.data_len = 0;
5551 ssl_session->session_id.data = ssl_session->_session_id;
5552 ssl_session->client_random.data_len = 0;
5553 ssl_session->client_random.data = ssl_session->_client_random;
5554 ssl_session->server_random.data_len = 0;
5555 ssl_session->server_random.data = ssl_session->_server_random;
5556 ssl_session->session_ticket.data_len = 0;
5557 ssl_session->session_ticket.data = NULL((void*)0); /* will be re-alloced as needed */
5558 ssl_session->server_data_for_iv.data_len = 0;
5559 ssl_session->server_data_for_iv.data = ssl_session->_server_data_for_iv;
5560 ssl_session->client_data_for_iv.data_len = 0;
5561 ssl_session->client_data_for_iv.data = ssl_session->_client_data_for_iv;
5562 ssl_session->app_data_segment.data = NULL((void*)0);
5563 ssl_session->app_data_segment.data_len = 0;
5564 /* The transcripts were zeroed by wmem_new0. */
5565 wmem_register_callback(wmem_file_scope(), ssl_session_destroy_cb, ssl_session);
5566
5567 /* Initialize parameters which are not necessary specific to decryption. */
5568 ssl_session->session.version = SSL_VER_UNKNOWN0;
5569 clear_address(&ssl_session->session.srv_addr);
5570 ssl_session->session.srv_ptype = PT_NONE;
5571 ssl_session->session.srv_port = 0;
5572 ssl_session->session.dtls13_current_epoch[0] = ssl_session->session.dtls13_current_epoch[1] = 0;
5573 ssl_session->session.dtls13_next_seq_num[0] = ssl_session->session.dtls13_next_seq_num[1] = 0;
5574 ssl_session->session.client_random.data_len = 0;
5575 ssl_session->session.client_random.data = ssl_session->session._client_random;
5576 memset(ssl_session->session.ech_confirmation, 0, sizeof(ssl_session->session.ech_confirmation));
5577 memset(ssl_session->session.hrr_ech_confirmation, 0, sizeof(ssl_session->session.hrr_ech_confirmation));
5578 memset(ssl_session->session.first_ech_auth_tag, 0, sizeof(ssl_session->session.first_ech_auth_tag));
5579 ssl_session->session.ech = false0;
5580 ssl_session->session.hrr_ech_declined = false0;
5581 ssl_session->session.first_ch_ech_frame = 0;
5582
5583 /* We want to increment the stream count for the normal tls handle and
5584 * dtls handle, but presumably not for the tls13_handshake handle used
5585 * by QUIC (it has its own Follow Stream handling, and the QUIC stream
5586 * doesn't get sent to the TLS follow tap.)
5587 */
5588 if (tls_handle == base_tls_handle) {
5589 ssl_session->session.stream = tls_increment_stream_count();
5590 } else if (tls_handle == dtls_handle) {
5591 ssl_session->session.stream = dtls_increment_stream_count();
5592 }
5593
5594 /* Store the session in the wmem map indexed by layer number */
5595 wmem_map_insert(session_map, GUINT_TO_POINTER((unsigned)curr_layer_num)((gpointer) (gulong) ((unsigned)curr_layer_num)), ssl_session);
5596
5597 return ssl_session;
5598}
5599
5600void
5601tls_check_client_hello_random(SslDecryptSession *ssl, tvbuff_t *tvb, uint32_t offset)
5602{
5603 /* RFC 8446 4.1.2: After a HelloRetryRequest, the client sends the same
5604 * ClientHello with only certain changes, which don't include the random.
5605 * A different random means this is a new handshake, e.g. a new connection
5606 * reusing the addresses and ports with the TCP handshake missing. */
5607 if (!ssl || !tvb_bytes_exist(tvb, offset + 2, 32))
5608 return;
5609
5610 if ((ssl->state & SSL_HELLO_RETRY_REQUEST(1<<14)) &&
5611 tvb_memeql(tvb, offset + 2, ssl->last_client_hello_random, 32) != 0) {
5612 ssl_debug_printf("%s ClientHello after a HelloRetryRequest has a new random, assuming a new handshake\n", G_STRFUNC((const char*) (__func__)));
5613 ssl->state &= ~SSL_HELLO_RETRY_REQUEST(1<<14);
5614 }
5615 tvb_memcpy(tvb, ssl->last_client_hello_random, offset + 2, 32);
5616}
5617
5618void ssl_reset_session(SslSession *session, SslDecryptSession *ssl, bool_Bool is_client)
5619{
5620 /* TLS 1.3 forbids renegotiation (and the version cannot change upon
5621 * renegotiation, in particular TLS 1.3 MUST NOT be [re]negotiated if a
5622 * prior version was negotiated.) However, we can get here in valid TLS
5623 * 1.3 for ClientHello or ServerHello following a HelloRetryRequest.
5624 */
5625 if (ssl) {
5626 /* Ensure that secrets are not restored using stale identifiers. Split
5627 * between client and server in case the packets somehow got out of order. */
5628 int clear_flags = SSL_HAVE_SESSION_KEY(1<<3) | SSL_MASTER_SECRET(1<<5) | SSL_PRE_MASTER_SECRET(1<<6);
5629
5630 if (is_client) {
5631 clear_flags |= SSL_CLIENT_EXTENDED_MASTER_SECRET(1<<7);
5632 ssl->session_id.data_len = 0;
5633 ssl->session_ticket.data_len = 0;
5634 ssl->master_secret.data_len = 0;
5635 ssl->client_random.data_len = 0;
5636 ssl->has_early_data = false0;
5637 if (!(ssl->state & SSL_HELLO_RETRY_REQUEST(1<<14))) {
5638 // The transcript starts with the Client Hello, ensure that
5639 // any messages before it are forgotten. After a Hello Retry
5640 // Request, the transcript continues with ClientHello2 (see
5641 // tls_check_client_hello_random.)
5642 tls_transcript_reset(&ssl->handshake_transcript);
5643 tls_transcript_reset(&ssl->ech_transcript);
5644 }
5645 } else {
5646 clear_flags |= SSL_SERVER_EXTENDED_MASTER_SECRET(1<<8) | SSL_NEW_SESSION_TICKET(1<<10);
5647 ssl->server_random.data_len = 0;
5648 ssl->pre_master_secret.data_len = 0;
5649#ifdef HAVE_LIBGNUTLS1
5650 ssl->cert_key_id = NULL((void*)0);
5651#endif
5652 ssl->has_psk = false0;
5653 ssl->has_key_share = false0;
5654 // There is no point in clearing the PSK when resetting the session,
5655 // we only store one global PSK in the prefs.
5656 //ssl->psk.data_len = 0;
5657 }
5658
5659 if (ssl->state & clear_flags) {
5660 ssl_debug_printf("%s detected renegotiation, clearing 0x%02x (%s side)\n",
5661 G_STRFUNC((const char*) (__func__)), ssl->state & clear_flags, is_client ? "client" : "server");
5662 ssl->state &= ~clear_flags;
5663 }
5664 }
5665
5666 /* These flags might be used for non-decryption purposes and may affect the
5667 * dissection, so reset them as well. */
5668 if (is_client) {
5669 session->client_cert_type = 0;
5670 } else {
5671 session->compression = 0;
5672 session->server_cert_type = 0;
5673 /* session->is_session_resumed is already handled in the ServerHello dissection. */
5674 }
5675 session->dtls13_next_seq_num[0] = session->dtls13_next_seq_num[1] = 0;
5676 session->dtls13_current_epoch[0] = session->dtls13_current_epoch[1] = 0;
5677}
5678
5679void
5680tls_set_appdata_dissector(dissector_handle_t tls_handle, packet_info *pinfo,
5681 dissector_handle_t app_handle)
5682{
5683 conversation_t *conversation;
5684 SslSession *session;
5685
5686 /* Ignore if the TLS or other dissector is disabled. */
5687 /* XXX - find_dissector still works if a dissector is disabled,
5688 * this would be if the dissector isn't registered at all or the
5689 * caller is calling this with explicit NULL. */
5690 if (!tls_handle || !app_handle)
5691 return;
5692
5693 int proto = dissector_handle_get_protocol_index(tls_handle);
5694 uint8_t curr_layer_num = p_get_proto_depth(pinfo, proto);
5695
5696 conversation = find_or_create_conversation(pinfo);
5697 session = &ssl_get_session(conversation, tls_handle, curr_layer_num)->session;
5698 session->app_handle = app_handle;
5699}
5700
5701static uint32_t
5702ssl_starttls(dissector_handle_t tls_handle, packet_info *pinfo,
5703 dissector_handle_t app_handle, uint32_t last_nontls_frame)
5704{
5705
5706 conversation_t *conversation;
5707 SslSession *session;
5708
5709 /* Ignore if the TLS dissector is disabled. */
5710 /* XXX - find_dissector still works if a dissector is disabled,
5711 * this would be if the dissector isn't registered at all (or the
5712 * caller has an error.) */
5713 if (!tls_handle)
5714 return 0;
5715
5716 int proto = dissector_handle_get_protocol_index(tls_handle);
5717 uint8_t curr_layer_num = p_get_proto_depth(pinfo, proto);
5718
5719 /* The caller should always pass a valid handle to its own dissector. */
5720 DISSECTOR_ASSERT(app_handle)((void) ((app_handle) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-tls-utils.c"
, 5720, "app_handle"))))
;
5721
5722 conversation = find_or_create_conversation(pinfo);
5723 session = &ssl_get_session(conversation, tls_handle, curr_layer_num)->session;
5724
5725 ssl_debug_printf("%s: old frame %d, app_handle=%p (%s)\n", G_STRFUNC((const char*) (__func__)),
5726 session->last_nontls_frame,
5727 (void *)session->app_handle,
5728 dissector_handle_get_dissector_name(session->app_handle));
5729 ssl_debug_printf("%s: current frame %d, app_handle=%p (%s)\n", G_STRFUNC((const char*) (__func__)),
5730 pinfo->num, (void *)app_handle,
5731 dissector_handle_get_dissector_name(app_handle));
5732
5733 /* Do not switch again if a dissector did it before. */
5734 if (session->last_nontls_frame) {
5735 ssl_debug_printf("%s: not overriding previous app handle!\n", G_STRFUNC((const char*) (__func__)));
5736 return session->last_nontls_frame;
5737 }
5738
5739 session->app_handle = app_handle;
5740 /* The TLS dissector should be called first for this conversation. */
5741 conversation_set_dissector(conversation, tls_handle);
5742 /* TLS starts after this frame. */
5743 session->last_nontls_frame = last_nontls_frame;
5744 return 0;
5745}
5746
5747/* ssl_starttls_ack: mark future frames as encrypted. */
5748uint32_t
5749ssl_starttls_ack(dissector_handle_t tls_handle, packet_info *pinfo,
5750 dissector_handle_t app_handle)
5751{
5752 return ssl_starttls(tls_handle, pinfo, app_handle, pinfo->num);
5753}
5754
5755uint32_t
5756ssl_starttls_post_ack(dissector_handle_t tls_handle, packet_info *pinfo,
5757 dissector_handle_t app_handle)
5758{
5759 return ssl_starttls(tls_handle, pinfo, app_handle, pinfo->num - 1);
5760}
5761
5762dissector_handle_t
5763ssl_find_appdata_dissector(const char *name)
5764{
5765 /* Accept 'http' for backwards compatibility and sanity. */
5766 if (!strcmp(name, "http"))
5767 name = "http-over-tls";
5768 /* XXX - Should this check to see if the dissector is actually added for
5769 * Decode As in the appropriate table?
5770 */
5771 return find_dissector(name);
5772}
5773
5774/* Functions for TLS/DTLS sessions and RSA private keys hashtables. {{{ */
5775static int
5776ssl_equal (const void *v, const void *v2)
5777{
5778 const StringInfo *val1;
5779 const StringInfo *val2;
5780 val1 = (const StringInfo *)v;
5781 val2 = (const StringInfo *)v2;
5782
5783 if (val1->data_len == val2->data_len &&
5784 !memcmp(val1->data, val2->data, val2->data_len)) {
5785 return 1;
5786 }
5787 return 0;
5788}
5789
5790static unsigned
5791ssl_hash(const void *v)
5792{
5793 const StringInfo* id;
5794 id = (const StringInfo*) v;
5795
5796 return wmem_strong_hash(id->data, id->data_len);
5797}
5798/* Functions for TLS/DTLS sessions and RSA private keys hashtables. }}} */
5799
5800/* Handling of association between tls/dtls ports and clear text protocol. {{{ */
5801void
5802ssl_association_add(const char* dissector_table_name, dissector_handle_t main_handle, dissector_handle_t subdissector_handle, unsigned port, bool_Bool tcp)
5803{
5804 DISSECTOR_ASSERT(main_handle)((void) ((main_handle) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-tls-utils.c"
, 5804, "main_handle"))))
;
5805 DISSECTOR_ASSERT(subdissector_handle)((void) ((subdissector_handle) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-tls-utils.c"
, 5805, "subdissector_handle"))))
;
5806 /* Registration is required for Export PDU feature to work properly. */
5807 DISSECTOR_ASSERT_HINT(dissector_handle_get_dissector_name(subdissector_handle),((void) ((dissector_handle_get_dissector_name(subdissector_handle
)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/dissectors/packet-tls-utils.c", 5808, "dissector_handle_get_dissector_name(subdissector_handle)"
, "SSL appdata dissectors must register with register_dissector()!"
))))
5808 "SSL appdata dissectors must register with register_dissector()!")((void) ((dissector_handle_get_dissector_name(subdissector_handle
)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\" (%s)"
, "epan/dissectors/packet-tls-utils.c", 5808, "dissector_handle_get_dissector_name(subdissector_handle)"
, "SSL appdata dissectors must register with register_dissector()!"
))))
;
5809 ssl_debug_printf("association_add %s port %d handle %p\n", dissector_table_name, port, (void *)subdissector_handle);
5810
5811 if (port) {
5812 dissector_add_uint(dissector_table_name, port, subdissector_handle);
5813 if (tcp)
5814 dissector_add_uint("tcp.port", port, main_handle);
5815 else
5816 dissector_add_uint("udp.port", port, main_handle);
5817 dissector_add_uint("sctp.port", port, main_handle);
5818 } else {
5819 dissector_add_for_decode_as(dissector_table_name, subdissector_handle);
5820 }
5821}
5822
5823void
5824ssl_association_remove(const char* dissector_table_name, dissector_handle_t main_handle, dissector_handle_t subdissector_handle, unsigned port, bool_Bool tcp)
5825{
5826 ssl_debug_printf("ssl_association_remove removing %s %u - handle %p\n",
5827 tcp?"TCP":"UDP", port, (void *)subdissector_handle);
5828 if (main_handle) {
5829 dissector_delete_uint(tcp?"tcp.port":"udp.port", port, main_handle);
5830 dissector_delete_uint("sctp.port", port, main_handle);
5831 }
5832
5833 if (port) {
5834 dissector_delete_uint(dissector_table_name, port, subdissector_handle);
5835 }
5836}
5837
5838void
5839ssl_set_server(SslSession *session, address *addr, port_type ptype, uint32_t port)
5840{
5841 copy_address_wmem(wmem_file_scope(), &session->srv_addr, addr);
5842 session->srv_ptype = ptype;
5843 session->srv_port = port;
5844}
5845
5846int
5847ssl_packet_from_server(SslSession *session, dissector_table_t table, const packet_info *pinfo)
5848{
5849 int ret;
5850 if (session && session->srv_addr.type != AT_NONE) {
5851 ret = (session->srv_ptype == pinfo->ptype) &&
5852 (session->srv_port == PINFO_SRCPORT(pinfo)((pinfo)->use_conv_addr_port_endpoints ? conversation_addr_port_endpoints_port1
((pinfo)->conv_addr_port_endpoints) : (pinfo)->srcport)
) &&
5853 addresses_equal(&session->srv_addr, PINFO_SRC(pinfo)((pinfo)->use_conv_addr_port_endpoints ? conversation_addr_port_endpoints_addr1
((pinfo)->conv_addr_port_endpoints) : &((pinfo)->src
))
);
5854 } else {
5855 ret = (dissector_get_uint_handle(table, PINFO_SRCPORT(pinfo)((pinfo)->use_conv_addr_port_endpoints ? conversation_addr_port_endpoints_port1
((pinfo)->conv_addr_port_endpoints) : (pinfo)->srcport)
) != 0);
5856 }
5857
5858 ssl_debug_printf("packet_from_server: is from server - %s\n", (ret)?"TRUE":"FALSE");
5859 return ret;
5860}
5861/* Handling of association between tls/dtls ports and clear text protocol. }}} */
5862
5863
5864/* Links SSL records with the real packet data. {{{ */
5865SslPacketInfo *
5866tls_add_packet_info(int proto, packet_info *pinfo, uint8_t curr_layer_num_ssl)
5867{
5868 SslPacketInfo *pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, curr_layer_num_ssl);
5869 if (!pi) {
5870 pi = wmem_new0(wmem_file_scope(), SslPacketInfo)((SslPacketInfo*)wmem_alloc0((wmem_file_scope()), sizeof(SslPacketInfo
)))
;
5871 pi->srcport = PINFO_SRCPORT(pinfo)((pinfo)->use_conv_addr_port_endpoints ? conversation_addr_port_endpoints_port1
((pinfo)->conv_addr_port_endpoints) : (pinfo)->srcport)
;
5872 pi->destport = PINFO_DESTPORT(pinfo)((pinfo)->use_conv_addr_port_endpoints ? conversation_addr_port_endpoints_port2
((pinfo)->conv_addr_port_endpoints) : (pinfo)->destport
)
;
5873 conversation_t *conv = find_or_create_conversation_strat(pinfo);
5874 SslDecryptSession *ssl_session = tls_get_session(conv, proto, curr_layer_num_ssl);
5875 if (ssl_session) {
5876 /* This can also be called by the QUIC TLS1.3 handshake only
5877 * dissector. That is not associated with a session, or a stream,
5878 * and doesn't need the information for Follow or Decode As. */
5879 pi->stream = ssl_session->session.stream;
5880 }
5881 p_add_proto_data(wmem_file_scope(), pinfo, proto, curr_layer_num_ssl, pi);
5882 }
5883
5884 return pi;
5885}
5886
5887/**
5888 * Remembers the decrypted TLS record fragment (TLSInnerPlaintext in TLS 1.3) to
5889 * avoid the need for a decoder in the second pass. Additionally, it remembers
5890 * sequence numbers (for reassembly and Follow TLS Stream).
5891 *
5892 * @param proto The protocol identifier (proto_ssl or proto_dtls).
5893 * @param pinfo The packet where the record originates from.
5894 * @param plain_data Decrypted plaintext to store in the record.
5895 * @param plain_data_len Total length of the plaintext.
5896 * @param content_len Length of the plaintext section corresponding to the record content.
5897 * @param record_id The identifier for this record within the current packet.
5898 * @param flow Information about sequence numbers, etc.
5899 * @param type TLS Content Type (such as handshake or application_data).
5900 * @param curr_layer_num_ssl The layer identifier for this TLS session.
5901 */
5902void
5903ssl_add_record_info(int proto, packet_info *pinfo,
5904 const unsigned char *plain_data, int plain_data_len, int content_len,
5905 int record_id, SslFlow *flow, ContentType type, uint8_t curr_layer_num_ssl,
5906 uint64_t record_seq)
5907{
5908 SslRecordInfo* rec, **prec;
5909 SslPacketInfo *pi = tls_add_packet_info(proto, pinfo, curr_layer_num_ssl);
5910
5911 ws_assert(content_len <= plain_data_len)do { if ((1) && !(content_len <= plain_data_len)) ws_log_fatal_full
("", LOG_LEVEL_ERROR, "epan/dissectors/packet-tls-utils.c", 5911
, __func__, "assertion failed: %s", "content_len <= plain_data_len"
); } while (0)
;
5912
5913 rec = wmem_new(wmem_file_scope(), SslRecordInfo)((SslRecordInfo*)wmem_alloc((wmem_file_scope()), sizeof(SslRecordInfo
)))
;
5914 rec->plain_data = (unsigned char *)wmem_memdup(wmem_file_scope(), plain_data, plain_data_len);
5915 rec->plain_data_len = plain_data_len;
5916 rec->content_len = content_len;
5917 rec->id = record_id;
5918 rec->type = type;
5919 rec->next = NULL((void*)0);
5920 rec->record_seq = record_seq;
5921
5922 if (flow && type == SSL_ID_APP_DATA) {
5923 rec->seq = flow->byte_seq;
5924 rec->flow = flow;
5925 flow->byte_seq += content_len;
5926 ssl_debug_printf("%s stored decrypted record seq=%d nxtseq=%d flow=%p\n",
5927 G_STRFUNC((const char*) (__func__)), rec->seq, rec->seq + content_len, (void*)flow);
5928 }
5929
5930 /* Remember decrypted records. */
5931 prec = &pi->records;
5932 while (*prec) prec = &(*prec)->next;
5933 *prec = rec;
5934}
5935
5936/* search in packet data for the specified id; return a newly created tvb for the associated data */
5937tvbuff_t*
5938ssl_get_record_info(tvbuff_t *parent_tvb, int proto, packet_info *pinfo, int record_id, uint8_t curr_layer_num_ssl, SslRecordInfo **matched_record)
5939{
5940 SslRecordInfo* rec;
5941 SslPacketInfo* pi;
5942 pi = (SslPacketInfo *)p_get_proto_data(wmem_file_scope(), pinfo, proto, curr_layer_num_ssl);
5943
5944 if (!pi)
5945 return NULL((void*)0);
5946
5947 for (rec = pi->records; rec; rec = rec->next)
5948 if (rec->id == record_id) {
5949 *matched_record = rec;
5950 /* link new real_data_tvb with a parent tvb so it is freed when frame dissection is complete */
5951 return tvb_new_child_real_data(parent_tvb, rec->plain_data, rec->plain_data_len, rec->plain_data_len);
5952 }
5953
5954 return NULL((void*)0);
5955}
5956/* Links SSL records with the real packet data. }}} */
5957
5958/* initialize/reset per capture state data (ssl sessions cache). {{{ */
5959void
5960ssl_common_init(ssl_master_key_map_t *mk_map,
5961 StringInfo *decrypted_data, StringInfo *compressed_data)
5962{
5963 mk_map->session = g_hash_table_new(ssl_hash, ssl_equal);
5964 mk_map->tickets = g_hash_table_new(ssl_hash, ssl_equal);
5965 mk_map->crandom = g_hash_table_new(ssl_hash, ssl_equal);
5966 mk_map->pre_master = g_hash_table_new(ssl_hash, ssl_equal);
5967 mk_map->pms = g_hash_table_new(ssl_hash, ssl_equal);
5968 mk_map->tls13_client_early = g_hash_table_new(ssl_hash, ssl_equal);
5969 mk_map->tls13_client_handshake = g_hash_table_new(ssl_hash, ssl_equal);
5970 mk_map->tls13_server_handshake = g_hash_table_new(ssl_hash, ssl_equal);
5971 mk_map->tls13_client_appdata = g_hash_table_new(ssl_hash, ssl_equal);
5972 mk_map->tls13_server_appdata = g_hash_table_new(ssl_hash, ssl_equal);
5973 mk_map->tls13_early_exporter = g_hash_table_new(ssl_hash, ssl_equal);
5974 mk_map->tls13_exporter = g_hash_table_new(ssl_hash, ssl_equal);
5975
5976 mk_map->ech_secret = g_hash_table_new(ssl_hash, ssl_equal);
5977 mk_map->ech_config = g_hash_table_new(ssl_hash, ssl_equal);
5978
5979 mk_map->used_crandom = g_hash_table_new(ssl_hash, ssl_equal);
5980
5981 ssl_data_alloc(decrypted_data, 32);
5982 ssl_data_alloc(compressed_data, 32);
5983}
5984
5985void
5986ssl_common_cleanup(ssl_master_key_map_t *mk_map, FILE **ssl_keylog_file,
5987 StringInfo *decrypted_data, StringInfo *compressed_data)
5988{
5989 g_hash_table_destroy(mk_map->session);
5990 g_hash_table_destroy(mk_map->tickets);
5991 g_hash_table_destroy(mk_map->crandom);
5992 g_hash_table_destroy(mk_map->pre_master);
5993 g_hash_table_destroy(mk_map->pms);
5994 g_hash_table_destroy(mk_map->tls13_client_early);
5995 g_hash_table_destroy(mk_map->tls13_client_handshake);
5996 g_hash_table_destroy(mk_map->tls13_server_handshake);
5997 g_hash_table_destroy(mk_map->tls13_client_appdata);
5998 g_hash_table_destroy(mk_map->tls13_server_appdata);
5999 g_hash_table_destroy(mk_map->tls13_early_exporter);
6000 g_hash_table_destroy(mk_map->tls13_exporter);
6001
6002 g_hash_table_destroy(mk_map->ech_secret);
6003 g_hash_table_destroy(mk_map->ech_config);
6004
6005 g_hash_table_destroy(mk_map->used_crandom);
6006
6007 g_free(decrypted_data->data)(__builtin_object_size ((decrypted_data->data), 0) != ((size_t
) - 1)) ? g_free_sized (decrypted_data->data, __builtin_object_size
((decrypted_data->data), 0)) : (g_free) (decrypted_data->
data)
;
6008 g_free(compressed_data->data)(__builtin_object_size ((compressed_data->data), 0) != ((size_t
) - 1)) ? g_free_sized (compressed_data->data, __builtin_object_size
((compressed_data->data), 0)) : (g_free) (compressed_data
->data)
;
6009
6010 /* close the previous keylog file now that the cache are cleared, this
6011 * allows the cache to be filled with the full keylog file contents. */
6012 if (*ssl_keylog_file) {
6013 fclose(*ssl_keylog_file);
6014 *ssl_keylog_file = NULL((void*)0);
6015 }
6016}
6017/* }}} */
6018
6019/* parse ssl related preferences (private keys and ports association strings) */
6020#if defined(HAVE_LIBGNUTLS1)
6021/* Load a single RSA key file item from preferences. {{{ */
6022void
6023ssl_parse_key_list(const ssldecrypt_assoc_t *uats, GHashTable *key_hash, const char* dissector_table_name, dissector_handle_t main_handle, bool_Bool tcp)
6024{
6025 gnutls_x509_privkey_t x509_priv_key;
6026 gnutls_privkey_t priv_key = NULL((void*)0);
6027 FILE* fp = NULL((void*)0);
6028 int ret;
6029 size_t key_id_len = 20;
6030 unsigned char *key_id = NULL((void*)0);
6031 char *err = NULL((void*)0);
6032 dissector_handle_t handle;
6033 /* try to load keys file first */
6034 fp = ws_fopenfopen(uats->keyfile, "rb");
6035 if (!fp) {
6036 report_open_failure(uats->keyfile, errno(*__errno_location ()), false0);
6037 return;
6038 }
6039
6040 if ((int)strlen(uats->password) == 0) {
6041 x509_priv_key = rsa_load_pem_key(fp, &err);
6042 } else {
6043 x509_priv_key = rsa_load_pkcs12(fp, uats->password, &err);
6044 }
6045 fclose(fp);
6046
6047 if (!x509_priv_key) {
6048 if (err) {
6049 report_failure("Can't load private key from %s: %s",
6050 uats->keyfile, err);
6051 g_free(err)(__builtin_object_size ((err), 0) != ((size_t) - 1)) ? g_free_sized
(err, __builtin_object_size ((err), 0)) : (g_free) (err)
;
6052 } else
6053 report_failure("Can't load private key from %s: unknown error",
6054 uats->keyfile);
6055 return;
6056 }
6057 if (err) {
6058 report_failure("Load of private key from %s \"succeeded\" with error %s",
6059 uats->keyfile, err);
6060 g_free(err)(__builtin_object_size ((err), 0) != ((size_t) - 1)) ? g_free_sized
(err, __builtin_object_size ((err), 0)) : (g_free) (err)
;
6061 }
6062
6063 gnutls_privkey_init(&priv_key);
6064 ret = gnutls_privkey_import_x509(priv_key, x509_priv_key,
6065 GNUTLS_PRIVKEY_IMPORT_AUTO_RELEASE|GNUTLS_PRIVKEY_IMPORT_COPY);
6066 if (ret < 0) {
6067 report_failure("Can't convert private key %s: %s",
6068 uats->keyfile, gnutls_strerror(ret));
6069 goto end;
6070 }
6071
6072 key_id = (unsigned char *) g_malloc0(key_id_len);
6073 ret = gnutls_x509_privkey_get_key_id(x509_priv_key, 0, key_id, &key_id_len);
6074 if (ret < 0) {
6075 report_failure("Can't calculate public key ID for %s: %s",
6076 uats->keyfile, gnutls_strerror(ret));
6077 goto end;
6078 }
6079 ssl_print_data("KeyID", key_id, key_id_len);
6080 if (key_id_len != 20) {
6081 report_failure("Expected Key ID size %u for %s, got %zu", 20,
6082 uats->keyfile, key_id_len);
6083 goto end;
6084 }
6085
6086 g_hash_table_replace(key_hash, key_id, priv_key);
6087 key_id = NULL((void*)0); /* used in key_hash, do not free. */
6088 priv_key = NULL((void*)0);
6089 ssl_debug_printf("ssl_init private key file %s successfully loaded.\n", uats->keyfile);
6090
6091 handle = ssl_find_appdata_dissector(uats->protocol);
6092 if (handle) {
6093 /* Port to subprotocol mapping */
6094 uint16_t port = 0;
6095 if (ws_strtou16(uats->port, NULL((void*)0), &port)) {
6096 if (port > 0) {
6097 ssl_debug_printf("ssl_init port '%d' filename '%s' password(only for p12 file) '%s'\n",
6098 port, uats->keyfile, uats->password);
6099
6100 ssl_association_add(dissector_table_name, main_handle, handle, port, tcp);
6101 }
6102 } else {
6103 if (strcmp(uats->port, "start_tls"))
6104 ssl_debug_printf("invalid ssl_init_port: %s\n", uats->port);
6105 }
6106 }
6107
6108end:
6109 gnutls_x509_privkey_deinit(x509_priv_key);
6110 gnutls_privkey_deinit(priv_key);
6111 g_free(key_id)(__builtin_object_size ((key_id), 0) != ((size_t) - 1)) ? g_free_sized
(key_id, __builtin_object_size ((key_id), 0)) : (g_free) (key_id
)
;
6112}
6113/* }}} */
6114#endif
6115
6116
6117/* Store/load a known (pre-)master secret from/for this SSL session. {{{ */
6118/** store a known (pre-)master secret into cache */
6119static void
6120ssl_save_master_key(const char *label, GHashTable *ht, StringInfo *key,
6121 StringInfo *mk)
6122{
6123 StringInfo *ht_key, *master_secret;
6124
6125 if (key->data_len == 0) {
6126 ssl_debug_printf("%s: not saving empty %s!\n", G_STRFUNC((const char*) (__func__)), label);
6127 return;
6128 }
6129
6130 if (mk->data_len == 0) {
6131 ssl_debug_printf("%s not saving empty (pre-)master secret for %s!\n",
6132 G_STRFUNC((const char*) (__func__)), label);
6133 return;
6134 }
6135
6136 ht_key = ssl_data_clone(key);
6137 master_secret = ssl_data_clone(mk);
6138 g_hash_table_insert(ht, ht_key, master_secret);
6139
6140 ssl_debug_printf("%s inserted (pre-)master secret for %s\n", G_STRFUNC((const char*) (__func__)), label);
6141 ssl_print_string("stored key", ht_key);
6142 ssl_print_string("stored (pre-)master secret", master_secret);
6143}
6144
6145/** restore a (pre-)master secret given some key in the cache */
6146static bool_Bool
6147ssl_restore_master_key(SslDecryptSession *ssl, const char *label,
6148 bool_Bool is_pre_master, GHashTable *ht, StringInfo *key)
6149{
6150 StringInfo *ms;
6151
6152 if (key->data_len == 0) {
6153 ssl_debug_printf("%s can't restore %smaster secret using an empty %s\n",
6154 G_STRFUNC((const char*) (__func__)), is_pre_master ? "pre-" : "", label);
6155 return false0;
6156 }
6157
6158 ms = (StringInfo *)g_hash_table_lookup(ht, key);
6159 if (!ms) {
6160 ssl_debug_printf("%s can't find %smaster secret by %s\n", G_STRFUNC((const char*) (__func__)),
6161 is_pre_master ? "pre-" : "", label);
6162 return false0;
6163 }
6164
6165 /* (pre)master secret found, clear knowledge of other keys and set it in the
6166 * current conversation */
6167 ssl->state &= ~(SSL_MASTER_SECRET(1<<5) | SSL_PRE_MASTER_SECRET(1<<6) |
6168 SSL_HAVE_SESSION_KEY(1<<3));
6169 if (is_pre_master) {
6170 /* unlike master secret, pre-master secret has a variable size (48 for
6171 * RSA, varying for PSK) and is therefore not statically allocated */
6172 ssl->pre_master_secret.data = (unsigned char *) wmem_alloc(wmem_file_scope(),
6173 ms->data_len);
6174 ssl_data_set(&ssl->pre_master_secret, ms->data, ms->data_len);
6175 ssl->state |= SSL_PRE_MASTER_SECRET(1<<6);
6176 } else {
6177 ssl_data_set(&ssl->master_secret, ms->data, ms->data_len);
6178 ssl->state |= SSL_MASTER_SECRET(1<<5);
6179 }
6180 ssl_debug_printf("%s %smaster secret retrieved using %s\n", G_STRFUNC((const char*) (__func__)),
6181 is_pre_master ? "pre-" : "", label);
6182 ssl_print_string(label, key);
6183 ssl_print_string("(pre-)master secret", ms);
6184 return true1;
6185}
6186/* Store/load a known (pre-)master secret from/for this SSL session. }}} */
6187
6188/* Should be called when all parameters are ready (after ChangeCipherSpec), and
6189 * the decoder should be attempted to be initialized. {{{*/
6190void
6191ssl_finalize_decryption(SslDecryptSession *ssl, ssl_master_key_map_t *mk_map)
6192{
6193 if (ssl->session.version == TLSV1DOT3_VERSION0x304) {
6194 /* TLS 1.3 implementations only provide secrets derived from the master
6195 * secret which are loaded in tls13_change_key. No master secrets can be
6196 * loaded here, so just return. */
6197 return;
6198 }
6199 ssl_debug_printf("%s state = 0x%02X\n", G_STRFUNC((const char*) (__func__)), ssl->state);
6200 if (ssl->state & SSL_HAVE_SESSION_KEY(1<<3)) {
6201 ssl_debug_printf(" session key already available, nothing to do.\n");
6202 return;
6203 }
6204 if (!(ssl->state & SSL_CIPHER(1<<2))) {
6205 ssl_debug_printf(" Cipher suite (Server Hello) is missing!\n");
6206 return;
6207 }
6208
6209 /* for decryption, there needs to be a master secret (which can be derived
6210 * from pre-master secret). If missing, try to pick a master key from cache
6211 * (an earlier packet in the capture or key logfile). */
6212 if (!(ssl->state & (SSL_MASTER_SECRET(1<<5) | SSL_PRE_MASTER_SECRET(1<<6))) &&
6213 !ssl_restore_master_key(ssl, "Session ID", false0,
6214 mk_map->session, &ssl->session_id) &&
6215 (!ssl->session.is_session_resumed ||
6216 !ssl_restore_master_key(ssl, "Session Ticket", false0,
6217 mk_map->tickets, &ssl->session_ticket)) &&
6218 !ssl_restore_master_key(ssl, "Client Random", false0,
6219 mk_map->crandom, &ssl->client_random)) {
6220 if (ssl->cipher_suite->enc != ENC_NULL0x3D) {
6221 /* how unfortunate, the master secret could not be found */
6222 ssl_debug_printf(" Cannot find master secret\n");
6223 return;
6224 } else {
6225 ssl_debug_printf(" Cannot find master secret, continuing anyway "
6226 "because of a NULL cipher\n");
6227 }
6228 }
6229
6230 if (ssl_generate_keyring_material(ssl) < 0) {
6231 ssl_debug_printf("%s can't generate keyring material\n", G_STRFUNC((const char*) (__func__)));
6232 return;
6233 }
6234 /* Save Client Random/ Session ID for "SSL Export Session keys" */
6235 ssl_save_master_key("Client Random", mk_map->crandom,
6236 &ssl->client_random, &ssl->master_secret);
6237 ssl_save_master_key("Session ID", mk_map->session,
6238 &ssl->session_id, &ssl->master_secret);
6239 /* Only save the new secrets if the server sent the ticket. The client
6240 * ticket might have become stale. */
6241 if (ssl->state & SSL_NEW_SESSION_TICKET(1<<10)) {
6242 ssl_save_master_key("Session Ticket", mk_map->tickets,
6243 &ssl->session_ticket, &ssl->master_secret);
6244 }
6245} /* }}} */
6246
6247static StringInfo*
6248tls13_load_secret_from_psk(SslDecryptSession *tls, bool_Bool is_from_server,
6249 TLSRecordType type)
6250{
6251 /* XXX - In addition to an out-of-bound PSK, we could also save the
6252 * PSK from a NewSessionTicket; we would also need to compute the
6253 * resumption_master_secret. */
6254 if (tls->psk.data_len == 0)
6255 return NULL((void*)0);
6256
6257 /* We SHOULD associate each PSK with a hash algorithm (e.g., use
6258 * a UAT instead of a single global PSK string preference, preferably
6259 * following RFC 9258.) Failing that, RFC 8864 4.2.1 and 9258 say SHA-256
6260 * SHOULD be used. We will try the negotiated hash algorithm regardless
6261 * with the PSK, but fall back to SHA-256 for the Early Secret, since
6262 * that's before the Server Hello completes negotiation.
6263 */
6264 const SslDigestAlgo *dig = ssl_cipher_suite_dig(tls->cipher_suite);
6265 if (type == TLS_SECRET_0RTT_APP && dig == &digests[DIG_NA0x45 - DIG_MD50x40]) {
6266 dig = &digests[DIG_SHA2560x42 - DIG_MD50x40];
6267 ssl_debug_printf("%s assuming PSK hash function is %s\n", G_STRFUNC((const char*) (__func__)), dig->name);
6268 }
6269
6270 int hash_algo = ssl_get_digest_by_name(dig->name);
6271 if (!hash_algo) {
6272 ssl_debug_printf("%s can't find hash function %s\n", G_STRFUNC((const char*) (__func__)), dig->name);
6273 return NULL((void*)0);
6274 }
6275
6276 /* We can re-use this to store the Pseudo Random Key for each epoch. */
6277 uint8_t prk[DIGEST_MAX_SIZE48];
6278 StringInfo prk_string = { prk, dig->len };
6279 uint8_t *derived_secret;
6280
6281 uint8_t zeroes[DIGEST_MAX_SIZE48];
6282 memset(zeroes, 0, dig->len);
6283
6284 StringInfo *secret = NULL((void*)0);
6285 const char *label;
6286
6287 /* PRK = Early Secret */
6288 hkdf_extract(hash_algo, zeroes, dig->len, tls->psk.data, tls->psk.data_len, prk);
6289
6290 if (type == TLS_SECRET_0RTT_APP) {
6291 DISSECTOR_ASSERT(!is_from_server)((void) ((!is_from_server) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-tls-utils.c"
, 6291, "!is_from_server"))))
;
6292 label = "c e traffic";
6293 } else {
6294 if (!tls13_derive_secret(hash_algo, &prk_string, tls13_hkdf_label_prefix(tls),
6295 "derived", NULL((void*)0), 0, dig->len, &derived_secret))
6296 return NULL((void*)0);
6297
6298 /* PRK = Handshake Secret [assume no (EC)DHE.] */
6299 hkdf_extract(hash_algo, derived_secret, dig->len, zeroes, dig->len, prk);
6300 wmem_free(NULL((void*)0), derived_secret);
6301
6302 if (type == TLS_SECRET_HANDSHAKE) {
6303 label = is_from_server ? "s hs traffic" : "c hs traffic";
6304 } else {
6305 if (!tls13_derive_secret(hash_algo, &prk_string, tls13_hkdf_label_prefix(tls),
6306 "derived", NULL((void*)0), 0, dig->len, &derived_secret))
6307 return NULL((void*)0);
6308
6309 /* PRK = Master Secret */
6310 hkdf_extract(hash_algo, derived_secret, dig->len, zeroes, dig->len, prk);
6311 wmem_free(NULL((void*)0), derived_secret);
6312
6313 label = is_from_server ? "s ap traffic" : "c ap traffic";
6314 }
6315 }
6316
6317 /* XXX - If Encrypted Client Hello was accepted (do client/server pairs
6318 * support ECHO with psk_ke?) then we should use ech_transcript instead
6319 * of handshake_transcript. Both are kept until the ServerHello indicates
6320 * whether ECHO was accepted or not, though the ECH transcript doesn't
6321 * currently get the messages after the ServerHello. */
6322 uint8_t transcript_hash[DIGEST_MAX_SIZE48];
6323 unsigned transcript_hash_len;
6324 if (!tls_transcript_hash(&tls->handshake_transcript, hash_algo, transcript_hash, &transcript_hash_len)) {
6325 ssl_debug_printf("%s can't get the transcript hash\n", G_STRFUNC((const char*) (__func__)));
6326 return NULL((void*)0);
6327 }
6328 if (!tls13_hkdf_expand_label_context(hash_algo, &prk_string,
6329 tls13_hkdf_label_prefix(tls), label,
6330 transcript_hash, transcript_hash_len,
6331 dig->len, &derived_secret))
6332 return NULL((void*)0);
6333
6334 secret = wmem_new(wmem_file_scope(), StringInfo)((StringInfo*)wmem_alloc((wmem_file_scope()), sizeof(StringInfo
)))
;
6335 secret->data = wmem_memdup(wmem_file_scope(), derived_secret, dig->len);
6336 secret->data_len = dig->len;
6337 wmem_free(NULL((void*)0), derived_secret);
6338 return secret;
6339}
6340
6341/* Load the traffic key secret from the keylog file. */
6342StringInfo *
6343tls13_load_secret(SslDecryptSession *ssl, ssl_master_key_map_t *mk_map,
6344 bool_Bool is_from_server, TLSRecordType type)
6345{
6346 GHashTable *key_map;
6347 const char *label;
6348
6349 if (ssl->session.version != TLSV1DOT3_VERSION0x304 && ssl->session.version != DTLSV1DOT3_VERSION0xfefc) {
6350 ssl_debug_printf("%s TLS version %#x is not 1.3\n", G_STRFUNC((const char*) (__func__)), ssl->session.version);
6351 return NULL((void*)0);
6352 }
6353
6354 if (ssl->client_random.data_len == 0) {
6355 /* May happen if Hello message is missing and Finished is found. */
6356 ssl_debug_printf("%s missing Client Random\n", G_STRFUNC((const char*) (__func__)));
6357 return NULL((void*)0);
6358 }
6359
6360 switch (type) {
6361 case TLS_SECRET_0RTT_APP:
6362 DISSECTOR_ASSERT(!is_from_server)((void) ((!is_from_server) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion \"%s\"", "epan/dissectors/packet-tls-utils.c"
, 6362, "!is_from_server"))))
;
6363 label = "CLIENT_EARLY_TRAFFIC_SECRET";
6364 key_map = mk_map->tls13_client_early;
6365 break;
6366 case TLS_SECRET_HANDSHAKE:
6367 if (is_from_server) {
6368 label = "SERVER_HANDSHAKE_TRAFFIC_SECRET";
6369 key_map = mk_map->tls13_server_handshake;
6370 } else {
6371 label = "CLIENT_HANDSHAKE_TRAFFIC_SECRET";
6372 key_map = mk_map->tls13_client_handshake;
6373 }
6374 break;
6375 case TLS_SECRET_APP:
6376 if (is_from_server) {
6377 label = "SERVER_TRAFFIC_SECRET_0";
6378 key_map = mk_map->tls13_server_appdata;
6379 } else {
6380 label = "CLIENT_TRAFFIC_SECRET_0";
6381 key_map = mk_map->tls13_client_appdata;
6382 }
6383 break;
6384 default:
6385 ws_assert_not_reached()ws_log_fatal_full("", LOG_LEVEL_ERROR, "epan/dissectors/packet-tls-utils.c"
, 6385, __func__, "assertion \"not reached\" failed")
;
6386 }
6387
6388 /* Transitioning to new keys, mark old ones as unusable. */
6389 ssl_debug_printf("%s transitioning to new key, old state 0x%02x\n", G_STRFUNC((const char*) (__func__)), ssl->state);
6390 ssl->state &= ~(SSL_MASTER_SECRET(1<<5) | SSL_PRE_MASTER_SECRET(1<<6) | SSL_HAVE_SESSION_KEY(1<<3));
6391
6392 StringInfo *secret = (StringInfo *)g_hash_table_lookup(key_map, &ssl->client_random);
6393 if (!secret) {
6394 secret = tls13_load_secret_from_psk(ssl, is_from_server, type);
6395 if (secret) {
6396 ssl_debug_printf("%s Calculated TLS 1.3 traffic secret from PSK.\n", G_STRFUNC((const char*) (__func__)));
6397 /* Doing this allows us to save the secret as a DSB in a pcapng. */
6398 g_hash_table_insert(key_map, ssl_data_clone(&ssl->client_random), secret);
6399 }
6400 }
6401 if (!secret) {
6402 ssl_debug_printf("%s Cannot find %s, decryption impossible\n", G_STRFUNC((const char*) (__func__)), label);
6403 /* Disable decryption, the keys are invalid. */
6404 if (is_from_server) {
6405 ssl->server = NULL((void*)0);
6406 } else {
6407 ssl->client = NULL((void*)0);
6408 }
6409 return NULL((void*)0);
6410 }
6411
6412 /* TLS 1.3 secret found, set new keys. */
6413 ssl_debug_printf("%s Retrieved TLS 1.3 traffic secret.\n", G_STRFUNC((const char*) (__func__)));
6414 ssl_print_string("Client Random", &ssl->client_random);
6415 ssl_print_string(label, secret);
6416 return secret;
6417}
6418
6419/* Load the new key. */
6420void
6421tls13_change_key(SslDecryptSession *ssl, ssl_master_key_map_t *mk_map,
6422 bool_Bool is_from_server, TLSRecordType type)
6423{
6424 if (ssl->state & SSL_QUIC_RECORD_LAYER(1<<13)) {
6425 /*
6426 * QUIC does not use the TLS record layer for message protection.
6427 * The required keys will be extracted later by QUIC.
6428 */
6429 return;
6430 }
6431
6432 StringInfo *secret = tls13_load_secret(ssl, mk_map, is_from_server, type);
6433 if (!secret) {
6434 if (type != TLS_SECRET_HANDSHAKE) {
6435 return;
6436 }
6437 /*
6438 * Workaround for when for some reason we don't have the handshake
6439 * secret but do have the application traffic secret. (#20240)
6440 * If we can't find the handshake secret, we'll never decrypt the
6441 * Finished message, so we won't know when to change to the app
6442 * traffic key, so we do so now.
6443 */
6444 type = TLS_SECRET_APP;
6445 secret = tls13_load_secret(ssl, mk_map, is_from_server, type);
6446 if (!secret) {
6447 return;
6448 }
6449 }
6450
6451 if (tls13_generate_keys(ssl, secret, is_from_server)) {
6452 /*
6453 * Remember the application traffic secret to support Key Update. The
6454 * other secrets cannot be used for this purpose, so free them.
6455 */
6456 SslDecoder *decoder = is_from_server ? ssl->server : ssl->client;
6457 StringInfo *app_secret = &decoder->app_traffic_secret;
6458 if (type == TLS_SECRET_APP) {
6459 app_secret->data = (unsigned char *) wmem_realloc(wmem_file_scope(),
6460 app_secret->data,
6461 secret->data_len);
6462 ssl_data_set(app_secret, secret->data, secret->data_len);
6463 } else {
6464 wmem_free(wmem_file_scope(), app_secret->data);
6465 app_secret->data = NULL((void*)0);
6466 app_secret->data_len = 0;
6467 }
6468 }
6469}
6470
6471/**
6472 * Update to next application data traffic secret for TLS 1.3. The previous
6473 * secret should have been set by tls13_change_key.
6474 */
6475void
6476tls13_key_update(SslDecryptSession *ssl, bool_Bool is_from_server)
6477{
6478 /* RFC 8446 Section 7.2:
6479 * application_traffic_secret_N+1 =
6480 * HKDF-Expand-Label(application_traffic_secret_N,
6481 * "traffic upd", "", Hash.length)
6482 *
6483 * Both application_traffic_secret_N are of the same length (Hash.length).
6484 */
6485 const SslCipherSuite *cipher_suite = ssl->cipher_suite;
6486 SslDecoder *decoder = is_from_server ? ssl->server : ssl->client;
6487 StringInfo *app_secret = decoder ? &decoder->app_traffic_secret : NULL((void*)0);
6488 uint8_t tls13_draft_version = ssl->session.tls13_draft_version;
6489
6490 if (!cipher_suite || !app_secret || app_secret->data_len == 0) {
6491 ssl_debug_printf("%s Cannot perform Key Update due to missing info\n", G_STRFUNC((const char*) (__func__)));
6492 return;
6493 }
6494
6495 /*
6496 * Previous traffic secret is available, so find the hash function,
6497 * expand the new traffic secret and generate new keys.
6498 */
6499 const char *hash_name = ssl_cipher_suite_dig(cipher_suite)->name;
6500 int hash_algo = ssl_get_digest_by_name(hash_name);
6501 const unsigned hash_len = app_secret->data_len;
6502 unsigned char *new_secret;
6503 const char *label = "traffic upd";
6504 if (tls13_draft_version && tls13_draft_version < 20) {
6505 label = "application traffic secret";
6506 }
6507 if (!tls13_hkdf_expand_label(hash_algo, app_secret,
6508 tls13_hkdf_label_prefix(ssl),
6509 label, hash_len, &new_secret)) {
6510 ssl_debug_printf("%s traffic_secret_N+1 expansion failed\n", G_STRFUNC((const char*) (__func__)));
6511 return;
6512 }
6513 ssl_data_set(app_secret, new_secret, hash_len);
6514 if (tls13_generate_keys(ssl, app_secret, is_from_server)) {
6515 /*
6516 * Remember the application traffic secret on the new decoder to
6517 * support another Key Update.
6518 */
6519 decoder = is_from_server ? ssl->server : ssl->client;
6520 app_secret = &decoder->app_traffic_secret;
6521 app_secret->data = (unsigned char *) wmem_realloc(wmem_file_scope(),
6522 app_secret->data,
6523 hash_len);
6524 ssl_data_set(app_secret, new_secret, hash_len);
6525 }
6526 wmem_free(NULL((void*)0), new_secret);
6527}
6528
6529void
6530tls_save_crandom(SslDecryptSession *ssl, ssl_master_key_map_t *mk_map)
6531{
6532 if (ssl && (ssl->state & SSL_CLIENT_RANDOM(1<<0))) {
6533 g_hash_table_add(mk_map->used_crandom, ssl_data_clone(&ssl->client_random));
6534 }
6535}
6536
6537/** SSL keylog file handling. {{{ */
6538
6539static GRegex *
6540ssl_compile_keyfile_regex(void)
6541{
6542#define OCTET "(?:[[:xdigit:]]{2})"
6543 const char *pattern =
6544 "(?:"
6545 /* Matches Client Hellos having this Client Random */
6546 "PMS_CLIENT_RANDOM (?<client_random_pms>" OCTET "{32}) "
6547 /* Matches first part of encrypted RSA pre-master secret */
6548 "|RSA (?<encrypted_pmk>" OCTET "{8}) "
6549 /* Pre-Master-Secret is given, it is 48 bytes for RSA,
6550 but it can be of any length for DHE */
6551 ")(?<pms>" OCTET "+)"
6552 "|(?:"
6553 /* Matches Server Hellos having a Session ID */
6554 "RSA Session-ID:(?<session_id>" OCTET "+) Master-Key:"
6555 /* Matches Client Hellos having this Client Random */
6556 "|CLIENT_RANDOM (?<client_random>" OCTET "{32}) "
6557 /* Master-Secret is given, its length is fixed */
6558 ")(?<master_secret>" OCTET "{" G_STRINGIFY(SSL_MASTER_SECRET_LENGTH)"48" "})"
6559 "|(?"
6560 /* TLS 1.3 Client Random to Derived Secrets mapping. */
6561 ":CLIENT_EARLY_TRAFFIC_SECRET (?<client_early>" OCTET "{32})"
6562 "|CLIENT_HANDSHAKE_TRAFFIC_SECRET (?<client_handshake>" OCTET "{32})"
6563 "|SERVER_HANDSHAKE_TRAFFIC_SECRET (?<server_handshake>" OCTET "{32})"
6564 "|CLIENT_TRAFFIC_SECRET_0 (?<client_appdata>" OCTET "{32})"
6565 "|SERVER_TRAFFIC_SECRET_0 (?<server_appdata>" OCTET "{32})"
6566 "|EARLY_EXPORTER_SECRET (?<early_exporter>" OCTET "{32})"
6567 "|EXPORTER_SECRET (?<exporter>" OCTET "{32})"
6568 /* ECH. Secret length is defined by HPKE KEM Nsecret and can vary between 32 and 64 bytes */
6569 /* These labels and their notation are specified in draft-ietf-tls-ech-keylogfile-01 */
6570 "|ECH_SECRET (?<ech_secret>" OCTET "{32,64})"
6571 "|ECH_CONFIG (?<ech_config>" OCTET "{22,})"
6572 ") (?<derived_secret>" OCTET "+)";
6573#undef OCTET
6574 static GRegex *regex = NULL((void*)0);
6575 GError *gerr = NULL((void*)0);
6576
6577 if (!regex) {
6578 regex = g_regex_new(pattern,
6579 (GRegexCompileFlags)(G_REGEX_OPTIMIZE | G_REGEX_ANCHORED | G_REGEX_RAW),
6580 G_REGEX_MATCH_ANCHORED, &gerr);
6581 if (gerr) {
6582 ssl_debug_printf("%s failed to compile regex: %s\n", G_STRFUNC((const char*) (__func__)),
6583 gerr->message);
6584 g_error_free(gerr);
6585 regex = NULL((void*)0);
6586 }
6587 }
6588
6589 return regex;
6590}
6591
6592typedef struct ssl_master_key_match_group {
6593 const char *re_group_name;
6594 GHashTable *master_key_ht;
6595} ssl_master_key_match_group_t;
6596
6597void
6598tls_keylog_process_lines(const ssl_master_key_map_t *mk_map, const uint8_t *data, unsigned datalen)
6599{
6600 ssl_master_key_match_group_t mk_groups[] = {
6601 { "encrypted_pmk", mk_map->pre_master },
6602 { "session_id", mk_map->session },
6603 { "client_random", mk_map->crandom },
6604 { "client_random_pms", mk_map->pms },
6605 /* TLS 1.3 map from Client Random to derived secret. */
6606 { "client_early", mk_map->tls13_client_early },
6607 { "client_handshake", mk_map->tls13_client_handshake },
6608 { "server_handshake", mk_map->tls13_server_handshake },
6609 { "client_appdata", mk_map->tls13_client_appdata },
6610 { "server_appdata", mk_map->tls13_server_appdata },
6611 { "early_exporter", mk_map->tls13_early_exporter },
6612 { "exporter", mk_map->tls13_exporter },
6613 { "ech_secret", mk_map->ech_secret },
6614 { "ech_config", mk_map->ech_config },
6615 };
6616
6617 /* The format of the file is a series of records with one of the following formats:
6618 * - "RSA xxxx yyyy"
6619 * Where xxxx are the first 8 bytes of the encrypted pre-master secret (hex-encoded)
6620 * Where yyyy is the cleartext pre-master secret (hex-encoded)
6621 * (this is the original format introduced with bug 4349)
6622 *
6623 * - "RSA Session-ID:xxxx Master-Key:yyyy"
6624 * Where xxxx is the SSL session ID (hex-encoded)
6625 * Where yyyy is the cleartext master secret (hex-encoded)
6626 * (added to support openssl s_client Master-Key output)
6627 * This is somewhat is a misnomer because there's nothing RSA specific
6628 * about this.
6629 *
6630 * - "PMS_CLIENT_RANDOM xxxx yyyy"
6631 * Where xxxx is the client_random from the ClientHello (hex-encoded)
6632 * Where yyyy is the cleartext pre-master secret (hex-encoded)
6633 * (This format allows SSL connections to be decrypted, if a user can
6634 * capture the PMS but could not recover the MS for a specific session
6635 * with a SSL Server.)
6636 *
6637 * - "CLIENT_RANDOM xxxx yyyy"
6638 * Where xxxx is the client_random from the ClientHello (hex-encoded)
6639 * Where yyyy is the cleartext master secret (hex-encoded)
6640 * (This format allows non-RSA SSL connections to be decrypted, i.e.
6641 * ECDHE-RSA.)
6642 *
6643 * - "CLIENT_EARLY_TRAFFIC_SECRET xxxx yyyy"
6644 * - "CLIENT_HANDSHAKE_TRAFFIC_SECRET xxxx yyyy"
6645 * - "SERVER_HANDSHAKE_TRAFFIC_SECRET xxxx yyyy"
6646 * - "CLIENT_TRAFFIC_SECRET_0 xxxx yyyy"
6647 * - "SERVER_TRAFFIC_SECRET_0 xxxx yyyy"
6648 * - "EARLY_EXPORTER_SECRET xxxx yyyy"
6649 * - "EXPORTER_SECRET xxxx yyyy"
6650 * Where xxxx is the client_random from the ClientHello (hex-encoded)
6651 * Where yyyy is the secret (hex-encoded) derived from the early,
6652 * handshake or master secrets. (This format is introduced with TLS 1.3
6653 * and supported by BoringSSL, OpenSSL, etc. See bug 12779.)
6654 */
6655 GRegex *regex = ssl_compile_keyfile_regex();
6656 if (!regex)
6657 return;
6658
6659 const char *next_line = (const char *)data;
6660 const char *line_end = next_line + datalen;
6661 while (next_line && next_line < line_end) {
6662 const char *line = next_line;
6663 next_line = (const char *)memchr(line, '\n', line_end - line);
6664 ssize_t linelen;
6665
6666 if (next_line) {
6667 linelen = next_line - line;
6668 next_line++; /* drop LF */
6669 } else {
6670 linelen = (ssize_t)(line_end - line);
6671 }
6672 if (linelen > 0 && line[linelen - 1] == '\r') {
6673 linelen--; /* drop CR */
6674 }
6675
6676 ssl_debug_printf(" checking keylog line: %.*s\n", (int)linelen, line);
6677 GMatchInfo *mi;
6678 if (g_regex_match_full(regex, line, linelen, 0, G_REGEX_MATCH_ANCHORED, &mi, NULL((void*)0))) {
6679 char *hex_key, *hex_pre_ms_or_ms;
6680 StringInfo *key = wmem_new(wmem_file_scope(), StringInfo)((StringInfo*)wmem_alloc((wmem_file_scope()), sizeof(StringInfo
)))
;
6681 StringInfo *pre_ms_or_ms = NULL((void*)0);
6682 GHashTable *ht = NULL((void*)0);
6683
6684 /* Is the PMS being supplied with the PMS_CLIENT_RANDOM
6685 * otherwise we will use the Master Secret
6686 */
6687 hex_pre_ms_or_ms = g_match_info_fetch_named(mi, "master_secret");
6688 if (hex_pre_ms_or_ms == NULL((void*)0) || !*hex_pre_ms_or_ms) {
6689 g_free(hex_pre_ms_or_ms)(__builtin_object_size ((hex_pre_ms_or_ms), 0) != ((size_t) -
1)) ? g_free_sized (hex_pre_ms_or_ms, __builtin_object_size (
(hex_pre_ms_or_ms), 0)) : (g_free) (hex_pre_ms_or_ms)
;
6690 hex_pre_ms_or_ms = g_match_info_fetch_named(mi, "pms");
6691 }
6692 if (hex_pre_ms_or_ms == NULL((void*)0) || !*hex_pre_ms_or_ms) {
6693 g_free(hex_pre_ms_or_ms)(__builtin_object_size ((hex_pre_ms_or_ms), 0) != ((size_t) -
1)) ? g_free_sized (hex_pre_ms_or_ms, __builtin_object_size (
(hex_pre_ms_or_ms), 0)) : (g_free) (hex_pre_ms_or_ms)
;
6694 hex_pre_ms_or_ms = g_match_info_fetch_named(mi, "derived_secret");
6695 }
6696 /* There is always a match, otherwise the regex is wrong. */
6697 DISSECTOR_ASSERT(hex_pre_ms_or_ms && strlen(hex_pre_ms_or_ms))((void) ((hex_pre_ms_or_ms && strlen(hex_pre_ms_or_ms
)) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/dissectors/packet-tls-utils.c", 6697, "hex_pre_ms_or_ms && strlen(hex_pre_ms_or_ms)"
))))
;
6698
6699 /* convert from hex to bytes and save to hashtable */
6700 pre_ms_or_ms = wmem_new(wmem_file_scope(), StringInfo)((StringInfo*)wmem_alloc((wmem_file_scope()), sizeof(StringInfo
)))
;
6701 from_hex(pre_ms_or_ms, hex_pre_ms_or_ms, strlen(hex_pre_ms_or_ms));
6702 g_free(hex_pre_ms_or_ms)(__builtin_object_size ((hex_pre_ms_or_ms), 0) != ((size_t) -
1)) ? g_free_sized (hex_pre_ms_or_ms, __builtin_object_size (
(hex_pre_ms_or_ms), 0)) : (g_free) (hex_pre_ms_or_ms)
;
6703
6704 /* Find a master key from any format (CLIENT_RANDOM, SID, ...) */
6705 for (unsigned i = 0; i < G_N_ELEMENTS(mk_groups)(sizeof (mk_groups) / sizeof ((mk_groups)[0])); i++) {
6706 ssl_master_key_match_group_t *g = &mk_groups[i];
6707 hex_key = g_match_info_fetch_named(mi, g->re_group_name);
6708 if (hex_key && *hex_key) {
6709 ssl_debug_printf(" matched %s\n", g->re_group_name);
6710 ht = g->master_key_ht;
6711 from_hex(key, hex_key, strlen(hex_key));
6712 g_free(hex_key)(__builtin_object_size ((hex_key), 0) != ((size_t) - 1)) ? g_free_sized
(hex_key, __builtin_object_size ((hex_key), 0)) : (g_free) (
hex_key)
;
6713 break;
6714 }
6715 g_free(hex_key)(__builtin_object_size ((hex_key), 0) != ((size_t) - 1)) ? g_free_sized
(hex_key, __builtin_object_size ((hex_key), 0)) : (g_free) (
hex_key)
;
6716 }
6717 DISSECTOR_ASSERT(ht)((void) ((ht) ? (void)0 : (proto_report_dissector_bug("%s:%u: failed assertion \"%s\""
, "epan/dissectors/packet-tls-utils.c", 6717, "ht"))))
; /* Cannot be reached, or regex is wrong. */
6718
6719 g_hash_table_insert(ht, key, pre_ms_or_ms);
6720
6721 } else if (linelen > 0 && line[0] != '#') {
6722 ssl_debug_printf(" unrecognized line\n");
6723 }
6724 /* always free match info even if there is no match. */
6725 g_match_info_free(mi);
6726 }
6727}
6728
6729void
6730ssl_load_keyfile(const char *tls_keylog_filename, FILE **keylog_file,
6731 const ssl_master_key_map_t *mk_map)
6732{
6733 /* no need to try if no key log file is configured. */
6734 if (!tls_keylog_filename || !*tls_keylog_filename) {
6735 ssl_debug_printf("%s dtls/tls.keylog_file is not configured!\n",
6736 G_STRFUNC((const char*) (__func__)));
6737 return;
6738 }
6739
6740 /* Validate regexes before even trying to use it. */
6741 if (!ssl_compile_keyfile_regex()) {
6742 return;
6743 }
6744
6745 ssl_debug_printf("trying to use TLS keylog in %s\n", tls_keylog_filename);
6746
6747 /* if the keylog file was deleted/overwritten, re-open it */
6748 if (*keylog_file && file_needs_reopen(ws_filenofileno(*keylog_file), tls_keylog_filename)) {
6749 ssl_debug_printf("%s file got deleted, trying to re-open\n", G_STRFUNC((const char*) (__func__)));
6750 fclose(*keylog_file);
6751 *keylog_file = NULL((void*)0);
6752 }
6753
6754 if (*keylog_file == NULL((void*)0)) {
6755 *keylog_file = ws_fopenfopen(tls_keylog_filename, "r");
6756 if (!*keylog_file) {
6757 ssl_debug_printf("%s failed to open SSL keylog\n", G_STRFUNC((const char*) (__func__)));
6758 return;
6759 }
6760 }
6761
6762 for (;;) {
6763 char buf[1110], *line;
6764 line = fgets(buf, sizeof(buf), *keylog_file);
6765 if (!line) {
6766 if (feof(*keylog_file)) {
6767 /* Ensure that newly appended keys can be read in the future. */
6768 clearerr(*keylog_file);
6769 } else if (ferror(*keylog_file)) {
6770 ssl_debug_printf("%s Error while reading key log file, closing it!\n", G_STRFUNC((const char*) (__func__)));
6771 fclose(*keylog_file);
6772 *keylog_file = NULL((void*)0);
6773 }
6774 break;
6775 }
6776 tls_keylog_process_lines(mk_map, (uint8_t *)line, (int)strlen(line));
6777 }
6778}
6779/** SSL keylog file handling. }}} */
6780
6781#ifdef SSL_DECRYPT_DEBUG /* {{{ */
6782
6783static FILE* ssl_debug_file;
6784
6785void
6786ssl_set_debug(const char* name)
6787{
6788 static int debug_file_must_be_closed;
6789 int use_stderr;
6790
6791 use_stderr = name?(strcmp(name, SSL_DEBUG_USE_STDERR"-") == 0):0;
6792
6793 if (debug_file_must_be_closed)
6794 fclose(ssl_debug_file);
6795
6796 if (use_stderr)
6797 ssl_debug_file = stderrstderr;
6798 else if (!name || (strcmp(name, "") ==0))
6799 ssl_debug_file = NULL((void*)0);
6800 else
6801 ssl_debug_file = ws_fopenfopen(name, "w");
6802
6803 if (!use_stderr && ssl_debug_file)
6804 debug_file_must_be_closed = 1;
6805 else
6806 debug_file_must_be_closed = 0;
6807
6808 ssl_debug_printf("Wireshark SSL debug log \n\n");
6809#ifdef HAVE_LIBGNUTLS1
6810 ssl_debug_printf("GnuTLS version: %s\n", gnutls_check_version(NULL((void*)0)));
6811#endif
6812 ssl_debug_printf("Libgcrypt version: %s\n", gcry_check_version(NULL((void*)0)));
6813 ssl_debug_printf("\n");
6814}
6815
6816void
6817ssl_debug_flush(void)
6818{
6819 if (ssl_debug_file)
6820 fflush(ssl_debug_file);
6821}
6822
6823void
6824ssl_debug_printf(const char* fmt, ...)
6825{
6826 va_list ap;
6827
6828 if (!ssl_debug_file)
6829 return;
6830
6831 va_start(ap, fmt)__builtin_va_start(ap, fmt);
6832 vfprintf(ssl_debug_file, fmt, ap);
6833 va_end(ap)__builtin_va_end(ap);
6834}
6835
6836void
6837ssl_print_data(const char* name, const unsigned char* data, size_t len)
6838{
6839 size_t i, j, k;
6840 if (!ssl_debug_file)
6841 return;
6842 fprintf(ssl_debug_file,"%s[%d]:\n",name, (int) len);
6843 for (i=0; i<len; i+=16) {
6844 fprintf(ssl_debug_file,"| ");
6845 for (j=i, k=0; k<16 && j<len; ++j, ++k)
6846 fprintf(ssl_debug_file,"%.2x ",data[j]);
6847 for (; k<16; ++k)
6848 fprintf(ssl_debug_file," ");
6849 fputc('|', ssl_debug_file);
6850 for (j=i, k=0; k<16 && j<len; ++j, ++k) {
6851 unsigned char c = data[j];
6852 if (!g_ascii_isprint(c)((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0) || (c=='\t')) c = '.';
6853 fputc(c, ssl_debug_file);
6854 }
6855 for (; k<16; ++k)
6856 fputc(' ', ssl_debug_file);
6857 fprintf(ssl_debug_file,"|\n");
6858 }
6859}
6860
6861void
6862ssl_print_string(const char* name, const StringInfo* data)
6863{
6864 ssl_print_data(name, data->data, data->data_len);
6865}
6866#endif /* SSL_DECRYPT_DEBUG }}} */
6867
6868/* UAT preferences callbacks. {{{ */
6869/* checks for SSL and DTLS UAT key list fields */
6870
6871bool_Bool
6872ssldecrypt_uat_fld_ip_chk_cb(void* r _U___attribute__((unused)), const char* p _U___attribute__((unused)), unsigned len _U___attribute__((unused)), const void* u1 _U___attribute__((unused)), const void* u2 _U___attribute__((unused)), char** err)
6873{
6874 // This should be removed in favor of Decode As. Make it optional.
6875 *err = NULL((void*)0);
6876 return true1;
6877}
6878
6879bool_Bool
6880ssldecrypt_uat_fld_port_chk_cb(void* r _U___attribute__((unused)), const char* p, unsigned len _U___attribute__((unused)), const void* u1 _U___attribute__((unused)), const void* u2 _U___attribute__((unused)), char** err)
6881{
6882 if (!p || strlen(p) == 0u) {
6883 // This should be removed in favor of Decode As. Make it optional.
6884 *err = NULL((void*)0);
6885 return true1;
6886 }
6887
6888 if (strcmp(p, "start_tls") != 0){
6889 uint16_t port;
6890 if (!ws_strtou16(p, NULL((void*)0), &port)) {
6891 *err = g_strdup("Invalid port given.")g_strdup_inline ("Invalid port given.");
6892 return false0;
6893 }
6894 }
6895
6896 *err = NULL((void*)0);
6897 return true1;
6898}
6899
6900bool_Bool
6901ssldecrypt_uat_fld_fileopen_chk_cb(void* r _U___attribute__((unused)), const char* p, unsigned len _U___attribute__((unused)), const void* u1 _U___attribute__((unused)), const void* u2 _U___attribute__((unused)), char** err)
6902{
6903 ws_statb64struct stat st;
6904
6905 if (!p || strlen(p) == 0u) {
6906 *err = g_strdup("No filename given.")g_strdup_inline ("No filename given.");
6907 return false0;
6908 } else {
6909 if (ws_stat64stat(p, &st) != 0) {
6910 *err = ws_strdup_printf("File '%s' does not exist or access is denied.", p)wmem_strdup_printf(((void*)0), "File '%s' does not exist or access is denied."
, p)
;
6911 return false0;
6912 }
6913 }
6914
6915 *err = NULL((void*)0);
6916 return true1;
6917}
6918
6919bool_Bool
6920ssldecrypt_uat_fld_password_chk_cb(void *r _U___attribute__((unused)), const char *p _U___attribute__((unused)), unsigned len _U___attribute__((unused)), const void *u1 _U___attribute__((unused)), const void *u2 _U___attribute__((unused)), char **err)
6921{
6922#if defined(HAVE_LIBGNUTLS1)
6923 ssldecrypt_assoc_t* f = (ssldecrypt_assoc_t *)r;
6924 FILE *fp = NULL((void*)0);
6925
6926 if (p && (strlen(p) > 0u)) {
6927 fp = ws_fopenfopen(f->keyfile, "rb");
6928 if (fp) {
6929 char *msg = NULL((void*)0);
6930 gnutls_x509_privkey_t priv_key = rsa_load_pkcs12(fp, p, &msg);
6931 if (!priv_key) {
6932 fclose(fp);
6933 *err = ws_strdup_printf("Could not load PKCS#12 key file: %s", msg)wmem_strdup_printf(((void*)0), "Could not load PKCS#12 key file: %s"
, msg)
;
6934 g_free(msg)(__builtin_object_size ((msg), 0) != ((size_t) - 1)) ? g_free_sized
(msg, __builtin_object_size ((msg), 0)) : (g_free) (msg)
;
6935 return false0;
6936 }
6937 g_free(msg)(__builtin_object_size ((msg), 0) != ((size_t) - 1)) ? g_free_sized
(msg, __builtin_object_size ((msg), 0)) : (g_free) (msg)
;
6938 gnutls_x509_privkey_deinit(priv_key);
6939 fclose(fp);
6940 } else {
6941 *err = ws_strdup_printf("Leave this field blank if the keyfile is not PKCS#12.")wmem_strdup_printf(((void*)0), "Leave this field blank if the keyfile is not PKCS#12."
)
;
6942 return false0;
6943 }
6944 }
6945
6946 *err = NULL((void*)0);
6947 return true1;
6948#else
6949 *err = g_strdup("Cannot load key files, support is not compiled in.")g_strdup_inline ("Cannot load key files, support is not compiled in."
)
;
6950 return false0;
6951#endif
6952}
6953/* UAT preferences callbacks. }}} */
6954
6955/** maximum size of ssl_association_info() string */
6956#define SSL_ASSOC_MAX_LEN8192 8192
6957
6958typedef struct ssl_association_info_callback_data
6959{
6960 char *str;
6961 const char *table_protocol;
6962} ssl_association_info_callback_data_t;
6963
6964/**
6965 * callback function used by ssl_association_info() to traverse the SSL associations.
6966 */
6967static void
6968ssl_association_info_(const char *table _U___attribute__((unused)), void *handle, void *user_data)
6969{
6970 ssl_association_info_callback_data_t* data = (ssl_association_info_callback_data_t*)user_data;
6971 const int l = (const int)strlen(data->str);
6972 snprintf(data->str+l, SSL_ASSOC_MAX_LEN8192-l, "'%s' (%s)\n", dissector_handle_get_dissector_name((dissector_handle_t)handle), dissector_handle_get_description((dissector_handle_t)handle));
6973}
6974
6975/**
6976 * @return an information string on the SSL protocol associations. The string must be freed.
6977 */
6978char*
6979ssl_association_info(const char* dissector_table_name, const char* table_protocol)
6980{
6981 ssl_association_info_callback_data_t data;
6982
6983 data.str = (char *)g_malloc0(SSL_ASSOC_MAX_LEN8192);
6984 data.table_protocol = table_protocol;
6985 dissector_table_foreach_handle(dissector_table_name, ssl_association_info_, &data);
6986 return data.str;
6987}
6988
6989
6990/** Begin of code related to dissection of wire data. */
6991
6992/* Helpers for dissecting Variable-Length Vectors. {{{ */
6993bool_Bool
6994ssl_add_vector(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
6995 unsigned offset, unsigned offset_end, uint32_t *ret_length,
6996 int hf_length, uint32_t min_value, uint32_t max_value)
6997{
6998 unsigned veclen_size;
6999 uint32_t veclen_value;
7000 proto_item *pi;
7001
7002 DISSECTOR_ASSERT_CMPUINT(min_value, <=, max_value)((void) ((min_value <= max_value) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion " "min_value" " " "<=" " " "max_value"
" (" "%" "l" "u" " " "<=" " " "%" "l" "u" ")", "epan/dissectors/packet-tls-utils.c"
, 7002, (uint64_t)min_value, (uint64_t)max_value))))
;
7003 if (offset > offset_end) {
7004 expert_add_info_format(pinfo, tree, &hf->ei.malformed_buffer_too_small,
7005 "Vector offset is past buffer end offset (%u > %u)",
7006 offset, offset_end);
7007 *ret_length = 0;
7008 return false0; /* Cannot read length. */
7009 }
7010
7011 if (max_value > 0xffffff) {
7012 veclen_size = 4;
7013 } else if (max_value > 0xffff) {
7014 veclen_size = 3;
7015 } else if (max_value > 0xff) {
7016 veclen_size = 2;
7017 } else {
7018 veclen_size = 1;
7019 }
7020
7021 if (offset_end - offset < veclen_size) {
7022 proto_tree_add_expert_format(tree, pinfo, &hf->ei.malformed_buffer_too_small,
7023 tvb, offset, offset_end - offset,
7024 "No more room for vector of length %u",
7025 veclen_size);
7026 *ret_length = 0;
7027 return false0; /* Cannot read length. */
7028 }
7029
7030 pi = proto_tree_add_item_ret_uint(tree, hf_length, tvb, offset, veclen_size, ENC_BIG_ENDIAN0x00000000, &veclen_value);
7031 offset += veclen_size;
7032
7033 if (veclen_value < min_value) {
7034 expert_add_info_format(pinfo, pi, &hf->ei.malformed_vector_length,
7035 "Vector length %u is smaller than minimum %u",
7036 veclen_value, min_value);
7037 } else if (veclen_value > max_value) {
7038 expert_add_info_format(pinfo, pi, &hf->ei.malformed_vector_length,
7039 "Vector length %u is larger than maximum %u",
7040 veclen_value, max_value);
7041 }
7042
7043 if (offset_end - offset < veclen_value) {
7044 expert_add_info_format(pinfo, pi, &hf->ei.malformed_buffer_too_small,
7045 "Vector length %u is too large, truncating it to %u",
7046 veclen_value, offset_end - offset);
7047 *ret_length = offset_end - offset;
7048 return false0; /* Length is truncated to avoid overflow. */
7049 }
7050
7051 *ret_length = veclen_value;
7052 return true1; /* Length is OK. */
7053}
7054
7055bool_Bool
7056ssl_end_vector(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
7057 unsigned offset, unsigned offset_end)
7058{
7059 if (offset < offset_end) {
7060 unsigned trailing = offset_end - offset;
7061 proto_tree_add_expert_format(tree, pinfo, &hf->ei.malformed_trailing_data,
7062 tvb, offset, trailing,
7063 "%u trailing byte%s unprocessed",
7064 trailing, plurality(trailing, " was", "s were")((trailing) == 1 ? (" was") : ("s were")));
7065 return false0; /* unprocessed data warning */
7066 } else if (offset > offset_end) {
7067 /*
7068 * Returned offset runs past the end. This should not happen and is
7069 * possibly a dissector bug.
7070 */
7071 unsigned excess = offset - offset_end;
7072 proto_tree_add_expert_format(tree, pinfo, &hf->ei.malformed_buffer_too_small,
7073 tvb, offset_end, excess,
7074 "Dissector processed too much data (%u byte%s)",
7075 excess, plurality(excess, "", "s")((excess) == 1 ? ("") : ("s")));
7076 return false0; /* overflow error */
7077 }
7078
7079 return true1; /* OK, offset matches. */
7080}
7081/** }}} */
7082
7083
7084static uint32_t
7085ssl_dissect_digitally_signed(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
7086 proto_tree *tree, uint32_t offset, uint32_t offset_end,
7087 uint16_t version, int hf_sig_len, int hf_sig);
7088
7089/* change_cipher_spec(20) dissection */
7090void
7091ssl_dissect_change_cipher_spec(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7092 packet_info *pinfo, proto_tree *tree,
7093 uint32_t offset, SslSession *session,
7094 bool_Bool is_from_server,
7095 const SslDecryptSession *ssl)
7096{
7097 /*
7098 * struct {
7099 * enum { change_cipher_spec(1), (255) } type;
7100 * } ChangeCipherSpec;
7101 */
7102 proto_item *ti;
7103 proto_item_set_text(tree,
7104 "%s Record Layer: %s Protocol: Change Cipher Spec",
7105 val_to_str_const(session->version, ssl_version_short_names, "SSL"),
7106 val_to_str_const(SSL_ID_CHG_CIPHER_SPEC, ssl_31_content_type, "unknown"));
7107 ti = proto_tree_add_item(tree, hf->hf.change_cipher_spec, tvb, offset, 1, ENC_NA0x00000000);
7108
7109 if (session->version == TLSV1DOT3_VERSION0x304) {
7110 /* CCS is a dummy message in TLS 1.3, do not parse it further. */
7111 return;
7112 }
7113
7114 /* Remember frame number of first CCS */
7115 uint32_t *ccs_frame = is_from_server ? &session->server_ccs_frame : &session->client_ccs_frame;
7116 if (*ccs_frame == 0 && !PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited))
7117 *ccs_frame = pinfo->num;
7118
7119 /* Use heuristics to detect an abbreviated handshake, assume that missing
7120 * ServerHelloDone implies reusing previously negotiating keys. Then when
7121 * a Session ID or ticket is present, it must be a resumed session.
7122 * Normally this should be done at the Finished message, but that may be
7123 * encrypted so we do it here, at the last cleartext message. */
7124 if (is_from_server && ssl) {
7125 if (session->is_session_resumed) {
7126 const char *resumed = NULL((void*)0);
7127 if (ssl->session_ticket.data_len) {
7128 resumed = "Session Ticket";
7129 } else if (ssl->session_id.data_len) {
7130 resumed = "Session ID";
7131 }
7132 if (resumed) {
7133 ssl_debug_printf("%s Session resumption using %s\n", G_STRFUNC((const char*) (__func__)), resumed);
7134 } else {
7135 /* Can happen if the capture somehow starts in the middle */
7136 ssl_debug_printf("%s No Session resumption, missing packets?\n", G_STRFUNC((const char*) (__func__)));
7137 }
7138 } else {
7139 ssl_debug_printf("%s Not using Session resumption\n", G_STRFUNC((const char*) (__func__)));
7140 }
7141 }
7142 if (is_from_server && session->is_session_resumed)
7143 expert_add_info(pinfo, ti, &hf->ei.resumed);
7144}
7145
7146/** Begin of handshake(22) record dissections */
7147
7148/* Dissects a SignatureScheme (TLS 1.3) or SignatureAndHashAlgorithm (TLS 1.2).
7149 * {{{ */
7150static void
7151tls_dissect_signature_algorithm(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree, uint32_t offset, ja4_data_t *ja4_data)
7152{
7153 uint32_t sighash, hashalg, sigalg;
7154 proto_item *ti_sigalg;
7155 proto_tree *sigalg_tree;
7156
7157 ti_sigalg = proto_tree_add_item_ret_uint(tree, hf->hf.hs_sig_hash_alg, tvb,
7158 offset, 2, ENC_BIG_ENDIAN0x00000000, &sighash);
7159 if (ja4_data && !IS_GREASE_TLS(sighash)((((sighash) & 0x0f0f) == 0x0a0a) && (((sighash) &
0xff) == (((sighash)>>8) & 0xff)))
) {
7160 wmem_list_append(ja4_data->sighash_list, GUINT_TO_POINTER(sighash)((gpointer) (gulong) (sighash)));
7161 }
7162
7163 sigalg_tree = proto_item_add_subtree(ti_sigalg, hf->ett.hs_sig_hash_alg);
7164
7165 /* TLS 1.2: SignatureAndHashAlgorithm { hash, signature } */
7166 proto_tree_add_item_ret_uint(sigalg_tree, hf->hf.hs_sig_hash_hash, tvb,
7167 offset, 1, ENC_BIG_ENDIAN0x00000000, &hashalg);
7168 proto_tree_add_item_ret_uint(sigalg_tree, hf->hf.hs_sig_hash_sig, tvb,
7169 offset + 1, 1, ENC_BIG_ENDIAN0x00000000, &sigalg);
7170
7171 /* No TLS 1.3 SignatureScheme? Fallback to TLS 1.2 interpretation. */
7172 if (!try_val_to_str(sighash, tls13_signature_algorithm)) {
7173 proto_item_set_text(ti_sigalg, "Signature Algorithm: %s %s (0x%04x)",
7174 val_to_str_const(hashalg, tls_hash_algorithm, "Unknown"),
7175 val_to_str_const(sigalg, tls_signature_algorithm, "Unknown"),
7176 sighash);
7177 }
7178} /* }}} */
7179
7180/* dissect a list of hash algorithms, return the number of bytes dissected
7181 this is used for the signature algorithms extension and for the
7182 TLS1.2 certificate request. {{{ */
7183static int
7184ssl_dissect_hash_alg_list(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
7185 packet_info* pinfo, uint32_t offset, uint32_t offset_end, ja4_data_t *ja4_data)
7186{
7187 /* https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1
7188 * struct {
7189 * HashAlgorithm hash;
7190 * SignatureAlgorithm signature;
7191 * } SignatureAndHashAlgorithm;
7192 * SignatureAndHashAlgorithm supported_signature_algorithms<2..2^16-2>;
7193 */
7194 proto_tree *subtree;
7195 proto_item *ti;
7196 unsigned sh_alg_length;
7197 uint32_t next_offset;
7198
7199 /* SignatureAndHashAlgorithm supported_signature_algorithms<2..2^16-2> */
7200 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &sh_alg_length,
7201 hf->hf.hs_sig_hash_alg_len, 2, UINT16_MAX(65535) - 1)) {
7202 return offset_end;
7203 }
7204 offset += 2;
7205 next_offset = offset + sh_alg_length;
7206
7207 ti = proto_tree_add_none_format(tree, hf->hf.hs_sig_hash_algs, tvb, offset, sh_alg_length,
7208 "Signature Hash Algorithms (%u algorithm%s)",
7209 sh_alg_length / 2, plurality(sh_alg_length / 2, "", "s")((sh_alg_length / 2) == 1 ? ("") : ("s")));
7210 subtree = proto_item_add_subtree(ti, hf->ett.hs_sig_hash_algs);
7211
7212 while (offset + 2 <= next_offset) {
7213 tls_dissect_signature_algorithm(hf, tvb, subtree, offset, ja4_data);
7214 offset += 2;
7215 }
7216
7217 if (!ssl_end_vector(hf, tvb, pinfo, subtree, offset, next_offset)) {
7218 offset = next_offset;
7219 }
7220
7221 return offset;
7222} /* }}} */
7223
7224/* Dissection of DistinguishedName (for CertificateRequest and
7225 * certificate_authorities extension). {{{ */
7226static uint32_t
7227tls_dissect_certificate_authorities(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
7228 proto_tree *tree, uint32_t offset, uint32_t offset_end)
7229{
7230 proto_item *ti;
7231 proto_tree *subtree;
7232 uint32_t dnames_length, next_offset;
7233 asn1_ctx_t asn1_ctx;
7234 int dnames_count = 100; /* the maximum number of DNs to add to the tree */
7235
7236 /* Note: minimum length is 0 for TLS 1.1/1.2 and 3 for earlier/later */
7237 /* DistinguishedName certificate_authorities<0..2^16-1> */
7238 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &dnames_length,
7239 hf->hf.hs_dnames_len, 0, UINT16_MAX(65535))) {
7240 return offset_end;
7241 }
7242 offset += 2;
7243 next_offset = offset + dnames_length;
7244
7245 if (dnames_length > 0) {
7246 ti = proto_tree_add_none_format(tree,
7247 hf->hf.hs_dnames,
7248 tvb, offset, dnames_length,
7249 "Distinguished Names (%d byte%s)",
7250 dnames_length,
7251 plurality(dnames_length, "", "s")((dnames_length) == 1 ? ("") : ("s")));
7252 subtree = proto_item_add_subtree(ti, hf->ett.dnames);
7253
7254 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true1, pinfo);
7255
7256 while (offset < next_offset) {
7257 /* get the length of the current certificate */
7258 uint32_t name_length;
7259
7260 if (dnames_count-- == 0) {
7261 /* stop adding to tree when the list is considered too large
7262 * https://gitlab.com/wireshark/wireshark/-/issues/16202
7263 Note: dnames_count must be set low enough not to hit the
7264 limit set by PINFO_LAYER_MAX_RECURSION_DEPTH in packet.c
7265 */
7266 ti = proto_tree_add_item(subtree, hf->hf.hs_dnames_truncated,
7267 tvb, offset, next_offset - offset, ENC_NA0x00000000);
7268 proto_item_set_generated(ti);
7269 return next_offset;
7270 }
7271
7272 /* opaque DistinguishedName<1..2^16-1> */
7273 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, next_offset, &name_length,
7274 hf->hf.hs_dname_len, 1, UINT16_MAX(65535))) {
7275 return next_offset;
7276 }
7277 offset += 2;
7278
7279 dissect_x509if_DistinguishedName(false0, tvb, offset, &asn1_ctx,
7280 subtree, hf->hf.hs_dname);
7281 offset += name_length;
7282 }
7283 }
7284 return offset;
7285} /* }}} */
7286
7287
7288/** TLS Extensions (in Client Hello and Server Hello). {{{ */
7289static int
7290ssl_dissect_hnd_hello_ext_sig_hash_algs(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7291 proto_tree *tree, packet_info* pinfo, uint32_t offset, uint32_t offset_end, ja4_data_t *ja4_data)
7292{
7293 return ssl_dissect_hash_alg_list(hf, tvb, tree, pinfo, offset, offset_end, ja4_data);
7294}
7295
7296static int
7297ssl_dissect_hnd_ext_delegated_credentials(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7298 proto_tree *tree, packet_info* pinfo, uint32_t offset, uint32_t offset_end, uint8_t hnd_type)
7299{
7300 if (hnd_type == SSL_HND_CLIENT_HELLO ||
7301 hnd_type == SSL_HND_CERT_REQUEST) {
7302 /*
7303 * struct {
7304 * SignatureScheme supported_signature_algorithm<2..2^16-2>;
7305 * } SignatureSchemeList;
7306 */
7307
7308 return ssl_dissect_hash_alg_list(hf, tvb, tree, pinfo, offset, offset_end, NULL((void*)0));
7309 } else {
7310 asn1_ctx_t asn1_ctx;
7311 unsigned pubkey_length, sign_length;
7312
7313 /*
7314 * struct {
7315 * uint32 valid_time;
7316 * SignatureScheme expected_cert_verify_algorithm;
7317 * opaque ASN1_subjectPublicKeyInfo<1..2^24-1>;
7318 * } Credential;
7319 *
7320 * struct {
7321 * Credential cred;
7322 * SignatureScheme algorithm;
7323 * opaque signature<0..2^16-1>;
7324 * } DelegatedCredential;
7325 */
7326
7327 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true1, pinfo);
7328
7329 proto_tree_add_item(tree, hf->hf.hs_cred_valid_time, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
7330 offset += 4;
7331
7332 tls_dissect_signature_algorithm(hf, tvb, tree, offset, NULL((void*)0));
7333 offset += 2;
7334
7335 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &pubkey_length,
7336 hf->hf.hs_cred_pubkey_len, 1, G_MAXUINT24((1U << 24) - 1))) {
7337 return offset_end;
7338 }
7339 offset += 3;
7340 dissect_x509af_SubjectPublicKeyInfo(false0, tvb, offset, &asn1_ctx, tree, hf->hf.hs_cred_pubkey);
7341 offset += pubkey_length;
7342
7343 tls_dissect_signature_algorithm(hf, tvb, tree, offset, NULL((void*)0));
7344 offset += 2;
7345
7346 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &sign_length,
7347 hf->hf.hs_cred_signature_len, 1, UINT16_MAX(65535))) {
7348 return offset_end;
7349 }
7350 offset += 2;
7351 proto_tree_add_item(tree, hf->hf.hs_cred_signature,
7352 tvb, offset, sign_length, ENC_ASCII0x00000000|ENC_NA0x00000000);
7353 offset += sign_length;
7354
7355 return offset;
7356 }
7357}
7358
7359static int
7360ssl_dissect_hnd_hello_ext_alps(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7361 packet_info *pinfo, proto_tree *tree,
7362 uint32_t offset, uint32_t offset_end,
7363 uint8_t hnd_type)
7364{
7365
7366 /* https://datatracker.ietf.org/doc/html/draft-vvv-tls-alps-01#section-4 */
7367
7368 switch (hnd_type) {
7369 case SSL_HND_CLIENT_HELLO: {
7370 proto_tree *alps_tree;
7371 proto_item *ti;
7372 uint32_t next_offset, alps_length, name_length;
7373
7374 /*
7375 * opaque ProtocolName<1..2^8-1>;
7376 * struct {
7377 * ProtocolName supported_protocols<2..2^16-1>
7378 * } ApplicationSettingsSupport;
7379 */
7380
7381 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &alps_length,
7382 hf->hf.hs_ext_alps_len, 2, UINT16_MAX(65535))) {
7383 return offset_end;
7384 }
7385 offset += 2;
7386 next_offset = offset + alps_length;
7387
7388 ti = proto_tree_add_item(tree, hf->hf.hs_ext_alps_alpn_list,
7389 tvb, offset, alps_length, ENC_NA0x00000000);
7390 alps_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_alps);
7391
7392 /* Parse list (note missing check for end of vector, ssl_add_vector below
7393 * ensures that data is always available.) */
7394 while (offset < next_offset) {
7395 if (!ssl_add_vector(hf, tvb, pinfo, alps_tree, offset, next_offset, &name_length,
7396 hf->hf.hs_ext_alps_alpn_str_len, 1, UINT8_MAX(255))) {
7397 return next_offset;
7398 }
7399 offset++;
7400
7401 proto_tree_add_item(alps_tree, hf->hf.hs_ext_alps_alpn_str,
7402 tvb, offset, name_length, ENC_ASCII0x00000000|ENC_NA0x00000000);
7403 offset += name_length;
7404 }
7405
7406 return offset;
7407 }
7408 case SSL_HND_ENCRYPTED_EXTS:
7409 /* Opaque blob */
7410 proto_tree_add_item(tree, hf->hf.hs_ext_alps_settings,
7411 tvb, offset, offset_end - offset, ENC_ASCII0x00000000|ENC_NA0x00000000);
7412 break;
7413 }
7414
7415 return offset_end;
7416}
7417
7418static int
7419ssl_dissect_hnd_hello_ext_alpn(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7420 packet_info *pinfo, proto_tree *tree,
7421 uint32_t offset, uint32_t offset_end,
7422 uint8_t hnd_type, SslSession *session,
7423 bool_Bool is_dtls, ja4_data_t *ja4_data)
7424{
7425
7426 /* https://tools.ietf.org/html/rfc7301#section-3.1
7427 * opaque ProtocolName<1..2^8-1>;
7428 * struct {
7429 * ProtocolName protocol_name_list<2..2^16-1>
7430 * } ProtocolNameList;
7431 */
7432 proto_tree *alpn_tree;
7433 proto_item *ti;
7434 uint32_t next_offset, alpn_length, name_length;
7435 const char *proto_name = NULL((void*)0), *client_proto_name = NULL((void*)0);
7436
7437 /* ProtocolName protocol_name_list<2..2^16-1> */
7438 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &alpn_length,
7439 hf->hf.hs_ext_alpn_len, 2, UINT16_MAX(65535))) {
7440 return offset_end;
7441 }
7442 offset += 2;
7443 next_offset = offset + alpn_length;
7444
7445 ti = proto_tree_add_item(tree, hf->hf.hs_ext_alpn_list,
7446 tvb, offset, alpn_length, ENC_NA0x00000000);
7447 alpn_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_alpn);
7448
7449 /* Parse list (note missing check for end of vector, ssl_add_vector below
7450 * ensures that data is always available.) */
7451 while (offset < next_offset) {
7452 /* opaque ProtocolName<1..2^8-1> */
7453 if (!ssl_add_vector(hf, tvb, pinfo, alpn_tree, offset, next_offset, &name_length,
7454 hf->hf.hs_ext_alpn_str_len, 1, UINT8_MAX(255))) {
7455 return next_offset;
7456 }
7457 offset++;
7458
7459 proto_tree_add_item(alpn_tree, hf->hf.hs_ext_alpn_str,
7460 tvb, offset, name_length, ENC_ASCII0x00000000|ENC_NA0x00000000);
7461 if (ja4_data && wmem_strbuf_get_len(ja4_data->alpn) == 0) {
7462 const char alpn_first_char = (char)tvb_get_uint8(tvb,offset);
7463 const char alpn_last_char = (char)tvb_get_uint8(tvb,offset + name_length - 1);
7464 if ((g_ascii_isalnum(alpn_first_char)((g_ascii_table[(guchar) (alpn_first_char)] & G_ASCII_ALNUM
) != 0)
) && g_ascii_isalnum(alpn_last_char)((g_ascii_table[(guchar) (alpn_last_char)] & G_ASCII_ALNUM
) != 0)
) {
7465 wmem_strbuf_append_printf(ja4_data->alpn, "%c%c", alpn_first_char, alpn_last_char);
7466 }
7467 else {
7468 wmem_strbuf_append_printf(ja4_data->alpn, "%x%x",(alpn_first_char >> 4) & 0x0F,
7469 alpn_last_char & 0x0F);
7470 }
7471 }
7472 /* Remember first ALPN ProtocolName entry for server. */
7473 if (hnd_type == SSL_HND_SERVER_HELLO || hnd_type == SSL_HND_ENCRYPTED_EXTENSIONS) {
7474 /* '\0'-terminated string for dissector table match and prefix
7475 * comparison purposes. */
7476 proto_name = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset,
7477 name_length, ENC_ASCII0x00000000);
7478 } else if (hnd_type == SSL_HND_CLIENT_HELLO) {
7479 client_proto_name = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset,
7480 name_length, ENC_ASCII0x00000000);
7481 }
7482 offset += name_length;
7483 }
7484
7485 /* If ALPN is given in ServerHello, then ProtocolNameList MUST contain
7486 * exactly one "ProtocolName". */
7487 if (proto_name) {
7488 dissector_handle_t handle;
7489
7490 if (!PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited))
7491 session->alpn_name = wmem_strdup(wmem_file_scope(), proto_name);
7492
7493 if (is_dtls) {
7494 handle = dissector_get_string_handle(dtls_alpn_dissector_table,
7495 proto_name);
7496 } else {
7497 handle = dissector_get_string_handle(ssl_alpn_dissector_table,
7498 proto_name);
7499 if (handle == NULL((void*)0)) {
7500 /* Try prefix matching */
7501 for (size_t i = 0; i < G_N_ELEMENTS(ssl_alpn_prefix_match_protocols)(sizeof (ssl_alpn_prefix_match_protocols) / sizeof ((ssl_alpn_prefix_match_protocols
)[0]))
; i++) {
7502 const ssl_alpn_prefix_match_protocol_t *alpn_proto = &ssl_alpn_prefix_match_protocols[i];
7503
7504 /* string_string is inappropriate as it compares strings
7505 * while "byte strings MUST NOT be truncated" (RFC 7301) */
7506 if (g_str_has_prefix(proto_name, alpn_proto->proto_prefix)(__builtin_constant_p (alpn_proto->proto_prefix)? __extension__
({ const char * const __str = (proto_name); const char * const
__prefix = (alpn_proto->proto_prefix); gboolean __result =
(0); if (__str == ((void*)0) || __prefix == ((void*)0)) __result
= (g_str_has_prefix) (__str, __prefix); else { const size_t __str_len
= strlen (((__str) + !(__str))); const size_t __prefix_len =
strlen (((__prefix) + !(__prefix))); if (__str_len >= __prefix_len
) __result = memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix
)), __prefix_len) == 0; } __result; }) : (g_str_has_prefix) (
proto_name, alpn_proto->proto_prefix) )
) {
7507 handle = find_dissector(alpn_proto->dissector_name);
7508 break;
7509 }
7510 }
7511 }
7512 }
7513 if (handle != NULL((void*)0) && !PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
7514 /* ProtocolName match, so set the App data dissector handle.
7515 * This may override protocols given via the UAT dialog, but
7516 * since the ALPN hint is precise, do it anyway. */
7517 ssl_debug_printf("%s: changing handle %p to %p (%s)", G_STRFUNC((const char*) (__func__)),
7518 (void *)session->app_handle,
7519 (void *)handle,
7520 dissector_handle_get_dissector_name(handle));
7521 session->app_handle = handle;
7522 }
7523 } else if (client_proto_name && !PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
7524 // No current use for looking up the handle as the only consumer of this API is currently the QUIC dissector
7525 // and it just needs the string since there are/were various HTTP/3 ALPNs to check for.
7526 session->client_alpn_name = wmem_strdup(wmem_file_scope(), client_proto_name);
7527 }
7528
7529 return offset;
7530}
7531
7532static int
7533ssl_dissect_hnd_hello_ext_npn(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7534 packet_info *pinfo, proto_tree *tree,
7535 uint32_t offset, uint32_t offset_end)
7536{
7537 /* https://tools.ietf.org/html/draft-agl-tls-nextprotoneg-04#page-3
7538 * The "extension_data" field of a "next_protocol_negotiation" extension
7539 * in a "ServerHello" contains an optional list of protocols advertised
7540 * by the server. Protocols are named by opaque, non-empty byte strings
7541 * and the list of protocols is serialized as a concatenation of 8-bit,
7542 * length prefixed byte strings. Implementations MUST ensure that the
7543 * empty string is not included and that no byte strings are truncated.
7544 */
7545 uint32_t npn_length;
7546 proto_tree *npn_tree;
7547
7548 /* List is optional, do not add tree if there are no entries. */
7549 if (offset == offset_end) {
7550 return offset;
7551 }
7552
7553 npn_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset, hf->ett.hs_ext_npn, NULL((void*)0), "Next Protocol Negotiation");
7554
7555 while (offset < offset_end) {
7556 /* non-empty, 8-bit length prefixed strings means range 1..255 */
7557 if (!ssl_add_vector(hf, tvb, pinfo, npn_tree, offset, offset_end, &npn_length,
7558 hf->hf.hs_ext_npn_str_len, 1, UINT8_MAX(255))) {
7559 return offset_end;
7560 }
7561 offset++;
7562
7563 proto_tree_add_item(npn_tree, hf->hf.hs_ext_npn_str,
7564 tvb, offset, npn_length, ENC_ASCII0x00000000|ENC_NA0x00000000);
7565 offset += npn_length;
7566 }
7567
7568 return offset;
7569}
7570
7571static int
7572ssl_dissect_hnd_hello_ext_reneg_info(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7573 packet_info *pinfo, proto_tree *tree,
7574 uint32_t offset, uint32_t offset_end)
7575{
7576 /* https://tools.ietf.org/html/rfc5746#section-3.2
7577 * struct {
7578 * opaque renegotiated_connection<0..255>;
7579 * } RenegotiationInfo;
7580 *
7581 */
7582 proto_tree *reneg_info_tree;
7583 uint32_t reneg_info_length;
7584
7585 reneg_info_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset, hf->ett.hs_ext_reneg_info, NULL((void*)0), "Renegotiation Info extension");
7586
7587 /* opaque renegotiated_connection<0..255> */
7588 if (!ssl_add_vector(hf, tvb, pinfo, reneg_info_tree, offset, offset_end, &reneg_info_length,
7589 hf->hf.hs_ext_reneg_info_len, 0, 255)) {
7590 return offset_end;
7591 }
7592 offset++;
7593
7594 if (reneg_info_length > 0) {
7595 proto_tree_add_item(reneg_info_tree, hf->hf.hs_ext_reneg_info, tvb, offset, reneg_info_length, ENC_NA0x00000000);
7596 offset += reneg_info_length;
7597 }
7598
7599 return offset;
7600}
7601
7602static int
7603ssl_dissect_hnd_hello_ext_key_share_entry(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
7604 proto_tree *tree, uint32_t offset, uint32_t offset_end,
7605 const char **group_name_out)
7606{
7607 /* RFC 8446 Section 4.2.8
7608 * struct {
7609 * NamedGroup group;
7610 * opaque key_exchange<1..2^16-1>;
7611 * } KeyShareEntry;
7612 */
7613 uint32_t key_exchange_length, group;
7614 proto_tree *ks_tree;
7615
7616 ks_tree = proto_tree_add_subtree(tree, tvb, offset, 4, hf->ett.hs_ext_key_share_ks, NULL((void*)0), "Key Share Entry");
7617
7618 proto_tree_add_item_ret_uint(ks_tree, hf->hf.hs_ext_key_share_group, tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &group);
7619 offset += 2;
7620 const char *group_name = val_to_str(pinfo->pool, group, ssl_extension_curves, "Unknown (%u)");
7621 proto_item_append_text(ks_tree, ": Group: %s", group_name);
7622 if (group_name_out) {
7623 *group_name_out = !IS_GREASE_TLS(group)((((group) & 0x0f0f) == 0x0a0a) && (((group) &
0xff) == (((group)>>8) & 0xff)))
? group_name : NULL((void*)0);
7624 }
7625
7626 /* opaque key_exchange<1..2^16-1> */
7627 if (!ssl_add_vector(hf, tvb, pinfo, ks_tree, offset, offset_end, &key_exchange_length,
7628 hf->hf.hs_ext_key_share_key_exchange_length, 1, UINT16_MAX(65535))) {
7629 return offset_end; /* Bad (possible truncated) length, skip to end of KeyShare extension. */
7630 }
7631 offset += 2;
7632 proto_item_set_len(ks_tree, 2 + 2 + key_exchange_length);
7633 proto_item_append_text(ks_tree, ", Key Exchange length: %u", key_exchange_length);
7634
7635 proto_tree_add_item(ks_tree, hf->hf.hs_ext_key_share_key_exchange, tvb, offset, key_exchange_length, ENC_NA0x00000000);
7636 offset += key_exchange_length;
7637
7638 return offset;
7639}
7640
7641static int
7642ssl_dissect_hnd_hello_ext_key_share(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
7643 proto_tree *tree, uint32_t offset, uint32_t offset_end,
7644 uint8_t hnd_type, SslDecryptSession *ssl)
7645{
7646 proto_tree *key_share_tree;
7647 uint32_t next_offset;
7648 uint32_t client_shares_length;
7649 uint32_t group;
7650 const char *group_name = NULL((void*)0);
7651
7652 if (offset_end <= offset) { /* Check if ext_len == 0 and "overflow" (offset + ext_len) > uint32_t) */
7653 return offset;
7654 }
7655
7656 key_share_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset, hf->ett.hs_ext_key_share, NULL((void*)0), "Key Share extension");
7657
7658 switch(hnd_type){
7659 case SSL_HND_CLIENT_HELLO:
7660 /* KeyShareEntry client_shares<0..2^16-1> */
7661 if (!ssl_add_vector(hf, tvb, pinfo, key_share_tree, offset, offset_end, &client_shares_length,
7662 hf->hf.hs_ext_key_share_client_length, 0, UINT16_MAX(65535))) {
7663 return offset_end;
7664 }
7665 offset += 2;
7666 next_offset = offset + client_shares_length;
7667 const char *sep = " ";
7668 while (offset + 4 <= next_offset) { /* (NamedGroup (2 bytes), key_exchange (1 byte for length, 1 byte minimum data) */
7669 offset = ssl_dissect_hnd_hello_ext_key_share_entry(hf, tvb, pinfo, key_share_tree, offset, next_offset, &group_name);
7670 if (group_name) {
7671 proto_item_append_text(tree, "%s%s", sep, group_name);
7672 sep = ", ";
7673 }
7674 }
7675 if (!ssl_end_vector(hf, tvb, pinfo, key_share_tree, offset, next_offset)) {
7676 return next_offset;
7677 }
7678 break;
7679 case SSL_HND_SERVER_HELLO:
7680 if (ssl) {
7681 ssl->has_key_share = true1;
7682 }
7683 offset = ssl_dissect_hnd_hello_ext_key_share_entry(hf, tvb, pinfo, key_share_tree, offset, offset_end, &group_name);
7684 if (group_name) {
7685 proto_item_append_text(tree, " %s", group_name);
7686 }
7687 break;
7688 case SSL_HND_HELLO_RETRY_REQUEST:
7689 proto_tree_add_item_ret_uint(key_share_tree, hf->hf.hs_ext_key_share_selected_group, tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &group);
7690 offset += 2;
7691 group_name = val_to_str(pinfo->pool, group, ssl_extension_curves, "Unknown (%u)");
7692 proto_item_append_text(tree, " %s", group_name);
7693 break;
7694 default: /* no default */
7695 break;
7696 }
7697
7698 return offset;
7699}
7700
7701static int
7702ssl_dissect_hnd_hello_ext_pre_shared_key(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
7703 proto_tree *tree, uint32_t offset, uint32_t offset_end,
7704 uint8_t hnd_type, SslDecryptSession *ssl)
7705{
7706 /* RFC 8446 Section 4.2.11
7707 * struct {
7708 * opaque identity<1..2^16-1>;
7709 * uint32 obfuscated_ticket_age;
7710 * } PskIdentity;
7711 * opaque PskBinderEntry<32..255>;
7712 * struct {
7713 * select (Handshake.msg_type) {
7714 * case client_hello:
7715 * PskIdentity identities<7..2^16-1>;
7716 * PskBinderEntry binders<33..2^16-1>;
7717 * case server_hello:
7718 * uint16 selected_identity;
7719 * };
7720 * } PreSharedKeyExtension;
7721 */
7722
7723 proto_tree *psk_tree;
7724
7725 psk_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset, hf->ett.hs_ext_pre_shared_key, NULL((void*)0), "Pre-Shared Key extension");
7726
7727 switch (hnd_type){
7728 case SSL_HND_CLIENT_HELLO: {
7729 uint32_t identities_length, identities_end, binders_length;
7730
7731 /* PskIdentity identities<7..2^16-1> */
7732 if (!ssl_add_vector(hf, tvb, pinfo, psk_tree, offset, offset_end, &identities_length,
7733 hf->hf.hs_ext_psk_identities_length, 7, UINT16_MAX(65535))) {
7734 return offset_end;
7735 }
7736 offset += 2;
7737 identities_end = offset + identities_length;
7738
7739 while (offset < identities_end) {
7740 uint32_t identity_length;
7741 proto_tree *identity_tree;
7742
7743 identity_tree = proto_tree_add_subtree(psk_tree, tvb, offset, 4, hf->ett.hs_ext_psk_identity, NULL((void*)0), "PSK Identity (");
7744
7745 /* opaque identity<1..2^16-1> */
7746 if (!ssl_add_vector(hf, tvb, pinfo, identity_tree, offset, identities_end, &identity_length,
7747 hf->hf.hs_ext_psk_identity_identity_length, 1, UINT16_MAX(65535))) {
7748 return identities_end;
7749 }
7750 offset += 2;
7751 proto_item_append_text(identity_tree, "length: %u)", identity_length);
7752
7753 proto_tree_add_item(identity_tree, hf->hf.hs_ext_psk_identity_identity, tvb, offset, identity_length, ENC_BIG_ENDIAN0x00000000);
7754 offset += identity_length;
7755
7756 proto_tree_add_item(identity_tree, hf->hf.hs_ext_psk_identity_obfuscated_ticket_age, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
7757 offset += 4;
7758
7759 proto_item_set_len(identity_tree, 2 + identity_length + 4);
7760 }
7761 if (!ssl_end_vector(hf, tvb, pinfo, psk_tree, offset, identities_end)) {
7762 offset = identities_end;
7763 }
7764
7765 /* PskBinderEntry binders<33..2^16-1> */
7766 if (!ssl_add_vector(hf, tvb, pinfo, psk_tree, offset, offset_end, &binders_length,
7767 hf->hf.hs_ext_psk_binders_length, 33, UINT16_MAX(65535))) {
7768 return offset_end;
7769 }
7770 offset += 2;
7771
7772 proto_item *binders_item;
7773 proto_tree *binders_tree;
7774 binders_item = proto_tree_add_item(psk_tree, hf->hf.hs_ext_psk_binders, tvb, offset, binders_length, ENC_NA0x00000000);
7775 binders_tree = proto_item_add_subtree(binders_item, hf->ett.hs_ext_psk_binders);
7776 uint32_t binders_end = offset + binders_length;
7777 while (offset < binders_end) {
7778 uint32_t binder_length;
7779 proto_item *binder_item;
7780 proto_tree *binder_tree;
7781
7782 binder_item = proto_tree_add_item(binders_tree, hf->hf.hs_ext_psk_binder, tvb, offset, 1, ENC_NA0x00000000);
7783 binder_tree = proto_item_add_subtree(binder_item, hf->ett.hs_ext_psk_binder);
7784
7785 /* opaque PskBinderEntry<32..255>; */
7786 if (!ssl_add_vector(hf, tvb, pinfo, binder_tree, offset, binders_end, &binder_length,
7787 hf->hf.hs_ext_psk_binder_binder_length, 32, 255)) {
7788 return binders_end;
7789 }
7790 offset += 1;
7791 proto_item_append_text(binder_tree, " (length: %u)", binder_length);
7792
7793 proto_tree_add_item(binder_tree, hf->hf.hs_ext_psk_binder_binder, tvb, offset, binder_length, ENC_BIG_ENDIAN0x00000000);
7794 offset += binder_length;
7795
7796 proto_item_set_end(binder_item, tvb, offset);
7797 }
7798 }
7799 break;
7800 case SSL_HND_SERVER_HELLO: {
7801 if (ssl) {
7802 ssl_debug_printf("%s found pre_shared_key extension\n", G_STRFUNC((const char*) (__func__)));
7803 ssl->has_psk = true1;
7804 }
7805 proto_tree_add_item(psk_tree, hf->hf.hs_ext_psk_identity_selected, tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
7806 offset += 2;
7807 }
7808 break;
7809 default:
7810 break;
7811 }
7812
7813 return offset;
7814}
7815
7816static uint32_t
7817ssl_dissect_hnd_hello_ext_early_data(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo _U___attribute__((unused)),
7818 proto_tree *tree, uint32_t offset, uint32_t offset_end _U___attribute__((unused)),
7819 uint8_t hnd_type, SslDecryptSession *ssl)
7820{
7821 /* RFC 8446 Section 4.2.10
7822 * struct {} Empty;
7823 * struct {
7824 * select (Handshake.msg_type) {
7825 * case new_session_ticket: uint32 max_early_data_size;
7826 * case client_hello: Empty;
7827 * case encrypted_extensions: Empty;
7828 * };
7829 * } EarlyDataIndication;
7830 */
7831 switch (hnd_type) {
7832 case SSL_HND_CLIENT_HELLO:
7833 /* Remember that early_data will follow the handshake. */
7834 if (ssl) {
7835 ssl_debug_printf("%s found early_data extension\n", G_STRFUNC((const char*) (__func__)));
7836 ssl->has_early_data = true1;
7837 }
7838 break;
7839 case SSL_HND_NEWSESSION_TICKET:
7840 proto_tree_add_item(tree, hf->hf.hs_ext_max_early_data_size, tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
7841 offset += 4;
7842 break;
7843 default:
7844 break;
7845 }
7846 return offset;
7847}
7848
7849static uint16_t
7850tls_try_get_version(bool_Bool is_dtls, uint16_t version, uint8_t *draft_version)
7851{
7852 if (draft_version) {
7853 *draft_version = 0;
7854 }
7855 if (!is_dtls) {
7856 uint8_t tls13_draft = extract_tls13_draft_version(version);
7857 if (tls13_draft != 0) {
7858 /* This is TLS 1.3 (a draft version). */
7859 if (draft_version) {
7860 *draft_version = tls13_draft;
7861 }
7862 version = TLSV1DOT3_VERSION0x304;
7863 }
7864 if (version == 0xfb17 || version == 0xfb1a) {
7865 /* Unofficial TLS 1.3 draft version for Facebook fizz. */
7866 tls13_draft = (uint8_t)version;
7867 if (draft_version) {
7868 *draft_version = tls13_draft;
7869 }
7870 version = TLSV1DOT3_VERSION0x304;
7871 }
7872 }
7873
7874 switch (version) {
7875 case SSLV3_VERSION0x300:
7876 case TLSV1_VERSION0x301:
7877 case TLSV1DOT1_VERSION0x302:
7878 case TLSV1DOT2_VERSION0x303:
7879 case TLSV1DOT3_VERSION0x304:
7880 case TLCPV1_VERSION0x101:
7881 if (is_dtls)
7882 return SSL_VER_UNKNOWN0;
7883 break;
7884
7885 case DTLSV1DOT0_VERSION0xfeff:
7886 case DTLSV1DOT0_OPENSSL_VERSION0x100:
7887 case DTLSV1DOT2_VERSION0xfefd:
7888 case DTLSV1DOT3_VERSION0xfefc:
7889 if (!is_dtls)
7890 return SSL_VER_UNKNOWN0;
7891 break;
7892
7893 default: /* invalid version number */
7894 return SSL_VER_UNKNOWN0;
7895 }
7896
7897 return version;
7898}
7899
7900static int
7901ssl_dissect_hnd_hello_ext_supported_versions(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
7902 proto_tree *tree, uint32_t offset, uint32_t offset_end,
7903 SslSession *session, bool_Bool is_dtls, ja4_data_t *ja4_data)
7904{
7905
7906 /* RFC 8446 Section 4.2.1
7907 * struct {
7908 * ProtocolVersion versions<2..254>; // ClientHello
7909 * } SupportedVersions;
7910 * Note that ServerHello and HelloRetryRequest are handled by the caller.
7911 */
7912 uint32_t versions_length, next_offset;
7913 /* ProtocolVersion versions<2..254> */
7914 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &versions_length,
7915 hf->hf.hs_ext_supported_versions_len, 2, 254)) {
7916 return offset_end;
7917 }
7918 offset++;
7919 next_offset = offset + versions_length;
7920
7921 unsigned version;
7922 unsigned current_version, lowest_version = SSL_VER_UNKNOWN0;
7923 uint8_t draft_version, max_draft_version = 0;
7924 const char *sep = " ";
7925 while (offset + 2 <= next_offset) {
7926 proto_tree_add_item_ret_uint(tree, hf->hf.hs_ext_supported_version, tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &version);
7927 offset += 2;
7928
7929 if (!IS_GREASE_TLS(version)((((version) & 0x0f0f) == 0x0a0a) && (((version) &
0xff) == (((version)>>8) & 0xff)))
) {
7930 proto_item_append_text(tree, "%s%s", sep, val_to_str(pinfo->pool, version, ssl_versions, "Unknown (0x%04x)"));
7931 sep = ", ";
7932 }
7933
7934 current_version = tls_try_get_version(is_dtls, version, &draft_version);
7935 if (session->version == SSL_VER_UNKNOWN0) {
7936 if (lowest_version == SSL_VER_UNKNOWN0) {
7937 lowest_version = current_version;
7938 } else if (current_version != SSL_VER_UNKNOWN0) {
7939 if (!is_dtls) {
7940 lowest_version = MIN(lowest_version, current_version)(((lowest_version) < (current_version)) ? (lowest_version)
: (current_version))
;
7941 } else {
7942 lowest_version = MAX(lowest_version, current_version)(((lowest_version) > (current_version)) ? (lowest_version)
: (current_version))
;
7943 }
7944 }
7945 }
7946 max_draft_version = MAX(draft_version, max_draft_version)(((draft_version) > (max_draft_version)) ? (draft_version)
: (max_draft_version))
;
7947 if (ja4_data && !IS_GREASE_TLS(version)((((version) & 0x0f0f) == 0x0a0a) && (((version) &
0xff) == (((version)>>8) & 0xff)))
) {
7948 /* The DTLS version numbers get mapped to "00" for unknown per
7949 * JA4 spec, but if JA4 ever does support DTLS we'll probably
7950 * need to take the MIN instead of MAX here for DTLS.
7951 */
7952 ja4_data->max_version = MAX(version, ja4_data->max_version)(((version) > (ja4_data->max_version)) ? (version) : (ja4_data
->max_version))
;
7953 }
7954 }
7955 if (session->version == SSL_VER_UNKNOWN0 && lowest_version != SSL_VER_UNKNOWN0) {
7956 col_set_str(pinfo->cinfo, COL_PROTOCOL,
7957 val_to_str_const(version, ssl_version_short_names, is_dtls ? "DTLS" : "TLS"));
7958 }
7959 if (!ssl_end_vector(hf, tvb, pinfo, tree, offset, next_offset)) {
7960 offset = next_offset;
7961 }
7962
7963 /* XXX remove this when draft 19 support is dropped,
7964 * this is only required for early data decryption. */
7965 if (max_draft_version) {
7966 session->tls13_draft_version = max_draft_version;
7967 }
7968
7969 return offset;
7970}
7971
7972static int
7973ssl_dissect_hnd_hello_ext_cookie(ssl_common_dissect_t *hf, tvbuff_t *tvb,
7974 packet_info *pinfo, proto_tree *tree,
7975 uint32_t offset, uint32_t offset_end)
7976{
7977 /* RFC 8446 Section 4.2.2
7978 * struct {
7979 * opaque cookie<1..2^16-1>;
7980 * } Cookie;
7981 */
7982 uint32_t cookie_length;
7983 /* opaque cookie<1..2^16-1> */
7984 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &cookie_length,
7985 hf->hf.hs_ext_cookie_len, 1, UINT16_MAX(65535))) {
7986 return offset_end;
7987 }
7988 offset += 2;
7989
7990 proto_tree_add_item(tree, hf->hf.hs_ext_cookie, tvb, offset, cookie_length, ENC_NA0x00000000);
7991 offset += cookie_length;
7992
7993 return offset;
7994}
7995
7996static int
7997ssl_dissect_hnd_hello_ext_psk_key_exchange_modes(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
7998 proto_tree *tree, uint32_t offset, uint32_t offset_end)
7999{
8000 /* RFC 8446 Section 4.2.9
8001 * enum { psk_ke(0), psk_dhe_ke(1), (255) } PskKeyExchangeMode;
8002 *
8003 * struct {
8004 * PskKeyExchangeMode ke_modes<1..255>;
8005 * } PskKeyExchangeModes;
8006 */
8007 uint32_t ke_modes_length, next_offset;
8008
8009 /* PskKeyExchangeMode ke_modes<1..255> */
8010 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &ke_modes_length,
8011 hf->hf.hs_ext_psk_ke_modes_length, 1, 255)) {
8012 return offset_end;
8013 }
8014 offset++;
8015 next_offset = offset + ke_modes_length;
8016
8017 while (offset < next_offset) {
8018 proto_tree_add_item(tree, hf->hf.hs_ext_psk_ke_mode, tvb, offset, 1, ENC_NA0x00000000);
8019 offset++;
8020 }
8021
8022 return offset;
8023}
8024
8025static uint32_t
8026ssl_dissect_hnd_hello_ext_certificate_authorities(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
8027 proto_tree *tree, uint32_t offset, uint32_t offset_end)
8028{
8029 /* RFC 8446 Section 4.2.4
8030 * opaque DistinguishedName<1..2^16-1>;
8031 * struct {
8032 * DistinguishedName authorities<3..2^16-1>;
8033 * } CertificateAuthoritiesExtension;
8034 */
8035 return tls_dissect_certificate_authorities(hf, tvb, pinfo, tree, offset, offset_end);
8036}
8037
8038static int
8039ssl_dissect_hnd_hello_ext_oid_filters(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
8040 proto_tree *tree, uint32_t offset, uint32_t offset_end)
8041{
8042 /* RFC 8446 Section 4.2.5
8043 * struct {
8044 * opaque certificate_extension_oid<1..2^8-1>;
8045 * opaque certificate_extension_values<0..2^16-1>;
8046 * } OIDFilter;
8047 * struct {
8048 * OIDFilter filters<0..2^16-1>;
8049 * } OIDFilterExtension;
8050 */
8051 proto_tree *subtree;
8052 uint32_t filters_length, oid_length, values_length, value_offset;
8053 asn1_ctx_t asn1_ctx;
8054 const char *oid, *name;
8055
8056 /* OIDFilter filters<0..2^16-1> */
8057 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &filters_length,
8058 hf->hf.hs_ext_psk_ke_modes_length, 0, UINT16_MAX(65535))) {
8059 return offset_end;
8060 }
8061 offset += 2;
8062 offset_end = offset + filters_length;
8063
8064 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true1, pinfo);
8065
8066 while (offset < offset_end) {
8067 subtree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset,
8068 hf->ett.hs_ext_oid_filter, NULL((void*)0), "OID Filter");
8069
8070 /* opaque certificate_extension_oid<1..2^8-1> */
8071 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, offset_end, &oid_length,
8072 hf->hf.hs_ext_oid_filters_oid_length, 1, UINT8_MAX(255))) {
8073 return offset_end;
8074 }
8075 offset++;
8076 dissect_ber_object_identifier_str(false0, &asn1_ctx, subtree, tvb, offset,
8077 hf->hf.hs_ext_oid_filters_oid, &oid);
8078 offset += oid_length;
8079
8080 /* Append OID to tree label */
8081 name = oid_resolved_from_string(pinfo->pool, oid);
8082 proto_item_append_text(subtree, " (%s)", name ? name : oid);
8083
8084 /* opaque certificate_extension_values<0..2^16-1> */
8085 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, offset_end, &values_length,
8086 hf->hf.hs_ext_oid_filters_values_length, 0, UINT16_MAX(65535))) {
8087 return offset_end;
8088 }
8089 offset += 2;
8090 proto_item_set_len(subtree, 1 + oid_length + 2 + values_length);
8091 if (values_length > 0) {
8092 value_offset = offset;
8093 value_offset = dissect_ber_identifier(pinfo, subtree, tvb, value_offset, NULL((void*)0), NULL((void*)0), NULL((void*)0));
8094 value_offset = dissect_ber_length(pinfo, subtree, tvb, value_offset, NULL((void*)0), NULL((void*)0));
8095 call_ber_oid_callback(oid, tvb, value_offset, pinfo, subtree, NULL((void*)0));
8096 }
8097 offset += values_length;
8098 }
8099
8100 return offset;
8101}
8102
8103static int
8104ssl_dissect_hnd_hello_ext_server_name(ssl_common_dissect_t *hf, tvbuff_t *tvb,
8105 packet_info *pinfo, proto_tree *tree,
8106 uint32_t offset, uint32_t offset_end)
8107{
8108 /* https://tools.ietf.org/html/rfc6066#section-3
8109 *
8110 * struct {
8111 * NameType name_type;
8112 * select (name_type) {
8113 * case host_name: HostName;
8114 * } name;
8115 * } ServerName;
8116 *
8117 * enum {
8118 * host_name(0), (255)
8119 * } NameType;
8120 *
8121 * opaque HostName<1..2^16-1>;
8122 *
8123 * struct {
8124 * ServerName server_name_list<1..2^16-1>
8125 * } ServerNameList;
8126 */
8127 proto_tree *server_name_tree;
8128 uint32_t list_length, server_name_length, next_offset;
8129
8130 /* The server SHALL include "server_name" extension with empty data. */
8131 if (offset == offset_end) {
8132 return offset;
8133 }
8134
8135 server_name_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset, hf->ett.hs_ext_server_name, NULL((void*)0), "Server Name Indication extension");
8136
8137 /* ServerName server_name_list<1..2^16-1> */
8138 if (!ssl_add_vector(hf, tvb, pinfo, server_name_tree, offset, offset_end, &list_length,
8139 hf->hf.hs_ext_server_name_list_len, 1, UINT16_MAX(65535))) {
8140 return offset_end;
8141 }
8142 offset += 2;
8143 next_offset = offset + list_length;
8144
8145 while (offset < next_offset) {
8146 uint32_t name_type;
8147 const char *server_name = NULL((void*)0);
8148 proto_tree_add_item_ret_uint(server_name_tree, hf->hf.hs_ext_server_name_type,
8149 tvb, offset, 1, ENC_NA0x00000000, &name_type);
8150 offset++;
8151
8152 /* opaque HostName<1..2^16-1> */
8153 if (!ssl_add_vector(hf, tvb, pinfo, server_name_tree, offset, next_offset, &server_name_length,
8154 hf->hf.hs_ext_server_name_len, 1, UINT16_MAX(65535))) {
8155 return next_offset;
8156 }
8157 offset += 2;
8158
8159 proto_tree_add_item_ret_string(server_name_tree, hf->hf.hs_ext_server_name,
8160 tvb, offset, server_name_length, ENC_ASCII0x00000000|ENC_NA0x00000000,
8161 pinfo->pool, (const uint8_t**)&server_name);
8162 offset += server_name_length;
8163 // Each type must only occur once, so we don't check for duplicates.
8164 if (name_type == 0) {
8165 proto_item_append_text(tree, " name=%s", server_name);
8166 col_append_fstr(pinfo->cinfo, COL_INFO, " (SNI=%s)", server_name);
8167
8168 if (gbl_resolv_flags.handshake_sni_addr_resolution) {
8169 // Client Hello: Client (Src) -> Server (Dst)
8170 switch (PINFO_DST(pinfo)((pinfo)->use_conv_addr_port_endpoints ? conversation_addr_port_endpoints_addr2
((pinfo)->conv_addr_port_endpoints) : &((pinfo)->dst
))
->type) {
8171 case AT_IPv4:
8172 if (PINFO_DST(pinfo)((pinfo)->use_conv_addr_port_endpoints ? conversation_addr_port_endpoints_addr2
((pinfo)->conv_addr_port_endpoints) : &((pinfo)->dst
))
->len == sizeof(uint32_t)) {
8173 /* The address may point to unaligned frame data. */
8174 uint32_t addr;
8175 memcpy(&addr, PINFO_DST(pinfo)((pinfo)->use_conv_addr_port_endpoints ? conversation_addr_port_endpoints_addr2
((pinfo)->conv_addr_port_endpoints) : &((pinfo)->dst
))
->data, sizeof addr);
8176 add_ipv4_name(addr, server_name, false0);
8177 }
8178 break;
8179 case AT_IPv6:
8180 if (PINFO_DST(pinfo)((pinfo)->use_conv_addr_port_endpoints ? conversation_addr_port_endpoints_addr2
((pinfo)->conv_addr_port_endpoints) : &((pinfo)->dst
))
->len == sizeof(ws_in6_addr)) {
8181 add_ipv6_name(PINFO_DST(pinfo)((pinfo)->use_conv_addr_port_endpoints ? conversation_addr_port_endpoints_addr2
((pinfo)->conv_addr_port_endpoints) : &((pinfo)->dst
))
->data, server_name, false0);
8182 }
8183 break;
8184 }
8185 }
8186 }
8187 }
8188 return offset;
8189}
8190
8191static int
8192ssl_dissect_hnd_hello_ext_session_ticket(ssl_common_dissect_t *hf, tvbuff_t *tvb,
8193 proto_tree *tree, uint32_t offset, uint32_t offset_end, uint8_t hnd_type, SslDecryptSession *ssl)
8194{
8195 unsigned ext_len = offset_end - offset;
8196 if (hnd_type == SSL_HND_CLIENT_HELLO && ssl && ext_len != 0) {
8197 tvb_ensure_bytes_exist(tvb, offset, ext_len);
8198 /* Save the Session Ticket such that it can be used as identifier for
8199 * restoring a previous Master Secret (in ChangeCipherSpec) */
8200 ssl->session_ticket.data = (unsigned char*)wmem_realloc(wmem_file_scope(),
8201 ssl->session_ticket.data, ext_len);
8202 ssl->session_ticket.data_len = ext_len;
8203 tvb_memcpy(tvb,ssl->session_ticket.data, offset, ext_len);
8204 }
8205 proto_tree_add_item(tree, hf->hf.hs_ext_session_ticket,
8206 tvb, offset, ext_len, ENC_NA0x00000000);
8207 return offset + ext_len;
8208}
8209
8210static int
8211ssl_dissect_hnd_hello_ext_cert_type(ssl_common_dissect_t *hf, tvbuff_t *tvb,
8212 proto_tree *tree, uint32_t offset, uint32_t offset_end,
8213 uint8_t hnd_type, uint16_t ext_type, SslSession *session)
8214{
8215 uint8_t cert_list_length;
8216 uint8_t cert_type;
8217 proto_tree *cert_list_tree;
8218 proto_item *ti;
8219
8220 switch(hnd_type){
8221 case SSL_HND_CLIENT_HELLO:
8222 cert_list_length = tvb_get_uint8(tvb, offset);
8223 proto_tree_add_item(tree, hf->hf.hs_ext_cert_types_len,
8224 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
8225 offset += 1;
8226 if (offset_end - offset != (uint32_t)cert_list_length)
8227 return offset;
8228
8229 ti = proto_tree_add_item(tree, hf->hf.hs_ext_cert_types, tvb, offset,
8230 cert_list_length, ENC_NA0x00000000);
8231 proto_item_append_text(ti, " (%d)", cert_list_length);
8232
8233 /* make this a subtree */
8234 cert_list_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_cert_types);
8235
8236 /* loop over all point formats */
8237 while (cert_list_length > 0)
8238 {
8239 proto_tree_add_item(cert_list_tree, hf->hf.hs_ext_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
8240 offset++;
8241 cert_list_length--;
8242 }
8243 break;
8244 case SSL_HND_SERVER_HELLO:
8245 case SSL_HND_ENCRYPTED_EXTENSIONS:
8246 case SSL_HND_CERTIFICATE:
8247 cert_type = tvb_get_uint8(tvb, offset);
8248 proto_tree_add_item(tree, hf->hf.hs_ext_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
8249 offset += 1;
8250 if (ext_type == SSL_HND_HELLO_EXT_CERT_TYPE9 || ext_type == SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE19) {
8251 session->client_cert_type = cert_type;
8252 }
8253 if (ext_type == SSL_HND_HELLO_EXT_CERT_TYPE9 || ext_type == SSL_HND_HELLO_EXT_SERVER_CERT_TYPE20) {
8254 session->server_cert_type = cert_type;
8255 }
8256 break;
8257 default: /* no default */
8258 break;
8259 }
8260
8261 return offset;
8262}
8263
8264static uint32_t
8265ssl_dissect_hnd_hello_ext_compress_certificate(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
8266 proto_tree *tree, uint32_t offset, uint32_t offset_end,
8267 uint8_t hnd_type, SslDecryptSession *ssl _U___attribute__((unused)))
8268{
8269 uint32_t compress_certificate_algorithms_length, next_offset;
8270
8271 /* https://tools.ietf.org/html/draft-ietf-tls-certificate-compression-03#section-3.0
8272 * enum {
8273 * zlib(1),
8274 * brotli(2),
8275 * (65535)
8276 * } CertificateCompressionAlgorithm;
8277 *
8278 * struct {
8279 * CertificateCompressionAlgorithm algorithms<1..2^8-1>;
8280 * } CertificateCompressionAlgorithms;
8281 */
8282 switch (hnd_type) {
8283 case SSL_HND_CLIENT_HELLO:
8284 case SSL_HND_CERT_REQUEST:
8285 /* CertificateCompressionAlgorithm algorithms<1..2^8-1>;*/
8286 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &compress_certificate_algorithms_length,
8287 hf->hf.hs_ext_compress_certificate_algorithms_length, 1, UINT8_MAX(255)-1)) {
8288 return offset_end;
8289 }
8290 offset += 1;
8291 next_offset = offset + compress_certificate_algorithms_length;
8292
8293 while (offset < next_offset) {
8294 proto_tree_add_item(tree, hf->hf.hs_ext_compress_certificate_algorithm,
8295 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
8296 offset += 2;
8297 }
8298 break;
8299 default:
8300 break;
8301 }
8302
8303 return offset;
8304}
8305
8306static uint32_t
8307ssl_dissect_hnd_hello_ext_token_binding(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
8308 proto_tree *tree, uint32_t offset, uint32_t offset_end,
8309 uint8_t hnd_type, SslDecryptSession *ssl _U___attribute__((unused)))
8310{
8311 uint32_t key_parameters_length, next_offset;
8312 proto_item *p_ti;
8313 proto_tree *p_tree;
8314
8315 /* RFC 8472
8316 *
8317 * struct {
8318 * uint8 major;
8319 * uint8 minor;
8320 * } TB_ProtocolVersion;
8321 *
8322 * enum {
8323 * rsa2048_pkcs1.5(0), rsa2048_pss(1), ecdsap256(2), (255)
8324 * } TokenBindingKeyParameters;
8325 *
8326 * struct {
8327 * TB_ProtocolVersion token_binding_version;
8328 * TokenBindingKeyParameters key_parameters_list<1..2^8-1>
8329 * } TokenBindingParameters;
8330 */
8331
8332 switch (hnd_type) {
8333 case SSL_HND_CLIENT_HELLO:
8334 case SSL_HND_SERVER_HELLO:
8335 proto_tree_add_item(tree, hf->hf.hs_ext_token_binding_version_major, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
8336 offset += 1;
8337 proto_tree_add_item(tree, hf->hf.hs_ext_token_binding_version_minor, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
8338 offset += 1;
8339
8340 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &key_parameters_length,
8341 hf->hf.hs_ext_token_binding_key_parameters_length, 1, UINT8_MAX(255))) {
8342 return offset_end;
8343 }
8344 offset += 1;
8345 next_offset = offset + key_parameters_length;
8346
8347 p_ti = proto_tree_add_none_format(tree,
8348 hf->hf.hs_ext_token_binding_key_parameters,
8349 tvb, offset, key_parameters_length,
8350 "Key parameters identifiers (%d identifier%s)",
8351 key_parameters_length,
8352 plurality(key_parameters_length, "", "s")((key_parameters_length) == 1 ? ("") : ("s")));
8353 p_tree = proto_item_add_subtree(p_ti, hf->ett.hs_ext_token_binding_key_parameters);
8354
8355 while (offset < next_offset) {
8356 proto_tree_add_item(p_tree, hf->hf.hs_ext_token_binding_key_parameter,
8357 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
8358 offset += 1;
8359 }
8360
8361 if (!ssl_end_vector(hf, tvb, pinfo, p_tree, offset, next_offset)) {
8362 offset = next_offset;
8363 }
8364
8365 break;
8366 default:
8367 break;
8368 }
8369
8370 return offset;
8371}
8372
8373static uint32_t
8374ssl_dissect_hnd_hello_ext_quic_transport_parameters(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
8375 proto_tree *tree, uint32_t offset, uint32_t offset_end,
8376 uint8_t hnd_type, SslDecryptSession *ssl _U___attribute__((unused)))
8377{
8378 bool_Bool use_varint_encoding = true1; // Whether this is draft -27 or newer.
8379 uint32_t next_offset;
8380
8381 /* https://tools.ietf.org/html/draft-ietf-quic-transport-25#section-18
8382 *
8383 * Note: the following structures are not literally defined in the spec,
8384 * they instead use an ASCII diagram.
8385 *
8386 * struct {
8387 * uint16 id;
8388 * opaque value<0..2^16-1>;
8389 * } TransportParameter; // before draft -27
8390 * TransportParameter TransportParameters<0..2^16-1>; // before draft -27
8391 *
8392 * struct {
8393 * opaque ipv4Address[4];
8394 * uint16 ipv4Port;
8395 * opaque ipv6Address[16];
8396 * uint16 ipv6Port;
8397 * opaque connectionId<0..18>;
8398 * opaque statelessResetToken[16];
8399 * } PreferredAddress;
8400 */
8401
8402 if (offset_end - offset >= 6 &&
8403 2 + (unsigned)tvb_get_ntohs(tvb, offset) == offset_end - offset &&
8404 6 + (unsigned)tvb_get_ntohs(tvb, offset + 4) <= offset_end - offset) {
8405 // Assume encoding of Transport Parameters draft -26 or older with at
8406 // least one transport parameter that has a valid length.
8407 use_varint_encoding = false0;
8408 }
8409
8410 if (use_varint_encoding) {
8411 next_offset = offset_end;
8412 } else {
8413 uint32_t quic_length;
8414 // Assume draft -26 or earlier.
8415 /* TransportParameter TransportParameters<0..2^16-1>; */
8416 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &quic_length,
8417 hf->hf.hs_ext_quictp_len, 0, UINT16_MAX(65535))) {
8418 return offset_end;
8419 }
8420 offset += 2;
8421 next_offset = offset + quic_length;
8422 }
8423
8424 while (offset < next_offset) {
8425 uint64_t parameter_type; /* 62-bit space */
8426 uint32_t parameter_length;
8427 proto_tree *parameter_tree;
8428 uint32_t parameter_end_offset;
8429 uint64_t value;
8430 uint32_t i;
8431 unsigned len = 0;
8432
8433 parameter_tree = proto_tree_add_subtree(tree, tvb, offset, 2, hf->ett.hs_ext_quictp_parameter,
8434 NULL((void*)0), "Parameter");
8435 /* TransportParameter ID and Length. */
8436 if (use_varint_encoding) {
8437 uint64_t parameter_length64;
8438 unsigned type_len = 0;
8439
8440 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_type,
8441 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &parameter_type, &type_len);
8442 offset += type_len;
8443
8444 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_len,
8445 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &parameter_length64, &len);
8446 parameter_length = (uint32_t)parameter_length64;
8447 offset += len;
8448
8449 proto_item_set_len(parameter_tree, type_len + len + parameter_length);
8450 } else {
8451 parameter_type = tvb_get_ntohs(tvb, offset);
8452 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_type,
8453 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
8454 offset += 2;
8455
8456 /* opaque value<0..2^16-1> */
8457 if (!ssl_add_vector(hf, tvb, pinfo, parameter_tree, offset, next_offset, &parameter_length,
8458 hf->hf.hs_ext_quictp_parameter_len_old, 0, UINT16_MAX(65535))) {
8459 return next_offset;
8460 }
8461 offset += 2;
8462
8463 proto_item_set_len(parameter_tree, 4 + parameter_length);
8464 }
8465
8466 if (IS_GREASE_QUIC(parameter_type)((parameter_type) > 27 ? ((((parameter_type) - 27) % 31) ==
0) : 0)
) {
8467 proto_item_append_text(parameter_tree, ": GREASE");
8468 } else {
8469 proto_item_append_text(parameter_tree, ": %s", val64_to_str_wmem(pinfo->pool, parameter_type, quic_transport_parameter_id, "Unknown 0x%04x"));
8470 }
8471
8472 proto_item_append_text(parameter_tree, " (len=%u)", parameter_length);
8473 parameter_end_offset = offset + parameter_length;
8474
8475 /* Omit the value field if the parameter's length is 0. */
8476 if (parameter_length != 0) {
8477 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_value,
8478 tvb, offset, parameter_length, ENC_NA0x00000000);
8479 }
8480
8481 switch (parameter_type) {
8482 case SSL_HND_QUIC_TP_ORIGINAL_DESTINATION_CONNECTION_ID0x00:
8483 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_original_destination_connection_id,
8484 tvb, offset, parameter_length, ENC_NA0x00000000);
8485 offset += parameter_length;
8486 break;
8487 case SSL_HND_QUIC_TP_MAX_IDLE_TIMEOUT0x01:
8488 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_max_idle_timeout,
8489 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8490 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u" " ms", value);
8491 offset += len;
8492 break;
8493 case SSL_HND_QUIC_TP_STATELESS_RESET_TOKEN0x02:
8494 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_stateless_reset_token,
8495 tvb, offset, 16, ENC_BIG_ENDIAN0x00000000);
8496 quic_add_stateless_reset_token(pinfo, tvb, offset, NULL((void*)0));
8497 offset += 16;
8498 break;
8499 case SSL_HND_QUIC_TP_MAX_UDP_PAYLOAD_SIZE0x03:
8500 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_max_udp_payload_size,
8501 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8502 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8503 /*TODO display expert info about invalid value (< 1252 or >65527) ? */
8504 offset += len;
8505 break;
8506 case SSL_HND_QUIC_TP_INITIAL_MAX_DATA0x04:
8507 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_initial_max_data,
8508 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8509 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8510 offset += len;
8511 break;
8512 case SSL_HND_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_LOCAL0x05:
8513 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_initial_max_stream_data_bidi_local,
8514 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8515 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8516 offset += len;
8517 break;
8518 case SSL_HND_QUIC_TP_INITIAL_MAX_STREAM_DATA_BIDI_REMOTE0x06:
8519 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_initial_max_stream_data_bidi_remote,
8520 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8521 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8522 offset += len;
8523 break;
8524 case SSL_HND_QUIC_TP_INITIAL_MAX_STREAM_DATA_UNI0x07:
8525 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_initial_max_stream_data_uni,
8526 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8527 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8528 offset += len;
8529 break;
8530 case SSL_HND_QUIC_TP_INITIAL_MAX_STREAMS_UNI0x09:
8531 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_initial_max_streams_uni,
8532 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8533 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8534 offset += len;
8535 break;
8536 case SSL_HND_QUIC_TP_INITIAL_MAX_STREAMS_BIDI0x08:
8537 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_initial_max_streams_bidi,
8538 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8539 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8540 offset += len;
8541 break;
8542 case SSL_HND_QUIC_TP_ACK_DELAY_EXPONENT0x0a:
8543 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_ack_delay_exponent,
8544 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, NULL((void*)0), &len);
8545 /*TODO display multiplier (x8) and expert info about invalid value (> 20) ? */
8546 offset += len;
8547 break;
8548 case SSL_HND_QUIC_TP_MAX_ACK_DELAY0x0b:
8549 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_max_ack_delay,
8550 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8551 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8552 offset += len;
8553 break;
8554 case SSL_HND_QUIC_TP_DISABLE_ACTIVE_MIGRATION0x0c:
8555 /* No Payload */
8556 break;
8557 case SSL_HND_QUIC_TP_PREFERRED_ADDRESS0x0d: {
8558 uint32_t connectionid_length;
8559 quic_cid_t cid;
8560
8561 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_pa_ipv4address,
8562 tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
8563 offset += 4;
8564 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_pa_ipv4port,
8565 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
8566 offset += 2;
8567 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_pa_ipv6address,
8568 tvb, offset, 16, ENC_NA0x00000000);
8569 offset += 16;
8570 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_pa_ipv6port,
8571 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
8572 offset += 2;
8573 /* XXX - Should we add these addresses and ports as addresses that the client
8574 * is allowed / expected to migrate the server address to? Right now we don't
8575 * enforce that (see RFC 9000 Section 9, which implies that while the client
8576 * can migrate to whatever address it wants, it can only migrate the server
8577 * address to the Server's Preferred Address as in 9.6. Also Issue #20165.)
8578 */
8579
8580 if (!ssl_add_vector(hf, tvb, pinfo, parameter_tree, offset, offset_end, &connectionid_length,
8581 hf->hf.hs_ext_quictp_parameter_pa_connectionid_length, 0, 20)) {
8582 break;
8583 }
8584 offset += 1;
8585
8586 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_pa_connectionid,
8587 tvb, offset, connectionid_length, ENC_NA0x00000000);
8588 if (connectionid_length >= 1 && connectionid_length <= QUIC_MAX_CID_LENGTH20) {
8589 cid.len = connectionid_length;
8590 // RFC 9000 5.1.1 "If the preferred_address transport
8591 // parameter is sent, the sequence number of the supplied
8592 // connection ID is 1."
8593 cid.seq_num = 1;
8594 // Multipath draft-07 "Also, the Path Identifier for the
8595 // connection ID specified in the "preferred address"
8596 // transport parameter is 0."
8597 cid.path_id = 0;
8598 tvb_memcpy(tvb, cid.cid, offset, connectionid_length);
8599 quic_add_connection(pinfo, &cid);
8600 }
8601 offset += connectionid_length;
8602
8603 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_pa_statelessresettoken,
8604 tvb, offset, 16, ENC_NA0x00000000);
8605 if (connectionid_length >= 1 && connectionid_length <= QUIC_MAX_CID_LENGTH20) {
8606 quic_add_stateless_reset_token(pinfo, tvb, offset, &cid);
8607 }
8608 offset += 16;
8609 }
8610 break;
8611 case SSL_HND_QUIC_TP_ACTIVE_CONNECTION_ID_LIMIT0x0e:
8612 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_active_connection_id_limit,
8613 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8614 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8615 offset += len;
8616 break;
8617 case SSL_HND_QUIC_TP_INITIAL_SOURCE_CONNECTION_ID0x0f:
8618 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_initial_source_connection_id,
8619 tvb, offset, parameter_length, ENC_NA0x00000000);
8620 offset += parameter_length;
8621 break;
8622 case SSL_HND_QUIC_TP_RETRY_SOURCE_CONNECTION_ID0x10:
8623 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_retry_source_connection_id,
8624 tvb, offset, parameter_length, ENC_NA0x00000000);
8625 offset += parameter_length;
8626 break;
8627 case SSL_HND_QUIC_TP_MAX_DATAGRAM_FRAME_SIZE0x20:
8628 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_max_datagram_frame_size,
8629 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8630 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8631 offset += len;
8632 break;
8633 case SSL_HND_QUIC_TP_CIBIR_ENCODING0x1000:
8634 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_cibir_encoding_length,
8635 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8636 proto_item_append_text(parameter_tree, " Length: %" PRIu64"l" "u", value);
8637 offset += len;
8638 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_cibir_encoding_offset,
8639 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8640 proto_item_append_text(parameter_tree, ", Offset: %" PRIu64"l" "u", value);
8641 offset += len;
8642 break;
8643 case SSL_HND_QUIC_TP_LOSS_BITS0x1057:
8644 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_loss_bits,
8645 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8646 if (len > 0) {
8647 quic_add_loss_bits(pinfo, value);
8648 }
8649 offset += 1;
8650 break;
8651 case SSL_HND_QUIC_TP_ADDRESS_DISCOVERY0x9f81a176:
8652 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_address_discovery,
8653 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, NULL((void*)0), &len);
8654 offset += len;
8655 break;
8656 case SSL_HND_QUIC_TP_MIN_ACK_DELAY_OLD0xde1a:
8657 case SSL_HND_QUIC_TP_MIN_ACK_DELAY_DRAFT_V10xFF03DE1A:
8658 case SSL_HND_QUIC_TP_MIN_ACK_DELAY_DRAFT050xff04de1a:
8659 case SSL_HND_QUIC_TP_MIN_ACK_DELAY0xff04de1b:
8660 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_min_ack_delay,
8661 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8662 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u", value);
8663 offset += len;
8664 break;
8665 case SSL_HND_QUIC_TP_GOOGLE_USER_AGENT0x3129:
8666 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_google_user_agent_id,
8667 tvb, offset, parameter_length, ENC_ASCII0x00000000|ENC_NA0x00000000);
8668 offset += parameter_length;
8669 break;
8670 case SSL_HND_QUIC_TP_GOOGLE_KEY_UPDATE_NOT_YET_SUPPORTED0x312B:
8671 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_google_key_update_not_yet_supported,
8672 tvb, offset, parameter_length, ENC_NA0x00000000);
8673 offset += parameter_length;
8674 break;
8675 case SSL_HND_QUIC_TP_GOOGLE_QUIC_VERSION0x4752:
8676 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_google_quic_version,
8677 tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
8678 offset += 4;
8679 if (hnd_type == SSL_HND_ENCRYPTED_EXTENSIONS) { /* From server */
8680 uint32_t versions_length;
8681
8682 proto_tree_add_item_ret_uint(parameter_tree, hf->hf.hs_ext_quictp_parameter_google_supported_versions_length,
8683 tvb, offset, 1, ENC_NA0x00000000, &versions_length);
8684 offset += 1;
8685 for (i = 0; i < versions_length / 4; i++) {
8686 quic_proto_tree_add_version(tvb, parameter_tree,
8687 hf->hf.hs_ext_quictp_parameter_google_supported_version, offset);
8688 offset += 4;
8689 }
8690 }
8691 break;
8692 case SSL_HND_QUIC_TP_GOOGLE_INITIAL_RTT0x3127:
8693 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_google_initial_rtt,
8694 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8695 proto_item_append_text(parameter_tree, " %" PRIu64"l" "u" " us", value);
8696 offset += len;
8697 break;
8698 case SSL_HND_QUIC_TP_GOOGLE_SUPPORT_HANDSHAKE_DONE0x312A:
8699 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_google_support_handshake_done,
8700 tvb, offset, parameter_length, ENC_NA0x00000000);
8701 offset += parameter_length;
8702 break;
8703 case SSL_HND_QUIC_TP_GOOGLE_QUIC_PARAMS0x4751:
8704 /* This field was used for non-standard Google-specific parameters encoded as a
8705 * Google QUIC_CRYPTO CHLO and it has been replaced (version >= T051) by individual
8706 * parameters. Report it as a bytes blob... */
8707 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_google_quic_params,
8708 tvb, offset, parameter_length, ENC_NA0x00000000);
8709 /* ... and try decoding it: not sure what the first 4 bytes are (but they seems to be always 0) */
8710 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_google_quic_params_unknown_field,
8711 tvb, offset, 4, ENC_NA0x00000000);
8712 dissect_gquic_tags(tvb, pinfo, parameter_tree, offset + 4);
8713 offset += parameter_length;
8714 break;
8715 case SSL_HND_QUIC_TP_GOOGLE_CONNECTION_OPTIONS0x3128:
8716 proto_tree_add_item(parameter_tree, hf->hf.hs_ext_quictp_parameter_google_connection_options,
8717 tvb, offset, parameter_length, ENC_NA0x00000000);
8718 offset += parameter_length;
8719 break;
8720 case SSL_HND_QUIC_TP_ENABLE_TIME_STAMP0x7157:
8721 /* No Payload */
8722 break;
8723 case SSL_HND_QUIC_TP_ENABLE_TIME_STAMP_V20x7158:
8724 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_enable_time_stamp_v2,
8725 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8726 offset += parameter_length;
8727 break;
8728 case SSL_HND_QUIC_TP_VERSION_INFORMATION_DRAFT0xff73db:
8729 case SSL_HND_QUIC_TP_VERSION_INFORMATION0x11:
8730 quic_proto_tree_add_version(tvb, parameter_tree,
8731 hf->hf.hs_ext_quictp_parameter_chosen_version, offset);
8732 offset += 4;
8733 for (i = 4; i < parameter_length; i += 4) {
8734 quic_proto_tree_add_version(tvb, parameter_tree,
8735 hf->hf.hs_ext_quictp_parameter_other_version, offset);
8736 offset += 4;
8737 }
8738 break;
8739 case SSL_HND_QUIC_TP_GREASE_QUIC_BIT0x2ab2:
8740 /* No Payload */
8741 quic_add_grease_quic_bit(pinfo);
8742 break;
8743 case SSL_HND_QUIC_TP_FACEBOOK_PARTIAL_RELIABILITY0xFF00:
8744 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_facebook_partial_reliability,
8745 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8746 offset += parameter_length;
8747 break;
8748 case SSL_HND_QUIC_TP_ENABLE_MULTIPATH_DRAFT040x0f739bbc1b666d04:
8749 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_enable_multipath,
8750 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8751 if (value == 1) {
8752 quic_add_multipath(pinfo, QUIC_MP_NO_PATH_ID1);
8753 }
8754 offset += parameter_length;
8755 break;
8756 case SSL_HND_QUIC_TP_ENABLE_MULTIPATH_DRAFT050x0f739bbc1b666d05:
8757 case SSL_HND_QUIC_TP_ENABLE_MULTIPATH0x0f739bbc1b666d06:
8758 /* No Payload */
8759 quic_add_multipath(pinfo, QUIC_MP_NO_PATH_ID1);
8760 break;
8761 case SSL_HND_QUIC_TP_INITIAL_MAX_PATHS0x0f739bbc1b666d07:
8762 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_initial_max_paths,
8763 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8764 if (value > 1) {
8765 quic_add_multipath(pinfo, QUIC_MP_PATH_ID2);
8766 }
8767 /* multipath draft-07: "The value of the initial_max_paths
8768 * parameter MUST be at least 2." TODO: Expert Info? */
8769 offset += parameter_length;
8770 break;
8771 case SSL_HND_QUIC_TP_INITIAL_MAX_PATH_ID_DRAFT090x0f739bbc1b666d09:
8772 case SSL_HND_QUIC_TP_INITIAL_MAX_PATH_ID_DRAFT110x0f739bbc1b666d11:
8773 case SSL_HND_QUIC_TP_INITIAL_MAX_PATH_ID_DRAFT120x0f739bbc1b666d0c:
8774 case SSL_HND_QUIC_TP_INITIAL_MAX_PATH_ID_DRAFT130x0f739bbc1b666d0d:
8775 case SSL_HND_QUIC_TP_INITIAL_MAX_PATH_ID0x3e:
8776 proto_tree_add_item_ret_varint(parameter_tree, hf->hf.hs_ext_quictp_parameter_initial_max_path_id,
8777 tvb, offset, -1, ENC_VARINT_QUIC0x00000004, &value, &len);
8778 /* multipath draft-09 and later: "If an endpoint receives an
8779 * initial_max_path_id transport parameter with value 0, the
8780 * peer aims to enable the multipath extension without allowing
8781 * extra paths immediately."
8782 */
8783 quic_add_multipath(pinfo, QUIC_MP_PATH_ID2);
8784 offset += parameter_length;
8785 break;
8786 default:
8787 offset += parameter_length;
8788 /*TODO display expert info about unknown ? */
8789 break;
8790 }
8791
8792 if (!ssl_end_vector(hf, tvb, pinfo, parameter_tree, offset, parameter_end_offset)) {
8793 /* Dissection did not end at expected location, fix it. */
8794 offset = parameter_end_offset;
8795 }
8796 }
8797
8798 return offset;
8799}
8800
8801typedef struct tls_ech_confirm {
8802 tvbuff_t *confirm_tvb;
8803 proto_item *parent_item;
8804} tls_ech_confirm_t;
8805
8806static int
8807ssl_dissect_hnd_hello_common(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
8808 proto_tree *tree, uint32_t offset,
8809 SslSession *session, SslDecryptSession *ssl,
8810 bool_Bool from_server, bool_Bool is_hrr)
8811{
8812 uint8_t sessid_length;
8813 proto_tree *rnd_tree;
8814 proto_tree *ti_rnd;
8815 uint8_t draft_version = session->tls13_draft_version;
8816
8817 if (ssl) {
8818 StringInfo *rnd;
8819 if (from_server)
8820 rnd = &ssl->server_random;
8821 else
8822 rnd = &ssl->client_random;
8823
8824 /* save provided random for later keyring generation */
8825 tvb_memcpy(tvb, rnd->data, offset, 32);
8826 rnd->data_len = 32;
8827 if (from_server)
8828 ssl->state |= SSL_SERVER_RANDOM(1<<1);
8829 else
8830 ssl->state |= SSL_CLIENT_RANDOM(1<<0);
8831 ssl_debug_printf("%s found %s RANDOM -> state 0x%02X\n", G_STRFUNC((const char*) (__func__)),
8832 from_server ? "SERVER" : "CLIENT", ssl->state);
8833
8834 if (is_hrr) {
8835 ssl->state |= SSL_HELLO_RETRY_REQUEST(1<<14);
8836 }
8837 }
8838
8839 if (!from_server && session->client_random.data_len == 0) {
8840 session->client_random.data_len = 32;
8841 tvb_memcpy(tvb, session->client_random.data, offset, 32);
8842 }
8843
8844 ti_rnd = proto_tree_add_item(tree, hf->hf.hs_random, tvb, offset, 32, ENC_NA0x00000000);
8845
8846 if ((session->version != TLSV1DOT3_VERSION0x304) && (session->version != DTLSV1DOT3_VERSION0xfefc)) { /* No time on first bytes random with TLS 1.3 */
8847
8848 rnd_tree = proto_item_add_subtree(ti_rnd, hf->ett.hs_random);
8849 /* show the time */
8850 proto_tree_add_item(rnd_tree, hf->hf.hs_random_time,
8851 tvb, offset, 4, ENC_TIME_SECS0x00000012|ENC_BIG_ENDIAN0x00000000);
8852 offset += 4;
8853
8854 /* show the random bytes */
8855 proto_tree_add_item(rnd_tree, hf->hf.hs_random_bytes,
8856 tvb, offset, 28, ENC_NA0x00000000);
8857 offset += 28;
8858 } else {
8859 if (is_hrr) {
8860 proto_item_append_text(ti_rnd, " (HelloRetryRequest magic)");
8861 } else if (from_server && (session->ech || (ssl && !tls_transcript_is_empty(&ssl->ech_transcript)))) {
8862 /* We can't calculate the transcript hash until we have the Cipher
8863 * Suite, which comes later, so save this so we can show it in the
8864 * tree on the first pass. */
8865 tls_ech_confirm_t *ech_confirm = wmem_new(pinfo->pool, tls_ech_confirm_t)((tls_ech_confirm_t*)wmem_alloc((pinfo->pool), sizeof(tls_ech_confirm_t
)))
;
8866 ech_confirm->parent_item = ti_rnd;
8867 ech_confirm->confirm_tvb = tvb_new_subset_length(tvb, offset + 24, 8);
8868 /* We can use a hf id instead of a proto id (they're allocated from
8869 * the same pool and the latter are just a subset of the former),
8870 * which is convenient as we don't seem to store the proto id (TLS v
8871 * DTLS) in ssl_common_dissect_t or anywhere else. Arguably it
8872 * relies on undocumented behavior, though using it as the key too
8873 * means that the chance of collision is ~zero even if behavior
8874 * changes.
8875 */
8876 p_add_proto_data(pinfo->pool, pinfo, hf->hf.hs_ech_confirm, hf->hf.hs_ech_confirm, ech_confirm);
8877 }
8878
8879 offset += 32;
8880 }
8881
8882 /* No Session ID with TLS 1.3 on Server Hello before draft -22 */
8883 if (from_server == 0 || !(session->version == TLSV1DOT3_VERSION0x304 && draft_version > 0 && draft_version < 22)) {
8884 /* show the session id (length followed by actual Session ID) */
8885 sessid_length = tvb_get_uint8(tvb, offset);
8886 proto_tree_add_item(tree, hf->hf.hs_session_id_len,
8887 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
8888 offset++;
8889
8890 if (ssl) {
8891 /* save the authoritative SID for later use in ChangeCipherSpec.
8892 * (D)TLS restricts the SID to 32 chars, it does not make sense to
8893 * save more, so ignore larger ones. To support ECH, also save
8894 * the SID from the ClientHelloOuter. */
8895 if (sessid_length <= 32 && (from_server || sessid_length > 0)) {
8896 tvb_memcpy(tvb, ssl->session_id.data, offset, sessid_length);
8897 ssl->session_id.data_len = sessid_length;
8898 }
8899 }
8900 if (sessid_length > 0) {
8901 proto_tree_add_item(tree, hf->hf.hs_session_id,
8902 tvb, offset, sessid_length, ENC_NA0x00000000);
8903 offset += sessid_length;
8904 }
8905 }
8906
8907 return offset;
8908}
8909
8910static int
8911ssl_dissect_hnd_hello_ext_status_request(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
8912 proto_tree *tree, uint32_t offset, uint32_t offset_end,
8913 bool_Bool has_length)
8914{
8915 /* TLS 1.2/1.3 status_request Client Hello Extension.
8916 * TLS 1.2 status_request_v2 CertificateStatusRequestItemV2 type.
8917 * https://tools.ietf.org/html/rfc6066#section-8 (status_request)
8918 * https://tools.ietf.org/html/rfc6961#section-2.2 (status_request_v2)
8919 * struct {
8920 * CertificateStatusType status_type;
8921 * uint16 request_length; // for status_request_v2
8922 * select (status_type) {
8923 * case ocsp: OCSPStatusRequest;
8924 * case ocsp_multi: OCSPStatusRequest;
8925 * } request;
8926 * } CertificateStatusRequest; // CertificateStatusRequestItemV2
8927 *
8928 * enum { ocsp(1), ocsp_multi(2), (255) } CertificateStatusType;
8929 * struct {
8930 * ResponderID responder_id_list<0..2^16-1>;
8931 * Extensions request_extensions;
8932 * } OCSPStatusRequest;
8933 * opaque ResponderID<1..2^16-1>;
8934 * opaque Extensions<0..2^16-1>;
8935 */
8936 unsigned cert_status_type;
8937
8938 cert_status_type = tvb_get_uint8(tvb, offset);
8939 proto_tree_add_item(tree, hf->hf.hs_ext_cert_status_type,
8940 tvb, offset, 1, ENC_NA0x00000000);
8941 offset++;
8942
8943 if (has_length) {
8944 proto_tree_add_item(tree, hf->hf.hs_ext_cert_status_request_len,
8945 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
8946 offset += 2;
8947 }
8948
8949 switch (cert_status_type) {
8950 case SSL_HND_CERT_STATUS_TYPE_OCSP1:
8951 case SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI2:
8952 {
8953 uint32_t responder_id_list_len;
8954 uint32_t request_extensions_len;
8955
8956 /* ResponderID responder_id_list<0..2^16-1> */
8957 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &responder_id_list_len,
8958 hf->hf.hs_ext_cert_status_responder_id_list_len, 0, UINT16_MAX(65535))) {
8959 return offset_end;
8960 }
8961 offset += 2;
8962 if (responder_id_list_len != 0) {
8963 proto_tree_add_expert_format(tree, pinfo, &hf->ei.hs_ext_cert_status_undecoded,
8964 tvb, offset, responder_id_list_len,
8965 "Responder ID list is not implemented, contact Wireshark"
8966 " developers if you want this to be supported");
8967 }
8968 offset += responder_id_list_len;
8969
8970 /* opaque Extensions<0..2^16-1> */
8971 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &request_extensions_len,
8972 hf->hf.hs_ext_cert_status_request_extensions_len, 0, UINT16_MAX(65535))) {
8973 return offset_end;
8974 }
8975 offset += 2;
8976 if (request_extensions_len != 0) {
8977 proto_tree_add_expert_format(tree, pinfo, &hf->ei.hs_ext_cert_status_undecoded,
8978 tvb, offset, request_extensions_len,
8979 "Request Extensions are not implemented, contact"
8980 " Wireshark developers if you want this to be supported");
8981 }
8982 offset += request_extensions_len;
8983 break;
8984 }
8985 }
8986
8987 return offset;
8988}
8989
8990static unsigned
8991ssl_dissect_hnd_hello_ext_status_request_v2(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
8992 proto_tree *tree, uint32_t offset, uint32_t offset_end)
8993{
8994 /* https://tools.ietf.org/html/rfc6961#section-2.2
8995 * struct {
8996 * CertificateStatusRequestItemV2 certificate_status_req_list<1..2^16-1>;
8997 * } CertificateStatusRequestListV2;
8998 */
8999 uint32_t req_list_length, next_offset;
9000
9001 /* CertificateStatusRequestItemV2 certificate_status_req_list<1..2^16-1> */
9002 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &req_list_length,
9003 hf->hf.hs_ext_cert_status_request_list_len, 1, UINT16_MAX(65535))) {
9004 return offset_end;
9005 }
9006 offset += 2;
9007 next_offset = offset + req_list_length;
9008
9009 while (offset < next_offset) {
9010 offset = ssl_dissect_hnd_hello_ext_status_request(hf, tvb, pinfo, tree, offset, next_offset, true1);
9011 }
9012
9013 return offset;
9014}
9015
9016static uint32_t
9017tls_dissect_ocsp_response(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
9018 uint32_t offset, uint32_t offset_end)
9019{
9020 uint32_t response_length;
9021 proto_item *ocsp_resp;
9022 proto_tree *ocsp_resp_tree;
9023 asn1_ctx_t asn1_ctx;
9024
9025 /* opaque OCSPResponse<1..2^24-1>; */
9026 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &response_length,
9027 hf->hf.hs_ocsp_response_len, 1, G_MAXUINT24((1U << 24) - 1))) {
9028 return offset_end;
9029 }
9030 offset += 3;
9031
9032 ocsp_resp = proto_tree_add_item(tree, proto_ocsp, tvb, offset,
9033 response_length, ENC_BIG_ENDIAN0x00000000);
9034 proto_item_set_text(ocsp_resp, "OCSP Response");
9035 ocsp_resp_tree = proto_item_add_subtree(ocsp_resp, hf->ett.ocsp_response);
9036 if (proto_is_protocol_enabled(find_protocol_by_id(proto_ocsp))) {
9037 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true1, pinfo);
9038 dissect_ocsp_OCSPResponse(false0, tvb, offset, &asn1_ctx, ocsp_resp_tree, -1);
9039 }
9040 offset += response_length;
9041
9042 return offset;
9043}
9044
9045uint32_t
9046tls_dissect_hnd_certificate_status(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
9047 proto_tree *tree, uint32_t offset, uint32_t offset_end)
9048{
9049 /* TLS 1.2 "CertificateStatus" handshake message.
9050 * TLS 1.3 "status_request" Certificate extension.
9051 * struct {
9052 * CertificateStatusType status_type;
9053 * select (status_type) {
9054 * case ocsp: OCSPResponse;
9055 * case ocsp_multi: OCSPResponseList; // status_request_v2
9056 * } response;
9057 * } CertificateStatus;
9058 * opaque OCSPResponse<1..2^24-1>;
9059 * struct {
9060 * OCSPResponse ocsp_response_list<1..2^24-1>;
9061 * } OCSPResponseList; // status_request_v2
9062 */
9063 uint32_t status_type, resp_list_length, next_offset;
9064
9065 proto_tree_add_item_ret_uint(tree, hf->hf.hs_ext_cert_status_type,
9066 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000, &status_type);
9067 offset += 1;
9068
9069 switch (status_type) {
9070 case SSL_HND_CERT_STATUS_TYPE_OCSP1:
9071 offset = tls_dissect_ocsp_response(hf, tvb, pinfo, tree, offset, offset_end);
9072 break;
9073
9074 case SSL_HND_CERT_STATUS_TYPE_OCSP_MULTI2:
9075 /* OCSPResponse ocsp_response_list<1..2^24-1> */
9076 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &resp_list_length,
9077 hf->hf.hs_ocsp_response_list_len, 1, G_MAXUINT24((1U << 24) - 1))) {
9078 return offset_end;
9079 }
9080 offset += 3;
9081 next_offset = offset + resp_list_length;
9082
9083 while (offset < next_offset) {
9084 offset = tls_dissect_ocsp_response(hf, tvb, pinfo, tree, offset, next_offset);
9085 }
9086 break;
9087 }
9088
9089 return offset;
9090}
9091
9092static unsigned
9093ssl_dissect_hnd_hello_ext_supported_groups(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
9094 proto_tree *tree, uint32_t offset, uint32_t offset_end,
9095 wmem_strbuf_t *ja3)
9096{
9097 /* RFC 8446 Section 4.2.7
9098 * enum { ..., (0xFFFF) } NamedGroup;
9099 * struct {
9100 * NamedGroup named_group_list<2..2^16-1>
9101 * } NamedGroupList;
9102 *
9103 * NOTE: "NamedCurve" (RFC 4492) is renamed to "NamedGroup" (RFC 7919) and
9104 * the extension itself from "elliptic_curves" to "supported_groups".
9105 */
9106 uint32_t groups_length, next_offset;
9107 proto_tree *groups_tree;
9108 proto_item *ti;
9109 char *ja3_dash = "";
9110
9111 /* NamedGroup named_group_list<2..2^16-1> */
9112 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &groups_length,
9113 hf->hf.hs_ext_supported_groups_len, 2, UINT16_MAX(65535))) {
9114 return offset_end;
9115 }
9116 offset += 2;
9117 next_offset = offset + groups_length;
9118
9119 ti = proto_tree_add_none_format(tree,
9120 hf->hf.hs_ext_supported_groups,
9121 tvb, offset, groups_length,
9122 "Supported Groups (%d group%s)",
9123 groups_length / 2,
9124 plurality(groups_length/2, "", "s")((groups_length/2) == 1 ? ("") : ("s")));
9125
9126 /* make this a subtree */
9127 groups_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_groups);
9128
9129 if (ja3) {
9130 wmem_strbuf_append_c(ja3, ',');
9131 }
9132 /* loop over all groups */
9133 while (offset + 2 <= next_offset) {
9134 uint32_t ext_supported_group;
9135
9136 proto_tree_add_item_ret_uint(groups_tree, hf->hf.hs_ext_supported_group, tvb, offset, 2,
9137 ENC_BIG_ENDIAN0x00000000, &ext_supported_group);
9138 offset += 2;
9139 if (ja3 && !IS_GREASE_TLS(ext_supported_group)((((ext_supported_group) & 0x0f0f) == 0x0a0a) && (
((ext_supported_group) & 0xff) == (((ext_supported_group)
>>8) & 0xff)))
) {
9140 wmem_strbuf_append_printf(ja3, "%s%i",ja3_dash, ext_supported_group);
9141 ja3_dash = "-";
9142 }
9143 }
9144 if (!ssl_end_vector(hf, tvb, pinfo, groups_tree, offset, next_offset)) {
9145 offset = next_offset;
9146 }
9147
9148 return offset;
9149}
9150
9151static int
9152ssl_dissect_hnd_hello_ext_ec_point_formats(ssl_common_dissect_t *hf, tvbuff_t *tvb,
9153 proto_tree *tree, uint32_t offset, wmem_strbuf_t *ja3)
9154{
9155 uint8_t ecpf_length;
9156 proto_tree *ecpf_tree;
9157 proto_item *ti;
9158
9159 ecpf_length = tvb_get_uint8(tvb, offset);
9160 proto_tree_add_item(tree, hf->hf.hs_ext_ec_point_formats_len,
9161 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
9162
9163 offset += 1;
9164 ti = proto_tree_add_none_format(tree,
9165 hf->hf.hs_ext_ec_point_formats,
9166 tvb, offset, ecpf_length,
9167 "Elliptic curves point formats (%d)",
9168 ecpf_length);
9169
9170 /* make this a subtree */
9171 ecpf_tree = proto_item_add_subtree(ti, hf->ett.hs_ext_curves_point_formats);
9172
9173 if (ja3) {
9174 wmem_strbuf_append_c(ja3, ',');
9175 }
9176
9177 /* loop over all point formats */
9178 while (ecpf_length > 0)
9179 {
9180 uint32_t ext_ec_point_format;
9181
9182 proto_tree_add_item_ret_uint(ecpf_tree, hf->hf.hs_ext_ec_point_format, tvb, offset, 1,
9183 ENC_BIG_ENDIAN0x00000000, &ext_ec_point_format);
9184 offset++;
9185 ecpf_length--;
9186 if (ja3) {
9187 wmem_strbuf_append_printf(ja3, "%i", ext_ec_point_format);
9188 if (ecpf_length > 0) {
9189 wmem_strbuf_append_c(ja3, '-');
9190 }
9191 }
9192 }
9193
9194 return offset;
9195}
9196
9197static int
9198ssl_dissect_hnd_hello_ext_srp(ssl_common_dissect_t *hf, tvbuff_t *tvb,
9199 packet_info *pinfo, proto_tree *tree,
9200 uint32_t offset, uint32_t next_offset)
9201{
9202 /* https://tools.ietf.org/html/rfc5054#section-2.8.1
9203 * opaque srp_I<1..2^8-1>;
9204 */
9205 uint32_t username_len;
9206
9207 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, next_offset, &username_len,
9208 hf->hf.hs_ext_srp_len, 1, UINT8_MAX(255))) {
9209 return next_offset;
9210 }
9211 offset++;
9212
9213 proto_tree_add_item(tree, hf->hf.hs_ext_srp_username,
9214 tvb, offset, username_len, ENC_UTF_80x00000002|ENC_NA0x00000000);
9215 offset += username_len;
9216
9217 return offset;
9218}
9219
9220static uint32_t
9221tls_dissect_sct(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
9222 uint32_t offset, uint32_t offset_end, uint16_t version)
9223{
9224 /* https://tools.ietf.org/html/rfc6962#section-3.2
9225 * enum { v1(0), (255) } Version;
9226 * struct {
9227 * opaque key_id[32];
9228 * } LogID;
9229 * opaque CtExtensions<0..2^16-1>;
9230 * struct {
9231 * Version sct_version;
9232 * LogID id;
9233 * uint64 timestamp;
9234 * CtExtensions extensions;
9235 * digitally-signed struct { ... };
9236 * } SignedCertificateTimestamp;
9237 */
9238 uint32_t sct_version;
9239 uint64_t sct_timestamp_ms;
9240 nstime_t sct_timestamp;
9241 uint32_t exts_len;
9242 const char *log_name;
9243
9244 proto_tree_add_item_ret_uint(tree, hf->hf.sct_sct_version, tvb, offset, 1, ENC_NA0x00000000, &sct_version);
9245 offset++;
9246 if (sct_version != 0) {
9247 // TODO expert info about unknown SCT version?
9248 return offset;
9249 }
9250 proto_tree_add_item(tree, hf->hf.sct_sct_logid, tvb, offset, 32, ENC_BIG_ENDIAN0x00000000);
9251 log_name = bytesval_to_str_wmem(pinfo->pool, tvb_get_ptr(tvb, offset, 32), 32, ct_logids, "Unknown Log");
9252 proto_item_append_text(tree, " (%s)", log_name);
9253 offset += 32;
9254 sct_timestamp_ms = tvb_get_ntoh64(tvb, offset);
9255 sct_timestamp.secs = (time_t)(sct_timestamp_ms / 1000);
9256 sct_timestamp.nsecs = (int)((sct_timestamp_ms % 1000) * 1000000);
9257 proto_tree_add_time(tree, hf->hf.sct_sct_timestamp, tvb, offset, 8, &sct_timestamp);
9258 offset += 8;
9259 /* opaque CtExtensions<0..2^16-1> */
9260 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &exts_len,
9261 hf->hf.sct_sct_extensions_length, 0, UINT16_MAX(65535))) {
9262 return offset_end;
9263 }
9264 offset += 2;
9265 if (exts_len > 0) {
9266 proto_tree_add_item(tree, hf->hf.sct_sct_extensions, tvb, offset, exts_len, ENC_BIG_ENDIAN0x00000000);
9267 offset += exts_len;
9268 }
9269 offset = ssl_dissect_digitally_signed(hf, tvb, pinfo, tree, offset, offset_end, version,
9270 hf->hf.sct_sct_signature_length,
9271 hf->hf.sct_sct_signature);
9272 return offset;
9273}
9274
9275uint32_t
9276tls_dissect_sct_list(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
9277 uint32_t offset, uint32_t offset_end, uint16_t version)
9278{
9279 /* https://tools.ietf.org/html/rfc6962#section-3.3
9280 * opaque SerializedSCT<1..2^16-1>;
9281 * struct {
9282 * SerializedSCT sct_list <1..2^16-1>;
9283 * } SignedCertificateTimestampList;
9284 */
9285 uint32_t list_length, sct_length, next_offset;
9286 proto_tree *subtree;
9287
9288 /* SerializedSCT sct_list <1..2^16-1> */
9289 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &list_length,
9290 hf->hf.sct_scts_length, 1, UINT16_MAX(65535))) {
9291 return offset_end;
9292 }
9293 offset += 2;
9294
9295 while (offset < offset_end) {
9296 subtree = proto_tree_add_subtree(tree, tvb, offset, 2, hf->ett.sct, NULL((void*)0), "Signed Certificate Timestamp");
9297
9298 /* opaque SerializedSCT<1..2^16-1> */
9299 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, offset_end, &sct_length,
9300 hf->hf.sct_sct_length, 1, UINT16_MAX(65535))) {
9301 return offset_end;
9302 }
9303 offset += 2;
9304 next_offset = offset + sct_length;
9305 proto_item_set_len(subtree, 2 + sct_length);
9306 offset = tls_dissect_sct(hf, tvb, pinfo, subtree, offset, next_offset, version);
9307 if (!ssl_end_vector(hf, tvb, pinfo, subtree, offset, next_offset)) {
9308 offset = next_offset;
9309 }
9310 }
9311
9312 return offset;
9313}
9314
9315static int
9316dissect_ech_hpke_cipher_suite(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo _U___attribute__((unused)),
9317 proto_tree *tree, uint32_t offset)
9318{
9319 uint32_t kdf_id, aead_id;
9320 proto_item *cs_ti;
9321 proto_tree *cs_tree;
9322
9323 cs_ti = proto_tree_add_item(tree, hf->hf.ech_hpke_keyconfig_cipher_suite,
9324 tvb, offset, 4, ENC_NA0x00000000);
9325 cs_tree = proto_item_add_subtree(cs_ti, hf->ett.ech_hpke_cipher_suite);
9326
9327 proto_tree_add_item_ret_uint(cs_tree, hf->hf.ech_hpke_keyconfig_cipher_suite_kdf_id,
9328 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &kdf_id);
9329 offset += 2;
9330 proto_tree_add_item_ret_uint(cs_tree, hf->hf.ech_hpke_keyconfig_cipher_suite_aead_id,
9331 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &aead_id);
9332 offset += 2;
9333
9334 proto_item_append_text(cs_ti, ": %s/%s",
9335 val_to_str_const(kdf_id, kdf_id_type_vals, "Unknown"),
9336 val_to_str_const(aead_id, aead_id_type_vals, "Unknown"));
9337 return offset;
9338}
9339
9340static int
9341dissect_ech_hpke_key_config(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
9342 proto_tree *tree, uint32_t offset, uint32_t offset_end,
9343 uint32_t *config_id)
9344{
9345 uint32_t length, cipher_suite_length;
9346 proto_item *kc_ti, *css_ti;
9347 proto_tree *kc_tree, *css_tree;
9348 uint32_t original_offset = offset, next_offset;
9349
9350 kc_ti = proto_tree_add_item(tree, hf->hf.ech_hpke_keyconfig,
9351 tvb, offset, -1, ENC_NA0x00000000);
9352 kc_tree = proto_item_add_subtree(kc_ti, hf->ett.ech_hpke_keyconfig);
9353
9354 proto_tree_add_item_ret_uint(kc_tree, hf->hf.ech_hpke_keyconfig_config_id,
9355 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000, config_id);
9356 offset += 1;
9357 proto_tree_add_item(kc_tree, hf->hf.ech_hpke_keyconfig_kem_id,
9358 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
9359 offset += 2;
9360 proto_tree_add_item_ret_uint(kc_tree, hf->hf.ech_hpke_keyconfig_public_key_length,
9361 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &length);
9362 offset += 2;
9363 proto_tree_add_item(kc_tree, hf->hf.ech_hpke_keyconfig_public_key,
9364 tvb, offset, length, ENC_NA0x00000000);
9365 offset += length;
9366
9367 /* HpkeSymmetricCipherSuite cipher_suites<4..2^16-4> */
9368 if (!ssl_add_vector(hf, tvb, pinfo, kc_tree, offset, offset_end, &cipher_suite_length,
9369 hf->hf.ech_hpke_keyconfig_cipher_suites_length, 4, UINT16_MAX(65535) - 3)) {
9370 return offset_end;
9371 }
9372 offset += 2;
9373 next_offset = offset + cipher_suite_length;
9374
9375 css_ti = proto_tree_add_none_format(kc_tree,
9376 hf->hf.ech_hpke_keyconfig_cipher_suites,
9377 tvb, offset, cipher_suite_length,
9378 "Cipher Suites (%d suite%s)",
9379 cipher_suite_length / 4,
9380 plurality(cipher_suite_length / 4, "", "s")((cipher_suite_length / 4) == 1 ? ("") : ("s")));
9381 css_tree = proto_item_add_subtree(css_ti, hf->ett.ech_hpke_cipher_suites);
9382
9383
9384 while (offset + 4 <= next_offset) {
9385 offset = dissect_ech_hpke_cipher_suite(hf, tvb, pinfo, css_tree, offset);
9386 }
9387
9388 if (!ssl_end_vector(hf, tvb, pinfo, css_tree, offset, next_offset)) {
9389 offset = next_offset;
9390 }
9391
9392 proto_item_set_len(kc_ti, offset - original_offset);
9393
9394 return offset;
9395}
9396
9397static int
9398dissect_ech_echconfig_contents(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
9399 proto_tree *tree, uint32_t offset, uint32_t offset_end,
9400 const uint8_t **public_name, uint32_t *config_id)
9401{
9402 uint32_t public_name_length, extensions_length, next_offset;
9403
9404 offset = dissect_ech_hpke_key_config(hf, tvb, pinfo, tree, offset, offset_end, config_id);
9405 proto_tree_add_item(tree, hf->hf.ech_echconfigcontents_maximum_name_length,
9406 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
9407 offset += 1;
9408 proto_tree_add_item_ret_uint(tree, hf->hf.ech_echconfigcontents_public_name_length,
9409 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000, &public_name_length);
9410 offset += 1;
9411 proto_tree_add_item_ret_string(tree, hf->hf.ech_echconfigcontents_public_name,
9412 tvb, offset, public_name_length, ENC_ASCII0x00000000, pinfo->pool, public_name);
9413 offset += public_name_length;
9414
9415 /* Extension extensions<0..2^16-1>; */
9416 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &extensions_length,
9417 hf->hf.ech_echconfigcontents_extensions_length, 0, UINT16_MAX(65535))) {
9418 return offset_end;
9419 }
9420 offset += 2;
9421 next_offset = offset + extensions_length;
9422
9423 if (extensions_length > 0) {
9424 proto_tree_add_item(tree, hf->hf.ech_echconfigcontents_extensions,
9425 tvb, offset, extensions_length, ENC_NA0x00000000);
9426 }
9427 offset += extensions_length;
9428
9429 if (!ssl_end_vector(hf, tvb, pinfo, tree, offset, next_offset)) {
9430 offset = next_offset;
9431 }
9432
9433 return offset;
9434}
9435
9436static int
9437dissect_ech_echconfig(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
9438 proto_tree *tree, uint32_t offset, uint32_t offset_end)
9439{
9440 uint32_t version, length;
9441 proto_item *ech_ti;
9442 proto_tree *ech_tree;
9443 const uint8_t *public_name = NULL((void*)0);
9444 uint32_t config_id = 0;
9445
9446 ech_ti = proto_tree_add_item(tree, hf->hf.ech_echconfig, tvb, offset, -1, ENC_NA0x00000000);
9447 ech_tree = proto_item_add_subtree(ech_ti, hf->ett.ech_echconfig);
9448
9449 proto_tree_add_item_ret_uint(ech_tree, hf->hf.ech_echconfig_version,
9450 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &version);
9451 offset += 2;
9452 proto_tree_add_item_ret_uint(ech_tree, hf->hf.ech_echconfig_length,
9453 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &length);
9454 offset += 2;
9455
9456 proto_item_set_len(ech_ti, 4 + length);
9457
9458 switch(version) {
9459 case 0xfe0d:
9460 dissect_ech_echconfig_contents(hf, tvb, pinfo, ech_tree, offset, MIN(offset_end, offset + length)(((offset_end) < (offset + length)) ? (offset_end) : (offset
+ length))
, &public_name, &config_id);
9461 proto_item_append_text(ech_ti, ": id=%d %s", config_id, public_name);
9462 break;
9463
9464 default:
9465 expert_add_info_format(pinfo, ech_ti, &hf->ei.ech_echconfig_invalid_version, "Unsupported/unknown ECHConfig version 0x%x", version);
9466 }
9467
9468 return 4 + length;
9469}
9470
9471uint32_t
9472ssl_dissect_ext_ech_echconfiglist(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
9473 proto_tree *tree, uint32_t offset, uint32_t offset_end)
9474{
9475 uint32_t echconfiglist_length, next_offset;
9476
9477 /* ECHConfig ECHConfigList<1..2^16-1>; */
9478 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &echconfiglist_length,
9479 hf->hf.ech_echconfiglist_length, 1, UINT16_MAX(65535))) {
9480 return offset_end;
9481 }
9482 offset += 2;
9483 next_offset = offset + echconfiglist_length;
9484
9485 while (offset < next_offset) {
9486 offset += dissect_ech_echconfig(hf, tvb, pinfo, tree, offset, offset_end);
9487 }
9488
9489 if (!ssl_end_vector(hf, tvb, pinfo, tree, offset, next_offset)) {
9490 offset = next_offset;
9491 }
9492
9493 return offset;
9494}
9495
9496static uint32_t
9497ssl_dissect_hnd_ech_outer_ext(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
9498 uint32_t offset, uint32_t offset_end)
9499{
9500 uint32_t ext_length, next_offset;
9501 proto_tree *ext_tree;
9502 proto_item *ti;
9503
9504 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &ext_length,
9505 hf->hf.hs_ext_ech_outer_ext_len, 2, UINT8_MAX(255))) {
9506 return offset_end;
9507 }
9508 offset += 1;
9509 next_offset = offset + ext_length;
9510
9511 ti = proto_tree_add_none_format(tree,
9512 hf->hf.hs_ext_ech_outer_ext,
9513 tvb, offset, ext_length,
9514 "Outer Extensions (%d extension%s)",
9515 ext_length / 2,
9516 plurality(ext_length/2, "", "s")((ext_length/2) == 1 ? ("") : ("s")));
9517
9518 ext_tree = proto_item_add_subtree(ti, hf->ett.hs_ext);
9519
9520 while (offset + 2 <= next_offset) {
9521 proto_tree_add_item(ext_tree, hf->hf.hs_ext_type, tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
9522 offset += 2;
9523 }
9524
9525 if (!ssl_end_vector(hf, tvb, pinfo, ext_tree, offset, next_offset)) {
9526 offset = next_offset;
9527 }
9528
9529 return offset;
9530}
9531
9532static uint32_t
9533// NOLINTNEXTLINE(misc-no-recursion)
9534ssl_dissect_hnd_hello_ext_ech(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
9535 proto_tree *tree, uint32_t offset, uint32_t offset_end,
9536 uint8_t hnd_type, SslSession *session, SslDecryptSession *ssl, ssl_master_key_map_t *mk_map)
9537{
9538 uint32_t ch_type, length;
9539 proto_item *ti, *payload_ti;
9540 proto_tree *retry_tree, *payload_tree;
9541 uint32_t hello_length = tvb_reported_length(tvb);
9542
9543 switch (hnd_type) {
9544 case SSL_HND_CLIENT_HELLO:
9545 /*
9546 * enum { outer(0), inner(1) } ECHClientHelloType;
9547 *
9548 * struct {
9549 * ECHClientHelloType type;
9550 * select (ECHClientHello.type) {
9551 * case outer:
9552 * HpkeSymmetricCipherSuite cipher_suite;
9553 * uint8 config_id;
9554 * opaque enc<0..2^16-1>;
9555 * opaque payload<1..2^16-1>;
9556 * case inner:
9557 * Empty;
9558 * };
9559 * } ECHClientHello;
9560 */
9561
9562 proto_tree_add_item_ret_uint(tree, hf->hf.ech_clienthello_type, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000, &ch_type);
9563 offset += 1;
9564 switch (ch_type) {
9565 case 0: /* outer */
9566 if (ssl && session->first_ch_ech_frame == 0) {
9567 session->first_ch_ech_frame = pinfo->num;
9568 }
9569 offset = dissect_ech_hpke_cipher_suite(hf, tvb, pinfo, tree, offset);
9570 uint16_t kdf_id = tvb_get_ntohs(tvb, offset - 4);
9571 uint16_t aead_id = tvb_get_ntohs(tvb, offset - 2);
9572
9573 proto_tree_add_item(tree, hf->hf.ech_config_id, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
9574 uint8_t config_id = tvb_get_uint8(tvb, offset);
9575 offset += 1;
9576 proto_tree_add_item_ret_uint(tree, hf->hf.ech_enc_length, tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &length);
9577 offset += 2;
9578 proto_tree_add_item(tree, hf->hf.ech_enc, tvb, offset, length, ENC_NA0x00000000);
9579 offset += length;
9580 proto_tree_add_item_ret_uint(tree, hf->hf.ech_payload_length, tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &length);
9581 offset += 2;
9582 payload_ti = proto_tree_add_item(tree, hf->hf.ech_payload, tvb, offset, length, ENC_NA0x00000000);
9583 offset += length;
9584
9585 /* XXX - We could save the decrypted Client Hello instead of
9586 * recalculating it every pass, similar to what is done with
9587 * normal encrypted records. Normally there shouldn't be many
9588 * ECH so it doesn't make much difference either way. */
9589 if (!mk_map) {
9590 break;
9591 }
9592 if (session->client_random.data_len == 0) {
9593 ssl_debug_printf("%s missing Client Random\n", G_STRFUNC((const char*) (__func__)));
9594 break;
9595 }
9596 StringInfo *ech_secret = (StringInfo *)g_hash_table_lookup(mk_map->ech_secret, &session->client_random);
9597 StringInfo *ech_config = (StringInfo *)g_hash_table_lookup(mk_map->ech_config, &session->client_random);
9598 if (!ech_secret || !ech_config) {
9599 ssl_debug_printf("%s Cannot find ECH_SECRET or ECH_CONFIG, Encrypted Client Hello decryption impossible\n",
9600 G_STRFUNC((const char*) (__func__)));
9601 break;
9602 }
9603
9604 if (hpke_hkdf_len(kdf_id) == 0) {
9605 ssl_debug_printf("Unsupported KDF\n");
9606 break;
9607 }
9608
9609 if (hpke_aead_key_len(aead_id) == 0) {
9610 ssl_debug_printf("Unsupported AEAD\n");
9611 break;
9612 }
9613
9614 size_t aead_nonce_len = hpke_aead_nonce_len(aead_id);
9615
9616 unsigned aead_auth_tag_len = hpke_aead_auth_tag_len(aead_id);
9617 if (length < aead_auth_tag_len) {
9618 ssl_debug_printf("Encrypted payload length %u < Cipher suite authentication tag length %u.\n", length, aead_auth_tag_len);
9619 break;
9620 }
9621 unsigned decrypted_len = length - aead_auth_tag_len;
9622
9623 uint16_t version = pntohu16(ech_config->data);
9624 if (version != SSL_HND_HELLO_EXT_ENCRYPTED_CLIENT_HELLO65037) {
9625 ssl_debug_printf("Unexpected version in ECH Config\n");
9626 break;
9627 }
9628 uint32_t ech_config_offset = 2;
9629 if (pntohu16(&ech_config->data[ech_config_offset]) != ech_config->data_len - 4) {
9630 ssl_debug_printf("Malformed ECH Config, invalid length\n");
9631 break;
9632 }
9633 ech_config_offset += 2;
9634 if (*(ech_config->data + ech_config_offset) != config_id) {
9635 ssl_debug_printf("ECH Config version mismatch\n");
9636 break;
9637 }
9638 ech_config_offset += 1;
9639 uint16_t kem_id = pntohu16(&ech_config->data[ech_config_offset]);
9640 uint8_t suite_id[HPKE_SUIT_ID_LEN10];
9641 hpke_suite_id(kem_id, kdf_id, aead_id, suite_id);
9642 GByteArray *info = g_byte_array_new();
9643 g_byte_array_append(info, (const uint8_t*)"tls ech", 8);
9644 g_byte_array_append(info, ech_config->data, ech_config->data_len);
9645 uint8_t key[AEAD_MAX_KEY_LENGTH32];
9646 uint8_t base_nonce[HPKE_AEAD_NONCE_LENGTH12];
9647 if (hpke_key_schedule(kdf_id, aead_id, ech_secret->data, ech_secret->data_len, suite_id, info->data, info->len, HPKE_MODE_BASE0,
9648 key, base_nonce)) {
9649 g_byte_array_free(info, TRUE(!(0)));
9650 break;
9651 }
9652 g_byte_array_free(info, TRUE(!(0)));
9653 gcry_cipher_hd_t cipher;
9654 if (hpke_setup_aead(&cipher, aead_id, key) ||
9655 hpke_set_nonce(cipher, !session->hrr_ech_declined && pinfo->num > session->first_ch_ech_frame, base_nonce, aead_nonce_len)) {
9656 gcry_cipher_close(cipher);
9657 break;
9658 }
9659 const uint8_t *payload = tvb_get_ptr(tvb, offset - length, length);
9660 uint8_t *ech_aad = (uint8_t *)wmem_alloc(NULL((void*)0), hello_length);
9661 tvb_memcpy(tvb, ech_aad, 0, hello_length);
9662 memset(ech_aad + offset - length, 0, length);
9663 if (gcry_cipher_authenticate(cipher, ech_aad, hello_length)) {
9664 gcry_cipher_close(cipher);
9665 wmem_free(NULL((void*)0), ech_aad);
9666 break;
9667 }
9668 wmem_free(NULL((void*)0), ech_aad);
9669 uint8_t *ech_decrypted_data = (uint8_t *)wmem_alloc(pinfo->pool, decrypted_len);
9670 if (gcry_cipher_decrypt(cipher, ech_decrypted_data, decrypted_len, payload, decrypted_len)) {
9671 gcry_cipher_close(cipher);
9672 break;
9673 }
9674 unsigned char *ech_auth_tag_calc = wmem_alloc0(pinfo->pool, aead_auth_tag_len);
9675 if (gcry_cipher_gettag(cipher, ech_auth_tag_calc, aead_auth_tag_len)) {
9676 gcry_cipher_close(cipher);
9677 break;
9678 }
9679 if (ssl && !session->hrr_ech_declined && session->first_ch_ech_frame == pinfo->num)
9680 memcpy(session->first_ech_auth_tag, ech_auth_tag_calc, aead_auth_tag_len);
9681 gcry_cipher_close(cipher);
9682 if (memcmp(pinfo->num > session->first_ch_ech_frame ? ech_auth_tag_calc : session->first_ech_auth_tag,
9683 payload + decrypted_len, aead_auth_tag_len)) {
9684 ssl_debug_printf("%s ECH auth tag mismatch\n", G_STRFUNC((const char*) (__func__)));
9685 } else {
9686 payload_tree = proto_item_add_subtree(payload_ti, hf->ett.ech_decrypt);
9687 tvbuff_t *ech_tvb = tvb_new_child_real_data(tvb, ech_decrypted_data, decrypted_len, decrypted_len);
9688 add_new_data_source(pinfo, ech_tvb, "Client Hello Inner");
9689 if (ssl) {
9690 /* Note the Outer Client Random for Inject TLS Secrets */
9691 tls_save_crandom(ssl, mk_map);
9692
9693 tvb_memcpy(ech_tvb, ssl->client_random.data, 2, 32);
9694 /* Build ClientHelloInner here and then add it to the
9695 * transcript, which might only keep the digest state. */
9696 unsigned char *inner = (unsigned char*)wmem_alloc(pinfo->pool, hello_length + 4);
9697 uint32_t inner_len;
9698 inner[0] = SSL_HND_CLIENT_HELLO;
9699 inner[1] = 0;
9700 /* Copy ClientHelloInner up to the legacy_session_id field. */
9701 tvb_memcpy(ech_tvb, inner + 4, 0, 34);
9702 inner_len = 38;
9703 /* Now copy the legacy_session_id field from ClientHelloOuter. */
9704 inner[inner_len] = ssl->session_id.data_len;
9705 inner_len++;
9706 memcpy(&inner[inner_len], ssl->session_id.data, ssl->session_id.data_len);
9707 inner_len += ssl->session_id.data_len;
9708 /* Skip past the legacy_session_id field in ClientHelloInner
9709 * (which should be the empty string, i.e. just a 0 size.) */
9710 uint32_t ech_offset = 35 + tvb_get_uint8(ech_tvb, 34);
9711 /* Copy the Cipher Suites from ClientHelloInner. */
9712 tvb_memcpy(ech_tvb, inner + inner_len, ech_offset,
9713 2 + tvb_get_ntohs(ech_tvb, ech_offset));
9714 inner_len += 2 + tvb_get_ntohs(ech_tvb, ech_offset);
9715 ech_offset += 2 + tvb_get_ntohs(ech_tvb, ech_offset);
9716 /* Copy the Compression Methods */
9717 tvb_memcpy(ech_tvb, inner + inner_len, ech_offset,
9718 1 + tvb_get_uint8(ech_tvb, ech_offset));
9719 inner_len += 1 + tvb_get_uint8(ech_tvb, ech_offset);
9720 ech_offset += 1 + tvb_get_uint8(ech_tvb, ech_offset);
9721 /* Now replace extensions in ech_outer_extensions with the
9722 * data from ClientHelloOuter. */
9723 uint32_t ech_extensions_len_offset = inner_len;
9724 inner_len += 2;
9725 uint32_t extensions_end = ech_offset + tvb_get_ntohs(ech_tvb, ech_offset) + 2;
9726 ech_offset += 2;
9727 bool_Bool ech_outer_extensions_found = false0;
9728 while (extensions_end - ech_offset >= 4) {
9729 uint16_t ext_type = tvb_get_ntohs(ech_tvb, ech_offset);
9730 ech_offset += 2;
9731 uint16_t ext_len = tvb_get_ntohs(ech_tvb, ech_offset);
9732 ech_offset += 2;
9733 if (ext_type != SSL_HND_HELLO_EXT_ECH_OUTER_EXTENSIONS64768) {
9734 /* Copy this extension directly */
9735 tvb_memcpy(ech_tvb, inner + inner_len,
9736 ech_offset - 4, 4 + ext_len);
9737 inner_len += 4 + ext_len;
9738 ech_offset += ext_len;
9739 } else if (ext_len > 0) {
9740 if (ech_outer_extensions_found) {
9741 ssl_debug_printf("Illegal parameter; only a single \"ech_outer_extensions\" extension is allowed\n");
9742 /* This could lead to a buffer overflow by
9743 * making the post-copying ClientHelloInner
9744 * longer than ClientHelloOuter and is
9745 * illegal, so skip this and don't copy. */
9746 ech_offset += ext_len;
9747 continue;
9748 }
9749 ech_outer_extensions_found = true1;
9750 unsigned num_ech_outer_extensions = tvb_get_uint8(ech_tvb, ech_offset);
9751 ech_offset += 1;
9752 uint32_t ech_outer_extensions_end = ech_offset + num_ech_outer_extensions;
9753 /* In ClientHelloOuter, skip past the legacy_session_id */
9754 uint32_t outer_offset = 35 + tvb_get_uint8(tvb, 34);
9755 /* Skip past Cipher Suites */
9756 outer_offset += tvb_get_ntohs(tvb, outer_offset) + 2;
9757 /* Skip past Compression Methods */
9758 outer_offset += tvb_get_uint8(tvb, outer_offset) + 3;
9759 /* Now at the start of ClientHelloOuter's extensions */
9760 while (ech_outer_extensions_end - ech_offset >= 2) {
9761 ext_type = tvb_get_ntohs(ech_tvb, ech_offset);
9762 if (ext_type == SSL_HND_HELLO_EXT_ENCRYPTED_CLIENT_HELLO65037) {
9763 ssl_debug_printf("Illegal parameter; encrypted_client_hello cannot appear within ech_outer_extensions\n");
9764 /* This could lead to a buffer overflow by
9765 * making the post-copying ClientHelloInner
9766 * longer than ClientHelloOuter and is
9767 * illegal, so don't copy. */
9768 break;
9769 }
9770 bool_Bool found = false0;
9771 while (tvb_reported_length_remaining(tvb, outer_offset) >= 4) {
9772 uint16_t outer_ext_type = tvb_get_ntohs(tvb, outer_offset);
9773 uint16_t outer_ext_len = tvb_get_ntohs(tvb, outer_offset + 2);
9774 if (ext_type == outer_ext_type) {
9775 tvb_memcpy(tvb, inner + inner_len, outer_offset,
9776 4 + outer_ext_len);
9777 inner_len += 4 + outer_ext_len;
9778 outer_offset += 4 + outer_ext_len;
9779 found = true1;
9780 break;
9781 } else {
9782 outer_offset += 4 + outer_ext_len;
9783 }
9784 }
9785 if (!found) {
9786 ssl_debug_printf("Extension %s was not found in ClientHelloOuter (possibly out of order or referenced more than once)\n", val_to_str(pinfo->pool, ext_type, tls_hello_extension_types, "unknown (0x%02x)"));
9787 }
9788 ech_offset += 2;
9789 }
9790 }
9791 }
9792 uint16_t ech_extensions_len = inner_len - ech_extensions_len_offset - 2;
9793 phtonu16(&inner[ech_extensions_len_offset], ech_extensions_len);
9794 phtonu16(&inner[2], inner_len - 4);
9795 tls_transcript_add(&ssl->ech_transcript, inner, inner_len);
9796 }
9797 uint32_t ech_padding_begin = (uint32_t)ssl_dissect_hnd_cli_hello(hf, ech_tvb, pinfo, payload_tree, 0, decrypted_len, session,
9798 ssl, NULL((void*)0), mk_map);
9799 if (ech_padding_begin < decrypted_len) {
9800 proto_tree_add_item(payload_tree, hf->hf.ech_padding_data, ech_tvb, ech_padding_begin, decrypted_len - ech_padding_begin,
9801 ENC_NA0x00000000);
9802 }
9803 }
9804
9805 break;
9806 case 1: /* inner */
9807 break;
9808 }
9809 break;
9810
9811 case SSL_HND_ENCRYPTED_EXTENSIONS:
9812 /*
9813 * struct {
9814 * ECHConfigList retry_configs;
9815 * } ECHEncryptedExtensions;
9816 */
9817
9818 ti = proto_tree_add_item(tree, hf->hf.ech_retry_configs, tvb, offset, offset_end - offset, ENC_NA0x00000000);
9819 retry_tree = proto_item_add_subtree(ti, hf->ett.ech_retry_configs);
9820 offset = ssl_dissect_ext_ech_echconfiglist(hf, tvb, pinfo, retry_tree, offset, offset_end);
9821 break;
9822
9823 case SSL_HND_HELLO_RETRY_REQUEST:
9824 /*
9825 * struct {
9826 * opaque confirmation[8];
9827 * } ECHHelloRetryRequest;
9828 */
9829
9830 proto_tree_add_item(tree, hf->hf.ech_confirmation, tvb, offset, 8, ENC_NA0x00000000);
9831 if (session->ech) {
9832 ti = proto_tree_add_bytes_with_length(tree, hf->hf.hs_ech_confirm_compute, tvb, offset, 0, session->hrr_ech_confirmation, 8);
9833 proto_item_set_generated(ti);
9834 if (tvb_memeql(tvb, offset, session->hrr_ech_confirmation, 8) != 0) {
9835 expert_add_info(pinfo, ti, &hf->ei.ech_rejected);
9836 } else {
9837 expert_add_info(pinfo, ti, &hf->ei.ech_accepted);
9838 }
9839 }
9840 offset += 8;
9841 break;
9842 }
9843
9844 return offset;
9845}
9846
9847static uint32_t
9848ssl_dissect_hnd_hello_ext_esni(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
9849 proto_tree *tree, uint32_t offset, uint32_t offset_end,
9850 uint8_t hnd_type, SslDecryptSession *ssl _U___attribute__((unused)))
9851{
9852 uint32_t record_digest_length, encrypted_sni_length;
9853
9854 switch (hnd_type) {
9855 case SSL_HND_CLIENT_HELLO:
9856 /*
9857 * struct {
9858 * CipherSuite suite;
9859 * KeyShareEntry key_share;
9860 * opaque record_digest<0..2^16-1>;
9861 * opaque encrypted_sni<0..2^16-1>;
9862 * } ClientEncryptedSNI;
9863 */
9864 proto_tree_add_item(tree, hf->hf.esni_suite, tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
9865 offset += 2;
9866 offset = ssl_dissect_hnd_hello_ext_key_share_entry(hf, tvb, pinfo, tree, offset, offset_end, NULL((void*)0));
9867
9868 /* opaque record_digest<0..2^16-1> */
9869 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &record_digest_length,
9870 hf->hf.esni_record_digest_length, 0, UINT16_MAX(65535))) {
9871 return offset_end;
9872 }
9873 offset += 2;
9874 if (record_digest_length > 0) {
9875 proto_tree_add_item(tree, hf->hf.esni_record_digest, tvb, offset, record_digest_length, ENC_NA0x00000000);
9876 offset += record_digest_length;
9877 }
9878
9879 /* opaque encrypted_sni<0..2^16-1> */
9880 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &encrypted_sni_length,
9881 hf->hf.esni_encrypted_sni_length, 0, UINT16_MAX(65535))) {
9882 return offset_end;
9883 }
9884 offset += 2;
9885 if (encrypted_sni_length > 0) {
9886 proto_tree_add_item(tree, hf->hf.esni_encrypted_sni, tvb, offset, encrypted_sni_length, ENC_NA0x00000000);
9887 offset += encrypted_sni_length;
9888 }
9889 break;
9890
9891 case SSL_HND_ENCRYPTED_EXTENSIONS:
9892 proto_tree_add_item(tree, hf->hf.esni_nonce, tvb, offset, 16, ENC_NA0x00000000);
9893 offset += 16;
9894 break;
9895 }
9896
9897 return offset;
9898}
9899/** TLS Extensions (in Client Hello and Server Hello). }}} */
9900
9901/* Connection ID dissection. {{{ */
9902static uint32_t
9903ssl_dissect_ext_connection_id(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
9904 proto_tree *tree, uint32_t offset, SslDecryptSession *ssl,
9905 uint8_t cidl, uint8_t **session_cid, uint8_t *session_cidl)
9906{
9907 /* keep track of the decrypt session only for the first pass */
9908 if (cidl > 0 && !PINFO_FD_VISITED(pinfo)((pinfo)->fd->visited)) {
9909 tvb_ensure_bytes_exist(tvb, offset + 1, cidl);
9910 *session_cidl = cidl;
9911 *session_cid = (uint8_t*)wmem_alloc0(wmem_file_scope(), cidl);
9912 tvb_memcpy(tvb, *session_cid, offset + 1, cidl);
9913 if (ssl) {
9914 ssl_add_session_by_cid(ssl);
9915 }
9916 }
9917
9918 proto_tree_add_item(tree, hf->hf.hs_ext_connection_id_length,
9919 tvb, offset, 1, ENC_NA0x00000000);
9920 offset++;
9921
9922 if (cidl > 0) {
9923 proto_tree_add_item(tree, hf->hf.hs_ext_connection_id,
9924 tvb, offset, cidl, ENC_NA0x00000000);
9925 offset += cidl;
9926 }
9927
9928 return offset;
9929}
9930
9931static uint32_t
9932ssl_dissect_hnd_hello_ext_connection_id(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
9933 proto_tree *tree, uint32_t offset, uint8_t hnd_type,
9934 SslSession *session, SslDecryptSession *ssl)
9935{
9936 uint8_t cidl = tvb_get_uint8(tvb, offset);
9937
9938 switch (hnd_type) {
9939 case SSL_HND_CLIENT_HELLO:
9940 session->client_cid_len_present = true1;
9941 return ssl_dissect_ext_connection_id(hf, tvb, pinfo, tree, offset, ssl,
9942 cidl, &session->client_cid, &session->client_cid_len);
9943 case SSL_HND_SERVER_HELLO:
9944 session->server_cid_len_present = true1;
9945 return ssl_dissect_ext_connection_id(hf, tvb, pinfo, tree, offset, ssl,
9946 cidl, &session->server_cid, &session->server_cid_len);
9947 default:
9948 return offset;
9949 }
9950} /* }}} */
9951
9952/* Trusted CA dissection. {{{ */
9953static uint32_t
9954ssl_dissect_hnd_hello_ext_trusted_ca_keys(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
9955 uint32_t offset, uint32_t offset_end)
9956{
9957 proto_item *ti;
9958 proto_tree *subtree;
9959 uint32_t keys_length, next_offset;
9960
9961 /*
9962 * struct {
9963 * TrustedAuthority trusted_authorities_list<0..2^16-1>;
9964 * } TrustedAuthorities;
9965 *
9966 * struct {
9967 * IdentifierType identifier_type;
9968 * select (identifier_type) {
9969 * case pre_agreed: struct {};
9970 * case key_sha1_hash: SHA1Hash;
9971 * case x509_name: DistinguishedName;
9972 * case cert_sha1_hash: SHA1Hash;
9973 * } identifier;
9974 * } TrustedAuthority;
9975 *
9976 * enum {
9977 * pre_agreed(0), key_sha1_hash(1), x509_name(2),
9978 * cert_sha1_hash(3), (255)
9979 * } IdentifierType;
9980 *
9981 * opaque DistinguishedName<1..2^16-1>;
9982 *
9983 */
9984
9985
9986 /* TrustedAuthority trusted_authorities_list<0..2^16-1> */
9987 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &keys_length, hf->hf.hs_ext_trusted_ca_keys_len,
9988 0, UINT16_MAX(65535)))
9989 {
9990 return offset_end;
9991 }
9992 offset += 2;
9993 next_offset = offset + keys_length;
9994
9995 if (keys_length > 0)
9996 {
9997 ti = proto_tree_add_none_format(tree, hf->hf.hs_ext_trusted_ca_keys_list, tvb, offset, keys_length,
9998 "Trusted CA keys (%d byte%s)", keys_length, plurality(keys_length, "", "s")((keys_length) == 1 ? ("") : ("s")));
9999 subtree = proto_item_add_subtree(ti, hf->ett.hs_ext_trusted_ca_keys);
10000
10001 while (offset < next_offset)
10002 {
10003 uint32_t identifier_type;
10004 proto_tree *trusted_key_tree;
10005 proto_item *trusted_key_item;
10006 asn1_ctx_t asn1_ctx;
10007 uint32_t key_len = 0;
10008
10009 identifier_type = tvb_get_uint8(tvb, offset);
10010
10011 // Use 0 as length for now as we'll only know the size when we decode the identifier
10012 trusted_key_item = proto_tree_add_none_format(subtree, hf->hf.hs_ext_trusted_ca_key, tvb,
10013 offset, 0, "Trusted CA Key");
10014 trusted_key_tree = proto_item_add_subtree(trusted_key_item, hf->ett.hs_ext_trusted_ca_key);
10015
10016 proto_tree_add_uint(trusted_key_tree, hf->hf.hs_ext_trusted_ca_key_type, tvb,
10017 offset, 1, identifier_type);
10018 offset++;
10019
10020 /*
10021 * enum {
10022 * pre_agreed(0), key_sha1_hash(1), x509_name(2),
10023 * cert_sha1_hash(3), (255)
10024 * } IdentifierType;
10025 */
10026 switch (identifier_type)
10027 {
10028 case 0:
10029 key_len = 0;
10030 break;
10031 case 2:
10032 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true1, pinfo);
10033
10034 uint32_t name_length;
10035 /* opaque DistinguishedName<1..2^16-1> */
10036 if (!ssl_add_vector(hf, tvb, pinfo, trusted_key_tree, offset, next_offset, &name_length,
10037 hf->hf.hs_ext_trusted_ca_key_dname_len, 1, UINT16_MAX(65535))) {
10038 return next_offset;
10039 }
10040 offset += 2;
10041
10042 dissect_x509if_DistinguishedName(false0, tvb, offset, &asn1_ctx,
10043 trusted_key_tree, hf->hf.hs_ext_trusted_ca_key_dname);
10044 offset += name_length;
10045 break;
10046 case 1:
10047 case 3:
10048 key_len = 20;
10049 /* opaque SHA1Hash[20]; */
10050 proto_tree_add_item(trusted_key_tree, hf->hf.hs_ext_trusted_ca_key_hash, tvb,
10051 offset, 20, ENC_NA0x00000000);
10052 break;
10053
10054 default:
10055 key_len = 0;
10056 /*TODO display expert info about unknown ? */
10057 break;
10058 }
10059 proto_item_set_len(trusted_key_item, 1 + key_len);
10060 offset += key_len;
10061 }
10062 }
10063
10064 if (!ssl_end_vector(hf, tvb, pinfo, tree, offset, next_offset))
10065 {
10066 offset = next_offset;
10067 }
10068
10069 return offset;
10070} /* }}} */
10071
10072
10073/* Whether the Content and Handshake Types are valid; handle Protocol Version. {{{ */
10074bool_Bool
10075ssl_is_valid_content_type(uint8_t type)
10076{
10077 switch ((ContentType) type) {
10078 case SSL_ID_CHG_CIPHER_SPEC:
10079 case SSL_ID_ALERT:
10080 case SSL_ID_HANDSHAKE:
10081 case SSL_ID_APP_DATA:
10082 case SSL_ID_HEARTBEAT:
10083 case SSL_ID_TLS12_CID:
10084 case SSL_ID_DTLS13_ACK:
10085 return true1;
10086 }
10087 return false0;
10088}
10089
10090bool_Bool
10091ssl_is_valid_handshake_type(uint8_t hs_type, bool_Bool is_dtls)
10092{
10093 switch ((HandshakeType) hs_type) {
10094 case SSL_HND_HELLO_VERIFY_REQUEST:
10095 /* hello_verify_request is DTLS-only */
10096 return is_dtls;
10097
10098 case SSL_HND_HELLO_REQUEST:
10099 case SSL_HND_CLIENT_HELLO:
10100 case SSL_HND_SERVER_HELLO:
10101 case SSL_HND_NEWSESSION_TICKET:
10102 case SSL_HND_END_OF_EARLY_DATA:
10103 case SSL_HND_HELLO_RETRY_REQUEST:
10104 case SSL_HND_ENCRYPTED_EXTENSIONS:
10105 case SSL_HND_CERTIFICATE:
10106 case SSL_HND_SERVER_KEY_EXCHG:
10107 case SSL_HND_CERT_REQUEST:
10108 case SSL_HND_SVR_HELLO_DONE:
10109 case SSL_HND_CERT_VERIFY:
10110 case SSL_HND_CLIENT_KEY_EXCHG:
10111 case SSL_HND_FINISHED:
10112 case SSL_HND_CERT_URL:
10113 case SSL_HND_CERT_STATUS:
10114 case SSL_HND_SUPPLEMENTAL_DATA:
10115 case SSL_HND_KEY_UPDATE:
10116 case SSL_HND_COMPRESSED_CERTIFICATE:
10117 case SSL_HND_ENCRYPTED_EXTS:
10118 return true1;
10119 case SSL_HND_MESSAGE_HASH:
10120 return false0;
10121 }
10122 return false0;
10123}
10124
10125static bool_Bool
10126ssl_is_authoritative_version_message(uint8_t content_type, uint8_t handshake_type,
10127 bool_Bool is_dtls)
10128{
10129 /* Consider all valid Handshake messages (except for Client Hello) and
10130 * all other valid record types (other than Handshake) */
10131 return (content_type == SSL_ID_HANDSHAKE &&
10132 ssl_is_valid_handshake_type(handshake_type, is_dtls) &&
10133 handshake_type != SSL_HND_CLIENT_HELLO) ||
10134 (content_type != SSL_ID_HANDSHAKE &&
10135 ssl_is_valid_content_type(content_type));
10136}
10137
10138/**
10139 * Scan a Server Hello handshake message for the negotiated version. For TLS 1.3
10140 * draft 22 and newer, it also checks whether it is a HelloRetryRequest.
10141 * Returns true if the supported_versions extension was found, false if not.
10142 */
10143bool_Bool
10144tls_scan_server_hello(tvbuff_t *tvb, uint32_t offset, uint32_t offset_end,
10145 uint16_t *server_version, bool_Bool *is_hrr)
10146{
10147 /* SHA256("HelloRetryRequest") */
10148 static const uint8_t tls13_hrr_random_magic[] = {
10149 0xcf, 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11, 0xbe, 0x1d, 0x8c, 0x02, 0x1e, 0x65, 0xb8, 0x91,
10150 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e, 0x07, 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c
10151 };
10152 uint8_t session_id_length;
10153
10154 *server_version = tvb_get_ntohs(tvb, offset);
10155
10156 /*
10157 * Try to look for supported_versions extension. Minimum length:
10158 * 2 + 32 + 1 = 35 (version, random, session id length)
10159 * 2 + 1 + 2 = 5 (cipher suite, compression method, extensions length)
10160 * 2 + 2 + 2 = 6 (ext type, ext len, version)
10161 *
10162 * We only check for the [legacy_]version field to be [D]TLS 1.2; if it's 1.3,
10163 * there's a separate expert info warning for that.
10164 */
10165 if ((*server_version == TLSV1DOT2_VERSION0x303 || *server_version == DTLSV1DOT2_VERSION0xfefd) && offset_end - offset >= 46) {
10166 offset += 2;
10167 if (is_hrr) {
10168 *is_hrr = tvb_memeql(tvb, offset, tls13_hrr_random_magic, sizeof(tls13_hrr_random_magic)) == 0;
10169 }
10170 offset += 32;
10171 session_id_length = tvb_get_uint8(tvb, offset);
10172 offset++;
10173 if (offset_end - offset < session_id_length + 5u) {
10174 return false0;
10175 }
10176 offset += session_id_length + 5;
10177
10178 while (offset_end - offset >= 6) {
10179 uint16_t ext_type = tvb_get_ntohs(tvb, offset);
10180 uint16_t ext_len = tvb_get_ntohs(tvb, offset + 2);
10181 if (offset_end - offset < 4u + ext_len) {
10182 break; /* not enough data for type, length and data */
10183 }
10184 if (ext_type == SSL_HND_HELLO_EXT_SUPPORTED_VERSIONS43) {
10185 if (ext_len == 2) {
10186 *server_version = tvb_get_ntohs(tvb, offset + 4);
10187 }
10188 return true1;
10189 }
10190 offset += 4 + ext_len;
10191 }
10192 } else {
10193 if (is_hrr) {
10194 *is_hrr = false0;
10195 }
10196 }
10197 return false0;
10198}
10199
10200/**
10201 * Scan a Client Hello handshake message to see if the supported_versions
10202 * extension is found, in which case the version field is legacy_version.
10203 */
10204static bool_Bool
10205tls_scan_client_hello(tvbuff_t *tvb, uint32_t offset, uint32_t offset_end)
10206{
10207 uint8_t session_id_length;
10208
10209 uint16_t client_version = tvb_get_ntohs(tvb, offset);
10210
10211 /*
10212 * Try to look for supported_versions extension. Minimum length:
10213 * 2 + 32 + 1 = 35 (version, random, session id length)
10214 * 2 + 2 + 1 + 2 = 5 (cipher suite, compression method, extensions length)
10215 * 2 + 2 + 2 = 6 (ext type, ext len, version)
10216 *
10217 * We only check for the [legacy_]version field to be [D]TLS 1.2; if it's 1.3,
10218 * there's a separate expert info warning for that.
10219 */
10220 if ((client_version == TLSV1DOT2_VERSION0x303 || client_version == DTLSV1DOT2_VERSION0xfefd) && offset_end - offset >= 46) {
10221 offset += 2;
10222 offset += 32;
10223 session_id_length = tvb_get_uint8(tvb, offset);
10224 offset++;
10225 if (offset_end - offset < session_id_length + 2u) {
10226 return false0;
10227 }
10228 offset += session_id_length;
10229 if (client_version == DTLSV1DOT2_VERSION0xfefd) {
10230 uint8_t cookie_length = tvb_get_uint8(tvb, offset);
10231 offset++;
10232 if (offset_end - offset < cookie_length + 2u) {
10233 return false0;
10234 }
10235 }
10236 uint16_t cipher_suites_length = tvb_get_ntohs(tvb, offset);
10237 offset += 2;
10238 if (offset_end - offset < cipher_suites_length + 1u) {
10239 return false0;
10240 }
10241 offset += cipher_suites_length;
10242 uint8_t compression_methods_length = tvb_get_uint8(tvb, offset);
10243 offset++;
10244 if (offset_end - offset < compression_methods_length + 2u) {
10245 return false0;
10246 }
10247 offset += compression_methods_length + 2;
10248
10249 while (offset_end - offset >= 6) {
10250 uint16_t ext_type = tvb_get_ntohs(tvb, offset);
10251 uint16_t ext_len = tvb_get_ntohs(tvb, offset + 2);
10252 if (offset_end - offset < 4u + ext_len) {
10253 break; /* not enough data for type, length and data */
10254 }
10255 if (ext_type == SSL_HND_HELLO_EXT_SUPPORTED_VERSIONS43) {
10256 return true1;
10257 }
10258 offset += 4 + ext_len;
10259 }
10260 }
10261 return false0;
10262}
10263void
10264ssl_try_set_version(SslSession *session, SslDecryptSession *ssl,
10265 uint8_t content_type, uint8_t handshake_type,
10266 bool_Bool is_dtls, uint16_t version)
10267{
10268 uint8_t tls13_draft = 0;
10269
10270 if (!ssl_is_authoritative_version_message(content_type, handshake_type,
10271 is_dtls))
10272 return;
10273
10274 version = tls_try_get_version(is_dtls, version, &tls13_draft);
10275 if (version == SSL_VER_UNKNOWN0) {
10276 return;
10277 }
10278
10279 session->tls13_draft_version = tls13_draft;
10280 session->version = version;
10281 if (ssl) {
10282 ssl->state |= SSL_VERSION(1<<4);
10283 ssl_debug_printf("%s found version 0x%04X -> state 0x%02X\n", G_STRFUNC((const char*) (__func__)), version, ssl->state);
10284 }
10285}
10286
10287void
10288ssl_check_record_length(ssl_common_dissect_t *hf, packet_info *pinfo,
10289 ContentType content_type,
10290 unsigned record_length, proto_item *length_pi,
10291 uint16_t version, tvbuff_t *decrypted_tvb)
10292{
10293 unsigned max_expansion;
10294 if (version == TLSV1DOT3_VERSION0x304) {
10295 /* TLS 1.3: Max length is 2^14 + 256 */
10296 max_expansion = 256;
10297 } else {
10298 /* RFC 5246, Section 6.2.3: TLSCiphertext.fragment length MUST NOT exceed 2^14 + 2048 */
10299 max_expansion = 2048;
10300 }
10301 /*
10302 * RFC 5246 (TLS 1.2), Section 6.2.1 forbids zero-length Handshake, Alert
10303 * and ChangeCipherSpec.
10304 * RFC 6520 (Heartbeats) does not mention zero-length Heartbeat fragments,
10305 * so assume it is permitted.
10306 * RFC 6347 (DTLS 1.2) does not mention zero-length fragments either, so
10307 * assume TLS 1.2 requirements.
10308 */
10309 if (record_length == 0 &&
10310 (content_type == SSL_ID_CHG_CIPHER_SPEC ||
10311 content_type == SSL_ID_ALERT ||
10312 content_type == SSL_ID_HANDSHAKE)) {
10313 expert_add_info_format(pinfo, length_pi, &hf->ei.record_length_invalid,
10314 "Zero-length %s fragments are not allowed",
10315 val_to_str_const(content_type, ssl_31_content_type, "unknown"));
10316 }
10317 if (record_length > TLS_MAX_RECORD_LENGTH0x4000 + max_expansion) {
10318 expert_add_info_format(pinfo, length_pi, &hf->ei.record_length_invalid,
10319 "TLSCiphertext length MUST NOT exceed 2^14 + %u", max_expansion);
10320 }
10321 if (decrypted_tvb && tvb_captured_length(decrypted_tvb) > TLS_MAX_RECORD_LENGTH0x4000) {
10322 expert_add_info_format(pinfo, length_pi, &hf->ei.record_length_invalid,
10323 "TLSPlaintext length MUST NOT exceed 2^14");
10324 }
10325}
10326
10327static void
10328ssl_set_cipher(SslDecryptSession *ssl, uint16_t cipher)
10329{
10330 /* store selected cipher suite for decryption */
10331 ssl->session.cipher = cipher;
10332
10333 const SslCipherSuite *cs = ssl_find_cipher(cipher);
8
Calling 'ssl_find_cipher'
12
Returning from 'ssl_find_cipher'
10334 if (!cs
12.1
'cs' is null
) {
13
Taking true branch
10335 ssl->cipher_suite = NULL((void*)0);
14
Null pointer value stored to field 'cipher_suite'
10336 ssl->state &= ~SSL_CIPHER(1<<2);
10337 ssl_debug_printf("%s can't find cipher suite 0x%04X\n", G_STRFUNC((const char*) (__func__)), cipher);
10338 } else if (ssl->session.version == SSLV3_VERSION0x300 && !(cs->dig == DIG_MD50x40 || cs->dig == DIG_SHA0x41)) {
10339 /* A malicious packet capture contains a SSL 3.0 session using a TLS 1.2
10340 * cipher suite that uses for example MACAlgorithm SHA256. Reject that
10341 * to avoid a potential buffer overflow in ssl3_check_mac. */
10342 ssl->cipher_suite = NULL((void*)0);
10343 ssl->state &= ~SSL_CIPHER(1<<2);
10344 ssl_debug_printf("%s invalid SSL 3.0 cipher suite 0x%04X\n", G_STRFUNC((const char*) (__func__)), cipher);
10345 } else {
10346 /* Cipher found, save this for the delayed decoder init */
10347 ssl->cipher_suite = cs;
10348 ssl->state |= SSL_CIPHER(1<<2);
10349 ssl_debug_printf("%s found CIPHER 0x%04X %s -> state 0x%02X\n", G_STRFUNC((const char*) (__func__)), cipher,
10350 val_to_str_ext_const(cipher, &ssl_31_ciphersuite_ext, "unknown"),
10351 ssl->state);
10352 }
10353}
10354/* }}} */
10355
10356
10357/* Client Hello and Server Hello dissections. {{{ */
10358static int
10359ja4_compare_uint16(const void *a, const void *b)
10360{
10361 uint16_t va = *(const uint16_t *)a;
10362 uint16_t vb = *(const uint16_t *)b;
10363 return (va > vb) - (va < vb);
10364}
10365
10366static int
10367ssl_dissect_hnd_extension(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
10368 packet_info* pinfo, uint32_t offset, uint32_t offset_end, uint8_t hnd_type,
10369 SslSession *session, SslDecryptSession *ssl,
10370 bool_Bool is_dtls, wmem_strbuf_t *ja3, ja4_data_t *ja4_data,
10371 ssl_master_key_map_t *mk_map);
10372int
10373// NOLINTNEXTLINE(misc-no-recursion)
10374ssl_dissect_hnd_cli_hello(ssl_common_dissect_t *hf, tvbuff_t *tvb,
10375 packet_info *pinfo, proto_tree *tree, uint32_t offset,
10376 uint32_t offset_end, SslSession *session,
10377 SslDecryptSession *ssl, dtls_hfs_t *dtls_hfs, ssl_master_key_map_t *mk_map)
10378{
10379 /* struct {
10380 * ProtocolVersion client_version;
10381 * Random random;
10382 * SessionID session_id;
10383 * opaque cookie<0..32>; //new field for DTLS
10384 * CipherSuite cipher_suites<2..2^16-1>;
10385 * CompressionMethod compression_methods<1..2^8-1>;
10386 * Extension client_hello_extension_list<0..2^16-1>;
10387 * } ClientHello;
10388 */
10389 proto_item *ti;
10390 proto_tree *cs_tree;
10391 uint32_t client_version;
10392 uint32_t cipher_suite_length;
10393 uint32_t compression_methods_length;
10394 uint8_t compression_method;
10395 uint32_t next_offset;
10396 uint32_t initial_offset = offset;
10397 wmem_strbuf_t *ja3 = wmem_strbuf_new(pinfo->pool, "");
10398 char *ja3_hash;
10399 char *ja3_dash = "";
10400 char *ja4, *ja4_r, *ja4_hash, *ja4_b, *ja4_c;
10401 ja4_data_t ja4_data;
10402 wmem_strbuf_t *ja4_a = wmem_strbuf_new(pinfo->pool, "");
10403 wmem_strbuf_t *ja4_br = wmem_strbuf_new(pinfo->pool, "");
10404 wmem_strbuf_t *ja4_cr = wmem_strbuf_new(pinfo->pool, "");
10405 wmem_list_frame_t *curr_entry;
10406
10407 DISSECTOR_ASSERT_CMPINT(initial_offset, <=, offset_end)((void) ((initial_offset <= offset_end) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion " "initial_offset" " " "<=" " " "offset_end"
" (" "%" "l" "d" " " "<=" " " "%" "l" "d" ")", "epan/dissectors/packet-tls-utils.c"
, 10407, (int64_t)initial_offset, (int64_t)offset_end))))
;
10408 tvbuff_t *hello_tvb = tvb_new_subset_length(tvb, initial_offset, offset_end - initial_offset);
10409 offset = 0;
10410 offset_end = tvb_reported_length(hello_tvb);
10411
10412 ja4_data.max_version = 0;
10413 ja4_data.server_name_present = false0;
10414 ja4_data.num_cipher_suites = 0;
10415 ja4_data.num_extensions = 0;
10416 ja4_data.alpn = wmem_strbuf_new(pinfo->pool, "");
10417 ja4_data.cipher_array = wmem_array_new(pinfo->pool, sizeof(uint16_t));
10418 ja4_data.extension_array = wmem_array_new(pinfo->pool, sizeof(uint16_t));
10419 ja4_data.sighash_list = wmem_list_new(pinfo->pool);
10420
10421 /* show the client version */
10422 ti = proto_tree_add_item_ret_uint(tree, hf->hf.hs_client_version, hello_tvb,
10423 offset, 2, ENC_BIG_ENDIAN0x00000000,
10424 &client_version);
10425 if (tls_scan_client_hello(hello_tvb, offset, offset_end)) {
10426 expert_add_info(pinfo, ti, &hf->ei.legacy_version);
10427 }
10428 offset += 2;
10429 wmem_strbuf_append_printf(ja3, "%i,", client_version);
10430
10431 /*
10432 * Is it version 1.3?
10433 * If so, that's an error; TLS and DTLS 1.3 Client Hellos claim
10434 * to be TLS 1.2, and mention 1.3 in an extension. See RFC 8446
10435 * section 4.1.2 "Client Hello" and RFC 9147 Section 5.3 "Client
10436 * Hello".
10437 */
10438 if (dtls_hfs != NULL((void*)0)) {
10439 if (client_version == DTLSV1DOT3_VERSION0xfefc) {
10440 /* Don't do that. */
10441 expert_add_info(pinfo, ti, &hf->ei.client_version_error);
10442 }
10443 } else {
10444 if (client_version == TLSV1DOT3_VERSION0x304) {
10445 /* Don't do that. */
10446 expert_add_info(pinfo, ti, &hf->ei.client_version_error);
10447 }
10448 }
10449
10450 /* dissect fields that are present in both ClientHello and ServerHello */
10451 offset = ssl_dissect_hnd_hello_common(hf, hello_tvb, pinfo, tree, offset, session, ssl, false0, false0);
10452
10453 /* fields specific for DTLS (cookie_len, cookie) */
10454 if (dtls_hfs != NULL((void*)0)) {
10455 uint32_t cookie_length;
10456 /* opaque cookie<0..32> (for DTLS only) */
10457 if (!ssl_add_vector(hf, hello_tvb, pinfo, tree, offset, offset_end, &cookie_length,
10458 dtls_hfs->hf_dtls_handshake_cookie_len, 0, 32)) {
10459 return offset;
10460 }
10461 offset++;
10462 if (cookie_length > 0) {
10463 proto_tree_add_item(tree, dtls_hfs->hf_dtls_handshake_cookie,
10464 hello_tvb, offset, cookie_length, ENC_NA0x00000000);
10465 offset += cookie_length;
10466 }
10467 }
10468
10469 /* CipherSuite cipher_suites<2..2^16-1> */
10470 if (!ssl_add_vector(hf, hello_tvb, pinfo, tree, offset, offset_end, &cipher_suite_length,
10471 hf->hf.hs_cipher_suites_len, 2, UINT16_MAX(65535))) {
10472 return offset;
10473 }
10474 offset += 2;
10475 next_offset = offset + cipher_suite_length;
10476 ti = proto_tree_add_none_format(tree,
10477 hf->hf.hs_cipher_suites,
10478 hello_tvb, offset, cipher_suite_length,
10479 "Cipher Suites (%d suite%s)",
10480 cipher_suite_length / 2,
10481 plurality(cipher_suite_length/2, "", "s")((cipher_suite_length/2) == 1 ? ("") : ("s")));
10482 cs_tree = proto_item_add_subtree(ti, hf->ett.cipher_suites);
10483 while (offset + 2 <= next_offset) {
10484 uint32_t cipher_suite;
10485
10486 proto_tree_add_item_ret_uint(cs_tree, hf->hf.hs_cipher_suite, hello_tvb, offset, 2,
10487 ENC_BIG_ENDIAN0x00000000, &cipher_suite);
10488 offset += 2;
10489 if (!IS_GREASE_TLS(cipher_suite)((((cipher_suite) & 0x0f0f) == 0x0a0a) && (((cipher_suite
) & 0xff) == (((cipher_suite)>>8) & 0xff)))
) {
10490 wmem_strbuf_append_printf(ja3, "%s%i",ja3_dash, cipher_suite);
10491 ja3_dash = "-";
10492 ja4_data.num_cipher_suites += 1;
10493 uint16_t cs16 = (uint16_t)cipher_suite;
10494 wmem_array_append_one(ja4_data.cipher_array, cs16)wmem_array_append((ja4_data.cipher_array), &(cs16), 1);
10495 }
10496 }
10497 wmem_strbuf_append_c(ja3, ',');
10498 if (!ssl_end_vector(hf, hello_tvb, pinfo, cs_tree, offset, next_offset)) {
10499 offset = next_offset;
10500 }
10501
10502 /* CompressionMethod compression_methods<1..2^8-1> */
10503 if (!ssl_add_vector(hf, hello_tvb, pinfo, tree, offset, offset_end, &compression_methods_length,
10504 hf->hf.hs_comp_methods_len, 1, UINT8_MAX(255))) {
10505 return offset;
10506 }
10507 offset++;
10508 next_offset = offset + compression_methods_length;
10509 ti = proto_tree_add_none_format(tree,
10510 hf->hf.hs_comp_methods,
10511 hello_tvb, offset, compression_methods_length,
10512 "Compression Methods (%u method%s)",
10513 compression_methods_length,
10514 plurality(compression_methods_length,((compression_methods_length) == 1 ? ("") : ("s"))
10515 "", "s")((compression_methods_length) == 1 ? ("") : ("s")));
10516 cs_tree = proto_item_add_subtree(ti, hf->ett.comp_methods);
10517 while (offset < next_offset) {
10518 compression_method = tvb_get_uint8(hello_tvb, offset);
10519 /* TODO: make reserved/private comp meth. fields selectable */
10520 if (compression_method < 64)
10521 proto_tree_add_uint(cs_tree, hf->hf.hs_comp_method,
10522 hello_tvb, offset, 1, compression_method);
10523 else if (compression_method < 193)
10524 proto_tree_add_uint_format_value(cs_tree, hf->hf.hs_comp_method, hello_tvb, offset, 1,
10525 compression_method, "Reserved - to be assigned by IANA (%u)",
10526 compression_method);
10527 else
10528 proto_tree_add_uint_format_value(cs_tree, hf->hf.hs_comp_method, hello_tvb, offset, 1,
10529 compression_method, "Private use range (%u)",
10530 compression_method);
10531 offset++;
10532 }
10533
10534 /* SSL v3.0 has no extensions, so length field can indeed be missing. */
10535 if (offset < offset_end) {
10536 offset = ssl_dissect_hnd_extension(hf, hello_tvb, tree, pinfo, offset,
10537 offset_end, SSL_HND_CLIENT_HELLO,
10538 session, ssl, dtls_hfs != NULL((void*)0), ja3, &ja4_data, mk_map);
10539 if (ja4_data.max_version > 0) {
10540 client_version = ja4_data.max_version;
10541 }
10542 } else {
10543 wmem_strbuf_append_printf(ja3, ",,");
10544 }
10545
10546 if (proto_is_frame_protocol(pinfo->layers,"tcp")) {
10547 wmem_strbuf_append(ja4_a, "t");
10548 } else if (proto_is_frame_protocol(pinfo->layers,"quic")) {
10549 wmem_strbuf_append(ja4_a, "q");
10550 } else if (proto_is_frame_protocol(pinfo->layers,"dtls")) {
10551 wmem_strbuf_append(ja4_a, "d");
10552 }
10553 wmem_strbuf_append_printf(ja4_a, "%s", val_to_str_const(client_version, ssl_version_ja4_names, "00"));
10554 wmem_strbuf_append_printf(ja4_a, "%s", ja4_data.server_name_present ? "d" : "i");
10555 if (ja4_data.num_cipher_suites > 99) {
10556 wmem_strbuf_append(ja4_a, "99");
10557 } else {
10558 wmem_strbuf_append_printf(ja4_a, "%02d", ja4_data.num_cipher_suites);
10559 }
10560 if (ja4_data.num_extensions > 99) {
10561 wmem_strbuf_append(ja4_a, "99");
10562 } else {
10563 wmem_strbuf_append_printf(ja4_a, "%02d", ja4_data.num_extensions);
10564 }
10565 if (wmem_strbuf_get_len(ja4_data.alpn) > 0 ) {
10566 wmem_strbuf_append_printf(ja4_a, "%s", wmem_strbuf_get_str(ja4_data.alpn));
10567 } else {
10568 wmem_strbuf_append(ja4_a, "00");
10569 }
10570
10571 /* Sort once instead of inserting in sorted order (quadratic). */
10572 wmem_array_sort(ja4_data.cipher_array, ja4_compare_uint16);
10573 for (unsigned i = 0; i < wmem_array_get_count(ja4_data.cipher_array); i++) {
10574 wmem_strbuf_append_printf(ja4_br, "%04x", *(uint16_t *)wmem_array_index(ja4_data.cipher_array, i));
10575 if (i < wmem_array_get_count(ja4_data.cipher_array) - 1) {
10576 wmem_strbuf_append(ja4_br, ",");
10577 }
10578 }
10579
10580 wmem_array_sort(ja4_data.extension_array, ja4_compare_uint16);
10581 for (unsigned i = 0; i < wmem_array_get_count(ja4_data.extension_array); i++) {
10582 wmem_strbuf_append_printf(ja4_cr, "%04x", *(uint16_t *)wmem_array_index(ja4_data.extension_array, i));
10583 if (i < wmem_array_get_count(ja4_data.extension_array) - 1) {
10584 wmem_strbuf_append(ja4_cr, ",");
10585 }
10586 }
10587
10588 if (wmem_list_count(ja4_data.sighash_list) > 0) {
10589 wmem_strbuf_append(ja4_cr, "_");
10590 curr_entry = wmem_list_head(ja4_data.sighash_list);
10591 for (unsigned i = 0; i < wmem_list_count(ja4_data.sighash_list); i++) {
10592 wmem_strbuf_append_printf(ja4_cr, "%04x", GPOINTER_TO_UINT(wmem_list_frame_data(curr_entry))((guint) (gulong) (wmem_list_frame_data(curr_entry))));
10593 if (i < wmem_list_count(ja4_data.sighash_list) - 1) {
10594 wmem_strbuf_append(ja4_cr, ",");
10595 }
10596 curr_entry = wmem_list_frame_next(curr_entry);
10597 }
10598 }
10599 if ( wmem_strbuf_get_len(ja4_br) == 0 ) {
10600 ja4_hash = g_strdup("000000000000")g_strdup_inline ("000000000000");
10601 } else {
10602 ja4_hash = g_compute_checksum_for_string(G_CHECKSUM_SHA256, wmem_strbuf_get_str(ja4_br),-1);
10603 }
10604 ja4_b = wmem_strndup(pinfo->pool, ja4_hash, 12);
10605
10606 g_free(ja4_hash)(__builtin_object_size ((ja4_hash), 0) != ((size_t) - 1)) ? g_free_sized
(ja4_hash, __builtin_object_size ((ja4_hash), 0)) : (g_free)
(ja4_hash)
;
10607 if ( wmem_strbuf_get_len(ja4_cr) == 0 ) {
10608 ja4_hash = g_strdup("000000000000")g_strdup_inline ("000000000000");
10609 } else {
10610 ja4_hash = g_compute_checksum_for_string(G_CHECKSUM_SHA256, wmem_strbuf_get_str(ja4_cr),-1);
10611 }
10612 ja4_c = wmem_strndup(pinfo->pool, ja4_hash, 12);
10613 g_free(ja4_hash)(__builtin_object_size ((ja4_hash), 0) != ((size_t) - 1)) ? g_free_sized
(ja4_hash, __builtin_object_size ((ja4_hash), 0)) : (g_free)
(ja4_hash)
;
10614
10615 ja4 = wmem_strdup_printf(pinfo->pool, "%s_%s_%s", wmem_strbuf_get_str(ja4_a), ja4_b, ja4_c);
10616 ja4_r = wmem_strdup_printf(pinfo->pool, "%s_%s_%s", wmem_strbuf_get_str(ja4_a), wmem_strbuf_get_str(ja4_br), wmem_strbuf_get_str(ja4_cr));
10617
10618 ti = proto_tree_add_string(tree, hf->hf.hs_ja4, hello_tvb, offset, 0, ja4);
10619 proto_item_set_generated(ti);
10620 ti = proto_tree_add_string(tree, hf->hf.hs_ja4_r, hello_tvb, offset, 0, ja4_r);
10621 proto_item_set_generated(ti);
10622
10623 ja3_hash = g_compute_checksum_for_string(G_CHECKSUM_MD5, wmem_strbuf_get_str(ja3),
10624 wmem_strbuf_get_len(ja3));
10625 ti = proto_tree_add_string(tree, hf->hf.hs_ja3_full, hello_tvb, offset, 0, wmem_strbuf_get_str(ja3));
10626 proto_item_set_generated(ti);
10627 ti = proto_tree_add_string(tree, hf->hf.hs_ja3_hash, hello_tvb, offset, 0, ja3_hash);
10628 proto_item_set_generated(ti);
10629 g_free(ja3_hash)(__builtin_object_size ((ja3_hash), 0) != ((size_t) - 1)) ? g_free_sized
(ja3_hash, __builtin_object_size ((ja3_hash), 0)) : (g_free)
(ja3_hash)
;
10630 return initial_offset + offset;
10631}
10632
10633/* The hash function(s) for the handshake transcript, matching what
10634 * ssl_generate_keyring_material and tls13_load_secret_from_psk use. */
10635static bool_Bool
10636tls_transcript_hash_algos(SslDecryptSession *ssl, int *algo, int *algo2)
10637{
10638 *algo2 = 0;
10639 switch (ssl->session.version) {
30
Control jumps to the 'default' case at line 10648
10640 case TLSV1_VERSION0x301:
10641 case TLSV1DOT1_VERSION0x302:
10642 case DTLSV1DOT0_VERSION0xfeff:
10643 case DTLSV1DOT0_OPENSSL_VERSION0x100:
10644 case TLCPV1_VERSION0x101:
10645 *algo = GCRY_MD_MD5;
10646 *algo2 = GCRY_MD_SHA1;
10647 return true1;
10648 default:
10649 break;
10650 }
10651
10652 if (!(ssl->state & SSL_CIPHER(1<<2)))
31
Execution continues on line 10652
32
Taking false branch
10653 return false0;
10654
10655 switch (ssl->session.version) {
33
Control jumps to the 'default' case at line 10660
10656 case TLSV1DOT3_VERSION0x304:
10657 case DTLSV1DOT3_VERSION0xfefc:
10658 *algo = ssl_get_digest_by_name(ssl_cipher_suite_dig(ssl->cipher_suite)->name);
10659 return *algo != 0;
10660 default:
10661 *algo = ssl->cipher_suite->dig == DIG_SHA3840x43 ? GCRY_MD_SHA384 : GCRY_MD_SHA256;
34
Access to field 'dig' results in a dereference of a null pointer (loaded from field 'cipher_suite')
10662 return true1;
10663 }
10664}
10665
10666static void
10667tls_calculate_ech_handshake_hash(packet_info *pinfo, SslDecryptSession *ssl, tvbuff_t *tvb, uint32_t offset, uint32_t length, bool_Bool is_hrr)
10668{
10669 /* Note length here, unlike ssl_calculate_handshake_hash, does *not* include
10670 * the 4 bytes for the handshake type and length fields themselves. */
10671 if (!ssl
16.1
'ssl' is non-null
|| tls_transcript_is_empty(&ssl->ech_transcript) || !(ssl->state & SSL_CIPHER(1<<2)) || ssl->client_random.data_len == 0)
17
Assuming the condition is false
18
Assuming field 'data_len' is not equal to 0
19
Taking false branch
10672 return;
10673
10674 /* RFC 9849 7.2 Backend Server */
10675 int hash_algo = ssl_get_digest_by_name(ssl_cipher_suite_dig(ssl->cipher_suite)->name);
10676 if (!hash_algo)
20
Assuming 'hash_algo' is 0
21
Taking true branch
10677 return;
10678
10679 /* Check that the entire message is present and find the confirmation
10680 * before using the transcript, so that a truncated or malformed message
10681 * doesn't throw an exception here (preventing the extensions from being
10682 * dissected, or leaving the transcript partially updated.) */
10683 if (length < 34 || !tvb_bytes_exist(tvb, offset, length))
10684 return;
10685 /* The ServerHello confirmation is the last 8 bytes of the random. */
10686 uint32_t confirmation_offset = offset + 26;
10687 bool_Bool zero_confirmation = !is_hrr;
10688 if (is_hrr) {
10689 /* The HelloRetryRequest confirmation is in the extension. */
10690 uint32_t hrr_offset = offset + 34;
10691 uint32_t message_end = offset + length;
10692 uint32_t extensions_end = hrr_offset;
10693 if (message_end - hrr_offset >= 1) {
10694 /* legacy_session_id_echo, cipher_suite, legacy_compression_method */
10695 hrr_offset += tvb_get_uint8(tvb, hrr_offset) + 1 + 3;
10696 if (hrr_offset <= message_end && message_end - hrr_offset >= 2) {
10697 extensions_end = hrr_offset + 2 + tvb_get_ntohs(tvb, hrr_offset);
10698 hrr_offset += 2;
10699 if (extensions_end > message_end) {
10700 extensions_end = message_end;
10701 }
10702 }
10703 }
10704 while (hrr_offset <= extensions_end && extensions_end - hrr_offset >= 4) {
10705 uint16_t ext_type = tvb_get_ntohs(tvb, hrr_offset);
10706 uint16_t ext_len = tvb_get_ntohs(tvb, hrr_offset + 2);
10707 if (ext_type == SSL_HND_HELLO_EXT_ENCRYPTED_CLIENT_HELLO65037 && ext_len == 8 &&
10708 extensions_end - hrr_offset >= 12) {
10709 confirmation_offset = hrr_offset + 4;
10710 zero_confirmation = true1;
10711 break;
10712 }
10713 hrr_offset += 4 + ext_len;
10714 }
10715 }
10716 uint8_t *message = (uint8_t *)wmem_alloc(pinfo->pool, 4 + length);
10717 message[0] = SSL_HND_SERVER_HELLO;
10718 phtonu24(&message[1], length);
10719 tvb_memcpy(tvb, message + 4, offset, length);
10720 uint8_t *zeroed = (uint8_t *)wmem_memdup(pinfo->pool, message, 4 + length);
10721 if (zero_confirmation) {
10722 memset(zeroed + 4 + confirmation_offset - offset, 0, 8);
10723 }
10724
10725 if (is_hrr) {
10726 /* RFC 8446 4.4.1 The Transcript Hash
10727 * Special synthetic handshake following a HelloRetryRequest */
10728 if (!tls_transcript_hello_retry(&ssl->ech_transcript, hash_algo, 0))
10729 return;
10730 }
10731
10732 unsigned char transcript_hash[DIGEST_MAX_SIZE48];
10733 unsigned char prk[DIGEST_MAX_SIZE48];
10734 unsigned char *ech_verify_out = NULL((void*)0);
10735 unsigned int len;
10736 gcry_md_hd_t md = tls_transcript_copy(&ssl->ech_transcript, hash_algo, 0);
10737 if (!md)
10738 return;
10739 gcry_md_write(md, zeroed, 4 + length);
10740 len = gcry_md_get_algo_dlen(hash_algo);
10741 memcpy(transcript_hash, gcry_md_read(md, hash_algo), len);
10742 gcry_md_close(md);
10743
10744 /* The transcript continues with the actual message. */
10745 if (tls_transcript_set_hash(&ssl->ech_transcript, hash_algo, 0))
10746 tls_transcript_add(&ssl->ech_transcript, message, 4 + length);
10747
10748 hkdf_extract(hash_algo, NULL((void*)0), 0, ssl->client_random.data, 32, prk);
10749 StringInfo prk_string = {prk, len};
10750 if (tls13_hkdf_expand_label_context(hash_algo, &prk_string, tls13_hkdf_label_prefix(ssl),
10751 is_hrr ? "hrr ech accept confirmation" : "ech accept confirmation",
10752 transcript_hash, len, 8, &ech_verify_out)) {
10753 memcpy(is_hrr ? ssl->session.hrr_ech_confirmation : ssl->session.ech_confirmation, ech_verify_out, 8);
10754 if (tvb_memeql(tvb, confirmation_offset, ech_verify_out, 8) == -1) {
10755 if (is_hrr) {
10756 ssl->session.hrr_ech_declined = true1;
10757 ssl->session.first_ch_ech_frame = 0;
10758 }
10759 memcpy(ssl->client_random.data, ssl->session.client_random.data, ssl->session.client_random.data_len);
10760 ssl_print_data("Updated Client Random", ssl->client_random.data, 32);
10761 }
10762 wmem_free(NULL((void*)0), ech_verify_out);
10763 }
10764 /* XXX - If ECH is accepted, then the ECH transcript should be used
10765 * instead of the handshake_transcript for various purposes, like PSK KE.
10766 * If declined, then we don't need the ECH transcript anymore.
10767 */
10768 ssl->session.ech = true1;
10769}
10770
10771void
10772ssl_dissect_hnd_srv_hello(ssl_common_dissect_t *hf, tvbuff_t *tvb,
10773 packet_info* pinfo, proto_tree *tree, uint32_t offset, uint32_t offset_end,
10774 SslSession *session, SslDecryptSession *ssl,
10775 bool_Bool is_dtls, bool_Bool is_hrr)
10776{
10777 /* struct {
10778 * ProtocolVersion server_version;
10779 * Random random;
10780 * SessionID session_id; // TLS 1.2 and before
10781 * CipherSuite cipher_suite;
10782 * CompressionMethod compression_method; // TLS 1.2 and before
10783 * Extension server_hello_extension_list<0..2^16-1>;
10784 * } ServerHello;
10785 */
10786 uint8_t draft_version = session->tls13_draft_version;
10787 proto_item *ti;
10788 uint32_t server_version;
10789 uint32_t cipher_suite;
10790 uint32_t initial_offset = offset;
10791 wmem_strbuf_t *ja3 = wmem_strbuf_new(pinfo->pool, "");
10792 char *ja3_hash;
10793
10794 col_set_str(pinfo->cinfo, COL_PROTOCOL,
10795 val_to_str_const(session->version, ssl_version_short_names, "SSL"));
10796
10797 /* Initially assume that the session is resumed. If this is not the case, a
10798 * ServerHelloDone will be observed before the ChangeCipherSpec message
10799 * which will reset this flag. */
10800 session->is_session_resumed = true1;
10801
10802 /* show the server version */
10803 ti = proto_tree_add_item_ret_uint(tree, hf->hf.hs_server_version, tvb,
10804 offset, 2, ENC_BIG_ENDIAN0x00000000, &server_version);
10805
10806 uint16_t supported_server_version;
10807 if (tls_scan_server_hello(tvb, offset, offset_end, &supported_server_version, NULL((void*)0))) {
1
Taking false branch
10808 expert_add_info(pinfo, ti, &hf->ei.legacy_version);
10809 }
10810 /*
10811 * Is it version 1.3?
10812 * If so, that's an error; TLS and DTLS 1.3 Server Hellos claim
10813 * to be TLS 1.2, and mention 1.3 in an extension. See RFC 8446
10814 * section 4.1.3 "Server Hello" and RFC 9147 Section 5.4 "Server
10815 * Hello".
10816 */
10817 if (is_dtls) {
2
Assuming 'is_dtls' is false
3
Taking false branch
10818 if (server_version == DTLSV1DOT3_VERSION0xfefc) {
10819 /* Don't do that. */
10820 expert_add_info(pinfo, ti, &hf->ei.server_version_error);
10821 }
10822 } else {
10823 if (server_version == TLSV1DOT3_VERSION0x304) {
4
Assuming 'server_version' is not equal to TLSV1DOT3_VERSION
5
Taking false branch
10824 /* Don't do that. */
10825 expert_add_info(pinfo, ti, &hf->ei.server_version_error);
10826 }
10827 }
10828
10829 offset += 2;
10830 wmem_strbuf_append_printf(ja3, "%i", server_version);
10831
10832 /* dissect fields that are present in both ClientHello and ServerHello */
10833 offset = ssl_dissect_hnd_hello_common(hf, tvb, pinfo, tree, offset, session, ssl, true1, is_hrr);
10834
10835 if (ssl
5.1
'ssl' is non-null
) {
6
Taking true branch
10836 /* store selected cipher suite for decryption */
10837 ssl_set_cipher(ssl, tvb_get_ntohs(tvb, offset));
7
Calling 'ssl_set_cipher'
15
Returning from 'ssl_set_cipher'
10838
10839 /* XXX - If we previously had a HRR, we should check to make sure the
10840 * Cipher Suite did not change (similar with the supported_versions ext.
10841 * https://www.rfc-editor.org/rfc/rfc9846.html#name-hello-retry-request
10842 */
10843 }
10844
10845 /* now the server-selected cipher suite */
10846 proto_tree_add_item_ret_uint(tree, hf->hf.hs_cipher_suite,
10847 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &cipher_suite);
10848 offset += 2;
10849 wmem_strbuf_append_printf(ja3, ",%i,", cipher_suite);
10850
10851 /* With the Cipher Suite, we can now calculate the ECH handshake hash.
10852 * Do it now so we have it before the encrypted_client_hello extension
10853 * in a HRR. */
10854 tls_calculate_ech_handshake_hash(pinfo, ssl, tvb, initial_offset, offset_end - initial_offset, is_hrr);
16
Calling 'tls_calculate_ech_handshake_hash'
22
Returning from 'tls_calculate_ech_handshake_hash'
10855
10856 if (session->ech) {
23
Assuming field 'ech' is false
10857 tls_ech_confirm_t *ech_confirm = p_get_proto_data(pinfo->pool, pinfo, hf->hf.hs_ech_confirm, hf->hf.hs_ech_confirm);
10858 if (ech_confirm) {
10859 proto_tree *ech_confirm_tree = proto_item_add_subtree(ech_confirm->parent_item, hf->ett.hs_random);
10860 proto_tree_add_item(ech_confirm_tree, hf->hf.hs_ech_confirm, ech_confirm->confirm_tvb, 0, 8, ENC_NA0x00000000);
10861 ti = proto_tree_add_bytes_with_length(ech_confirm_tree, hf->hf.hs_ech_confirm_compute,
10862 ech_confirm->confirm_tvb, 0, 0,
10863 session->ech_confirmation, 8);
10864 proto_item_set_generated(ti);
10865 if (tvb_memeql(ech_confirm->confirm_tvb, 0, session->ech_confirmation, 8)) {
10866 expert_add_info(pinfo, ti, &hf->ei.ech_rejected);
10867 } else {
10868 expert_add_info(pinfo, ti, &hf->ei.ech_accepted);
10869 }
10870 }
10871 }
10872
10873 /* No compression with TLS 1.3 before draft -22 */
10874 if (!(session->version
23.1
Field 'version' is not equal to TLSV1DOT3_VERSION
== TLSV1DOT3_VERSION0x304 && draft_version > 0 && draft_version < 22)) {
24
Taking true branch
10875 if (ssl
24.1
'ssl' is non-null
) {
25
Taking true branch
10876 /* store selected compression method for decryption */
10877 ssl->session.compression = tvb_get_uint8(tvb, offset);
10878 }
10879 /* and the server-selected compression method */
10880 proto_tree_add_item(tree, hf->hf.hs_comp_method,
10881 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
10882 offset++;
10883 }
10884
10885 /* SSL v3.0 has no extensions, so length field can indeed be missing. */
10886 if (offset < offset_end) {
26
Assuming 'offset' is >= 'offset_end'
27
Taking false branch
10887 offset = ssl_dissect_hnd_extension(hf, tvb, tree, pinfo, offset,
10888 offset_end,
10889 is_hrr ? SSL_HND_HELLO_RETRY_REQUEST : SSL_HND_SERVER_HELLO,
10890 session, ssl, is_dtls, ja3, NULL((void*)0), NULL((void*)0));
10891 }
10892
10893 if (ssl
27.1
'ssl' is non-null
) {
28
Taking true branch
10894 /* The version and cipher suite are known now, so we know the hash
10895 * function and can keep only the digest state of the transcript. */
10896 int algo, algo2;
10897 if (!tls_transcript_hash_algos(ssl, &algo, &algo2)) {
29
Calling 'tls_transcript_hash_algos'
10898 ssl_debug_printf("%s can't determine the transcript hash\n", G_STRFUNC((const char*) (__func__)));
10899 tls_transcript_fail(&ssl->handshake_transcript);
10900 } else if (is_hrr) {
10901 /* The HelloRetryRequest itself is already in the transcript. */
10902 tls_transcript_hello_retry(&ssl->handshake_transcript, algo,
10903 (is_dtls ? 12 : 4) + offset_end - initial_offset);
10904 } else {
10905 tls_transcript_set_hash(&ssl->handshake_transcript, algo, algo2);
10906 }
10907 if (!is_hrr) {
10908 ssl->state &= ~SSL_HELLO_RETRY_REQUEST(1<<14);
10909 }
10910 }
10911
10912 ja3_hash = g_compute_checksum_for_string(G_CHECKSUM_MD5, wmem_strbuf_get_str(ja3),
10913 wmem_strbuf_get_len(ja3));
10914 ti = proto_tree_add_string(tree, hf->hf.hs_ja3s_full, tvb, offset, 0, wmem_strbuf_get_str(ja3));
10915 proto_item_set_generated(ti);
10916 ti = proto_tree_add_string(tree, hf->hf.hs_ja3s_hash, tvb, offset, 0, ja3_hash);
10917 proto_item_set_generated(ti);
10918 g_free(ja3_hash)(__builtin_object_size ((ja3_hash), 0) != ((size_t) - 1)) ? g_free_sized
(ja3_hash, __builtin_object_size ((ja3_hash), 0)) : (g_free)
(ja3_hash)
;
10919}
10920/* Client Hello and Server Hello dissections. }}} */
10921
10922/* New Session Ticket dissection. {{{ */
10923void
10924ssl_dissect_hnd_new_ses_ticket(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
10925 proto_tree *tree, uint32_t offset, uint32_t offset_end,
10926 SslSession *session, SslDecryptSession *ssl,
10927 bool_Bool is_dtls, GHashTable *session_hash)
10928{
10929 /* https://tools.ietf.org/html/rfc5077#section-3.3 (TLS >= 1.0):
10930 * struct {
10931 * uint32 ticket_lifetime_hint;
10932 * opaque ticket<0..2^16-1>;
10933 * } NewSessionTicket;
10934 *
10935 * RFC 8446 Section 4.6.1 (TLS 1.3):
10936 * struct {
10937 * uint32 ticket_lifetime;
10938 * uint32 ticket_age_add;
10939 * opaque ticket_nonce<0..255>; // new in draft -21, updated in -22
10940 * opaque ticket<1..2^16-1>;
10941 * Extension extensions<0..2^16-2>;
10942 * } NewSessionTicket;
10943 */
10944 proto_tree *subtree;
10945 proto_item *subitem;
10946 uint32_t ticket_len;
10947 bool_Bool is_tls13 = session->version == TLSV1DOT3_VERSION0x304 || session->version == DTLSV1DOT3_VERSION0xfefc;
10948 unsigned char draft_version = session->tls13_draft_version;
10949 uint32_t lifetime_hint;
10950
10951 subtree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset,
10952 hf->ett.session_ticket, NULL((void*)0),
10953 "TLS Session Ticket");
10954
10955 /* ticket lifetime hint */
10956 subitem = proto_tree_add_item_ret_uint(subtree, hf->hf.hs_session_ticket_lifetime_hint,
10957 tvb, offset, 4, ENC_BIG_ENDIAN0x00000000, &lifetime_hint);
10958 offset += 4;
10959
10960 if (lifetime_hint >= 60) {
10961 char *time_str = unsigned_time_secs_to_str(pinfo->pool, lifetime_hint);
10962 proto_item_append_text(subitem, " (%s)", time_str);
10963 }
10964
10965 if (is_tls13) {
10966
10967 /* for TLS 1.3: ticket_age_add */
10968 proto_tree_add_item(subtree, hf->hf.hs_session_ticket_age_add,
10969 tvb, offset, 4, ENC_BIG_ENDIAN0x00000000);
10970 offset += 4;
10971
10972 /* for TLS 1.3: ticket_nonce (coming with Draft 21)*/
10973 if (draft_version == 0 || draft_version >= 21) {
10974 uint32_t ticket_nonce_len;
10975
10976 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, offset_end, &ticket_nonce_len,
10977 hf->hf.hs_session_ticket_nonce_len, 0, 255)) {
10978 return;
10979 }
10980 offset++;
10981
10982 proto_tree_add_item(subtree, hf->hf.hs_session_ticket_nonce, tvb, offset, ticket_nonce_len, ENC_NA0x00000000);
10983 offset += ticket_nonce_len;
10984 }
10985
10986 }
10987
10988 /* opaque ticket<0..2^16-1> (with TLS 1.3 the minimum is 1) */
10989 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, offset_end, &ticket_len,
10990 hf->hf.hs_session_ticket_len, is_tls13 ? 1 : 0, UINT16_MAX(65535))) {
10991 return;
10992 }
10993 offset += 2;
10994
10995 /* Content depends on implementation, so just show data! */
10996 proto_tree_add_item(subtree, hf->hf.hs_session_ticket,
10997 tvb, offset, ticket_len, ENC_NA0x00000000);
10998 /* save the session ticket to cache for ssl_finalize_decryption */
10999 if (ssl && !is_tls13) {
11000 if (ssl->session.is_session_resumed) {
11001 /* NewSessionTicket is received in ServerHello before ChangeCipherSpec
11002 * (Abbreviated Handshake Using New Session Ticket).
11003 * Restore the master key for this session ticket before saving
11004 * it to the new session ticket. */
11005 ssl_restore_master_key(ssl, "Session Ticket", false0,
11006 session_hash, &ssl->session_ticket);
11007 }
11008 tvb_ensure_bytes_exist(tvb, offset, ticket_len);
11009 ssl->session_ticket.data = (unsigned char*)wmem_realloc(wmem_file_scope(),
11010 ssl->session_ticket.data, ticket_len);
11011 ssl->session_ticket.data_len = ticket_len;
11012 tvb_memcpy(tvb, ssl->session_ticket.data, offset, ticket_len);
11013 /* NewSessionTicket is received after the first (client)
11014 * ChangeCipherSpec, and before the second (server) ChangeCipherSpec.
11015 * Since the second CCS has already the session key available it will
11016 * just return. To ensure that the session ticket is mapped to a
11017 * master key (from the first CCS), save the ticket here too. */
11018 ssl_save_master_key("Session Ticket", session_hash,
11019 &ssl->session_ticket, &ssl->master_secret);
11020 ssl->state |= SSL_NEW_SESSION_TICKET(1<<10);
11021 }
11022 offset += ticket_len;
11023
11024 if (is_tls13) {
11025 ssl_dissect_hnd_extension(hf, tvb, subtree, pinfo, offset,
11026 offset_end, SSL_HND_NEWSESSION_TICKET,
11027 session, ssl, is_dtls, NULL((void*)0), NULL((void*)0), NULL((void*)0));
11028 }
11029} /* }}} */
11030
11031void
11032ssl_dissect_hnd_hello_retry_request(ssl_common_dissect_t *hf, tvbuff_t *tvb,
11033 packet_info* pinfo, proto_tree *tree, uint32_t offset, uint32_t offset_end,
11034 SslSession *session, SslDecryptSession *ssl,
11035 bool_Bool is_dtls)
11036{
11037 /* https://tools.ietf.org/html/draft-ietf-tls-tls13-19#section-4.1.4
11038 * struct {
11039 * ProtocolVersion server_version;
11040 * CipherSuite cipher_suite; // not before draft -19
11041 * Extension extensions<2..2^16-1>;
11042 * } HelloRetryRequest;
11043 * Note: no longer used since draft -22
11044 */
11045 uint32_t version;
11046 uint8_t draft_version;
11047
11048 proto_tree_add_item_ret_uint(tree, hf->hf.hs_server_version, tvb,
11049 offset, 2, ENC_BIG_ENDIAN0x00000000, &version);
11050 draft_version = extract_tls13_draft_version(version);
11051 offset += 2;
11052
11053 if (draft_version == 0 || draft_version >= 19) {
11054 proto_tree_add_item(tree, hf->hf.hs_cipher_suite,
11055 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
11056 offset += 2;
11057 }
11058
11059 /* We assume that there's nothing out there that supports only TLS 1.3
11060 * draft-22 but also Encrypted Client Hello, or else we should set the
11061 * cipher suite and call tls_calculate_ech_handshake_hash here. */
11062 if (ssl) {
11063 ssl->state |= SSL_HELLO_RETRY_REQUEST(1<<14);
11064 }
11065
11066 ssl_dissect_hnd_extension(hf, tvb, tree, pinfo, offset,
11067 offset_end, SSL_HND_HELLO_RETRY_REQUEST,
11068 session, ssl, is_dtls, NULL((void*)0), NULL((void*)0), NULL((void*)0));
11069}
11070
11071void
11072ssl_dissect_hnd_encrypted_extensions(ssl_common_dissect_t *hf, tvbuff_t *tvb,
11073 packet_info* pinfo, proto_tree *tree, uint32_t offset, uint32_t offset_end,
11074 SslSession *session, SslDecryptSession *ssl,
11075 bool_Bool is_dtls)
11076{
11077 /* RFC 8446 Section 4.3.1
11078 * struct {
11079 * Extension extensions<0..2^16-1>;
11080 * } EncryptedExtensions;
11081 */
11082 ssl_dissect_hnd_extension(hf, tvb, tree, pinfo, offset,
11083 offset_end, SSL_HND_ENCRYPTED_EXTENSIONS,
11084 session, ssl, is_dtls, NULL((void*)0), NULL((void*)0), NULL((void*)0));
11085}
11086
11087/* Certificate and Certificate Request dissections. {{{ */
11088void
11089ssl_dissect_hnd_cert(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
11090 uint32_t offset, uint32_t offset_end, packet_info *pinfo,
11091 SslSession *session, SslDecryptSession *ssl _U___attribute__((unused)),
11092 bool_Bool is_from_server, bool_Bool is_dtls)
11093{
11094 /* opaque ASN.1Cert<1..2^24-1>;
11095 *
11096 * Before RFC 8446 (TLS <= 1.2):
11097 * struct {
11098 * select(certificate_type) {
11099 *
11100 * // certificate type defined in RFC 7250
11101 * case RawPublicKey:
11102 * opaque ASN.1_subjectPublicKeyInfo<1..2^24-1>;
11103 *
11104 * // X.509 certificate defined in RFC 5246
11105 * case X.509:
11106 * ASN.1Cert certificate_list<0..2^24-1>;
11107 * };
11108 * } Certificate;
11109 *
11110 * RFC 8446 (since draft -20):
11111 * struct {
11112 * select(certificate_type){
11113 * case RawPublicKey:
11114 * // From RFC 7250 ASN.1_subjectPublicKeyInfo
11115 * opaque ASN1_subjectPublicKeyInfo<1..2^24-1>;
11116 *
11117 * case X.509:
11118 * opaque cert_data<1..2^24-1>;
11119 * }
11120 * Extension extensions<0..2^16-1>;
11121 * } CertificateEntry;
11122 * struct {
11123 * opaque certificate_request_context<0..2^8-1>;
11124 * CertificateEntry certificate_list<0..2^24-1>;
11125 * } Certificate;
11126 */
11127 enum { CERT_X509, CERT_RPK } cert_type;
11128 asn1_ctx_t asn1_ctx;
11129#if defined(HAVE_LIBGNUTLS1)
11130 gnutls_datum_t subjectPublicKeyInfo = { NULL((void*)0), 0 };
11131 unsigned certificate_index = 0;
11132#endif
11133 uint32_t next_offset, certificate_list_length, cert_length;
11134 proto_tree *subtree = tree;
11135
11136 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true1, pinfo);
11137
11138 if ((is_from_server && session->server_cert_type == SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY2) ||
11139 (!is_from_server && session->client_cert_type == SSL_HND_CERT_TYPE_RAW_PUBLIC_KEY2)) {
11140 cert_type = CERT_RPK;
11141 } else {
11142 cert_type = CERT_X509;
11143 }
11144
11145#if defined(HAVE_LIBGNUTLS1)
11146 /* Ask the pkcs1 dissector to return the public key details */
11147 if (ssl)
11148 asn1_ctx.private_data = &subjectPublicKeyInfo;
11149#endif
11150
11151 /* TLS 1.3: opaque certificate_request_context<0..2^8-1> */
11152 if (session->version == TLSV1DOT3_VERSION0x304 || session->version == DTLSV1DOT3_VERSION0xfefc) {
11153 uint32_t context_length;
11154 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &context_length,
11155 hf->hf.hs_certificate_request_context_length, 0, UINT8_MAX(255))) {
11156 return;
11157 }
11158 offset++;
11159 if (context_length > 0) {
11160 proto_tree_add_item(tree, hf->hf.hs_certificate_request_context,
11161 tvb, offset, context_length, ENC_NA0x00000000);
11162 offset += context_length;
11163 }
11164 }
11165
11166 if ((session->version != TLSV1DOT3_VERSION0x304 && session->version != DTLSV1DOT3_VERSION0xfefc) && cert_type == CERT_RPK) {
11167 /* For RPK before TLS 1.3, the single RPK is stored directly without
11168 * another "certificate_list" field. */
11169 certificate_list_length = offset_end - offset;
11170 next_offset = offset_end;
11171 } else {
11172 /* CertificateEntry certificate_list<0..2^24-1> */
11173 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &certificate_list_length,
11174 hf->hf.hs_certificates_len, 0, G_MAXUINT24((1U << 24) - 1))) {
11175 return;
11176 }
11177 offset += 3; /* 24-bit length value */
11178 next_offset = offset + certificate_list_length;
11179 }
11180
11181 /* RawPublicKey must have one cert, but X.509 can have multiple. */
11182 if (certificate_list_length > 0 && cert_type == CERT_X509) {
11183 proto_item *ti;
11184
11185 ti = proto_tree_add_none_format(tree,
11186 hf->hf.hs_certificates,
11187 tvb, offset, certificate_list_length,
11188 "Certificates (%u bytes)",
11189 certificate_list_length);
11190
11191 /* make it a subtree */
11192 subtree = proto_item_add_subtree(ti, hf->ett.certificates);
11193 }
11194
11195 while (offset < next_offset) {
11196 switch (cert_type) {
11197 case CERT_RPK:
11198 /* TODO add expert info if there is more than one RPK entry (certificate_index > 0) */
11199 /* opaque ASN.1_subjectPublicKeyInfo<1..2^24-1> */
11200 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, next_offset, &cert_length,
11201 hf->hf.hs_certificate_len, 1, G_MAXUINT24((1U << 24) - 1))) {
11202 return;
11203 }
11204 offset += 3;
11205
11206 dissect_x509af_SubjectPublicKeyInfo(false0, tvb, offset, &asn1_ctx, subtree, hf->hf.hs_certificate);
11207 offset += cert_length;
11208 break;
11209 case CERT_X509:
11210 /* opaque ASN1Cert<1..2^24-1> */
11211 if (!ssl_add_vector(hf, tvb, pinfo, subtree, offset, next_offset, &cert_length,
11212 hf->hf.hs_certificate_len, 1, G_MAXUINT24((1U << 24) - 1))) {
11213 return;
11214 }
11215 offset += 3;
11216
11217 dissect_x509af_Certificate(false0, tvb, offset, &asn1_ctx, subtree, hf->hf.hs_certificate);
11218#if defined(HAVE_LIBGNUTLS1)
11219 if (is_from_server && ssl && certificate_index == 0) {
11220 ssl_find_private_key_by_pubkey(ssl, &subjectPublicKeyInfo);
11221 /* Only attempt to get the RSA modulus for the first cert. */
11222 asn1_ctx.private_data = NULL((void*)0);
11223 }
11224#endif
11225 offset += cert_length;
11226 break;
11227 }
11228
11229 /* TLS 1.3: Extension extensions<0..2^16-1> */
11230 if ((session->version == TLSV1DOT3_VERSION0x304 || session->version == DTLSV1DOT3_VERSION0xfefc)) {
11231 offset = ssl_dissect_hnd_extension(hf, tvb, subtree, pinfo, offset,
11232 next_offset, SSL_HND_CERTIFICATE,
11233 session, ssl, is_dtls, NULL((void*)0), NULL((void*)0), NULL((void*)0));
11234 }
11235
11236#if defined(HAVE_LIBGNUTLS1)
11237 certificate_index++;
11238#endif
11239 }
11240}
11241
11242void
11243ssl_dissect_hnd_cert_req(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
11244 proto_tree *tree, uint32_t offset, uint32_t offset_end,
11245 SslSession *session, bool_Bool is_dtls)
11246{
11247 /* From SSL 3.0 and up (note that since TLS 1.1 certificate_authorities can be empty):
11248 * enum {
11249 * rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
11250 * (255)
11251 * } ClientCertificateType;
11252 *
11253 * opaque DistinguishedName<1..2^16-1>;
11254 *
11255 * struct {
11256 * ClientCertificateType certificate_types<1..2^8-1>;
11257 * DistinguishedName certificate_authorities<3..2^16-1>;
11258 * } CertificateRequest;
11259 *
11260 *
11261 * As per TLSv1.2 (RFC 5246) the format has changed to:
11262 *
11263 * enum {
11264 * rsa_sign(1), dss_sign(2), rsa_fixed_dh(3), dss_fixed_dh(4),
11265 * rsa_ephemeral_dh_RESERVED(5), dss_ephemeral_dh_RESERVED(6),
11266 * fortezza_dms_RESERVED(20), (255)
11267 * } ClientCertificateType;
11268 *
11269 * enum {
11270 * none(0), md5(1), sha1(2), sha224(3), sha256(4), sha384(5),
11271 * sha512(6), (255)
11272 * } HashAlgorithm;
11273 *
11274 * enum { anonymous(0), rsa(1), dsa(2), ecdsa(3), (255) }
11275 * SignatureAlgorithm;
11276 *
11277 * struct {
11278 * HashAlgorithm hash;
11279 * SignatureAlgorithm signature;
11280 * } SignatureAndHashAlgorithm;
11281 *
11282 * SignatureAndHashAlgorithm
11283 * supported_signature_algorithms<2..2^16-2>;
11284 *
11285 * opaque DistinguishedName<1..2^16-1>;
11286 *
11287 * struct {
11288 * ClientCertificateType certificate_types<1..2^8-1>;
11289 * SignatureAndHashAlgorithm supported_signature_algorithms<2^16-1>;
11290 * DistinguishedName certificate_authorities<0..2^16-1>;
11291 * } CertificateRequest;
11292 *
11293 * draft-ietf-tls-tls13-18:
11294 * struct {
11295 * opaque certificate_request_context<0..2^8-1>;
11296 * SignatureScheme
11297 * supported_signature_algorithms<2..2^16-2>;
11298 * DistinguishedName certificate_authorities<0..2^16-1>;
11299 * CertificateExtension certificate_extensions<0..2^16-1>;
11300 * } CertificateRequest;
11301 *
11302 * RFC 8446 (since draft-ietf-tls-tls13-19):
11303 *
11304 * struct {
11305 * opaque certificate_request_context<0..2^8-1>;
11306 * Extension extensions<2..2^16-1>;
11307 * } CertificateRequest;
11308 */
11309 proto_item *ti;
11310 proto_tree *subtree;
11311 uint32_t next_offset;
11312 asn1_ctx_t asn1_ctx;
11313 bool_Bool is_tls13 = (session->version == TLSV1DOT3_VERSION0x304 || session->version == DTLSV1DOT3_VERSION0xfefc);
11314 unsigned char draft_version = session->tls13_draft_version;
11315
11316 if (!tree)
11317 return;
11318
11319 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true1, pinfo);
11320
11321 if (is_tls13) {
11322 uint32_t context_length;
11323 /* opaque certificate_request_context<0..2^8-1> */
11324 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &context_length,
11325 hf->hf.hs_certificate_request_context_length, 0, UINT8_MAX(255))) {
11326 return;
11327 }
11328 offset++;
11329 if (context_length > 0) {
11330 proto_tree_add_item(tree, hf->hf.hs_certificate_request_context,
11331 tvb, offset, context_length, ENC_NA0x00000000);
11332 offset += context_length;
11333 }
11334 } else {
11335 uint32_t cert_types_count;
11336 /* ClientCertificateType certificate_types<1..2^8-1> */
11337 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &cert_types_count,
11338 hf->hf.hs_cert_types_count, 1, UINT8_MAX(255))) {
11339 return;
11340 }
11341 offset++;
11342 next_offset = offset + cert_types_count;
11343
11344 ti = proto_tree_add_none_format(tree,
11345 hf->hf.hs_cert_types,
11346 tvb, offset, cert_types_count,
11347 "Certificate types (%u type%s)",
11348 cert_types_count,
11349 plurality(cert_types_count, "", "s")((cert_types_count) == 1 ? ("") : ("s")));
11350 subtree = proto_item_add_subtree(ti, hf->ett.cert_types);
11351
11352 while (offset < next_offset) {
11353 proto_tree_add_item(subtree, hf->hf.hs_cert_type, tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
11354 offset++;
11355 }
11356 }
11357
11358 if (session->version == TLSV1DOT2_VERSION0x303 || session->version == DTLSV1DOT2_VERSION0xfefd ||
11359 (is_tls13 && (draft_version > 0 && draft_version < 19))) {
11360 offset = ssl_dissect_hash_alg_list(hf, tvb, tree, pinfo, offset, offset_end, NULL((void*)0));
11361 }
11362
11363 if (is_tls13 && (draft_version == 0 || draft_version >= 19)) {
11364 /*
11365 * TLS 1.3 draft 19 and newer: Extensions.
11366 * SslDecryptSession pointer is NULL because Certificate Extensions
11367 * should not influence decryption state.
11368 */
11369 ssl_dissect_hnd_extension(hf, tvb, tree, pinfo, offset,
11370 offset_end, SSL_HND_CERT_REQUEST,
11371 session, NULL((void*)0), is_dtls, NULL((void*)0), NULL((void*)0), NULL((void*)0));
11372 } else if (is_tls13 && draft_version <= 18) {
11373 /*
11374 * TLS 1.3 draft 18 and older: certificate_authorities and
11375 * certificate_extensions (a vector of OID mappings).
11376 */
11377 offset = tls_dissect_certificate_authorities(hf, tvb, pinfo, tree, offset, offset_end);
11378 ssl_dissect_hnd_hello_ext_oid_filters(hf, tvb, pinfo, tree, offset, offset_end);
11379 } else {
11380 /* for TLS 1.2 and older, the certificate_authorities field. */
11381 tls_dissect_certificate_authorities(hf, tvb, pinfo, tree, offset, offset_end);
11382 }
11383}
11384/* Certificate and Certificate Request dissections. }}} */
11385
11386void
11387ssl_dissect_hnd_cli_cert_verify(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
11388 proto_tree *tree, uint32_t offset, uint32_t offset_end, uint16_t version)
11389{
11390 ssl_dissect_digitally_signed(hf, tvb, pinfo, tree, offset, offset_end, version,
11391 hf->hf.hs_client_cert_vrfy_sig_len,
11392 hf->hf.hs_client_cert_vrfy_sig);
11393}
11394
11395/* Finished dissection. {{{ */
11396void
11397ssl_dissect_hnd_finished(ssl_common_dissect_t *hf, tvbuff_t *tvb,
11398 proto_tree *tree, uint32_t offset, uint32_t offset_end,
11399 const SslSession *session, ssl_hfs_t *ssl_hfs)
11400{
11401 /* For SSLv3:
11402 * struct {
11403 * opaque md5_hash[16];
11404 * opaque sha_hash[20];
11405 * } Finished;
11406 *
11407 * For (D)TLS:
11408 * struct {
11409 * opaque verify_data[12];
11410 * } Finished;
11411 *
11412 * For TLS 1.3:
11413 * struct {
11414 * opaque verify_data[Hash.length];
11415 * }
11416 */
11417 if (!tree)
11418 return;
11419
11420 if (session->version == SSLV3_VERSION0x300) {
11421 if (ssl_hfs != NULL((void*)0)) {
11422 proto_tree_add_item(tree, ssl_hfs->hs_md5_hash,
11423 tvb, offset, 16, ENC_NA0x00000000);
11424 proto_tree_add_item(tree, ssl_hfs->hs_sha_hash,
11425 tvb, offset + 16, 20, ENC_NA0x00000000);
11426 }
11427 } else {
11428 /* Length should be 12 for TLS before 1.3, assume this is the case. */
11429 proto_tree_add_item(tree, hf->hf.hs_finished,
11430 tvb, offset, offset_end - offset, ENC_NA0x00000000);
11431 }
11432} /* }}} */
11433
11434/* RFC 6066 Certificate URL handshake message dissection. {{{ */
11435void
11436ssl_dissect_hnd_cert_url(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree, uint32_t offset)
11437{
11438 uint32_t url_hash_len;
11439
11440 /* enum {
11441 * individual_certs(0), pkipath(1), (255)
11442 * } CertChainType;
11443 *
11444 * struct {
11445 * CertChainType type;
11446 * URLAndHash url_and_hash_list<1..2^16-1>;
11447 * } CertificateURL;
11448 *
11449 * struct {
11450 * opaque url<1..2^16-1>;
11451 * uint8 padding;
11452 * opaque SHA1Hash[20];
11453 * } URLAndHash;
11454 */
11455
11456 proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_type,
11457 tvb, offset, 1, ENC_NA0x00000000);
11458 offset++;
11459
11460 url_hash_len = tvb_get_ntohs(tvb, offset);
11461 proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_url_hash_list_len,
11462 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
11463 offset += 2;
11464 url_hash_len += offset;
11465 while (offset < url_hash_len) {
11466 proto_item *urlhash_item;
11467 proto_tree *urlhash_tree;
11468 uint16_t url_len;
11469
11470 urlhash_item = proto_tree_add_item(tree, hf->hf.hs_ext_cert_url_item,
11471 tvb, offset, -1, ENC_NA0x00000000);
11472 urlhash_tree = proto_item_add_subtree(urlhash_item, hf->ett.urlhash);
11473
11474 url_len = tvb_get_ntohs(tvb, offset);
11475 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_url_len,
11476 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
11477 offset += 2;
11478
11479 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_url,
11480 tvb, offset, url_len, ENC_ASCII0x00000000|ENC_NA0x00000000);
11481 offset += url_len;
11482
11483 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_padding,
11484 tvb, offset, 1, ENC_NA0x00000000);
11485 offset++;
11486 /* Note: RFC 6066 says that padding must be 0x01 */
11487
11488 proto_tree_add_item(urlhash_tree, hf->hf.hs_ext_cert_url_sha1,
11489 tvb, offset, 20, ENC_NA0x00000000);
11490 offset += 20;
11491 }
11492} /* }}} */
11493
11494void
11495ssl_dissect_hnd_compress_certificate(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
11496 uint32_t offset, uint32_t offset_end, packet_info *pinfo,
11497 SslSession *session, SslDecryptSession *ssl,
11498 bool_Bool is_from_server, bool_Bool is_dtls)
11499{
11500 uint32_t algorithm, uncompressed_length;
11501 uint32_t compressed_certificate_message_length;
11502 tvbuff_t *uncompressed_tvb = NULL((void*)0);
11503 proto_item *ti;
11504 /*
11505 * enum {
11506 * zlib(1),
11507 * brotli(2),
11508 * zstd(3),
11509 * (65535)
11510 * } CertificateCompressionAlgorithm;
11511 *
11512 * struct {
11513 * CertificateCompressionAlgorithm algorithm;
11514 * uint24 uncompressed_length;
11515 * opaque compressed_certificate_message<1..2^24-1>;
11516 * } CompressedCertificate;
11517 */
11518
11519 proto_tree_add_item_ret_uint(tree, hf->hf.hs_ext_compress_certificate_algorithm,
11520 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &algorithm);
11521 offset += 2;
11522
11523 proto_tree_add_item_ret_uint(tree, hf->hf.hs_ext_compress_certificate_uncompressed_length,
11524 tvb, offset, 3, ENC_BIG_ENDIAN0x00000000, &uncompressed_length);
11525 offset += 3;
11526
11527 /* opaque compressed_certificate_message<1..2^24-1>; */
11528 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &compressed_certificate_message_length,
11529 hf->hf.hs_ext_compress_certificate_compressed_certificate_message_length, 1, G_MAXUINT24((1U << 24) - 1))) {
11530 return;
11531 }
11532 offset += 3;
11533
11534 ti = proto_tree_add_item(tree, hf->hf.hs_ext_compress_certificate_compressed_certificate_message,
11535 tvb, offset, compressed_certificate_message_length, ENC_NA0x00000000);
11536
11537 /* Certificate decompression following algorithm */
11538 switch (algorithm) {
11539 case 1: /* zlib */
11540 uncompressed_tvb = tvb_child_uncompress_zlib(tvb, tvb, offset, compressed_certificate_message_length);
11541 break;
11542 case 2: /* brotli */
11543 uncompressed_tvb = tvb_child_uncompress_brotli(tvb, tvb, offset, compressed_certificate_message_length);
11544 break;
11545 case 3: /* zstd */
11546 uncompressed_tvb = tvb_child_uncompress_zstd(tvb, tvb, offset, compressed_certificate_message_length);
11547 break;
11548 }
11549
11550 if (uncompressed_tvb) {
11551 proto_tree *uncompressed_tree;
11552
11553 if (uncompressed_length != tvb_captured_length(uncompressed_tvb)) {
11554 proto_tree_add_expert_format(tree, pinfo, &hf->ei.decompression_error,
11555 tvb, offset, offset_end - offset,
11556 "Invalid uncompressed length %u (expected %u)",
11557 tvb_captured_length(uncompressed_tvb),
11558 uncompressed_length);
11559 } else {
11560 uncompressed_tree = proto_item_add_subtree(ti, hf->ett.uncompressed_certificates);
11561 ssl_dissect_hnd_cert(hf, uncompressed_tvb, uncompressed_tree,
11562 0, uncompressed_length, pinfo, session, ssl, is_from_server, is_dtls);
11563 add_new_data_source(pinfo, uncompressed_tvb, "Uncompressed certificate(s)");
11564 }
11565 }
11566}
11567
11568/* Dissection of TLS Extensions in Client Hello, Server Hello, etc. {{{ */
11569static int
11570// NOLINTNEXTLINE(misc-no-recursion)
11571ssl_dissect_hnd_extension(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree,
11572 packet_info* pinfo, uint32_t offset, uint32_t offset_end, uint8_t hnd_type,
11573 SslSession *session, SslDecryptSession *ssl,
11574 bool_Bool is_dtls, wmem_strbuf_t *ja3, ja4_data_t *ja4_data,
11575 ssl_master_key_map_t *mk_map)
11576{
11577 uint32_t exts_len;
11578 uint16_t ext_type;
11579 uint32_t ext_len;
11580 uint32_t next_offset;
11581 proto_item *ext_item;
11582 proto_tree *ext_tree;
11583 bool_Bool is_tls13 = session->version == TLSV1DOT3_VERSION0x304;
11584 wmem_strbuf_t *ja3_sg = wmem_strbuf_new(pinfo->pool, "");
11585 wmem_strbuf_t *ja3_ecpf = wmem_strbuf_new(pinfo->pool, "");
11586 char *ja3_dash = "";
11587 unsigned supported_version;
11588
11589 /* Extension extensions<0..2^16-2> (for TLS 1.3 HRR/CR min-length is 2) */
11590 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &exts_len,
11591 hf->hf.hs_exts_len, 0, UINT16_MAX(65535))) {
11592 return offset_end;
11593 }
11594 offset += 2;
11595 offset_end = offset + exts_len;
11596
11597 if (ja4_data) {
11598 ja4_data->num_extensions = 0;
11599 }
11600 while (offset_end - offset >= 4)
11601 {
11602 ext_type = tvb_get_ntohs(tvb, offset);
11603 ext_len = tvb_get_ntohs(tvb, offset + 2);
11604
11605 if (ja4_data && !IS_GREASE_TLS(ext_type)((((ext_type) & 0x0f0f) == 0x0a0a) && (((ext_type
) & 0xff) == (((ext_type)>>8) & 0xff)))
) {
11606 ja4_data->num_extensions += 1;
11607 if (ext_type != SSL_HND_HELLO_EXT_SERVER_NAME0 &&
11608 ext_type != SSL_HND_HELLO_EXT_ALPN16) {
11609 uint16_t et16 = (uint16_t)ext_type;
11610 wmem_array_append_one(ja4_data->extension_array, et16)wmem_array_append((ja4_data->extension_array), &(et16)
, 1)
;
11611 }
11612 }
11613
11614 ext_item = proto_tree_add_none_format(tree, hf->hf.hs_ext, tvb, offset, 4 + ext_len,
11615 "Extension: %s (len=%u)", val_to_str(pinfo->pool, ext_type,
11616 tls_hello_extension_types,
11617 "Unknown type %u"), ext_len);
11618 ext_tree = proto_item_add_subtree(ext_item, hf->ett.hs_ext);
11619
11620 proto_tree_add_uint(ext_tree, hf->hf.hs_ext_type,
11621 tvb, offset, 2, ext_type);
11622 offset += 2;
11623 if (ja3 && !IS_GREASE_TLS(ext_type)((((ext_type) & 0x0f0f) == 0x0a0a) && (((ext_type
) & 0xff) == (((ext_type)>>8) & 0xff)))
) {
11624 wmem_strbuf_append_printf(ja3, "%s%i",ja3_dash, ext_type);
11625 ja3_dash = "-";
11626 }
11627
11628 /* opaque extension_data<0..2^16-1> */
11629 if (!ssl_add_vector(hf, tvb, pinfo, ext_tree, offset, offset_end, &ext_len,
11630 hf->hf.hs_ext_len, 0, UINT16_MAX(65535))) {
11631 return offset_end;
11632 }
11633 offset += 2;
11634 next_offset = offset + ext_len;
11635
11636 switch (ext_type) {
11637 case SSL_HND_HELLO_EXT_SERVER_NAME0:
11638 if (hnd_type == SSL_HND_CLIENT_HELLO) {
11639 offset = ssl_dissect_hnd_hello_ext_server_name(hf, tvb, pinfo, ext_tree, offset, next_offset);
11640 if (ja4_data) {
11641 ja4_data->server_name_present = true1;
11642 }
11643 }
11644 break;
11645 case SSL_HND_HELLO_EXT_MAX_FRAGMENT_LENGTH1:
11646 proto_tree_add_item(ext_tree, hf->hf.hs_ext_max_fragment_length, tvb, offset, 1, ENC_NA0x00000000);
11647 offset += 1;
11648 break;
11649 case SSL_HND_HELLO_EXT_STATUS_REQUEST5:
11650 if (hnd_type == SSL_HND_CLIENT_HELLO) {
11651 offset = ssl_dissect_hnd_hello_ext_status_request(hf, tvb, pinfo, ext_tree, offset, next_offset, false0);
11652 } else if (is_tls13 && hnd_type == SSL_HND_CERTIFICATE) {
11653 offset = tls_dissect_hnd_certificate_status(hf, tvb, pinfo, ext_tree, offset, next_offset);
11654 }
11655 break;
11656 case SSL_HND_HELLO_EXT_CERT_TYPE9:
11657 offset = ssl_dissect_hnd_hello_ext_cert_type(hf, tvb, ext_tree,
11658 offset, next_offset,
11659 hnd_type, ext_type,
11660 session);
11661 break;
11662 case SSL_HND_HELLO_EXT_SUPPORTED_GROUPS10:
11663 if (hnd_type == SSL_HND_CLIENT_HELLO) {
11664 offset = ssl_dissect_hnd_hello_ext_supported_groups(hf, tvb, pinfo, ext_tree, offset,
11665 next_offset, ja3_sg);
11666 } else {
11667 offset = ssl_dissect_hnd_hello_ext_supported_groups(hf, tvb, pinfo, ext_tree, offset,
11668 next_offset, NULL((void*)0));
11669 }
11670 break;
11671 case SSL_HND_HELLO_EXT_EC_POINT_FORMATS11:
11672 if (hnd_type == SSL_HND_CLIENT_HELLO) {
11673 offset = ssl_dissect_hnd_hello_ext_ec_point_formats(hf, tvb, ext_tree, offset, ja3_ecpf);
11674 } else {
11675 offset = ssl_dissect_hnd_hello_ext_ec_point_formats(hf, tvb, ext_tree, offset, NULL((void*)0));
11676 }
11677 break;
11678 case SSL_HND_HELLO_EXT_SRP12:
11679 offset = ssl_dissect_hnd_hello_ext_srp(hf, tvb, pinfo, ext_tree, offset, next_offset);
11680 break;
11681 case SSL_HND_HELLO_EXT_SIGNATURE_ALGORITHMS13:
11682 offset = ssl_dissect_hnd_hello_ext_sig_hash_algs(hf, tvb, ext_tree, pinfo, offset, next_offset, ja4_data);
11683 break;
11684 case SSL_HND_HELLO_EXT_SIGNATURE_ALGORITHMS_CERT50: /* since TLS 1.3 draft -23 */
11685 offset = ssl_dissect_hnd_hello_ext_sig_hash_algs(hf, tvb, ext_tree, pinfo, offset, next_offset, NULL((void*)0));
11686 break;
11687 case SSL_HND_HELLO_EXT_DELEGATED_CREDENTIALS34:
11688 offset = ssl_dissect_hnd_ext_delegated_credentials(hf, tvb, ext_tree, pinfo, offset, next_offset, hnd_type);
11689 break;
11690 case SSL_HND_HELLO_EXT_USE_SRTP14:
11691 if (is_dtls) {
11692 if (hnd_type == SSL_HND_CLIENT_HELLO) {
11693 offset = dtls_dissect_hnd_hello_ext_use_srtp(pinfo, tvb, ext_tree, offset, next_offset, false0);
11694 } else if (hnd_type == SSL_HND_SERVER_HELLO) {
11695 offset = dtls_dissect_hnd_hello_ext_use_srtp(pinfo, tvb, ext_tree, offset, next_offset, true1);
11696 }
11697 } else {
11698 // XXX expert info: This extension MUST only be used with DTLS, and not with TLS.
11699 }
11700 break;
11701 case SSL_HND_HELLO_EXT_ECH_OUTER_EXTENSIONS64768:
11702 offset = ssl_dissect_hnd_ech_outer_ext(hf, tvb, pinfo, ext_tree, offset, next_offset);
11703 break;
11704 case SSL_HND_HELLO_EXT_ENCRYPTED_CLIENT_HELLO65037:
11705 offset = ssl_dissect_hnd_hello_ext_ech(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type, session, ssl, mk_map);
11706 break;
11707 case SSL_HND_HELLO_EXT_HEARTBEAT15:
11708 proto_tree_add_item(ext_tree, hf->hf.hs_ext_heartbeat_mode,
11709 tvb, offset, 1, ENC_BIG_ENDIAN0x00000000);
11710 offset++;
11711 break;
11712 case SSL_HND_HELLO_EXT_ALPN16:
11713 offset = ssl_dissect_hnd_hello_ext_alpn(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type, session, is_dtls, ja4_data);
11714 break;
11715 case SSL_HND_HELLO_EXT_STATUS_REQUEST_V217:
11716 if (hnd_type == SSL_HND_CLIENT_HELLO)
11717 offset = ssl_dissect_hnd_hello_ext_status_request_v2(hf, tvb, pinfo, ext_tree, offset, next_offset);
11718 break;
11719 case SSL_HND_HELLO_EXT_SIGNED_CERTIFICATE_TIMESTAMP18:
11720 // TLS 1.3 note: SCT only appears in EE in draft -16 and before.
11721 if (hnd_type == SSL_HND_SERVER_HELLO || hnd_type == SSL_HND_ENCRYPTED_EXTENSIONS || hnd_type == SSL_HND_CERTIFICATE)
11722 offset = tls_dissect_sct_list(hf, tvb, pinfo, ext_tree, offset, next_offset, session->version);
11723 break;
11724 case SSL_HND_HELLO_EXT_CLIENT_CERT_TYPE19:
11725 case SSL_HND_HELLO_EXT_SERVER_CERT_TYPE20:
11726 offset = ssl_dissect_hnd_hello_ext_cert_type(hf, tvb, ext_tree,
11727 offset, next_offset,
11728 hnd_type, ext_type,
11729 session);
11730 break;
11731 case SSL_HND_HELLO_EXT_PADDING21:
11732 proto_tree_add_item(ext_tree, hf->hf.hs_ext_padding_data, tvb, offset, ext_len, ENC_NA0x00000000);
11733 offset += ext_len;
11734 break;
11735 case SSL_HND_HELLO_EXT_ENCRYPT_THEN_MAC22:
11736 if (ssl && hnd_type == SSL_HND_SERVER_HELLO) {
11737 ssl_debug_printf("%s enabling Encrypt-then-MAC\n", G_STRFUNC((const char*) (__func__)));
11738 ssl->state |= SSL_ENCRYPT_THEN_MAC(1<<11);
11739 }
11740 break;
11741 case SSL_HND_HELLO_EXT_EXTENDED_MASTER_SECRET23:
11742 if (ssl) {
11743 switch (hnd_type) {
11744 case SSL_HND_CLIENT_HELLO:
11745 ssl->state |= SSL_CLIENT_EXTENDED_MASTER_SECRET(1<<7);
11746 break;
11747 case SSL_HND_SERVER_HELLO:
11748 ssl->state |= SSL_SERVER_EXTENDED_MASTER_SECRET(1<<8);
11749 break;
11750 default: /* no default */
11751 break;
11752 }
11753 }
11754 break;
11755 case SSL_HND_HELLO_EXT_COMPRESS_CERTIFICATE27:
11756 offset = ssl_dissect_hnd_hello_ext_compress_certificate(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type, ssl);
11757 break;
11758 case SSL_HND_HELLO_EXT_TOKEN_BINDING24:
11759 offset = ssl_dissect_hnd_hello_ext_token_binding(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type, ssl);
11760 break;
11761 case SSL_HND_HELLO_EXT_RECORD_SIZE_LIMIT28:
11762 proto_tree_add_item(ext_tree, hf->hf.hs_ext_record_size_limit,
11763 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
11764 offset += 2;
11765 break;
11766 case SSL_HND_HELLO_EXT_QUIC_TRANSPORT_PARAMETERS65445:
11767 case SSL_HND_HELLO_EXT_QUIC_TRANSPORT_PARAMETERS_V157:
11768 offset = ssl_dissect_hnd_hello_ext_quic_transport_parameters(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type, ssl);
11769 break;
11770 case SSL_HND_HELLO_EXT_SESSION_TICKET_TLS35:
11771 offset = ssl_dissect_hnd_hello_ext_session_ticket(hf, tvb, ext_tree, offset, next_offset, hnd_type, ssl);
11772 break;
11773 case SSL_HND_HELLO_EXT_KEY_SHARE_OLD40: /* used before TLS 1.3 draft -23 */
11774 case SSL_HND_HELLO_EXT_KEY_SHARE51:
11775 offset = ssl_dissect_hnd_hello_ext_key_share(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type, ssl);
11776 break;
11777 case SSL_HND_HELLO_EXT_PRE_SHARED_KEY41:
11778 offset = ssl_dissect_hnd_hello_ext_pre_shared_key(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type, ssl);
11779 break;
11780 case SSL_HND_HELLO_EXT_EARLY_DATA42:
11781 case SSL_HND_HELLO_EXT_TICKET_EARLY_DATA_INFO46:
11782 offset = ssl_dissect_hnd_hello_ext_early_data(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type, ssl);
11783 break;
11784 case SSL_HND_HELLO_EXT_SUPPORTED_VERSIONS43:
11785 switch (hnd_type) {
11786 case SSL_HND_CLIENT_HELLO:
11787 offset = ssl_dissect_hnd_hello_ext_supported_versions(hf, tvb, pinfo, ext_tree, offset, next_offset, session, is_dtls, ja4_data);
11788 break;
11789 case SSL_HND_SERVER_HELLO:
11790 case SSL_HND_HELLO_RETRY_REQUEST:
11791 proto_tree_add_item_ret_uint(ext_tree, hf->hf.hs_ext_supported_version, tvb, offset, 2, ENC_BIG_ENDIAN0x00000000, &supported_version);
11792 offset += 2;
11793 proto_item_append_text(ext_tree, " %s", val_to_str(pinfo->pool, supported_version, ssl_versions, "Unknown (0x%04x)"));
11794 break;
11795 }
11796 break;
11797 case SSL_HND_HELLO_EXT_COOKIE44:
11798 offset = ssl_dissect_hnd_hello_ext_cookie(hf, tvb, pinfo, ext_tree, offset, next_offset);
11799 break;
11800 case SSL_HND_HELLO_EXT_PSK_KEY_EXCHANGE_MODES45:
11801 offset = ssl_dissect_hnd_hello_ext_psk_key_exchange_modes(hf, tvb, pinfo, ext_tree, offset, next_offset);
11802 break;
11803 case SSL_HND_HELLO_EXT_CERTIFICATE_AUTHORITIES47:
11804 offset = ssl_dissect_hnd_hello_ext_certificate_authorities(hf, tvb, pinfo, ext_tree, offset, next_offset);
11805 break;
11806 case SSL_HND_HELLO_EXT_OID_FILTERS48:
11807 offset = ssl_dissect_hnd_hello_ext_oid_filters(hf, tvb, pinfo, ext_tree, offset, next_offset);
11808 break;
11809 case SSL_HND_HELLO_EXT_POST_HANDSHAKE_AUTH49:
11810 break;
11811 case SSL_HND_HELLO_EXT_NPN13172:
11812 offset = ssl_dissect_hnd_hello_ext_npn(hf, tvb, pinfo, ext_tree, offset, next_offset);
11813 break;
11814 case SSL_HND_HELLO_EXT_ALPS_OLD17513:
11815 offset = ssl_dissect_hnd_hello_ext_alps(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type);
11816 break;
11817 case SSL_HND_HELLO_EXT_ALPS17613:
11818 offset = ssl_dissect_hnd_hello_ext_alps(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type);
11819 break;
11820 case SSL_HND_HELLO_EXT_RENEGOTIATION_INFO65281:
11821 offset = ssl_dissect_hnd_hello_ext_reneg_info(hf, tvb, pinfo, ext_tree, offset, next_offset);
11822 break;
11823 case SSL_HND_HELLO_EXT_ENCRYPTED_SERVER_NAME65486:
11824 offset = ssl_dissect_hnd_hello_ext_esni(hf, tvb, pinfo, ext_tree, offset, next_offset, hnd_type, ssl);
11825 break;
11826 case SSL_HND_HELLO_EXT_CONNECTION_ID_DEPRECATED53:
11827 session->deprecated_cid = true1;
11828 /* FALLTHRU */
11829 case SSL_HND_HELLO_EXT_CONNECTION_ID54:
11830 offset = ssl_dissect_hnd_hello_ext_connection_id(hf, tvb, pinfo, ext_tree, offset, hnd_type, session, ssl);
11831 break;
11832 case SSL_HND_HELLO_EXT_TRUSTED_CA_KEYS3:
11833 offset = ssl_dissect_hnd_hello_ext_trusted_ca_keys(hf, tvb, pinfo, ext_tree, offset, next_offset);
11834 break;
11835 default:
11836 proto_tree_add_item(ext_tree, hf->hf.hs_ext_data,
11837 tvb, offset, ext_len, ENC_NA0x00000000);
11838 offset += ext_len;
11839 break;
11840 }
11841
11842 if (!ssl_end_vector(hf, tvb, pinfo, ext_tree, offset, next_offset)) {
11843 /* Dissection did not end at expected location, fix it. */
11844 offset = next_offset;
11845 }
11846 }
11847
11848 if (ja3) {
11849 if (hnd_type == SSL_HND_CLIENT_HELLO) {
11850 if(wmem_strbuf_get_len(ja3_sg) > 0) {
11851 wmem_strbuf_append_printf(ja3, "%s", wmem_strbuf_get_str(ja3_sg));
11852 } else {
11853 wmem_strbuf_append_c(ja3, ',');
11854 }
11855 if(wmem_strbuf_get_len(ja3_ecpf) > 0) {
11856 wmem_strbuf_append_printf(ja3, "%s", wmem_strbuf_get_str(ja3_ecpf));
11857 } else {
11858 wmem_strbuf_append_c(ja3, ',');
11859 }
11860 }
11861 }
11862
11863 /* Check if Extensions vector is correctly terminated. */
11864 if (!ssl_end_vector(hf, tvb, pinfo, tree, offset, offset_end)) {
11865 offset = offset_end;
11866 }
11867
11868 return offset;
11869} /* }}} */
11870
11871
11872/* ClientKeyExchange algo-specific dissectors. {{{ */
11873
11874static void
11875dissect_ssl3_hnd_cli_keyex_ecdh(ssl_common_dissect_t *hf, tvbuff_t *tvb,
11876 proto_tree *tree, uint32_t offset,
11877 uint32_t length)
11878{
11879 int point_len;
11880 proto_tree *ssl_ecdh_tree;
11881
11882 ssl_ecdh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
11883 hf->ett.keyex_params, NULL((void*)0), "EC Diffie-Hellman Client Params");
11884
11885 /* point */
11886 point_len = tvb_get_uint8(tvb, offset);
11887 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_client_keyex_point_len, tvb,
11888 offset, 1, ENC_BIG_ENDIAN0x00000000);
11889 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_client_keyex_point, tvb,
11890 offset + 1, point_len, ENC_NA0x00000000);
11891}
11892
11893static void
11894dissect_ssl3_hnd_cli_keyex_dhe(ssl_common_dissect_t *hf, tvbuff_t *tvb,
11895 proto_tree *tree, uint32_t offset, uint32_t length)
11896{
11897 int yc_len;
11898 proto_tree *ssl_dh_tree;
11899
11900 ssl_dh_tree = proto_tree_add_subtree(tree, tvb, offset, length,
11901 hf->ett.keyex_params, NULL((void*)0), "Diffie-Hellman Client Params");
11902
11903 /* ClientDiffieHellmanPublic.dh_public (explicit) */
11904 yc_len = tvb_get_ntohs(tvb, offset);
11905 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_client_keyex_yc_len, tvb,
11906 offset, 2, ENC_BIG_ENDIAN0x00000000);
11907 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_client_keyex_yc, tvb,
11908 offset + 2, yc_len, ENC_NA0x00000000);
11909}
11910
11911static void
11912dissect_ssl3_hnd_cli_keyex_rsa(ssl_common_dissect_t *hf, tvbuff_t *tvb,
11913 proto_tree *tree, uint32_t offset,
11914 uint32_t length, const SslSession *session)
11915{
11916 int epms_len;
11917 proto_tree *ssl_rsa_tree;
11918
11919 ssl_rsa_tree = proto_tree_add_subtree(tree, tvb, offset, length,
11920 hf->ett.keyex_params, NULL((void*)0), "RSA Encrypted PreMaster Secret");
11921
11922 /* EncryptedPreMasterSecret.pre_master_secret */
11923 switch (session->version) {
11924 case SSLV2_VERSION0x0002:
11925 case SSLV3_VERSION0x300:
11926 case DTLSV1DOT0_OPENSSL_VERSION0x100:
11927 /* OpenSSL pre-0.9.8f DTLS and pre-TLS quirk: 2-octet length vector is
11928 * not present. The handshake contents represents the EPMS, see:
11929 * https://gitlab.com/wireshark/wireshark/-/issues/10222 */
11930 epms_len = length;
11931 break;
11932
11933 default:
11934 /* TLS and DTLS include vector length before EPMS */
11935 epms_len = tvb_get_ntohs(tvb, offset);
11936 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_client_keyex_epms_len, tvb,
11937 offset, 2, ENC_BIG_ENDIAN0x00000000);
11938 offset += 2;
11939 break;
11940 }
11941 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_client_keyex_epms, tvb,
11942 offset, epms_len, ENC_NA0x00000000);
11943}
11944
11945/* Used in PSK cipher suites */
11946static uint32_t
11947dissect_ssl3_hnd_cli_keyex_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
11948 proto_tree *tree, uint32_t offset)
11949{
11950 unsigned identity_len;
11951 proto_tree *ssl_psk_tree;
11952
11953 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, -1,
11954 hf->ett.keyex_params, NULL((void*)0), "PSK Client Params");
11955 /* identity */
11956 identity_len = tvb_get_ntohs(tvb, offset);
11957 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity_len, tvb,
11958 offset, 2, ENC_BIG_ENDIAN0x00000000);
11959 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity, tvb,
11960 offset + 2, identity_len, ENC_NA0x00000000);
11961
11962 proto_item_set_len(ssl_psk_tree, 2 + identity_len);
11963 return 2 + identity_len;
11964}
11965
11966/* Used in RSA PSK cipher suites */
11967static void
11968dissect_ssl3_hnd_cli_keyex_rsa_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
11969 proto_tree *tree, uint32_t offset,
11970 uint32_t length)
11971{
11972 int identity_len, epms_len;
11973 proto_tree *ssl_psk_tree;
11974
11975 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, length,
11976 hf->ett.keyex_params, NULL((void*)0), "RSA PSK Client Params");
11977
11978 /* identity */
11979 identity_len = tvb_get_ntohs(tvb, offset);
11980 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity_len,
11981 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
11982 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_identity,
11983 tvb, offset + 2, identity_len, ENC_NA0x00000000);
11984 offset += 2 + identity_len;
11985
11986 /* Yc */
11987 epms_len = tvb_get_ntohs(tvb, offset);
11988 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_epms_len, tvb,
11989 offset, 2, ENC_BIG_ENDIAN0x00000000);
11990 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_client_keyex_epms, tvb,
11991 offset + 2, epms_len, ENC_NA0x00000000);
11992}
11993
11994/* Used in Diffie-Hellman PSK cipher suites */
11995static void
11996dissect_ssl3_hnd_cli_keyex_dhe_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
11997 proto_tree *tree, uint32_t offset, uint32_t length)
11998{
11999 /*
12000 * struct {
12001 * select (KeyExchangeAlgorithm) {
12002 * case diffie_hellman_psk:
12003 * opaque psk_identity<0..2^16-1>;
12004 * ClientDiffieHellmanPublic public;
12005 * } exchange_keys;
12006 * } ClientKeyExchange;
12007 */
12008
12009 uint32_t psk_len = dissect_ssl3_hnd_cli_keyex_psk(hf, tvb, tree, offset);
12010 dissect_ssl3_hnd_cli_keyex_dhe(hf, tvb, tree, offset + psk_len, length - psk_len);
12011}
12012
12013/* Used in EC Diffie-Hellman PSK cipher suites */
12014static void
12015dissect_ssl3_hnd_cli_keyex_ecdh_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
12016 proto_tree *tree, uint32_t offset, uint32_t length)
12017{
12018 /*
12019 * struct {
12020 * select (KeyExchangeAlgorithm) {
12021 * case ec_diffie_hellman_psk:
12022 * opaque psk_identity<0..2^16-1>;
12023 * ClientECDiffieHellmanPublic public;
12024 * } exchange_keys;
12025 * } ClientKeyExchange;
12026 */
12027
12028 uint32_t psk_len = dissect_ssl3_hnd_cli_keyex_psk(hf, tvb, tree, offset);
12029 dissect_ssl3_hnd_cli_keyex_ecdh(hf, tvb, tree, offset + psk_len, length - psk_len);
12030}
12031
12032/* Used in EC J-PAKE cipher suites */
12033static void
12034dissect_ssl3_hnd_cli_keyex_ecjpake(ssl_common_dissect_t *hf, tvbuff_t *tvb,
12035 proto_tree *tree, uint32_t offset,
12036 uint32_t length)
12037{
12038 /*
12039 * struct {
12040 * ECPoint V;
12041 * opaque r<1..2^8-1>;
12042 * } ECSchnorrZKP;
12043 *
12044 * struct {
12045 * ECPoint X;
12046 * ECSchnorrZKP zkp;
12047 * } ECJPAKEKeyKP;
12048 *
12049 * struct {
12050 * ECJPAKEKeyKP ecjpake_key_kp;
12051 * } ClientECJPAKEParams;
12052 *
12053 * select (KeyExchangeAlgorithm) {
12054 * case ecjpake:
12055 * ClientECJPAKEParams params;
12056 * } ClientKeyExchange;
12057 */
12058
12059 int point_len;
12060 proto_tree *ssl_ecjpake_tree;
12061
12062 ssl_ecjpake_tree = proto_tree_add_subtree(tree, tvb, offset, length,
12063 hf->ett.keyex_params, NULL((void*)0),
12064 "EC J-PAKE Client Params");
12065
12066 /* ECJPAKEKeyKP.X */
12067 point_len = tvb_get_uint8(tvb, offset);
12068 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_client_keyex_xc_len, tvb,
12069 offset, 1, ENC_BIG_ENDIAN0x00000000);
12070 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_client_keyex_xc, tvb,
12071 offset + 1, point_len, ENC_NA0x00000000);
12072 offset += 1 + point_len;
12073
12074 /* ECJPAKEKeyKP.zkp.V */
12075 point_len = tvb_get_uint8(tvb, offset);
12076 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_client_keyex_vc_len, tvb,
12077 offset, 1, ENC_BIG_ENDIAN0x00000000);
12078 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_client_keyex_vc, tvb,
12079 offset + 1, point_len, ENC_NA0x00000000);
12080 offset += 1 + point_len;
12081
12082 /* ECJPAKEKeyKP.zkp.r */
12083 point_len = tvb_get_uint8(tvb, offset);
12084 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_client_keyex_rc_len, tvb,
12085 offset, 1, ENC_BIG_ENDIAN0x00000000);
12086 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_client_keyex_rc, tvb,
12087 offset + 1, point_len, ENC_NA0x00000000);
12088}
12089
12090static void
12091dissect_ssl3_hnd_cli_keyex_ecc_sm2(ssl_common_dissect_t *hf, tvbuff_t *tvb,
12092 proto_tree *tree, uint32_t offset,
12093 uint32_t length)
12094{
12095 int epms_len;
12096 proto_tree *ssl_ecc_sm2_tree;
12097
12098 ssl_ecc_sm2_tree = proto_tree_add_subtree(tree, tvb, offset, length,
12099 hf->ett.keyex_params, NULL((void*)0),
12100 "ECC-SM2 Encrypted PreMaster Secret");
12101
12102 epms_len = tvb_get_ntohs(tvb, offset);
12103 proto_tree_add_item(ssl_ecc_sm2_tree, hf->hf.hs_client_keyex_epms_len, tvb,
12104 offset, 2, ENC_BIG_ENDIAN0x00000000);
12105 offset += 2;
12106 proto_tree_add_item(ssl_ecc_sm2_tree, hf->hf.hs_client_keyex_epms, tvb,
12107 offset, epms_len, ENC_NA0x00000000);
12108}
12109/* ClientKeyExchange algo-specific dissectors. }}} */
12110
12111
12112/* Dissects DigitallySigned (see RFC 5246 4.7 Cryptographic Attributes). {{{ */
12113static uint32_t
12114ssl_dissect_digitally_signed(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
12115 proto_tree *tree, uint32_t offset, uint32_t offset_end,
12116 uint16_t version, int hf_sig_len, int hf_sig)
12117{
12118 uint32_t sig_len;
12119
12120 switch (version) {
12121 case TLSV1DOT2_VERSION0x303:
12122 case DTLSV1DOT2_VERSION0xfefd:
12123 case TLSV1DOT3_VERSION0x304:
12124 case DTLSV1DOT3_VERSION0xfefc:
12125 tls_dissect_signature_algorithm(hf, tvb, tree, offset, NULL((void*)0));
12126 offset += 2;
12127 break;
12128
12129 default:
12130 break;
12131 }
12132
12133 /* Sig */
12134 if (!ssl_add_vector(hf, tvb, pinfo, tree, offset, offset_end, &sig_len,
12135 hf_sig_len, 0, UINT16_MAX(65535))) {
12136 return offset_end;
12137 }
12138 offset += 2;
12139 proto_tree_add_item(tree, hf_sig, tvb, offset, sig_len, ENC_NA0x00000000);
12140 offset += sig_len;
12141 return offset;
12142} /* }}} */
12143
12144/* ServerKeyExchange algo-specific dissectors. {{{ */
12145
12146/* dissects signed_params inside a ServerKeyExchange for some keyex algos */
12147static void
12148dissect_ssl3_hnd_srv_keyex_sig(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
12149 proto_tree *tree, uint32_t offset, uint32_t offset_end,
12150 uint16_t version)
12151{
12152 /*
12153 * TLSv1.2 (RFC 5246 sec 7.4.8)
12154 * struct {
12155 * digitally-signed struct {
12156 * opaque handshake_messages[handshake_messages_length];
12157 * }
12158 * } CertificateVerify;
12159 *
12160 * TLSv1.0/TLSv1.1 (RFC 5436 sec 7.4.8 and 7.4.3) works essentially the same
12161 * as TLSv1.2, but the hash algorithms are not explicit in digitally-signed.
12162 *
12163 * SSLv3 (RFC 6101 sec 5.6.8) essentially works the same as TLSv1.0 but it
12164 * does more hashing including the master secret and padding.
12165 */
12166 ssl_dissect_digitally_signed(hf, tvb, pinfo, tree, offset, offset_end, version,
12167 hf->hf.hs_server_keyex_sig_len,
12168 hf->hf.hs_server_keyex_sig);
12169}
12170
12171static uint32_t
12172dissect_tls_ecparameters(ssl_common_dissect_t *hf, tvbuff_t *tvb, proto_tree *tree, uint32_t offset, uint32_t offset_end)
12173{
12174 /*
12175 * RFC 4492 ECC cipher suites for TLS
12176 *
12177 * struct {
12178 * ECCurveType curve_type;
12179 * select (curve_type) {
12180 * case explicit_prime:
12181 * ...
12182 * case explicit_char2:
12183 * ...
12184 * case named_curve:
12185 * NamedCurve namedcurve;
12186 * };
12187 * } ECParameters;
12188 */
12189
12190 int curve_type;
12191
12192 /* ECParameters.curve_type */
12193 curve_type = tvb_get_uint8(tvb, offset);
12194 proto_tree_add_item(tree, hf->hf.hs_server_keyex_curve_type, tvb,
12195 offset, 1, ENC_BIG_ENDIAN0x00000000);
12196 offset++;
12197
12198 if (curve_type != 3)
12199 return offset_end; /* only named_curves are supported */
12200
12201 /* case curve_type == named_curve; ECParameters.namedcurve */
12202 proto_tree_add_item(tree, hf->hf.hs_server_keyex_named_curve, tvb,
12203 offset, 2, ENC_BIG_ENDIAN0x00000000);
12204 offset += 2;
12205
12206 return offset;
12207}
12208
12209static void
12210dissect_ssl3_hnd_srv_keyex_ecdh(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
12211 proto_tree *tree, uint32_t offset, uint32_t offset_end,
12212 uint16_t version, bool_Bool anon)
12213{
12214 /*
12215 * RFC 4492 ECC cipher suites for TLS
12216 *
12217 * struct {
12218 * opaque point <1..2^8-1>;
12219 * } ECPoint;
12220 *
12221 * struct {
12222 * ECParameters curve_params;
12223 * ECPoint public;
12224 * } ServerECDHParams;
12225 *
12226 * select (KeyExchangeAlgorithm) {
12227 * case ec_diffie_hellman:
12228 * ServerECDHParams params;
12229 * Signature signed_params;
12230 * } ServerKeyExchange;
12231 */
12232
12233 int point_len;
12234 proto_tree *ssl_ecdh_tree;
12235
12236 ssl_ecdh_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset,
12237 hf->ett.keyex_params, NULL((void*)0), "EC Diffie-Hellman Server Params");
12238
12239 offset = dissect_tls_ecparameters(hf, tvb, ssl_ecdh_tree, offset, offset_end);
12240 if (offset >= offset_end)
12241 return; /* only named_curves are supported */
12242
12243 /* ECPoint.point */
12244 point_len = tvb_get_uint8(tvb, offset);
12245 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_point_len, tvb,
12246 offset, 1, ENC_BIG_ENDIAN0x00000000);
12247 proto_tree_add_item(ssl_ecdh_tree, hf->hf.hs_server_keyex_point, tvb,
12248 offset + 1, point_len, ENC_NA0x00000000);
12249 offset += 1 + point_len;
12250
12251 /* Signature (if non-anonymous KEX) */
12252 if (!anon) {
12253 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, pinfo, ssl_ecdh_tree, offset, offset_end, version);
12254 }
12255}
12256
12257static void
12258dissect_ssl3_hnd_srv_keyex_dhe(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
12259 proto_tree *tree, uint32_t offset, uint32_t offset_end,
12260 uint16_t version, bool_Bool anon)
12261{
12262 int p_len, g_len, ys_len;
12263 proto_tree *ssl_dh_tree;
12264
12265 ssl_dh_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset,
12266 hf->ett.keyex_params, NULL((void*)0), "Diffie-Hellman Server Params");
12267
12268 /* p */
12269 p_len = tvb_get_ntohs(tvb, offset);
12270 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_p_len, tvb,
12271 offset, 2, ENC_BIG_ENDIAN0x00000000);
12272 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_p, tvb,
12273 offset + 2, p_len, ENC_NA0x00000000);
12274 offset += 2 + p_len;
12275
12276 /* g */
12277 g_len = tvb_get_ntohs(tvb, offset);
12278 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_g_len, tvb,
12279 offset, 2, ENC_BIG_ENDIAN0x00000000);
12280 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_g, tvb,
12281 offset + 2, g_len, ENC_NA0x00000000);
12282 offset += 2 + g_len;
12283
12284 /* Ys */
12285 ys_len = tvb_get_ntohs(tvb, offset);
12286 proto_tree_add_uint(ssl_dh_tree, hf->hf.hs_server_keyex_ys_len, tvb,
12287 offset, 2, ys_len);
12288 proto_tree_add_item(ssl_dh_tree, hf->hf.hs_server_keyex_ys, tvb,
12289 offset + 2, ys_len, ENC_NA0x00000000);
12290 offset += 2 + ys_len;
12291
12292 /* Signature (if non-anonymous KEX) */
12293 if (!anon) {
12294 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, pinfo, ssl_dh_tree, offset, offset_end, version);
12295 }
12296}
12297
12298/* Only used in RSA-EXPORT cipher suites */
12299static void
12300dissect_ssl3_hnd_srv_keyex_rsa(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
12301 proto_tree *tree, uint32_t offset, uint32_t offset_end,
12302 uint16_t version)
12303{
12304 int modulus_len, exponent_len;
12305 proto_tree *ssl_rsa_tree;
12306
12307 ssl_rsa_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset,
12308 hf->ett.keyex_params, NULL((void*)0), "RSA-EXPORT Server Params");
12309
12310 /* modulus */
12311 modulus_len = tvb_get_ntohs(tvb, offset);
12312 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_modulus_len, tvb,
12313 offset, 2, ENC_BIG_ENDIAN0x00000000);
12314 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_modulus, tvb,
12315 offset + 2, modulus_len, ENC_NA0x00000000);
12316 offset += 2 + modulus_len;
12317
12318 /* exponent */
12319 exponent_len = tvb_get_ntohs(tvb, offset);
12320 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_exponent_len,
12321 tvb, offset, 2, ENC_BIG_ENDIAN0x00000000);
12322 proto_tree_add_item(ssl_rsa_tree, hf->hf.hs_server_keyex_exponent,
12323 tvb, offset + 2, exponent_len, ENC_NA0x00000000);
12324 offset += 2 + exponent_len;
12325
12326 /* Signature */
12327 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, pinfo, ssl_rsa_tree, offset, offset_end, version);
12328}
12329
12330/* Used in RSA PSK and PSK cipher suites */
12331static uint32_t
12332dissect_ssl3_hnd_srv_keyex_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb,
12333 proto_tree *tree, uint32_t offset)
12334{
12335 unsigned hint_len;
12336 proto_tree *ssl_psk_tree;
12337
12338 ssl_psk_tree = proto_tree_add_subtree(tree, tvb, offset, -1,
12339 hf->ett.keyex_params, NULL((void*)0), "PSK Server Params");
12340
12341 /* hint */
12342 hint_len = tvb_get_ntohs(tvb, offset);
12343 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_server_keyex_hint_len, tvb,
12344 offset, 2, ENC_BIG_ENDIAN0x00000000);
12345 proto_tree_add_item(ssl_psk_tree, hf->hf.hs_server_keyex_hint, tvb,
12346 offset + 2, hint_len, ENC_NA0x00000000);
12347
12348 proto_item_set_len(ssl_psk_tree, 2 + hint_len);
12349 return 2 + hint_len;
12350}
12351
12352/* Used in Diffie-Hellman PSK cipher suites */
12353static void
12354dissect_ssl3_hnd_srv_keyex_dhe_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
12355 proto_tree *tree, uint32_t offset, uint32_t offset_end)
12356{
12357 /*
12358 * struct {
12359 * select (KeyExchangeAlgorithm) {
12360 * case diffie_hellman_psk:
12361 * opaque psk_identity_hint<0..2^16-1>;
12362 * ServerDHParams params;
12363 * };
12364 * } ServerKeyExchange;
12365 */
12366
12367 uint32_t psk_len = dissect_ssl3_hnd_srv_keyex_psk(hf, tvb, tree, offset);
12368 dissect_ssl3_hnd_srv_keyex_dhe(hf, tvb, pinfo, tree, offset + psk_len, offset_end, 0, true1);
12369}
12370
12371/* Used in EC Diffie-Hellman PSK cipher suites */
12372static void
12373dissect_ssl3_hnd_srv_keyex_ecdh_psk(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
12374 proto_tree *tree, uint32_t offset, uint32_t offset_end)
12375{
12376 /*
12377 * struct {
12378 * select (KeyExchangeAlgorithm) {
12379 * case ec_diffie_hellman_psk:
12380 * opaque psk_identity_hint<0..2^16-1>;
12381 * ServerECDHParams params;
12382 * };
12383 * } ServerKeyExchange;
12384 */
12385
12386 uint32_t psk_len = dissect_ssl3_hnd_srv_keyex_psk(hf, tvb, tree, offset);
12387 dissect_ssl3_hnd_srv_keyex_ecdh(hf, tvb, pinfo, tree, offset + psk_len, offset_end, 0, true1);
12388}
12389
12390/* Used in EC J-PAKE cipher suites */
12391static void
12392dissect_ssl3_hnd_srv_keyex_ecjpake(ssl_common_dissect_t *hf, tvbuff_t *tvb,
12393 proto_tree *tree, uint32_t offset, uint32_t offset_end)
12394{
12395 /*
12396 * struct {
12397 * ECPoint V;
12398 * opaque r<1..2^8-1>;
12399 * } ECSchnorrZKP;
12400 *
12401 * struct {
12402 * ECPoint X;
12403 * ECSchnorrZKP zkp;
12404 * } ECJPAKEKeyKP;
12405 *
12406 * struct {
12407 * ECParameters curve_params;
12408 * ECJPAKEKeyKP ecjpake_key_kp;
12409 * } ServerECJPAKEParams;
12410 *
12411 * select (KeyExchangeAlgorithm) {
12412 * case ecjpake:
12413 * ServerECJPAKEParams params;
12414 * } ServerKeyExchange;
12415 */
12416
12417 int point_len;
12418 proto_tree *ssl_ecjpake_tree;
12419
12420 ssl_ecjpake_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset,
12421 hf->ett.keyex_params, NULL((void*)0),
12422 "EC J-PAKE Server Params");
12423
12424 offset = dissect_tls_ecparameters(hf, tvb, ssl_ecjpake_tree, offset, offset_end);
12425 if (offset >= offset_end)
12426 return; /* only named_curves are supported */
12427
12428 /* ECJPAKEKeyKP.X */
12429 point_len = tvb_get_uint8(tvb, offset);
12430 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_server_keyex_xs_len, tvb,
12431 offset, 1, ENC_BIG_ENDIAN0x00000000);
12432 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_server_keyex_xs, tvb,
12433 offset + 1, point_len, ENC_NA0x00000000);
12434 offset += 1 + point_len;
12435
12436 /* ECJPAKEKeyKP.zkp.V */
12437 point_len = tvb_get_uint8(tvb, offset);
12438 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_server_keyex_vs_len, tvb,
12439 offset, 1, ENC_BIG_ENDIAN0x00000000);
12440 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_server_keyex_vs, tvb,
12441 offset + 1, point_len, ENC_NA0x00000000);
12442 offset += 1 + point_len;
12443
12444 /* ECJPAKEKeyKP.zkp.r */
12445 point_len = tvb_get_uint8(tvb, offset);
12446 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_server_keyex_rs_len, tvb,
12447 offset, 1, ENC_BIG_ENDIAN0x00000000);
12448 proto_tree_add_item(ssl_ecjpake_tree, hf->hf.hs_server_keyex_rs, tvb,
12449 offset + 1, point_len, ENC_NA0x00000000);
12450}
12451
12452/* Only used in ECC-SM2-EXPORT cipher suites */
12453static void
12454dissect_ssl3_hnd_srv_keyex_ecc_sm2(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
12455 proto_tree *tree, uint32_t offset, uint32_t offset_end,
12456 uint16_t version)
12457{
12458 proto_tree *ssl_ecc_sm2_tree;
12459
12460 ssl_ecc_sm2_tree = proto_tree_add_subtree(tree, tvb, offset, offset_end - offset,
12461 hf->ett.keyex_params, NULL((void*)0), "ECC-SM2-EXPORT Server Params");
12462
12463 /* Signature */
12464 dissect_ssl3_hnd_srv_keyex_sig(hf, tvb, pinfo, ssl_ecc_sm2_tree, offset, offset_end, version);
12465}
12466/* ServerKeyExchange algo-specific dissectors. }}} */
12467
12468/* Client Key Exchange and Server Key Exchange handshake dissections. {{{ */
12469void
12470ssl_dissect_hnd_cli_keyex(ssl_common_dissect_t *hf, tvbuff_t *tvb,
12471 proto_tree *tree, uint32_t offset, uint32_t length,
12472 const SslSession *session)
12473{
12474 switch (ssl_get_keyex_alg(session->cipher)) {
12475 case KEX_DH_ANON0x13: /* RFC 5246; DHE_DSS, DHE_RSA, DH_DSS, DH_RSA, DH_ANON: ClientDiffieHellmanPublic */
12476 case KEX_DH_DSS0x14:
12477 case KEX_DH_RSA0x15:
12478 case KEX_DHE_DSS0x10:
12479 case KEX_DHE_RSA0x12:
12480 dissect_ssl3_hnd_cli_keyex_dhe(hf, tvb, tree, offset, length);
12481 break;
12482 case KEX_DHE_PSK0x11: /* RFC 4279; diffie_hellman_psk: psk_identity, ClientDiffieHellmanPublic */
12483 dissect_ssl3_hnd_cli_keyex_dhe_psk(hf, tvb, tree, offset, length);
12484 break;
12485 case KEX_ECDH_ANON0x19: /* RFC 4492; ec_diffie_hellman: ClientECDiffieHellmanPublic */
12486 case KEX_ECDH_ECDSA0x1a:
12487 case KEX_ECDH_RSA0x1b:
12488 case KEX_ECDHE_ECDSA0x16:
12489 case KEX_ECDHE_RSA0x18:
12490 dissect_ssl3_hnd_cli_keyex_ecdh(hf, tvb, tree, offset, length);
12491 break;
12492 case KEX_ECDHE_PSK0x17: /* RFC 5489; ec_diffie_hellman_psk: psk_identity, ClientECDiffieHellmanPublic */
12493 dissect_ssl3_hnd_cli_keyex_ecdh_psk(hf, tvb, tree, offset, length);
12494 break;
12495 case KEX_KRB50x1c: /* RFC 2712; krb5: KerberosWrapper */
12496 /* XXX: implement support for KRB5 */
12497 proto_tree_add_expert_format(tree, NULL((void*)0), &hf->ei.hs_ciphersuite_undecoded,
12498 tvb, offset, length,
12499 "Kerberos ciphersuites (RFC 2712) are not implemented, contact Wireshark"
12500 " developers if you want them to be supported");
12501 break;
12502 case KEX_PSK0x1d: /* RFC 4279; psk: psk_identity */
12503 dissect_ssl3_hnd_cli_keyex_psk(hf, tvb, tree, offset);
12504 break;
12505 case KEX_RSA0x1e: /* RFC 5246; rsa: EncryptedPreMasterSecret */
12506 dissect_ssl3_hnd_cli_keyex_rsa(hf, tvb, tree, offset, length, session);
12507 break;
12508 case KEX_RSA_PSK0x1f: /* RFC 4279; rsa_psk: psk_identity, EncryptedPreMasterSecret */
12509 dissect_ssl3_hnd_cli_keyex_rsa_psk(hf, tvb, tree, offset, length);
12510 break;
12511 case KEX_SRP_SHA0x20: /* RFC 5054; srp: ClientSRPPublic */
12512 case KEX_SRP_SHA_DSS0x21:
12513 case KEX_SRP_SHA_RSA0x22:
12514 /* XXX: implement support for SRP_SHA* */
12515 proto_tree_add_expert_format(tree, NULL((void*)0), &hf->ei.hs_ciphersuite_undecoded,
12516 tvb, offset, length,
12517 "SRP_SHA ciphersuites (RFC 5054) are not implemented, contact Wireshark"
12518 " developers if you want them to be supported");
12519 break;
12520 case KEX_ECJPAKE0x24: /* https://tools.ietf.org/html/draft-cragie-tls-ecjpake-01 used in Thread Commissioning */
12521 dissect_ssl3_hnd_cli_keyex_ecjpake(hf, tvb, tree, offset, length);
12522 break;
12523 case KEX_ECC_SM20x26: /* GB/T 38636 */
12524 dissect_ssl3_hnd_cli_keyex_ecc_sm2(hf, tvb, tree, offset, length);
12525 break;
12526 default:
12527 if (session->cipher == 0) {
12528 proto_tree_add_expert_format(tree, NULL((void*)0), &hf->ei.hs_ciphersuite_undecoded,
12529 tvb, offset, length,
12530 "Cipher Suite not found");
12531 } else {
12532 proto_tree_add_expert_format(tree, NULL((void*)0), &hf->ei.hs_ciphersuite_undecoded,
12533 tvb, offset, length,
12534 "Cipher Suite 0x%04x is not implemented, "
12535 "contact Wireshark developers if you want this to be supported",
12536 session->cipher);
12537 }
12538 break;
12539 }
12540}
12541
12542void
12543ssl_dissect_hnd_srv_keyex(ssl_common_dissect_t *hf, tvbuff_t *tvb, packet_info *pinfo,
12544 proto_tree *tree, uint32_t offset, uint32_t offset_end,
12545 const SslSession *session)
12546{
12547 switch (ssl_get_keyex_alg(session->cipher)) {
12548 case KEX_DH_ANON0x13: /* RFC 5246; ServerDHParams */
12549 dissect_ssl3_hnd_srv_keyex_dhe(hf, tvb, pinfo, tree, offset, offset_end, session->version, true1);
12550 break;
12551 case KEX_DH_DSS0x14: /* RFC 5246; not allowed */
12552 case KEX_DH_RSA0x15:
12553 proto_tree_add_expert(tree, NULL((void*)0), &hf->ei.hs_srv_keyex_illegal,
12554 tvb, offset, offset_end - offset);
12555 break;
12556 case KEX_DHE_DSS0x10: /* RFC 5246; dhe_dss, dhe_rsa: ServerDHParams, Signature */
12557 case KEX_DHE_RSA0x12:
12558 dissect_ssl3_hnd_srv_keyex_dhe(hf, tvb, pinfo, tree, offset, offset_end, session->version, false0);
12559 break;
12560 case KEX_DHE_PSK0x11: /* RFC 4279; diffie_hellman_psk: psk_identity_hint, ServerDHParams */
12561 dissect_ssl3_hnd_srv_keyex_dhe_psk(hf, tvb, pinfo, tree, offset, offset_end);
12562 break;
12563 case KEX_ECDH_ANON0x19: /* RFC 4492; ec_diffie_hellman: ServerECDHParams (without signature for anon) */
12564 dissect_ssl3_hnd_srv_keyex_ecdh(hf, tvb, pinfo, tree, offset, offset_end, session->version, true1);
12565 break;
12566 case KEX_ECDHE_PSK0x17: /* RFC 5489; psk_identity_hint, ServerECDHParams */
12567 dissect_ssl3_hnd_srv_keyex_ecdh_psk(hf, tvb, pinfo, tree, offset, offset_end);
12568 break;
12569 case KEX_ECDH_ECDSA0x1a: /* RFC 4492; ec_diffie_hellman: ServerECDHParams, Signature */
12570 case KEX_ECDH_RSA0x1b:
12571 case KEX_ECDHE_ECDSA0x16:
12572 case KEX_ECDHE_RSA0x18:
12573 dissect_ssl3_hnd_srv_keyex_ecdh(hf, tvb, pinfo, tree, offset, offset_end, session->version, false0);
12574 break;
12575 case KEX_KRB50x1c: /* RFC 2712; not allowed */
12576 proto_tree_add_expert(tree, NULL((void*)0), &hf->ei.hs_srv_keyex_illegal,
12577 tvb, offset, offset_end - offset);
12578 break;
12579 case KEX_PSK0x1d: /* RFC 4279; psk, rsa: psk_identity */
12580 case KEX_RSA_PSK0x1f:
12581 dissect_ssl3_hnd_srv_keyex_psk(hf, tvb, tree, offset);
12582 break;
12583 case KEX_RSA0x1e: /* only allowed if the public key in the server certificate is longer than 512 bits */
12584 dissect_ssl3_hnd_srv_keyex_rsa(hf, tvb, pinfo, tree, offset, offset_end, session->version);
12585 break;
12586 case KEX_ECC_SM20x26: /* GB/T 38636 */
12587 dissect_ssl3_hnd_srv_keyex_ecc_sm2(hf, tvb, pinfo, tree, offset, offset_end, session->version);
12588 break;
12589 case KEX_SRP_SHA0x20: /* RFC 5054; srp: ServerSRPParams, Signature */
12590 case KEX_SRP_SHA_DSS0x21:
12591 case KEX_SRP_SHA_RSA0x22:
12592 /* XXX: implement support for SRP_SHA* */
12593 proto_tree_add_expert_format(tree, NULL((void*)0), &hf->ei.hs_ciphersuite_undecoded,
12594 tvb, offset, offset_end - offset,
12595 "SRP_SHA ciphersuites (RFC 5054) are not implemented, contact Wireshark"
12596 " developers if you want them to be supported");
12597 break;
12598 case KEX_ECJPAKE0x24: /* https://tools.ietf.org/html/draft-cragie-tls-ecjpake-01 used in Thread Commissioning */
12599 dissect_ssl3_hnd_srv_keyex_ecjpake(hf, tvb, tree, offset, offset_end);
12600 break;
12601 default:
12602 if (session->cipher == 0) {
12603 proto_tree_add_expert_format(tree, NULL((void*)0), &hf->ei.hs_ciphersuite_undecoded,
12604 tvb, offset, offset_end - offset,
12605 "Cipher Suite not found");
12606 } else {
12607 proto_tree_add_expert_format(tree, NULL((void*)0), &hf->ei.hs_ciphersuite_undecoded,
12608 tvb, offset, offset_end - offset,
12609 "Cipher Suite 0x%04x is not implemented, "
12610 "contact Wireshark developers if you want this to be supported",
12611 session->cipher);
12612 }
12613 break;
12614 }
12615}
12616/* Client Key Exchange and Server Key Exchange handshake dissections. }}} */
12617
12618void
12619tls13_dissect_hnd_key_update(ssl_common_dissect_t *hf, tvbuff_t *tvb,
12620 proto_tree *tree, uint32_t offset)
12621{
12622 /* RFC 8446 Section 4.6.3
12623 * enum {
12624 * update_not_requested(0), update_requested(1), (255)
12625 * } KeyUpdateRequest;
12626 *
12627 * struct {
12628 * KeyUpdateRequest request_update;
12629 * } KeyUpdate;
12630 */
12631 proto_tree_add_item(tree, hf->hf.hs_key_update_request_update, tvb, offset, 1, ENC_NA0x00000000);
12632}
12633
12634void
12635ssl_common_register_ssl_alpn_dissector_table(const char *name,
12636 const char *ui_name, const int proto)
12637{
12638 ssl_alpn_dissector_table = register_dissector_table(name, ui_name,
12639 proto, FT_STRING, STRING_CASE_SENSITIVE0);
12640 register_dissector_table_alias(ssl_alpn_dissector_table, "ssl.handshake.extensions_alpn_str");
12641}
12642
12643void
12644ssl_common_register_dtls_alpn_dissector_table(const char *name,
12645 const char *ui_name, const int proto)
12646{
12647 dtls_alpn_dissector_table = register_dissector_table(name, ui_name,
12648 proto, FT_STRING, STRING_CASE_SENSITIVE0);
12649 register_dissector_table_alias(ssl_alpn_dissector_table, "dtls.handshake.extensions_alpn_str");
12650}
12651
12652void
12653ssl_common_register_options(module_t *module, ssl_common_options_t *options, bool_Bool is_dtls)
12654{
12655 prefs_register_string_preference(module, "psk", "Pre-Shared Key",
12656 "Pre-Shared Key as HEX string. Should be 0 to 16 bytes.",
12657 &(options->psk));
12658
12659 if (is_dtls) {
12660 prefs_register_obsolete_preference(module, "keylog_file");
12661 prefs_register_static_text_preference(module, "keylog_file_removed",
12662 "The (Pre)-Master-Secret log filename preference can be configured in the TLS protocol preferences.",
12663 "Use the TLS protocol preference to configure the keylog file for both DTLS and TLS.");
12664 return;
12665 }
12666
12667 prefs_register_filename_preference(module, "keylog_file", "(Pre)-Master-Secret log filename",
12668 "The name of a file which contains a list of \n"
12669 "(pre-)master secrets in one of the following formats:\n"
12670 "\n"
12671 "RSA <EPMS> <PMS>\n"
12672 "RSA Session-ID:<SSLID> Master-Key:<MS>\n"
12673 "CLIENT_RANDOM <CRAND> <MS>\n"
12674 "PMS_CLIENT_RANDOM <CRAND> <PMS>\n"
12675 "\n"
12676 "Where:\n"
12677 "<EPMS> = First 8 bytes of the Encrypted PMS\n"
12678 "<PMS> = The Pre-Master-Secret (PMS) used to derive the MS\n"
12679 "<SSLID> = The SSL Session ID\n"
12680 "<MS> = The Master-Secret (MS)\n"
12681 "<CRAND> = The Client's random number from the ClientHello message\n"
12682 "\n"
12683 "(All fields are in hex notation)",
12684 &(options->keylog_filename), false0);
12685}
12686
12687void
12688ssl_calculate_handshake_hash(SslDecryptSession *ssl_session, tvbuff_t *tvb, uint32_t offset, uint32_t length, uint8_t msg_type, bool_Bool is_from_server)
12689{
12690 /* The handshake transcript can be used in [D]TLS 1.2 for the extended
12691 * master secret of RFC 7627, and in [D]TLS 1.3 for computing the secrets,
12692 * though the latter is only useful when pke_ke (PSK-only key exchange) is
12693 * negotiated. */
12694 if (!ssl_session)
12695 return;
12696
12697 switch (ssl_session->session.version) {
12698 /* The handshake message types used in the handshake hash are different
12699 * in different versions. [D]TLS 1.3 tracks the messages up to the
12700 * Finished, whereas 1.2 stops at the ClientKeyExchange. However, all start
12701 * at the ClientHello and include the messages up to the ServerHello, at
12702 * which point we know the version.
12703 *
12704 * XXX - However, DTLS 1.2 includes the DTLS-specific fragment info fields
12705 * in its handshake transcript, whereas DTLS 1.3 does not (using the same
12706 * format as TLS 1.3). We don't know at the point of the ClientHello which
12707 * version will be used, so PSK only likely doesn't work for DTLS 1.3 yet.
12708 *
12709 * When the server responds with a HelloRetryRequest, for subsequent
12710 * hashes (other than the first PSK Binder, see 4.2.11.2) ClientHello1 is
12711 * replaced with a synthetic handshake message of type "message_hash",
12712 * per RFC 8446 4.4.1. That is done in ssl_dissect_hnd_srv_hello, once
12713 * the cipher suite (and thus the hash function) is known; after that,
12714 * only the digest state of the transcript is kept.
12715 */
12716 case TLSV1DOT3_VERSION0x304:
12717 case DTLSV1DOT3_VERSION0xfefc:
12718 /* In [D]TLS 1.3 only the following handshake messages are used in the
12719 * handshake transcript. EndOfEarlyData and the Client Certificate,
12720 * Certificate Verify, and Finished are used in deriving the
12721 * resumption_master_secret but not the other secrets derived from
12722 * the master secret (client or server app traffic secret, exporter
12723 * secret). We don't yet support calculating a PSK to resume via
12724 * the resumption_master_secret, so we simply stop the transcript
12725 * with the server Finished. See RFC 8446 4.4.1 & 7.1 */
12726 switch (msg_type) {
12727 case SSL_HND_CLIENT_HELLO:
12728 case SSL_HND_SERVER_HELLO:
12729 case SSL_HND_HELLO_RETRY_REQUEST:
12730 case SSL_HND_ENCRYPTED_EXTENSIONS:
12731 case SSL_HND_CERT_REQUEST:
12732 break;
12733 case SSL_HND_CERTIFICATE:
12734 case SSL_HND_CERT_VERIFY:
12735 case SSL_HND_FINISHED:
12736 if (!is_from_server)
12737 return;
12738 break;
12739 case SSL_HND_END_OF_EARLY_DATA:
12740 default:
12741 return;
12742 }
12743 break;
12744 default:
12745 /* In [D]TLS 1.2, the handshake hash for the Extended Master Secret
12746 * (RFC 7627) is calculated up to and including ClientKeyExchange,
12747 * but the keys are not retrieved until ChangeCipherSpec later. If
12748 * mutual authentication is requested by the server, an intervening
12749 * CertificateVerify message can be sent but is not to be included
12750 * in the hash. */
12751 if (msg_type == SSL_HND_CERT_VERIFY)
12752 return;
12753 if (ssl_session->state & SSL_MASTER_SECRET(1<<5))
12754 return;
12755 break;
12756 }
12757
12758 /* Until the ServerHello gives the hash function, the transcript should
12759 * only have the ClientHello (in DTLS, possibly a HelloVerifyRequest,
12760 * which resets the transcript) and the ServerHello or HelloRetryRequest
12761 * itself; there's no point in buffering anything else. */
12762 if (ssl_session->handshake_transcript.md == NULL((void*)0)) {
12763 switch (msg_type) {
12764 case SSL_HND_CLIENT_HELLO:
12765 case SSL_HND_SERVER_HELLO:
12766 case SSL_HND_HELLO_RETRY_REQUEST:
12767 case SSL_HND_HELLO_VERIFY_REQUEST:
12768 break;
12769 default:
12770 if (!ssl_session->handshake_transcript.failed) {
12771 ssl_debug_printf("%s handshake message %u before the ServerHello\n", G_STRFUNC((const char*) (__func__)), msg_type);
12772 tls_transcript_fail(&ssl_session->handshake_transcript);
12773 }
12774 return;
12775 }
12776 }
12777
12778 ssl_debug_printf("Calculating hash with offset %d %d\n", offset, length);
12779 if (tvb) {
12780 if (tvb_bytes_exist(tvb, offset, length)) {
12781 tls_transcript_add(&ssl_session->handshake_transcript, tvb_get_ptr(tvb, offset, length), length);
12782 }
12783 } else {
12784 /* DTLS calculates the hash as if each handshake message had been
12785 * sent as a single fragment (RFC 6347, section 4.2.6) and passes
12786 * in a null tvbuff to add 3 bytes for a zero fragment offset.
12787 */
12788 static const uint8_t zeros[3];
12789 DISSECTOR_ASSERT_CMPINT(length, <, 4)((void) ((length < 4) ? (void)0 : (proto_report_dissector_bug
("%s:%u: failed assertion " "length" " " "<" " " "4" " (" "%"
"l" "d" " " "<" " " "%" "l" "d" ")", "epan/dissectors/packet-tls-utils.c"
, 12789, (int64_t)length, (int64_t)4))))
;
12790 tls_transcript_add(&ssl_session->handshake_transcript, zeros, length);
12791 }
12792}
12793
12794
12795/*
12796 * Editor modelines - https://www.wireshark.org/tools/modelines.html
12797 *
12798 * Local variables:
12799 * c-basic-offset: 4
12800 * tab-width: 8
12801 * indent-tabs-mode: nil
12802 * End:
12803 *
12804 * vi: set shiftwidth=4 tabstop=8 expandtab:
12805 * :indentSize=4:tabSize=8:noTabs=true:
12806 */