From 33250b046180aa27124410d3914cba53cec51652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 11 Sep 2013 23:46:51 +0200 Subject: [PATCH] Add test for x509write_pubkey_pem() --- tests/data_files/server1.pubkey | 9 +++++++ tests/suites/test_suite_x509write.data | 4 +++ tests/suites/test_suite_x509write.function | 30 ++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 tests/data_files/server1.pubkey diff --git a/tests/data_files/server1.pubkey b/tests/data_files/server1.pubkey new file mode 100644 index 000000000..93c669c61 --- /dev/null +++ b/tests/data_files/server1.pubkey @@ -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----- diff --git a/tests/suites/test_suite_x509write.data b/tests/suites/test_suite_x509write.data index 1be6c84b7..5a6597665 100644 --- a/tests/suites/test_suite_x509write.data +++ b/tests/suites/test_suite_x509write.data @@ -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" diff --git a/tests/suites/test_suite_x509write.function b/tests/suites/test_suite_x509write.function index bfe07c6a2..d05190388 100644 --- a/tests/suites/test_suite_x509write.function +++ b/tests/suites/test_suite_x509write.function @@ -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 */