source: mod_gnutls/src/mod_gnutls.c @ e021722

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

Update copyright headers for Nikos Mavrogiannopoulos' PKCS #11 patch

This affects source files changed in commit
031acac9c6541034777f8917633164b51f6bd10a.

  • Property mode set to 100644
File size: 9.0 KB
Line 
1/**
2 *  Copyright 2004-2005 Paul Querna
3 *  Copyright 2008, 2014 Nikos Mavrogiannopoulos
4 *  Copyright 2011 Dash Shendy
5 *  Copyright 2015 Thomas Klute
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
21#include "mod_gnutls.h"
22
23#ifdef APLOG_USE_MODULE
24APLOG_USE_MODULE(gnutls);
25#endif
26
27static void gnutls_hooks(apr_pool_t * p __attribute__((unused)))
28{
29    /* Try Run Post-Config Hook After mod_proxy */
30    static const char * const aszPre[] = { "mod_proxy.c", NULL };
31    ap_hook_post_config(mgs_hook_post_config, aszPre, NULL,
32                        APR_HOOK_REALLY_LAST);
33    /* HTTP Scheme Hook */
34#if USING_2_1_RECENT
35    ap_hook_http_scheme(mgs_hook_http_scheme, NULL, NULL, APR_HOOK_MIDDLE);
36#else
37    ap_hook_http_method(mgs_hook_http_scheme, NULL, NULL, APR_HOOK_MIDDLE);
38#endif
39    /* Default Port Hook */
40    ap_hook_default_port(mgs_hook_default_port, NULL, NULL, APR_HOOK_MIDDLE);
41    /* Pre-Connect Hook */
42    ap_hook_pre_connection(mgs_hook_pre_connection, NULL, NULL,
43                           APR_HOOK_MIDDLE);
44    /* Pre-Config Hook */
45    ap_hook_pre_config(mgs_hook_pre_config, NULL, NULL,
46                       APR_HOOK_MIDDLE);
47    /* Child-Init Hook */
48    ap_hook_child_init(mgs_hook_child_init, NULL, NULL,
49                       APR_HOOK_MIDDLE);
50    /* Authentication Hook */
51    ap_hook_access_checker(mgs_hook_authz, NULL, NULL,
52                           APR_HOOK_REALLY_FIRST);
53    /* Fixups Hook */
54    ap_hook_fixups(mgs_hook_fixups, NULL, NULL, APR_HOOK_REALLY_FIRST);
55
56    /* TODO: HTTP Upgrade Filter */
57    /* ap_register_output_filter ("UPGRADE_FILTER",
58     *          ssl_io_filter_Upgrade, NULL, AP_FTYPE_PROTOCOL + 5);
59     */
60
61    /* Input Filter */
62    ap_register_input_filter(GNUTLS_INPUT_FILTER_NAME, mgs_filter_input,
63                             NULL, AP_FTYPE_CONNECTION + 5);
64    /* Output Filter */
65    ap_register_output_filter(GNUTLS_OUTPUT_FILTER_NAME, mgs_filter_output,
66                              NULL, AP_FTYPE_CONNECTION + 5);
67
68    /* mod_proxy calls these functions */
69    APR_REGISTER_OPTIONAL_FN(ssl_proxy_enable);
70    APR_REGISTER_OPTIONAL_FN(ssl_engine_disable);
71}
72
73int ssl_is_https(conn_rec *c)
74{
75    mgs_srvconf_rec *sc = (mgs_srvconf_rec *)
76        ap_get_module_config(c->base_server->module_config, &gnutls_module);
77    if(sc->enabled == 0 || sc->non_ssl_request == 1) {
78        /* SSL/TLS Disabled or Plain HTTP Connection Detected */
79        return 0;
80    }
81    /* Connection is Using SSL/TLS */
82    return 1;
83}
84
85int ssl_engine_disable(conn_rec *c)
86{
87    mgs_srvconf_rec *sc = (mgs_srvconf_rec *)
88        ap_get_module_config(c->base_server->module_config, &gnutls_module);
89    if(sc->enabled == GNUTLS_ENABLED_FALSE) {
90        return 1;
91    }
92
93    /* disable TLS for this connection */
94    mgs_handle_t *ctxt = (mgs_handle_t *)
95        ap_get_module_config(c->conn_config, &gnutls_module);
96    if (ctxt == NULL)
97    {
98        ctxt = apr_pcalloc(c->pool, sizeof (*ctxt));
99        ap_set_module_config(c->conn_config, &gnutls_module, ctxt);
100    }
101    ctxt->enabled = GNUTLS_ENABLED_FALSE;
102    ctxt->is_proxy = GNUTLS_ENABLED_TRUE;
103
104    if (c->input_filters)
105        ap_remove_input_filter(c->input_filters);
106    if (c->output_filters)
107        ap_remove_output_filter(c->output_filters);
108
109    return 1;
110}
111
112int ssl_proxy_enable(conn_rec *c)
113{
114    /* check if TLS proxy support is enabled */
115    mgs_srvconf_rec *sc = (mgs_srvconf_rec *)
116        ap_get_module_config(c->base_server->module_config, &gnutls_module);
117    if (sc->proxy_enabled != GNUTLS_ENABLED_TRUE)
118    {
119        ap_log_cerror(APLOG_MARK, APLOG_ERR, 0, c,
120                      "%s: mod_proxy requested TLS proxy, but not enabled "
121                      "for %s", __func__, sc->cert_cn);
122        return 0;
123    }
124
125    /* enable TLS for this connection */
126    mgs_handle_t *ctxt = (mgs_handle_t *)
127        ap_get_module_config(c->conn_config, &gnutls_module);
128    if (ctxt == NULL)
129    {
130        ctxt = apr_pcalloc(c->pool, sizeof (*ctxt));
131        ap_set_module_config(c->conn_config, &gnutls_module, ctxt);
132    }
133    ctxt->enabled = GNUTLS_ENABLED_TRUE;
134    ctxt->is_proxy = GNUTLS_ENABLED_TRUE;
135    return 1;
136}
137
138static const command_rec mgs_config_cmds[] = {
139    AP_INIT_TAKE1("GnuTLSProxyEngine", mgs_set_proxy_engine,
140    NULL,
141    RSRC_CONF | OR_AUTHCFG,
142    "Enable SSL Proxy Engine"),
143    AP_INIT_TAKE1("GnuTLSP11Module", mgs_set_p11_module,
144    NULL,
145    RSRC_CONF,
146    "Load this additional PKCS #11 provider library"),
147    AP_INIT_RAW_ARGS("GnuTLSPIN", mgs_set_pin,
148    NULL,
149    RSRC_CONF,
150    "The PIN to use in case of encrypted keys or PKCS #11 tokens."),
151    AP_INIT_RAW_ARGS("GnuTLSSRKPIN", mgs_set_srk_pin,
152    NULL,
153    RSRC_CONF,
154    "The SRK PIN to use in case of TPM keys."),
155    AP_INIT_TAKE1("GnuTLSClientVerify", mgs_set_client_verify,
156    NULL,
157    RSRC_CONF | OR_AUTHCFG,
158    "Set Verification Requirements of the Client Certificate"),
159    AP_INIT_TAKE1("GnuTLSClientVerifyMethod", mgs_set_client_verify_method,
160    NULL,
161    RSRC_CONF,
162    "Set Verification Method of the Client Certificate"),
163    AP_INIT_TAKE1("GnuTLSClientCAFile", mgs_set_client_ca_file,
164    NULL,
165    RSRC_CONF,
166    "Set the CA File to verify Client Certificates"),
167    AP_INIT_TAKE1("GnuTLSX509CAFile", mgs_set_client_ca_file,
168    NULL,
169    RSRC_CONF,
170    "Set the CA File to verify Client Certificates"),
171    AP_INIT_TAKE1("GnuTLSPGPKeyringFile", mgs_set_keyring_file,
172    NULL,
173    RSRC_CONF,
174    "Set the Keyring File to verify Client Certificates"),
175    AP_INIT_TAKE1("GnuTLSDHFile", mgs_set_dh_file,
176    NULL,
177    RSRC_CONF,
178    "Set the file to read Diffie Hellman parameters from"),
179    AP_INIT_TAKE1("GnuTLSCertificateFile", mgs_set_cert_file,
180    NULL,
181    RSRC_CONF,
182    "SSL Server X509 Certificate file"),
183    AP_INIT_TAKE1("GnuTLSKeyFile", mgs_set_key_file,
184    NULL,
185    RSRC_CONF,
186    "SSL Server X509 Private Key file"),
187    AP_INIT_TAKE1("GnuTLSX509CertificateFile", mgs_set_cert_file,
188    NULL,
189    RSRC_CONF,
190    "SSL Server X509 Certificate file"),
191    AP_INIT_TAKE1("GnuTLSX509KeyFile", mgs_set_key_file,
192    NULL,
193    RSRC_CONF,
194    "SSL Server X509 Private Key file"),
195    AP_INIT_TAKE1("GnuTLSPGPCertificateFile", mgs_set_pgpcert_file,
196    NULL,
197    RSRC_CONF,
198    "SSL Server PGP Certificate file"),
199    AP_INIT_TAKE1("GnuTLSPGPKeyFile", mgs_set_pgpkey_file,
200    NULL,
201    RSRC_CONF,
202    "SSL Server PGP Private key file"),
203#ifdef ENABLE_SRP
204    AP_INIT_TAKE1("GnuTLSSRPPasswdFile", mgs_set_srp_tpasswd_file,
205    NULL,
206    RSRC_CONF,
207    "SSL Server SRP Password Conf file"),
208    AP_INIT_TAKE1("GnuTLSSRPPasswdConfFile",
209    mgs_set_srp_tpasswd_conf_file,
210    NULL,
211    RSRC_CONF,
212    "SSL Server SRP Parameters file"),
213#endif
214    AP_INIT_TAKE1("GnuTLSCacheTimeout", mgs_set_cache_timeout,
215    NULL,
216    RSRC_CONF,
217    "Cache Timeout"),
218    AP_INIT_TAKE12("GnuTLSCache", mgs_set_cache,
219    NULL,
220    RSRC_CONF,
221    "Cache Configuration"),
222    AP_INIT_TAKE1("GnuTLSSessionTickets", mgs_set_tickets,
223    NULL,
224    RSRC_CONF,
225    "Session Tickets Configuration"),
226    AP_INIT_RAW_ARGS("GnuTLSPriorities", mgs_set_priorities,
227    NULL,
228    RSRC_CONF,
229    "The priorities to enable (ciphers, Key exchange, macs, compression)."),
230    AP_INIT_TAKE1("GnuTLSEnable", mgs_set_enabled,
231    NULL,
232    RSRC_CONF,
233    "Whether this server has GnuTLS Enabled. Default: Off"),
234    AP_INIT_TAKE1("GnuTLSExportCertificates",
235    mgs_set_export_certificates_size,
236    NULL,
237    RSRC_CONF,
238    "Max size to export PEM encoded certificates to CGIs (or off to disable). Default: off"),
239    AP_INIT_TAKE1("GnuTLSProxyKeyFile", mgs_store_cred_path,
240    NULL,
241    RSRC_CONF,
242    "X509 client private file for proxy connections"),
243    AP_INIT_TAKE1("GnuTLSProxyCertificateFile", mgs_store_cred_path,
244    NULL,
245    RSRC_CONF,
246    "X509 client certificate file for proxy connections"),
247    AP_INIT_TAKE1("GnuTLSProxyCAFile", mgs_store_cred_path,
248    NULL,
249    RSRC_CONF,
250    "X509 trusted CA file for proxy connections"),
251    AP_INIT_TAKE1("GnuTLSProxyCRLFile", mgs_store_cred_path,
252    NULL,
253    RSRC_CONF,
254    "X509 CRL file for proxy connections"),
255    AP_INIT_RAW_ARGS("GnuTLSProxyPriorities", mgs_set_priorities,
256    NULL,
257    RSRC_CONF,
258    "The priorities to enable for proxy connections (ciphers, key exchange, "
259    "MACs, compression)."),
260    { NULL },
261};
262
263module AP_MODULE_DECLARE_DATA gnutls_module = {
264    STANDARD20_MODULE_STUFF,
265    .create_dir_config = mgs_config_dir_create,
266    .merge_dir_config = mgs_config_dir_merge,
267    .create_server_config = mgs_config_server_create,
268    .merge_server_config = mgs_config_server_merge,
269    .cmds = mgs_config_cmds,
270    .register_hooks = gnutls_hooks
271};
Note: See TracBrowser for help on using the repository browser.