Merge remote-tracking branch 'public/pr/2421' into development
* public/pr/2421: (68 commits) Fix unused variable warning in ssl_parse_certificate_coordinate() Add missing compile time guard in ssl_client2 Update programs/ssl/query_config.c ssl_client2: Reset peer CRT info string on reconnect Add further debug statements on assertion failures Fix typo in documentation of ssl_parse_certificate_chain() Add debug output in case of assertion failure Fix typo in SSL ticket documentation Add config sanity check for !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE ssl_client2: Zeroize peer CRT info buffer when reconnecting Reintroduce numerous ssl-opt.sh tests if !MBEDTLS_SSL_KEEP_PEER_CERT ssl_client2: Extract peer CRT info from verification callback Improve documentation of mbedtls_ssl_get_peer_cert() Improve documentation of MBEDTLS_SSL_KEEP_PEER_CERTIFICATE Fix indentation of Doxygen comment in ssl_internal.h Set peer CRT length only after successful allocation Remove question in comment about verify flags on cli vs. server Remove misleading and redundant guard around restartable ECC field Add test for !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE to all.sh Free peer CRT chain immediately after verifying it ...
This commit is contained in:
commit
535ee4a35b
19 changed files with 901 additions and 452 deletions
|
@ -280,6 +280,14 @@
|
|||
#error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) && \
|
||||
!defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) && \
|
||||
( !defined(MBEDTLS_SHA256_C) && \
|
||||
!defined(MBEDTLS_SHA512_C) && \
|
||||
!defined(MBEDTLS_SHA1_C) )
|
||||
#error "!MBEDTLS_SSL_KEEP_PEER_CERTIFICATE requires MBEDTLS_SHA512_C, MBEDTLS_SHA256_C or MBEDTLS_SHA1_C"
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
|
||||
#error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
|
||||
|
|
|
@ -1374,6 +1374,28 @@
|
|||
*/
|
||||
#define MBEDTLS_SSL_FALLBACK_SCSV
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
|
||||
*
|
||||
* This option controls the availability of the API mbedtls_ssl_get_peer_cert()
|
||||
* giving access to the peer's certificate after completion of the handshake.
|
||||
*
|
||||
* Unless you need mbedtls_ssl_peer_cert() in your application, it is
|
||||
* recommended to disable this option for reduced RAM usage.
|
||||
*
|
||||
* \note If this option is disabled, mbedtls_ssl_get_peer_cert() is still
|
||||
* defined, but always returns \c NULL.
|
||||
*
|
||||
* \note This option has no influence on the protection against the
|
||||
* triple handshake attack. Even if it is disabled, Mbed TLS will
|
||||
* still ensure that certificates do not change during renegotiation,
|
||||
* for exaple by keeping a hash of the peer's certificate.
|
||||
*
|
||||
* Comment this macro to disable storing the peer's certificate
|
||||
* after the handshake.
|
||||
*/
|
||||
#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
|
||||
|
||||
/**
|
||||
* \def MBEDTLS_SSL_HW_RECORD_ACCEL
|
||||
*
|
||||
|
|
|
@ -787,6 +787,25 @@ typedef int mbedtls_ssl_async_resume_t( mbedtls_ssl_context *ssl,
|
|||
typedef void mbedtls_ssl_async_cancel_t( mbedtls_ssl_context *ssl );
|
||||
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED) && \
|
||||
!defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||
#define MBEDTLS_SSL_PEER_CERT_DIGEST_MAX_LEN 48
|
||||
#if defined(MBEDTLS_SHA256_C)
|
||||
#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA256
|
||||
#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 32
|
||||
#elif defined(MBEDTLS_SHA512_C)
|
||||
#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA384
|
||||
#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 48
|
||||
#elif defined(MBEDTLS_SHA1_C)
|
||||
#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE MBEDTLS_MD_SHA1
|
||||
#define MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN 20
|
||||
#else
|
||||
/* This is already checked in check_config.h, but be sure. */
|
||||
#error "Bad configuration - need SHA-1, SHA-256 or SHA-512 enabled to compute digest of peer CRT."
|
||||
#endif
|
||||
#endif /* MBEDTLS_KEY_EXCHANGE__WITH_CERT__ENABLED &&
|
||||
!MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||
|
||||
/*
|
||||
* This structure is used for storing current session data.
|
||||
*/
|
||||
|
@ -802,7 +821,15 @@ struct mbedtls_ssl_session
|
|||
unsigned char master[48]; /*!< the master secret */
|
||||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
mbedtls_x509_crt *peer_cert; /*!< peer X.509 cert chain */
|
||||
#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||
mbedtls_x509_crt *peer_cert; /*!< peer X.509 cert chain */
|
||||
#else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||
/*! The digest of the peer's end-CRT. This must be kept to detect CRT
|
||||
* changes during renegotiation, mitigating the triple handshake attack. */
|
||||
unsigned char *peer_cert_digest;
|
||||
size_t peer_cert_digest_len;
|
||||
mbedtls_md_type_t peer_cert_digest_type;
|
||||
#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
uint32_t verify_result; /*!< verification result */
|
||||
|
||||
|
@ -2972,18 +2999,34 @@ int mbedtls_ssl_get_max_out_record_payload( const mbedtls_ssl_context *ssl );
|
|||
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
/**
|
||||
* \brief Return the peer certificate from the current connection
|
||||
* \brief Return the peer certificate from the current connection.
|
||||
*
|
||||
* Note: Can be NULL in case no certificate was sent during
|
||||
* the handshake. Different calls for the same connection can
|
||||
* return the same or different pointers for the same
|
||||
* certificate and even a different certificate altogether.
|
||||
* The peer cert CAN change in a single connection if
|
||||
* renegotiation is performed.
|
||||
* \param ssl The SSL context to use. This must be initialized and setup.
|
||||
*
|
||||
* \param ssl SSL context
|
||||
* \return The current peer certificate, if available.
|
||||
* The returned certificate is owned by the SSL context and
|
||||
* is valid only until the next call to the SSL API.
|
||||
* \return \c NULL if no peer certificate is available. This might
|
||||
* be because the chosen ciphersuite doesn't use CRTs
|
||||
* (PSK-based ciphersuites, for example), or because
|
||||
* #MBEDTLS_SSL_KEEP_PEER_CERTIFICATE has been disabled,
|
||||
* allowing the stack to free the peer's CRT to save memory.
|
||||
*
|
||||
* \return the current peer certificate
|
||||
* \note For one-time inspection of the peer's certificate during
|
||||
* the handshake, consider registering an X.509 CRT verification
|
||||
* callback through mbedtls_ssl_conf_verify() instead of calling
|
||||
* this function. Using mbedtls_ssl_conf_verify() also comes at
|
||||
* the benefit of allowing you to influence the verification
|
||||
* process, for example by masking expected and tolerated
|
||||
* verification failures.
|
||||
*
|
||||
* \warning You must not use the pointer returned by this function
|
||||
* after any further call to the SSL API, including
|
||||
* mbedtls_ssl_read() and mbedtls_ssl_write(); this is
|
||||
* because the pointer might change during renegotiation,
|
||||
* which happens transparently to the user.
|
||||
* If you want to use the certificate across API calls,
|
||||
* you must make a copy.
|
||||
*/
|
||||
const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl );
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
|
|
|
@ -70,7 +70,8 @@ struct mbedtls_ssl_cache_entry
|
|||
mbedtls_time_t timestamp; /*!< entry timestamp */
|
||||
#endif
|
||||
mbedtls_ssl_session session; /*!< entry session */
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||
defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||
mbedtls_x509_buf peer_cert; /*!< entry peer_cert */
|
||||
#endif
|
||||
mbedtls_ssl_cache_entry *next; /*!< chain pointer */
|
||||
|
|
|
@ -486,6 +486,24 @@ static inline int mbedtls_ssl_ciphersuite_cert_req_allowed( const mbedtls_ssl_ci
|
|||
}
|
||||
}
|
||||
|
||||
static inline int mbedtls_ssl_ciphersuite_uses_srv_cert( const mbedtls_ssl_ciphersuite_t *info )
|
||||
{
|
||||
switch( info->key_exchange )
|
||||
{
|
||||
case MBEDTLS_KEY_EXCHANGE_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_RSA_PSK:
|
||||
case MBEDTLS_KEY_EXCHANGE_DHE_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_RSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA:
|
||||
case MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA:
|
||||
return( 1 );
|
||||
|
||||
default:
|
||||
return( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED)
|
||||
static inline int mbedtls_ssl_ciphersuite_uses_dhe( const mbedtls_ssl_ciphersuite_t *info )
|
||||
{
|
||||
|
|
|
@ -331,8 +331,13 @@ struct mbedtls_ssl_handshake_params
|
|||
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
|
||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||
!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 */
|
||||
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||
unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */
|
||||
unsigned int in_msg_seq; /*!< Incoming handshake sequence number */
|
||||
|
@ -766,6 +771,9 @@ int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context *ssl );
|
|||
void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl );
|
||||
#endif
|
||||
|
||||
int mbedtls_ssl_session_copy( mbedtls_ssl_session *dst,
|
||||
const mbedtls_ssl_session *src );
|
||||
|
||||
/* constant-time buffer comparison */
|
||||
static inline int mbedtls_ssl_safer_memcmp( const void *a, const void *b, size_t n )
|
||||
{
|
||||
|
|
|
@ -70,6 +70,7 @@ typedef struct mbedtls_x509_crt
|
|||
mbedtls_x509_time valid_from; /**< Start time of certificate validity. */
|
||||
mbedtls_x509_time valid_to; /**< End time of certificate validity. */
|
||||
|
||||
mbedtls_x509_buf pk_raw;
|
||||
mbedtls_pk_context pk; /**< Container for the public key context. */
|
||||
|
||||
mbedtls_x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue