Skip to content

Commit 78af591

Browse files
committed
tls_openssl: enable certificate hostname validation
Based on example from https://wiki.openssl.org/index.php/Hostname_validation
1 parent 080fce6 commit 78af591

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

modules/tls_openssl/openssl_conn_ops.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <openssl/opensslv.h>
2626
#include <openssl/err.h>
2727
#include <openssl/rand.h>
28+
#include <openssl/x509v3.h>
2829

2930
#include <poll.h>
3031
#include <errno.h>
@@ -199,6 +200,8 @@ int openssl_tls_update_fd(struct tcp_connection *c, int fd)
199200

200201
int openssl_tls_conn_init(struct tcp_connection* c, struct tls_domain *tls_dom)
201202
{
203+
X509_VERIFY_PARAM *param = NULL;
204+
202205
/*
203206
* new connection within a single process, no lock necessary
204207
*/
@@ -218,6 +221,13 @@ int openssl_tls_conn_init(struct tcp_connection* c, struct tls_domain *tls_dom)
218221
return -1;
219222
}
220223

224+
param = SSL_get0_param(c->extra_data);
225+
X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS);
226+
if (!X509_VERIFY_PARAM_set1_host(param, c->hostname, strlen(c->hostname))) {
227+
LM_ERR("failed to set hostname for SSL context\n");
228+
return -1;
229+
}
230+
221231
/* put pointers to the tcp_connection and tls_domain structs
222232
* in the SSL struct as extra data */
223233
if (!SSL_set_ex_data(c->extra_data, SSL_EX_CONN_IDX, c)) {

0 commit comments

Comments
 (0)