rfc5652.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. # coding: utf-8
  2. #
  3. # This file is part of pyasn1-modules software.
  4. #
  5. # Created by Stanisław Pitucha with asn1ate tool.
  6. # Modified by Russ Housley to add support for opentypes.
  7. #
  8. # Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
  9. # License: http://snmplabs.com/pyasn1/license.html
  10. #
  11. # Cryptographic Message Syntax (CMS)
  12. #
  13. # ASN.1 source from:
  14. # http://www.ietf.org/rfc/rfc5652.txt
  15. #
  16. from pyasn1.type import constraint
  17. from pyasn1.type import namedtype
  18. from pyasn1.type import namedval
  19. from pyasn1.type import opentype
  20. from pyasn1.type import tag
  21. from pyasn1.type import univ
  22. from pyasn1.type import useful
  23. from pyasn1_modules import rfc3281
  24. from pyasn1_modules import rfc5280
  25. MAX = float('inf')
  26. def _buildOid(*components):
  27. output = []
  28. for x in tuple(components):
  29. if isinstance(x, univ.ObjectIdentifier):
  30. output.extend(list(x))
  31. else:
  32. output.append(int(x))
  33. return univ.ObjectIdentifier(output)
  34. cmsContentTypesMap = { }
  35. cmsAttributesMap = { }
  36. otherKeyAttributesMap = { }
  37. otherCertFormatMap = { }
  38. otherRevInfoFormatMap = { }
  39. otherRecipientInfoMap = { }
  40. class AttCertVersionV1(univ.Integer):
  41. pass
  42. AttCertVersionV1.namedValues = namedval.NamedValues(
  43. ('v1', 0)
  44. )
  45. class AttributeCertificateInfoV1(univ.Sequence):
  46. pass
  47. AttributeCertificateInfoV1.componentType = namedtype.NamedTypes(
  48. namedtype.DefaultedNamedType('version', AttCertVersionV1().subtype(value="v1")),
  49. namedtype.NamedType(
  50. 'subject', univ.Choice(
  51. componentType=namedtype.NamedTypes(
  52. namedtype.NamedType('baseCertificateID', rfc3281.IssuerSerial().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  53. namedtype.NamedType('subjectName', rfc5280.GeneralNames().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
  54. )
  55. )
  56. ),
  57. namedtype.NamedType('issuer', rfc5280.GeneralNames()),
  58. namedtype.NamedType('signature', rfc5280.AlgorithmIdentifier()),
  59. namedtype.NamedType('serialNumber', rfc5280.CertificateSerialNumber()),
  60. namedtype.NamedType('attCertValidityPeriod', rfc3281.AttCertValidityPeriod()),
  61. namedtype.NamedType('attributes', univ.SequenceOf(componentType=rfc5280.Attribute())),
  62. namedtype.OptionalNamedType('issuerUniqueID', rfc5280.UniqueIdentifier()),
  63. namedtype.OptionalNamedType('extensions', rfc5280.Extensions())
  64. )
  65. class AttributeCertificateV1(univ.Sequence):
  66. pass
  67. AttributeCertificateV1.componentType = namedtype.NamedTypes(
  68. namedtype.NamedType('acInfo', AttributeCertificateInfoV1()),
  69. namedtype.NamedType('signatureAlgorithm', rfc5280.AlgorithmIdentifier()),
  70. namedtype.NamedType('signature', univ.BitString())
  71. )
  72. class AttributeValue(univ.Any):
  73. pass
  74. class Attribute(univ.Sequence):
  75. pass
  76. Attribute.componentType = namedtype.NamedTypes(
  77. namedtype.NamedType('attrType', univ.ObjectIdentifier()),
  78. namedtype.NamedType('attrValues', univ.SetOf(componentType=AttributeValue()),
  79. openType=opentype.OpenType('attrType', cmsAttributesMap)
  80. )
  81. )
  82. class SignedAttributes(univ.SetOf):
  83. pass
  84. SignedAttributes.componentType = Attribute()
  85. SignedAttributes.sizeSpec = constraint.ValueSizeConstraint(1, MAX)
  86. class AttributeCertificateV2(rfc3281.AttributeCertificate):
  87. pass
  88. class OtherKeyAttribute(univ.Sequence):
  89. pass
  90. OtherKeyAttribute.componentType = namedtype.NamedTypes(
  91. namedtype.NamedType('keyAttrId', univ.ObjectIdentifier()),
  92. namedtype.OptionalNamedType('keyAttr', univ.Any(),
  93. openType=opentype.OpenType('keyAttrId', otherKeyAttributesMap)
  94. )
  95. )
  96. class UnauthAttributes(univ.SetOf):
  97. pass
  98. UnauthAttributes.componentType = Attribute()
  99. UnauthAttributes.sizeSpec = constraint.ValueSizeConstraint(1, MAX)
  100. id_encryptedData = _buildOid(1, 2, 840, 113549, 1, 7, 6)
  101. class SignatureValue(univ.OctetString):
  102. pass
  103. class IssuerAndSerialNumber(univ.Sequence):
  104. pass
  105. IssuerAndSerialNumber.componentType = namedtype.NamedTypes(
  106. namedtype.NamedType('issuer', rfc5280.Name()),
  107. namedtype.NamedType('serialNumber', rfc5280.CertificateSerialNumber())
  108. )
  109. class SubjectKeyIdentifier(univ.OctetString):
  110. pass
  111. class RecipientKeyIdentifier(univ.Sequence):
  112. pass
  113. RecipientKeyIdentifier.componentType = namedtype.NamedTypes(
  114. namedtype.NamedType('subjectKeyIdentifier', SubjectKeyIdentifier()),
  115. namedtype.OptionalNamedType('date', useful.GeneralizedTime()),
  116. namedtype.OptionalNamedType('other', OtherKeyAttribute())
  117. )
  118. class KeyAgreeRecipientIdentifier(univ.Choice):
  119. pass
  120. KeyAgreeRecipientIdentifier.componentType = namedtype.NamedTypes(
  121. namedtype.NamedType('issuerAndSerialNumber', IssuerAndSerialNumber()),
  122. namedtype.NamedType('rKeyId', RecipientKeyIdentifier().subtype(
  123. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)))
  124. )
  125. class EncryptedKey(univ.OctetString):
  126. pass
  127. class RecipientEncryptedKey(univ.Sequence):
  128. pass
  129. RecipientEncryptedKey.componentType = namedtype.NamedTypes(
  130. namedtype.NamedType('rid', KeyAgreeRecipientIdentifier()),
  131. namedtype.NamedType('encryptedKey', EncryptedKey())
  132. )
  133. class RecipientEncryptedKeys(univ.SequenceOf):
  134. pass
  135. RecipientEncryptedKeys.componentType = RecipientEncryptedKey()
  136. class MessageAuthenticationCode(univ.OctetString):
  137. pass
  138. class CMSVersion(univ.Integer):
  139. pass
  140. CMSVersion.namedValues = namedval.NamedValues(
  141. ('v0', 0),
  142. ('v1', 1),
  143. ('v2', 2),
  144. ('v3', 3),
  145. ('v4', 4),
  146. ('v5', 5)
  147. )
  148. class OtherCertificateFormat(univ.Sequence):
  149. pass
  150. OtherCertificateFormat.componentType = namedtype.NamedTypes(
  151. namedtype.NamedType('otherCertFormat', univ.ObjectIdentifier()),
  152. namedtype.NamedType('otherCert', univ.Any(),
  153. openType=opentype.OpenType('otherCertFormat', otherCertFormatMap)
  154. )
  155. )
  156. class ExtendedCertificateInfo(univ.Sequence):
  157. pass
  158. ExtendedCertificateInfo.componentType = namedtype.NamedTypes(
  159. namedtype.NamedType('version', CMSVersion()),
  160. namedtype.NamedType('certificate', rfc5280.Certificate()),
  161. namedtype.NamedType('attributes', UnauthAttributes())
  162. )
  163. class Signature(univ.BitString):
  164. pass
  165. class SignatureAlgorithmIdentifier(rfc5280.AlgorithmIdentifier):
  166. pass
  167. class ExtendedCertificate(univ.Sequence):
  168. pass
  169. ExtendedCertificate.componentType = namedtype.NamedTypes(
  170. namedtype.NamedType('extendedCertificateInfo', ExtendedCertificateInfo()),
  171. namedtype.NamedType('signatureAlgorithm', SignatureAlgorithmIdentifier()),
  172. namedtype.NamedType('signature', Signature())
  173. )
  174. class CertificateChoices(univ.Choice):
  175. pass
  176. CertificateChoices.componentType = namedtype.NamedTypes(
  177. namedtype.NamedType('certificate', rfc5280.Certificate()),
  178. namedtype.NamedType('extendedCertificate', ExtendedCertificate().subtype(
  179. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  180. namedtype.NamedType('v1AttrCert', AttributeCertificateV1().subtype(
  181. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  182. namedtype.NamedType('v2AttrCert', AttributeCertificateV2().subtype(
  183. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  184. namedtype.NamedType('other', OtherCertificateFormat().subtype(
  185. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)))
  186. )
  187. class CertificateSet(univ.SetOf):
  188. pass
  189. CertificateSet.componentType = CertificateChoices()
  190. class OtherRevocationInfoFormat(univ.Sequence):
  191. pass
  192. OtherRevocationInfoFormat.componentType = namedtype.NamedTypes(
  193. namedtype.NamedType('otherRevInfoFormat', univ.ObjectIdentifier()),
  194. namedtype.NamedType('otherRevInfo', univ.Any(),
  195. openType=opentype.OpenType('otherRevInfoFormat', otherRevInfoFormatMap)
  196. )
  197. )
  198. class RevocationInfoChoice(univ.Choice):
  199. pass
  200. RevocationInfoChoice.componentType = namedtype.NamedTypes(
  201. namedtype.NamedType('crl', rfc5280.CertificateList()),
  202. namedtype.NamedType('other', OtherRevocationInfoFormat().subtype(
  203. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
  204. )
  205. class RevocationInfoChoices(univ.SetOf):
  206. pass
  207. RevocationInfoChoices.componentType = RevocationInfoChoice()
  208. class OriginatorInfo(univ.Sequence):
  209. pass
  210. OriginatorInfo.componentType = namedtype.NamedTypes(
  211. namedtype.OptionalNamedType('certs', CertificateSet().subtype(
  212. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  213. namedtype.OptionalNamedType('crls', RevocationInfoChoices().subtype(
  214. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
  215. )
  216. class ContentType(univ.ObjectIdentifier):
  217. pass
  218. class EncryptedContent(univ.OctetString):
  219. pass
  220. class ContentEncryptionAlgorithmIdentifier(rfc5280.AlgorithmIdentifier):
  221. pass
  222. class EncryptedContentInfo(univ.Sequence):
  223. pass
  224. EncryptedContentInfo.componentType = namedtype.NamedTypes(
  225. namedtype.NamedType('contentType', ContentType()),
  226. namedtype.NamedType('contentEncryptionAlgorithm', ContentEncryptionAlgorithmIdentifier()),
  227. namedtype.OptionalNamedType('encryptedContent', EncryptedContent().subtype(
  228. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
  229. )
  230. class UnprotectedAttributes(univ.SetOf):
  231. pass
  232. UnprotectedAttributes.componentType = Attribute()
  233. UnprotectedAttributes.sizeSpec = constraint.ValueSizeConstraint(1, MAX)
  234. class KeyEncryptionAlgorithmIdentifier(rfc5280.AlgorithmIdentifier):
  235. pass
  236. class KEKIdentifier(univ.Sequence):
  237. pass
  238. KEKIdentifier.componentType = namedtype.NamedTypes(
  239. namedtype.NamedType('keyIdentifier', univ.OctetString()),
  240. namedtype.OptionalNamedType('date', useful.GeneralizedTime()),
  241. namedtype.OptionalNamedType('other', OtherKeyAttribute())
  242. )
  243. class KEKRecipientInfo(univ.Sequence):
  244. pass
  245. KEKRecipientInfo.componentType = namedtype.NamedTypes(
  246. namedtype.NamedType('version', CMSVersion()),
  247. namedtype.NamedType('kekid', KEKIdentifier()),
  248. namedtype.NamedType('keyEncryptionAlgorithm', KeyEncryptionAlgorithmIdentifier()),
  249. namedtype.NamedType('encryptedKey', EncryptedKey())
  250. )
  251. class KeyDerivationAlgorithmIdentifier(rfc5280.AlgorithmIdentifier):
  252. pass
  253. class PasswordRecipientInfo(univ.Sequence):
  254. pass
  255. PasswordRecipientInfo.componentType = namedtype.NamedTypes(
  256. namedtype.NamedType('version', CMSVersion()),
  257. namedtype.OptionalNamedType('keyDerivationAlgorithm', KeyDerivationAlgorithmIdentifier().subtype(
  258. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  259. namedtype.NamedType('keyEncryptionAlgorithm', KeyEncryptionAlgorithmIdentifier()),
  260. namedtype.NamedType('encryptedKey', EncryptedKey())
  261. )
  262. class RecipientIdentifier(univ.Choice):
  263. pass
  264. RecipientIdentifier.componentType = namedtype.NamedTypes(
  265. namedtype.NamedType('issuerAndSerialNumber', IssuerAndSerialNumber()),
  266. namedtype.NamedType('subjectKeyIdentifier', SubjectKeyIdentifier().subtype(
  267. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
  268. )
  269. class KeyTransRecipientInfo(univ.Sequence):
  270. pass
  271. KeyTransRecipientInfo.componentType = namedtype.NamedTypes(
  272. namedtype.NamedType('version', CMSVersion()),
  273. namedtype.NamedType('rid', RecipientIdentifier()),
  274. namedtype.NamedType('keyEncryptionAlgorithm', KeyEncryptionAlgorithmIdentifier()),
  275. namedtype.NamedType('encryptedKey', EncryptedKey())
  276. )
  277. class UserKeyingMaterial(univ.OctetString):
  278. pass
  279. class OriginatorPublicKey(univ.Sequence):
  280. pass
  281. OriginatorPublicKey.componentType = namedtype.NamedTypes(
  282. namedtype.NamedType('algorithm', rfc5280.AlgorithmIdentifier()),
  283. namedtype.NamedType('publicKey', univ.BitString())
  284. )
  285. class OriginatorIdentifierOrKey(univ.Choice):
  286. pass
  287. OriginatorIdentifierOrKey.componentType = namedtype.NamedTypes(
  288. namedtype.NamedType('issuerAndSerialNumber', IssuerAndSerialNumber()),
  289. namedtype.NamedType('subjectKeyIdentifier', SubjectKeyIdentifier().subtype(
  290. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  291. namedtype.NamedType('originatorKey', OriginatorPublicKey().subtype(
  292. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)))
  293. )
  294. class KeyAgreeRecipientInfo(univ.Sequence):
  295. pass
  296. KeyAgreeRecipientInfo.componentType = namedtype.NamedTypes(
  297. namedtype.NamedType('version', CMSVersion()),
  298. namedtype.NamedType('originator', OriginatorIdentifierOrKey().subtype(
  299. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  300. namedtype.OptionalNamedType('ukm', UserKeyingMaterial().subtype(
  301. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  302. namedtype.NamedType('keyEncryptionAlgorithm', KeyEncryptionAlgorithmIdentifier()),
  303. namedtype.NamedType('recipientEncryptedKeys', RecipientEncryptedKeys())
  304. )
  305. class OtherRecipientInfo(univ.Sequence):
  306. pass
  307. OtherRecipientInfo.componentType = namedtype.NamedTypes(
  308. namedtype.NamedType('oriType', univ.ObjectIdentifier()),
  309. namedtype.NamedType('oriValue', univ.Any(),
  310. openType=opentype.OpenType('oriType', otherRecipientInfoMap)
  311. )
  312. )
  313. class RecipientInfo(univ.Choice):
  314. pass
  315. RecipientInfo.componentType = namedtype.NamedTypes(
  316. namedtype.NamedType('ktri', KeyTransRecipientInfo()),
  317. namedtype.NamedType('kari', KeyAgreeRecipientInfo().subtype(
  318. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))),
  319. namedtype.NamedType('kekri', KEKRecipientInfo().subtype(
  320. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2))),
  321. namedtype.NamedType('pwri', PasswordRecipientInfo().subtype(
  322. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3))),
  323. namedtype.NamedType('ori', OtherRecipientInfo().subtype(
  324. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 4)))
  325. )
  326. class RecipientInfos(univ.SetOf):
  327. pass
  328. RecipientInfos.componentType = RecipientInfo()
  329. RecipientInfos.sizeSpec = constraint.ValueSizeConstraint(1, MAX)
  330. class EnvelopedData(univ.Sequence):
  331. pass
  332. EnvelopedData.componentType = namedtype.NamedTypes(
  333. namedtype.NamedType('version', CMSVersion()),
  334. namedtype.OptionalNamedType('originatorInfo', OriginatorInfo().subtype(
  335. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  336. namedtype.NamedType('recipientInfos', RecipientInfos()),
  337. namedtype.NamedType('encryptedContentInfo', EncryptedContentInfo()),
  338. namedtype.OptionalNamedType('unprotectedAttrs', UnprotectedAttributes().subtype(
  339. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
  340. )
  341. class DigestAlgorithmIdentifier(rfc5280.AlgorithmIdentifier):
  342. pass
  343. id_ct_contentInfo = _buildOid(1, 2, 840, 113549, 1, 9, 16, 1, 6)
  344. id_digestedData = _buildOid(1, 2, 840, 113549, 1, 7, 5)
  345. class EncryptedData(univ.Sequence):
  346. pass
  347. EncryptedData.componentType = namedtype.NamedTypes(
  348. namedtype.NamedType('version', CMSVersion()),
  349. namedtype.NamedType('encryptedContentInfo', EncryptedContentInfo()),
  350. namedtype.OptionalNamedType('unprotectedAttrs', UnprotectedAttributes().subtype(
  351. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
  352. )
  353. id_messageDigest = _buildOid(1, 2, 840, 113549, 1, 9, 4)
  354. id_signedData = _buildOid(1, 2, 840, 113549, 1, 7, 2)
  355. class MessageAuthenticationCodeAlgorithm(rfc5280.AlgorithmIdentifier):
  356. pass
  357. class UnsignedAttributes(univ.SetOf):
  358. pass
  359. UnsignedAttributes.componentType = Attribute()
  360. UnsignedAttributes.sizeSpec = constraint.ValueSizeConstraint(1, MAX)
  361. class SignerIdentifier(univ.Choice):
  362. pass
  363. SignerIdentifier.componentType = namedtype.NamedTypes(
  364. namedtype.NamedType('issuerAndSerialNumber', IssuerAndSerialNumber()),
  365. namedtype.NamedType('subjectKeyIdentifier', SubjectKeyIdentifier().subtype(
  366. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
  367. )
  368. class SignerInfo(univ.Sequence):
  369. pass
  370. SignerInfo.componentType = namedtype.NamedTypes(
  371. namedtype.NamedType('version', CMSVersion()),
  372. namedtype.NamedType('sid', SignerIdentifier()),
  373. namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()),
  374. namedtype.OptionalNamedType('signedAttrs', SignedAttributes().subtype(
  375. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  376. namedtype.NamedType('signatureAlgorithm', SignatureAlgorithmIdentifier()),
  377. namedtype.NamedType('signature', SignatureValue()),
  378. namedtype.OptionalNamedType('unsignedAttrs', UnsignedAttributes().subtype(
  379. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
  380. )
  381. class SignerInfos(univ.SetOf):
  382. pass
  383. SignerInfos.componentType = SignerInfo()
  384. class Countersignature(SignerInfo):
  385. pass
  386. class ContentInfo(univ.Sequence):
  387. pass
  388. ContentInfo.componentType = namedtype.NamedTypes(
  389. namedtype.NamedType('contentType', ContentType()),
  390. namedtype.NamedType('content', univ.Any().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)),
  391. openType=opentype.OpenType('contentType', cmsContentTypesMap)
  392. )
  393. )
  394. class EncapsulatedContentInfo(univ.Sequence):
  395. pass
  396. EncapsulatedContentInfo.componentType = namedtype.NamedTypes(
  397. namedtype.NamedType('eContentType', ContentType()),
  398. namedtype.OptionalNamedType('eContent', univ.OctetString().subtype(
  399. explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
  400. )
  401. id_countersignature = _buildOid(1, 2, 840, 113549, 1, 9, 6)
  402. id_data = _buildOid(1, 2, 840, 113549, 1, 7, 1)
  403. class MessageDigest(univ.OctetString):
  404. pass
  405. class AuthAttributes(univ.SetOf):
  406. pass
  407. AuthAttributes.componentType = Attribute()
  408. AuthAttributes.sizeSpec = constraint.ValueSizeConstraint(1, MAX)
  409. class Time(univ.Choice):
  410. pass
  411. Time.componentType = namedtype.NamedTypes(
  412. namedtype.NamedType('utcTime', useful.UTCTime()),
  413. namedtype.NamedType('generalTime', useful.GeneralizedTime())
  414. )
  415. class AuthenticatedData(univ.Sequence):
  416. pass
  417. AuthenticatedData.componentType = namedtype.NamedTypes(
  418. namedtype.NamedType('version', CMSVersion()),
  419. namedtype.OptionalNamedType('originatorInfo', OriginatorInfo().subtype(
  420. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  421. namedtype.NamedType('recipientInfos', RecipientInfos()),
  422. namedtype.NamedType('macAlgorithm', MessageAuthenticationCodeAlgorithm()),
  423. namedtype.OptionalNamedType('digestAlgorithm', DigestAlgorithmIdentifier().subtype(
  424. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  425. namedtype.NamedType('encapContentInfo', EncapsulatedContentInfo()),
  426. namedtype.OptionalNamedType('authAttrs', AuthAttributes().subtype(
  427. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))),
  428. namedtype.NamedType('mac', MessageAuthenticationCode()),
  429. namedtype.OptionalNamedType('unauthAttrs', UnauthAttributes().subtype(
  430. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3)))
  431. )
  432. id_contentType = _buildOid(1, 2, 840, 113549, 1, 9, 3)
  433. class ExtendedCertificateOrCertificate(univ.Choice):
  434. pass
  435. ExtendedCertificateOrCertificate.componentType = namedtype.NamedTypes(
  436. namedtype.NamedType('certificate', rfc5280.Certificate()),
  437. namedtype.NamedType('extendedCertificate', ExtendedCertificate().subtype(
  438. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)))
  439. )
  440. class Digest(univ.OctetString):
  441. pass
  442. class DigestedData(univ.Sequence):
  443. pass
  444. DigestedData.componentType = namedtype.NamedTypes(
  445. namedtype.NamedType('version', CMSVersion()),
  446. namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()),
  447. namedtype.NamedType('encapContentInfo', EncapsulatedContentInfo()),
  448. namedtype.NamedType('digest', Digest())
  449. )
  450. id_envelopedData = _buildOid(1, 2, 840, 113549, 1, 7, 3)
  451. class DigestAlgorithmIdentifiers(univ.SetOf):
  452. pass
  453. DigestAlgorithmIdentifiers.componentType = DigestAlgorithmIdentifier()
  454. class SignedData(univ.Sequence):
  455. pass
  456. SignedData.componentType = namedtype.NamedTypes(
  457. namedtype.NamedType('version', CMSVersion()),
  458. namedtype.NamedType('digestAlgorithms', DigestAlgorithmIdentifiers()),
  459. namedtype.NamedType('encapContentInfo', EncapsulatedContentInfo()),
  460. namedtype.OptionalNamedType('certificates', CertificateSet().subtype(
  461. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  462. namedtype.OptionalNamedType('crls', RevocationInfoChoices().subtype(
  463. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
  464. namedtype.NamedType('signerInfos', SignerInfos())
  465. )
  466. id_signingTime = _buildOid(1, 2, 840, 113549, 1, 9, 5)
  467. class SigningTime(Time):
  468. pass
  469. id_ct_authData = _buildOid(1, 2, 840, 113549, 1, 9, 16, 1, 2)
  470. # CMS Content Type Map
  471. _cmsContentTypesMapUpdate = {
  472. id_ct_contentInfo: ContentInfo(),
  473. id_data: univ.OctetString(),
  474. id_signedData: SignedData(),
  475. id_envelopedData: EnvelopedData(),
  476. id_digestedData: DigestedData(),
  477. id_encryptedData: EncryptedData(),
  478. id_ct_authData: AuthenticatedData(),
  479. }
  480. cmsContentTypesMap.update(_cmsContentTypesMapUpdate)
  481. # CMS Attribute Map
  482. _cmsAttributesMapUpdate = {
  483. id_contentType: ContentType(),
  484. id_messageDigest: MessageDigest(),
  485. id_signingTime: SigningTime(),
  486. id_countersignature: Countersignature(),
  487. }
  488. cmsAttributesMap.update(_cmsAttributesMapUpdate)