OCSP_resp_find_status.pod 9.0 KB

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