altarch-user / rpms / httpd

Forked from rpms/httpd 2 years ago
Clone

Blame SOURCES/httpd-2.4.6-r1332643+.patch

008793
# ./pullrev.sh 1332643 1345599 1487772
008793
008793
https://bugzilla.redhat.com//show_bug.cgi?id=809599
008793
008793
http://svn.apache.org/viewvc?view=revision&revision=1332643
008793
http://svn.apache.org/viewvc?view=revision&revision=1345599
008793
http://svn.apache.org/viewvc?view=revision&revision=1487772
008793
008793
--- httpd-2.4.6/modules/ssl/mod_ssl.c.r1332643+
008793
+++ httpd-2.4.6/modules/ssl/mod_ssl.c
008793
@@ -413,6 +413,37 @@ int ssl_engine_disable(conn_rec *c)
008793
     return 1;
008793
 }
008793
 
008793
+static int modssl_register_npn(conn_rec *c, 
008793
+                               ssl_npn_advertise_protos advertisefn,
008793
+                               ssl_npn_proto_negotiated negotiatedfn)
008793
+{
008793
+#ifdef HAVE_TLS_NPN
008793
+    SSLConnRec *sslconn = myConnConfig(c);
008793
+
008793
+    if (!sslconn) {
008793
+        return DECLINED;
008793
+    }
008793
+
008793
+    if (!sslconn->npn_advertfns) {
008793
+        sslconn->npn_advertfns = 
008793
+            apr_array_make(c->pool, 5, sizeof(ssl_npn_advertise_protos));
008793
+        sslconn->npn_negofns = 
008793
+            apr_array_make(c->pool, 5, sizeof(ssl_npn_proto_negotiated));
008793
+    }
008793
+
008793
+    if (advertisefn)
008793
+        APR_ARRAY_PUSH(sslconn->npn_advertfns, ssl_npn_advertise_protos) =
008793
+            advertisefn;
008793
+    if (negotiatedfn)
008793
+        APR_ARRAY_PUSH(sslconn->npn_negofns, ssl_npn_proto_negotiated) =
008793
+            negotiatedfn;
008793
+
008793
+    return OK;
008793
+#else
008793
+    return DECLINED;
008793
+#endif
008793
+}
008793
+
008793
 int ssl_init_ssl_connection(conn_rec *c, request_rec *r)
