mirror of
https://github.com/apache/httpd.git
synced 2025-08-05 16:55:50 +03:00
Added server name indication (RFC 4366) support (PR 34607).
Submitted by: Kaspar Brand <asfbugz velox.ch> git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@606190 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -135,6 +135,87 @@ static int ssl_tmp_keys_init(server_rec *s)
|
||||
return OK;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_TLSEXT
|
||||
static int set_ssl_vhost(void *servername, conn_rec *c, server_rec *s)
|
||||
{
|
||||
SSLSrvConfigRec *sc;
|
||||
SSL *ssl;
|
||||
BOOL found = FALSE;
|
||||
apr_array_header_t *names;
|
||||
int i;
|
||||
|
||||
/* check ServerName */
|
||||
if (!strcasecmp(servername, s->server_hostname))
|
||||
found = TRUE;
|
||||
|
||||
/* if not matched yet, check ServerAlias entries */
|
||||
if (!found) {
|
||||
names = s->names;
|
||||
if (names) {
|
||||
char **name = (char **) names->elts;
|
||||
for (i = 0; i < names->nelts; ++i) {
|
||||
if(!name[i]) continue;
|
||||
if (!strcasecmp(servername, name[i])) {
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if still no match, check ServerAlias entries with wildcards */
|
||||
if (!found) {
|
||||
names = s->wild_names;
|
||||
if (names) {
|
||||
char **name = (char **) names->elts;
|
||||
for (i = 0; i < names->nelts; ++i) {
|
||||
if(!name[i]) continue;
|
||||
if (!ap_strcasecmp_match(servername, name[i])) {
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* set SSL_CTX (if matched) */
|
||||
if (found) {
|
||||
if ((ssl = ((SSLConnRec *)myConnConfig(c))->ssl) == NULL)
|
||||
return 0;
|
||||
if (!(sc = mySrvConfig(s)))
|
||||
return 0;
|
||||
SSL_set_SSL_CTX(ssl,sc->server->ssl_ctx);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ssl_set_vhost_ctx(SSL *ssl, const char *servername)
|
||||
{
|
||||
conn_rec *c;
|
||||
|
||||
if (servername == NULL) /* should not occur. */
|
||||
return 0;
|
||||
|
||||
SSL_set_SSL_CTX(ssl,NULL);
|
||||
|
||||
if (!(c = (conn_rec *)SSL_get_app_data(ssl)))
|
||||
return 0;
|
||||
|
||||
return ap_vhost_iterate_given_conn(c,set_ssl_vhost,servername);
|
||||
}
|
||||
|
||||
int ssl_servername_cb(SSL *s, int *al, modssl_ctx_t *mctx)
|
||||
{
|
||||
const char *servername = SSL_get_servername(s,TLSEXT_NAMETYPE_host_name);
|
||||
|
||||
if (servername) {
|
||||
return ssl_set_vhost_ctx(s,servername)?SSL_TLSEXT_ERR_OK:SSL_TLSEXT_ERR_ALERT_FATAL;
|
||||
}
|
||||
return SSL_TLSEXT_ERR_NOACK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Per-module initialization
|
||||
*/
|
||||
@@ -355,6 +436,29 @@ static void ssl_init_server_check(server_rec *s,
|
||||
}
|
||||
}
|
||||
|
||||
static void ssl_init_server_extensions(server_rec *s,
|
||||
apr_pool_t *p,
|
||||
apr_pool_t *ptemp,
|
||||
modssl_ctx_t *mctx)
|
||||
{
|
||||
/*
|
||||
* Configure TLS extensions support
|
||||
*/
|
||||
|
||||
#ifndef OPENSSL_NO_TLSEXT
|
||||
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
|
||||
"Configuring TLS extensions facility");
|
||||
|
||||
if (!SSL_CTX_set_tlsext_servername_callback(mctx->ssl_ctx, ssl_servername_cb) ||
|
||||
!SSL_CTX_set_tlsext_servername_arg(mctx->ssl_ctx, mctx)) {
|
||||
ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
|
||||
"Unable to initialize servername callback, bad openssl version.");
|
||||
ssl_log_ssl_error(APLOG_MARK, APLOG_ERR, s);
|
||||
ssl_die();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ssl_init_ctx_protocol(server_rec *s,
|
||||
apr_pool_t *p,
|
||||
apr_pool_t *ptemp,
|
||||
@@ -712,6 +816,8 @@ static void ssl_init_ctx(server_rec *s,
|
||||
/* XXX: proxy support? */
|
||||
ssl_init_ctx_cert_chain(s, p, ptemp, mctx);
|
||||
}
|
||||
|
||||
ssl_init_server_extensions(s, p, ptemp, mctx);
|
||||
}
|
||||
|
||||
static int ssl_server_import_cert(server_rec *s,
|
||||
@@ -1038,6 +1144,7 @@ void ssl_init_CheckServers(server_rec *base_server, apr_pool_t *p)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef OPENSSL_NO_TLSEXT
|
||||
/*
|
||||
* Give out warnings when more than one SSL-aware virtual server uses the
|
||||
* same IP:port. This doesn't work because mod_ssl then will always use
|
||||
@@ -1082,6 +1189,7 @@ void ssl_init_CheckServers(server_rec *base_server, apr_pool_t *p)
|
||||
"Init: You should not use name-based "
|
||||
"virtual hosts in conjunction with SSL!!");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef SSLC_VERSION_NUMBER
|
||||
|
Reference in New Issue
Block a user