Add X509_NAME_hash_ex() to be able to check if it failed due to unsupported SHA1
[openssl.git] / doc / man3 / OCSP_resp_find_status.pod
1 =pod
2
3 =head1 NAME
4
5 OCSP_resp_get0_certs,
6 OCSP_resp_get0_signer,
7 OCSP_resp_get0_id,
8 OCSP_resp_get1_id,
9 OCSP_resp_get0_produced_at,
10 OCSP_resp_get0_signature,
11 OCSP_resp_get0_tbs_sigalg,
12 OCSP_resp_get0_respdata,
13 OCSP_resp_find_status, OCSP_resp_count, OCSP_resp_get0, OCSP_resp_find,
14 OCSP_single_get0_status, OCSP_check_validity,
15 OCSP_basic_verify
16 - OCSP response utility functions
17
18 =head1 SYNOPSIS
19
20  #include <openssl/ocsp.h>
21
22  int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
23                            int *reason,
24                            ASN1_GENERALIZEDTIME **revtime,
25                            ASN1_GENERALIZEDTIME **thisupd,
26                            ASN1_GENERALIZEDTIME **nextupd);
27
28  int OCSP_resp_count(OCSP_BASICRESP *bs);
29  OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx);
30  int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last);
31  int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
32                              ASN1_GENERALIZEDTIME **revtime,
33                              ASN1_GENERALIZEDTIME **thisupd,
34                              ASN1_GENERALIZEDTIME **nextupd);
35
36  const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(
37                              const OCSP_BASICRESP* single);
38
39  const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *bs);
40  const X509_ALGOR *OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *bs);
41  const OCSP_RESPDATA *OCSP_resp_get0_respdata(const OCSP_BASICRESP *bs);
42  const STACK_OF(X509) *OCSP_resp_get0_certs(const OCSP_BASICRESP *bs);
43
44  int OCSP_resp_get0_signer(OCSP_BASICRESP *bs, X509 **signer,
45                            STACK_OF(X509) *extra_certs);
46
47  int OCSP_resp_get0_id(const OCSP_BASICRESP *bs,
48                        const ASN1_OCTET_STRING **pid,
49                        const X509_NAME **pname);
50  int OCSP_resp_get1_id(const OCSP_BASICRESP *bs,
51                        ASN1_OCTET_STRING **pid,
52                        X509_NAME **pname);
53
54  int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
55                          ASN1_GENERALIZEDTIME *nextupd,
56                          long sec, long maxsec);
57
58  int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
59                       X509_STORE *st, unsigned long flags);
60
61 =head1 DESCRIPTION
62
63 OCSP_resp_find_status() searches I<bs> for an OCSP response for I<id>. If it is
64 successful the fields of the response are returned in I<*status>, I<*reason>,
65 I<*revtime>, I<*thisupd> and I<*nextupd>.  The I<*status> value will be one of
66 B<V_OCSP_CERTSTATUS_GOOD>, B<V_OCSP_CERTSTATUS_REVOKED> or
67 B<V_OCSP_CERTSTATUS_UNKNOWN>. The I<*reason> and I<*revtime> fields are only
68 set if the status is B<V_OCSP_CERTSTATUS_REVOKED>. If set the I<*reason> field
69 will be set to the revocation reason which will be one of
70 B<OCSP_REVOKED_STATUS_NOSTATUS>, B<OCSP_REVOKED_STATUS_UNSPECIFIED>,
71 B<OCSP_REVOKED_STATUS_KEYCOMPROMISE>, B<OCSP_REVOKED_STATUS_CACOMPROMISE>,
72 B<OCSP_REVOKED_STATUS_AFFILIATIONCHANGED>, B<OCSP_REVOKED_STATUS_SUPERSEDED>,
73 B<OCSP_REVOKED_STATUS_CESSATIONOFOPERATION>,
74 B<OCSP_REVOKED_STATUS_CERTIFICATEHOLD> or B<OCSP_REVOKED_STATUS_REMOVEFROMCRL>.
75
76 OCSP_resp_count() returns the number of B<OCSP_SINGLERESP> structures in I<bs>.
77
78 OCSP_resp_get0() returns the B<OCSP_SINGLERESP> structure in I<bs>
79 corresponding to index I<idx>. Where I<idx> runs from 0 to
80 OCSP_resp_count(bs) - 1.
81
82 OCSP_resp_find() searches I<bs> for I<id> and returns the index of the first
83 matching entry after I<last> or starting from the beginning if I<last> is -1.
84
85 OCSP_single_get0_status() extracts the fields of I<single> in I<*reason>,
86 I<*revtime>, I<*thisupd> and I<*nextupd>.
87
88 OCSP_resp_get0_produced_at() extracts the B<producedAt> field from the
89 single response I<bs>.
90
91 OCSP_resp_get0_signature() returns the signature from I<bs>.
92
93 OCSP_resp_get0_tbs_sigalg() returns the B<signatureAlgorithm> from I<bs>.
94
95 OCSP_resp_get0_respdata() returns the B<tbsResponseData> from I<bs>.
96
97 OCSP_resp_get0_certs() returns any certificates included in I<bs>.
98
99 OCSP_resp_get0_signer() attempts to retrieve the certificate that directly
100 signed I<bs>.  The OCSP protocol does not require that this certificate
101 is included in the B<certs> field of the response, so additional certificates
102 can be supplied via the I<extra_certs> if the certificates that may have
103 signed the response are known via some out-of-band mechanism.
104
105 OCSP_resp_get0_id() gets the responder id of I<bs>. If the responder ID is
106 a name then <*pname> is set to the name and I<*pid> is set to NULL. If the
107 responder ID is by key ID then I<*pid> is set to the key ID and I<*pname>
108 is set to NULL. OCSP_resp_get1_id() leaves ownership of I<*pid> and I<*pname>
109 with the caller, who is responsible for freeing them. Both functions return 1
110 in case of success and 0 in case of failure. If OCSP_resp_get1_id() returns 0,
111 no freeing of the results is necessary.
112
113 OCSP_check_validity() checks the validity of its I<thisupd> and I<nextupd>
114 arguments, which will be typically obtained from OCSP_resp_find_status() or
115 OCSP_single_get0_status(). If I<sec> is nonzero it indicates how many seconds
116 leeway should be allowed in the check. If I<maxsec> is positive it indicates
117 the maximum age of I<thisupd> in seconds.
118
119 OCSP_basic_verify() checks that the basic response message I<bs> is correctly
120 signed and that the signer certificate can be validated. It takes I<st> as
121 the trusted store and I<certs> as a set of untrusted intermediate certificates.
122 The function first tries to find the signer certificate of the response
123 in I<certs>. It then searches the certificates the responder may have included
124 in I<bs> unless I<flags> contains B<OCSP_NOINTERN>.
125 It fails if the signer certificate cannot be found.
126 Next, unless I<flags> contains B<OCSP_NOSIGS>, the function checks
127 the signature of I<bs> and fails on error. Then the function already returns
128 success if I<flags> contains B<OCSP_NOVERIFY> or if the signer certificate
129 was found in I<certs> and I<flags> contains B<OCSP_TRUSTOTHER>.
130 Otherwise the function continues by validating the signer certificate.
131 If I<flags> contains B<OCSP_PARTIAL_CHAIN> it takes intermediate CA
132 certificates in I<st> as trust anchors.
133 For more details, see the description of B<X509_V_FLAG_PARTIAL_CHAIN>
134 in L<X509_VERIFY_PARAM_set_flags(3)/VERIFICATION FLAGS>.
135 If I<flags> contains B<OCSP_NOCHAIN> it ignores all certificates in I<certs>
136 and in I<bs>, else it takes them as untrusted intermediate CA certificates
137 and uses them for constructing the validation path for the signer certificate.
138 Certicate revocation status checks using CRLs is disabled during path validation
139 if the signer certificate contains the B<id-pkix-ocsp-no-check> extension.
140 After successful path
141 validation the function returns success if the B<OCSP_NOCHECKS> flag is set.
142 Otherwise it verifies that the signer certificate meets the OCSP issuer
143 criteria including potential delegation. If this does not succeed and the
144 B<OCSP_NOEXPLICIT> flag is not set the function checks for explicit
145 trust for OCSP signing in the root CA certificate.
146
147 =head1 RETURN VALUES
148
149 OCSP_resp_find_status() returns 1 if I<id> is found in I<bs> and 0 otherwise.
150
151 OCSP_resp_count() returns the total number of B<OCSP_SINGLERESP> fields in
152 I<bs>.
153
154 OCSP_resp_get0() returns a pointer to an B<OCSP_SINGLERESP> structure or
155 NULL if I<idx> is out of range.
156
157 OCSP_resp_find() returns the index of I<id> in I<bs> (which may be 0) or -1 if
158 I<id> was not found.
159
160 OCSP_single_get0_status() returns the status of I<single> or -1 if an error
161 occurred.
162
163 OCSP_resp_get0_signer() returns 1 if the signing certificate was located,
164 or 0 on error.
165
166 OCSP_basic_verify() returns 1 on success, 0 on error, or -1 on fatal error such
167 as malloc failure.
168
169 =head1 NOTES
170
171 Applications will typically call OCSP_resp_find_status() using the certificate
172 ID of interest and then check its validity using OCSP_check_validity(). They
173 can then take appropriate action based on the status of the certificate.
174
175 An OCSP response for a certificate contains B<thisUpdate> and B<nextUpdate>
176 fields. Normally the current time should be between these two values. To
177 account for clock skew the I<maxsec> field can be set to nonzero in
178 OCSP_check_validity(). Some responders do not set the B<nextUpdate> field, this
179 would otherwise mean an ancient response would be considered valid: the
180 I<maxsec> parameter to OCSP_check_validity() can be used to limit the permitted
181 age of responses.
182
183 The values written to I<*revtime>, I<*thisupd> and I<*nextupd> by
184 OCSP_resp_find_status() and OCSP_single_get0_status() are internal pointers
185 which MUST NOT be freed up by the calling application. Any or all of these
186 parameters can be set to NULL if their value is not required.
187
188 =head1 SEE ALSO
189
190 L<crypto(7)>,
191 L<OCSP_cert_to_id(3)>,
192 L<OCSP_request_add1_nonce(3)>,
193 L<OCSP_REQUEST_new(3)>,
194 L<OCSP_response_status(3)>,
195 L<OCSP_sendreq_new(3)>,
196 L<X509_VERIFY_PARAM_set_flags(3)>
197
198 =head1 COPYRIGHT
199
200 Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
201
202 Licensed under the Apache License 2.0 (the "License").  You may not use
203 this file except in compliance with the License.  You can obtain a copy
204 in the file LICENSE in the source distribution or at
205 L<https://www.openssl.org/source/license.html>.
206
207 =cut