From 03cd120ce4f8d4d66b74e72bbef2e7c1689a4091 Mon Sep 17 00:00:00 2001 From: Jarno Lamsa Date: Wed, 27 Mar 2019 15:45:04 +0200 Subject: [PATCH] Test for ca list callback --- tests/suites/test_suite_x509parse.function | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function index 4a826082b..6b93a5fe1 100644 --- a/tests/suites/test_suite_x509parse.function +++ b/tests/suites/test_suite_x509parse.function @@ -68,6 +68,25 @@ int verify_all( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32 return 0; } +#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) +int verify_cb( void *data, mbedtls_x509_crt *child, mbedtls_x509_crt **candidates) +{ + mbedtls_x509_crt *ca = (mbedtls_x509_crt *) data; + + mbedtls_x509_crt *first = mbedtls_calloc( 1, sizeof( mbedtls_x509_crt ) ); + TEST_ASSERT( first != NULL); + TEST_ASSERT( mbedtls_x509_crt_init( first ) == 0 ); + TEST_ASSERT( mbedtls_x509_crt_parse_der( first, ca->raw.p, ca->raw.len ) == 0); + while( ca->next != NULL ) + { + ca = ca->next; + TEST_ASSERT( mbedtls_x509_crt_parse_der( first, ca->raw.p, ca->raw.len ) == 0); + } + *candidates = first; + return 0; +} +#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ + int verify_fatal( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint32_t *flags ) { int *levels = (int *) data; @@ -374,6 +393,14 @@ void x509_verify( char *crt_file, char *ca_file, char *crl_file, TEST_ASSERT( res == ( result ) ); TEST_ASSERT( flags == (uint32_t)( flags_result ) ); +#if defined(MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK) + flags = 0; + + res = mbedtls_x509_crt_verify_with_cb( &crt, verify_cb, &ca, profile, cn_name, &flags, f_vrfy, NULL ); + + TEST_ASSERT( res == ( result ) ); + TEST_ASSERT( flags == (uint32_t)( flags_result ) ); +#endif /* MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK */ exit: mbedtls_x509_crt_free( &crt ); mbedtls_x509_crt_free( &ca );