ocsp.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * Copyright (C) 2011-2012 Free Software Foundation, Inc.
  3. *
  4. * Author: Simon Josefsson
  5. *
  6. * This file is part of GnuTLS.
  7. *
  8. * The GnuTLS is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public License
  10. * as published by the Free Software Foundation; either version 2.1 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. /* Online Certificate Status Protocol - RFC 2560
  23. */
  24. #ifndef GNUTLS_OCSP_H
  25. #define GNUTLS_OCSP_H
  26. #include <gnutls/gnutls.h>
  27. #include <gnutls/x509.h>
  28. /* *INDENT-OFF* */
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* *INDENT-ON* */
  33. #define GNUTLS_OCSP_NONCE "1.3.6.1.5.5.7.48.1.2"
  34. /**
  35. * gnutls_ocsp_print_formats_t:
  36. * @GNUTLS_OCSP_PRINT_FULL: Full information about OCSP request/response.
  37. * @GNUTLS_OCSP_PRINT_COMPACT: More compact information about OCSP request/response.
  38. *
  39. * Enumeration of different OCSP printing variants.
  40. */
  41. typedef enum gnutls_ocsp_print_formats_t {
  42. GNUTLS_OCSP_PRINT_FULL = 0,
  43. GNUTLS_OCSP_PRINT_COMPACT = 1
  44. } gnutls_ocsp_print_formats_t;
  45. /**
  46. * gnutls_ocsp_resp_status_t:
  47. * @GNUTLS_OCSP_RESP_SUCCESSFUL: Response has valid confirmations.
  48. * @GNUTLS_OCSP_RESP_MALFORMEDREQUEST: Illegal confirmation request
  49. * @GNUTLS_OCSP_RESP_INTERNALERROR: Internal error in issuer
  50. * @GNUTLS_OCSP_RESP_TRYLATER: Try again later
  51. * @GNUTLS_OCSP_RESP_SIGREQUIRED: Must sign the request
  52. * @GNUTLS_OCSP_RESP_UNAUTHORIZED: Request unauthorized
  53. *
  54. * Enumeration of different OCSP response status codes.
  55. */
  56. typedef enum gnutls_ocsp_resp_status_t {
  57. GNUTLS_OCSP_RESP_SUCCESSFUL = 0,
  58. GNUTLS_OCSP_RESP_MALFORMEDREQUEST = 1,
  59. GNUTLS_OCSP_RESP_INTERNALERROR = 2,
  60. GNUTLS_OCSP_RESP_TRYLATER = 3,
  61. GNUTLS_OCSP_RESP_SIGREQUIRED = 5,
  62. GNUTLS_OCSP_RESP_UNAUTHORIZED = 6
  63. } gnutls_ocsp_resp_status_t;
  64. /**
  65. * gnutls_ocsp_cert_status_t:
  66. * @GNUTLS_OCSP_CERT_GOOD: Positive response to status inquiry.
  67. * @GNUTLS_OCSP_CERT_REVOKED: Certificate has been revoked.
  68. * @GNUTLS_OCSP_CERT_UNKNOWN: The responder doesn't know about the
  69. * certificate.
  70. *
  71. * Enumeration of different OCSP response certificate status codes.
  72. */
  73. typedef enum gnutls_ocsp_cert_status_t {
  74. GNUTLS_OCSP_CERT_GOOD = 0,
  75. GNUTLS_OCSP_CERT_REVOKED = 1,
  76. GNUTLS_OCSP_CERT_UNKNOWN = 2
  77. } gnutls_ocsp_cert_status_t;
  78. /**
  79. * gnutls_x509_crl_reason_t:
  80. * @GNUTLS_X509_CRLREASON_UNSPECIFIED: Unspecified reason.
  81. * @GNUTLS_X509_CRLREASON_KEYCOMPROMISE: Private key compromised.
  82. * @GNUTLS_X509_CRLREASON_CACOMPROMISE: CA compromised.
  83. * @GNUTLS_X509_CRLREASON_AFFILIATIONCHANGED: Affiliation has changed.
  84. * @GNUTLS_X509_CRLREASON_SUPERSEDED: Certificate superseded.
  85. * @GNUTLS_X509_CRLREASON_CESSATIONOFOPERATION: Operation has ceased.
  86. * @GNUTLS_X509_CRLREASON_CERTIFICATEHOLD: Certificate is on hold.
  87. * @GNUTLS_X509_CRLREASON_REMOVEFROMCRL: Will be removed from delta CRL.
  88. * @GNUTLS_X509_CRLREASON_PRIVILEGEWITHDRAWN: Privilege withdrawn.
  89. * @GNUTLS_X509_CRLREASON_AACOMPROMISE: AA compromised.
  90. *
  91. * Enumeration of different reason codes. Note that this
  92. * corresponds to the CRLReason ASN.1 enumeration type, and not the
  93. * ReasonFlags ASN.1 bit string.
  94. */
  95. typedef enum gnutls_x509_crl_reason_t {
  96. GNUTLS_X509_CRLREASON_UNSPECIFIED = 0,
  97. GNUTLS_X509_CRLREASON_KEYCOMPROMISE = 1,
  98. GNUTLS_X509_CRLREASON_CACOMPROMISE = 2,
  99. GNUTLS_X509_CRLREASON_AFFILIATIONCHANGED = 3,
  100. GNUTLS_X509_CRLREASON_SUPERSEDED = 4,
  101. GNUTLS_X509_CRLREASON_CESSATIONOFOPERATION = 5,
  102. GNUTLS_X509_CRLREASON_CERTIFICATEHOLD = 6,
  103. GNUTLS_X509_CRLREASON_REMOVEFROMCRL = 8,
  104. GNUTLS_X509_CRLREASON_PRIVILEGEWITHDRAWN = 9,
  105. GNUTLS_X509_CRLREASON_AACOMPROMISE = 10
  106. } gnutls_x509_crl_reason_t;
  107. /**
  108. * gnutls_ocsp_verify_reason_t:
  109. * @GNUTLS_OCSP_VERIFY_SIGNER_NOT_FOUND: Signer cert not found.
  110. * @GNUTLS_OCSP_VERIFY_SIGNER_KEYUSAGE_ERROR: Signer keyusage bits incorrect.
  111. * @GNUTLS_OCSP_VERIFY_UNTRUSTED_SIGNER: Signer is not trusted.
  112. * @GNUTLS_OCSP_VERIFY_INSECURE_ALGORITHM: Signature using insecure algorithm.
  113. * @GNUTLS_OCSP_VERIFY_SIGNATURE_FAILURE: Signature mismatch.
  114. * @GNUTLS_OCSP_VERIFY_CERT_NOT_ACTIVATED: Signer cert is not yet activated.
  115. * @GNUTLS_OCSP_VERIFY_CERT_EXPIRED: Signer cert has expired.
  116. *
  117. * Enumeration of OCSP verify status codes, used by
  118. * gnutls_ocsp_resp_verify() and gnutls_ocsp_resp_verify_direct().
  119. */
  120. typedef enum gnutls_ocsp_verify_reason_t {
  121. GNUTLS_OCSP_VERIFY_SIGNER_NOT_FOUND = 1,
  122. GNUTLS_OCSP_VERIFY_SIGNER_KEYUSAGE_ERROR = 2,
  123. GNUTLS_OCSP_VERIFY_UNTRUSTED_SIGNER = 4,
  124. GNUTLS_OCSP_VERIFY_INSECURE_ALGORITHM = 8,
  125. GNUTLS_OCSP_VERIFY_SIGNATURE_FAILURE = 16,
  126. GNUTLS_OCSP_VERIFY_CERT_NOT_ACTIVATED = 32,
  127. GNUTLS_OCSP_VERIFY_CERT_EXPIRED = 64
  128. } gnutls_ocsp_verify_reason_t;
  129. struct gnutls_ocsp_req_int;
  130. typedef struct gnutls_ocsp_req_int *gnutls_ocsp_req_t;
  131. int gnutls_ocsp_req_init(gnutls_ocsp_req_t * req);
  132. void gnutls_ocsp_req_deinit(gnutls_ocsp_req_t req);
  133. int gnutls_ocsp_req_import(gnutls_ocsp_req_t req,
  134. const gnutls_datum_t * data);
  135. int gnutls_ocsp_req_export(gnutls_ocsp_req_t req, gnutls_datum_t * data);
  136. int gnutls_ocsp_req_print(gnutls_ocsp_req_t req,
  137. gnutls_ocsp_print_formats_t format,
  138. gnutls_datum_t * out);
  139. int gnutls_ocsp_req_get_version(gnutls_ocsp_req_t req);
  140. int gnutls_ocsp_req_get_cert_id(gnutls_ocsp_req_t req,
  141. unsigned indx,
  142. gnutls_digest_algorithm_t * digest,
  143. gnutls_datum_t * issuer_name_hash,
  144. gnutls_datum_t * issuer_key_hash,
  145. gnutls_datum_t * serial_number);
  146. int gnutls_ocsp_req_add_cert_id(gnutls_ocsp_req_t req,
  147. gnutls_digest_algorithm_t digest,
  148. const gnutls_datum_t *
  149. issuer_name_hash,
  150. const gnutls_datum_t *
  151. issuer_key_hash,
  152. const gnutls_datum_t * serial_number);
  153. int gnutls_ocsp_req_add_cert(gnutls_ocsp_req_t req,
  154. gnutls_digest_algorithm_t digest,
  155. gnutls_x509_crt_t issuer,
  156. gnutls_x509_crt_t cert);
  157. int gnutls_ocsp_req_get_extension(gnutls_ocsp_req_t req,
  158. unsigned indx,
  159. gnutls_datum_t * oid,
  160. unsigned int *critical,
  161. gnutls_datum_t * data);
  162. int gnutls_ocsp_req_set_extension(gnutls_ocsp_req_t req,
  163. const char *oid,
  164. unsigned int critical,
  165. const gnutls_datum_t * data);
  166. int gnutls_ocsp_req_get_nonce(gnutls_ocsp_req_t req,
  167. unsigned int *critical,
  168. gnutls_datum_t * nonce);
  169. int gnutls_ocsp_req_set_nonce(gnutls_ocsp_req_t req,
  170. unsigned int critical,
  171. const gnutls_datum_t * nonce);
  172. int gnutls_ocsp_req_randomize_nonce(gnutls_ocsp_req_t req);
  173. struct gnutls_ocsp_resp_int;
  174. typedef struct gnutls_ocsp_resp_int *gnutls_ocsp_resp_t;
  175. int gnutls_ocsp_resp_init(gnutls_ocsp_resp_t * resp);
  176. void gnutls_ocsp_resp_deinit(gnutls_ocsp_resp_t resp);
  177. int gnutls_ocsp_resp_import(gnutls_ocsp_resp_t resp,
  178. const gnutls_datum_t * data);
  179. int gnutls_ocsp_resp_export(gnutls_ocsp_resp_t resp,
  180. gnutls_datum_t * data);
  181. int gnutls_ocsp_resp_print(gnutls_ocsp_resp_t resp,
  182. gnutls_ocsp_print_formats_t format,
  183. gnutls_datum_t * out);
  184. int gnutls_ocsp_resp_get_status(gnutls_ocsp_resp_t resp);
  185. int gnutls_ocsp_resp_get_response(gnutls_ocsp_resp_t resp,
  186. gnutls_datum_t *
  187. response_type_oid,
  188. gnutls_datum_t * response);
  189. int gnutls_ocsp_resp_get_version(gnutls_ocsp_resp_t resp);
  190. int gnutls_ocsp_resp_get_responder(gnutls_ocsp_resp_t resp,
  191. gnutls_datum_t * dn);
  192. int gnutls_ocsp_resp_get_responder2(gnutls_ocsp_resp_t resp,
  193. gnutls_datum_t * dn,
  194. unsigned flags);
  195. /* the raw key ID of the responder */
  196. #define GNUTLS_OCSP_RESP_ID_KEY 1
  197. /* the raw DN of the responder */
  198. #define GNUTLS_OCSP_RESP_ID_DN 2
  199. int
  200. gnutls_ocsp_resp_get_responder_raw_id(gnutls_ocsp_resp_t resp,
  201. unsigned type,
  202. gnutls_datum_t * raw);
  203. time_t gnutls_ocsp_resp_get_produced(gnutls_ocsp_resp_t resp);
  204. int gnutls_ocsp_resp_get_single(gnutls_ocsp_resp_t resp,
  205. unsigned indx,
  206. gnutls_digest_algorithm_t * digest,
  207. gnutls_datum_t * issuer_name_hash,
  208. gnutls_datum_t * issuer_key_hash,
  209. gnutls_datum_t * serial_number,
  210. unsigned int *cert_status,
  211. time_t * this_update,
  212. time_t * next_update,
  213. time_t * revocation_time,
  214. unsigned int *revocation_reason);
  215. int gnutls_ocsp_resp_get_extension(gnutls_ocsp_resp_t resp,
  216. unsigned indx,
  217. gnutls_datum_t * oid,
  218. unsigned int *critical,
  219. gnutls_datum_t * data);
  220. int gnutls_ocsp_resp_get_nonce(gnutls_ocsp_resp_t resp,
  221. unsigned int *critical,
  222. gnutls_datum_t * nonce);
  223. int gnutls_ocsp_resp_get_signature_algorithm(gnutls_ocsp_resp_t resp);
  224. int gnutls_ocsp_resp_get_signature(gnutls_ocsp_resp_t resp,
  225. gnutls_datum_t * sig);
  226. int gnutls_ocsp_resp_get_certs(gnutls_ocsp_resp_t resp,
  227. gnutls_x509_crt_t ** certs,
  228. size_t * ncerts);
  229. int gnutls_ocsp_resp_verify_direct(gnutls_ocsp_resp_t resp,
  230. gnutls_x509_crt_t issuer,
  231. unsigned int *verify,
  232. unsigned int flags);
  233. int gnutls_ocsp_resp_verify(gnutls_ocsp_resp_t resp,
  234. gnutls_x509_trust_list_t trustlist,
  235. unsigned int *verify, unsigned int flags);
  236. int gnutls_ocsp_resp_check_crt(gnutls_ocsp_resp_t resp,
  237. unsigned int indx, gnutls_x509_crt_t crt);
  238. /* *INDENT-OFF* */
  239. #ifdef __cplusplus
  240. }
  241. #endif
  242. /* *INDENT-ON* */
  243. #endif /* GNUTLS_OCSP_H */