rfc3852.py 20 KB

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