crmf_asn.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. * CRMF implementation by Martin Peylo, Miikka Viljanen, and David von Oheimb.
  12. */
  13. #include <openssl/asn1t.h>
  14. #include "crmf_local.h"
  15. /* explicit #includes not strictly needed since implied by the above: */
  16. #include <openssl/crmf.h>
  17. ASN1_SEQUENCE(OSSL_CRMF_PRIVATEKEYINFO) = {
  18. ASN1_SIMPLE(OSSL_CRMF_PRIVATEKEYINFO, version, ASN1_INTEGER),
  19. ASN1_SIMPLE(OSSL_CRMF_PRIVATEKEYINFO, privateKeyAlgorithm, X509_ALGOR),
  20. ASN1_SIMPLE(OSSL_CRMF_PRIVATEKEYINFO, privateKey, ASN1_OCTET_STRING),
  21. ASN1_IMP_SET_OF_OPT(OSSL_CRMF_PRIVATEKEYINFO, attributes, X509_ATTRIBUTE, 0)
  22. } ASN1_SEQUENCE_END(OSSL_CRMF_PRIVATEKEYINFO)
  23. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_PRIVATEKEYINFO)
  24. ASN1_CHOICE(OSSL_CRMF_ENCKEYWITHID_IDENTIFIER) = {
  25. ASN1_SIMPLE(OSSL_CRMF_ENCKEYWITHID_IDENTIFIER,
  26. value.string, ASN1_UTF8STRING),
  27. ASN1_SIMPLE(OSSL_CRMF_ENCKEYWITHID_IDENTIFIER,
  28. value.generalName, GENERAL_NAME)
  29. } ASN1_CHOICE_END(OSSL_CRMF_ENCKEYWITHID_IDENTIFIER)
  30. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_ENCKEYWITHID_IDENTIFIER)
  31. ASN1_SEQUENCE(OSSL_CRMF_ENCKEYWITHID) = {
  32. ASN1_SIMPLE(OSSL_CRMF_ENCKEYWITHID, privateKey, OSSL_CRMF_PRIVATEKEYINFO),
  33. ASN1_OPT(OSSL_CRMF_ENCKEYWITHID, identifier,
  34. OSSL_CRMF_ENCKEYWITHID_IDENTIFIER)
  35. } ASN1_SEQUENCE_END(OSSL_CRMF_ENCKEYWITHID)
  36. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_ENCKEYWITHID)
  37. ASN1_SEQUENCE(OSSL_CRMF_CERTID) = {
  38. ASN1_SIMPLE(OSSL_CRMF_CERTID, issuer, GENERAL_NAME),
  39. ASN1_SIMPLE(OSSL_CRMF_CERTID, serialNumber, ASN1_INTEGER)
  40. } ASN1_SEQUENCE_END(OSSL_CRMF_CERTID)
  41. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_CERTID)
  42. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CRMF_CERTID)
  43. ASN1_SEQUENCE(OSSL_CRMF_ENCRYPTEDVALUE) = {
  44. ASN1_IMP_OPT(OSSL_CRMF_ENCRYPTEDVALUE, intendedAlg, X509_ALGOR, 0),
  45. ASN1_IMP_OPT(OSSL_CRMF_ENCRYPTEDVALUE, symmAlg, X509_ALGOR, 1),
  46. ASN1_IMP_OPT(OSSL_CRMF_ENCRYPTEDVALUE, encSymmKey, ASN1_BIT_STRING, 2),
  47. ASN1_IMP_OPT(OSSL_CRMF_ENCRYPTEDVALUE, keyAlg, X509_ALGOR, 3),
  48. ASN1_IMP_OPT(OSSL_CRMF_ENCRYPTEDVALUE, valueHint, ASN1_OCTET_STRING, 4),
  49. ASN1_SIMPLE(OSSL_CRMF_ENCRYPTEDVALUE, encValue, ASN1_BIT_STRING)
  50. } ASN1_SEQUENCE_END(OSSL_CRMF_ENCRYPTEDVALUE)
  51. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_ENCRYPTEDVALUE)
  52. ASN1_SEQUENCE(OSSL_CRMF_SINGLEPUBINFO) = {
  53. ASN1_SIMPLE(OSSL_CRMF_SINGLEPUBINFO, pubMethod, ASN1_INTEGER),
  54. ASN1_SIMPLE(OSSL_CRMF_SINGLEPUBINFO, pubLocation, GENERAL_NAME)
  55. } ASN1_SEQUENCE_END(OSSL_CRMF_SINGLEPUBINFO)
  56. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_SINGLEPUBINFO)
  57. ASN1_SEQUENCE(OSSL_CRMF_PKIPUBLICATIONINFO) = {
  58. ASN1_SIMPLE(OSSL_CRMF_PKIPUBLICATIONINFO, action, ASN1_INTEGER),
  59. ASN1_SEQUENCE_OF_OPT(OSSL_CRMF_PKIPUBLICATIONINFO, pubInfos,
  60. OSSL_CRMF_SINGLEPUBINFO)
  61. } ASN1_SEQUENCE_END(OSSL_CRMF_PKIPUBLICATIONINFO)
  62. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_PKIPUBLICATIONINFO)
  63. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CRMF_PKIPUBLICATIONINFO)
  64. ASN1_SEQUENCE(OSSL_CRMF_PKMACVALUE) = {
  65. ASN1_SIMPLE(OSSL_CRMF_PKMACVALUE, algId, X509_ALGOR),
  66. ASN1_SIMPLE(OSSL_CRMF_PKMACVALUE, value, ASN1_BIT_STRING)
  67. } ASN1_SEQUENCE_END(OSSL_CRMF_PKMACVALUE)
  68. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_PKMACVALUE)
  69. ASN1_CHOICE(OSSL_CRMF_POPOPRIVKEY) = {
  70. ASN1_IMP(OSSL_CRMF_POPOPRIVKEY, value.thisMessage, ASN1_BIT_STRING, 0),
  71. ASN1_IMP(OSSL_CRMF_POPOPRIVKEY, value.subsequentMessage, ASN1_INTEGER, 1),
  72. ASN1_IMP(OSSL_CRMF_POPOPRIVKEY, value.dhMAC, ASN1_BIT_STRING, 2),
  73. ASN1_IMP(OSSL_CRMF_POPOPRIVKEY, value.agreeMAC, OSSL_CRMF_PKMACVALUE, 3),
  74. ASN1_IMP(OSSL_CRMF_POPOPRIVKEY, value.encryptedKey, ASN1_NULL, 4),
  75. /* When supported, ASN1_NULL needs to be replaced by CMS_ENVELOPEDDATA */
  76. } ASN1_CHOICE_END(OSSL_CRMF_POPOPRIVKEY)
  77. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPOPRIVKEY)
  78. ASN1_SEQUENCE(OSSL_CRMF_PBMPARAMETER) = {
  79. ASN1_SIMPLE(OSSL_CRMF_PBMPARAMETER, salt, ASN1_OCTET_STRING),
  80. ASN1_SIMPLE(OSSL_CRMF_PBMPARAMETER, owf, X509_ALGOR),
  81. ASN1_SIMPLE(OSSL_CRMF_PBMPARAMETER, iterationCount, ASN1_INTEGER),
  82. ASN1_SIMPLE(OSSL_CRMF_PBMPARAMETER, mac, X509_ALGOR)
  83. } ASN1_SEQUENCE_END(OSSL_CRMF_PBMPARAMETER)
  84. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_PBMPARAMETER)
  85. ASN1_CHOICE(OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO) = {
  86. ASN1_EXP(OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO, value.sender,
  87. GENERAL_NAME, 0),
  88. ASN1_SIMPLE(OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO, value.publicKeyMAC,
  89. OSSL_CRMF_PKMACVALUE)
  90. } ASN1_CHOICE_END(OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO)
  91. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO)
  92. ASN1_SEQUENCE(OSSL_CRMF_POPOSIGNINGKEYINPUT) = {
  93. ASN1_SIMPLE(OSSL_CRMF_POPOSIGNINGKEYINPUT, authInfo,
  94. OSSL_CRMF_POPOSIGNINGKEYINPUT_AUTHINFO),
  95. ASN1_SIMPLE(OSSL_CRMF_POPOSIGNINGKEYINPUT, publicKey, X509_PUBKEY)
  96. } ASN1_SEQUENCE_END(OSSL_CRMF_POPOSIGNINGKEYINPUT)
  97. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEYINPUT)
  98. ASN1_SEQUENCE(OSSL_CRMF_POPOSIGNINGKEY) = {
  99. ASN1_IMP_OPT(OSSL_CRMF_POPOSIGNINGKEY, poposkInput,
  100. OSSL_CRMF_POPOSIGNINGKEYINPUT, 0),
  101. ASN1_SIMPLE(OSSL_CRMF_POPOSIGNINGKEY, algorithmIdentifier, X509_ALGOR),
  102. ASN1_SIMPLE(OSSL_CRMF_POPOSIGNINGKEY, signature, ASN1_BIT_STRING)
  103. } ASN1_SEQUENCE_END(OSSL_CRMF_POPOSIGNINGKEY)
  104. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPOSIGNINGKEY)
  105. ASN1_CHOICE(OSSL_CRMF_POPO) = {
  106. ASN1_IMP(OSSL_CRMF_POPO, value.raVerified, ASN1_NULL, 0),
  107. ASN1_IMP(OSSL_CRMF_POPO, value.signature, OSSL_CRMF_POPOSIGNINGKEY, 1),
  108. ASN1_EXP(OSSL_CRMF_POPO, value.keyEncipherment, OSSL_CRMF_POPOPRIVKEY, 2),
  109. ASN1_EXP(OSSL_CRMF_POPO, value.keyAgreement, OSSL_CRMF_POPOPRIVKEY, 3)
  110. } ASN1_CHOICE_END(OSSL_CRMF_POPO)
  111. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_POPO)
  112. ASN1_ADB_TEMPLATE(attributetypeandvalue_default) =
  113. ASN1_OPT(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, value.other, ASN1_ANY);
  114. ASN1_ADB(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) = {
  115. ADB_ENTRY(NID_id_regCtrl_regToken,
  116. ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
  117. value.regToken, ASN1_UTF8STRING)),
  118. ADB_ENTRY(NID_id_regCtrl_authenticator,
  119. ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
  120. value.authenticator, ASN1_UTF8STRING)),
  121. ADB_ENTRY(NID_id_regCtrl_pkiPublicationInfo,
  122. ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
  123. value.pkiPublicationInfo,
  124. OSSL_CRMF_PKIPUBLICATIONINFO)),
  125. ADB_ENTRY(NID_id_regCtrl_oldCertID,
  126. ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
  127. value.oldCertID, OSSL_CRMF_CERTID)),
  128. ADB_ENTRY(NID_id_regCtrl_protocolEncrKey,
  129. ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
  130. value.protocolEncrKey, X509_PUBKEY)),
  131. ADB_ENTRY(NID_id_regInfo_utf8Pairs,
  132. ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
  133. value.utf8Pairs, ASN1_UTF8STRING)),
  134. ADB_ENTRY(NID_id_regInfo_certReq,
  135. ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE,
  136. value.certReq, OSSL_CRMF_CERTREQUEST)),
  137. } ASN1_ADB_END(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, 0, type, 0,
  138. &attributetypeandvalue_default_tt, NULL);
  139. ASN1_SEQUENCE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE) = {
  140. ASN1_SIMPLE(OSSL_CRMF_ATTRIBUTETYPEANDVALUE, type, ASN1_OBJECT),
  141. ASN1_ADB_OBJECT(OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
  142. } ASN1_SEQUENCE_END(OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
  143. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
  144. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
  145. ASN1_SEQUENCE(OSSL_CRMF_OPTIONALVALIDITY) = {
  146. ASN1_EXP_OPT(OSSL_CRMF_OPTIONALVALIDITY, notBefore, ASN1_TIME, 0),
  147. ASN1_EXP_OPT(OSSL_CRMF_OPTIONALVALIDITY, notAfter, ASN1_TIME, 1)
  148. } ASN1_SEQUENCE_END(OSSL_CRMF_OPTIONALVALIDITY)
  149. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_OPTIONALVALIDITY)
  150. ASN1_SEQUENCE(OSSL_CRMF_CERTTEMPLATE) = {
  151. ASN1_IMP_OPT(OSSL_CRMF_CERTTEMPLATE, version, ASN1_INTEGER, 0),
  152. /*
  153. * serialNumber MUST be omitted. This field is assigned by the CA
  154. * during certificate creation.
  155. */
  156. ASN1_IMP_OPT(OSSL_CRMF_CERTTEMPLATE, serialNumber, ASN1_INTEGER, 1),
  157. /*
  158. * signingAlg MUST be omitted. This field is assigned by the CA
  159. * during certificate creation.
  160. */
  161. ASN1_IMP_OPT(OSSL_CRMF_CERTTEMPLATE, signingAlg, X509_ALGOR, 2),
  162. ASN1_EXP_OPT(OSSL_CRMF_CERTTEMPLATE, issuer, X509_NAME, 3),
  163. ASN1_IMP_OPT(OSSL_CRMF_CERTTEMPLATE, validity,
  164. OSSL_CRMF_OPTIONALVALIDITY, 4),
  165. ASN1_EXP_OPT(OSSL_CRMF_CERTTEMPLATE, subject, X509_NAME, 5),
  166. ASN1_IMP_OPT(OSSL_CRMF_CERTTEMPLATE, publicKey, X509_PUBKEY, 6),
  167. /* issuerUID is deprecated in version 2 */
  168. ASN1_IMP_OPT(OSSL_CRMF_CERTTEMPLATE, issuerUID, ASN1_BIT_STRING, 7),
  169. /* subjectUID is deprecated in version 2 */
  170. ASN1_IMP_OPT(OSSL_CRMF_CERTTEMPLATE, subjectUID, ASN1_BIT_STRING, 8),
  171. ASN1_IMP_SEQUENCE_OF_OPT(OSSL_CRMF_CERTTEMPLATE, extensions,
  172. X509_EXTENSION, 9),
  173. } ASN1_SEQUENCE_END(OSSL_CRMF_CERTTEMPLATE)
  174. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_CERTTEMPLATE)
  175. ASN1_SEQUENCE(OSSL_CRMF_CERTREQUEST) = {
  176. ASN1_SIMPLE(OSSL_CRMF_CERTREQUEST, certReqId, ASN1_INTEGER),
  177. ASN1_SIMPLE(OSSL_CRMF_CERTREQUEST, certTemplate, OSSL_CRMF_CERTTEMPLATE),
  178. ASN1_SEQUENCE_OF_OPT(OSSL_CRMF_CERTREQUEST, controls,
  179. OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
  180. } ASN1_SEQUENCE_END(OSSL_CRMF_CERTREQUEST)
  181. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_CERTREQUEST)
  182. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CRMF_CERTREQUEST)
  183. ASN1_SEQUENCE(OSSL_CRMF_MSG) = {
  184. ASN1_SIMPLE(OSSL_CRMF_MSG, certReq, OSSL_CRMF_CERTREQUEST),
  185. ASN1_OPT(OSSL_CRMF_MSG, popo, OSSL_CRMF_POPO),
  186. ASN1_SEQUENCE_OF_OPT(OSSL_CRMF_MSG, regInfo,
  187. OSSL_CRMF_ATTRIBUTETYPEANDVALUE)
  188. } ASN1_SEQUENCE_END(OSSL_CRMF_MSG)
  189. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_MSG)
  190. IMPLEMENT_ASN1_DUP_FUNCTION(OSSL_CRMF_MSG)
  191. ASN1_ITEM_TEMPLATE(OSSL_CRMF_MSGS) =
  192. ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
  193. OSSL_CRMF_MSGS, OSSL_CRMF_MSG)
  194. ASN1_ITEM_TEMPLATE_END(OSSL_CRMF_MSGS)
  195. IMPLEMENT_ASN1_FUNCTIONS(OSSL_CRMF_MSGS)