b94896592b15da0fc4ef221c4cd59145202c23bd
[openssl.git] / doc / crypto / OCSP_resp_find_status.pod
1 =pod
2
3 =head1 NAME
4
5 OCSP_resp_get0_produced_at,
6 OCSP_resp_find_status, OCSP_resp_count, OCSP_resp_get0, OCSP_resp_find,
7 OCSP_single_get0_status, OCSP_check_validity
8 - OCSP response utility functions
9
10 =head1 SYNOPSIS
11
12  #include <openssl/ocsp.h>
13
14  int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
15                            int *reason,
16                            ASN1_GENERALIZEDTIME **revtime,
17                            ASN1_GENERALIZEDTIME **thisupd,
18                            ASN1_GENERALIZEDTIME **nextupd);
19
20  int OCSP_resp_count(OCSP_BASICRESP *bs);
21  OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx);
22  int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last);
23  int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
24                              ASN1_GENERALIZEDTIME **revtime,
25                              ASN1_GENERALIZEDTIME **thisupd,
26                              ASN1_GENERALIZEDTIME **nextupd);
27
28  ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(OCSP_BASICRESP* single);
29
30  const STACK_OF(X509) *OCSP_resp_get0_certs(const OCSP_BASICRESP *bs);
31
32  int OCSP_resp_get0_id(const OCSP_BASICRESP *bs,
33                        const ASN1_OCTET_STRING **pid,
34                        const X509_NAME **pname);
35
36  int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
37                          ASN1_GENERALIZEDTIME *nextupd,
38                          long sec, long maxsec);
39
40 =head1 DESCRIPTION
41
42 OCSP_resp_find_status() searches B<bs> for an OCSP response for B<id>. If it is
43 successful the fields of the response are returned in B<*status>, B<*reason>,
44 B<*revtime>, B<*thisupd> and B<*nextupd>.  The B<*status> value will be one of
45 B<V_OCSP_CERTSTATUS_GOOD>, B<V_OCSP_CERTSTATUS_REVOKED> or
46 B<V_OCSP_CERTSTATUS_UNKNOWN>. The B<*reason> and B<*revtime> fields are only
47 set if the status is B<V_OCSP_CERTSTATUS_REVOKED>. If set the B<*reason> field
48 will be set to the revocation reason which will be one of
49 B<OCSP_REVOKED_STATUS_NOSTATUS>, B<OCSP_REVOKED_STATUS_UNSPECIFIED>,
50 B<OCSP_REVOKED_STATUS_KEYCOMPROMISE>, B<OCSP_REVOKED_STATUS_CACOMPROMISE>,
51 B<OCSP_REVOKED_STATUS_AFFILIATIONCHANGED>, B<OCSP_REVOKED_STATUS_SUPERSEDED>,
52 B<OCSP_REVOKED_STATUS_CESSATIONOFOPERATION>,
53 B<OCSP_REVOKED_STATUS_CERTIFICATEHOLD> or B<OCSP_REVOKED_STATUS_REMOVEFROMCRL>.
54
55 OCSP_resp_count() returns the number of B<OCSP_SINGLERESP> structures in B<bs>.
56
57 OCSP_resp_get0() returns the B<OCSP_SINGLERESP> structure in B<bs>
58 corresponding to index B<idx>. Where B<idx> runs from 0 to
59 OCSP_resp_count(bs) - 1.
60
61 OCSP_resp_find() searches B<bs> for B<id> and returns the index of the first
62 matching entry after B<last> or starting from the beginning if B<last> is -1.
63
64 OCSP_single_get0_status() extracts the fields of B<single> in B<*reason>,
65 B<*revtime>, B<*thisupd> and B<*nextupd>.
66
67 OCSP_resp_get0_produced_at() extracts the B<producedAt> field from the
68 single response B<bs>.
69
70 OCSP_resp_get0_certs() returns any certificates included in B<bs>.
71
72 OCSP_resp_get0_id() gets the responder id of <bs>. If the responder ID is
73 a name then <*pname> is set to the name and B<*pid> is set to NULL. If the
74 responder ID is by key ID then B<*pid> is set to the key ID and B<*pname>
75 is set to NULL.
76
77 OCSP_check_validity() checks the validity of B<thisupd> and B<nextupd> values
78 which will be typically obtained from OCSP_resp_find_status() or
79 OCSP_single_get0_status(). If B<sec> is non-zero it indicates how many seconds
80 leeway should be allowed in the check. If B<maxsec> is positive it indicates
81 the maximum age of B<thisupd> in seconds.
82
83 =head1 RETURN VALUES
84
85 OCSP_resp_find_status() returns 1 if B<id> is found in B<bs> and 0 otherwise.
86
87 OCSP_resp_count() returns the total number of B<OCSP_SINGLERESP> fields in
88 B<bs>.
89
90 OCSP_resp_get0() returns a pointer to an B<OCSP_SINGLERESP> structure or
91 B<NULL> if B<idx> is out of range.
92
93 OCSP_resp_find() returns the index of B<id> in B<bs> (which may be 0) or -1 if
94 B<id> was not found.
95
96 OCSP_single_get0_status() returns the status of B<single> or -1 if an error
97 occurred.
98
99 =head1 NOTES
100
101 Applications will typically call OCSP_resp_find_status() using the certificate
102 ID of interest and then check its validity using OCSP_check_validity(). They
103 can then take appropriate action based on the status of the certificate.
104
105 An OCSP response for a certificate contains B<thisUpdate> and B<nextUpdate>
106 fields. Normally the current time should be between these two values. To
107 account for clock skew the B<maxsec> field can be set to non-zero in
108 OCSP_check_validity(). Some responders do not set the B<nextUpdate> field, this
109 would otherwise mean an ancient response would be considered valid: the
110 B<maxsec> parameter to OCSP_check_validity() can be used to limit the permitted
111 age of responses.
112
113 The values written to B<*revtime>, B<*thisupd> and B<*nextupd> by
114 OCSP_resp_find_status() and OCSP_single_get0_status() are internal pointers
115 which B<MUST NOT> be freed up by the calling application. Any or all of these
116 parameters can be set to NULL if their value is not required.
117
118 =head1 SEE ALSO
119
120 L<crypto(3)>,
121 L<OCSP_cert_to_id(3)>,
122 L<OCSP_request_add1_nonce(3)>,
123 L<OCSP_REQUEST_new(3)>,
124 L<OCSP_response_status(3)>,
125 L<OCSP_sendreq_new(3)>
126
127 =head1 COPYRIGHT
128
129 Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
130
131 Licensed under the OpenSSL license (the "License").  You may not use
132 this file except in compliance with the License.  You can obtain a copy
133 in the file LICENSE in the source distribution or at
134 L<https://www.openssl.org/source/license.html>.
135
136 =cut