xref: /freebsd-src/crypto/openssl/doc/man3/OCSP_resp_find_status.pod (revision aa7957345732816fb0ba8308798d2f79f45597f9)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5b077aed3SPierre ProncheryOCSP_resp_find_status, OCSP_resp_count,
6b077aed3SPierre ProncheryOCSP_resp_get0, OCSP_resp_find, OCSP_single_get0_status,
7b077aed3SPierre ProncheryOCSP_resp_get0_produced_at, OCSP_resp_get0_signature,
8b077aed3SPierre ProncheryOCSP_resp_get0_tbs_sigalg, OCSP_resp_get0_respdata,
9b077aed3SPierre ProncheryOCSP_resp_get0_certs, OCSP_resp_get0_signer,
10b077aed3SPierre ProncheryOCSP_resp_get0_id, OCSP_resp_get1_id,
11b077aed3SPierre ProncheryOCSP_check_validity, OCSP_basic_verify
12e71b7053SJung-uk Kim- OCSP response utility functions
13e71b7053SJung-uk Kim
14e71b7053SJung-uk Kim=head1 SYNOPSIS
15e71b7053SJung-uk Kim
16e71b7053SJung-uk Kim #include <openssl/ocsp.h>
17e71b7053SJung-uk Kim
18e71b7053SJung-uk Kim int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
19e71b7053SJung-uk Kim                           int *reason,
20e71b7053SJung-uk Kim                           ASN1_GENERALIZEDTIME **revtime,
21e71b7053SJung-uk Kim                           ASN1_GENERALIZEDTIME **thisupd,
22e71b7053SJung-uk Kim                           ASN1_GENERALIZEDTIME **nextupd);
23e71b7053SJung-uk Kim
24e71b7053SJung-uk Kim int OCSP_resp_count(OCSP_BASICRESP *bs);
25e71b7053SJung-uk Kim OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx);
26e71b7053SJung-uk Kim int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last);
27e71b7053SJung-uk Kim int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
28e71b7053SJung-uk Kim                             ASN1_GENERALIZEDTIME **revtime,
29e71b7053SJung-uk Kim                             ASN1_GENERALIZEDTIME **thisupd,
30e71b7053SJung-uk Kim                             ASN1_GENERALIZEDTIME **nextupd);
31e71b7053SJung-uk Kim
32e71b7053SJung-uk Kim const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(
33e71b7053SJung-uk Kim                             const OCSP_BASICRESP* single);
34e71b7053SJung-uk Kim
35e71b7053SJung-uk Kim const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *bs);
36e71b7053SJung-uk Kim const X509_ALGOR *OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *bs);
37e71b7053SJung-uk Kim const OCSP_RESPDATA *OCSP_resp_get0_respdata(const OCSP_BASICRESP *bs);
38e71b7053SJung-uk Kim const STACK_OF(X509) *OCSP_resp_get0_certs(const OCSP_BASICRESP *bs);
39e71b7053SJung-uk Kim
40e71b7053SJung-uk Kim int OCSP_resp_get0_signer(OCSP_BASICRESP *bs, X509 **signer,
41e71b7053SJung-uk Kim                           STACK_OF(X509) *extra_certs);
42e71b7053SJung-uk Kim
43e71b7053SJung-uk Kim int OCSP_resp_get0_id(const OCSP_BASICRESP *bs,
44e71b7053SJung-uk Kim                       const ASN1_OCTET_STRING **pid,
45e71b7053SJung-uk Kim                       const X509_NAME **pname);
46e71b7053SJung-uk Kim int OCSP_resp_get1_id(const OCSP_BASICRESP *bs,
47e71b7053SJung-uk Kim                       ASN1_OCTET_STRING **pid,
48e71b7053SJung-uk Kim                       X509_NAME **pname);
49e71b7053SJung-uk Kim
50e71b7053SJung-uk Kim int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
51e71b7053SJung-uk Kim                         ASN1_GENERALIZEDTIME *nextupd,
52e71b7053SJung-uk Kim                         long sec, long maxsec);
53e71b7053SJung-uk Kim
54e71b7053SJung-uk Kim int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
55e71b7053SJung-uk Kim                      X509_STORE *st, unsigned long flags);
56e71b7053SJung-uk Kim
57e71b7053SJung-uk Kim=head1 DESCRIPTION
58e71b7053SJung-uk Kim
59b077aed3SPierre ProncheryOCSP_resp_find_status() searches I<bs> for an OCSP response for I<id>. If it is
60b077aed3SPierre Proncherysuccessful the fields of the response are returned in I<*status>, I<*reason>,
61b077aed3SPierre ProncheryI<*revtime>, I<*thisupd> and I<*nextupd>.  The I<*status> value will be one of
62e71b7053SJung-uk KimB<V_OCSP_CERTSTATUS_GOOD>, B<V_OCSP_CERTSTATUS_REVOKED> or
63b077aed3SPierre ProncheryB<V_OCSP_CERTSTATUS_UNKNOWN>. The I<*reason> and I<*revtime> fields are only
64b077aed3SPierre Proncheryset if the status is B<V_OCSP_CERTSTATUS_REVOKED>. If set the I<*reason> field
65e71b7053SJung-uk Kimwill be set to the revocation reason which will be one of
66e71b7053SJung-uk KimB<OCSP_REVOKED_STATUS_NOSTATUS>, B<OCSP_REVOKED_STATUS_UNSPECIFIED>,
67e71b7053SJung-uk KimB<OCSP_REVOKED_STATUS_KEYCOMPROMISE>, B<OCSP_REVOKED_STATUS_CACOMPROMISE>,
68e71b7053SJung-uk KimB<OCSP_REVOKED_STATUS_AFFILIATIONCHANGED>, B<OCSP_REVOKED_STATUS_SUPERSEDED>,
69e71b7053SJung-uk KimB<OCSP_REVOKED_STATUS_CESSATIONOFOPERATION>,
70e71b7053SJung-uk KimB<OCSP_REVOKED_STATUS_CERTIFICATEHOLD> or B<OCSP_REVOKED_STATUS_REMOVEFROMCRL>.
71e71b7053SJung-uk Kim
72b077aed3SPierre ProncheryOCSP_resp_count() returns the number of B<OCSP_SINGLERESP> structures in I<bs>.
73e71b7053SJung-uk Kim
74b077aed3SPierre ProncheryOCSP_resp_get0() returns the B<OCSP_SINGLERESP> structure in I<bs> corresponding
75b077aed3SPierre Proncheryto index I<idx>, where I<idx> runs from 0 to OCSP_resp_count(bs) - 1.
76e71b7053SJung-uk Kim
77b077aed3SPierre ProncheryOCSP_resp_find() searches I<bs> for I<id> and returns the index of the first
78b077aed3SPierre Proncherymatching entry after I<last> or starting from the beginning if I<last> is -1.
79e71b7053SJung-uk Kim
80b077aed3SPierre ProncheryOCSP_single_get0_status() extracts the fields of I<single> in I<*reason>,
81b077aed3SPierre ProncheryI<*revtime>, I<*thisupd> and I<*nextupd>.
82e71b7053SJung-uk Kim
83e71b7053SJung-uk KimOCSP_resp_get0_produced_at() extracts the B<producedAt> field from the
84b077aed3SPierre Proncherysingle response I<bs>.
85e71b7053SJung-uk Kim
86b077aed3SPierre ProncheryOCSP_resp_get0_signature() returns the signature from I<bs>.
87e71b7053SJung-uk Kim
88b077aed3SPierre ProncheryOCSP_resp_get0_tbs_sigalg() returns the B<signatureAlgorithm> from I<bs>.
89e71b7053SJung-uk Kim
90b077aed3SPierre ProncheryOCSP_resp_get0_respdata() returns the B<tbsResponseData> from I<bs>.
91e71b7053SJung-uk Kim
92b077aed3SPierre ProncheryOCSP_resp_get0_certs() returns any certificates included in I<bs>.
93e71b7053SJung-uk Kim
94e71b7053SJung-uk KimOCSP_resp_get0_signer() attempts to retrieve the certificate that directly
95b077aed3SPierre Proncherysigned I<bs>.  The OCSP protocol does not require that this certificate
96e71b7053SJung-uk Kimis included in the B<certs> field of the response, so additional certificates
97b077aed3SPierre Proncherycan be supplied via the I<extra_certs> if the certificates that may have
98e71b7053SJung-uk Kimsigned the response are known via some out-of-band mechanism.
99e71b7053SJung-uk Kim
100b077aed3SPierre ProncheryOCSP_resp_get0_id() gets the responder id of I<bs>. If the responder ID is
101b077aed3SPierre Proncherya name then <*pname> is set to the name and I<*pid> is set to NULL. If the
102b077aed3SPierre Proncheryresponder ID is by key ID then I<*pid> is set to the key ID and I<*pname>
103b077aed3SPierre Proncheryis set to NULL.
104e71b7053SJung-uk Kim
105b077aed3SPierre ProncheryOCSP_resp_get1_id() is the same as OCSP_resp_get0_id()
106b077aed3SPierre Proncherybut leaves ownership of I<*pid> and I<*pname> with the caller,
107b077aed3SPierre Proncherywho is responsible for freeing them unless the function returns 0.
108e71b7053SJung-uk Kim
109b077aed3SPierre ProncheryOCSP_check_validity() checks the validity of its I<thisupd> and I<nextupd>
110b077aed3SPierre Proncheryarguments, which will be typically obtained from OCSP_resp_find_status() or
111b077aed3SPierre ProncheryOCSP_single_get0_status(). If I<sec> is nonzero it indicates how many seconds
112b077aed3SPierre Proncheryleeway should be allowed in the check. If I<maxsec> is positive it indicates
113b077aed3SPierre Proncherythe maximum age of I<thisupd> in seconds.
114b077aed3SPierre Pronchery
115b077aed3SPierre ProncheryOCSP_basic_verify() checks that the basic response message I<bs> is correctly
116b077aed3SPierre Proncherysigned and that the signer certificate can be validated. It takes I<st> as
117b077aed3SPierre Proncherythe trusted store and I<certs> as a set of untrusted intermediate certificates.
118e71b7053SJung-uk KimThe function first tries to find the signer certificate of the response
119b077aed3SPierre Proncheryin I<certs>. It then searches the certificates the responder may have included
120b077aed3SPierre Proncheryin I<bs> unless I<flags> contains B<OCSP_NOINTERN>.
121e71b7053SJung-uk KimIt fails if the signer certificate cannot be found.
122b077aed3SPierre ProncheryNext, unless I<flags> contains B<OCSP_NOSIGS>, the function checks
123b077aed3SPierre Proncherythe signature of I<bs> and fails on error. Then the function already returns
124b077aed3SPierre Proncherysuccess if I<flags> contains B<OCSP_NOVERIFY> or if the signer certificate
125b077aed3SPierre Proncherywas found in I<certs> and I<flags> contains B<OCSP_TRUSTOTHER>.
126e71b7053SJung-uk KimOtherwise the function continues by validating the signer certificate.
127b077aed3SPierre ProncheryIf I<flags> contains B<OCSP_PARTIAL_CHAIN> it takes intermediate CA
128b077aed3SPierre Proncherycertificates in I<st> as trust anchors.
129b077aed3SPierre ProncheryFor more details, see the description of B<X509_V_FLAG_PARTIAL_CHAIN>
130b077aed3SPierre Proncheryin L<X509_VERIFY_PARAM_set_flags(3)/VERIFICATION FLAGS>.
131b077aed3SPierre ProncheryIf I<flags> contains B<OCSP_NOCHAIN> it ignores all certificates in I<certs>
132b077aed3SPierre Proncheryand in I<bs>, else it takes them as untrusted intermediate CA certificates
133b077aed3SPierre Proncheryand uses them for constructing the validation path for the signer certificate.
134*aa795734SPierre ProncheryCertificate revocation status checks using CRLs is disabled during path validation
135b077aed3SPierre Proncheryif the signer certificate contains the B<id-pkix-ocsp-no-check> extension.
136b077aed3SPierre ProncheryAfter successful path
137e71b7053SJung-uk Kimvalidation the function returns success if the B<OCSP_NOCHECKS> flag is set.
138e71b7053SJung-uk KimOtherwise it verifies that the signer certificate meets the OCSP issuer
139e71b7053SJung-uk Kimcriteria including potential delegation. If this does not succeed and the
140b077aed3SPierre ProncheryB<OCSP_NOEXPLICIT> flag is not set the function checks for explicit
141e71b7053SJung-uk Kimtrust for OCSP signing in the root CA certificate.
142e71b7053SJung-uk Kim
143e71b7053SJung-uk Kim=head1 RETURN VALUES
144e71b7053SJung-uk Kim
145b077aed3SPierre ProncheryOCSP_resp_find_status() returns 1 if I<id> is found in I<bs> and 0 otherwise.
146e71b7053SJung-uk Kim
147b077aed3SPierre ProncheryOCSP_resp_count() returns the total number of B<OCSP_SINGLERESP> fields in I<bs>
148b077aed3SPierre Proncheryor -1 on error.
149e71b7053SJung-uk Kim
150e71b7053SJung-uk KimOCSP_resp_get0() returns a pointer to an B<OCSP_SINGLERESP> structure or
151b077aed3SPierre ProncheryNULL on error, such as I<idx> being out of range.
152e71b7053SJung-uk Kim
153b077aed3SPierre ProncheryOCSP_resp_find() returns the index of I<id> in I<bs> (which may be 0)
154b077aed3SPierre Proncheryor -1 on error, such as when I<id> was not found.
155e71b7053SJung-uk Kim
156b077aed3SPierre ProncheryOCSP_single_get0_status() returns the status of I<single> or -1 if an error
157e71b7053SJung-uk Kimoccurred.
158e71b7053SJung-uk Kim
159b077aed3SPierre ProncheryOCSP_resp_get0_produced_at() returns the B<producedAt> field from I<bs>.
160e71b7053SJung-uk Kim
161b077aed3SPierre ProncheryOCSP_resp_get0_signature() returns the signature from I<bs>.
162b077aed3SPierre Pronchery
163b077aed3SPierre ProncheryOCSP_resp_get0_tbs_sigalg() returns the B<signatureAlgorithm> field from I<bs>.
164b077aed3SPierre Pronchery
165b077aed3SPierre ProncheryOCSP_resp_get0_respdata() returns the B<tbsResponseData> field from I<bs>.
166b077aed3SPierre Pronchery
167b077aed3SPierre ProncheryOCSP_resp_get0_certs() returns any certificates included in I<bs>.
168b077aed3SPierre Pronchery
169b077aed3SPierre ProncheryOCSP_resp_get0_signer() returns 1 if the signing certificate was located,
170b077aed3SPierre Proncheryor 0 if not found or on error.
171b077aed3SPierre Pronchery
172b077aed3SPierre ProncheryOCSP_resp_get0_id() and OCSP_resp_get1_id() return 1 on success, 0 on failure.
173b077aed3SPierre Pronchery
174b077aed3SPierre ProncheryOCSP_check_validity() returns 1 if I<thisupd> and I<nextupd> are valid time
175b077aed3SPierre Proncheryvalues and the current time + I<sec> is not before I<thisupd> and,
176b077aed3SPierre Proncheryif I<maxsec> >= 0, the current time - I<maxsec> is not past I<nextupd>.
177b077aed3SPierre ProncheryOtherwise it returns 0 to indicate an error.
178b077aed3SPierre Pronchery
179b077aed3SPierre ProncheryOCSP_basic_verify() returns 1 on success, 0 on verification not successful,
180b077aed3SPierre Proncheryor -1 on a fatal error such as malloc failure.
181e71b7053SJung-uk Kim
182e71b7053SJung-uk Kim=head1 NOTES
183e71b7053SJung-uk Kim
184e71b7053SJung-uk KimApplications will typically call OCSP_resp_find_status() using the certificate
185e71b7053SJung-uk KimID of interest and then check its validity using OCSP_check_validity(). They
186e71b7053SJung-uk Kimcan then take appropriate action based on the status of the certificate.
187e71b7053SJung-uk Kim
188e71b7053SJung-uk KimAn OCSP response for a certificate contains B<thisUpdate> and B<nextUpdate>
189e71b7053SJung-uk Kimfields. Normally the current time should be between these two values. To
190b077aed3SPierre Proncheryaccount for clock skew the I<maxsec> field can be set to nonzero in
191e71b7053SJung-uk KimOCSP_check_validity(). Some responders do not set the B<nextUpdate> field, this
192e71b7053SJung-uk Kimwould otherwise mean an ancient response would be considered valid: the
193b077aed3SPierre ProncheryI<maxsec> parameter to OCSP_check_validity() can be used to limit the permitted
194e71b7053SJung-uk Kimage of responses.
195e71b7053SJung-uk Kim
196b077aed3SPierre ProncheryThe values written to I<*revtime>, I<*thisupd> and I<*nextupd> by
197e71b7053SJung-uk KimOCSP_resp_find_status() and OCSP_single_get0_status() are internal pointers
198b077aed3SPierre Proncherywhich MUST NOT be freed up by the calling application. Any or all of these
199e71b7053SJung-uk Kimparameters can be set to NULL if their value is not required.
200e71b7053SJung-uk Kim
201e71b7053SJung-uk Kim=head1 SEE ALSO
202e71b7053SJung-uk Kim
203e71b7053SJung-uk KimL<crypto(7)>,
204e71b7053SJung-uk KimL<OCSP_cert_to_id(3)>,
205e71b7053SJung-uk KimL<OCSP_request_add1_nonce(3)>,
206e71b7053SJung-uk KimL<OCSP_REQUEST_new(3)>,
207e71b7053SJung-uk KimL<OCSP_response_status(3)>,
208b077aed3SPierre ProncheryL<OCSP_sendreq_new(3)>,
209b077aed3SPierre ProncheryL<X509_VERIFY_PARAM_set_flags(3)>
210e71b7053SJung-uk Kim
211e71b7053SJung-uk Kim=head1 COPYRIGHT
212e71b7053SJung-uk Kim
213*aa795734SPierre ProncheryCopyright 2015-2023 The OpenSSL Project Authors. All Rights Reserved.
214e71b7053SJung-uk Kim
215b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License").  You may not use
216e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
217e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
218e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
219e71b7053SJung-uk Kim
220e71b7053SJung-uk Kim=cut
221