ssl_tls12_server.c: Remove some unnecessary checks on TLS minor version
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
b894ac7f99
commit
8457c12127
1 changed files with 95 additions and 128 deletions
|
@ -1103,16 +1103,13 @@ static int ssl_ciphersuite_match( mbedtls_ssl_context *ssl, int suite_id,
|
||||||
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
|
#if defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
|
||||||
/* If the ciphersuite requires signing, check whether
|
/* If the ciphersuite requires signing, check whether
|
||||||
* a suitable hash algorithm is present. */
|
* a suitable hash algorithm is present. */
|
||||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3 )
|
sig_type = mbedtls_ssl_get_ciphersuite_sig_alg( suite_info );
|
||||||
|
if( sig_type != MBEDTLS_PK_NONE &&
|
||||||
|
mbedtls_ssl_sig_hash_set_find( &ssl->handshake->hash_algs, sig_type ) == MBEDTLS_MD_NONE )
|
||||||
{
|
{
|
||||||
sig_type = mbedtls_ssl_get_ciphersuite_sig_alg( suite_info );
|
MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: no suitable hash algorithm "
|
||||||
if( sig_type != MBEDTLS_PK_NONE &&
|
"for signature algorithm %u", (unsigned) sig_type ) );
|
||||||
mbedtls_ssl_sig_hash_set_find( &ssl->handshake->hash_algs, sig_type ) == MBEDTLS_MD_NONE )
|
return( 0 );
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "ciphersuite mismatch: no suitable hash algorithm "
|
|
||||||
"for signature algorithm %u", (unsigned) sig_type ) );
|
|
||||||
return( 0 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
|
#endif /* MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED */
|
||||||
|
@ -1945,21 +1942,18 @@ have_ciphersuite:
|
||||||
/* Debugging-only output for testsuite */
|
/* Debugging-only output for testsuite */
|
||||||
#if defined(MBEDTLS_DEBUG_C) && \
|
#if defined(MBEDTLS_DEBUG_C) && \
|
||||||
defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
|
defined(MBEDTLS_KEY_EXCHANGE_WITH_CERT_ENABLED)
|
||||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3 )
|
mbedtls_pk_type_t sig_alg = mbedtls_ssl_get_ciphersuite_sig_alg( ciphersuite_info );
|
||||||
|
if( sig_alg != MBEDTLS_PK_NONE )
|
||||||
{
|
{
|
||||||
mbedtls_pk_type_t sig_alg = mbedtls_ssl_get_ciphersuite_sig_alg( ciphersuite_info );
|
mbedtls_md_type_t md_alg = mbedtls_ssl_sig_hash_set_find( &ssl->handshake->hash_algs,
|
||||||
if( sig_alg != MBEDTLS_PK_NONE )
|
sig_alg );
|
||||||
{
|
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v3, signature_algorithm ext: %d",
|
||||||
mbedtls_md_type_t md_alg = mbedtls_ssl_sig_hash_set_find( &ssl->handshake->hash_algs,
|
mbedtls_ssl_hash_from_md_alg( md_alg ) ) );
|
||||||
sig_alg );
|
}
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "client hello v3, signature_algorithm ext: %d",
|
else
|
||||||
mbedtls_ssl_hash_from_md_alg( md_alg ) ) );
|
{
|
||||||
}
|
MBEDTLS_SSL_DEBUG_MSG( 3, ( "no hash algorithm for signature algorithm "
|
||||||
else
|
"%u - should not happen", (unsigned) sig_alg ) );
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "no hash algorithm for signature algorithm "
|
|
||||||
"%u - should not happen", (unsigned) sig_alg ) );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2794,33 +2788,27 @@ static int ssl_write_certificate_request( mbedtls_ssl_context *ssl )
|
||||||
* enum { (255) } HashAlgorithm;
|
* enum { (255) } HashAlgorithm;
|
||||||
* enum { (255) } SignatureAlgorithm;
|
* enum { (255) } SignatureAlgorithm;
|
||||||
*/
|
*/
|
||||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3 )
|
const uint16_t *sig_alg = mbedtls_ssl_get_sig_algs( ssl );
|
||||||
|
if( sig_alg == NULL )
|
||||||
|
return( MBEDTLS_ERR_SSL_BAD_CONFIG );
|
||||||
|
|
||||||
|
for( ; *sig_alg != MBEDTLS_TLS1_3_SIG_NONE; sig_alg++ )
|
||||||
{
|
{
|
||||||
/*
|
unsigned char hash = MBEDTLS_BYTE_1( *sig_alg );
|
||||||
* Supported signature algorithms
|
|
||||||
*/
|
|
||||||
const uint16_t *sig_alg = mbedtls_ssl_get_sig_algs( ssl );
|
|
||||||
if( sig_alg == NULL )
|
|
||||||
return( MBEDTLS_ERR_SSL_BAD_CONFIG );
|
|
||||||
|
|
||||||
for( ; *sig_alg != MBEDTLS_TLS1_3_SIG_NONE; sig_alg++ )
|
if( mbedtls_ssl_set_calc_verify_md( ssl, hash ) )
|
||||||
{
|
continue;
|
||||||
unsigned char hash = MBEDTLS_BYTE_1( *sig_alg );
|
if( ! mbedtls_ssl_sig_alg_is_supported( ssl, *sig_alg ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
if( mbedtls_ssl_set_calc_verify_md( ssl, hash ) )
|
MBEDTLS_PUT_UINT16_BE( *sig_alg, p, sa_len );
|
||||||
continue;
|
|
||||||
if( ! mbedtls_ssl_sig_alg_is_supported( ssl, *sig_alg ) )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
MBEDTLS_PUT_UINT16_BE( *sig_alg, p, sa_len );
|
|
||||||
sa_len += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
MBEDTLS_PUT_UINT16_BE( sa_len, p, 0 );
|
|
||||||
sa_len += 2;
|
sa_len += 2;
|
||||||
p += sa_len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MBEDTLS_PUT_UINT16_BE( sa_len, p, 0 );
|
||||||
|
sa_len += 2;
|
||||||
|
p += sa_len;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* DistinguishedName certificate_authorities<0..2^16-1>;
|
* DistinguishedName certificate_authorities<0..2^16-1>;
|
||||||
* opaque DistinguishedName<1..2^16-1>;
|
* opaque DistinguishedName<1..2^16-1>;
|
||||||
|
@ -3243,26 +3231,18 @@ curve_matching_done:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
mbedtls_md_type_t md_alg;
|
mbedtls_md_type_t md_alg;
|
||||||
|
|
||||||
mbedtls_pk_type_t sig_alg =
|
mbedtls_pk_type_t sig_alg =
|
||||||
mbedtls_ssl_get_ciphersuite_sig_pk_alg( ciphersuite_info );
|
mbedtls_ssl_get_ciphersuite_sig_pk_alg( ciphersuite_info );
|
||||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3 )
|
|
||||||
{
|
/* For TLS 1.2, obey signature-hash-algorithm extension
|
||||||
/* For TLS 1.2, obey signature-hash-algorithm extension
|
* (RFC 5246, Sec. 7.4.1.4.1). */
|
||||||
* (RFC 5246, Sec. 7.4.1.4.1). */
|
if( sig_alg == MBEDTLS_PK_NONE ||
|
||||||
if( sig_alg == MBEDTLS_PK_NONE ||
|
( md_alg = mbedtls_ssl_sig_hash_set_find( &ssl->handshake->hash_algs,
|
||||||
( md_alg = mbedtls_ssl_sig_hash_set_find( &ssl->handshake->hash_algs,
|
sig_alg ) ) == MBEDTLS_MD_NONE )
|
||||||
sig_alg ) ) == MBEDTLS_MD_NONE )
|
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
|
||||||
/* (... because we choose a cipher suite
|
|
||||||
* only if there is a matching hash.) */
|
|
||||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||||
|
/* (... because we choose a cipher suite
|
||||||
|
* only if there is a matching hash.) */
|
||||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3291,29 +3271,24 @@ curve_matching_done:
|
||||||
/*
|
/*
|
||||||
* 2.3: Compute and add the signature
|
* 2.3: Compute and add the signature
|
||||||
*/
|
*/
|
||||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3 )
|
/*
|
||||||
{
|
* We need to specify signature and hash algorithm explicitly through
|
||||||
/*
|
* a prefix to the signature.
|
||||||
* For TLS 1.2, we need to specify signature and hash algorithm
|
*
|
||||||
* explicitly through a prefix to the signature.
|
* struct {
|
||||||
*
|
* HashAlgorithm hash;
|
||||||
* struct {
|
* SignatureAlgorithm signature;
|
||||||
* HashAlgorithm hash;
|
* } SignatureAndHashAlgorithm;
|
||||||
* SignatureAlgorithm signature;
|
*
|
||||||
* } SignatureAndHashAlgorithm;
|
* struct {
|
||||||
*
|
* SignatureAndHashAlgorithm algorithm;
|
||||||
* struct {
|
* opaque signature<0..2^16-1>;
|
||||||
* SignatureAndHashAlgorithm algorithm;
|
* } DigitallySigned;
|
||||||
* opaque signature<0..2^16-1>;
|
*
|
||||||
* } DigitallySigned;
|
*/
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
ssl->out_msg[ssl->out_msglen++] =
|
ssl->out_msg[ssl->out_msglen++] = mbedtls_ssl_hash_from_md_alg( md_alg );
|
||||||
mbedtls_ssl_hash_from_md_alg( md_alg );
|
ssl->out_msg[ssl->out_msglen++] = mbedtls_ssl_sig_from_pk_alg( sig_alg );
|
||||||
ssl->out_msg[ssl->out_msglen++] =
|
|
||||||
mbedtls_ssl_sig_from_pk_alg( sig_alg );
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
||||||
if( ssl->conf->f_async_sign_start != NULL )
|
if( ssl->conf->f_async_sign_start != NULL )
|
||||||
|
@ -4261,64 +4236,56 @@ static int ssl_parse_certificate_verify( mbedtls_ssl_context *ssl )
|
||||||
* opaque signature<0..2^16-1>;
|
* opaque signature<0..2^16-1>;
|
||||||
* } DigitallySigned;
|
* } DigitallySigned;
|
||||||
*/
|
*/
|
||||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_3 )
|
if( i + 2 > ssl->in_hslen )
|
||||||
{
|
{
|
||||||
if( i + 2 > ssl->in_hslen )
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate verify message" ) );
|
||||||
{
|
return( MBEDTLS_ERR_SSL_DECODE_ERROR );
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate verify message" ) );
|
}
|
||||||
return( MBEDTLS_ERR_SSL_DECODE_ERROR );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hash
|
* Hash
|
||||||
*/
|
*/
|
||||||
md_alg = mbedtls_ssl_md_alg_from_hash( ssl->in_msg[i] );
|
md_alg = mbedtls_ssl_md_alg_from_hash( ssl->in_msg[i] );
|
||||||
|
|
||||||
if( md_alg == MBEDTLS_MD_NONE || mbedtls_ssl_set_calc_verify_md( ssl, ssl->in_msg[i] ) )
|
if( md_alg == MBEDTLS_MD_NONE || mbedtls_ssl_set_calc_verify_md( ssl, ssl->in_msg[i] ) )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "peer not adhering to requested sig_alg"
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "peer not adhering to requested sig_alg"
|
||||||
" for verify message" ) );
|
" for verify message" ) );
|
||||||
return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
|
return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !defined(MBEDTLS_MD_SHA1)
|
#if !defined(MBEDTLS_MD_SHA1)
|
||||||
if( MBEDTLS_MD_SHA1 == md_alg )
|
if( MBEDTLS_MD_SHA1 == md_alg )
|
||||||
hash_start += 16;
|
hash_start += 16;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Info from md_alg will be used instead */
|
/* Info from md_alg will be used instead */
|
||||||
hashlen = 0;
|
hashlen = 0;
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Signature
|
* Signature
|
||||||
*/
|
*/
|
||||||
if( ( pk_alg = mbedtls_ssl_pk_alg_from_sig( ssl->in_msg[i] ) )
|
if( ( pk_alg = mbedtls_ssl_pk_alg_from_sig( ssl->in_msg[i] ) )
|
||||||
== MBEDTLS_PK_NONE )
|
== MBEDTLS_PK_NONE )
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "peer not adhering to requested sig_alg"
|
|
||||||
" for verify message" ) );
|
|
||||||
return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Check the certificate's key type matches the signature alg
|
|
||||||
*/
|
|
||||||
if( !mbedtls_pk_can_do( peer_pk, pk_alg ) )
|
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "sig_alg doesn't match cert key" ) );
|
|
||||||
return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
|
|
||||||
}
|
|
||||||
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "peer not adhering to requested sig_alg"
|
||||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
" for verify message" ) );
|
||||||
|
return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check the certificate's key type matches the signature alg
|
||||||
|
*/
|
||||||
|
if( !mbedtls_pk_can_do( peer_pk, pk_alg ) )
|
||||||
|
{
|
||||||
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "sig_alg doesn't match cert key" ) );
|
||||||
|
return( MBEDTLS_ERR_SSL_ILLEGAL_PARAMETER );
|
||||||
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
if( i + 2 > ssl->in_hslen )
|
if( i + 2 > ssl->in_hslen )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate verify message" ) );
|
MBEDTLS_SSL_DEBUG_MSG( 1, ( "bad certificate verify message" ) );
|
||||||
|
|
Loading…
Reference in a new issue