mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-04-26 05:23:47 +02:00
98 lines
2.8 KiB
Plaintext
98 lines
2.8 KiB
Plaintext
/* BEGIN_HEADER */
|
|
#include "mbedtls/x509.h"
|
|
#include "mbedtls/x509_ocsp.h"
|
|
/* END_HEADER */
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
* depends_on:MBEDTLS_X509_OCSP_PARSE_C
|
|
* END_DEPENDENCIES
|
|
*/
|
|
|
|
/* BEGIN_CASE */
|
|
void x509parse_ocsp_response( char *resp_data, char *result_str, int result )
|
|
{
|
|
mbedtls_x509_ocsp_response resp;
|
|
unsigned char resp_der[3000];
|
|
char resp_info[2000];
|
|
int data_len, ret;
|
|
|
|
mbedtls_x509_ocsp_response_init( &resp );
|
|
memset( resp_der, 0, sizeof( resp_der ) );
|
|
memset( resp_info, 0, sizeof( resp_info ) );
|
|
|
|
data_len = unhexify( resp_der, resp_data );
|
|
|
|
TEST_ASSERT( mbedtls_x509_ocsp_response_parse( &resp, resp_der,
|
|
data_len ) == result );
|
|
if( result == 0 )
|
|
{
|
|
ret = mbedtls_x509_ocsp_response_info( resp_info, sizeof( resp_info ),
|
|
"", &resp );
|
|
TEST_ASSERT( ret >= 0 );
|
|
TEST_ASSERT( strcmp( result_str, resp_info ) == 0 );
|
|
}
|
|
|
|
exit:
|
|
mbedtls_x509_ocsp_response_free( &resp );
|
|
}
|
|
/* END_CASE */
|
|
|
|
/* BEGIN_CASE */
|
|
void x509_ocsp_response_verify( char *resp_file, char *req_crt_file,
|
|
char *crt_chain_file, char *ca_file,
|
|
int result, int flags_result )
|
|
{
|
|
mbedtls_x509_ocsp_response resp;
|
|
mbedtls_x509_crt req_crt;
|
|
mbedtls_x509_crt chain;
|
|
mbedtls_x509_crt ca;
|
|
mbedtls_x509_ocsp_response *resp_ptr = NULL;
|
|
mbedtls_x509_crt *req_crt_ptr = NULL;
|
|
mbedtls_x509_crt *chain_ptr = NULL;
|
|
mbedtls_x509_crt *ca_ptr = NULL;
|
|
uint32_t flags = 0;
|
|
int ret;
|
|
|
|
mbedtls_x509_ocsp_response_init( &resp );
|
|
mbedtls_x509_crt_init( &req_crt );
|
|
mbedtls_x509_crt_init( &chain );
|
|
mbedtls_x509_crt_init( &ca );
|
|
|
|
if ( strlen( resp_file ) != 0 )
|
|
{
|
|
ret = mbedtls_x509_ocsp_response_parse_file( &resp, resp_file );
|
|
TEST_ASSERT( ret == 0 );
|
|
resp_ptr = &resp;
|
|
}
|
|
if ( strlen( req_crt_file ) != 0 )
|
|
{
|
|
ret = mbedtls_x509_crt_parse_file( &req_crt, req_crt_file );
|
|
TEST_ASSERT( ret == 0 );
|
|
req_crt_ptr = &req_crt;
|
|
}
|
|
if ( strlen( crt_chain_file ) != 0 )
|
|
{
|
|
ret = mbedtls_x509_crt_parse_file( &chain, crt_chain_file );
|
|
TEST_ASSERT( ret == 0 );
|
|
chain_ptr = &chain;
|
|
}
|
|
if ( strlen( ca_file ) != 0 )
|
|
{
|
|
ret = mbedtls_x509_crt_parse_file( &ca, ca_file );
|
|
TEST_ASSERT( ret == 0 );
|
|
ca_ptr = &ca;
|
|
}
|
|
|
|
ret = mbedtls_x509_ocsp_response_verify( resp_ptr, req_crt_ptr, chain_ptr,
|
|
ca_ptr, &flags );
|
|
TEST_ASSERT( ret == ( result ) );
|
|
TEST_ASSERT( flags == (uint32_t)( flags_result ) );
|
|
|
|
exit:
|
|
mbedtls_x509_ocsp_response_free( &resp );
|
|
mbedtls_x509_crt_free( &req_crt );
|
|
mbedtls_x509_crt_free( &chain );
|
|
mbedtls_x509_crt_free( &ca );
|
|
}
|
|
/* END_CASE */
|