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

Make TLS client cert/key file optional #601

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
62 changes: 30 additions & 32 deletions src/sslsocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,41 @@ const char *SSL_error_string(int ssl_error, int orig_ret)

SSL* SSL_new_client()
{
if (access(tls_cert_name, F_OK) == 0 && access(tls_key_name, F_OK) == 0) {
if (SSL_CTX_use_certificate_file(sip_trp_ssl_ctx_client,
tls_cert_name,
SSL_FILETYPE_PEM) != 1) {
ERROR("TLS_init_context: SSL_CTX_use_certificate_file (client) failed");
return NULL;
}
if (SSL_CTX_use_PrivateKey_file(sip_trp_ssl_ctx_client,
tls_key_name,
SSL_FILETYPE_PEM) != 1) {
ERROR("TLS_init_context: SSL_CTX_use_PrivateKey_file (client) failed");
return NULL;
}
}

return SSL_new(sip_trp_ssl_ctx_client);
}

SSL* SSL_new_server()
{

if (SSL_CTX_use_certificate_file(sip_trp_ssl_ctx,
tls_cert_name,
SSL_FILETYPE_PEM) != 1) {
ERROR("SSL_new_server: SSL_CTX_use_certificate_file failed");
return NULL;
}

if (SSL_CTX_use_PrivateKey_file(sip_trp_ssl_ctx,
tls_key_name,
SSL_FILETYPE_PEM) != 1) {
Copy link
Member

Choose a reason for hiding this comment

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

For indentation all the way to the right, please indent exactly to after the (, like above.

ERROR("SSL_new_server: SSL_CTX_use_PrivateKey_file failed");
return NULL;
}

return SSL_new(sip_trp_ssl_ctx);
}

Expand Down Expand Up @@ -332,38 +362,6 @@ enum tls_init_status TLS_init_context(void)
passwd_call_back_routine);
SSL_CTX_set_default_passwd_cb(sip_trp_ssl_ctx_client,
passwd_call_back_routine);

if (SSL_CTX_use_certificate_file(sip_trp_ssl_ctx,
tls_cert_name,
SSL_FILETYPE_PEM) != 1) {
char errbuf[256] = {'\0'};
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
ERROR("TLS_init_context: SSL_CTX_use_certificate_file failed: %s", errbuf);
return TLS_INIT_ERROR;
}

if (SSL_CTX_use_certificate_file(sip_trp_ssl_ctx_client,
tls_cert_name,
SSL_FILETYPE_PEM) != 1) {
char errbuf[256] = {'\0'};
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
ERROR("TLS_init_context: SSL_CTX_use_certificate_file (client) failed: %s", errbuf);
return TLS_INIT_ERROR;
}
Copy link
Member

Choose a reason for hiding this comment

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

Is a client cert now optional? Or is it not possible anymore?

if (SSL_CTX_use_PrivateKey_file(sip_trp_ssl_ctx,
tls_key_name,
SSL_FILETYPE_PEM) != 1) {
ERROR("TLS_init_context: SSL_CTX_use_PrivateKey_file failed");
return TLS_INIT_ERROR;
}

if (SSL_CTX_use_PrivateKey_file(sip_trp_ssl_ctx_client,
tls_key_name,
SSL_FILETYPE_PEM) != 1) {
ERROR("TLS_init_context: SSL_CTX_use_PrivateKey_file (client) failed");
return TLS_INIT_ERROR;
}

return TLS_INIT_NORMAL;
}

Expand Down