Moved x509_self_test() from x509_crt.c to x509.c and fixed mem-free bug

This commit is contained in:
Paul Bakker 2013-09-16 22:53:25 +02:00
parent f20ba4b7b6
commit e9e6ae338b
2 changed files with 72 additions and 73 deletions

View file

@ -688,4 +688,76 @@ int x509parse_time_expired( const x509_time *to )
}
#endif /* POLARSSL_HAVE_TIME */
#if defined(POLARSSL_SELF_TEST)
#include "polarssl/x509_crt.h"
#include "polarssl/certs.h"
/*
* Checkup routine
*/
int x509_self_test( int verbose )
{
#if defined(POLARSSL_CERTS_C) && defined(POLARSSL_MD5_C)
int ret;
int flags;
x509_cert cacert;
x509_cert clicert;
if( verbose != 0 )
printf( " X.509 certificate load: " );
memset( &clicert, 0, sizeof( x509_cert ) );
ret = x509parse_crt( &clicert, (const unsigned char *) test_cli_crt,
strlen( test_cli_crt ) );
if( ret != 0 )
{
if( verbose != 0 )
printf( "failed\n" );
return( ret );
}
memset( &cacert, 0, sizeof( x509_cert ) );
ret = x509parse_crt( &cacert, (const unsigned char *) test_ca_crt,
strlen( test_ca_crt ) );
if( ret != 0 )
{
if( verbose != 0 )
printf( "failed\n" );
return( ret );
}
if( verbose != 0 )
printf( "passed\n X.509 signature verify: ");
ret = x509parse_verify( &clicert, &cacert, NULL, NULL, &flags, NULL, NULL );
if( ret != 0 )
{
if( verbose != 0 )
printf( "failed\n" );
printf("ret = %d, &flags = %04x\n", ret, flags);
return( ret );
}
if( verbose != 0 )
printf( "passed\n\n");
x509_crt_free( &cacert );
x509_crt_free( &clicert );
return( 0 );
#else
((void) verbose);
return( POLARSSL_ERR_X509_FEATURE_UNAVAILABLE );
#endif
}
#endif
#endif /* POLARSSL_X509_USE_C */

View file

@ -1680,77 +1680,4 @@ void x509_crt_free( x509_cert *crt )
while( cert_cur != NULL );
}
#if defined(POLARSSL_SELF_TEST)
#include "polarssl/certs.h"
/*
* Checkup routine
*/
int x509_self_test( int verbose )
{
#if defined(POLARSSL_CERTS_C) && defined(POLARSSL_MD5_C)
int ret;
int flags;
x509_cert cacert;
x509_cert clicert;
pk_context pkey;
if( verbose != 0 )
printf( " X.509 certificate load: " );
memset( &clicert, 0, sizeof( x509_cert ) );
ret = x509parse_crt( &clicert, (const unsigned char *) test_cli_crt,
strlen( test_cli_crt ) );
if( ret != 0 )
{
if( verbose != 0 )
printf( "failed\n" );
return( ret );
}
memset( &cacert, 0, sizeof( x509_cert ) );
ret = x509parse_crt( &cacert, (const unsigned char *) test_ca_crt,
strlen( test_ca_crt ) );
if( ret != 0 )
{
if( verbose != 0 )
printf( "failed\n" );
return( ret );
}
if( verbose != 0 )
printf( "passed\n X.509 signature verify: ");
ret = x509parse_verify( &clicert, &cacert, NULL, NULL, &flags, NULL, NULL );
if( ret != 0 )
{
if( verbose != 0 )
printf( "failed\n" );
printf("ret = %d, &flags = %04x\n", ret, flags);
return( ret );
}
if( verbose != 0 )
printf( "passed\n\n");
x509_crt_free( &cacert );
x509_crt_free( &clicert );
pk_free( &pkey );
return( 0 );
#else
((void) verbose);
return( POLARSSL_ERR_X509_FEATURE_UNAVAILABLE );
#endif
}
#endif
#endif