source: mod_gnutls/src/gnutls_ocsp.h

mod_gnutls/0.12.0
Last change on this file was 9c4ae9c2, checked in by Fiona Klute <fiona.klute@…>, 3 months ago

Use the issuer certificate directly to verify OCSP responses

The detour over a trust list is unnecessary by using
gnutls_ocsp_resp_verify_direct(), which simplifies the code a lot, and
also avoids a current bug in gnutls_ocsp_resp_verify() [1].

[1] https://gitlab.com/gnutls/gnutls/-/issues/1254

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 *  Copyright 2016-2020 Fiona Klute
3 *
4 *  Licensed under the Apache License, Version 2.0 (the "License");
5 *  you may not use this file except in compliance with the License.
6 *  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
17#ifndef __MOD_GNUTLS_OCSP_H__
18#define __MOD_GNUTLS_OCSP_H__
19
20#include "mod_gnutls.h"
21
22#include <gnutls/gnutls.h>
23#include <gnutls/x509.h>
24#include <httpd.h>
25#include <http_config.h>
26
27#define MGS_OCSP_MUTEX_NAME "gnutls-ocsp"
28#define MGS_OCSP_CACHE_MUTEX_NAME "gnutls-ocsp-cache"
29#define MGS_OCSP_CACHE_NAME "gnutls_ocsp"
30
31/** Default OCSP response cache timeout in seconds */
32#define MGS_OCSP_CACHE_TIMEOUT 3600
33/** Default OCSP failure timeout in seconds */
34#define MGS_OCSP_FAILURE_TIMEOUT 300
35/** Default socket timeout for OCSP responder connections, in
36 * seconds. Note that the timeout applies to "absolutely no data sent
37 * or received", not the whole connection. 10 seconds in mod_ssl. */
38#define MGS_OCSP_SOCKET_TIMEOUT 6
39
40/**
41 * Vhost specific OCSP data structure
42 */
43struct mgs_ocsp_data {
44    /** The certificate the following elements refer to. */
45    gnutls_x509_crt_t cert;
46    /** Issuer certificate, used for verifying OCSP responses. */
47    gnutls_x509_crt_t issuer;
48    /** OCSP URI extracted from the certificate. NULL if unset. */
49    apr_uri_t *uri;
50    /** OCSP response file for the certificate. NULL if unset. Takes
51     * precedence over uri. */
52    char *response_file;
53    /** Certificate fingerprint, used as cache key for the OCSP
54     * response. */
55    gnutls_datum_t fingerprint;
56    /** Server (virtual host) that uses the certificate */
57    server_rec *server;
58};
59
60const char *mgs_ocsp_stapling_enable(cmd_parms *parms,
61                                     void *dummy __attribute__((unused)),
62                                     const int arg);
63
64const char *mgs_set_ocsp_auto_refresh(cmd_parms *parms,
65                                      void *dummy __attribute__((unused)),
66                                      const int arg);
67
68const char *mgs_set_ocsp_check_nonce(cmd_parms *parms,
69                                     void *dummy __attribute__((unused)),
70                                     const int arg);
71
72const char *mgs_store_ocsp_response_path(cmd_parms * parms,
73                                         void *dummy __attribute__((unused)),
74                                         int argc, char *const *argv);
75
76/**
77 * Create a trust list from a certificate chain (one or more
78 * certificates).
79 *
80 * @param tl This trust list will be initialized and filled with the
81 * specified certificate(s)
82 *
83 * @param chain certificate chain, must contain at least `num`
84 * certifictes
85 *
86 * @param num number of certificates to load from chain
87 *
88 * Chain is supposed to be static (the trust chain of the server
89 * certificate), so when `gnutls_x509_trust_list_deinit()` is called on
90 * tl later, the "all" parameter should be zero.
91 *
92 * @return `GNUTLS_E_SUCCESS` or a GnuTLS error code. In case of error
93 * tl will be uninitialized.
94 */
95int mgs_create_ocsp_trust_list(gnutls_x509_trust_list_t *tl,
96                               const gnutls_x509_crt_t *chain,
97                               const int num);
98
99/**
100 * Pool cleanup function that deinits the trust list without
101 * deinitializing certificates.
102 */
103apr_status_t mgs_cleanup_trust_list(void *data);
104
105/**
106 * Try to generate the OCSP stapling configuration for a (virtual)
107 * host. This function must be called in the post_config hook after
108 * certificates have been loaded. This method does not actually enable
109 * stapling, it only prepares the configuration. The reason for
110 * splitting these tasks is that configuration failure may be ignored
111 * if stapling is not explicitly enabled but only opportunistically.
112 *
113 * @return `NULL` on success, a string describing why configuration
114 * failed otherwise (static or allocated from ptemp)
115 */
116const char* mgs_ocsp_configure_stapling(apr_pool_t *pconf, apr_pool_t *ptemp,
117                                        server_rec *server);
118
119/**
120 * Enable OCSP stapling for a (virtual) host. Must be called in the
121 * post_config hook after mgs_ocsp_configure_stapling has returned
122 * successfully for that host.
123 *
124 * @return OK or DECLINED on success, any other value on error (like
125 * the post_config hook)
126 */
127int mgs_ocsp_enable_stapling(apr_pool_t *pconf, apr_pool_t *ptemp,
128                             server_rec *server);
129
130int mgs_get_ocsp_response(mgs_handle_t *ctxt,
131                          struct mgs_ocsp_data *req_data,
132                          gnutls_datum_t *ocsp_response);
133
134#endif /* __MOD_GNUTLS_OCSP_H__ */
Note: See TracBrowser for help on using the repository browser.