OLD | NEW |
(Empty) | |
| 1 # |
| 2 # PKCS#7 message syntax |
| 3 # |
| 4 # ASN.1 source from: |
| 5 # http://www.trl.ibm.com/projects/xml/xss4j/data/asn1/grammars/pkcs7.asn |
| 6 # |
| 7 # Sample captures from: |
| 8 # openssl crl2pkcs7 -nocrl -certfile cert1.cer -out outfile.p7b |
| 9 # |
| 10 from pyasn1.type import tag,namedtype,namedval,univ,constraint,char,useful |
| 11 from pyasn1_modules.rfc2459 import * |
| 12 |
| 13 class Attribute(univ.Sequence): |
| 14 componentType = namedtype.NamedTypes( |
| 15 namedtype.NamedType('type', AttributeType()), |
| 16 namedtype.NamedType('values', univ.SetOf(componentType=AttributeValue())
) |
| 17 ) |
| 18 |
| 19 class AttributeValueAssertion(univ.Sequence): |
| 20 componentType = namedtype.NamedTypes( |
| 21 namedtype.NamedType('attributeType', AttributeType()), |
| 22 namedtype.NamedType('attributeValue', AttributeValue()) |
| 23 ) |
| 24 |
| 25 pkcs_7 = univ.ObjectIdentifier('1.2.840.113549.1.7') |
| 26 data = univ.ObjectIdentifier('1.2.840.113549.1.7.1') |
| 27 signedData = univ.ObjectIdentifier('1.2.840.113549.1.7.2') |
| 28 envelopedData = univ.ObjectIdentifier('1.2.840.113549.1.7.3') |
| 29 signedAndEnvelopedData = univ.ObjectIdentifier('1.2.840.113549.1.7.4') |
| 30 digestedData = univ.ObjectIdentifier('1.2.840.113549.1.7.5') |
| 31 encryptedData = univ.ObjectIdentifier('1.2.840.113549.1.7.6') |
| 32 |
| 33 class ContentType(univ.ObjectIdentifier): pass |
| 34 |
| 35 class ContentEncryptionAlgorithmIdentifier(AlgorithmIdentifier): pass |
| 36 |
| 37 class EncryptedContent(univ.OctetString): pass |
| 38 |
| 39 class EncryptedContentInfo(univ.Sequence): |
| 40 componentType = namedtype.NamedTypes( |
| 41 namedtype.NamedType('contentType', ContentType()), |
| 42 namedtype.NamedType('contentEncryptionAlgorithm', ContentEncryptionAlgor
ithmIdentifier()), |
| 43 namedtype.OptionalNamedType('encryptedContent', EncryptedContent().subty
pe(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))) |
| 44 ) |
| 45 |
| 46 class Version(univ.Integer): pass # overrides x509.Version |
| 47 |
| 48 class EncryptedData(univ.Sequence): |
| 49 componentType = namedtype.NamedTypes( |
| 50 namedtype.NamedType('version', Version()), |
| 51 namedtype.NamedType('encryptedContentInfo', EncryptedContentInfo()) |
| 52 ) |
| 53 |
| 54 class DigestAlgorithmIdentifier(AlgorithmIdentifier): pass |
| 55 |
| 56 class DigestAlgorithmIdentifiers(univ.SetOf): |
| 57 componentType = DigestAlgorithmIdentifier() |
| 58 |
| 59 class Digest(univ.OctetString): pass |
| 60 |
| 61 class ContentInfo(univ.Sequence): |
| 62 componentType = namedtype.NamedTypes( |
| 63 namedtype.NamedType('contentType', ContentType()), |
| 64 namedtype.OptionalNamedType('content', univ.Any().subtype(explicitTag=ta
g.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))) |
| 65 ) |
| 66 |
| 67 class DigestedData(univ.Sequence): |
| 68 componentType = namedtype.NamedTypes( |
| 69 namedtype.NamedType('version', Version()), |
| 70 namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()), |
| 71 namedtype.NamedType('contentInfo', ContentInfo()), |
| 72 namedtype.NamedType('digest', Digest) |
| 73 ) |
| 74 |
| 75 class IssuerAndSerialNumber(univ.Sequence): |
| 76 componentType = namedtype.NamedTypes( |
| 77 namedtype.NamedType('issuer', Name()), |
| 78 namedtype.NamedType('serialNumber', CertificateSerialNumber()) |
| 79 ) |
| 80 |
| 81 class KeyEncryptionAlgorithmIdentifier(AlgorithmIdentifier): pass |
| 82 |
| 83 class EncryptedKey(univ.OctetString): pass |
| 84 |
| 85 class RecipientInfo(univ.Sequence): |
| 86 componentType = namedtype.NamedTypes( |
| 87 namedtype.NamedType('version', Version()), |
| 88 namedtype.NamedType('issuerAndSerialNumber', IssuerAndSerialNumber()), |
| 89 namedtype.NamedType('keyEncryptionAlgorithm', KeyEncryptionAlgorithmIden
tifier()), |
| 90 namedtype.NamedType('encryptedKey', EncryptedKey()) |
| 91 ) |
| 92 |
| 93 class RecipientInfos(univ.SetOf): |
| 94 componentType = RecipientInfo() |
| 95 |
| 96 class Attributes(univ.SetOf): |
| 97 componentType = Attribute() |
| 98 |
| 99 class ExtendedCertificateInfo(univ.Sequence): |
| 100 componentType = namedtype.NamedTypes( |
| 101 namedtype.NamedType('version', Version()), |
| 102 namedtype.NamedType('certificate', Certificate()), |
| 103 namedtype.NamedType('attributes', Attributes()) |
| 104 ) |
| 105 |
| 106 class SignatureAlgorithmIdentifier(AlgorithmIdentifier): pass |
| 107 |
| 108 class Signature(univ.BitString): pass |
| 109 |
| 110 class ExtendedCertificate(univ.Sequence): |
| 111 componentType = namedtype.NamedTypes( |
| 112 namedtype.NamedType('extendedCertificateInfo', ExtendedCertificateInfo()
), |
| 113 namedtype.NamedType('signatureAlgorithm', SignatureAlgorithmIdentifier()
), |
| 114 namedtype.NamedType('signature', Signature()) |
| 115 ) |
| 116 |
| 117 class ExtendedCertificateOrCertificate(univ.Choice): |
| 118 componentType = namedtype.NamedTypes( |
| 119 namedtype.NamedType('certificate', Certificate()), |
| 120 namedtype.NamedType('extendedCertificate', ExtendedCertificate().subtype
(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))) |
| 121 ) |
| 122 |
| 123 class ExtendedCertificatesAndCertificates(univ.SetOf): |
| 124 componentType = ExtendedCertificateOrCertificate() |
| 125 |
| 126 class SerialNumber(univ.Integer): pass |
| 127 |
| 128 class CRLEntry(univ.Sequence): |
| 129 componentType = namedtype.NamedTypes( |
| 130 namedtype.NamedType('userCertificate', SerialNumber()), |
| 131 namedtype.NamedType('revocationDate', useful.UTCTime()) |
| 132 ) |
| 133 |
| 134 class TBSCertificateRevocationList(univ.Sequence): |
| 135 componentType = namedtype.NamedTypes( |
| 136 namedtype.NamedType('signature', AlgorithmIdentifier()), |
| 137 namedtype.NamedType('issuer', Name()), |
| 138 namedtype.NamedType('lastUpdate', useful.UTCTime()), |
| 139 namedtype.NamedType('nextUpdate', useful.UTCTime()), |
| 140 namedtype.OptionalNamedType('revokedCertificates', univ.SequenceOf(compo
nentType=CRLEntry())) |
| 141 ) |
| 142 |
| 143 class CertificateRevocationList(univ.Sequence): |
| 144 componentType = namedtype.NamedTypes( |
| 145 namedtype.NamedType('tbsCertificateRevocationList', TBSCertificateRevoca
tionList()), |
| 146 namedtype.NamedType('signatureAlgorithm', AlgorithmIdentifier()), |
| 147 namedtype.NamedType('signature', univ.BitString()) |
| 148 ) |
| 149 |
| 150 class CertificateRevocationLists(univ.SetOf): |
| 151 componentType = CertificateRevocationList() |
| 152 |
| 153 class DigestEncryptionAlgorithmIdentifier(AlgorithmIdentifier): pass |
| 154 |
| 155 class EncryptedDigest(univ.OctetString): pass |
| 156 |
| 157 class SignerInfo(univ.Sequence): |
| 158 componentType = namedtype.NamedTypes( |
| 159 namedtype.NamedType('version', Version()), |
| 160 namedtype.NamedType('issuerAndSerialNumber', IssuerAndSerialNumber()), |
| 161 namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()), |
| 162 namedtype.OptionalNamedType('authenticatedAttributes', Attributes().subt
ype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))), |
| 163 namedtype.NamedType('digestEncryptionAlgorithm', DigestEncryptionAlgorit
hmIdentifier()), |
| 164 namedtype.NamedType('encryptedDigest', EncryptedDigest()), |
| 165 namedtype.OptionalNamedType('unauthenticatedAttributes', Attributes().su
btype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))) |
| 166 ) |
| 167 |
| 168 class SignerInfos(univ.SetOf): |
| 169 componentType = SignerInfo() |
| 170 |
| 171 class SignedAndEnvelopedData(univ.Sequence): |
| 172 componentType = namedtype.NamedTypes( |
| 173 namedtype.NamedType('version', Version()), |
| 174 namedtype.NamedType('recipientInfos', RecipientInfos()), |
| 175 namedtype.NamedType('digestAlgorithms', DigestAlgorithmIdentifiers()), |
| 176 namedtype.NamedType('encryptedContentInfo', EncryptedContentInfo()), |
| 177 namedtype.OptionalNamedType('certificates', ExtendedCertificatesAndCerti
ficates().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstruc
ted, 0))), |
| 178 namedtype.OptionalNamedType('crls', CertificateRevocationLists().subtype
(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))), |
| 179 namedtype.NamedType('signerInfos', SignerInfos()) |
| 180 ) |
| 181 |
| 182 class EnvelopedData(univ.Sequence): |
| 183 componentType = namedtype.NamedTypes( |
| 184 namedtype.NamedType('version', Version()), |
| 185 namedtype.NamedType('recipientInfos', RecipientInfos()), |
| 186 namedtype.NamedType('encryptedContentInfo', EncryptedContentInfo()) |
| 187 ) |
| 188 |
| 189 class DigestInfo(univ.Sequence): |
| 190 componentType = namedtype.NamedTypes( |
| 191 namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()), |
| 192 namedtype.NamedType('digest', Digest()) |
| 193 ) |
| 194 |
| 195 class SignedData(univ.Sequence): |
| 196 componentType = namedtype.NamedTypes( |
| 197 namedtype.NamedType('version', Version()), |
| 198 namedtype.NamedType('digestAlgorithms', DigestAlgorithmIdentifiers()), |
| 199 namedtype.NamedType('contentInfo', ContentInfo()), |
| 200 namedtype.OptionalNamedType('certificates', ExtendedCertificatesAndCerti
ficates().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstruc
ted, 0))), |
| 201 namedtype.OptionalNamedType('crls', CertificateRevocationLists().subtype
(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1))), |
| 202 namedtype.NamedType('signerInfos', SignerInfos()) |
| 203 ) |
| 204 |
| 205 class Data(univ.OctetString): pass |
OLD | NEW |