ocspti.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /*
  5. * Private header defining OCSP types.
  6. */
  7. #ifndef _OCSPTI_H_
  8. #define _OCSPTI_H_
  9. #include "ocspt.h"
  10. #include "certt.h"
  11. #include "plarena.h"
  12. #include "seccomon.h"
  13. #include "secoidt.h"
  14. /*
  15. * Some notes about naming conventions...
  16. *
  17. * The public data types all start with "CERTOCSP" (e.g. CERTOCSPRequest).
  18. * (Even the public types are opaque, however. Only their names are
  19. * "exported".)
  20. *
  21. * Internal-only data types drop the "CERT" prefix and use only the
  22. * lower-case "ocsp" (e.g. ocspTBSRequest), for brevity sake.
  23. *
  24. * In either case, the base/suffix of the type name usually matches the
  25. * name as defined in the OCSP specification. The exceptions to this are:
  26. * - When there is overlap between the "OCSP" or "ocsp" prefix and
  27. * the name used in the standard. That is, you cannot strip off the
  28. * "CERTOCSP" or "ocsp" prefix and necessarily get the name of the
  29. * type as it is defined in the standard; the "real" name will be
  30. * *either* "OCSPSuffix" or just "Suffix".
  31. * - When the name in the standard was a little too generic. (e.g. The
  32. * standard defines "Request" but we call it a "SingleRequest".)
  33. * In this case a comment above the type definition calls attention
  34. * to the difference.
  35. *
  36. * The definitions laid out in this header file are intended to follow
  37. * the same order as the definitions in the OCSP specification itself.
  38. * With the OCSP standard in hand, you should be able to move through
  39. * this file and follow along. To future modifiers of this file: please
  40. * try to keep it that way. The only exceptions are the few cases where
  41. * we need to define a type before it is referenced (e.g. enumerations),
  42. * whereas in the OCSP specification these are usually defined the other
  43. * way around (reference before definition).
  44. */
  45. /*
  46. * Forward-declarations of internal-only data structures.
  47. *
  48. * These are in alphabetical order (case-insensitive); please keep it that way!
  49. */
  50. typedef struct ocspBasicOCSPResponseStr ocspBasicOCSPResponse;
  51. typedef struct ocspCertStatusStr ocspCertStatus;
  52. typedef struct ocspResponderIDStr ocspResponderID;
  53. typedef struct ocspResponseBytesStr ocspResponseBytes;
  54. typedef struct ocspResponseDataStr ocspResponseData;
  55. typedef struct ocspRevokedInfoStr ocspRevokedInfo;
  56. typedef struct ocspServiceLocatorStr ocspServiceLocator;
  57. typedef struct ocspSignatureStr ocspSignature;
  58. typedef struct ocspSingleRequestStr ocspSingleRequest;
  59. typedef struct ocspSingleResponseStr ocspSingleResponse;
  60. typedef struct ocspTBSRequestStr ocspTBSRequest;
  61. /*
  62. * An OCSPRequest; this is what is sent (encoded) to an OCSP responder.
  63. */
  64. struct CERTOCSPRequestStr {
  65. PLArenaPool *arena; /* local; not part of encoding */
  66. ocspTBSRequest *tbsRequest;
  67. ocspSignature *optionalSignature;
  68. };
  69. /*
  70. * A TBSRequest; when an OCSPRequest is signed, the encoding of this
  71. * is what the signature is actually applied to. ("TBS" == To Be Signed)
  72. * Whether signed or not, however, this structure will be present, and
  73. * is the "meat" of the OCSPRequest.
  74. *
  75. * Note that the "requestorName" field cannot be encoded/decoded in the
  76. * same pass as the entire request -- it needs to be handled with a special
  77. * call to convert to/from our internal form of a GeneralName. Thus the
  78. * "derRequestorName" field, which is the actual DER-encoded bytes.
  79. *
  80. * The "extensionHandle" field is used on creation only; it holds
  81. * in-progress extensions as they are optionally added to the request.
  82. */
  83. struct ocspTBSRequestStr {
  84. SECItem version; /* an INTEGER */
  85. SECItem *derRequestorName; /* encoded GeneralName; see above */
  86. CERTGeneralNameList *requestorName; /* local; not part of encoding */
  87. ocspSingleRequest **requestList;
  88. CERTCertExtension **requestExtensions;
  89. void *extensionHandle; /* local; not part of encoding */
  90. };
  91. /*
  92. * This is the actual signature information for an OCSPRequest (applied to
  93. * the TBSRequest structure) or for a BasicOCSPResponse (applied to a
  94. * ResponseData structure).
  95. *
  96. * Note that the "signature" field itself is a BIT STRING; operations on
  97. * it need to keep that in mind, converting the length to bytes as needed
  98. * and back again afterward (so that the length is usually expressing bits).
  99. *
  100. * The "cert" field is the signer's certificate. In the case of a received
  101. * signature, it will be filled in when the signature is verified. In the
  102. * case of a created signature, it is filled in on creation and will be the
  103. * cert used to create the signature when the signing-and-encoding occurs,
  104. * as well as the cert (and its chain) to fill in derCerts if requested.
  105. *
  106. * The extra fields cache information about the signature after we have
  107. * attempted a verification. "wasChecked", if true, means the signature
  108. * has been checked against the appropriate data and thus that "status"
  109. * contains the result of that verification. If "status" is not SECSuccess,
  110. * "failureReason" is a copy of the error code that was set at the time;
  111. * presumably it tells why the signature verification failed.
  112. */
  113. struct ocspSignatureStr {
  114. SECAlgorithmID signatureAlgorithm;
  115. SECItem signature; /* a BIT STRING */
  116. SECItem **derCerts; /* a SEQUENCE OF Certificate */
  117. CERTCertificate *cert; /* local; not part of encoding */
  118. PRBool wasChecked; /* local; not part of encoding */
  119. SECStatus status; /* local; not part of encoding */
  120. int failureReason; /* local; not part of encoding */
  121. };
  122. /*
  123. * An OCSPRequest contains a SEQUENCE OF these, one for each certificate
  124. * whose status is being checked.
  125. *
  126. * Note that in the OCSP specification this is just called "Request",
  127. * but since that seemed confusing (vs. an OCSPRequest) and to be more
  128. * consistent with the parallel type "SingleResponse", I called it a
  129. * "SingleRequest".
  130. *
  131. * XXX figure out how to get rid of that arena -- there must be a way
  132. */
  133. struct ocspSingleRequestStr {
  134. PLArenaPool *arena; /* just a copy of the response arena,
  135. * needed here for extension handling
  136. * routines, on creation only */
  137. CERTOCSPCertID *reqCert;
  138. CERTCertExtension **singleRequestExtensions;
  139. };
  140. /*
  141. * A CertID is the means of identifying a certificate, used both in requests
  142. * and in responses.
  143. *
  144. * When in a SingleRequest it specifies the certificate to be checked.
  145. * When in a SingleResponse it is the cert whose status is being given.
  146. */
  147. struct CERTOCSPCertIDStr {
  148. SECAlgorithmID hashAlgorithm;
  149. SECItem issuerNameHash; /* an OCTET STRING */
  150. SECItem issuerKeyHash; /* an OCTET STRING */
  151. SECItem serialNumber; /* an INTEGER */
  152. SECItem issuerSHA1NameHash; /* keep other hashes around when */
  153. SECItem issuerMD5NameHash; /* we have them */
  154. SECItem issuerMD2NameHash;
  155. SECItem issuerSHA1KeyHash; /* keep other hashes around when */
  156. SECItem issuerMD5KeyHash; /* we have them */
  157. SECItem issuerMD2KeyHash;
  158. PLArenaPool *poolp;
  159. };
  160. /*
  161. * This describes the value of the responseStatus field in an OCSPResponse.
  162. * The corresponding ASN.1 definition is:
  163. *
  164. * OCSPResponseStatus ::= ENUMERATED {
  165. * successful (0), --Response has valid confirmations
  166. * malformedRequest (1), --Illegal confirmation request
  167. * internalError (2), --Internal error in issuer
  168. * tryLater (3), --Try again later
  169. * --(4) is not used
  170. * sigRequired (5), --Must sign the request
  171. * unauthorized (6), --Request unauthorized
  172. * }
  173. */
  174. typedef enum {
  175. ocspResponse_min = 0,
  176. ocspResponse_successful = 0,
  177. ocspResponse_malformedRequest = 1,
  178. ocspResponse_internalError = 2,
  179. ocspResponse_tryLater = 3,
  180. ocspResponse_unused = 4,
  181. ocspResponse_sigRequired = 5,
  182. ocspResponse_unauthorized = 6,
  183. ocspResponse_max = 6 /* Please update max when adding values.
  184. * Remember to also update arrays, e.g.
  185. * "responseStatusNames" in ocspclnt.c
  186. * and potentially other places. */
  187. } ocspResponseStatus;
  188. /*
  189. * An OCSPResponse is what is sent (encoded) by an OCSP responder.
  190. *
  191. * The field "responseStatus" is the ASN.1 encoded value; the field
  192. * "statusValue" is simply that same value translated into our local
  193. * type ocspResponseStatus.
  194. */
  195. struct CERTOCSPResponseStr {
  196. PLArenaPool *arena; /* local; not part of encoding */
  197. SECItem responseStatus; /* an ENUMERATED, see above */
  198. ocspResponseStatus statusValue; /* local; not part of encoding */
  199. ocspResponseBytes *responseBytes; /* only when status is successful */
  200. };
  201. /*
  202. * A ResponseBytes (despite appearances) is what contains the meat
  203. * of a successful response -- but still in encoded form. The type
  204. * given as "responseType" tells you how to decode the string.
  205. *
  206. * We look at the OID and translate it into our local OID representation
  207. * "responseTypeTag", and use that value to tell us how to decode the
  208. * actual response itself. For now the only kind of OCSP response we
  209. * know about is a BasicOCSPResponse. However, the intention in the
  210. * OCSP specification is to allow for other response types, so we are
  211. * building in that flexibility from the start and thus put a pointer
  212. * to that data structure inside of a union. Whenever OCSP adds more
  213. * response types, just add them to the union.
  214. */
  215. struct ocspResponseBytesStr {
  216. SECItem responseType; /* an OBJECT IDENTIFIER */
  217. SECOidTag responseTypeTag; /* local; not part of encoding */
  218. SECItem response; /* an OCTET STRING */
  219. union {
  220. ocspBasicOCSPResponse *basic; /* when type is id-pkix-ocsp-basic */
  221. } decodedResponse; /* local; not part of encoding */
  222. };
  223. /*
  224. * A BasicOCSPResponse -- when the responseType in a ResponseBytes is
  225. * id-pkix-ocsp-basic, the "response" OCTET STRING above is the DER
  226. * encoding of one of these.
  227. *
  228. * Note that in the OCSP specification, the signature fields are not
  229. * part of a separate sub-structure. But since they are the same fields
  230. * as we define for the signature in a request, it made sense to share
  231. * the C data structure here and in some shared code to operate on them.
  232. */
  233. struct ocspBasicOCSPResponseStr {
  234. SECItem tbsResponseDataDER;
  235. ocspResponseData *tbsResponseData; /* "tbs" == To Be Signed */
  236. ocspSignature responseSignature;
  237. };
  238. /*
  239. * A ResponseData is the part of a BasicOCSPResponse that is signed
  240. * (after it is DER encoded). It contains the real details of the response
  241. * (a per-certificate status).
  242. */
  243. struct ocspResponseDataStr {
  244. SECItem version; /* an INTEGER */
  245. SECItem derResponderID;
  246. ocspResponderID *responderID; /* local; not part of encoding */
  247. SECItem producedAt; /* a GeneralizedTime */
  248. CERTOCSPSingleResponse **responses;
  249. CERTCertExtension **responseExtensions;
  250. };
  251. struct ocspResponderIDStr {
  252. CERTOCSPResponderIDType responderIDType; /* local; not part of encoding */
  253. union {
  254. CERTName name; /* when ocspResponderID_byName */
  255. SECItem keyHash; /* when ocspResponderID_byKey */
  256. SECItem other; /* when ocspResponderID_other */
  257. } responderIDValue;
  258. };
  259. /*
  260. * The ResponseData in a BasicOCSPResponse contains a SEQUENCE OF
  261. * SingleResponse -- one for each certificate whose status is being supplied.
  262. *
  263. * XXX figure out how to get rid of that arena -- there must be a way
  264. */
  265. struct CERTOCSPSingleResponseStr {
  266. PLArenaPool *arena; /* just a copy of the response arena,
  267. * needed here for extension handling
  268. * routines, on creation only */
  269. CERTOCSPCertID *certID;
  270. SECItem derCertStatus;
  271. ocspCertStatus *certStatus; /* local; not part of encoding */
  272. SECItem thisUpdate; /* a GeneralizedTime */
  273. SECItem *nextUpdate; /* a GeneralizedTime */
  274. CERTCertExtension **singleExtensions;
  275. };
  276. /*
  277. * A CertStatus is the actual per-certificate status. Its ASN.1 definition:
  278. *
  279. * CertStatus ::= CHOICE {
  280. * good [0] IMPLICIT NULL,
  281. * revoked [1] IMPLICIT RevokedInfo,
  282. * unknown [2] IMPLICIT UnknownInfo }
  283. *
  284. * (where for now UnknownInfo is defined to be NULL but in the
  285. * future may be replaced with an enumeration).
  286. *
  287. * Because it is CHOICE, the status value and its associated information
  288. * (if any) are actually encoded together. To represent this same
  289. * information internally, we explicitly define a type and save it,
  290. * along with the value, into a data structure.
  291. */
  292. typedef enum {
  293. ocspCertStatus_good, /* cert is not revoked */
  294. ocspCertStatus_revoked, /* cert is revoked */
  295. ocspCertStatus_unknown, /* cert was unknown to the responder */
  296. ocspCertStatus_other /* status was not an expected value */
  297. } ocspCertStatusType;
  298. /*
  299. * This is the actual per-certificate status.
  300. *
  301. * The "goodInfo" and "unknownInfo" items are only place-holders for a NULL.
  302. * (Though someday OCSP may replace UnknownInfo with an enumeration that
  303. * gives more detailed information.)
  304. */
  305. struct ocspCertStatusStr {
  306. ocspCertStatusType certStatusType; /* local; not part of encoding */
  307. union {
  308. SECItem *goodInfo; /* when ocspCertStatus_good */
  309. ocspRevokedInfo *revokedInfo; /* when ocspCertStatus_revoked */
  310. SECItem *unknownInfo; /* when ocspCertStatus_unknown */
  311. SECItem *otherInfo; /* when ocspCertStatus_other */
  312. } certStatusInfo;
  313. };
  314. /*
  315. * A RevokedInfo gives information about a revoked certificate -- when it
  316. * was revoked and why.
  317. */
  318. struct ocspRevokedInfoStr {
  319. SECItem revocationTime; /* a GeneralizedTime */
  320. SECItem *revocationReason; /* a CRLReason; ignored for now */
  321. };
  322. /*
  323. * ServiceLocator can be included as one of the singleRequestExtensions.
  324. * When added, it specifies the (name of the) issuer of the cert being
  325. * checked, and optionally the value of the AuthorityInfoAccess extension
  326. * if the cert has one.
  327. */
  328. struct ocspServiceLocatorStr {
  329. CERTName *issuer;
  330. SECItem locator; /* DER encoded authInfoAccess extension from cert */
  331. };
  332. #endif /* _OCSPTI_H_ */