class ContentInfo(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('contentType', ContentType()), namedtype.OptionalNamedType( 'content', univ.Any().subtype(explicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0))))
class ExtendedCertificateOrCertificate(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType('certificate', x509.Certificate()), namedtype.NamedType( 'extendedCertificate', ExtendedCertificate().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0))))
class ExtendedCertificate(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('extendedCertificateInfo', ExtendedCertificateInfo()), namedtype.NamedType('signatureAlgorithm', SignatureAlgorithmIdentifier()), namedtype.NamedType('signature', Signatures()))
class SpcSpOpusInfo(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.OptionalNamedType( 'programName', SpcString().subtype(explicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0))), namedtype.OptionalNamedType( 'moreInfo', SpcLink().subtype(explicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 1))))
class SpcString(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType( 'unicode', char.BMPString().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0))), namedtype.NamedType( 'ascii', char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 1))))
class SignedData(univ.Sequence): """As defined by PKCS#7.""" componentType = namedtype.NamedTypes( namedtype.NamedType('version', Version()), namedtype.NamedType('digestAlgorithms', DigestAlgorithmIdentifiers()), namedtype.NamedType('contentInfo', ContentInfo()), namedtype.OptionalNamedType( 'certificates', ExtendedCertificatesAndCertificates().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0))), namedtype.OptionalNamedType( 'crls', CertificateRevocationLists().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 1))), namedtype.NamedType('signerInfos', SignerInfos()))
class SpcLink(univ.Choice): """According to Authenticode specification.""" componentType = namedtype.NamedTypes( namedtype.NamedType( 'url', char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0))), namedtype.NamedType( 'moniker', SpcSerializedObject().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 1))), namedtype.NamedType( 'file', SpcString().subtype(explicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 2))))
class SignerInfo(univ.Sequence): """As defined by PKCS#7.""" componentType = namedtype.NamedTypes( namedtype.NamedType('version', Version()), namedtype.NamedType('issuerAndSerialNumber', IssuerAndSerialNumber()), namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()), namedtype.OptionalNamedType( 'authenticatedAttributes', Attributes().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0))), namedtype.NamedType('digestEncryptionAlgorithm', DigestEncryptionAlgorithmIdentifier()), namedtype.NamedType('encryptedDigest', EncryptedDigest()), namedtype.OptionalNamedType( 'unauthenticatedAttributes', Attributes().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 1))))
class Time(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType('utcTime', useful.UTCTime()), namedtype.NamedType('generalTime', useful.GeneralizedTime())) def ToPythonEpochTime(self): """Takes a ASN.1 Time choice, and returns seconds since epoch in UTC.""" utc_time = self.getComponentByName('utcTime') general_time = self.getComponentByName('generalTime') if utc_time and general_time: raise error.PyAsn1Error('Both elements of a choice are present.') if general_time: format_str = '%Y%m%d%H%M%SZ' time_str = str(general_time) else: format_str = '%y%m%d%H%M%SZ' time_str = str(utc_time) time_tpl = time.strptime(time_str, format_str) return calendar.timegm(time_tpl)
class TBSCertificate(univ.Sequence): """According to X.509 specification.""" componentType = namedtype.NamedTypes( namedtype.DefaultedNamedType( 'version', Version('v1', tagSet=Version.tagSet.tagExplicitly(tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 0)))), namedtype.NamedType('serialNumber', CertificateSerialNumber()), namedtype.NamedType('signature', AlgorithmIdentifier()), namedtype.NamedType('issuer', Name()), namedtype.NamedType('validity', Validity()), namedtype.NamedType('subject', Name()), namedtype.NamedType('subjectPublicKeyInfo', SubjectPublicKeyInfo()), namedtype.OptionalNamedType( 'issuerUniqueID', UniqueIdentifier().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 1))), namedtype.OptionalNamedType( 'subjectUniqueID', UniqueIdentifier().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 2))), namedtype.OptionalNamedType('extensions', Extensions().subtype( explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 3))))
class AttributeTypeAndValue(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('type', AttributeType()), namedtype.NamedType('value', AttributeValue()))
class SequenceAndSetBase(base.AbstractConstructedAsn1Item): componentType = namedtype.NamedTypes() def __init__(self, componentType=None, tagSet=None, subtypeSpec=None, sizeSpec=None): base.AbstractConstructedAsn1Item.__init__(self, componentType, tagSet, subtypeSpec, sizeSpec) if self._componentType is None: self._componentTypeLen = 0 else: self._componentTypeLen = len(self._componentType) def __getitem__(self, idx): if isinstance(idx, str): return self.getComponentByName(idx) else: return base.AbstractConstructedAsn1Item.__getitem__(self, idx) def __setitem__(self, idx, value): if isinstance(idx, str): self.setComponentByName(idx, value) else: base.AbstractConstructedAsn1Item.__setitem__(self, idx, value) def _cloneComponentValues(self, myClone, cloneValueFlag): idx = 0 l = len(self._componentValues) while idx < l: c = self._componentValues[idx] if c is not None: if isinstance(c, base.AbstractConstructedAsn1Item): myClone.setComponentByPosition( idx, c.clone(cloneValueFlag=cloneValueFlag)) else: myClone.setComponentByPosition(idx, c.clone()) idx = idx + 1 def _verifyComponent(self, idx, value): if idx >= self._componentTypeLen: raise error.PyAsn1Error('Component type error out of range') t = self._componentType[idx].getType() if not t.isSuperTypeOf(value): raise error.PyAsn1Error('Component type error %r vs %r' % (t, value)) def getComponentByName(self, name): return self.getComponentByPosition( self._componentType.getPositionByName(name)) def setComponentByName(self, name, value=None, verifyConstraints=True): return self.setComponentByPosition( self._componentType.getPositionByName(name), value, verifyConstraints) def getComponentByPosition(self, idx): try: return self._componentValues[idx] except IndexError: if idx < self._componentTypeLen: return raise def setComponentByPosition(self, idx, value=None, verifyConstraints=True): l = len(self._componentValues) if idx >= l: self._componentValues = self._componentValues + (idx - l + 1) * [None] if value is None: if self._componentValues[idx] is None: self._componentValues[ idx] = self._componentType.getTypeByPosition(idx).clone() self._componentValuesSet = self._componentValuesSet + 1 return self elif not isinstance(value, base.Asn1Item): t = self._componentType.getTypeByPosition(idx) if isinstance(t, base.AbstractSimpleAsn1Item): value = t.clone(value=value) else: raise error.PyAsn1Error('Instance value required') if verifyConstraints: if self._componentTypeLen: self._verifyComponent(idx, value) self._verifySubtypeSpec(value, idx) if self._componentValues[idx] is None: self._componentValuesSet = self._componentValuesSet + 1 self._componentValues[idx] = value return self def getNameByPosition(self, idx): if self._componentTypeLen: return self._componentType.getNameByPosition(idx) def getDefaultComponentByPosition(self, idx): if self._componentTypeLen and self._componentType[idx].isDefaulted: return self._componentType[idx].getType() def getComponentType(self): if self._componentTypeLen: return self._componentType def setDefaultComponents(self): if self._componentTypeLen == self._componentValuesSet: return idx = self._componentTypeLen while idx: idx = idx - 1 if self._componentType[idx].isDefaulted: if self.getComponentByPosition(idx) is None: self.setComponentByPosition(idx) elif not self._componentType[idx].isOptional: if self.getComponentByPosition(idx) is None: raise error.PyAsn1Error( 'Uninitialized component #%s at %r' % (idx, self)) def prettyPrint(self, scope=0): scope = scope + 1 r = self.__class__.__name__ + ':\n' for idx in range(len(self._componentValues)): if self._componentValues[idx] is not None: r = r + ' ' * scope componentType = self.getComponentType() if componentType is None: r = r + '<no-name>' else: r = r + componentType.getNameByPosition(idx) r = '%s=%s\n' % (r, self._componentValues[idx].prettyPrint(scope)) return r
class IssuerAndSerialNumber(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('issuer', x509.Name()), namedtype.NamedType('serialNumber', x509.CertificateSerialNumber()))
class ExtendedCertificateInfo(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('version', Version()), namedtype.NamedType('certificate', x509.Certificate()), namedtype.NamedType('attributes', Attributes()))
class DigestInfo(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('digestAlgorithm', DigestAlgorithmIdentifier()), namedtype.NamedType('digest', Digest()))
class Name(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType('', RDNSequence()))
class AlgorithmIdentifier(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('algorithm', univ.ObjectIdentifier()), namedtype.OptionalNamedType('parameters', univ.Any()))
class Attribute(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('type', x509.AttributeType()), namedtype.NamedType('values', univ.SetOf(componentType=x509.AttributeValue())))
class SubjectPublicKeyInfo(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('algorithm', AlgorithmIdentifier()), namedtype.NamedType('subjectPublicKey', univ.BitString()))
class Extension(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('extnID', univ.ObjectIdentifier()), namedtype.DefaultedNamedType('critical', univ.Boolean('False')), namedtype.NamedType('extnValue', univ.Any()))
class Validity(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('notBefore', Time()), namedtype.NamedType('notAfter', Time()))
class SpcAttributeTypeAndOptionalValue(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('type', x509.AttributeType()), namedtype.OptionalNamedType('value', x509.AttributeValue()))
class Certificate(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('tbsCertificate', TBSCertificate()), namedtype.NamedType('signatureAlgorithm', AlgorithmIdentifier()), namedtype.NamedType('signatureValue', univ.BitString()))
class SpcIndirectDataContent(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('data', SpcAttributeTypeAndOptionalValue()), namedtype.NamedType('messageDigest', DigestInfo()))
class SpcSerializedObject(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('classId', SpcUuid()), namedtype.NamedType('serializedData', univ.OctetString()))