source: mod_gnutls/src/mod_gnutls.c @ 3d361b8

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

Check if filters exist before removing them in ssl_engine_disable

Trying to remove filters that are NULL leads to a segfault in the worker
thread. Check if c->input_filters and c->output_filters are defined
before removing and remove only if set.

Also, output filters should be removed with the dedicated function.

  • Property mode set to 100644
File size: 6.7 KB
Line 
1/**
2 *  Copyright 2004-2005 Paul Querna
3 *  Copyright 2008 Nikos Mavrogiannopoulos
4 *  Copyright 2011 Dash Shendy
5 *
6 *  Licensed under the Apache License, Version 2.0 (the "License");
7 *  you may not use this file except in compliance with the License.
8 *  You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *  Unless required by applicable law or agreed to in writing, software
13 *  distributed under the License is distributed on an "AS IS" BASIS,
14 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *  See the License for the specific language governing permissions and
16 *  limitations under the License.
17 *
18 */
19
20#include "mod_gnutls.h"
21
22static void gnutls_hooks(apr_pool_t * p __attribute__((unused))) {
23
24    /* Try Run Post-Config Hook After mod_proxy */
25    static const char * const aszPre[] = { "mod_proxy.c", NULL };
26    ap_hook_post_config(mgs_hook_post_config, aszPre, NULL,APR_HOOK_REALLY_LAST);
27    /* HTTP Scheme Hook */
28#if USING_2_1_RECENT
29    ap_hook_http_scheme(mgs_hook_http_scheme, NULL, NULL, APR_HOOK_MIDDLE);
30#else
31    ap_hook_http_method(mgs_hook_http_scheme, NULL, NULL, APR_HOOK_MIDDLE);
32#endif
33    /* Default Port Hook */
34    ap_hook_default_port(mgs_hook_default_port,  NULL,NULL, APR_HOOK_MIDDLE);
35    /* Pre-Connect Hook */
36    ap_hook_pre_connection(mgs_hook_pre_connection, NULL, NULL, APR_HOOK_MIDDLE);
37    /* Pre-Config Hook */
38    ap_hook_pre_config(mgs_hook_pre_config, NULL, NULL,
39            APR_HOOK_MIDDLE);
40    /* Child-Init Hook */
41    ap_hook_child_init(mgs_hook_child_init, NULL, NULL,
42            APR_HOOK_MIDDLE);
43    /* Authentication Hook */
44    ap_hook_access_checker(mgs_hook_authz, NULL, NULL,
45            APR_HOOK_REALLY_FIRST);
46    /* Fixups Hook */
47    ap_hook_fixups(mgs_hook_fixups, NULL, NULL, APR_HOOK_REALLY_FIRST);
48
49    /* TODO: HTTP Upgrade Filter */
50    /* ap_register_output_filter ("UPGRADE_FILTER",
51     *          ssl_io_filter_Upgrade, NULL, AP_FTYPE_PROTOCOL + 5);
52     */
53
54    /* Input Filter */
55    ap_register_input_filter(GNUTLS_INPUT_FILTER_NAME,
56            mgs_filter_input, NULL,AP_FTYPE_CONNECTION + 5);
57    /* Output Filter */
58    ap_register_output_filter(GNUTLS_OUTPUT_FILTER_NAME,
59            mgs_filter_output, NULL,AP_FTYPE_CONNECTION + 5);
60
61    /* mod_proxy calls these functions */
62    APR_REGISTER_OPTIONAL_FN(ssl_proxy_enable);
63    APR_REGISTER_OPTIONAL_FN(ssl_engine_disable);
64}
65
66int ssl_is_https(conn_rec *c) {
67    mgs_srvconf_rec *sc = (mgs_srvconf_rec *)
68            ap_get_module_config(c->base_server->module_config, &gnutls_module);
69    if(sc->enabled == 0 || sc->non_ssl_request == 1) {
70        /* SSL/TLS Disabled or Plain HTTP Connection Detected */
71        return 0;
72    }
73    /* Connection is Using SSL/TLS */
74    return 1;
75}
76
77int ssl_engine_disable(conn_rec *c) {
78    mgs_srvconf_rec *sc = (mgs_srvconf_rec *)
79            ap_get_module_config(c->base_server->module_config, &gnutls_module);
80    if(sc->enabled == GNUTLS_ENABLED_FALSE) {
81        return 1;
82    }
83    if (c->input_filters)
84        ap_remove_input_filter(c->input_filters);
85    if (c->output_filters)
86        ap_remove_output_filter(c->output_filters);
87    mgs_cleanup_pre_config(c->pool);
88    sc->enabled = GNUTLS_ENABLED_FALSE;
89    return 1;
90}
91
92int ssl_proxy_enable(conn_rec *c) {
93    mgs_srvconf_rec *sc = (mgs_srvconf_rec *)
94            ap_get_module_config(c->base_server->module_config, &gnutls_module);
95    sc->proxy_enabled = GNUTLS_ENABLED_TRUE;
96    sc->enabled = GNUTLS_ENABLED_FALSE;
97    return 1;
98}
99
100static const command_rec mgs_config_cmds[] = {
101    AP_INIT_TAKE1("SSLProxyEngine", mgs_set_proxy_engine,
102    NULL,
103    RSRC_CONF | OR_AUTHCFG,
104    "Enable SSL Proxy Engine"),
105    AP_INIT_TAKE1("GnuTLSClientVerify", mgs_set_client_verify,
106    NULL,
107    RSRC_CONF | OR_AUTHCFG,
108    "Set Verification Requirements of the Client Certificate"),
109    AP_INIT_TAKE1("GnuTLSClientVerifyMethod", mgs_set_client_verify_method,
110    NULL,
111    RSRC_CONF,
112    "Set Verification Method of the Client Certificate"),
113    AP_INIT_TAKE1("GnuTLSClientCAFile", mgs_set_client_ca_file,
114    NULL,
115    RSRC_CONF,
116    "Set the CA File to verify Client Certificates"),
117    AP_INIT_TAKE1("GnuTLSX509CAFile", mgs_set_client_ca_file,
118    NULL,
119    RSRC_CONF,
120    "Set the CA File to verify Client Certificates"),
121    AP_INIT_TAKE1("GnuTLSPGPKeyringFile", mgs_set_keyring_file,
122    NULL,
123    RSRC_CONF,
124    "Set the Keyring File to verify Client Certificates"),
125    AP_INIT_TAKE1("GnuTLSDHFile", mgs_set_dh_file,
126    NULL,
127    RSRC_CONF,
128    "Set the file to read Diffie Hellman parameters from"),
129    AP_INIT_TAKE1("GnuTLSCertificateFile", mgs_set_cert_file,
130    NULL,
131    RSRC_CONF,
132    "SSL Server X509 Certificate file"),
133    AP_INIT_TAKE1("GnuTLSKeyFile", mgs_set_key_file,
134    NULL,
135    RSRC_CONF,
136    "SSL Server X509 Private Key file"),
137    AP_INIT_TAKE1("GnuTLSX509CertificateFile", mgs_set_cert_file,
138    NULL,
139    RSRC_CONF,
140    "SSL Server X509 Certificate file"),
141    AP_INIT_TAKE1("GnuTLSX509KeyFile", mgs_set_key_file,
142    NULL,
143    RSRC_CONF,
144    "SSL Server X509 Private Key file"),
145    AP_INIT_TAKE1("GnuTLSPGPCertificateFile", mgs_set_pgpcert_file,
146    NULL,
147    RSRC_CONF,
148    "SSL Server PGP Certificate file"),
149    AP_INIT_TAKE1("GnuTLSPGPKeyFile", mgs_set_pgpkey_file,
150    NULL,
151    RSRC_CONF,
152    "SSL Server PGP Private key file"),
153#ifdef ENABLE_SRP
154    AP_INIT_TAKE1("GnuTLSSRPPasswdFile", mgs_set_srp_tpasswd_file,
155    NULL,
156    RSRC_CONF,
157    "SSL Server SRP Password Conf file"),
158    AP_INIT_TAKE1("GnuTLSSRPPasswdConfFile",
159    mgs_set_srp_tpasswd_conf_file,
160    NULL,
161    RSRC_CONF,
162    "SSL Server SRP Parameters file"),
163#endif
164    AP_INIT_TAKE1("GnuTLSCacheTimeout", mgs_set_cache_timeout,
165    NULL,
166    RSRC_CONF,
167    "Cache Timeout"),
168    AP_INIT_TAKE12("GnuTLSCache", mgs_set_cache,
169    NULL,
170    RSRC_CONF,
171    "Cache Configuration"),
172    AP_INIT_TAKE1("GnuTLSSessionTickets", mgs_set_tickets,
173    NULL,
174    RSRC_CONF,
175    "Session Tickets Configuration"),
176    AP_INIT_RAW_ARGS("GnuTLSPriorities", mgs_set_priorities,
177    NULL,
178    RSRC_CONF,
179    "The priorities to enable (ciphers, Key exchange, macs, compression)."),
180    AP_INIT_TAKE1("GnuTLSEnable", mgs_set_enabled,
181    NULL,
182    RSRC_CONF,
183    "Whether this server has GnuTLS Enabled. Default: Off"),
184    AP_INIT_TAKE1("GnuTLSExportCertificates",
185    mgs_set_export_certificates_size,
186    NULL,
187    RSRC_CONF,
188    "Max size to export PEM encoded certificates to CGIs (or off to disable). Default: off"),
189    { NULL },
190};
191
192module AP_MODULE_DECLARE_DATA gnutls_module = {
193    STANDARD20_MODULE_STUFF,
194    .create_dir_config = mgs_config_dir_create,
195    .merge_dir_config = mgs_config_dir_merge,
196    .create_server_config = mgs_config_server_create,
197    .merge_server_config = mgs_config_server_merge,
198    .cmds = mgs_config_cmds,
199    .register_hooks = gnutls_hooks
200};
Note: See TracBrowser for help on using the repository browser.