ソースを参照

Support multiple domains (Step 8/?) - experimental

bel2125 7 年 前
コミット
0f941f3eaa
3 ファイル変更19 行追加1 行削除
  1. 2 0
      examples/README.md
  2. 8 1
      examples/multidomain/README.md
  3. 9 0
      src/civetweb.c

+ 2 - 0
examples/README.md

@@ -7,6 +7,8 @@ The C++ wrapper only offers a subset of the full C API, thus the C example is mo
 
 In addition, there is one example how to configure a HTTPS server, to comply with modern security standards ([https](https://github.com/civetweb/civetweb/tree/master/examples/https)). It does not hold any source, but only a configuration file and some documentation how to use it.
 
+The [multidomain](https://github.com/civetweb/civetweb/tree/master/examples/multidomain) example demonstrates how to host multiple domains with different HTTPS certificates. It uses the standalone server (civetweb.c + main.c) and existing certificates.
+
 Some no longer maintained examples can be found in the ["obsolete"](https://github.com/civetweb/civetweb/tree/master/examples/_obsolete) folder. It is not guaranteed that they work in the current version - they are kept for reference, but might be removed in the future.
 
 All examples are subject to the MIT license (unless noted otherwise) - they come without warranty of any kind.

+ 8 - 1
examples/multidomain/README.md

@@ -1,3 +1,10 @@
-Compile civetweb to the repository root and run
+Compile CivetWeb to the repository root and run it from there
+
 ./civetweb examples/multidomain/base_domain.conf
 
+Check what cerfificate is used
+
+echo | openssl s_client -showcerts -servername default-domain -connect localhost:443 2>/dev/null | openssl x509 -inform pem -noout -text | grep Serial
+
+echo | openssl s_client -showcerts -servername localhost -connect localhost:443 2>/dev/null | openssl x509 -inform pem -noout -text | grep Serial
+

+ 9 - 0
src/civetweb.c

@@ -14453,6 +14453,8 @@ ssl_servername_callback(SSL *ssl, int *ad, void *arg)
 	 */
 	if ((servername == NULL) || (*servername == 0)) {
 		DEBUG_TRACE("%s", "SSL connection not supporting SNI");
+		conn->dom_ctx = &(ctx->dd);
+		SSL_set_SSL_CTX(ssl, conn->dom_ctx->ssl_ctx);
 		return SSL_TLSEXT_ERR_NOACK;
 	}
 
@@ -14460,7 +14462,10 @@ ssl_servername_callback(SSL *ssl, int *ad, void *arg)
 
 	while (dom) {
 		if (!mg_strcasecmp(servername, dom->config[AUTHENTICATION_DOMAIN])) {
+
 			/* Found matching domain */
+			DEBUG_TRACE("TLS domain %s found",
+			            dom->config[AUTHENTICATION_DOMAIN]);
 			SSL_set_SSL_CTX(ssl, dom->ssl_ctx);
 			conn->dom_ctx = dom;
 			return SSL_TLSEXT_ERR_OK;
@@ -14469,6 +14474,10 @@ ssl_servername_callback(SSL *ssl, int *ad, void *arg)
 	}
 
 	/* Default domain */
+	DEBUG_TRACE("TLS default domain %s used",
+	            ctx->dd.config[AUTHENTICATION_DOMAIN]);
+	conn->dom_ctx = &(ctx->dd);
+	SSL_set_SSL_CTX(ssl, conn->dom_ctx->ssl_ctx);
 	return SSL_TLSEXT_ERR_OK;
 }