ocsp.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* ocsp.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /* wolfSSL OCSP API */
  22. #ifndef WOLFSSL_OCSP_H
  23. #define WOLFSSL_OCSP_H
  24. #ifdef HAVE_OCSP
  25. #include <wolfssl/ssl.h>
  26. #include <wolfssl/wolfcrypt/asn.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. typedef struct WOLFSSL_OCSP WOLFSSL_OCSP;
  31. #if defined(OPENSSL_ALL) || defined(OPENSSL_EXTRA) || defined(WOLFSSL_NGINX) ||\
  32. defined(WOLFSSL_HAPROXY) || defined(HAVE_LIGHTY)
  33. typedef struct OcspResponse WOLFSSL_OCSP_BASICRESP;
  34. typedef struct OcspEntry WOLFSSL_OCSP_CERTID;
  35. typedef struct OcspEntry WOLFSSL_OCSP_SINGLERESP;
  36. typedef struct OcspRequest WOLFSSL_OCSP_ONEREQ;
  37. typedef struct OcspRequest WOLFSSL_OCSP_REQUEST;
  38. #endif
  39. WOLFSSL_LOCAL int InitOCSP(WOLFSSL_OCSP* ocsp, WOLFSSL_CERT_MANAGER* cm);
  40. WOLFSSL_LOCAL void FreeOCSP(WOLFSSL_OCSP* ocsp, int dynamic);
  41. WOLFSSL_LOCAL int CheckCertOCSP(WOLFSSL_OCSP* ocsp, DecodedCert* cert);
  42. WOLFSSL_LOCAL int CheckCertOCSP_ex(WOLFSSL_OCSP* ocsp, DecodedCert* cert,
  43. WOLFSSL* ssl);
  44. WOLFSSL_LOCAL int CheckOcspRequest(WOLFSSL_OCSP* ocsp,
  45. OcspRequest* ocspRequest, WOLFSSL_BUFFER_INFO* responseBuffer,
  46. void* heap);
  47. WOLFSSL_LOCAL int CheckOcspResponse(WOLFSSL_OCSP *ocsp, byte *response, int responseSz,
  48. WOLFSSL_BUFFER_INFO *responseBuffer, CertStatus *status,
  49. OcspEntry *entry, OcspRequest *ocspRequest,
  50. void* heap);
  51. WOLFSSL_LOCAL int CheckOcspResponder(OcspResponse *bs, DecodedCert *cert,
  52. void* vp);
  53. #if defined(OPENSSL_ALL) || defined(WOLFSSL_NGINX) || defined(WOLFSSL_HAPROXY) || \
  54. defined(WOLFSSL_APACHE_HTTPD) || defined(HAVE_LIGHTY)
  55. WOLFSSL_API int wolfSSL_OCSP_resp_find_status(WOLFSSL_OCSP_BASICRESP *bs,
  56. WOLFSSL_OCSP_CERTID *id, int *status, int *reason,
  57. WOLFSSL_ASN1_TIME **revtime, WOLFSSL_ASN1_TIME **thisupd,
  58. WOLFSSL_ASN1_TIME **nextupd);
  59. WOLFSSL_API const char *wolfSSL_OCSP_cert_status_str(long s);
  60. WOLFSSL_API int wolfSSL_OCSP_check_validity(WOLFSSL_ASN1_TIME* thisupd,
  61. WOLFSSL_ASN1_TIME* nextupd, long sec, long maxsec);
  62. WOLFSSL_API void wolfSSL_OCSP_CERTID_free(WOLFSSL_OCSP_CERTID* certId);
  63. WOLFSSL_API WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_cert_to_id(
  64. const WOLFSSL_EVP_MD *dgst, const WOLFSSL_X509 *subject,
  65. const WOLFSSL_X509 *issuer);
  66. WOLFSSL_API void wolfSSL_OCSP_BASICRESP_free(WOLFSSL_OCSP_BASICRESP* basicResponse);
  67. WOLFSSL_API int wolfSSL_OCSP_basic_verify(WOLFSSL_OCSP_BASICRESP *bs,
  68. WOLF_STACK_OF(WOLFSSL_X509) *certs, WOLFSSL_X509_STORE *st, unsigned long flags);
  69. WOLFSSL_API void wolfSSL_OCSP_RESPONSE_free(OcspResponse* response);
  70. #ifndef NO_BIO
  71. WOLFSSL_API OcspResponse* wolfSSL_d2i_OCSP_RESPONSE_bio(WOLFSSL_BIO* bio,
  72. OcspResponse** response);
  73. #endif
  74. WOLFSSL_API OcspResponse* wolfSSL_d2i_OCSP_RESPONSE(OcspResponse** response,
  75. const unsigned char** data, int len);
  76. WOLFSSL_API int wolfSSL_i2d_OCSP_RESPONSE(OcspResponse* response,
  77. unsigned char** data);
  78. WOLFSSL_API int wolfSSL_OCSP_response_status(OcspResponse *response);
  79. WOLFSSL_API const char *wolfSSL_OCSP_response_status_str(long s);
  80. WOLFSSL_API WOLFSSL_OCSP_BASICRESP* wolfSSL_OCSP_response_get1_basic(
  81. OcspResponse* response);
  82. WOLFSSL_API OcspRequest* wolfSSL_OCSP_REQUEST_new(void);
  83. WOLFSSL_API void wolfSSL_OCSP_REQUEST_free(OcspRequest* request);
  84. WOLFSSL_API int wolfSSL_i2d_OCSP_REQUEST(OcspRequest* request,
  85. unsigned char** data);
  86. WOLFSSL_API WOLFSSL_OCSP_ONEREQ* wolfSSL_OCSP_request_add0_id(OcspRequest *req,
  87. WOLFSSL_OCSP_CERTID *cid);
  88. WOLFSSL_API WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_CERTID_dup(
  89. WOLFSSL_OCSP_CERTID* id);
  90. #ifndef NO_BIO
  91. WOLFSSL_API int wolfSSL_i2d_OCSP_REQUEST_bio(WOLFSSL_BIO* out,
  92. WOLFSSL_OCSP_REQUEST *req);
  93. #endif
  94. WOLFSSL_API int wolfSSL_i2d_OCSP_CERTID(WOLFSSL_OCSP_CERTID* id,
  95. unsigned char** data);
  96. WOLFSSL_API
  97. WOLFSSL_OCSP_CERTID* wolfSSL_d2i_OCSP_CERTID(WOLFSSL_OCSP_CERTID** cidOut,
  98. const unsigned char** derIn,
  99. int length);
  100. WOLFSSL_API const WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_SINGLERESP_get0_id(
  101. const WOLFSSL_OCSP_SINGLERESP *single);
  102. WOLFSSL_API int wolfSSL_OCSP_id_cmp(WOLFSSL_OCSP_CERTID *a, WOLFSSL_OCSP_CERTID *b);
  103. WOLFSSL_API int wolfSSL_OCSP_single_get0_status(WOLFSSL_OCSP_SINGLERESP *single,
  104. int *reason,
  105. WOLFSSL_ASN1_TIME **revtime,
  106. WOLFSSL_ASN1_TIME **thisupd,
  107. WOLFSSL_ASN1_TIME **nextupd);
  108. WOLFSSL_API int wolfSSL_OCSP_resp_count(WOLFSSL_OCSP_BASICRESP *bs);
  109. WOLFSSL_API WOLFSSL_OCSP_SINGLERESP* wolfSSL_OCSP_resp_get0(
  110. WOLFSSL_OCSP_BASICRESP *bs, int idx);
  111. #endif
  112. #ifdef OPENSSL_EXTRA
  113. WOLFSSL_API int wolfSSL_OCSP_REQUEST_add_ext(OcspRequest* req,
  114. WOLFSSL_X509_EXTENSION* ext, int idx);
  115. WOLFSSL_API OcspResponse* wolfSSL_OCSP_response_create(int status,
  116. WOLFSSL_OCSP_BASICRESP* bs);
  117. WOLFSSL_API const char* wolfSSL_OCSP_crl_reason_str(long s);
  118. WOLFSSL_API int wolfSSL_OCSP_id_get0_info(WOLFSSL_ASN1_STRING **name,
  119. WOLFSSL_ASN1_OBJECT **pmd, WOLFSSL_ASN1_STRING **keyHash,
  120. WOLFSSL_ASN1_INTEGER **serial, WOLFSSL_OCSP_CERTID *cid);
  121. WOLFSSL_API int wolfSSL_OCSP_request_add1_nonce(OcspRequest* req,
  122. unsigned char* val, int sz);
  123. WOLFSSL_API int wolfSSL_OCSP_check_nonce(OcspRequest* req,
  124. WOLFSSL_OCSP_BASICRESP* bs);
  125. #endif
  126. #ifdef __cplusplus
  127. } /* extern "C" */
  128. #endif
  129. #endif /* HAVE_OCSP */
  130. #endif /* WOLFSSL_OCSP_H */