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