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