Changeset 564f33f in mod_gnutls


Ignore:
Timestamp:
Dec 17, 2018, 4:39:50 PM (4 years ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
asyncio, debian/master, main, master, proxy-ticket
Children:
c7710cf
Parents:
0378c22
Message:

Move SNI and ALPN setup for proxy connections to gnutls_proxy.c

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/gnutls_io.c

    r0378c22 r564f33f  
    2020#include "mod_gnutls.h"
    2121#include "gnutls_proxy.h"
    22 #include <apr_strings.h>
    2322
    2423#ifdef APLOG_USE_MODULE
     
    385384    }
    386385
    387     /* Enable SNI for proxy connections */
     386    /* Enable SNI and ALPN for proxy connections */
    388387    if (ctxt->is_proxy == GNUTLS_ENABLED_TRUE)
    389     {
    390         /* Get peer hostname from note left by mod_proxy */
    391         const char *peer_hostname =
    392             apr_table_get(ctxt->c->notes, PROXY_SNI_NOTE);
    393         /* Used only as target for apr_ipsubnet_create() */
    394         apr_ipsubnet_t *probe;
    395         /* Check if the note is present (!= NULL) and NOT an IP
    396          * address */
    397         if ((peer_hostname) != NULL
    398             && (apr_ipsubnet_create(&probe, peer_hostname, NULL, ctxt->c->pool)
    399                 != APR_SUCCESS))
    400         {
    401             ret = gnutls_server_name_set(ctxt->session, GNUTLS_NAME_DNS,
    402                                          peer_hostname, strlen(peer_hostname));
    403             if (ret != GNUTLS_E_SUCCESS)
    404                 ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, ctxt->c,
    405                               "Could not set SNI '%s' for proxy connection: "
    406                               "%s (%d)",
    407                               peer_hostname, gnutls_strerror(ret), ret);
    408         }
    409 
    410         const char *proxy_alpn =
    411             apr_table_get(ctxt->c->notes, PROXY_ALPN_NOTE);
    412         if (proxy_alpn != NULL)
    413         {
    414             // TODO: mod_ssl ssl_engine_io.c does some tokenization of
    415             // the input string, so it looks like the API allows
    416             // multiple protocols.
    417             gnutls_datum_t alpn_proto = {
    418                 .data = (unsigned char *) apr_pstrdup(ctxt->c->pool, proxy_alpn),
    419                 .size = strlen(proxy_alpn)
    420             };
    421             ap_log_cerror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, ctxt->c,
    422                           "%s: proxy module requests ALPN proto '%s', "
    423                           "length %" APR_SIZE_T_FMT ".",
    424                           __func__, proxy_alpn, strlen(proxy_alpn));
    425             ret = gnutls_alpn_set_protocols(ctxt->session,
    426                                             &alpn_proto,
    427                                             1 /* number of proposals */,
    428                                             0 /* flags */);
    429             if (ret != GNUTLS_E_SUCCESS)
    430                 ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, ctxt->c,
    431                               "Could not set ALPN proposal '%s' for proxy "
    432                               "connection: %s (%d)",
    433                               proxy_alpn, gnutls_strerror(ret), ret);
    434         }
    435     }
     388        mgs_set_proxy_handshake_ext(ctxt);
    436389
    437390tryagain:
  • src/gnutls_proxy.c

    r0378c22 r564f33f  
    1919#include "gnutls_util.h"
    2020
     21#include <apr_strings.h>
    2122#include <gnutls/gnutls.h>
    2223
     
    290291    return ret;
    291292}
     293
     294
     295
     296static void proxy_conn_set_sni(mgs_handle_t *ctxt)
     297{
     298    /* Get peer hostname from note left by mod_proxy */
     299    const char *peer_hostname =
     300        apr_table_get(ctxt->c->notes, PROXY_SNI_NOTE);
     301    /* Used only as target for apr_ipsubnet_create() */
     302    apr_ipsubnet_t *probe;
     303    /* Check if the note is present (!= NULL) and NOT an IP
     304     * address */
     305    if ((peer_hostname) != NULL
     306        && (apr_ipsubnet_create(&probe, peer_hostname, NULL, ctxt->c->pool)
     307            != APR_SUCCESS))
     308    {
     309        int ret = gnutls_server_name_set(ctxt->session, GNUTLS_NAME_DNS,
     310                                         peer_hostname, strlen(peer_hostname));
     311        if (ret != GNUTLS_E_SUCCESS)
     312            ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, ctxt->c,
     313                          "Could not set SNI '%s' for proxy connection: "
     314                          "%s (%d)",
     315                          peer_hostname, gnutls_strerror(ret), ret);
     316    }
     317}
     318
     319
     320
     321static void proxy_conn_set_alpn(mgs_handle_t *ctxt)
     322{
     323    const char *proxy_alpn =
     324        apr_table_get(ctxt->c->notes, PROXY_ALPN_NOTE);
     325    if (proxy_alpn != NULL)
     326    {
     327        // TODO: mod_ssl ssl_engine_io.c does some tokenization of
     328        // the input string, so it looks like the API allows
     329        // multiple protocols.
     330        gnutls_datum_t alpn_proto = {
     331            .data = (unsigned char *) apr_pstrdup(ctxt->c->pool, proxy_alpn),
     332            .size = strlen(proxy_alpn)
     333        };
     334        ap_log_cerror(APLOG_MARK, APLOG_DEBUG, APR_SUCCESS, ctxt->c,
     335                      "%s: proxy module requests ALPN proto '%s', "
     336                      "length %" APR_SIZE_T_FMT ".",
     337                      __func__, proxy_alpn, strlen(proxy_alpn));
     338        int ret = gnutls_alpn_set_protocols(ctxt->session,
     339                                            &alpn_proto,
     340                                            1 /* number of proposals */,
     341                                            0 /* flags */);
     342        if (ret != GNUTLS_E_SUCCESS)
     343            ap_log_cerror(APLOG_MARK, APLOG_ERR, ret, ctxt->c,
     344                          "Could not set ALPN proposal '%s' for proxy "
     345                          "connection: %s (%d)",
     346                          proxy_alpn, gnutls_strerror(ret), ret);
     347    }
     348}
     349
     350
     351
     352void mgs_set_proxy_handshake_ext(mgs_handle_t *ctxt)
     353{
     354    proxy_conn_set_sni(ctxt);
     355    proxy_conn_set_alpn(ctxt);
     356}
  • src/gnutls_proxy.h

    r0378c22 r564f33f  
    3636    __attribute__((nonnull));
    3737
     38/**
     39 * Configure extensions for the TLS handshake on proxy connections,
     40 * currently SNI and ALPN.
     41 */
     42void mgs_set_proxy_handshake_ext(mgs_handle_t * ctxt);
     43
    3844#endif /* __MOD_GNUTLS_PROXY_H__ */
Note: See TracChangeset for help on using the changeset viewer.