]> git.ipfire.org Git - thirdparty/openssl.git/blob - include/openssl/ocsp.h
In OpenSSL builds, declare STACK for datatypes ...
[thirdparty/openssl.git] / include / openssl / ocsp.h
1 /*
2 * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
8 */
9
10 #ifndef OPENSSL_OCSP_H
11 # define OPENSSL_OCSP_H
12 # pragma once
13
14 # include <openssl/macros.h>
15 # ifndef OPENSSL_NO_DEPRECATED_3_0
16 # define HEADER_OCSP_H
17 # endif
18
19 # include <openssl/opensslconf.h>
20
21 /*
22 * These definitions are outside the OPENSSL_NO_OCSP guard because although for
23 * historical reasons they have OCSP_* names, they can actually be used
24 * independently of OCSP. E.g. see RFC5280
25 */
26 /*-
27 * CRLReason ::= ENUMERATED {
28 * unspecified (0),
29 * keyCompromise (1),
30 * cACompromise (2),
31 * affiliationChanged (3),
32 * superseded (4),
33 * cessationOfOperation (5),
34 * certificateHold (6),
35 * -- value 7 is not used
36 * removeFromCRL (8),
37 * privilegeWithdrawn (9),
38 * aACompromise (10) }
39 */
40 # define OCSP_REVOKED_STATUS_NOSTATUS -1
41 # define OCSP_REVOKED_STATUS_UNSPECIFIED 0
42 # define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1
43 # define OCSP_REVOKED_STATUS_CACOMPROMISE 2
44 # define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3
45 # define OCSP_REVOKED_STATUS_SUPERSEDED 4
46 # define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5
47 # define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6
48 # define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8
49 # define OCSP_REVOKED_STATUS_PRIVILEGEWITHDRAWN 9
50 # define OCSP_REVOKED_STATUS_AACOMPROMISE 10
51
52 /*
53 * These definitions are outside the OPENSSL_NO_OCSP guard because although for
54 * historical reasons they have OCSP_* names, they are used for the HTTP client.
55 */
56 # include <openssl/asn1.h>
57 /* The following functions are used only internally */
58 OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *wbio, BIO *rbio,
59 int method_GET, int maxline,
60 unsigned long max_resp_len, int timeout,
61 const char *expected_content_type,
62 int expect_asn1);
63 void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx);
64 int OCSP_REQ_CTX_http(OCSP_REQ_CTX *rctx,
65 const char *server, const char *port, const char *path);
66 int OCSP_REQ_CTX_add1_header(OCSP_REQ_CTX *rctx,
67 const char *name, const char *value);
68 int OCSP_REQ_CTX_i2d(OCSP_REQ_CTX *rctx, const char *content_type,
69 const ASN1_ITEM *it, ASN1_VALUE *req);
70 int OCSP_REQ_CTX_nbio(OCSP_REQ_CTX *rctx);
71 ASN1_VALUE *OCSP_REQ_CTX_nbio_d2i(OCSP_REQ_CTX *rctx, const ASN1_ITEM *it);
72 BIO *OCSP_REQ_CTX_get0_mem_bio(OCSP_REQ_CTX *rctx);
73 void OCSP_set_max_response_length(OCSP_REQ_CTX *rctx, unsigned long len);
74 /* End of functions used only internally */
75
76
77 # ifndef OPENSSL_NO_OCSP
78
79 # include <openssl/x509.h>
80 # include <openssl/x509v3.h>
81 # include <openssl/safestack.h>
82 # include <openssl/ocsperr.h>
83
84 # ifdef __cplusplus
85 extern "C" {
86 # endif
87
88 /* Various flags and values */
89
90 # define OCSP_DEFAULT_NONCE_LENGTH 16
91
92 # define OCSP_NOCERTS 0x1
93 # define OCSP_NOINTERN 0x2
94 # define OCSP_NOSIGS 0x4
95 # define OCSP_NOCHAIN 0x8
96 # define OCSP_NOVERIFY 0x10
97 # define OCSP_NOEXPLICIT 0x20
98 # define OCSP_NOCASIGN 0x40
99 # define OCSP_NODELEGATED 0x80
100 # define OCSP_NOCHECKS 0x100
101 # define OCSP_TRUSTOTHER 0x200
102 # define OCSP_RESPID_KEY 0x400
103 # define OCSP_NOTIME 0x800
104
105 DEFINE_OR_DECLARE_STACK_OF(OCSP_CERTID)
106 DEFINE_OR_DECLARE_STACK_OF(OCSP_ONEREQ)
107 DEFINE_OR_DECLARE_STACK_OF(OCSP_RESPID)
108 DEFINE_OR_DECLARE_STACK_OF(OCSP_SINGLERESP)
109
110 typedef struct ocsp_cert_id_st OCSP_CERTID;
111 typedef struct ocsp_one_request_st OCSP_ONEREQ;
112 typedef struct ocsp_req_info_st OCSP_REQINFO;
113 typedef struct ocsp_signature_st OCSP_SIGNATURE;
114 typedef struct ocsp_request_st OCSP_REQUEST;
115
116 # define OCSP_RESPONSE_STATUS_SUCCESSFUL 0
117 # define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1
118 # define OCSP_RESPONSE_STATUS_INTERNALERROR 2
119 # define OCSP_RESPONSE_STATUS_TRYLATER 3
120 # define OCSP_RESPONSE_STATUS_SIGREQUIRED 5
121 # define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6
122
123 typedef struct ocsp_resp_bytes_st OCSP_RESPBYTES;
124
125 # define V_OCSP_RESPID_NAME 0
126 # define V_OCSP_RESPID_KEY 1
127
128
129 typedef struct ocsp_revoked_info_st OCSP_REVOKEDINFO;
130
131 # define V_OCSP_CERTSTATUS_GOOD 0
132 # define V_OCSP_CERTSTATUS_REVOKED 1
133 # define V_OCSP_CERTSTATUS_UNKNOWN 2
134
135 typedef struct ocsp_cert_status_st OCSP_CERTSTATUS;
136 typedef struct ocsp_single_response_st OCSP_SINGLERESP;
137
138
139 typedef struct ocsp_response_data_st OCSP_RESPDATA;
140
141 typedef struct ocsp_basic_response_st OCSP_BASICRESP;
142
143 typedef struct ocsp_crl_id_st OCSP_CRLID;
144 typedef struct ocsp_service_locator_st OCSP_SERVICELOC;
145
146 # define PEM_STRING_OCSP_REQUEST "OCSP REQUEST"
147 # define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE"
148
149 # define d2i_OCSP_REQUEST_bio(bp,p) ASN1_d2i_bio_of(OCSP_REQUEST,OCSP_REQUEST_new,d2i_OCSP_REQUEST,bp,p)
150
151 # define d2i_OCSP_RESPONSE_bio(bp,p) ASN1_d2i_bio_of(OCSP_RESPONSE,OCSP_RESPONSE_new,d2i_OCSP_RESPONSE,bp,p)
152
153 # define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \
154 (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST, \
155 bp,(char **)(x),cb,NULL)
156
157 # define PEM_read_bio_OCSP_RESPONSE(bp,x,cb) (OCSP_RESPONSE *)PEM_ASN1_read_bio(\
158 (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE, \
159 bp,(char **)(x),cb,NULL)
160
161 # define PEM_write_bio_OCSP_REQUEST(bp,o) \
162 PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\
163 bp,(char *)(o), NULL,NULL,0,NULL,NULL)
164
165 # define PEM_write_bio_OCSP_RESPONSE(bp,o) \
166 PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\
167 bp,(char *)(o), NULL,NULL,0,NULL,NULL)
168
169 # define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio_of(OCSP_RESPONSE,i2d_OCSP_RESPONSE,bp,o)
170
171 # define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio_of(OCSP_REQUEST,i2d_OCSP_REQUEST,bp,o)
172
173 # define ASN1_BIT_STRING_digest(data,type,md,len) \
174 ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len)
175
176 # define OCSP_CERTSTATUS_dup(cs)\
177 (OCSP_CERTSTATUS*)ASN1_dup((i2d_of_void *)i2d_OCSP_CERTSTATUS,\
178 (d2i_of_void *)d2i_OCSP_CERTSTATUS,(char *)(cs))
179
180 DECLARE_ASN1_DUP_FUNCTION(OCSP_CERTID)
181
182 OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req);
183 OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path, OCSP_REQUEST *req,
184 int maxline);
185 int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx);
186
187 /* TODO: remove this (documented but) meanwhile obsolete function? */
188 int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, const OCSP_REQUEST *req);
189
190 OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, const X509 *subject,
191 const X509 *issuer);
192
193 OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
194 const X509_NAME *issuerName,
195 const ASN1_BIT_STRING *issuerKey,
196 const ASN1_INTEGER *serialNumber);
197
198 OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid);
199
200 int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len);
201 int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len);
202 int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs);
203 int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req);
204
205 int OCSP_request_set1_name(OCSP_REQUEST *req, const X509_NAME *nm);
206 int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert);
207
208 int OCSP_request_sign(OCSP_REQUEST *req,
209 X509 *signer,
210 EVP_PKEY *key,
211 const EVP_MD *dgst,
212 STACK_OF(X509) *certs, unsigned long flags);
213
214 int OCSP_response_status(OCSP_RESPONSE *resp);
215 OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp);
216
217 const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *bs);
218 const X509_ALGOR *OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *bs);
219 const OCSP_RESPDATA *OCSP_resp_get0_respdata(const OCSP_BASICRESP *bs);
220 int OCSP_resp_get0_signer(OCSP_BASICRESP *bs, X509 **signer,
221 STACK_OF(X509) *extra_certs);
222
223 int OCSP_resp_count(OCSP_BASICRESP *bs);
224 OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx);
225 const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(const OCSP_BASICRESP* bs);
226 const STACK_OF(X509) *OCSP_resp_get0_certs(const OCSP_BASICRESP *bs);
227 int OCSP_resp_get0_id(const OCSP_BASICRESP *bs,
228 const ASN1_OCTET_STRING **pid,
229 const X509_NAME **pname);
230 int OCSP_resp_get1_id(const OCSP_BASICRESP *bs,
231 ASN1_OCTET_STRING **pid,
232 X509_NAME **pname);
233
234 int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last);
235 int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
236 ASN1_GENERALIZEDTIME **revtime,
237 ASN1_GENERALIZEDTIME **thisupd,
238 ASN1_GENERALIZEDTIME **nextupd);
239 int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
240 int *reason,
241 ASN1_GENERALIZEDTIME **revtime,
242 ASN1_GENERALIZEDTIME **thisupd,
243 ASN1_GENERALIZEDTIME **nextupd);
244 int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
245 ASN1_GENERALIZEDTIME *nextupd, long sec, long maxsec);
246
247 int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs,
248 X509_STORE *store, unsigned long flags);
249
250 # define OCSP_parse_url OSSL_HTTP_parse_url /* for backward compatibility */
251
252 int OCSP_id_issuer_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b);
253 int OCSP_id_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b);
254
255 int OCSP_request_onereq_count(OCSP_REQUEST *req);
256 OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i);
257 OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one);
258 int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd,
259 ASN1_OCTET_STRING **pikeyHash,
260 ASN1_INTEGER **pserial, OCSP_CERTID *cid);
261 int OCSP_request_is_signed(OCSP_REQUEST *req);
262 OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs);
263 OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp,
264 OCSP_CERTID *cid,
265 int status, int reason,
266 ASN1_TIME *revtime,
267 ASN1_TIME *thisupd,
268 ASN1_TIME *nextupd);
269 int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert);
270 int OCSP_basic_sign(OCSP_BASICRESP *brsp,
271 X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
272 STACK_OF(X509) *certs, unsigned long flags);
273 int OCSP_basic_sign_ctx(OCSP_BASICRESP *brsp,
274 X509 *signer, EVP_MD_CTX *ctx,
275 STACK_OF(X509) *certs, unsigned long flags);
276 int OCSP_RESPID_set_by_name(OCSP_RESPID *respid, X509 *cert);
277 int OCSP_RESPID_set_by_key_ex(OCSP_RESPID *respid, X509 *cert,
278 OPENSSL_CTX *libctx, const char *propq);
279 int OCSP_RESPID_set_by_key(OCSP_RESPID *respid, X509 *cert);
280 int OCSP_RESPID_match_ex(OCSP_RESPID *respid, X509 *cert, OPENSSL_CTX *libctx,
281 const char *propq);
282 int OCSP_RESPID_match(OCSP_RESPID *respid, X509 *cert);
283
284 X509_EXTENSION *OCSP_crlID_new(const char *url, long *n, char *tim);
285
286 X509_EXTENSION *OCSP_accept_responses_new(char **oids);
287
288 X509_EXTENSION *OCSP_archive_cutoff_new(char *tim);
289
290 X509_EXTENSION *OCSP_url_svcloc_new(const X509_NAME *issuer, const char **urls);
291
292 int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x);
293 int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos);
294 int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, const ASN1_OBJECT *obj,
295 int lastpos);
296 int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos);
297 X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc);
298 X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc);
299 void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit,
300 int *idx);
301 int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
302 unsigned long flags);
303 int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc);
304
305 int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x);
306 int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos);
307 int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, const ASN1_OBJECT *obj, int lastpos);
308 int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos);
309 X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc);
310 X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc);
311 void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx);
312 int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
313 unsigned long flags);
314 int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc);
315
316 int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x);
317 int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos);
318 int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, const ASN1_OBJECT *obj,
319 int lastpos);
320 int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit,
321 int lastpos);
322 X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc);
323 X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc);
324 void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit,
325 int *idx);
326 int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value,
327 int crit, unsigned long flags);
328 int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc);
329
330 int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x);
331 int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos);
332 int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, const ASN1_OBJECT *obj,
333 int lastpos);
334 int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit,
335 int lastpos);
336 X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc);
337 X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc);
338 void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit,
339 int *idx);
340 int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value,
341 int crit, unsigned long flags);
342 int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc);
343 const OCSP_CERTID *OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *x);
344
345 DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP)
346 DECLARE_ASN1_FUNCTIONS(OCSP_CERTSTATUS)
347 DECLARE_ASN1_FUNCTIONS(OCSP_REVOKEDINFO)
348 DECLARE_ASN1_FUNCTIONS(OCSP_BASICRESP)
349 DECLARE_ASN1_FUNCTIONS(OCSP_RESPDATA)
350 DECLARE_ASN1_FUNCTIONS(OCSP_RESPID)
351 DECLARE_ASN1_FUNCTIONS(OCSP_RESPONSE)
352 DECLARE_ASN1_FUNCTIONS(OCSP_RESPBYTES)
353 DECLARE_ASN1_FUNCTIONS(OCSP_ONEREQ)
354 DECLARE_ASN1_FUNCTIONS(OCSP_CERTID)
355 DECLARE_ASN1_FUNCTIONS(OCSP_REQUEST)
356 DECLARE_ASN1_FUNCTIONS(OCSP_SIGNATURE)
357 DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO)
358 DECLARE_ASN1_FUNCTIONS(OCSP_CRLID)
359 DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC)
360
361 const char *OCSP_response_status_str(long s);
362 const char *OCSP_cert_status_str(long s);
363 const char *OCSP_crl_reason_str(long s);
364
365 int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST *a, unsigned long flags);
366 int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE *o, unsigned long flags);
367
368 int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
369 X509_STORE *st, unsigned long flags);
370
371
372 # ifdef __cplusplus
373 }
374 # endif
375 # endif /* !defined(OPENSSL_NO_OCSP) */
376 #endif