blob: 5c926743ffcaf91a7bb01eaec356f8bebb1fdba0 [file] [log] [blame]
Jerry Yu3cc4c2a2021-08-06 16:29:08 +08001/*
Jerry Yub9930e72021-08-06 17:11:51 +08002 * TLS 1.3 server-side functions
Jerry Yu3cc4c2a2021-08-06 16:29:08 +08003 *
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
20#include "common.h"
21
Jerry Yufb4b6472022-01-27 15:03:26 +080022#if defined(MBEDTLS_SSL_SRV_C) && defined(MBEDTLS_SSL_PROTO_TLS1_3)
Jerry Yu3cc4c2a2021-08-06 16:29:08 +080023
Jerry Yu687101b2021-09-14 16:03:56 +080024#include "mbedtls/debug.h"
25
Jerry Yu3cc4c2a2021-08-06 16:29:08 +080026#include "ssl_misc.h"
XiaokangQian7807f9f2022-02-15 10:04:37 +000027#include "ssl_tls13_keys.h"
Gilles Peskine923d5c92021-12-15 12:56:54 +010028#include "ssl_debug_helpers.h"
XiaokangQian7807f9f2022-02-15 10:04:37 +000029#include <string.h>
30#if defined(MBEDTLS_ECP_C)
31#include "mbedtls/ecp.h"
XiaokangQian7807f9f2022-02-15 10:04:37 +000032#endif /* MBEDTLS_ECP_C */
Jerry Yu3cc4c2a2021-08-06 16:29:08 +080033
XiaokangQiana9c58412022-02-17 09:41:26 +000034#if defined(MBEDTLS_PLATFORM_C)
35#include "mbedtls/platform.h"
36#else
37#include <stdlib.h>
38#define mbedtls_calloc calloc
39#define mbedtls_free free
40#endif /* MBEDTLS_PLATFORM_C */
XiaokangQian7807f9f2022-02-15 10:04:37 +000041
42/* From RFC 8446:
43 * struct {
XiaokangQiancfd925f2022-04-14 07:10:37 +000044 * ProtocolVersion versions<2..254>;
XiaokangQian7807f9f2022-02-15 10:04:37 +000045 * } SupportedVersions;
46 */
47static int ssl_tls13_parse_supported_versions_ext( mbedtls_ssl_context *ssl,
48 const unsigned char *buf,
49 const unsigned char *end )
50{
XiaokangQian7807f9f2022-02-15 10:04:37 +000051 const unsigned char *p = buf;
XiaokangQian8f9dfe42022-04-15 02:52:39 +000052 size_t versions_len;
XiaokangQian4080a7f2022-04-11 09:55:18 +000053 const unsigned char *versions_end;
XiaokangQian8f9dfe42022-04-15 02:52:39 +000054 int major_ver, minor_ver;
55 int tls13_supported = 0;
XiaokangQian7807f9f2022-02-15 10:04:37 +000056
57 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, 1 );
XiaokangQian4080a7f2022-04-11 09:55:18 +000058 versions_len = p[0];
XiaokangQian7807f9f2022-02-15 10:04:37 +000059 p += 1;
60
XiaokangQian4080a7f2022-04-11 09:55:18 +000061 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, versions_len );
XiaokangQian4080a7f2022-04-11 09:55:18 +000062 versions_end = p + versions_len;
63 while( p < versions_end )
XiaokangQian7807f9f2022-02-15 10:04:37 +000064 {
XiaokangQiancfd925f2022-04-14 07:10:37 +000065 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, versions_end, 2 );
XiaokangQian7807f9f2022-02-15 10:04:37 +000066 mbedtls_ssl_read_version( &major_ver, &minor_ver, ssl->conf->transport, p );
XiaokangQianb67384d2022-04-19 00:02:38 +000067 p += 2;
XiaokangQian7807f9f2022-02-15 10:04:37 +000068
69 /* In this implementation we only support TLS 1.3 and DTLS 1.3. */
70 if( major_ver == MBEDTLS_SSL_MAJOR_VERSION_3 &&
71 minor_ver == MBEDTLS_SSL_MINOR_VERSION_4 )
72 {
73 tls13_supported = 1;
74 break;
75 }
XiaokangQian7807f9f2022-02-15 10:04:37 +000076 }
77
XiaokangQianb67384d2022-04-19 00:02:38 +000078 if( !tls13_supported )
XiaokangQian7807f9f2022-02-15 10:04:37 +000079 {
XiaokangQian7807f9f2022-02-15 10:04:37 +000080 MBEDTLS_SSL_DEBUG_MSG( 1, ( "TLS 1.3 is not supported by the client" ) );
81
82 MBEDTLS_SSL_PEND_FATAL_ALERT( MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION,
83 MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION );
84 return( MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION );
85 }
86
87 MBEDTLS_SSL_DEBUG_MSG( 1, ( "Negotiated version. Supported is [%d:%d]",
88 major_ver, minor_ver ) );
89
90 ssl->major_ver = major_ver;
91 ssl->minor_ver = minor_ver;
XiaokangQian7807f9f2022-02-15 10:04:37 +000092 return( 0 );
93}
94
XiaokangQian8f9dfe42022-04-15 02:52:39 +000095#if defined(MBEDTLS_ECDH_C)
XiaokangQian7807f9f2022-02-15 10:04:37 +000096/* This function parses the TLS 1.3 supported_groups extension and
97 * stores the received groups in ssl->handshake->curves.
98 *
99 * From RFC 8446:
100 * enum {
101 * ... (0xFFFF)
102 * } NamedGroup;
103 * struct {
104 * NamedGroup named_group_list<2..2^16-1>;
105 * } NamedGroupList;
106 */
XiaokangQiancfd925f2022-04-14 07:10:37 +0000107static int ssl_tls13_parse_supported_groups_ext(
XiaokangQian7807f9f2022-02-15 10:04:37 +0000108 mbedtls_ssl_context *ssl,
109 const unsigned char *buf, const unsigned char *end )
110{
XiaokangQian7807f9f2022-02-15 10:04:37 +0000111 const unsigned char *p = buf;
XiaokangQian84823772022-04-19 07:57:30 +0000112 size_t named_group_list_len;
113 const mbedtls_ecp_curve_info *curve_info;
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000114 const unsigned char *named_group_list_end;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000115
116 MBEDTLS_SSL_DEBUG_BUF( 3, "supported_groups extension", p, end - buf );
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000117 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, 2 );
XiaokangQian4080a7f2022-04-11 09:55:18 +0000118 named_group_list_len = MBEDTLS_GET_UINT16_BE( p, 0 );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000119 p += 2;
XiaokangQian4080a7f2022-04-11 09:55:18 +0000120 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, named_group_list_len );
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000121 named_group_list_end = p + named_group_list_len;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000122
XiaokangQian84823772022-04-19 07:57:30 +0000123 while ( p < named_group_list_end )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000124 {
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000125 uint16_t tls_grp_id;
126 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, named_group_list_end, 2 );
127 tls_grp_id = MBEDTLS_GET_UINT16_BE( p, 0 );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000128 curve_info = mbedtls_ecp_curve_info_from_tls_id( tls_grp_id );
129
XiaokangQian7807f9f2022-02-15 10:04:37 +0000130 if( curve_info != NULL )
131 {
XiaokangQian84823772022-04-19 07:57:30 +0000132
XiaokangQian7807f9f2022-02-15 10:04:37 +0000133 MBEDTLS_SSL_DEBUG_MSG( 4, ( "supported curve: %s", curve_info->name ) );
XiaokangQian84823772022-04-19 07:57:30 +0000134 /*
135 * Here we only update offered_group_id field with the first
136 * offered group
137 */
138 ssl->handshake->offered_group_id = tls_grp_id;
139 break;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000140 }
141
142 p += 2;
143 }
144
145 return( 0 );
146
147}
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000148#endif /* MBEDTLS_ECDH_C */
XiaokangQian7807f9f2022-02-15 10:04:37 +0000149
XiaokangQian88408882022-04-02 10:15:03 +0000150#if defined(MBEDTLS_ECDH_C)
XiaokangQian7807f9f2022-02-15 10:04:37 +0000151/*
152 * ssl_tls13_parse_key_shares_ext() verifies whether the information in the
153 * extension is correct and stores the provided key shares. Whether this is an
154 * acceptable key share depends on the selected ciphersuite.
155 *
156 * Possible return values are:
157 * - 0: Successful processing of the client provided key share extension.
158 * - MBEDTLS_ERR_SSL_HRR_REQUIRED: The key share provided by the client
159 * does not match a group supported by the server. A HelloRetryRequest will
160 * be needed.
161 * - Another negative return value for fatal errors.
162*/
163
164static int ssl_tls13_parse_key_shares_ext( mbedtls_ssl_context *ssl,
165 const unsigned char *buf,
166 const unsigned char *end )
167{
XiaokangQianb67384d2022-04-19 00:02:38 +0000168 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000169 unsigned char const *p = buf;
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000170 unsigned char const *client_shares_end;
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000171 size_t client_shares_len, key_exchange_len;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000172 int match_found = 0;
173
174 /* From RFC 8446:
175 *
176 * struct {
177 * KeyShareEntry client_shares<0..2^16-1>;
178 * } KeyShareClientHello;
179 *
180 */
181
XiaokangQian7807f9f2022-02-15 10:04:37 +0000182 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, 2 );
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000183 client_shares_len = MBEDTLS_GET_UINT16_BE( p, 0 );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000184 p += 2;
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000185 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, client_shares_len );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000186
187 ssl->handshake->offered_group_id = 0;
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000188 client_shares_end = p + client_shares_len;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000189
190 /* We try to find a suitable key share entry and copy it to the
191 * handshake context. Later, we have to find out whether we can do
192 * something with the provided key share or whether we have to
XiaokangQianc5763b52022-04-02 03:34:37 +0000193 * dismiss it and send a HelloRetryRequest message.
194 */
XiaokangQian7807f9f2022-02-15 10:04:37 +0000195
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000196 for( ; p < client_shares_end; p += key_exchange_len )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000197 {
XiaokangQian9b5d04b2022-04-10 10:20:43 +0000198 uint16_t group;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000199
200 /*
201 * struct {
202 * NamedGroup group;
203 * opaque key_exchange<1..2^16-1>;
204 * } KeyShareEntry;
205 */
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000206 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, client_shares_end, 4 );
XiaokangQian9b5d04b2022-04-10 10:20:43 +0000207 group = MBEDTLS_GET_UINT16_BE( p, 0 );
208 p += 2;
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000209 key_exchange_len = MBEDTLS_GET_UINT16_BE( p, 0 );
XiaokangQian9b5d04b2022-04-10 10:20:43 +0000210 p += 2;
XiaokangQianb67384d2022-04-19 00:02:38 +0000211 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, client_shares_end, key_exchange_len );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000212
213 /* Continue parsing even if we have already found a match,
XiaokangQianc5763b52022-04-02 03:34:37 +0000214 * for input validation purposes.
215 */
XiaokangQian7807f9f2022-02-15 10:04:37 +0000216 if( match_found == 1 )
217 continue;
218
219 /*
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000220 * For now, we only support ECDHE groups.
XiaokangQian7807f9f2022-02-15 10:04:37 +0000221 */
XiaokangQian9b5d04b2022-04-10 10:20:43 +0000222 if( mbedtls_ssl_tls13_named_group_is_ecdhe( group ) )
223 {
224 const mbedtls_ecp_curve_info *curve_info =
225 mbedtls_ecp_curve_info_from_tls_id( group );
226 if( curve_info == NULL )
227 {
228 MBEDTLS_SSL_DEBUG_MSG( 1, ( "Invalid TLS curve group id" ) );
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000229 continue;
XiaokangQian9b5d04b2022-04-10 10:20:43 +0000230 }
XiaokangQian7807f9f2022-02-15 10:04:37 +0000231
XiaokangQian9b5d04b2022-04-10 10:20:43 +0000232 match_found = 1;
XiaokangQian9b5d04b2022-04-10 10:20:43 +0000233 MBEDTLS_SSL_DEBUG_MSG( 2, ( "ECDH curve: %s", curve_info->name ) );
XiaokangQian3f84d5d2022-04-19 06:36:17 +0000234 ret = psa_crypto_init();
235 if( ret != PSA_SUCCESS )
236 {
237 MBEDTLS_SSL_DEBUG_RET( 1, "psa_crypto_init()", ret );
238 return( ret );
239 }
XiaokangQianb67384d2022-04-19 00:02:38 +0000240 ret = mbedtls_ssl_tls13_read_public_ecdhe_share( ssl, p - 2, end - p + 2 );
XiaokangQian9b5d04b2022-04-10 10:20:43 +0000241 if( ret != 0 )
242 return( ret );
243 }
244 else
XiaokangQian7807f9f2022-02-15 10:04:37 +0000245 {
246 MBEDTLS_SSL_DEBUG_MSG( 4, ( "Unrecognized NamedGroup %u",
XiaokangQian9b5d04b2022-04-10 10:20:43 +0000247 (unsigned) group ) );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000248 continue;
249 }
250
XiaokangQian9b5d04b2022-04-10 10:20:43 +0000251 ssl->handshake->offered_group_id = group;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000252 }
253
254 if( match_found == 0 )
255 {
256 MBEDTLS_SSL_DEBUG_MSG( 1, ( "no matching key share" ) );
257 return( MBEDTLS_ERR_SSL_HRR_REQUIRED );
258 }
259 return( 0 );
260}
XiaokangQian88408882022-04-02 10:15:03 +0000261#endif /* MBEDTLS_ECDH_C */
XiaokangQian7807f9f2022-02-15 10:04:37 +0000262
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000263#if defined(MBEDTLS_DEBUG_C)
XiaokangQian4080a7f2022-04-11 09:55:18 +0000264static void ssl_tls13_debug_print_client_hello_exts( mbedtls_ssl_context *ssl )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000265{
XiaokangQian3207a322022-02-23 03:15:27 +0000266 ((void) ssl);
267
XiaokangQian7807f9f2022-02-15 10:04:37 +0000268 MBEDTLS_SSL_DEBUG_MSG( 3, ( "Supported Extensions:" ) );
XiaokangQianb67384d2022-04-19 00:02:38 +0000269 MBEDTLS_SSL_DEBUG_MSG( 3,
270 ( "- KEY_SHARE_EXTENSION ( %s )",
271 ( ( ssl->handshake->extensions_present
272 & MBEDTLS_SSL_EXT_KEY_SHARE ) > 0 ) ? "TRUE" : "FALSE" ) );
273 MBEDTLS_SSL_DEBUG_MSG( 3,
274 ( "- PSK_KEY_EXCHANGE_MODES_EXTENSION ( %s )",
275 ( ( ssl->handshake->extensions_present
276 & MBEDTLS_SSL_EXT_PSK_KEY_EXCHANGE_MODES ) > 0 ) ?
277 "TRUE" : "FALSE" ) );
278 MBEDTLS_SSL_DEBUG_MSG( 3,
279 ( "- PRE_SHARED_KEY_EXTENSION ( %s )",
280 ( ( ssl->handshake->extensions_present
281 & MBEDTLS_SSL_EXT_PRE_SHARED_KEY ) > 0 ) ? "TRUE" : "FALSE" ) );
282 MBEDTLS_SSL_DEBUG_MSG( 3,
283 ( "- SIGNATURE_ALGORITHM_EXTENSION ( %s )",
284 ( ( ssl->handshake->extensions_present
285 & MBEDTLS_SSL_EXT_SIG_ALG ) > 0 ) ? "TRUE" : "FALSE" ) );
286 MBEDTLS_SSL_DEBUG_MSG( 3,
287 ( "- SUPPORTED_GROUPS_EXTENSION ( %s )",
288 ( ( ssl->handshake->extensions_present
289 & MBEDTLS_SSL_EXT_SUPPORTED_GROUPS ) >0 ) ?
290 "TRUE" : "FALSE" ) );
291 MBEDTLS_SSL_DEBUG_MSG( 3,
292 ( "- SUPPORTED_VERSION_EXTENSION ( %s )",
293 ( ( ssl->handshake->extensions_present
294 & MBEDTLS_SSL_EXT_SUPPORTED_VERSIONS ) > 0 ) ?
295 "TRUE" : "FALSE" ) );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000296#if defined ( MBEDTLS_SSL_SERVER_NAME_INDICATION )
XiaokangQianb67384d2022-04-19 00:02:38 +0000297 MBEDTLS_SSL_DEBUG_MSG( 3,
298 ( "- SERVERNAME_EXTENSION ( %s )",
299 ( ( ssl->handshake->extensions_present
300 & MBEDTLS_SSL_EXT_SERVERNAME ) > 0 ) ?
301 "TRUE" : "FALSE" ) );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000302#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
XiaokangQian7807f9f2022-02-15 10:04:37 +0000303}
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000304#endif /* MBEDTLS_DEBUG_C */
XiaokangQian7807f9f2022-02-15 10:04:37 +0000305
XiaokangQian4080a7f2022-04-11 09:55:18 +0000306static int ssl_tls13_client_hello_has_exts( mbedtls_ssl_context *ssl,
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000307 int exts_mask )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000308{
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000309 int masked = ssl->handshake->extensions_present & exts_mask;
310 return( masked == exts_mask );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000311}
312
XiaokangQianb67384d2022-04-19 00:02:38 +0000313static int ssl_tls13_client_hello_has_exts_for_ephemeral_key_exchange(
314 mbedtls_ssl_context *ssl )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000315{
XiaokangQian4080a7f2022-04-11 09:55:18 +0000316 return( ssl_tls13_client_hello_has_exts( ssl,
XiaokangQian7807f9f2022-02-15 10:04:37 +0000317 MBEDTLS_SSL_EXT_SUPPORTED_GROUPS |
318 MBEDTLS_SSL_EXT_KEY_SHARE |
319 MBEDTLS_SSL_EXT_SIG_ALG ) );
320}
321
XiaokangQianb67384d2022-04-19 00:02:38 +0000322static int ssl_tls13_check_ephemeral_key_exchange( mbedtls_ssl_context *ssl )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000323{
324 if( !mbedtls_ssl_conf_tls13_ephemeral_enabled( ssl ) )
325 return( 0 );
326
XiaokangQianb67384d2022-04-19 00:02:38 +0000327 if( !ssl_tls13_client_hello_has_exts_for_ephemeral_key_exchange( ssl ) )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000328 return( 0 );
329
XiaokangQianb67384d2022-04-19 00:02:38 +0000330 ssl->handshake->tls13_kex_modes =
331 MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000332 return( 1 );
333}
334
XiaokangQian4080a7f2022-04-11 09:55:18 +0000335/*
XiaokangQianed582dd2022-04-13 08:21:05 +0000336 *
337 * STATE HANDLING: ClientHello
338 *
XiaokangQianb67384d2022-04-19 00:02:38 +0000339 * There are three possible classes of outcomes when parsing the ClientHello:
XiaokangQianed582dd2022-04-13 08:21:05 +0000340 *
XiaokangQianb67384d2022-04-19 00:02:38 +0000341 * 1) The ClientHello was well-formed and matched the server's configuration.
XiaokangQianed582dd2022-04-13 08:21:05 +0000342 *
343 * In this case, the server progresses to sending its ServerHello.
344 *
XiaokangQianb67384d2022-04-19 00:02:38 +0000345 * 2) The ClientHello was well-formed but didn't match the server's
346 * configuration.
XiaokangQianed582dd2022-04-13 08:21:05 +0000347 *
348 * For example, the client might not have offered a key share which
349 * the server supports, or the server might require a cookie.
350 *
351 * In this case, the server sends a HelloRetryRequest.
352 *
XiaokangQianb67384d2022-04-19 00:02:38 +0000353 * 3) The ClientHello was ill-formed
XiaokangQianed582dd2022-04-13 08:21:05 +0000354 *
355 * In this case, we abort the handshake.
356 *
357 */
358
359/*
XiaokangQian4080a7f2022-04-11 09:55:18 +0000360 * Structure of this message:
361 *
362 * uint16 ProtocolVersion;
363 * opaque Random[32];
XiaokangQian4080a7f2022-04-11 09:55:18 +0000364 * uint8 CipherSuite[2]; // Cryptographic suite selector
365 *
366 * struct {
367 * ProtocolVersion legacy_version = 0x0303; // TLS v1.2
368 * Random random;
369 * opaque legacy_session_id<0..32>;
370 * CipherSuite cipher_suites<2..2^16-2>;
371 * opaque legacy_compression_methods<1..2^8-1>;
372 * Extension extensions<8..2^16-1>;
373 * } ClientHello;
374 */
XiaokangQianed582dd2022-04-13 08:21:05 +0000375
376#define SSL_CLIENT_HELLO_OK 0
377#define SSL_CLIENT_HELLO_HRR_REQUIRED 1
378
XiaokangQian4080a7f2022-04-11 09:55:18 +0000379static int ssl_tls13_parse_client_hello( mbedtls_ssl_context *ssl,
380 const unsigned char *buf,
381 const unsigned char *end )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000382{
XiaokangQianb67384d2022-04-19 00:02:38 +0000383 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
384 const unsigned char *p = buf;
XiaokangQian4080a7f2022-04-11 09:55:18 +0000385 size_t legacy_session_id_len;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000386 size_t cipher_suites_len;
XiaokangQianed582dd2022-04-13 08:21:05 +0000387 const unsigned char *cipher_suites_start;
XiaokangQianb67384d2022-04-19 00:02:38 +0000388 size_t extensions_len;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000389 const unsigned char *extensions_end;
390
XiaokangQianed582dd2022-04-13 08:21:05 +0000391 const int* cipher_suites;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000392 const mbedtls_ssl_ciphersuite_t* ciphersuite_info;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000393 int hrr_required = 0;
394
395 ssl->handshake->extensions_present = MBEDTLS_SSL_EXT_NONE;
396
397 /*
XiaokangQianb67384d2022-04-19 00:02:38 +0000398 * ClientHello layout:
XiaokangQian7807f9f2022-02-15 10:04:37 +0000399 * 0 . 1 protocol version
400 * 2 . 33 random bytes ( starting with 4 bytes of Unix time )
XiaokangQianc5763b52022-04-02 03:34:37 +0000401 * 34 . 34 session id length ( 1 byte )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000402 * 35 . 34+x session id
XiaokangQian7807f9f2022-02-15 10:04:37 +0000403 * .. . .. ciphersuite list length ( 2 bytes )
404 * .. . .. ciphersuite list
405 * .. . .. compression alg. list length ( 1 byte )
406 * .. . .. compression alg. list
407 * .. . .. extensions length ( 2 bytes, optional )
408 * .. . .. extensions ( optional )
409 */
410
XiaokangQianb67384d2022-04-19 00:02:38 +0000411 /*
412 * Needs to be updated due to mandatory extensions
XiaokangQian7807f9f2022-02-15 10:04:37 +0000413 * Minimal length ( with everything empty and extensions ommitted ) is
414 * 2 + 32 + 1 + 2 + 1 = 38 bytes. Check that first, so that we can
415 * read at least up to session id length without worrying.
416 */
417 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, 38 );
418
419 /* ...
420 * ProtocolVersion legacy_version = 0x0303; // TLS 1.2
421 * ...
422 * with ProtocolVersion defined as:
423 * uint16 ProtocolVersion;
424 */
425 if( !( p[0] == MBEDTLS_SSL_MAJOR_VERSION_3 &&
426 p[1] == MBEDTLS_SSL_MINOR_VERSION_3 ) )
427 {
428 MBEDTLS_SSL_DEBUG_MSG( 1, ( "Unsupported version of TLS." ) );
429 MBEDTLS_SSL_PEND_FATAL_ALERT( MBEDTLS_SSL_ALERT_MSG_PROTOCOL_VERSION,
430 MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION );
XiaokangQianb67384d2022-04-19 00:02:38 +0000431 return ( MBEDTLS_ERR_SSL_BAD_PROTOCOL_VERSION );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000432 }
433 p += 2;
434
435 /*
XiaokangQianf8ceb942022-04-15 11:43:27 +0000436 * Only support TLS 1.3 currently, temporarily set the version.
437 */
438 ssl->major_ver = MBEDTLS_SSL_MAJOR_VERSION_3;
439 ssl->minor_ver = MBEDTLS_SSL_MINOR_VERSION_4;
440
441 /*
XiaokangQian7807f9f2022-02-15 10:04:37 +0000442 * Save client random
XiaokangQianb67384d2022-04-19 00:02:38 +0000443 *
444 * ---
445 * Random random;
446 * ---
447 * with Random defined as:
448 * opaque Random[32];
XiaokangQian7807f9f2022-02-15 10:04:37 +0000449 */
XiaokangQian4080a7f2022-04-11 09:55:18 +0000450 MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, random bytes",
451 p, MBEDTLS_SERVER_HELLO_RANDOM_LEN );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000452
XiaokangQian4080a7f2022-04-11 09:55:18 +0000453 memcpy( &ssl->handshake->randbytes[0], p, MBEDTLS_SERVER_HELLO_RANDOM_LEN );
XiaokangQian4080a7f2022-04-11 09:55:18 +0000454 p += MBEDTLS_SERVER_HELLO_RANDOM_LEN;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000455
XiaokangQianb67384d2022-04-19 00:02:38 +0000456 /* ---
457 * opaque legacy_session_id<0..32>;
458 * ---
XiaokangQian7807f9f2022-02-15 10:04:37 +0000459 */
XiaokangQian4080a7f2022-04-11 09:55:18 +0000460 legacy_session_id_len = p[0];
XiaokangQianc5763b52022-04-02 03:34:37 +0000461 p++;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000462
XiaokangQianb67384d2022-04-19 00:02:38 +0000463 if( legacy_session_id_len > sizeof( ssl->session_negotiate->id ) )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000464 {
465 MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad client hello message" ) );
466 return( MBEDTLS_ERR_SSL_DECODE_ERROR );
467 }
468
XiaokangQian4080a7f2022-04-11 09:55:18 +0000469 ssl->session_negotiate->id_len = legacy_session_id_len;
XiaokangQianed582dd2022-04-13 08:21:05 +0000470 MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, session id",
471 buf, legacy_session_id_len );
XiaokangQianb67384d2022-04-19 00:02:38 +0000472 /*
473 * Check we have enough data for the legacy session identifier
474 * and the ciphersuite list length.
475 */
476 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, legacy_session_id_len + 2 );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000477
XiaokangQianed582dd2022-04-13 08:21:05 +0000478 memcpy( &ssl->session_negotiate->id[0], p, legacy_session_id_len );
XiaokangQian4080a7f2022-04-11 09:55:18 +0000479 p += legacy_session_id_len;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000480
XiaokangQian7807f9f2022-02-15 10:04:37 +0000481 cipher_suites_len = MBEDTLS_GET_UINT16_BE( p, 0 );
482 p += 2;
483
XiaokangQianb67384d2022-04-19 00:02:38 +0000484 /* Check we have enough data for the ciphersuite list, the legacy
485 * compression methods and the length of the extensions.
486 */
487 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, cipher_suites_len + 2 + 2 );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000488
489 /* store pointer to ciphersuite list */
XiaokangQianed582dd2022-04-13 08:21:05 +0000490 cipher_suites_start = p;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000491
492 MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, ciphersuitelist",
493 p, cipher_suites_len );
494
XiaokangQian17f974c2022-04-19 09:57:41 +0000495 /*
496 * Search for a matching ciphersuite
497 */
498 size_t ciphersuite_exist = 0;
499 cipher_suites = ssl->conf->ciphersuite_list;
500 ciphersuite_info = NULL;
501 for ( size_t j = 0; j < cipher_suites_len;
502 j += 2, p += 2 )
503 {
504 for ( size_t i = 0; cipher_suites[i] != 0; i++ )
505 {
506 if( MBEDTLS_GET_UINT16_BE(p, 0) == cipher_suites[i] )
507 {
508 ciphersuite_info = mbedtls_ssl_ciphersuite_from_id(
509 cipher_suites[i] );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000510
XiaokangQian17f974c2022-04-19 09:57:41 +0000511 if( ciphersuite_info == NULL )
512 {
513 MBEDTLS_SSL_DEBUG_MSG(
514 1,
515 ( "mbedtls_ssl_ciphersuite_from_id: should never happen" ) );
516 return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
517 }
518
519 ssl->session_negotiate->ciphersuite = cipher_suites[i];
520 ssl->handshake->ciphersuite_info = ciphersuite_info;
521 ciphersuite_exist = 1;
522
523 break;
524
525 }
526
527 }
528 }
529
530 if( !ciphersuite_exist )
531 return( MBEDTLS_ERR_SSL_HANDSHAKE_FAILURE );
532
533 MBEDTLS_SSL_DEBUG_MSG( 2, ( "selected ciphersuite: %s",
534 ciphersuite_info->name ) );
535
536 p = cipher_suites_start + cipher_suites_len;
XiaokangQian4080a7f2022-04-11 09:55:18 +0000537 /* ...
XiaokangQianb67384d2022-04-19 00:02:38 +0000538 * opaque legacy_compression_methods<1..2^8-1>;
XiaokangQian4080a7f2022-04-11 09:55:18 +0000539 * ...
XiaokangQian7807f9f2022-02-15 10:04:37 +0000540 */
XiaokangQianb67384d2022-04-19 00:02:38 +0000541 if( p[0] != 1 || p[1] != 0 )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000542 {
XiaokangQian4080a7f2022-04-11 09:55:18 +0000543 MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad legacy compression method" ) );
544 MBEDTLS_SSL_PEND_FATAL_ALERT( MBEDTLS_SSL_ALERT_MSG_ILLEGAL_PARAMETER,
545 MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
546 return ( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000547 }
XiaokangQianb67384d2022-04-19 00:02:38 +0000548 p += 2;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000549
XiaokangQianb67384d2022-04-19 00:02:38 +0000550 /* ---
551 * Extension extensions<8..2^16-1>;
552 * ---
553 * with Extension defined as:
554 * struct {
555 * ExtensionType extension_type;
556 * opaque extension_data<0..2^16-1>;
557 * } Extension;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000558 */
XiaokangQian4080a7f2022-04-11 09:55:18 +0000559 extensions_len = MBEDTLS_GET_UINT16_BE( p, 0 );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000560 p += 2;
XiaokangQian4080a7f2022-04-11 09:55:18 +0000561 extensions_end = p + extensions_len;
562 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, extensions_len );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000563
XiaokangQian4080a7f2022-04-11 09:55:18 +0000564 MBEDTLS_SSL_DEBUG_BUF( 3, "client hello extensions", p, extensions_len );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000565
566 while( p < extensions_end )
567 {
568 unsigned int extension_type;
569 size_t extension_data_len;
570 const unsigned char *extension_data_end;
571
572 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, end, 4 );
573 extension_type = MBEDTLS_GET_UINT16_BE( p, 0 );
574 extension_data_len = MBEDTLS_GET_UINT16_BE( p, 2 );
575 p += 4;
576
577 MBEDTLS_SSL_CHK_BUF_READ_PTR( p, extensions_end, extension_data_len );
578 extension_data_end = p + extension_data_len;
579
580 switch( extension_type )
581 {
XiaokangQianb67384d2022-04-19 00:02:38 +0000582#if defined(MBEDTLS_ECDH_C)
XiaokangQian7807f9f2022-02-15 10:04:37 +0000583 case MBEDTLS_TLS_EXT_SUPPORTED_GROUPS:
584 MBEDTLS_SSL_DEBUG_MSG( 3, ( "found supported group extension" ) );
585
586 /* Supported Groups Extension
587 *
588 * When sent by the client, the "supported_groups" extension
589 * indicates the named groups which the client supports,
590 * ordered from most preferred to least preferred.
591 */
XiaokangQiancfd925f2022-04-14 07:10:37 +0000592 ret = ssl_tls13_parse_supported_groups_ext( ssl, p,
XiaokangQian7807f9f2022-02-15 10:04:37 +0000593 extension_data_end );
594 if( ret != 0 )
595 {
596 MBEDTLS_SSL_DEBUG_RET( 1,
597 "mbedtls_ssl_parse_supported_groups_ext", ret );
598 return( ret );
599 }
600
601 ssl->handshake->extensions_present |= MBEDTLS_SSL_EXT_SUPPORTED_GROUPS;
602 break;
XiaokangQianb67384d2022-04-19 00:02:38 +0000603#endif /* MBEDTLS_ECDH_C */
XiaokangQian7807f9f2022-02-15 10:04:37 +0000604
XiaokangQian88408882022-04-02 10:15:03 +0000605#if defined(MBEDTLS_ECDH_C)
XiaokangQian7807f9f2022-02-15 10:04:37 +0000606 case MBEDTLS_TLS_EXT_KEY_SHARE:
607 MBEDTLS_SSL_DEBUG_MSG( 3, ( "found key share extension" ) );
608
609 /*
610 * Key Share Extension
611 *
612 * When sent by the client, the "key_share" extension
613 * contains the endpoint's cryptographic parameters for
614 * ECDHE/DHE key establishment methods.
615 */
616 ret = ssl_tls13_parse_key_shares_ext( ssl, p, extension_data_end );
617 if( ret == MBEDTLS_ERR_SSL_HRR_REQUIRED )
618 {
XiaokangQianed582dd2022-04-13 08:21:05 +0000619 MBEDTLS_SSL_DEBUG_MSG( 2, ( "HRR needed " ) );
620 ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000621 }
622
623 if( ret != 0 )
624 return( ret );
625
626 ssl->handshake->extensions_present |= MBEDTLS_SSL_EXT_KEY_SHARE;
627 break;
XiaokangQian88408882022-04-02 10:15:03 +0000628#endif /* MBEDTLS_ECDH_C */
XiaokangQian7807f9f2022-02-15 10:04:37 +0000629
630 case MBEDTLS_TLS_EXT_SUPPORTED_VERSIONS:
631 MBEDTLS_SSL_DEBUG_MSG( 3, ( "found supported versions extension" ) );
632
633 ret = ssl_tls13_parse_supported_versions_ext(
XiaokangQianb67384d2022-04-19 00:02:38 +0000634 ssl, p, extension_data_end );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000635 if( ret != 0 )
636 {
637 MBEDTLS_SSL_DEBUG_RET( 1,
638 ( "ssl_tls13_parse_supported_versions_ext" ), ret );
639 return( ret );
640 }
641 ssl->handshake->extensions_present |= MBEDTLS_SSL_EXT_SUPPORTED_VERSIONS;
642 break;
643
644#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
645 case MBEDTLS_TLS_EXT_SIG_ALG:
646 MBEDTLS_SSL_DEBUG_MSG( 3, ( "found signature_algorithms extension" ) );
647
648 ret = mbedtls_ssl_tls13_parse_sig_alg_ext( ssl, p,
649 extension_data_end );
650 if( ret != 0 )
651 {
652 MBEDTLS_SSL_DEBUG_MSG( 1,
653 ( "ssl_parse_supported_signature_algorithms_server_ext ( %d )",
654 ret ) );
655 return( ret );
656 }
657 ssl->handshake->extensions_present |= MBEDTLS_SSL_EXT_SIG_ALG;
658 break;
659#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
660
661 default:
662 MBEDTLS_SSL_DEBUG_MSG( 3,
663 ( "unknown extension found: %ud ( ignoring )",
664 extension_type ) );
665 }
666
667 p += extension_data_len;
668 }
669
670 /* Update checksum with either
671 * - The entire content of the CH message, if no PSK extension is present
672 * - The content up to but excluding the PSK extension, if present.
673 */
XiaokangQian3f84d5d2022-04-19 06:36:17 +0000674 mbedtls_ssl_add_hs_msg_to_checksum( ssl, MBEDTLS_SSL_HS_CLIENT_HELLO,
XiaokangQianc4b8c992022-04-07 11:31:38 +0000675 buf, p - buf );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000676
677 /* List all the extensions we have received */
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000678#if defined(MBEDTLS_DEBUG_C)
XiaokangQian4080a7f2022-04-11 09:55:18 +0000679 ssl_tls13_debug_print_client_hello_exts( ssl );
XiaokangQian8f9dfe42022-04-15 02:52:39 +0000680#endif /* MBEDTLS_DEBUG_C */
XiaokangQian7807f9f2022-02-15 10:04:37 +0000681
682 /*
XiaokangQianb67384d2022-04-19 00:02:38 +0000683 * Here we only support the ephemeral or (EC)DHE key echange mode
XiaokangQian7807f9f2022-02-15 10:04:37 +0000684 */
685
XiaokangQianb67384d2022-04-19 00:02:38 +0000686 if( !ssl_tls13_check_ephemeral_key_exchange( ssl ) )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000687 {
688 MBEDTLS_SSL_DEBUG_MSG(
689 1,
690 ( "ClientHello message misses mandatory extensions." ) );
691 MBEDTLS_SSL_PEND_FATAL_ALERT( MBEDTLS_SSL_ALERT_MSG_MISSING_EXTENSION ,
692 MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
693 return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
694 }
695
XiaokangQian7807f9f2022-02-15 10:04:37 +0000696 if( hrr_required == 1 )
697 return( SSL_CLIENT_HELLO_HRR_REQUIRED );
698
699 return( 0 );
700}
701
XiaokangQianed582dd2022-04-13 08:21:05 +0000702/* Update the handshake state machine */
703
XiaokangQiancfd925f2022-04-14 07:10:37 +0000704static int ssl_tls13_postprocess_client_hello( mbedtls_ssl_context* ssl )
XiaokangQian7807f9f2022-02-15 10:04:37 +0000705{
706 int ret = 0;
707
XiaokangQian7807f9f2022-02-15 10:04:37 +0000708 ret = mbedtls_ssl_tls13_key_schedule_stage_early( ssl );
709 if( ret != 0 )
710 {
711 MBEDTLS_SSL_DEBUG_RET( 1,
712 "mbedtls_ssl_tls1_3_key_schedule_stage_early", ret );
713 return( ret );
714 }
715
716 mbedtls_ssl_handshake_set_state( ssl, MBEDTLS_SSL_SERVER_HELLO );
717 return( 0 );
718
719}
720
721/*
XiaokangQianed582dd2022-04-13 08:21:05 +0000722 * Main entry point from the state machine; orchestrates the otherfunctions.
723 */
724
725static int ssl_tls13_process_client_hello( mbedtls_ssl_context *ssl )
726{
727
728 int ret = 0;
XiaokangQianed582dd2022-04-13 08:21:05 +0000729 unsigned char* buf = NULL;
730 size_t buflen = 0;
731 MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> parse client hello" ) );
732
733 ssl->major_ver = MBEDTLS_SSL_MAJOR_VERSION_3;
734 MBEDTLS_SSL_PROC_CHK( mbedtls_ssl_tls13_fetch_handshake_msg(
735 ssl, MBEDTLS_SSL_HS_CLIENT_HELLO,
736 &buf, &buflen ) );
737
738 MBEDTLS_SSL_PROC_CHK_NEG( ssl_tls13_parse_client_hello( ssl, buf,
739 buf + buflen ) );
XiaokangQianed582dd2022-04-13 08:21:05 +0000740 MBEDTLS_SSL_DEBUG_MSG( 1, ( "postprocess" ) );
XiaokangQiancfd925f2022-04-14 07:10:37 +0000741 MBEDTLS_SSL_PROC_CHK( ssl_tls13_postprocess_client_hello( ssl ) );
XiaokangQianed582dd2022-04-13 08:21:05 +0000742
743cleanup:
744
745 MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= parse client hello" ) );
746 return( ret );
747}
748
749/*
XiaokangQian7807f9f2022-02-15 10:04:37 +0000750 * TLS and DTLS 1.3 State Maschine -- server side
751 */
Jerry Yu27561932021-08-27 17:07:38 +0800752int mbedtls_ssl_tls13_handshake_server_step( mbedtls_ssl_context *ssl )
Jerry Yub9930e72021-08-06 17:11:51 +0800753{
XiaokangQian7807f9f2022-02-15 10:04:37 +0000754 int ret = 0;
755
756 if( ssl->state == MBEDTLS_SSL_HANDSHAKE_OVER || ssl->handshake == NULL )
757 return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
758
Jerry Yue3b34122021-09-28 17:53:35 +0800759 MBEDTLS_SSL_DEBUG_MSG( 2, ( "tls13 server state: %s(%d)",
760 mbedtls_ssl_states_str( ssl->state ),
761 ssl->state ) );
Jerry Yu6e81b272021-09-27 11:16:17 +0800762
XiaokangQian7807f9f2022-02-15 10:04:37 +0000763 switch( ssl->state )
764 {
765 /* start state */
766 case MBEDTLS_SSL_HELLO_REQUEST:
XiaokangQian7807f9f2022-02-15 10:04:37 +0000767 mbedtls_ssl_handshake_set_state( ssl, MBEDTLS_SSL_CLIENT_HELLO );
768
769 break;
770
771 /* ----- READ CLIENT HELLO ----*/
772
773 case MBEDTLS_SSL_CLIENT_HELLO:
774
XiaokangQian4080a7f2022-04-11 09:55:18 +0000775 ret = ssl_tls13_process_client_hello( ssl );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000776 if( ret != 0 )
XiaokangQian4080a7f2022-04-11 09:55:18 +0000777 MBEDTLS_SSL_DEBUG_RET( 1, "ssl_tls13_process_client_hello", ret );
XiaokangQian7807f9f2022-02-15 10:04:37 +0000778
779 break;
780
XiaokangQian3f84d5d2022-04-19 06:36:17 +0000781 case MBEDTLS_SSL_SERVER_HELLO:
782 MBEDTLS_SSL_DEBUG_MSG( 1, ( "SSL - The requested feature is not available" ) );
783 return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
784
785 break;
XiaokangQian7807f9f2022-02-15 10:04:37 +0000786 default:
787 MBEDTLS_SSL_DEBUG_MSG( 1, ( "invalid state %d", ssl->state ) );
788 return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
789 }
790
791 return( ret );
Jerry Yub9930e72021-08-06 17:11:51 +0800792}
Jerry Yu3cc4c2a2021-08-06 16:29:08 +0800793
Jerry Yufb4b6472022-01-27 15:03:26 +0800794#endif /* MBEDTLS_SSL_SRV_C && MBEDTLS_SSL_PROTO_TLS1_3 */