summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanno Becker <hanno.becker@arm.com>2018-11-01 14:10:23 +0000
committerHanno Becker <hanno.becker@arm.com>2018-11-01 16:46:40 +0000
commit56e84632ef0be6b66a04d87b6a1efbc93cd8cf1d (patch)
tree2623c3b5f70dca092eef48d0f4dbac9442725e92
parentf745733bb16768af3a95ca482ee2538012a0acc6 (diff)
Add 'password' cmd line parameter to cert_req example program
-rw-r--r--programs/x509/cert_req.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/programs/x509/cert_req.c b/programs/x509/cert_req.c
index dcfc1410..95184478 100644
--- a/programs/x509/cert_req.c
+++ b/programs/x509/cert_req.c
@@ -56,6 +56,7 @@ int main( void )
#include <string.h>
#define DFL_FILENAME "keyfile.key"
+#define DFL_PASSWORD NULL
#define DFL_DEBUG_LEVEL 0
#define DFL_OUTPUT_FILENAME "cert.req"
#define DFL_SUBJECT_NAME "CN=Cert,O=mbed TLS,C=UK"
@@ -67,6 +68,7 @@ int main( void )
"\n usage: cert_req param=<>...\n" \
"\n acceptable parameters:\n" \
" filename=%%s default: keyfile.key\n" \
+ " password=%%s default: NULL\n" \
" debug_level=%%d default: 0 (disabled)\n" \
" output_file=%%s default: cert.req\n" \
" subject_name=%%s default: CN=Cert,O=mbed TLS,C=UK\n" \
@@ -101,6 +103,7 @@ int main( void )
struct options
{
const char *filename; /* filename of the key file */
+ const char *password; /* password for the key file */
int debug_level; /* level of debugging */
const char *output_file; /* where to store the constructed key file */
const char *subject_name; /* subject name for certificate request */
@@ -167,6 +170,7 @@ int main( int argc, char *argv[] )
}
opt.filename = DFL_FILENAME;
+ opt.password = DFL_PASSWORD;
opt.debug_level = DFL_DEBUG_LEVEL;
opt.output_file = DFL_OUTPUT_FILENAME;
opt.subject_name = DFL_SUBJECT_NAME;
@@ -184,6 +188,8 @@ int main( int argc, char *argv[] )
if( strcmp( p, "filename" ) == 0 )
opt.filename = q;
+ else if( strcmp( p, "password" ) == 0 )
+ opt.password = q;
else if( strcmp( p, "output_file" ) == 0 )
opt.output_file = q;
else if( strcmp( p, "debug_level" ) == 0 )
@@ -347,7 +353,7 @@ int main( int argc, char *argv[] )
mbedtls_printf( " . Loading the private key ..." );
fflush( stdout );
- ret = mbedtls_pk_parse_keyfile( &key, opt.filename, NULL );
+ ret = mbedtls_pk_parse_keyfile( &key, opt.filename, opt.password );
if( ret != 0 )
{