source: mod_gnutls/src/mod_gnutls.c @ a784735

debian/masterdebian/stretch-backportsupstream
Last change on this file since a784735 was 4d4a406, checked in by Thomas Klute <thomas2.klute@…>, 3 years ago

New config option: GnuTLSOCSPStapling

This flag option enables/disables OCSP stapling, instead of enabling
stapling if a response file is set.

  • Property mode set to 100644
File size: 9.9 KB
RevLine 
[fcb122d]1/**
2 *  Copyright 2004-2005 Paul Querna
[e021722]3 *  Copyright 2008, 2014 Nikos Mavrogiannopoulos
[e183628]4 *  Copyright 2011 Dash Shendy
[8913410]5 *  Copyright 2015-2016 Thomas Klute
[9706fc2]6 *
7 *  Licensed under the Apache License, Version 2.0 (the "License");
8 *  you may not use this file except in compliance with the License.
9 *  You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 *  Unless required by applicable law or agreed to in writing, software
14 *  distributed under the License is distributed on an "AS IS" BASIS,
15 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 *  See the License for the specific language governing permissions and
17 *  limitations under the License.
18 *
19 */
20
[7e2b223]21#include "mod_gnutls.h"
[94cb972]22#include "gnutls_ocsp.h"
[9706fc2]23
[e8acf05]24#ifdef APLOG_USE_MODULE
25APLOG_USE_MODULE(gnutls);
26#endif
[671b64f]27
[e8acf05]28static void gnutls_hooks(apr_pool_t * p __attribute__((unused)))
29{
[33826c5]30    /* Try Run Post-Config Hook After mod_proxy */
31    static const char * const aszPre[] = { "mod_proxy.c", NULL };
[accbb83]32    ap_hook_post_config(mgs_hook_post_config, aszPre, NULL,
33                        APR_HOOK_REALLY_LAST);
[33826c5]34    /* HTTP Scheme Hook */
35    ap_hook_http_scheme(mgs_hook_http_scheme, NULL, NULL, APR_HOOK_MIDDLE);
36    /* Default Port Hook */
[accbb83]37    ap_hook_default_port(mgs_hook_default_port, NULL, NULL, APR_HOOK_MIDDLE);
[33826c5]38    /* Pre-Connect Hook */
[accbb83]39    ap_hook_pre_connection(mgs_hook_pre_connection, NULL, NULL,
40                           APR_HOOK_MIDDLE);
[33826c5]41    /* Pre-Config Hook */
[e183628]42    ap_hook_pre_config(mgs_hook_pre_config, NULL, NULL,
[accbb83]43                       APR_HOOK_MIDDLE);
[33826c5]44    /* Child-Init Hook */
45    ap_hook_child_init(mgs_hook_child_init, NULL, NULL,
[accbb83]46                       APR_HOOK_MIDDLE);
[33826c5]47    /* Authentication Hook */
[e183628]48    ap_hook_access_checker(mgs_hook_authz, NULL, NULL,
[accbb83]49                           APR_HOOK_REALLY_FIRST);
[33826c5]50    /* Fixups Hook */
[e183628]51    ap_hook_fixups(mgs_hook_fixups, NULL, NULL, APR_HOOK_REALLY_FIRST);
[e02dd8c]52
[e183628]53    /* TODO: HTTP Upgrade Filter */
[671b64f]54    /* ap_register_output_filter ("UPGRADE_FILTER",
[e183628]55     *          ssl_io_filter_Upgrade, NULL, AP_FTYPE_PROTOCOL + 5);
56     */
[e02dd8c]57
[33826c5]58    /* Input Filter */
[accbb83]59    ap_register_input_filter(GNUTLS_INPUT_FILTER_NAME, mgs_filter_input,
60                             NULL, AP_FTYPE_CONNECTION + 5);
[33826c5]61    /* Output Filter */
[accbb83]62    ap_register_output_filter(GNUTLS_OUTPUT_FILTER_NAME, mgs_filter_output,
63                              NULL, AP_FTYPE_CONNECTION + 5);
[671b64f]64
[33826c5]65    /* mod_proxy calls these functions */
66    APR_REGISTER_OPTIONAL_FN(ssl_proxy_enable);
67    APR_REGISTER_OPTIONAL_FN(ssl_engine_disable);
[8ac7c0d]68
69    /* mod_rewrite calls this function to detect HTTPS */
70    APR_REGISTER_OPTIONAL_FN(ssl_is_https);
[33826c5]71}
72
[8ac7c0d]73
74
75/*
76 * mod_rewrite calls this function to fill %{HTTPS}. A non-zero return
77 * value means that HTTPS is in use.
78 */
[accbb83]79int ssl_is_https(conn_rec *c)
80{
[671b64f]81    mgs_srvconf_rec *sc = (mgs_srvconf_rec *)
[accbb83]82        ap_get_module_config(c->base_server->module_config, &gnutls_module);
[8ac7c0d]83    mgs_handle_t *ctxt = (mgs_handle_t *)
84        ap_get_module_config(c->conn_config, &gnutls_module);
85
86    if(sc->enabled == GNUTLS_ENABLED_FALSE
87       || ctxt == NULL
88       || ctxt->enabled == GNUTLS_ENABLED_FALSE)
89    {
[33826c5]90        /* SSL/TLS Disabled or Plain HTTP Connection Detected */
91        return 0;
92    }
93    /* Connection is Using SSL/TLS */
94    return 1;
95}
96
[8ac7c0d]97
98
[e8acf05]99int ssl_engine_disable(conn_rec *c)
100{
[671b64f]101    mgs_srvconf_rec *sc = (mgs_srvconf_rec *)
[e8acf05]102        ap_get_module_config(c->base_server->module_config, &gnutls_module);
[33826c5]103    if(sc->enabled == GNUTLS_ENABLED_FALSE) {
104        return 1;
[671b64f]105    }
[e8acf05]106
107    /* disable TLS for this connection */
[accbb83]108    mgs_handle_t *ctxt = (mgs_handle_t *)
109        ap_get_module_config(c->conn_config, &gnutls_module);
[e8acf05]110    if (ctxt == NULL)
111    {
112        ctxt = apr_pcalloc(c->pool, sizeof (*ctxt));
113        ap_set_module_config(c->conn_config, &gnutls_module, ctxt);
114    }
115    ctxt->enabled = GNUTLS_ENABLED_FALSE;
[c1ef069]116    ctxt->is_proxy = GNUTLS_ENABLED_TRUE;
[e8acf05]117
[3d361b8]118    if (c->input_filters)
119        ap_remove_input_filter(c->input_filters);
120    if (c->output_filters)
121        ap_remove_output_filter(c->output_filters);
[c782c1f]122
[33826c5]123    return 1;
124}
125
[accbb83]126int ssl_proxy_enable(conn_rec *c)
127{
[07d548d]128    /* check if TLS proxy support is enabled */
[671b64f]129    mgs_srvconf_rec *sc = (mgs_srvconf_rec *)
[accbb83]130        ap_get_module_config(c->base_server->module_config, &gnutls_module);
[07d548d]131    if (sc->proxy_enabled != GNUTLS_ENABLED_TRUE)
132    {
133        ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c,
134                      "%s: mod_proxy requested TLS proxy, but not enabled "
135                      "for %s", __func__, sc->cert_cn);
136        return 0;
137    }
138
139    /* enable TLS for this connection */
140    mgs_handle_t *ctxt = (mgs_handle_t *)
141        ap_get_module_config(c->conn_config, &gnutls_module);
142    if (ctxt == NULL)
143    {
144        ctxt = apr_pcalloc(c->pool, sizeof (*ctxt));
145        ap_set_module_config(c->conn_config, &gnutls_module, ctxt);
146    }
147    ctxt->enabled = GNUTLS_ENABLED_TRUE;
[c1ef069]148    ctxt->is_proxy = GNUTLS_ENABLED_TRUE;
[37f8282]149    return 1;
[9706fc2]150}
151
[46b85d8]152static const command_rec mgs_config_cmds[] = {
[176047e]153    AP_INIT_FLAG("GnuTLSProxyEngine", mgs_set_proxy_engine,
[33826c5]154    NULL,
155    RSRC_CONF | OR_AUTHCFG,
[176047e]156    "Enable TLS Proxy Engine"),
[87f1ed2]157    AP_INIT_TAKE1("GnuTLSP11Module", mgs_set_p11_module,
158    NULL,
159    RSRC_CONF,
[f21d2a6]160    "Load this specific PKCS #11 provider library"),
[031acac]161    AP_INIT_RAW_ARGS("GnuTLSPIN", mgs_set_pin,
162    NULL,
163    RSRC_CONF,
164    "The PIN to use in case of encrypted keys or PKCS #11 tokens."),
165    AP_INIT_RAW_ARGS("GnuTLSSRKPIN", mgs_set_srk_pin,
166    NULL,
167    RSRC_CONF,
168    "The SRK PIN to use in case of TPM keys."),
[e183628]169    AP_INIT_TAKE1("GnuTLSClientVerify", mgs_set_client_verify,
170    NULL,
171    RSRC_CONF | OR_AUTHCFG,
172    "Set Verification Requirements of the Client Certificate"),
[cf2b905]173    AP_INIT_TAKE1("GnuTLSClientVerifyMethod", mgs_set_client_verify_method,
174    NULL,
175    RSRC_CONF,
176    "Set Verification Method of the Client Certificate"),
[e183628]177    AP_INIT_TAKE1("GnuTLSClientCAFile", mgs_set_client_ca_file,
178    NULL,
179    RSRC_CONF,
180    "Set the CA File to verify Client Certificates"),
181    AP_INIT_TAKE1("GnuTLSX509CAFile", mgs_set_client_ca_file,
182    NULL,
183    RSRC_CONF,
184    "Set the CA File to verify Client Certificates"),
185    AP_INIT_TAKE1("GnuTLSPGPKeyringFile", mgs_set_keyring_file,
186    NULL,
187    RSRC_CONF,
188    "Set the Keyring File to verify Client Certificates"),
189    AP_INIT_TAKE1("GnuTLSDHFile", mgs_set_dh_file,
190    NULL,
191    RSRC_CONF,
192    "Set the file to read Diffie Hellman parameters from"),
193    AP_INIT_TAKE1("GnuTLSCertificateFile", mgs_set_cert_file,
194    NULL,
195    RSRC_CONF,
[88df24d]196    "TLS Server X509 Certificate file"),
[e183628]197    AP_INIT_TAKE1("GnuTLSKeyFile", mgs_set_key_file,
198    NULL,
199    RSRC_CONF,
[88df24d]200    "TLS Server X509 Private Key file"),
[e183628]201    AP_INIT_TAKE1("GnuTLSX509CertificateFile", mgs_set_cert_file,
202    NULL,
203    RSRC_CONF,
[88df24d]204    "TLS Server X509 Certificate file"),
[e183628]205    AP_INIT_TAKE1("GnuTLSX509KeyFile", mgs_set_key_file,
206    NULL,
207    RSRC_CONF,
[88df24d]208    "TLS Server X509 Private Key file"),
[e183628]209    AP_INIT_TAKE1("GnuTLSPGPCertificateFile", mgs_set_pgpcert_file,
210    NULL,
211    RSRC_CONF,
[88df24d]212    "TLS Server PGP Certificate file"),
[e183628]213    AP_INIT_TAKE1("GnuTLSPGPKeyFile", mgs_set_pgpkey_file,
214    NULL,
215    RSRC_CONF,
[88df24d]216    "TLS Server PGP Private key file"),
[787dab7]217#ifdef ENABLE_SRP
[e183628]218    AP_INIT_TAKE1("GnuTLSSRPPasswdFile", mgs_set_srp_tpasswd_file,
219    NULL,
220    RSRC_CONF,
[88df24d]221    "TLS Server SRP Password Conf file"),
[e183628]222    AP_INIT_TAKE1("GnuTLSSRPPasswdConfFile",
223    mgs_set_srp_tpasswd_conf_file,
224    NULL,
225    RSRC_CONF,
[88df24d]226    "TLS Server SRP Parameters file"),
[787dab7]227#endif
[70a1e5a]228    AP_INIT_TAKE1("GnuTLSCacheTimeout", mgs_set_timeout,
[e183628]229    NULL,
230    RSRC_CONF,
231    "Cache Timeout"),
232    AP_INIT_TAKE12("GnuTLSCache", mgs_set_cache,
233    NULL,
234    RSRC_CONF,
235    "Cache Configuration"),
[176047e]236    AP_INIT_FLAG("GnuTLSSessionTickets", mgs_set_tickets,
[e183628]237    NULL,
238    RSRC_CONF,
239    "Session Tickets Configuration"),
240    AP_INIT_RAW_ARGS("GnuTLSPriorities", mgs_set_priorities,
241    NULL,
242    RSRC_CONF,
243    "The priorities to enable (ciphers, Key exchange, macs, compression)."),
[176047e]244    AP_INIT_FLAG("GnuTLSEnable", mgs_set_enabled,
[e183628]245    NULL,
246    RSRC_CONF,
247    "Whether this server has GnuTLS Enabled. Default: Off"),
[7d1ab49]248    AP_INIT_TAKE1("GnuTLSExportCertificates",
[2aaf4f5]249    mgs_set_export_certificates_size,
[7d1ab49]250    NULL,
251    RSRC_CONF,
[2aaf4f5]252    "Max size to export PEM encoded certificates to CGIs (or off to disable). Default: off"),
[0de1839]253    AP_INIT_TAKE1("GnuTLSProxyKeyFile", mgs_store_cred_path,
254    NULL,
255    RSRC_CONF,
256    "X509 client private file for proxy connections"),
257    AP_INIT_TAKE1("GnuTLSProxyCertificateFile", mgs_store_cred_path,
258    NULL,
259    RSRC_CONF,
260    "X509 client certificate file for proxy connections"),
261    AP_INIT_TAKE1("GnuTLSProxyCAFile", mgs_store_cred_path,
262    NULL,
263    RSRC_CONF,
264    "X509 trusted CA file for proxy connections"),
[809c422]265    AP_INIT_TAKE1("GnuTLSProxyCRLFile", mgs_store_cred_path,
266    NULL,
267    RSRC_CONF,
268    "X509 CRL file for proxy connections"),
[f030883]269    AP_INIT_RAW_ARGS("GnuTLSProxyPriorities", mgs_set_priorities,
270    NULL,
271    RSRC_CONF,
272    "The priorities to enable for proxy connections (ciphers, key exchange, "
273    "MACs, compression)."),
[4d4a406]274    AP_INIT_FLAG("GnuTLSOCSPStapling", mgs_ocsp_stapling_enable,
275                 NULL,
276                 RSRC_CONF,
277                 "EXPERIMENTAL: Enable OCSP stapling"),
[94cb972]278    AP_INIT_TAKE1("GnuTLSOCSPResponseFile", mgs_store_ocsp_response_path,
279    NULL,
280    RSRC_CONF,
281    "EXPERIMENTAL: OCSP response for stapling (must be updated externally)"),
[70a1e5a]282    AP_INIT_TAKE1("GnuTLSOCSPGraceTime", mgs_set_timeout,
283    NULL,
284    RSRC_CONF,
285    "EXPERIMENTAL: Replace cached OCSP responses this many seconds before "
286    "they expire"),
[15b22cb]287#ifdef __clang__
288    /* Workaround for this clang bug:
289     * https://llvm.org/bugs/show_bug.cgi?id=21689 */
290    {},
291#else
[7d1ab49]292    { NULL },
[15b22cb]293#endif
[46b85d8]294};
[9706fc2]295
296module AP_MODULE_DECLARE_DATA gnutls_module = {
[e183628]297    STANDARD20_MODULE_STUFF,
[2d0f6cf]298    .create_dir_config = mgs_config_dir_create,
299    .merge_dir_config = mgs_config_dir_merge,
300    .create_server_config = mgs_config_server_create,
[040387c]301    .merge_server_config = mgs_config_server_merge,
[2d0f6cf]302    .cmds = mgs_config_cmds,
303    .register_hooks = gnutls_hooks
[9706fc2]304};
Note: See TracBrowser for help on using the repository browser.