Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add option to load the private_key_password from a file #4938

Open
wants to merge 3 commits into
base: v3.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/include/tls-h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ struct fr_tls_server_conf_t {
CONF_SECTION *cs;

char const *private_key_password;
char const *private_key_password_file;
char const *private_key_file;
char const *certificate_file;
char const *random_file;
Expand Down
24 changes: 24 additions & 0 deletions src/main/tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,7 @@ static CONF_PARSER tls_server_config[] = {
{ "CA_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT | PW_TYPE_DEPRECATED, fr_tls_server_conf_t, ca_file), NULL },
{ "ca_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, fr_tls_server_conf_t, ca_file), NULL },
{ "private_key_password", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_SECRET, fr_tls_server_conf_t, private_key_password), NULL },
{ "private_key_password_file", FR_CONF_OFFSET(PW_TYPE_FILE_INPUT, fr_tls_server_conf_t, private_key_password_file), NULL },
#ifdef PSK_MAX_IDENTITY_LEN
{ "psk_identity", FR_CONF_OFFSET(PW_TYPE_STRING, fr_tls_server_conf_t, psk_identity), NULL },
{ "psk_hexphrase", FR_CONF_OFFSET(PW_TYPE_STRING | PW_TYPE_SECRET, fr_tls_server_conf_t, psk_password), NULL },
Expand Down Expand Up @@ -3851,6 +3852,29 @@ SSL_CTX *tls_init_ctx(fr_tls_server_conf_t *conf, int client, char const *chain_
SSL_CTX_set_default_passwd_cb(ctx, cbtls_password);
}
}
if (conf->private_key_password_file) {
FILE* passwordfile = fopen(conf->private_key_password_file, "r");
if (passwordfile) {
char password[256];
if(fgets(password, sizeof(password), passwordfile)) {
/*
* Remove CR/LF characters at the end of the string
*/
size_t index = strlen(password);
while (index > 0 && (password[index - 1] == '\r' || password[index - 1] == '\n')) {
index = index - 1;
password[index] = '\0';
}
SSL_CTX_set_default_passwd_cb_userdata(ctx, password);
SSL_CTX_set_default_passwd_cb(ctx, cbtls_password);
} else {
ERROR(LOG_PREFIX ": Error reading private_key_password_file %s", conf->private_key_password_file);
}
fclose(passwordfile);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will call fclose() when passwordfile is NULL. That is not recommended.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure ? There is a check if(passwordfile) and only if it is true (e.g. passwordfile is not NULL) fclose is executed.
Or what I have overlooked ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess. The random indentation and weird formatting is confusing.

} else {
ERROR(LOG_PREFIX ": Error opening private_key_password_file %s", conf->private_key_password_file);
}
}

#ifdef PSK_MAX_IDENTITY_LEN
/*
Expand Down