Apache HTTPD
tls_core.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <assert.h>
17#include <apr_lib.h>
18#include <apr_strings.h>
19#include <apr_network_io.h>
20
21#include <httpd.h>
22#include <http_core.h>
23#include <http_log.h>
24#include <http_protocol.h>
25#include <http_ssl.h>
26#include <http_vhost.h>
27#include <http_main.h>
28#include <ap_socache.h>
29
30#include <rustls.h>
31
32#include "tls_proto.h"
33#include "tls_cert.h"
34#include "tls_conf.h"
35#include "tls_core.h"
36#include "tls_ocsp.h"
37#include "tls_util.h"
38#include "tls_cache.h"
39#include "tls_var.h"
40
41
42extern module AP_MODULE_DECLARE_DATA tls_module;
44
46{
47 return ap_get_module_config(c->conn_config, &tls_module);
48}
49
51{
52 ap_set_module_config(c->conn_config, &tls_module, cc);
53}
54
56{
57 tls_conf_conn_t *cc = tls_conf_conn_get(c->master? c->master : c);
58 if (TLS_CONN_ST_IS_ENABLED(cc)) {
59 return OK;
60 }
61 return DECLINED;
62}
63
65{
67
68 if (gc->tls_addresses && sc->base_server) {
69 /* The base server listens to every port and may be selected via SNI */
70 return 1;
71 }
72 for (la = gc->tls_addresses; la; la = la->next) {
73 for (sa = s->addrs; sa; sa = sa->next) {
74 if (la->host_port == sa->host_port
75 && la->host_addr->ipaddr_len == sa->host_addr->ipaddr_len
76 && !memcmp(la->host_addr->ipaddr_ptr,
77 la->host_addr->ipaddr_ptr, (size_t)la->host_addr->ipaddr_len)) {
78 /* exact match */
79 return 1;
80 }
81 }
82 }
83 return 0;
84}
85
87{
88 server_rec *base_server = (server_rec *)data;
89 tls_conf_server_t *sc = tls_conf_server_get(base_server);
90
91 if (sc && sc->global && sc->global->rustls_hello_config) {
94 }
95 tls_cache_free(base_server);
96 return APR_SUCCESS;
97}
98
101 apr_array_header_t *cert_specs,
102 tls_cert_reg_t *cert_reg)
103{
106 tls_cert_spec_t *spec;
107 int i;
108
109 if (cert_specs && cert_specs->nelts > 0) {
110 for (i = 0; i < cert_specs->nelts; ++i) {
111 spec = APR_ARRAY_IDX(cert_specs, i, tls_cert_spec_t*);
112 rv = tls_cert_reg_get_certified_key(cert_reg, s, spec, &ckey);
113 if (APR_SUCCESS != rv) {
115 "Failed to load certificate %d[cert=%s(%d), key=%s(%d)] for %s",
116 i, spec->cert_file, (int)(spec->cert_pem? strlen(spec->cert_pem) : 0),
117 spec->pkey_file, (int)(spec->pkey_pem? strlen(spec->pkey_pem) : 0),
118 s->server_hostname);
119 goto cleanup;
120 }
121 assert(ckey);
123 }
124 }
125cleanup:
126 return rv;
127}
128
130 conn_rec *c, const char *cert_pem, const char *pkey_pem)
131{
134 tls_cert_spec_t spec;
136
137 memset(&spec, 0, sizeof(spec));
138 spec.cert_pem = cert_pem;
139 spec.pkey_pem = pkey_pem;
140 rv = tls_cert_load_cert_key(c->pool, &spec, NULL, &ckey);
141 if (APR_SUCCESS != rv) goto cleanup;
142
143 cc->local_keys = apr_array_make(c->pool, 2, sizeof(const rustls_certified_key*));
145 ckey = NULL;
146
147cleanup:
149 return rv;
150}
151
152static void add_file_specs(
154 apr_pool_t *p,
155 apr_array_header_t *cert_files,
156 apr_array_header_t *key_files)
157{
158 tls_cert_spec_t *spec;
159 int i;
160
161 for (i = 0; i < cert_files->nelts; ++i) {
162 spec = apr_pcalloc(p, sizeof(*spec));
163 spec->cert_file = APR_ARRAY_IDX(cert_files, i, const char*);
164 spec->pkey_file = (i < key_files->nelts)? APR_ARRAY_IDX(key_files, i, const char*) : NULL;
166 }
167}
168
171 server_rec *s,
173 const char *proxy,
177{
184 int i;
185
186
187 /* remove all suppressed ciphers from the ones supported by rustls */
188 ciphers = tls_util_array_uint16_remove(pool, gc->proto->supported_cipher_ids, supp_ciphers);
190 /* if preferred ciphers are actually still present in allowed_ciphers, put
191 * them into `ciphers` in this order */
192 for (i = 0; i < pref_ciphers->nelts; ++i) {
195 "checking preferred cipher %s: %d",
196 s->server_hostname, id);
199 "checking preferred cipher %s: %d is known",
200 s->server_hostname, id);
201 if (ordered_ciphers == NULL) {
203 }
205 }
206 else if (!tls_proto_is_cipher_supported(gc->proto, id)) {
208 "checking preferred cipher %s: %d is unsupported",
209 s->server_hostname, id);
212 }
213 }
214 /* if we found ciphers with preference among allowed_ciphers,
215 * append all other allowed ciphers. */
216 if (ordered_ciphers) {
217 for (i = 0; i < ciphers->nelts; ++i) {
221 }
222 }
224 }
225
226 if (ciphers == gc->proto->supported_cipher_ids) {
227 ciphers = NULL;
228 }
229
230 if (unsupported && unsupported->nelts) {
232 "Server '%s' has TLS%sCiphersPrefer configured that are not "
233 "supported by rustls. These will not have an effect: %s",
234 s->server_hostname, proxy,
236 }
237
238 if (RUSTLS_RESULT_OK != rr) {
239 const char *err_descr;
242 "Failed to configure ciphers %s: [%d] %s",
243 s->server_hostname, (int)rr, err_descr);
244 }
245 *pciphers = (APR_SUCCESS == rv)? ciphers : NULL;
246 return rv;
247}
248
252{
255
256 rv = calc_ciphers(pool, sc->server, sc->global,
258 &ciphers);
259 if (APR_SUCCESS != rv) goto cleanup;
260
261 if (ciphers) {
263 sc->global->proto, ciphers, pool);
264 if (APLOGtrace2(sc->server)) {
265 tls_proto_conf_t *conf = sc->global->proto;
267 "tls ciphers configured[%s]: %s",
270 }
271 }
272
273cleanup:
274 *pciphersuites = (APR_SUCCESS == rv)? suites : NULL;
275 return rv;
276}
277
280{
282
283 /* Take the configured certificate specifications and ask
284 * around for other modules to add specifications to this server.
285 * This is the way mod_md provides certificates.
286 *
287 * If the server then still has no cert specifications, ask
288 * around for `fallback` certificates which are commonly self-signed,
289 * temporary ones which let the server startup in order to
290 * obtain the `real` certificates from sources like ACME.
291 * Servers will fallbacks will answer all requests with 503.
292 */
293 specs = apr_array_copy(p, sc->cert_specs);
294 cert_adds = apr_array_make(p, 2, sizeof(const char*));
295 key_adds = apr_array_make(p, 2, sizeof(const char*));
296
299 "init server: complete_cert_specs added %d certs", cert_adds->nelts);
301
302 if (apr_is_empty_array(specs)) {
304 "init server: no certs configured, looking for fallback");
306 if (cert_adds->nelts > 0) {
308 sc->service_unavailable = 1;
310 "Init: %s will respond with '503 Service Unavailable' for now. There "
311 "are no SSL certificates configured and no other module contributed any.",
313 }
314 else if (!sc->base_server) {
316 "Init: %s has no certificates configured. Use 'TLSCertificate' to "
317 "configure a certificate and key file.",
319 }
320 }
321 return specs;
322}
323
325 void* userdata, const rustls_client_hello *hello)
326{
327 conn_rec *c = userdata;
328 tls_conf_conn_t *cc;
333 apr_status_t rv;
334
335 ap_assert(c);
336 cc = tls_conf_conn_get(c);
337 ap_assert(cc);
338 ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, c, "client hello select certified key");
339 if (!cc || !cc->server) goto cleanup;
340 sc = tls_conf_server_get(cc->server);
341 if (!sc) goto cleanup;
342
343 cc->key = NULL;
344 cc->key_cloned = 0;
345 if (cc->local_keys && cc->local_keys->nelts > 0) {
346 keys = cc->local_keys;
347 }
348 else {
349 keys = sc->certified_keys;
350 }
351 if (!keys || keys->nelts <= 0) goto cleanup;
352
354 (const rustls_certified_key**)keys->elts, (size_t)keys->nelts, &cc->key);
355 if (RUSTLS_RESULT_OK != rr) goto cleanup;
356
357 if (APR_SUCCESS == tls_ocsp_update_key(c, cc->key, &clone)) {
358 /* got OCSP response data for it, meaning the key was cloned and we need to remember */
359 cc->key_cloned = 1;
360 cc->key = clone;
361 }
362 if (APLOGctrace2(c)) {
363 const char *key_id = tls_cert_reg_get_id(sc->global->cert_reg, cc->key);
365 "client hello selected key: %s", key_id? key_id : "unknown");
366 }
367 return cc->key;
368
369cleanup:
370 if (RUSTLS_RESULT_OK != rr) {
371 const char *err_descr;
372 rv = tls_util_rustls_error(c->pool, rr, &err_descr);
374 "Failed to select certified key: [%d] %s", (int)rr, err_descr);
375 }
376 return NULL;
377}
378
381{
382 apr_array_header_t *cert_specs;
384
385 /* TODO: most code has been stripped here with the changes in rustls-ffi v0.8.0
386 * and this means that any errors are only happening at connection setup, which
387 * is too late.
388 */
389 (void)p;
391 "init server: %s", sc->server->server_hostname);
392
393 if (sc->client_auth != TLS_CLIENT_AUTH_NONE && !sc->client_ca) {
395 "TLSClientAuthentication is enabled for %s, but no client CA file is set. "
396 "Use 'TLSClientCA <file>' to specify the trust anchors.",
398 rv = APR_EINVAL; goto cleanup;
399 }
400
401 cert_specs = complete_cert_specs(ptemp, sc);
403 rv = load_certified_keys(sc->certified_keys, sc->server, cert_specs, gc->cert_reg);
404 if (APR_SUCCESS != rv) goto cleanup;
405
406 rv = get_server_ciphersuites(&sc->ciphersuites, p, sc);
407 if (APR_SUCCESS != rv) goto cleanup;
408
410 "init server: %s with %d certificates loaded",
412cleanup:
413 return rv;
414}
415
418{
421
422 rv = calc_ciphers(pool, pc->defined_in, pc->global,
423 "", pc->proxy_pref_ciphers, pc->proxy_supp_ciphers, &ciphers);
424 if (APR_SUCCESS != rv) goto cleanup;
425
426 if (ciphers) {
428 /* this changed the default rustls ciphers, configure it. */
429 if (APLOGtrace2(pc->defined_in)) {
430 tls_proto_conf_t *conf = pc->global->proto;
431 ap_log_error(APLOG_MARK, APLOG_TRACE2, 0, pc->defined_in,
432 "tls proxy ciphers configured[%s]: %s",
433 pc->defined_in->server_hostname,
435 }
436 }
437
438cleanup:
439 *pciphersuites = (APR_SUCCESS == rv)? suites : NULL;
440 return rv;
441}
442
445{
447
448 (void)p; (void)ptemp;
449 ap_assert(pc->defined_in);
450 pc->global = gc;
451
452 if (pc->proxy_ca && strcasecmp(pc->proxy_ca, "default")) {
453 ap_log_error(APLOG_MARK, APLOG_TRACE2, rv, pc->defined_in,
454 "proxy: will use roots in %s from %s",
455 pc->defined_in->server_hostname, pc->proxy_ca);
456 }
457 else {
458 ap_log_error(APLOG_MARK, APLOG_WARNING, rv, pc->defined_in,
459 "proxy: there is no TLSProxyCA configured in %s which means "
460 "the certificates of remote servers contacted from here will not be trusted.",
461 pc->defined_in->server_hostname);
462 }
463
464 if (pc->proxy_protocol_min > 0) {
466
467 ap_log_error(APLOG_MARK, APLOG_TRACE1, rv, pc->defined_in,
468 "init server: set proxy protocol min version %04x", pc->proxy_protocol_min);
470 gc->proto, (apr_uint16_t)pc->proxy_protocol_min, ptemp);
471 if (tls_versions->nelts > 0) {
472 if (pc->proxy_protocol_min != APR_ARRAY_IDX(tls_versions, 0, apr_uint16_t)) {
473 ap_log_error(APLOG_MARK, APLOG_WARNING, 0, pc->defined_in, APLOGNO(10326)
474 "Init: the minimum proxy protocol version configured for %s (%04x) "
475 "is not supported and version %04x was selected instead.",
476 pc->defined_in->server_hostname, pc->proxy_protocol_min,
478 }
479 }
480 else {
481 ap_log_error(APLOG_MARK, APLOG_ERR, 0, pc->defined_in, APLOGNO(10327)
482 "Unable to configure the proxy protocol version for %s: "
483 "neither the configured minimum version (%04x), nor any higher one is "
484 "available.", pc->defined_in->server_hostname, pc->proxy_protocol_min);
485 rv = APR_ENOTIMPL; goto cleanup;
486 }
487 }
488
489#if TLS_MACHINE_CERTS
490 rv = load_certified_keys(pc->machine_certified_keys, pc->defined_in,
491 pc->machine_cert_specs, gc->cert_reg);
492 if (APR_SUCCESS != rv) goto cleanup;
493#endif
494
495cleanup:
496 return rv;
497}
498
500 void* userdata, const rustls_client_hello *hello)
501{
502 conn_rec *c = userdata;
504 size_t i, len;
505 unsigned short n;
506
507 ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, c, "extract client hello values");
508 if (!cc) goto cleanup;
509 cc->client_hello_seen = 1;
510 if (hello->server_name.len > 0) {
511 cc->sni_hostname = apr_pstrndup(c->pool, hello->server_name.data, hello->server_name.len);
512 ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c, "sni detected: %s", cc->sni_hostname);
513 }
514 else {
515 cc->sni_hostname = NULL;
516 ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c, "no sni from client");
517 }
518 if (APLOGctrace4(c) && hello->signature_schemes.len > 0) {
519 for (i = 0; i < hello->signature_schemes.len; ++i) {
520 n = hello->signature_schemes.data[i];
522 "client supports signature scheme: %x", (int)n);
523 }
524 }
525 if ((len = rustls_slice_slice_bytes_len(hello->alpn)) > 0) {
526 apr_array_header_t *alpn = apr_array_make(c->pool, 5, sizeof(const char*));
527 const char *protocol;
528 ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c, "ALPN: client proposes %d protocols", (int)len);
529 for (i = 0; i < len; ++i) {
531 protocol = apr_pstrndup(c->pool, (const char*)rs.data, rs.len);
532 APR_ARRAY_PUSH(alpn, const char*) = protocol;
534 "ALPN: client proposes %d: `%s`", (int)i, protocol);
535 }
536 cc->alpn = alpn;
537 }
538 else {
539 ap_log_cerror(APLOG_MARK, APLOG_DEBUG, 0, c, "ALPN: no alpn proposed by client");
540 }
541cleanup:
542 return NULL;
543}
544
546{
550
552 if (!builder) {
554 }
556 gc->rustls_hello_config = rustls_server_config_builder_build(builder);
557 if (!gc->rustls_hello_config) {
559 }
560
561cleanup:
562 if (RUSTLS_RESULT_OK != rr) {
563 const char *err_descr = NULL;
565 ap_log_error(APLOG_MARK, APLOG_ERR, rv, base_server, APLOGNO(10328)
566 "Failed to init generic hello config: [%d] %s", (int)rr, err_descr);
567 goto cleanup;
568 }
569 return rv;
570}
571
573{
574 tls_conf_server_t *sc = tls_conf_server_get(base_server);
576 server_rec *s;
578
579 ap_log_error(APLOG_MARK, APLOG_TRACE2, 0, base_server, "tls_core_init incoming");
582
583 rv = tls_proto_post_config(p, ptemp, base_server);
584 if (APR_SUCCESS != rv) goto cleanup;
585
586 for (s = base_server; s; s = s->next) {
588 assert(sc);
589 ap_assert(sc->global == gc);
590
591 /* If 'TLSEngine' has been configured, use those addresses to
592 * decide if we are enabled on this server. */
593 sc->base_server = (s == base_server);
595 }
596
597 rv = tls_cache_post_config(p, ptemp, base_server);
598 if (APR_SUCCESS != rv) goto cleanup;
599
600 rv = setup_hello_config(p, base_server, gc);
601 if (APR_SUCCESS != rv) goto cleanup;
602
603 /* Setup server configs and collect all certificates we use. */
604 gc->cert_reg = tls_cert_reg_make(p);
605 gc->stores = tls_cert_root_stores_make(p);
606 gc->verifiers = tls_cert_verifiers_make(p, gc->stores);
607 for (s = base_server; s; s = s->next) {
610 if (APR_SUCCESS != rv) goto cleanup;
611 if (sc->enabled != TLS_FLAG_TRUE) continue;
612 rv = server_conf_setup(p, ptemp, sc, gc);
613 if (APR_SUCCESS != rv) {
614 ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, "server setup failed: %s",
615 s->server_hostname);
616 goto cleanup;
617 }
618 }
619
620cleanup:
621 if (APR_SUCCESS != rv) {
622 ap_log_error(APLOG_MARK, APLOG_ERR, rv, base_server, "error during post_config");
623 }
624 return rv;
625}
626
628{
629 tls_conf_server_t *sc = tls_conf_server_get(base_server);
631 tls_conf_dir_t *dc;
633 server_rec *s;
635 int i;
636
637 (void)p; (void)ptemp;
638 (void)gc;
639 ap_log_error(APLOG_MARK, APLOG_TRACE2, 0, base_server, "tls_core_init outgoing");
640 ap_assert(gc->mod_proxy_post_config_done);
641 /* Collect all proxy'ing default server dir configs.
642 * All <Proxy> section dir_configs should already be there - if there were any. */
643 for (s = base_server; s; s = s->next) {
646 if (APR_SUCCESS != rv) goto cleanup;
647 if (dc->proxy_enabled != TLS_FLAG_TRUE) continue;
649 ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, s, "%s: adding proxy_conf to globals",
650 s->server_hostname);
651 APR_ARRAY_PUSH(gc->proxy_configs, tls_conf_proxy_t*) = dc->proxy_config;
652 }
653 /* Now gc->proxy_configs contains all configurations we need to possibly
654 * act on for outgoing connections. */
655 for (i = 0; i < gc->proxy_configs->nelts; ++i) {
656 pc = APR_ARRAY_IDX(gc->proxy_configs, i, tls_conf_proxy_t*);
657 rv = proxy_conf_setup(p, ptemp, pc, gc);
658 if (APR_SUCCESS != rv) goto cleanup;
659 }
660
661cleanup:
662 return rv;
663}
664
666{
667 tls_conf_server_t *sc = tls_conf_server_get(base_server);
670
671 ap_assert(gc);
672 if (TLS_CONF_ST_INIT == gc->status) {
673 rv = init_incoming(p, ptemp, base_server);
674 if (APR_SUCCESS != rv) goto cleanup;
676 }
677 if (TLS_CONF_ST_INCOMING_DONE == gc->status) {
678 if (!gc->mod_proxy_post_config_done) goto cleanup;
679
680 rv = init_outgoing(p, ptemp, base_server);
681 if (APR_SUCCESS != rv) goto cleanup;
683 }
684 if (TLS_CONF_ST_OUTGOING_DONE == gc->status) {
685 /* register all loaded certificates for OCSP stapling */
686 rv = tls_ocsp_prime_certs(gc, p, base_server);
687 if (APR_SUCCESS != rv) goto cleanup;
688
689 if (gc->verifiers) tls_cert_verifiers_clear(gc->verifiers);
690 if (gc->stores) tls_cert_root_stores_clear(gc->stores);
691 gc->status = TLS_CONF_ST_DONE;
692 }
693cleanup:
694 return rv;
695}
696
698{
699 tls_conf_conn_t *cc = data;
700
701 /* free all rustls things we are owning. */
702 if (cc->rustls_connection) {
705 }
706 if (cc->rustls_server_config) {
709 }
710 if (cc->rustls_client_config) {
713 }
714 if (cc->key_cloned && cc->key) {
716 cc->key = NULL;
717 }
718 if (cc->local_keys) {
720 int i;
721
722 for (i = 0; i < cc->local_keys->nelts; ++i) {
725 }
727 }
728 return APR_SUCCESS;
729}
730
732{
734 if (!cc) {
735 cc = apr_pcalloc(c->pool, sizeof(*cc));
736 cc->server = c->base_server;
738 tls_conf_conn_set(c, cc);
741 }
742 return cc;
743}
744
746{
747 tls_conf_conn_t *cc;
748 cc = cc_get_or_make(c);
749 if (cc->state == TLS_CONN_ST_INIT) {
751 }
752}
753
759
760
762{
765 const apr_array_header_t *ciphersuites = NULL;
771 const char *hostname = NULL, *alpn_note = NULL;
774
775 ap_assert(cc->outgoing);
776 ap_assert(cc->dc);
777 pc = cc->dc->proxy_config;
778 ap_assert(pc);
779
780 hostname = apr_table_get(c->notes, "proxy-request-hostname");
781 alpn_note = apr_table_get(c->notes, "proxy-request-alpn-protos");
782 ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, c->base_server,
783 "setup_outgoing: to %s [ALPN: %s] from configuration in %s"
784 " using CA %s", hostname, alpn_note, pc->defined_in->server_hostname, pc->proxy_ca);
785
786 rv = get_proxy_ciphers(&ciphersuites, c->pool, pc);
787 if (APR_SUCCESS != rv) goto cleanup;
788
789 if (pc->proxy_protocol_min > 0) {
791 pc->global->proto, (apr_uint16_t)pc->proxy_protocol_min, c->pool);
792 }
793
794 if (ciphersuites && ciphersuites->nelts > 0
795 && tls_versions && tls_versions->nelts >= 0) {
797 (const struct rustls_supported_ciphersuite *const *)ciphersuites->elts,
798 (size_t)ciphersuites->nelts,
799 (const uint16_t *)tls_versions->elts, (size_t)tls_versions->nelts,
800 &builder);
801 if (RUSTLS_RESULT_OK != rr) goto cleanup;
802 }
803 else {
805 if (NULL == builder) {
806 rv = APR_ENOMEM;
807 goto cleanup;
808 }
809 }
810
811 if (pc->proxy_ca && strcasecmp(pc->proxy_ca, "default")) {
812 rv = tls_cert_root_stores_get(pc->global->stores, pc->proxy_ca, &ca_store);
813 if (APR_SUCCESS != rv) goto cleanup;
816 if (RUSTLS_RESULT_OK != rr) goto cleanup;
818 }
819
820#if TLS_MACHINE_CERTS
821 if (pc->machine_certified_keys->nelts > 0) {
822 ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, c->base_server,
823 "setup_outgoing: adding %d client certificate", (int)pc->machine_certified_keys->nelts);
825 builder, (const rustls_certified_key**)pc->machine_certified_keys->elts,
826 (size_t)pc->machine_certified_keys->nelts);
827 if (RUSTLS_RESULT_OK != rr) goto cleanup;
828 }
829#endif
830
831 if (hostname) {
833 }
834 else {
835 hostname = "unknown.proxy.local";
837 }
838
839 if (alpn_note) {
841 char *p, *last;
843
844 alpn_proposed = apr_array_make(c->pool, 3, sizeof(const char*));
845 p = apr_pstrdup(c->pool, alpn_note);
846 while ((p = apr_strtok(p, ", ", &last))) {
847 len = (apr_size_t)(last - p - (*last? 1 : 0));
848 if (len > 255) {
850 "ALPN proxy protocol identifier too long: %s", p);
851 rv = APR_EGENERAL;
852 goto cleanup;
853 }
854 APR_ARRAY_PUSH(alpn_proposed, const char*) = apr_pstrndup(c->pool, p, len);
855 p = NULL;
856 }
857 if (alpn_proposed->nelts > 0) {
859 const char* proto;
861 int i;
862
864 for (i = 0; i < alpn_proposed->nelts; ++i) {
865 proto = APR_ARRAY_IDX(alpn_proposed, i, const char*);
866 bytes.data = (const unsigned char*)proto;
867 bytes.len = strlen(proto);
869 }
870
873 if (RUSTLS_RESULT_OK != rr) goto cleanup;
874
875 ap_log_error(APLOG_MARK, APLOG_TRACE2, 0, c->base_server,
876 "setup_outgoing: to %s, added %d ALPN protocols from %s",
878 }
879 }
880
882 builder = NULL;
883
885 if (RUSTLS_RESULT_OK != rr) goto cleanup;
887
888cleanup:
891 if (RUSTLS_RESULT_OK != rr) {
892 const char *err_descr = NULL;
893 rv = tls_util_rustls_error(c->pool, rr, &err_descr);
895 "Failed to init pre_session for outgoing %s to %s: [%d] %s",
897 c->aborted = 1;
899 goto cleanup;
900 }
901 return rv;
902}
903
905{
906 tls_conf_server_t *sc = tls_conf_server_get(c->base_server);
907 tls_conf_conn_t *cc;
908
909 cc = cc_get_or_make(c);
910 if (cc->state == TLS_CONN_ST_INIT) {
911 /* Need to decide if we TLS this connection or not */
912 int enabled =
913#if AP_MODULE_MAGIC_AT_LEAST(20120211, 109)
914 !c->outgoing &&
915#endif
916 sc->enabled == TLS_FLAG_TRUE;
918 cc->client_auth = sc->client_auth;
919 ap_log_error(APLOG_MARK, APLOG_TRACE3, 0, c->base_server,
920 "tls_core_conn_init: %s for tls: %s",
921 enabled? "enabled" : "disabled", c->base_server->server_hostname);
922 }
923 else if (cc->state == TLS_CONN_ST_DISABLED) {
924 ap_log_error(APLOG_MARK, APLOG_TRACE4, 0, c->base_server,
925 "tls_core_conn_init, not our connection: %s",
926 c->base_server->server_hostname);
927 goto cleanup;
928 }
929
930cleanup:
931 return TLS_CONN_ST_IS_ENABLED(cc)? OK : DECLINED;
932}
933
935{
936 tls_conf_server_t *sc = tls_conf_server_get(c->base_server);
937 tls_conf_conn_t *cc;
940
941 cc = tls_conf_conn_get(c);
942 if (cc && TLS_CONN_ST_IS_ENABLED(cc) && !cc->rustls_connection) {
943 if (cc->outgoing) {
945 if (APR_SUCCESS != rv) goto cleanup;
946 }
947 else {
948 /* Use a generic rustls_connection with its defaults, which we feed
949 * the first TLS bytes from the client. Its Hello message will trigger
950 * our callback where we can inspect the (possibly) supplied SNI and
951 * select another server.
952 */
954 if (RUSTLS_RESULT_OK != rr) goto cleanup;
955 /* we might refuse requests on this connection, e.g. ACME challenge */
957 }
959 }
960
961cleanup:
962 if (RUSTLS_RESULT_OK != rr) {
963 const char *err_descr = NULL;
964 rv = tls_util_rustls_error(c->pool, rr, &err_descr);
966 "Failed to init TLS connection for server %s: [%d] %s",
967 sc->server->server_hostname, (int)rr, err_descr);
968 c->aborted = 1;
970 goto cleanup;
971 }
972 return rv;
973}
974
975static int find_vhost(void *sni_hostname, conn_rec *c, server_rec *s)
976{
977 if (tls_util_name_matches_server(sni_hostname, s)) {
979 cc->server = s;
980 return 1;
981 }
982 return 0;
983}
984
987{
989 const char *proposed;
992
993 /* The server always has a protocol it uses, normally "http/1.1".
994 * if the client, via ALPN, proposes protocols, they are in
995 * order of preference.
996 * We propose those to modules registered in the server and
997 * get the protocol back that someone is willing to run on this
998 * connection.
999 * If this is different from what the connection already does,
1000 * we tell the server (and all protocol modules) to switch.
1001 * If successful, we announce that protocol back to the client as
1002 * our only ALPN protocol and then do the 'real' handshake.
1003 */
1005 if (cc->alpn && cc->alpn->nelts > 0) {
1007
1009 if (!proposed) {
1011 "ALPN: no protocol selected in server");
1012 goto cleanup;
1013 }
1014
1017 "ALPN: switching protocol from `%s` to `%s`", cc->application_protocol, proposed);
1019 if (APR_SUCCESS != rv) goto cleanup;
1020 }
1021
1022 rsb.data = (const unsigned char*)proposed;
1023 rsb.len = strlen(proposed);
1025 if (RUSTLS_RESULT_OK != rr) goto cleanup;
1026
1029 "ALPN: using connection protocol `%s`", cc->application_protocol);
1030
1031 /* protocol was switched, this could be a challenge protocol
1032 * such as "acme-tls/1". Give handlers the opportunity to
1033 * override the certificate for this connection. */
1034 if (strcmp("h2", proposed) && strcmp("http/1.1", proposed)) {
1035 const char *cert_pem = NULL, *key_pem = NULL;
1036 if (ap_ssl_answer_challenge(c, cc->sni_hostname, &cert_pem, &key_pem)) {
1037 /* With ACME we can have challenge connections to a unknown domains
1038 * that need to be answered with a special certificate and will
1039 * otherwise not answer any requests. See RFC 8555 */
1040 rv = use_local_key(c, cert_pem, key_pem);
1041 if (APR_SUCCESS != rv) goto cleanup;
1042
1043 cc->service_unavailable = 1;
1045 }
1046 }
1047 }
1048
1049cleanup:
1050 if (rr != RUSTLS_RESULT_OK) {
1051 const char *err_descr = NULL;
1052 rv = tls_util_rustls_error(c->pool, rr, &err_descr);
1054 "Failed to init session for server %s: [%d] %s",
1055 s->server_hostname, (int)rr, err_descr);
1056 c->aborted = 1;
1057 goto cleanup;
1058 }
1059 return rv;
1060}
1061
1063 const rustls_server_config **pconfig,
1064 conn_rec *c)
1065{
1070 const rustls_server_config *config = NULL;
1071 rustls_connection *rconnection = NULL;
1074
1075 sc = tls_conf_server_get(cc->server);
1076
1077 if (sc->tls_protocol_min > 0) {
1079 "init server: set protocol min version %04x", sc->tls_protocol_min);
1081 sc->global->proto, (apr_uint16_t)sc->tls_protocol_min, c->pool);
1082 if (tls_versions->nelts > 0) {
1085 "Init: the minimum protocol version configured for %s (%04x) "
1086 "is not supported and version %04x was selected instead.",
1089 }
1090 }
1091 else {
1093 "Unable to configure the protocol version for %s: "
1094 "neither the configured minimum version (%04x), nor any higher one is "
1095 "available.", sc->server->server_hostname, sc->tls_protocol_min);
1096 rv = APR_ENOTIMPL; goto cleanup;
1097 }
1098 }
1099 else if (sc->ciphersuites && sc->ciphersuites->nelts > 0) {
1100 /* FIXME: rustls-ffi current has not way to make a builder with ALL_PROTOCOL_VERSIONS */
1102 }
1103
1104 if (sc->ciphersuites && sc->ciphersuites->nelts > 0
1105 && tls_versions && tls_versions->nelts >= 0) {
1107 (const struct rustls_supported_ciphersuite *const *)sc->ciphersuites->elts,
1108 (size_t)sc->ciphersuites->nelts,
1109 (const uint16_t *)tls_versions->elts, (size_t)tls_versions->nelts,
1110 &builder);
1111 if (RUSTLS_RESULT_OK != rr) goto cleanup;
1112 }
1113 else {
1115 if (NULL == builder) {
1116 rv = APR_ENOMEM;
1117 goto cleanup;
1118 }
1119 }
1120
1121 /* decide on the application protocol, this may change other
1122 * settings like client_auth. */
1124
1125 if (cc->client_auth != TLS_CLIENT_AUTH_NONE) {
1126 ap_assert(sc->client_ca); /* checked in server_setup */
1130 if (APR_SUCCESS != rv) goto cleanup;
1132 }
1133 else {
1136 if (APR_SUCCESS != rv) goto cleanup;
1138 }
1139 }
1140
1142
1145 if (RUSTLS_RESULT_OK != rr) goto cleanup;
1146
1148 if (APR_SUCCESS != rv) goto cleanup;
1149
1151 builder = NULL;
1152 if (!config) {
1153 rv = APR_ENOMEM; goto cleanup;
1154 }
1155
1157 if (RUSTLS_RESULT_OK != rr) goto cleanup;
1159
1160cleanup:
1161 if (rr != RUSTLS_RESULT_OK) {
1162 const char *err_descr = NULL;
1163 rv = tls_util_rustls_error(c->pool, rr, &err_descr);
1165 "Failed to init session for server %s: [%d] %s",
1166 sc->server->server_hostname, (int)rr, err_descr);
1167 }
1168 if (APR_SUCCESS == rv) {
1169 *pconfig = config;
1172 "tls_core_conn_server_init done: %s",
1173 sc->server->server_hostname);
1174 }
1175 else {
1177 "Failed to init session for server %s",
1178 sc->server->server_hostname);
1179 c->aborted = 1;
1180 if (config) rustls_server_config_free(config);
1182 }
1183 return rv;
1184}
1185
1187{
1191 int sni_match = 0;
1192
1193 /* The initial rustls generic session has been fed the client hello and
1194 * we have extracted SNI and ALPN values (so present).
1195 * Time to select the actual server_rec and application protocol that
1196 * will be used on this connection. */
1197 ap_assert(cc);
1198 sc = tls_conf_server_get(cc->server);
1199 if (!cc->client_hello_seen) goto cleanup;
1200
1201 if (cc->sni_hostname) {
1204 "vhost_init: virtual host found for SNI '%s'", cc->sni_hostname);
1205 sni_match = 1;
1206 }
1209 "vhost_init: virtual host NOT found, but base server[%s] matches SNI '%s'",
1211 cc->server = ap_server_conf;
1212 sni_match = 1;
1213 }
1214 else if (sc->strict_sni == TLS_FLAG_FALSE) {
1216 "vhost_init: no virtual host found, relaxed SNI checking enabled, SNI '%s'",
1217 cc->sni_hostname);
1218 }
1219 else {
1221 "vhost_init: no virtual host, nor base server[%s] matches SNI '%s'",
1222 c->base_server->server_hostname, cc->sni_hostname);
1223 cc->server = sc->global->ap_server;
1224 rv = APR_NOTFOUND; goto cleanup;
1225 }
1226 }
1227 else {
1229 "vhost_init: no SNI hostname provided by client");
1230 }
1231
1232 /* reinit, we might have a new server selected */
1233 sc = tls_conf_server_get(cc->server);
1234 /* on relaxed SNI matches, we do not enforce the 503 of fallback
1235 * certificates. */
1236 if (!cc->service_unavailable) {
1238 }
1239
1240 /* if found or not, cc->server will be the server we use now to do
1241 * the real handshake and, if successful, the traffic after that.
1242 * Free the current session and create the real one for the
1243 * selected server. */
1244 if (cc->rustls_server_config) {
1247 }
1249 cc->rustls_connection = NULL;
1250
1252
1253cleanup:
1254 return rv;
1255}
1256
1258{
1262 const rustls_certificate *cert;
1264
1266 rv = APR_EGENERAL;
1268 "post handshake, but rustls claims to still be handshaking: %s",
1269 cc->server->server_hostname);
1270 goto cleanup;
1271 }
1272
1275 cc->tls_protocol_id, c->pool);
1277 if (!rsuite) {
1278 rv = APR_EGENERAL;
1280 "post handshake, but rustls does not report negotiated cipher suite: %s",
1281 cc->server->server_hostname);
1282 goto cleanup;
1283 }
1286 cc->tls_cipher_id, c->pool);
1287 ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c, "post_handshake %s: %s [%s]",
1289
1291 if (cert) {
1292 size_t i = 0;
1293
1294 cc->peer_certs = apr_array_make(c->pool, 5, sizeof(const rustls_certificate*));
1295 while (cert) {
1298 }
1299 }
1300 if (!cc->peer_certs && sc->client_auth == TLS_CLIENT_AUTH_REQUIRED) {
1302 "A client certificate is required, but no acceptable certificate was presented.");
1303 rv = APR_ECONNABORTED;
1304 }
1305
1307cleanup:
1308 return rv;
1309}
1310
1315{
1316 tls_conf_server_t *oc, *sc;
1317 const rustls_certified_key *sk, *ok;
1318 int i;
1319
1320 /* - differences in certificates are the responsibility of the client.
1321 * if it thinks the SNI server works for r->server, we are fine with that.
1322 * - if there are differences in requirements to client certificates, we
1323 * need to deny the request.
1324 */
1325 if (!cc->server || !other) return 0;
1326 if (cc->server == other) return 1;
1327 oc = tls_conf_server_get(other);
1328 if (!oc) return 0;
1329 sc = tls_conf_server_get(cc->server);
1330 if (!sc) return 0;
1331
1332 /* same certified keys used? */
1333 if (sc->certified_keys->nelts != oc->certified_keys->nelts) return 0;
1334 for (i = 0; i < sc->certified_keys->nelts; ++i) {
1336 ok = APR_ARRAY_IDX(oc->certified_keys, i, const rustls_certified_key*);
1337 if (sk != ok) return 0;
1338 }
1339
1340 /* If the connection TLS version is below other other min one, no */
1341 if (oc->tls_protocol_min > 0 && cc->tls_protocol_id < oc->tls_protocol_min) return 0;
1342 /* If the connection TLS cipher is listed as suppressed by other, no */
1343 if (oc->tls_supp_ciphers && tls_util_array_uint16_contains(
1344 oc->tls_supp_ciphers, cc->tls_cipher_id)) return 0;
1345 return 1;
1346}
1347
1349{
1350 conn_rec *c = r->connection;
1351 tls_conf_conn_t *cc = tls_conf_conn_get(c->master? c->master : c);
1352 int rv = DECLINED; /* do not object to the request */
1353
1354 /* If we are not enabled on this connection, leave. We are not renegotiating.
1355 * Otherwise:
1356 * - service is unavailable when we have only a fallback certificate or
1357 * when a challenge protocol is active (ACME tls-alpn-01 for example).
1358 * - with vhosts configured and no SNI from the client, deny access.
1359 * - are servers compatible for connection sharing?
1360 */
1361 if (!TLS_CONN_ST_IS_ENABLED(cc)) goto cleanup;
1362
1364 "tls_core_request_check[%s, %d]: %s", r->hostname,
1365 cc? cc->service_unavailable : 2, r->the_request);
1366 if (cc->service_unavailable) {
1368 }
1370 rv = HTTP_FORBIDDEN; goto cleanup;
1371 }
1372 if (!tls_conn_compatible_for(cc, r->server)) {
1375 "Connection host %s, selected via SNI, and request host %s"
1376 " have incompatible TLS configurations.",
1378 goto cleanup;
1379 }
1380cleanup:
1381 return rv;
1382}
1383
1385{
1387 apr_status_t rv;
1388
1389 rv = tls_util_rustls_error(c->pool, rr, perrstr);
1390 if (cc) {
1391 cc->last_error = rr;
1393 }
1394 return rv;
1395}
1396
1398{
1399 tls_conf_conn_t *cc;
1400 int rv = DECLINED;
1401
1403 "tls_core_setup_outgoing called");
1404#if AP_MODULE_MAGIC_AT_LEAST(20120211, 109)
1405 if (!c->outgoing) goto cleanup;
1406#endif
1407 cc = cc_get_or_make(c);
1408 if (cc->state == TLS_CONN_ST_DISABLED) {
1410 "tls_core_setup_outgoing: already disabled");
1411 goto cleanup;
1412 }
1413 if (TLS_CONN_ST_IS_ENABLED(cc)) {
1414 /* we already handle it, allow repeated calls */
1416 "tls_core_setup_outgoing: already enabled");
1417 rv = OK; goto cleanup;
1418 }
1419 cc->outgoing = 1;
1420 if (!cc->dc) {
1421 /* In case there is not dir_conf bound for this connection, we fallback
1422 * to the defaults in the base server (we have no virtual host config to use) */
1423 cc->dc = ap_get_module_config(c->base_server->lookup_defaults, &tls_module);
1424 }
1425 if (cc->dc->proxy_enabled != TLS_FLAG_TRUE) {
1428 "tls_core_setup_outgoing: TLSProxyEngine not configured");
1429 goto cleanup;
1430 }
1431 /* we handle this connection */
1433 rv = OK;
1434
1435cleanup:
1437 "tls_core_setup_outgoing returns %s", rv == OK? "OK" : "DECLINED");
1438 return rv;
1439}
int n
Definition ap_regex.h:278
const char apr_size_t len
Definition ap_regex.h:187
Small object cache provider interface.
APR general purpose library routines.
APR Network library.
APR Strings library.
#define APLOG_USE_MODULE(foo)
#define ap_get_module_config(v, m)
struct ap_conf_vector_t ap_conf_vector_t
#define ap_set_module_config(v, m, val)
const char * hostname
request_rec * r
#define DECLINED
Definition httpd.h:457
#define OK
Definition httpd.h:456
#define APLOGNO(n)
Definition http_log.h:117
#define APLOGctrace2(c)
Definition http_log.h:258
#define APLOG_TRACE4
Definition http_log.h:75
#define APLOG_INFO
Definition http_log.h:70
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_ERR
Definition http_log.h:67
#define APLOG_TRACE3
Definition http_log.h:74
#define ap_log_error
Definition http_log.h:370
#define ap_log_cerror
Definition http_log.h:498
#define APLOGctrace4(c)
Definition http_log.h:260
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_WARNING
Definition http_log.h:68
#define APLOG_TRACE2
Definition http_log.h:73
#define APLOG_TRACE1
Definition http_log.h:72
#define APLOGtrace2(s)
Definition http_log.h:236
#define APLOG_DEBUG
Definition http_log.h:71
server_rec * ap_server_conf
Definition config.c:62
int ap_ssl_answer_challenge(conn_rec *c, const char *server_name, const char **pcert_pem, const char **pkey_pem)
Definition ssl.c:239
apr_status_t ap_switch_protocol(conn_rec *c, request_rec *r, server_rec *s, const char *protocol)
Definition protocol.c:2532
const char * ap_get_protocol(conn_rec *c)
Definition protocol.c:2397
apr_status_t ap_ssl_add_cert_files(server_rec *s, apr_pool_t *p, apr_array_header_t *cert_files, apr_array_header_t *key_files)
Definition ssl.c:223
const char * ap_select_protocol(conn_rec *c, request_rec *r, server_rec *s, const apr_array_header_t *choices)
Definition protocol.c:2444
apr_status_t ap_ssl_add_fallback_cert_files(server_rec *s, apr_pool_t *p, apr_array_header_t *cert_files, apr_array_header_t *key_files)
Definition ssl.c:231
#define APR_EGENERAL
Definition apr_errno.h:313
#define APR_ENOMEM
Definition apr_errno.h:683
#define APR_ENOTIMPL
Definition apr_errno.h:476
#define APR_ECONNABORTED
Definition apr_errno.h:769
#define APR_NOTFOUND
Definition apr_errno.h:463
#define APR_EINVAL
Definition apr_errno.h:711
int enabled
apr_redis_server_t * rs
Definition apr_redis.h:205
#define HTTP_SERVICE_UNAVAILABLE
Definition httpd.h:538
#define HTTP_FORBIDDEN
Definition httpd.h:511
#define HTTP_MISDIRECTED_REQUEST
Definition httpd.h:526
#define ap_assert(exp)
Definition httpd.h:2271
apr_size_t size
const char int apr_pool_t * pool
Definition apr_cstr.h:84
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
const char * key
void * data
void const char apr_status_t(* cleanup)(void *))
int strcasecmp(const char *a, const char *b)
apr_vformatter_buff_t * c
Definition apr_lib.h:175
apr_sockaddr_t * sa
int int int protocol
const char apr_uint32_t * id
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
const void apr_size_t bytes
Definition apr_random.h:91
const char char ** last
const char * s
Definition apr_strings.h:95
#define APR_ARRAY_PUSH(ary, type)
Definition apr_tables.h:150
#define APR_ARRAY_IDX(ary, i, type)
Definition apr_tables.h:141
CORE HTTP Daemon.
Apache Logging library.
Command line options.
HTTP protocol handling.
SSL protocol handling.
Virtual Host package.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
static long gc(server_rec *s)
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
apr_sockaddr_t * next
Structure to store things which are per connection.
Definition httpd.h:1152
void * vhost_lookup_data
Definition httpd.h:1158
A structure that represents the current request.
Definition httpd.h:845
const char * hostname
Definition httpd.h:883
char * the_request
Definition httpd.h:866
conn_rec * connection
Definition httpd.h:849
server_rec * server
Definition httpd.h:851
A structure to be used for Per-vhost config.
Definition httpd.h:1301
A structure to store information for each virtual server.
Definition httpd.h:1322
server_rec * next
Definition httpd.h:1326
char * server_hostname
Definition httpd.h:1365
const char * cert_file
Definition tls_cert.h:33
const char * pkey_pem
Definition tls_cert.h:36
const char * pkey_file
Definition tls_cert.h:34
const char * cert_pem
Definition tls_cert.h:35
rustls_connection * rustls_connection
Definition tls_core.h:49
const char * sni_hostname
Definition tls_core.h:58
const char * application_protocol
Definition tls_core.h:60
const char * tls_protocol_name
Definition tls_core.h:65
tls_client_auth_t client_auth
Definition tls_core.h:46
server_rec * server
Definition tls_core.h:40
apr_uint16_t tls_protocol_id
Definition tls_core.h:64
const rustls_server_config * rustls_server_config
Definition tls_core.h:50
const rustls_client_config * rustls_client_config
Definition tls_core.h:51
int client_hello_seen
Definition tls_core.h:47
tls_conf_dir_t * dc
Definition tls_core.h:42
const char * last_error_descr
Definition tls_core.h:73
apr_uint16_t tls_cipher_id
Definition tls_core.h:66
apr_array_header_t * peer_certs
Definition tls_core.h:57
int service_unavailable
Definition tls_core.h:45
tls_conn_state_t state
Definition tls_core.h:43
apr_array_header_t * local_keys
Definition tls_core.h:54
const apr_array_header_t * alpn
Definition tls_core.h:59
const char * tls_cipher_name
Definition tls_core.h:67
const rustls_certified_key * key
Definition tls_core.h:55
rustls_result last_error
Definition tls_core.h:72
tls_conf_proxy_t * proxy_config
Definition tls_conf.h:139
struct tls_cert_reg_t * cert_reg
Definition tls_conf.h:79
struct tls_cert_verifiers_t * verifiers
Definition tls_conf.h:81
struct tls_proto_conf_t * proto
Definition tls_conf.h:77
server_rec * ap_server
Definition tls_conf.h:67
const rustls_server_config * rustls_hello_config
Definition tls_conf.h:88
apr_array_header_t * certified_keys
Definition tls_conf.h:112
const char * client_ca
Definition tls_conf.h:108
tls_client_auth_t client_auth
Definition tls_conf.h:109
apr_array_header_t * tls_supp_ciphers
Definition tls_conf.h:103
apr_array_header_t * tls_pref_ciphers
Definition tls_conf.h:102
server_rec * server
Definition tls_conf.h:96
apr_array_header_t * cert_specs
Definition tls_conf.h:100
const apr_array_header_t * ciphersuites
Definition tls_conf.h:104
tls_conf_global_t * global
Definition tls_conf.h:97
static const char hello[]
void tls_cache_free(server_rec *s)
Definition tls_cache.c:189
apr_status_t tls_cache_init_server(rustls_server_config_builder *builder, server_rec *s)
Definition tls_cache.c:299
apr_status_t tls_cache_post_config(apr_pool_t *p, apr_pool_t *ptemp, server_rec *s)
Definition tls_cache.c:137
apr_status_t tls_cert_client_verifiers_get_optional(tls_cert_verifiers_t *verifiers, const char *store_file, const rustls_client_cert_verifier **pverifier)
Definition tls_cert.c:577
apr_status_t tls_cert_root_stores_get(tls_cert_root_stores_t *stores, const char *store_file, const rustls_root_cert_store **pstore)
Definition tls_cert.c:428
void tls_cert_verifiers_clear(tls_cert_verifiers_t *verifiers)
Definition tls_cert.c:498
apr_status_t tls_cert_reg_get_certified_key(tls_cert_reg_t *reg, server_rec *s, const tls_cert_spec_t *spec, const rustls_certified_key **pckey)
Definition tls_cert.c:266
void tls_cert_root_stores_clear(tls_cert_root_stores_t *stores)
Definition tls_cert.c:420
apr_status_t tls_cert_load_cert_key(apr_pool_t *p, const tls_cert_spec_t *spec, const char **pcert_pem, const rustls_certified_key **pckey)
Definition tls_cert.c:177
const char * tls_cert_reg_get_id(tls_cert_reg_t *reg, const rustls_certified_key *certified_key)
Definition tls_cert.c:325
tls_cert_verifiers_t * tls_cert_verifiers_make(apr_pool_t *p, tls_cert_root_stores_t *stores)
Definition tls_cert.c:485
tls_cert_reg_t * tls_cert_reg_make(apr_pool_t *p)
Definition tls_cert.c:242
apr_status_t tls_cert_client_verifiers_get(tls_cert_verifiers_t *verifiers, const char *store_file, const rustls_client_cert_verifier **pverifier)
Definition tls_cert.c:569
tls_cert_root_stores_t * tls_cert_root_stores_make(apr_pool_t *p)
Definition tls_cert.c:409
apr_status_t tls_conf_dir_apply_defaults(tls_conf_dir_t *dc, apr_pool_t *p)
Definition tls_conf.c:214
tls_conf_proxy_t * tls_conf_proxy_make(apr_pool_t *p, tls_conf_dir_t *dc, tls_conf_global_t *gc, server_rec *s)
Definition tls_conf.c:223
tls_conf_server_t * tls_conf_server_get(server_rec *s)
Definition tls_conf.c:68
apr_status_t tls_conf_server_apply_defaults(tls_conf_server_t *sc, apr_pool_t *p)
Definition tls_conf.c:203
tls_conf_dir_t * tls_conf_dir_server_get(server_rec *s)
Definition tls_conf.c:131
#define TLS_FLAG_FALSE
Definition tls_conf.h:21
@ TLS_CONF_ST_DONE
Definition tls_conf.h:60
@ TLS_CONF_ST_INIT
Definition tls_conf.h:57
@ TLS_CONF_ST_OUTGOING_DONE
Definition tls_conf.h:59
@ TLS_CONF_ST_INCOMING_DONE
Definition tls_conf.h:58
@ TLS_CLIENT_AUTH_REQUIRED
Definition tls_conf.h:52
@ TLS_CLIENT_AUTH_NONE
Definition tls_conf.h:51
#define TLS_FLAG_TRUE
Definition tls_conf.h:22
static apr_status_t load_certified_keys(apr_array_header_t *keys, server_rec *s, apr_array_header_t *cert_specs, tls_cert_reg_t *cert_reg)
Definition tls_core.c:99
static apr_status_t build_server_connection(rustls_connection **pconnection, const rustls_server_config **pconfig, conn_rec *c)
Definition tls_core.c:1062
apr_status_t tls_core_conn_post_handshake(conn_rec *c)
Definition tls_core.c:1257
static apr_status_t tls_core_free(void *data)
Definition tls_core.c:86
static apr_status_t use_local_key(conn_rec *c, const char *cert_pem, const char *pkey_pem)
Definition tls_core.c:129
apr_status_t tls_core_conn_init(conn_rec *c)
Definition tls_core.c:934
apr_status_t tls_core_init(apr_pool_t *p, apr_pool_t *ptemp, server_rec *base_server)
Definition tls_core.c:665
static const rustls_certified_key * extract_client_hello_values(void *userdata, const rustls_client_hello *hello)
Definition tls_core.c:499
int tls_core_setup_outgoing(conn_rec *c)
Definition tls_core.c:1397
static int we_listen_on(tls_conf_global_t *gc, server_rec *s, tls_conf_server_t *sc)
Definition tls_core.c:64
static apr_status_t calc_ciphers(apr_pool_t *pool, server_rec *s, tls_conf_global_t *gc, const char *proxy, apr_array_header_t *pref_ciphers, apr_array_header_t *supp_ciphers, const apr_array_header_t **pciphers)
Definition tls_core.c:169
static int tls_conn_compatible_for(tls_conf_conn_t *cc, server_rec *other)
Definition tls_core.c:1314
static apr_status_t init_outgoing_connection(conn_rec *c)
Definition tls_core.c:761
void tls_core_conn_bind(conn_rec *c, ap_conf_vector_t *dir_conf)
Definition tls_core.c:754
static void add_file_specs(apr_array_header_t *certificates, apr_pool_t *p, apr_array_header_t *cert_files, apr_array_header_t *key_files)
Definition tls_core.c:152
static tls_conf_conn_t * cc_get_or_make(conn_rec *c)
Definition tls_core.c:731
static apr_status_t setup_hello_config(apr_pool_t *p, server_rec *base_server, tls_conf_global_t *gc)
Definition tls_core.c:545
apr_status_t tls_core_error(conn_rec *c, rustls_result rr, const char **perrstr)
Definition tls_core.c:1384
void tls_core_conn_disable(conn_rec *c)
Definition tls_core.c:745
static apr_status_t select_application_protocol(conn_rec *c, server_rec *s, rustls_server_config_builder *builder)
Definition tls_core.c:985
static apr_status_t server_conf_setup(apr_pool_t *p, apr_pool_t *ptemp, tls_conf_server_t *sc, tls_conf_global_t *gc)
Definition tls_core.c:379
static apr_status_t init_outgoing(apr_pool_t *p, apr_pool_t *ptemp, server_rec *base_server)
Definition tls_core.c:627
int tls_conn_check_ssl(conn_rec *c)
Definition tls_core.c:55
int tls_core_request_check(request_rec *r)
Definition tls_core.c:1348
static apr_status_t proxy_conf_setup(apr_pool_t *p, apr_pool_t *ptemp, tls_conf_proxy_t *pc, tls_conf_global_t *gc)
Definition tls_core.c:443
static int find_vhost(void *sni_hostname, conn_rec *c, server_rec *s)
Definition tls_core.c:975
static apr_status_t get_server_ciphersuites(const apr_array_header_t **pciphersuites, apr_pool_t *pool, tls_conf_server_t *sc)
Definition tls_core.c:249
int tls_core_pre_conn_init(conn_rec *c)
Definition tls_core.c:904
void tls_conf_conn_set(conn_rec *c, tls_conf_conn_t *cc)
Definition tls_core.c:50
static apr_status_t tls_core_conn_free(void *data)
Definition tls_core.c:697
static apr_status_t get_proxy_ciphers(const apr_array_header_t **pciphersuites, apr_pool_t *pool, tls_conf_proxy_t *pc)
Definition tls_core.c:416
static apr_array_header_t * complete_cert_specs(apr_pool_t *p, tls_conf_server_t *sc)
Definition tls_core.c:278
static const rustls_certified_key * select_certified_key(void *userdata, const rustls_client_hello *hello)
Definition tls_core.c:324
tls_conf_conn_t * tls_conf_conn_get(conn_rec *c)
Definition tls_core.c:45
static apr_status_t init_incoming(apr_pool_t *p, apr_pool_t *ptemp, server_rec *base_server)
Definition tls_core.c:572
apr_status_t tls_core_conn_seen_client_hello(conn_rec *c)
Definition tls_core.c:1186
#define TLS_CONN_ST_IS_ENABLED(cc)
Definition tls_core.h:31
@ TLS_CONN_ST_INIT
Definition tls_core.h:22
@ TLS_CONN_ST_DISABLED
Definition tls_core.h:23
@ TLS_CONN_ST_CLIENT_HELLO
Definition tls_core.h:24
apr_status_t tls_ocsp_prime_certs(tls_conf_global_t *gc, apr_pool_t *p, server_rec *s)
Definition tls_ocsp.c:52
apr_status_t tls_ocsp_update_key(conn_rec *c, const rustls_certified_key *certified_key, const rustls_certified_key **pkey_out)
Definition tls_ocsp.c:88
const char * tls_proto_get_cipher_names(tls_proto_conf_t *conf, const apr_array_header_t *ciphers, apr_pool_t *pool)
Definition tls_proto.c:464
int tls_proto_is_cipher_supported(tls_proto_conf_t *conf, apr_uint16_t cipher)
Definition tls_proto.c:560
const char * tls_proto_get_version_name(tls_proto_conf_t *conf, apr_uint16_t id, apr_pool_t *pool)
Definition tls_proto.c:530
apr_array_header_t * tls_proto_create_versions_plus(tls_proto_conf_t *conf, apr_uint16_t min_version, apr_pool_t *pool)
Definition tls_proto.c:544
apr_array_header_t * tls_proto_get_rustls_suites(tls_proto_conf_t *conf, const apr_array_header_t *ids, apr_pool_t *pool)
Definition tls_proto.c:586
apr_status_t tls_proto_post_config(apr_pool_t *pool, apr_pool_t *ptemp, server_rec *s)
Definition tls_proto.c:485
const char * tls_proto_get_cipher_name(tls_proto_conf_t *conf, apr_uint16_t id, apr_pool_t *pool)
Definition tls_proto.c:576
int tls_util_name_matches_server(const char *name, server_rec *s)
Definition tls_util.c:292
apr_status_t tls_util_rustls_error(apr_pool_t *p, rustls_result rr, const char **perr_descr)
Definition tls_util.c:66
const apr_array_header_t * tls_util_array_uint16_remove(apr_pool_t *pool, const apr_array_header_t *from, const apr_array_header_t *others)
Definition tls_util.c:150
int tls_util_array_uint16_contains(const apr_array_header_t *a, apr_uint16_t n)
Definition tls_util.c:141
apr_status_t tls_var_handshake_done(conn_rec *c)
Definition tls_var.c:358
int ap_vhost_iterate_given_conn(conn_rec *conn, ap_vhost_iterate_conn_cb func_cb, void *baton)
Definition vhost.c:1229