mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-12 09:45:39 +00:00
Merge pull request #583 from ARMmbed/remove_peer_crt_after_handshake-baremetal
[Baremetal] Allow removal of peer certificate to reduce RAM usage
This commit is contained in:
commit
79cf74a95f
|
@ -42,6 +42,13 @@ Features
|
||||||
API Changes
|
API Changes
|
||||||
* Add a new X.509 API call `mbedtls_x509_parse_der_nocopy()`.
|
* Add a new X.509 API call `mbedtls_x509_parse_der_nocopy()`.
|
||||||
See the Features section for more information.
|
See the Features section for more information.
|
||||||
|
* Allow to opt in to the removal the API mbedtls_ssl_get_peer_cert()
|
||||||
|
for the benefit of saving RAM, by disabling the new compile-time
|
||||||
|
option MBEDTLS_SSL_KEEP_PEER_CERTIFICATE (enabled by default for
|
||||||
|
API stability). Disabling this option makes mbedtls_ssl_get_peer_cert()
|
||||||
|
always return NULL, and removes the peer_cert field from the
|
||||||
|
mbedtls_ssl_session structure which otherwise stores the peer's
|
||||||
|
certificate.
|
||||||
|
|
||||||
Bugfix
|
Bugfix
|
||||||
* Server's RSA certificate in certs.c was SHA-1 signed. In the default
|
* Server's RSA certificate in certs.c was SHA-1 signed. In the default
|
||||||
|
|
|
@ -278,6 +278,14 @@
|
||||||
#error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites"
|
#error "MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED defined, but not all prerequisites"
|
||||||
#endif
|
#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 defined, but not all prerequesites"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && \
|
||||||
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
|
( !defined(MBEDTLS_PLATFORM_C) || !defined(MBEDTLS_PLATFORM_MEMORY) )
|
||||||
#error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
|
#error "MBEDTLS_MEMORY_BUFFER_ALLOC_C defined, but not all prerequisites"
|
||||||
|
|
|
@ -1404,6 +1404,28 @@
|
||||||
*/
|
*/
|
||||||
#define MBEDTLS_SSL_FALLBACK_SCSV
|
#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
|
* \def MBEDTLS_SSL_HW_RECORD_ACCEL
|
||||||
*
|
*
|
||||||
|
|
|
@ -812,6 +812,25 @@ typedef int mbedtls_ssl_async_resume_t( mbedtls_ssl_context *ssl,
|
||||||
typedef void mbedtls_ssl_async_cancel_t( mbedtls_ssl_context *ssl );
|
typedef void mbedtls_ssl_async_cancel_t( mbedtls_ssl_context *ssl );
|
||||||
#endif /* MBEDTLS_SSL_ASYNC_PRIVATE */
|
#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.
|
* This structure is used for storing current session data.
|
||||||
*
|
*
|
||||||
|
@ -835,7 +854,15 @@ struct mbedtls_ssl_session
|
||||||
unsigned char master[48]; /*!< the master secret */
|
unsigned char master[48]; /*!< the master secret */
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
#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 */
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||||
uint32_t verify_result; /*!< verification result */
|
uint32_t verify_result; /*!< verification result */
|
||||||
|
|
||||||
|
@ -3230,18 +3257,34 @@ int mbedtls_ssl_get_max_out_record_payload( const mbedtls_ssl_context *ssl );
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
#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
|
* \param ssl The SSL context to use. This must be initialized and setup.
|
||||||
* 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 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 );
|
const mbedtls_x509_crt *mbedtls_ssl_get_peer_cert( const mbedtls_ssl_context *ssl );
|
||||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||||
|
|
|
@ -70,7 +70,8 @@ struct mbedtls_ssl_cache_entry
|
||||||
mbedtls_time_t timestamp; /*!< entry timestamp */
|
mbedtls_time_t timestamp; /*!< entry timestamp */
|
||||||
#endif
|
#endif
|
||||||
mbedtls_ssl_session session; /*!< entry session */
|
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 */
|
mbedtls_x509_buf peer_cert; /*!< entry peer_cert */
|
||||||
#endif
|
#endif
|
||||||
mbedtls_ssl_cache_entry *next; /*!< chain pointer */
|
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)
|
#if defined(MBEDTLS_KEY_EXCHANGE__SOME__DHE_ENABLED)
|
||||||
static inline int mbedtls_ssl_ciphersuite_uses_dhe( const mbedtls_ssl_ciphersuite_t *info )
|
static inline int mbedtls_ssl_ciphersuite_uses_dhe( const mbedtls_ssl_ciphersuite_t *info )
|
||||||
{
|
{
|
||||||
|
|
|
@ -396,8 +396,13 @@ struct mbedtls_ssl_handshake_params
|
||||||
ssl_ecrs_cke_ecdh_calc_secret, /*!< ClientKeyExchange: ECDH step 2 */
|
ssl_ecrs_cke_ecdh_calc_secret, /*!< ClientKeyExchange: ECDH step 2 */
|
||||||
ssl_ecrs_crt_vrfy_sign, /*!< CertificateVerify: pk_sign() */
|
ssl_ecrs_crt_vrfy_sign, /*!< CertificateVerify: pk_sign() */
|
||||||
} ecrs_state; /*!< current (or last) operation */
|
} 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 */
|
size_t ecrs_n; /*!< place for saving a length */
|
||||||
#endif
|
#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)
|
#if defined(MBEDTLS_SSL_PROTO_DTLS)
|
||||||
unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */
|
unsigned int out_msg_seq; /*!< Outgoing handshake sequence number */
|
||||||
unsigned int in_msg_seq; /*!< Incoming handshake sequence number */
|
unsigned int in_msg_seq; /*!< Incoming handshake sequence number */
|
||||||
|
@ -989,6 +994,9 @@ int mbedtls_ssl_dtls_replay_check( mbedtls_ssl_context *ssl );
|
||||||
void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl );
|
void mbedtls_ssl_dtls_replay_update( mbedtls_ssl_context *ssl );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int mbedtls_ssl_session_copy( mbedtls_ssl_session *dst,
|
||||||
|
const mbedtls_ssl_session *src );
|
||||||
|
|
||||||
/* constant-time buffer comparison */
|
/* constant-time buffer comparison */
|
||||||
static inline int mbedtls_ssl_safer_memcmp( const void *a, const void *b, size_t n )
|
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_from; /**< Start time of certificate validity. */
|
||||||
mbedtls_x509_time valid_to; /**< End 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_pk_context pk; /**< Container for the public key context. */
|
||||||
|
|
||||||
mbedtls_x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
|
mbedtls_x509_buf issuer_id; /**< Optional X.509 v2/v3 issuer unique identifier. */
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "mbedtls/ssl_cache.h"
|
#include "mbedtls/ssl_cache.h"
|
||||||
|
#include "mbedtls/ssl_internal.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -92,16 +93,24 @@ int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session )
|
||||||
entry->session.id_len ) != 0 )
|
entry->session.id_len ) != 0 )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
memcpy( session->master, entry->session.master, 48 );
|
ret = mbedtls_ssl_session_copy( session, &entry->session );
|
||||||
|
if( ret != 0 )
|
||||||
|
{
|
||||||
|
ret = 1;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
session->verify_result = entry->session.verify_result;
|
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||||
|
defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
|
||||||
/*
|
/*
|
||||||
* Restore peer certificate (without rest of the original chain)
|
* Restore peer certificate (without rest of the original chain)
|
||||||
*/
|
*/
|
||||||
if( entry->peer_cert.p != NULL )
|
if( entry->peer_cert.p != NULL )
|
||||||
{
|
{
|
||||||
|
/* `session->peer_cert` is NULL after the call to
|
||||||
|
* mbedtls_ssl_session_copy(), because cache entries
|
||||||
|
* have the `peer_cert` field set to NULL. */
|
||||||
|
|
||||||
if( ( session->peer_cert = mbedtls_calloc( 1,
|
if( ( session->peer_cert = mbedtls_calloc( 1,
|
||||||
sizeof(mbedtls_x509_crt) ) ) == NULL )
|
sizeof(mbedtls_x509_crt) ) ) == NULL )
|
||||||
{
|
{
|
||||||
|
@ -119,7 +128,7 @@ int mbedtls_ssl_cache_get( void *data, mbedtls_ssl_session *session )
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto exit;
|
goto exit;
|
||||||
|
@ -239,9 +248,8 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy( &cur->session, session, sizeof( mbedtls_ssl_session ) );
|
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||||
|
defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
|
||||||
/*
|
/*
|
||||||
* If we're reusing an entry, free its certificate first
|
* If we're reusing an entry, free its certificate first
|
||||||
*/
|
*/
|
||||||
|
@ -250,26 +258,43 @@ int mbedtls_ssl_cache_set( void *data, const mbedtls_ssl_session *session )
|
||||||
mbedtls_free( cur->peer_cert.p );
|
mbedtls_free( cur->peer_cert.p );
|
||||||
memset( &cur->peer_cert, 0, sizeof(mbedtls_x509_buf) );
|
memset( &cur->peer_cert, 0, sizeof(mbedtls_x509_buf) );
|
||||||
}
|
}
|
||||||
|
#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
/*
|
/* Copy the entire session; this temporarily makes a copy of the
|
||||||
* Store peer certificate
|
* X.509 CRT structure even though we only want to store the raw CRT.
|
||||||
*/
|
* This inefficiency will go away as soon as we implement on-demand
|
||||||
if( session->peer_cert != NULL )
|
* parsing of CRTs, in which case there's no need for the `peer_cert`
|
||||||
|
* field anymore in the first place, and we're done after this call. */
|
||||||
|
ret = mbedtls_ssl_session_copy( &cur->session, session );
|
||||||
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
cur->peer_cert.p = mbedtls_calloc( 1, session->peer_cert->raw.len );
|
ret = 1;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||||
|
defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
/* If present, free the X.509 structure and only store the raw CRT data. */
|
||||||
|
if( cur->session.peer_cert != NULL )
|
||||||
|
{
|
||||||
|
cur->peer_cert.p =
|
||||||
|
mbedtls_calloc( 1, cur->session.peer_cert->raw.len );
|
||||||
if( cur->peer_cert.p == NULL )
|
if( cur->peer_cert.p == NULL )
|
||||||
{
|
{
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy( cur->peer_cert.p, session->peer_cert->raw.p,
|
memcpy( cur->peer_cert.p,
|
||||||
session->peer_cert->raw.len );
|
cur->session.peer_cert->raw.p,
|
||||||
|
cur->session.peer_cert->raw.len );
|
||||||
cur->peer_cert.len = session->peer_cert->raw.len;
|
cur->peer_cert.len = session->peer_cert->raw.len;
|
||||||
|
|
||||||
|
mbedtls_x509_crt_free( cur->session.peer_cert );
|
||||||
|
mbedtls_free( cur->session.peer_cert );
|
||||||
cur->session.peer_cert = NULL;
|
cur->session.peer_cert = NULL;
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
@ -311,9 +336,10 @@ void mbedtls_ssl_cache_free( mbedtls_ssl_cache_context *cache )
|
||||||
|
|
||||||
mbedtls_ssl_session_free( &prv->session );
|
mbedtls_ssl_session_free( &prv->session );
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
#if defined(MBEDTLS_X509_CRT_PARSE_C) && \
|
||||||
|
defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
mbedtls_free( prv->peer_cert.p );
|
mbedtls_free( prv->peer_cert.p );
|
||||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
#endif /* MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
mbedtls_free( prv );
|
mbedtls_free( prv );
|
||||||
}
|
}
|
||||||
|
|
|
@ -2288,6 +2288,7 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl,
|
||||||
int ret;
|
int ret;
|
||||||
size_t len_bytes = ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 ? 0 : 2;
|
size_t len_bytes = ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 ? 0 : 2;
|
||||||
unsigned char *p = ssl->handshake->premaster + pms_offset;
|
unsigned char *p = ssl->handshake->premaster + pms_offset;
|
||||||
|
mbedtls_pk_context * peer_pk;
|
||||||
|
|
||||||
if( offset + len_bytes > MBEDTLS_SSL_OUT_CONTENT_LEN )
|
if( offset + len_bytes > MBEDTLS_SSL_OUT_CONTENT_LEN )
|
||||||
{
|
{
|
||||||
|
@ -2313,23 +2314,28 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl,
|
||||||
|
|
||||||
ssl->handshake->pmslen = 48;
|
ssl->handshake->pmslen = 48;
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
peer_pk = &ssl->handshake->peer_pubkey;
|
||||||
|
#else /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
if( ssl->session_negotiate->peer_cert == NULL )
|
if( ssl->session_negotiate->peer_cert == NULL )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "certificate required" ) );
|
/* Should never happen */
|
||||||
return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||||
|
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||||
}
|
}
|
||||||
|
peer_pk = &ssl->session_negotiate->peer_cert->pk;
|
||||||
|
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now write it out, encrypted
|
* Now write it out, encrypted
|
||||||
*/
|
*/
|
||||||
if( ! mbedtls_pk_can_do( &ssl->session_negotiate->peer_cert->pk,
|
if( ! mbedtls_pk_can_do( peer_pk, MBEDTLS_PK_RSA ) )
|
||||||
MBEDTLS_PK_RSA ) )
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "certificate key type mismatch" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "certificate key type mismatch" ) );
|
||||||
return( MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH );
|
return( MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( ret = mbedtls_pk_encrypt( &ssl->session_negotiate->peer_cert->pk,
|
if( ( ret = mbedtls_pk_encrypt( peer_pk,
|
||||||
p, ssl->handshake->pmslen,
|
p, ssl->handshake->pmslen,
|
||||||
ssl->out_msg + offset + len_bytes, olen,
|
ssl->out_msg + offset + len_bytes, olen,
|
||||||
MBEDTLS_SSL_OUT_CONTENT_LEN - offset - len_bytes,
|
MBEDTLS_SSL_OUT_CONTENT_LEN - offset - len_bytes,
|
||||||
|
@ -2349,6 +2355,10 @@ static int ssl_write_encrypted_pms( mbedtls_ssl_context *ssl,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
/* We don't need the peer's public key anymore. Free it. */
|
||||||
|
mbedtls_pk_free( peer_pk );
|
||||||
|
#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED ||
|
#endif /* MBEDTLS_KEY_EXCHANGE_RSA_ENABLED ||
|
||||||
|
@ -2424,21 +2434,27 @@ static int ssl_get_ecdh_params_from_cert( mbedtls_ssl_context *ssl )
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
const mbedtls_ecp_keypair *peer_key;
|
const mbedtls_ecp_keypair *peer_key;
|
||||||
|
mbedtls_pk_context * peer_pk;
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
peer_pk = &ssl->handshake->peer_pubkey;
|
||||||
|
#else /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
if( ssl->session_negotiate->peer_cert == NULL )
|
if( ssl->session_negotiate->peer_cert == NULL )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "certificate required" ) );
|
/* Should never happen */
|
||||||
return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||||
|
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||||
}
|
}
|
||||||
|
peer_pk = &ssl->session_negotiate->peer_cert->pk;
|
||||||
|
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
if( ! mbedtls_pk_can_do( &ssl->session_negotiate->peer_cert->pk,
|
if( ! mbedtls_pk_can_do( peer_pk, MBEDTLS_PK_ECKEY ) )
|
||||||
MBEDTLS_PK_ECKEY ) )
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "server key not ECDH capable" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "server key not ECDH capable" ) );
|
||||||
return( MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH );
|
return( MBEDTLS_ERR_SSL_PK_TYPE_MISMATCH );
|
||||||
}
|
}
|
||||||
|
|
||||||
peer_key = mbedtls_pk_ec( ssl->session_negotiate->peer_cert->pk );
|
peer_key = mbedtls_pk_ec( *peer_pk );
|
||||||
|
|
||||||
if( ( ret = mbedtls_ecdh_get_params( &ssl->handshake->ecdh_ctx, peer_key,
|
if( ( ret = mbedtls_ecdh_get_params( &ssl->handshake->ecdh_ctx, peer_key,
|
||||||
MBEDTLS_ECDH_THEIRS ) ) != 0 )
|
MBEDTLS_ECDH_THEIRS ) ) != 0 )
|
||||||
|
@ -2453,6 +2469,13 @@ static int ssl_get_ecdh_params_from_cert( mbedtls_ssl_context *ssl )
|
||||||
return( MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE );
|
return( MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
/* We don't need the peer's public key anymore. Free it,
|
||||||
|
* so that more RAM is available for upcoming expensive
|
||||||
|
* operations like ECDHE. */
|
||||||
|
mbedtls_pk_free( peer_pk );
|
||||||
|
#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) ||
|
#endif /* MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) ||
|
||||||
|
@ -2645,6 +2668,8 @@ start_processing:
|
||||||
size_t params_len = p - params;
|
size_t params_len = p - params;
|
||||||
void *rs_ctx = NULL;
|
void *rs_ctx = NULL;
|
||||||
|
|
||||||
|
mbedtls_pk_context * peer_pk;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle the digitally-signed structure
|
* Handle the digitally-signed structure
|
||||||
*/
|
*/
|
||||||
|
@ -2747,18 +2772,22 @@ start_processing:
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_BUF( 3, "parameters hash", hash, hashlen );
|
MBEDTLS_SSL_DEBUG_BUF( 3, "parameters hash", hash, hashlen );
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
peer_pk = &ssl->handshake->peer_pubkey;
|
||||||
|
#else /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
if( ssl->session_negotiate->peer_cert == NULL )
|
if( ssl->session_negotiate->peer_cert == NULL )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "certificate required" ) );
|
/* Should never happen */
|
||||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||||
MBEDTLS_SSL_ALERT_MSG_HANDSHAKE_FAILURE );
|
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||||
return( MBEDTLS_ERR_SSL_UNEXPECTED_MESSAGE );
|
|
||||||
}
|
}
|
||||||
|
peer_pk = &ssl->session_negotiate->peer_cert->pk;
|
||||||
|
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Verify signature
|
* Verify signature
|
||||||
*/
|
*/
|
||||||
if( ! mbedtls_pk_can_do( &ssl->session_negotiate->peer_cert->pk, pk_alg ) )
|
if( !mbedtls_pk_can_do( peer_pk, pk_alg ) )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server key exchange message" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad server key exchange message" ) );
|
||||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||||
|
@ -2771,8 +2800,7 @@ start_processing:
|
||||||
rs_ctx = &ssl->handshake->ecrs_ctx.pk;
|
rs_ctx = &ssl->handshake->ecrs_ctx.pk;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( ( ret = mbedtls_pk_verify_restartable(
|
if( ( ret = mbedtls_pk_verify_restartable( peer_pk,
|
||||||
&ssl->session_negotiate->peer_cert->pk,
|
|
||||||
md_alg, hash, hashlen, p, sig_len, rs_ctx ) ) != 0 )
|
md_alg, hash, hashlen, p, sig_len, rs_ctx ) ) != 0 )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_SSL__ECP_RESTARTABLE)
|
#if defined(MBEDTLS_SSL__ECP_RESTARTABLE)
|
||||||
|
@ -2787,6 +2815,13 @@ start_processing:
|
||||||
#endif
|
#endif
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
/* We don't need the peer's public key anymore. Free it,
|
||||||
|
* so that more RAM is available for upcoming expensive
|
||||||
|
* operations like ECDHE. */
|
||||||
|
mbedtls_pk_free( peer_pk );
|
||||||
|
#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED */
|
#endif /* MBEDTLS_KEY_EXCHANGE__WITH_SERVER_SIGNATURE__ENABLED */
|
||||||
|
|
||||||
|
@ -3306,12 +3341,7 @@ ecdh_calc_secret:
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && \
|
#if !defined(MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED)
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)&& \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
|
|
||||||
static int ssl_write_certificate_verify( mbedtls_ssl_context *ssl )
|
static int ssl_write_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
{
|
{
|
||||||
const mbedtls_ssl_ciphersuite_t *ciphersuite_info =
|
const mbedtls_ssl_ciphersuite_t *ciphersuite_info =
|
||||||
|
@ -3326,11 +3356,7 @@ static int ssl_write_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK ||
|
if( !mbedtls_ssl_ciphersuite_cert_req_allowed( ciphersuite_info ) )
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE )
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate verify" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate verify" ) );
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
|
@ -3340,7 +3366,7 @@ static int ssl_write_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||||
}
|
}
|
||||||
#else
|
#else /* !MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED */
|
||||||
static int ssl_write_certificate_verify( mbedtls_ssl_context *ssl )
|
static int ssl_write_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
{
|
{
|
||||||
int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
|
int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
|
||||||
|
@ -3369,11 +3395,7 @@ static int ssl_write_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK ||
|
if( !mbedtls_ssl_ciphersuite_cert_req_allowed( ciphersuite_info ) )
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE )
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate verify" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate verify" ) );
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
|
@ -3514,12 +3536,7 @@ sign:
|
||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* !MBEDTLS_KEY_EXCHANGE_RSA_ENABLED &&
|
#endif /* MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED */
|
||||||
!MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
||||||
static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl )
|
static int ssl_parse_new_session_ticket( mbedtls_ssl_context *ssl )
|
||||||
|
|
|
@ -2801,12 +2801,7 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && \
|
#if !defined(MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED)
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)&& \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
|
|
||||||
static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
||||||
{
|
{
|
||||||
const mbedtls_ssl_ciphersuite_t *ciphersuite_info =
|
const mbedtls_ssl_ciphersuite_t *ciphersuite_info =
|
||||||
|
@ -2814,11 +2809,7 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> write certificate request" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> write certificate request" ) );
|
||||||
|
|
||||||
if( ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK ||
|
if( !mbedtls_ssl_ciphersuite_cert_req_allowed( ciphersuite_info ) )
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE )
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate request" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate request" ) );
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
|
@ -2828,7 +2819,7 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||||
}
|
}
|
||||||
#else
|
#else /* !MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED */
|
||||||
static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
||||||
{
|
{
|
||||||
int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
|
int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
|
||||||
|
@ -2852,11 +2843,7 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
||||||
#endif
|
#endif
|
||||||
authmode = ssl->conf->authmode;
|
authmode = ssl->conf->authmode;
|
||||||
|
|
||||||
if( ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK ||
|
if( !mbedtls_ssl_ciphersuite_cert_req_allowed( ciphersuite_info ) ||
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE ||
|
|
||||||
authmode == MBEDTLS_SSL_VERIFY_NONE )
|
authmode == MBEDTLS_SSL_VERIFY_NONE )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate request" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip write certificate request" ) );
|
||||||
|
@ -2995,12 +2982,7 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* !MBEDTLS_KEY_EXCHANGE_RSA_ENABLED &&
|
#endif /* MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED */
|
||||||
!MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
#if defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) || \
|
||||||
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)
|
||||||
|
@ -4147,12 +4129,7 @@ static int ssl_parse_client_key_exchange( mbedtls_ssl_context *ssl )
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_KEY_EXCHANGE_RSA_ENABLED) && \
|
#if !defined(MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED)
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) && \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED)&& \
|
|
||||||
!defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
|
|
||||||
static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
{
|
{
|
||||||
const mbedtls_ssl_ciphersuite_t *ciphersuite_info =
|
const mbedtls_ssl_ciphersuite_t *ciphersuite_info =
|
||||||
|
@ -4160,11 +4137,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> parse certificate verify" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> parse certificate verify" ) );
|
||||||
|
|
||||||
if( ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK ||
|
if( !mbedtls_ssl_ciphersuite_cert_req_allowed( ciphersuite_info ) )
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE )
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) );
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
|
@ -4174,7 +4147,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||||
}
|
}
|
||||||
#else
|
#else /* !MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED */
|
||||||
static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
{
|
{
|
||||||
int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
|
int ret = MBEDTLS_ERR_SSL_FEATURE_UNAVAILABLE;
|
||||||
|
@ -4188,21 +4161,33 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
mbedtls_md_type_t md_alg;
|
mbedtls_md_type_t md_alg;
|
||||||
const mbedtls_ssl_ciphersuite_t *ciphersuite_info =
|
const mbedtls_ssl_ciphersuite_t *ciphersuite_info =
|
||||||
ssl->handshake->ciphersuite_info;
|
ssl->handshake->ciphersuite_info;
|
||||||
|
mbedtls_pk_context * peer_pk;
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> parse certificate verify" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "=> parse certificate verify" ) );
|
||||||
|
|
||||||
if( ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_PSK ||
|
if( !mbedtls_ssl_ciphersuite_cert_req_allowed( ciphersuite_info ) )
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_RSA_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECDHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_DHE_PSK ||
|
|
||||||
ciphersuite_info->key_exchange == MBEDTLS_KEY_EXCHANGE_ECJPAKE ||
|
|
||||||
ssl->session_negotiate->peer_cert == NULL )
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) );
|
||||||
ssl->state++;
|
ssl->state++;
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
if( ssl->session_negotiate->peer_cert == NULL )
|
||||||
|
{
|
||||||
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) );
|
||||||
|
ssl->state++;
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
#else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
if( ssl->session_negotiate->peer_cert_digest == NULL )
|
||||||
|
{
|
||||||
|
MBEDTLS_SSL_DEBUG_MSG( 2, ( "<= skip parse certificate verify" ) );
|
||||||
|
ssl->state++;
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
/* Read the message without adding it to the checksum */
|
/* Read the message without adding it to the checksum */
|
||||||
ret = mbedtls_ssl_read_record( ssl, 0 /* no checksum update */ );
|
ret = mbedtls_ssl_read_record( ssl, 0 /* no checksum update */ );
|
||||||
if( 0 != ret )
|
if( 0 != ret )
|
||||||
|
@ -4223,6 +4208,17 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
|
|
||||||
i = mbedtls_ssl_hs_hdr_len( ssl );
|
i = mbedtls_ssl_hs_hdr_len( ssl );
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
peer_pk = &ssl->handshake->peer_pubkey;
|
||||||
|
#else /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
if( ssl->session_negotiate->peer_cert == NULL )
|
||||||
|
{
|
||||||
|
/* Should never happen */
|
||||||
|
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||||
|
}
|
||||||
|
peer_pk = &ssl->session_negotiate->peer_cert->pk;
|
||||||
|
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* struct {
|
* struct {
|
||||||
* SignatureAndHashAlgorithm algorithm; -- TLS 1.2 only
|
* SignatureAndHashAlgorithm algorithm; -- TLS 1.2 only
|
||||||
|
@ -4237,8 +4233,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
hashlen = 36;
|
hashlen = 36;
|
||||||
|
|
||||||
/* For ECDSA, use SHA-1, not MD-5 + SHA-1 */
|
/* For ECDSA, use SHA-1, not MD-5 + SHA-1 */
|
||||||
if( mbedtls_pk_can_do( &ssl->session_negotiate->peer_cert->pk,
|
if( mbedtls_pk_can_do( peer_pk, MBEDTLS_PK_ECDSA ) )
|
||||||
MBEDTLS_PK_ECDSA ) )
|
|
||||||
{
|
{
|
||||||
hash_start += 16;
|
hash_start += 16;
|
||||||
hashlen -= 16;
|
hashlen -= 16;
|
||||||
|
@ -4293,7 +4288,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
/*
|
/*
|
||||||
* Check the certificate's key type matches the signature alg
|
* Check the certificate's key type matches the signature alg
|
||||||
*/
|
*/
|
||||||
if( ! mbedtls_pk_can_do( &ssl->session_negotiate->peer_cert->pk, pk_alg ) )
|
if( !mbedtls_pk_can_do( peer_pk, pk_alg ) )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "sig_alg doesn't match cert key" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "sig_alg doesn't match cert key" ) );
|
||||||
return( MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY );
|
return( MBEDTLS_ERR_SSL_BAD_HS_CERTIFICATE_VERIFY );
|
||||||
|
@ -4329,7 +4324,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
ssl->handshake->calc_verify( ssl, hash, &dummy_hlen );
|
ssl->handshake->calc_verify( ssl, hash, &dummy_hlen );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( ret = mbedtls_pk_verify( &ssl->session_negotiate->peer_cert->pk,
|
if( ( ret = mbedtls_pk_verify( peer_pk,
|
||||||
md_alg, hash_start, hashlen,
|
md_alg, hash_start, hashlen,
|
||||||
ssl->in_msg + i, sig_len ) ) != 0 )
|
ssl->in_msg + i, sig_len ) ) != 0 )
|
||||||
{
|
{
|
||||||
|
@ -4343,12 +4338,7 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
#endif /* !MBEDTLS_KEY_EXCHANGE_RSA_ENABLED &&
|
#endif /* MBEDTLS_KEY_EXCHANGE__CERT_REQ_ALLOWED__ENABLED */
|
||||||
!MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED &&
|
|
||||||
!MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED */
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
||||||
static int ssl_write_new_session_ticket( mbedtls_ssl_context *ssl )
|
static int ssl_write_new_session_ticket( mbedtls_ssl_context *ssl )
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -456,6 +456,9 @@ static const char *features[] = {
|
||||||
#if defined(MBEDTLS_SSL_FALLBACK_SCSV)
|
#if defined(MBEDTLS_SSL_FALLBACK_SCSV)
|
||||||
"MBEDTLS_SSL_FALLBACK_SCSV",
|
"MBEDTLS_SSL_FALLBACK_SCSV",
|
||||||
#endif /* MBEDTLS_SSL_FALLBACK_SCSV */
|
#endif /* MBEDTLS_SSL_FALLBACK_SCSV */
|
||||||
|
#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
"MBEDTLS_SSL_KEEP_PEER_CERTIFICATE",
|
||||||
|
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||||
"MBEDTLS_SSL_HW_RECORD_ACCEL",
|
"MBEDTLS_SSL_HW_RECORD_ACCEL",
|
||||||
#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
|
#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
|
||||||
|
|
|
@ -990,11 +990,13 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt,
|
||||||
/*
|
/*
|
||||||
* SubjectPublicKeyInfo
|
* SubjectPublicKeyInfo
|
||||||
*/
|
*/
|
||||||
|
crt->pk_raw.p = p;
|
||||||
if( ( ret = mbedtls_pk_parse_subpubkey( &p, end, &crt->pk ) ) != 0 )
|
if( ( ret = mbedtls_pk_parse_subpubkey( &p, end, &crt->pk ) ) != 0 )
|
||||||
{
|
{
|
||||||
mbedtls_x509_crt_free( crt );
|
mbedtls_x509_crt_free( crt );
|
||||||
return( ret );
|
return( ret );
|
||||||
}
|
}
|
||||||
|
crt->pk_raw.len = p - crt->pk_raw.p;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL,
|
* issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL,
|
||||||
|
|
|
@ -1258,6 +1258,14 @@ int query_config( const char *config )
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_SSL_FALLBACK_SCSV */
|
#endif /* MBEDTLS_SSL_FALLBACK_SCSV */
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
if( strcmp( "MBEDTLS_SSL_KEEP_PEER_CERTIFICATE", config ) == 0 )
|
||||||
|
{
|
||||||
|
MACRO_EXPANSION_TO_STR( MBEDTLS_SSL_KEEP_PEER_CERTIFICATE );
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||||
if( strcmp( "MBEDTLS_SSL_HW_RECORD_ACCEL", config ) == 0 )
|
if( strcmp( "MBEDTLS_SSL_HW_RECORD_ACCEL", config ) == 0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -494,6 +494,8 @@ static int my_send( void *ctx, const unsigned char *buf, size_t len )
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||||
|
static unsigned char peer_crt_info[1024];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Enabled if debug_level > 1 in code below
|
* Enabled if debug_level > 1 in code below
|
||||||
*/
|
*/
|
||||||
|
@ -506,8 +508,14 @@ static int my_verify( void *data, mbedtls_x509_crt *crt,
|
||||||
((void) data);
|
((void) data);
|
||||||
|
|
||||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||||
mbedtls_printf( "\nVerify requested for (Depth %d):\n", depth );
|
|
||||||
mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
|
mbedtls_x509_crt_info( buf, sizeof( buf ) - 1, "", crt );
|
||||||
|
if( depth == 0 )
|
||||||
|
memcpy( peer_crt_info, buf, sizeof( buf ) );
|
||||||
|
|
||||||
|
if( opt.debug_level == 0 )
|
||||||
|
return( 0 );
|
||||||
|
|
||||||
|
mbedtls_printf( "\nVerify requested for (Depth %d):\n", depth );
|
||||||
mbedtls_printf( "%s", buf );
|
mbedtls_printf( "%s", buf );
|
||||||
#else
|
#else
|
||||||
((void) crt);
|
((void) crt);
|
||||||
|
@ -1641,8 +1649,8 @@ int main( int argc, char *argv[] )
|
||||||
mbedtls_ssl_conf_sig_hashes( &conf, ssl_sig_hashes_for_test );
|
mbedtls_ssl_conf_sig_hashes( &conf, ssl_sig_hashes_for_test );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( opt.debug_level > 0 )
|
mbedtls_ssl_conf_verify( &conf, my_verify, NULL );
|
||||||
mbedtls_ssl_conf_verify( &conf, my_verify, NULL );
|
memset( peer_crt_info, 0, sizeof( peer_crt_info ) );
|
||||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
#if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID)
|
||||||
|
@ -2021,13 +2029,8 @@ int main( int argc, char *argv[] )
|
||||||
mbedtls_printf( " ok\n" );
|
mbedtls_printf( " ok\n" );
|
||||||
|
|
||||||
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
#if !defined(MBEDTLS_X509_REMOVE_INFO)
|
||||||
if( mbedtls_ssl_get_peer_cert( &ssl ) != NULL )
|
mbedtls_printf( " . Peer certificate information ...\n" );
|
||||||
{
|
mbedtls_printf( "%s\n", peer_crt_info );
|
||||||
mbedtls_printf( " . Peer certificate information ...\n" );
|
|
||||||
mbedtls_x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ",
|
|
||||||
mbedtls_ssl_get_peer_cert( &ssl ) );
|
|
||||||
mbedtls_printf( "%s\n", buf );
|
|
||||||
}
|
|
||||||
#endif /* !MBEDTLS_X509_REMOVE_INFO */
|
#endif /* !MBEDTLS_X509_REMOVE_INFO */
|
||||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||||
|
|
||||||
|
@ -2357,6 +2360,10 @@ send_request:
|
||||||
mbedtls_printf( " . Restarting connection from same port..." );
|
mbedtls_printf( " . Restarting connection from same port..." );
|
||||||
fflush( stdout );
|
fflush( stdout );
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||||
|
memset( peer_crt_info, 0, sizeof( peer_crt_info ) );
|
||||||
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||||
|
|
||||||
if( ( ret = mbedtls_ssl_session_reset( &ssl ) ) != 0 )
|
if( ( ret = mbedtls_ssl_session_reset( &ssl ) ) != 0 )
|
||||||
{
|
{
|
||||||
mbedtls_printf( " failed\n ! mbedtls_ssl_session_reset returned -0x%x\n\n",
|
mbedtls_printf( " failed\n ! mbedtls_ssl_session_reset returned -0x%x\n\n",
|
||||||
|
@ -2511,6 +2518,10 @@ reconnect:
|
||||||
|
|
||||||
mbedtls_printf( " . Reconnecting with saved session..." );
|
mbedtls_printf( " . Reconnecting with saved session..." );
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||||
|
memset( peer_crt_info, 0, sizeof( peer_crt_info ) );
|
||||||
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||||
|
|
||||||
if( ( ret = mbedtls_ssl_session_reset( &ssl ) ) != 0 )
|
if( ( ret = mbedtls_ssl_session_reset( &ssl ) ) != 0 )
|
||||||
{
|
{
|
||||||
mbedtls_printf( " failed\n ! mbedtls_ssl_session_reset returned -0x%x\n\n",
|
mbedtls_printf( " failed\n ! mbedtls_ssl_session_reset returned -0x%x\n\n",
|
||||||
|
|
|
@ -467,9 +467,12 @@ int main( int argc, char *argv[] )
|
||||||
/*
|
/*
|
||||||
* 5. Print the certificate
|
* 5. Print the certificate
|
||||||
*/
|
*/
|
||||||
|
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
mbedtls_printf( " . Peer certificate information ... skipped\n" );
|
||||||
|
#else
|
||||||
mbedtls_printf( " . Peer certificate information ...\n" );
|
mbedtls_printf( " . Peer certificate information ...\n" );
|
||||||
ret = mbedtls_x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ",
|
ret = mbedtls_x509_crt_info( (char *) buf, sizeof( buf ) - 1, " ",
|
||||||
ssl.session->peer_cert );
|
mbedtls_ssl_get_peer_cert( &ssl ) );
|
||||||
if( ret == -1 )
|
if( ret == -1 )
|
||||||
{
|
{
|
||||||
mbedtls_printf( " failed\n ! mbedtls_x509_crt_info returned %d\n\n", ret );
|
mbedtls_printf( " failed\n ! mbedtls_x509_crt_info returned %d\n\n", ret );
|
||||||
|
@ -477,6 +480,7 @@ int main( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_printf( "%s\n", buf );
|
mbedtls_printf( "%s\n", buf );
|
||||||
|
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
mbedtls_ssl_close_notify( &ssl );
|
mbedtls_ssl_close_notify( &ssl );
|
||||||
|
|
||||||
|
|
|
@ -885,6 +885,22 @@ component_test_no_max_fragment_length () {
|
||||||
if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
|
if_build_succeeded tests/ssl-opt.sh -f "Max fragment length"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
component_test_asan_remove_peer_certificate () {
|
||||||
|
msg "build: default config with MBEDTLS_SSL_KEEP_PEER_CERTIFICATE disabled (ASan build)"
|
||||||
|
scripts/config.pl unset MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
|
||||||
|
CC=gcc cmake -D CMAKE_BUILD_TYPE:String=Asan .
|
||||||
|
make
|
||||||
|
|
||||||
|
msg "test: !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
|
||||||
|
make test
|
||||||
|
|
||||||
|
msg "test: ssl-opt.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
|
||||||
|
if_build_succeeded tests/ssl-opt.sh
|
||||||
|
|
||||||
|
msg "test: compat.sh, !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE"
|
||||||
|
if_build_succeeded tests/compat.sh
|
||||||
|
}
|
||||||
|
|
||||||
component_test_no_max_fragment_length_small_ssl_out_content_len () {
|
component_test_no_max_fragment_length_small_ssl_out_content_len () {
|
||||||
msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
|
msg "build: no MFL extension, small SSL_OUT_CONTENT_LEN (ASan build)"
|
||||||
scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
|
scripts/config.pl unset MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/* BEGIN_HEADER */
|
/* BEGIN_HEADER */
|
||||||
#include <mbedtls/ssl.h>
|
#include <mbedtls/ssl.h>
|
||||||
#include <mbedtls/ssl_internal.h>
|
#include <mbedtls/ssl_internal.h>
|
||||||
|
#include <mbedtls/md.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Helper function setting up inverse record transformations
|
* Helper function setting up inverse record transformations
|
||||||
|
@ -287,15 +288,40 @@ static int ssl_populate_session( mbedtls_ssl_session *session,
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_FS_IO)
|
#if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_FS_IO)
|
||||||
if( strlen( crt_file ) != 0 )
|
if( strlen( crt_file ) != 0 )
|
||||||
{
|
{
|
||||||
|
mbedtls_x509_crt tmp_crt;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
mbedtls_x509_crt_init( &tmp_crt );
|
||||||
|
ret = mbedtls_x509_crt_parse_file( &tmp_crt, crt_file );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
|
#if !defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
|
/* Calculate digest of temporary CRT. */
|
||||||
|
session->peer_cert_digest =
|
||||||
|
mbedtls_calloc( 1, MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN );
|
||||||
|
if( session->peer_cert_digest == NULL )
|
||||||
|
return( -1 );
|
||||||
|
ret = mbedtls_md( mbedtls_md_info_from_type(
|
||||||
|
MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE ),
|
||||||
|
tmp_crt.raw.p, tmp_crt.raw.len,
|
||||||
|
session->peer_cert_digest );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
session->peer_cert_digest_type =
|
||||||
|
MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_TYPE;
|
||||||
|
session->peer_cert_digest_len =
|
||||||
|
MBEDTLS_SSL_PEER_CERT_DIGEST_DFL_LEN;
|
||||||
|
#else /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
/* Move temporary CRT. */
|
||||||
session->peer_cert = mbedtls_calloc( 1, sizeof( *session->peer_cert ) );
|
session->peer_cert = mbedtls_calloc( 1, sizeof( *session->peer_cert ) );
|
||||||
if( session->peer_cert == NULL )
|
if( session->peer_cert == NULL )
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
*session->peer_cert = tmp_crt;
|
||||||
|
memset( &tmp_crt, 0, sizeof( tmp_crt ) );
|
||||||
|
#endif /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
|
||||||
ret = mbedtls_x509_crt_parse_file( session->peer_cert, crt_file );
|
mbedtls_x509_crt_free( &tmp_crt );
|
||||||
if( ret != 0 )
|
|
||||||
return( ret );
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
(void) crt_file;
|
(void) crt_file;
|
||||||
|
@ -681,6 +707,7 @@ void ssl_serialize_session_save_load( int ticket_len, char *crt_file )
|
||||||
restored.master, sizeof( original.master ) ) == 0 );
|
restored.master, sizeof( original.master ) ) == 0 );
|
||||||
|
|
||||||
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
#if defined(MBEDTLS_X509_CRT_PARSE_C)
|
||||||
|
#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
|
||||||
TEST_ASSERT( ( original.peer_cert == NULL ) ==
|
TEST_ASSERT( ( original.peer_cert == NULL ) ==
|
||||||
( restored.peer_cert == NULL ) );
|
( restored.peer_cert == NULL ) );
|
||||||
if( original.peer_cert != NULL )
|
if( original.peer_cert != NULL )
|
||||||
|
@ -691,7 +718,21 @@ void ssl_serialize_session_save_load( int ticket_len, char *crt_file )
|
||||||
restored.peer_cert->raw.p,
|
restored.peer_cert->raw.p,
|
||||||
original.peer_cert->raw.len ) == 0 );
|
original.peer_cert->raw.len ) == 0 );
|
||||||
}
|
}
|
||||||
#endif
|
#else /* MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
TEST_ASSERT( original.peer_cert_digest_type ==
|
||||||
|
restored.peer_cert_digest_type );
|
||||||
|
TEST_ASSERT( original.peer_cert_digest_len ==
|
||||||
|
restored.peer_cert_digest_len );
|
||||||
|
TEST_ASSERT( ( original.peer_cert_digest == NULL ) ==
|
||||||
|
( restored.peer_cert_digest == NULL ) );
|
||||||
|
if( original.peer_cert_digest != NULL )
|
||||||
|
{
|
||||||
|
TEST_ASSERT( memcmp( original.peer_cert_digest,
|
||||||
|
restored.peer_cert_digest,
|
||||||
|
original.peer_cert_digest_len ) == 0 );
|
||||||
|
}
|
||||||
|
#endif /* !MBEDTLS_SSL_KEEP_PEER_CERTIFICATE */
|
||||||
|
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||||
TEST_ASSERT( original.verify_result == restored.verify_result );
|
TEST_ASSERT( original.verify_result == restored.verify_result );
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
|
#if defined(MBEDTLS_SSL_SESSION_TICKETS) && defined(MBEDTLS_SSL_CLI_C)
|
||||||
|
|
Loading…
Reference in a new issue