blob: 96f844cdb1d9b9a7b9f20fb5cb83e571c6f0b7ed [file] [log] [blame] [view]
Hanno Becker0c3bebf2020-06-02 06:32:43 +01001TLS 1.3 Experimental Developments
Hanno Becker9338f9f2020-05-31 07:39:50 +01002=================================
3
4Overview
5--------
6
7Mbed TLS doesn't support the TLS 1.3 protocol yet, but a prototype is in development.
8Stable parts of this prototype that can be independently tested are being successively
9upstreamed under the guard of the following macro:
10
11```
12MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL
13```
14
15This macro will likely be renamed to `MBEDTLS_SSL_PROTO_TLS1_3` once a minimal viable
16implementation of the TLS 1.3 protocol is available.
17
Bence Szépkútibb0cfeb2021-05-28 09:42:25 +020018See the [documentation of `MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL`](../../include/mbedtls/mbedtls_config.h)
Hanno Becker9338f9f2020-05-31 07:39:50 +010019for more information.
20
21Status
22------
23
24The following lists which parts of the TLS 1.3 prototype have already been upstreamed
25together with their level of testing:
26
27* TLS 1.3 record protection mechanisms
28
29 The record protection routines `mbedtls_ssl_{encrypt|decrypt}_buf()` have been extended
30 to support the modified TLS 1.3 record protection mechanism, including modified computation
31 of AAD, IV, and the introduction of a flexible padding.
32
33 Those record protection routines have unit tests in `test_suite_ssl` alongside the
34 tests for the other record protection routines.
35
36 TODO: Add some test vectors from RFC 8448.
Hanno Becker5a83d292020-06-02 06:33:00 +010037
38- The HKDF key derivation function on which the TLS 1.3 key schedule is based,
39 is already present as an independent module controlled by `MBEDTLS_HKDF_C`
40 independently of the development of the TLS 1.3 prototype.
Hanno Beckerb11c3092020-08-10 17:00:19 +010041
42- The TLS 1.3-specific HKDF-based key derivation functions (see RFC 8446):
43 * HKDF-Expand-Label
44 * Derive-Secret
45 - Secret evolution
46 * The traffic {Key,IV} generation from secret
47 Those functions are implemented in `library/ssl_tls13_keys.c` and
48 tested in `test_suite_ssl` using test vectors from RFC 8448 and
49 https://tls13.ulfheim.net/.
Hanno Becker7594c682021-03-05 05:17:11 +000050
51- New TLS Message Processing Stack (MPS)
52
53 The TLS 1.3 prototype is developed alongside a rewrite of the TLS messaging layer,
54 encompassing low-level details such as record parsing, handshake reassembly, and
55 DTLS retransmission state machine.
56
57 MPS has the following components:
58 - Layer 1 (Datagram handling)
59 - Layer 2 (Record handling)
60 - Layer 3 (Message handling)
61 - Layer 4 (Retransmission State Machine)
62 - Reader (Abstracted pointer arithmetic and reassembly logic for incoming data)
63 - Writer (Abstracted pointer arithmetic and fragmentation logic for outgoing data)
64
65 Of those components, the following have been upstreamed
66 as part of `MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL`:
67
68 - Reader ([`library/mps_reader.h`](../../library/mps_reader.h))
Ronald Cron3785c902021-09-20 09:05:36 +020069
70
71MVP definition
72--------------
73
74The TLS 1.3 MVP implements only the client side of the protocol.
75The TLS 1.3 MVP does not support the handling of server HelloRetryRequest and
76CertificateRequest messages. If it receives one of those messages, it aborts
77the handshake with an handshake_failure closure alert.
78
79- Supported cipher suites: depends on the library configuration. Potentially
80 all of them:
81 TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256,
82 TLS_AES_128_CCM_SHA256 and TLS_AES_128_CCM_8_SHA256.
83
84- Supported ClientHello extensions:
85
86 MVP Prototype
87 (for comparison)
88
89 server_name no YES
90 max_fragment_length no YES
91 status_request no no
92 supported_groups YES YES
93 signature_algorithms YES YES
94 use_srtp no no
95 heartbeat no no
96 apln no YES
97 signed_certificate_timestamp no no
98 client_certificate_type no no
99 server_certificate_type no no
100 padding no no
101 key_share YES YES
102 pre_shared_key no YES
103 psk_key_exchange_modes no YES
104 early_data no YES
105 cookie no YES
106 supported_versions YES YES
107 certificate_authorities no no
108 post_handshake_auth no no
109 signature_algorithms_cert no no
110
111- Supported groups: depends on the library configuration.
112 Potentially all ECDHE groups:
113 secp256r1, secp384r1, secp521r1(0x0019), x25519, x448.
114
115- Supported signature algorithms: depends on the library configuration.
116 Potentially:
117 ecdsa_secp256r1_sha256, ecdsa_secp384r1_sha384, ecdsa_secp521r1_sha512,
118 rsa_pss_rsae_sha256.
119
120- Supported versions: only TLS 1.3
121
122- Support of Mbed TLS SSL/TLS related (not DTLS) features:
123
124 The TLS 1.3 MVP is compatible with all TLS 1.2 configuration options in the
125 sense that when enabling the TLS 1.3 MVP in the library there is no need to
126 modify the configuration for TLS 1.2. Mbed TLS SSL/TLS related features are
127 not supported or not applicable to the TLS 1.3 MVP:
128
129 Supported Comment
130 MBEDTLS_SSL_ALL_ALERT_MESSAGES no
131 MBEDTLS_SSL_ASYNC_PRIVATE no
132 MBEDTLS_SSL_CONTEXT_SERIALIZATION no
133 MBEDTLS_SSL_DEBUG_ALL no
134 MBEDTLS_SSL_ENCRYPT_THEN_MAC n/a
135 MBEDTLS_SSL_EXTENDED_MASTER_SECRET n/a
136 MBEDTLS_SSL_KEEP_PEER_CERTIFICATE no
Ronald Crondef52c32021-09-27 12:03:55 +0200137 MBEDTLS_SSL_RENEGOTIATION n/a
Ronald Cron3785c902021-09-20 09:05:36 +0200138 MBEDTLS_SSL_MAX_FRAGMENT_LENGTH no
139 MBEDTLS_SSL_ALPN no
140
141 MBEDTLS_SSL_SESSION_TICKETS no
142 MBEDTLS_SSL_EXPORT_KEYS no Incomplete support
143 MBEDTLS_SSL_SERVER_NAME_INDICATION no
144 MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH no
145
146 MBEDTLS_ECP_RESTARTABLE no
147 MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED no
148
149 MBEDTLS_KEY_EXCHANGE_PSK_ENABLED n/a Make sense in TLS 1.3
150 MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED n/a context but their current
151 MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED n/a definition is TLS 1.2 only.
152 MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED n/a
153 MBEDTLS_KEY_EXCHANGE_RSA_ENABLED n/a
154 MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED n/a
155 MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED n/a
156 MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED n/a
157 MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED n/a
158 MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED n/a
159 MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED n/a
160
161 MBEDTLS_USE_PSA_CRYPTO no
162
163Not in the plan yet but probably necessary for a viable client:
164- server_name extension
165- support for HelloRetryRequest
166- fallback to TLS 1.2
167
168Coding rules checklist for TLS 1.3
169----------------------------------
170
171The following coding rules are aimed to be a checklist for TLS 1.3 upstreaming
172work to reduce review rounds and the number of comments in each round. They
173come along (do NOT replace) the project coding rules
174(https://tls.mbed.org/kb/development/mbedtls-coding-standards). They have been
175established and discussed following the review of #4882 that was the
176PR upstreaming the first part of TLS 1.3 ClientHello writing code.
177
178TLS 1.3 specific coding rules:
179
180 - TLS 1.3 specific C modules, headers, static functions names are prefixed
181 with `ssl_tls1_3_`. The same applies to structures and types that are
182 internal to C modules.
183
184 - TLS 1.3 specific exported functions, macros, structures and types are
185 prefixed with `mbedtls_ssl_tls1_3_`.
186
187 - The names of macros and variables related to a field or structure in the
188 TLS 1.3 specification should contain as far as possible the field name as
189 it is in the specification. If the field name is `too long` and we prefer
190 to introduce some kind of abbreviation of it, use the same abbreviation
191 everywhere in the code.
192
193 Example 1: #define CLIENT_HELLO_RANDOM_LEN 32, macro for the length of the
194 `random` field of the ClientHello message.
195
196 Example 2 (consistent abbreviation): mbedtls_ssl_tls1_3_write_sig_alg_ext()
197 and MBEDTLS_TLS_EXT_SIG_ALG, `sig_alg` standing for
198 `signature_algorithms`.
199
200 - Regarding vectors that are represented by a length followed by their value
201 in the data exchanged between servers and clients:
202
203 - Use `<vector name>_len` for the name of a variable used to compute the
204 length in bytes of the vector, where <vector name> is the name of the
205 vector as defined in the TLS 1.3 specification.
206
207 - Use `<vector_name>_len_ptr` for the name of a variable intended to hold
208 the address of the first byte of the vector length.
209
210 - Use `<vector_name>_ptr` for the name of a variable intended to hold the
211 address of the first byte of the vector value.
212
213 - Use `<vector_name>_end_ptr` for the name of a variable intended to hold
214 the address of the first byte past the vector value.
215
216 Those two last idioms should lower the risk of mis-using one of the address
217 in place of the other one which could potentially lead to some nasty
218 issues.
219
220 Example: `cipher_suites` vector of ClientHello in
221 ssl_tls1_3_write_client_hello_cipher_suites()
222
223 size_t cipher_suites_len;
224 unsigned char *cipher_suites_len_ptr;
225 unsigned char *cipher_suites_ptr;
226
227 - Use of MBEDTLS_BYTE_xyz, MBEDTLS_PUT/GET_xyz, MBEDTLS_SSL_CHK_BUF_PTR
228 MBEDTLS_SSL_CHK_BUF_READ_PTR macros where applicable.
229
230 These macros were introduced after the prototype was written thus are
231 likely not to be used in prototype where we now would use them in
232 development.
233
234 The two first types, MBEDTLS_BYTE_xyz and MBEDTLS_PUT/GET_xyz, improve
235 the readability of the code and reduce the risk of writing or reading
236 bytes in the wrong order: we should probably have only MBEDTLS_GET/PUT_*_BE
237 (BE stands for Big-Endian) macros in the TLS 1.3 code.
238
239 The two last types, MBEDTLS_SSL_CHK_BUF_PTR and
240 MBEDTLS_SSL_CHK_BUF_READ_PTR, improve the readability of the code and
241 reduce the risk of error in the non-completely-trivial arithmetic to
242 check that we do not write or read past the end of a data buffer. The
243 usage of those macros combined with the following rule mitigate the risk
244 to read/write past the end of a data buffer.
245
246 Examples: hs_hdr[1] = MBEDTLS_BYTE_2( total_hs_len );
247 MBEDTLS_PUT_UINT16_BE( MBEDTLS_TLS_EXT_SUPPORTED_VERSIONS, p, 0 );
248 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 7 );
249
250 - To mitigate what happened here
251 (https://github.com/ARMmbed/mbedtls/pull/4882#discussion_r701704527) from
252 happening again, use always a local variable named `p` for the reading
253 pointer in functions parsing TLS 1.3 data, and for the writing pointer in
254 functions writing data into an output buffer. The name `p` has been
255 chosen as it was already widely used in TLS code.
256
257 - When an TLS 1.3 structure is written or read by a function or as part of
258 a function, provide as documentation the definition of the structure as
259 it is in the TLS 1.3 specification.
260
261General coding rules:
262
263 - We prefer grouping `related statement lines` by not adding blank lines
264 between them.
265
266 Example 1:
267
268 ret = ssl_tls13_write_client_hello_cipher_suites( ssl, buf, end, &output_len );
269 if( ret != 0 )
270 return( ret );
271 buf += output_len;
272
273 Example 2:
274
275 MBEDTLS_SSL_CHK_BUF_PTR( cipher_suites_iter, end, 2 );
276 MBEDTLS_PUT_UINT16_BE( cipher_suite, cipher_suites_iter, 0 );
277 cipher_suites_iter += 2;
278
279 - Use macros for constants that are used in different functions, different
280 places in the code. When a constant is used only locally in a function
281 (like the length in bytes of the vector lengths in functions reading and
282 writing TLS handshake message) there is no need to define a macro for it.
283
284 Example: #define CLIENT_HELLO_RANDOM_LEN 32
285
286 - When declaring a pointer the dereferencing operator should be prepended to
287 the pointer name not appended to the pointer type:
288
289 Example: mbedtls_ssl_context *ssl;
290
291 - Maximum line length is 80 characters.
292
293 Exceptions:
294
295 - string literals can extend beyond 80 characters as we do not want to
296 split them to ease their search in the code base.
297
298 - A line can be more than 80 characters by a few characters if just looking
299 at the 80 first characters is enough to fully understand the line. For
300 example it is generally fine if some closure characters like ";" or ")"
301 are beyond the 80 characters limit.
302
303 - When in successive lines, functions and macros parameters should be aligned
304 vertically.
305
306 Example:
307 int mbedtls_ssl_tls13_start_handshake_msg( mbedtls_ssl_context *ssl,
308 unsigned hs_type,
309 unsigned char **buf,
310 size_t *buf_len );