| 1 |
// Copyright 2015-2021 The OpenSSL Project Authors. All Rights Reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
#ifndef AWSLC_OCSP_H |
| 5 |
#define AWSLC_OCSP_H |
| 6 |
|
| 7 |
#include <openssl/asn1t.h> |
| 8 |
#include <openssl/safestack.h> |
| 9 |
#include <openssl/x509.h> |
| 10 |
#include <openssl/x509v3.h> |
| 11 |
|
| 12 |
#if defined(__cplusplus) |
| 13 |
extern "C" { |
| 14 |
#endif |
| 15 |
|
| 16 |
// Various OCSP flags and values |
| 17 |
|
| 18 |
|
| 19 |
// The following constants are OCSP reason codes identify the reason for the |
| 20 |
// certificate revocation. |
| 21 |
// |
| 22 |
// CRLReason ::= ENUMERATED { |
| 23 |
// unspecified (0), |
| 24 |
// keyCompromise (1), |
| 25 |
// cACompromise (2), |
| 26 |
// affiliationChanged (3), |
| 27 |
// superseded (4), |
| 28 |
// cessationOfOperation (5), |
| 29 |
// -- value 7 is not used |
| 30 |
// certificateHold (6), |
| 31 |
// removeFromCRL (8), |
| 32 |
// privilegeWithdrawn (9), |
| 33 |
// aACompromise (10) } |
| 34 |
// |
| 35 |
// Reason Code RFC: https://www.rfc-editor.org/rfc/rfc5280#section-5.3.1 |
| 36 |
// |
| 37 |
// Note: OCSP_REVOKED_STATUS_NOSTATUS is defined by OpenSSL and is not defined |
| 38 |
// within the RFC. |
| 39 |
#define OCSP_REVOKED_STATUS_NOSTATUS -1 |
| 40 |
#define OCSP_REVOKED_STATUS_UNSPECIFIED 0 |
| 41 |
#define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1 |
| 42 |
#define OCSP_REVOKED_STATUS_CACOMPROMISE 2 |
| 43 |
#define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3 |
| 44 |
#define OCSP_REVOKED_STATUS_SUPERSEDED 4 |
| 45 |
#define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5 |
| 46 |
#define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6 |
| 47 |
#define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8 |
| 48 |
#define OCSP_REVOKED_STATUS_PRIVILEGEWITHDRAWN 9 |
| 49 |
#define OCSP_REVOKED_STATUS_AACOMPROMISE 10 |
| 50 |
|
| 51 |
// OCSP_NOCERTS is for |OCSP_request_sign| and |OCSP_basic_sign|. Setting |
| 52 |
// this excludes certificates request/response and ignores the |certs| |
| 53 |
// parameter. Certificates are optional. |
| 54 |
#define OCSP_NOCERTS 0x1 |
| 55 |
// OCSP_NOINTERN is for |OCSP_basic_verify| and |OCSP_request_verify|. |
| 56 |
// Certificates included within |bs| or |req| will be included in the |
| 57 |
// search for the signing certificate by default, unless |OCSP_NOINTERN| is set. |
| 58 |
#define OCSP_NOINTERN 0x2 |
| 59 |
// OCSP_NOCHAIN is for |OCSP_basic_verify| and |OCSP_request_verify|. |
| 60 |
// For |OCSP_basic_verify|, certificates in both |certs| and in |bs| are |
| 61 |
// considered as certificates for the construction of the validation path for |
| 62 |
// the signer certificate by default, unless |OCSP_NOCHAIN| is set. |
| 63 |
// For |OCSP_request_verify|, certificates in |req| are considered as |
| 64 |
// certificates for the construction of the validation path for the signer |
| 65 |
// certificate by default, unless |OCSP_NOCHAIN| is set. |
| 66 |
#define OCSP_NOCHAIN 0x8 |
| 67 |
// OCSP_NOVERIFY is for |OCSP_basic_verify| and |OCSP_request_verify|. When |
| 68 |
// setting this flag, the signature on the OCSP response/request will still be |
| 69 |
// verified, but additionally verification of the signer certificate will be |
| 70 |
// skipped. |
| 71 |
#define OCSP_NOVERIFY 0x10 |
| 72 |
// OCSP_NOEXPLICIT is for |OCSP_basic_verify|. We will check for explicit trust |
| 73 |
// for OCSP signing in the root CA certificate, unless the flags contain |
| 74 |
// |OCSP_NOEXPLICIT|. |
| 75 |
#define OCSP_NOEXPLICIT 0x20 |
| 76 |
// OCSP_TRUSTOTHER is for |OCSP_basic_verify| and |OCSP_request_verify|. When |
| 77 |
// set, all certificates within |certs| are implicitly trusted. |
| 78 |
#define OCSP_TRUSTOTHER 0x200 |
| 79 |
// OCSP_RESPID_KEY is for |OCSP_basic_sign|. By default, the OCSP responder is |
| 80 |
// identified by name and included in the response. Setting this changes the |
| 81 |
// default identifier to be the hash of the issuer's public key instead. |
| 82 |
#define OCSP_RESPID_KEY 0x400 |
| 83 |
// OCSP_NOTIME is for |OCSP_basic_sign|. Setting this excludes the default |
| 84 |
// behavior of setting the |producedAt| time field in |resp| against the current |
| 85 |
// time and leaves it empty. |
| 86 |
#define OCSP_NOTIME 0x800 |
| 87 |
|
| 88 |
|
| 89 |
typedef struct ocsp_cert_id_st OCSP_CERTID; |
| 90 |
typedef struct ocsp_one_request_st OCSP_ONEREQ; |
| 91 |
typedef struct ocsp_req_info_st OCSP_REQINFO; |
| 92 |
typedef struct ocsp_signature_st OCSP_SIGNATURE; |
| 93 |
typedef struct ocsp_request_st OCSP_REQUEST; |
| 94 |
typedef struct ocsp_resp_bytes_st OCSP_RESPBYTES; |
| 95 |
typedef struct ocsp_revoked_info_st OCSP_REVOKEDINFO; |
| 96 |
typedef struct ocsp_cert_status_st OCSP_CERTSTATUS; |
| 97 |
typedef struct ocsp_single_response_st OCSP_SINGLERESP; |
| 98 |
typedef struct ocsp_response_data_st OCSP_RESPDATA; |
| 99 |
typedef struct ocsp_response_st OCSP_RESPONSE; |
| 100 |
typedef struct ocsp_responder_id_st OCSP_RESPID; |
| 101 |
typedef struct ocsp_basic_response_st OCSP_BASICRESP; |
| 102 |
|
| 103 |
DEFINE_STACK_OF(OCSP_CERTID) |
| 104 |
DEFINE_STACK_OF(OCSP_ONEREQ) |
| 105 |
DEFINE_STACK_OF(OCSP_RESPID) |
| 106 |
DEFINE_STACK_OF(OCSP_SINGLERESP) |
| 107 |
|
| 108 |
DECLARE_ASN1_FUNCTIONS(OCSP_BASICRESP) |
| 109 |
DECLARE_ASN1_FUNCTIONS(OCSP_RESPONSE) |
| 110 |
DECLARE_ASN1_FUNCTIONS(OCSP_CERTID) |
| 111 |
DECLARE_ASN1_FUNCTIONS(OCSP_REQUEST) |
| 112 |
DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP) |
| 113 |
DECLARE_ASN1_FUNCTIONS(OCSP_ONEREQ) |
| 114 |
|
| 115 |
// d2i_OCSP_REQUEST_bio parses a DER-encoded OCSP request from |bp|, converts it |
| 116 |
// into an |OCSP_REQUEST|, and writes the result in |preq|. |
| 117 |
OPENSSL_EXPORT OCSP_REQUEST *d2i_OCSP_REQUEST_bio(BIO *bp, OCSP_REQUEST **preq); |
| 118 |
|
| 119 |
// d2i_OCSP_RESPONSE_bio parses a DER-encoded OCSP response from |bp|, converts |
| 120 |
// it into an |OCSP_RESPONSE|, and writes the result in |presp|. |
| 121 |
OPENSSL_EXPORT OCSP_RESPONSE *d2i_OCSP_RESPONSE_bio(BIO *bp, |
| 122 |
OCSP_RESPONSE **presp); |
| 123 |
|
| 124 |
// i2d_OCSP_RESPONSE_bio marshals |presp| as a DER-encoded OCSP response and |
| 125 |
// writes the result to |bp|. |
| 126 |
OPENSSL_EXPORT int i2d_OCSP_RESPONSE_bio(BIO *bp, OCSP_RESPONSE *presp); |
| 127 |
|
| 128 |
// i2d_OCSP_REQUEST_bio marshals |preq| as a DER-encoded OCSP request and |
| 129 |
// writes the result to |bp|. |
| 130 |
OPENSSL_EXPORT int i2d_OCSP_REQUEST_bio(BIO *bp, OCSP_REQUEST *preq); |
| 131 |
|
| 132 |
// OCSP_CERTID_dup allocates a new |OCSP_CERTID| and sets it equal to the state |
| 133 |
// of |id|. It returns the new |OCSP_CERTID| or NULL on error. |
| 134 |
OPENSSL_EXPORT OCSP_CERTID *OCSP_CERTID_dup(OCSP_CERTID *id); |
| 135 |
|
| 136 |
// OCSP_sendreq_bio is a blocking OCSP request handler which is a special case |
| 137 |
// of non-blocking I/O. |
| 138 |
// |OCSP_sendreq_bio| combines |OCSP_sendreq_new| with as many calls of |
| 139 |
// |OCSP_sendreq_nbio| as needed and then |OCSP_REQ_CTX_free|, with a response |
| 140 |
// header maximum line length of 4k. It waits indefinitely on a response, if |
| 141 |
// |BIO_should_retry| is true and the |BIO| persists. |
| 142 |
// |
| 143 |
// WARNING: This is retained only for compatibility. This does not support |
| 144 |
// setting a timeout or adding your own HTTP headers. |
| 145 |
// Use |OCSP_sendreq_nbio| and handle the timeout accordingly to the |BIO| type. |
| 146 |
// You can also use |OCSP_REQ_CTX_add1_header| to add your own HTTP headers. |
| 147 |
OPENSSL_EXPORT OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, |
| 148 |
OCSP_REQUEST *req); |
| 149 |
|
| 150 |
// OCSP_sendreq_new returns an |OCSP_REQ_CTX| structure using the responder io, |
| 151 |
// the URL path, the |OCSP_REQUEST| req to be sent, and with a response header |
| 152 |
// maximum line length of maxline. If maxline is zero or less, a default value |
| 153 |
// of 4k is used. The |OCSP_REQUEST| req may be set to NULL and provided later |
| 154 |
// if required. |
| 155 |
OPENSSL_EXPORT OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path, |
| 156 |
OCSP_REQUEST *req, int maxline); |
| 157 |
|
| 158 |
// OCSP_sendreq_nbio attempts to send the request prepared in |rctx| and to |
| 159 |
// gather the response via HTTP, using the |BIO| io and path that were given |
| 160 |
// when calling |OCSP_sendreq_new|. |
| 161 |
OPENSSL_EXPORT int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx); |
| 162 |
|
| 163 |
// OCSP_REQ_CTX_new creates a new |OCSP_REQ_CTX|. |OCSP_REQ_CTX| is used to |
| 164 |
// contain the information to send the OCSP request and gather the response |
| 165 |
// over HTTP. |
| 166 |
OPENSSL_EXPORT OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *io, int maxline); |
| 167 |
|
| 168 |
// OCSP_REQ_CTX_free frees the memory allocated by |OCSP_REQ_CTX|. |
| 169 |
OPENSSL_EXPORT void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx); |
| 170 |
|
| 171 |
// OCSP_set_max_response_length sets the maximum response length for an OCSP |
| 172 |
// request over HTTP to |len|. If a custom max response length is needed, this |
| 173 |
// should be set before |OCSP_REQ_CTX| is sent out to retrieve the OCSP |
| 174 |
// response. |
| 175 |
OPENSSL_EXPORT void OCSP_set_max_response_length(OCSP_REQ_CTX *rctx, |
| 176 |
unsigned long len); |
| 177 |
|
| 178 |
// OCSP_REQ_CTX_http adds the HTTP request line to the context. |
| 179 |
OPENSSL_EXPORT int OCSP_REQ_CTX_http(OCSP_REQ_CTX *rctx, const char *op, |
| 180 |
const char *path); |
| 181 |
|
| 182 |
// OCSP_REQ_CTX_set1_req finalizes the HTTP request context. It is needed if |
| 183 |
// an ASN.1-encoded request should be sent. |
| 184 |
OPENSSL_EXPORT int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, OCSP_REQUEST *req); |
| 185 |
|
| 186 |
// OCSP_REQ_CTX_add1_header adds header name with value |value| to the |
| 187 |
// context |rctx|. It can be called more than once to add multiple header |
| 188 |
// lines. |
| 189 |
OPENSSL_EXPORT int OCSP_REQ_CTX_add1_header(OCSP_REQ_CTX *rctx, |
| 190 |
const char *name, |
| 191 |
const char *value); |
| 192 |
|
| 193 |
// OCSP_REQ_CTX_i2d parses the ASN.1 contents of |rctx| into the der format. |
| 194 |
int OCSP_REQ_CTX_i2d(OCSP_REQ_CTX *rctx, const ASN1_ITEM *it, ASN1_VALUE *val); |
| 195 |
|
| 196 |
// OCSP_request_add0_id adds |cid| to |req|. Returns the new |OCSP_ONEREQ| |
| 197 |
// pointer allocated on the stack within |req|. This is useful if we want to |
| 198 |
// add extensions. |
| 199 |
// WARNING: This allocates a new |OCSP_ONEREQ| and assigns the pointer to |cid| |
| 200 |
// to it. It then adds the newly allocated |OCSP_ONEREQ| to the stack within |
| 201 |
// |req|. |req| now takes ownership of |cid|, and also maintains ownership of |
| 202 |
// the pointer to |OCSP_ONEREQ|. |
| 203 |
OPENSSL_EXPORT OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, |
| 204 |
OCSP_CERTID *cid); |
| 205 |
|
| 206 |
// OCSP_onereq_get0_id returns the certificate identifier |
| 207 |
// associated with an OCSP request |
| 208 |
OPENSSL_EXPORT OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one); |
| 209 |
|
| 210 |
// OCSP_request_add1_nonce adds a nonce of value |val| and length |len| to |
| 211 |
// |req|. If |val| is NULL, a random nonce is generated and used. If |len| is |
| 212 |
// zero or negative, a default length of 16 bytes will be used. |
| 213 |
// If |val| is non-NULL, |len| must equal the length of |val|. This is different |
| 214 |
// from OpenSSL, which allows a default length for |len| to be used. Mis-usage |
| 215 |
// of the default length could result in a read overflow, so we disallow it. |
| 216 |
OPENSSL_EXPORT int OCSP_request_add1_nonce(OCSP_REQUEST *req, |
| 217 |
unsigned char *val, int len); |
| 218 |
|
| 219 |
// OCSP_basic_add1_nonce is identical to |OCSP_request_add1_nonce|, but adds the |
| 220 |
// nonce to |resp| instead (the response). |
| 221 |
OPENSSL_EXPORT int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, |
| 222 |
unsigned char *val, int len); |
| 223 |
|
| 224 |
// OCSP_check_nonce checks nonce existence and equality in |req| and |bs|. If |
| 225 |
// there is parsing issue with |req| or |bs|, it will be determined that a |
| 226 |
// nonce does not exist within |req| or |bs|. |
| 227 |
// |
| 228 |
// Return value reflects result: |
| 229 |
// OCSP_NONCE_EQUAL (1: nonces present and equal.) |
| 230 |
// OCSP_NONCE_BOTH_ABSENT (2: nonces both absent.) |
| 231 |
// OCSP_NONCE_RESPONSE_ONLY (3: nonce present in |bs| only.) |
| 232 |
// OCSP_NONCE_NOT_EQUAL (0: parameters are NULL or nonces are both present |
| 233 |
// but not equal.) |
| 234 |
// OCSP_NONCE_REQUEST_ONLY (-1: nonce in |req| only.) |
| 235 |
// |
| 236 |
// For most responders, clients can check "return > 0". |
| 237 |
// If an OCSP responder doesn't handle nonces, "return != 0" may be necessary. |
| 238 |
// "return == 0" will always be an error. The error can mean that NULL |
| 239 |
// parameter was passed into the function, or that the nonces are both present, |
| 240 |
// but aren't equal. |
| 241 |
OPENSSL_EXPORT int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs); |
| 242 |
|
| 243 |
// OCSP_copy_nonce copies the nonce value (if any) from |req| to |resp|. Returns |
| 244 |
// 1 on success and 0 on failure. If the optional nonce value does not exist in |
| 245 |
// |req|, we return 2 instead. |
| 246 |
// |
| 247 |
// Note: |OCSP_copy_nonce| allows for multiple OCSP nonces to exist and appends |
| 248 |
// the new nonce to the end of the extension list. This causes issues with |
| 249 |
// |OCSP_check_nonce|, since it looks for the first one in the list. The old |
| 250 |
// nonce extension should be deleted prior to calling |OCSP_copy_nonce|. |
| 251 |
OPENSSL_EXPORT int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req); |
| 252 |
|
| 253 |
// OCSP_request_set1_name sets |requestorName| from an |X509_NAME| structure. |
| 254 |
OPENSSL_EXPORT int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm); |
| 255 |
|
| 256 |
// OCSP_request_add1_cert adds a certificate to an |OCSP_REQUEST|. |
| 257 |
OPENSSL_EXPORT int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert); |
| 258 |
|
| 259 |
// OCSP_request_is_signed checks if the optional signature exists for |req|. |
| 260 |
OPENSSL_EXPORT int OCSP_request_is_signed(OCSP_REQUEST *req); |
| 261 |
|
| 262 |
// OCSP_request_onereq_count returns the number of |OCSP_ONEREQ|s in |req|. |
| 263 |
OPENSSL_EXPORT int OCSP_request_onereq_count(OCSP_REQUEST *req); |
| 264 |
|
| 265 |
// OCSP_request_onereq_get0 returns the |OCSP_ONEREQ| in |req| at index |i| or |
| 266 |
// NULL if |i| is out of bounds. |
| 267 |
OPENSSL_EXPORT OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i); |
| 268 |
|
| 269 |
// OCSP_request_sign signs the OCSP request |req| using |key| and |dgst|. |key| |
| 270 |
// MUST be the private key of |signer|. One or more optional certificates can be |
| 271 |
// added to |resp| with |certs|. This function will fail if a signature in |req| |
| 272 |
// already exists. |
| 273 |
// |
| 274 |
// Note: 1. The OCSP requester is identified by the subject name from |signer| |
| 275 |
// and included in |req|. |
| 276 |
// 2. All certificates in |certs| are added to |req| by default. Setting |
| 277 |
// |OCSP_NOCERTS| excludes certificates from being added in |req| and |
| 278 |
// ignores the |certs| parameter. |
| 279 |
OPENSSL_EXPORT int OCSP_request_sign(OCSP_REQUEST *req, X509 *signer, |
| 280 |
EVP_PKEY *key, const EVP_MD *dgst, |
| 281 |
STACK_OF(X509) *certs, |
| 282 |
unsigned long flags); |
| 283 |
|
| 284 |
// OCSP_response_status returns response status from |OCSP_RESPONSE|. |
| 285 |
OPENSSL_EXPORT int OCSP_response_status(OCSP_RESPONSE *resp); |
| 286 |
|
| 287 |
// OCSP_response_get1_basic returns |OCSP_BASICRESP| from |OCSP_RESPONSE|. |
| 288 |
OPENSSL_EXPORT OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp); |
| 289 |
|
| 290 |
// OCSP_resp_count returns the number of |OCSP_SINGLERESP| responses present |
| 291 |
// in |bs|. |
| 292 |
OPENSSL_EXPORT int OCSP_resp_count(OCSP_BASICRESP *bs); |
| 293 |
|
| 294 |
// OCSP_resp_get0 returns the |OCSP_SINGLERESP| at the |idx| within |bs|. |
| 295 |
OPENSSL_EXPORT OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, size_t idx); |
| 296 |
|
| 297 |
// OCSP_single_get0_status returns the status of |single|. |
| 298 |
// |
| 299 |
// Note: 1. |reason| value is allowed to be null. |
| 300 |
// 2. Time values passed into function are allowed to be NULL if |
| 301 |
// certificate fields are empty. |
| 302 |
// 3. |revtime| and |reason| values only set if the certificate status is |
| 303 |
// revoked. |
| 304 |
OPENSSL_EXPORT int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason, |
| 305 |
ASN1_GENERALIZEDTIME **revtime, |
| 306 |
ASN1_GENERALIZEDTIME **thisupd, |
| 307 |
ASN1_GENERALIZEDTIME **nextupd); |
| 308 |
|
| 309 |
// OCSP_resp_find returns the index of the |OCSP_SINGLERESP| in |bs| which |
| 310 |
// matches |id| if found, or -1 if not found. |
| 311 |
OPENSSL_EXPORT int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, |
| 312 |
int last); |
| 313 |
|
| 314 |
// OCSP_resp_find_status looks up a cert id and extract the update time and |
| 315 |
// revocation status of certificate sent back from OCSP responder if found. |
| 316 |
// Returns 1 on success. |
| 317 |
// |
| 318 |
// Note: 1. Revocation status code is passed into |*status| parameter. Status |
| 319 |
// code will not be passed if |*status| is NULL. |
| 320 |
OPENSSL_EXPORT int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, |
| 321 |
int *status, int *reason, |
| 322 |
ASN1_GENERALIZEDTIME **revtime, |
| 323 |
ASN1_GENERALIZEDTIME **thisupd, |
| 324 |
ASN1_GENERALIZEDTIME **nextupd); |
| 325 |
|
| 326 |
// OCSP_check_validity checks the validity of |thisUpdate| and |nextUpdate| |
| 327 |
// fields from an |OCSP_SINGLERESP|. |
| 328 |
// |
| 329 |
// Note: 1. It is possible that the request will take a few seconds to process |
| 330 |
// and/or the local system time isn't exactly the same as the OCSP |
| 331 |
// responder's time. Therefore, to avoid rejecting otherwise valid time |
| 332 |
// we allow the times to be within |drift_num_seconds| of the current |
| 333 |
// time. |
| 334 |
// 2. Also, to avoid accepting very old responses without a |
| 335 |
// |nextUpdate| field, an optional |max_age_seconds| parameter |
| 336 |
// specifies the maximum age the |thisUpdate| field can be. |
| 337 |
// |max_age_seconds| should be the number of seconds relative to |
| 338 |
// |thisUpdate|. You can also set |max_age_seconds| to "-1", if the |
| 339 |
// maximum age should not be checked. |
| 340 |
// 3. |thisUpdate| should be within the range of: (current time - |
| 341 |
// max_age_seconds) < |thisUpdate| < (current time + |
| 342 |
// drift_num_seconds). |
| 343 |
// |nextUpdate| should be in the future: (current time + |
| 344 |
// drift_num_seconds) < |nextUpdate|. |
| 345 |
// 4. |thisUpdate| and |nextUpdate| are defined in the RFC: |
| 346 |
// https://datatracker.ietf.org/doc/html/rfc6960#section-2.4 |
| 347 |
OPENSSL_EXPORT int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisUpdate, |
| 348 |
ASN1_GENERALIZEDTIME *nextUpdate, |
| 349 |
long drift_num_seconds, |
| 350 |
long max_age_seconds); |
| 351 |
|
| 352 |
// OCSP_basic_verify verifies a basic response message. It checks that |bs| is |
| 353 |
// correctly signed and that the signer certificate can be validated. |
| 354 |
// Returns 1 if the response is valid, 0 if the signature cannot be verified, |
| 355 |
// or -1 on fatal errors such as malloc failure. |
| 356 |
// |
| 357 |
// Note: 1. Checks that OCSP response CAN be verified, but does not imply |
| 358 |
// anything about the corresponding certificate's revocation status. |
| 359 |
// 2. |OCSP_resp_find_status| should be used to check if the OCSP |
| 360 |
// response's cert status is |V_OCSP_CERTSTATUS_GOOD|. |
| 361 |
// |OCSP_check_validity| should also be used to validate that the OCSP |
| 362 |
// response's timestamps are correct. |
| 363 |
OPENSSL_EXPORT int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs, |
| 364 |
X509_STORE *st, unsigned long flags); |
| 365 |
|
| 366 |
// OCSP_request_verify verifies the OCSP request message, |req|, with |st|. |
| 367 |
// OCSP request signatures are optional according to RFC6960, but one can check |
| 368 |
// that |req| is correctly signed and that the signer certificate can be |
| 369 |
// validated if a signature exists. This returns 1 if |req| is valid or returns |
| 370 |
// 0 if |req|'s signature is non-existent or cannot be verified. |
| 371 |
OPENSSL_EXPORT int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, |
| 372 |
X509_STORE *st, unsigned long flags); |
| 373 |
|
| 374 |
// OCSP_cert_id_new creates and returns a new |OCSP_CERTID| using |dgst|, |
| 375 |
// |issuerName|, |issuerKey|, and |serialNumber| as its contents. |
| 376 |
OPENSSL_EXPORT OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst, |
| 377 |
const X509_NAME *issuerName, |
| 378 |
const ASN1_BIT_STRING *issuerKey, |
| 379 |
const ASN1_INTEGER *serialNumber); |
| 380 |
|
| 381 |
// OCSP_cert_to_id returns a |OCSP_CERTID| converted from a certificate and its |
| 382 |
// issuer. |
| 383 |
// |
| 384 |
// Note: 1. If |subject| is NULL, we get the subject name from the issuer and |
| 385 |
// set the serial number to NULL. |
| 386 |
// 2. OpenSSL's legacy OCSP code decided to make SHA-1 as default hash |
| 387 |
// algorithm when the |dgst| is set as NULL. We keep this to maintain |
| 388 |
// backwards compatibility, but strongly advise to set a digest when |
| 389 |
// using this function. Even though this is not used cryptographically, |
| 390 |
// there is the possibility of a response being returned with a forced |
| 391 |
// issuer name when using SHA-1 (assuming a preimage attack, which is |
| 392 |
// beyond the scope of how SHA-1 is currently vulnerable). |
| 393 |
OPENSSL_EXPORT OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, |
| 394 |
const X509 *subject, |
| 395 |
const X509 *issuer); |
| 396 |
|
| 397 |
// OCSP_parse_url parses an OCSP responder URL and returns its component parts. |
| 398 |
// |url| argument must be a null-terminated string containing the URL to be |
| 399 |
// parsed. The other arguments are pointers to variables that will be set to the |
| 400 |
// parsed components of the URL. When |OCSP_parse_url| returns 1, these |
| 401 |
// arguments will allocate new memory with a copy of value. It is the caller's |
| 402 |
// responsibility to free these. |
| 403 |
// |
| 404 |
// |phost|: A pointer to a char pointer that will be set to the host component |
| 405 |
// of the URL. If the URL does not contain a host component, this will |
| 406 |
// be set to an empty string. |
| 407 |
// |pport|: A pointer to an int that will be set to the port number specified |
| 408 |
// in the URL, or to the default port (80 for HTTP, 443 for HTTPS) |
| 409 |
// if no port number is specified. |
| 410 |
// |ppath|: A pointer to a char pointer that will be set to the path component |
| 411 |
// of the URL. If the URL does not contain a path component, this |
| 412 |
// will be set to "/". |
| 413 |
// |pssl|: A pointer to an int that will be set to 1 if the URL specifies the |
| 414 |
// HTTPS protocol, or 0 if HTTP. |
| 415 |
// |
| 416 |
// Note: |OCSP_parse_url| does not perform any validation of the URL or its |
| 417 |
// components beyond basic parsing. It is the responsibility of the |
| 418 |
// caller to ensure that the URL is well-formed and valid. |
| 419 |
OPENSSL_EXPORT int OCSP_parse_url(const char *url, char **phost, char **pport, |
| 420 |
char **ppath, int *pssl); |
| 421 |
|
| 422 |
// OCSP_id_issuer_cmp compares the issuers' name and key hash of |a| and |b|. It |
| 423 |
// returns 0 on equal. |
| 424 |
OPENSSL_EXPORT int OCSP_id_issuer_cmp(const OCSP_CERTID *a, |
| 425 |
const OCSP_CERTID *b); |
| 426 |
|
| 427 |
// OCSP_id_cmp calls |OCSP_id_issuer_cmp| and additionally compares the |
| 428 |
// |serialNumber| of |a| and |b|. It returns 0 on equal. |
| 429 |
OPENSSL_EXPORT int OCSP_id_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b); |
| 430 |
|
| 431 |
// OCSP_id_get0_info returns the issuer name hash, hash OID, issuer key hash, |
| 432 |
// and the serial number contained in |cid|. If any of the values are not |
| 433 |
// required, the corresponding parameter can be set to NULL. |
| 434 |
OPENSSL_EXPORT int OCSP_id_get0_info(ASN1_OCTET_STRING **nameHash, |
| 435 |
ASN1_OBJECT **algor, |
| 436 |
ASN1_OCTET_STRING **keyHash, |
| 437 |
ASN1_INTEGER **serial, OCSP_CERTID *cid); |
| 438 |
|
| 439 |
// OCSP_basic_add1_cert adds |cert| to the |resp|. |
| 440 |
OPENSSL_EXPORT int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert); |
| 441 |
|
| 442 |
// OCSP_basic_add1_status creates and returns an |OCSP_SINGLERESP| with |cid|, |
| 443 |
// |status|, |this_update| and |next_update|. The newly created |
| 444 |
// |OCSP_SINGLERESP| is pushed onto the internal |OCSP_SINGLERESP| stack in |
| 445 |
// |resp|. |status| should be a value defined by |V_OCSP_CERTSTATUS_*|. |
| 446 |
// |
| 447 |
// 1. If |status| has the value |V_OCSP_CERTSTATUS_REVOKED|, |revoked_reason| |
| 448 |
// should be a valid |OCSP_REVOKED_STATUS_*| value and |revoked_time| cannot be |
| 449 |
// empty. |
| 450 |
// 2. If |status| has the value of either |V_OCSP_CERTSTATUS_GOOD| or |
| 451 |
// |V_OCSP_CERTSTATUS_UNKNOWN|, |revoked_reason| and |revoked_time| are ignored. |
| 452 |
OPENSSL_EXPORT OCSP_SINGLERESP *OCSP_basic_add1_status( |
| 453 |
OCSP_BASICRESP *resp, OCSP_CERTID *cid, int status, int revoked_reason, |
| 454 |
ASN1_TIME *revoked_time, ASN1_TIME *this_update, ASN1_TIME *next_update); |
| 455 |
|
| 456 |
// OCSP_basic_sign signs the OCSP response |resp| using |key| and |dgst|. |key| |
| 457 |
// MUST be the private key of |signer|. One or more optional certificates can be |
| 458 |
// added to |resp| with |certs|. |
| 459 |
// |
| 460 |
// Note: 1. By default, the OCSP responder is identified by the subject name |
| 461 |
// from |signer| and included in |resp|. Users can set |
| 462 |
// |OCSP_RESPID_KEY| with |flags|, if they wish for the responder to |
| 463 |
// be identified by the hash of |signer|'s public key instead. |
| 464 |
// 2. All certificates in |certs| are added to |resp| by default. Setting |
| 465 |
// |OCSP_NOCERTS| excludes certificates from being added in |resp| and |
| 466 |
// ignores the |certs| parameter. |
| 467 |
// 3. The |producedAt| time field is set to the current time by default. |
| 468 |
// Setting |OCSP_NOTIME| excludes setting the |producedAt| time field |
| 469 |
// in |resp| and leaves it empty. |
| 470 |
OPENSSL_EXPORT int OCSP_basic_sign(OCSP_BASICRESP *resp, X509 *signer, |
| 471 |
EVP_PKEY *key, const EVP_MD *dgst, |
| 472 |
STACK_OF(X509) *certs, unsigned long flags); |
| 473 |
|
| 474 |
// OCSP_response_create creates an |OCSP_RESPONSE| and encodes an optional |bs| |
| 475 |
// within it. |
| 476 |
OPENSSL_EXPORT OCSP_RESPONSE *OCSP_response_create(int status, |
| 477 |
OCSP_BASICRESP *bs); |
| 478 |
|
| 479 |
// OCSP_SINGLERESP_get0_id returns the |OCSP_CERTID| within |x|. |
| 480 |
OPENSSL_EXPORT const OCSP_CERTID *OCSP_SINGLERESP_get0_id( |
| 481 |
const OCSP_SINGLERESP *x); |
| 482 |
|
| 483 |
// OCSP_response_status_str returns the OCSP response status of |status_code| as |
| 484 |
// a string. |
| 485 |
OPENSSL_EXPORT const char *OCSP_response_status_str(long status_code); |
| 486 |
|
| 487 |
// OCSP_cert_status_str returns the OCSP cert status of |status_code| as |
| 488 |
// a string. |
| 489 |
OPENSSL_EXPORT const char *OCSP_cert_status_str(long status_code); |
| 490 |
|
| 491 |
// OCSP_crl_reason_str returns the OCSP CRL reason of |status_code| as a string. |
| 492 |
// |OCSP_resp_find_status| can be used to retrieve the reason status code |
| 493 |
// if an OCSP response is revoked. |
| 494 |
OPENSSL_EXPORT const char *OCSP_crl_reason_str(long status_code); |
| 495 |
|
| 496 |
// OCSP_REQUEST_print prints the contents of an OCSP request to |bp|. |flags| is |
| 497 |
// used to configure printing of the |req|'s extensions (See |
| 498 |
// |X509V3_extensions_print| for more information). |
| 499 |
// This is typically used for debugging or diagnostic purposes. |
| 500 |
OPENSSL_EXPORT int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST *req, |
| 501 |
unsigned long flags); |
| 502 |
|
| 503 |
// OCSP_RESPONSE_print prints the contents of an OCSP response to |bp|. |flags| |
| 504 |
// is used to configure printing of the |resp|'s extensions (See |
| 505 |
// |X509V3_extensions_print| for more information). |
| 506 |
// This is typically used for debugging or diagnostic purposes. |
| 507 |
OPENSSL_EXPORT int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE *resp, |
| 508 |
unsigned long flags); |
| 509 |
|
| 510 |
// OCSP_BASICRESP_get_ext_by_NID returns the index of an extension |bs| by its |
| 511 |
// NID. Returns -1 if not found. |
| 512 |
OPENSSL_EXPORT int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *bs, int nid, |
| 513 |
int lastpos); |
| 514 |
|
| 515 |
// OCSP_BASICRESP_get_ext returns the |X509_EXTENSION| in |bs| at index |loc|, |
| 516 |
// or NULL if |loc| is out of bounds. |
| 517 |
OPENSSL_EXPORT X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *bs, |
| 518 |
int loc); |
| 519 |
|
| 520 |
|
| 521 |
// OCSP |X509_EXTENSION| Functions |
| 522 |
|
| 523 |
// OCSP_BASICRESP_delete_ext removes the extension in |x| at index |loc| and |
| 524 |
// returns the removed extension, or NULL if |loc| was out of bounds. If an |
| 525 |
// extension was returned, the caller must release it with |
| 526 |
// |X509_EXTENSION_free|. |
| 527 |
OPENSSL_EXPORT X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, |
| 528 |
int loc); |
| 529 |
|
| 530 |
// OCSP_SINGLERESP_add_ext adds a copy of |ex| to the extension list in |
| 531 |
// |*sresp|. It returns 1 on success and 0 on error. The new extension is |
| 532 |
// inserted at index |loc|, shifting extensions to the right. If |loc| is -1 or |
| 533 |
// out of bounds, the new extension is appended to the list. |
| 534 |
OPENSSL_EXPORT int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *sresp, |
| 535 |
X509_EXTENSION *ex, int loc); |
| 536 |
|
| 537 |
// OCSP_SINGLERESP_get_ext_count returns the number of |X509_EXTENSION|s in |
| 538 |
// |sresp|. |
| 539 |
OPENSSL_EXPORT int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *sresp); |
| 540 |
|
| 541 |
// OCSP_SINGLERESP_get_ext returns the |X509_EXTENSION| in |sresp| |
| 542 |
// at index |loc|, or NULL if |loc| is out of bounds. |
| 543 |
OPENSSL_EXPORT X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *sresp, |
| 544 |
int loc); |
| 545 |
|
| 546 |
|
| 547 |
// OCSP no-op flags [Deprecated]. |
| 548 |
|
| 549 |
// OCSP_NOSIGS does nothing. In OpenSSL, this skips signature verification in |
| 550 |
// |OCSP_basic_verify| and |OCSP_request_verify|. |
| 551 |
#define OCSP_NOSIGS 0 |
| 552 |
|
| 553 |
// OCSP_NOCASIGN does nothing. It's a legacy OCSP flag deprecated since OpenSSL |
| 554 |
// 1.0.1g. |
| 555 |
#define OCSP_NOCASIGN 0 |
| 556 |
|
| 557 |
// OCSP_NODELEGATED does nothing. It's a legacy OCSP flag deprecated since |
| 558 |
// OpenSSL 1.0.1g. |
| 559 |
#define OCSP_NODELEGATED 0 |
| 560 |
|
| 561 |
// OCSP_NOCHECKS does nothing. In OpenSSL, this disables verifying that the |
| 562 |
// signer certificate has met the OCSP issuer criteria or any potential |
| 563 |
// delegation in |OCSP_basic_verify|. |
| 564 |
#define OCSP_NOCHECKS 0 |
| 565 |
|
| 566 |
|
| 567 |
#if defined(__cplusplus) |
| 568 |
} // extern C |
| 569 |
#endif |
| 570 |
|
| 571 |
#if !defined(BORINGSSL_NO_CXX) |
| 572 |
extern "C++" { |
| 573 |
|
| 574 |
BSSL_NAMESPACE_BEGIN |
| 575 |
|
| 576 |
BORINGSSL_MAKE_DELETER(OCSP_REQUEST, OCSP_REQUEST_free) |
| 577 |
BORINGSSL_MAKE_DELETER(OCSP_REQ_CTX, OCSP_REQ_CTX_free) |
| 578 |
BORINGSSL_MAKE_DELETER(OCSP_RESPONSE, OCSP_RESPONSE_free) |
| 579 |
BORINGSSL_MAKE_DELETER(OCSP_BASICRESP, OCSP_BASICRESP_free) |
| 580 |
BORINGSSL_MAKE_DELETER(OCSP_CERTID, OCSP_CERTID_free) |
| 581 |
BORINGSSL_MAKE_DELETER(OCSP_SINGLERESP, OCSP_SINGLERESP_free) |
| 582 |
|
| 583 |
BSSL_NAMESPACE_END |
| 584 |
|
| 585 |
} // extern C++ |
| 586 |
#endif // !BORINGSSL_NO_CXX |
| 587 |
|
| 588 |
#define OCSP_RESPONSE_STATUS_SUCCESSFUL 0 |
| 589 |
#define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1 |
| 590 |
#define OCSP_RESPONSE_STATUS_INTERNALERROR 2 |
| 591 |
#define OCSP_RESPONSE_STATUS_TRYLATER 3 |
| 592 |
#define OCSP_RESPONSE_STATUS_SIGREQUIRED 5 |
| 593 |
#define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6 |
| 594 |
|
| 595 |
#define V_OCSP_RESPID_NAME 0 |
| 596 |
#define V_OCSP_RESPID_KEY 1 |
| 597 |
|
| 598 |
#define V_OCSP_CERTSTATUS_GOOD 0 |
| 599 |
#define V_OCSP_CERTSTATUS_REVOKED 1 |
| 600 |
#define V_OCSP_CERTSTATUS_UNKNOWN 2 |
| 601 |
|
| 602 |
#define OCSP_NONCE_EQUAL 1 |
| 603 |
#define OCSP_NONCE_BOTH_ABSENT 2 |
| 604 |
#define OCSP_NONCE_RESPONSE_ONLY 3 |
| 605 |
#define OCSP_NONCE_NOT_EQUAL 0 |
| 606 |
#define OCSP_NONCE_REQUEST_ONLY -1 |
| 607 |
|
| 608 |
#define OCSP_R_CERTIFICATE_VERIFY_ERROR 101 |
| 609 |
#define OCSP_R_DIGEST_ERR 102 |
| 610 |
#define OCSP_R_MISSING_OCSPSIGNING_USAGE 103 |
| 611 |
#define OCSP_R_NOT_BASIC_RESPONSE 104 |
| 612 |
#define OCSP_R_NO_CERTIFICATES_IN_CHAIN 105 |
| 613 |
#define OCSP_R_NO_RESPONSE_DATA 108 |
| 614 |
#define OCSP_R_NO_REVOKED_TIME 109 |
| 615 |
#define OCSP_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 110 |
| 616 |
#define OCSP_R_RESPONSE_CONTAINS_NO_REVOCATION_DATA 111 |
| 617 |
#define OCSP_R_ROOT_CA_NOT_TRUSTED 112 |
| 618 |
#define OCSP_R_SERVER_RESPONSE_PARSE_ERROR 115 |
| 619 |
#define OCSP_R_SIGNATURE_FAILURE 117 |
| 620 |
#define OCSP_R_SIGNER_CERTIFICATE_NOT_FOUND 118 |
| 621 |
#define OCSP_R_UNKNOWN_MESSAGE_DIGEST 119 |
| 622 |
#define OCSP_R_UNKNOWN_NID 120 |
| 623 |
#define OCSP_R_ERROR_PARSING_URL 121 |
| 624 |
#define OCSP_R_ERROR_IN_NEXTUPDATE_FIELD 122 |
| 625 |
#define OCSP_R_ERROR_IN_THISUPDATE_FIELD 123 |
| 626 |
#define OCSP_R_NEXTUPDATE_BEFORE_THISUPDATE 124 |
| 627 |
#define OCSP_R_STATUS_EXPIRED 125 |
| 628 |
#define OCSP_R_STATUS_NOT_YET_VALID 126 |
| 629 |
#define OCSP_R_STATUS_TOO_OLD 127 |
| 630 |
#define OCSP_R_REQUEST_NOT_SIGNED 128 |
| 631 |
#define OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE 129 |
| 632 |
#define OCSP_R_NO_SIGNER_KEY 130 |
| 633 |
#define OCSP_R_OCSP_REQUEST_DUPLICATE_SIGNATURE 131 |
| 634 |
#define OCSP_R_UNKNOWN_FIELD_VALUE 132 |
| 635 |
|
| 636 |
#endif // AWSLC_OCSP_H |