blob: 0190ee5f395146b574d5e9497d69713f4b2b6d64 [file] [log] [blame]
Jerry Yu3cc4c2a2021-08-06 16:29:08 +08001/*
2 * TLS 1.3 client-side functions
3 *
4 * Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * This file is part of mbed TLS ( https://tls.mbed.org )
20 */
21
22#include "common.h"
23
24#if defined(MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL)
25
26#if defined(MBEDTLS_SSL_CLI_C)
27
Jerry Yubc20bdd2021-08-24 15:59:48 +080028#include <string.h>
29
Jerry Yu56fc07f2021-09-01 17:48:49 +080030#include "mbedtls/debug.h"
31#include "mbedtls/error.h"
Jerry Yua13c7e72021-08-17 10:44:40 +080032
Jerry Yubdc71882021-09-14 19:30:36 +080033#include "ssl_misc.h"
34#include "ecdh_misc.h"
35
Jerry Yu08906d02021-08-31 11:05:27 +080036#define CLIENT_HELLO_RANDOM_LEN 32
Jerry Yu65dd2cc2021-08-18 16:38:40 +080037
Jerry Yubc20bdd2021-08-24 15:59:48 +080038/* Write extensions */
39
Jerry Yu92c6b402021-08-27 16:59:09 +080040/*
41 * ssl_tls13_write_supported_versions_ext():
42 *
43 * struct {
44 * ProtocolVersion versions<2..254>;
45 * } SupportedVersions;
46 */
Jerry Yuf4436812021-08-26 22:59:56 +080047static int ssl_tls13_write_supported_versions_ext( mbedtls_ssl_context *ssl,
Jerry Yueecfbf02021-08-30 18:32:07 +080048 unsigned char *buf,
49 unsigned char *end,
50 size_t *olen )
Jerry Yu92c6b402021-08-27 16:59:09 +080051{
52 unsigned char *p = buf;
53
54 *olen = 0;
55
Jerry Yu159c5a02021-08-31 12:51:25 +080056 MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding supported versions extension" ) );
Jerry Yu92c6b402021-08-27 16:59:09 +080057
Jerry Yub60e3cf2021-09-08 16:41:02 +080058 /* Check if we have space for header and length fields:
59 * - extension_type (2 bytes)
60 * - extension_data_length (2 bytes)
61 * - versions_length (1 byte )
62 * - versions (2 bytes)
Jerry Yu159c5a02021-08-31 12:51:25 +080063 */
Jerry Yu92c6b402021-08-27 16:59:09 +080064 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 7 );
65
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080066 /* Write extension_type */
Jerry Yueecfbf02021-08-30 18:32:07 +080067 MBEDTLS_PUT_UINT16_BE( MBEDTLS_TLS_EXT_SUPPORTED_VERSIONS, p, 0 );
Jerry Yu92c6b402021-08-27 16:59:09 +080068
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080069 /* Write extension_data_length */
Jerry Yub7ab3362021-08-31 16:16:19 +080070 MBEDTLS_PUT_UINT16_BE( 3, p, 2 );
Jerry Yueecfbf02021-08-30 18:32:07 +080071 p += 4;
Jerry Yu92c6b402021-08-27 16:59:09 +080072
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080073 /* Length of versions */
Jerry Yu92c6b402021-08-27 16:59:09 +080074 *p++ = 0x2;
75
Jerry Yu0c63af62021-09-02 12:59:12 +080076 /* Write values of supported versions.
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080077 *
Jerry Yu0c63af62021-09-02 12:59:12 +080078 * They are defined by the configuration.
Jerry Yu1bc2c1f2021-09-01 12:57:29 +080079 *
Jerry Yu0c63af62021-09-02 12:59:12 +080080 * Currently, only one version is advertised.
Jerry Yu92c6b402021-08-27 16:59:09 +080081 */
Jerry Yueecfbf02021-08-30 18:32:07 +080082 mbedtls_ssl_write_version( ssl->conf->max_major_ver,
83 ssl->conf->max_minor_ver,
84 ssl->conf->transport, p );
Jerry Yu92c6b402021-08-27 16:59:09 +080085
86 MBEDTLS_SSL_DEBUG_MSG( 3, ( "supported version: [%d:%d]",
Jerry Yueecfbf02021-08-30 18:32:07 +080087 ssl->conf->max_major_ver,
88 ssl->conf->max_minor_ver ) );
Jerry Yu92c6b402021-08-27 16:59:09 +080089
90 *olen = 7;
91
92 return( 0 );
93}
Jerry Yubc20bdd2021-08-24 15:59:48 +080094
95#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
96
Jerry Yu6b64fe32021-09-01 17:05:13 +080097/*
98 * Functions for writing supported_groups extension.
99 *
100 * Stucture of supported_groups:
101 * enum {
102 * secp256r1(0x0017), secp384r1(0x0018), secp521r1(0x0019),
103 * x25519(0x001D), x448(0x001E),
104 * ffdhe2048(0x0100), ffdhe3072(0x0101), ffdhe4096(0x0102),
105 * ffdhe6144(0x0103), ffdhe8192(0x0104),
106 * ffdhe_private_use(0x01FC..0x01FF),
107 * ecdhe_private_use(0xFE00..0xFEFF),
108 * (0xFFFF)
109 * } NamedGroup;
110 * struct {
111 * NamedGroup named_group_list<2..2^16-1>;
112 * } NamedGroupList;
113 */
Jerry Yu6b64fe32021-09-01 17:05:13 +0800114#if defined(MBEDTLS_ECDH_C)
115/*
116 * In versions of TLS prior to TLS 1.3, this extension was named
117 * 'elliptic_curves' and only contained elliptic curve groups.
118 */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800119static int ssl_tls13_write_named_group_list_ecdhe( mbedtls_ssl_context *ssl,
120 unsigned char *buf,
121 unsigned char *end,
122 size_t *olen )
Jerry Yu6b64fe32021-09-01 17:05:13 +0800123{
124 unsigned char *p = buf;
Jerry Yu6b64fe32021-09-01 17:05:13 +0800125
126 *olen = 0;
127
Jerry Yu7c522d42021-09-08 17:55:09 +0800128 if( ssl->conf->curve_list == NULL )
129 return( MBEDTLS_ERR_SSL_BAD_CONFIG );
130
Jerry Yu6b64fe32021-09-01 17:05:13 +0800131 for ( const mbedtls_ecp_group_id *grp_id = ssl->conf->curve_list;
132 *grp_id != MBEDTLS_ECP_DP_NONE;
133 grp_id++ )
134 {
135 const mbedtls_ecp_curve_info *info;
136 info = mbedtls_ecp_curve_info_from_grp_id( *grp_id );
137 if( info == NULL )
138 continue;
Jerry Yu7c522d42021-09-08 17:55:09 +0800139
Jerry Yub60e3cf2021-09-08 16:41:02 +0800140 if( !mbedtls_ssl_tls13_named_group_is_ecdhe( info->tls_id ) )
Jerry Yu6b64fe32021-09-01 17:05:13 +0800141 continue;
142
143 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2);
144 MBEDTLS_PUT_UINT16_BE( info->tls_id, p, 0 );
145 p += 2;
146
147 MBEDTLS_SSL_DEBUG_MSG( 3, ( "NamedGroup: %s ( %x )",
148 mbedtls_ecp_curve_info_from_tls_id( info->tls_id )->name,
149 info->tls_id ) );
150 }
151
152 *olen = p - buf;
153
154 return( 0 );
155}
156#else
Jerry Yub60e3cf2021-09-08 16:41:02 +0800157static int ssl_tls13_write_named_group_list_ecdhe( mbedtls_ssl_context *ssl,
158 unsigned char *buf,
159 unsigned char *end,
160 size_t *olen )
Jerry Yu92c6b402021-08-27 16:59:09 +0800161{
162 ((void) ssl);
163 ((void) buf);
164 ((void) end);
Jerry Yu75336352021-09-01 15:59:36 +0800165 *olen = 0;
Jerry Yu6b64fe32021-09-01 17:05:13 +0800166 return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
167}
168#endif /* MBEDTLS_ECDH_C */
169
Jerry Yub60e3cf2021-09-08 16:41:02 +0800170static int ssl_tls13_write_named_group_list_dhe( mbedtls_ssl_context *ssl,
171 unsigned char *buf,
172 unsigned char *end,
173 size_t *olen )
Jerry Yu6b64fe32021-09-01 17:05:13 +0800174{
175 ((void) ssl);
176 ((void) buf);
177 ((void) end);
178 *olen = 0;
179 MBEDTLS_SSL_DEBUG_MSG( 3, ( "write_named_group_dhe is not implemented" ) );
180 return( MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE );
181}
182
Jerry Yu6b64fe32021-09-01 17:05:13 +0800183static int ssl_tls13_write_supported_groups_ext( mbedtls_ssl_context *ssl,
184 unsigned char *buf,
185 unsigned char *end,
186 size_t *olen )
187{
188 unsigned char *p = buf ;
Jerry Yu72fc69b2021-09-10 10:23:24 +0800189 unsigned char *named_group_list_ptr; /* Start of named_group_list */
190 size_t named_group_list_len; /* Length of named_group_list */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800191 size_t output_len = 0;
192 int ret_ecdhe, ret_dhe;
Jerry Yu6b64fe32021-09-01 17:05:13 +0800193
194 *olen = 0;
195
196 if( !mbedtls_ssl_conf_tls13_some_ephemeral_enabled( ssl ) )
197 return( 0 );
198
199 MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, adding supported_groups extension" ) );
200
Jerry Yub60e3cf2021-09-08 16:41:02 +0800201 /* Check if we have space for header and length fields:
202 * - extension_type (2 bytes)
203 * - extension_data_length (2 bytes)
204 * - named_group_list_length (2 bytes)
205 */
Jerry Yu6b64fe32021-09-01 17:05:13 +0800206 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 6 );
207 p += 6;
208
Jerry Yu72fc69b2021-09-10 10:23:24 +0800209 named_group_list_ptr = p;
Jerry Yub60e3cf2021-09-08 16:41:02 +0800210 ret_ecdhe = ssl_tls13_write_named_group_list_ecdhe( ssl, p, end, &output_len );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800211 if( ret_ecdhe != 0 )
212 {
Jerry Yub60e3cf2021-09-08 16:41:02 +0800213 MBEDTLS_SSL_DEBUG_RET( 1, "ssl_tls13_write_named_group_list_ecdhe", ret_ecdhe );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800214 }
Jerry Yub60e3cf2021-09-08 16:41:02 +0800215 p += output_len;
Jerry Yu6b64fe32021-09-01 17:05:13 +0800216
Jerry Yub60e3cf2021-09-08 16:41:02 +0800217 ret_dhe = ssl_tls13_write_named_group_list_dhe( ssl, p, end, &output_len );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800218 if( ret_dhe != 0 )
219 {
Jerry Yub60e3cf2021-09-08 16:41:02 +0800220 MBEDTLS_SSL_DEBUG_RET( 1, "ssl_tls13_write_named_group_list_dhe", ret_dhe );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800221 }
Jerry Yub60e3cf2021-09-08 16:41:02 +0800222 p += output_len;
Jerry Yu6b64fe32021-09-01 17:05:13 +0800223
224 /* Both ECDHE and DHE Fail. */
225 if( ret_ecdhe != 0 && ret_dhe != 0 )
226 {
227 MBEDTLS_SSL_DEBUG_MSG( 1, ( "Both ECDHE and DHE groups are fail. " ) );
228 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
229 }
230
231 /* Length of named_group_list*/
Jerry Yu72fc69b2021-09-10 10:23:24 +0800232 named_group_list_len = p - named_group_list_ptr;
Jerry Yub60e3cf2021-09-08 16:41:02 +0800233 if( named_group_list_len == 0 )
Jerry Yu6b64fe32021-09-01 17:05:13 +0800234 {
Jerry Yu72fc69b2021-09-10 10:23:24 +0800235 MBEDTLS_SSL_DEBUG_MSG( 1, ( "No group Available." ) );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800236 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
237 }
238
239 /* Write extension_type */
240 MBEDTLS_PUT_UINT16_BE( MBEDTLS_TLS_EXT_SUPPORTED_GROUPS, buf, 0 );
241 /* Write extension_data_length */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800242 MBEDTLS_PUT_UINT16_BE( named_group_list_len + 2, buf, 2 );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800243 /* Write length of named_group_list */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800244 MBEDTLS_PUT_UINT16_BE( named_group_list_len, buf, 4 );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800245
Jerry Yub60e3cf2021-09-08 16:41:02 +0800246 MBEDTLS_SSL_DEBUG_BUF( 3, "Supported groups extension", buf + 4, named_group_list_len + 2 );
Jerry Yu6b64fe32021-09-01 17:05:13 +0800247
248 *olen = p - buf;
249
250 ssl->handshake->extensions_present |= MBEDTLS_SSL_EXT_SUPPORTED_GROUPS;
251
Jerry Yub60e3cf2021-09-08 16:41:02 +0800252 return( 0 );
Jerry Yu92c6b402021-08-27 16:59:09 +0800253}
Jerry Yubc20bdd2021-08-24 15:59:48 +0800254
Jerry Yu56fc07f2021-09-01 17:48:49 +0800255/*
256 * Functions for writing key_share extension.
257 */
258#if defined(MBEDTLS_ECDH_C)
Jerry Yu7c522d42021-09-08 17:55:09 +0800259static int ssl_tls13_generate_and_write_ecdh_key_exchange(
Jerry Yub60e3cf2021-09-08 16:41:02 +0800260 mbedtls_ssl_context *ssl,
261 uint16_t named_group,
262 unsigned char *buf,
263 unsigned char *end,
264 size_t *olen )
Jerry Yu92c6b402021-08-27 16:59:09 +0800265{
Jerry Yu56fc07f2021-09-01 17:48:49 +0800266 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Jerry Yu56fc07f2021-09-01 17:48:49 +0800267 const mbedtls_ecp_curve_info *curve_info =
268 mbedtls_ecp_curve_info_from_tls_id( named_group );
269
270 if( curve_info == NULL )
271 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
272
273 MBEDTLS_SSL_DEBUG_MSG( 3, ( "offer curve %s", curve_info->name ) );
274
275 if( ( ret = mbedtls_ecdh_setup( &ssl->handshake->ecdh_ctx,
276 curve_info->grp_id ) ) != 0 )
277 {
278 MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecp_group_load", ret );
279 return( ret );
280 }
281
282 ret = mbedtls_ecdh_tls13_make_params( &ssl->handshake->ecdh_ctx, olen,
283 buf, end - buf,
284 ssl->conf->f_rng, ssl->conf->p_rng );
285 if( ret != 0 )
286 {
287 MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_ecdh_tls13_make_params", ret );
288 return( ret );
289 }
290
291 MBEDTLS_SSL_DEBUG_ECDH( 3, &ssl->handshake->ecdh_ctx,
292 MBEDTLS_DEBUG_ECDH_Q );
Jerry Yu75336352021-09-01 15:59:36 +0800293 return( 0 );
Jerry Yu92c6b402021-08-27 16:59:09 +0800294}
Jerry Yu56fc07f2021-09-01 17:48:49 +0800295#endif /* MBEDTLS_ECDH_C */
296
Jerry Yub60e3cf2021-09-08 16:41:02 +0800297static int ssl_tls13_get_default_group_id( mbedtls_ssl_context *ssl,
298 uint16_t *group_id )
Jerry Yu56fc07f2021-09-01 17:48:49 +0800299{
300 int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
301
302 /* Pick first entry of curve list.
303 *
304 * TODO: When we introduce PQC KEMs, we'll have a NamedGroup
305 * list instead, and can just return its first element.
306 */
307
308 /* Check if ecdhe named groups are available and pick first entry */
309#if defined(MBEDTLS_ECDH_C)
310#if !defined(MBEDTLS_ECP_C)
311 ((void) ssl);
312#endif
313#if defined(MBEDTLS_ECP_C)
314 for ( const mbedtls_ecp_group_id * grp_id = ssl->conf->curve_list;
315 *grp_id != MBEDTLS_ECP_DP_NONE;
316 grp_id++ )
317 {
318 const mbedtls_ecp_curve_info *info;
319 info = mbedtls_ecp_curve_info_from_grp_id( *grp_id );
320#else
321 for ( const mbedtls_ecp_curve_info *info = mbedtls_ecp_curve_list();
322 info->grp_id != MBEDTLS_ECP_DP_NONE;
323 info++ )
324 {
325#endif
Jerry Yub60e3cf2021-09-08 16:41:02 +0800326 if( info != NULL && mbedtls_ssl_tls13_named_group_is_ecdhe( info->tls_id ) )
Jerry Yu56fc07f2021-09-01 17:48:49 +0800327 {
Jerry Yub60e3cf2021-09-08 16:41:02 +0800328 *group_id = info->tls_id;
Jerry Yu56fc07f2021-09-01 17:48:49 +0800329 return( 0 );
330 }
331 }
332#else
333 ((void) ssl);
Jerry Yub60e3cf2021-09-08 16:41:02 +0800334 ((void) group_id);
Jerry Yu56fc07f2021-09-01 17:48:49 +0800335#endif /* MBEDTLS_ECDH_C */
336
337 /*
338 * Add DHE named groups here.
339 * Check if ecdhe named groups are available and pick first entry
340 */
341
342 return( ret );
343}
344
345/*
346 * ssl_tls13_write_key_share_ext
347 *
348 * Structure of key_share extension in ClientHelo:
349 *
350 * struct {
351 * NamedGroup group;
352 * opaque key_exchange<1..2^16-1>;
353 * } KeyShareEntry;
354 * struct {
355 * KeyShareEntry client_shares<0..2^16-1>;
356 * } KeyShareClientHello;
357 */
358static int ssl_tls13_write_key_share_ext( mbedtls_ssl_context *ssl,
359 unsigned char *buf,
360 unsigned char *end,
361 size_t *olen )
362{
363 unsigned char *p = buf;
364 unsigned char *client_shares_ptr; /* Start of client_shares */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800365 size_t client_shares_len; /* Length of client_shares */
Jerry Yu56fc07f2021-09-01 17:48:49 +0800366 uint16_t group_id;
Jerry Yu56fc07f2021-09-01 17:48:49 +0800367 int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
368
369 *olen = 0;
370
371 if( !mbedtls_ssl_conf_tls13_some_ephemeral_enabled( ssl ) )
372 return( 0 );
373
Jerry Yub60e3cf2021-09-08 16:41:02 +0800374 /* Check if we have space for header and length fields:
Jerry Yu56fc07f2021-09-01 17:48:49 +0800375 * - extension_type (2 bytes)
376 * - extension_data_length (2 bytes)
377 * - client_shares_length (2 bytes)
378 */
379 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 6 );
380 p += 6;
381
382 MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello: adding key share extension" ) );
383
384 /* HRR could already have requested something else. */
385 group_id = ssl->handshake->offered_group_id;
Jerry Yub60e3cf2021-09-08 16:41:02 +0800386 if( !mbedtls_ssl_tls13_named_group_is_ecdhe( group_id ) &&
387 !mbedtls_ssl_tls13_named_group_is_dhe( group_id ) )
Jerry Yu56fc07f2021-09-01 17:48:49 +0800388 {
Jerry Yub60e3cf2021-09-08 16:41:02 +0800389 MBEDTLS_SSL_PROC_CHK( ssl_tls13_get_default_group_id( ssl,
Jerry Yu56fc07f2021-09-01 17:48:49 +0800390 &group_id ) );
391 }
392
393 /*
394 * Dispatch to type-specific key generation function.
395 *
396 * So far, we're only supporting ECDHE. With the introduction
397 * of PQC KEMs, we'll want to have multiple branches, one per
398 * type of KEM, and dispatch to the corresponding crypto. And
399 * only one key share entry is allowed.
400 */
401 client_shares_ptr = p;
402#if defined(MBEDTLS_ECDH_C)
Jerry Yub60e3cf2021-09-08 16:41:02 +0800403 if( mbedtls_ssl_tls13_named_group_is_ecdhe( group_id ) )
Jerry Yu56fc07f2021-09-01 17:48:49 +0800404 {
405 /* Pointer of group */
406 unsigned char *group_id_ptr = p;
407 /* Length of key_exchange */
408 size_t key_exchange_len;
409
410 /* Check there is space for header of KeyShareEntry
411 * - group (2 bytes)
412 * - key_exchange_length (2 bytes)
413 */
414 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 4 );
415 p += 4;
Jerry Yub60e3cf2021-09-08 16:41:02 +0800416 ret = ssl_tls13_generate_and_write_ecdh_key_exchange( ssl, group_id,
417 p, end,
418 &key_exchange_len );
Jerry Yu56fc07f2021-09-01 17:48:49 +0800419 p += key_exchange_len;
420 if( ret != 0 )
421 return( ret );
422
423 /* Write group */
424 MBEDTLS_PUT_UINT16_BE( group_id, group_id_ptr, 0 );
425 /* Write key_exchange_length */
426 MBEDTLS_PUT_UINT16_BE( key_exchange_len, group_id_ptr, 2 );
427 }
428 else
429#endif /* MBEDTLS_ECDH_C */
430 if( 0 /* other KEMs? */ )
431 {
432 /* Do something */
433 }
434 else
435 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
436
Jerry Yub60e3cf2021-09-08 16:41:02 +0800437 /* Length of client_shares */
438 client_shares_len = p - client_shares_ptr;
439 if( client_shares_len == 0)
440 {
441 MBEDTLS_SSL_DEBUG_MSG( 1, ( "No key share defined." ) );
442 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
Jerry Yu7c522d42021-09-08 17:55:09 +0800443 }
Jerry Yu56fc07f2021-09-01 17:48:49 +0800444 /* Write extension_type */
445 MBEDTLS_PUT_UINT16_BE( MBEDTLS_TLS_EXT_KEY_SHARE, buf, 0 );
446 /* Write extension_data_length */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800447 MBEDTLS_PUT_UINT16_BE( client_shares_len + 2, buf, 2 );
Jerry Yu56fc07f2021-09-01 17:48:49 +0800448 /* Write client_shares_length */
Jerry Yub60e3cf2021-09-08 16:41:02 +0800449 MBEDTLS_PUT_UINT16_BE( client_shares_len, buf, 4 );
Jerry Yu56fc07f2021-09-01 17:48:49 +0800450
451 /* Update offered_group_id field */
452 ssl->handshake->offered_group_id = group_id;
453
454 /* Output the total length of key_share extension. */
455 *olen = p - buf;
456
457 MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, key_share extension", buf, *olen );
458
459 ssl->handshake->extensions_present |= MBEDTLS_SSL_EXT_KEY_SHARE;
460
461cleanup:
462
463 return( ret );
464}
Jerry Yubc20bdd2021-08-24 15:59:48 +0800465
466#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
467
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800468/* Write cipher_suites
Jerry Yu6a643102021-08-31 14:40:36 +0800469 * CipherSuite cipher_suites<2..2^16-2>;
470 */
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800471static int ssl_tls13_write_client_hello_cipher_suites(
Jerry Yu6a643102021-08-31 14:40:36 +0800472 mbedtls_ssl_context *ssl,
473 unsigned char *buf,
474 unsigned char *end,
475 size_t *olen )
476{
Jerry Yufec982e2021-09-07 17:26:06 +0800477 unsigned char *p = buf;
Jerry Yu0c63af62021-09-02 12:59:12 +0800478 const int *ciphersuite_list;
Jerry Yubbe09522021-09-06 21:17:54 +0800479 unsigned char *cipher_suites_ptr; /* Start of the cipher_suites list */
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800480 size_t cipher_suites_len;
Jerry Yu92c6b402021-08-27 16:59:09 +0800481
Jerry Yu6a643102021-08-31 14:40:36 +0800482 *olen = 0 ;
483
484 /*
485 * Ciphersuite list
486 *
487 * This is a list of the symmetric cipher options supported by
488 * the client, specifically the record protection algorithm
489 * ( including secret key length ) and a hash to be used with
490 * HKDF, in descending order of client preference.
491 */
Jerry Yu0c63af62021-09-02 12:59:12 +0800492 ciphersuite_list = ssl->conf->ciphersuite_list;
Jerry Yu6a643102021-08-31 14:40:36 +0800493
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800494 /* Check there is space for the cipher suite list length (2 bytes). */
Jerry Yu4e388282021-09-06 21:28:08 +0800495 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
496 p += 2;
Jerry Yu6a643102021-08-31 14:40:36 +0800497
Jerry Yu0c63af62021-09-02 12:59:12 +0800498 /* Write cipher_suites */
Jerry Yu4e388282021-09-06 21:28:08 +0800499 cipher_suites_ptr = p;
Jerry Yu0c63af62021-09-02 12:59:12 +0800500 for ( size_t i = 0; ciphersuite_list[i] != 0; i++ )
Jerry Yu6a643102021-08-31 14:40:36 +0800501 {
Jerry Yu0c63af62021-09-02 12:59:12 +0800502 int cipher_suite = ciphersuite_list[i];
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800503 const mbedtls_ssl_ciphersuite_t *ciphersuite_info;
Jerry Yu6a643102021-08-31 14:40:36 +0800504
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800505 ciphersuite_info = mbedtls_ssl_ciphersuite_from_id( cipher_suite );
Jerry Yu6a643102021-08-31 14:40:36 +0800506 if( ciphersuite_info == NULL )
507 continue;
Jerry Yudbfb7bd2021-09-04 09:58:58 +0800508 if( !( MBEDTLS_SSL_MINOR_VERSION_4 >= ciphersuite_info->min_minor_ver &&
509 MBEDTLS_SSL_MINOR_VERSION_4 <= ciphersuite_info->max_minor_ver ) )
Jerry Yu6a643102021-08-31 14:40:36 +0800510 continue;
511
512 MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, add ciphersuite: %04x, %s",
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800513 (unsigned int) cipher_suite,
Jerry Yu6a643102021-08-31 14:40:36 +0800514 ciphersuite_info->name ) );
515
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800516 /* Check there is space for the cipher suite identifier (2 bytes). */
Jerry Yubbe09522021-09-06 21:17:54 +0800517 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
518 MBEDTLS_PUT_UINT16_BE( cipher_suite, p, 0 );
519 p += 2;
Jerry Yu6a643102021-08-31 14:40:36 +0800520 }
521
Jerry Yu0c63af62021-09-02 12:59:12 +0800522 /* Write the cipher_suites length in number of bytes */
Jerry Yubbe09522021-09-06 21:17:54 +0800523 cipher_suites_len = p - cipher_suites_ptr;
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800524 MBEDTLS_PUT_UINT16_BE( cipher_suites_len, buf, 0 );
Jerry Yu6a643102021-08-31 14:40:36 +0800525 MBEDTLS_SSL_DEBUG_MSG( 3,
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800526 ( "client hello, got %" MBEDTLS_PRINTF_SIZET " cipher suites",
527 cipher_suites_len/2 ) );
Jerry Yu6a643102021-08-31 14:40:36 +0800528
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800529 /* Output the total length of cipher_suites field. */
Jerry Yubbe09522021-09-06 21:17:54 +0800530 *olen = p - buf;
Jerry Yuf171e832021-08-31 18:31:09 +0800531
Jerry Yu6a643102021-08-31 14:40:36 +0800532 return( 0 );
533}
534
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800535/*
536 * Structure of ClientHello message:
537 *
538 * struct {
539 * ProtocolVersion legacy_version = 0x0303; // TLS v1.2
540 * Random random;
541 * opaque legacy_session_id<0..32>;
542 * CipherSuite cipher_suites<2..2^16-2>;
543 * opaque legacy_compression_methods<1..2^8-1>;
544 * Extension extensions<8..2^16-1>;
545 * } ClientHello;
546 */
Jerry Yu08906d02021-08-31 11:05:27 +0800547static int ssl_tls13_write_client_hello_body( mbedtls_ssl_context *ssl,
Jerry Yueecfbf02021-08-30 18:32:07 +0800548 unsigned char *buf,
Jerry Yuef387d72021-09-02 13:59:41 +0800549 unsigned char *end,
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800550 size_t *olen )
Jerry Yu65dd2cc2021-08-18 16:38:40 +0800551{
Jerry Yubc20bdd2021-08-24 15:59:48 +0800552
Jerry Yubc20bdd2021-08-24 15:59:48 +0800553 int ret;
Jerry Yu8c02bb42021-09-03 21:09:22 +0800554 unsigned char *extensions_len_ptr; /* Pointer to extensions length */
Jerry Yu790656a2021-09-01 15:51:48 +0800555 size_t output_len; /* Length of buffer used by function */
556 size_t extensions_len; /* Length of the list of extensions*/
Jerry Yubc20bdd2021-08-24 15:59:48 +0800557
Jerry Yubc20bdd2021-08-24 15:59:48 +0800558 /* Buffer management */
Jerry Yubbe09522021-09-06 21:17:54 +0800559 unsigned char *p = buf;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800560
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800561 *olen = 0;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800562
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800563 /* No validation needed here. It has been done by ssl_conf_check() */
Jerry Yubc20bdd2021-08-24 15:59:48 +0800564 ssl->major_ver = ssl->conf->min_major_ver;
565 ssl->minor_ver = ssl->conf->min_minor_ver;
566
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800567 /*
568 * Write legacy_version
Jerry Yu6a643102021-08-31 14:40:36 +0800569 * ProtocolVersion legacy_version = 0x0303; // TLS v1.2
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800570 *
571 * For TLS 1.3 we use the legacy version number {0x03, 0x03}
Jerry Yubc20bdd2021-08-24 15:59:48 +0800572 * instead of the true version number.
Jerry Yubc20bdd2021-08-24 15:59:48 +0800573 */
Jerry Yufec982e2021-09-07 17:26:06 +0800574 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
Jerry Yubbe09522021-09-06 21:17:54 +0800575 MBEDTLS_PUT_UINT16_BE( 0x0303, p, 0 );
Jerry Yufec982e2021-09-07 17:26:06 +0800576 p += 2;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800577
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800578 /* Write the random bytes ( random ).*/
Jerry Yubbe09522021-09-06 21:17:54 +0800579 MBEDTLS_SSL_CHK_BUF_PTR( p, end, CLIENT_HELLO_RANDOM_LEN );
580 memcpy( p, ssl->handshake->randbytes, CLIENT_HELLO_RANDOM_LEN );
Jerry Yue885b762021-08-26 17:32:34 +0800581 MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, random bytes",
Jerry Yubbe09522021-09-06 21:17:54 +0800582 p, CLIENT_HELLO_RANDOM_LEN );
583 p += CLIENT_HELLO_RANDOM_LEN;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800584
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800585 /*
586 * Write legacy_session_id
587 *
588 * Versions of TLS before TLS 1.3 supported a "session resumption" feature
589 * which has been merged with pre-shared keys in this version. A client
590 * which has a cached session ID set by a pre-TLS 1.3 server SHOULD set
591 * this field to that value. In compatibility mode, this field MUST be
592 * non-empty, so a client not offering a pre-TLS 1.3 session MUST generate
593 * a new 32-byte value. This value need not be random but SHOULD be
594 * unpredictable to avoid implementations fixating on a specific value
595 * ( also known as ossification ). Otherwise, it MUST be set as a zero-length
596 * vector ( i.e., a zero-valued single byte length field ).
Jerry Yubc20bdd2021-08-24 15:59:48 +0800597 */
Jerry Yubbe09522021-09-06 21:17:54 +0800598 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 1 );
599 *p++ = 0; /* session id length set to zero */
Jerry Yubc20bdd2021-08-24 15:59:48 +0800600
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800601 /* Write cipher_suites */
Jerry Yubbe09522021-09-06 21:17:54 +0800602 ret = ssl_tls13_write_client_hello_cipher_suites( ssl, p, end, &output_len );
Jerry Yudbfb7bd2021-09-04 09:58:58 +0800603 if( ret != 0 )
Jerry Yu6a643102021-08-31 14:40:36 +0800604 return( ret );
Jerry Yubbe09522021-09-06 21:17:54 +0800605 p += output_len;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800606
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800607 /* Write legacy_compression_methods
608 *
609 * For every TLS 1.3 ClientHello, this vector MUST contain exactly
Jerry Yubc20bdd2021-08-24 15:59:48 +0800610 * one byte set to zero, which corresponds to the 'null' compression
611 * method in prior versions of TLS.
Jerry Yubc20bdd2021-08-24 15:59:48 +0800612 */
Jerry Yubbe09522021-09-06 21:17:54 +0800613 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
614 *p++ = 1;
615 *p++ = MBEDTLS_SSL_COMPRESS_NULL;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800616
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800617 /* Write extensions */
618
619 /* Keeping track of the included extensions */
620 ssl->handshake->extensions_present = MBEDTLS_SSL_EXT_NONE;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800621
622 /* First write extensions, then the total length */
Jerry Yubbe09522021-09-06 21:17:54 +0800623 MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2 );
624 extensions_len_ptr = p;
625 p += 2;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800626
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800627 /* Write supported_versions extension
Jerry Yubc20bdd2021-08-24 15:59:48 +0800628 *
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800629 * Supported Versions Extension is mandatory with TLS 1.3.
Jerry Yubc20bdd2021-08-24 15:59:48 +0800630 */
Jerry Yubbe09522021-09-06 21:17:54 +0800631 ret = ssl_tls13_write_supported_versions_ext( ssl, p, end, &output_len );
Jerry Yu92c6b402021-08-27 16:59:09 +0800632 if( ret != 0 )
633 return( ret );
Jerry Yubbe09522021-09-06 21:17:54 +0800634 p += output_len;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800635
636#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800637 /* Write supported_groups extension
638 *
639 * It is REQUIRED for ECDHE cipher_suites.
Jerry Yubc20bdd2021-08-24 15:59:48 +0800640 */
Jerry Yubbe09522021-09-06 21:17:54 +0800641 ret = ssl_tls13_write_supported_groups_ext( ssl, p, end, &output_len );
Jerry Yubc20bdd2021-08-24 15:59:48 +0800642 if( ret != 0 )
643 return( ret );
Jerry Yubbe09522021-09-06 21:17:54 +0800644 p += output_len;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800645
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800646 /* Write key_share extension
647 *
648 * We need to send the key shares under three conditions:
Jerry Yu159c5a02021-08-31 12:51:25 +0800649 * 1) A certificate-based ciphersuite is being offered. In this case
650 * supported_groups and supported_signature extensions have been
651 * successfully added.
652 * 2) A PSK-based ciphersuite with ECDHE is offered. In this case the
Jerry Yubc20bdd2021-08-24 15:59:48 +0800653 * psk_key_exchange_modes has been added as the last extension.
Jerry Yu159c5a02021-08-31 12:51:25 +0800654 * 3) Or, in case all ciphers are supported ( which includes #1 and #2
655 * from above )
Jerry Yubc20bdd2021-08-24 15:59:48 +0800656 */
Jerry Yu56fc07f2021-09-01 17:48:49 +0800657 ret = ssl_tls13_write_key_share_ext( ssl, p, end, &output_len );
Jerry Yubc20bdd2021-08-24 15:59:48 +0800658 if( ret != 0 )
659 return( ret );
Jerry Yubbe09522021-09-06 21:17:54 +0800660 p += output_len;
Jerry Yu6a643102021-08-31 14:40:36 +0800661
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800662 /* Write signature_algorithms extension
663 *
664 * It is REQUIRED for certificate authenticated cipher_suites.
665 */
Jerry Yubbe09522021-09-06 21:17:54 +0800666 ret = mbedtls_ssl_tls13_write_sig_alg_ext( ssl, p, end, &output_len );
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800667 if( ret != 0 )
668 return( ret );
Jerry Yubbe09522021-09-06 21:17:54 +0800669 p += output_len;
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800670
Jerry Yubc20bdd2021-08-24 15:59:48 +0800671#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
672
673 /* Add more extensions here */
674
Jerry Yu1bc2c1f2021-09-01 12:57:29 +0800675 /* Write the length of the list of extensions. */
Jerry Yubbe09522021-09-06 21:17:54 +0800676 extensions_len = p - extensions_len_ptr - 2;
Jerry Yu790656a2021-09-01 15:51:48 +0800677 MBEDTLS_PUT_UINT16_BE( extensions_len, extensions_len_ptr, 0 );
Jerry Yubc20bdd2021-08-24 15:59:48 +0800678 MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello, total extension length: %" MBEDTLS_PRINTF_SIZET ,
Jerry Yu790656a2021-09-01 15:51:48 +0800679 extensions_len ) );
680 MBEDTLS_SSL_DEBUG_BUF( 3, "client hello extensions", extensions_len_ptr, extensions_len );
Jerry Yubc20bdd2021-08-24 15:59:48 +0800681
Jerry Yubbe09522021-09-06 21:17:54 +0800682 *olen = p - buf;
Jerry Yubc20bdd2021-08-24 15:59:48 +0800683 return( 0 );
684}
685
Jerry Yu335aca92021-09-12 20:18:56 +0800686static int ssl_tls13_finalize_client_hello( mbedtls_ssl_context *ssl )
Jerry Yubc20bdd2021-08-24 15:59:48 +0800687{
Jerry Yu92c6b402021-08-27 16:59:09 +0800688 mbedtls_ssl_handshake_set_state( ssl, MBEDTLS_SSL_SERVER_HELLO );
689 return( 0 );
690}
Jerry Yuef6b36b2021-08-24 16:29:02 +0800691
Jerry Yu92c6b402021-08-27 16:59:09 +0800692static int ssl_tls13_prepare_client_hello( mbedtls_ssl_context *ssl )
693{
694 int ret;
Jerry Yuef6b36b2021-08-24 16:29:02 +0800695
Jerry Yu92c6b402021-08-27 16:59:09 +0800696 if( ssl->conf->f_rng == NULL )
697 {
698 MBEDTLS_SSL_DEBUG_MSG( 1, ( "no RNG provided" ) );
699 return( MBEDTLS_ERR_SSL_NO_RNG );
700 }
Jerry Yuef6b36b2021-08-24 16:29:02 +0800701
Jerry Yu92c6b402021-08-27 16:59:09 +0800702 if( ( ret = ssl->conf->f_rng( ssl->conf->p_rng,
703 ssl->handshake->randbytes,
Jerry Yu08906d02021-08-31 11:05:27 +0800704 CLIENT_HELLO_RANDOM_LEN ) ) != 0 )
Jerry Yu92c6b402021-08-27 16:59:09 +0800705 {
Jerry Yu8c02bb42021-09-03 21:09:22 +0800706 MBEDTLS_SSL_DEBUG_RET( 1, "f_rng", ret );
Jerry Yu92c6b402021-08-27 16:59:09 +0800707 return( ret );
708 }
Jerry Yu6f13f642021-08-26 17:18:15 +0800709
710 return( 0 );
Jerry Yubc20bdd2021-08-24 15:59:48 +0800711}
712
Jerry Yu92c6b402021-08-27 16:59:09 +0800713/*
Jerry Yu159c5a02021-08-31 12:51:25 +0800714 * Write ClientHello handshake message.
Jerry Yu92c6b402021-08-27 16:59:09 +0800715 */
716static int ssl_tls13_write_client_hello( mbedtls_ssl_context *ssl )
Jerry Yubc20bdd2021-08-24 15:59:48 +0800717{
Jerry Yu92c6b402021-08-27 16:59:09 +0800718 int ret = 0;
719 unsigned char *buf;
720 size_t buf_len, msg_len;
721
722 MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> write client hello" ) );
723
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800724 MBEDTLS_SSL_PROC_CHK( ssl_tls13_prepare_client_hello( ssl ) );
Jerry Yu92c6b402021-08-27 16:59:09 +0800725
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800726 MBEDTLS_SSL_PROC_CHK( mbedtls_ssl_tls13_start_handshake_msg(
727 ssl, MBEDTLS_SSL_HS_CLIENT_HELLO,
728 &buf, &buf_len ) );
Jerry Yu92c6b402021-08-27 16:59:09 +0800729
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800730 MBEDTLS_SSL_PROC_CHK( ssl_tls13_write_client_hello_body( ssl, buf,
Jerry Yuef387d72021-09-02 13:59:41 +0800731 buf + buf_len,
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800732 &msg_len ) );
Jerry Yu92c6b402021-08-27 16:59:09 +0800733
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800734 mbedtls_ssl_tls13_add_hs_hdr_to_checksum( ssl,
735 MBEDTLS_SSL_HS_CLIENT_HELLO,
Jerry Yu0c63af62021-09-02 12:59:12 +0800736 msg_len );
737 ssl->handshake->update_checksum( ssl, buf, msg_len );
Jerry Yu92c6b402021-08-27 16:59:09 +0800738
Jerry Yu2c0fbf32021-09-02 13:53:46 +0800739 MBEDTLS_SSL_PROC_CHK( ssl_tls13_finalize_client_hello( ssl ) );
740 MBEDTLS_SSL_PROC_CHK( mbedtls_ssl_tls13_finish_handshake_msg( ssl,
741 buf_len,
742 msg_len ) );
Jerry Yu92c6b402021-08-27 16:59:09 +0800743
744cleanup:
745
746 MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= write client hello" ) );
747 return ret;
Jerry Yu65dd2cc2021-08-18 16:38:40 +0800748}
749
Jerry Yu92c6b402021-08-27 16:59:09 +0800750int mbedtls_ssl_tls13_handshake_client_step( mbedtls_ssl_context *ssl )
Jerry Yubc20bdd2021-08-24 15:59:48 +0800751{
Jerry Yu92c6b402021-08-27 16:59:09 +0800752 int ret = 0;
Jerry Yuc8a392c2021-08-18 16:46:28 +0800753
Jerry Yu92c6b402021-08-27 16:59:09 +0800754 MBEDTLS_SSL_DEBUG_MSG( 2, ( "client state: %d", ssl->state ) );
755
756 switch( ssl->state )
757 {
758 /*
Jerry Yu0c63af62021-09-02 12:59:12 +0800759 * ssl->state is initialized as HELLO_REQUEST. It is the same
760 * as CLIENT_HELLO state.
Jerry Yu92c6b402021-08-27 16:59:09 +0800761 */
762 case MBEDTLS_SSL_HELLO_REQUEST:
763 case MBEDTLS_SSL_CLIENT_HELLO:
764 ret = ssl_tls13_write_client_hello( ssl );
765 break;
766
767 case MBEDTLS_SSL_SERVER_HELLO:
768 // Stop here : we haven't finished whole flow
769 ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
770 mbedtls_ssl_handshake_set_state( ssl, MBEDTLS_SSL_ENCRYPTED_EXTENSIONS );
771 break;
772
773 default:
774 MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid state %d", ssl->state ) );
775 return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
776 }
777
778 return( ret );
779}
Jerry Yu65dd2cc2021-08-18 16:38:40 +0800780
Jerry Yu3cc4c2a2021-08-06 16:29:08 +0800781#endif /* MBEDTLS_SSL_CLI_C */
782
783#endif /* MBEDTLS_SSL_PROTO_TLS1_3_EXPERIMENTAL */