Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rfc7191.py 6.9KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. # This file is being contributed to of pyasn1-modules software.
  2. #
  3. # Created by Russ Housley without assistance from the asn1ate tool.
  4. # Modified by Russ Housley to add support for opentypes.
  5. #
  6. # Copyright (c) 2019, Vigil Security, LLC
  7. # License: http://snmplabs.com/pyasn1/license.html
  8. #
  9. # CMS Key Package Receipt and Error Content Types
  10. #
  11. # ASN.1 source from:
  12. # https://www.rfc-editor.org/rfc/rfc7191.txt
  13. from pyasn1.type import constraint
  14. from pyasn1.type import namedtype
  15. from pyasn1.type import namedval
  16. from pyasn1.type import opentype
  17. from pyasn1.type import tag
  18. from pyasn1.type import univ
  19. from pyasn1_modules import rfc5280
  20. from pyasn1_modules import rfc5652
  21. MAX = float('inf')
  22. DistinguishedName = rfc5280.DistinguishedName
  23. # SingleAttribute is the same as Attribute in RFC 5652, except that the
  24. # attrValues SET must have one and only one member
  25. class AttributeValue(univ.Any):
  26. pass
  27. class AttributeValues(univ.SetOf):
  28. pass
  29. AttributeValues.componentType = AttributeValue()
  30. AttributeValues.sizeSpec = univ.Set.sizeSpec + constraint.ValueSizeConstraint(1, 1)
  31. class SingleAttribute(univ.Sequence):
  32. pass
  33. SingleAttribute.componentType = namedtype.NamedTypes(
  34. namedtype.NamedType('attrType', univ.ObjectIdentifier()),
  35. namedtype.NamedType('attrValues', AttributeValues(),
  36. openType=opentype.OpenType('attrType', rfc5652.cmsAttributesMap)
  37. )
  38. )
  39. # SIR Entity Name
  40. class SIREntityNameType(univ.ObjectIdentifier):
  41. pass
  42. class SIREntityNameValue(univ.Any):
  43. pass
  44. class SIREntityName(univ.Sequence):
  45. pass
  46. SIREntityName.componentType = namedtype.NamedTypes(
  47. namedtype.NamedType('sirenType', SIREntityNameType()),
  48. namedtype.NamedType('sirenValue', univ.OctetString())
  49. # CONTAINING the DER-encoded SIREntityNameValue
  50. )
  51. class SIREntityNames(univ.SequenceOf):
  52. pass
  53. SIREntityNames.componentType = SIREntityName()
  54. SIREntityNames.sizeSpec=constraint.ValueSizeConstraint(1, MAX)
  55. id_dn = univ.ObjectIdentifier('2.16.840.1.101.2.1.16.0')
  56. class siren_dn(SIREntityName):
  57. def __init__(self):
  58. SIREntityName.__init__(self)
  59. self['sirenType'] = id_dn
  60. # Key Package Error CMS Content Type
  61. class EnumeratedErrorCode(univ.Enumerated):
  62. pass
  63. # Error codes with values <= 33 are aligned with RFC 5934
  64. EnumeratedErrorCode.namedValues = namedval.NamedValues(
  65. ('decodeFailure', 1),
  66. ('badContentInfo', 2),
  67. ('badSignedData', 3),
  68. ('badEncapContent', 4),
  69. ('badCertificate', 5),
  70. ('badSignerInfo', 6),
  71. ('badSignedAttrs', 7),
  72. ('badUnsignedAttrs', 8),
  73. ('missingContent', 9),
  74. ('noTrustAnchor', 10),
  75. ('notAuthorized', 11),
  76. ('badDigestAlgorithm', 12),
  77. ('badSignatureAlgorithm', 13),
  78. ('unsupportedKeySize', 14),
  79. ('unsupportedParameters', 15),
  80. ('signatureFailure', 16),
  81. ('insufficientMemory', 17),
  82. ('incorrectTarget', 23),
  83. ('missingSignature', 29),
  84. ('resourcesBusy', 30),
  85. ('versionNumberMismatch', 31),
  86. ('revokedCertificate', 33),
  87. ('ambiguousDecrypt', 60),
  88. ('noDecryptKey', 61),
  89. ('badEncryptedData', 62),
  90. ('badEnvelopedData', 63),
  91. ('badAuthenticatedData', 64),
  92. ('badAuthEnvelopedData', 65),
  93. ('badKeyAgreeRecipientInfo', 66),
  94. ('badKEKRecipientInfo', 67),
  95. ('badEncryptContent', 68),
  96. ('badEncryptAlgorithm', 69),
  97. ('missingCiphertext', 70),
  98. ('decryptFailure', 71),
  99. ('badMACAlgorithm', 72),
  100. ('badAuthAttrs', 73),
  101. ('badUnauthAttrs', 74),
  102. ('invalidMAC', 75),
  103. ('mismatchedDigestAlg', 76),
  104. ('missingCertificate', 77),
  105. ('tooManySigners', 78),
  106. ('missingSignedAttributes', 79),
  107. ('derEncodingNotUsed', 80),
  108. ('missingContentHints', 81),
  109. ('invalidAttributeLocation', 82),
  110. ('badMessageDigest', 83),
  111. ('badKeyPackage', 84),
  112. ('badAttributes', 85),
  113. ('attributeComparisonFailure', 86),
  114. ('unsupportedSymmetricKeyPackage', 87),
  115. ('unsupportedAsymmetricKeyPackage', 88),
  116. ('constraintViolation', 89),
  117. ('ambiguousDefaultValue', 90),
  118. ('noMatchingRecipientInfo', 91),
  119. ('unsupportedKeyWrapAlgorithm', 92),
  120. ('badKeyTransRecipientInfo', 93),
  121. ('other', 127)
  122. )
  123. class ErrorCodeChoice(univ.Choice):
  124. pass
  125. ErrorCodeChoice.componentType = namedtype.NamedTypes(
  126. namedtype.NamedType('enum', EnumeratedErrorCode()),
  127. namedtype.NamedType('oid', univ.ObjectIdentifier())
  128. )
  129. class KeyPkgID(univ.OctetString):
  130. pass
  131. class KeyPkgIdentifier(univ.Choice):
  132. pass
  133. KeyPkgIdentifier.componentType = namedtype.NamedTypes(
  134. namedtype.NamedType('pkgID', KeyPkgID()),
  135. namedtype.NamedType('attribute', SingleAttribute())
  136. )
  137. class KeyPkgVersion(univ.Integer):
  138. pass
  139. KeyPkgVersion.namedValues = namedval.NamedValues(
  140. ('v1', 1),
  141. ('v2', 2)
  142. )
  143. KeyPkgVersion.subtypeSpec = constraint.ValueRangeConstraint(1, 65535)
  144. id_ct_KP_keyPackageError = univ.ObjectIdentifier('2.16.840.1.101.2.1.2.78.6')
  145. class KeyPackageError(univ.Sequence):
  146. pass
  147. KeyPackageError.componentType = namedtype.NamedTypes(
  148. namedtype.DefaultedNamedType('version', KeyPkgVersion().subtype(value='v2')),
  149. namedtype.OptionalNamedType('errorOf', KeyPkgIdentifier().subtype(
  150. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
  151. namedtype.NamedType('errorBy', SIREntityName()),
  152. namedtype.NamedType('errorCode', ErrorCodeChoice())
  153. )
  154. # Key Package Receipt CMS Content Type
  155. id_ct_KP_keyPackageReceipt = univ.ObjectIdentifier('2.16.840.1.101.2.1.2.78.3')
  156. class KeyPackageReceipt(univ.Sequence):
  157. pass
  158. KeyPackageReceipt.componentType = namedtype.NamedTypes(
  159. namedtype.DefaultedNamedType('version', KeyPkgVersion().subtype(value='v2')),
  160. namedtype.NamedType('receiptOf', KeyPkgIdentifier()),
  161. namedtype.NamedType('receivedBy', SIREntityName())
  162. )
  163. # Key Package Receipt Request Attribute
  164. class KeyPkgReceiptReq(univ.Sequence):
  165. pass
  166. KeyPkgReceiptReq.componentType = namedtype.NamedTypes(
  167. namedtype.DefaultedNamedType('encryptReceipt', univ.Boolean().subtype(value=0)),
  168. namedtype.OptionalNamedType('receiptsFrom', SIREntityNames().subtype(
  169. implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
  170. namedtype.NamedType('receiptsTo', SIREntityNames())
  171. )
  172. id_aa_KP_keyPkgIdAndReceiptReq = univ.ObjectIdentifier('2.16.840.1.101.2.1.5.65')
  173. class KeyPkgIdentifierAndReceiptReq(univ.Sequence):
  174. pass
  175. KeyPkgIdentifierAndReceiptReq.componentType = namedtype.NamedTypes(
  176. namedtype.NamedType('pkgID', KeyPkgID()),
  177. namedtype.OptionalNamedType('receiptReq', KeyPkgReceiptReq())
  178. )
  179. # Map of Attribute Type OIDs to Attributes are added to
  180. # the ones that are in rfc5652.py
  181. _cmsAttributesMapUpdate = {
  182. id_aa_KP_keyPkgIdAndReceiptReq: KeyPkgIdentifierAndReceiptReq(),
  183. }
  184. rfc5652.cmsAttributesMap.update(_cmsAttributesMapUpdate)
  185. # Map of CMC Content Type OIDs to CMC Content Types are added to
  186. # the ones that are in rfc5652.py
  187. _cmsContentTypesMapUpdate = {
  188. id_ct_KP_keyPackageError: KeyPackageError(),
  189. id_ct_KP_keyPackageReceipt: KeyPackageReceipt(),
  190. }
  191. rfc5652.cmsContentTypesMap.update(_cmsContentTypesMapUpdate)