You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Ruediger Pluem <rp...@apache.org> on 2008/01/12 07:51:06 UTC
Re: svn commit: r611216 - in /httpd/httpd/trunk/modules/ssl: ssl_engine_init.c
ssl_engine_kernel.c ssl_engine_vars.c ssl_private.h
On 01/11/2008 05:04 PM, fuankg@apache.org wrote:
> Author: fuankg
> Date: Fri Jan 11 08:04:26 2008
> New Revision: 611216
>
> URL: http://svn.apache.org/viewvc?rev=611216&view=rev
> Log:
> Restructured server name indication support (PR 34607);
> added missing client cert support.
> Submitted by: Kaspar Brand <asfbugz velox.ch>
>
> Modified:
> httpd/httpd/trunk/modules/ssl/ssl_engine_init.c
> httpd/httpd/trunk/modules/ssl/ssl_engine_kernel.c
> httpd/httpd/trunk/modules/ssl/ssl_engine_vars.c
> httpd/httpd/trunk/modules/ssl/ssl_private.h
>
> Modified: httpd/httpd/trunk/modules/ssl/ssl_engine_kernel.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/ssl/ssl_engine_kernel.c?rev=611216&r1=611215&r2=611216&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/ssl/ssl_engine_kernel.c (original)
> +++ httpd/httpd/trunk/modules/ssl/ssl_engine_kernel.c Fri Jan 11 08:04:26 2008
> @@ -1909,3 +1913,118 @@
> +static int ssl_find_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
> + * (adapted from vhost.c:matches_aliases())
> + */
> + 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 && (ssl = ((SSLConnRec *)myConnConfig(c))->ssl) &&
> + (sc = mySrvConfig(s))) {
> + SSL_set_SSL_CTX(ssl, sc->server->ssl_ctx);
> + /*
> + * SSL_set_SSL_CTX() only deals with the server cert,
> + * so we need to duplicate a few additional settings
> + * from the ctx by hand
> + */
> + SSL_set_options(ssl, SSL_CTX_get_options(ssl->ctx));
Sorry for being confused, but shouldn't this be sc->server->ssl_ctx
instead of ssl->ctx?
> + if ((SSL_get_verify_mode(ssl) == SSL_VERIFY_NONE) ||
> + (SSL_num_renegotiations(ssl) == 0)) {
> + /*
> + * Only initialize the verification settings from the ctx
> + * if they are not yet set, or if we're called when a new
> + * SSL connection is set up (num_renegotiations == 0).
> + * Otherwise, we would possibly reset a per-directory
> + * configuration which was put into effect by ssl_hook_Access.
> + */
> + SSL_set_verify(ssl, SSL_CTX_get_verify_mode(ssl->ctx),
> + SSL_CTX_get_verify_callback(ssl->ctx));
Same question as above.
> + }
> +
> + return 1;
> + }
> +
> + return 0;
> +}
> +#endif
Regards
RĂ¼diger
Re: svn commit: r611216 - in /httpd/httpd/trunk/modules/ssl: ssl_engine_init.c
ssl_engine_kernel.c ssl_engine_vars.c ssl_private.h
Posted by Kaspar Brand <ht...@velox.ch>.
Thanks for your review, RĂ¼diger.
>> + /* set SSL_CTX (if matched) */
>> + if (found && (ssl = ((SSLConnRec *)myConnConfig(c))->ssl) &&
>> + (sc = mySrvConfig(s))) {
>> + SSL_set_SSL_CTX(ssl, sc->server->ssl_ctx);
>> + /*
>> + * SSL_set_SSL_CTX() only deals with the server cert,
>> + * so we need to duplicate a few additional settings
>> + * from the ctx by hand
>> + */
>> + SSL_set_options(ssl, SSL_CTX_get_options(ssl->ctx));
>
>
> Sorry for being confused, but shouldn't this be sc->server->ssl_ctx
> instead of ssl->ctx?
It would amount to exactly the same thing, in fact. This is OpenSSL's
implementation of SSL_set_SSL_CTX (from ssl/ssl_lib.c):
> SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX* ctx)
> {
> if (ssl->ctx == ctx)
> return ssl->ctx;
> #ifndef OPENSSL_NO_TLSEXT
> if (ctx == NULL)
> ctx = ssl->initial_ctx;
> #endif
> if (ssl->cert != NULL)
> ssl_cert_free(ssl->cert);
> ssl->cert = ssl_cert_dup(ctx->cert);
> CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);
> if (ssl->ctx != NULL)
> SSL_CTX_free(ssl->ctx); /* decrement reference count */
> ssl->ctx = ctx;
> return(ssl->ctx);
> }
I.e. calling "SSL_set_SSL_CTX(ssl, sc->server->ssl_ctx)" from modssl
will set ssl->ctx to sc->server->ssl_ctx, so
"SSL_CTX_get_options(ssl->ctx)" and
"SSL_CTX_get_options(sc->server->ssl_ctx)" will do the same thing
afterwards.
My idea was that it would be more appropriate to refer to the newly set
context (that's why the SSL_set_SSL_CTX call is happening - which is
actually the most important step). But on the other hand I have no
strong feelings against using sc->server->ssl_ctx instead, if you prefer
that one.
>> + SSL_set_verify(ssl, SSL_CTX_get_verify_mode(ssl->ctx),
>> + SSL_CTX_get_verify_callback(ssl->ctx));
>
> Same question as above.
Same answer as above :-)
Kaspar