diff --git a/configs/config-picocoin.h b/configs/config-picocoin.h index 7bd1cab73..1a1cd283d 100644 --- a/configs/config-picocoin.h +++ b/configs/config-picocoin.h @@ -43,8 +43,6 @@ #define POLARSSL_MD5_C // ??? #define POLARSSL_OID_C #define POLARSSL_PADLOCK_C -#define POLARSSL_PEM_PARSE_C // ??? -#define POLARSSL_PEM_WRITE_C // ??? #define POLARSSL_PK_C #define POLARSSL_PK_PARSE_C #define POLARSSL_PK_WRITE_C diff --git a/programs/pkey/key_app_writer.c b/programs/pkey/key_app_writer.c index c35736f9c..983b64e3f 100644 --- a/programs/pkey/key_app_writer.c +++ b/programs/pkey/key_app_writer.c @@ -63,8 +63,13 @@ int main( int argc, char *argv[] ) #define DFL_FILENAME "keyfile.key" #define DFL_DEBUG_LEVEL 0 #define DFL_OUTPUT_MODE OUTPUT_MODE_NONE +#if defined(POLARSSL_PEM_WRITE_C) #define DFL_OUTPUT_FILENAME "keyfile.pem" #define DFL_OUTPUT_FORMAT OUTPUT_FORMAT_PEM +#else +#define DFL_OUTPUT_FILENAME "keyfile.der" +#define DFL_OUTPUT_FORMAT OUTPUT_FORMAT_DER +#endif /* * global options @@ -88,6 +93,7 @@ static int write_public_key( pk_context *key, const char *output_file ) memset(output_buf, 0, 16000); +#if defined(POLARSSL_PEM_WRITE_C) if( opt.output_format == OUTPUT_FORMAT_PEM ) { if( ( ret = pk_write_pubkey_pem( key, output_buf, 16000 ) ) != 0 ) @@ -96,6 +102,7 @@ static int write_public_key( pk_context *key, const char *output_file ) len = strlen( (char *) output_buf ); } else +#endif { if( ( ret = pk_write_pubkey_der( key, output_buf, 16000 ) ) < 0 ) return( ret ); @@ -127,6 +134,8 @@ static int write_private_key( pk_context *key, const char *output_file ) size_t len = 0; memset(output_buf, 0, 16000); + +#if defined(POLARSSL_PEM_WRITE_C) if( opt.output_format == OUTPUT_FORMAT_PEM ) { if( ( ret = pk_write_key_pem( key, output_buf, 16000 ) ) != 0 ) @@ -135,6 +144,7 @@ static int write_private_key( pk_context *key, const char *output_file ) len = strlen( (char *) output_buf ); } else +#endif { if( ( ret = pk_write_key_der( key, output_buf, 16000 ) ) < 0 ) return( ret ); @@ -157,14 +167,23 @@ static int write_private_key( pk_context *key, const char *output_file ) return( 0 ); } +#if defined(POLARSSL_PEM_WRITE_C) +#define USAGE_OUT \ + " output_file=%%s default: keyfile.pem\n" \ + " output_format=pem|der default: pem\n" +#else +#define USAGE_OUT \ + " output_file=%%s default: keyfile.der\n" \ + " output_format=der default: der\n" +#endif + #define USAGE \ "\n usage: key_app param=<>...\n" \ "\n acceptable parameters:\n" \ " mode=private|public default: none\n" \ " filename=%%s default: keyfile.key\n" \ " output_mode=private|public default: none\n" \ - " output_file=%%s default: keyfile.pem\n" \ - " output_format=pem|der default: pem\n" \ + USAGE_OUT \ "\n" int main( int argc, char *argv[] ) @@ -222,9 +241,12 @@ int main( int argc, char *argv[] ) } else if( strcmp( p, "output_format" ) == 0 ) { +#if defined(POLARSSL_PEM_WRITE_C) if( strcmp( q, "pem" ) == 0 ) opt.output_format = OUTPUT_FORMAT_PEM; - else if( strcmp( q, "der" ) == 0 ) + else +#endif + if( strcmp( q, "der" ) == 0 ) opt.output_format = OUTPUT_FORMAT_DER; else goto usage; diff --git a/tests/suites/test_suite_pkwrite.function b/tests/suites/test_suite_pkwrite.function index 2ea940997..e172315b8 100644 --- a/tests/suites/test_suite_pkwrite.function +++ b/tests/suites/test_suite_pkwrite.function @@ -9,7 +9,7 @@ * END_DEPENDENCIES */ -/* BEGIN_CASE */ +/* BEGIN_CASE depends_on:POLARSSL_PEM_WRITE_C */ void pk_write_pubkey_check( char *key_file ) { pk_context key; @@ -40,7 +40,7 @@ void pk_write_pubkey_check( char *key_file ) } /* END_CASE */ -/* BEGIN_CASE */ +/* BEGIN_CASE depends_on:POLARSSL_PEM_WRITE_C */ void pk_write_key_check( char *key_file ) { pk_context key;