2013-09-15 14:54:56 +02:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
#include <polarssl/pk.h>
|
|
|
|
#include <polarssl/pem.h>
|
|
|
|
#include <polarssl/oid.h>
|
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
2013-09-15 17:04:23 +02:00
|
|
|
* depends_on:POLARSSL_PK_WRITE_C:POLARSSL_BIGNUM_C:POLARSSL_FS_IO
|
2013-09-15 14:54:56 +02:00
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
2014-06-24 13:11:25 +02:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_PEM_WRITE_C */
|
2013-09-15 14:54:56 +02:00
|
|
|
void pk_write_pubkey_check( char *key_file )
|
|
|
|
{
|
|
|
|
pk_context key;
|
|
|
|
unsigned char buf[5000];
|
|
|
|
unsigned char check_buf[5000];
|
|
|
|
int ret;
|
|
|
|
FILE *f;
|
2014-04-17 16:08:20 +02:00
|
|
|
size_t ilen;
|
2013-09-15 14:54:56 +02:00
|
|
|
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
|
|
memset( check_buf, 0, sizeof( check_buf ) );
|
|
|
|
|
|
|
|
pk_init( &key );
|
|
|
|
TEST_ASSERT( pk_parse_public_keyfile( &key, key_file ) == 0 );
|
|
|
|
|
|
|
|
ret = pk_write_pubkey_pem( &key, buf, sizeof( buf ) - 1);
|
|
|
|
TEST_ASSERT( ret >= 0 );
|
|
|
|
|
|
|
|
f = fopen( key_file, "r" );
|
|
|
|
TEST_ASSERT( f != NULL );
|
2014-04-17 16:08:20 +02:00
|
|
|
ilen = fread( check_buf, 1, sizeof( check_buf ) - 1, f );
|
2013-09-15 14:54:56 +02:00
|
|
|
fclose( f );
|
|
|
|
|
2014-04-17 16:08:20 +02:00
|
|
|
TEST_ASSERT( ilen == strlen( (char *) buf ) );
|
2013-09-15 14:54:56 +02:00
|
|
|
TEST_ASSERT( strncmp( (char *) buf, (char *) check_buf, sizeof( buf ) ) == 0 );
|
|
|
|
|
|
|
|
pk_free( &key );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2014-06-24 13:11:25 +02:00
|
|
|
/* BEGIN_CASE depends_on:POLARSSL_PEM_WRITE_C */
|
2013-09-15 14:54:56 +02:00
|
|
|
void pk_write_key_check( char *key_file )
|
|
|
|
{
|
|
|
|
pk_context key;
|
|
|
|
unsigned char buf[5000];
|
|
|
|
unsigned char check_buf[5000];
|
|
|
|
int ret;
|
|
|
|
FILE *f;
|
2014-04-17 16:08:20 +02:00
|
|
|
size_t ilen;
|
2013-09-15 14:54:56 +02:00
|
|
|
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
|
|
memset( check_buf, 0, sizeof( check_buf ) );
|
|
|
|
|
|
|
|
pk_init( &key );
|
|
|
|
TEST_ASSERT( pk_parse_keyfile( &key, key_file, NULL ) == 0 );
|
|
|
|
|
|
|
|
ret = pk_write_key_pem( &key, buf, sizeof( buf ) - 1);
|
|
|
|
TEST_ASSERT( ret >= 0 );
|
|
|
|
|
|
|
|
f = fopen( key_file, "r" );
|
|
|
|
TEST_ASSERT( f != NULL );
|
2014-04-17 16:08:20 +02:00
|
|
|
ilen = fread( check_buf, 1, sizeof( check_buf ) - 1, f );
|
2013-09-15 14:54:56 +02:00
|
|
|
fclose( f );
|
|
|
|
|
2014-04-17 16:08:20 +02:00
|
|
|
TEST_ASSERT( ilen == strlen( (char *) buf ) );
|
2013-09-15 14:54:56 +02:00
|
|
|
TEST_ASSERT( strncmp( (char *) buf, (char *) check_buf, sizeof( buf ) ) == 0 );
|
|
|
|
|
|
|
|
pk_free( &key );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|