2009-07-11 00:38:58 +02:00
|
|
|
BEGIN_HEADER
|
|
|
|
#include <polarssl/x509.h>
|
|
|
|
END_HEADER
|
|
|
|
|
|
|
|
BEGIN_CASE
|
|
|
|
x509_cert_info:crt_file:result_str
|
|
|
|
{
|
|
|
|
x509_cert crt;
|
|
|
|
char buf[2000];
|
2009-07-11 21:15:20 +02:00
|
|
|
int res;
|
2009-07-11 00:38:58 +02:00
|
|
|
|
|
|
|
memset( &crt, 0, sizeof( x509_cert ) );
|
|
|
|
memset( buf, 0, 2000 );
|
|
|
|
|
|
|
|
TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
|
2009-07-11 21:15:20 +02:00
|
|
|
res = x509parse_cert_info( buf, 2000, "", &crt );
|
2009-07-11 00:38:58 +02:00
|
|
|
|
|
|
|
TEST_ASSERT( res != -1 );
|
|
|
|
TEST_ASSERT( res != -2 );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
|
|
|
|
}
|
|
|
|
END_CASE
|
|
|
|
|
|
|
|
BEGIN_CASE
|
|
|
|
x509_crl_info:crl_file:result_str
|
|
|
|
{
|
|
|
|
x509_crl crl;
|
|
|
|
char buf[2000];
|
2009-07-11 21:15:20 +02:00
|
|
|
int res;
|
2009-07-11 00:38:58 +02:00
|
|
|
|
|
|
|
memset( &crl, 0, sizeof( x509_crl ) );
|
|
|
|
memset( buf, 0, 2000 );
|
|
|
|
|
|
|
|
TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
|
2009-07-11 21:15:20 +02:00
|
|
|
res = x509parse_crl_info( buf, 2000, "", &crl );
|
2009-07-11 00:38:58 +02:00
|
|
|
|
|
|
|
TEST_ASSERT( res != -1 );
|
|
|
|
TEST_ASSERT( res != -2 );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
|
|
|
|
}
|
|
|
|
END_CASE
|
|
|
|
|
|
|
|
BEGIN_CASE
|
|
|
|
x509_verify:crt_file:ca_file:crl_file:cn_name:result
|
|
|
|
{
|
|
|
|
x509_cert crt;
|
|
|
|
x509_cert ca;
|
|
|
|
x509_crl crl;
|
|
|
|
int flags = 0;
|
2009-07-11 21:15:20 +02:00
|
|
|
int res;
|
2009-07-11 00:38:58 +02:00
|
|
|
|
|
|
|
memset( &crt, 0, sizeof( x509_cert ) );
|
|
|
|
memset( &ca, 0, sizeof( x509_cert ) );
|
|
|
|
memset( &crl, 0, sizeof( x509_crl ) );
|
|
|
|
|
|
|
|
TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
|
|
|
|
TEST_ASSERT( x509parse_crtfile( &ca, {ca_file} ) == 0 );
|
|
|
|
TEST_ASSERT( x509parse_crlfile( &crl, {crl_file} ) == 0 );
|
|
|
|
|
2009-07-11 21:15:20 +02:00
|
|
|
res = x509parse_verify( &crt, &ca, &crl, {cn_name}, &flags );
|
2009-07-11 00:38:58 +02:00
|
|
|
|
|
|
|
if( res == 0 )
|
|
|
|
{
|
|
|
|
TEST_ASSERT( res == ( {result} ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TEST_ASSERT( flags == ( {result} ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
END_CASE
|
|
|
|
|
|
|
|
BEGIN_CASE
|
|
|
|
x509_dn_gets:crt_file:entity:result_str
|
|
|
|
{
|
|
|
|
x509_cert crt;
|
|
|
|
char buf[2000];
|
2009-07-11 21:15:20 +02:00
|
|
|
int res;
|
2009-07-11 00:38:58 +02:00
|
|
|
|
|
|
|
memset( &crt, 0, sizeof( x509_cert ) );
|
|
|
|
memset( buf, 0, 2000 );
|
|
|
|
|
|
|
|
TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
|
2009-07-11 21:15:20 +02:00
|
|
|
res = x509parse_dn_gets( buf, 2000, &crt.{entity} );
|
2009-07-11 00:38:58 +02:00
|
|
|
|
|
|
|
TEST_ASSERT( res != -1 );
|
|
|
|
TEST_ASSERT( res != -2 );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( buf, {result_str} ) == 0 );
|
|
|
|
}
|
|
|
|
END_CASE
|
|
|
|
|
|
|
|
BEGIN_CASE
|
|
|
|
x509_time_expired:crt_file:entity:result
|
|
|
|
{
|
|
|
|
x509_cert crt;
|
|
|
|
|
|
|
|
memset( &crt, 0, sizeof( x509_cert ) );
|
|
|
|
|
|
|
|
TEST_ASSERT( x509parse_crtfile( &crt, {crt_file} ) == 0 );
|
|
|
|
TEST_ASSERT( x509parse_time_expired( &crt.{entity} ) == {result} );
|
|
|
|
}
|
|
|
|
END_CASE
|
|
|
|
|
|
|
|
BEGIN_CASE
|
|
|
|
x509parse_key:key_file:password:result
|
|
|
|
{
|
|
|
|
rsa_context rsa;
|
2009-07-11 21:15:20 +02:00
|
|
|
int res;
|
2009-07-11 00:38:58 +02:00
|
|
|
|
|
|
|
memset( &rsa, 0, sizeof( rsa_context ) );
|
|
|
|
|
2009-07-11 21:15:20 +02:00
|
|
|
res = x509parse_keyfile( &rsa, {key_file}, {password} );
|
2009-07-11 00:38:58 +02:00
|
|
|
|
|
|
|
TEST_ASSERT( res == {result} );
|
|
|
|
|
|
|
|
if( res == 0 )
|
|
|
|
{
|
|
|
|
TEST_ASSERT( rsa_check_privkey( &rsa ) == 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
END_CASE
|
|
|
|
|
2009-07-19 21:36:15 +02:00
|
|
|
BEGIN_CASE
|
|
|
|
x509parse_crt:crt_data:result_str:result
|
|
|
|
{
|
|
|
|
x509_cert crt;
|
|
|
|
unsigned char buf[2000];
|
|
|
|
unsigned char output[2000];
|
|
|
|
int data_len, res;
|
|
|
|
|
|
|
|
memset( &crt, 0, sizeof( x509_cert ) );
|
|
|
|
memset( buf, 0, 2000 );
|
|
|
|
memset( output, 0, 2000 );
|
|
|
|
|
|
|
|
data_len = unhexify( buf, {crt_data} );
|
|
|
|
|
|
|
|
res = x509parse_crt( &crt, buf, data_len );
|
2009-07-19 22:30:14 +02:00
|
|
|
|
2009-07-19 21:36:15 +02:00
|
|
|
TEST_ASSERT( x509parse_crt( &crt, buf, data_len ) == ( {result} ) );
|
|
|
|
if( ( {result} ) == 0 )
|
|
|
|
{
|
|
|
|
res = x509parse_cert_info( (char *) output, 2000, "", &crt );
|
|
|
|
|
|
|
|
TEST_ASSERT( res != -1 );
|
|
|
|
TEST_ASSERT( res != -2 );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcmp( (char *) output, {result_str} ) == 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
END_CASE
|
|
|
|
|
2009-07-11 00:38:58 +02:00
|
|
|
BEGIN_CASE
|
|
|
|
x509_selftest:
|
|
|
|
{
|
|
|
|
TEST_ASSERT( x509_self_test( 0 ) == 0 );
|
|
|
|
}
|
|
|
|
END_CASE
|