cmp_asn.c 17 KB

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