Skip to content

Commit 634dda2

Browse files
committed
add option to load the private_key_password from a file
1 parent 29e7d78 commit 634dda2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/include/tls-h

+1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ struct fr_tls_server_conf_t {
351351
CONF_SECTION *cs;
352352

353353
char const *private_key_password;
354+
char const *private_key_password_file;
354355
char const *private_key_file;
355356
char const *certificate_file;
356357
char const *random_file;

src/main/tls.c

+18
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,7 @@ static CONF_PARSER tls_server_config[] = {
16341634
{ "CA_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, fr_tls_server_conf_t, ca_file), NULL },
16351635
{ "ca_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, fr_tls_server_conf_t, ca_file), NULL },
16361636
{ "private_key_password", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_SECRET, fr_tls_server_conf_t, private_key_password), NULL },
1637+
{ "private_key_password_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, fr_tls_server_conf_t, private_key_password_file), NULL },
16371638
#ifdef PSK_MAX_IDENTITY_LEN
16381639
{ "psk_identity", FR_CONF_OFFSET(PW_TYPE_STRING, fr_tls_server_conf_t, psk_identity), NULL },
16391640
{ "psk_hexphrase", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_SECRET, fr_tls_server_conf_t, psk_password), NULL },
@@ -3851,6 +3852,23 @@ SSL_CTX *tls_init_ctx(fr_tls_server_conf_t *conf, int client, char const *chain_
38513852
SSL_CTX_set_default_passwd_cb(ctx, cbtls_password);
38523853
}
38533854
}
3855+
if (conf->private_key_password_file) {
3856+
FILE* passwordfile = fopen(conf->private_key_password_file, "r");
3857+
if (passwordfile) {
3858+
char password[256];
3859+
if(fgets(password, sizeof(password), passwordfile)) {
3860+
SSL_CTX_set_default_passwd_cb_userdata(ctx, password);
3861+
SSL_CTX_set_default_passwd_cb(ctx, cbtls_password);
3862+
}
3863+
else {
3864+
ERROR(LOG_PREFIX ": Error reading private_key_password_file %s", conf->private_key_password_file);
3865+
}
3866+
fclose(passwordfile);
3867+
}
3868+
else {
3869+
ERROR(LOG_PREFIX ": Error opening private_key_password_file %s", conf->private_key_password_file);
3870+
}
3871+
}
38543872

38553873
#ifdef PSK_MAX_IDENTITY_LEN
38563874
/*

0 commit comments

Comments
 (0)