Add test for x509write_key

This commit is contained in:
Manuel Pégourié-Gonnard 2013-09-12 03:31:34 +02:00 committed by Paul Bakker
parent 0088c69fbf
commit 7f1f0926e4
3 changed files with 33 additions and 21 deletions

View file

@ -563,27 +563,6 @@ int x509write_key_der( rsa_context *rsa, unsigned char *buf, size_t size )
ASN1_CHK_ADD( len, asn1_write_len( &c, buf, len ) );
ASN1_CHK_ADD( len, asn1_write_tag( &c, buf, ASN1_CONSTRUCTED | ASN1_SEQUENCE ) );
// TODO: Make NON RSA Specific variant later on
/* *--c = 0;
len += 1;
len += asn1_write_len( &c, len);
len += asn1_write_tag( &c, ASN1_BIT_STRING );
len += asn1_write_oid( &c, OID_PKCS1_RSA );
len += asn1_write_int( &c, 0 );
len += asn1_write_len( &c, len);
len += asn1_write_tag( &c, ASN1_CONSTRUCTED | ASN1_SEQUENCE );*/
/* for(i = 0; i < len; ++i)
{
if (i % 16 == 0 ) printf("\n");
printf("%02x ", c[i]);
}
printf("\n");*/
return( len );
}

View file

@ -37,3 +37,7 @@ x509_pubkey_check:"data_files/server1.pubkey"
Public key write check EC
depends_on:POLARSSL_ECP_C:POLARSSL_BASE64_C
x509_pubkey_check:"data_files/ec_pub.pem"
Private key write check RSA
depends_on:POLARSSL_RSA_C:POLARSSL_BASE64_C
x509_key_check:"data_files/server1.key"

View file

@ -153,3 +153,32 @@ void x509_pubkey_check( char *key_file )
pk_free( &key );
}
/* END_CASE */
/* BEGIN_CASE */
void x509_key_check( char *key_file )
{
pk_context key;
unsigned char buf[5000];
unsigned char check_buf[5000];
int ret;
FILE *f;
memset( buf, 0, sizeof( buf ) );
memset( check_buf, 0, sizeof( check_buf ) );
pk_init( &key );
TEST_ASSERT( x509parse_keyfile( &key, key_file, NULL ) == 0 );
ret = x509write_key_pem( pk_rsa( key ), buf, sizeof( buf ) - 1);
TEST_ASSERT( ret >= 0 );
f = fopen( key_file, "r" );
TEST_ASSERT( f != NULL );
fread( check_buf, 1, sizeof( check_buf ) - 1, f );
fclose( f );
TEST_ASSERT( strncmp( (char *) buf, (char *) check_buf, sizeof( buf ) ) == 0 );
pk_free( &key );
}
/* END_CASE */