cmp_asn.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. /*
  2. * Copyright 2007-2021 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright Nokia 2007-2019
  4. * Copyright Siemens AG 2015-2019
  5. *
  6. * Licensed under the Apache License 2.0 (the "License"). You may not use
  7. * this file except in compliance with the License. You can obtain a copy
  8. * in the file LICENSE in the source distribution or at
  9. * https://www.openssl.org/source/license.html
  10. */
  11. #include <openssl/asn1t.h>
  12. #include "cmp_local.h"
  13. /* explicit #includes not strictly needed since implied by the above: */
  14. #include <openssl/cmp.h>
  15. #include <openssl/crmf.h>
  16. /* ASN.1 declarations from RFC4210 */
  17. ASN1_SEQUENCE(OSSL_CMP_REVANNCONTENT) = {
  18. /* OSSL_CMP_PKISTATUS is effectively ASN1_INTEGER so it is used directly */
  19. ASN1_SIMPLE(OSSL_CMP_REVANNCONTENT, status, ASN1_INTEGER),
  20. ASN1_SIMPLE(OSSL_CMP_REVANNCONTENT, certId, OSSL_CRMF_CERTID),
  21. ASN1_SIMPLE(OSSL_CMP_REVANNCONTENT, willBeRevokedAt, ASN1_GENERALIZEDTIME),
  22. ASN1_SIMPLE(OSSL_CMP_REVANNCONTENT, badSinceDate, ASN1_GENERALIZEDTIME),
  23. ASN1_OPT(OSSL_CMP_REVANNCONTENT, crlDetails, X509_EXTENSIONS)
  24. } ASN1_SEQUENCE_END(OSSL_CMP_REVANNCONTENT)
  25. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_REVANNCONTENT)
  26. ASN1_SEQUENCE(OSSL_CMP_CHALLENGE) = {
  27. ASN1_OPT(OSSL_CMP_CHALLENGE, owf, X509_ALGOR),
  28. ASN1_SIMPLE(OSSL_CMP_CHALLENGE, witness, ASN1_OCTET_STRING),
  29. ASN1_SIMPLE(OSSL_CMP_CHALLENGE, challenge, ASN1_OCTET_STRING)
  30. } ASN1_SEQUENCE_END(OSSL_CMP_CHALLENGE)
  31. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CHALLENGE)
  32. ASN1_ITEM_TEMPLATE(OSSL_CMP_POPODECKEYCHALLCONTENT) =
  33. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
  34. OSSL_CMP_POPODECKEYCHALLCONTENT, OSSL_CMP_CHALLENGE)
  35. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_POPODECKEYCHALLCONTENT)
  36. ASN1_ITEM_TEMPLATE(OSSL_CMP_POPODECKEYRESPCONTENT) =
  37. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
  38. OSSL_CMP_POPODECKEYRESPCONTENT, ASN1_INTEGER)
  39. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_POPODECKEYRESPCONTENT)
  40. ASN1_SEQUENCE(OSSL_CMP_CAKEYUPDANNCONTENT) = {
  41. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  42. ASN1_SIMPLE(OSSL_CMP_CAKEYUPDANNCONTENT, oldWithNew, X509),
  43. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  44. ASN1_SIMPLE(OSSL_CMP_CAKEYUPDANNCONTENT, newWithOld, X509),
  45. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  46. ASN1_SIMPLE(OSSL_CMP_CAKEYUPDANNCONTENT, newWithNew, X509)
  47. } ASN1_SEQUENCE_END(OSSL_CMP_CAKEYUPDANNCONTENT)
  48. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CAKEYUPDANNCONTENT)
  49. ASN1_SEQUENCE(OSSL_CMP_ERRORMSGCONTENT) = {
  50. ASN1_SIMPLE(OSSL_CMP_ERRORMSGCONTENT, pKIStatusInfo, OSSL_CMP_PKISI),
  51. ASN1_OPT(OSSL_CMP_ERRORMSGCONTENT, errorCode, ASN1_INTEGER),
  52. /*
  53. * OSSL_CMP_PKIFREETEXT is effectively a sequence of ASN1_UTF8STRING
  54. * so it is used directly
  55. *
  56. */
  57. ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ERRORMSGCONTENT, errorDetails,
  58. ASN1_UTF8STRING)
  59. } ASN1_SEQUENCE_END(OSSL_CMP_ERRORMSGCONTENT)
  60. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_ERRORMSGCONTENT)
  61. ASN1_ADB_TEMPLATE(infotypeandvalue_default) = ASN1_OPT(OSSL_CMP_ITAV,
  62. infoValue.other,
  63. ASN1_ANY);
  64. /* ITAV means InfoTypeAndValue */
  65. ASN1_ADB(OSSL_CMP_ITAV) = {
  66. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  67. ADB_ENTRY(NID_id_it_caProtEncCert, ASN1_OPT(OSSL_CMP_ITAV,
  68. infoValue.caProtEncCert, X509)),
  69. ADB_ENTRY(NID_id_it_signKeyPairTypes,
  70. ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ITAV,
  71. infoValue.signKeyPairTypes, X509_ALGOR)),
  72. ADB_ENTRY(NID_id_it_encKeyPairTypes,
  73. ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ITAV,
  74. infoValue.encKeyPairTypes, X509_ALGOR)),
  75. ADB_ENTRY(NID_id_it_preferredSymmAlg,
  76. ASN1_OPT(OSSL_CMP_ITAV, infoValue.preferredSymmAlg,
  77. X509_ALGOR)),
  78. ADB_ENTRY(NID_id_it_caKeyUpdateInfo,
  79. ASN1_OPT(OSSL_CMP_ITAV, infoValue.caKeyUpdateInfo,
  80. OSSL_CMP_CAKEYUPDANNCONTENT)),
  81. ADB_ENTRY(NID_id_it_currentCRL,
  82. ASN1_OPT(OSSL_CMP_ITAV, infoValue.currentCRL, X509_CRL)),
  83. ADB_ENTRY(NID_id_it_unsupportedOIDs,
  84. ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ITAV,
  85. infoValue.unsupportedOIDs, ASN1_OBJECT)),
  86. ADB_ENTRY(NID_id_it_keyPairParamReq,
  87. ASN1_OPT(OSSL_CMP_ITAV, infoValue.keyPairParamReq,
  88. ASN1_OBJECT)),
  89. ADB_ENTRY(NID_id_it_keyPairParamRep,
  90. ASN1_OPT(OSSL_CMP_ITAV, infoValue.keyPairParamRep,
  91. X509_ALGOR)),
  92. ADB_ENTRY(NID_id_it_revPassphrase,
  93. ASN1_OPT(OSSL_CMP_ITAV, infoValue.revPassphrase,
  94. OSSL_CRMF_ENCRYPTEDVALUE)),
  95. ADB_ENTRY(NID_id_it_implicitConfirm,
  96. ASN1_OPT(OSSL_CMP_ITAV, infoValue.implicitConfirm,
  97. ASN1_NULL)),
  98. ADB_ENTRY(NID_id_it_confirmWaitTime,
  99. ASN1_OPT(OSSL_CMP_ITAV, infoValue.confirmWaitTime,
  100. ASN1_GENERALIZEDTIME)),
  101. ADB_ENTRY(NID_id_it_origPKIMessage,
  102. ASN1_OPT(OSSL_CMP_ITAV, infoValue.origPKIMessage,
  103. OSSL_CMP_MSGS)),
  104. ADB_ENTRY(NID_id_it_suppLangTags,
  105. ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ITAV, infoValue.suppLangTagsValue,
  106. ASN1_UTF8STRING)),
  107. } ASN1_ADB_END(OSSL_CMP_ITAV, 0, infoType, 0,
  108. &infotypeandvalue_default_tt, NULL);
  109. ASN1_SEQUENCE(OSSL_CMP_ITAV) = {
  110. ASN1_SIMPLE(OSSL_CMP_ITAV, infoType, ASN1_OBJECT),
  111. ASN1_ADB_OBJECT(OSSL_CMP_ITAV)
  112. } ASN1_SEQUENCE_END(OSSL_CMP_ITAV)
  113. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_ITAV)
  114. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CMP_ITAV)
  115. OSSL_CMP_ITAV *OSSL_CMP_ITAV_create(ASN1_OBJECT *type, ASN1_TYPE *value)
  116. {
  117. OSSL_CMP_ITAV *itav;
  118. if (type == NULL || (itav = OSSL_CMP_ITAV_new()) == NULL)
  119. return NULL;
  120. OSSL_CMP_ITAV_set0(itav, type, value);
  121. return itav;
  122. }
  123. void OSSL_CMP_ITAV_set0(OSSL_CMP_ITAV *itav, ASN1_OBJECT *type,
  124. ASN1_TYPE *value)
  125. {
  126. itav->infoType = type;
  127. itav->infoValue.other = value;
  128. }
  129. ASN1_OBJECT *OSSL_CMP_ITAV_get0_type(const OSSL_CMP_ITAV *itav)
  130. {
  131. if (itav == NULL)
  132. return NULL;
  133. return itav->infoType;
  134. }
  135. ASN1_TYPE *OSSL_CMP_ITAV_get0_value(const OSSL_CMP_ITAV *itav)
  136. {
  137. if (itav == NULL)
  138. return NULL;
  139. return itav->infoValue.other;
  140. }
  141. int OSSL_CMP_ITAV_push0_stack_item(STACK_OF(OSSL_CMP_ITAV) **itav_sk_p,
  142. OSSL_CMP_ITAV *itav)
  143. {
  144. int created = 0;
  145. if (itav_sk_p == NULL || itav == NULL) {
  146. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  147. goto err;
  148. }
  149. if (*itav_sk_p == NULL) {
  150. if ((*itav_sk_p = sk_OSSL_CMP_ITAV_new_null()) == NULL)
  151. goto err;
  152. created = 1;
  153. }
  154. if (!sk_OSSL_CMP_ITAV_push(*itav_sk_p, itav))
  155. goto err;
  156. return 1;
  157. err:
  158. if (created != 0) {
  159. sk_OSSL_CMP_ITAV_free(*itav_sk_p);
  160. *itav_sk_p = NULL;
  161. }
  162. return 0;
  163. }
  164. /* get ASN.1 encoded integer, return -1 on error */
  165. int ossl_cmp_asn1_get_int(const ASN1_INTEGER *a)
  166. {
  167. int64_t res;
  168. if (!ASN1_INTEGER_get_int64(&res, a)) {
  169. ERR_raise(ERR_LIB_CMP, ASN1_R_INVALID_NUMBER);
  170. return -1;
  171. }
  172. if (res < INT_MIN) {
  173. ERR_raise(ERR_LIB_CMP, ASN1_R_TOO_SMALL);
  174. return -1;
  175. }
  176. if (res > INT_MAX) {
  177. ERR_raise(ERR_LIB_CMP, ASN1_R_TOO_LARGE);
  178. return -1;
  179. }
  180. return (int)res;
  181. }
  182. static int ossl_cmp_msg_cb(int operation, ASN1_VALUE **pval,
  183. const ASN1_ITEM *it, void *exarg)
  184. {
  185. OSSL_CMP_MSG *msg = (OSSL_CMP_MSG *)*pval;
  186. switch (operation) {
  187. case ASN1_OP_FREE_POST:
  188. OPENSSL_free(msg->propq);
  189. break;
  190. case ASN1_OP_DUP_POST:
  191. {
  192. OSSL_CMP_MSG *old = exarg;
  193. if (!ossl_cmp_msg_set0_libctx(msg, old->libctx, old->propq))
  194. return 0;
  195. }
  196. break;
  197. case ASN1_OP_GET0_LIBCTX:
  198. {
  199. OSSL_LIB_CTX **libctx = exarg;
  200. *libctx = msg->libctx;
  201. }
  202. break;
  203. case ASN1_OP_GET0_PROPQ:
  204. {
  205. const char **propq = exarg;
  206. *propq = msg->propq;
  207. }
  208. break;
  209. default:
  210. break;
  211. }
  212. return 1;
  213. }
  214. ASN1_CHOICE(OSSL_CMP_CERTORENCCERT) = {
  215. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  216. ASN1_EXP(OSSL_CMP_CERTORENCCERT, value.certificate, X509, 0),
  217. ASN1_EXP(OSSL_CMP_CERTORENCCERT, value.encryptedCert,
  218. OSSL_CRMF_ENCRYPTEDVALUE, 1),
  219. } ASN1_CHOICE_END(OSSL_CMP_CERTORENCCERT)
  220. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTORENCCERT)
  221. ASN1_SEQUENCE(OSSL_CMP_CERTIFIEDKEYPAIR) = {
  222. ASN1_SIMPLE(OSSL_CMP_CERTIFIEDKEYPAIR, certOrEncCert,
  223. OSSL_CMP_CERTORENCCERT),
  224. ASN1_EXP_OPT(OSSL_CMP_CERTIFIEDKEYPAIR, privateKey,
  225. OSSL_CRMF_ENCRYPTEDVALUE, 0),
  226. ASN1_EXP_OPT(OSSL_CMP_CERTIFIEDKEYPAIR, publicationInfo,
  227. OSSL_CRMF_PKIPUBLICATIONINFO, 1)
  228. } ASN1_SEQUENCE_END(OSSL_CMP_CERTIFIEDKEYPAIR)
  229. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTIFIEDKEYPAIR)
  230. ASN1_SEQUENCE(OSSL_CMP_REVDETAILS) = {
  231. ASN1_SIMPLE(OSSL_CMP_REVDETAILS, certDetails, OSSL_CRMF_CERTTEMPLATE),
  232. ASN1_OPT(OSSL_CMP_REVDETAILS, crlEntryDetails, X509_EXTENSIONS)
  233. } ASN1_SEQUENCE_END(OSSL_CMP_REVDETAILS)
  234. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_REVDETAILS)
  235. ASN1_ITEM_TEMPLATE(OSSL_CMP_REVREQCONTENT) =
  236. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_REVREQCONTENT,
  237. OSSL_CMP_REVDETAILS)
  238. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_REVREQCONTENT)
  239. ASN1_SEQUENCE(OSSL_CMP_REVREPCONTENT) = {
  240. ASN1_SEQUENCE_OF(OSSL_CMP_REVREPCONTENT, status, OSSL_CMP_PKISI),
  241. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_REVREPCONTENT, revCerts, OSSL_CRMF_CERTID,
  242. 0),
  243. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_REVREPCONTENT, crls, X509_CRL, 1)
  244. } ASN1_SEQUENCE_END(OSSL_CMP_REVREPCONTENT)
  245. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_REVREPCONTENT)
  246. ASN1_SEQUENCE(OSSL_CMP_KEYRECREPCONTENT) = {
  247. ASN1_SIMPLE(OSSL_CMP_KEYRECREPCONTENT, status, OSSL_CMP_PKISI),
  248. ASN1_EXP_OPT(OSSL_CMP_KEYRECREPCONTENT, newSigCert, X509, 0),
  249. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_KEYRECREPCONTENT, caCerts, X509, 1),
  250. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_KEYRECREPCONTENT, keyPairHist,
  251. OSSL_CMP_CERTIFIEDKEYPAIR, 2)
  252. } ASN1_SEQUENCE_END(OSSL_CMP_KEYRECREPCONTENT)
  253. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_KEYRECREPCONTENT)
  254. ASN1_ITEM_TEMPLATE(OSSL_CMP_PKISTATUS) =
  255. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_UNIVERSAL, 0, status, ASN1_INTEGER)
  256. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_PKISTATUS)
  257. ASN1_SEQUENCE(OSSL_CMP_PKISI) = {
  258. ASN1_SIMPLE(OSSL_CMP_PKISI, status, OSSL_CMP_PKISTATUS),
  259. /*
  260. * CMP_PKIFREETEXT is effectively a sequence of ASN1_UTF8STRING
  261. * so it is used directly
  262. */
  263. ASN1_SEQUENCE_OF_OPT(OSSL_CMP_PKISI, statusString, ASN1_UTF8STRING),
  264. /*
  265. * OSSL_CMP_PKIFAILUREINFO is effectively ASN1_BIT_STRING so used directly
  266. */
  267. ASN1_OPT(OSSL_CMP_PKISI, failInfo, ASN1_BIT_STRING)
  268. } ASN1_SEQUENCE_END(OSSL_CMP_PKISI)
  269. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PKISI)
  270. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CMP_PKISI)
  271. ASN1_SEQUENCE(OSSL_CMP_CERTSTATUS) = {
  272. ASN1_SIMPLE(OSSL_CMP_CERTSTATUS, certHash, ASN1_OCTET_STRING),
  273. ASN1_SIMPLE(OSSL_CMP_CERTSTATUS, certReqId, ASN1_INTEGER),
  274. ASN1_OPT(OSSL_CMP_CERTSTATUS, statusInfo, OSSL_CMP_PKISI),
  275. ASN1_EXP_OPT(OSSL_CMP_CERTSTATUS, hashAlg, X509_ALGOR, 0)
  276. } ASN1_SEQUENCE_END(OSSL_CMP_CERTSTATUS)
  277. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTSTATUS)
  278. ASN1_ITEM_TEMPLATE(OSSL_CMP_CERTCONFIRMCONTENT) =
  279. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_CERTCONFIRMCONTENT,
  280. OSSL_CMP_CERTSTATUS)
  281. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_CERTCONFIRMCONTENT)
  282. ASN1_SEQUENCE(OSSL_CMP_CERTRESPONSE) = {
  283. ASN1_SIMPLE(OSSL_CMP_CERTRESPONSE, certReqId, ASN1_INTEGER),
  284. ASN1_SIMPLE(OSSL_CMP_CERTRESPONSE, status, OSSL_CMP_PKISI),
  285. ASN1_OPT(OSSL_CMP_CERTRESPONSE, certifiedKeyPair,
  286. OSSL_CMP_CERTIFIEDKEYPAIR),
  287. ASN1_OPT(OSSL_CMP_CERTRESPONSE, rspInfo, ASN1_OCTET_STRING)
  288. } ASN1_SEQUENCE_END(OSSL_CMP_CERTRESPONSE)
  289. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTRESPONSE)
  290. ASN1_SEQUENCE(OSSL_CMP_POLLREQ) = {
  291. ASN1_SIMPLE(OSSL_CMP_POLLREQ, certReqId, ASN1_INTEGER)
  292. } ASN1_SEQUENCE_END(OSSL_CMP_POLLREQ)
  293. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_POLLREQ)
  294. ASN1_ITEM_TEMPLATE(OSSL_CMP_POLLREQCONTENT) =
  295. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_POLLREQCONTENT,
  296. OSSL_CMP_POLLREQ)
  297. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_POLLREQCONTENT)
  298. ASN1_SEQUENCE(OSSL_CMP_POLLREP) = {
  299. ASN1_SIMPLE(OSSL_CMP_POLLREP, certReqId, ASN1_INTEGER),
  300. ASN1_SIMPLE(OSSL_CMP_POLLREP, checkAfter, ASN1_INTEGER),
  301. ASN1_SEQUENCE_OF_OPT(OSSL_CMP_POLLREP, reason, ASN1_UTF8STRING),
  302. } ASN1_SEQUENCE_END(OSSL_CMP_POLLREP)
  303. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_POLLREP)
  304. ASN1_ITEM_TEMPLATE(OSSL_CMP_POLLREPCONTENT) =
  305. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
  306. OSSL_CMP_POLLREPCONTENT,
  307. OSSL_CMP_POLLREP)
  308. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_POLLREPCONTENT)
  309. ASN1_SEQUENCE(OSSL_CMP_CERTREPMESSAGE) = {
  310. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  311. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_CERTREPMESSAGE, caPubs, X509, 1),
  312. ASN1_SEQUENCE_OF(OSSL_CMP_CERTREPMESSAGE, response, OSSL_CMP_CERTRESPONSE)
  313. } ASN1_SEQUENCE_END(OSSL_CMP_CERTREPMESSAGE)
  314. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTREPMESSAGE)
  315. ASN1_ITEM_TEMPLATE(OSSL_CMP_GENMSGCONTENT) =
  316. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_GENMSGCONTENT,
  317. OSSL_CMP_ITAV)
  318. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_GENMSGCONTENT)
  319. ASN1_ITEM_TEMPLATE(OSSL_CMP_GENREPCONTENT) =
  320. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_GENREPCONTENT,
  321. OSSL_CMP_ITAV)
  322. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_GENREPCONTENT)
  323. ASN1_ITEM_TEMPLATE(OSSL_CMP_CRLANNCONTENT) =
  324. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
  325. OSSL_CMP_CRLANNCONTENT, X509_CRL)
  326. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_CRLANNCONTENT)
  327. ASN1_CHOICE(OSSL_CMP_PKIBODY) = {
  328. ASN1_EXP(OSSL_CMP_PKIBODY, value.ir, OSSL_CRMF_MSGS, 0),
  329. ASN1_EXP(OSSL_CMP_PKIBODY, value.ip, OSSL_CMP_CERTREPMESSAGE, 1),
  330. ASN1_EXP(OSSL_CMP_PKIBODY, value.cr, OSSL_CRMF_MSGS, 2),
  331. ASN1_EXP(OSSL_CMP_PKIBODY, value.cp, OSSL_CMP_CERTREPMESSAGE, 3),
  332. ASN1_EXP(OSSL_CMP_PKIBODY, value.p10cr, X509_REQ, 4),
  333. ASN1_EXP(OSSL_CMP_PKIBODY, value.popdecc,
  334. OSSL_CMP_POPODECKEYCHALLCONTENT, 5),
  335. ASN1_EXP(OSSL_CMP_PKIBODY, value.popdecr,
  336. OSSL_CMP_POPODECKEYRESPCONTENT, 6),
  337. ASN1_EXP(OSSL_CMP_PKIBODY, value.kur, OSSL_CRMF_MSGS, 7),
  338. ASN1_EXP(OSSL_CMP_PKIBODY, value.kup, OSSL_CMP_CERTREPMESSAGE, 8),
  339. ASN1_EXP(OSSL_CMP_PKIBODY, value.krr, OSSL_CRMF_MSGS, 9),
  340. ASN1_EXP(OSSL_CMP_PKIBODY, value.krp, OSSL_CMP_KEYRECREPCONTENT, 10),
  341. ASN1_EXP(OSSL_CMP_PKIBODY, value.rr, OSSL_CMP_REVREQCONTENT, 11),
  342. ASN1_EXP(OSSL_CMP_PKIBODY, value.rp, OSSL_CMP_REVREPCONTENT, 12),
  343. ASN1_EXP(OSSL_CMP_PKIBODY, value.ccr, OSSL_CRMF_MSGS, 13),
  344. ASN1_EXP(OSSL_CMP_PKIBODY, value.ccp, OSSL_CMP_CERTREPMESSAGE, 14),
  345. ASN1_EXP(OSSL_CMP_PKIBODY, value.ckuann, OSSL_CMP_CAKEYUPDANNCONTENT, 15),
  346. ASN1_EXP(OSSL_CMP_PKIBODY, value.cann, X509, 16),
  347. ASN1_EXP(OSSL_CMP_PKIBODY, value.rann, OSSL_CMP_REVANNCONTENT, 17),
  348. ASN1_EXP(OSSL_CMP_PKIBODY, value.crlann, OSSL_CMP_CRLANNCONTENT, 18),
  349. ASN1_EXP(OSSL_CMP_PKIBODY, value.pkiconf, ASN1_ANY, 19),
  350. ASN1_EXP(OSSL_CMP_PKIBODY, value.nested, OSSL_CMP_MSGS, 20),
  351. ASN1_EXP(OSSL_CMP_PKIBODY, value.genm, OSSL_CMP_GENMSGCONTENT, 21),
  352. ASN1_EXP(OSSL_CMP_PKIBODY, value.genp, OSSL_CMP_GENREPCONTENT, 22),
  353. ASN1_EXP(OSSL_CMP_PKIBODY, value.error, OSSL_CMP_ERRORMSGCONTENT, 23),
  354. ASN1_EXP(OSSL_CMP_PKIBODY, value.certConf, OSSL_CMP_CERTCONFIRMCONTENT, 24),
  355. ASN1_EXP(OSSL_CMP_PKIBODY, value.pollReq, OSSL_CMP_POLLREQCONTENT, 25),
  356. ASN1_EXP(OSSL_CMP_PKIBODY, value.pollRep, OSSL_CMP_POLLREPCONTENT, 26),
  357. } ASN1_CHOICE_END(OSSL_CMP_PKIBODY)
  358. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PKIBODY)
  359. ASN1_SEQUENCE(OSSL_CMP_PKIHEADER) = {
  360. ASN1_SIMPLE(OSSL_CMP_PKIHEADER, pvno, ASN1_INTEGER),
  361. ASN1_SIMPLE(OSSL_CMP_PKIHEADER, sender, GENERAL_NAME),
  362. ASN1_SIMPLE(OSSL_CMP_PKIHEADER, recipient, GENERAL_NAME),
  363. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, messageTime, ASN1_GENERALIZEDTIME, 0),
  364. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, protectionAlg, X509_ALGOR, 1),
  365. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, senderKID, ASN1_OCTET_STRING, 2),
  366. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, recipKID, ASN1_OCTET_STRING, 3),
  367. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, transactionID, ASN1_OCTET_STRING, 4),
  368. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, senderNonce, ASN1_OCTET_STRING, 5),
  369. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, recipNonce, ASN1_OCTET_STRING, 6),
  370. /*
  371. * OSSL_CMP_PKIFREETEXT is effectively a sequence of ASN1_UTF8STRING
  372. * so it is used directly
  373. */
  374. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_PKIHEADER, freeText, ASN1_UTF8STRING, 7),
  375. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_PKIHEADER, generalInfo,
  376. OSSL_CMP_ITAV, 8)
  377. } ASN1_SEQUENCE_END(OSSL_CMP_PKIHEADER)
  378. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PKIHEADER)
  379. ASN1_SEQUENCE(OSSL_CMP_PROTECTEDPART) = {
  380. ASN1_SIMPLE(OSSL_CMP_MSG, header, OSSL_CMP_PKIHEADER),
  381. ASN1_SIMPLE(OSSL_CMP_MSG, body, OSSL_CMP_PKIBODY)
  382. } ASN1_SEQUENCE_END(OSSL_CMP_PROTECTEDPART)
  383. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PROTECTEDPART)
  384. ASN1_SEQUENCE_cb(OSSL_CMP_MSG, ossl_cmp_msg_cb) = {
  385. ASN1_SIMPLE(OSSL_CMP_MSG, header, OSSL_CMP_PKIHEADER),
  386. ASN1_SIMPLE(OSSL_CMP_MSG, body, OSSL_CMP_PKIBODY),
  387. ASN1_EXP_OPT(OSSL_CMP_MSG, protection, ASN1_BIT_STRING, 0),
  388. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  389. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_MSG, extraCerts, X509, 1)
  390. } ASN1_SEQUENCE_END_cb(OSSL_CMP_MSG, OSSL_CMP_MSG)
  391. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CMP_MSG)
  392. ASN1_ITEM_TEMPLATE(OSSL_CMP_MSGS) =
  393. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_MSGS,
  394. OSSL_CMP_MSG)
  395. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_MSGS)