cmp_asn.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. /*
  2. * Copyright 2007-2023 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. ADB_ENTRY(NID_id_it_caCerts,
  108. ASN1_SEQUENCE_OF_OPT(OSSL_CMP_ITAV, infoValue.caCerts, X509)),
  109. ADB_ENTRY(NID_id_it_rootCaCert,
  110. ASN1_OPT(OSSL_CMP_ITAV, infoValue.rootCaCert, X509)),
  111. ADB_ENTRY(NID_id_it_rootCaKeyUpdate,
  112. ASN1_OPT(OSSL_CMP_ITAV, infoValue.rootCaKeyUpdate,
  113. OSSL_CMP_ROOTCAKEYUPDATE)),
  114. } ASN1_ADB_END(OSSL_CMP_ITAV, 0, infoType, 0,
  115. &infotypeandvalue_default_tt, NULL);
  116. ASN1_SEQUENCE(OSSL_CMP_ITAV) = {
  117. ASN1_SIMPLE(OSSL_CMP_ITAV, infoType, ASN1_OBJECT),
  118. ASN1_ADB_OBJECT(OSSL_CMP_ITAV)
  119. } ASN1_SEQUENCE_END(OSSL_CMP_ITAV)
  120. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_ITAV)
  121. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CMP_ITAV)
  122. ASN1_SEQUENCE(OSSL_CMP_ROOTCAKEYUPDATE) = {
  123. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  124. ASN1_SIMPLE(OSSL_CMP_ROOTCAKEYUPDATE, newWithNew, X509),
  125. ASN1_EXP_OPT(OSSL_CMP_ROOTCAKEYUPDATE, newWithOld, X509, 0),
  126. ASN1_EXP_OPT(OSSL_CMP_ROOTCAKEYUPDATE, oldWithNew, X509, 1)
  127. } ASN1_SEQUENCE_END(OSSL_CMP_ROOTCAKEYUPDATE)
  128. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_ROOTCAKEYUPDATE)
  129. OSSL_CMP_ITAV *OSSL_CMP_ITAV_create(ASN1_OBJECT *type, ASN1_TYPE *value)
  130. {
  131. OSSL_CMP_ITAV *itav;
  132. if (type == NULL || (itav = OSSL_CMP_ITAV_new()) == NULL)
  133. return NULL;
  134. OSSL_CMP_ITAV_set0(itav, type, value);
  135. return itav;
  136. }
  137. void OSSL_CMP_ITAV_set0(OSSL_CMP_ITAV *itav, ASN1_OBJECT *type,
  138. ASN1_TYPE *value)
  139. {
  140. itav->infoType = type;
  141. itav->infoValue.other = value;
  142. }
  143. ASN1_OBJECT *OSSL_CMP_ITAV_get0_type(const OSSL_CMP_ITAV *itav)
  144. {
  145. if (itav == NULL)
  146. return NULL;
  147. return itav->infoType;
  148. }
  149. ASN1_TYPE *OSSL_CMP_ITAV_get0_value(const OSSL_CMP_ITAV *itav)
  150. {
  151. if (itav == NULL)
  152. return NULL;
  153. return itav->infoValue.other;
  154. }
  155. int OSSL_CMP_ITAV_push0_stack_item(STACK_OF(OSSL_CMP_ITAV) **itav_sk_p,
  156. OSSL_CMP_ITAV *itav)
  157. {
  158. int created = 0;
  159. if (itav_sk_p == NULL || itav == NULL) {
  160. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  161. goto err;
  162. }
  163. if (*itav_sk_p == NULL) {
  164. if ((*itav_sk_p = sk_OSSL_CMP_ITAV_new_null()) == NULL)
  165. goto err;
  166. created = 1;
  167. }
  168. if (!sk_OSSL_CMP_ITAV_push(*itav_sk_p, itav))
  169. goto err;
  170. return 1;
  171. err:
  172. if (created != 0) {
  173. sk_OSSL_CMP_ITAV_free(*itav_sk_p);
  174. *itav_sk_p = NULL;
  175. }
  176. return 0;
  177. }
  178. OSSL_CMP_ITAV *OSSL_CMP_ITAV_new_caCerts(const STACK_OF(X509) *caCerts)
  179. {
  180. OSSL_CMP_ITAV *itav = OSSL_CMP_ITAV_new();
  181. if (itav == NULL)
  182. return NULL;
  183. if (sk_X509_num(caCerts) > 0
  184. && (itav->infoValue.caCerts =
  185. sk_X509_deep_copy(caCerts, X509_dup, X509_free)) == NULL) {
  186. OSSL_CMP_ITAV_free(itav);
  187. return NULL;
  188. }
  189. itav->infoType = OBJ_nid2obj(NID_id_it_caCerts);
  190. return itav;
  191. }
  192. int OSSL_CMP_ITAV_get0_caCerts(const OSSL_CMP_ITAV *itav, STACK_OF(X509) **out)
  193. {
  194. if (itav == NULL || out == NULL) {
  195. ERR_raise(ERR_LIB_CMP, ERR_R_PASSED_NULL_PARAMETER);
  196. return 0;
  197. }
  198. if (OBJ_obj2nid(itav->infoType) != NID_id_it_caCerts) {
  199. ERR_raise(ERR_LIB_CMP, ERR_R_PASSED_INVALID_ARGUMENT);
  200. return 0;
  201. }
  202. *out = sk_X509_num(itav->infoValue.caCerts) > 0
  203. ? itav->infoValue.caCerts : NULL;
  204. return 1;
  205. }
  206. OSSL_CMP_ITAV *OSSL_CMP_ITAV_new_rootCaCert(const X509 *rootCaCert)
  207. {
  208. OSSL_CMP_ITAV *itav = OSSL_CMP_ITAV_new();
  209. if (itav == NULL)
  210. return NULL;
  211. if (rootCaCert != NULL
  212. && (itav->infoValue.rootCaCert = X509_dup(rootCaCert)) == NULL) {
  213. OSSL_CMP_ITAV_free(itav);
  214. return NULL;
  215. }
  216. itav->infoType = OBJ_nid2obj(NID_id_it_rootCaCert);
  217. return itav;
  218. }
  219. int OSSL_CMP_ITAV_get0_rootCaCert(const OSSL_CMP_ITAV *itav, X509 **out)
  220. {
  221. if (itav == NULL || out == NULL) {
  222. ERR_raise(ERR_LIB_CMP, ERR_R_PASSED_NULL_PARAMETER);
  223. return 0;
  224. }
  225. if (OBJ_obj2nid(itav->infoType) != NID_id_it_rootCaCert) {
  226. ERR_raise(ERR_LIB_CMP, ERR_R_PASSED_INVALID_ARGUMENT);
  227. return 0;
  228. }
  229. *out = itav->infoValue.rootCaCert;
  230. return 1;
  231. }
  232. OSSL_CMP_ITAV *OSSL_CMP_ITAV_new_rootCaKeyUpdate(const X509 *newWithNew,
  233. const X509 *newWithOld,
  234. const X509 *oldWithNew)
  235. {
  236. OSSL_CMP_ITAV *itav;
  237. OSSL_CMP_ROOTCAKEYUPDATE *upd = OSSL_CMP_ROOTCAKEYUPDATE_new();
  238. if (upd == NULL)
  239. return NULL;
  240. if (newWithNew != NULL && (upd->newWithNew = X509_dup(newWithNew)) == NULL)
  241. goto err;
  242. if (newWithOld != NULL && (upd->newWithOld = X509_dup(newWithOld)) == NULL)
  243. goto err;
  244. if (oldWithNew != NULL && (upd->oldWithNew = X509_dup(oldWithNew)) == NULL)
  245. goto err;
  246. if ((itav = OSSL_CMP_ITAV_new()) == NULL)
  247. goto err;
  248. itav->infoType = OBJ_nid2obj(NID_id_it_rootCaKeyUpdate);
  249. itav->infoValue.rootCaKeyUpdate = upd;
  250. return itav;
  251. err:
  252. OSSL_CMP_ROOTCAKEYUPDATE_free(upd);
  253. return NULL;
  254. }
  255. int OSSL_CMP_ITAV_get0_rootCaKeyUpdate(const OSSL_CMP_ITAV *itav,
  256. X509 **newWithNew,
  257. X509 **newWithOld,
  258. X509 **oldWithNew)
  259. {
  260. OSSL_CMP_ROOTCAKEYUPDATE *upd;
  261. if (itav == NULL || newWithNew == NULL) {
  262. ERR_raise(ERR_LIB_CMP, ERR_R_PASSED_NULL_PARAMETER);
  263. return 0;
  264. }
  265. if (OBJ_obj2nid(itav->infoType) != NID_id_it_rootCaKeyUpdate) {
  266. ERR_raise(ERR_LIB_CMP, ERR_R_PASSED_INVALID_ARGUMENT);
  267. return 0;
  268. }
  269. upd = itav->infoValue.rootCaKeyUpdate;
  270. *newWithNew = upd->newWithNew;
  271. if (newWithOld != NULL)
  272. *newWithOld = upd->newWithOld;
  273. if (oldWithNew != NULL)
  274. *oldWithNew = upd->oldWithNew;
  275. return 1;
  276. }
  277. /* get ASN.1 encoded integer, return -2 on error; -1 is valid for certReqId */
  278. int ossl_cmp_asn1_get_int(const ASN1_INTEGER *a)
  279. {
  280. int64_t res;
  281. if (!ASN1_INTEGER_get_int64(&res, a)) {
  282. ERR_raise(ERR_LIB_CMP, ASN1_R_INVALID_NUMBER);
  283. return -2;
  284. }
  285. if (res < INT_MIN) {
  286. ERR_raise(ERR_LIB_CMP, ASN1_R_TOO_SMALL);
  287. return -2;
  288. }
  289. if (res > INT_MAX) {
  290. ERR_raise(ERR_LIB_CMP, ASN1_R_TOO_LARGE);
  291. return -2;
  292. }
  293. return (int)res;
  294. }
  295. static int ossl_cmp_msg_cb(int operation, ASN1_VALUE **pval,
  296. const ASN1_ITEM *it, void *exarg)
  297. {
  298. OSSL_CMP_MSG *msg = (OSSL_CMP_MSG *)*pval;
  299. switch (operation) {
  300. case ASN1_OP_FREE_POST:
  301. OPENSSL_free(msg->propq);
  302. break;
  303. case ASN1_OP_DUP_POST:
  304. {
  305. OSSL_CMP_MSG *old = exarg;
  306. if (!ossl_cmp_msg_set0_libctx(msg, old->libctx, old->propq))
  307. return 0;
  308. }
  309. break;
  310. case ASN1_OP_GET0_LIBCTX:
  311. {
  312. OSSL_LIB_CTX **libctx = exarg;
  313. *libctx = msg->libctx;
  314. }
  315. break;
  316. case ASN1_OP_GET0_PROPQ:
  317. {
  318. const char **propq = exarg;
  319. *propq = msg->propq;
  320. }
  321. break;
  322. default:
  323. break;
  324. }
  325. return 1;
  326. }
  327. ASN1_CHOICE(OSSL_CMP_CERTORENCCERT) = {
  328. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  329. ASN1_EXP(OSSL_CMP_CERTORENCCERT, value.certificate, X509, 0),
  330. ASN1_EXP(OSSL_CMP_CERTORENCCERT, value.encryptedCert,
  331. OSSL_CRMF_ENCRYPTEDVALUE, 1),
  332. } ASN1_CHOICE_END(OSSL_CMP_CERTORENCCERT)
  333. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTORENCCERT)
  334. ASN1_SEQUENCE(OSSL_CMP_CERTIFIEDKEYPAIR) = {
  335. ASN1_SIMPLE(OSSL_CMP_CERTIFIEDKEYPAIR, certOrEncCert,
  336. OSSL_CMP_CERTORENCCERT),
  337. ASN1_EXP_OPT(OSSL_CMP_CERTIFIEDKEYPAIR, privateKey,
  338. OSSL_CRMF_ENCRYPTEDVALUE, 0),
  339. ASN1_EXP_OPT(OSSL_CMP_CERTIFIEDKEYPAIR, publicationInfo,
  340. OSSL_CRMF_PKIPUBLICATIONINFO, 1)
  341. } ASN1_SEQUENCE_END(OSSL_CMP_CERTIFIEDKEYPAIR)
  342. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTIFIEDKEYPAIR)
  343. ASN1_SEQUENCE(OSSL_CMP_REVDETAILS) = {
  344. ASN1_SIMPLE(OSSL_CMP_REVDETAILS, certDetails, OSSL_CRMF_CERTTEMPLATE),
  345. ASN1_OPT(OSSL_CMP_REVDETAILS, crlEntryDetails, X509_EXTENSIONS)
  346. } ASN1_SEQUENCE_END(OSSL_CMP_REVDETAILS)
  347. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_REVDETAILS)
  348. ASN1_ITEM_TEMPLATE(OSSL_CMP_REVREQCONTENT) =
  349. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_REVREQCONTENT,
  350. OSSL_CMP_REVDETAILS)
  351. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_REVREQCONTENT)
  352. ASN1_SEQUENCE(OSSL_CMP_REVREPCONTENT) = {
  353. ASN1_SEQUENCE_OF(OSSL_CMP_REVREPCONTENT, status, OSSL_CMP_PKISI),
  354. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_REVREPCONTENT, revCerts, OSSL_CRMF_CERTID,
  355. 0),
  356. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_REVREPCONTENT, crls, X509_CRL, 1)
  357. } ASN1_SEQUENCE_END(OSSL_CMP_REVREPCONTENT)
  358. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_REVREPCONTENT)
  359. ASN1_SEQUENCE(OSSL_CMP_KEYRECREPCONTENT) = {
  360. ASN1_SIMPLE(OSSL_CMP_KEYRECREPCONTENT, status, OSSL_CMP_PKISI),
  361. ASN1_EXP_OPT(OSSL_CMP_KEYRECREPCONTENT, newSigCert, X509, 0),
  362. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_KEYRECREPCONTENT, caCerts, X509, 1),
  363. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_KEYRECREPCONTENT, keyPairHist,
  364. OSSL_CMP_CERTIFIEDKEYPAIR, 2)
  365. } ASN1_SEQUENCE_END(OSSL_CMP_KEYRECREPCONTENT)
  366. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_KEYRECREPCONTENT)
  367. ASN1_ITEM_TEMPLATE(OSSL_CMP_PKISTATUS) =
  368. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_UNIVERSAL, 0, status, ASN1_INTEGER)
  369. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_PKISTATUS)
  370. ASN1_SEQUENCE(OSSL_CMP_PKISI) = {
  371. ASN1_SIMPLE(OSSL_CMP_PKISI, status, OSSL_CMP_PKISTATUS),
  372. /*
  373. * CMP_PKIFREETEXT is effectively a sequence of ASN1_UTF8STRING
  374. * so it is used directly
  375. */
  376. ASN1_SEQUENCE_OF_OPT(OSSL_CMP_PKISI, statusString, ASN1_UTF8STRING),
  377. /*
  378. * OSSL_CMP_PKIFAILUREINFO is effectively ASN1_BIT_STRING so used directly
  379. */
  380. ASN1_OPT(OSSL_CMP_PKISI, failInfo, ASN1_BIT_STRING)
  381. } ASN1_SEQUENCE_END(OSSL_CMP_PKISI)
  382. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PKISI)
  383. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CMP_PKISI)
  384. ASN1_SEQUENCE(OSSL_CMP_CERTSTATUS) = {
  385. ASN1_SIMPLE(OSSL_CMP_CERTSTATUS, certHash, ASN1_OCTET_STRING),
  386. ASN1_SIMPLE(OSSL_CMP_CERTSTATUS, certReqId, ASN1_INTEGER),
  387. ASN1_OPT(OSSL_CMP_CERTSTATUS, statusInfo, OSSL_CMP_PKISI),
  388. ASN1_EXP_OPT(OSSL_CMP_CERTSTATUS, hashAlg, X509_ALGOR, 0)
  389. } ASN1_SEQUENCE_END(OSSL_CMP_CERTSTATUS)
  390. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTSTATUS)
  391. ASN1_ITEM_TEMPLATE(OSSL_CMP_CERTCONFIRMCONTENT) =
  392. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_CERTCONFIRMCONTENT,
  393. OSSL_CMP_CERTSTATUS)
  394. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_CERTCONFIRMCONTENT)
  395. ASN1_SEQUENCE(OSSL_CMP_CERTRESPONSE) = {
  396. ASN1_SIMPLE(OSSL_CMP_CERTRESPONSE, certReqId, ASN1_INTEGER),
  397. ASN1_SIMPLE(OSSL_CMP_CERTRESPONSE, status, OSSL_CMP_PKISI),
  398. ASN1_OPT(OSSL_CMP_CERTRESPONSE, certifiedKeyPair,
  399. OSSL_CMP_CERTIFIEDKEYPAIR),
  400. ASN1_OPT(OSSL_CMP_CERTRESPONSE, rspInfo, ASN1_OCTET_STRING)
  401. } ASN1_SEQUENCE_END(OSSL_CMP_CERTRESPONSE)
  402. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTRESPONSE)
  403. ASN1_SEQUENCE(OSSL_CMP_POLLREQ) = {
  404. ASN1_SIMPLE(OSSL_CMP_POLLREQ, certReqId, ASN1_INTEGER)
  405. } ASN1_SEQUENCE_END(OSSL_CMP_POLLREQ)
  406. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_POLLREQ)
  407. ASN1_ITEM_TEMPLATE(OSSL_CMP_POLLREQCONTENT) =
  408. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_POLLREQCONTENT,
  409. OSSL_CMP_POLLREQ)
  410. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_POLLREQCONTENT)
  411. ASN1_SEQUENCE(OSSL_CMP_POLLREP) = {
  412. ASN1_SIMPLE(OSSL_CMP_POLLREP, certReqId, ASN1_INTEGER),
  413. ASN1_SIMPLE(OSSL_CMP_POLLREP, checkAfter, ASN1_INTEGER),
  414. ASN1_SEQUENCE_OF_OPT(OSSL_CMP_POLLREP, reason, ASN1_UTF8STRING),
  415. } ASN1_SEQUENCE_END(OSSL_CMP_POLLREP)
  416. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_POLLREP)
  417. ASN1_ITEM_TEMPLATE(OSSL_CMP_POLLREPCONTENT) =
  418. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
  419. OSSL_CMP_POLLREPCONTENT,
  420. OSSL_CMP_POLLREP)
  421. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_POLLREPCONTENT)
  422. ASN1_SEQUENCE(OSSL_CMP_CERTREPMESSAGE) = {
  423. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  424. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_CERTREPMESSAGE, caPubs, X509, 1),
  425. ASN1_SEQUENCE_OF(OSSL_CMP_CERTREPMESSAGE, response, OSSL_CMP_CERTRESPONSE)
  426. } ASN1_SEQUENCE_END(OSSL_CMP_CERTREPMESSAGE)
  427. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_CERTREPMESSAGE)
  428. ASN1_ITEM_TEMPLATE(OSSL_CMP_GENMSGCONTENT) =
  429. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_GENMSGCONTENT,
  430. OSSL_CMP_ITAV)
  431. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_GENMSGCONTENT)
  432. ASN1_ITEM_TEMPLATE(OSSL_CMP_GENREPCONTENT) =
  433. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_GENREPCONTENT,
  434. OSSL_CMP_ITAV)
  435. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_GENREPCONTENT)
  436. ASN1_ITEM_TEMPLATE(OSSL_CMP_CRLANNCONTENT) =
  437. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
  438. OSSL_CMP_CRLANNCONTENT, X509_CRL)
  439. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_CRLANNCONTENT)
  440. ASN1_CHOICE(OSSL_CMP_PKIBODY) = {
  441. ASN1_EXP(OSSL_CMP_PKIBODY, value.ir, OSSL_CRMF_MSGS, 0),
  442. ASN1_EXP(OSSL_CMP_PKIBODY, value.ip, OSSL_CMP_CERTREPMESSAGE, 1),
  443. ASN1_EXP(OSSL_CMP_PKIBODY, value.cr, OSSL_CRMF_MSGS, 2),
  444. ASN1_EXP(OSSL_CMP_PKIBODY, value.cp, OSSL_CMP_CERTREPMESSAGE, 3),
  445. ASN1_EXP(OSSL_CMP_PKIBODY, value.p10cr, X509_REQ, 4),
  446. ASN1_EXP(OSSL_CMP_PKIBODY, value.popdecc,
  447. OSSL_CMP_POPODECKEYCHALLCONTENT, 5),
  448. ASN1_EXP(OSSL_CMP_PKIBODY, value.popdecr,
  449. OSSL_CMP_POPODECKEYRESPCONTENT, 6),
  450. ASN1_EXP(OSSL_CMP_PKIBODY, value.kur, OSSL_CRMF_MSGS, 7),
  451. ASN1_EXP(OSSL_CMP_PKIBODY, value.kup, OSSL_CMP_CERTREPMESSAGE, 8),
  452. ASN1_EXP(OSSL_CMP_PKIBODY, value.krr, OSSL_CRMF_MSGS, 9),
  453. ASN1_EXP(OSSL_CMP_PKIBODY, value.krp, OSSL_CMP_KEYRECREPCONTENT, 10),
  454. ASN1_EXP(OSSL_CMP_PKIBODY, value.rr, OSSL_CMP_REVREQCONTENT, 11),
  455. ASN1_EXP(OSSL_CMP_PKIBODY, value.rp, OSSL_CMP_REVREPCONTENT, 12),
  456. ASN1_EXP(OSSL_CMP_PKIBODY, value.ccr, OSSL_CRMF_MSGS, 13),
  457. ASN1_EXP(OSSL_CMP_PKIBODY, value.ccp, OSSL_CMP_CERTREPMESSAGE, 14),
  458. ASN1_EXP(OSSL_CMP_PKIBODY, value.ckuann, OSSL_CMP_CAKEYUPDANNCONTENT, 15),
  459. ASN1_EXP(OSSL_CMP_PKIBODY, value.cann, X509, 16),
  460. ASN1_EXP(OSSL_CMP_PKIBODY, value.rann, OSSL_CMP_REVANNCONTENT, 17),
  461. ASN1_EXP(OSSL_CMP_PKIBODY, value.crlann, OSSL_CMP_CRLANNCONTENT, 18),
  462. ASN1_EXP(OSSL_CMP_PKIBODY, value.pkiconf, ASN1_ANY, 19),
  463. ASN1_EXP(OSSL_CMP_PKIBODY, value.nested, OSSL_CMP_MSGS, 20),
  464. ASN1_EXP(OSSL_CMP_PKIBODY, value.genm, OSSL_CMP_GENMSGCONTENT, 21),
  465. ASN1_EXP(OSSL_CMP_PKIBODY, value.genp, OSSL_CMP_GENREPCONTENT, 22),
  466. ASN1_EXP(OSSL_CMP_PKIBODY, value.error, OSSL_CMP_ERRORMSGCONTENT, 23),
  467. ASN1_EXP(OSSL_CMP_PKIBODY, value.certConf, OSSL_CMP_CERTCONFIRMCONTENT, 24),
  468. ASN1_EXP(OSSL_CMP_PKIBODY, value.pollReq, OSSL_CMP_POLLREQCONTENT, 25),
  469. ASN1_EXP(OSSL_CMP_PKIBODY, value.pollRep, OSSL_CMP_POLLREPCONTENT, 26),
  470. } ASN1_CHOICE_END(OSSL_CMP_PKIBODY)
  471. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PKIBODY)
  472. ASN1_SEQUENCE(OSSL_CMP_PKIHEADER) = {
  473. ASN1_SIMPLE(OSSL_CMP_PKIHEADER, pvno, ASN1_INTEGER),
  474. ASN1_SIMPLE(OSSL_CMP_PKIHEADER, sender, GENERAL_NAME),
  475. ASN1_SIMPLE(OSSL_CMP_PKIHEADER, recipient, GENERAL_NAME),
  476. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, messageTime, ASN1_GENERALIZEDTIME, 0),
  477. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, protectionAlg, X509_ALGOR, 1),
  478. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, senderKID, ASN1_OCTET_STRING, 2),
  479. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, recipKID, ASN1_OCTET_STRING, 3),
  480. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, transactionID, ASN1_OCTET_STRING, 4),
  481. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, senderNonce, ASN1_OCTET_STRING, 5),
  482. ASN1_EXP_OPT(OSSL_CMP_PKIHEADER, recipNonce, ASN1_OCTET_STRING, 6),
  483. /*
  484. * OSSL_CMP_PKIFREETEXT is effectively a sequence of ASN1_UTF8STRING
  485. * so it is used directly
  486. */
  487. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_PKIHEADER, freeText, ASN1_UTF8STRING, 7),
  488. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_PKIHEADER, generalInfo,
  489. OSSL_CMP_ITAV, 8)
  490. } ASN1_SEQUENCE_END(OSSL_CMP_PKIHEADER)
  491. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PKIHEADER)
  492. ASN1_SEQUENCE(OSSL_CMP_PROTECTEDPART) = {
  493. ASN1_SIMPLE(OSSL_CMP_MSG, header, OSSL_CMP_PKIHEADER),
  494. ASN1_SIMPLE(OSSL_CMP_MSG, body, OSSL_CMP_PKIBODY)
  495. } ASN1_SEQUENCE_END(OSSL_CMP_PROTECTEDPART)
  496. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CMP_PROTECTEDPART)
  497. ASN1_SEQUENCE_cb(OSSL_CMP_MSG, ossl_cmp_msg_cb) = {
  498. ASN1_SIMPLE(OSSL_CMP_MSG, header, OSSL_CMP_PKIHEADER),
  499. ASN1_SIMPLE(OSSL_CMP_MSG, body, OSSL_CMP_PKIBODY),
  500. ASN1_EXP_OPT(OSSL_CMP_MSG, protection, ASN1_BIT_STRING, 0),
  501. /* OSSL_CMP_CMPCERTIFICATE is effectively X509 so it is used directly */
  502. ASN1_EXP_SEQUENCE_OF_OPT(OSSL_CMP_MSG, extraCerts, X509, 1)
  503. } ASN1_SEQUENCE_END_cb(OSSL_CMP_MSG, OSSL_CMP_MSG)
  504. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CMP_MSG)
  505. ASN1_ITEM_TEMPLATE(OSSL_CMP_MSGS) =
  506. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, OSSL_CMP_MSGS,
  507. OSSL_CMP_MSG)
  508. ASN1_ITEM_TEMPLATE_END(OSSL_CMP_MSGS)