tls: register SNI callback for server default profile
authorDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 20 May 2019 08:56:08 +0000 (10:56 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Mon, 20 May 2019 08:56:08 +0000 (10:56 +0200)
- make SNI work for other profile when the default one does not have
server_name
- GH #1938

src/modules/tls/tls_domain.c

index f22b8e8..fff4603 100644 (file)
@@ -1061,17 +1061,20 @@ static int ksr_tls_fix_domain(tls_domain_t* d, tls_domain_t* def)
                * check server domains for server_name extension and register
                * callback function
                */
-               if ((d->type & TLS_DOMAIN_SRV) && d->server_name.len>0) {
+               if ((d->type & TLS_DOMAIN_SRV)
+                               && (d->server_name.len>0 || (d->type & TLS_DOMAIN_DEF))) {
                        if (!SSL_CTX_set_tlsext_servername_callback(d->ctx[i], tls_server_name_cb)) {
                                LM_ERR("register server_name callback handler for socket "
                                        "[%s:%d], server_name='%s' failed for proc %d\n",
-                                       ip_addr2a(&d->ip), d->port, d->server_name.s, i);
+                                       ip_addr2a(&d->ip), d->port,
+                                       (d->server_name.s)?d->server_name.s:"<default>", i);
                                return -1;
                        }
                        if (!SSL_CTX_set_tlsext_servername_arg(d->ctx[i], d)) {
                                LM_ERR("register server_name callback handler data for socket "
                                        "[%s:%d], server_name='%s' failed for proc %d\n",
-                                       ip_addr2a(&d->ip), d->port, d->server_name.s, i);
+                                       ip_addr2a(&d->ip), d->port,
+                                       (d->server_name.s)?d->server_name.s:"<default>", i);
                                return -1;
                        }
                }
@@ -1079,10 +1082,11 @@ static int ksr_tls_fix_domain(tls_domain_t* d, tls_domain_t* def)
        }
 
 #ifndef OPENSSL_NO_TLSEXT
-       if ((d->type & TLS_DOMAIN_SRV) && d->server_name.len>0) {
+       if ((d->type & TLS_DOMAIN_SRV)
+                       && (d->server_name.len>0 || (d->type & TLS_DOMAIN_DEF))) {
                LM_NOTICE("registered server_name callback handler for socket "
                        "[%s:%d], server_name='%s' ...\n", ip_addr2a(&d->ip), d->port,
-                       d->server_name.s);
+                       (d->server_name.s)?d->server_name.s:"<default>");
        }
 #endif