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