A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

375 lines
16 KiB

9 years ago
  1. /*
  2. * Copyright 2000-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OPENSSL_OCSP_H
  10. # define OPENSSL_OCSP_H
  11. # pragma once
  12. # include <openssl/macros.h>
  13. # ifndef OPENSSL_NO_DEPRECATED_3_0
  14. # define HEADER_OCSP_H
  15. # endif
  16. # include <openssl/opensslconf.h>
  17. /*
  18. * These definitions are outside the OPENSSL_NO_OCSP guard because although for
  19. * historical reasons they have OCSP_* names, they can actually be used
  20. * independently of OCSP. E.g. see RFC5280
  21. */
  22. /*-
  23. * CRLReason ::= ENUMERATED {
  24. * unspecified (0),
  25. * keyCompromise (1),
  26. * cACompromise (2),
  27. * affiliationChanged (3),
  28. * superseded (4),
  29. * cessationOfOperation (5),
  30. * certificateHold (6),
  31. * -- value 7 is not used
  32. * removeFromCRL (8),
  33. * privilegeWithdrawn (9),
  34. * aACompromise (10) }
  35. */
  36. # define OCSP_REVOKED_STATUS_NOSTATUS -1
  37. # define OCSP_REVOKED_STATUS_UNSPECIFIED 0
  38. # define OCSP_REVOKED_STATUS_KEYCOMPROMISE 1
  39. # define OCSP_REVOKED_STATUS_CACOMPROMISE 2
  40. # define OCSP_REVOKED_STATUS_AFFILIATIONCHANGED 3
  41. # define OCSP_REVOKED_STATUS_SUPERSEDED 4
  42. # define OCSP_REVOKED_STATUS_CESSATIONOFOPERATION 5
  43. # define OCSP_REVOKED_STATUS_CERTIFICATEHOLD 6
  44. # define OCSP_REVOKED_STATUS_REMOVEFROMCRL 8
  45. # define OCSP_REVOKED_STATUS_PRIVILEGEWITHDRAWN 9
  46. # define OCSP_REVOKED_STATUS_AACOMPROMISE 10
  47. /*
  48. * These definitions are outside the OPENSSL_NO_OCSP guard because although for
  49. * historical reasons they have OCSP_* names, they are used for the HTTP client.
  50. */
  51. # include <openssl/asn1.h>
  52. /* The following functions are used only internally */
  53. OCSP_REQ_CTX *OCSP_REQ_CTX_new(BIO *wbio, BIO *rbio,
  54. int method_GET, int maxline,
  55. unsigned long max_resp_len, int timeout,
  56. const char *expected_content_type,
  57. int expect_asn1);
  58. void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx);
  59. int OCSP_REQ_CTX_http(OCSP_REQ_CTX *rctx,
  60. const char *server, const char *port, const char *path);
  61. int OCSP_REQ_CTX_add1_header(OCSP_REQ_CTX *rctx,
  62. const char *name, const char *value);
  63. int OCSP_REQ_CTX_i2d(OCSP_REQ_CTX *rctx, const char *content_type,
  64. const ASN1_ITEM *it, ASN1_VALUE *req);
  65. int OCSP_REQ_CTX_nbio(OCSP_REQ_CTX *rctx);
  66. ASN1_VALUE *OCSP_REQ_CTX_nbio_d2i(OCSP_REQ_CTX *rctx, const ASN1_ITEM *it);
  67. BIO *OCSP_REQ_CTX_get0_mem_bio(OCSP_REQ_CTX *rctx);
  68. void OCSP_set_max_response_length(OCSP_REQ_CTX *rctx, unsigned long len);
  69. /* End of functions used only internally */
  70. # ifndef OPENSSL_NO_OCSP
  71. # include <openssl/x509.h>
  72. # include <openssl/x509v3.h>
  73. # include <openssl/safestack.h>
  74. # include <openssl/ocsperr.h>
  75. # ifdef __cplusplus
  76. extern "C" {
  77. # endif
  78. /* Various flags and values */
  79. # define OCSP_DEFAULT_NONCE_LENGTH 16
  80. # define OCSP_NOCERTS 0x1
  81. # define OCSP_NOINTERN 0x2
  82. # define OCSP_NOSIGS 0x4
  83. # define OCSP_NOCHAIN 0x8
  84. # define OCSP_NOVERIFY 0x10
  85. # define OCSP_NOEXPLICIT 0x20
  86. # define OCSP_NOCASIGN 0x40
  87. # define OCSP_NODELEGATED 0x80
  88. # define OCSP_NOCHECKS 0x100
  89. # define OCSP_TRUSTOTHER 0x200
  90. # define OCSP_RESPID_KEY 0x400
  91. # define OCSP_NOTIME 0x800
  92. typedef struct ocsp_cert_id_st OCSP_CERTID;
  93. DEFINE_STACK_OF(OCSP_CERTID)
  94. typedef struct ocsp_one_request_st OCSP_ONEREQ;
  95. DEFINE_STACK_OF(OCSP_ONEREQ)
  96. typedef struct ocsp_req_info_st OCSP_REQINFO;
  97. typedef struct ocsp_signature_st OCSP_SIGNATURE;
  98. typedef struct ocsp_request_st OCSP_REQUEST;
  99. # define OCSP_RESPONSE_STATUS_SUCCESSFUL 0
  100. # define OCSP_RESPONSE_STATUS_MALFORMEDREQUEST 1
  101. # define OCSP_RESPONSE_STATUS_INTERNALERROR 2
  102. # define OCSP_RESPONSE_STATUS_TRYLATER 3
  103. # define OCSP_RESPONSE_STATUS_SIGREQUIRED 5
  104. # define OCSP_RESPONSE_STATUS_UNAUTHORIZED 6
  105. typedef struct ocsp_resp_bytes_st OCSP_RESPBYTES;
  106. # define V_OCSP_RESPID_NAME 0
  107. # define V_OCSP_RESPID_KEY 1
  108. DEFINE_STACK_OF(OCSP_RESPID)
  109. typedef struct ocsp_revoked_info_st OCSP_REVOKEDINFO;
  110. # define V_OCSP_CERTSTATUS_GOOD 0
  111. # define V_OCSP_CERTSTATUS_REVOKED 1
  112. # define V_OCSP_CERTSTATUS_UNKNOWN 2
  113. typedef struct ocsp_cert_status_st OCSP_CERTSTATUS;
  114. typedef struct ocsp_single_response_st OCSP_SINGLERESP;
  115. DEFINE_STACK_OF(OCSP_SINGLERESP)
  116. typedef struct ocsp_response_data_st OCSP_RESPDATA;
  117. typedef struct ocsp_basic_response_st OCSP_BASICRESP;
  118. typedef struct ocsp_crl_id_st OCSP_CRLID;
  119. typedef struct ocsp_service_locator_st OCSP_SERVICELOC;
  120. # define PEM_STRING_OCSP_REQUEST "OCSP REQUEST"
  121. # define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE"
  122. # define d2i_OCSP_REQUEST_bio(bp,p) ASN1_d2i_bio_of(OCSP_REQUEST,OCSP_REQUEST_new,d2i_OCSP_REQUEST,bp,p)
  123. # define d2i_OCSP_RESPONSE_bio(bp,p) ASN1_d2i_bio_of(OCSP_RESPONSE,OCSP_RESPONSE_new,d2i_OCSP_RESPONSE,bp,p)
  124. # define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \
  125. (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST, \
  126. bp,(char **)(x),cb,NULL)
  127. # define PEM_read_bio_OCSP_RESPONSE(bp,x,cb) (OCSP_RESPONSE *)PEM_ASN1_read_bio(\
  128. (char *(*)())d2i_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE, \
  129. bp,(char **)(x),cb,NULL)
  130. # define PEM_write_bio_OCSP_REQUEST(bp,o) \
  131. PEM_ASN1_write_bio((int (*)())i2d_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,\
  132. bp,(char *)(o), NULL,NULL,0,NULL,NULL)
  133. # define PEM_write_bio_OCSP_RESPONSE(bp,o) \
  134. PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\
  135. bp,(char *)(o), NULL,NULL,0,NULL,NULL)
  136. # define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio_of(OCSP_RESPONSE,i2d_OCSP_RESPONSE,bp,o)
  137. # define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio_of(OCSP_REQUEST,i2d_OCSP_REQUEST,bp,o)
  138. # define ASN1_BIT_STRING_digest(data,type,md,len) \
  139. ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len)
  140. # define OCSP_CERTSTATUS_dup(cs)\
  141. (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\
  142. (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs))
  143. DECLARE_ASN1_DUP_FUNCTION(OCSP_CERTID)
  144. OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, const char *path, OCSP_REQUEST *req);
  145. OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, const char *path, OCSP_REQUEST *req,
  146. int maxline);
  147. int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx);
  148. /* TODO: remove this (documented but) meanwhile obsolete function? */
  149. int OCSP_REQ_CTX_set1_req(OCSP_REQ_CTX *rctx, const OCSP_REQUEST *req);
  150. OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, const X509 *subject,
  151. const X509 *issuer);
  152. OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
  153. const X509_NAME *issuerName,
  154. const ASN1_BIT_STRING *issuerKey,
  155. const ASN1_INTEGER *serialNumber);
  156. OCSP_ONEREQ *OCSP_request_add0_id(OCSP_REQUEST *req, OCSP_CERTID *cid);
  157. int OCSP_request_add1_nonce(OCSP_REQUEST *req, unsigned char *val, int len);
  158. int OCSP_basic_add1_nonce(OCSP_BASICRESP *resp, unsigned char *val, int len);
  159. int OCSP_check_nonce(OCSP_REQUEST *req, OCSP_BASICRESP *bs);
  160. int OCSP_copy_nonce(OCSP_BASICRESP *resp, OCSP_REQUEST *req);
  161. int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm);
  162. int OCSP_request_add1_cert(OCSP_REQUEST *req, X509 *cert);
  163. int OCSP_request_sign(OCSP_REQUEST *req,
  164. X509 *signer,
  165. EVP_PKEY *key,
  166. const EVP_MD *dgst,
  167. STACK_OF(X509) *certs, unsigned long flags);
  168. int OCSP_response_status(OCSP_RESPONSE *resp);
  169. OCSP_BASICRESP *OCSP_response_get1_basic(OCSP_RESPONSE *resp);
  170. const ASN1_OCTET_STRING *OCSP_resp_get0_signature(const OCSP_BASICRESP *bs);
  171. const X509_ALGOR *OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *bs);
  172. const OCSP_RESPDATA *OCSP_resp_get0_respdata(const OCSP_BASICRESP *bs);
  173. int OCSP_resp_get0_signer(OCSP_BASICRESP *bs, X509 **signer,
  174. STACK_OF(X509) *extra_certs);
  175. int OCSP_resp_count(OCSP_BASICRESP *bs);
  176. OCSP_SINGLERESP *OCSP_resp_get0(OCSP_BASICRESP *bs, int idx);
  177. const ASN1_GENERALIZEDTIME *OCSP_resp_get0_produced_at(const OCSP_BASICRESP* bs);
  178. const STACK_OF(X509) *OCSP_resp_get0_certs(const OCSP_BASICRESP *bs);
  179. int OCSP_resp_get0_id(const OCSP_BASICRESP *bs,
  180. const ASN1_OCTET_STRING **pid,
  181. const X509_NAME **pname);
  182. int OCSP_resp_get1_id(const OCSP_BASICRESP *bs,
  183. ASN1_OCTET_STRING **pid,
  184. X509_NAME **pname);
  185. int OCSP_resp_find(OCSP_BASICRESP *bs, OCSP_CERTID *id, int last);
  186. int OCSP_single_get0_status(OCSP_SINGLERESP *single, int *reason,
  187. ASN1_GENERALIZEDTIME **revtime,
  188. ASN1_GENERALIZEDTIME **thisupd,
  189. ASN1_GENERALIZEDTIME **nextupd);
  190. int OCSP_resp_find_status(OCSP_BASICRESP *bs, OCSP_CERTID *id, int *status,
  191. int *reason,
  192. ASN1_GENERALIZEDTIME **revtime,
  193. ASN1_GENERALIZEDTIME **thisupd,
  194. ASN1_GENERALIZEDTIME **nextupd);
  195. int OCSP_check_validity(ASN1_GENERALIZEDTIME *thisupd,
  196. ASN1_GENERALIZEDTIME *nextupd, long sec, long maxsec);
  197. int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs,
  198. X509_STORE *store, unsigned long flags);
  199. # define OCSP_parse_url OSSL_HTTP_parse_url /* for backward compatibility */
  200. int OCSP_id_issuer_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b);
  201. int OCSP_id_cmp(const OCSP_CERTID *a, const OCSP_CERTID *b);
  202. int OCSP_request_onereq_count(OCSP_REQUEST *req);
  203. OCSP_ONEREQ *OCSP_request_onereq_get0(OCSP_REQUEST *req, int i);
  204. OCSP_CERTID *OCSP_onereq_get0_id(OCSP_ONEREQ *one);
  205. int OCSP_id_get0_info(ASN1_OCTET_STRING **piNameHash, ASN1_OBJECT **pmd,
  206. ASN1_OCTET_STRING **pikeyHash,
  207. ASN1_INTEGER **pserial, OCSP_CERTID *cid);
  208. int OCSP_request_is_signed(OCSP_REQUEST *req);
  209. OCSP_RESPONSE *OCSP_response_create(int status, OCSP_BASICRESP *bs);
  210. OCSP_SINGLERESP *OCSP_basic_add1_status(OCSP_BASICRESP *rsp,
  211. OCSP_CERTID *cid,
  212. int status, int reason,
  213. ASN1_TIME *revtime,
  214. ASN1_TIME *thisupd,
  215. ASN1_TIME *nextupd);
  216. int OCSP_basic_add1_cert(OCSP_BASICRESP *resp, X509 *cert);
  217. int OCSP_basic_sign(OCSP_BASICRESP *brsp,
  218. X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
  219. STACK_OF(X509) *certs, unsigned long flags);
  220. int OCSP_basic_sign_ctx(OCSP_BASICRESP *brsp,
  221. X509 *signer, EVP_MD_CTX *ctx,
  222. STACK_OF(X509) *certs, unsigned long flags);
  223. int OCSP_RESPID_set_by_name(OCSP_RESPID *respid, X509 *cert);
  224. int OCSP_RESPID_set_by_key(OCSP_RESPID *respid, X509 *cert);
  225. int OCSP_RESPID_match(OCSP_RESPID *respid, X509 *cert);
  226. X509_EXTENSION *OCSP_crlID_new(const char *url, long *n, char *tim);
  227. X509_EXTENSION *OCSP_accept_responses_new(char **oids);
  228. X509_EXTENSION *OCSP_archive_cutoff_new(char *tim);
  229. X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME *issuer, const char **urls);
  230. int OCSP_REQUEST_get_ext_count(OCSP_REQUEST *x);
  231. int OCSP_REQUEST_get_ext_by_NID(OCSP_REQUEST *x, int nid, int lastpos);
  232. int OCSP_REQUEST_get_ext_by_OBJ(OCSP_REQUEST *x, const ASN1_OBJECT *obj,
  233. int lastpos);
  234. int OCSP_REQUEST_get_ext_by_critical(OCSP_REQUEST *x, int crit, int lastpos);
  235. X509_EXTENSION *OCSP_REQUEST_get_ext(OCSP_REQUEST *x, int loc);
  236. X509_EXTENSION *OCSP_REQUEST_delete_ext(OCSP_REQUEST *x, int loc);
  237. void *OCSP_REQUEST_get1_ext_d2i(OCSP_REQUEST *x, int nid, int *crit,
  238. int *idx);
  239. int OCSP_REQUEST_add1_ext_i2d(OCSP_REQUEST *x, int nid, void *value, int crit,
  240. unsigned long flags);
  241. int OCSP_REQUEST_add_ext(OCSP_REQUEST *x, X509_EXTENSION *ex, int loc);
  242. int OCSP_ONEREQ_get_ext_count(OCSP_ONEREQ *x);
  243. int OCSP_ONEREQ_get_ext_by_NID(OCSP_ONEREQ *x, int nid, int lastpos);
  244. int OCSP_ONEREQ_get_ext_by_OBJ(OCSP_ONEREQ *x, const ASN1_OBJECT *obj, int lastpos);
  245. int OCSP_ONEREQ_get_ext_by_critical(OCSP_ONEREQ *x, int crit, int lastpos);
  246. X509_EXTENSION *OCSP_ONEREQ_get_ext(OCSP_ONEREQ *x, int loc);
  247. X509_EXTENSION *OCSP_ONEREQ_delete_ext(OCSP_ONEREQ *x, int loc);
  248. void *OCSP_ONEREQ_get1_ext_d2i(OCSP_ONEREQ *x, int nid, int *crit, int *idx);
  249. int OCSP_ONEREQ_add1_ext_i2d(OCSP_ONEREQ *x, int nid, void *value, int crit,
  250. unsigned long flags);
  251. int OCSP_ONEREQ_add_ext(OCSP_ONEREQ *x, X509_EXTENSION *ex, int loc);
  252. int OCSP_BASICRESP_get_ext_count(OCSP_BASICRESP *x);
  253. int OCSP_BASICRESP_get_ext_by_NID(OCSP_BASICRESP *x, int nid, int lastpos);
  254. int OCSP_BASICRESP_get_ext_by_OBJ(OCSP_BASICRESP *x, const ASN1_OBJECT *obj,
  255. int lastpos);
  256. int OCSP_BASICRESP_get_ext_by_critical(OCSP_BASICRESP *x, int crit,
  257. int lastpos);
  258. X509_EXTENSION *OCSP_BASICRESP_get_ext(OCSP_BASICRESP *x, int loc);
  259. X509_EXTENSION *OCSP_BASICRESP_delete_ext(OCSP_BASICRESP *x, int loc);
  260. void *OCSP_BASICRESP_get1_ext_d2i(OCSP_BASICRESP *x, int nid, int *crit,
  261. int *idx);
  262. int OCSP_BASICRESP_add1_ext_i2d(OCSP_BASICRESP *x, int nid, void *value,
  263. int crit, unsigned long flags);
  264. int OCSP_BASICRESP_add_ext(OCSP_BASICRESP *x, X509_EXTENSION *ex, int loc);
  265. int OCSP_SINGLERESP_get_ext_count(OCSP_SINGLERESP *x);
  266. int OCSP_SINGLERESP_get_ext_by_NID(OCSP_SINGLERESP *x, int nid, int lastpos);
  267. int OCSP_SINGLERESP_get_ext_by_OBJ(OCSP_SINGLERESP *x, const ASN1_OBJECT *obj,
  268. int lastpos);
  269. int OCSP_SINGLERESP_get_ext_by_critical(OCSP_SINGLERESP *x, int crit,
  270. int lastpos);
  271. X509_EXTENSION *OCSP_SINGLERESP_get_ext(OCSP_SINGLERESP *x, int loc);
  272. X509_EXTENSION *OCSP_SINGLERESP_delete_ext(OCSP_SINGLERESP *x, int loc);
  273. void *OCSP_SINGLERESP_get1_ext_d2i(OCSP_SINGLERESP *x, int nid, int *crit,
  274. int *idx);
  275. int OCSP_SINGLERESP_add1_ext_i2d(OCSP_SINGLERESP *x, int nid, void *value,
  276. int crit, unsigned long flags);
  277. int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc);
  278. const OCSP_CERTID *OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *x);
  279. DECLARE_ASN1_FUNCTIONS(OCSP_SINGLERESP)
  280. DECLARE_ASN1_FUNCTIONS(OCSP_CERTSTATUS)
  281. DECLARE_ASN1_FUNCTIONS(OCSP_REVOKEDINFO)
  282. DECLARE_ASN1_FUNCTIONS(OCSP_BASICRESP)
  283. DECLARE_ASN1_FUNCTIONS(OCSP_RESPDATA)
  284. DECLARE_ASN1_FUNCTIONS(OCSP_RESPID)
  285. DECLARE_ASN1_FUNCTIONS(OCSP_RESPONSE)
  286. DECLARE_ASN1_FUNCTIONS(OCSP_RESPBYTES)
  287. DECLARE_ASN1_FUNCTIONS(OCSP_ONEREQ)
  288. DECLARE_ASN1_FUNCTIONS(OCSP_CERTID)
  289. DECLARE_ASN1_FUNCTIONS(OCSP_REQUEST)
  290. DECLARE_ASN1_FUNCTIONS(OCSP_SIGNATURE)
  291. DECLARE_ASN1_FUNCTIONS(OCSP_REQINFO)
  292. DECLARE_ASN1_FUNCTIONS(OCSP_CRLID)
  293. DECLARE_ASN1_FUNCTIONS(OCSP_SERVICELOC)
  294. const char *OCSP_response_status_str(long s);
  295. const char *OCSP_cert_status_str(long s);
  296. const char *OCSP_crl_reason_str(long s);
  297. int OCSP_REQUEST_print(BIO *bp, OCSP_REQUEST *a, unsigned long flags);
  298. int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE *o, unsigned long flags);
  299. int OCSP_basic_verify(OCSP_BASICRESP *bs, STACK_OF(X509) *certs,
  300. X509_STORE *st, unsigned long flags);
  301. # ifdef __cplusplus
  302. }
  303. # endif
  304. # endif /* !defined OPENSSL_NO_OCSP */
  305. #endif