class GeneralName(univ.Choice): '''ASN.1 configuration for X.509 certificate subjectAltNames fields''' componentType = namedtype.NamedTypes( namedtype.NamedType( 'otherName', AnotherName().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 0))), namedtype.NamedType( 'rfc822Name', char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 1))), namedtype.NamedType( 'dNSName', char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 2))), namedtype.NamedType( 'directoryName', Name().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4))), namedtype.NamedType( 'uniformResourceIdentifier', char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 6))), namedtype.NamedType( 'iPAddress', univ.OctetString().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 7))), namedtype.NamedType( 'registeredID', univ.ObjectIdentifier().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 8))), )
class GeneralName(univ.Choice): componentType = namedtype.NamedTypes( # namedtype.NamedType('otherName', AnotherName()), namedtype.NamedType( 'rfc822Name', char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 1))), namedtype.NamedType( 'dNSName', char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 2))), # namedtype.NamedType('x400Address', ORAddress()), namedtype.NamedType( 'directoryName', Name().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 4))), # namedtype.NamedType('ediPartyName', EDIPartyName()), namedtype.NamedType( 'uniformResourceIdentifier', char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 6))), namedtype.NamedType( 'iPAddress', univ.OctetString().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 7))), namedtype.NamedType( 'registeredID', univ.ObjectIdentifier().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 8))), )
class GeneralName(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType('otherName', univ.Sequence().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0x0))), namedtype.NamedType('rfc822Name', char.IA5String().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0x1))), namedtype.NamedType('dNSName', char.IA5String().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0x2))), namedtype.NamedType('x400Address', univ.Sequence().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0x3))), namedtype.NamedType('directoryName', Name().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0x4))), namedtype.NamedType('ediPartyName', univ.Sequence().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0x5))), namedtype.NamedType('uniformResourceIdentifier', char.IA5String().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0x6))), namedtype.NamedType('iPAddress', univ.OctetString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0x7))), namedtype.NamedType('registeredID', univ.ObjectIdentifier().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0x8))), )
class LogotypeAudioInfo(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('fileSize', univ.Integer()), namedtype.NamedType('playTime', univ.Integer()), namedtype.NamedType('channels', univ.Integer()), namedtype.OptionalNamedType('sampleRate', univ.Integer()), namedtype.OptionalNamedType('language', char.IA5String()))
class DirectoryString(univ.Choice): """ASN.1 Directory string class""" componentType = namedtype.NamedTypes( namedtype.NamedType( 'teletexString', char.TeletexString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'printableString', char.PrintableString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'universalString', char.UniversalString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'utf8String', char.UTF8String().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'bmpString', char.BMPString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'ia5String', char.IA5String().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), )
class DirectoryString(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType( "teletexString", char.TeletexString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( "printableString", char.PrintableString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( "universalString", char.UniversalString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( "utf8String", char.UTF8String().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( "bmpString", char.BMPString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType("ia5String", char.IA5String().subtype( subtypeSpec=constraint.ValueSizeConstraint( 1, MAX))) # hm, this should not be here!? )
class DirectoryString(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType( 'teletexString', char.TeletexString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'printableString', char.PrintableString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'universalString', char.UniversalString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'utf8String', char.UTF8String().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'bmpString', char.BMPString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, MAX))), namedtype.NamedType( 'ia5String', char.IA5String().subtype( subtypeSpec=constraint.ValueSizeConstraint( 1, MAX))) # hm, this should not be here!? XXX ) to_python = generic.parse_directory_string
class BiometricData(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType('typeOfBiometricData', TypeOfBiometricData()), namedtype.NamedType('hashAlgorithm', AlgorithmIdentifier()), namedtype.NamedType('biometricDataHash', univ.OctetString()), namedtype.OptionalNamedType('sourceDataUri', char.IA5String()) )
class RelaxedDisplayText(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType("ia5String", char.IA5String()), namedtype.NamedType("visibleString", char.VisibleString()), namedtype.NamedType("bmpString", char.BMPString()), namedtype.NamedType("utf8String", char.UTF8String()), )
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 _GeneralName(univ.Choice): # We are only interested in dNSNames. We use a default handler to ignore # other types. componentType = namedtype.NamedTypes( namedtype.NamedType( 'dNSName', char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 2))), )
def _build_extension_netscapeURL(strurl): ext = rfc2459.Extension() extoid = utility.OID_ns_netscape_base_url extval = char.IA5String(strurl) encapsulated = univ.OctetString(encoder.encode(extval)) ext.setComponentByName('extnID', extoid) ext.setComponentByName('extnValue', encapsulated) return ext
class LogotypeImageInfo(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.DefaultedNamedType('type', LogotypeImageType('color')), namedtype.NamedType('fileSize', univ.Integer()), namedtype.NamedType('xSize', univ.Integer()), namedtype.NamedType('ySize', univ.Integer()), namedtype.OptionalNamedType('resolution', LogotypeImageResolution()), namedtype.OptionalNamedType('language', char.IA5String()))
class CrlID(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.OptionalNamedType('crlUrl', char.IA5String().subtype( explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))), namedtype.OptionalNamedType('crlNum', univ.Integer().subtype( explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))), namedtype.OptionalNamedType('crlTime', useful.GeneralizedTime().subtype( explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2))) )
class TimeStampedData(univ.Sequence): componentType = namedtype.NamedTypes( namedtype.NamedType( 'version', univ.Integer(namedValues=namedval.NamedValues(('v1', 1)))), namedtype.OptionalNamedType('dataUri', char.IA5String()), namedtype.OptionalNamedType('metaData', MetaData()), namedtype.OptionalNamedType('content', univ.OctetString()), namedtype.NamedType('temporalEvidence', Evidence()))
class _GeneralName(univ.Choice): # We only care about dNSName and iPAddress componentType = namedtype.NamedTypes( namedtype.NamedType('dNSName', char.IA5String().subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2) )), namedtype.NamedType('iPAddress', univ.OctetString().subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 7) )), )
class DirectoryString(univ.Choice): """ASN.1 Directory string class""" componentType = namedtype.NamedTypes( namedtype.NamedType('teletexString', char.TeletexString()), namedtype.NamedType('printableString', char.PrintableString()), namedtype.NamedType('universalString', char.UniversalString()), namedtype.NamedType('utf8String', char.UTF8String()), namedtype.NamedType('bmpString', char.BMPString()), namedtype.NamedType('ia5String', char.IA5String()), )
class _GeneralName(univ.Choice): # Copied from https://github.com/theprincy/sslchecker # We are only interested in dNSNames. We use a default handler to ignore # other types. # TODO: We should also handle iPAddresses. componentType = namedtype.NamedTypes( namedtype.NamedType('dNSName', char.IA5String().subtype( implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2) ) ), )
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 SpcString(univ.Choice): """SPC String class represetning unicode or ascii strings.""" componentType = namedtype.NamedTypes( namedtype.NamedType( "unicode", char.BMPString(encoding="utf-16-be").subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 0)), ), namedtype.NamedType( "ascii", char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 1)), ), )
def decodeDIRACGroup(m2cert): """Decode the content of the dirac group extension :param m2cert: M2crypto x509 object, a certificate :returns: the dirac group :raises: same as retrieveExtension """ diracGroupOctetString = retrieveExtension(m2cert, DIRAC_GROUP_OID) diracGroupUTF8Str, _rest = der_decode(diracGroupOctetString, asn1Spec=asn1char.IA5String()) return diracGroupUTF8Str.asOctets().decode()
class DirectoryString(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType('teletexString', char.TeletexString()), namedtype.NamedType('printableString', char.PrintableString()), namedtype.NamedType('universalString', char.UniversalString()), namedtype.NamedType('utf8String', char.UTF8String()), namedtype.NamedType('bmpString', char.BMPString()), namedtype.NamedType('ia5String', char.IA5String()), namedtype.NamedType('gString', univ.OctetString())) def __str__(self): return str(self.getComponentByPosition(self._currentIdx)).decode( 'utf-8', 'ignore') def __repr__(self): return self.__str__()
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)))) def to_python(self): if 'unicode' in self: return str(self['unicode']) elif 'ascii' in self: return str(self['ascii'])
def testDerCodec(self): substrate = pem.readBase64fromText(self.pem_text) asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec) self.assertFalse(rest) self.assertTrue(asn1Object.prettyPrint()) self.assertEqual(substrate, der_encoder(asn1Object)) emailAttr = asn1Object['subject']['rdnSequence'][5][0] oid = univ.ObjectIdentifier('1.2.840.113549.1.9.1') self.assertEqual(oid, emailAttr['type']) email, rest = der_decoder(emailAttr['value'], asn1Spec=char.IA5String()) self.assertFalse(rest) self.assertTrue(email.prettyPrint()) self.assertEqual(emailAttr['value'], der_encoder(email)) self.assertEqual('*****@*****.**', email)
class DisplayText(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType( 'ia5String', char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0x0))), namedtype.NamedType( 'visibleString', char.VisibleString().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0x1))), namedtype.NamedType( 'bmpString', char.BMPString().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0x2))), namedtype.NamedType( 'utf8String', char.UTF8String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatConstructed, 0x3))), )
class DirectoryString(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType('teletexString', char.TeletexString()), namedtype.NamedType('printableString', char.PrintableString()), namedtype.NamedType('universalString', char.UniversalString()), namedtype.NamedType('utf8String', char.UTF8String()), namedtype.NamedType('bmpString', char.BMPString()), namedtype.NamedType('ia5String', char.IA5String()), namedtype.NamedType('gString', univ.OctetString())) def __repr__(self): try: c = self.getComponent() return c.__str__() except: return "Choice type not chosen" def __str__(self): return repr(self)
class DirectoryString(univ.Choice): componentType = namedtype.NamedTypes( namedtype.NamedType('teletexString', char.TeletexString()), namedtype.NamedType('printableString', char.PrintableString()), namedtype.NamedType('universalString', char.UniversalString()), namedtype.NamedType('utf8String', char.UTF8String()), namedtype.NamedType('bmpString', char.BMPString()), namedtype.NamedType('ia5String', char.IA5String()), #for legacy pkcs9-email #namedtype.NamedType('gString', univ.OctetString()), namedtype.NamedType('bitString', univ.BitString()), #needed for X500 Unique Identifier, RFC 4519 ) def __repr__(self): try: c = self.getComponent() return c.__str__() except: return "Choice type not chosen" def __str__(self): return repr(self)
class SpcLink(univ.Choice): """SPC Link class for holding references to URLs or files.""" componentType = namedtype.NamedTypes( namedtype.NamedType( "url", char.IA5String().subtype(implicitTag=tag.Tag( tag.tagClassContext, tag.tagFormatSimple, 0)), ), namedtype.NamedType( "moniker", univ.Any().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)), ), namedtype.NamedType( "file", SpcString().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)), ), )
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)))) def to_python(self): if 'url' in self: return str(self['url']) elif 'moniker' in self: return None # TODO elif 'file' in self: return self['file'].to_python()
'bmpString', char.BMPString().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, 255)))) # PKCS9String is DirectoryString with an additional choice of IA5String, # and the SIZE is limited to 255 class PKCS9String(univ.Choice): pass PKCS9String.componentType = namedtype.NamedTypes( namedtype.NamedType( 'ia5String', char.IA5String().subtype( subtypeSpec=constraint.ValueSizeConstraint(1, 255))), namedtype.NamedType('directoryString', DirectoryString())) # Upper Bounds pkcs_9_ub_pkcs9String = univ.Integer(255) pkcs_9_ub_challengePassword = univ.Integer(pkcs_9_ub_pkcs9String) pkcs_9_ub_emailAddress = univ.Integer(pkcs_9_ub_pkcs9String) pkcs_9_ub_friendlyName = univ.Integer(pkcs_9_ub_pkcs9String) pkcs_9_ub_match = univ.Integer(pkcs_9_ub_pkcs9String) pkcs_9_ub_signingDescription = univ.Integer(pkcs_9_ub_pkcs9String)