Add test for x509write_pubkey_pem()

This commit is contained in:
Manuel Pégourié-Gonnard 2013-09-11 23:46:51 +02:00 committed by Paul Bakker
parent ee73179b2f
commit 33250b0461
3 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,9 @@
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqQIfPUBq1VVTi/027oJl
LhVhXom/uOhFkNvuiBZS0/FDUEeWEllkh2v9K+BG+XO+3c+S4ZFb7Wagb4kpeUWA
0INq1UFDd185fAkER4KwVzlw7aPsFRkeqDMIR8EFQqn9TMO0390GH00QUUBncxMP
QPhtgSVfCrFTxjB+FTms+Vruf5KepgVb5xOXhbUjktnUJAbVCSWJdQfdphqPPwkZ
vq1lLGTrlZvc/kFeF6babFtpzAK6FCwWJJxK3M3Q91Jnc/EtoCP9fvQxyi1wyokL
BNsupk9wbp7OvViJ4lNZnm5akmXiiD8MlBmj3eXonZUT7Snbq3AS3FrKaxerUoJU
sQIDAQAB
-----END PUBLIC KEY-----

View file

@ -29,3 +29,7 @@ x509_csr_check:"data_files/server1.key":POLARSSL_MD_MD5:"data_files/server1.req.
Certificate write check Server1 SHA1
depends_on:POLARSSL_SHA1_C:POLARSSL_RSA_C:POLARSSL_PKCS1_V15
x509_crt_check:"data_files/server1.key":"":"C=NL,O=PolarSSL,CN=PolarSSL Server 1":"data_files/test-ca.key":"PolarSSLTest":"C=NL,O=PolarSSL,CN=PolarSSL Test CA":"1":"20110212144406":"20210212144406":POLARSSL_MD_SHA1:"data_files/server1.crt"
Public key write check RSA
depends_on:POLARSSL_RSA_C:POLARSSL_BASE64_C
x509_pubkey_check:"data_files/server1.pubkey"

View file

@ -124,3 +124,33 @@ void x509_crt_check( char *subject_key_file, char *subject_pwd,
mpi_free( &serial );
}
/* END_CASE */
/* BEGIN_CASE */
void x509_pubkey_check( char *key_file )
{
pk_context key;
unsigned char buf[5000];
unsigned char check_buf[5000];
int ret;
size_t olen = sizeof( check_buf );
FILE *f;
memset( buf, 0, sizeof( buf ) );
memset( check_buf, 0, sizeof( check_buf ) );
pk_init( &key );
TEST_ASSERT( x509parse_public_keyfile( &key, key_file ) == 0 );
ret = x509write_pubkey_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 */