Add support for password protected key file to ssl_server2
The example application programs/ssl/ssl_server2 allows the configuration of up to two CRTs through the command line parameters - crt_file, key_file - crt_file2, key_file2. However, password protected key files are not supported. This commit adds command line options - key_pwd - key_pwd2 which allow to specify passwords for the key files specified in key_file and key_file2, respectively.
This commit is contained in:
parent
0ca6d38bc3
commit
e58a630cb0
@ -124,8 +124,10 @@ int main( void )
|
||||
#define DFL_CA_PATH ""
|
||||
#define DFL_CRT_FILE ""
|
||||
#define DFL_KEY_FILE ""
|
||||
#define DFL_KEY_PWD ""
|
||||
#define DFL_CRT_FILE2 ""
|
||||
#define DFL_KEY_FILE2 ""
|
||||
#define DFL_KEY_PWD2 ""
|
||||
#define DFL_ASYNC_OPERATIONS "-"
|
||||
#define DFL_ASYNC_PRIVATE_DELAY1 ( -1 )
|
||||
#define DFL_ASYNC_PRIVATE_DELAY2 ( -1 )
|
||||
@ -218,11 +220,15 @@ int main( void )
|
||||
" crt_file=%%s Your own cert and chain (in bottom to top order, top may be omitted)\n" \
|
||||
" default: see note after key_file2\n" \
|
||||
" key_file=%%s default: see note after key_file2\n" \
|
||||
" key_pwd=%%s Password for key specified by key_file argument\n"\
|
||||
" default: none\n" \
|
||||
" crt_file2=%%s Your second cert and chain (in bottom to top order, top may be omitted)\n" \
|
||||
" default: see note after key_file2\n" \
|
||||
" key_file2=%%s default: see note below\n" \
|
||||
" note: if neither crt_file/key_file nor crt_file2/key_file2 are used,\n" \
|
||||
" preloaded certificate(s) and key(s) are used if available\n" \
|
||||
" key_pwd2=%%s Password for key specified by key_file2 argument\n"\
|
||||
" default: none\n" \
|
||||
" dhm_file=%%s File containing Diffie-Hellman parameters\n" \
|
||||
" default: preloaded parameters\n"
|
||||
#else
|
||||
@ -572,8 +578,10 @@ struct options
|
||||
const char *ca_path; /* the path with the CA certificate(s) reside */
|
||||
const char *crt_file; /* the file with the server certificate */
|
||||
const char *key_file; /* the file with the server key */
|
||||
const char *key_pwd; /* the password for the server key */
|
||||
const char *crt_file2; /* the file with the 2nd server certificate */
|
||||
const char *key_file2; /* the file with the 2nd server key */
|
||||
const char *key_pwd2; /* the password for the 2nd server key */
|
||||
const char *async_operations; /* supported SSL asynchronous operations */
|
||||
int async_private_delay1; /* number of times f_async_resume needs to be called for key 1, or -1 for no async */
|
||||
int async_private_delay2; /* number of times f_async_resume needs to be called for key 2, or -1 for no async */
|
||||
@ -1907,8 +1915,10 @@ int main( int argc, char *argv[] )
|
||||
opt.ca_path = DFL_CA_PATH;
|
||||
opt.crt_file = DFL_CRT_FILE;
|
||||
opt.key_file = DFL_KEY_FILE;
|
||||
opt.key_pwd = DFL_KEY_PWD;
|
||||
opt.crt_file2 = DFL_CRT_FILE2;
|
||||
opt.key_file2 = DFL_KEY_FILE2;
|
||||
opt.key_pwd2 = DFL_KEY_PWD2;
|
||||
opt.async_operations = DFL_ASYNC_OPERATIONS;
|
||||
opt.async_private_delay1 = DFL_ASYNC_PRIVATE_DELAY1;
|
||||
opt.async_private_delay2 = DFL_ASYNC_PRIVATE_DELAY2;
|
||||
@ -2028,10 +2038,14 @@ int main( int argc, char *argv[] )
|
||||
opt.crt_file = q;
|
||||
else if( strcmp( p, "key_file" ) == 0 )
|
||||
opt.key_file = q;
|
||||
else if( strcmp( p, "key_pwd" ) == 0 )
|
||||
opt.key_pwd = q;
|
||||
else if( strcmp( p, "crt_file2" ) == 0 )
|
||||
opt.crt_file2 = q;
|
||||
else if( strcmp( p, "key_file2" ) == 0 )
|
||||
opt.key_file2 = q;
|
||||
else if( strcmp( p, "key_pwd2" ) == 0 )
|
||||
opt.key_pwd2 = q;
|
||||
else if( strcmp( p, "dhm_file" ) == 0 )
|
||||
opt.dhm_file = q;
|
||||
#if defined(MBEDTLS_SSL_ASYNC_PRIVATE)
|
||||
@ -2817,7 +2831,8 @@ int main( int argc, char *argv[] )
|
||||
if( strlen( opt.key_file ) && strcmp( opt.key_file, "none" ) != 0 )
|
||||
{
|
||||
key_cert_init++;
|
||||
if( ( ret = mbedtls_pk_parse_keyfile( &pkey, opt.key_file, "" ) ) != 0 )
|
||||
if( ( ret = mbedtls_pk_parse_keyfile( &pkey, opt.key_file,
|
||||
opt.key_pwd ) ) != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile returned -0x%x\n\n", (unsigned int) -ret );
|
||||
goto exit;
|
||||
@ -2842,7 +2857,8 @@ int main( int argc, char *argv[] )
|
||||
if( strlen( opt.key_file2 ) && strcmp( opt.key_file2, "none" ) != 0 )
|
||||
{
|
||||
key_cert_init2++;
|
||||
if( ( ret = mbedtls_pk_parse_keyfile( &pkey2, opt.key_file2, "" ) ) != 0 )
|
||||
if( ( ret = mbedtls_pk_parse_keyfile( &pkey2, opt.key_file2,
|
||||
opt.key_pwd2 ) ) != 0 )
|
||||
{
|
||||
mbedtls_printf( " failed\n ! mbedtls_pk_parse_keyfile(2) returned -0x%x\n\n",
|
||||
(unsigned int) -ret );
|
||||
|
Loading…
Reference in New Issue
Block a user