Test for ca list callback
@@ -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 );
