Check transport in the extension parser/writer

Signed-off-by: Johan Pascal <johan.pascal@belledonne-communications.com>
This commit is contained in:
Johan Pascal 2020-10-28 17:18:18 +01:00
parent 5ef72d214f
commit c3ccd98a91
2 changed files with 23 additions and 31 deletions

View file

@ -768,8 +768,9 @@ static int ssl_write_use_srtp_ext( mbedtls_ssl_context *ssl,
*olen = 0; *olen = 0;
if( ( ssl->conf->dtls_srtp_profile_list == NULL ) || if( ( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) ||
( ssl->conf->dtls_srtp_profile_list_len == 0 ) ) ( ssl->conf->dtls_srtp_profile_list == NULL ) ||
( ssl->conf->dtls_srtp_profile_list_len == 0 ) )
{ {
return( 0 ); return( 0 );
} }
@ -1397,16 +1398,13 @@ static int ssl_write_client_hello( mbedtls_ssl_context *ssl )
#endif #endif
#if defined(MBEDTLS_SSL_DTLS_SRTP) #if defined(MBEDTLS_SSL_DTLS_SRTP)
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) if( ( ret = ssl_write_use_srtp_ext( ssl, p + 2 + ext_len,
end, &olen ) ) != 0 )
{ {
if( ( ret = ssl_write_use_srtp_ext( ssl, p + 2 + ext_len, MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_use_srtp_ext", ret );
end, &olen ) ) != 0 ) return( ret );
{
MBEDTLS_SSL_DEBUG_RET( 1, "ssl_write_use_srtp_ext", ret );
return( ret );
}
ext_len += olen;
} }
ext_len += olen;
#endif #endif
#if defined(MBEDTLS_SSL_SESSION_TICKETS) #if defined(MBEDTLS_SSL_SESSION_TICKETS)
@ -1852,8 +1850,9 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl,
uint16_t server_protection_profile_value = 0; uint16_t server_protection_profile_value = 0;
/* If use_srtp is not configured, just ignore the extension */ /* If use_srtp is not configured, just ignore the extension */
if( ssl->conf->dtls_srtp_profile_list == NULL || if( ( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) ||
ssl->conf->dtls_srtp_profile_list_len == 0 ) ( ssl->conf->dtls_srtp_profile_list == NULL ) ||
( ssl->conf->dtls_srtp_profile_list_len == 0 ) )
return( 0 ); return( 0 );
/* RFC 5764 section 4.1.1 /* RFC 5764 section 4.1.1
@ -2530,11 +2529,8 @@ static int ssl_parse_server_hello( mbedtls_ssl_context *ssl )
case MBEDTLS_TLS_EXT_USE_SRTP: case MBEDTLS_TLS_EXT_USE_SRTP:
MBEDTLS_SSL_DEBUG_MSG( 3, ( "found use_srtp extension" ) ); MBEDTLS_SSL_DEBUG_MSG( 3, ( "found use_srtp extension" ) );
if ( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) if( ( ret = ssl_parse_use_srtp_ext( ssl, ext + 4, ext_size ) ) != 0 )
{ return( ret );
if( ( ret = ssl_parse_use_srtp_ext( ssl, ext + 4, ext_size ) ) != 0 )
return( ret );
}
break; break;
#endif /* MBEDTLS_SSL_DTLS_SRTP */ #endif /* MBEDTLS_SSL_DTLS_SRTP */

View file

@ -789,8 +789,9 @@ static int ssl_parse_use_srtp_ext( mbedtls_ssl_context *ssl,
const size_t size_of_lengths = 3; const size_t size_of_lengths = 3;
/* If use_srtp is not configured, just ignore the extension */ /* If use_srtp is not configured, just ignore the extension */
if( ssl->conf->dtls_srtp_profile_list == NULL || if( ( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) ||
ssl->conf->dtls_srtp_profile_list_len == 0 ) ( ssl->conf->dtls_srtp_profile_list == NULL ) ||
( ssl->conf->dtls_srtp_profile_list_len == 0 ) )
{ {
return( 0 ); return( 0 );
} }
@ -2065,12 +2066,9 @@ read_record_header:
case MBEDTLS_TLS_EXT_USE_SRTP: case MBEDTLS_TLS_EXT_USE_SRTP:
MBEDTLS_SSL_DEBUG_MSG( 3, ( "found use_srtp extension" ) ); MBEDTLS_SSL_DEBUG_MSG( 3, ( "found use_srtp extension" ) );
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) ret = ssl_parse_use_srtp_ext( ssl, ext + 4, ext_size );
{ if( ret != 0 )
ret = ssl_parse_use_srtp_ext( ssl, ext + 4, ext_size ); return( ret );
if( ret != 0 )
return( ret );
}
break; break;
#endif /* MBEDTLS_SSL_DTLS_SRTP */ #endif /* MBEDTLS_SSL_DTLS_SRTP */
@ -2643,7 +2641,8 @@ static void ssl_write_use_srtp_ext( mbedtls_ssl_context *ssl,
*olen = 0; *olen = 0;
if( ssl->dtls_srtp_info.chosen_dtls_srtp_profile == MBEDTLS_TLS_SRTP_UNSET ) if( ( ssl->conf->transport != MBEDTLS_SSL_TRANSPORT_DATAGRAM ) ||
( ssl->dtls_srtp_info.chosen_dtls_srtp_profile == MBEDTLS_TLS_SRTP_UNSET ) )
{ {
return; return;
} }
@ -2992,11 +2991,8 @@ static int ssl_write_server_hello( mbedtls_ssl_context *ssl )
#endif #endif
#if defined(MBEDTLS_SSL_DTLS_SRTP) #if defined(MBEDTLS_SSL_DTLS_SRTP)
if( ssl->conf->transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM ) ssl_write_use_srtp_ext( ssl, p + 2 + ext_len, &olen );
{ ext_len += olen;
ssl_write_use_srtp_ext( ssl, p + 2 + ext_len, &olen );
ext_len += olen;
}
#endif #endif
MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, total extension length: %d", ext_len ) ); MBEDTLS_SSL_DEBUG_MSG( 3, ( "server hello, total extension length: %d", ext_len ) );