Browse code

tls: register SNI callback for server default profile

- make SNI work for other profile when the default one does not have
server_name
- GH #1938

Daniel-Constantin Mierla authored on 20/05/2019 08:56:08
Showing 1 changed files
... ...
@@ -1061,17 +1061,20 @@ static int ksr_tls_fix_domain(tls_domain_t* d, tls_domain_t* def)
1061 1061
 		* check server domains for server_name extension and register
1062 1062
 		* callback function
1063 1063
 		*/
1064
-		if ((d->type & TLS_DOMAIN_SRV) && d->server_name.len>0) {
1064
+		if ((d->type & TLS_DOMAIN_SRV)
1065
+				&& (d->server_name.len>0 || (d->type & TLS_DOMAIN_DEF))) {
1065 1066
 			if (!SSL_CTX_set_tlsext_servername_callback(d->ctx[i], tls_server_name_cb)) {
1066 1067
 				LM_ERR("register server_name callback handler for socket "
1067 1068
 					"[%s:%d], server_name='%s' failed for proc %d\n",
1068
-					ip_addr2a(&d->ip), d->port, d->server_name.s, i);
1069
+					ip_addr2a(&d->ip), d->port,
1070
+					(d->server_name.s)?d->server_name.s:"<default>", i);
1069 1071
 				return -1;
1070 1072
 			}
1071 1073
 			if (!SSL_CTX_set_tlsext_servername_arg(d->ctx[i], d)) {
1072 1074
 				LM_ERR("register server_name callback handler data for socket "
1073 1075
 					"[%s:%d], server_name='%s' failed for proc %d\n",
1074
-					ip_addr2a(&d->ip), d->port, d->server_name.s, i);
1076
+					ip_addr2a(&d->ip), d->port,
1077
+					(d->server_name.s)?d->server_name.s:"<default>", i);
1075 1078
 				return -1;
1076 1079
 			}
1077 1080
 		}
... ...
@@ -1079,10 +1082,11 @@ static int ksr_tls_fix_domain(tls_domain_t* d, tls_domain_t* def)
1079 1082
 	}
1080 1083
 
1081 1084
 #ifndef OPENSSL_NO_TLSEXT
1082
-	if ((d->type & TLS_DOMAIN_SRV) && d->server_name.len>0) {
1085
+	if ((d->type & TLS_DOMAIN_SRV)
1086
+			&& (d->server_name.len>0 || (d->type & TLS_DOMAIN_DEF))) {
1083 1087
 		LM_NOTICE("registered server_name callback handler for socket "
1084 1088
 			"[%s:%d], server_name='%s' ...\n", ip_addr2a(&d->ip), d->port,
1085
-			d->server_name.s);
1089
+			(d->server_name.s)?d->server_name.s:"<default>");
1086 1090
 	}
1087 1091
 #endif
1088 1092