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.

ocsp.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef _IPXE_OCSP_H
  2. #define _IPXE_OCSP_H
  3. /** @file
  4. *
  5. * Online Certificate Status Protocol
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdarg.h>
  10. #include <time.h>
  11. #include <ipxe/asn1.h>
  12. #include <ipxe/x509.h>
  13. #include <ipxe/refcnt.h>
  14. /** OCSP algorithm identifier */
  15. #define OCSP_ALGORITHM_IDENTIFIER( ... ) \
  16. ASN1_OID, VA_ARG_COUNT ( __VA_ARGS__ ), __VA_ARGS__, \
  17. ASN1_NULL, 0x00
  18. /* OCSP response statuses */
  19. #define OCSP_STATUS_SUCCESSFUL 0x00
  20. #define OCSP_STATUS_MALFORMED_REQUEST 0x01
  21. #define OCSP_STATUS_INTERNAL_ERROR 0x02
  22. #define OCSP_STATUS_TRY_LATER 0x03
  23. #define OCSP_STATUS_SIG_REQUIRED 0x05
  24. #define OCSP_STATUS_UNAUTHORIZED 0x06
  25. struct ocsp_check;
  26. /** An OCSP request */
  27. struct ocsp_request {
  28. /** Request builder */
  29. struct asn1_builder builder;
  30. /** Certificate ID */
  31. struct asn1_cursor cert_id;
  32. };
  33. /** An OCSP responder */
  34. struct ocsp_responder {
  35. /**
  36. * Check if certificate is the responder's certificate
  37. *
  38. * @v ocsp OCSP check
  39. * @v cert Certificate
  40. * @ret difference Difference as returned by memcmp()
  41. */
  42. int ( * compare ) ( struct ocsp_check *ocsp,
  43. struct x509_certificate *cert );
  44. /** Responder ID */
  45. struct asn1_cursor id;
  46. };
  47. /** An OCSP response */
  48. struct ocsp_response {
  49. /** Raw response */
  50. void *data;
  51. /** Raw tbsResponseData */
  52. struct asn1_cursor tbs;
  53. /** Responder */
  54. struct ocsp_responder responder;
  55. /** Time at which status is known to be correct */
  56. time_t this_update;
  57. /** Time at which newer status information will be available */
  58. time_t next_update;
  59. /** Signature algorithm */
  60. struct asn1_algorithm *algorithm;
  61. /** Signature value */
  62. struct asn1_bit_string signature;
  63. /** Signing certificate */
  64. struct x509_certificate *signer;
  65. };
  66. /** An OCSP check */
  67. struct ocsp_check {
  68. /** Reference count */
  69. struct refcnt refcnt;
  70. /** Certificate being checked */
  71. struct x509_certificate *cert;
  72. /** Issuing certificate */
  73. struct x509_certificate *issuer;
  74. /** URI string */
  75. char *uri_string;
  76. /** Request */
  77. struct ocsp_request request;
  78. /** Response */
  79. struct ocsp_response response;
  80. };
  81. /**
  82. * Get reference to OCSP check
  83. *
  84. * @v ocsp OCSP check
  85. * @ret ocsp OCSP check
  86. */
  87. static inline __attribute__ (( always_inline )) struct ocsp_check *
  88. ocsp_get ( struct ocsp_check *ocsp ) {
  89. ref_get ( &ocsp->refcnt );
  90. return ocsp;
  91. }
  92. /**
  93. * Drop reference to OCSP check
  94. *
  95. * @v ocsp OCSP check
  96. */
  97. static inline __attribute__ (( always_inline )) void
  98. ocsp_put ( struct ocsp_check *ocsp ) {
  99. ref_put ( &ocsp->refcnt );
  100. }
  101. /**
  102. * Check if X.509 certificate requires an OCSP check
  103. *
  104. * @v cert X.509 certificate
  105. * @ret ocsp_required An OCSP check is required
  106. */
  107. static inline int ocsp_required ( struct x509_certificate *cert ) {
  108. /* An OCSP check is required if an OCSP URI exists but the
  109. * OCSP status is not (yet) good.
  110. */
  111. return ( cert->extensions.auth_info.ocsp.uri.len &&
  112. ( ! cert->extensions.auth_info.ocsp.good ) );
  113. }
  114. extern int ocsp_check ( struct x509_certificate *cert,
  115. struct x509_certificate *issuer,
  116. struct ocsp_check **ocsp );
  117. extern int ocsp_response ( struct ocsp_check *ocsp, const void *data,
  118. size_t len );
  119. extern int ocsp_validate ( struct ocsp_check *check, time_t time );
  120. #endif /* _IPXE_OCSP_H */