Skip to content

Commit 4a7bccb

Browse files
committed
Make TLS client cert/key file optional
1 parent 58d74ec commit 4a7bccb

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

src/sslsocket.cpp

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,41 @@ const char *SSL_error_string(int ssl_error, int orig_ret)
126126

127127
SSL* SSL_new_client()
128128
{
129+
if (access(tls_cert_name, F_OK) == 0 && access(tls_key_name, F_OK) == 0) {
130+
if (SSL_CTX_use_certificate_file(sip_trp_ssl_ctx_client,
131+
tls_cert_name,
132+
SSL_FILETYPE_PEM) != 1) {
133+
ERROR("TLS_init_context: SSL_CTX_use_certificate_file (client) failed");
134+
return NULL;
135+
}
136+
if (SSL_CTX_use_PrivateKey_file(sip_trp_ssl_ctx_client,
137+
tls_key_name,
138+
SSL_FILETYPE_PEM) != 1) {
139+
ERROR("TLS_init_context: SSL_CTX_use_PrivateKey_file (client) failed");
140+
return NULL;
141+
}
142+
}
143+
129144
return SSL_new(sip_trp_ssl_ctx_client);
130145
}
131146

132147
SSL* SSL_new_server()
133148
{
149+
150+
if (SSL_CTX_use_certificate_file(sip_trp_ssl_ctx,
151+
tls_cert_name,
152+
SSL_FILETYPE_PEM) != 1) {
153+
ERROR("SSL_new_server: SSL_CTX_use_certificate_file failed");
154+
return NULL;
155+
}
156+
157+
if (SSL_CTX_use_PrivateKey_file(sip_trp_ssl_ctx,
158+
tls_key_name,
159+
SSL_FILETYPE_PEM) != 1) {
160+
ERROR("SSL_new_server: SSL_CTX_use_PrivateKey_file failed");
161+
return NULL;
162+
}
163+
134164
return SSL_new(sip_trp_ssl_ctx);
135165
}
136166

@@ -332,38 +362,6 @@ enum tls_init_status TLS_init_context(void)
332362
passwd_call_back_routine);
333363
SSL_CTX_set_default_passwd_cb(sip_trp_ssl_ctx_client,
334364
passwd_call_back_routine);
335-
336-
if (SSL_CTX_use_certificate_file(sip_trp_ssl_ctx,
337-
tls_cert_name,
338-
SSL_FILETYPE_PEM) != 1) {
339-
char errbuf[256] = {'\0'};
340-
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
341-
ERROR("TLS_init_context: SSL_CTX_use_certificate_file failed: %s", errbuf);
342-
return TLS_INIT_ERROR;
343-
}
344-
345-
if (SSL_CTX_use_certificate_file(sip_trp_ssl_ctx_client,
346-
tls_cert_name,
347-
SSL_FILETYPE_PEM) != 1) {
348-
char errbuf[256] = {'\0'};
349-
ERR_error_string_n(ERR_get_error(), errbuf, sizeof(errbuf));
350-
ERROR("TLS_init_context: SSL_CTX_use_certificate_file (client) failed: %s", errbuf);
351-
return TLS_INIT_ERROR;
352-
}
353-
if (SSL_CTX_use_PrivateKey_file(sip_trp_ssl_ctx,
354-
tls_key_name,
355-
SSL_FILETYPE_PEM) != 1) {
356-
ERROR("TLS_init_context: SSL_CTX_use_PrivateKey_file failed");
357-
return TLS_INIT_ERROR;
358-
}
359-
360-
if (SSL_CTX_use_PrivateKey_file(sip_trp_ssl_ctx_client,
361-
tls_key_name,
362-
SSL_FILETYPE_PEM) != 1) {
363-
ERROR("TLS_init_context: SSL_CTX_use_PrivateKey_file (client) failed");
364-
return TLS_INIT_ERROR;
365-
}
366-
367365
return TLS_INIT_NORMAL;
368366
}
369367

0 commit comments

Comments
 (0)