mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 13:35:42 +01:00
Set SSL minor version only after validation
This commit is contained in:
parent
e965bd397e
commit
3fa1ee567c
@ -1716,20 +1716,24 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
|
||||
*/
|
||||
buf += mbedtls_ssl_hs_hdr_len( ssl );
|
||||
|
||||
MBEDTLS_SSL_DEBUG_BUF( 3, "server hello, version", buf + 0, 2 );
|
||||
mbedtls_ssl_read_version( &ssl->major_ver, &ssl->minor_ver,
|
||||
ssl->conf->transport, buf + 0 );
|
||||
{
|
||||
int major_ver, minor_ver;
|
||||
|
||||
if( ssl->major_ver < mbedtls_ssl_conf_get_min_major_ver( ssl->conf ) ||
|
||||
ssl->minor_ver < mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) ||
|
||||
ssl->major_ver > mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) ||
|
||||
ssl->minor_ver > mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) )
|
||||
MBEDTLS_SSL_DEBUG_BUF( 3, "server hello, version", buf + 0, 2 );
|
||||
mbedtls_ssl_read_version( &major_ver, &minor_ver,
|
||||
ssl->conf->transport,
|
||||
buf + 0 );
|
||||
|
||||
if( major_ver < mbedtls_ssl_conf_get_min_major_ver( ssl->conf ) ||
|
||||
minor_ver < mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) ||
|
||||
major_ver > mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) ||
|
||||
minor_ver > mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "server version out of bounds - "
|
||||
" min: [%d:%d], server: [%d:%d], max: [%d:%d]",
|
||||
mbedtls_ssl_conf_get_min_major_ver( ssl->conf ),
|
||||
mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ),
|
||||
ssl->major_ver, ssl->minor_ver,
|
||||
major_ver, minor_ver,
|
||||
mbedtls_ssl_conf_get_max_major_ver( ssl->conf ),
|
||||
mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) ) );
|
||||
|
||||
@ -1739,6 +1743,10 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION );
|
||||
}
|
||||
|
||||
ssl->minor_ver = minor_ver;
|
||||
ssl->major_ver = major_ver;
|
||||
}
|
||||
|
||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, current time: %lu",
|
||||
( (uint32_t) buf[2] << 24 ) |
|
||||
( (uint32_t) buf[3] << 16 ) |
|
||||
|
@ -1621,18 +1621,21 @@ read_record_header:
|
||||
*/
|
||||
MBEDTLS_SSL_DEBUG_BUF( 3, "client hello, version", buf, 2 );
|
||||
|
||||
mbedtls_ssl_read_version( &ssl->major_ver, &ssl->minor_ver,
|
||||
ssl->conf->transport, buf );
|
||||
{
|
||||
int minor_ver, major_ver;
|
||||
mbedtls_ssl_read_version( &major_ver, &minor_ver,
|
||||
ssl->conf->transport,
|
||||
buf );
|
||||
|
||||
ssl->handshake->max_major_ver = ssl->major_ver;
|
||||
ssl->handshake->max_minor_ver = ssl->minor_ver;
|
||||
ssl->handshake->max_major_ver = major_ver;
|
||||
ssl->handshake->max_minor_ver = minor_ver;
|
||||
|
||||
if( ssl->major_ver < mbedtls_ssl_conf_get_min_major_ver( ssl->conf ) ||
|
||||
ssl->minor_ver < mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) )
|
||||
if( major_ver < mbedtls_ssl_conf_get_min_major_ver( ssl->conf ) ||
|
||||
minor_ver < mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "client only supports ssl smaller than minimum"
|
||||
" [%d:%d] < [%d:%d]",
|
||||
ssl->major_ver, ssl->minor_ver,
|
||||
major_ver, minor_ver,
|
||||
mbedtls_ssl_conf_get_min_major_ver( ssl->conf ),
|
||||
mbedtls_ssl_conf_get_min_minor_ver( ssl->conf ) ) );
|
||||
mbedtls_ssl_send_alert_message( ssl, MBEDTLS_SSL_ALERT_LEVEL_FATAL,
|
||||
@ -1640,13 +1643,17 @@ read_record_header:
|
||||
return( MBEDTLS_ERR_SSL_BAD_HS_PROTOCOL_VERSION );
|
||||
}
|
||||
|
||||
if( ssl->major_ver > mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) )
|
||||
if( major_ver > mbedtls_ssl_conf_get_max_major_ver( ssl->conf ) )
|
||||
{
|
||||
ssl->major_ver = mbedtls_ssl_conf_get_max_major_ver( ssl->conf );
|
||||
ssl->minor_ver = mbedtls_ssl_conf_get_max_minor_ver( ssl->conf );
|
||||
major_ver = mbedtls_ssl_conf_get_max_major_ver( ssl->conf );
|
||||
minor_ver = mbedtls_ssl_conf_get_max_minor_ver( ssl->conf );
|
||||
}
|
||||
else if( minor_ver > mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) )
|
||||
minor_ver = mbedtls_ssl_conf_get_max_minor_ver( ssl->conf );
|
||||
|
||||
ssl->major_ver = major_ver;
|
||||
ssl->minor_ver = minor_ver;
|
||||
}
|
||||
else if( ssl->minor_ver > mbedtls_ssl_conf_get_max_minor_ver( ssl->conf ) )
|
||||
ssl->minor_ver = mbedtls_ssl_conf_get_max_minor_ver( ssl->conf );
|
||||
|
||||
/*
|
||||
* Save client random (inc. Unix time)
|
||||
|
Loading…
Reference in New Issue
Block a user