2015-05-26 11:57:05 +02:00
|
|
|
/**
|
2021-03-05 19:38:47 +01:00
|
|
|
* \file ssl_misc.h
|
2015-05-26 11:57:05 +02:00
|
|
|
*
|
|
|
|
* \brief Internal functions shared by the SSL modules
|
2018-01-05 16:33:17 +01:00
|
|
|
*/
|
|
|
|
/*
|
2020-08-07 13:07:28 +02:00
|
|
|
* Copyright The Mbed TLS Contributors
|
2015-09-04 14:21:07 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-05-26 11:57:05 +02:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-05-26 11:57:05 +02:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-05-26 11:57:05 +02:00
|
|
|
*
|
2015-09-04 14:21:07 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-05-26 11:57:05 +02:00
|
|
|
*/
|
2021-03-05 19:38:47 +01:00
|
|
|
#ifndef MBEDTLS_SSL_MISC_H
|
|
|
|
#define MBEDTLS_SSL_MISC_H
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2021-05-27 11:25:03 +02:00
|
|
|
#include "mbedtls/build_info.h"
|
2019-01-31 14:20:20 +01:00
|
|
|
|
2019-07-04 21:01:14 +02:00
|
|
|
#include "mbedtls/ssl.h"
|
|
|
|
#include "mbedtls/cipher.h"
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2022-02-10 10:12:12 +01:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2019-01-29 15:14:33 +01:00
|
|
|
#include "psa/crypto.h"
|
2022-02-10 10:12:12 +01:00
|
|
|
#include "mbedtls/psa_util.h"
|
2022-07-18 13:41:11 +02:00
|
|
|
#include "hash_info.h"
|
2019-01-29 15:14:33 +01:00
|
|
|
#endif
|
|
|
|
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_MD5)
|
2019-07-04 21:01:14 +02:00
|
|
|
#include "mbedtls/md5.h"
|
2015-05-26 12:19:45 +02:00
|
|
|
#endif
|
|
|
|
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA1)
|
2019-07-04 21:01:14 +02:00
|
|
|
#include "mbedtls/sha1.h"
|
2015-05-26 12:19:45 +02:00
|
|
|
#endif
|
|
|
|
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA256)
|
2019-07-04 21:01:14 +02:00
|
|
|
#include "mbedtls/sha256.h"
|
2015-05-26 12:19:45 +02:00
|
|
|
#endif
|
|
|
|
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA512)
|
2019-07-04 21:01:14 +02:00
|
|
|
#include "mbedtls/sha512.h"
|
2015-05-26 12:19:45 +02:00
|
|
|
#endif
|
|
|
|
|
2022-05-31 14:43:23 +02:00
|
|
|
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
|
|
|
|
!defined(MBEDTLS_USE_PSA_CRYPTO)
|
2019-07-04 21:01:14 +02:00
|
|
|
#include "mbedtls/ecjpake.h"
|
2015-09-15 12:10:54 +02:00
|
|
|
#endif
|
|
|
|
|
2023-03-07 18:14:34 +01:00
|
|
|
#include "mbedtls/pk.h"
|
2022-01-19 10:43:22 +01:00
|
|
|
#include "common.h"
|
|
|
|
|
2017-05-17 11:56:15 +02:00
|
|
|
/* Shorthand for restartable ECC */
|
2017-05-16 09:26:48 +02:00
|
|
|
#if defined(MBEDTLS_ECP_RESTARTABLE) && \
|
|
|
|
defined(MBEDTLS_SSL_CLI_C) && \
|
|
|
|
defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
|
|
|
|
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
|
2020-03-10 12:19:08 +01:00
|
|
|
#define MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED
|
2017-05-16 09:26:48 +02:00
|
|
|
#endif
|
|
|
|
|
2015-05-26 12:31:46 +02:00
|
|
|
#define MBEDTLS_SSL_INITIAL_HANDSHAKE 0
|
|
|
|
#define MBEDTLS_SSL_RENEGOTIATION_IN_PROGRESS 1 /* In progress */
|
|
|
|
#define MBEDTLS_SSL_RENEGOTIATION_DONE 2 /* Done or aborted */
|
|
|
|
#define MBEDTLS_SSL_RENEGOTIATION_PENDING 3 /* Requested (server only) */
|
|
|
|
|
2022-10-31 05:48:30 +01:00
|
|
|
/* Faked handshake message identity for HelloRetryRequest. */
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_TLS1_3_HS_HELLO_RETRY_REQUEST (-MBEDTLS_SSL_HS_SERVER_HELLO)
|
2022-10-31 05:48:30 +01:00
|
|
|
|
2021-08-26 09:31:37 +02:00
|
|
|
/*
|
2022-11-08 14:01:17 +01:00
|
|
|
* Internal identity of handshake extensions
|
2021-08-26 09:31:37 +02:00
|
|
|
*/
|
2022-10-31 06:08:18 +01:00
|
|
|
#define MBEDTLS_SSL_EXT_ID_UNRECOGNIZED 0
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SERVERNAME 1
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SERVERNAME_HOSTNAME 1
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_MAX_FRAGMENT_LENGTH 2
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_STATUS_REQUEST 3
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SUPPORTED_GROUPS 4
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SUPPORTED_ELLIPTIC_CURVES 4
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SIG_ALG 5
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_USE_SRTP 6
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_HEARTBEAT 7
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_ALPN 8
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SCT 9
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_CLI_CERT_TYPE 10
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SERV_CERT_TYPE 11
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_PADDING 12
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_PRE_SHARED_KEY 13
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_EARLY_DATA 14
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SUPPORTED_VERSIONS 15
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_COOKIE 16
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_PSK_KEY_EXCHANGE_MODES 17
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_CERT_AUTH 18
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_OID_FILTERS 19
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_POST_HANDSHAKE_AUTH 20
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SIG_ALG_CERT 21
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_KEY_SHARE 22
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_TRUNCATED_HMAC 23
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SUPPORTED_POINT_FORMATS 24
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_ENCRYPT_THEN_MAC 25
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_EXTENDED_MASTER_SECRET 26
|
|
|
|
#define MBEDTLS_SSL_EXT_ID_SESSION_TICKET 27
|
2023-02-10 12:45:19 +01:00
|
|
|
#define MBEDTLS_SSL_EXT_ID_RECORD_SIZE_LIMIT 28
|
2022-10-31 06:08:18 +01:00
|
|
|
|
|
|
|
/* Utility for translating IANA extension type. */
|
2023-01-11 14:50:10 +01:00
|
|
|
uint32_t mbedtls_ssl_get_extension_id(unsigned int extension_type);
|
|
|
|
uint32_t mbedtls_ssl_get_extension_mask(unsigned int extension_type);
|
2022-10-31 06:08:18 +01:00
|
|
|
/* Macros used to define mask constants */
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_EXT_MASK(id) (1ULL << (MBEDTLS_SSL_EXT_ID_##id))
|
2022-10-31 06:08:18 +01:00
|
|
|
/* Reset value of extension mask */
|
|
|
|
#define MBEDTLS_SSL_EXT_MASK_NONE 0
|
2021-08-18 06:47:24 +02:00
|
|
|
|
2022-10-29 03:08:47 +02:00
|
|
|
/* In messages containing extension requests, we should ignore unrecognized
|
|
|
|
* extensions. In messages containing extension responses, unrecognized
|
|
|
|
* extensions should result in handshake abortion. Messages containing
|
|
|
|
* extension requests include ClientHello, CertificateRequest and
|
|
|
|
* NewSessionTicket. Messages containing extension responses include
|
|
|
|
* ServerHello, HelloRetryRequest, EncryptedExtensions and Certificate.
|
2022-08-04 10:29:22 +02:00
|
|
|
*
|
2022-08-29 04:58:31 +02:00
|
|
|
* RFC 8446 section 4.1.3
|
2022-08-04 10:29:22 +02:00
|
|
|
*
|
|
|
|
* The ServerHello MUST only include extensions which are required to establish
|
|
|
|
* the cryptographic context and negotiate the protocol version.
|
|
|
|
*
|
2022-08-29 04:58:31 +02:00
|
|
|
* RFC 8446 section 4.2
|
2022-08-04 10:29:22 +02:00
|
|
|
*
|
|
|
|
* If an implementation receives an extension which it recognizes and which is
|
|
|
|
* not specified for the message in which it appears, it MUST abort the handshake
|
|
|
|
* with an "illegal_parameter" alert.
|
|
|
|
*/
|
2022-10-31 06:20:57 +01:00
|
|
|
|
2022-11-08 14:01:17 +01:00
|
|
|
/* Extensions that are not recognized by TLS 1.3 */
|
|
|
|
#define MBEDTLS_SSL_TLS1_3_EXT_MASK_UNRECOGNIZED \
|
2023-01-11 14:50:10 +01:00
|
|
|
(MBEDTLS_SSL_EXT_MASK(SUPPORTED_POINT_FORMATS) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(ENCRYPT_THEN_MAC) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(EXTENDED_MASTER_SECRET) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SESSION_TICKET) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(TRUNCATED_HMAC) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(UNRECOGNIZED))
|
2022-08-04 10:29:22 +02:00
|
|
|
|
2022-12-04 18:19:59 +01:00
|
|
|
/* RFC 8446 section 4.2. Allowed extensions for ClientHello */
|
2022-08-04 10:29:22 +02:00
|
|
|
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_CH \
|
2023-01-11 14:50:10 +01:00
|
|
|
(MBEDTLS_SSL_EXT_MASK(SERVERNAME) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(MAX_FRAGMENT_LENGTH) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(STATUS_REQUEST) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SUPPORTED_GROUPS) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SIG_ALG) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(USE_SRTP) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(HEARTBEAT) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(ALPN) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SCT) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(CLI_CERT_TYPE) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SERV_CERT_TYPE) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(PADDING) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(KEY_SHARE) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(PRE_SHARED_KEY) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(PSK_KEY_EXCHANGE_MODES) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(EARLY_DATA) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(COOKIE) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SUPPORTED_VERSIONS) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(CERT_AUTH) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(POST_HANDSHAKE_AUTH) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SIG_ALG_CERT) | \
|
2023-02-10 12:45:19 +01:00
|
|
|
MBEDTLS_SSL_EXT_MASK(RECORD_SIZE_LIMIT) | \
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_SSL_TLS1_3_EXT_MASK_UNRECOGNIZED)
|
2022-08-04 10:29:22 +02:00
|
|
|
|
2022-08-29 04:58:31 +02:00
|
|
|
/* RFC 8446 section 4.2. Allowed extensions for EncryptedExtensions */
|
2022-08-04 10:29:22 +02:00
|
|
|
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_EE \
|
2023-01-11 14:50:10 +01:00
|
|
|
(MBEDTLS_SSL_EXT_MASK(SERVERNAME) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(MAX_FRAGMENT_LENGTH) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SUPPORTED_GROUPS) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(USE_SRTP) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(HEARTBEAT) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(ALPN) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(CLI_CERT_TYPE) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SERV_CERT_TYPE) | \
|
2023-02-10 12:45:19 +01:00
|
|
|
MBEDTLS_SSL_EXT_MASK(EARLY_DATA) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(RECORD_SIZE_LIMIT))
|
2022-08-04 10:29:22 +02:00
|
|
|
|
2022-08-29 04:58:31 +02:00
|
|
|
/* RFC 8446 section 4.2. Allowed extensions for CertificateRequest */
|
2022-08-04 10:29:22 +02:00
|
|
|
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_CR \
|
2023-01-11 14:50:10 +01:00
|
|
|
(MBEDTLS_SSL_EXT_MASK(STATUS_REQUEST) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SIG_ALG) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SCT) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(CERT_AUTH) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(OID_FILTERS) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SIG_ALG_CERT) | \
|
|
|
|
MBEDTLS_SSL_TLS1_3_EXT_MASK_UNRECOGNIZED)
|
2022-08-04 10:29:22 +02:00
|
|
|
|
2022-08-29 04:58:31 +02:00
|
|
|
/* RFC 8446 section 4.2. Allowed extensions for Certificate */
|
2022-08-04 10:29:22 +02:00
|
|
|
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_CT \
|
2023-01-11 14:50:10 +01:00
|
|
|
(MBEDTLS_SSL_EXT_MASK(STATUS_REQUEST) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SCT))
|
2022-08-04 10:29:22 +02:00
|
|
|
|
2022-08-29 04:58:31 +02:00
|
|
|
/* RFC 8446 section 4.2. Allowed extensions for ServerHello */
|
2022-08-04 10:29:22 +02:00
|
|
|
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_SH \
|
2023-01-11 14:50:10 +01:00
|
|
|
(MBEDTLS_SSL_EXT_MASK(KEY_SHARE) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(PRE_SHARED_KEY) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SUPPORTED_VERSIONS))
|
2022-08-04 10:29:22 +02:00
|
|
|
|
2022-08-29 04:58:31 +02:00
|
|
|
/* RFC 8446 section 4.2. Allowed extensions for HelloRetryRequest */
|
2022-08-04 10:29:22 +02:00
|
|
|
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_HRR \
|
2023-01-11 14:50:10 +01:00
|
|
|
(MBEDTLS_SSL_EXT_MASK(KEY_SHARE) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(COOKIE) | \
|
|
|
|
MBEDTLS_SSL_EXT_MASK(SUPPORTED_VERSIONS))
|
2022-08-04 10:29:22 +02:00
|
|
|
|
2022-08-29 04:58:31 +02:00
|
|
|
/* RFC 8446 section 4.2. Allowed extensions for NewSessionTicket */
|
2022-08-04 10:29:22 +02:00
|
|
|
#define MBEDTLS_SSL_TLS1_3_ALLOWED_EXTS_OF_NST \
|
2023-01-11 14:50:10 +01:00
|
|
|
(MBEDTLS_SSL_EXT_MASK(EARLY_DATA) | \
|
|
|
|
MBEDTLS_SSL_TLS1_3_EXT_MASK_UNRECOGNIZED)
|
2022-08-04 10:29:22 +02:00
|
|
|
|
2021-08-27 11:21:44 +02:00
|
|
|
/*
|
2021-09-03 15:09:22 +02:00
|
|
|
* Helper macros for function call with return check.
|
2021-08-27 11:21:44 +02:00
|
|
|
*/
|
|
|
|
/*
|
2021-09-03 15:09:22 +02:00
|
|
|
* Exit when return non-zero value
|
2021-08-27 11:21:44 +02:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_PROC_CHK(f) \
|
2021-08-18 10:38:40 +02:00
|
|
|
do { \
|
2023-01-11 14:50:10 +01:00
|
|
|
ret = (f); \
|
|
|
|
if (ret != 0) \
|
2021-08-18 10:38:40 +02:00
|
|
|
{ \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
2023-01-11 14:50:10 +01:00
|
|
|
} while (0)
|
2021-08-27 11:21:44 +02:00
|
|
|
/*
|
2021-09-03 15:09:22 +02:00
|
|
|
* Exit when return negative value
|
2021-08-27 11:21:44 +02:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_PROC_CHK_NEG(f) \
|
2021-08-18 10:38:40 +02:00
|
|
|
do { \
|
2023-01-11 14:50:10 +01:00
|
|
|
ret = (f); \
|
|
|
|
if (ret < 0) \
|
2021-08-18 10:38:40 +02:00
|
|
|
{ \
|
|
|
|
goto cleanup; \
|
|
|
|
} \
|
2023-01-11 14:50:10 +01:00
|
|
|
} while (0)
|
2021-08-18 10:38:40 +02:00
|
|
|
|
2015-05-26 12:31:46 +02:00
|
|
|
/*
|
|
|
|
* DTLS retransmission states, see RFC 6347 4.2.4
|
|
|
|
*
|
|
|
|
* The SENDING state is merged in PREPARING for initial sends,
|
|
|
|
* but is distinct for resends.
|
|
|
|
*
|
|
|
|
* Note: initial state is wrong for server, but is not used anyway.
|
|
|
|
*/
|
|
|
|
#define MBEDTLS_SSL_RETRANS_PREPARING 0
|
|
|
|
#define MBEDTLS_SSL_RETRANS_SENDING 1
|
|
|
|
#define MBEDTLS_SSL_RETRANS_WAITING 2
|
|
|
|
#define MBEDTLS_SSL_RETRANS_FINISHED 3
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow extra bytes for record, authentication and encryption overhead:
|
2021-02-19 14:27:22 +01:00
|
|
|
* counter (8) + header (5) + IV(16) + MAC (16-48) + padding (0-256).
|
2015-05-26 12:31:46 +02:00
|
|
|
*/
|
|
|
|
|
2021-05-20 14:46:20 +02:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
2020-11-30 09:56:52 +01:00
|
|
|
|
2020-07-31 12:53:39 +02:00
|
|
|
/* This macro determines whether CBC is supported. */
|
2020-07-09 12:11:39 +02:00
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC) && \
|
2023-01-11 14:50:10 +01:00
|
|
|
(defined(MBEDTLS_AES_C) || \
|
|
|
|
defined(MBEDTLS_CAMELLIA_C) || \
|
|
|
|
defined(MBEDTLS_ARIA_C) || \
|
|
|
|
defined(MBEDTLS_DES_C))
|
2020-07-09 12:11:39 +02:00
|
|
|
#define MBEDTLS_SSL_SOME_SUITES_USE_CBC
|
|
|
|
#endif
|
|
|
|
|
2020-11-30 09:56:52 +01:00
|
|
|
/* This macro determines whether a ciphersuite using a
|
|
|
|
* stream cipher can be used. */
|
|
|
|
#if defined(MBEDTLS_CIPHER_NULL_CIPHER)
|
|
|
|
#define MBEDTLS_SSL_SOME_SUITES_USE_STREAM
|
|
|
|
#endif
|
|
|
|
|
2021-05-12 17:49:18 +02:00
|
|
|
/* This macro determines whether the CBC construct used in TLS 1.2 is supported. */
|
2020-07-21 11:20:30 +02:00
|
|
|
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC) && \
|
2023-01-11 14:50:10 +01:00
|
|
|
defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
2020-07-21 11:20:30 +02:00
|
|
|
#define MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC
|
|
|
|
#endif
|
|
|
|
|
2021-03-22 12:05:58 +01:00
|
|
|
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_STREAM) || \
|
2020-07-09 12:11:39 +02:00
|
|
|
defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC)
|
2020-11-30 09:54:23 +01:00
|
|
|
#define MBEDTLS_SSL_SOME_SUITES_USE_MAC
|
2018-01-03 16:24:20 +01:00
|
|
|
#endif
|
|
|
|
|
2022-04-05 11:16:53 +02:00
|
|
|
/* This macro determines whether a ciphersuite uses Encrypt-then-MAC with CBC */
|
|
|
|
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC) && \
|
|
|
|
defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
|
|
|
|
#define MBEDTLS_SSL_SOME_SUITES_USE_CBC_ETM
|
|
|
|
#endif
|
|
|
|
|
2021-05-20 14:46:20 +02:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
2020-11-30 09:56:52 +01:00
|
|
|
|
2020-11-30 09:54:23 +01:00
|
|
|
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC)
|
2015-05-26 12:31:46 +02:00
|
|
|
/* Ciphersuites using HMAC */
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA384)
|
2015-05-26 12:31:46 +02:00
|
|
|
#define MBEDTLS_SSL_MAC_ADD 48 /* SHA-384 used for HMAC */
|
2023-03-17 12:50:01 +01:00
|
|
|
#elif defined(MBEDTLS_MD_CAN_SHA256)
|
2015-05-26 12:31:46 +02:00
|
|
|
#define MBEDTLS_SSL_MAC_ADD 32 /* SHA-256 used for HMAC */
|
|
|
|
#else
|
|
|
|
#define MBEDTLS_SSL_MAC_ADD 20 /* SHA-1 used for HMAC */
|
|
|
|
#endif
|
2020-11-30 09:54:23 +01:00
|
|
|
#else /* MBEDTLS_SSL_SOME_SUITES_USE_MAC */
|
2015-05-26 12:31:46 +02:00
|
|
|
/* AEAD ciphersuites: GCM and CCM use a 128 bits tag */
|
|
|
|
#define MBEDTLS_SSL_MAC_ADD 16
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
#define MBEDTLS_SSL_PADDING_ADD 256
|
|
|
|
#else
|
|
|
|
#define MBEDTLS_SSL_PADDING_ADD 0
|
|
|
|
#endif
|
|
|
|
|
2019-05-15 15:03:01 +02:00
|
|
|
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
2021-05-12 14:19:11 +02:00
|
|
|
#define MBEDTLS_SSL_MAX_CID_EXPANSION MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY
|
2019-05-08 16:40:11 +02:00
|
|
|
#else
|
|
|
|
#define MBEDTLS_SSL_MAX_CID_EXPANSION 0
|
|
|
|
#endif
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_PAYLOAD_OVERHEAD (MBEDTLS_MAX_IV_LENGTH + \
|
|
|
|
MBEDTLS_SSL_MAC_ADD + \
|
|
|
|
MBEDTLS_SSL_PADDING_ADD + \
|
|
|
|
MBEDTLS_SSL_MAX_CID_EXPANSION \
|
|
|
|
)
|
2016-05-25 12:56:48 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_IN_PAYLOAD_LEN (MBEDTLS_SSL_PAYLOAD_OVERHEAD + \
|
|
|
|
(MBEDTLS_SSL_IN_CONTENT_LEN))
|
2016-05-25 12:56:48 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_OUT_PAYLOAD_LEN (MBEDTLS_SSL_PAYLOAD_OVERHEAD + \
|
|
|
|
(MBEDTLS_SSL_OUT_CONTENT_LEN))
|
2016-05-25 12:56:48 +02:00
|
|
|
|
2018-08-16 14:23:47 +02:00
|
|
|
/* The maximum number of buffered handshake messages. */
|
2018-08-16 17:35:37 +02:00
|
|
|
#define MBEDTLS_SSL_MAX_BUFFERED_HS 4
|
2018-08-16 14:23:47 +02:00
|
|
|
|
2016-05-25 12:56:48 +02:00
|
|
|
/* Maximum length we can advertise as our max content length for
|
|
|
|
RFC 6066 max_fragment_length extension negotiation purposes
|
|
|
|
(the lesser of both sizes, if they are unequal.)
|
|
|
|
*/
|
|
|
|
#define MBEDTLS_TLS_EXT_ADV_CONTENT_LEN ( \
|
|
|
|
(MBEDTLS_SSL_IN_CONTENT_LEN > MBEDTLS_SSL_OUT_CONTENT_LEN) \
|
2023-01-11 14:50:10 +01:00
|
|
|
? (MBEDTLS_SSL_OUT_CONTENT_LEN) \
|
|
|
|
: (MBEDTLS_SSL_IN_CONTENT_LEN) \
|
2016-05-25 12:56:48 +02:00
|
|
|
)
|
2015-05-26 12:31:46 +02:00
|
|
|
|
2022-01-19 03:36:30 +01:00
|
|
|
/* Maximum size in bytes of list in signature algorithms ext., RFC 5246/8446 */
|
|
|
|
#define MBEDTLS_SSL_MAX_SIG_ALG_LIST_LEN 65534
|
|
|
|
|
2022-01-20 08:54:26 +01:00
|
|
|
/* Minimum size in bytes of list in signature algorithms ext., RFC 5246/8446 */
|
2022-01-19 03:36:30 +01:00
|
|
|
#define MBEDTLS_SSL_MIN_SIG_ALG_LIST_LEN 2
|
2017-04-12 15:54:42 +02:00
|
|
|
|
|
|
|
/* Maximum size in bytes of list in supported elliptic curve ext., RFC 4492 */
|
|
|
|
#define MBEDTLS_SSL_MAX_CURVE_LIST_LEN 65535
|
|
|
|
|
2022-01-28 07:37:15 +01:00
|
|
|
#define MBEDTLS_RECEIVED_SIG_ALGS_SIZE 20
|
2022-01-26 10:21:54 +01:00
|
|
|
|
2022-10-05 12:46:29 +02:00
|
|
|
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
2022-05-09 16:37:58 +02:00
|
|
|
|
2022-05-10 12:51:14 +02:00
|
|
|
#define MBEDTLS_TLS_SIG_NONE MBEDTLS_TLS1_3_SIG_NONE
|
|
|
|
|
2022-05-09 16:37:58 +02:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_TLS12_SIG_AND_HASH_ALG(sig, hash) ((hash << 8) | sig)
|
2022-05-10 12:59:00 +02:00
|
|
|
#define MBEDTLS_SSL_TLS12_SIG_ALG_FROM_SIG_AND_HASH_ALG(alg) (alg & 0xFF)
|
|
|
|
#define MBEDTLS_SSL_TLS12_HASH_ALG_FROM_SIG_AND_HASH_ALG(alg) (alg >> 8)
|
2022-05-09 16:37:58 +02:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
|
|
|
|
2022-10-05 12:46:29 +02:00
|
|
|
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
2022-05-09 16:37:58 +02:00
|
|
|
|
2017-09-18 11:54:39 +02:00
|
|
|
/*
|
|
|
|
* Check that we obey the standard's message size bounds
|
|
|
|
*/
|
|
|
|
|
2021-05-04 19:36:56 +02:00
|
|
|
#if MBEDTLS_SSL_IN_CONTENT_LEN > 16384
|
|
|
|
#error "Bad configuration - incoming record content too large."
|
2017-09-18 11:54:39 +02:00
|
|
|
#endif
|
|
|
|
|
2021-05-04 19:36:56 +02:00
|
|
|
#if MBEDTLS_SSL_OUT_CONTENT_LEN > 16384
|
|
|
|
#error "Bad configuration - outgoing record content too large."
|
2016-05-25 12:56:48 +02:00
|
|
|
#endif
|
|
|
|
|
2021-05-04 19:36:56 +02:00
|
|
|
#if MBEDTLS_SSL_IN_PAYLOAD_LEN > MBEDTLS_SSL_IN_CONTENT_LEN + 2048
|
2016-05-25 12:56:48 +02:00
|
|
|
#error "Bad configuration - incoming protected record payload too large."
|
2017-09-18 11:54:39 +02:00
|
|
|
#endif
|
|
|
|
|
2021-05-04 19:36:56 +02:00
|
|
|
#if MBEDTLS_SSL_OUT_PAYLOAD_LEN > MBEDTLS_SSL_OUT_CONTENT_LEN + 2048
|
2016-05-25 12:56:48 +02:00
|
|
|
#error "Bad configuration - outgoing protected record payload too large."
|
2017-09-18 11:54:39 +02:00
|
|
|
#endif
|
|
|
|
|
2016-05-25 12:56:48 +02:00
|
|
|
/* Calculate buffer sizes */
|
|
|
|
|
2017-12-07 09:22:51 +01:00
|
|
|
/* Note: Even though the TLS record header is only 5 bytes
|
|
|
|
long, we're internally using 8 bytes to store the
|
|
|
|
implicit sequence number. */
|
2017-10-04 14:56:42 +02:00
|
|
|
#define MBEDTLS_SSL_HEADER_LEN 13
|
2017-09-18 11:54:39 +02:00
|
|
|
|
2020-03-03 11:57:59 +01:00
|
|
|
#if !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
2016-05-25 12:56:48 +02:00
|
|
|
#define MBEDTLS_SSL_IN_BUFFER_LEN \
|
2023-01-11 14:50:10 +01:00
|
|
|
((MBEDTLS_SSL_HEADER_LEN) + (MBEDTLS_SSL_IN_PAYLOAD_LEN))
|
2019-05-08 16:40:11 +02:00
|
|
|
#else
|
|
|
|
#define MBEDTLS_SSL_IN_BUFFER_LEN \
|
2023-01-11 14:50:10 +01:00
|
|
|
((MBEDTLS_SSL_HEADER_LEN) + (MBEDTLS_SSL_IN_PAYLOAD_LEN) \
|
|
|
|
+ (MBEDTLS_SSL_CID_IN_LEN_MAX))
|
2019-05-08 16:40:11 +02:00
|
|
|
#endif
|
2016-05-25 12:56:48 +02:00
|
|
|
|
2020-03-03 11:57:59 +01:00
|
|
|
#if !defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
2016-05-25 12:56:48 +02:00
|
|
|
#define MBEDTLS_SSL_OUT_BUFFER_LEN \
|
2023-01-11 14:50:10 +01:00
|
|
|
((MBEDTLS_SSL_HEADER_LEN) + (MBEDTLS_SSL_OUT_PAYLOAD_LEN))
|
2019-05-08 16:40:11 +02:00
|
|
|
#else
|
|
|
|
#define MBEDTLS_SSL_OUT_BUFFER_LEN \
|
2023-01-11 14:50:10 +01:00
|
|
|
((MBEDTLS_SSL_HEADER_LEN) + (MBEDTLS_SSL_OUT_PAYLOAD_LEN) \
|
|
|
|
+ (MBEDTLS_SSL_CID_OUT_LEN_MAX))
|
2019-05-08 16:40:11 +02:00
|
|
|
#endif
|
2016-05-25 12:56:48 +02:00
|
|
|
|
2021-10-26 04:44:32 +02:00
|
|
|
#define MBEDTLS_CLIENT_HELLO_RANDOM_LEN 32
|
|
|
|
#define MBEDTLS_SERVER_HELLO_RANDOM_LEN 32
|
|
|
|
|
2021-04-21 06:54:33 +02:00
|
|
|
#if defined(MBEDTLS_SSL_MAX_FRAGMENT_LENGTH)
|
|
|
|
/**
|
|
|
|
* \brief Return the maximum fragment length (payload, in bytes) for
|
|
|
|
* the output buffer. For the client, this is the configured
|
|
|
|
* value. For the server, it is the minimum of two - the
|
|
|
|
* configured value and the negotiated one.
|
|
|
|
*
|
|
|
|
* \sa mbedtls_ssl_conf_max_frag_len()
|
|
|
|
* \sa mbedtls_ssl_get_max_out_record_payload()
|
|
|
|
*
|
|
|
|
* \param ssl SSL context
|
|
|
|
*
|
|
|
|
* \return Current maximum fragment length for the output buffer.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t mbedtls_ssl_get_output_max_frag_len(const mbedtls_ssl_context *ssl);
|
2021-04-21 06:54:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Return the maximum fragment length (payload, in bytes) for
|
|
|
|
* the input buffer. This is the negotiated maximum fragment
|
2021-06-08 06:30:45 +02:00
|
|
|
* length, or, if there is none, MBEDTLS_SSL_IN_CONTENT_LEN.
|
2021-04-21 06:54:33 +02:00
|
|
|
* If it is not defined either, the value is 2^14. This function
|
|
|
|
* works as its predecessor, \c mbedtls_ssl_get_max_frag_len().
|
|
|
|
*
|
|
|
|
* \sa mbedtls_ssl_conf_max_frag_len()
|
|
|
|
* \sa mbedtls_ssl_get_max_in_record_payload()
|
|
|
|
*
|
|
|
|
* \param ssl SSL context
|
|
|
|
*
|
|
|
|
* \return Current maximum fragment length for the output buffer.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t mbedtls_ssl_get_input_max_frag_len(const mbedtls_ssl_context *ssl);
|
2021-04-21 06:54:33 +02:00
|
|
|
#endif /* MBEDTLS_SSL_MAX_FRAGMENT_LENGTH */
|
|
|
|
|
2020-03-03 16:39:58 +01:00
|
|
|
#if defined(MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH)
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline size_t mbedtls_ssl_get_output_buflen(const mbedtls_ssl_context *ctx)
|
2020-03-03 16:39:58 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
|
|
|
return mbedtls_ssl_get_output_max_frag_len(ctx)
|
|
|
|
+ MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD
|
|
|
|
+ MBEDTLS_SSL_CID_OUT_LEN_MAX;
|
2020-03-03 16:39:58 +01:00
|
|
|
#else
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_get_output_max_frag_len(ctx)
|
|
|
|
+ MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD;
|
2020-03-03 16:39:58 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline size_t mbedtls_ssl_get_input_buflen(const mbedtls_ssl_context *ctx)
|
2020-03-03 16:39:58 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
|
|
|
return mbedtls_ssl_get_input_max_frag_len(ctx)
|
|
|
|
+ MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD
|
|
|
|
+ MBEDTLS_SSL_CID_IN_LEN_MAX;
|
2020-03-03 16:39:58 +01:00
|
|
|
#else
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_get_input_max_frag_len(ctx)
|
|
|
|
+ MBEDTLS_SSL_HEADER_LEN + MBEDTLS_SSL_PAYLOAD_OVERHEAD;
|
2020-03-03 16:39:58 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-26 12:31:46 +02:00
|
|
|
/*
|
|
|
|
* TLS extension flags (for extensions with outgoing ServerHello content
|
|
|
|
* that need it (e.g. for RENEGOTIATION_INFO the server already knows because
|
|
|
|
* of state of the renegotiation flag, so no indicator is required)
|
|
|
|
*/
|
|
|
|
#define MBEDTLS_TLS_EXT_SUPPORTED_POINT_FORMATS_PRESENT (1 << 0)
|
2015-09-16 15:04:01 +02:00
|
|
|
#define MBEDTLS_TLS_EXT_ECJPAKE_KKPP_OK (1 << 1)
|
2015-05-26 12:31:46 +02:00
|
|
|
|
2017-04-12 15:54:42 +02:00
|
|
|
/**
|
|
|
|
* \brief This function checks if the remaining size in a buffer is
|
|
|
|
* greater or equal than a needed space.
|
|
|
|
*
|
|
|
|
* \param cur Pointer to the current position in the buffer.
|
|
|
|
* \param end Pointer to one past the end of the buffer.
|
|
|
|
* \param need Needed space in bytes.
|
|
|
|
*
|
2020-06-11 09:50:51 +02:00
|
|
|
* \return Zero if the needed space is available in the buffer, non-zero
|
2017-04-12 15:54:42 +02:00
|
|
|
* otherwise.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#if !defined(MBEDTLS_TEST_HOOKS)
|
|
|
|
static inline int mbedtls_ssl_chk_buf_ptr(const uint8_t *cur,
|
|
|
|
const uint8_t *end, size_t need)
|
2017-04-12 15:54:42 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return (cur > end) || (need > (size_t) (end - cur));
|
2017-04-12 15:54:42 +02:00
|
|
|
}
|
2022-06-10 17:18:09 +02:00
|
|
|
#else
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef struct {
|
2022-06-10 17:18:09 +02:00
|
|
|
const uint8_t *cur;
|
|
|
|
const uint8_t *end;
|
|
|
|
size_t need;
|
|
|
|
} mbedtls_ssl_chk_buf_ptr_args;
|
|
|
|
|
|
|
|
void mbedtls_ssl_set_chk_buf_ptr_fail_args(
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint8_t *cur, const uint8_t *end, size_t need);
|
|
|
|
void mbedtls_ssl_reset_chk_buf_ptr_fail_args(void);
|
2022-07-08 18:56:49 +02:00
|
|
|
|
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_cmp_chk_buf_ptr_fail_args(mbedtls_ssl_chk_buf_ptr_args *args);
|
2022-06-10 17:18:09 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_chk_buf_ptr(const uint8_t *cur,
|
|
|
|
const uint8_t *end, size_t need)
|
2022-06-10 17:18:09 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
if ((cur > end) || (need > (size_t) (end - cur))) {
|
|
|
|
mbedtls_ssl_set_chk_buf_ptr_fail_args(cur, end, need);
|
|
|
|
return 1;
|
2022-06-10 17:18:09 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-06-10 17:18:09 +02:00
|
|
|
}
|
2022-06-17 15:54:16 +02:00
|
|
|
#endif /* MBEDTLS_TEST_HOOKS */
|
2017-04-12 15:54:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief This macro checks if the remaining size in a buffer is
|
|
|
|
* greater or equal than a needed space. If it is not the case,
|
|
|
|
* it returns an SSL_BUFFER_TOO_SMALL error.
|
|
|
|
*
|
|
|
|
* \param cur Pointer to the current position in the buffer.
|
|
|
|
* \param end Pointer to one past the end of the buffer.
|
|
|
|
* \param need Needed space in bytes.
|
|
|
|
*
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_CHK_BUF_PTR(cur, end, need) \
|
2017-04-12 15:54:42 +02:00
|
|
|
do { \
|
2023-01-11 14:50:10 +01:00
|
|
|
if (mbedtls_ssl_chk_buf_ptr((cur), (end), (need)) != 0) \
|
2017-04-12 15:54:42 +02:00
|
|
|
{ \
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL; \
|
2017-04-12 15:54:42 +02:00
|
|
|
} \
|
2023-01-11 14:50:10 +01:00
|
|
|
} while (0)
|
2017-04-12 15:54:42 +02:00
|
|
|
|
2021-09-19 12:05:08 +02:00
|
|
|
/**
|
2021-09-28 15:06:07 +02:00
|
|
|
* \brief This macro checks if the remaining length in an input buffer is
|
|
|
|
* greater or equal than a needed length. If it is not the case, it
|
2021-10-08 10:16:24 +02:00
|
|
|
* returns #MBEDTLS_ERR_SSL_DECODE_ERROR error and pends a
|
2021-10-08 08:19:29 +02:00
|
|
|
* #MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR alert message.
|
2021-10-09 04:40:40 +02:00
|
|
|
*
|
|
|
|
* This is a function-like macro. It is guaranteed to evaluate each
|
|
|
|
* argument exactly once.
|
2021-09-19 12:05:08 +02:00
|
|
|
*
|
|
|
|
* \param cur Pointer to the current position in the buffer.
|
|
|
|
* \param end Pointer to one past the end of the buffer.
|
2021-09-28 15:06:07 +02:00
|
|
|
* \param need Needed length in bytes.
|
2021-09-19 12:05:08 +02:00
|
|
|
*
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_CHK_BUF_READ_PTR(cur, end, need) \
|
2021-09-19 12:05:08 +02:00
|
|
|
do { \
|
2023-01-11 14:50:10 +01:00
|
|
|
if (mbedtls_ssl_chk_buf_ptr((cur), (end), (need)) != 0) \
|
2021-09-19 12:05:08 +02:00
|
|
|
{ \
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_SSL_DEBUG_MSG(1, \
|
|
|
|
("missing input data in %s", __func__)); \
|
|
|
|
MBEDTLS_SSL_PEND_FATAL_ALERT(MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR, \
|
|
|
|
MBEDTLS_ERR_SSL_DECODE_ERROR); \
|
|
|
|
return MBEDTLS_ERR_SSL_DECODE_ERROR; \
|
2021-09-19 12:05:08 +02:00
|
|
|
} \
|
2023-01-11 14:50:10 +01:00
|
|
|
} while (0)
|
2021-09-19 12:05:08 +02:00
|
|
|
|
2015-05-26 11:57:05 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef int mbedtls_ssl_tls_prf_cb(const unsigned char *secret, size_t slen,
|
|
|
|
const char *label,
|
|
|
|
const unsigned char *random, size_t rlen,
|
|
|
|
unsigned char *dstbuf, size_t dlen);
|
2020-08-21 14:03:34 +02:00
|
|
|
|
2020-09-16 10:24:14 +02:00
|
|
|
/* cipher.h exports the maximum IV, key and block length from
|
2020-09-08 12:29:11 +02:00
|
|
|
* all ciphers enabled in the config, regardless of whether those
|
|
|
|
* ciphers are actually usable in SSL/TLS. Notably, XTS is enabled
|
|
|
|
* in the default configuration and uses 64 Byte keys, but it is
|
|
|
|
* not used for record protection in SSL/TLS.
|
|
|
|
*
|
|
|
|
* In order to prevent unnecessary inflation of key structures,
|
|
|
|
* we introduce SSL-specific variants of the max-{key,block,IV}
|
|
|
|
* macros here which are meant to only take those ciphers into
|
|
|
|
* account which can be negotiated in SSL/TLS.
|
|
|
|
*
|
|
|
|
* Since the current definitions of MBEDTLS_MAX_{KEY|BLOCK|IV}_LENGTH
|
|
|
|
* in cipher.h are rough overapproximations of the real maxima, here
|
2020-09-09 10:24:54 +02:00
|
|
|
* we content ourselves with replicating those overapproximations
|
2020-09-08 12:29:11 +02:00
|
|
|
* for the maximum block and IV length, and excluding XTS from the
|
|
|
|
* computation of the maximum key length. */
|
|
|
|
#define MBEDTLS_SSL_MAX_BLOCK_LENGTH 16
|
|
|
|
#define MBEDTLS_SSL_MAX_IV_LENGTH 16
|
|
|
|
#define MBEDTLS_SSL_MAX_KEY_LENGTH 32
|
|
|
|
|
2020-08-21 14:03:34 +02:00
|
|
|
/**
|
|
|
|
* \brief The data structure holding the cryptographic material (key and IV)
|
|
|
|
* used for record protection in TLS 1.3.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
struct mbedtls_ssl_key_set {
|
2020-08-21 14:03:34 +02:00
|
|
|
/*! The key for client->server records. */
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char client_write_key[MBEDTLS_SSL_MAX_KEY_LENGTH];
|
2020-08-21 14:03:34 +02:00
|
|
|
/*! The key for server->client records. */
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char server_write_key[MBEDTLS_SSL_MAX_KEY_LENGTH];
|
2020-08-21 14:03:34 +02:00
|
|
|
/*! The IV for client->server records. */
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char client_write_iv[MBEDTLS_SSL_MAX_IV_LENGTH];
|
2020-08-21 14:03:34 +02:00
|
|
|
/*! The IV for server->client records. */
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char server_write_iv[MBEDTLS_SSL_MAX_IV_LENGTH];
|
2020-08-21 14:03:34 +02:00
|
|
|
|
2020-09-08 12:01:00 +02:00
|
|
|
size_t key_len; /*!< The length of client_write_key and
|
|
|
|
* server_write_key, in Bytes. */
|
|
|
|
size_t iv_len; /*!< The length of client_write_iv and
|
|
|
|
* server_write_iv, in Bytes. */
|
2020-08-21 14:03:34 +02:00
|
|
|
};
|
|
|
|
typedef struct mbedtls_ssl_key_set mbedtls_ssl_key_set;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef struct {
|
|
|
|
unsigned char binder_key[MBEDTLS_TLS1_3_MD_MAX_SIZE];
|
|
|
|
unsigned char client_early_traffic_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE];
|
|
|
|
unsigned char early_exporter_master_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE];
|
2021-11-12 09:53:56 +01:00
|
|
|
} mbedtls_ssl_tls13_early_secrets;
|
2021-09-16 12:59:08 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef struct {
|
|
|
|
unsigned char client_handshake_traffic_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE];
|
|
|
|
unsigned char server_handshake_traffic_secret[MBEDTLS_TLS1_3_MD_MAX_SIZE];
|
2021-11-12 09:53:56 +01:00
|
|
|
} mbedtls_ssl_tls13_handshake_secrets;
|
2021-09-16 12:59:08 +02:00
|
|
|
|
2015-05-26 12:11:48 +02:00
|
|
|
/*
|
|
|
|
* This structure contains the parameters only needed during handshake.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
struct mbedtls_ssl_handshake_params {
|
2021-11-29 12:18:09 +01:00
|
|
|
/* Frequently-used boolean or byte fields (placed early to take
|
|
|
|
* advantage of smaller code size for indirect access on Arm Thumb) */
|
|
|
|
uint8_t resume; /*!< session resume indicator*/
|
|
|
|
uint8_t cli_exts; /*!< client extension presence*/
|
|
|
|
|
2022-04-12 13:31:46 +02:00
|
|
|
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
|
|
|
|
uint8_t sni_authmode; /*!< authmode from SNI callback */
|
|
|
|
#endif
|
|
|
|
|
2022-05-10 10:12:17 +02:00
|
|
|
#if defined(MBEDTLS_SSL_SRV_C)
|
2022-05-13 07:55:41 +02:00
|
|
|
/* Flag indicating if a CertificateRequest message has been sent
|
|
|
|
* to the client or not. */
|
2022-05-15 06:26:57 +02:00
|
|
|
uint8_t certificate_request_sent;
|
2022-05-10 10:12:17 +02:00
|
|
|
#endif /* MBEDTLS_SSL_SRV_C */
|
|
|
|
|
2022-04-12 13:31:46 +02:00
|
|
|
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
|
|
|
uint8_t new_session_ticket; /*!< use NewSessionTicket? */
|
|
|
|
#endif /* MBEDTLS_SSL_SESSION_TICKETS */
|
|
|
|
|
2022-03-31 15:44:41 +02:00
|
|
|
#if defined(MBEDTLS_SSL_CLI_C)
|
2022-04-04 10:23:22 +02:00
|
|
|
/** Minimum TLS version to be negotiated.
|
2022-03-31 15:37:44 +02:00
|
|
|
*
|
2022-04-04 10:23:22 +02:00
|
|
|
* It is set up in the ClientHello writing preparation stage and used
|
|
|
|
* throughout the ClientHello writing. Not relevant anymore as soon as
|
|
|
|
* the protocol version has been negotiated thus as soon as the
|
|
|
|
* ServerHello is received.
|
|
|
|
* For a fresh handshake not linked to any previous handshake, it is
|
|
|
|
* equal to the configured minimum minor version to be negotiated. When
|
|
|
|
* renegotiating or resuming a session, it is equal to the previously
|
|
|
|
* negotiated minor version.
|
2022-03-31 15:37:44 +02:00
|
|
|
*
|
2022-04-04 10:23:22 +02:00
|
|
|
* There is no maximum TLS version field in this handshake context.
|
|
|
|
* From the start of the handshake, we need to define a current protocol
|
|
|
|
* version for the record layer which we define as the maximum TLS
|
|
|
|
* version to be negotiated. The `tls_version` field of the SSL context is
|
|
|
|
* used to store this maximum value until it contains the actual
|
|
|
|
* negotiated value.
|
2022-03-31 15:37:44 +02:00
|
|
|
*/
|
2022-04-12 13:31:46 +02:00
|
|
|
mbedtls_ssl_protocol_version min_tls_version;
|
2022-03-31 15:44:41 +02:00
|
|
|
#endif
|
2022-02-18 17:45:10 +01:00
|
|
|
|
2021-11-29 12:18:09 +01:00
|
|
|
#if defined(MBEDTLS_SSL_EXTENDED_MASTER_SECRET)
|
|
|
|
uint8_t extended_ms; /*!< use Extended Master Secret? */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
|
|
|
uint8_t async_in_progress; /*!< an asynchronous operation is in progress */
|
|
|
|
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
|
|
|
unsigned char retransmit_state; /*!< Retransmission state */
|
|
|
|
#endif
|
|
|
|
|
2021-12-08 18:25:39 +01:00
|
|
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
|
|
|
unsigned char group_list_heap_allocated;
|
2022-01-12 08:49:48 +01:00
|
|
|
unsigned char sig_algs_heap_allocated;
|
2021-12-08 18:25:39 +01:00
|
|
|
#endif
|
|
|
|
|
2021-11-29 12:18:09 +01:00
|
|
|
#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
|
|
|
|
uint8_t ecrs_enabled; /*!< Handshake supports EC restart? */
|
|
|
|
enum { /* this complements ssl->state with info on intra-state operations */
|
|
|
|
ssl_ecrs_none = 0, /*!< nothing going on (yet) */
|
|
|
|
ssl_ecrs_crt_verify, /*!< Certificate: crt_verify() */
|
|
|
|
ssl_ecrs_ske_start_processing, /*!< ServerKeyExchange: pk_verify() */
|
|
|
|
ssl_ecrs_cke_ecdh_calc_secret, /*!< ClientKeyExchange: ECDH step 2 */
|
|
|
|
ssl_ecrs_crt_vrfy_sign, /*!< CertificateVerify: pk_sign() */
|
|
|
|
} ecrs_state; /*!< current (or last) operation */
|
|
|
|
mbedtls_x509_crt *ecrs_peer_cert; /*!< The peer's CRT chain. */
|
|
|
|
size_t ecrs_n; /*!< place for saving a length */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mbedtls_ssl_ciphersuite_t const *ciphersuite_info;
|
|
|
|
|
2023-02-06 00:34:21 +01:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
Make handshake hashing functions return int
There are three family of functions: update_checksum, calc_verify,
calc_finished, that perform hashing operations and were returning void
so far. This is not correct, as hashing functions can return errors (for
example, on hardware failure when accelerated). Change them to return
int.
This commit just changes the types: for now the functions always return
0, and their return value is not checked; this will be fixed in the
next few commits.
There is a related function in TLS 1.3,
mbedtls_ssl_reset_transcript_for_hrr, which also handles hashes, and
already returns int but does not correctly check for errors from hashing
functions so far, it will also be handled in the next few commits.
There's a special case with handshake_params_init: _init functions
should return void, so we'll need to split out the part that can return
errors, see the next commit.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-02-05 09:46:59 +01:00
|
|
|
int (*update_checksum)(mbedtls_ssl_context *, const unsigned char *, size_t);
|
2023-02-06 00:34:21 +01:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
Make handshake hashing functions return int
There are three family of functions: update_checksum, calc_verify,
calc_finished, that perform hashing operations and were returning void
so far. This is not correct, as hashing functions can return errors (for
example, on hardware failure when accelerated). Change them to return
int.
This commit just changes the types: for now the functions always return
0, and their return value is not checked; this will be fixed in the
next few commits.
There is a related function in TLS 1.3,
mbedtls_ssl_reset_transcript_for_hrr, which also handles hashes, and
already returns int but does not correctly check for errors from hashing
functions so far, it will also be handled in the next few commits.
There's a special case with handshake_params_init: _init functions
should return void, so we'll need to split out the part that can return
errors, see the next commit.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-02-05 09:46:59 +01:00
|
|
|
int (*calc_verify)(const mbedtls_ssl_context *, unsigned char *, size_t *);
|
2023-02-06 00:34:21 +01:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
Make handshake hashing functions return int
There are three family of functions: update_checksum, calc_verify,
calc_finished, that perform hashing operations and were returning void
so far. This is not correct, as hashing functions can return errors (for
example, on hardware failure when accelerated). Change them to return
int.
This commit just changes the types: for now the functions always return
0, and their return value is not checked; this will be fixed in the
next few commits.
There is a related function in TLS 1.3,
mbedtls_ssl_reset_transcript_for_hrr, which also handles hashes, and
already returns int but does not correctly check for errors from hashing
functions so far, it will also be handled in the next few commits.
There's a special case with handshake_params_init: _init functions
should return void, so we'll need to split out the part that can return
errors, see the next commit.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-02-05 09:46:59 +01:00
|
|
|
int (*calc_finished)(mbedtls_ssl_context *, unsigned char *, int);
|
2021-11-29 12:18:09 +01:00
|
|
|
mbedtls_ssl_tls_prf_cb *tls_prf;
|
|
|
|
|
2015-05-26 12:11:48 +02:00
|
|
|
/*
|
|
|
|
* Handshake specific crypto variables
|
|
|
|
*/
|
2021-12-08 16:57:54 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2022-07-20 16:44:00 +02:00
|
|
|
uint8_t key_exchange_mode; /*!< Selected key exchange mode */
|
2017-04-28 18:15:26 +02:00
|
|
|
|
2022-05-05 05:14:19 +02:00
|
|
|
/** Number of HelloRetryRequest messages received/sent from/to the server. */
|
2022-01-18 07:23:32 +01:00
|
|
|
int hello_retry_request_count;
|
2022-07-21 09:35:20 +02:00
|
|
|
|
2022-04-20 09:16:41 +02:00
|
|
|
#if defined(MBEDTLS_SSL_SRV_C)
|
2022-04-20 11:43:51 +02:00
|
|
|
/** selected_group of key_share extension in HelloRetryRequest message. */
|
2022-04-20 09:16:41 +02:00
|
|
|
uint16_t hrr_selected_group;
|
2022-10-04 16:38:25 +02:00
|
|
|
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED)
|
2022-07-21 09:35:20 +02:00
|
|
|
uint8_t tls13_kex_modes; /*!< Key exchange modes supported by the client */
|
|
|
|
#endif
|
2022-08-09 07:33:50 +02:00
|
|
|
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
2022-09-22 17:30:49 +02:00
|
|
|
uint16_t new_session_tickets_count; /*!< number of session tickets */
|
2022-08-09 07:33:50 +02:00
|
|
|
#endif
|
2022-04-20 09:16:41 +02:00
|
|
|
#endif /* MBEDTLS_SSL_SRV_C */
|
2022-07-21 09:35:20 +02:00
|
|
|
|
2022-04-22 15:59:01 +02:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
|
2022-04-20 09:16:41 +02:00
|
|
|
|
2022-10-05 12:46:29 +02:00
|
|
|
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
2022-01-28 07:37:15 +01:00
|
|
|
uint16_t received_sig_algs[MBEDTLS_RECEIVED_SIG_ALGS_SIZE];
|
|
|
|
#endif
|
|
|
|
|
2021-12-08 18:25:39 +01:00
|
|
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
|
|
|
const uint16_t *group_list;
|
2022-01-12 08:49:48 +01:00
|
|
|
const uint16_t *sig_algs;
|
2021-12-08 18:25:39 +01:00
|
|
|
#endif
|
|
|
|
|
2015-05-26 12:11:48 +02:00
|
|
|
#if defined(MBEDTLS_DHM_C)
|
|
|
|
mbedtls_dhm_context dhm_ctx; /*!< DHM key exchange */
|
|
|
|
#endif
|
2021-11-16 15:21:44 +01:00
|
|
|
|
2020-11-17 07:08:34 +01:00
|
|
|
/* Adding guard for MBEDTLS_ECDSA_C to ensure no compile errors due
|
2022-03-07 16:20:30 +01:00
|
|
|
* to guards in client and server code. There is a gap in functionality that
|
|
|
|
* access to ecdh_ctx structure is needed for MBEDTLS_ECDSA_C which does not
|
|
|
|
* seem correct.
|
2020-11-17 07:08:34 +01:00
|
|
|
*/
|
|
|
|
#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C)
|
2022-04-13 15:12:43 +02:00
|
|
|
#if !defined(MBEDTLS_USE_PSA_CRYPTO)
|
2015-05-26 12:11:48 +02:00
|
|
|
mbedtls_ecdh_context ecdh_ctx; /*!< ECDH key exchange */
|
2022-04-13 15:12:43 +02:00
|
|
|
#endif /* !MBEDTLS_USE_PSA_CRYPTO */
|
2023-03-23 08:36:00 +01:00
|
|
|
#endif /* MBEDTLS_ECDH_C || MBEDTLS_ECDSA_C */
|
2019-02-18 17:41:55 +01:00
|
|
|
|
2023-03-23 08:36:00 +01:00
|
|
|
#if defined(PSA_WANT_ALG_ECDH) && \
|
|
|
|
(defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3))
|
2019-12-19 13:31:53 +01:00
|
|
|
psa_key_type_t ecdh_psa_type;
|
2022-03-25 15:42:20 +01:00
|
|
|
size_t ecdh_bits;
|
2022-01-03 12:53:24 +01:00
|
|
|
mbedtls_svc_key_id_t ecdh_psa_privkey;
|
2022-04-04 11:23:46 +02:00
|
|
|
uint8_t ecdh_psa_privkey_is_external;
|
2019-02-18 17:41:55 +01:00
|
|
|
unsigned char ecdh_psa_peerkey[MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH];
|
|
|
|
size_t ecdh_psa_peerkey_len;
|
2023-03-23 08:36:00 +01:00
|
|
|
#endif /* PSA_WANT_ALG_ECDH &&
|
|
|
|
(MBEDTLS_USE_PSA_CRYPTO || MBEDTLS_SSL_PROTO_TLS1_3) */
|
2019-02-18 17:41:55 +01:00
|
|
|
|
2015-09-16 10:05:04 +02:00
|
|
|
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
2022-05-31 14:43:23 +02:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
|
|
|
psa_pake_operation_t psa_pake_ctx; /*!< EC J-PAKE key exchange */
|
|
|
|
mbedtls_svc_key_id_t psa_pake_password;
|
|
|
|
uint8_t psa_pake_ctx_is_ok;
|
|
|
|
#else
|
2015-09-15 12:10:54 +02:00
|
|
|
mbedtls_ecjpake_context ecjpake_ctx; /*!< EC J-PAKE key exchange */
|
2022-05-31 14:43:23 +02:00
|
|
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
2015-09-17 13:59:49 +02:00
|
|
|
#if defined(MBEDTLS_SSL_CLI_C)
|
|
|
|
unsigned char *ecjpake_cache; /*!< Cache for ClientHello ext */
|
|
|
|
size_t ecjpake_cache_len; /*!< Length of cached data */
|
|
|
|
#endif
|
2017-04-28 18:08:27 +02:00
|
|
|
#endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */
|
2021-11-16 15:21:44 +01:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_ECDH_C) || defined(MBEDTLS_ECDSA_C) || \
|
2015-09-16 10:05:04 +02:00
|
|
|
defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)
|
2022-12-30 17:44:24 +01:00
|
|
|
uint16_t *curves_tls_id; /*!< List of TLS IDs of supported elliptic curves */
|
2015-05-26 12:11:48 +02:00
|
|
|
#endif
|
2021-11-16 15:21:44 +01:00
|
|
|
|
2022-10-05 14:31:43 +02:00
|
|
|
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
2018-10-22 16:29:46 +02:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
2022-01-03 12:53:24 +01:00
|
|
|
mbedtls_svc_key_id_t psk_opaque; /*!< Opaque PSK from the callback */
|
2022-05-03 09:35:09 +02:00
|
|
|
uint8_t psk_opaque_is_internal;
|
2022-05-03 10:22:14 +02:00
|
|
|
#else
|
2015-05-26 12:11:48 +02:00
|
|
|
unsigned char *psk; /*!< PSK from the callback */
|
|
|
|
size_t psk_len; /*!< Length of PSK from callback */
|
2022-05-03 10:22:14 +02:00
|
|
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
2022-07-21 09:11:34 +02:00
|
|
|
uint16_t selected_identity;
|
2022-10-05 14:31:43 +02:00
|
|
|
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
|
2021-11-16 15:21:44 +01:00
|
|
|
|
2021-12-08 18:38:51 +01:00
|
|
|
#if defined(MBEDTLS_SSL_ECP_RESTARTABLE_ENABLED)
|
|
|
|
mbedtls_x509_crt_restart_ctx ecrs_ctx; /*!< restart context */
|
|
|
|
#endif
|
|
|
|
|
2015-05-26 12:11:48 +02:00
|
|
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
|
|
|
mbedtls_ssl_key_cert *key_cert; /*!< chosen key/cert pair (server) */
|
|
|
|
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
|
|
|
|
mbedtls_ssl_key_cert *sni_key_cert; /*!< key/cert list from SNI */
|
|
|
|
mbedtls_x509_crt *sni_ca_chain; /*!< trusted CAs from SNI callback */
|
|
|
|
mbedtls_x509_crl *sni_ca_crl; /*!< trusted CAs CRLs from SNI */
|
2017-04-28 18:08:27 +02:00
|
|
|
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
|
2015-05-26 12:11:48 +02:00
|
|
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
2021-11-16 15:21:44 +01:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
2019-02-06 17:18:31 +01:00
|
|
|
!defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
|
|
|
mbedtls_pk_context peer_pubkey; /*!< The public key from the peer. */
|
|
|
|
#endif /* MBEDTLS_X509_CRT_PARSE_C && !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
2021-11-16 15:21:44 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
struct {
|
2021-11-29 12:18:09 +01:00
|
|
|
size_t total_bytes_buffered; /*!< Cumulative size of heap allocated
|
|
|
|
* buffers used for message buffering. */
|
|
|
|
|
|
|
|
uint8_t seen_ccs; /*!< Indicates if a CCS message has
|
|
|
|
* been seen in the current flight. */
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
struct mbedtls_ssl_hs_buffer {
|
2021-11-29 12:18:09 +01:00
|
|
|
unsigned is_valid : 1;
|
|
|
|
unsigned is_fragmented : 1;
|
|
|
|
unsigned is_complete : 1;
|
|
|
|
unsigned char *data;
|
|
|
|
size_t data_len;
|
|
|
|
} hs[MBEDTLS_SSL_MAX_BUFFERED_HS];
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
struct {
|
2021-11-29 12:18:09 +01:00
|
|
|
unsigned char *data;
|
|
|
|
size_t len;
|
|
|
|
unsigned epoch;
|
|
|
|
} future_record;
|
|
|
|
|
|
|
|
} buffering;
|
|
|
|
|
2022-02-09 07:02:25 +01:00
|
|
|
#if defined(MBEDTLS_SSL_CLI_C) && \
|
2023-01-11 14:50:10 +01:00
|
|
|
(defined(MBEDTLS_SSL_PROTO_DTLS) || \
|
|
|
|
defined(MBEDTLS_SSL_PROTO_TLS1_3))
|
2022-03-04 05:50:46 +01:00
|
|
|
unsigned char *cookie; /*!< HelloVerifyRequest cookie for DTLS
|
|
|
|
* HelloRetryRequest cookie for TLS 1.3 */
|
|
|
|
#if !defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
|
|
|
/* RFC 6347 page 15
|
|
|
|
...
|
|
|
|
opaque cookie<0..2^8-1>;
|
|
|
|
...
|
|
|
|
*/
|
|
|
|
uint8_t cookie_len;
|
|
|
|
#else
|
|
|
|
/* RFC 8446 page 39
|
|
|
|
...
|
|
|
|
opaque cookie<0..2^16-1>;
|
|
|
|
...
|
|
|
|
If TLS1_3 is enabled, the max length is 2^16 - 1
|
|
|
|
*/
|
|
|
|
uint16_t cookie_len; /*!< DTLS: HelloVerifyRequest cookie length
|
|
|
|
* TLS1_3: HelloRetryRequest cookie length */
|
|
|
|
#endif
|
2022-02-09 07:02:25 +01:00
|
|
|
#endif /* MBEDTLS_SSL_CLI_C &&
|
2022-03-04 05:50:46 +01:00
|
|
|
( MBEDTLS_SSL_PROTO_DTLS ||
|
|
|
|
MBEDTLS_SSL_PROTO_TLS1_3 ) */
|
|
|
|
#if defined(MBEDTLS_SSL_SRV_C) && defined(MBEDTLS_SSL_PROTO_DTLS)
|
|
|
|
unsigned char cookie_verify_result; /*!< Srv: flag for sending a cookie */
|
|
|
|
#endif /* MBEDTLS_SSL_SRV_C && MBEDTLS_SSL_PROTO_DTLS */
|
2022-01-26 10:49:29 +01:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
|
|
|
unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */
|
|
|
|
unsigned int in_msg_seq; /*!< Incoming handshake sequence number */
|
2015-05-26 12:11:48 +02:00
|
|
|
|
|
|
|
uint32_t retransmit_timeout; /*!< Current value of timeout */
|
2017-09-13 14:00:05 +02:00
|
|
|
mbedtls_ssl_flight_item *flight; /*!< Current outgoing flight */
|
|
|
|
mbedtls_ssl_flight_item *cur_msg; /*!< Current message in flight */
|
|
|
|
unsigned char *cur_msg_p; /*!< Position in current message */
|
2015-05-26 12:11:48 +02:00
|
|
|
unsigned int in_flight_start_seq; /*!< Minimum message sequence in the
|
|
|
|
flight being received */
|
|
|
|
mbedtls_ssl_transform *alt_transform_out; /*!< Alternative transform for
|
2023-01-11 14:50:10 +01:00
|
|
|
resending messages */
|
2021-10-08 09:21:19 +02:00
|
|
|
unsigned char alt_out_ctr[MBEDTLS_SSL_SEQUENCE_NUMBER_LEN]; /*!< Alternative record epoch/counter
|
|
|
|
for resending messages */
|
2018-08-15 16:11:57 +02:00
|
|
|
|
2019-05-15 15:03:01 +02:00
|
|
|
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
2019-04-25 16:46:59 +02:00
|
|
|
/* The state of CID configuration in this handshake. */
|
|
|
|
|
|
|
|
uint8_t cid_in_use; /*!< This indicates whether the use of the CID extension
|
2019-05-15 11:17:48 +02:00
|
|
|
* has been negotiated. Possible values are
|
2019-04-25 16:46:59 +02:00
|
|
|
* #MBEDTLS_SSL_CID_ENABLED and
|
|
|
|
* #MBEDTLS_SSL_CID_DISABLED. */
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char peer_cid[MBEDTLS_SSL_CID_OUT_LEN_MAX]; /*! The peer's CID */
|
2019-04-25 16:46:59 +02:00
|
|
|
uint8_t peer_cid_len; /*!< The length of
|
|
|
|
* \c peer_cid. */
|
2019-05-15 15:03:01 +02:00
|
|
|
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
2019-04-25 16:46:59 +02:00
|
|
|
|
2018-08-22 10:38:52 +02:00
|
|
|
uint16_t mtu; /*!< Handshake mtu, used to fragment outgoing messages */
|
2017-04-28 18:08:27 +02:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
2015-05-26 12:11:48 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Checksum contexts
|
|
|
|
*/
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA256)
|
2019-01-29 15:14:33 +01:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
|
|
|
psa_hash_operation_t fin_sha256_psa;
|
|
|
|
#else
|
2023-02-24 13:19:17 +01:00
|
|
|
mbedtls_md_context_t fin_sha256;
|
2015-05-26 12:11:48 +02:00
|
|
|
#endif
|
2019-01-29 15:14:33 +01:00
|
|
|
#endif
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA384)
|
2019-01-29 15:14:33 +01:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
2019-01-30 09:29:12 +01:00
|
|
|
psa_hash_operation_t fin_sha384_psa;
|
2019-01-29 15:14:33 +01:00
|
|
|
#else
|
2023-02-24 13:19:17 +01:00
|
|
|
mbedtls_md_context_t fin_sha384;
|
2015-05-26 12:11:48 +02:00
|
|
|
#endif
|
2019-01-29 15:14:33 +01:00
|
|
|
#endif
|
2015-05-26 12:11:48 +02:00
|
|
|
|
2021-12-08 16:57:54 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2021-09-01 11:48:49 +02:00
|
|
|
uint16_t offered_group_id; /* The NamedGroup value for the group
|
|
|
|
* that is being used for ephemeral
|
|
|
|
* key exchange.
|
|
|
|
*
|
|
|
|
* On the client: Defaults to the first
|
|
|
|
* entry in the client's group list,
|
|
|
|
* but can be overwritten by the HRR. */
|
2021-12-08 16:57:54 +01:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
|
2021-09-01 11:48:49 +02:00
|
|
|
|
2022-01-28 04:05:58 +01:00
|
|
|
#if defined(MBEDTLS_SSL_CLI_C)
|
2022-02-08 14:07:10 +01:00
|
|
|
uint8_t client_auth; /*!< used to check if CertificateRequest has been
|
2022-02-08 14:08:29 +01:00
|
|
|
received from server side. If CertificateRequest
|
2022-02-08 03:10:48 +01:00
|
|
|
has been received, Certificate and CertificateVerify
|
2022-01-28 04:05:58 +01:00
|
|
|
should be sent to server */
|
|
|
|
#endif /* MBEDTLS_SSL_CLI_C */
|
2021-09-18 08:20:25 +02:00
|
|
|
/*
|
|
|
|
* State-local variables used during the processing
|
|
|
|
* of a specific handshake state.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
union {
|
2021-09-18 08:20:25 +02:00
|
|
|
/* Outgoing Finished message */
|
2023-01-11 14:50:10 +01:00
|
|
|
struct {
|
2021-09-18 08:20:25 +02:00
|
|
|
uint8_t preparation_done;
|
|
|
|
|
|
|
|
/* Buffer holding digest of the handshake up to
|
|
|
|
* but excluding the outgoing finished message. */
|
2021-11-09 12:55:10 +01:00
|
|
|
unsigned char digest[MBEDTLS_TLS1_3_MD_MAX_SIZE];
|
2021-09-18 08:20:25 +02:00
|
|
|
size_t digest_len;
|
|
|
|
} finished_out;
|
|
|
|
|
|
|
|
/* Incoming Finished message */
|
2023-01-11 14:50:10 +01:00
|
|
|
struct {
|
2021-11-10 04:12:11 +01:00
|
|
|
uint8_t preparation_done;
|
|
|
|
|
2021-09-18 08:20:25 +02:00
|
|
|
/* Buffer holding digest of the handshake up to but
|
|
|
|
* excluding the peer's incoming finished message. */
|
2021-11-09 12:55:10 +01:00
|
|
|
unsigned char digest[MBEDTLS_TLS1_3_MD_MAX_SIZE];
|
2021-09-18 08:20:25 +02:00
|
|
|
size_t digest_len;
|
|
|
|
} finished_in;
|
|
|
|
|
|
|
|
} state_local;
|
|
|
|
|
|
|
|
/* End of state-local variables. */
|
|
|
|
|
2021-10-26 04:44:32 +02:00
|
|
|
unsigned char randbytes[MBEDTLS_CLIENT_HELLO_RANDOM_LEN +
|
|
|
|
MBEDTLS_SERVER_HELLO_RANDOM_LEN];
|
2023-01-11 14:50:10 +01:00
|
|
|
/*!< random bytes */
|
2022-10-05 17:20:21 +02:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
2015-05-26 12:11:48 +02:00
|
|
|
unsigned char premaster[MBEDTLS_PREMASTER_SIZE];
|
2023-01-11 14:50:10 +01:00
|
|
|
/*!< premaster secret */
|
2022-10-05 17:20:21 +02:00
|
|
|
size_t pmslen; /*!< premaster length */
|
|
|
|
#endif
|
2015-05-26 12:11:48 +02:00
|
|
|
|
2021-12-08 16:57:54 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2022-08-29 09:25:36 +02:00
|
|
|
uint32_t sent_extensions; /*!< extensions sent by endpoint */
|
|
|
|
uint32_t received_extensions; /*!< extensions received by endpoint */
|
2021-09-09 08:31:24 +02:00
|
|
|
|
2022-10-05 12:46:29 +02:00
|
|
|
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
2022-01-16 13:14:45 +01:00
|
|
|
unsigned char certificate_request_context_len;
|
|
|
|
unsigned char *certificate_request_context;
|
2021-12-23 13:09:05 +01:00
|
|
|
#endif
|
|
|
|
|
2022-11-04 07:07:25 +01:00
|
|
|
/** TLS 1.3 transform for encrypted handshake messages. */
|
|
|
|
mbedtls_ssl_transform *transform_handshake;
|
2023-01-11 14:50:10 +01:00
|
|
|
union {
|
|
|
|
unsigned char early[MBEDTLS_TLS1_3_MD_MAX_SIZE];
|
2021-10-08 09:36:57 +02:00
|
|
|
unsigned char handshake[MBEDTLS_TLS1_3_MD_MAX_SIZE];
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char app[MBEDTLS_TLS1_3_MD_MAX_SIZE];
|
2021-12-02 07:36:27 +01:00
|
|
|
} tls13_master_secrets;
|
2021-09-16 12:59:08 +02:00
|
|
|
|
2021-11-12 09:53:56 +01:00
|
|
|
mbedtls_ssl_tls13_handshake_secrets tls13_hs_secrets;
|
2022-11-04 07:07:25 +01:00
|
|
|
#if defined(MBEDTLS_SSL_EARLY_DATA)
|
2022-11-21 15:45:58 +01:00
|
|
|
/** TLS 1.3 transform for early data and handshake messages. */
|
2022-11-04 07:07:25 +01:00
|
|
|
mbedtls_ssl_transform *transform_earlydata;
|
|
|
|
#endif
|
2021-12-08 16:57:54 +01:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
|
2015-05-26 12:11:48 +02:00
|
|
|
|
2018-04-25 20:39:48 +02:00
|
|
|
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
|
|
|
/** Asynchronous operation context. This field is meant for use by the
|
|
|
|
* asynchronous operation callbacks (mbedtls_ssl_config::f_async_sign_start,
|
|
|
|
* mbedtls_ssl_config::f_async_decrypt_start,
|
|
|
|
* mbedtls_ssl_config::f_async_resume, mbedtls_ssl_config::f_async_cancel).
|
|
|
|
* The library does not use it internally. */
|
|
|
|
void *user_async_ctx;
|
|
|
|
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
|
2022-01-24 18:58:00 +01:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
|
|
|
|
const unsigned char *sni_name; /*!< raw SNI */
|
|
|
|
size_t sni_name_len; /*!< raw SNI len */
|
2022-03-11 07:37:23 +01:00
|
|
|
#if defined(MBEDTLS_KEY_EXCHANGE_CERT_REQ_ALLOWED_ENABLED)
|
|
|
|
const mbedtls_x509_crt *dn_hints; /*!< acceptable client cert issuers */
|
|
|
|
#endif
|
2022-01-24 18:58:00 +01:00
|
|
|
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
|
2015-05-26 12:11:48 +02:00
|
|
|
};
|
|
|
|
|
2018-08-16 14:23:47 +02:00
|
|
|
typedef struct mbedtls_ssl_hs_buffer mbedtls_ssl_hs_buffer;
|
|
|
|
|
2015-05-26 12:11:48 +02:00
|
|
|
/*
|
2018-01-03 16:23:11 +01:00
|
|
|
* Representation of decryption/encryption transformations on records
|
|
|
|
*
|
|
|
|
* There are the following general types of record transformations:
|
2021-06-25 14:40:09 +02:00
|
|
|
* - Stream transformations (TLS versions == 1.2 only)
|
2018-01-03 16:23:11 +01:00
|
|
|
* Transformation adding a MAC and applying a stream-cipher
|
|
|
|
* to the authenticated message.
|
2021-06-25 14:40:09 +02:00
|
|
|
* - CBC block cipher transformations ([D]TLS versions == 1.2 only)
|
|
|
|
* For TLS 1.2, no IV is generated at key extraction time, but every
|
|
|
|
* encrypted record is explicitly prefixed by the IV with which it was
|
|
|
|
* encrypted.
|
|
|
|
* - AEAD transformations ([D]TLS versions == 1.2 only)
|
2018-01-03 16:23:11 +01:00
|
|
|
* These come in two fundamentally different versions, the first one
|
|
|
|
* used in TLS 1.2, excluding ChaChaPoly ciphersuites, and the second
|
|
|
|
* one used for ChaChaPoly ciphersuites in TLS 1.2 as well as for TLS 1.3.
|
|
|
|
* In the first transformation, the IV to be used for a record is obtained
|
|
|
|
* as the concatenation of an explicit, static 4-byte IV and the 8-byte
|
|
|
|
* record sequence number, and explicitly prepending this sequence number
|
|
|
|
* to the encrypted record. In contrast, in the second transformation
|
|
|
|
* the IV is obtained by XOR'ing a static IV obtained at key extraction
|
|
|
|
* time with the 8-byte record sequence number, without prepending the
|
|
|
|
* latter to the encrypted record.
|
|
|
|
*
|
2020-05-04 13:29:05 +02:00
|
|
|
* Additionally, DTLS 1.2 + CID as well as TLS 1.3 use an inner plaintext
|
|
|
|
* which allows to add flexible length padding and to hide a record's true
|
|
|
|
* content type.
|
|
|
|
*
|
2018-01-03 16:23:11 +01:00
|
|
|
* In addition to type and version, the following parameters are relevant:
|
|
|
|
* - The symmetric cipher algorithm to be used.
|
|
|
|
* - The (static) encryption/decryption keys for the cipher.
|
|
|
|
* - For stream/CBC, the type of message digest to be used.
|
|
|
|
* - For stream/CBC, (static) encryption/decryption keys for the digest.
|
2018-10-18 16:39:53 +02:00
|
|
|
* - For AEAD transformations, the size (potentially 0) of an explicit,
|
|
|
|
* random initialization vector placed in encrypted records.
|
2021-07-09 16:55:11 +02:00
|
|
|
* - For some transformations (currently AEAD) an implicit IV. It is static
|
2018-01-03 16:23:11 +01:00
|
|
|
* and (if present) is combined with the explicit IV in a transformation-
|
2021-07-09 16:55:11 +02:00
|
|
|
* -dependent way (e.g. appending in TLS 1.2 and XOR'ing in TLS 1.3).
|
2018-01-03 16:23:11 +01:00
|
|
|
* - For stream/CBC, a flag determining the order of encryption and MAC.
|
|
|
|
* - The details of the transformation depend on the SSL/TLS version.
|
|
|
|
* - The length of the authentication tag.
|
|
|
|
*
|
|
|
|
* The struct below refines this abstract view as follows:
|
|
|
|
* - The cipher underlying the transformation is managed in
|
|
|
|
* cipher contexts cipher_ctx_{enc/dec}, which must have the
|
|
|
|
* same cipher type. The mode of these cipher contexts determines
|
|
|
|
* the type of the transformation in the sense above: e.g., if
|
|
|
|
* the type is MBEDTLS_CIPHER_AES_256_CBC resp. MBEDTLS_CIPHER_AES_192_GCM
|
|
|
|
* then the transformation has type CBC resp. AEAD.
|
|
|
|
* - The cipher keys are never stored explicitly but
|
|
|
|
* are maintained within cipher_ctx_{enc/dec}.
|
|
|
|
* - For stream/CBC transformations, the message digest contexts
|
|
|
|
* used for the MAC's are stored in md_ctx_{enc/dec}. These contexts
|
|
|
|
* are unused for AEAD transformations.
|
2021-06-25 14:40:09 +02:00
|
|
|
* - For stream/CBC transformations, the MAC keys are not stored explicitly
|
|
|
|
* but maintained within md_ctx_{enc/dec}.
|
|
|
|
* - The mac_enc and mac_dec fields are unused for EAD transformations.
|
2018-01-03 16:23:11 +01:00
|
|
|
* - For transformations using an implicit IV maintained within
|
|
|
|
* the transformation context, its contents are stored within
|
|
|
|
* iv_{enc/dec}.
|
|
|
|
* - The value of ivlen indicates the length of the IV.
|
|
|
|
* This is redundant in case of stream/CBC transformations
|
|
|
|
* which always use 0 resp. the cipher's block length as the
|
|
|
|
* IV length, but is needed for AEAD ciphers and may be
|
|
|
|
* different from the underlying cipher's block length
|
|
|
|
* in this case.
|
|
|
|
* - The field fixed_ivlen is nonzero for AEAD transformations only
|
|
|
|
* and indicates the length of the static part of the IV which is
|
|
|
|
* constant throughout the communication, and which is stored in
|
|
|
|
* the first fixed_ivlen bytes of the iv_{enc/dec} arrays.
|
2022-03-14 17:34:51 +01:00
|
|
|
* - tls_version denotes the 2-byte TLS version
|
2018-01-03 16:23:11 +01:00
|
|
|
* - For stream/CBC transformations, maclen denotes the length of the
|
|
|
|
* authentication tag, while taglen is unused and 0.
|
|
|
|
* - For AEAD transformations, taglen denotes the length of the
|
|
|
|
* authentication tag, while maclen is unused and 0.
|
|
|
|
* - For CBC transformations, encrypt_then_mac determines the
|
|
|
|
* order of encryption and authentication. This field is unused
|
|
|
|
* in other transformations.
|
|
|
|
*
|
2015-05-26 12:11:48 +02:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
struct mbedtls_ssl_transform {
|
2015-05-26 12:11:48 +02:00
|
|
|
/*
|
|
|
|
* Session specific crypto layer
|
|
|
|
*/
|
|
|
|
size_t minlen; /*!< min. ciphertext length */
|
|
|
|
size_t ivlen; /*!< IV length */
|
|
|
|
size_t fixed_ivlen; /*!< Fixed part of IV (AEAD) */
|
2017-12-27 22:34:08 +01:00
|
|
|
size_t maclen; /*!< MAC(CBC) len */
|
|
|
|
size_t taglen; /*!< TAG(AEAD) len */
|
2015-05-26 12:11:48 +02:00
|
|
|
|
|
|
|
unsigned char iv_enc[16]; /*!< IV (encryption) */
|
|
|
|
unsigned char iv_dec[16]; /*!< IV (decryption) */
|
|
|
|
|
2020-11-30 09:54:23 +01:00
|
|
|
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC)
|
2018-01-03 16:32:51 +01:00
|
|
|
|
2022-02-23 09:24:45 +01:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
|
|
|
mbedtls_svc_key_id_t psa_mac_enc; /*!< MAC (encryption) */
|
|
|
|
mbedtls_svc_key_id_t psa_mac_dec; /*!< MAC (decryption) */
|
|
|
|
psa_algorithm_t psa_mac_alg; /*!< psa MAC algorithm */
|
2022-02-24 11:17:45 +01:00
|
|
|
#else
|
2015-05-26 12:11:48 +02:00
|
|
|
mbedtls_md_context_t md_ctx_enc; /*!< MAC (encryption) */
|
|
|
|
mbedtls_md_context_t md_ctx_dec; /*!< MAC (decryption) */
|
2022-02-24 11:17:45 +01:00
|
|
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
2015-05-26 12:11:48 +02:00
|
|
|
|
2017-12-27 22:37:21 +01:00
|
|
|
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
|
|
|
|
int encrypt_then_mac; /*!< flag for EtM activation */
|
|
|
|
#endif
|
|
|
|
|
2020-11-30 09:54:23 +01:00
|
|
|
#endif /* MBEDTLS_SSL_SOME_SUITES_USE_MAC */
|
2018-01-03 16:32:51 +01:00
|
|
|
|
2022-03-14 17:34:51 +01:00
|
|
|
mbedtls_ssl_protocol_version tls_version;
|
2017-12-27 22:37:21 +01:00
|
|
|
|
2022-01-11 08:25:29 +01:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
|
|
|
mbedtls_svc_key_id_t psa_key_enc; /*!< psa encryption key */
|
|
|
|
mbedtls_svc_key_id_t psa_key_dec; /*!< psa decryption key */
|
|
|
|
psa_algorithm_t psa_alg; /*!< psa algorithm */
|
2022-01-19 16:00:22 +01:00
|
|
|
#else
|
|
|
|
mbedtls_cipher_context_t cipher_ctx_enc; /*!< encryption context */
|
|
|
|
mbedtls_cipher_context_t cipher_ctx_dec; /*!< decryption context */
|
2022-01-11 08:25:29 +01:00
|
|
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
|
|
|
|
2019-05-15 15:03:01 +02:00
|
|
|
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
2019-04-25 16:54:02 +02:00
|
|
|
uint8_t in_cid_len;
|
|
|
|
uint8_t out_cid_len;
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char in_cid[MBEDTLS_SSL_CID_IN_LEN_MAX];
|
|
|
|
unsigned char out_cid[MBEDTLS_SSL_CID_OUT_LEN_MAX];
|
2019-05-15 15:03:01 +02:00
|
|
|
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
2019-04-25 16:54:02 +02:00
|
|
|
|
2019-07-09 12:54:17 +02:00
|
|
|
#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
|
|
|
|
/* We need the Hello random bytes in order to re-derive keys from the
|
2021-03-22 07:59:27 +01:00
|
|
|
* Master Secret and other session info,
|
|
|
|
* see ssl_tls12_populate_transform() */
|
2021-10-26 04:44:32 +02:00
|
|
|
unsigned char randbytes[MBEDTLS_SERVER_HELLO_RANDOM_LEN +
|
|
|
|
MBEDTLS_CLIENT_HELLO_RANDOM_LEN];
|
2023-01-11 14:50:10 +01:00
|
|
|
/*!< ServerHello.random+ClientHello.random */
|
2019-07-09 12:54:17 +02:00
|
|
|
#endif /* MBEDTLS_SSL_CONTEXT_SERIALIZATION */
|
2015-05-26 12:11:48 +02:00
|
|
|
};
|
|
|
|
|
2019-07-10 14:14:05 +02:00
|
|
|
/*
|
|
|
|
* Return 1 if the transform uses an AEAD cipher, 0 otherwise.
|
|
|
|
* Equivalently, return 0 if a separate MAC is used, 1 otherwise.
|
|
|
|
*/
|
|
|
|
static inline int mbedtls_ssl_transform_uses_aead(
|
2023-01-11 14:50:10 +01:00
|
|
|
const mbedtls_ssl_transform *transform)
|
2019-07-10 14:14:05 +02:00
|
|
|
{
|
2020-11-30 09:54:23 +01:00
|
|
|
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_MAC)
|
2023-01-11 14:50:10 +01:00
|
|
|
return transform->maclen == 0 && transform->taglen != 0;
|
2019-07-10 14:14:05 +02:00
|
|
|
#else
|
|
|
|
(void) transform;
|
2023-01-11 14:50:10 +01:00
|
|
|
return 1;
|
2019-07-10 14:14:05 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-01-05 16:42:50 +01:00
|
|
|
/*
|
|
|
|
* Internal representation of record frames
|
|
|
|
*
|
|
|
|
* Instances come in two flavors:
|
|
|
|
* (1) Encrypted
|
|
|
|
* These always have data_offset = 0
|
|
|
|
* (2) Unencrypted
|
2019-04-04 17:29:48 +02:00
|
|
|
* These have data_offset set to the amount of
|
|
|
|
* pre-expansion during record protection. Concretely,
|
|
|
|
* this is the length of the fixed part of the explicit IV
|
|
|
|
* used for encryption, or 0 if no explicit IV is used
|
2021-06-25 14:40:09 +02:00
|
|
|
* (e.g. for stream ciphers).
|
2018-01-05 16:42:50 +01:00
|
|
|
*
|
|
|
|
* The reason for the data_offset in the unencrypted case
|
|
|
|
* is to allow for in-place conversion of an unencrypted to
|
|
|
|
* an encrypted record. If the offset wasn't included, the
|
|
|
|
* encrypted content would need to be shifted afterwards to
|
|
|
|
* make space for the fixed IV.
|
|
|
|
*
|
|
|
|
*/
|
2019-04-29 14:45:54 +02:00
|
|
|
#if MBEDTLS_SSL_CID_OUT_LEN_MAX > MBEDTLS_SSL_CID_IN_LEN_MAX
|
2019-04-30 16:01:51 +02:00
|
|
|
#define MBEDTLS_SSL_CID_LEN_MAX MBEDTLS_SSL_CID_OUT_LEN_MAX
|
2019-04-29 14:45:54 +02:00
|
|
|
#else
|
2019-04-30 16:01:51 +02:00
|
|
|
#define MBEDTLS_SSL_CID_LEN_MAX MBEDTLS_SSL_CID_IN_LEN_MAX
|
2019-04-29 14:45:54 +02:00
|
|
|
#endif
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
typedef struct {
|
2021-10-08 09:21:19 +02:00
|
|
|
uint8_t ctr[MBEDTLS_SSL_SEQUENCE_NUMBER_LEN]; /* In TLS: The implicit record sequence number.
|
|
|
|
* In DTLS: The 2-byte epoch followed by
|
|
|
|
* the 6-byte sequence number.
|
|
|
|
* This is stored as a raw big endian byte array
|
|
|
|
* as opposed to a uint64_t because we rarely
|
|
|
|
* need to perform arithmetic on this, but do
|
|
|
|
* need it as a Byte array for the purpose of
|
|
|
|
* MAC computations. */
|
2019-07-11 10:24:36 +02:00
|
|
|
uint8_t type; /* The record content type. */
|
|
|
|
uint8_t ver[2]; /* SSL/TLS version as present on the wire.
|
|
|
|
* Convert to internal presentation of versions
|
|
|
|
* using mbedtls_ssl_read_version() and
|
|
|
|
* mbedtls_ssl_write_version().
|
|
|
|
* Keep wire-format for MAC computations. */
|
|
|
|
|
|
|
|
unsigned char *buf; /* Memory buffer enclosing the record content */
|
|
|
|
size_t buf_len; /* Buffer length */
|
|
|
|
size_t data_offset; /* Offset of record content */
|
|
|
|
size_t data_len; /* Length of record content */
|
2018-01-05 16:42:50 +01:00
|
|
|
|
2019-05-15 15:03:01 +02:00
|
|
|
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
2019-07-11 10:24:36 +02:00
|
|
|
uint8_t cid_len; /* Length of the CID (0 if not present) */
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char cid[MBEDTLS_SSL_CID_LEN_MAX]; /* The CID */
|
2019-05-15 15:03:01 +02:00
|
|
|
#endif /* MBEDTLS_SSL_DTLS_CONNECTION_ID */
|
2018-01-05 16:42:50 +01:00
|
|
|
} mbedtls_record;
|
|
|
|
|
2015-05-26 12:11:48 +02:00
|
|
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
|
|
|
/*
|
|
|
|
* List of certificate + private key pairs
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
struct mbedtls_ssl_key_cert {
|
2015-05-26 12:11:48 +02:00
|
|
|
mbedtls_x509_crt *cert; /*!< cert */
|
|
|
|
mbedtls_pk_context *key; /*!< private key */
|
|
|
|
mbedtls_ssl_key_cert *next; /*!< next key/cert pair */
|
|
|
|
};
|
|
|
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
|
|
|
/*
|
|
|
|
* List of handshake messages kept around for resending
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
struct mbedtls_ssl_flight_item {
|
2015-05-26 12:11:48 +02:00
|
|
|
unsigned char *p; /*!< message, including handshake headers */
|
|
|
|
size_t len; /*!< length of p */
|
|
|
|
unsigned char type; /*!< type of the message: handshake or CCS */
|
|
|
|
mbedtls_ssl_flight_item *next; /*!< next handshake message(s) */
|
|
|
|
};
|
|
|
|
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
|
|
|
|
2022-02-20 10:35:26 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
|
|
|
/**
|
|
|
|
* \brief Given an SSL context and its associated configuration, write the TLS
|
|
|
|
* 1.2 specific extensions of the ClientHello message.
|
|
|
|
*
|
|
|
|
* \param[in] ssl SSL context
|
|
|
|
* \param[in] buf Base address of the buffer where to write the extensions
|
|
|
|
* \param[in] end End address of the buffer where to write the extensions
|
|
|
|
* \param uses_ec Whether one proposed ciphersuite uses an elliptic curve
|
|
|
|
* (<> 0) or not ( 0 ).
|
|
|
|
* \param[out] out_len Length of the data written into the buffer \p buf
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls12_write_client_hello_exts(mbedtls_ssl_context *ssl,
|
|
|
|
unsigned char *buf,
|
|
|
|
const unsigned char *end,
|
|
|
|
int uses_ec,
|
|
|
|
size_t *out_len);
|
2022-02-20 10:35:26 +01:00
|
|
|
#endif
|
|
|
|
|
2017-04-28 18:15:26 +02:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && \
|
2020-03-10 12:19:08 +01:00
|
|
|
defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
|
2017-04-28 18:15:26 +02:00
|
|
|
|
2022-05-10 12:44:09 +02:00
|
|
|
/**
|
|
|
|
* \brief Find the preferred hash for a given signature algorithm.
|
|
|
|
*
|
|
|
|
* \param[in] ssl SSL context
|
|
|
|
* \param[in] sig_alg A signature algorithm identifier as defined in the
|
|
|
|
* TLS 1.2 SignatureAlgorithm enumeration.
|
|
|
|
*
|
|
|
|
* \return The preferred hash algorithm for \p sig_alg. It is a hash algorithm
|
|
|
|
* identifier as defined in the TLS 1.2 HashAlgorithm enumeration.
|
|
|
|
*/
|
|
|
|
unsigned int mbedtls_ssl_tls12_get_preferred_hash_for_sig_alg(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_context *ssl,
|
|
|
|
unsigned int sig_alg);
|
2017-04-28 18:15:26 +02:00
|
|
|
|
2022-04-27 21:17:56 +02:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 &&
|
2020-03-10 12:19:08 +01:00
|
|
|
MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
|
2015-05-26 12:11:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Free referenced items in an SSL transform context and clear
|
|
|
|
* memory
|
|
|
|
*
|
|
|
|
* \param transform SSL transform context
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_transform_free(mbedtls_ssl_transform *transform);
|
2015-05-26 12:11:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Free referenced items in an SSL handshake context and clear
|
|
|
|
* memory
|
|
|
|
*
|
2018-04-25 20:32:43 +02:00
|
|
|
* \param ssl SSL context
|
2015-05-26 12:11:48 +02:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_handshake_free(mbedtls_ssl_context *ssl);
|
2015-05-26 12:11:48 +02:00
|
|
|
|
2021-09-05 15:05:50 +02:00
|
|
|
/* set inbound transform of ssl context */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_set_inbound_transform(mbedtls_ssl_context *ssl,
|
|
|
|
mbedtls_ssl_transform *transform);
|
2021-09-05 15:05:50 +02:00
|
|
|
|
|
|
|
/* set outbound transform of ssl context */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_set_outbound_transform(mbedtls_ssl_context *ssl,
|
|
|
|
mbedtls_ssl_transform *transform);
|
2021-09-05 15:05:50 +02:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_handshake_client_step(mbedtls_ssl_context *ssl);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_handshake_server_step(mbedtls_ssl_context *ssl);
|
|
|
|
void mbedtls_ssl_handshake_wrapup(mbedtls_ssl_context *ssl);
|
|
|
|
static inline void mbedtls_ssl_handshake_set_state(mbedtls_ssl_context *ssl,
|
|
|
|
mbedtls_ssl_states state)
|
2022-03-10 18:56:50 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
ssl->state = (int) state;
|
2022-03-10 18:56:50 +01:00
|
|
|
}
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_send_fatal_handshake_failure(mbedtls_ssl_context *ssl);
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2023-02-06 00:34:21 +01:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
Make handshake hashing functions return int
There are three family of functions: update_checksum, calc_verify,
calc_finished, that perform hashing operations and were returning void
so far. This is not correct, as hashing functions can return errors (for
example, on hardware failure when accelerated). Change them to return
int.
This commit just changes the types: for now the functions always return
0, and their return value is not checked; this will be fixed in the
next few commits.
There is a related function in TLS 1.3,
mbedtls_ssl_reset_transcript_for_hrr, which also handles hashes, and
already returns int but does not correctly check for errors from hashing
functions so far, it will also be handled in the next few commits.
There's a special case with handshake_params_init: _init functions
should return void, so we'll need to split out the part that can return
errors, see the next commit.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-02-05 09:46:59 +01:00
|
|
|
int mbedtls_ssl_reset_checksum(mbedtls_ssl_context *ssl);
|
2022-01-28 03:52:05 +01:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_derive_keys(mbedtls_ssl_context *ssl);
|
2022-01-28 03:52:05 +01:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_handle_message_type(mbedtls_ssl_context *ssl);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_prepare_handshake_record(mbedtls_ssl_context *ssl);
|
2023-02-06 00:34:21 +01:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
|
|
|
int mbedtls_ssl_update_handshake_status(mbedtls_ssl_context *ssl);
|
2016-10-13 18:21:01 +02:00
|
|
|
|
2017-05-24 17:27:30 +02:00
|
|
|
/**
|
|
|
|
* \brief Update record layer
|
|
|
|
*
|
|
|
|
* This function roughly separates the implementation
|
|
|
|
* of the logic of (D)TLS from the implementation
|
|
|
|
* of the secure transport.
|
|
|
|
*
|
2018-08-20 10:44:02 +02:00
|
|
|
* \param ssl The SSL context to use.
|
|
|
|
* \param update_hs_digest This indicates if the handshake digest
|
|
|
|
* should be automatically updated in case
|
|
|
|
* a handshake message is found.
|
2017-05-24 17:27:30 +02:00
|
|
|
*
|
|
|
|
* \return 0 or non-zero error code.
|
|
|
|
*
|
|
|
|
* \note A clarification on what is called 'record layer' here
|
|
|
|
* is in order, as many sensible definitions are possible:
|
|
|
|
*
|
|
|
|
* The record layer takes as input an untrusted underlying
|
|
|
|
* transport (stream or datagram) and transforms it into
|
|
|
|
* a serially multiplexed, secure transport, which
|
|
|
|
* conceptually provides the following:
|
|
|
|
*
|
|
|
|
* (1) Three datagram based, content-agnostic transports
|
|
|
|
* for handshake, alert and CCS messages.
|
|
|
|
* (2) One stream- or datagram-based transport
|
|
|
|
* for application data.
|
|
|
|
* (3) Functionality for changing the underlying transform
|
|
|
|
* securing the contents.
|
|
|
|
*
|
|
|
|
* The interface to this functionality is given as follows:
|
|
|
|
*
|
|
|
|
* a Updating
|
|
|
|
* [Currently implemented by mbedtls_ssl_read_record]
|
|
|
|
*
|
|
|
|
* Check if and on which of the four 'ports' data is pending:
|
|
|
|
* Nothing, a controlling datagram of type (1), or application
|
|
|
|
* data (2). In any case data is present, internal buffers
|
|
|
|
* provide access to the data for the user to process it.
|
|
|
|
* Consumption of type (1) datagrams is done automatically
|
|
|
|
* on the next update, invalidating that the internal buffers
|
|
|
|
* for previous datagrams, while consumption of application
|
|
|
|
* data (2) is user-controlled.
|
|
|
|
*
|
|
|
|
* b Reading of application data
|
|
|
|
* [Currently manual adaption of ssl->in_offt pointer]
|
|
|
|
*
|
|
|
|
* As mentioned in the last paragraph, consumption of data
|
|
|
|
* is different from the automatic consumption of control
|
|
|
|
* datagrams (1) because application data is treated as a stream.
|
|
|
|
*
|
|
|
|
* c Tracking availability of application data
|
|
|
|
* [Currently manually through decreasing ssl->in_msglen]
|
|
|
|
*
|
|
|
|
* For efficiency and to retain datagram semantics for
|
|
|
|
* application data in case of DTLS, the record layer
|
|
|
|
* provides functionality for checking how much application
|
|
|
|
* data is still available in the internal buffer.
|
|
|
|
*
|
|
|
|
* d Changing the transformation securing the communication.
|
|
|
|
*
|
|
|
|
* Given an opaque implementation of the record layer in the
|
|
|
|
* above sense, it should be possible to implement the logic
|
|
|
|
* of (D)TLS on top of it without the need to know anything
|
|
|
|
* about the record layer's internals. This is done e.g.
|
|
|
|
* in all the handshake handling functions, and in the
|
|
|
|
* application data reading function mbedtls_ssl_read.
|
|
|
|
*
|
|
|
|
* \note The above tries to give a conceptual picture of the
|
|
|
|
* record layer, but the current implementation deviates
|
|
|
|
* from it in some places. For example, our implementation of
|
|
|
|
* the update functionality through mbedtls_ssl_read_record
|
|
|
|
* discards datagrams depending on the current state, which
|
|
|
|
* wouldn't fall under the record layer's responsibility
|
|
|
|
* following the above definition.
|
|
|
|
*
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_read_record(mbedtls_ssl_context *ssl,
|
|
|
|
unsigned update_hs_digest);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_fetch_input(mbedtls_ssl_context *ssl, size_t nb_want);
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2022-03-10 18:56:50 +01:00
|
|
|
/*
|
|
|
|
* Write handshake message header
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_start_handshake_msg(mbedtls_ssl_context *ssl, unsigned hs_type,
|
|
|
|
unsigned char **buf, size_t *buf_len);
|
2022-03-10 18:56:50 +01:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_write_handshake_msg_ext(mbedtls_ssl_context *ssl,
|
|
|
|
int update_checksum,
|
|
|
|
int force_flush);
|
|
|
|
static inline int mbedtls_ssl_write_handshake_msg(mbedtls_ssl_context *ssl)
|
2021-08-07 15:29:49 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_write_handshake_msg_ext(ssl, 1 /* update checksum */, 1 /* force flush */);
|
2021-08-07 15:29:49 +02:00
|
|
|
}
|
|
|
|
|
2022-03-10 18:56:50 +01:00
|
|
|
/*
|
|
|
|
* Write handshake message tail
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_finish_handshake_msg(mbedtls_ssl_context *ssl,
|
|
|
|
size_t buf_len, size_t msg_len);
|
2022-03-10 18:56:50 +01:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_write_record(mbedtls_ssl_context *ssl, int force_flush);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_flush_output(mbedtls_ssl_context *ssl);
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_parse_certificate(mbedtls_ssl_context *ssl);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_write_certificate(mbedtls_ssl_context *ssl);
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_parse_change_cipher_spec(mbedtls_ssl_context *ssl);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_write_change_cipher_spec(mbedtls_ssl_context *ssl);
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_parse_finished(mbedtls_ssl_context *ssl);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_write_finished(mbedtls_ssl_context *ssl);
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_optimize_checksum(mbedtls_ssl_context *ssl,
|
|
|
|
const mbedtls_ssl_ciphersuite_t *ciphersuite_info);
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2022-03-10 18:56:50 +01:00
|
|
|
/*
|
|
|
|
* Update checksum of handshake messages.
|
|
|
|
*/
|
2023-02-06 00:34:21 +01:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
|
|
|
int mbedtls_ssl_add_hs_msg_to_checksum(mbedtls_ssl_context *ssl,
|
2023-02-06 11:48:19 +01:00
|
|
|
unsigned hs_type,
|
|
|
|
unsigned char const *msg,
|
|
|
|
size_t msg_len);
|
2022-03-10 18:56:50 +01:00
|
|
|
|
2023-02-06 00:34:21 +01:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
|
|
|
int mbedtls_ssl_add_hs_hdr_to_checksum(mbedtls_ssl_context *ssl,
|
2023-02-06 11:48:19 +01:00
|
|
|
unsigned hs_type,
|
|
|
|
size_t total_hs_len);
|
2022-07-19 11:51:50 +02:00
|
|
|
|
2020-03-10 12:19:08 +01:00
|
|
|
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
|
2022-05-03 17:56:38 +02:00
|
|
|
#if !defined(MBEDTLS_USE_PSA_CRYPTO)
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_psk_derive_premaster(mbedtls_ssl_context *ssl,
|
|
|
|
mbedtls_key_exchange_type_t key_ex);
|
2022-05-03 17:56:38 +02:00
|
|
|
#endif /* !MBEDTLS_USE_PSA_CRYPTO */
|
2022-10-05 14:31:43 +02:00
|
|
|
#endif /* MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED */
|
2022-10-19 10:33:48 +02:00
|
|
|
|
2022-10-05 14:31:43 +02:00
|
|
|
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED)
|
2022-10-19 10:33:48 +02:00
|
|
|
#if defined(MBEDTLS_SSL_CLI_C)
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_conf_has_static_psk(mbedtls_ssl_config const *conf);
|
2022-02-19 18:30:46 +01:00
|
|
|
#endif
|
2022-05-03 10:35:56 +02:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO)
|
|
|
|
/**
|
|
|
|
* Get the first defined opaque PSK by order of precedence:
|
|
|
|
* 1. handshake PSK set by \c mbedtls_ssl_set_hs_psk_opaque() in the PSK
|
|
|
|
* callback
|
|
|
|
* 2. static PSK configured by \c mbedtls_ssl_conf_psk_opaque()
|
|
|
|
* Return an opaque PSK
|
|
|
|
*/
|
|
|
|
static inline mbedtls_svc_key_id_t mbedtls_ssl_get_opaque_psk(
|
2023-01-11 14:50:10 +01:00
|
|
|
const mbedtls_ssl_context *ssl)
|
2022-05-03 10:35:56 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
if (!mbedtls_svc_key_id_is_null(ssl->handshake->psk_opaque)) {
|
|
|
|
return ssl->handshake->psk_opaque;
|
|
|
|
}
|
2022-05-03 10:35:56 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (!mbedtls_svc_key_id_is_null(ssl->conf->psk_opaque)) {
|
|
|
|
return ssl->conf->psk_opaque;
|
|
|
|
}
|
2022-05-03 10:35:56 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_SVC_KEY_ID_INIT;
|
2022-05-03 10:35:56 +02:00
|
|
|
}
|
|
|
|
#else
|
2020-03-27 12:13:39 +01:00
|
|
|
/**
|
2020-03-25 18:06:37 +01:00
|
|
|
* Get the first defined PSK by order of precedence:
|
|
|
|
* 1. handshake PSK set by \c mbedtls_ssl_set_hs_psk() in the PSK callback
|
|
|
|
* 2. static PSK configured by \c mbedtls_ssl_conf_psk()
|
|
|
|
* Return a code and update the pair (PSK, PSK length) passed to this function
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_get_psk(const mbedtls_ssl_context *ssl,
|
|
|
|
const unsigned char **psk, size_t *psk_len)
|
2020-03-25 18:06:37 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl->handshake->psk != NULL && ssl->handshake->psk_len > 0) {
|
2020-03-25 18:06:37 +01:00
|
|
|
*psk = ssl->handshake->psk;
|
|
|
|
*psk_len = ssl->handshake->psk_len;
|
2023-01-11 14:50:10 +01:00
|
|
|
} else if (ssl->conf->psk != NULL && ssl->conf->psk_len > 0) {
|
2020-03-25 18:06:37 +01:00
|
|
|
*psk = ssl->conf->psk;
|
|
|
|
*psk_len = ssl->conf->psk_len;
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
2020-04-01 12:23:58 +02:00
|
|
|
*psk = NULL;
|
|
|
|
*psk_len = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_ERR_SSL_PRIVATE_KEY_REQUIRED;
|
2020-03-25 18:06:37 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2020-03-25 18:06:37 +01:00
|
|
|
}
|
|
|
|
#endif /* MBEDTLS_USE_PSA_CRYPTO */
|
|
|
|
|
2022-10-05 14:31:43 +02:00
|
|
|
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_PSK_ENABLED */
|
2015-05-26 11:57:05 +02:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_PK_C)
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char mbedtls_ssl_sig_from_pk(mbedtls_pk_context *pk);
|
|
|
|
unsigned char mbedtls_ssl_sig_from_pk_alg(mbedtls_pk_type_t type);
|
|
|
|
mbedtls_pk_type_t mbedtls_ssl_pk_alg_from_sig(unsigned char sig);
|
2015-05-26 11:57:05 +02:00
|
|
|
#endif
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_md_type_t mbedtls_ssl_md_alg_from_hash(unsigned char hash);
|
|
|
|
unsigned char mbedtls_ssl_hash_from_md_alg(int md);
|
2022-03-07 10:21:40 +01:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_set_calc_verify_md(mbedtls_ssl_context *ssl, int md);
|
2022-03-07 10:21:40 +01:00
|
|
|
#endif
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_check_curve_tls_id(const mbedtls_ssl_context *ssl, uint16_t tls_id);
|
2015-06-17 11:43:30 +02:00
|
|
|
#if defined(MBEDTLS_ECP_C)
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_check_curve(const mbedtls_ssl_context *ssl, mbedtls_ecp_group_id grp_id);
|
2015-05-26 11:57:05 +02:00
|
|
|
#endif
|
|
|
|
|
2022-12-30 17:44:24 +01:00
|
|
|
/**
|
|
|
|
* \brief Return PSA EC info for the specified TLS ID.
|
|
|
|
*
|
|
|
|
* \param tls_id The TLS ID to look for
|
|
|
|
* \param family If the TLD ID is supported, then proper \c psa_ecc_family_t
|
|
|
|
* value is returned here. Can be NULL.
|
|
|
|
* \param bits If the TLD ID is supported, then proper bit size is returned
|
|
|
|
* here. Can be NULL.
|
|
|
|
* \return PSA_SUCCESS if the TLS ID is supported,
|
|
|
|
* PSA_ERROR_NOT_SUPPORTED otherwise
|
|
|
|
*
|
|
|
|
* \note If either \c family or \c bits parameters are NULL, then
|
|
|
|
* the corresponding value is not returned.
|
|
|
|
* The function can be called with both parameters as NULL
|
|
|
|
* simply to check if a specific TLS ID is supported.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_get_psa_curve_info_from_tls_id(uint16_t tls_id,
|
|
|
|
psa_ecc_family_t *family,
|
|
|
|
size_t *bits);
|
2022-12-30 17:44:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Return \c mbedtls_ecp_group_id for the specified TLS ID.
|
|
|
|
*
|
|
|
|
* \param tls_id The TLS ID to look for
|
|
|
|
* \return Proper \c mbedtls_ecp_group_id if the TLS ID is supported,
|
|
|
|
* or MBEDTLS_ECP_DP_NONE otherwise
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ecp_group_id mbedtls_ssl_get_ecp_group_id_from_tls_id(uint16_t tls_id);
|
2022-12-30 17:44:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Return TLS ID for the specified \c mbedtls_ecp_group_id.
|
|
|
|
*
|
|
|
|
* \param grp_id The \c mbedtls_ecp_group_id ID to look for
|
|
|
|
* \return Proper TLS ID if the \c mbedtls_ecp_group_id is supported,
|
|
|
|
* or 0 otherwise
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
uint16_t mbedtls_ssl_get_tls_id_from_ecp_group_id(mbedtls_ecp_group_id grp_id);
|
2022-12-30 17:44:24 +01:00
|
|
|
|
2023-01-04 16:12:42 +01:00
|
|
|
#if defined(MBEDTLS_DEBUG_C)
|
2022-12-30 17:44:24 +01:00
|
|
|
/**
|
|
|
|
* \brief Return EC's name for the specified TLS ID.
|
|
|
|
*
|
|
|
|
* \param tls_id The TLS ID to look for
|
|
|
|
* \return A pointer to a const string with the proper name. If TLS
|
2023-01-09 17:30:01 +01:00
|
|
|
* ID is not supported, a NULL pointer is returned instead.
|
2022-12-30 17:44:24 +01:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
const char *mbedtls_ssl_get_curve_name_from_tls_id(uint16_t tls_id);
|
2023-01-04 16:12:42 +01:00
|
|
|
#endif
|
2022-12-30 17:44:24 +01:00
|
|
|
|
2018-12-06 16:12:49 +01:00
|
|
|
#if defined(MBEDTLS_SSL_DTLS_SRTP)
|
2020-09-22 12:25:52 +02:00
|
|
|
static inline mbedtls_ssl_srtp_profile mbedtls_ssl_check_srtp_profile_value
|
2023-01-11 14:50:10 +01:00
|
|
|
(const uint16_t srtp_profile_value)
|
2018-12-06 16:12:49 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (srtp_profile_value) {
|
2020-08-25 10:01:54 +02:00
|
|
|
case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_80:
|
|
|
|
case MBEDTLS_TLS_SRTP_AES128_CM_HMAC_SHA1_32:
|
|
|
|
case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_80:
|
|
|
|
case MBEDTLS_TLS_SRTP_NULL_HMAC_SHA1_32:
|
2020-09-22 12:25:52 +02:00
|
|
|
return srtp_profile_value;
|
2018-12-06 16:12:49 +01:00
|
|
|
default: break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_TLS_SRTP_UNSET;
|
2018-12-06 16:12:49 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-26 11:57:05 +02:00
|
|
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline mbedtls_pk_context *mbedtls_ssl_own_key(mbedtls_ssl_context *ssl)
|
2015-05-26 11:57:05 +02:00
|
|
|
{
|
|
|
|
mbedtls_ssl_key_cert *key_cert;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl->handshake != NULL && ssl->handshake->key_cert != NULL) {
|
2015-05-26 11:57:05 +02:00
|
|
|
key_cert = ssl->handshake->key_cert;
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
2015-05-26 11:57:05 +02:00
|
|
|
key_cert = ssl->conf->key_cert;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return key_cert == NULL ? NULL : key_cert->key;
|
2015-05-26 11:57:05 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline mbedtls_x509_crt *mbedtls_ssl_own_cert(mbedtls_ssl_context *ssl)
|
2015-05-26 11:57:05 +02:00
|
|
|
{
|
|
|
|
mbedtls_ssl_key_cert *key_cert;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl->handshake != NULL && ssl->handshake->key_cert != NULL) {
|
2015-05-26 11:57:05 +02:00
|
|
|
key_cert = ssl->handshake->key_cert;
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
2015-05-26 11:57:05 +02:00
|
|
|
key_cert = ssl->conf->key_cert;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return key_cert == NULL ? NULL : key_cert->cert;
|
2015-05-26 11:57:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check usage of a certificate wrt extensions:
|
|
|
|
* keyUsage, extendedKeyUsage (later), and nSCertType (later).
|
|
|
|
*
|
|
|
|
* Warning: cert_endpoint is the endpoint of the cert (ie, of our peer when we
|
|
|
|
* check a cert we received from them)!
|
|
|
|
*
|
|
|
|
* Return 0 if everything is OK, -1 if not.
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_check_cert_usage(const mbedtls_x509_crt *cert,
|
|
|
|
const mbedtls_ssl_ciphersuite_t *ciphersuite,
|
|
|
|
int cert_endpoint,
|
|
|
|
uint32_t *flags);
|
2015-05-26 11:57:05 +02:00
|
|
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_write_version(unsigned char version[2], int transport,
|
|
|
|
mbedtls_ssl_protocol_version tls_version);
|
|
|
|
uint16_t mbedtls_ssl_read_version(const unsigned char version[2],
|
|
|
|
int transport);
|
2015-05-26 11:57:05 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline size_t mbedtls_ssl_in_hdr_len(const mbedtls_ssl_context *ssl)
|
2015-05-26 11:57:05 +02:00
|
|
|
{
|
2019-07-12 10:55:46 +02:00
|
|
|
#if !defined(MBEDTLS_SSL_PROTO_DTLS)
|
|
|
|
((void) ssl);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
|
|
|
|
return 13;
|
|
|
|
} else
|
2019-07-12 10:55:46 +02:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return 5;
|
2019-07-12 10:55:46 +02:00
|
|
|
}
|
2019-05-03 15:46:38 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline size_t mbedtls_ssl_out_hdr_len(const mbedtls_ssl_context *ssl)
|
2019-05-03 15:46:38 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return (size_t) (ssl->out_iv - ssl->out_hdr);
|
2015-05-26 11:57:05 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline size_t mbedtls_ssl_hs_hdr_len(const mbedtls_ssl_context *ssl)
|
2015-05-26 11:57:05 +02:00
|
|
|
{
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
|
|
|
|
return 12;
|
|
|
|
}
|
2015-05-26 11:57:05 +02:00
|
|
|
#else
|
|
|
|
((void) ssl);
|
|
|
|
#endif
|
2023-01-11 14:50:10 +01:00
|
|
|
return 4;
|
2015-05-26 11:57:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_send_flight_completed(mbedtls_ssl_context *ssl);
|
|
|
|
void mbedtls_ssl_recv_flight_completed(mbedtls_ssl_context *ssl);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_resend(mbedtls_ssl_context *ssl);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_flight_transmit(mbedtls_ssl_context *ssl);
|
2015-05-26 11:57:05 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Visible for testing purposes only */
|
|
|
|
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_dtls_replay_check(mbedtls_ssl_context const *ssl);
|
|
|
|
void mbedtls_ssl_dtls_replay_update(mbedtls_ssl_context *ssl);
|
2015-05-26 11:57:05 +02:00
|
|
|
#endif
|
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_session_copy(mbedtls_ssl_session *dst,
|
|
|
|
const mbedtls_ssl_session *src);
|
2019-02-06 15:30:46 +01:00
|
|
|
|
2021-05-12 17:49:18 +02:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
2019-01-14 10:35:19 +01:00
|
|
|
/* The hash buffer must have at least MBEDTLS_MD_MAX_SIZE bytes of length. */
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_get_key_exchange_md_tls1_2(mbedtls_ssl_context *ssl,
|
|
|
|
unsigned char *hash, size_t *hashlen,
|
|
|
|
unsigned char *data, size_t data_len,
|
|
|
|
mbedtls_md_type_t md_alg);
|
2021-05-12 17:49:18 +02:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
2017-07-20 17:17:51 +02:00
|
|
|
|
2015-05-26 11:57:05 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_transform_init(mbedtls_ssl_transform *transform);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_encrypt_buf(mbedtls_ssl_context *ssl,
|
|
|
|
mbedtls_ssl_transform *transform,
|
|
|
|
mbedtls_record *rec,
|
|
|
|
int (*f_rng)(void *, unsigned char *, size_t),
|
|
|
|
void *p_rng);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_decrypt_buf(mbedtls_ssl_context const *ssl,
|
|
|
|
mbedtls_ssl_transform *transform,
|
|
|
|
mbedtls_record *rec);
|
2018-01-03 15:27:32 +01:00
|
|
|
|
2020-02-05 11:38:31 +01:00
|
|
|
/* Length of the "epoch" field in the record header */
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline size_t mbedtls_ssl_ep_len(const mbedtls_ssl_context *ssl)
|
2020-02-05 11:38:31 +01:00
|
|
|
{
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM) {
|
|
|
|
return 2;
|
|
|
|
}
|
2020-02-05 11:38:31 +01:00
|
|
|
#else
|
|
|
|
((void) ssl);
|
|
|
|
#endif
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2020-02-05 11:38:31 +01:00
|
|
|
}
|
|
|
|
|
2020-02-11 16:40:07 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_resend_hello_request(mbedtls_ssl_context *ssl);
|
2020-02-11 16:40:07 +01:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
2020-02-05 11:37:26 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_set_timer(mbedtls_ssl_context *ssl, uint32_t millisecs);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_check_timer(mbedtls_ssl_context *ssl);
|
2020-02-05 11:39:31 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_reset_in_out_pointers(mbedtls_ssl_context *ssl);
|
|
|
|
void mbedtls_ssl_update_out_pointers(mbedtls_ssl_context *ssl,
|
|
|
|
mbedtls_ssl_transform *transform);
|
|
|
|
void mbedtls_ssl_update_in_pointers(mbedtls_ssl_context *ssl);
|
2020-02-05 11:40:57 +01:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_session_reset_int(mbedtls_ssl_context *ssl, int partial);
|
|
|
|
void mbedtls_ssl_session_reset_msg_layer(mbedtls_ssl_context *ssl,
|
|
|
|
int partial);
|
2020-02-05 11:44:56 +01:00
|
|
|
|
2021-09-13 13:26:39 +02:00
|
|
|
/*
|
2021-09-14 16:17:21 +02:00
|
|
|
* Send pending alert
|
2021-09-13 13:26:39 +02:00
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_handle_pending_alert(mbedtls_ssl_context *ssl);
|
2021-09-13 13:26:39 +02:00
|
|
|
|
2021-09-14 16:17:21 +02:00
|
|
|
/*
|
|
|
|
* Set pending fatal alert flag.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_pend_fatal_alert(mbedtls_ssl_context *ssl,
|
|
|
|
unsigned char alert_type,
|
|
|
|
int alert_reason);
|
2021-09-14 16:17:21 +02:00
|
|
|
|
|
|
|
/* Alias of mbedtls_ssl_pend_fatal_alert */
|
2023-01-11 14:50:10 +01:00
|
|
|
#define MBEDTLS_SSL_PEND_FATAL_ALERT(type, user_return_value) \
|
|
|
|
mbedtls_ssl_pend_fatal_alert(ssl, type, user_return_value)
|
2021-09-14 16:17:21 +02:00
|
|
|
|
2020-02-05 11:45:48 +01:00
|
|
|
#if defined(MBEDTLS_SSL_DTLS_ANTI_REPLAY)
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_dtls_replay_reset(mbedtls_ssl_context *ssl);
|
2020-02-05 11:45:48 +01:00
|
|
|
#endif
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ssl_handshake_wrapup_free_hs_transform(mbedtls_ssl_context *ssl);
|
2020-02-05 11:47:44 +01:00
|
|
|
|
2020-02-11 16:40:07 +01:00
|
|
|
#if defined(MBEDTLS_SSL_RENEGOTIATION)
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_start_renegotiation(mbedtls_ssl_context *ssl);
|
2020-02-11 16:40:07 +01:00
|
|
|
#endif /* MBEDTLS_SSL_RENEGOTIATION */
|
2020-02-05 11:50:12 +01:00
|
|
|
|
2020-02-05 11:49:13 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t mbedtls_ssl_get_current_mtu(const mbedtls_ssl_context *ssl);
|
|
|
|
void mbedtls_ssl_buffering_free(mbedtls_ssl_context *ssl);
|
|
|
|
void mbedtls_ssl_flight_free(mbedtls_ssl_flight_item *flight);
|
2020-02-05 11:49:13 +01:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_DTLS */
|
|
|
|
|
2021-08-04 04:13:52 +02:00
|
|
|
/**
|
|
|
|
* ssl utils functions for checking configuration.
|
|
|
|
*/
|
|
|
|
|
2021-12-08 16:57:54 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_conf_is_tls13_only(const mbedtls_ssl_config *conf)
|
2021-08-04 04:13:52 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return conf->min_tls_version == MBEDTLS_SSL_VERSION_TLS1_3 &&
|
|
|
|
conf->max_tls_version == MBEDTLS_SSL_VERSION_TLS1_3;
|
2021-08-04 04:13:52 +02:00
|
|
|
}
|
2022-01-11 10:13:16 +01:00
|
|
|
|
2021-12-08 16:57:54 +01:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
|
2021-08-04 04:13:52 +02:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_conf_is_tls12_only(const mbedtls_ssl_config *conf)
|
2021-08-04 04:13:52 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return conf->min_tls_version == MBEDTLS_SSL_VERSION_TLS1_2 &&
|
|
|
|
conf->max_tls_version == MBEDTLS_SSL_VERSION_TLS1_2;
|
2021-08-04 04:13:52 +02:00
|
|
|
}
|
2022-01-11 10:13:16 +01:00
|
|
|
|
2021-08-04 04:13:52 +02:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_conf_is_tls13_enabled(const mbedtls_ssl_config *conf)
|
2022-01-11 10:13:16 +01:00
|
|
|
{
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2023-01-11 14:50:10 +01:00
|
|
|
return conf->min_tls_version <= MBEDTLS_SSL_VERSION_TLS1_3 &&
|
|
|
|
conf->max_tls_version >= MBEDTLS_SSL_VERSION_TLS1_3;
|
2022-01-11 10:13:16 +01:00
|
|
|
#else
|
|
|
|
((void) conf);
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-01-11 10:13:16 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_conf_is_tls12_enabled(const mbedtls_ssl_config *conf)
|
2022-01-11 10:13:16 +01:00
|
|
|
{
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
2023-01-11 14:50:10 +01:00
|
|
|
return conf->min_tls_version <= MBEDTLS_SSL_VERSION_TLS1_2 &&
|
|
|
|
conf->max_tls_version >= MBEDTLS_SSL_VERSION_TLS1_2;
|
2022-01-11 10:13:16 +01:00
|
|
|
#else
|
|
|
|
((void) conf);
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-01-11 10:13:16 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-12-08 16:57:54 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2) && defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_conf_is_hybrid_tls12_tls13(const mbedtls_ssl_config *conf)
|
2021-08-04 04:13:52 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return conf->min_tls_version == MBEDTLS_SSL_VERSION_TLS1_2 &&
|
|
|
|
conf->max_tls_version == MBEDTLS_SSL_VERSION_TLS1_3;
|
2021-08-04 04:13:52 +02:00
|
|
|
}
|
2021-12-08 16:57:54 +01:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 && MBEDTLS_SSL_PROTO_TLS1_3 */
|
2021-08-04 04:13:52 +02:00
|
|
|
|
2021-12-08 16:57:54 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2022-04-25 13:31:51 +02:00
|
|
|
extern const uint8_t mbedtls_ssl_tls13_hello_retry_request_magic[
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_SERVER_HELLO_RANDOM_LEN];
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_process_finished_message(mbedtls_ssl_context *ssl);
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_write_finished_message(mbedtls_ssl_context *ssl);
|
|
|
|
void mbedtls_ssl_tls13_handshake_wrapup(mbedtls_ssl_context *ssl);
|
2021-11-17 10:54:13 +01:00
|
|
|
|
2022-02-18 17:24:56 +01:00
|
|
|
/**
|
|
|
|
* \brief Given an SSL context and its associated configuration, write the TLS
|
|
|
|
* 1.3 specific extensions of the ClientHello message.
|
|
|
|
*
|
|
|
|
* \param[in] ssl SSL context
|
|
|
|
* \param[in] buf Base address of the buffer where to write the extensions
|
|
|
|
* \param[in] end End address of the buffer where to write the extensions
|
|
|
|
* \param[out] out_len Length of the data written into the buffer \p buf
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_write_client_hello_exts(mbedtls_ssl_context *ssl,
|
|
|
|
unsigned char *buf,
|
|
|
|
unsigned char *end,
|
|
|
|
size_t *out_len);
|
2022-02-18 17:24:56 +01:00
|
|
|
|
2021-11-17 10:54:13 +01:00
|
|
|
/**
|
|
|
|
* \brief TLS 1.3 client side state machine entry
|
|
|
|
*
|
|
|
|
* \param ssl SSL context
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_handshake_client_step(mbedtls_ssl_context *ssl);
|
2021-11-17 10:54:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief TLS 1.3 server side state machine entry
|
|
|
|
*
|
|
|
|
* \param ssl SSL context
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_handshake_server_step(mbedtls_ssl_context *ssl);
|
2021-11-17 10:54:13 +01:00
|
|
|
|
|
|
|
|
2021-08-23 11:42:37 +02:00
|
|
|
/*
|
|
|
|
* Helper functions around key exchange modes.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline unsigned mbedtls_ssl_conf_tls13_check_kex_modes(mbedtls_ssl_context *ssl,
|
|
|
|
int kex_mode_mask)
|
2021-08-23 11:42:37 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return (ssl->conf->tls13_kex_modes & kex_mode_mask) != 0;
|
2021-08-23 11:42:37 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_conf_tls13_psk_enabled(mbedtls_ssl_context *ssl)
|
2021-08-23 11:42:37 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_conf_tls13_check_kex_modes(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK);
|
2021-08-23 11:42:37 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_conf_tls13_psk_ephemeral_enabled(mbedtls_ssl_context *ssl)
|
2021-08-23 11:42:37 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_conf_tls13_check_kex_modes(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL);
|
2021-08-23 11:42:37 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_conf_tls13_ephemeral_enabled(mbedtls_ssl_context *ssl)
|
2021-08-23 11:42:37 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_conf_tls13_check_kex_modes(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL);
|
2021-08-23 11:42:37 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_conf_tls13_some_ephemeral_enabled(mbedtls_ssl_context *ssl)
|
2021-08-23 11:42:37 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_conf_tls13_check_kex_modes(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ALL);
|
2021-08-23 11:42:37 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_conf_tls13_some_psk_enabled(mbedtls_ssl_context *ssl)
|
2021-08-23 11:42:37 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_conf_tls13_check_kex_modes(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL);
|
2021-08-23 11:42:37 +02:00
|
|
|
}
|
|
|
|
|
2022-10-04 16:38:25 +02:00
|
|
|
#if defined(MBEDTLS_SSL_SRV_C) && \
|
|
|
|
defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED)
|
2021-09-29 15:22:08 +02:00
|
|
|
/**
|
|
|
|
* Given a list of key exchange modes, check if at least one of them is
|
|
|
|
* supported.
|
|
|
|
*
|
|
|
|
* \param[in] ssl SSL context
|
2021-09-30 03:52:35 +02:00
|
|
|
* \param kex_modes_mask Mask of the key exchange modes to check
|
2021-09-29 15:22:08 +02:00
|
|
|
*
|
|
|
|
* \return 0 if at least one of the key exchange modes is supported,
|
2021-10-08 08:19:29 +02:00
|
|
|
* !=0 otherwise.
|
2021-09-29 15:22:08 +02:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline unsigned mbedtls_ssl_tls13_check_kex_modes(mbedtls_ssl_context *ssl,
|
|
|
|
int kex_modes_mask)
|
2021-09-09 11:09:12 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return (ssl->handshake->tls13_kex_modes & kex_modes_mask) == 0;
|
2021-09-09 11:09:12 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_tls13_psk_enabled(mbedtls_ssl_context *ssl)
|
2021-09-09 11:09:12 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return !mbedtls_ssl_tls13_check_kex_modes(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK);
|
2021-09-09 11:09:12 +02:00
|
|
|
}
|
|
|
|
|
2021-11-12 09:53:56 +01:00
|
|
|
static inline int mbedtls_ssl_tls13_psk_ephemeral_enabled(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_context *ssl)
|
2021-09-09 11:09:12 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return !mbedtls_ssl_tls13_check_kex_modes(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_EPHEMERAL);
|
2021-09-09 11:09:12 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_tls13_ephemeral_enabled(mbedtls_ssl_context *ssl)
|
2021-09-09 11:09:12 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return !mbedtls_ssl_tls13_check_kex_modes(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL);
|
2021-09-09 11:09:12 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_tls13_some_ephemeral_enabled(mbedtls_ssl_context *ssl)
|
2021-09-09 11:09:12 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return !mbedtls_ssl_tls13_check_kex_modes(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ALL);
|
2021-09-09 11:09:12 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_tls13_some_psk_enabled(mbedtls_ssl_context *ssl)
|
2021-09-09 11:09:12 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return !mbedtls_ssl_tls13_check_kex_modes(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL);
|
2021-09-09 11:09:12 +02:00
|
|
|
}
|
2022-10-04 16:38:25 +02:00
|
|
|
#endif /* MBEDTLS_SSL_SRV_C &&
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED */
|
2021-09-09 11:09:12 +02:00
|
|
|
|
2022-08-04 10:29:22 +02:00
|
|
|
/*
|
2022-11-08 14:01:17 +01:00
|
|
|
* Helper functions for extensions checking.
|
2022-08-04 10:29:22 +02:00
|
|
|
*/
|
|
|
|
|
2022-08-29 09:25:36 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2022-10-29 03:08:47 +02:00
|
|
|
int mbedtls_ssl_tls13_check_received_extension(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_context *ssl,
|
|
|
|
int hs_msg_type,
|
|
|
|
unsigned int received_extension_type,
|
|
|
|
uint32_t hs_msg_allowed_extensions_mask);
|
2022-10-29 03:08:47 +02:00
|
|
|
|
|
|
|
static inline void mbedtls_ssl_tls13_set_hs_sent_ext_mask(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_context *ssl, unsigned int extension_type)
|
2022-08-29 09:25:36 +02:00
|
|
|
{
|
|
|
|
ssl->handshake->sent_extensions |=
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_get_extension_mask(extension_type);
|
2022-08-29 09:25:36 +02:00
|
|
|
}
|
2022-08-04 10:29:22 +02:00
|
|
|
|
2022-07-20 16:44:00 +02:00
|
|
|
/*
|
|
|
|
* Helper functions to check the selected key exchange mode.
|
|
|
|
*/
|
|
|
|
static inline int mbedtls_ssl_tls13_key_exchange_mode_check(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_context *ssl, int kex_mask)
|
2022-07-20 16:44:00 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return (ssl->handshake->key_exchange_mode & kex_mask) != 0;
|
2022-07-20 16:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mbedtls_ssl_tls13_key_exchange_mode_with_psk(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_context *ssl)
|
2022-07-20 16:44:00 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_tls13_key_exchange_mode_check(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_PSK_ALL);
|
2022-07-20 16:44:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mbedtls_ssl_tls13_key_exchange_mode_with_ephemeral(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_context *ssl)
|
2022-07-20 16:44:00 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_tls13_key_exchange_mode_check(ssl,
|
|
|
|
MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ALL);
|
2022-07-20 16:44:00 +02:00
|
|
|
}
|
|
|
|
|
2021-09-24 09:51:16 +02:00
|
|
|
/*
|
|
|
|
* Fetch TLS 1.3 handshake message header
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_fetch_handshake_msg(mbedtls_ssl_context *ssl,
|
|
|
|
unsigned hs_type,
|
|
|
|
unsigned char **buf,
|
|
|
|
size_t *buf_len);
|
2021-09-24 09:51:16 +02:00
|
|
|
|
2021-09-29 11:12:03 +02:00
|
|
|
/*
|
|
|
|
* Handler of TLS 1.3 server certificate message
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_process_certificate(mbedtls_ssl_context *ssl);
|
2021-09-29 11:12:03 +02:00
|
|
|
|
2022-10-04 16:14:26 +02:00
|
|
|
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED)
|
2022-01-28 09:16:08 +01:00
|
|
|
/*
|
2022-02-15 04:05:59 +01:00
|
|
|
* Handler of TLS 1.3 write Certificate message
|
2022-01-28 09:16:08 +01:00
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_write_certificate(mbedtls_ssl_context *ssl);
|
2022-01-28 09:16:08 +01:00
|
|
|
|
2022-01-29 03:01:04 +01:00
|
|
|
/*
|
2022-02-15 04:05:59 +01:00
|
|
|
* Handler of TLS 1.3 write Certificate Verify message
|
2022-01-29 03:01:04 +01:00
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_write_certificate_verify(mbedtls_ssl_context *ssl);
|
2022-01-29 15:12:42 +01:00
|
|
|
|
2022-10-04 16:14:26 +02:00
|
|
|
#endif /* MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED */
|
2022-01-29 15:12:42 +01:00
|
|
|
|
2021-09-12 14:16:03 +02:00
|
|
|
/*
|
|
|
|
* Generic handler of Certificate Verify
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_process_certificate_verify(mbedtls_ssl_context *ssl);
|
2021-09-12 14:16:03 +02:00
|
|
|
|
2021-11-24 16:25:31 +01:00
|
|
|
/*
|
|
|
|
* Write of dummy-CCS's for middlebox compatibility
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_write_change_cipher_spec(mbedtls_ssl_context *ssl);
|
2021-11-24 16:25:31 +01:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_reset_transcript_for_hrr(mbedtls_ssl_context *ssl);
|
2021-12-07 10:16:29 +01:00
|
|
|
|
2023-03-20 15:22:47 +01:00
|
|
|
#if defined(PSA_WANT_ALG_ECDH)
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2022-03-30 16:43:29 +02:00
|
|
|
int mbedtls_ssl_tls13_generate_and_write_ecdh_key_exchange(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_context *ssl,
|
|
|
|
uint16_t named_group,
|
|
|
|
unsigned char *buf,
|
|
|
|
unsigned char *end,
|
|
|
|
size_t *out_len);
|
2023-03-20 15:22:47 +01:00
|
|
|
#endif /* PSA_WANT_ALG_ECDH */
|
2022-03-30 16:43:29 +02:00
|
|
|
|
2022-10-24 13:12:51 +02:00
|
|
|
#if defined(MBEDTLS_SSL_EARLY_DATA)
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_write_early_data_ext(mbedtls_ssl_context *ssl,
|
|
|
|
unsigned char *buf,
|
|
|
|
const unsigned char *end,
|
|
|
|
size_t *out_len);
|
2022-10-24 13:12:51 +02:00
|
|
|
#endif /* MBEDTLS_SSL_EARLY_DATA */
|
2022-03-30 16:43:29 +02:00
|
|
|
|
2022-01-12 08:49:48 +01:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 */
|
|
|
|
|
2022-10-05 12:46:29 +02:00
|
|
|
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
2022-12-01 12:43:12 +01:00
|
|
|
/*
|
|
|
|
* Write Signature Algorithm extension
|
|
|
|
*/
|
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_write_sig_alg_ext(mbedtls_ssl_context *ssl, unsigned char *buf,
|
|
|
|
const unsigned char *end, size_t *out_len);
|
2022-01-20 09:25:00 +01:00
|
|
|
/*
|
2022-05-10 13:20:55 +02:00
|
|
|
* Parse TLS Signature Algorithm extension
|
2022-01-20 09:25:00 +01:00
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_parse_sig_alg_ext(mbedtls_ssl_context *ssl,
|
|
|
|
const unsigned char *buf,
|
|
|
|
const unsigned char *end);
|
2022-10-05 12:46:29 +02:00
|
|
|
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
2021-08-18 10:38:40 +02:00
|
|
|
|
2021-09-14 05:12:51 +02:00
|
|
|
/* Get handshake transcript */
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_get_handshake_transcript(mbedtls_ssl_context *ssl,
|
|
|
|
const mbedtls_md_type_t md,
|
|
|
|
unsigned char *dst,
|
|
|
|
size_t dst_len,
|
|
|
|
size_t *olen);
|
2021-09-14 05:12:51 +02:00
|
|
|
|
2021-08-17 10:53:13 +02:00
|
|
|
/*
|
|
|
|
* Return supported groups.
|
|
|
|
*
|
|
|
|
* In future, invocations can be changed to ssl->conf->group_list
|
|
|
|
* when mbedtls_ssl_conf_curves() is deleted.
|
|
|
|
*
|
|
|
|
* ssl->handshake->group_list is either a translation of curve_list to IANA TLS group
|
|
|
|
* identifiers when mbedtls_ssl_conf_curves() has been used, or a pointer to
|
|
|
|
* ssl->conf->group_list when mbedtls_ssl_conf_groups() has been more recently invoked.
|
|
|
|
*
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline const void *mbedtls_ssl_get_groups(const mbedtls_ssl_context *ssl)
|
2021-08-17 10:53:13 +02:00
|
|
|
{
|
|
|
|
#if defined(MBEDTLS_DEPRECATED_REMOVED) || !defined(MBEDTLS_ECP_C)
|
2023-01-11 14:50:10 +01:00
|
|
|
return ssl->conf->group_list;
|
2021-08-17 10:53:13 +02:00
|
|
|
#else
|
2023-01-11 14:50:10 +01:00
|
|
|
if ((ssl->handshake != NULL) && (ssl->handshake->group_list != NULL)) {
|
|
|
|
return ssl->handshake->group_list;
|
|
|
|
} else {
|
|
|
|
return ssl->conf->group_list;
|
|
|
|
}
|
2021-08-17 10:53:13 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-12-20 15:22:15 +01:00
|
|
|
/*
|
|
|
|
* Helper functions for NamedGroup.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_tls12_named_group_is_ecdhe(uint16_t named_group)
|
2021-12-20 15:22:15 +01:00
|
|
|
{
|
|
|
|
/*
|
2022-01-11 10:13:16 +01:00
|
|
|
* RFC 8422 section 5.1.1
|
2021-12-20 15:22:15 +01:00
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
return named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X25519 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_BP256R1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_BP384R1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_BP512R1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X448 ||
|
|
|
|
/* Below deprecated curves should be removed with notice to users */
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP192K1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP192R1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP224K1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP224R1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP256K1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1;
|
2021-12-20 15:22:15 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_tls13_named_group_is_ecdhe(uint16_t named_group)
|
2021-12-20 15:22:15 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X25519 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP256R1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP384R1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_SECP521R1 ||
|
|
|
|
named_group == MBEDTLS_SSL_IANA_TLS_GROUP_X448;
|
2021-12-20 15:22:15 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_tls13_named_group_is_dhe(uint16_t named_group)
|
2021-12-20 15:22:15 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
return named_group >= MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE2048 &&
|
|
|
|
named_group <= MBEDTLS_SSL_IANA_TLS_GROUP_FFDHE8192;
|
2021-12-20 15:22:15 +01:00
|
|
|
}
|
|
|
|
|
2022-04-20 09:16:41 +02:00
|
|
|
static inline int mbedtls_ssl_named_group_is_offered(
|
2023-01-11 14:50:10 +01:00
|
|
|
const mbedtls_ssl_context *ssl, uint16_t named_group)
|
2022-04-20 09:16:41 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint16_t *group_list = mbedtls_ssl_get_groups(ssl);
|
2022-04-20 09:16:41 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (group_list == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-04-20 09:16:41 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (; *group_list != 0; group_list++) {
|
|
|
|
if (*group_list == named_group) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-04-20 09:16:41 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-04-20 09:16:41 +02:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_named_group_is_supported(uint16_t named_group)
|
2022-04-20 09:16:41 +02:00
|
|
|
{
|
2023-03-20 15:22:47 +01:00
|
|
|
#if defined(PSA_WANT_ALG_ECDH)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (mbedtls_ssl_tls13_named_group_is_ecdhe(named_group)) {
|
|
|
|
if (mbedtls_ssl_get_ecp_group_id_from_tls_id(named_group) !=
|
|
|
|
MBEDTLS_ECP_DP_NONE) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-04-20 09:16:41 +02:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
((void) named_group);
|
2023-03-20 15:22:47 +01:00
|
|
|
#endif /* PSA_WANT_ALG_ECDH */
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-04-20 09:16:41 +02:00
|
|
|
}
|
|
|
|
|
2021-12-22 03:49:02 +01:00
|
|
|
/*
|
2022-01-17 11:16:35 +01:00
|
|
|
* Return supported signature algorithms.
|
|
|
|
*
|
|
|
|
* In future, invocations can be changed to ssl->conf->sig_algs when
|
|
|
|
* mbedtls_ssl_conf_sig_hashes() is deleted.
|
|
|
|
*
|
2022-01-19 04:08:05 +01:00
|
|
|
* ssl->handshake->sig_algs is either a translation of sig_hashes to IANA TLS
|
|
|
|
* signature algorithm identifiers when mbedtls_ssl_conf_sig_hashes() has been
|
|
|
|
* used, or a pointer to ssl->conf->sig_algs when mbedtls_ssl_conf_sig_algs() has
|
|
|
|
* been more recently invoked.
|
|
|
|
*
|
2021-12-22 03:49:02 +01:00
|
|
|
*/
|
2022-01-17 11:16:35 +01:00
|
|
|
static inline const void *mbedtls_ssl_get_sig_algs(
|
2023-01-11 14:50:10 +01:00
|
|
|
const mbedtls_ssl_context *ssl)
|
2021-12-22 03:49:02 +01:00
|
|
|
{
|
2022-10-05 12:46:29 +02:00
|
|
|
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
2022-01-28 10:05:56 +01:00
|
|
|
|
2022-01-12 09:36:14 +01:00
|
|
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl->handshake != NULL &&
|
2022-06-27 10:27:35 +02:00
|
|
|
ssl->handshake->sig_algs_heap_allocated == 1 &&
|
2023-01-11 14:50:10 +01:00
|
|
|
ssl->handshake->sig_algs != NULL) {
|
|
|
|
return ssl->handshake->sig_algs;
|
2022-06-24 13:35:40 +02:00
|
|
|
}
|
2022-01-12 09:36:14 +01:00
|
|
|
#endif
|
2023-01-11 14:50:10 +01:00
|
|
|
return ssl->conf->sig_algs;
|
2022-01-28 10:05:56 +01:00
|
|
|
|
2022-10-05 12:46:29 +02:00
|
|
|
#else /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
2021-12-22 03:49:02 +01:00
|
|
|
|
2022-01-12 09:36:14 +01:00
|
|
|
((void) ssl);
|
2023-01-11 14:50:10 +01:00
|
|
|
return NULL;
|
2022-10-05 12:46:29 +02:00
|
|
|
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
2021-12-22 03:49:02 +01:00
|
|
|
}
|
2021-12-20 15:22:15 +01:00
|
|
|
|
2022-10-04 16:14:26 +02:00
|
|
|
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED)
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_sig_alg_is_received(const mbedtls_ssl_context *ssl,
|
|
|
|
uint16_t own_sig_alg)
|
2022-01-29 03:01:04 +01:00
|
|
|
{
|
2022-01-30 03:52:11 +01:00
|
|
|
const uint16_t *sig_alg = ssl->handshake->received_sig_algs;
|
2023-01-11 14:50:10 +01:00
|
|
|
if (sig_alg == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-01-30 03:52:11 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (; *sig_alg != MBEDTLS_TLS_SIG_NONE; sig_alg++) {
|
|
|
|
if (*sig_alg == own_sig_alg) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-01-30 03:52:11 +01:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-01-29 03:01:04 +01:00
|
|
|
}
|
|
|
|
|
2022-06-24 04:10:47 +02:00
|
|
|
static inline int mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported(
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint16_t sig_alg)
|
2022-06-21 10:34:57 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (sig_alg) {
|
2023-02-22 12:38:07 +01:00
|
|
|
#if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
|
2022-09-14 09:09:16 +02:00
|
|
|
#if defined(PSA_WANT_ALG_SHA_256) && defined(MBEDTLS_ECP_DP_SECP256R1_ENABLED)
|
2022-03-23 06:34:04 +01:00
|
|
|
case MBEDTLS_TLS1_3_SIG_ECDSA_SECP256R1_SHA256:
|
|
|
|
break;
|
2022-09-14 09:09:16 +02:00
|
|
|
#endif /* PSA_WANT_ALG_SHA_256 && MBEDTLS_ECP_DP_SECP256R1_ENABLED */
|
|
|
|
#if defined(PSA_WANT_ALG_SHA_384) && defined(MBEDTLS_ECP_DP_SECP384R1_ENABLED)
|
2022-03-23 06:34:04 +01:00
|
|
|
case MBEDTLS_TLS1_3_SIG_ECDSA_SECP384R1_SHA384:
|
|
|
|
break;
|
2022-09-14 09:09:16 +02:00
|
|
|
#endif /* PSA_WANT_ALG_SHA_384 && MBEDTLS_ECP_DP_SECP384R1_ENABLED */
|
|
|
|
#if defined(PSA_WANT_ALG_SHA_512) && defined(MBEDTLS_ECP_DP_SECP521R1_ENABLED)
|
2022-03-23 06:34:04 +01:00
|
|
|
case MBEDTLS_TLS1_3_SIG_ECDSA_SECP521R1_SHA512:
|
|
|
|
break;
|
2022-09-14 09:09:16 +02:00
|
|
|
#endif /* PSA_WANT_ALG_SHA_512 && MBEDTLS_ECP_DP_SECP521R1_ENABLED */
|
2023-02-22 12:38:07 +01:00
|
|
|
#endif /* MBEDTLS_PK_CAN_ECDSA_SOME */
|
2022-03-23 14:01:33 +01:00
|
|
|
|
2022-07-01 12:03:31 +02:00
|
|
|
#if defined(MBEDTLS_PKCS1_V21)
|
2022-09-14 09:09:16 +02:00
|
|
|
#if defined(PSA_WANT_ALG_SHA_256)
|
2022-03-23 06:34:04 +01:00
|
|
|
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256:
|
|
|
|
break;
|
2022-09-14 09:09:16 +02:00
|
|
|
#endif /* PSA_WANT_ALG_SHA_256 */
|
|
|
|
#if defined(PSA_WANT_ALG_SHA_384)
|
2022-03-23 06:34:04 +01:00
|
|
|
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384:
|
|
|
|
break;
|
2022-09-14 09:09:16 +02:00
|
|
|
#endif /* PSA_WANT_ALG_SHA_384 */
|
|
|
|
#if defined(PSA_WANT_ALG_SHA_512)
|
2022-03-23 06:34:04 +01:00
|
|
|
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512:
|
|
|
|
break;
|
2022-09-14 09:09:16 +02:00
|
|
|
#endif /* PSA_WANT_ALG_SHA_512 */
|
2022-07-01 12:03:31 +02:00
|
|
|
#endif /* MBEDTLS_PKCS1_V21 */
|
2022-06-21 10:34:57 +02:00
|
|
|
default:
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-06-21 10:34:57 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return 1;
|
2022-03-23 06:34:04 +01:00
|
|
|
|
2022-06-22 13:30:32 +02:00
|
|
|
}
|
2022-03-23 14:01:33 +01:00
|
|
|
|
2022-06-22 13:30:32 +02:00
|
|
|
static inline int mbedtls_ssl_tls13_sig_alg_is_supported(
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint16_t sig_alg)
|
2022-06-22 13:30:32 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (sig_alg) {
|
2022-07-01 12:03:31 +02:00
|
|
|
#if defined(MBEDTLS_PKCS1_V15)
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA256)
|
2022-03-23 06:34:04 +01:00
|
|
|
case MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA256:
|
|
|
|
break;
|
2023-03-17 12:50:01 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA256 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA384)
|
2022-03-23 06:34:04 +01:00
|
|
|
case MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA384:
|
|
|
|
break;
|
2023-03-17 12:50:01 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA384 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA512)
|
2022-03-23 06:34:04 +01:00
|
|
|
case MBEDTLS_TLS1_3_SIG_RSA_PKCS1_SHA512:
|
|
|
|
break;
|
2023-03-17 12:50:01 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA512 */
|
2022-07-01 12:03:31 +02:00
|
|
|
#endif /* MBEDTLS_PKCS1_V15 */
|
2022-06-22 13:30:32 +02:00
|
|
|
default:
|
2023-01-11 14:50:10 +01:00
|
|
|
return mbedtls_ssl_tls13_sig_alg_for_cert_verify_is_supported(
|
|
|
|
sig_alg);
|
2022-06-22 13:30:32 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return 1;
|
2022-03-23 06:34:04 +01:00
|
|
|
}
|
2022-10-11 08:20:56 +02:00
|
|
|
|
2022-10-04 16:14:26 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_check_sig_alg_cert_key_match(uint16_t sig_alg,
|
|
|
|
mbedtls_pk_context *key);
|
2022-10-04 16:14:26 +02:00
|
|
|
#endif /* MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED */
|
|
|
|
|
2022-10-05 12:46:29 +02:00
|
|
|
#if defined(MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED)
|
2023-01-11 14:50:10 +01:00
|
|
|
static inline int mbedtls_ssl_sig_alg_is_offered(const mbedtls_ssl_context *ssl,
|
|
|
|
uint16_t proposed_sig_alg)
|
2022-10-04 16:14:26 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint16_t *sig_alg = mbedtls_ssl_get_sig_algs(ssl);
|
|
|
|
if (sig_alg == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-10-04 16:14:26 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (; *sig_alg != MBEDTLS_TLS_SIG_NONE; sig_alg++) {
|
|
|
|
if (*sig_alg == proposed_sig_alg) {
|
|
|
|
return 1;
|
|
|
|
}
|
2022-10-04 16:14:26 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-10-04 16:14:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mbedtls_ssl_get_pk_type_and_md_alg_from_sig_alg(
|
2023-01-11 14:50:10 +01:00
|
|
|
uint16_t sig_alg, mbedtls_pk_type_t *pk_type, mbedtls_md_type_t *md_alg)
|
2022-10-04 16:14:26 +02:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
*pk_type = mbedtls_ssl_pk_alg_from_sig(sig_alg & 0xff);
|
|
|
|
*md_alg = mbedtls_ssl_md_alg_from_hash((sig_alg >> 8) & 0xff);
|
2022-10-04 16:14:26 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (*pk_type != MBEDTLS_PK_NONE && *md_alg != MBEDTLS_MD_NONE) {
|
|
|
|
return 0;
|
|
|
|
}
|
2022-10-04 16:14:26 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (sig_alg) {
|
2022-10-04 16:14:26 +02:00
|
|
|
#if defined(MBEDTLS_PKCS1_V21)
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA256)
|
2022-10-04 16:14:26 +02:00
|
|
|
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA256:
|
|
|
|
*md_alg = MBEDTLS_MD_SHA256;
|
|
|
|
*pk_type = MBEDTLS_PK_RSASSA_PSS;
|
|
|
|
break;
|
2023-03-17 12:50:01 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA256 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA384)
|
2022-10-04 16:14:26 +02:00
|
|
|
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA384:
|
|
|
|
*md_alg = MBEDTLS_MD_SHA384;
|
|
|
|
*pk_type = MBEDTLS_PK_RSASSA_PSS;
|
|
|
|
break;
|
2023-03-17 12:50:01 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA384 */
|
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA512)
|
2022-10-04 16:14:26 +02:00
|
|
|
case MBEDTLS_TLS1_3_SIG_RSA_PSS_RSAE_SHA512:
|
|
|
|
*md_alg = MBEDTLS_MD_SHA512;
|
|
|
|
*pk_type = MBEDTLS_PK_RSASSA_PSS;
|
|
|
|
break;
|
2023-03-17 12:50:01 +01:00
|
|
|
#endif /* MBEDTLS_MD_CAN_SHA512 */
|
2022-10-04 16:14:26 +02:00
|
|
|
#endif /* MBEDTLS_PKCS1_V21 */
|
2023-01-11 14:50:10 +01:00
|
|
|
default:
|
|
|
|
return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
return 0;
|
2022-10-04 16:14:26 +02:00
|
|
|
}
|
2022-03-23 06:34:04 +01:00
|
|
|
|
2022-06-16 07:54:47 +02:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
|
|
|
static inline int mbedtls_ssl_tls12_sig_alg_is_supported(
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint16_t sig_alg)
|
2022-01-19 10:43:22 +01:00
|
|
|
{
|
2022-06-16 07:54:47 +02:00
|
|
|
/* High byte is hash */
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char hash = MBEDTLS_BYTE_1(sig_alg);
|
|
|
|
unsigned char sig = MBEDTLS_BYTE_0(sig_alg);
|
2022-01-19 10:43:22 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (hash) {
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_MD5)
|
2022-06-16 07:54:47 +02:00
|
|
|
case MBEDTLS_SSL_HASH_MD5:
|
|
|
|
break;
|
2022-01-21 09:16:01 +01:00
|
|
|
#endif
|
|
|
|
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA1)
|
2022-06-16 07:54:47 +02:00
|
|
|
case MBEDTLS_SSL_HASH_SHA1:
|
|
|
|
break;
|
2022-01-21 09:16:01 +01:00
|
|
|
#endif
|
|
|
|
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA224)
|
2022-06-16 07:54:47 +02:00
|
|
|
case MBEDTLS_SSL_HASH_SHA224:
|
|
|
|
break;
|
2022-01-21 09:16:01 +01:00
|
|
|
#endif
|
|
|
|
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA256)
|
2022-06-16 07:54:47 +02:00
|
|
|
case MBEDTLS_SSL_HASH_SHA256:
|
|
|
|
break;
|
2022-01-21 09:16:01 +01:00
|
|
|
#endif
|
|
|
|
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA384)
|
2022-06-16 07:54:47 +02:00
|
|
|
case MBEDTLS_SSL_HASH_SHA384:
|
|
|
|
break;
|
2022-01-21 09:16:01 +01:00
|
|
|
#endif
|
|
|
|
|
2023-03-17 12:50:01 +01:00
|
|
|
#if defined(MBEDTLS_MD_CAN_SHA512)
|
2022-06-16 07:54:47 +02:00
|
|
|
case MBEDTLS_SSL_HASH_SHA512:
|
|
|
|
break;
|
2022-01-21 09:16:01 +01:00
|
|
|
#endif
|
2022-01-19 10:43:22 +01:00
|
|
|
|
2022-06-16 07:54:47 +02:00
|
|
|
default:
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-06-16 07:54:47 +02:00
|
|
|
}
|
2022-01-19 10:43:22 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (sig) {
|
2022-01-21 09:16:01 +01:00
|
|
|
#if defined(MBEDTLS_RSA_C)
|
2022-06-16 07:54:47 +02:00
|
|
|
case MBEDTLS_SSL_SIG_RSA:
|
|
|
|
break;
|
2022-01-21 09:16:01 +01:00
|
|
|
#endif
|
2022-01-19 10:43:22 +01:00
|
|
|
|
2023-02-22 12:38:07 +01:00
|
|
|
#if defined(MBEDTLS_PK_CAN_ECDSA_SOME)
|
2022-06-16 07:54:47 +02:00
|
|
|
case MBEDTLS_SSL_SIG_ECDSA:
|
|
|
|
break;
|
2022-01-21 09:16:01 +01:00
|
|
|
#endif
|
2022-01-19 10:43:22 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
default:
|
|
|
|
return 0;
|
2022-06-16 07:54:47 +02:00
|
|
|
}
|
2022-01-19 10:43:22 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
return 1;
|
2022-06-16 07:54:47 +02:00
|
|
|
}
|
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
2022-01-19 10:43:22 +01:00
|
|
|
|
2022-06-16 07:54:47 +02:00
|
|
|
static inline int mbedtls_ssl_sig_alg_is_supported(
|
2023-01-11 14:50:10 +01:00
|
|
|
const mbedtls_ssl_context *ssl,
|
|
|
|
const uint16_t sig_alg)
|
2022-06-16 07:54:47 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_2)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl->tls_version == MBEDTLS_SSL_VERSION_TLS1_2) {
|
|
|
|
return mbedtls_ssl_tls12_sig_alg_is_supported(sig_alg);
|
2022-01-19 10:43:22 +01:00
|
|
|
}
|
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_2 */
|
|
|
|
|
2022-10-04 16:14:26 +02:00
|
|
|
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_EPHEMERAL_ENABLED)
|
2023-01-11 14:50:10 +01:00
|
|
|
if (ssl->tls_version == MBEDTLS_SSL_VERSION_TLS1_3) {
|
|
|
|
return mbedtls_ssl_tls13_sig_alg_is_supported(sig_alg);
|
2022-01-19 10:43:22 +01:00
|
|
|
}
|
2022-10-04 16:14:26 +02:00
|
|
|
#endif
|
2022-01-19 10:43:22 +01:00
|
|
|
((void) ssl);
|
|
|
|
((void) sig_alg);
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-01-19 10:43:22 +01:00
|
|
|
}
|
2022-10-05 12:46:29 +02:00
|
|
|
#endif /* MBEDTLS_SSL_HANDSHAKE_WITH_CERT_ENABLED */
|
2022-01-19 10:43:22 +01:00
|
|
|
|
2022-05-18 11:44:56 +02:00
|
|
|
#if defined(MBEDTLS_USE_PSA_CRYPTO) || defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2022-01-25 00:56:34 +01:00
|
|
|
/* Corresponding PSA algorithm for MBEDTLS_CIPHER_NULL.
|
2022-04-13 20:28:52 +02:00
|
|
|
* Same value is used for PSA_ALG_CATEGORY_CIPHER, hence it is
|
2022-01-25 00:56:34 +01:00
|
|
|
* guaranteed to not be a valid PSA algorithm identifier.
|
|
|
|
*/
|
|
|
|
#define MBEDTLS_SSL_NULL_CIPHER 0x04000000
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Translate mbedtls cipher type/taglen pair to psa:
|
|
|
|
* algorithm, key type and key size.
|
|
|
|
*
|
|
|
|
* \param mbedtls_cipher_type [in] given mbedtls cipher type
|
|
|
|
* \param taglen [in] given tag length
|
|
|
|
* 0 - default tag length
|
|
|
|
* \param alg [out] corresponding PSA alg
|
|
|
|
* There is no corresponding PSA
|
2022-02-03 10:44:02 +01:00
|
|
|
* alg for MBEDTLS_CIPHER_NULL, so
|
|
|
|
* in this case MBEDTLS_SSL_NULL_CIPHER
|
|
|
|
* is returned via this parameter
|
2022-01-25 00:56:34 +01:00
|
|
|
* \param key_type [out] corresponding PSA key type
|
|
|
|
* \param key_size [out] corresponding PSA key size
|
|
|
|
*
|
|
|
|
* \return PSA_SUCCESS on success or PSA_ERROR_NOT_SUPPORTED if
|
|
|
|
* conversion is not supported.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_status_t mbedtls_ssl_cipher_to_psa(mbedtls_cipher_type_t mbedtls_cipher_type,
|
|
|
|
size_t taglen,
|
|
|
|
psa_algorithm_t *alg,
|
|
|
|
psa_key_type_t *key_type,
|
|
|
|
size_t *key_size);
|
2022-01-25 00:56:34 +01:00
|
|
|
|
2022-12-23 17:00:06 +01:00
|
|
|
#if !defined(MBEDTLS_DEPRECATED_REMOVED)
|
2022-01-25 00:56:34 +01:00
|
|
|
/**
|
|
|
|
* \brief Convert given PSA status to mbedtls error code.
|
|
|
|
*
|
|
|
|
* \param status [in] given PSA status
|
|
|
|
*
|
|
|
|
* \return corresponding mbedtls error code
|
|
|
|
*/
|
2022-12-23 17:00:06 +01:00
|
|
|
static inline MBEDTLS_DEPRECATED int psa_ssl_status_to_mbedtls(psa_status_t status)
|
2022-01-25 00:56:34 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (status) {
|
2022-01-25 00:56:34 +01:00
|
|
|
case PSA_SUCCESS:
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-01-25 00:56:34 +01:00
|
|
|
case PSA_ERROR_INSUFFICIENT_MEMORY:
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
|
2022-01-25 00:56:34 +01:00
|
|
|
case PSA_ERROR_NOT_SUPPORTED:
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
|
2022-01-31 09:18:07 +01:00
|
|
|
case PSA_ERROR_INVALID_SIGNATURE:
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_ERR_SSL_INVALID_MAC;
|
2022-03-21 12:17:49 +01:00
|
|
|
case PSA_ERROR_INVALID_ARGUMENT:
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
|
2022-03-21 12:17:49 +01:00
|
|
|
case PSA_ERROR_BAD_STATE:
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
2022-04-05 10:50:53 +02:00
|
|
|
case PSA_ERROR_BUFFER_TOO_SMALL:
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL;
|
2022-01-25 00:56:34 +01:00
|
|
|
default:
|
2023-01-11 14:50:10 +01:00
|
|
|
return MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED;
|
2022-01-25 00:56:34 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-23 17:00:06 +01:00
|
|
|
#endif /* !MBEDTLS_DEPRECATED_REMOVED */
|
2022-02-10 10:12:12 +01:00
|
|
|
#endif /* MBEDTLS_USE_PSA_CRYPTO || MBEDTLS_SSL_PROTO_TLS1_3 */
|
2022-01-19 10:43:22 +01:00
|
|
|
|
2022-11-15 14:08:42 +01:00
|
|
|
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \
|
|
|
|
defined(MBEDTLS_USE_PSA_CRYPTO)
|
2022-11-15 16:39:55 +01:00
|
|
|
|
2022-11-17 17:14:54 +01:00
|
|
|
typedef enum {
|
|
|
|
MBEDTLS_ECJPAKE_ROUND_ONE,
|
|
|
|
MBEDTLS_ECJPAKE_ROUND_TWO
|
|
|
|
} mbedtls_ecjpake_rounds_t;
|
|
|
|
|
2022-11-15 14:08:42 +01:00
|
|
|
/**
|
|
|
|
* \brief Parse the provided input buffer for getting the first round
|
|
|
|
* of key exchange. This code is common between server and client
|
|
|
|
*
|
|
|
|
* \param pake_ctx [in] the PAKE's operation/context structure
|
|
|
|
* \param buf [in] input buffer to parse
|
|
|
|
* \param len [in] length of the input buffer
|
2022-11-17 17:14:54 +01:00
|
|
|
* \param round [in] either MBEDTLS_ECJPAKE_ROUND_ONE or
|
|
|
|
* MBEDTLS_ECJPAKE_ROUND_TWO
|
2022-11-15 14:08:42 +01:00
|
|
|
*
|
|
|
|
* \return 0 on success or a negative error code in case of failure
|
|
|
|
*/
|
2022-11-17 17:14:54 +01:00
|
|
|
int mbedtls_psa_ecjpake_read_round(
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_pake_operation_t *pake_ctx,
|
|
|
|
const unsigned char *buf,
|
|
|
|
size_t len, mbedtls_ecjpake_rounds_t round);
|
2022-11-15 14:08:42 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Write the first round of key exchange into the provided output
|
|
|
|
* buffer. This code is common between server and client
|
|
|
|
*
|
|
|
|
* \param pake_ctx [in] the PAKE's operation/context structure
|
|
|
|
* \param buf [out] the output buffer in which data will be written to
|
|
|
|
* \param len [in] length of the output buffer
|
|
|
|
* \param olen [out] the length of the data really written on the buffer
|
2022-11-17 17:14:54 +01:00
|
|
|
* \param round [in] either MBEDTLS_ECJPAKE_ROUND_ONE or
|
|
|
|
* MBEDTLS_ECJPAKE_ROUND_TWO
|
2022-11-15 14:08:42 +01:00
|
|
|
*
|
|
|
|
* \return 0 on success or a negative error code in case of failure
|
|
|
|
*/
|
2022-11-17 17:14:54 +01:00
|
|
|
int mbedtls_psa_ecjpake_write_round(
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_pake_operation_t *pake_ctx,
|
|
|
|
unsigned char *buf,
|
|
|
|
size_t len, size_t *olen,
|
|
|
|
mbedtls_ecjpake_rounds_t round);
|
2022-11-15 14:08:42 +01:00
|
|
|
|
|
|
|
#endif //MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED && MBEDTLS_USE_PSA_CRYPTO
|
|
|
|
|
2022-03-30 10:57:37 +02:00
|
|
|
/**
|
|
|
|
* \brief TLS record protection modes
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
MBEDTLS_SSL_MODE_STREAM = 0,
|
|
|
|
MBEDTLS_SSL_MODE_CBC,
|
|
|
|
MBEDTLS_SSL_MODE_CBC_ETM,
|
|
|
|
MBEDTLS_SSL_MODE_AEAD
|
|
|
|
} mbedtls_ssl_mode_t;
|
|
|
|
|
2022-04-04 11:07:59 +02:00
|
|
|
mbedtls_ssl_mode_t mbedtls_ssl_get_mode_from_transform(
|
2023-01-11 14:50:10 +01:00
|
|
|
const mbedtls_ssl_transform *transform);
|
2022-03-30 10:57:37 +02:00
|
|
|
|
2022-04-05 11:16:53 +02:00
|
|
|
#if defined(MBEDTLS_SSL_SOME_SUITES_USE_CBC_ETM)
|
2022-04-04 11:07:59 +02:00
|
|
|
mbedtls_ssl_mode_t mbedtls_ssl_get_mode_from_ciphersuite(
|
2023-01-11 14:50:10 +01:00
|
|
|
int encrypt_then_mac,
|
|
|
|
const mbedtls_ssl_ciphersuite_t *suite);
|
2022-04-01 10:35:48 +02:00
|
|
|
#else
|
2022-04-04 11:07:59 +02:00
|
|
|
mbedtls_ssl_mode_t mbedtls_ssl_get_mode_from_ciphersuite(
|
2023-01-11 14:50:10 +01:00
|
|
|
const mbedtls_ssl_ciphersuite_t *suite);
|
2022-04-05 11:16:53 +02:00
|
|
|
#endif /* MBEDTLS_SSL_SOME_SUITES_USE_CBC_ETM */
|
2022-04-01 10:35:48 +02:00
|
|
|
|
2023-03-20 15:22:47 +01:00
|
|
|
#if defined(PSA_WANT_ALG_ECDH)
|
2022-04-10 12:20:43 +02:00
|
|
|
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_tls13_read_public_ecdhe_share(mbedtls_ssl_context *ssl,
|
|
|
|
const unsigned char *buf,
|
|
|
|
size_t buf_len);
|
2022-04-10 12:20:43 +02:00
|
|
|
|
2023-03-20 15:22:47 +01:00
|
|
|
#endif /* PSA_WANT_ALG_ECDH */
|
2022-04-10 12:20:43 +02:00
|
|
|
|
2022-04-21 05:01:38 +02:00
|
|
|
static inline int mbedtls_ssl_tls13_cipher_suite_is_offered(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_context *ssl, int cipher_suite)
|
2022-04-21 05:01:38 +02:00
|
|
|
{
|
|
|
|
const int *ciphersuite_list = ssl->conf->ciphersuite_list;
|
|
|
|
|
|
|
|
/* Check whether we have offered this ciphersuite */
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; ciphersuite_list[i] != 0; i++) {
|
|
|
|
if (ciphersuite_list[i] == cipher_suite) {
|
|
|
|
return 1;
|
2022-04-21 05:01:38 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
return 0;
|
2022-04-21 05:01:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Validate cipher suite against config in SSL context.
|
|
|
|
*
|
|
|
|
* \param ssl SSL context
|
|
|
|
* \param suite_info Cipher suite to validate
|
|
|
|
* \param min_tls_version Minimal TLS version to accept a cipher suite
|
|
|
|
* \param max_tls_version Maximal TLS version to accept a cipher suite
|
|
|
|
*
|
|
|
|
* \return 0 if valid, negative value otherwise.
|
|
|
|
*/
|
2022-06-17 10:53:58 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2022-04-21 05:01:38 +02:00
|
|
|
int mbedtls_ssl_validate_ciphersuite(
|
|
|
|
const mbedtls_ssl_context *ssl,
|
|
|
|
const mbedtls_ssl_ciphersuite_t *suite_info,
|
|
|
|
mbedtls_ssl_protocol_version min_tls_version,
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_protocol_version max_tls_version);
|
2022-04-20 09:16:41 +02:00
|
|
|
|
2022-05-07 11:02:40 +02:00
|
|
|
#if defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
|
2022-07-08 18:56:49 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_parse_server_name_ext(mbedtls_ssl_context *ssl,
|
|
|
|
const unsigned char *buf,
|
|
|
|
const unsigned char *end);
|
2022-05-07 11:02:40 +02:00
|
|
|
#endif /* MBEDTLS_SSL_SERVER_NAME_INDICATION */
|
|
|
|
|
2023-02-10 12:45:19 +01:00
|
|
|
#if defined(MBEDTLS_SSL_RECORD_SIZE_LIMIT)
|
2023-03-15 11:04:45 +01:00
|
|
|
#define MBEDTLS_SSL_RECORD_SIZE_LIMIT_EXTENSION_DATA_LENGTH (2)
|
|
|
|
#define MBEDTLS_SSL_RECORD_SIZE_LIMIT_MIN (64)
|
|
|
|
|
2023-02-10 12:45:19 +01:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
|
|
|
int mbedtls_ssl_tls13_parse_record_size_limit_ext(mbedtls_ssl_context *ssl,
|
|
|
|
const unsigned char *buf,
|
|
|
|
const unsigned char *end);
|
|
|
|
#endif /* MBEDTLS_SSL_RECORD_SIZE_LIMIT */
|
|
|
|
|
2022-06-17 12:18:48 +02:00
|
|
|
#if defined(MBEDTLS_SSL_ALPN)
|
2022-07-08 18:56:49 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_parse_alpn_ext(mbedtls_ssl_context *ssl,
|
|
|
|
const unsigned char *buf,
|
|
|
|
const unsigned char *end);
|
2022-06-17 12:18:48 +02:00
|
|
|
|
|
|
|
|
2022-07-08 18:56:49 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_write_alpn_ext(mbedtls_ssl_context *ssl,
|
|
|
|
unsigned char *buf,
|
|
|
|
unsigned char *end,
|
|
|
|
size_t *out_len);
|
2022-06-17 12:18:48 +02:00
|
|
|
#endif /* MBEDTLS_SSL_ALPN */
|
|
|
|
|
2022-06-06 19:08:23 +02:00
|
|
|
#if defined(MBEDTLS_TEST_HOOKS)
|
2022-06-08 17:47:33 +02:00
|
|
|
int mbedtls_ssl_check_dtls_clihlo_cookie(
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ssl_context *ssl,
|
|
|
|
const unsigned char *cli_id, size_t cli_id_len,
|
|
|
|
const unsigned char *in, size_t in_len,
|
|
|
|
unsigned char *obuf, size_t buf_len, size_t *olen);
|
2022-06-06 19:08:23 +02:00
|
|
|
#endif
|
|
|
|
|
2022-10-04 16:38:25 +02:00
|
|
|
#if defined(MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED)
|
2022-07-05 10:21:43 +02:00
|
|
|
/**
|
|
|
|
* \brief Given an SSL context and its associated configuration, write the TLS
|
|
|
|
* 1.3 specific Pre-Shared key extension.
|
|
|
|
*
|
|
|
|
* \param[in] ssl SSL context
|
|
|
|
* \param[in] buf Base address of the buffer where to write the extension
|
|
|
|
* \param[in] end End address of the buffer where to write the extension
|
2022-07-14 09:54:01 +02:00
|
|
|
* \param[out] out_len Length in bytes of the Pre-Shared key extension: data
|
|
|
|
* written into the buffer \p buf by this function plus
|
|
|
|
* the length of the binders to be written.
|
2022-07-05 10:21:43 +02:00
|
|
|
* \param[out] binders_len Length of the binders to be written at the end of
|
2022-07-14 09:54:01 +02:00
|
|
|
* the extension.
|
2022-07-05 10:21:43 +02:00
|
|
|
*/
|
2022-07-19 11:51:50 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2022-07-21 04:26:21 +02:00
|
|
|
int mbedtls_ssl_tls13_write_identities_of_pre_shared_key_ext(
|
2022-07-05 10:21:43 +02:00
|
|
|
mbedtls_ssl_context *ssl,
|
|
|
|
unsigned char *buf, unsigned char *end,
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t *out_len, size_t *binders_len);
|
2022-07-05 10:21:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Given an SSL context and its associated configuration, write the TLS
|
|
|
|
* 1.3 specific Pre-Shared key extension binders at the end of the
|
|
|
|
* ClientHello.
|
|
|
|
*
|
|
|
|
* \param[in] ssl SSL context
|
2022-07-14 09:54:01 +02:00
|
|
|
* \param[in] buf Base address of the buffer where to write the binders
|
|
|
|
* \param[in] end End address of the buffer where to write the binders
|
2022-07-05 10:21:43 +02:00
|
|
|
*/
|
2022-07-19 11:51:50 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
|
|
|
int mbedtls_ssl_tls13_write_binders_of_pre_shared_key_ext(
|
2022-07-05 10:21:43 +02:00
|
|
|
mbedtls_ssl_context *ssl,
|
2023-01-11 14:50:10 +01:00
|
|
|
unsigned char *buf, unsigned char *end);
|
2022-10-04 16:38:25 +02:00
|
|
|
#endif /* MBEDTLS_SSL_TLS1_3_KEY_EXCHANGE_MODE_SOME_PSK_ENABLED */
|
2022-07-05 10:21:43 +02:00
|
|
|
|
2022-10-11 08:20:56 +02:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && \
|
2022-10-12 04:49:52 +02:00
|
|
|
defined(MBEDTLS_SSL_SESSION_TICKETS) && \
|
2022-10-12 08:58:13 +02:00
|
|
|
defined(MBEDTLS_SSL_SERVER_NAME_INDICATION) && \
|
2022-10-12 10:31:11 +02:00
|
|
|
defined(MBEDTLS_SSL_CLI_C)
|
2022-10-12 04:49:52 +02:00
|
|
|
MBEDTLS_CHECK_RETURN_CRITICAL
|
2023-01-11 14:50:10 +01:00
|
|
|
int mbedtls_ssl_session_set_hostname(mbedtls_ssl_session *session,
|
|
|
|
const char *hostname);
|
2022-10-11 08:20:56 +02:00
|
|
|
#endif
|
|
|
|
|
2022-11-17 08:14:12 +01:00
|
|
|
#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && defined(MBEDTLS_SSL_SESSION_TICKETS)
|
2023-01-12 04:54:04 +01:00
|
|
|
static inline unsigned int mbedtls_ssl_session_get_ticket_flags(
|
2023-01-16 04:23:24 +01:00
|
|
|
mbedtls_ssl_session *session, unsigned int flags)
|
2022-11-17 08:14:12 +01:00
|
|
|
{
|
|
|
|
return session->ticket_flags &
|
|
|
|
(flags & MBEDTLS_SSL_TLS1_3_TICKET_FLAGS_MASK);
|
|
|
|
}
|
|
|
|
|
2023-01-12 04:54:04 +01:00
|
|
|
static inline void mbedtls_ssl_session_set_ticket_flags(
|
2023-01-16 04:23:24 +01:00
|
|
|
mbedtls_ssl_session *session, unsigned int flags)
|
2022-11-17 08:14:12 +01:00
|
|
|
{
|
|
|
|
session->ticket_flags |= (flags & MBEDTLS_SSL_TLS1_3_TICKET_FLAGS_MASK);
|
|
|
|
}
|
|
|
|
|
2023-01-12 04:54:04 +01:00
|
|
|
static inline void mbedtls_ssl_session_clear_ticket_flags(
|
2023-01-16 04:23:24 +01:00
|
|
|
mbedtls_ssl_session *session, unsigned int flags)
|
2022-11-17 08:14:12 +01:00
|
|
|
{
|
|
|
|
session->ticket_flags &= ~(flags & MBEDTLS_SSL_TLS1_3_TICKET_FLAGS_MASK);
|
|
|
|
}
|
2022-12-13 06:49:59 +01:00
|
|
|
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 && MBEDTLS_SSL_SESSION_TICKETS */
|
2022-11-17 08:14:12 +01:00
|
|
|
|
2023-01-04 08:38:50 +01:00
|
|
|
#if defined(MBEDTLS_SSL_CLI_C) && defined(MBEDTLS_SSL_PROTO_TLS1_3)
|
2023-02-06 11:23:04 +01:00
|
|
|
int mbedtls_ssl_tls13_finalize_client_hello(mbedtls_ssl_context *ssl);
|
2023-01-04 08:38:50 +01:00
|
|
|
#endif
|
2023-01-03 11:29:41 +01:00
|
|
|
|
2021-03-05 19:38:47 +01:00
|
|
|
#endif /* ssl_misc.h */
|