source: mod_gnutls/src/mod_gnutls.c @ 33826c5

debian/masterdebian/stretch-backportsjessie-backportsmsvaupstream
Last change on this file since 33826c5 was 33826c5, checked in by Dash Shendy <neuromancer@…>, 8 years ago

mod_proxy support

  • Property mode set to 100644
File size: 6.5 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) {
23
24    ap_hook_open_logs(mgs_hook_open_logs, NULL, NULL,APR_HOOK_MIDDLE);
25    /* Try Run Post-Config Hook After mod_proxy */
26    static const char * const aszPre[] = { "mod_proxy.c", NULL };
27    ap_hook_post_config(mgs_hook_post_config, aszPre, NULL,APR_HOOK_REALLY_LAST); 
28    /* HTTP Scheme Hook */
29#if USING_2_1_RECENT
30    ap_hook_http_scheme(mgs_hook_http_scheme, NULL, NULL, APR_HOOK_MIDDLE);
31#else
32    ap_hook_http_method(mgs_hook_http_scheme, NULL, NULL, APR_HOOK_MIDDLE);
33#endif
34    /* Default Port Hook */
35    ap_hook_default_port(nss_hook_default_port,  NULL,NULL, APR_HOOK_MIDDLE);
36    /* Pre-Connect Hook */
37    ap_hook_pre_connection(mgs_hook_default_port, NULL, NULL, APR_HOOK_MIDDLE);
38    /* Pre-Config Hook */
39    ap_hook_pre_config(mgs_hook_pre_config, NULL, NULL,
40            APR_HOOK_MIDDLE);   
41    /* Child-Init Hook */
42    ap_hook_child_init(mgs_hook_child_init, NULL, NULL,
43            APR_HOOK_MIDDLE);
44    /* Authentication Hook */
45    ap_hook_access_checker(mgs_hook_authz, NULL, NULL,
46            APR_HOOK_REALLY_FIRST);
47    /* Fixups Hook */
48    ap_hook_fixups(mgs_hook_fixups, NULL, NULL, APR_HOOK_REALLY_FIRST);
49
50    /* TODO: HTTP Upgrade Filter */
51    /* ap_register_output_filter ("UPGRADE_FILTER",
52     *          ssl_io_filter_Upgrade, NULL, AP_FTYPE_PROTOCOL + 5);
53     */
54
55    /* Input Filter */
56    ap_register_input_filter(GNUTLS_INPUT_FILTER_NAME,
57            mgs_filter_input, NULL,AP_FTYPE_CONNECTION + 5);
58    /* Output Filter */
59    ap_register_output_filter(GNUTLS_OUTPUT_FILTER_NAME,
60            mgs_filter_output, NULL,AP_FTYPE_CONNECTION + 5);
61   
62    /* mod_proxy calls these functions */
63    APR_REGISTER_OPTIONAL_FN(ssl_proxy_enable);
64    APR_REGISTER_OPTIONAL_FN(ssl_engine_disable);
65}
66
67int ssl_is_https(conn_rec *c) {
68    mgs_srvconf_rec *sc = (mgs_srvconf_rec *) 
69            ap_get_module_config(c->base_server->module_config, &gnutls_module);
70    if(sc->enabled == GNUTLS_ENABLED_FALSE || sc->non_ssl_request) {
71        /* SSL/TLS Disabled or Plain HTTP Connection Detected */
72        return 0;
73    }
74    /* Connection is Using SSL/TLS */
75    return 1;
76}
77
78int ssl_engine_disable(conn_rec *c) {
79    mgs_srvconf_rec *sc = (mgs_srvconf_rec *) 
80            ap_get_module_config(c->base_server->module_config, &gnutls_module);
81    if(sc->enabled == GNUTLS_ENABLED_FALSE) {
82        return 1;
83    } 
84    ap_remove_input_filter(c->input_filters);
85    ap_remove_input_filter(c->output_filters);
86    mgs_cleanup_pre_config(c->pool);
87    sc->enabled = 0;
88    return 1;
89}
90
91int ssl_proxy_enable(conn_rec *c) {
92    mgs_srvconf_rec *sc = (mgs_srvconf_rec *) 
93            ap_get_module_config(c->base_server->module_config, &gnutls_module);
94    return sc->proxy_enabled;
95}
96
97static const command_rec mgs_config_cmds[] = {
98    AP_INIT_TAKE1("SSLProxyEngine", mgs_set_proxy_engine,
99    NULL,
100    RSRC_CONF | OR_AUTHCFG,
101    "Set Verification Requirements of the Client Certificate"),
102    AP_INIT_TAKE1("GnuTLSClientVerify", mgs_set_client_verify,
103    NULL,
104    RSRC_CONF | OR_AUTHCFG,
105    "Set Verification Requirements of the Client Certificate"),
106    AP_INIT_TAKE1("GnuTLSClientCAFile", mgs_set_client_ca_file,
107    NULL,
108    RSRC_CONF,
109    "Set the CA File to verify Client Certificates"),
110    AP_INIT_TAKE1("GnuTLSX509CAFile", mgs_set_client_ca_file,
111    NULL,
112    RSRC_CONF,
113    "Set the CA File to verify Client Certificates"),
114    AP_INIT_TAKE1("GnuTLSPGPKeyringFile", mgs_set_keyring_file,
115    NULL,
116    RSRC_CONF,
117    "Set the Keyring File to verify Client Certificates"),
118    AP_INIT_TAKE1("GnuTLSDHFile", mgs_set_dh_file,
119    NULL,
120    RSRC_CONF,
121    "Set the file to read Diffie Hellman parameters from"),
122    AP_INIT_TAKE1("GnuTLSRSAFile", mgs_set_rsa_export_file,
123    NULL,
124    RSRC_CONF,
125    "Set the file to read RSA-EXPORT parameters from"),
126    AP_INIT_TAKE1("GnuTLSCertificateFile", mgs_set_cert_file,
127    NULL,
128    RSRC_CONF,
129    "SSL Server X509 Certificate file"),
130    AP_INIT_TAKE1("GnuTLSKeyFile", mgs_set_key_file,
131    NULL,
132    RSRC_CONF,
133    "SSL Server X509 Private Key file"),
134    AP_INIT_TAKE1("GnuTLSX509CertificateFile", mgs_set_cert_file,
135    NULL,
136    RSRC_CONF,
137    "SSL Server X509 Certificate file"),
138    AP_INIT_TAKE1("GnuTLSX509KeyFile", mgs_set_key_file,
139    NULL,
140    RSRC_CONF,
141    "SSL Server X509 Private Key file"),
142    AP_INIT_TAKE1("GnuTLSPGPCertificateFile", mgs_set_pgpcert_file,
143    NULL,
144    RSRC_CONF,
145    "SSL Server PGP Certificate file"),
146    AP_INIT_TAKE1("GnuTLSPGPKeyFile", mgs_set_pgpkey_file,
147    NULL,
148    RSRC_CONF,
149    "SSL Server PGP Private key file"),
150#ifdef ENABLE_SRP
151    AP_INIT_TAKE1("GnuTLSSRPPasswdFile", mgs_set_srp_tpasswd_file,
152    NULL,
153    RSRC_CONF,
154    "SSL Server SRP Password Conf file"),
155    AP_INIT_TAKE1("GnuTLSSRPPasswdConfFile",
156    mgs_set_srp_tpasswd_conf_file,
157    NULL,
158    RSRC_CONF,
159    "SSL Server SRP Parameters file"),
160#endif
161    AP_INIT_TAKE1("GnuTLSCacheTimeout", mgs_set_cache_timeout,
162    NULL,
163    RSRC_CONF,
164    "Cache Timeout"),
165    AP_INIT_TAKE12("GnuTLSCache", mgs_set_cache,
166    NULL,
167    RSRC_CONF,
168    "Cache Configuration"),
169    AP_INIT_TAKE1("GnuTLSSessionTickets", mgs_set_tickets,
170    NULL,
171    RSRC_CONF,
172    "Session Tickets Configuration"),
173    AP_INIT_RAW_ARGS("GnuTLSPriorities", mgs_set_priorities,
174    NULL,
175    RSRC_CONF,
176    "The priorities to enable (ciphers, Key exchange, macs, compression)."),
177    AP_INIT_TAKE1("GnuTLSEnable", mgs_set_enabled,
178    NULL,
179    RSRC_CONF,
180    "Whether this server has GnuTLS Enabled. Default: Off"),
181    AP_INIT_TAKE1("GnuTLSExportCertificates",
182    mgs_set_export_certificates_enabled,
183    NULL,
184    RSRC_CONF,
185    "Whether to export PEM encoded certificates to CGIs. Default: Off"),
186    { NULL }
187};
188
189module AP_MODULE_DECLARE_DATA gnutls_module = {
190    STANDARD20_MODULE_STUFF,
191    mgs_config_dir_create,
192    mgs_config_dir_merge,
193    mgs_config_server_create,
194    NULL,
195    mgs_config_cmds,
196    gnutls_hooks
197};
Note: See TracBrowser for help on using the repository browser.