ocsp.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. from __future__ import absolute_import, division, print_function
  5. INCLUDES = """
  6. #include <openssl/ocsp.h>
  7. """
  8. TYPES = """
  9. typedef ... OCSP_REQUEST;
  10. typedef ... OCSP_ONEREQ;
  11. typedef ... OCSP_RESPONSE;
  12. typedef ... OCSP_BASICRESP;
  13. typedef ... OCSP_SINGLERESP;
  14. typedef ... OCSP_CERTID;
  15. typedef ... OCSP_RESPDATA;
  16. static const long OCSP_NOCERTS;
  17. static const long OCSP_RESPID_KEY;
  18. """
  19. FUNCTIONS = """
  20. int OCSP_response_status(OCSP_RESPONSE *);
  21. OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *);
  22. int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *);
  23. const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *);
  24. Cryptography_STACK_OF_X509 *OCSP_resp_get0_certs(const OCSP_BASICRESP *);
  25. const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(
  26. const OCSP_BASICRESP *);
  27. const OCSP_CERTID *OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *);
  28. int OCSP_resp_get0_id(const OCSP_BASICRESP *, const ASN1_OCTET_STRING **,
  29. const X509_NAME **);
  30. const X509_ALGOR *OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *);
  31. const OCSP_RESPDATA *OCSP_resp_get0_respdata(const OCSP_BASICRESP *);
  32. X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *, int);
  33. int OCSP_resp_count(OCSP_BASICRESP *);
  34. OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *, int);
  35. int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *);
  36. X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *, int);
  37. int OCSP_single_get0_status(OCSP_SINGLERESP *, int *, ASN1_GENERALIZEDTIME **,
  38. ASN1_GENERALIZEDTIME **, ASN1_GENERALIZEDTIME **);
  39. int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *);
  40. X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *, int);
  41. int OCSP_request_onereq_count(OCSP_REQUEST *);
  42. OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *, int);
  43. OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *);
  44. OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *, OCSP_CERTID *);
  45. OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *, const X509 *, const X509 *);
  46. void OCSP_CERTID_free(OCSP_CERTID *);
  47. OCSP_BASICRESP *OCSP_BASICRESP_new(void);
  48. void OCSP_BASICRESP_free(OCSP_BASICRESP *);
  49. OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *, OCSP_CERTID *, int,
  50. int, ASN1_TIME *, ASN1_TIME *,
  51. ASN1_TIME *);
  52. int OCSP_basic_add1_cert(OCSP_BASICRESP *, X509 *);
  53. int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *, X509_EXTENSION *, int);
  54. int OCSP_basic_sign(OCSP_BASICRESP *, X509 *, EVP_PKEY *, const EVP_MD *,
  55. Cryptography_STACK_OF_X509 *, unsigned long);
  56. OCSP_RESPONSE *OCSP_response_create(int, OCSP_BASICRESP *);
  57. void OCSP_RESPONSE_free(OCSP_RESPONSE *);
  58. OCSP_REQUEST *OCSP_REQUEST_new(void);
  59. void OCSP_REQUEST_free(OCSP_REQUEST *);
  60. int OCSP_REQUEST_add_ext(OCSP_REQUEST *, X509_EXTENSION *, int);
  61. int OCSP_id_get0_info(ASN1_OCTET_STRING **, ASN1_OBJECT **,
  62. ASN1_OCTET_STRING **, ASN1_INTEGER **, OCSP_CERTID *);
  63. OCSP_REQUEST *d2i_OCSP_REQUEST_bio(BIO *, OCSP_REQUEST **);
  64. OCSP_RESPONSE *d2i_OCSP_RESPONSE_bio(BIO *, OCSP_RESPONSE **);
  65. int i2d_OCSP_REQUEST_bio(BIO *, OCSP_REQUEST *);
  66. int i2d_OCSP_RESPONSE_bio(BIO *, OCSP_RESPONSE *);
  67. int i2d_OCSP_RESPDATA(OCSP_RESPDATA *, unsigned char **);
  68. """
  69. CUSTOMIZATIONS = """
  70. #if ( \
  71. !CRYPTOGRAPHY_IS_LIBRESSL && \
  72. CRYPTOGRAPHY_OPENSSL_LESS_THAN_110J \
  73. )
  74. /* These structs come from ocsp_lcl.h and are needed to de-opaque the struct
  75. for the getters in OpenSSL 1.1.0 through 1.1.0i */
  76. struct ocsp_responder_id_st {
  77. int type;
  78. union {
  79. X509_NAME *byName;
  80. ASN1_OCTET_STRING *byKey;
  81. } value;
  82. };
  83. struct ocsp_response_data_st {
  84. ASN1_INTEGER *version;
  85. OCSP_RESPID responderId;
  86. ASN1_GENERALIZEDTIME *producedAt;
  87. STACK_OF(OCSP_SINGLERESP) *responses;
  88. STACK_OF(X509_EXTENSION) *responseExtensions;
  89. };
  90. struct ocsp_basic_response_st {
  91. OCSP_RESPDATA tbsResponseData;
  92. X509_ALGOR signatureAlgorithm;
  93. ASN1_BIT_STRING *signature;
  94. STACK_OF(X509) *certs;
  95. };
  96. #endif
  97. #if CRYPTOGRAPHY_IS_LIBRESSL
  98. /* These functions are all taken from ocsp_cl.c in OpenSSL 1.1.0 */
  99. const OCSP_CERTID *OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *single)
  100. {
  101. return single->certId;
  102. }
  103. const Cryptography_STACK_OF_X509 *OCSP_resp_get0_certs(
  104. const OCSP_BASICRESP *bs)
  105. {
  106. return bs->certs;
  107. }
  108. int OCSP_resp_get0_id(const OCSP_BASICRESP *bs,
  109. const ASN1_OCTET_STRING **pid,
  110. const X509_NAME **pname)
  111. {
  112. const OCSP_RESPID *rid = bs->tbsResponseData->responderId;
  113. if (rid->type == V_OCSP_RESPID_NAME) {
  114. *pname = rid->value.byName;
  115. *pid = NULL;
  116. } else if (rid->type == V_OCSP_RESPID_KEY) {
  117. *pid = rid->value.byKey;
  118. *pname = NULL;
  119. } else {
  120. return 0;
  121. }
  122. return 1;
  123. }
  124. const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(
  125. const OCSP_BASICRESP* bs)
  126. {
  127. return bs->tbsResponseData->producedAt;
  128. }
  129. const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *bs)
  130. {
  131. return bs->signature;
  132. }
  133. #endif
  134. #if CRYPTOGRAPHY_OPENSSL_LESS_THAN_110J
  135. const X509_ALGOR *OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *bs)
  136. {
  137. #if CRYPTOGRAPHY_IS_LIBRESSL
  138. return bs->signatureAlgorithm;
  139. #else
  140. return &bs->signatureAlgorithm;
  141. #endif
  142. }
  143. const OCSP_RESPDATA *OCSP_resp_get0_respdata(const OCSP_BASICRESP *bs)
  144. {
  145. #if CRYPTOGRAPHY_IS_LIBRESSL
  146. return bs->tbsResponseData;
  147. #else
  148. return &bs->tbsResponseData;
  149. #endif
  150. }
  151. #endif
  152. """