From bb676f7d32b7e88b7e1178127caa2a7ec986d08e Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Fri, 1 Feb 2019 08:15:06 +0000 Subject: [PATCH] Adapt ssl_client2 to parse DER encoded test CRTs if PEM is disabled --- programs/ssl/ssl_client2.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 13439702e..3f29ec5a1 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -1235,6 +1235,8 @@ int main( int argc, char *argv[] ) else #endif #if defined(MBEDTLS_CERTS_C) + { +#if defined(MBEDTLS_PEM_PARSE_C) for( i = 0; mbedtls_test_cas[i] != NULL; i++ ) { ret = mbedtls_x509_crt_parse( &cacert, @@ -1243,12 +1245,23 @@ int main( int argc, char *argv[] ) if( ret != 0 ) break; } + if( ret == 0 ) +#endif /* MBEDTLS_PEM_PARSE_C */ + for( i = 0; mbedtls_test_cas_der[i] != NULL; i++ ) + { + ret = mbedtls_x509_crt_parse_der( &cacert, + (const unsigned char *) mbedtls_test_cas_der[i], + mbedtls_test_cas_der_len[i] ); + if( ret != 0 ) + break; + } + } #else { ret = 1; mbedtls_printf( "MBEDTLS_CERTS_C not defined." ); } -#endif +#endif /* MBEDTLS_CERTS_C */ if( ret < 0 ) { mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n",