[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 | |
---|
[031acac] | 30 | static int pin_callback(void *user, int attempt, const char *token_url, |
---|
| 31 | const char *token_label, unsigned int flags, |
---|
| 32 | char *pin, size_t pin_max) |
---|
| 33 | { |
---|
| 34 | mgs_srvconf_rec *sc = user; |
---|
| 35 | |
---|
| 36 | if (sc->pin == NULL || flags & GNUTLS_PIN_FINAL_TRY || |
---|
| 37 | flags & GNUTLS_PIN_WRONG) { |
---|
| 38 | return -1; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | if (token_label && strcmp(token_label, "SRK") == 0) { |
---|
| 42 | snprintf(pin, pin_max, "%s", sc->srk_pin); |
---|
| 43 | } else { |
---|
| 44 | snprintf(pin, pin_max, "%s", sc->pin); |
---|
| 45 | } |
---|
| 46 | return 0; |
---|
| 47 | } |
---|
| 48 | |
---|
[7bebb42] | 49 | static int load_datum_from_file(apr_pool_t * pool, |
---|
[031acac] | 50 | const char *file, gnutls_datum_t * data) |
---|
| 51 | { |
---|
[e183628] | 52 | apr_file_t *fp; |
---|
| 53 | apr_finfo_t finfo; |
---|
| 54 | apr_status_t rv; |
---|
| 55 | apr_size_t br = 0; |
---|
[7bebb42] | 56 | |
---|
[e183628] | 57 | rv = apr_file_open(&fp, file, APR_READ | APR_BINARY, |
---|
[031acac] | 58 | APR_OS_DEFAULT, pool); |
---|
[e183628] | 59 | if (rv != APR_SUCCESS) { |
---|
[031acac] | 60 | return rv; |
---|
[e183628] | 61 | } |
---|
[7bebb42] | 62 | |
---|
[e183628] | 63 | rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, fp); |
---|
[7bebb42] | 64 | |
---|
[e183628] | 65 | if (rv != APR_SUCCESS) { |
---|
[031acac] | 66 | return rv; |
---|
[e183628] | 67 | } |
---|
[7bebb42] | 68 | |
---|
[e183628] | 69 | data->data = apr_palloc(pool, finfo.size + 1); |
---|
| 70 | rv = apr_file_read_full(fp, data->data, finfo.size, &br); |
---|
[7bebb42] | 71 | |
---|
[e183628] | 72 | if (rv != APR_SUCCESS) { |
---|
[031acac] | 73 | return rv; |
---|
[e183628] | 74 | } |
---|
| 75 | apr_file_close(fp); |
---|
[7bebb42] | 76 | |
---|
[e183628] | 77 | data->data[br] = '\0'; |
---|
| 78 | data->size = br; |
---|
[7bebb42] | 79 | |
---|
[e183628] | 80 | return 0; |
---|
[46b85d8] | 81 | } |
---|
| 82 | |
---|
[031acac] | 83 | /* 2048-bit group parameters from SRP specification */ |
---|
| 84 | const char static_dh_params[] = "-----BEGIN DH PARAMETERS-----\n" |
---|
| 85 | "MIIBBwKCAQCsa9tBMkqam/Fm3l4TiVgvr3K2ZRmH7gf8MZKUPbVgUKNzKcu0oJnt\n" |
---|
| 86 | "gZPgdXdnoT3VIxKrSwMxDc1/SKnaBP1Q6Ag5ae23Z7DPYJUXmhY6s2YaBfvV+qro\n" |
---|
| 87 | "KRipli8Lk7hV+XmT7Jde6qgNdArb9P90c1nQQdXDPqcdKB5EaxR3O8qXtDoj+4AW\n" |
---|
| 88 | "dr0gekNsZIHx0rkHhxdGGludMuaI+HdIVEUjtSSw1X1ep3onddLs+gMs+9v1L7N4\n" |
---|
| 89 | "YWAnkATleuavh05zA85TKZzMBBx7wwjYKlaY86jQw4JxrjX46dv7tpS1yAPYn3rk\n" |
---|
| 90 | "Nd4jbVJfVHWbZeNy/NaO8g+nER+eSv9zAgEC\n" |
---|
| 91 | "-----END DH PARAMETERS-----\n"; |
---|
| 92 | |
---|
| 93 | int mgs_load_files(apr_pool_t * p, server_rec * s) |
---|
| 94 | { |
---|
[e183628] | 95 | apr_pool_t *spool; |
---|
[031acac] | 96 | const char *file; |
---|
| 97 | gnutls_datum_t data; |
---|
| 98 | int ret; |
---|
[e183628] | 99 | mgs_srvconf_rec *sc = |
---|
[031acac] | 100 | (mgs_srvconf_rec *) ap_get_module_config(s->module_config, |
---|
| 101 | &gnutls_module); |
---|
[e183628] | 102 | |
---|
[031acac] | 103 | apr_pool_create(&spool, p); |
---|
[e183628] | 104 | |
---|
[031acac] | 105 | sc->cert_pgp = apr_pcalloc(p, sizeof(sc->cert_pgp[0])); |
---|
| 106 | sc->cert_crt_pgp = apr_pcalloc(p, sizeof(sc->cert_crt_pgp[0])); |
---|
| 107 | sc->certs_x509_chain = |
---|
| 108 | apr_pcalloc(p, MAX_CHAIN_SIZE * sizeof(sc->certs_x509_chain[0])); |
---|
| 109 | sc->certs_x509_crt_chain = |
---|
| 110 | apr_pcalloc(p, |
---|
| 111 | MAX_CHAIN_SIZE * sizeof(sc->certs_x509_crt_chain[0])); |
---|
[e183628] | 112 | |
---|
[031acac] | 113 | ret = gnutls_certificate_allocate_credentials(&sc->certs); |
---|
| 114 | if (ret < 0) { |
---|
| 115 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 116 | "GnuTLS: Failed to initialize" ": (%d) %s", ret, |
---|
| 117 | gnutls_strerror(ret)); |
---|
| 118 | ret = -1; |
---|
| 119 | goto cleanup; |
---|
[e183628] | 120 | } |
---|
| 121 | |
---|
[031acac] | 122 | ret = gnutls_anon_allocate_server_credentials(&sc->anon_creds); |
---|
[e183628] | 123 | if (ret < 0) { |
---|
[031acac] | 124 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 125 | "GnuTLS: Failed to initialize" ": (%d) %s", ret, |
---|
| 126 | gnutls_strerror(ret)); |
---|
| 127 | ret = -1; |
---|
| 128 | goto cleanup; |
---|
[e183628] | 129 | } |
---|
| 130 | |
---|
[031acac] | 131 | /* Load SRP parameters */ |
---|
| 132 | #ifdef ENABLE_SRP |
---|
| 133 | ret = gnutls_srp_allocate_server_credentials(&sc->srp_creds); |
---|
[e183628] | 134 | if (ret < 0) { |
---|
[031acac] | 135 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 136 | "GnuTLS: Failed to initialize" ": (%d) %s", ret, |
---|
| 137 | gnutls_strerror(ret)); |
---|
| 138 | ret = -1; |
---|
| 139 | goto cleanup; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | if (sc->srp_tpasswd_conf_file != NULL && sc->srp_tpasswd_file != NULL) { |
---|
| 143 | ret = gnutls_srp_set_server_credentials_file |
---|
| 144 | (sc->srp_creds, sc->srp_tpasswd_file, |
---|
| 145 | sc->srp_tpasswd_conf_file); |
---|
| 146 | |
---|
| 147 | if (ret < 0 && sc->enabled == GNUTLS_ENABLED_TRUE) { |
---|
| 148 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, |
---|
| 149 | s, |
---|
| 150 | "GnuTLS: Host '%s:%d' is missing a " |
---|
| 151 | "SRP password or conf File!", |
---|
| 152 | s->server_hostname, s->port); |
---|
| 153 | ret = -1; |
---|
| 154 | goto cleanup; |
---|
| 155 | } |
---|
[e183628] | 156 | } |
---|
[031acac] | 157 | #endif |
---|
[e183628] | 158 | |
---|
[031acac] | 159 | ret = gnutls_dh_params_init(&sc->dh_params); |
---|
| 160 | if (ret < 0) { |
---|
| 161 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 162 | "GnuTLS: Failed to initialize" |
---|
| 163 | ": (%d) %s", ret, gnutls_strerror(ret)); |
---|
| 164 | ret = -1; |
---|
| 165 | goto cleanup; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | /* Load DH parameters */ |
---|
| 169 | if (sc->dh_file) { |
---|
| 170 | if (load_datum_from_file(spool, sc->dh_file, &data) != 0) { |
---|
| 171 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 172 | "GnuTLS: Error Reading " "DH params '%s'", sc->dh_file); |
---|
| 173 | ret = -1; |
---|
| 174 | goto cleanup; |
---|
| 175 | } |
---|
[7bebb42] | 176 | |
---|
[3b4c0d0] | 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 | |
---|
| 424 | ret = |
---|
| 425 | gnutls_privkey_import_openpgp_raw(sc->privkey_pgp, &data, |
---|
| 426 | GNUTLS_OPENPGP_FMT_BASE64, |
---|
| 427 | NULL, NULL); |
---|
| 428 | if (ret != 0) { |
---|
| 429 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 430 | "GnuTLS: Failed to Import " |
---|
| 431 | "PGP Private Key '%s': (%d) %s", |
---|
| 432 | sc->pgp_key_file, ret, gnutls_strerror(ret)); |
---|
| 433 | ret = -1; |
---|
| 434 | goto cleanup; |
---|
| 435 | } |
---|
[e183628] | 436 | } |
---|
| 437 | |
---|
[031acac] | 438 | /* Load the keyring file */ |
---|
| 439 | if (sc->pgp_ring_file) { |
---|
| 440 | if (load_datum_from_file(spool, sc->pgp_ring_file, &data) != 0) { |
---|
| 441 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 442 | "GnuTLS: Error Reading " "Keyring File '%s'", |
---|
| 443 | sc->pgp_ring_file); |
---|
| 444 | ret = -1; |
---|
| 445 | goto cleanup; |
---|
| 446 | } |
---|
[e183628] | 447 | |
---|
[031acac] | 448 | ret = gnutls_openpgp_keyring_init(&sc->pgp_list); |
---|
| 449 | if (ret < 0) { |
---|
| 450 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 451 | "GnuTLS: Failed to initialize" |
---|
| 452 | "keyring: (%d) %s", ret, gnutls_strerror(ret)); |
---|
| 453 | ret = -1; |
---|
| 454 | goto cleanup; |
---|
[3b4c0d0] | 455 | } |
---|
[e183628] | 456 | |
---|
[031acac] | 457 | ret = gnutls_openpgp_keyring_import(sc->pgp_list, &data, |
---|
| 458 | GNUTLS_OPENPGP_FMT_BASE64); |
---|
| 459 | if (ret < 0) { |
---|
| 460 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 461 | "GnuTLS: Failed to load " |
---|
| 462 | "Keyring File '%s': (%d) %s", sc->pgp_ring_file, |
---|
| 463 | ret, gnutls_strerror(ret)); |
---|
| 464 | ret = -1; |
---|
| 465 | goto cleanup; |
---|
| 466 | } |
---|
[e183628] | 467 | } |
---|
[3b4c0d0] | 468 | |
---|
[031acac] | 469 | if (sc->priorities_str) { |
---|
| 470 | const char *err; |
---|
| 471 | ret = |
---|
| 472 | gnutls_priority_init(&sc->priorities, sc->priorities_str, |
---|
| 473 | &err); |
---|
| 474 | |
---|
| 475 | if (ret < 0) { |
---|
| 476 | if (ret == GNUTLS_E_INVALID_REQUEST) { |
---|
| 477 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 478 | "GnuTLS: Syntax error parsing priorities string at: %s", |
---|
| 479 | err); |
---|
| 480 | } else { |
---|
| 481 | ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, s, |
---|
| 482 | "GnuTLS: error parsing priorities string"); |
---|
| 483 | |
---|
| 484 | } |
---|
| 485 | ret = -1; |
---|
| 486 | goto cleanup; |
---|
| 487 | } |
---|
| 488 | } |
---|
| 489 | |
---|
| 490 | ret = 0; |
---|
| 491 | cleanup: |
---|
[e183628] | 492 | apr_pool_destroy(spool); |
---|
[3b4c0d0] | 493 | |
---|
[031acac] | 494 | return ret; |
---|
[46b85d8] | 495 | } |
---|
| 496 | |
---|
[031acac] | 497 | int mgs_pkcs11_reinit(server_rec * base_server) |
---|
| 498 | { |
---|
[e183628] | 499 | int ret; |
---|
[031acac] | 500 | server_rec *s; |
---|
| 501 | mgs_srvconf_rec *sc; |
---|
[e183628] | 502 | |
---|
[031acac] | 503 | gnutls_pkcs11_reinit(); |
---|
[e183628] | 504 | |
---|
[031acac] | 505 | for (s = base_server; s; s = s->next) { |
---|
| 506 | sc = (mgs_srvconf_rec *) ap_get_module_config(s->module_config, &gnutls_module); |
---|
[e183628] | 507 | |
---|
[031acac] | 508 | /* gnutls caches the session in a private key, so we need to open |
---|
| 509 | * a new one */ |
---|
| 510 | if (sc->x509_key_file && gnutls_url_is_supported(sc->x509_key_file) != 0) { |
---|
| 511 | gnutls_privkey_deinit(sc->privkey_x509); |
---|
[e183628] | 512 | |
---|
[031acac] | 513 | ret = gnutls_privkey_init(&sc->privkey_x509); |
---|
| 514 | if (ret < 0) { |
---|
| 515 | ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, |
---|
| 516 | "GnuTLS: Failed to initialize: (%d) %s", ret, |
---|
| 517 | gnutls_strerror(ret)); |
---|
| 518 | goto fail; |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | gnutls_privkey_set_pin_function(sc->privkey_x509, pin_callback, sc); |
---|
| 522 | |
---|
| 523 | ret = gnutls_privkey_import_url(sc->privkey_x509, sc->x509_key_file, 0); |
---|
| 524 | if (ret < 0) { |
---|
| 525 | ap_log_error(APLOG_MARK, APLOG_EMERG, 0, s, |
---|
| 526 | "GnuTLS: Failed to Re-Import Private Key URL '%s': (%d) %s", |
---|
| 527 | sc->x509_key_file, ret, gnutls_strerror(ret)); |
---|
| 528 | goto fail; |
---|
| 529 | } |
---|
| 530 | } |
---|
[e183628] | 531 | } |
---|
| 532 | |
---|
[031acac] | 533 | return 0; |
---|
| 534 | |
---|
| 535 | fail: |
---|
| 536 | gnutls_privkey_deinit(sc->privkey_x509); |
---|
| 537 | return -1; |
---|
| 538 | } |
---|
| 539 | |
---|
| 540 | const char *mgs_set_dh_file(cmd_parms * parms, void *dummy, |
---|
| 541 | const char *arg) |
---|
| 542 | { |
---|
| 543 | mgs_srvconf_rec *sc = |
---|
| 544 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 545 | module_config, |
---|
| 546 | &gnutls_module); |
---|
| 547 | |
---|
| 548 | sc->dh_file = ap_server_root_relative(parms->pool, arg); |
---|
| 549 | |
---|
[e183628] | 550 | return NULL; |
---|
[e5bbda4] | 551 | } |
---|
| 552 | |
---|
[031acac] | 553 | const char *mgs_set_cert_file(cmd_parms * parms, void *dummy, |
---|
| 554 | const char *arg) |
---|
| 555 | { |
---|
| 556 | |
---|
[e183628] | 557 | mgs_srvconf_rec *sc = |
---|
[031acac] | 558 | (mgs_srvconf_rec *) ap_get_module_config(parms-> |
---|
| 559 | server->module_config, |
---|
| 560 | &gnutls_module); |
---|
[e183628] | 561 | |
---|
[031acac] | 562 | sc->x509_cert_file = apr_pstrdup(parms->pool, arg); |
---|
[e183628] | 563 | |
---|
[031acac] | 564 | return NULL; |
---|
| 565 | |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | const char *mgs_set_key_file(cmd_parms * parms, void *dummy, |
---|
| 569 | const char *arg) |
---|
| 570 | { |
---|
| 571 | |
---|
| 572 | mgs_srvconf_rec *sc = |
---|
| 573 | (mgs_srvconf_rec *) ap_get_module_config(parms-> |
---|
| 574 | server->module_config, |
---|
| 575 | &gnutls_module); |
---|
| 576 | |
---|
| 577 | sc->x509_key_file = apr_pstrdup(parms->pool, arg); |
---|
| 578 | |
---|
| 579 | return NULL; |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | const char *mgs_set_pgpcert_file(cmd_parms * parms, void *dummy, |
---|
| 583 | const char *arg) |
---|
| 584 | { |
---|
| 585 | mgs_srvconf_rec *sc = |
---|
| 586 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 587 | module_config, |
---|
| 588 | &gnutls_module); |
---|
| 589 | |
---|
| 590 | sc->pgp_cert_file = ap_server_root_relative(parms->pool, arg); |
---|
| 591 | |
---|
| 592 | return NULL; |
---|
| 593 | } |
---|
| 594 | |
---|
| 595 | const char *mgs_set_pgpkey_file(cmd_parms * parms, void *dummy, |
---|
| 596 | const char *arg) |
---|
| 597 | { |
---|
| 598 | mgs_srvconf_rec *sc = |
---|
| 599 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 600 | module_config, |
---|
| 601 | &gnutls_module); |
---|
| 602 | |
---|
| 603 | sc->pgp_key_file = ap_server_root_relative(parms->pool, arg); |
---|
[e183628] | 604 | |
---|
| 605 | return NULL; |
---|
[e5bbda4] | 606 | } |
---|
| 607 | |
---|
[ae233c2] | 608 | const char *mgs_set_tickets(cmd_parms * parms, void *dummy, |
---|
[031acac] | 609 | const char *arg) |
---|
| 610 | { |
---|
[e183628] | 611 | mgs_srvconf_rec *sc = |
---|
[031acac] | 612 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 613 | module_config, |
---|
| 614 | &gnutls_module); |
---|
[e183628] | 615 | |
---|
| 616 | sc->tickets = 0; |
---|
| 617 | if (strcasecmp("on", arg) == 0) { |
---|
[031acac] | 618 | sc->tickets = 1; |
---|
[e183628] | 619 | } |
---|
| 620 | |
---|
| 621 | return NULL; |
---|
[ae233c2] | 622 | } |
---|
| 623 | |
---|
[e5bbda4] | 624 | |
---|
[787dab7] | 625 | #ifdef ENABLE_SRP |
---|
| 626 | |
---|
[7bebb42] | 627 | const char *mgs_set_srp_tpasswd_file(cmd_parms * parms, void *dummy, |
---|
[031acac] | 628 | const char *arg) |
---|
| 629 | { |
---|
[e183628] | 630 | mgs_srvconf_rec *sc = |
---|
[031acac] | 631 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 632 | module_config, |
---|
| 633 | &gnutls_module); |
---|
[7bebb42] | 634 | |
---|
[e183628] | 635 | sc->srp_tpasswd_file = ap_server_root_relative(parms->pool, arg); |
---|
[7bebb42] | 636 | |
---|
[e183628] | 637 | return NULL; |
---|
[7bebb42] | 638 | } |
---|
| 639 | |
---|
| 640 | const char *mgs_set_srp_tpasswd_conf_file(cmd_parms * parms, void *dummy, |
---|
[031acac] | 641 | const char *arg) |
---|
| 642 | { |
---|
[e183628] | 643 | mgs_srvconf_rec *sc = |
---|
[031acac] | 644 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 645 | module_config, |
---|
| 646 | &gnutls_module); |
---|
[7bebb42] | 647 | |
---|
[031acac] | 648 | sc->srp_tpasswd_conf_file = ap_server_root_relative(parms->pool, arg); |
---|
[7bebb42] | 649 | |
---|
[e183628] | 650 | return NULL; |
---|
[7bebb42] | 651 | } |
---|
| 652 | |
---|
[787dab7] | 653 | #endif |
---|
| 654 | |
---|
[46b85d8] | 655 | const char *mgs_set_cache(cmd_parms * parms, void *dummy, |
---|
[031acac] | 656 | const char *type, const char *arg) |
---|
| 657 | { |
---|
[e183628] | 658 | const char *err; |
---|
| 659 | mgs_srvconf_rec *sc = |
---|
[031acac] | 660 | ap_get_module_config(parms->server->module_config, |
---|
| 661 | &gnutls_module); |
---|
[e183628] | 662 | if ((err = ap_check_cmd_context(parms, GLOBAL_ONLY))) { |
---|
[031acac] | 663 | return err; |
---|
[e183628] | 664 | } |
---|
| 665 | |
---|
| 666 | if (strcasecmp("none", type) == 0) { |
---|
[031acac] | 667 | sc->cache_type = mgs_cache_none; |
---|
| 668 | sc->cache_config = NULL; |
---|
| 669 | return NULL; |
---|
[e183628] | 670 | } else if (strcasecmp("dbm", type) == 0) { |
---|
[031acac] | 671 | sc->cache_type = mgs_cache_dbm; |
---|
[e183628] | 672 | } else if (strcasecmp("gdbm", type) == 0) { |
---|
[031acac] | 673 | sc->cache_type = mgs_cache_gdbm; |
---|
[e183628] | 674 | } |
---|
[46b85d8] | 675 | #if HAVE_APR_MEMCACHE |
---|
[e183628] | 676 | else if (strcasecmp("memcache", type) == 0) { |
---|
[031acac] | 677 | sc->cache_type = mgs_cache_memcache; |
---|
[e183628] | 678 | } |
---|
[46b85d8] | 679 | #endif |
---|
[e183628] | 680 | else { |
---|
[031acac] | 681 | return "Invalid Type for GnuTLSCache!"; |
---|
[e183628] | 682 | } |
---|
| 683 | |
---|
| 684 | if (arg == NULL) |
---|
[031acac] | 685 | return "Invalid argument 2 for GnuTLSCache!"; |
---|
[e183628] | 686 | |
---|
| 687 | if (sc->cache_type == mgs_cache_dbm |
---|
[031acac] | 688 | || sc->cache_type == mgs_cache_gdbm) { |
---|
| 689 | sc->cache_config = ap_server_root_relative(parms->pool, arg); |
---|
[e183628] | 690 | } else { |
---|
[031acac] | 691 | sc->cache_config = apr_pstrdup(parms->pool, arg); |
---|
[e183628] | 692 | } |
---|
| 693 | |
---|
| 694 | return NULL; |
---|
[46b85d8] | 695 | } |
---|
| 696 | |
---|
| 697 | const char *mgs_set_cache_timeout(cmd_parms * parms, void *dummy, |
---|
[031acac] | 698 | const char *arg) |
---|
| 699 | { |
---|
[e183628] | 700 | int argint; |
---|
[480aba1] | 701 | const char *err; |
---|
[e183628] | 702 | mgs_srvconf_rec *sc = |
---|
[031acac] | 703 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 704 | module_config, |
---|
| 705 | &gnutls_module); |
---|
[e183628] | 706 | |
---|
[480aba1] | 707 | if ((err = ap_check_cmd_context(parms, GLOBAL_ONLY))) { |
---|
[031acac] | 708 | return err; |
---|
[480aba1] | 709 | } |
---|
| 710 | |
---|
[e183628] | 711 | argint = atoi(arg); |
---|
| 712 | |
---|
| 713 | if (argint < 0) { |
---|
[031acac] | 714 | return "GnuTLSCacheTimeout: Invalid argument"; |
---|
[e183628] | 715 | } else if (argint == 0) { |
---|
[031acac] | 716 | sc->cache_timeout = 0; |
---|
[e183628] | 717 | } else { |
---|
[031acac] | 718 | sc->cache_timeout = apr_time_from_sec(argint); |
---|
[e183628] | 719 | } |
---|
| 720 | |
---|
| 721 | return NULL; |
---|
[e02dd8c] | 722 | } |
---|
| 723 | |
---|
[cf2b905] | 724 | const char *mgs_set_client_verify_method(cmd_parms * parms, void *dummy, |
---|
[031acac] | 725 | const char *arg) |
---|
| 726 | { |
---|
| 727 | mgs_srvconf_rec *sc = |
---|
| 728 | (mgs_srvconf_rec *) ap_get_module_config(parms-> |
---|
| 729 | server->module_config, |
---|
| 730 | &gnutls_module); |
---|
[cf2b905] | 731 | |
---|
| 732 | if (strcasecmp("cartel", arg) == 0) { |
---|
[031acac] | 733 | sc->client_verify_method = mgs_cvm_cartel; |
---|
[cf2b905] | 734 | } else if (strcasecmp("msva", arg) == 0) { |
---|
| 735 | #ifdef ENABLE_MSVA |
---|
[031acac] | 736 | sc->client_verify_method = mgs_cvm_msva; |
---|
[cf2b905] | 737 | #else |
---|
[031acac] | 738 | return "GnuTLSClientVerifyMethod: msva is not supported"; |
---|
[cf2b905] | 739 | #endif |
---|
| 740 | } else { |
---|
[031acac] | 741 | return "GnuTLSClientVerifyMethod: Invalid argument"; |
---|
[cf2b905] | 742 | } |
---|
| 743 | |
---|
| 744 | return NULL; |
---|
| 745 | } |
---|
| 746 | |
---|
[e02dd8c] | 747 | const char *mgs_set_client_verify(cmd_parms * parms, void *dummy, |
---|
[031acac] | 748 | const char *arg) |
---|
| 749 | { |
---|
[e183628] | 750 | int mode; |
---|
| 751 | |
---|
| 752 | if (strcasecmp("none", arg) == 0 || strcasecmp("ignore", arg) == 0) { |
---|
[031acac] | 753 | mode = GNUTLS_CERT_IGNORE; |
---|
[e183628] | 754 | } else if (strcasecmp("optional", arg) == 0 |
---|
[031acac] | 755 | || strcasecmp("request", arg) == 0) { |
---|
| 756 | mode = GNUTLS_CERT_REQUEST; |
---|
[e183628] | 757 | } else if (strcasecmp("require", arg) == 0) { |
---|
[031acac] | 758 | mode = GNUTLS_CERT_REQUIRE; |
---|
[e183628] | 759 | } else { |
---|
[031acac] | 760 | return "GnuTLSClientVerify: Invalid argument"; |
---|
[e183628] | 761 | } |
---|
| 762 | |
---|
| 763 | /* This was set from a directory context */ |
---|
| 764 | if (parms->path) { |
---|
[031acac] | 765 | mgs_dirconf_rec *dc = (mgs_dirconf_rec *) dummy; |
---|
| 766 | dc->client_verify_mode = mode; |
---|
[e183628] | 767 | } else { |
---|
[031acac] | 768 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
| 769 | ap_get_module_config(parms->server->module_config, |
---|
| 770 | &gnutls_module); |
---|
| 771 | sc->client_verify_mode = mode; |
---|
[e183628] | 772 | } |
---|
| 773 | |
---|
| 774 | return NULL; |
---|
[46b85d8] | 775 | } |
---|
| 776 | |
---|
| 777 | const char *mgs_set_client_ca_file(cmd_parms * parms, void *dummy, |
---|
[031acac] | 778 | const char *arg) |
---|
| 779 | { |
---|
[e183628] | 780 | mgs_srvconf_rec *sc = |
---|
[031acac] | 781 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 782 | module_config, |
---|
| 783 | &gnutls_module); |
---|
[e183628] | 784 | |
---|
[031acac] | 785 | sc->x509_ca_file = ap_server_root_relative(parms->pool, arg); |
---|
[e183628] | 786 | |
---|
| 787 | return NULL; |
---|
[46b85d8] | 788 | } |
---|
| 789 | |
---|
[e5bbda4] | 790 | const char *mgs_set_keyring_file(cmd_parms * parms, void *dummy, |
---|
[031acac] | 791 | const char *arg) |
---|
| 792 | { |
---|
[e183628] | 793 | mgs_srvconf_rec *sc = |
---|
[031acac] | 794 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 795 | module_config, |
---|
| 796 | &gnutls_module); |
---|
[e183628] | 797 | |
---|
[031acac] | 798 | sc->pgp_ring_file = ap_server_root_relative(parms->pool, arg); |
---|
[e183628] | 799 | |
---|
| 800 | return NULL; |
---|
[e5bbda4] | 801 | } |
---|
| 802 | |
---|
[33826c5] | 803 | const char *mgs_set_proxy_engine(cmd_parms * parms, void *dummy, |
---|
[031acac] | 804 | const char *arg) |
---|
| 805 | { |
---|
[671b64f] | 806 | |
---|
[031acac] | 807 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
| 808 | ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
[671b64f] | 809 | |
---|
[33826c5] | 810 | if (!strcasecmp(arg, "On")) { |
---|
[031acac] | 811 | sc->proxy_enabled = GNUTLS_ENABLED_TRUE; |
---|
[33826c5] | 812 | } else if (!strcasecmp(arg, "Off")) { |
---|
[031acac] | 813 | sc->proxy_enabled = GNUTLS_ENABLED_FALSE; |
---|
[33826c5] | 814 | } else { |
---|
[031acac] | 815 | return "SSLProxyEngine must be set to 'On' or 'Off'"; |
---|
[33826c5] | 816 | } |
---|
| 817 | |
---|
| 818 | return NULL; |
---|
| 819 | } |
---|
| 820 | |
---|
[46b85d8] | 821 | const char *mgs_set_enabled(cmd_parms * parms, void *dummy, |
---|
[031acac] | 822 | const char *arg) |
---|
| 823 | { |
---|
[e183628] | 824 | mgs_srvconf_rec *sc = |
---|
[031acac] | 825 | (mgs_srvconf_rec *) ap_get_module_config(parms->server-> |
---|
| 826 | module_config, |
---|
| 827 | &gnutls_module); |
---|
[e183628] | 828 | if (!strcasecmp(arg, "On")) { |
---|
[031acac] | 829 | sc->enabled = GNUTLS_ENABLED_TRUE; |
---|
[e183628] | 830 | } else if (!strcasecmp(arg, "Off")) { |
---|
[031acac] | 831 | sc->enabled = GNUTLS_ENABLED_FALSE; |
---|
[e183628] | 832 | } else { |
---|
[031acac] | 833 | return "GnuTLSEnable must be set to 'On' or 'Off'"; |
---|
[e183628] | 834 | } |
---|
| 835 | |
---|
| 836 | return NULL; |
---|
[7bebb42] | 837 | } |
---|
| 838 | |
---|
[031acac] | 839 | const char *mgs_set_export_certificates_size(cmd_parms * parms, |
---|
| 840 | void *dummy, const char *arg) |
---|
| 841 | { |
---|
| 842 | mgs_srvconf_rec *sc = |
---|
| 843 | (mgs_srvconf_rec *) ap_get_module_config(parms-> |
---|
| 844 | server->module_config, |
---|
| 845 | &gnutls_module); |
---|
[7d1ab49] | 846 | if (!strcasecmp(arg, "On")) { |
---|
[031acac] | 847 | sc->export_certificates_size = 16 * 1024; |
---|
[7d1ab49] | 848 | } else if (!strcasecmp(arg, "Off")) { |
---|
[031acac] | 849 | sc->export_certificates_size = 0; |
---|
[7d1ab49] | 850 | } else { |
---|
[031acac] | 851 | char *endptr; |
---|
| 852 | sc->export_certificates_size = strtol(arg, &endptr, 10); |
---|
| 853 | while (apr_isspace(*endptr)) |
---|
| 854 | endptr++; |
---|
| 855 | if (*endptr == '\0' || *endptr == 'b' || *endptr == 'B') { |
---|
| 856 | ; |
---|
| 857 | } else if (*endptr == 'k' || *endptr == 'K') { |
---|
| 858 | sc->export_certificates_size *= 1024; |
---|
| 859 | } else { |
---|
| 860 | return |
---|
| 861 | "GnuTLSExportCertificates must be set to a size (in bytes) or 'On' or 'Off'"; |
---|
| 862 | } |
---|
[7d1ab49] | 863 | } |
---|
| 864 | |
---|
| 865 | return NULL; |
---|
| 866 | } |
---|
| 867 | |
---|
[031acac] | 868 | const char *mgs_set_priorities(cmd_parms * parms, void *dummy, |
---|
| 869 | const char *arg) |
---|
| 870 | { |
---|
[e183628] | 871 | |
---|
[671b64f] | 872 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
[031acac] | 873 | ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
[e183628] | 874 | |
---|
[031acac] | 875 | sc->priorities_str = apr_pstrdup(parms->pool, arg); |
---|
[3b4c0d0] | 876 | |
---|
[031acac] | 877 | return NULL; |
---|
| 878 | } |
---|
| 879 | |
---|
| 880 | const char *mgs_set_pin(cmd_parms * parms, void *dummy, const char *arg) |
---|
| 881 | { |
---|
| 882 | |
---|
| 883 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
| 884 | ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
| 885 | |
---|
| 886 | sc->pin = apr_pstrdup(parms->pool, arg); |
---|
[e183628] | 887 | |
---|
| 888 | return NULL; |
---|
[46b85d8] | 889 | } |
---|
| 890 | |
---|
[031acac] | 891 | const char *mgs_set_srk_pin(cmd_parms * parms, void *dummy, const char *arg) |
---|
| 892 | { |
---|
[e183628] | 893 | |
---|
[031acac] | 894 | mgs_srvconf_rec *sc = (mgs_srvconf_rec *) |
---|
| 895 | ap_get_module_config(parms->server->module_config, &gnutls_module); |
---|
[e183628] | 896 | |
---|
[031acac] | 897 | sc->srk_pin = apr_pstrdup(parms->pool, arg); |
---|
[e183628] | 898 | |
---|
[031acac] | 899 | return NULL; |
---|
| 900 | } |
---|
| 901 | |
---|
| 902 | static mgs_srvconf_rec *_mgs_config_server_create(apr_pool_t * p, |
---|
| 903 | char **err) |
---|
| 904 | { |
---|
| 905 | mgs_srvconf_rec *sc = apr_pcalloc(p, sizeof(*sc)); |
---|
| 906 | |
---|
| 907 | sc->enabled = GNUTLS_ENABLED_UNSET; |
---|
[e183628] | 908 | |
---|
[787dab7] | 909 | |
---|
[e183628] | 910 | sc->privkey_x509 = NULL; |
---|
[031acac] | 911 | sc->privkey_pgp = NULL; |
---|
[3b4c0d0] | 912 | sc->certs_x509_chain_num = 0; |
---|
[031acac] | 913 | sc->cache_timeout = -1; /* -1 means "unset" */ |
---|
[040387c] | 914 | sc->cache_type = mgs_cache_unset; |
---|
[8400c2e] | 915 | sc->cache_config = NULL; |
---|
[040387c] | 916 | sc->tickets = GNUTLS_ENABLED_UNSET; |
---|
| 917 | sc->priorities = NULL; |
---|
| 918 | sc->dh_params = NULL; |
---|
| 919 | sc->proxy_enabled = GNUTLS_ENABLED_UNSET; |
---|
[2aaf4f5] | 920 | sc->export_certificates_size = -1; |
---|
[671b64f] | 921 | sc->client_verify_method = mgs_cvm_unset; |
---|
| 922 | |
---|
[040387c] | 923 | /* this relies on GnuTLS never changing the gnutls_certificate_request_t enum to define -1 */ |
---|
[671b64f] | 924 | sc->client_verify_mode = -1; |
---|
[7bebb42] | 925 | |
---|
[040387c] | 926 | return sc; |
---|
| 927 | } |
---|
| 928 | |
---|
[031acac] | 929 | void *mgs_config_server_create(apr_pool_t * p, server_rec * s) |
---|
| 930 | { |
---|
[040387c] | 931 | char *err = NULL; |
---|
| 932 | mgs_srvconf_rec *sc = _mgs_config_server_create(p, &err); |
---|
[031acac] | 933 | if (sc) |
---|
| 934 | return sc; |
---|
| 935 | else |
---|
| 936 | return err; |
---|
[040387c] | 937 | } |
---|
| 938 | |
---|
| 939 | #define gnutls_srvconf_merge(t, unset) sc->t = (add->t == unset) ? base->t : add->t |
---|
| 940 | #define gnutls_srvconf_assign(t) sc->t = add->t |
---|
| 941 | |
---|
[031acac] | 942 | void *mgs_config_server_merge(apr_pool_t * p, void *BASE, void *ADD) |
---|
| 943 | { |
---|
[040387c] | 944 | int i; |
---|
| 945 | char *err = NULL; |
---|
[031acac] | 946 | mgs_srvconf_rec *base = (mgs_srvconf_rec *) BASE; |
---|
| 947 | mgs_srvconf_rec *add = (mgs_srvconf_rec *) ADD; |
---|
[040387c] | 948 | mgs_srvconf_rec *sc = _mgs_config_server_create(p, &err); |
---|
[031acac] | 949 | if (NULL == sc) |
---|
| 950 | return err; |
---|
[040387c] | 951 | |
---|
| 952 | gnutls_srvconf_merge(enabled, GNUTLS_ENABLED_UNSET); |
---|
| 953 | gnutls_srvconf_merge(tickets, GNUTLS_ENABLED_UNSET); |
---|
| 954 | gnutls_srvconf_merge(proxy_enabled, GNUTLS_ENABLED_UNSET); |
---|
[2aaf4f5] | 955 | gnutls_srvconf_merge(export_certificates_size, -1); |
---|
[cf2b905] | 956 | gnutls_srvconf_merge(client_verify_method, mgs_cvm_unset); |
---|
[040387c] | 957 | gnutls_srvconf_merge(client_verify_mode, -1); |
---|
| 958 | gnutls_srvconf_merge(srp_tpasswd_file, NULL); |
---|
| 959 | gnutls_srvconf_merge(srp_tpasswd_conf_file, NULL); |
---|
[031acac] | 960 | gnutls_srvconf_merge(x509_cert_file, NULL); |
---|
| 961 | |
---|
| 962 | gnutls_srvconf_merge(x509_key_file, NULL); |
---|
| 963 | gnutls_srvconf_merge(x509_ca_file, NULL); |
---|
| 964 | gnutls_srvconf_merge(pin, NULL); |
---|
| 965 | gnutls_srvconf_merge(pgp_cert_file, NULL); |
---|
| 966 | gnutls_srvconf_merge(pgp_key_file, NULL); |
---|
| 967 | gnutls_srvconf_merge(pgp_ring_file, NULL); |
---|
| 968 | gnutls_srvconf_merge(dh_file, NULL); |
---|
| 969 | gnutls_srvconf_merge(priorities_str, NULL); |
---|
[040387c] | 970 | |
---|
| 971 | /* FIXME: the following items are pre-allocated, and should be |
---|
| 972 | * properly disposed of before assigning in order to avoid leaks; |
---|
| 973 | * so at the moment, we can't actually have them in the config. |
---|
[031acac] | 974 | * what happens during de-allocation? */ |
---|
| 975 | gnutls_srvconf_assign(ca_list); |
---|
| 976 | gnutls_srvconf_assign(ca_list_size); |
---|
| 977 | gnutls_srvconf_assign(cert_pgp); |
---|
| 978 | gnutls_srvconf_assign(cert_crt_pgp); |
---|
| 979 | gnutls_srvconf_assign(pgp_list); |
---|
[040387c] | 980 | gnutls_srvconf_assign(certs); |
---|
| 981 | gnutls_srvconf_assign(anon_creds); |
---|
| 982 | gnutls_srvconf_assign(srp_creds); |
---|
| 983 | gnutls_srvconf_assign(certs_x509_chain); |
---|
[031acac] | 984 | gnutls_srvconf_assign(certs_x509_crt_chain); |
---|
[040387c] | 985 | gnutls_srvconf_assign(certs_x509_chain_num); |
---|
| 986 | |
---|
| 987 | /* how do these get transferred cleanly before the data from ADD |
---|
| 988 | * goes away? */ |
---|
| 989 | gnutls_srvconf_assign(cert_cn); |
---|
| 990 | for (i = 0; i < MAX_CERT_SAN; i++) |
---|
[031acac] | 991 | gnutls_srvconf_assign(cert_san[i]); |
---|
[7bebb42] | 992 | |
---|
[e183628] | 993 | return sc; |
---|
[46b85d8] | 994 | } |
---|
| 995 | |
---|
[040387c] | 996 | #undef gnutls_srvconf_merge |
---|
| 997 | #undef gnutls_srvconf_assign |
---|
| 998 | |
---|
[031acac] | 999 | void *mgs_config_dir_merge(apr_pool_t * p, void *basev, void *addv) |
---|
| 1000 | { |
---|
[e183628] | 1001 | mgs_dirconf_rec *new; |
---|
| 1002 | /* mgs_dirconf_rec *base = (mgs_dirconf_rec *) basev; */ |
---|
| 1003 | mgs_dirconf_rec *add = (mgs_dirconf_rec *) addv; |
---|
[e02dd8c] | 1004 | |
---|
[031acac] | 1005 | new = (mgs_dirconf_rec *) apr_pcalloc(p, sizeof(mgs_dirconf_rec)); |
---|
[e183628] | 1006 | new->client_verify_mode = add->client_verify_mode; |
---|
| 1007 | return new; |
---|
[84cb5b2] | 1008 | } |
---|
| 1009 | |
---|
[031acac] | 1010 | void *mgs_config_dir_create(apr_pool_t * p, char *dir) |
---|
| 1011 | { |
---|
| 1012 | mgs_dirconf_rec *dc = apr_palloc(p, sizeof(*dc)); |
---|
[e183628] | 1013 | dc->client_verify_mode = -1; |
---|
| 1014 | return dc; |
---|
[46b85d8] | 1015 | } |
---|