mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Refine code based on commnets
Change code layout Change hostname_len type to size_t Fix various issues Signed-off-by: Xiaokang Qian <xiaokang.qian@arm.com>
This commit is contained in:
@ -54,7 +54,6 @@ static int ssl_write_hostname_ext( mbedtls_ssl_context *ssl,
|
||||
{
|
||||
unsigned char *p = buf;
|
||||
size_t hostname_len;
|
||||
size_t cmp_hostname_len;
|
||||
|
||||
*olen = 0;
|
||||
|
||||
@ -65,25 +64,8 @@ static int ssl_write_hostname_ext( mbedtls_ssl_context *ssl,
|
||||
( "client hello, adding server name extension: %s",
|
||||
ssl->hostname ) );
|
||||
|
||||
ssl->session_negotiate->hostname_mismatch = 0;
|
||||
hostname_len = strlen( ssl->hostname );
|
||||
|
||||
cmp_hostname_len = hostname_len < ssl->session_negotiate->hostname_len ?
|
||||
hostname_len : ssl->session_negotiate->hostname_len;
|
||||
|
||||
if( hostname_len != ssl->session_negotiate->hostname_len ||
|
||||
memcmp( ssl->hostname, ssl->session_negotiate->hostname, cmp_hostname_len ) )
|
||||
ssl->session_negotiate->hostname_mismatch = 1;
|
||||
|
||||
if( ssl->session_negotiate->hostname == NULL )
|
||||
{
|
||||
ssl->session_negotiate->hostname = mbedtls_calloc( 1, hostname_len );
|
||||
if( ssl->session_negotiate->hostname == NULL )
|
||||
return( MBEDTLS_ERR_SSL_ALLOC_FAILED );
|
||||
memcpy(ssl->session_negotiate->hostname, ssl->hostname, hostname_len);
|
||||
}
|
||||
ssl->session_negotiate->hostname_len = hostname_len;
|
||||
|
||||
MBEDTLS_SSL_CHK_BUF_PTR( p, end, hostname_len + 9 );
|
||||
|
||||
/*
|
||||
@ -888,6 +870,34 @@ static int ssl_prepare_client_hello( mbedtls_ssl_context *ssl )
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_TLS1_3) && \
|
||||
defined(MBEDTLS_SSL_SERVER_NAME_INDICATION)
|
||||
if( ssl->handshake->resume )
|
||||
{
|
||||
if( ssl->hostname != NULL && ssl->session_negotiate->hostname != NULL )
|
||||
{
|
||||
if( strcmp( ssl->hostname, ssl->session_negotiate->hostname ) )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1,
|
||||
( "hostname mismatch the session ticket, should not resume " ) );
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
}
|
||||
else if( ssl->session_negotiate->hostname != NULL )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1,
|
||||
( "hostname missed, should not resume " ) );
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mbedtls_ssl_session_set_hostname( ssl->session_negotiate,
|
||||
ssl->hostname );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_PROTO_TLS1_3 &&
|
||||
MBEDTLS_SSL_SERVER_NAME_INDICATION */
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
/*
|
||||
|
Reference in New Issue
Block a user