008793
 {
008793
     SSLSrvConfigRec *sc;
008793
@@ -584,6 +615,7 @@ static void ssl_register_hooks(apr_pool_
008793
 
008793
     APR_REGISTER_OPTIONAL_FN(ssl_proxy_enable);
008793
     APR_REGISTER_OPTIONAL_FN(ssl_engine_disable);
008793
+    APR_REGISTER_OPTIONAL_FN(modssl_register_npn);
008793
 
008793
     ap_register_auth_provider(p, AUTHZ_PROVIDER_GROUP, "ssl",
008793
                               AUTHZ_PROVIDER_VERSION,
008793
--- httpd-2.4.6/modules/ssl/mod_ssl.h.r1332643+
008793
+++ httpd-2.4.6/modules/ssl/mod_ssl.h
008793
@@ -63,5 +63,40 @@ APR_DECLARE_OPTIONAL_FN(int, ssl_proxy_e
008793
 
008793
 APR_DECLARE_OPTIONAL_FN(int, ssl_engine_disable, (conn_rec *));
008793
 
008793
+/** The npn_advertise_protos callback allows another modules to add
008793
+ * entries to the list of protocol names advertised by the server
008793
+ * during the Next Protocol Negotiation (NPN) portion of the SSL
008793
+ * handshake.  The callback is given the connection and an APR array;
008793
+ * it should push one or more char*'s pointing to NUL-terminated
008793
+ * strings (such as "http/1.1" or "spdy/2") onto the array and return
008793
+ * OK.  To prevent further processing of (other modules') callbacks,
008793
+ * return DONE. */
008793
+typedef int (*ssl_npn_advertise_protos)(conn_rec *connection, 
008793
+                                        apr_array_header_t *protos);
008793
+
008793
+/** The npn_proto_negotiated callback allows other modules to discover
008793
+ * the name of the protocol that was chosen during the Next Protocol
008793
+ * Negotiation (NPN) portion of the SSL handshake.  Note that this may
008793
+ * be the empty string (in which case modules should probably assume
008793
+ * HTTP), or it may be a protocol that was never even advertised by
008793
+ * the server.  The callback is given the connection, a
008793
+ * non-NUL-terminated string containing the protocol name, and the
008793
+ * length of the string; it should do something appropriate
008793
+ * (i.e. insert or remove filters) and return OK.  To prevent further
008793
+ * processing of (other modules') callbacks, return DONE. */
008793
+typedef int (*ssl_npn_proto_negotiated)(conn_rec *connection, 
008793
+                                        const char *proto_name,
008793
+                                        apr_size_t proto_name_len);
008793
+
008793
+/* An optional function which can be used to register a pair of
008793
+ * callbacks for NPN handling.  This optional function should be
008793
+ * invoked from a pre_connection hook which runs *after* mod_ssl.c's
008793
+ * pre_connection hook.  The function returns OK if the callbacks are
008793
+ * register, or DECLINED otherwise (for example if mod_ssl does not
008793
+l * support NPN).  */
008793
+APR_DECLARE_OPTIONAL_FN(int, modssl_register_npn, (conn_rec *conn, 
008793
+                                                   ssl_npn_advertise_protos advertisefn,
008793
+                                                   ssl_npn_proto_negotiated negotiatedfn));
008793
+
008793
 #endif /* __MOD_SSL_H__ */
008793
 /** @} */
008793
--- httpd-2.4.6/modules/ssl/ssl_engine_init.c.r1332643+
008793
+++ httpd-2.4.6/modules/ssl/ssl_engine_init.c
008793
@@ -725,6 +725,11 @@ static void ssl_init_ctx_callbacks(serve
008793
 #endif
008793
 
008793
     SSL_CTX_set_info_callback(ctx, ssl_callback_Info);
008793
+
008793
+#ifdef HAVE_TLS_NPN
008793
+    SSL_CTX_set_next_protos_advertised_cb(
008793
+        ctx, ssl_callback_AdvertiseNextProtos, NULL);
008793
+#endif
008793
 }
008793
 
008793
 static void ssl_init_ctx_verify(server_rec *s,
008793
--- httpd-2.4.6/modules/ssl/ssl_engine_io.c.r1332643+
008793
+++ httpd-2.4.6/modules/ssl/ssl_engine_io.c
008793
@@ -297,6 +297,7 @@ typedef struct {
008793
     apr_pool_t *pool;
008793
     char buffer[AP_IOBUFSIZE];
008793
     ssl_filter_ctx_t *filter_ctx;
008793
+    int npn_finished;  /* 1 if NPN has finished, 0 otherwise */
008793
 } bio_filter_in_ctx_t;
008793
 
008793
 /*
008793
@@ -1400,6 +1401,37 @@ static apr_status_t ssl_io_filter_input(
008793
         APR_BRIGADE_INSERT_TAIL(bb, bucket);
008793
     }
008793
 
008793
+#ifdef HAVE_TLS_NPN
008793
+    /* By this point, Next Protocol Negotiation (NPN) should be completed (if
008793
+     * our version of OpenSSL supports it).  If we haven't already, find out
008793
+     * which protocol was decided upon and inform other modules by calling
008793
+     * npn_proto_negotiated_hook. */
008793
+    if (!inctx->npn_finished) {
008793
+        SSLConnRec *sslconn = myConnConfig(f->c);
008793
+        const unsigned char *next_proto = NULL;
008793
+        unsigned next_proto_len = 0;
008793
+        int n;
008793
+
008793
+        if (sslconn->npn_negofns) {
008793
+            SSL_get0_next_proto_negotiated(
008793
+                inctx->ssl, &next_proto, &next_proto_len);
008793
+            ap_log_cerror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, f->c,
008793
+                          APLOGNO(02306) "SSL NPN negotiated protocol: '%*s'",
008793
+                          next_proto_len, (const char*)next_proto);
008793
+            
008793
+            for (n = 0; n < sslconn->npn_negofns->nelts; n++) {
008793
+                ssl_npn_proto_negotiated fn = 
008793
+                    APR_ARRAY_IDX(sslconn->npn_negofns, n, ssl_npn_proto_negotiated);
008793
+                
008793
+                if (fn(f->c, (const char *)next_proto, next_proto_len) == DONE)
008793
+                    break;
008793
+            }
008793
+        }
008793
+            
008793
+        inctx->npn_finished = 1;
008793
+    }
008793
+#endif
008793
+
008793
     return APR_SUCCESS;
008793
 }
008793
 
008793
@@ -1881,6 +1913,7 @@ static void ssl_io_input_add_filter(ssl_
008793
     inctx->block = APR_BLOCK_READ;
008793
     inctx->pool = c->pool;
008793
     inctx->filter_ctx = filter_ctx;
008793
+    inctx->npn_finished = 0;
008793
 }
008793
 
008793
 /* The request_rec pointer is passed in here only to ensure that the
008793
--- httpd-2.4.6/modules/ssl/ssl_engine_kernel.c.r1332643+
008793
+++ httpd-2.4.6/modules/ssl/ssl_engine_kernel.c
008793
@@ -2161,6 +2161,97 @@ int ssl_callback_SessionTicket(SSL *ssl,
008793
 }
008793
 #endif /* HAVE_TLS_SESSION_TICKETS */
008793
 
008793
+#ifdef HAVE_TLS_NPN
008793
+/*
008793
+ * This callback function is executed when SSL needs to decide what protocols
008793
+ * to advertise during Next Protocol Negotiation (NPN).  It must produce a
008793
+ * string in wire format -- a sequence of length-prefixed strings -- indicating
008793
+ * the advertised protocols.  Refer to SSL_CTX_set_next_protos_advertised_cb
008793
+ * in OpenSSL for reference.
008793
+ */
008793
+int ssl_callback_AdvertiseNextProtos(SSL *ssl, const unsigned char **data_out,
008793
+                                     unsigned int *size_out, void *arg)
008793
+{
008793
+    conn_rec *c = (conn_rec*)SSL_get_app_data(ssl);
008793
+    SSLConnRec *sslconn = myConnConfig(c);
008793
+    apr_array_header_t *protos;
008793
+    int num_protos;
008793
+    unsigned int size;
008793
+    int i;
008793
+    unsigned char *data;
008793
+    unsigned char *start;
008793
+
008793
+    *data_out = NULL;
008793
+    *size_out = 0;
008793
+
008793
+    /* If the connection object is not available, or there are no NPN
008793
+     * hooks registered, then there's nothing for us to do. */
008793
+    if (c == NULL || sslconn->npn_advertfns == NULL) {
008793
+        return SSL_TLSEXT_ERR_NOACK;
008793
+    }
008793
+
008793
+    /* Invoke our npn_advertise_protos hook, giving other modules a chance to
008793
+     * add alternate protocol names to advertise. */
008793
+    protos = apr_array_make(c->pool, 0, sizeof(char *));
008793
+    for (i = 0; i < sslconn->npn_advertfns->nelts; i++) {
008793
+        ssl_npn_advertise_protos fn = 
008793
+            APR_ARRAY_IDX(sslconn->npn_advertfns, i, ssl_npn_advertise_protos);
008793
+        
008793
+        if (fn(c, protos) == DONE)
008793
+            break;
008793
+    }
008793
+    num_protos = protos->nelts;
008793
+
008793
+    /* We now have a list of null-terminated strings; we need to concatenate
008793
+     * them together into a single string, where each protocol name is prefixed
008793
+     * by its length.  First, calculate how long that string will be. */
008793
+    size = 0;
008793
+    for (i = 0; i < num_protos; ++i) {
008793
+        const char *string = APR_ARRAY_IDX(protos, i, const char*);
008793
+        unsigned int length = strlen(string);
008793
+        /* If the protocol name is too long (the length must fit in one byte),
008793
+         * then log an error and skip it. */
008793
+        if (length > 255) {
008793
+            ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c, APLOGNO(02307)
008793
+                          "SSL NPN protocol name too long (length=%u): %s",
008793
+                          length, string);
008793
+            continue;
008793
+        }
008793
+        /* Leave room for the length prefix (one byte) plus the protocol name
008793
+         * itself. */
008793
+        size += 1 + length;
008793
+    }
008793
+
008793
+    /* If there is nothing to advertise (either because no modules added
008793
+     * anything to the protos array, or because all strings added to the array
008793
+     * were skipped), then we're done. */
008793
+    if (size == 0) {
008793
+        return SSL_TLSEXT_ERR_NOACK;
008793
+    }
008793
+
008793
+    /* Now we can build the string.  Copy each protocol name string into the
008793
+     * larger string, prefixed by its length. */
008793
+    data = apr_palloc(c->pool, size * sizeof(unsigned char));
008793
+    start = data;
008793
+    for (i = 0; i < num_protos; ++i) {
008793
+        const char *string = APR_ARRAY_IDX(protos, i, const char*);
008793
+        apr_size_t length = strlen(string);
008793
+        if (length > 255)
008793
+            continue;
008793
+        *start = (unsigned char)length;
008793
+        ++start;
008793
+        memcpy(start, string, length * sizeof(unsigned char));
008793
+        start += length;
008793
+    }
008793
+
008793
+    /* Success. */
008793
+    *data_out = data;
008793
+    *size_out = size;
008793
+    return SSL_TLSEXT_ERR_OK;
008793
+}
008793
+
008793
+#endif /* HAVE_TLS_NPN */
008793
+
008793
 #ifndef OPENSSL_NO_SRP
008793
 
008793
 int ssl_callback_SRPServerParams(SSL *ssl, int *ad, void *arg)
008793
--- httpd-2.4.6/modules/ssl/ssl_private.h.r1332643+
008793
+++ httpd-2.4.6/modules/ssl/ssl_private.h
008793
@@ -98,6 +98,8 @@
008793
 #include <openssl/x509_vfy.h>
008793
 #include <openssl/ocsp.h>
008793
 
008793
+#include "mod_ssl.h"
008793
+
008793
 /* Avoid tripping over an engine build installed globally and detected
008793
  * when the user points at an explicit non-engine flavor of OpenSSL
008793
  */
008793
@@ -139,6 +141,11 @@
008793
 #define HAVE_FIPS
008793
 #endif
008793
 
008793
+#if OPENSSL_VERSION_NUMBER >= 0x10001000L && !defined(OPENSSL_NO_NEXTPROTONEG) \
008793
+    && !defined(OPENSSL_NO_TLSEXT)
008793
+#define HAVE_TLS_NPN
008793
+#endif
008793
+
008793
 #if (OPENSSL_VERSION_NUMBER >= 0x10000000)
008793
 #define MODSSL_SSL_CIPHER_CONST const
008793
 #define MODSSL_SSL_METHOD_CONST const
008793
@@ -487,6 +494,12 @@ typedef struct {
008793
                      * connection */
008793
     } reneg_state;
008793
 
008793
+#ifdef HAVE_TLS_NPN
008793
+    /* Poor man's inter-module optional hooks for NPN. */
008793
+    apr_array_header_t *npn_advertfns; /* list of ssl_npn_advertise_protos callbacks */
008793
+    apr_array_header_t *npn_negofns; /* list of ssl_npn_proto_negotiated callbacks. */
008793
+#endif
008793
+
008793
     server_rec *server;
008793
 } SSLConnRec;
008793
 
008793
@@ -842,6 +855,7 @@ int          ssl_callback_ServerNameIndi
008793
 int         ssl_callback_SessionTicket(SSL *, unsigned char *, unsigned char *,
008793
                                        EVP_CIPHER_CTX *, HMAC_CTX *, int);
008793
 #endif
008793
+int ssl_callback_AdvertiseNextProtos(SSL *ssl, const unsigned char **data, unsigned int *len, void *arg);
008793
 
008793
 /**  Session Cache Support  */
008793
 void         ssl_scache_init(server_rec *, apr_pool_t *);