From 3f8f0dc3fd458393d9ed4f106102fd4ea0689a43 Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Wed, 27 Feb 2019 18:06:47 +0000 Subject: [PATCH] Use mbedtls_x509_crt_get_subject() in test_suite_x509parse test --- tests/suites/test_suite_x509parse.function | 32 +++++----------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function index 91aa696b8..de0bc6d55 100644 --- a/tests/suites/test_suite_x509parse.function +++ b/tests/suites/test_suite_x509parse.function @@ -24,17 +24,6 @@ const mbedtls_x509_crt_profile profile_all = 1024, }; -static void x509_free_name( mbedtls_x509_name *name ) -{ - while( name != NULL ) - { - mbedtls_x509_name *next = name->next; - mbedtls_platform_zeroize( name, sizeof( *name ) ); - mbedtls_free( name ); - name = next; - } -} - /* Profile for backward compatibility. Allows SHA-1, unlike the default profile. */ const mbedtls_x509_crt_profile compat_profile = @@ -154,24 +143,17 @@ int verify_print( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint char *p = ctx->p; size_t n = ctx->buf + sizeof( ctx->buf ) - ctx->p; mbedtls_x509_crt_frame *frame; - mbedtls_x509_name subject; + mbedtls_x509_name *subject; ((void) flags); + ret = mbedtls_x509_crt_get_subject( crt, &subject ); + if( ret != 0 ) + return( ret ); + ret = mbedtls_x509_crt_frame_acquire( crt, &frame ); if( ret != 0 ) return( ret ); - /* Get linked list presentation of issuer which - * `mbedtls_x509_dn_gets()` understands. */ - { - unsigned char *subject_start = frame->subject_raw.p; - unsigned char *subject_end = frame->subject_raw.p + frame->subject_raw.len; - - ret = mbedtls_x509_get_name( &subject_start, subject_end, &subject ); - if( ret != 0 ) - goto cleanup; - } - ret = mbedtls_snprintf( p, n, "depth %d - serial ", certificate_depth ); MBEDTLS_X509_SAFE_SNPRINTF_WITH_ERROR; @@ -186,7 +168,7 @@ int verify_print( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint ret = mbedtls_snprintf( p, n, " - subject " ); MBEDTLS_X509_SAFE_SNPRINTF_WITH_ERROR; - ret = mbedtls_x509_dn_gets( p, n, &subject ); + ret = mbedtls_x509_dn_gets( p, n, subject ); MBEDTLS_X509_SAFE_SNPRINTF_WITH_ERROR; ret = mbedtls_snprintf( p, n, " - flags 0x%08x\n", *flags ); @@ -196,7 +178,7 @@ int verify_print( void *data, mbedtls_x509_crt *crt, int certificate_depth, uint cleanup: - x509_free_name( subject.next ); + mbedtls_x509_name_free( subject ); mbedtls_x509_crt_frame_release( crt, frame ); if( ret < 0 )