iPXE
tlsfmt_test.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26/** @file
27 *
28 * TLS data format tests
29 *
30 */
31
32/* Forcibly enable assertions */
33#undef NDEBUG
34
35#include <string.h>
36#include <byteswap.h>
37#include <ipxe/tls.h>
38#include <ipxe/tlsfmt.h>
39#include <ipxe/test.h>
40
41/** Known valid TLSv1.3 ServerHello (from RFC 8448) */
43 0x03, 0x03, 0xa6, 0xaf, 0x06, 0xa4, 0x12, 0x18, 0x60, 0xdc, 0x5e,
44 0x6e, 0x60, 0x24, 0x9c, 0xd3, 0x4c, 0x95, 0x93, 0x0c, 0x8a, 0xc5,
45 0xcb, 0x14, 0x34, 0xda, 0xc1, 0x55, 0x77, 0x2e, 0xd3, 0xe2, 0x69,
46 0x28, 0x00, 0x13, 0x01, 0x00, 0x00, 0x2e, 0x00, 0x33, 0x00, 0x24,
47 0x00, 0x1d, 0x00, 0x20, 0xc9, 0x82, 0x88, 0x76, 0x11, 0x20, 0x95,
48 0xfe, 0x66, 0x76, 0x2b, 0xdb, 0xf7, 0xc6, 0x72, 0xe1, 0x56, 0xd6,
49 0xcc, 0x25, 0x3b, 0x83, 0x3d, 0xf1, 0xdd, 0x69, 0xb1, 0xb0, 0x4e,
50 0x75, 0x1f, 0x0f, 0x00, 0x2b, 0x00, 0x02, 0x03, 0x04
51};
52
53/** TLSv1.3 ServerHello random bytes */
55 0xa6, 0xaf, 0x06, 0xa4, 0x12, 0x18, 0x60, 0xdc, 0x5e, 0x6e, 0x60,
56 0x24, 0x9c, 0xd3, 0x4c, 0x95, 0x93, 0x0c, 0x8a, 0xc5, 0xcb, 0x14,
57 0x34, 0xda, 0xc1, 0x55, 0x77, 0x2e, 0xd3, 0xe2, 0x69, 0x28
58};
59
60/** TLSv1.3 ServerHello public key */
62 0xc9, 0x82, 0x88, 0x76, 0x11, 0x20, 0x95, 0xfe, 0x66, 0x76, 0x2b,
63 0xdb, 0xf7, 0xc6, 0x72, 0xe1, 0x56, 0xd6, 0xcc, 0x25, 0x3b, 0x83,
64 0x3d, 0xf1, 0xdd, 0x69, 0xb1, 0xb0, 0x4e, 0x75, 0x1f, 0x0f
65};
66
67/** Known valid TLSv1.3 Certificate (from RFC 8448) */
69 0x00, 0x00, 0x01, 0xb5, 0x00, 0x01, 0xb0, 0x30, 0x82, 0x01, 0xac,
70 0x30, 0x82, 0x01, 0x15, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01,
71 0x02, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
72 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0e, 0x31, 0x0c, 0x30, 0x0a,
73 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x03, 0x72, 0x73, 0x61, 0x30,
74 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x37, 0x33, 0x30, 0x30, 0x31,
75 0x32, 0x33, 0x35, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x37,
76 0x33, 0x30, 0x30, 0x31, 0x32, 0x33, 0x35, 0x39, 0x5a, 0x30, 0x0e,
77 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x03,
78 0x72, 0x73, 0x61, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a,
79 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03,
80 0x81, 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xb4,
81 0xbb, 0x49, 0x8f, 0x82, 0x79, 0x30, 0x3d, 0x98, 0x08, 0x36, 0x39,
82 0x9b, 0x36, 0xc6, 0x98, 0x8c, 0x0c, 0x68, 0xde, 0x55, 0xe1, 0xbd,
83 0xb8, 0x26, 0xd3, 0x90, 0x1a, 0x24, 0x61, 0xea, 0xfd, 0x2d, 0xe4,
84 0x9a, 0x91, 0xd0, 0x15, 0xab, 0xbc, 0x9a, 0x95, 0x13, 0x7a, 0xce,
85 0x6c, 0x1a, 0xf1, 0x9e, 0xaa, 0x6a, 0xf9, 0x8c, 0x7c, 0xed, 0x43,
86 0x12, 0x09, 0x98, 0xe1, 0x87, 0xa8, 0x0e, 0xe0, 0xcc, 0xb0, 0x52,
87 0x4b, 0x1b, 0x01, 0x8c, 0x3e, 0x0b, 0x63, 0x26, 0x4d, 0x44, 0x9a,
88 0x6d, 0x38, 0xe2, 0x2a, 0x5f, 0xda, 0x43, 0x08, 0x46, 0x74, 0x80,
89 0x30, 0x53, 0x0e, 0xf0, 0x46, 0x1c, 0x8c, 0xa9, 0xd9, 0xef, 0xbf,
90 0xae, 0x8e, 0xa6, 0xd1, 0xd0, 0x3e, 0x2b, 0xd1, 0x93, 0xef, 0xf0,
91 0xab, 0x9a, 0x80, 0x02, 0xc4, 0x74, 0x28, 0xa6, 0xd3, 0x5a, 0x8d,
92 0x88, 0xd7, 0x9f, 0x7f, 0x1e, 0x3f, 0x02, 0x03, 0x01, 0x00, 0x01,
93 0xa3, 0x1a, 0x30, 0x18, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13,
94 0x04, 0x02, 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f,
95 0x04, 0x04, 0x03, 0x02, 0x05, 0xa0, 0x30, 0x0d, 0x06, 0x09, 0x2a,
96 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03,
97 0x81, 0x81, 0x00, 0x85, 0xaa, 0xd2, 0xa0, 0xe5, 0xb9, 0x27, 0x6b,
98 0x90, 0x8c, 0x65, 0xf7, 0x3a, 0x72, 0x67, 0x17, 0x06, 0x18, 0xa5,
99 0x4c, 0x5f, 0x8a, 0x7b, 0x33, 0x7d, 0x2d, 0xf7, 0xa5, 0x94, 0x36,
100 0x54, 0x17, 0xf2, 0xea, 0xe8, 0xf8, 0xa5, 0x8c, 0x8f, 0x81, 0x72,
101 0xf9, 0x31, 0x9c, 0xf3, 0x6b, 0x7f, 0xd6, 0xc5, 0x5b, 0x80, 0xf2,
102 0x1a, 0x03, 0x01, 0x51, 0x56, 0x72, 0x60, 0x96, 0xfd, 0x33, 0x5e,
103 0x5e, 0x67, 0xf2, 0xdb, 0xf1, 0x02, 0x70, 0x2e, 0x60, 0x8c, 0xca,
104 0xe6, 0xbe, 0xc1, 0xfc, 0x63, 0xa4, 0x2a, 0x99, 0xbe, 0x5c, 0x3e,
105 0xb7, 0x10, 0x7c, 0x3c, 0x54, 0xe9, 0xb9, 0xeb, 0x2b, 0xd5, 0x20,
106 0x3b, 0x1c, 0x3b, 0x84, 0xe0, 0xa8, 0xb2, 0xf7, 0x59, 0x40, 0x9b,
107 0xa3, 0xea, 0xc9, 0xd9, 0x1d, 0x40, 0x2d, 0xcc, 0x0c, 0xc8, 0xf8,
108 0x96, 0x12, 0x29, 0xac, 0x91, 0x87, 0xb4, 0x2b, 0x4d, 0xe1, 0x00,
109 0x00
110};
111
112/** TLSv1.2 Certificate (derived from RFC 8448) */
114 0x00, 0x01, 0xb3, 0x00, 0x01, 0xb0, 0x30, 0x82, 0x01, 0xac, 0x30,
115 0x82, 0x01, 0x15, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x02,
116 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01,
117 0x01, 0x0b, 0x05, 0x00, 0x30, 0x0e, 0x31, 0x0c, 0x30, 0x0a, 0x06,
118 0x03, 0x55, 0x04, 0x03, 0x13, 0x03, 0x72, 0x73, 0x61, 0x30, 0x1e,
119 0x17, 0x0d, 0x31, 0x36, 0x30, 0x37, 0x33, 0x30, 0x30, 0x31, 0x32,
120 0x33, 0x35, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x36, 0x30, 0x37, 0x33,
121 0x30, 0x30, 0x31, 0x32, 0x33, 0x35, 0x39, 0x5a, 0x30, 0x0e, 0x31,
122 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x03, 0x72,
123 0x73, 0x61, 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
124 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81,
125 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xb4, 0xbb,
126 0x49, 0x8f, 0x82, 0x79, 0x30, 0x3d, 0x98, 0x08, 0x36, 0x39, 0x9b,
127 0x36, 0xc6, 0x98, 0x8c, 0x0c, 0x68, 0xde, 0x55, 0xe1, 0xbd, 0xb8,
128 0x26, 0xd3, 0x90, 0x1a, 0x24, 0x61, 0xea, 0xfd, 0x2d, 0xe4, 0x9a,
129 0x91, 0xd0, 0x15, 0xab, 0xbc, 0x9a, 0x95, 0x13, 0x7a, 0xce, 0x6c,
130 0x1a, 0xf1, 0x9e, 0xaa, 0x6a, 0xf9, 0x8c, 0x7c, 0xed, 0x43, 0x12,
131 0x09, 0x98, 0xe1, 0x87, 0xa8, 0x0e, 0xe0, 0xcc, 0xb0, 0x52, 0x4b,
132 0x1b, 0x01, 0x8c, 0x3e, 0x0b, 0x63, 0x26, 0x4d, 0x44, 0x9a, 0x6d,
133 0x38, 0xe2, 0x2a, 0x5f, 0xda, 0x43, 0x08, 0x46, 0x74, 0x80, 0x30,
134 0x53, 0x0e, 0xf0, 0x46, 0x1c, 0x8c, 0xa9, 0xd9, 0xef, 0xbf, 0xae,
135 0x8e, 0xa6, 0xd1, 0xd0, 0x3e, 0x2b, 0xd1, 0x93, 0xef, 0xf0, 0xab,
136 0x9a, 0x80, 0x02, 0xc4, 0x74, 0x28, 0xa6, 0xd3, 0x5a, 0x8d, 0x88,
137 0xd7, 0x9f, 0x7f, 0x1e, 0x3f, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3,
138 0x1a, 0x30, 0x18, 0x30, 0x09, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04,
139 0x02, 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04,
140 0x04, 0x03, 0x02, 0x05, 0xa0, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
141 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x81,
142 0x81, 0x00, 0x85, 0xaa, 0xd2, 0xa0, 0xe5, 0xb9, 0x27, 0x6b, 0x90,
143 0x8c, 0x65, 0xf7, 0x3a, 0x72, 0x67, 0x17, 0x06, 0x18, 0xa5, 0x4c,
144 0x5f, 0x8a, 0x7b, 0x33, 0x7d, 0x2d, 0xf7, 0xa5, 0x94, 0x36, 0x54,
145 0x17, 0xf2, 0xea, 0xe8, 0xf8, 0xa5, 0x8c, 0x8f, 0x81, 0x72, 0xf9,
146 0x31, 0x9c, 0xf3, 0x6b, 0x7f, 0xd6, 0xc5, 0x5b, 0x80, 0xf2, 0x1a,
147 0x03, 0x01, 0x51, 0x56, 0x72, 0x60, 0x96, 0xfd, 0x33, 0x5e, 0x5e,
148 0x67, 0xf2, 0xdb, 0xf1, 0x02, 0x70, 0x2e, 0x60, 0x8c, 0xca, 0xe6,
149 0xbe, 0xc1, 0xfc, 0x63, 0xa4, 0x2a, 0x99, 0xbe, 0x5c, 0x3e, 0xb7,
150 0x10, 0x7c, 0x3c, 0x54, 0xe9, 0xb9, 0xeb, 0x2b, 0xd5, 0x20, 0x3b,
151 0x1c, 0x3b, 0x84, 0xe0, 0xa8, 0xb2, 0xf7, 0x59, 0x40, 0x9b, 0xa3,
152 0xea, 0xc9, 0xd9, 0x1d, 0x40, 0x2d, 0xcc, 0x0c, 0xc8, 0xf8, 0x96,
153 0x12, 0x29, 0xac, 0x91, 0x87, 0xb4, 0x2b, 0x4d, 0xe1
154};
155
156/** TLSv1.1 ServerHello with no extensions */
158 0x03, 0x02, 0x1d, 0xd2, 0xbc, 0xd6, 0xce, 0xb4, 0x4b, 0x7c, 0x86,
159 0xd1, 0xac, 0x69, 0xef, 0x72, 0xf0, 0x97, 0xf7, 0xba, 0x9a, 0x84,
160 0x8d, 0x7c, 0x43, 0xf0, 0x9b, 0xea, 0x2a, 0xc0, 0x2b, 0xe6, 0xc2,
161 0xca, 0x00, 0x00, 0x2f, 0x00
162};
163
164/** TLSv1.2 ServerKeyExchange with explicit signature hash algorithm */
166 0x03, 0x00, 0x1d, 0x20, 0x79, 0xc4, 0x99, 0x60, 0xa2, 0x38, 0xa5,
167 0x11, 0xe1, 0xd1, 0x88, 0x30, 0x17, 0xb0, 0xbe, 0xef, 0xd3, 0x93,
168 0x71, 0x1e, 0xc4, 0x76, 0x70, 0x5a, 0xd5, 0x24, 0x94, 0xdb, 0x6a,
169 0xfa, 0x1c, 0x74, 0x02, 0x01, 0x01, 0x00, 0x4a, 0x8e, 0x81, 0x8b,
170 0x7f, 0x7c, 0xe0, 0x0f, 0x71, 0xe6, 0xcf, 0x24, 0xce, 0x99, 0xb4,
171 0x18, 0xf1, 0xb0, 0x68, 0x8b, 0xbf, 0x18, 0xe9, 0xed, 0xf5, 0xb4,
172 0x61, 0x4a, 0x89, 0x57, 0xa2, 0x30, 0xe8, 0x67, 0xdd, 0x70, 0x85,
173 0x60, 0xc8, 0x16, 0x4e, 0x6b, 0x0e, 0x7f, 0x8d, 0xa3, 0x5b, 0xd8,
174 0xbc, 0x2b, 0xc7, 0x81, 0xf2, 0x5f, 0xda, 0xed, 0x25, 0x60, 0x7b,
175 0x01, 0x8d, 0xaf, 0xad, 0x6b, 0x7e, 0x89, 0x2e, 0x4b, 0x14, 0xa0,
176 0x17, 0xa9, 0x53, 0xd9, 0x1f, 0xd2, 0x82, 0x88, 0x9c, 0xd9, 0x2e,
177 0x6e, 0x30, 0x78, 0x07, 0xf1, 0x9f, 0x53, 0x1f, 0xc8, 0xec, 0x2d,
178 0xf2, 0xf7, 0xdc, 0x19, 0x2b, 0x36, 0xbc, 0xf6, 0xec, 0x73, 0x9a,
179 0x43, 0xf1, 0x44, 0xa2, 0x9d, 0x80, 0xd5, 0xee, 0x18, 0xf5, 0x76,
180 0xcd, 0x81, 0xfd, 0x66, 0xb0, 0xf0, 0xa5, 0x23, 0x35, 0x42, 0x4b,
181 0xc2, 0x36, 0xbc, 0x9f, 0x55, 0x33, 0x0f, 0x64, 0x97, 0xda, 0x67,
182 0x25, 0xcb, 0x2c, 0xae, 0x78, 0xab, 0xd0, 0xa2, 0xd4, 0xf8, 0xde,
183 0x88, 0x44, 0x5a, 0x6a, 0x46, 0x1d, 0x69, 0x98, 0x2f, 0x2e, 0xe7,
184 0xd2, 0xde, 0x87, 0x0b, 0x25, 0xe3, 0x2c, 0xc1, 0x8f, 0xb6, 0xec,
185 0xf1, 0xb3, 0xba, 0xdc, 0xd7, 0x17, 0xf8, 0xbc, 0x40, 0x8f, 0xa5,
186 0x76, 0x3a, 0x40, 0xe6, 0x4c, 0x6d, 0x84, 0x76, 0x88, 0xf8, 0x37,
187 0xf4, 0x53, 0x14, 0xf6, 0x9c, 0x59, 0x39, 0x5f, 0x9b, 0x02, 0xea,
188 0x22, 0xbf, 0xa3, 0xb2, 0xde, 0x06, 0xc5, 0xba, 0x01, 0xd8, 0x15,
189 0xdc, 0x02, 0x8c, 0xdb, 0xa5, 0x56, 0x85, 0xa7, 0xbd, 0x8b, 0x9a,
190 0xdf, 0x8e, 0xbd, 0x7b, 0xac, 0xe4, 0xf3, 0x5a, 0xc4, 0x52, 0xd6,
191 0xba, 0x32, 0xca, 0xdc, 0x9f, 0x71, 0x0e, 0x00, 0xc9, 0xb0, 0x9a,
192 0x6e, 0xc6, 0xe3, 0x20, 0xb2, 0x9b, 0xe5, 0x02, 0x07, 0x2e
193};
194
195/** TLSv1.1 ServerKeyExchange with implicit signature hash algorithm */
197 0x03, 0x00, 0x1d, 0x20, 0x79, 0xc4, 0x99, 0x60, 0xa2, 0x38, 0xa5,
198 0x11, 0xe1, 0xd1, 0x88, 0x30, 0x17, 0xb0, 0xbe, 0xef, 0xd3, 0x93,
199 0x71, 0x1e, 0xc4, 0x76, 0x70, 0x5a, 0xd5, 0x24, 0x94, 0xdb, 0x6a,
200 0xfa, 0x1c, 0x74, 0x01, 0x00, 0x4a, 0x8e, 0x81, 0x8b, 0x7f, 0x7c,
201 0xe0, 0x0f, 0x71, 0xe6, 0xcf, 0x24, 0xce, 0x99, 0xb4, 0x18, 0xf1,
202 0xb0, 0x68, 0x8b, 0xbf, 0x18, 0xe9, 0xed, 0xf5, 0xb4, 0x61, 0x4a,
203 0x89, 0x57, 0xa2, 0x30, 0xe8, 0x67, 0xdd, 0x70, 0x85, 0x60, 0xc8,
204 0x16, 0x4e, 0x6b, 0x0e, 0x7f, 0x8d, 0xa3, 0x5b, 0xd8, 0xbc, 0x2b,
205 0xc7, 0x81, 0xf2, 0x5f, 0xda, 0xed, 0x25, 0x60, 0x7b, 0x01, 0x8d,
206 0xaf, 0xad, 0x6b, 0x7e, 0x89, 0x2e, 0x4b, 0x14, 0xa0, 0x17, 0xa9,
207 0x53, 0xd9, 0x1f, 0xd2, 0x82, 0x88, 0x9c, 0xd9, 0x2e, 0x6e, 0x30,
208 0x78, 0x07, 0xf1, 0x9f, 0x53, 0x1f, 0xc8, 0xec, 0x2d, 0xf2, 0xf7,
209 0xdc, 0x19, 0x2b, 0x36, 0xbc, 0xf6, 0xec, 0x73, 0x9a, 0x43, 0xf1,
210 0x44, 0xa2, 0x9d, 0x80, 0xd5, 0xee, 0x18, 0xf5, 0x76, 0xcd, 0x81,
211 0xfd, 0x66, 0xb0, 0xf0, 0xa5, 0x23, 0x35, 0x42, 0x4b, 0xc2, 0x36,
212 0xbc, 0x9f, 0x55, 0x33, 0x0f, 0x64, 0x97, 0xda, 0x67, 0x25, 0xcb,
213 0x2c, 0xae, 0x78, 0xab, 0xd0, 0xa2, 0xd4, 0xf8, 0xde, 0x88, 0x44,
214 0x5a, 0x6a, 0x46, 0x1d, 0x69, 0x98, 0x2f, 0x2e, 0xe7, 0xd2, 0xde,
215 0x87, 0x0b, 0x25, 0xe3, 0x2c, 0xc1, 0x8f, 0xb6, 0xec, 0xf1, 0xb3,
216 0xba, 0xdc, 0xd7, 0x17, 0xf8, 0xbc, 0x40, 0x8f, 0xa5, 0x76, 0x3a,
217 0x40, 0xe6, 0x4c, 0x6d, 0x84, 0x76, 0x88, 0xf8, 0x37, 0xf4, 0x53,
218 0x14, 0xf6, 0x9c, 0x59, 0x39, 0x5f, 0x9b, 0x02, 0xea, 0x22, 0xbf,
219 0xa3, 0xb2, 0xde, 0x06, 0xc5, 0xba, 0x01, 0xd8, 0x15, 0xdc, 0x02,
220 0x8c, 0xdb, 0xa5, 0x56, 0x85, 0xa7, 0xbd, 0x8b, 0x9a, 0xdf, 0x8e,
221 0xbd, 0x7b, 0xac, 0xe4, 0xf3, 0x5a, 0xc4, 0x52, 0xd6, 0xba, 0x32,
222 0xca, 0xdc, 0x9f, 0x71, 0x0e, 0x00, 0xc9, 0xb0, 0x9a, 0x6e, 0xc6,
223 0xe3, 0x20, 0xb2, 0x9b, 0xe5, 0x02, 0x07, 0x2e
224};
225
226/** ServerKeyExchange public curve point */
228 0x79, 0xc4, 0x99, 0x60, 0xa2, 0x38, 0xa5, 0x11, 0xe1, 0xd1, 0x88,
229 0x30, 0x17, 0xb0, 0xbe, 0xef, 0xd3, 0x93, 0x71, 0x1e, 0xc4, 0x76,
230 0x70, 0x5a, 0xd5, 0x24, 0x94, 0xdb, 0x6a, 0xfa, 0x1c, 0x74
231};
232
233/** ServerKeyExchange signature */
235 0x4a, 0x8e, 0x81, 0x8b, 0x7f, 0x7c, 0xe0, 0x0f, 0x71, 0xe6, 0xcf,
236 0x24, 0xce, 0x99, 0xb4, 0x18, 0xf1, 0xb0, 0x68, 0x8b, 0xbf, 0x18,
237 0xe9, 0xed, 0xf5, 0xb4, 0x61, 0x4a, 0x89, 0x57, 0xa2, 0x30, 0xe8,
238 0x67, 0xdd, 0x70, 0x85, 0x60, 0xc8, 0x16, 0x4e, 0x6b, 0x0e, 0x7f,
239 0x8d, 0xa3, 0x5b, 0xd8, 0xbc, 0x2b, 0xc7, 0x81, 0xf2, 0x5f, 0xda,
240 0xed, 0x25, 0x60, 0x7b, 0x01, 0x8d, 0xaf, 0xad, 0x6b, 0x7e, 0x89,
241 0x2e, 0x4b, 0x14, 0xa0, 0x17, 0xa9, 0x53, 0xd9, 0x1f, 0xd2, 0x82,
242 0x88, 0x9c, 0xd9, 0x2e, 0x6e, 0x30, 0x78, 0x07, 0xf1, 0x9f, 0x53,
243 0x1f, 0xc8, 0xec, 0x2d, 0xf2, 0xf7, 0xdc, 0x19, 0x2b, 0x36, 0xbc,
244 0xf6, 0xec, 0x73, 0x9a, 0x43, 0xf1, 0x44, 0xa2, 0x9d, 0x80, 0xd5,
245 0xee, 0x18, 0xf5, 0x76, 0xcd, 0x81, 0xfd, 0x66, 0xb0, 0xf0, 0xa5,
246 0x23, 0x35, 0x42, 0x4b, 0xc2, 0x36, 0xbc, 0x9f, 0x55, 0x33, 0x0f,
247 0x64, 0x97, 0xda, 0x67, 0x25, 0xcb, 0x2c, 0xae, 0x78, 0xab, 0xd0,
248 0xa2, 0xd4, 0xf8, 0xde, 0x88, 0x44, 0x5a, 0x6a, 0x46, 0x1d, 0x69,
249 0x98, 0x2f, 0x2e, 0xe7, 0xd2, 0xde, 0x87, 0x0b, 0x25, 0xe3, 0x2c,
250 0xc1, 0x8f, 0xb6, 0xec, 0xf1, 0xb3, 0xba, 0xdc, 0xd7, 0x17, 0xf8,
251 0xbc, 0x40, 0x8f, 0xa5, 0x76, 0x3a, 0x40, 0xe6, 0x4c, 0x6d, 0x84,
252 0x76, 0x88, 0xf8, 0x37, 0xf4, 0x53, 0x14, 0xf6, 0x9c, 0x59, 0x39,
253 0x5f, 0x9b, 0x02, 0xea, 0x22, 0xbf, 0xa3, 0xb2, 0xde, 0x06, 0xc5,
254 0xba, 0x01, 0xd8, 0x15, 0xdc, 0x02, 0x8c, 0xdb, 0xa5, 0x56, 0x85,
255 0xa7, 0xbd, 0x8b, 0x9a, 0xdf, 0x8e, 0xbd, 0x7b, 0xac, 0xe4, 0xf3,
256 0x5a, 0xc4, 0x52, 0xd6, 0xba, 0x32, 0xca, 0xdc, 0x9f, 0x71, 0x0e,
257 0x00, 0xc9, 0xb0, 0x9a, 0x6e, 0xc6, 0xe3, 0x20, 0xb2, 0x9b, 0xe5,
258 0x02, 0x07, 0x2e
259};
260
261/** Reference TLSv1.3 ClientHello (from RFC 8448) */
263 0x03, 0x03, 0xcb, 0x34, 0xec, 0xb1, 0xe7, 0x81, 0x63, 0xba, 0x1c,
264 0x38, 0xc6, 0xda, 0xcb, 0x19, 0x6a, 0x6d, 0xff, 0xa2, 0x1a, 0x8d,
265 0x99, 0x12, 0xec, 0x18, 0xa2, 0xef, 0x62, 0x83, 0x02, 0x4d, 0xec,
266 0xe7, 0x00, 0x00, 0x06, 0x13, 0x01, 0x13, 0x03, 0x13, 0x02, 0x01,
267 0x00, 0x00, 0x91, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x09, 0x00, 0x00,
268 0x06, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0xff, 0x01, 0x00, 0x01,
269 0x00, 0x00, 0x0a, 0x00, 0x14, 0x00, 0x12, 0x00, 0x1d, 0x00, 0x17,
270 0x00, 0x18, 0x00, 0x19, 0x01, 0x00, 0x01, 0x01, 0x01, 0x02, 0x01,
271 0x03, 0x01, 0x04, 0x00, 0x23, 0x00, 0x00, 0x00, 0x33, 0x00, 0x26,
272 0x00, 0x24, 0x00, 0x1d, 0x00, 0x20, 0x99, 0x38, 0x1d, 0xe5, 0x60,
273 0xe4, 0xbd, 0x43, 0xd2, 0x3d, 0x8e, 0x43, 0x5a, 0x7d, 0xba, 0xfe,
274 0xb3, 0xc0, 0x6e, 0x51, 0xc1, 0x3c, 0xae, 0x4d, 0x54, 0x13, 0x69,
275 0x1e, 0x52, 0x9a, 0xaf, 0x2c, 0x00, 0x2b, 0x00, 0x03, 0x02, 0x03,
276 0x04, 0x00, 0x0d, 0x00, 0x20, 0x00, 0x1e, 0x04, 0x03, 0x05, 0x03,
277 0x06, 0x03, 0x02, 0x03, 0x08, 0x04, 0x08, 0x05, 0x08, 0x06, 0x04,
278 0x01, 0x05, 0x01, 0x06, 0x01, 0x02, 0x01, 0x04, 0x02, 0x05, 0x02,
279 0x06, 0x02, 0x02, 0x02, 0x00, 0x2d, 0x00, 0x02, 0x01, 0x01, 0x00,
280 0x1c, 0x00, 0x02, 0x40, 0x01
281};
282
283/** TLSv1.3 ClientHello random bytes */
285 0xcb, 0x34, 0xec, 0xb1, 0xe7, 0x81, 0x63, 0xba, 0x1c, 0x38, 0xc6,
286 0xda, 0xcb, 0x19, 0x6a, 0x6d, 0xff, 0xa2, 0x1a, 0x8d, 0x99, 0x12,
287 0xec, 0x18, 0xa2, 0xef, 0x62, 0x83, 0x02, 0x4d, 0xec, 0xe7
288};
289
290/** TLSv1.3 ClientHello cipher suites */
292 0x13, 0x01, 0x13, 0x03, 0x13, 0x02
293};
294
295/** TLSv1.3 ClientHello supported groups */
297 0x00, 0x12, 0x00, 0x1d, 0x00, 0x17, 0x00, 0x18, 0x00, 0x19, 0x01,
298 0x00, 0x01, 0x01, 0x01, 0x02, 0x01, 0x03, 0x01, 0x04
299};
300
301/** TLSv1.3 ClientHello public key */
303 0x99, 0x38, 0x1d, 0xe5, 0x60, 0xe4, 0xbd, 0x43, 0xd2, 0x3d, 0x8e,
304 0x43, 0x5a, 0x7d, 0xba, 0xfe, 0xb3, 0xc0, 0x6e, 0x51, 0xc1, 0x3c,
305 0xae, 0x4d, 0x54, 0x13, 0x69, 0x1e, 0x52, 0x9a, 0xaf, 0x2c
306};
307
308/** TLSv1.3 ClientHello signature algorithms */
310 0x00, 0x1e, 0x04, 0x03, 0x05, 0x03, 0x06, 0x03, 0x02, 0x03, 0x08,
311 0x04, 0x08, 0x05, 0x08, 0x06, 0x04, 0x01, 0x05, 0x01, 0x06, 0x01,
312 0x02, 0x01, 0x04, 0x02, 0x05, 0x02, 0x06, 0x02, 0x02, 0x02
313};
314
315/** TLSv1.3 ClientHello supported version */
316static uint8_t tls13_client_hello_supvers[] = { 0x03, 0x04 };
317
318/** TLSv1.3 ClientHello pre-shared key modes */
320
321/** Space for test data */
333
334/**
335 * Report a mapping validity test result
336 *
337 * @v type Descriptor structure name
338 * @v version Protocol version
339 */
340#define map_version_ok( type, version ) do { \
341 struct tls_cursor cursor; \
342 struct type desc; \
343 void *empty; \
344 \
345 memset ( &desc, 0, sizeof ( desc ) ); \
346 ok ( tls_size ( type, version, &desc, &cursor ) == 0 ); \
347 empty = zalloc ( cursor.len ); \
348 ok ( empty != NULL ); \
349 cursor.data = empty; \
350 ok ( tls_build ( type, version, &desc, &cursor ) == 0 ); \
351 ok ( tls_parse ( type, version, &cursor, &desc ) == 0 ); \
352 free ( empty ); \
353 } while ( 0 )
354
355/**
356 * Report a mapping validity test result
357 *
358 * @v type Descriptor structure name
359 */
360#define map_ok( type ) do { \
361 map_version_ok ( type, TLS_VERSION_TLS_1_1 ); \
362 map_version_ok ( type, TLS_VERSION_TLS_1_2 ); \
363 map_version_ok ( type, TLS_VERSION_TLS_1_3 ); \
364 } while ( 0 )
365
366/**
367 * Report a cursor comparison test result
368 *
369 * @v cursor Cursor
370 * @v reference Reference cursor
371 * @v file Test code file
372 * @v line Test code line
373 */
374static void cursor_okx ( struct tls_cursor *cursor,
375 struct tls_cursor *reference,
376 const char *file, unsigned int line ) {
377
378 /* Compare cursors */
379 okx ( cursor->len == reference->len, file, line );
380 okx ( memcmp ( cursor->data, reference->data, reference->len ) == 0,
381 file, line );
382}
383#define cursor_ok( cursor, reference ) \
384 cursor_okx ( (cursor), (reference), __FILE__, __LINE__ )
385
386/**
387 * Report a pre-extensions comparison test result
388 *
389 * @v data Data
390 * @v ext Extensions
391 * @v reference Reference data
392 * @v reference_ext Reference extensions
393 * @v file Test code file
394 * @v line Test code line
395 */
396static void pre_ext_okx ( const void *data, struct tls_cursor *extensions,
397 const void *reference,
398 struct tls_cursor *reference_ext,
399 const char *file, unsigned int line ) {
400 size_t reference_len = ( reference_ext->data - reference );
401 size_t len = ( extensions->data - data );
402
403 /* Compare cursors */
404 okx ( len == reference_len, file, line );
405 okx ( memcmp ( data, reference, reference_len ) == 0, file, line );
406}
407#define pre_ext_ok( data, ext, reference, reference_ext ) \
408 pre_ext_okx ( (data), (ext), (reference), (reference_ext), \
409 __FILE__, __LINE__ )
410
411/**
412 * Perform TLS data format self-test
413 *
414 */
415static void tlsfmt_test_exec ( void ) {
416 union tlsfmt_test_data u;
417 struct tls_cursor cursor;
418 struct tls_client_hello client_hello;
419 struct tls_client_hello client_hello_ref;
420 struct tls_server_hello server_hello;
421 struct tls_server_hello server_hello_ref;
422 struct tls_supported_version supported_version;
423 struct tls_supported_versions supported_versions;
424 struct tls_key_share_entry key_share_entry;
425 struct tls_key_share_client_hello key_share_client_hello;
426 struct tls_certificate certificate;
427 struct tls_certificate_entry certificate_entry;
428 struct tls_server_key_exchange_ecdhe server_key_exchange_ecdhe;
429 struct tls_digitally_signed digitally_signed;
430 struct tls_server_name server_name;
431 struct tls_server_name_list server_name_list;
432 struct tls_psk_key_exchange_modes psk_key_exchange_modes;
433 struct x509_certificate *tls13_cert;
434 struct x509_certificate *tls12_cert;
435 unsigned int offset;
436 uint16_t __attribute__ (( aligned ( 1 ) )) *tmp16;
438 uint16_t record;
439 uint8_t empty[0];
440
441 /* Check validity of all mappings */
469
470 /* Well-formed TLSv1.3 ServerHello */
471 memset ( u.tls13_server_hello, 0xaa, sizeof ( u.tls13_server_hello ) );
472 memcpy ( u.tls13_server_hello, tls13_server_hello,
473 sizeof ( tls13_server_hello ) );
474 cursor.data = u.tls13_server_hello;
475 cursor.len = sizeof ( tls13_server_hello );
477 &server_hello ) == 0 );
478 ok ( server_hello.a->version == htons ( TLS_VERSION_TLS_1_2 ) );
479 ok ( server_hello.session_id.data != NULL );
480 ok ( server_hello.session_id.len == 0 );
481 ok ( server_hello.b->suite == htons ( TLS_AES_128_GCM_SHA256 ) );
482 ok ( server_hello.ext.reneg.data == NULL );
483 ok ( server_hello.ext.ems.data == NULL );
484 ok ( server_hello.ext.supver.data != NULL );
485 ok ( server_hello.ext.key.data != NULL );
487 &server_hello.ext.supver, &supported_version ) == 0 );
488 ok ( *supported_version.selected == htons ( TLS_VERSION_TLS_1_3 ) );
490 &server_hello.ext.key, &key_share_entry ) == 0 );
491 ok ( *key_share_entry.group == htons ( TLS_NAMED_GROUP_X25519 ) );
492 ok ( key_share_entry.public.data != NULL );
493 ok ( key_share_entry.public.len ==
494 sizeof ( tls13_server_hello_public ) );
495 ok ( key_share_entry.next.data != NULL );
496 ok ( key_share_entry.next.len == 0 );
497
498 /* Truncated fixed-length data */
499 cursor.data = server_hello.ext.supver.data;
500 cursor.len = server_hello.ext.supver.len;
502 &cursor, &supported_version ) == 0 );
503 cursor.len -= 1;
505 &cursor, &supported_version ) != 0 );
506
507 /* Truncated variable-length length */
508 cursor.data = server_hello.ext.key.data;
509 cursor.len = server_hello.ext.key.len;
511 &key_share_entry ) == 0 );
512 cursor.len = ( sizeof ( *key_share_entry.group ) + 1 );
514 &key_share_entry ) != 0 );
515
516 /* Truncated variable-length data */
517 cursor.data = u.tls13_server_hello;
518 cursor.len = sizeof ( tls13_server_hello );
520 &server_hello ) == 0 );
521 cursor.len -= 1;
523 &server_hello ) != 0 );
524
525 /* Excess data */
526 cursor.data = u.tls13_server_hello;
527 cursor.len = sizeof ( tls13_server_hello );
529 &server_hello ) == 0 );
530 cursor.len += 1;
532 &server_hello ) != 0 );
533
534 /* Duplicate extension type */
535 cursor.data = u.tls13_server_hello;
536 cursor.len = sizeof ( tls13_server_hello );
538 &server_hello ) == 0 );
539 offset = ( server_hello.ext.key.data - cursor.data - 4 );
540 tmp16 = ( ( void * ) &u.tls13_server_hello[offset] );
541 ok ( *tmp16 == htons ( TLS_KEY_SHARE ) );
542 *tmp16 = htons ( TLS_RENEGOTIATION_INFO );
544 &server_hello ) == 0 );
545 *tmp16 = htons ( TLS_SUPPORTED_VERSIONS );
547 &server_hello ) != 0 );
548 *tmp16 = htons ( TLS_KEY_SHARE );
550 &server_hello ) == 0 );
551
552 /* Malformed extension length */
553 cursor.data = u.tls13_server_hello;
554 cursor.len = sizeof ( tls13_server_hello );
556 &server_hello ) == 0 );
557 offset = ( server_hello.ext.key.data - cursor.data - 2 );
558 tmp16 = ( ( void * ) &u.tls13_server_hello[offset] );
559 ok ( *tmp16 == htons ( 36 ) );
560 *tmp16 = htons ( sizeof ( tls13_server_hello ) );
562 &server_hello ) != 0 );
563 *tmp16 = htons ( 36 );
565 &server_hello ) == 0 );
566
567 /* Well-formed TLSv1.3 Certificate */
568 memcpy ( u.tls13_certificate, tls13_certificate,
569 sizeof ( tls13_certificate ) );
570 cursor.data = u.tls13_certificate;
571 cursor.len = sizeof ( tls13_certificate );
573 &certificate ) == 0 );
575 &certificate.list, &certificate_entry ) == 0 );
576 ok ( x509_certificate ( certificate_entry.cert.data,
577 certificate_entry.cert.len,
578 &tls13_cert ) == 0 );
579 ok ( certificate_entry.next.data != NULL );
580 ok ( certificate_entry.next.len == 0 );
581 ok ( asn1_compare ( tls_asn1 ( &certificate_entry.cert ),
582 &tls13_cert->raw ) == 0 );
583
584 /* Fields not present in older TLS versions */
586 &certificate ) == 0 );
588 &certificate ) != 0 );
589
590 /* Well-formed TLSv1.2 Certificate */
591 memcpy ( u.tls12_certificate, tls12_certificate,
592 sizeof ( tls12_certificate ) );
593 cursor.data = u.tls12_certificate;
594 cursor.len = sizeof ( tls12_certificate );
596 &certificate ) == 0 );
598 &certificate.list, &certificate_entry ) == 0 );
599 ok ( x509_certificate ( certificate_entry.cert.data,
600 certificate_entry.cert.len,
601 &tls12_cert ) == 0 );
602 ok ( certificate_entry.next.data != NULL );
603 ok ( certificate_entry.next.len == 0 );
604 ok ( asn1_compare ( tls_asn1 ( &certificate_entry.cert ),
605 &tls12_cert->raw ) == 0 );
606 ok ( tls12_cert == tls13_cert );
607
608 /* Fields not present in newer TLS versions */
610 &certificate ) == 0 );
612 &certificate ) != 0 );
613
614 /* Well-formed TLSv1.1 ServerHello with no extensions */
615 memcpy ( u.tls11_server_hello, tls11_server_hello,
616 sizeof ( tls11_server_hello ) );
617 cursor.data = u.tls11_server_hello;
618 cursor.len = sizeof ( tls11_server_hello );
620 &server_hello ) == 0 );
622 &server_hello ) == 0 );
624 &server_hello ) != 0 );
625
626 /* Well-formed TLSv1.2 ServerKeyExchange with explicit algorithm */
627 memcpy ( u.tls12_server_key_exchange_ecdhe,
630 cursor.data = u.tls12_server_key_exchange_ecdhe;
631 cursor.len = sizeof ( tls12_server_key_exchange_ecdhe );
633 &cursor, &server_key_exchange_ecdhe ) == 0 );
634 ok ( server_key_exchange_ecdhe.curve->type == TLS_NAMED_CURVE_TYPE );
635 ok ( server_key_exchange_ecdhe.curve->group ==
638 &cursor, &server_key_exchange_ecdhe ) == 0 );
640 &server_key_exchange_ecdhe.dsig,
641 &digitally_signed ) == 0 );
642 ok ( digitally_signed.sig_hash != NULL );
643 ok ( *digitally_signed.sig_hash == htons ( TLS_RSA_SHA1_ALGORITHM ) );
645 &server_key_exchange_ecdhe.dsig,
646 &digitally_signed ) != 0 );
647
648 /* Well-formed TLSv1.1 ServerKeyExchange with implicit algorithm */
649 memcpy ( u.tls11_server_key_exchange_ecdhe,
652 cursor.data = u.tls11_server_key_exchange_ecdhe;
653 cursor.len = sizeof ( tls11_server_key_exchange_ecdhe );
655 &cursor, &server_key_exchange_ecdhe ) == 0 );
656 ok ( server_key_exchange_ecdhe.curve->type == TLS_NAMED_CURVE_TYPE );
657 ok ( server_key_exchange_ecdhe.curve->group ==
660 &cursor, &server_key_exchange_ecdhe ) == 0 );
662 &server_key_exchange_ecdhe.dsig,
663 &digitally_signed ) == 0 );
664 ok ( digitally_signed.sig_hash == NULL );
666 &server_key_exchange_ecdhe.dsig,
667 &digitally_signed ) != 0 );
668
669 /* Build TLSv1.3 ServerHello */
670 memset ( &supported_version, 0, sizeof ( supported_version ) );
671 memset ( &key_share_entry, 0, sizeof ( key_share_entry ) );
672 memset ( &server_hello, 0, sizeof ( server_hello ) );
674 key_share_entry.group = &group;
675 key_share_entry.public.data = tls13_server_hello_public;
676 key_share_entry.public.len = sizeof ( tls13_server_hello_public );
678 &supported_version, &server_hello.ext.supver ) == 0 );
680 &key_share_entry, &server_hello.ext.key ) == 0 );
682 &server_hello, &cursor ) == 0 );
683 ok ( cursor.len == sizeof ( tls13_server_hello ) );
684 cursor.data = u.tls13_server_hello;
686 &server_hello, &cursor ) == 0 );
687 server_hello.a->version = htons ( TLS_VERSION_TLS_1_2 );
688 memcpy ( server_hello.a->random, tls13_server_hello_random,
689 sizeof ( server_hello.a->random ) );
690 server_hello.b->suite = htons ( TLS_AES_128_GCM_SHA256 );
692 &key_share_entry, &server_hello.ext.key ) == 0 );
694 &supported_version, &server_hello.ext.supver ) == 0 );
695 *supported_version.selected = htons ( TLS_VERSION_TLS_1_3 );
696 DBGC ( &cursor, "TLSFMT built TLSv1.3 ServerHello:\n" );
697 DBGC_HDA ( &cursor, 0, cursor.data, cursor.len );
698 DBGC ( &cursor, "TLSFMT reference TLSv1.3 ServerHello:\n" );
699 DBGC_HDA ( &cursor, 0, tls13_server_hello,
700 sizeof ( tls13_server_hello ) );
701 cursor.data = tls13_server_hello;
702 cursor.len = sizeof ( tls13_server_hello );
704 &cursor, &server_hello_ref ) == 0 );
705 pre_ext_ok ( u.tls13_server_hello, &server_hello.ext.all,
706 tls13_server_hello, &server_hello_ref.ext.all );
707 cursor_ok ( &server_hello.ext.supver, &server_hello_ref.ext.supver );
708 cursor_ok ( &server_hello.ext.key, &server_hello_ref.ext.key );
709
710 /* Build TLSv1.2 ServerKeyExchange */
711 memset ( &digitally_signed, 0, sizeof ( digitally_signed ) );
712 memset ( &server_key_exchange_ecdhe, 0,
713 sizeof ( server_key_exchange_ecdhe ) );
714 server_key_exchange_ecdhe.point.data = server_key_exchange_point;
715 server_key_exchange_ecdhe.point.len =
716 sizeof ( server_key_exchange_point );
717 digitally_signed.sig.data = server_key_exchange_sig;
718 digitally_signed.sig.len = sizeof ( server_key_exchange_sig );
720 &digitally_signed,
721 &server_key_exchange_ecdhe.dsig ) == 0 );
723 &server_key_exchange_ecdhe, &cursor ) == 0 );
724 ok ( cursor.len == sizeof ( tls12_server_key_exchange_ecdhe ) );
725 cursor.data = u.tls12_server_key_exchange_ecdhe;
727 &server_key_exchange_ecdhe, &cursor ) == 0 );
729 &digitally_signed,
730 &server_key_exchange_ecdhe.dsig ) == 0 );
731 server_key_exchange_ecdhe.curve->type = TLS_NAMED_CURVE_TYPE;
732 server_key_exchange_ecdhe.curve->group =
734 ok ( digitally_signed.sig_hash != NULL );
735 *digitally_signed.sig_hash = htons ( TLS_RSA_SHA1_ALGORITHM );
736 DBGC ( &cursor, "TLSFMT built TLSv1.2 ServerKeyExchange:\n" );
737 DBGC_HDA ( &cursor, 0, cursor.data, cursor.len );
738 DBGC ( &cursor, "TLSFMT reference TLSv1.2 ServerKeyExchange:\n" );
741 ok ( memcmp ( u.tls12_server_key_exchange_ecdhe,
743 sizeof ( tls12_server_key_exchange_ecdhe ) ) == 0 );
744
745 /* Build TLSv1.1 ServerKeyExchange */
746 memset ( &digitally_signed, 0, sizeof ( digitally_signed ) );
747 memset ( &server_key_exchange_ecdhe, 0,
748 sizeof ( server_key_exchange_ecdhe ) );
749 server_key_exchange_ecdhe.point.data = server_key_exchange_point;
750 server_key_exchange_ecdhe.point.len =
751 sizeof ( server_key_exchange_point );
752 digitally_signed.sig.data = server_key_exchange_sig;
753 digitally_signed.sig.len = sizeof ( server_key_exchange_sig );
755 &digitally_signed,
756 &server_key_exchange_ecdhe.dsig ) == 0 );
758 &server_key_exchange_ecdhe, &cursor ) == 0 );
759 ok ( cursor.len == sizeof ( tls11_server_key_exchange_ecdhe ) );
760 cursor.data = u.tls11_server_key_exchange_ecdhe;
762 &server_key_exchange_ecdhe, &cursor ) == 0 );
764 &digitally_signed,
765 &server_key_exchange_ecdhe.dsig ) == 0 );
766 server_key_exchange_ecdhe.curve->type = TLS_NAMED_CURVE_TYPE;
767 server_key_exchange_ecdhe.curve->group =
769 ok ( digitally_signed.sig_hash == NULL );
770 DBGC ( &cursor, "TLSFMT built TLSv1.1 ServerKeyExchange:\n" );
771 DBGC_HDA ( &cursor, 0, cursor.data, cursor.len );
772 DBGC ( &cursor, "TLSFMT reference TLSv1.1 ServerKeyExchange:\n" );
775 ok ( memcmp ( u.tls11_server_key_exchange_ecdhe,
777 sizeof ( tls11_server_key_exchange_ecdhe ) ) == 0 );
778
779 /* Build TLSv1.3 ClientHello */
780 memset ( &server_name, 0, sizeof ( server_name ) );
781 memset ( &server_name_list, 0, sizeof ( server_name_list ) );
782 memset ( &key_share_entry, 0, sizeof ( key_share_entry ) );
783 memset ( &key_share_client_hello, 0,
784 sizeof ( key_share_client_hello ) );
785 memset ( &supported_versions, 0, sizeof ( supported_versions ) );
786 memset ( &psk_key_exchange_modes, 0,
787 sizeof ( psk_key_exchange_modes ) );
788 memset ( &client_hello, 0, sizeof ( client_hello ) );
789 server_name.name.data = "server";
790 server_name.name.len = strlen ( server_name.name.data );
792 &server_name, &server_name_list.list ) == 0 );
794 &server_name_list, &client_hello.ext.names ) == 0 );
796 key_share_entry.group = &group;
797 key_share_entry.public.data = tls13_client_hello_public;
798 key_share_entry.public.len = sizeof ( tls13_client_hello_public );
800 &key_share_entry,
801 &key_share_client_hello.list ) == 0 );
803 &key_share_client_hello,
804 &client_hello.ext.keys ) == 0 );
805 supported_versions.list.data = tls13_client_hello_supvers;
806 supported_versions.list.len = sizeof ( tls13_client_hello_supvers );
808 &supported_versions,
809 &client_hello.ext.supvers ) == 0 );
810 psk_key_exchange_modes.list.data = tls13_client_hello_pskmodes;
811 psk_key_exchange_modes.list.len =
814 &psk_key_exchange_modes,
815 &client_hello.ext.pskmodes ) == 0 );
817 client_hello.suites.len = sizeof ( tls13_client_hello_suites );
818 client_hello.compression.len = 1;
819 client_hello.ext.reneg.len = 1;
821 client_hello.ext.groups.len = sizeof ( tls13_client_hello_groups );
822 client_hello.ext.ticket.data = empty;
823 client_hello.ext.sigs.data = tls13_client_hello_sigs;
824 client_hello.ext.sigs.len = sizeof ( tls13_client_hello_sigs );
825 record = htons ( 0x4001 );
826 client_hello.ext.record.data = &record;
827 client_hello.ext.record.len = sizeof ( record );
829 &client_hello, &cursor ) == 0 );
830 ok ( cursor.len == sizeof ( tls13_client_hello ) );
831 cursor.data = u.tls13_client_hello;
833 &client_hello, &cursor ) == 0 );
834 client_hello.a->version = htons ( TLS_VERSION_TLS_1_2 );
836 &server_name_list, &client_hello.ext.names ) == 0 );
838 &server_name, &server_name_list.list ) == 0 );
840 &key_share_client_hello,
841 &client_hello.ext.keys ) == 0 );
843 &key_share_entry,
844 &key_share_client_hello.list ) == 0 );
846 &supported_versions,
847 &client_hello.ext.supvers ) == 0 );
849 &psk_key_exchange_modes,
850 &client_hello.ext.pskmodes ) == 0 );
851 memcpy ( client_hello.a->random, tls13_client_hello_random,
852 sizeof ( client_hello.a->random ) );
853 DBGC ( &cursor, "TLSFMT built TLSv1.3 ClientHello:\n" );
854 DBGC_HDA ( &cursor, 0, cursor.data, cursor.len );
855 DBGC ( &cursor, "TLSFMT reference TLSv1.3 ClientHello:\n" );
856 DBGC_HDA ( &cursor, 0, tls13_client_hello,
857 sizeof ( tls13_client_hello ) );
858 cursor.data = tls13_client_hello;
859 cursor.len = sizeof ( tls13_client_hello );
861 &cursor, &client_hello_ref ) == 0 );
862 pre_ext_ok ( u.tls13_client_hello, &client_hello.ext.all,
863 tls13_client_hello, &client_hello_ref.ext.all );
864 cursor_ok ( &client_hello.ext.ems, &client_hello_ref.ext.ems );
865 cursor_ok ( &client_hello.ext.frag, &client_hello_ref.ext.frag );
866 cursor_ok ( &client_hello.ext.groups, &client_hello_ref.ext.groups );
867 cursor_ok ( &client_hello.ext.keys, &client_hello_ref.ext.keys );
868 cursor_ok ( &client_hello.ext.names, &client_hello_ref.ext.names );
869 cursor_ok ( &client_hello.ext.pskmodes,
870 &client_hello_ref.ext.pskmodes );
871 cursor_ok ( &client_hello.ext.record, &client_hello_ref.ext.record );
872 cursor_ok ( &client_hello.ext.reneg, &client_hello_ref.ext.reneg );
873 cursor_ok ( &client_hello.ext.sigs, &client_hello_ref.ext.sigs );
874 cursor_ok ( &client_hello.ext.supvers, &client_hello_ref.ext.supvers );
875 cursor_ok ( &client_hello.ext.ticket, &client_hello_ref.ext.ticket );
876
877 /* Propagation of sizing errors */
878 memset ( &digitally_signed, 0, sizeof ( digitally_signed ) );
879 memset ( &server_key_exchange_ecdhe, 0,
880 sizeof ( server_key_exchange_ecdhe ) );
882 &digitally_signed,
883 &server_key_exchange_ecdhe.dsig ) == 0 );
885 &server_key_exchange_ecdhe, &cursor ) == 0 );
886 memset ( &digitally_signed, 0, sizeof ( digitally_signed ) );
887 memset ( &server_key_exchange_ecdhe, 0,
888 sizeof ( server_key_exchange_ecdhe ) );
889 digitally_signed.sig.len = 0x10000;
891 &digitally_signed,
892 &server_key_exchange_ecdhe.dsig ) != 0 );
894 &server_key_exchange_ecdhe, &cursor ) != 0 );
895
896 /* Drop certificate references */
897 x509_put ( tls12_cert );
898 x509_put ( tls13_cert );
899}
900
901/** TLS data format self-test */
902struct self_test tlsfmt_test __self_test = {
903 .name = "tlsfmt",
904 .exec = tlsfmt_test_exec,
905};
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
unsigned short uint16_t
Definition stdint.h:11
unsigned char uint8_t
Definition stdint.h:10
int asn1_compare(const struct asn1_cursor *cursor1, const struct asn1_cursor *cursor2)
Compare two ASN.1 objects.
Definition asn1.c:566
uint16_t offset
Offset to command line.
Definition bzimage.h:3
union @104331263140136355135267063077374276003064103115 u
ring len
Length.
Definition dwmac.h:226
uint8_t data[48]
Additional event data.
Definition ena.h:11
uint16_t group
Type of event.
Definition ena.h:1
#define DBGC(...)
Definition compiler.h:530
#define DBGC_HDA(...)
Definition compiler.h:531
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define htons(value)
Definition byteswap.h:136
#define __attribute__(x)
Definition compiler.h:10
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
size_t strlen(const char *src)
Get length of string.
Definition string.c:244
A self-test set.
Definition test.h:15
CertificateEntry descriptor.
Definition tlsfmt.h:400
struct tls_cursor next
Next certificate.
Definition tlsfmt.h:409
struct tls_cursor cert
Certificate data.
Definition tlsfmt.h:402
Certificate descriptor.
Definition tlsfmt.h:392
struct tls_cursor list
Certificate list.
Definition tlsfmt.h:396
ClientHello descriptor.
Definition tlsfmt.h:413
struct tls_cursor frag
Maximum fragment length extension.
Definition tlsfmt.h:436
struct tls_cursor sigs
Signature algorithms extension.
Definition tlsfmt.h:450
struct tls_client_hello::@300242163101377353070067133352065270331266023376 * a
Fixed portion.
struct tls_cursor pskmodes
Preshared key modes extension.
Definition tlsfmt.h:444
struct tls_client_hello::@315336275176055335347330363223260265225077223170 ext
Extensions of interest.
struct tls_cursor keys
Key share extension.
Definition tlsfmt.h:440
struct tls_cursor groups
Supported groups extension.
Definition tlsfmt.h:438
struct tls_cursor all
All extensions.
Definition tlsfmt.h:430
uint8_t random[32]
Client random bytes.
Definition tlsfmt.h:419
struct tls_cursor reneg
Renegotiation information extension.
Definition tlsfmt.h:448
struct tls_cursor compression
Compression methods.
Definition tlsfmt.h:426
uint16_t version
Offered version.
Definition tlsfmt.h:417
struct tls_cursor record
Record size limit extension.
Definition tlsfmt.h:446
struct tls_cursor suites
Cipher suites.
Definition tlsfmt.h:424
struct tls_cursor ems
Extended master secret extension.
Definition tlsfmt.h:434
struct tls_cursor ticket
Session ticket extension.
Definition tlsfmt.h:454
struct tls_cursor supvers
Supported versions extension.
Definition tlsfmt.h:452
struct tls_cursor names
Server name indication extension.
Definition tlsfmt.h:442
ClientKeyExchange descriptor (for DHE).
Definition tlsfmt.h:459
ClientKeyExchange descriptor (for ECDHE).
Definition tlsfmt.h:465
ClientKeyExchange descriptor (for key transport).
Definition tlsfmt.h:471
A TLS variable-length data cursor.
Definition tlsfmt.h:186
void * data
Data.
Definition tlsfmt.h:188
size_t len
Length of data.
Definition tlsfmt.h:190
DigitallySigned descriptor.
Definition tlsfmt.h:491
uint16_t * sig_hash
Signature and hash algorithm.
Definition tlsfmt.h:493
struct tls_cursor sig
Signature.
Definition tlsfmt.h:495
Extension descriptor.
Definition tlsfmt.h:499
HelloRequest descriptor.
Definition tlsfmt.h:509
KeyShareClientHello descriptor.
Definition tlsfmt.h:512
struct tls_cursor list
Key share list.
Definition tlsfmt.h:514
KeyShareEntry descriptor.
Definition tlsfmt.h:518
struct tls_cursor next
Next key share.
Definition tlsfmt.h:524
uint16_t * group
Named group.
Definition tlsfmt.h:520
struct tls_cursor public
Public key.
Definition tlsfmt.h:522
KeyShareHelloRetryRequest descriptor.
Definition tlsfmt.h:528
KeyShareServerHello descriptor.
Definition tlsfmt.h:534
MaxFragmentLength descriptor.
Definition tlsfmt.h:554
NamedGroupList descriptor.
Definition tlsfmt.h:560
NewSessionTicket descriptor.
Definition tlsfmt.h:566
PskKeyExchangeModes descriptor.
Definition tlsfmt.h:583
struct tls_cursor list
Mode list.
Definition tlsfmt.h:585
RenegotiationInfo descriptor.
Definition tlsfmt.h:589
ServerHelloDone descriptor.
Definition tlsfmt.h:630
ServerHello descriptor.
Definition tlsfmt.h:595
struct tls_cursor key
Key share extension.
Definition tlsfmt.h:623
struct tls_cursor all
All extensions.
Definition tlsfmt.h:615
struct tls_server_hello::@161027372353017270343224204013300325065157134244 * b
Second fixed-length portion.
struct tls_cursor session_id
Session ID.
Definition tlsfmt.h:604
struct tls_cursor ems
Extended master secret extension.
Definition tlsfmt.h:619
uint8_t random[32]
Server random bytes.
Definition tlsfmt.h:601
struct tls_server_hello::@217117216140245056320340176176032022306073365001 ext
Extensions of interest.
uint16_t version
Selected version.
Definition tlsfmt.h:599
struct tls_server_hello::@103274354304025060212205334334227305117174114135 * a
First fixed-length portion.
uint16_t suite
Selected cipher suite.
Definition tlsfmt.h:608
struct tls_cursor reneg
Renegotiation information extension.
Definition tlsfmt.h:617
struct tls_cursor supver
Supported versions extension.
Definition tlsfmt.h:621
ServerKeyExchange descriptor (for DHE).
Definition tlsfmt.h:633
ServerKeyExchange descriptor (for ECDHE).
Definition tlsfmt.h:645
struct tls_server_key_exchange_ecdhe::@335121145353041211061272202142307345103264367317 * curve
Curve parameters.
uint8_t type
Curve type.
Definition tlsfmt.h:649
uint16_t group
Named group.
Definition tlsfmt.h:651
struct tls_cursor dsig
Signature.
Definition tlsfmt.h:656
struct tls_cursor point
Curve point.
Definition tlsfmt.h:654
ServerNameList descriptor.
Definition tlsfmt.h:668
struct tls_cursor list
Server name list.
Definition tlsfmt.h:670
ServerName descriptor.
Definition tlsfmt.h:660
struct tls_cursor name
Host name.
Definition tlsfmt.h:664
SignatureSchemeList descriptor.
Definition tlsfmt.h:674
SupportedVersions descriptor (in ServerHello).
Definition tlsfmt.h:680
uint16_t * selected
Selected version.
Definition tlsfmt.h:682
SupportedVersions descriptor (in ClientHello).
Definition tlsfmt.h:686
struct tls_cursor list
Supported version list.
Definition tlsfmt.h:688
An X.509 certificate.
Definition x509.h:216
struct asn1_cursor raw
Raw certificate.
Definition x509.h:231
Self-test infrastructure.
#define okx(success, file, line)
Report test result.
Definition test.h:44
#define ok(success)
Definition test.h:46
#define __self_test
Declare a self-test.
Definition test.h:32
Transport Layer Security Protocol.
#define TLS_RENEGOTIATION_INFO
Definition tls.h:201
#define TLS_KEY_SHARE
Definition tls.h:198
#define TLS_SUPPORTED_VERSIONS
Definition tls.h:189
#define TLS_AES_128_GCM_SHA256
Definition tls.h:124
#define TLS_RSA_SHA1_ALGORITHM
Definition tls.h:140
#define TLS_NAMED_GROUP_X25519
Definition tls.h:171
#define TLS_NAMED_CURVE_TYPE
TLS named curve type.
Definition tls.h:305
TLS data formats.
#define tls_build(type, version, desc, cursor)
Build TLS data structure.
Definition tlsfmt.h:763
static const struct asn1_cursor * tls_asn1(const struct tls_cursor *cursor)
Get ASN.1 cursor from TLS cursor.
Definition tlsfmt.h:698
#define TLS_VERSION_TLS_1_2
TLS version 1.2.
Definition tlsfmt.h:177
#define tls_parse(type, version, cursor, desc)
Parse TLS data structure.
Definition tlsfmt.h:733
#define TLS_VERSION_TLS_1_3
TLS version 1.3.
Definition tlsfmt.h:180
#define TLS_VERSION_TLS_1_1
TLS version 1.1.
Definition tlsfmt.h:174
#define tls_size(type, version, desc, cursor)
Calculate length of TLS data structure.
Definition tlsfmt.h:778
static uint8_t tls13_client_hello_supvers[]
TLSv1.3 ClientHello supported version.
static uint8_t server_key_exchange_point[]
ServerKeyExchange public curve point.
static uint8_t tls11_server_hello[]
TLSv1.1 ServerHello with no extensions.
#define cursor_ok(cursor, reference)
static void tlsfmt_test_exec(void)
Perform TLS data format self-test.
static uint8_t tls11_server_key_exchange_ecdhe[]
TLSv1.1 ServerKeyExchange with implicit signature hash algorithm.
static void cursor_okx(struct tls_cursor *cursor, struct tls_cursor *reference, const char *file, unsigned int line)
Report a cursor comparison test result.
static uint8_t tls13_client_hello_sigs[]
TLSv1.3 ClientHello signature algorithms.
static uint8_t tls13_server_hello_public[]
TLSv1.3 ServerHello public key.
Definition tlsfmt_test.c:61
static uint8_t server_key_exchange_sig[]
ServerKeyExchange signature.
static uint8_t tls13_client_hello_random[]
TLSv1.3 ClientHello random bytes.
#define map_ok(type)
Report a mapping validity test result.
static void pre_ext_okx(const void *data, struct tls_cursor *extensions, const void *reference, struct tls_cursor *reference_ext, const char *file, unsigned int line)
Report a pre-extensions comparison test result.
static uint8_t tls13_server_hello_random[]
TLSv1.3 ServerHello random bytes.
Definition tlsfmt_test.c:54
static uint8_t tls13_client_hello_suites[]
TLSv1.3 ClientHello cipher suites.
static uint8_t tls13_server_hello[]
Known valid TLSv1.3 ServerHello (from RFC 8448).
Definition tlsfmt_test.c:42
#define pre_ext_ok(data, ext, reference, reference_ext)
static uint8_t tls13_client_hello_groups[]
TLSv1.3 ClientHello supported groups.
static uint8_t tls12_server_key_exchange_ecdhe[]
TLSv1.2 ServerKeyExchange with explicit signature hash algorithm.
static uint8_t tls12_certificate[]
TLSv1.2 Certificate (derived from RFC 8448).
static uint8_t tls13_client_hello_public[]
TLSv1.3 ClientHello public key.
static uint8_t tls13_certificate[]
Known valid TLSv1.3 Certificate (from RFC 8448).
Definition tlsfmt_test.c:68
static uint8_t tls13_client_hello[]
Reference TLSv1.3 ClientHello (from RFC 8448).
static uint8_t tls13_client_hello_pskmodes[]
TLSv1.3 ClientHello pre-shared key modes.
Space for test data.
uint8_t tls12_certificate[sizeof(tls12_certificate)]
uint8_t tls13_server_hello[sizeof(tls13_server_hello)+1]
uint8_t tls11_server_hello[sizeof(tls11_server_hello)]
uint8_t tls13_certificate[sizeof(tls13_certificate)]
uint8_t tls13_client_hello[sizeof(tls13_client_hello)]
uint8_t tls12_server_key_exchange_ecdhe[sizeof(tls12_server_key_exchange_ecdhe)]
uint8_t tls11_server_key_exchange_ecdhe[sizeof(tls11_server_key_exchange_ecdhe)]
static void x509_put(struct x509_certificate *cert)
Drop reference to X.509 certificate.
Definition x509.h:278