mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Unsupported extension tests in test_suite_x509parse
All combinations of critical or not, recognized or not by the callback are now tested as requested in https://github.com/ARMmbed/mbedtls/pull/3243#discussion_r432647880 In addition pass the OID of the unsupported extension to be parsed to the callback using the opaque pointer, which makes the tests fail if the library forwards the wrong pointer to the callback, as requested in https://github.com/ARMmbed/mbedtls/pull/3243#discussion_r432647392 Signed-off-by: Nicola Di Lieto <nicola.dilieto@gmail.com>
This commit is contained in:
@ -305,12 +305,14 @@ int verify_parse_san( mbedtls_x509_subject_alternative_name *san,
|
||||
int parse_crt_ext_cb( void *p_ctx, mbedtls_x509_crt const *crt, mbedtls_x509_buf const *oid,
|
||||
int critical, const unsigned char *p, const unsigned char *end )
|
||||
{
|
||||
( void ) p_ctx;
|
||||
( void ) crt;
|
||||
( void ) p;
|
||||
( void ) end;
|
||||
if( MBEDTLS_OID_CMP( MBEDTLS_OID_PKIX "\x01\x1F", oid ) != 0 && critical != 0 )
|
||||
return( MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
( void ) critical;
|
||||
mbedtls_x509_buf *new_oid = (mbedtls_x509_buf *)p_ctx;
|
||||
if( new_oid == NULL || new_oid->tag != oid->tag || new_oid->len != oid->len ||
|
||||
memcmp(new_oid->p, oid->p, oid->len) != 0 )
|
||||
return( MBEDTLS_ERR_X509_INVALID_EXTENSIONS + MBEDTLS_ERR_ASN1_UNEXPECTED_TAG );
|
||||
return( 0 );
|
||||
}
|
||||
#endif /* MBEDTLS_X509_CRT_PARSE_C */
|
||||
@ -822,13 +824,18 @@ exit:
|
||||
void x509parse_crt_cb( data_t * buf, char * result_str, int result )
|
||||
{
|
||||
mbedtls_x509_crt crt;
|
||||
mbedtls_x509_buf oid;
|
||||
unsigned char output[2000];
|
||||
int res;
|
||||
|
||||
oid.tag = MBEDTLS_ASN1_OID;
|
||||
oid.len = MBEDTLS_OID_SIZE(MBEDTLS_OID_PKIX "\x01\x1F");
|
||||
oid.p = (unsigned char *)MBEDTLS_OID_PKIX "\x01\x1F";
|
||||
|
||||
mbedtls_x509_crt_init( &crt );
|
||||
memset( output, 0, 2000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_x509_crt_parse_der_with_ext_cb( &crt, buf->x, buf->len, 0, parse_crt_ext_cb, NULL ) == ( result ) );
|
||||
TEST_ASSERT( mbedtls_x509_crt_parse_der_with_ext_cb( &crt, buf->x, buf->len, 0, parse_crt_ext_cb, &oid ) == ( result ) );
|
||||
if( ( result ) == 0 )
|
||||
{
|
||||
res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
|
||||
@ -843,7 +850,7 @@ void x509parse_crt_cb( data_t * buf, char * result_str, int result )
|
||||
mbedtls_x509_crt_init( &crt );
|
||||
memset( output, 0, 2000 );
|
||||
|
||||
TEST_ASSERT( mbedtls_x509_crt_parse_der_with_ext_cb( &crt, buf->x, buf->len, 1, parse_crt_ext_cb, NULL ) == ( result ) );
|
||||
TEST_ASSERT( mbedtls_x509_crt_parse_der_with_ext_cb( &crt, buf->x, buf->len, 1, parse_crt_ext_cb, &oid ) == ( result ) );
|
||||
if( ( result ) == 0 )
|
||||
{
|
||||
res = mbedtls_x509_crt_info( (char *) output, 2000, "", &crt );
|
||||
|
Reference in New Issue
Block a user