[46b85d8] | 1 | /** |
---|
| 2 | * Copyright 2004-2005 Paul Querna |
---|
[e021722] | 3 | * Copyright 2008, 2014 Nikos Mavrogiannopoulos |
---|
[e183628] | 4 | * Copyright 2011 Dash Shendy |
---|
[e391197] | 5 | * Copyright 2015 Thomas Klute |
---|
[46b85d8] | 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" |
---|
[2aaf4f5] | 22 | #include "apr_lib.h" |
---|
[031acac] | 23 | #include <gnutls/abstract.h> |
---|
| 24 | |
---|
| 25 | #define INIT_CA_SIZE 128 |
---|
[46b85d8] | 26 | |
---|
[55dc3f0] | 27 | #ifdef APLOG_USE_MODULE |
---|
| 28 | APLOG_USE_MODULE(gnutls); |
---|
| 29 | #endif |
---|
| 30 | |
---|
[259e835] | 31 | static int pin_callback(void *user, int attempt __attribute__((unused)), |
---|
| 32 | const char *token_url __attribute__((unused)), |
---|
| 33 | const char *token_label, unsigned int flags, |
---|
| 34 | char *pin, size_t pin_max) |
---|
[031acac] | 35 | { |
---|
| 36 | mgs_srvconf_rec *sc = user; |
---|
| 37 | |
---|
| 38 | if (sc->pin == NULL || flags & GNUTLS_PIN_FINAL_TRY || |
---|
| 39 | flags & GNUTLS_PIN_WRONG) { |
---|
| 40 | return -1; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | if (token_label && strcmp(token_label, "SRK") == 0) { |
---|
| 44 | snprintf(pin, pin_max, "%s", sc->srk_pin); |
---|
| 45 | } else { |
---|
| 46 | snprintf(pin, pin_max, "%s", sc->pin); |
---|
| 47 | } |
---|
| 48 | return 0; |
---|
| 49 | } |
---|
| 50 | |
---|
[7bebb42] | 51 | static int load_datum_from_file(apr_pool_t * pool, |
---|
[031acac] | 52 | const char *file, gnutls_datum_t * data) |
---|
| 53 | { |
---|
[e183628] | 54 | apr_file_t *fp; |
---|
| 55 | apr_finfo_t finfo; |
---|
| 56 | apr_status_t rv; |
---|
| 57 | apr_size_t br = 0; |
---|
[7bebb42] | 58 | |
---|
[e183628] | 59 | rv = apr_file_open(&fp, file, APR_READ | APR_BINARY, |
---|
[031acac] | 60 | APR_OS_DEFAULT, pool); |
---|
[e183628] | 61 | if (rv != APR_SUCCESS) { |
---|
[031acac] | 62 | return rv; |
---|
[e183628] | 63 | } |
---|
[7bebb42] | 64 | |
---|
[e183628] | 65 | rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, fp); |
---|
[7bebb42] | 66 | |
---|
[e183628] | 67 | if (rv != APR_SUCCESS) { |
---|
[031acac] | 68 | return rv; |
---|
[e183628] | 69 | } |
---|
[7bebb42] | 70 | |
---|
[e183628] | 71 | data->data = apr_palloc(pool, finfo.size + 1); |
---|
| 72 | rv = apr_file_read_full(fp, data->data, finfo.size, &br); |
---|
[7bebb42] | 73 | |
---|
[e183628] | 74 | if (rv != APR_SUCCESS) { |
---|
[031acac] | 75 | return rv; |
---|
[e183628] | 76 | } |
---|
| 77 | apr_file_close(fp); |
---|
[7bebb42] | 78 | |
---|
[e183628] | 79 | data->data[br] = '\0'; |
---|
| 80 | data->size = br; |
---|
[7bebb42] | 81 | |
---|
[e183628] | 82 | return 0; |
---|
[46b85d8] | 83 | } |
---|
| 84 | |
---|
[031acac] | 85 | /* 2048-bit group parameters from SRP specification */ |
---|
| 86 | const char static_dh_params[] = "-----BEGIN DH PARAMETERS-----\n" |
---|
| 87 | "MIIBBwKCAQCsa9tBMkqam/Fm3l4TiVgvr3K2ZRmH7gf8MZKUPbVgUKNzKcu0oJnt\n" |
---|
| 88 | "gZPgdXdnoT3VIxKrSwMxDc1/SKnaBP1Q6Ag5ae23Z7DPYJUXmhY6s2YaBfvV+qro\n" |
---|
| 89 | "KRipli8Lk7hV+XmT7Jde6qgNdArb9P90c1nQQdXDPqcdKB5EaxR3O8qXtDoj+4AW\n" |
---|
| 90 | "dr0gekNsZIHx0rkHhxdGGludMuaI+HdIVEUjtSSw1X1ep3onddLs+gMs+9v1L7N4\n" |
---|
| 91 | "YWAnkATleuavh05zA85TKZzMBBx7wwjYKlaY86jQw4JxrjX46dv7tpS1yAPYn3rk\n" |
---|
| 92 | "Nd4jbVJfVHWbZeNy/NaO8g+nER+eSv9zAgEC\n" |
---|
| 93 | "-----END DH PARAMETERS-----\n"; |
---|
| 94 | |
---|
| 95 | int mgs_load_files(apr_pool_t * p, server_rec * s) |
---|
| 96 | { |
---|
[e183628] | 97 | apr_pool_t *spool; |
---|
[031acac] | 98 | const char *file; |
---|
| 99 | gnutls_datum_t data; |
---|
| 100 | int ret; |
---|
[e183628] | 101 | mgs_srvconf_rec *sc = |
---|
[031acac] | 102 | (mgs_srvconf_rec *) ap_get_module_config(s->module_config, |
---|
| 103 | &gnutls_module); |
---|
[e183628] | 104 | |
---|
[031acac] | 105 | apr_pool_create(&spool, p); |
---|
[e183628] | 106 | |
---|
[031acac] | 107 | sc->cert_pgp = apr_pcalloc(p, sizeof(sc->cert_pgp[0])); |
---|
| 108 | sc->cert_crt_pgp = apr_pcalloc(p, sizeof(sc->cert_crt_pgp[0])); |
---|
| 109 | sc->certs_x509_chain = |
---|
| 110 | apr_pcalloc(p, MAX_CHAIN_SIZE * sizeof(sc->certs_x509_chain[0])); |
---|
| 111 | sc->certs_x509_crt_chain = |
---|
| 112 | apr_pcalloc(p, |
---|
| 113 | MAX_CHAIN_SIZE * sizeof(sc->certs_x509_crt_chain[0])); |
---|
[e183628] | 114 | |
---|
[031acac] | 115 | ret = gnutls_certificate_allocate_credentials(&sc->certs); |
---|
| 116 | if (ret < 0) { |
---|
| 117 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 118 | "GnuTLS: Failed to initialize" ": (%d) %s", ret, |
---|
| 119 | gnutls_strerror(ret)); |
---|
| 120 | ret = -1; |
---|
| 121 | goto cleanup; |
---|
[e183628] | 122 | } |
---|
| 123 | |
---|
[031acac] | 124 | ret = gnutls_anon_allocate_server_credentials(&sc->anon_creds); |
---|
[e183628] | 125 | if (ret < 0) { |
---|
[031acac] | 126 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 127 | "GnuTLS: Failed to initialize" ": (%d) %s", ret, |
---|
| 128 | gnutls_strerror(ret)); |
---|
| 129 | ret = -1; |
---|
| 130 | goto cleanup; |
---|
[e183628] | 131 | } |
---|
| 132 | |
---|
[031acac] | 133 | /* Load SRP parameters */ |
---|
| 134 | #ifdef ENABLE_SRP |
---|
| 135 | ret = gnutls_srp_allocate_server_credentials(&sc->srp_creds); |
---|
[e183628] | 136 | if (ret < 0) { |
---|
[031acac] | 137 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 138 | "GnuTLS: Failed to initialize" ": (%d) %s", ret, |
---|
| 139 | gnutls_strerror(ret)); |
---|
| 140 | ret = -1; |
---|
| 141 | goto cleanup; |
---|
[e183628] | 142 | } |
---|
| 143 | |
---|
[031acac] | 144 | if (sc->srp_tpasswd_conf_file != NULL && sc->srp_tpasswd_file != NULL) { |
---|
| 145 | ret = gnutls_srp_set_server_credentials_file |
---|
| 146 | (sc->srp_creds, sc->srp_tpasswd_file, |
---|
| 147 | sc->srp_tpasswd_conf_file); |
---|
| 148 | |
---|
| 149 | if (ret < 0 && sc->enabled == GNUTLS_ENABLED_TRUE) { |
---|
| 150 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, |
---|
| 151 | s, |
---|
| 152 | "GnuTLS: Host '%s:%d' is missing a " |
---|
| 153 | "SRP password or conf File!", |
---|
| 154 | s->server_hostname, s->port); |
---|
| 155 | ret = -1; |
---|
| 156 | goto cleanup; |
---|
| 157 | } |
---|
[e183628] | 158 | } |
---|
[031acac] | 159 | #endif |
---|
[e183628] | 160 | |
---|
[031acac] | 161 | ret = gnutls_dh_params_init(&sc->dh_params); |
---|
| 162 | if (ret < 0) { |
---|
| 163 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 164 | "GnuTLS: Failed to initialize" |
---|
| 165 | ": (%d) %s", ret, gnutls_strerror(ret)); |
---|
| 166 | ret = -1; |
---|
| 167 | goto cleanup; |
---|
| 168 | } |
---|
[7bebb42] | 169 | |
---|
[031acac] | 170 | /* Load DH parameters */ |
---|
| 171 | if (sc->dh_file) { |
---|
| 172 | if (load_datum_from_file(spool, sc->dh_file, &data) != 0) { |
---|
| 173 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 174 | "GnuTLS: Error Reading " "DH params '%s'", sc->dh_file); |
---|
| 175 | ret = -1; |
---|
| 176 | goto cleanup; |
---|
| 177 | } |
---|
[e183628] | 178 | |
---|
[031acac] | 179 | ret = |
---|
| 180 | gnutls_dh_params_import_pkcs3(sc->dh_params, &data, |
---|
| 181 | GNUTLS_X509_FMT_PEM); |
---|
| 182 | if (ret < 0) { |
---|
| 183 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 184 | "GnuTLS: Failed to Import " |
---|
| 185 | "DH params '%s': (%d) %s", sc->dh_file, ret, |
---|
| 186 | gnutls_strerror(ret)); |
---|
| 187 | ret = -1; |
---|
| 188 | goto cleanup; |
---|
| 189 | } |
---|
| 190 | } else { |
---|
| 191 | gnutls_datum_t pdata = { |
---|
| 192 | (void *) static_dh_params, |
---|
| 193 | sizeof(static_dh_params) |
---|
| 194 | }; |
---|
| 195 | |
---|
| 196 | ret = gnutls_dh_params_import_pkcs3(sc->dh_params, &pdata, GNUTLS_X509_FMT_PEM); |
---|
| 197 | if (ret < 0) { |
---|
| 198 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 199 | "GnuTLS: Unable to generate or load DH Params: (%d) %s", |
---|
| 200 | ret, gnutls_strerror(ret)); |
---|
| 201 | ret = -1; |
---|
| 202 | goto cleanup; |
---|
| 203 | } |
---|
| 204 | } |
---|
[e183628] | 205 | |
---|
[031acac] | 206 | if (sc->x509_cert_file != NULL) { |
---|
| 207 | unsigned int chain_num, i; |
---|
| 208 | unsigned format = GNUTLS_X509_FMT_PEM; |
---|
| 209 | |
---|
| 210 | /* Load X.509 certificate */ |
---|
| 211 | if (strncmp(sc->x509_cert_file, "pkcs11:", 7) == 0) { |
---|
| 212 | gnutls_pkcs11_obj_t obj; |
---|
| 213 | |
---|
| 214 | file = sc->x509_cert_file; |
---|
| 215 | |
---|
| 216 | ret = gnutls_pkcs11_obj_init(&obj); |
---|
| 217 | if (ret < 0) { |
---|
| 218 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 219 | "GnuTLS: Error Initializing PKCS #11 object"); |
---|
| 220 | ret = -1; |
---|
| 221 | goto cleanup; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | gnutls_pkcs11_obj_set_pin_function(obj, pin_callback, sc); |
---|
| 225 | |
---|
| 226 | ret = gnutls_pkcs11_obj_import_url(obj, file, GNUTLS_PKCS11_OBJ_FLAG_LOGIN); |
---|
| 227 | if (ret < 0) { |
---|
| 228 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 229 | "GnuTLS: Error Importing PKCS #11 object: '%s': %s", |
---|
| 230 | file, gnutls_strerror(ret)); |
---|
| 231 | ret = -1; |
---|
| 232 | goto cleanup; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | format = GNUTLS_X509_FMT_DER; |
---|
| 236 | ret = gnutls_pkcs11_obj_export2(obj, &data); |
---|
| 237 | if (ret < 0) { |
---|
| 238 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 239 | "GnuTLS: Error Exporting a PKCS #11 object: '%s': %s", |
---|
| 240 | file, gnutls_strerror(ret)); |
---|
| 241 | ret = -1; |
---|
| 242 | goto cleanup; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | gnutls_pkcs11_obj_deinit(obj); |
---|
| 246 | } else { |
---|
| 247 | file = ap_server_root_relative(spool, sc->x509_cert_file); |
---|
| 248 | |
---|
| 249 | ret = gnutls_load_file(file, &data); |
---|
| 250 | if (ret < 0) { |
---|
| 251 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 252 | "GnuTLS: Error Reading Certificate '%s': %s", |
---|
| 253 | file, gnutls_strerror(ret)); |
---|
| 254 | ret = -1; |
---|
| 255 | goto cleanup; |
---|
| 256 | } |
---|
| 257 | } |
---|
[e183628] | 258 | |
---|
[031acac] | 259 | ret = |
---|
| 260 | gnutls_x509_crt_list_import2(&sc->certs_x509_crt_chain, |
---|
| 261 | &chain_num, &data, format, |
---|
| 262 | GNUTLS_X509_CRT_LIST_FAIL_IF_UNSORTED); |
---|
| 263 | gnutls_free(data.data); |
---|
| 264 | sc->certs_x509_chain_num = chain_num; |
---|
| 265 | |
---|
| 266 | if (ret < 0) { |
---|
| 267 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 268 | "GnuTLS: Failed to Import Certificate Chain '%s': (%d) %s", |
---|
| 269 | file, ret, gnutls_strerror(ret)); |
---|
| 270 | ret = -1; |
---|
| 271 | goto cleanup; |
---|
| 272 | } |
---|
[e183628] | 273 | |
---|
[031acac] | 274 | for (i = 0; i < chain_num; i++) { |
---|
| 275 | ret = |
---|
| 276 | gnutls_pcert_import_x509(&sc->certs_x509_chain[i], |
---|
| 277 | sc->certs_x509_crt_chain[i], 0); |
---|
| 278 | if (ret < 0) { |
---|
| 279 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 280 | "GnuTLS: Failed to Import pCertificate '%s': (%d) %s", |
---|
| 281 | file, ret, gnutls_strerror(ret)); |
---|
| 282 | ret = -1; |
---|
| 283 | goto cleanup; |
---|
| 284 | } |
---|
| 285 | } |
---|
| 286 | sc->certs_x509_chain_num = chain_num; |
---|
[e183628] | 287 | } |
---|
[671b64f] | 288 | |
---|
[031acac] | 289 | if (sc->x509_key_file) { |
---|
| 290 | ret = gnutls_privkey_init(&sc->privkey_x509); |
---|
| 291 | if (ret < 0) { |
---|
| 292 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 293 | "GnuTLS: Failed to initialize: (%d) %s", ret, |
---|
| 294 | gnutls_strerror(ret)); |
---|
| 295 | ret = -1; |
---|
| 296 | goto cleanup; |
---|
| 297 | } |
---|
[e183628] | 298 | |
---|
[031acac] | 299 | if (gnutls_url_is_supported(sc->x509_key_file) != 0) { |
---|
| 300 | file = sc->x509_key_file; |
---|
| 301 | |
---|
| 302 | gnutls_privkey_set_pin_function(sc->privkey_x509, pin_callback, |
---|
| 303 | sc); |
---|
| 304 | |
---|
| 305 | ret = gnutls_privkey_import_url(sc->privkey_x509, file, 0); |
---|
| 306 | |
---|
| 307 | if (ret < 0) { |
---|
| 308 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 309 | "GnuTLS: Failed to Import Private Key URL '%s': (%d) %s", |
---|
| 310 | file, ret, gnutls_strerror(ret)); |
---|
| 311 | ret = -1; |
---|
| 312 | goto cleanup; |
---|
| 313 | } |
---|
| 314 | } else { |
---|
| 315 | file = ap_server_root_relative(spool, sc->x509_key_file); |
---|
| 316 | |
---|
| 317 | if (load_datum_from_file(spool, file, &data) != 0) { |
---|
| 318 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 319 | "GnuTLS: Error Reading Private Key '%s'", |
---|
| 320 | file); |
---|
| 321 | ret = -1; |
---|
| 322 | goto cleanup; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | ret = |
---|
| 326 | gnutls_privkey_import_x509_raw(sc->privkey_x509, &data, |
---|
| 327 | GNUTLS_X509_FMT_PEM, sc->pin, |
---|
| 328 | 0); |
---|
| 329 | |
---|
| 330 | if (ret < 0) { |
---|
| 331 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 332 | "GnuTLS: Failed to Import Private Key '%s': (%d) %s", |
---|
| 333 | file, ret, gnutls_strerror(ret)); |
---|
| 334 | ret = -1; |
---|
| 335 | goto cleanup; |
---|
| 336 | } |
---|
| 337 | } |
---|
| 338 | } |
---|
[46b85d8] | 339 | |
---|
[031acac] | 340 | /* Load the X.509 CA file */ |
---|
| 341 | if (sc->x509_ca_file) { |
---|
| 342 | if (load_datum_from_file(spool, sc->x509_ca_file, &data) != 0) { |
---|
| 343 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 344 | "GnuTLS: Error Reading " "Client CA File '%s'", |
---|
| 345 | sc->x509_ca_file); |
---|
| 346 | ret = -1; |
---|
| 347 | goto cleanup; |
---|
| 348 | } |
---|
[3b4c0d0] | 349 | |
---|
[031acac] | 350 | ret = gnutls_x509_crt_list_import2(&sc->ca_list, &sc->ca_list_size, |
---|
| 351 | &data, GNUTLS_X509_FMT_PEM, 0); |
---|
| 352 | if (ret < 0) { |
---|
| 353 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 354 | "GnuTLS: Failed to load " |
---|
| 355 | "Client CA File '%s': (%d) %s", sc->x509_ca_file, |
---|
| 356 | ret, gnutls_strerror(ret)); |
---|
| 357 | ret = -1; |
---|
| 358 | goto cleanup; |
---|
| 359 | } |
---|
| 360 | } |
---|
[3b4c0d0] | 361 | |
---|
[031acac] | 362 | if (sc->pgp_cert_file) { |
---|
| 363 | if (load_datum_from_file(spool, sc->pgp_cert_file, &data) != 0) { |
---|
| 364 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 365 | "GnuTLS: Error Reading " "Certificate '%s'", |
---|
| 366 | sc->pgp_cert_file); |
---|
| 367 | ret = -1; |
---|
| 368 | goto cleanup; |
---|
| 369 | } |
---|
[671b64f] | 370 | |
---|
[031acac] | 371 | ret = gnutls_openpgp_crt_init(&sc->cert_crt_pgp[0]); |
---|
| 372 | if (ret < 0) { |
---|
| 373 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 374 | "GnuTLS: Failed to Init " |
---|
| 375 | "PGP Certificate: (%d) %s", ret, |
---|
| 376 | gnutls_strerror(ret)); |
---|
| 377 | ret = -1; |
---|
| 378 | goto cleanup; |
---|
| 379 | } |
---|
[e183628] | 380 | |
---|
[031acac] | 381 | ret = |
---|
| 382 | gnutls_openpgp_crt_import(sc->cert_crt_pgp[0], &data, |
---|
| 383 | GNUTLS_OPENPGP_FMT_BASE64); |
---|
| 384 | if (ret < 0) { |
---|
| 385 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 386 | "GnuTLS: Failed to Import " |
---|
| 387 | "PGP Certificate: (%d) %s", ret, |
---|
| 388 | gnutls_strerror(ret)); |
---|
| 389 | ret = -1; |
---|
| 390 | goto cleanup; |
---|
| 391 | } |
---|
[e183628] | 392 | |
---|
[031acac] | 393 | ret = |
---|
| 394 | gnutls_pcert_import_openpgp(sc->cert_pgp, sc->cert_crt_pgp[0], |
---|
| 395 | 0); |
---|
| 396 | if (ret < 0) { |
---|
| 397 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 398 | "GnuTLS: Failed to Import " |
---|
| 399 | "PGP pCertificate: (%d) %s", ret, |
---|
| 400 | gnutls_strerror(ret)); |
---|
| 401 | ret = -1; |
---|
| 402 | goto cleanup; |
---|
| 403 | } |
---|
[e183628] | 404 | } |
---|
| 405 | |
---|
[031acac] | 406 | /* Load the PGP key file */ |
---|
| 407 | if (sc->pgp_key_file) { |
---|
| 408 | if (load_datum_from_file(spool, sc->pgp_key_file, &data) != 0) { |
---|
| 409 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 410 | "GnuTLS: Error Reading " "Private Key '%s'", |
---|
| 411 | sc->pgp_key_file); |
---|
| 412 | ret = -1; |
---|
| 413 | goto cleanup; |
---|
| 414 | } |
---|
[3b4c0d0] | 415 | |
---|
[031acac] | 416 | ret = gnutls_privkey_init(&sc->privkey_pgp); |
---|
| 417 | if (ret < 0) { |
---|
| 418 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 419 | "GnuTLS: Failed to initialize" |
---|
| 420 | ": (%d) %s", ret, gnutls_strerror(ret)); |
---|
| 421 | ret = -1; |
---|
| 422 | goto cleanup; |
---|
| 423 | } |
---|
| 424 | |
---|
[d04f7da] | 425 | #if GNUTLS_VERSION_NUMBER < 0x030312 |
---|
| 426 | /* GnuTLS versions before 3.3.12 contain a bug in |
---|
| 427 | * gnutls_privkey_import_openpgp_raw which frees data that is |
---|
| 428 | * accessed when the key is used, leading to segfault. Loading |
---|
| 429 | * the key into a gnutls_openpgp_privkey_t and then assigning |
---|
| 430 | * it to the gnutls_privkey_t works around the bug, hence this |
---|
| 431 | * chain of gnutls_openpgp_privkey_init, |
---|
[2cde8111] | 432 | * gnutls_openpgp_privkey_import and |
---|
[d04f7da] | 433 | * gnutls_privkey_import_openpgp. */ |
---|
[2cde8111] | 434 | ret = gnutls_openpgp_privkey_init(&sc->privkey_pgp_internal); |
---|
| 435 | if (ret != 0) { |
---|
| 436 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 437 | "GnuTLS: Failed to initialize " |
---|
| 438 | "PGP Private Key '%s': (%d) %s", |
---|
| 439 | sc->pgp_key_file, ret, gnutls_strerror(ret)); |
---|
| 440 | ret = -1; |
---|
| 441 | goto cleanup; |
---|
| 442 | } |
---|
| 443 | |
---|
| 444 | ret = gnutls_openpgp_privkey_import(sc->privkey_pgp_internal, &data, |
---|
| 445 | GNUTLS_OPENPGP_FMT_BASE64, NULL, 0); |
---|
[031acac] | 446 | if (ret != 0) { |
---|
| 447 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 448 | "GnuTLS: Failed to Import " |
---|
| 449 | "PGP Private Key '%s': (%d) %s", |
---|
| 450 | sc->pgp_key_file, ret, gnutls_strerror(ret)); |
---|
| 451 | ret = -1; |
---|
| 452 | goto cleanup; |
---|
| 453 | } |
---|
[2cde8111] | 454 | |
---|
| 455 | ret = gnutls_privkey_import_openpgp(sc->privkey_pgp, |
---|
| 456 | sc->privkey_pgp_internal, 0); |
---|
| 457 | if (ret != 0) |
---|
| 458 | { |
---|
| 459 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 460 | "GnuTLS: Failed to assign PGP Private Key '%s' " |
---|
| 461 | "to gnutls_privkey_t structure: (%d) %s", |
---|
| 462 | sc->pgp_key_file, ret, gnutls_strerror(ret)); |
---|
| 463 | ret = -1; |
---|
| 464 | goto cleanup; |
---|
| 465 | } |
---|
[d04f7da] | 466 | #else |
---|
| 467 | ret = gnutls_privkey_import_openpgp_raw(sc->privkey_pgp, &data, |
---|
| 468 | GNUTLS_OPENPGP_FMT_BASE64, |
---|
| 469 | NULL, NULL); |
---|
| 470 | if (ret != 0) |
---|
| 471 | { |
---|
| 472 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 473 | "GnuTLS: Failed to Import " |
---|
| 474 | "PGP Private Key '%s': (%d) %s", |
---|
| 475 | sc->pgp_key_file, ret, gnutls_strerror(ret)); |
---|
| 476 | ret = -1; |
---|
| 477 | goto cleanup; |
---|
| 478 | } |
---|
| 479 | #endif |
---|
[e183628] | 480 | } |
---|
| 481 | |
---|
[031acac] | 482 | /* Load the keyring file */ |
---|
| 483 | if (sc->pgp_ring_file) { |
---|
| 484 | if (load_datum_from_file(spool, sc->pgp_ring_file, &data) != 0) { |
---|
| 485 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 486 | "GnuTLS: Error Reading " "Keyring File '%s'", |
---|
| 487 | sc->pgp_ring_file); |
---|
| 488 | ret = -1; |
---|
| 489 | goto cleanup; |
---|
| 490 | } |
---|
[e183628] | 491 | |
---|
[031acac] | 492 | ret = gnutls_openpgp_keyring_init(&sc->pgp_list); |
---|
| 493 | if (ret < 0) { |
---|
| 494 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 495 | "GnuTLS: Failed to initialize" |
---|
| 496 | "keyring: (%d) %s", ret, gnutls_strerror(ret)); |
---|
| 497 | ret = -1; |
---|
| 498 | goto cleanup; |
---|
[3b4c0d0] | 499 | } |
---|
[e183628] | 500 | |
---|
[031acac] | 501 | ret = gnutls_openpgp_keyring_import(sc->pgp_list, &data, |
---|
| 502 | GNUTLS_OPENPGP_FMT_BASE64); |
---|
| 503 | if (ret < 0) { |
---|
| 504 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 505 | "GnuTLS: Failed to load " |
---|
| 506 | "Keyring File '%s': (%d) %s", sc->pgp_ring_file, |
---|
| 507 | ret, gnutls_strerror(ret)); |
---|
| 508 | ret = -1; |
---|
| 509 | goto cleanup; |
---|
| 510 | } |
---|
[e183628] | 511 | } |
---|
[3b4c0d0] | 512 | |
---|
[031acac] | 513 | if (sc->priorities_str) { |
---|
[7314438] | 514 | const char *err; |
---|
| 515 | ret = gnutls_priority_init(&sc->priorities, sc->priorities_str, &err); |
---|
[031acac] | 516 | |
---|
| 517 | if (ret < 0) { |
---|
| 518 | if (ret == GNUTLS_E_INVALID_REQUEST) { |
---|
| 519 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 520 | "GnuTLS: Syntax error parsing priorities string at: %s", |
---|
| 521 | err); |
---|
| 522 | } else { |
---|
| 523 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 524 | "GnuTLS: error parsing priorities string"); |
---|
| 525 | |
---|
| 526 | } |
---|
| 527 | ret = -1; |
---|
| 528 | goto cleanup; |
---|
| 529 | } |
---|
| 530 | } |
---|
| 531 | |
---|
| 532 | ret = 0; |
---|
| 533 | cleanup: |
---|
[e183628] | 534 | apr_pool_destroy(spool); |
---|
[3b4c0d0] | 535 | |
---|
[031acac] | 536 | return ret; |
---|
[46b85d8] | 537 | } |
---|
| 538 | |
---|
[031acac] | 539 | int mgs_pkcs11_reinit(server_rec * base_server) |
---|
| 540 | { |
---|
[e183628] | 541 | int ret; |
---|
[031acac] | 542 | server_rec *s; |
---|
| 543 | mgs_srvconf_rec *sc; |
---|
[e183628] | 544 | |
---|
[031acac] | 545 | gnutls_pkcs11_reinit(); |
---|
[e183628] | 546 | |
---|
[031acac] | 547 | for (s = base_server; s; s = s->next) { |
---|
| 548 | sc = (mgs_srvconf_rec *) ap_get_module_config(s->module_config, &gnutls_module); |
---|
[e183628] | 549 | |
---|
[031acac] | 550 | /* gnutls caches the session in a private key, so we need to open |
---|
| 551 | * a new one */ |
---|
| 552 | if (sc->x509_key_file && gnutls_url_is_supported(sc->x509_key_file) != 0) { |
---|
| 553 | gnutls_privkey_deinit(sc->privkey_x509); |
---|
[e183628] | 554 | |
---|
[031acac] | 555 | ret = gnutls_privkey_init(&sc->privkey_x509); |
---|
| 556 | if (ret < 0) { |
---|
| 557 | ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, |
---|
| 558 | "GnuTLS: Failed to initialize: (%d) %s", ret, |
---|
| 559 | gnutls_strerror(ret)); |
---|
| 560 | goto fail; |
---|
| 561 | } |
---|
| 562 | |
---|
| 563 | gnutls_privkey_set_pin_function(sc->privkey_x509, pin_callback, sc); |
---|
| 564 | |
---|
| 565 | ret = gnutls_privkey_import_url(sc->privkey_x509, sc->x509_key_file, 0); |
---|
| 566 | if (ret < 0) { |
---|
| 567 | ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, |
---|
| 568 | "GnuTLS: Failed to Re-Import Private Key URL '%s': (%d) %s", |
---|
| 569 | sc->x509_key_file, ret, gnutls_strerror(ret)); |
---|
| 570 | goto fail; |
---|
| 571 | } |
---|
| 572 | } |
---|
[e183628] | 573 | } |
---|
| 574 | |
---|
[031acac] | 575 | return 0; |
---|
| 576 | |
---|
| 577 | fail: |
---|
| 578 | gnutls_privkey_deinit(sc->privkey_x509); |
---|
| 579 | return -1; |
---|
| 580 | } |
---|
| 581 | |
---|
[1d9cfaf] | 582 | const char *mgs_set_dh_file(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
| 583 | const char *arg) { |
---|
[e183628] | 584 | mgs_srvconf_rec *sc = |
---|
[031acac] | 585 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 586 | module_config, |
---|
| 587 | &gnutls_module); |
---|
[e183628] | 588 | |
---|
[031acac] | 589 | sc->dh_file = ap_server_root_relative(parms->pool, arg); |
---|
[e183628] | 590 | |
---|
| 591 | return NULL; |
---|
[e5bbda4] | 592 | } |
---|
[e183628] | 593 | |
---|
[1d9cfaf] | 594 | const char *mgs_set_cert_file(cmd_parms * parms, void *dummy __attribute__((unused)), const char *arg) { |
---|
[e183628] | 595 | |
---|
| 596 | mgs_srvconf_rec *sc = |
---|
[031acac] | 597 | (mgs_srvconf_rec *) ap_get_module_config(parms-> |
---|
| 598 | server->module_config, |
---|
| 599 | &gnutls_module); |
---|
[e183628] | 600 | |
---|
[031acac] | 601 | sc->x509_cert_file = apr_pstrdup(parms->pool, arg); |
---|
[e183628] | 602 | |
---|
| 603 | return NULL; |
---|
[031acac] | 604 | |
---|
[e5bbda4] | 605 | } |
---|
| 606 | |
---|
[1d9cfaf] | 607 | const char *mgs_set_key_file(cmd_parms * parms, void *dummy __attribute__((unused)), const char *arg) { |
---|
[031acac] | 608 | |
---|
[e183628] | 609 | mgs_srvconf_rec *sc = |
---|
[031acac] | 610 | (mgs_srvconf_rec *) ap_get_module_config(parms-> |
---|
| 611 | server->module_config, |
---|
| 612 | &gnutls_module); |
---|
[e183628] | 613 | |
---|
[031acac] | 614 | sc->x509_key_file = apr_pstrdup(parms->pool, arg); |
---|
[e183628] | 615 | |
---|
[031acac] | 616 | return NULL; |
---|
| 617 | } |
---|
[e183628] | 618 | |
---|
[1d9cfaf] | 619 | const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[259e835] | 620 | const char *arg) |
---|
| 621 | { |
---|
[031acac] | 622 | mgs_srvconf_rec *sc = |
---|
| 623 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 624 | module_config, |
---|
| 625 | &gnutls_module); |
---|
| 626 | |
---|
| 627 | sc->pgp_cert_file = ap_server_root_relative(parms->pool, arg); |
---|
| 628 | |
---|
| 629 | return NULL; |
---|
| 630 | } |
---|
| 631 | |
---|
[1d9cfaf] | 632 | const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
| 633 | const char *arg) { |
---|
[031acac] | 634 | mgs_srvconf_rec *sc = |
---|
| 635 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 636 | module_config, |
---|
| 637 | &gnutls_module); |
---|
| 638 | |
---|
| 639 | sc->pgp_key_file = ap_server_root_relative(parms->pool, arg); |
---|
[e183628] | 640 | |
---|
| 641 | return NULL; |
---|
[e5bbda4] | 642 | } |
---|
| 643 | |
---|
[fd82e59] | 644 | const char *mgs_set_tickets(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[e183628] | 645 | const char *arg) { |
---|
| 646 | mgs_srvconf_rec *sc = |
---|
[031acac] | 647 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 648 | module_config, |
---|
| 649 | &gnutls_module); |
---|
[e183628] | 650 | |
---|
| 651 | sc->tickets = 0; |
---|
| 652 | if (strcasecmp("on", arg) == 0) { |
---|
[031acac] | 653 | sc->tickets = 1; |
---|
[e183628] | 654 | } |
---|
| 655 | |
---|
| 656 | return NULL; |
---|
[ae233c2] | 657 | } |
---|
| 658 | |
---|
[e5bbda4] | 659 | |
---|
[787dab7] | 660 | #ifdef ENABLE_SRP |
---|
| 661 | |
---|
[fd82e59] | 662 | const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[e183628] | 663 | const char *arg) { |
---|
| 664 | mgs_srvconf_rec *sc = |
---|
[031acac] | 665 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 666 | module_config, |
---|
| 667 | &gnutls_module); |
---|
[7bebb42] | 668 | |
---|
[e183628] | 669 | sc->srp_tpasswd_file = ap_server_root_relative(parms->pool, arg); |
---|
[7bebb42] | 670 | |
---|
[e183628] | 671 | return NULL; |
---|
[7bebb42] | 672 | } |
---|
| 673 | |
---|
[fd82e59] | 674 | const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[e183628] | 675 | const char *arg) { |
---|
| 676 | mgs_srvconf_rec *sc = |
---|
[031acac] | 677 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 678 | module_config, |
---|
| 679 | &gnutls_module); |
---|
[7bebb42] | 680 | |
---|
[031acac] | 681 | sc->srp_tpasswd_conf_file = ap_server_root_relative(parms->pool, arg); |
---|
[7bebb42] | 682 | |
---|
[e183628] | 683 | return NULL; |
---|
[7bebb42] | 684 | } |
---|
| 685 | |
---|
[787dab7] | 686 | #endif |
---|
| 687 | |
---|
[fd82e59] | 688 | const char *mgs_set_cache(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[e183628] | 689 | const char *type, const char *arg) { |
---|
| 690 | const char *err; |
---|
| 691 | mgs_srvconf_rec *sc = |
---|
[031acac] | 692 | ap_get_module_config(parms->server->module_config, |
---|
| 693 | &gnutls_module); |
---|
[e183628] | 694 | if ((err = ap_check_cmd_context(parms, GLOBAL_ONLY))) { |
---|
[031acac] | 695 | return err; |
---|
[e183628] | 696 | } |
---|
| 697 | |
---|
| 698 | if (strcasecmp("none", type) == 0) { |
---|
[031acac] | 699 | sc->cache_type = mgs_cache_none; |
---|
| 700 | sc->cache_config = NULL; |
---|
| 701 | return NULL; |
---|
[e183628] | 702 | } else if (strcasecmp("dbm", type) == 0) { |
---|
[031acac] | 703 | sc->cache_type = mgs_cache_dbm; |
---|
[e183628] | 704 | } else if (strcasecmp("gdbm", type) == 0) { |
---|
[031acac] | 705 | sc->cache_type = mgs_cache_gdbm; |
---|
[e183628] | 706 | } |
---|
[46b85d8] | 707 | #if HAVE_APR_MEMCACHE |
---|
[e183628] | 708 | else if (strcasecmp("memcache", type) == 0) { |
---|
[031acac] | 709 | sc->cache_type = mgs_cache_memcache; |
---|
[e183628] | 710 | } |
---|
[46b85d8] | 711 | #endif |
---|
[e183628] | 712 | else { |
---|
[031acac] | 713 | return "Invalid Type for GnuTLSCache!"; |
---|
[e183628] | 714 | } |
---|
| 715 | |
---|
| 716 | if (arg == NULL) |
---|
[031acac] | 717 | return "Invalid argument 2 for GnuTLSCache!"; |
---|
[e183628] | 718 | |
---|
| 719 | if (sc->cache_type == mgs_cache_dbm |
---|
[031acac] | 720 | || sc->cache_type == mgs_cache_gdbm) { |
---|
| 721 | sc->cache_config = ap_server_root_relative(parms->pool, arg); |
---|
[e183628] | 722 | } else { |
---|
[031acac] | 723 | sc->cache_config = apr_pstrdup(parms->pool, arg); |
---|
[e183628] | 724 | } |
---|
| 725 | |
---|
| 726 | return NULL; |
---|
[46b85d8] | 727 | } |
---|
| 728 | |
---|
[fd82e59] | 729 | const char *mgs_set_cache_timeout(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[e183628] | 730 | const char *arg) { |
---|
| 731 | int argint; |
---|
[480aba1] | 732 | const char *err; |
---|
[e183628] | 733 | mgs_srvconf_rec *sc = |
---|
[031acac] | 734 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 735 | module_config, |
---|
| 736 | &gnutls_module); |
---|
[e183628] | 737 | |
---|
[480aba1] | 738 | if ((err = ap_check_cmd_context(parms, GLOBAL_ONLY))) { |
---|
[031acac] | 739 | return err; |
---|
[480aba1] | 740 | } |
---|
| 741 | |
---|
[e183628] | 742 | argint = atoi(arg); |
---|
| 743 | |
---|
| 744 | if (argint < 0) { |
---|
[031acac] | 745 | return "GnuTLSCacheTimeout: Invalid argument"; |
---|
[e183628] | 746 | } else if (argint == 0) { |
---|
[031acac] | 747 | sc->cache_timeout = 0; |
---|
[e183628] | 748 | } else { |
---|
[031acac] | 749 | sc->cache_timeout = apr_time_from_sec(argint); |
---|
[e183628] | 750 | } |
---|
| 751 | |
---|
| 752 | return NULL; |
---|
[e02dd8c] | 753 | } |
---|
| 754 | |
---|
[fd82e59] | 755 | const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[cf2b905] | 756 | const char *arg) { |
---|
| 757 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *)ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
| 758 | |
---|
| 759 | if (strcasecmp("cartel", arg) == 0) { |
---|
[031acac] | 760 | sc->client_verify_method = mgs_cvm_cartel; |
---|
[cf2b905] | 761 | } else if (strcasecmp("msva", arg) == 0) { |
---|
| 762 | #ifdef ENABLE_MSVA |
---|
[031acac] | 763 | sc->client_verify_method = mgs_cvm_msva; |
---|
[cf2b905] | 764 | #else |
---|
[031acac] | 765 | return "GnuTLSClientVerifyMethod: msva is not supported"; |
---|
[cf2b905] | 766 | #endif |
---|
| 767 | } else { |
---|
[031acac] | 768 | return "GnuTLSClientVerifyMethod: Invalid argument"; |
---|
[cf2b905] | 769 | } |
---|
| 770 | |
---|
| 771 | return NULL; |
---|
| 772 | } |
---|
| 773 | |
---|
[fd82e59] | 774 | const char *mgs_set_client_verify(cmd_parms * parms, |
---|
| 775 | void *dirconf, |
---|
| 776 | const char *arg) { |
---|
[e183628] | 777 | int mode; |
---|
| 778 | |
---|
| 779 | if (strcasecmp("none", arg) == 0 || strcasecmp("ignore", arg) == 0) { |
---|
[031acac] | 780 | mode = GNUTLS_CERT_IGNORE; |
---|
[e183628] | 781 | } else if (strcasecmp("optional", arg) == 0 |
---|
[031acac] | 782 | || strcasecmp("request", arg) == 0) { |
---|
| 783 | mode = GNUTLS_CERT_REQUEST; |
---|
[e183628] | 784 | } else if (strcasecmp("require", arg) == 0) { |
---|
[031acac] | 785 | mode = GNUTLS_CERT_REQUIRE; |
---|
[e183628] | 786 | } else { |
---|
[031acac] | 787 | return "GnuTLSClientVerify: Invalid argument"; |
---|
[e183628] | 788 | } |
---|
| 789 | |
---|
| 790 | /* This was set from a directory context */ |
---|
| 791 | if (parms->path) { |
---|
[fd82e59] | 792 | mgs_dirconf_rec *dc = (mgs_dirconf_rec *) dirconf; |
---|
[e183628] | 793 | dc->client_verify_mode = mode; |
---|
| 794 | } else { |
---|
[031acac] | 795 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
| 796 | ap_get_module_config(parms->server->module_config, |
---|
| 797 | &gnutls_module); |
---|
| 798 | sc->client_verify_mode = mode; |
---|
[e183628] | 799 | } |
---|
| 800 | |
---|
| 801 | return NULL; |
---|
[46b85d8] | 802 | } |
---|
| 803 | |
---|
[fd82e59] | 804 | const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[e183628] | 805 | const char *arg) { |
---|
| 806 | mgs_srvconf_rec *sc = |
---|
[031acac] | 807 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 808 | module_config, |
---|
| 809 | &gnutls_module); |
---|
[e183628] | 810 | |
---|
[031acac] | 811 | sc->x509_ca_file = ap_server_root_relative(parms->pool, arg); |
---|
[e183628] | 812 | |
---|
| 813 | return NULL; |
---|
[46b85d8] | 814 | } |
---|
| 815 | |
---|
[fd82e59] | 816 | const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[e183628] | 817 | const char *arg) { |
---|
| 818 | mgs_srvconf_rec *sc = |
---|
[031acac] | 819 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 820 | module_config, |
---|
| 821 | &gnutls_module); |
---|
[e183628] | 822 | |
---|
[031acac] | 823 | sc->pgp_ring_file = ap_server_root_relative(parms->pool, arg); |
---|
[e183628] | 824 | |
---|
| 825 | return NULL; |
---|
[e5bbda4] | 826 | } |
---|
| 827 | |
---|
[fd82e59] | 828 | const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[33826c5] | 829 | const char *arg) { |
---|
[671b64f] | 830 | |
---|
[031acac] | 831 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
| 832 | ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
[671b64f] | 833 | |
---|
[33826c5] | 834 | if (!strcasecmp(arg, "On")) { |
---|
[031acac] | 835 | sc->proxy_enabled = GNUTLS_ENABLED_TRUE; |
---|
[33826c5] | 836 | } else if (!strcasecmp(arg, "Off")) { |
---|
[031acac] | 837 | sc->proxy_enabled = GNUTLS_ENABLED_FALSE; |
---|
[33826c5] | 838 | } else { |
---|
[a2e3c33] | 839 | return "GnuTLSProxyEngine must be set to 'On' or 'Off'"; |
---|
[33826c5] | 840 | } |
---|
| 841 | |
---|
| 842 | return NULL; |
---|
| 843 | } |
---|
| 844 | |
---|
[fd82e59] | 845 | const char *mgs_set_enabled(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
[e183628] | 846 | const char *arg) { |
---|
| 847 | mgs_srvconf_rec *sc = |
---|
[031acac] | 848 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 849 | module_config, |
---|
| 850 | &gnutls_module); |
---|
[e183628] | 851 | if (!strcasecmp(arg, "On")) { |
---|
[031acac] | 852 | sc->enabled = GNUTLS_ENABLED_TRUE; |
---|
[e183628] | 853 | } else if (!strcasecmp(arg, "Off")) { |
---|
[031acac] | 854 | sc->enabled = GNUTLS_ENABLED_FALSE; |
---|
[e183628] | 855 | } else { |
---|
[031acac] | 856 | return "GnuTLSEnable must be set to 'On' or 'Off'"; |
---|
[e183628] | 857 | } |
---|
| 858 | |
---|
| 859 | return NULL; |
---|
[7bebb42] | 860 | } |
---|
| 861 | |
---|
[fd82e59] | 862 | const char *mgs_set_export_certificates_size(cmd_parms * parms, void *dummy __attribute__((unused)), const char *arg) { |
---|
[7d1ab49] | 863 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
| 864 | if (!strcasecmp(arg, "On")) { |
---|
[031acac] | 865 | sc->export_certificates_size = 16 * 1024; |
---|
[7d1ab49] | 866 | } else if (!strcasecmp(arg, "Off")) { |
---|
[031acac] | 867 | sc->export_certificates_size = 0; |
---|
[7d1ab49] | 868 | } else { |
---|
[031acac] | 869 | char *endptr; |
---|
| 870 | sc->export_certificates_size = strtol(arg, &endptr, 10); |
---|
| 871 | while (apr_isspace(*endptr)) |
---|
| 872 | endptr++; |
---|
| 873 | if (*endptr == '\0' || *endptr == 'b' || *endptr == 'B') { |
---|
| 874 | ; |
---|
| 875 | } else if (*endptr == 'k' || *endptr == 'K') { |
---|
| 876 | sc->export_certificates_size *= 1024; |
---|
| 877 | } else { |
---|
| 878 | return |
---|
| 879 | "GnuTLSExportCertificates must be set to a size (in bytes) or 'On' or 'Off'"; |
---|
| 880 | } |
---|
[7d1ab49] | 881 | } |
---|
| 882 | |
---|
| 883 | return NULL; |
---|
| 884 | } |
---|
| 885 | |
---|
[e183628] | 886 | |
---|
[f030883] | 887 | |
---|
| 888 | /* |
---|
[4133f2d] | 889 | * Store GnuTLS priority strings. Used for GnuTLSPriorities and |
---|
| 890 | * GnuTLSProxyPriorities. |
---|
[f030883] | 891 | */ |
---|
| 892 | const char *mgs_set_priorities(cmd_parms * parms, |
---|
| 893 | void *dummy __attribute__((unused)), |
---|
| 894 | const char *arg) |
---|
| 895 | { |
---|
[671b64f] | 896 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
[f030883] | 897 | ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
| 898 | |
---|
| 899 | if (!strcasecmp(parms->directive->directive, "GnuTLSPriorities")) |
---|
[2cde026d] | 900 | sc->priorities_str = apr_pstrdup(parms->pool, arg); |
---|
[f030883] | 901 | else if (!strcasecmp(parms->directive->directive, "GnuTLSProxyPriorities")) |
---|
[4133f2d] | 902 | sc->proxy_priorities_str = apr_pstrdup(parms->pool, arg); |
---|
[f030883] | 903 | else |
---|
| 904 | /* Can't happen unless there's a serious bug in mod_gnutls or Apache */ |
---|
| 905 | return apr_psprintf(parms->pool, |
---|
| 906 | "mod_gnutls: %s called for invalid option '%s'", |
---|
| 907 | __func__, parms->directive->directive); |
---|
[3b4c0d0] | 908 | |
---|
[e183628] | 909 | return NULL; |
---|
[46b85d8] | 910 | } |
---|
| 911 | |
---|
[e183628] | 912 | |
---|
| 913 | |
---|
[259e835] | 914 | const char *mgs_set_pin(cmd_parms * parms, void *dummy __attribute__((unused)), |
---|
| 915 | const char *arg) |
---|
[031acac] | 916 | { |
---|
[e183628] | 917 | |
---|
[031acac] | 918 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
| 919 | ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
[beb14d9] | 920 | |
---|
[031acac] | 921 | sc->pin = apr_pstrdup(parms->pool, arg); |
---|
[0de1839] | 922 | |
---|
[e183628] | 923 | return NULL; |
---|
[46b85d8] | 924 | } |
---|
[0de1839] | 925 | |
---|
[259e835] | 926 | const char *mgs_set_srk_pin(cmd_parms * parms, |
---|
| 927 | void *dummy __attribute__((unused)), |
---|
| 928 | const char *arg) |
---|
[031acac] | 929 | { |
---|
[e183628] | 930 | |
---|
[031acac] | 931 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
| 932 | ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
[e183628] | 933 | |
---|
[031acac] | 934 | sc->srk_pin = apr_pstrdup(parms->pool, arg); |
---|
[e183628] | 935 | |
---|
[031acac] | 936 | return NULL; |
---|
| 937 | } |
---|
| 938 | |
---|
[2cde026d] | 939 | |
---|
| 940 | |
---|
[031acac] | 941 | static mgs_srvconf_rec *_mgs_config_server_create(apr_pool_t * p, |
---|
[259e835] | 942 | char **err __attribute__((unused))) |
---|
[031acac] | 943 | { |
---|
| 944 | mgs_srvconf_rec *sc = apr_pcalloc(p, sizeof(*sc)); |
---|
| 945 | |
---|
| 946 | sc->enabled = GNUTLS_ENABLED_UNSET; |
---|
[787dab7] | 947 | |
---|
[e183628] | 948 | sc->privkey_x509 = NULL; |
---|
[031acac] | 949 | sc->privkey_pgp = NULL; |
---|
[3b4c0d0] | 950 | sc->certs_x509_chain_num = 0; |
---|
[87f1ed2] | 951 | sc->p11_module = NULL; |
---|
[2cde026d] | 952 | sc->pin = NULL; |
---|
| 953 | sc->priorities_str = NULL; |
---|
[031acac] | 954 | sc->cache_timeout = -1; /* -1 means "unset" */ |
---|
[040387c] | 955 | sc->cache_type = mgs_cache_unset; |
---|
[8400c2e] | 956 | sc->cache_config = NULL; |
---|
[040387c] | 957 | sc->tickets = GNUTLS_ENABLED_UNSET; |
---|
| 958 | sc->priorities = NULL; |
---|
| 959 | sc->dh_params = NULL; |
---|
| 960 | sc->proxy_enabled = GNUTLS_ENABLED_UNSET; |
---|
[2aaf4f5] | 961 | sc->export_certificates_size = -1; |
---|
[671b64f] | 962 | sc->client_verify_method = mgs_cvm_unset; |
---|
| 963 | |
---|
[2cde026d] | 964 | sc->proxy_x509_key_file = NULL; |
---|
| 965 | sc->proxy_x509_cert_file = NULL; |
---|
| 966 | sc->proxy_x509_ca_file = NULL; |
---|
| 967 | sc->proxy_x509_crl_file = NULL; |
---|
[4133f2d] | 968 | sc->proxy_priorities_str = NULL; |
---|
[2cde026d] | 969 | sc->proxy_priorities = NULL; |
---|
| 970 | |
---|
[040387c] | 971 | /* this relies on GnuTLS never changing the gnutls_certificate_request_t enum to define -1 */ |
---|
[671b64f] | 972 | sc->client_verify_mode = -1; |
---|
[7bebb42] | 973 | |
---|
[040387c] | 974 | return sc; |
---|
| 975 | } |
---|
| 976 | |
---|
[fd82e59] | 977 | void *mgs_config_server_create(apr_pool_t * p, |
---|
| 978 | server_rec * s __attribute__((unused))) { |
---|
[040387c] | 979 | char *err = NULL; |
---|
| 980 | mgs_srvconf_rec *sc = _mgs_config_server_create(p, &err); |
---|
[031acac] | 981 | if (sc) |
---|
| 982 | return sc; |
---|
| 983 | else |
---|
| 984 | return err; |
---|
[040387c] | 985 | } |
---|
| 986 | |
---|
| 987 | #define gnutls_srvconf_merge(t, unset) sc->t = (add->t == unset) ? base->t : add->t |
---|
| 988 | #define gnutls_srvconf_assign(t) sc->t = add->t |
---|
| 989 | |
---|
[031acac] | 990 | void *mgs_config_server_merge(apr_pool_t * p, void *BASE, void *ADD) |
---|
| 991 | { |
---|
[040387c] | 992 | int i; |
---|
| 993 | char *err = NULL; |
---|
[031acac] | 994 | mgs_srvconf_rec *base = (mgs_srvconf_rec *) BASE; |
---|
| 995 | mgs_srvconf_rec *add = (mgs_srvconf_rec *) ADD; |
---|
[040387c] | 996 | mgs_srvconf_rec *sc = _mgs_config_server_create(p, &err); |
---|
[031acac] | 997 | if (NULL == sc) |
---|
| 998 | return err; |
---|
[040387c] | 999 | |
---|
| 1000 | gnutls_srvconf_merge(enabled, GNUTLS_ENABLED_UNSET); |
---|
| 1001 | gnutls_srvconf_merge(tickets, GNUTLS_ENABLED_UNSET); |
---|
| 1002 | gnutls_srvconf_merge(proxy_enabled, GNUTLS_ENABLED_UNSET); |
---|
[2aaf4f5] | 1003 | gnutls_srvconf_merge(export_certificates_size, -1); |
---|
[cf2b905] | 1004 | gnutls_srvconf_merge(client_verify_method, mgs_cvm_unset); |
---|
[040387c] | 1005 | gnutls_srvconf_merge(client_verify_mode, -1); |
---|
| 1006 | gnutls_srvconf_merge(srp_tpasswd_file, NULL); |
---|
| 1007 | gnutls_srvconf_merge(srp_tpasswd_conf_file, NULL); |
---|
[031acac] | 1008 | gnutls_srvconf_merge(x509_cert_file, NULL); |
---|
| 1009 | |
---|
| 1010 | gnutls_srvconf_merge(x509_key_file, NULL); |
---|
| 1011 | gnutls_srvconf_merge(x509_ca_file, NULL); |
---|
[87f1ed2] | 1012 | gnutls_srvconf_merge(p11_module, NULL); |
---|
[031acac] | 1013 | gnutls_srvconf_merge(pin, NULL); |
---|
| 1014 | gnutls_srvconf_merge(pgp_cert_file, NULL); |
---|
| 1015 | gnutls_srvconf_merge(pgp_key_file, NULL); |
---|
| 1016 | gnutls_srvconf_merge(pgp_ring_file, NULL); |
---|
| 1017 | gnutls_srvconf_merge(dh_file, NULL); |
---|
| 1018 | gnutls_srvconf_merge(priorities_str, NULL); |
---|
[040387c] | 1019 | |
---|
[0de1839] | 1020 | gnutls_srvconf_merge(proxy_x509_key_file, NULL); |
---|
| 1021 | gnutls_srvconf_merge(proxy_x509_cert_file, NULL); |
---|
| 1022 | gnutls_srvconf_merge(proxy_x509_ca_file, NULL); |
---|
[809c422] | 1023 | gnutls_srvconf_merge(proxy_x509_crl_file, NULL); |
---|
[4133f2d] | 1024 | gnutls_srvconf_merge(proxy_priorities_str, NULL); |
---|
[f030883] | 1025 | gnutls_srvconf_merge(proxy_priorities, NULL); |
---|
[0de1839] | 1026 | |
---|
[040387c] | 1027 | /* FIXME: the following items are pre-allocated, and should be |
---|
| 1028 | * properly disposed of before assigning in order to avoid leaks; |
---|
| 1029 | * so at the moment, we can't actually have them in the config. |
---|
[031acac] | 1030 | * what happens during de-allocation? */ |
---|
[2cde026d] | 1031 | /* TODO: mgs_load_files takes care of most of these now, verify |
---|
| 1032 | * and clean up the following lines */ |
---|
[031acac] | 1033 | gnutls_srvconf_assign(ca_list); |
---|
| 1034 | gnutls_srvconf_assign(ca_list_size); |
---|
| 1035 | gnutls_srvconf_assign(cert_pgp); |
---|
| 1036 | gnutls_srvconf_assign(cert_crt_pgp); |
---|
| 1037 | gnutls_srvconf_assign(pgp_list); |
---|
[040387c] | 1038 | gnutls_srvconf_assign(certs); |
---|
| 1039 | gnutls_srvconf_assign(anon_creds); |
---|
| 1040 | gnutls_srvconf_assign(srp_creds); |
---|
| 1041 | gnutls_srvconf_assign(certs_x509_chain); |
---|
[031acac] | 1042 | gnutls_srvconf_assign(certs_x509_crt_chain); |
---|
[040387c] | 1043 | gnutls_srvconf_assign(certs_x509_chain_num); |
---|
| 1044 | |
---|
| 1045 | /* how do these get transferred cleanly before the data from ADD |
---|
| 1046 | * goes away? */ |
---|
| 1047 | gnutls_srvconf_assign(cert_cn); |
---|
| 1048 | for (i = 0; i < MAX_CERT_SAN; i++) |
---|
[031acac] | 1049 | gnutls_srvconf_assign(cert_san[i]); |
---|
[7bebb42] | 1050 | |
---|
[e183628] | 1051 | return sc; |
---|
[46b85d8] | 1052 | } |
---|
| 1053 | |
---|
[040387c] | 1054 | #undef gnutls_srvconf_merge |
---|
| 1055 | #undef gnutls_srvconf_assign |
---|
| 1056 | |
---|
[fd82e59] | 1057 | void *mgs_config_dir_merge(apr_pool_t * p, |
---|
| 1058 | void *basev __attribute__((unused)), |
---|
| 1059 | void *addv __attribute__((unused))) { |
---|
[e183628] | 1060 | mgs_dirconf_rec *new; |
---|
| 1061 | /* mgs_dirconf_rec *base = (mgs_dirconf_rec *) basev; */ |
---|
| 1062 | mgs_dirconf_rec *add = (mgs_dirconf_rec *) addv; |
---|
[e02dd8c] | 1063 | |
---|
[031acac] | 1064 | new = (mgs_dirconf_rec *) apr_pcalloc(p, sizeof(mgs_dirconf_rec)); |
---|
[e183628] | 1065 | new->client_verify_mode = add->client_verify_mode; |
---|
| 1066 | return new; |
---|
[84cb5b2] | 1067 | } |
---|
| 1068 | |
---|
[fd82e59] | 1069 | void *mgs_config_dir_create(apr_pool_t * p, |
---|
| 1070 | char *dir __attribute__((unused))) { |
---|
[e183628] | 1071 | mgs_dirconf_rec *dc = apr_palloc(p, sizeof (*dc)); |
---|
| 1072 | dc->client_verify_mode = -1; |
---|
| 1073 | return dc; |
---|
[46b85d8] | 1074 | } |
---|
[040387c] | 1075 | |
---|
[2cde026d] | 1076 | |
---|
| 1077 | |
---|
[0de1839] | 1078 | /* |
---|
| 1079 | * Store paths to proxy credentials |
---|
| 1080 | * |
---|
| 1081 | * This function copies the paths provided in the configuration file |
---|
| 1082 | * into the server configuration. The post configuration hook takes |
---|
| 1083 | * care of actually loading the credentials, which means than invalid |
---|
| 1084 | * paths or the like will be detected there. |
---|
| 1085 | */ |
---|
| 1086 | const char *mgs_store_cred_path(cmd_parms * parms, |
---|
| 1087 | void *dummy __attribute__((unused)), |
---|
| 1088 | const char *arg) |
---|
| 1089 | { |
---|
| 1090 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
| 1091 | ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
| 1092 | |
---|
| 1093 | /* parms->directive->directive contains the directive string */ |
---|
| 1094 | if (!strcasecmp(parms->directive->directive, "GnuTLSProxyKeyFile")) |
---|
| 1095 | sc->proxy_x509_key_file = apr_pstrdup(parms->pool, arg); |
---|
| 1096 | else if (!strcasecmp(parms->directive->directive, |
---|
| 1097 | "GnuTLSProxyCertificateFile")) |
---|
| 1098 | sc->proxy_x509_cert_file = apr_pstrdup(parms->pool, arg); |
---|
| 1099 | else if (!strcasecmp(parms->directive->directive, "GnuTLSProxyCAFile")) |
---|
| 1100 | sc->proxy_x509_ca_file = apr_pstrdup(parms->pool, arg); |
---|
[809c422] | 1101 | else if (!strcasecmp(parms->directive->directive, "GnuTLSProxyCRLFile")) |
---|
| 1102 | sc->proxy_x509_crl_file = apr_pstrdup(parms->pool, arg); |
---|
[0de1839] | 1103 | return NULL; |
---|
| 1104 | } |
---|
[87f1ed2] | 1105 | |
---|
| 1106 | |
---|
| 1107 | |
---|
| 1108 | /* |
---|
| 1109 | * Record additional PKCS #11 module to load. Note that the value is |
---|
| 1110 | * only used in the base config, settings in virtual hosts are |
---|
| 1111 | * ignored. |
---|
| 1112 | */ |
---|
| 1113 | const char *mgs_set_p11_module(cmd_parms * parms, |
---|
| 1114 | void *dummy __attribute__((unused)), |
---|
| 1115 | const char *arg) |
---|
| 1116 | { |
---|
| 1117 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
| 1118 | ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
| 1119 | sc->p11_module = apr_pstrdup(parms->pool, arg); |
---|
| 1120 | return NULL; |
---|
| 1121 | } |
---|