Apache HTTPD
tls_ocsp.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
20#include <httpd.h>
21#include <http_connection.h>
22#include <http_core.h>
23#include <http_log.h>
24#include <http_ssl.h>
25
26#include <rustls.h>
27
28#include "tls_cert.h"
29#include "tls_conf.h"
30#include "tls_core.h"
31#include "tls_proto.h"
32#include "tls_ocsp.h"
33
34extern module AP_MODULE_DECLARE_DATA tls_module;
36
37
38static int prime_cert(
39 void *userdata, server_rec *s, const char *cert_id, const char *cert_pem,
40 const rustls_certified_key *certified_key)
41{
42 apr_pool_t *p = userdata;
43 apr_status_t rv;
44
45 (void)certified_key;
46 rv = ap_ssl_ocsp_prime(s, p, cert_id, strlen(cert_id), cert_pem);
47 ap_log_error(APLOG_MARK, APLOG_TRACE1, rv, s, "ocsp prime of cert [%s] from %s",
48 cert_id, s->server_hostname);
49 return 1;
50}
51
53{
54 ap_log_error(APLOG_MARK, APLOG_TRACE1, 0, s, "ocsp priming of %d certs",
55 (int)tls_cert_reg_count(gc->cert_reg));
56 tls_cert_reg_do(prime_cert, p, gc->cert_reg);
57 return APR_SUCCESS;
58}
59
60typedef struct {
65
66static void ocsp_clone_key(const unsigned char *der, apr_size_t der_len, void *userdata)
67{
68 ocsp_copy_ctx_t *ctx = userdata;
71
72 rslice.data = der;
73 rslice.len = der_len;
74
75 rr = rustls_certified_key_clone_with_ocsp(ctx->key_in, der_len? &rslice : NULL, &ctx->key_out);
76 if (RUSTLS_RESULT_OK != rr) {
77 const char *err_descr = NULL;
80 "Failed add OCSP data to certificate: [%d] %s", (int)rr, err_descr);
81 }
82 else {
84 "provided %ld bytes of ocsp response DER data to key.", (long)der_len);
85 }
86}
87
89 conn_rec *c, const rustls_certified_key *certified_key,
91{
94 const char *key_id;
97
98 assert(cc);
99 assert(cc->server);
100 sc = tls_conf_server_get(cc->server);
101 key_id = tls_cert_reg_get_id(sc->global->cert_reg, certified_key);
102 if (!key_id) {
103 rv = APR_ENOENT;
104 ap_log_cerror(APLOG_MARK, APLOG_TRACE1, rv, c, "certified key not registered");
105 goto cleanup;
106 }
107
108 ctx.c = c;
109 ctx.key_in = certified_key;
110 ctx.key_out = NULL;
111 rv = ap_ssl_ocsp_get_resp(cc->server, c, key_id, strlen(key_id), ocsp_clone_key, &ctx);
112 if (APR_SUCCESS != rv) {
114 "ocsp response not available for cert %s", key_id);
115 }
116
117cleanup:
118 *pkey_out = (APR_SUCCESS == rv)? ctx.key_out : NULL;
119 return rv;
120}
APR general purpose library routines.
APR Strings library.
#define APLOG_USE_MODULE(foo)
#define APLOGNO(n)
Definition http_log.h:117
#define APLOG_ERR
Definition http_log.h:67
#define ap_log_error
Definition http_log.h:370
#define ap_log_cerror
Definition http_log.h:498
#define APLOG_MARK
Definition http_log.h:283
#define APLOG_TRACE1
Definition http_log.h:72
apr_status_t ap_ssl_ocsp_get_resp(server_rec *s, conn_rec *c, const char *id, apr_size_t id_len, ap_ssl_ocsp_copy_resp *cb, void *userdata)
Definition ssl.c:253
apr_status_t ap_ssl_ocsp_prime(server_rec *s, apr_pool_t *p, const char *id, apr_size_t id_len, const char *pem)
Definition ssl.c:245
#define APR_ENOENT
Definition apr_errno.h:662
apr_brigade_flush void * ctx
apr_size_t size
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
void const char apr_status_t(* cleanup)(void *))
apr_vformatter_buff_t * c
Definition apr_lib.h:175
const char * s
Definition apr_strings.h:95
Apache connection library.
CORE HTTP Daemon.
Apache Logging library.
SSL protocol handling.
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
Structure to store things which are per connection.
Definition httpd.h:1152
conn_rec * c
Definition tls_ocsp.c:61
const rustls_certified_key * key_out
Definition tls_ocsp.c:63
const rustls_certified_key * key_in
Definition tls_ocsp.c:62
A structure to store information for each virtual server.
Definition httpd.h:1322
server_rec * server
Definition tls_core.h:40
struct tls_cert_reg_t * cert_reg
Definition tls_conf.h:79
tls_conf_global_t * global
Definition tls_conf.h:97
apr_size_t tls_cert_reg_count(tls_cert_reg_t *reg)
Definition tls_cert.c:254
void tls_cert_reg_do(tls_cert_reg_visitor *visitor, void *userdata, tls_cert_reg_t *reg)
Definition tls_cert.c:316
const char * tls_cert_reg_get_id(tls_cert_reg_t *reg, const rustls_certified_key *certified_key)
Definition tls_cert.c:325
tls_conf_server_t * tls_conf_server_get(server_rec *s)
Definition tls_conf.c:68
tls_conf_conn_t * tls_conf_conn_get(conn_rec *c)
Definition tls_core.c:45
apr_status_t tls_ocsp_prime_certs(tls_conf_global_t *gc, apr_pool_t *p, server_rec *s)
Definition tls_ocsp.c:52
static void ocsp_clone_key(const unsigned char *der, apr_size_t der_len, void *userdata)
Definition tls_ocsp.c:66
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
static int prime_cert(void *userdata, server_rec *s, const char *cert_id, const char *cert_pem, const rustls_certified_key *certified_key)
Definition tls_ocsp.c:38
apr_status_t tls_util_rustls_error(apr_pool_t *p, rustls_result rr, const char **perr_descr)
Definition tls_util.c:66