Exemplo n.º 1
0
 def testPosInt(self):
     assert encoder.encode(univ.Integer(12)) == ints2octs((2, 1, 12))
Exemplo n.º 2
0
class LdapSSOTokenRequestValue(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType(
            'ValidLifeTime',
            univ.Integer().subtype(implicitTag=tag.Tag(
                tag.tagClassUniversal, tag.tagFormatSimple, 0))), )
Exemplo n.º 3
0
class SimpleSyntax(TypeCoercionHackMixIn, univ.Choice):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('number', univ.Integer()),
        namedtype.NamedType('string', univ.OctetString()),
        namedtype.NamedType('object', univ.ObjectIdentifier()),
        namedtype.NamedType('empty', univ.Null()))
Exemplo n.º 4
0
mgf1SHA512Identifier = rfc5280.AlgorithmIdentifier()
mgf1SHA512Identifier['algorithm'] = id_mgf1
mgf1SHA512Identifier['parameters'] = sha512Identifier

pSpecifiedEmptyIdentifier = rfc5280.AlgorithmIdentifier()
pSpecifiedEmptyIdentifier['algorithm'] = id_pSpecified
pSpecifiedEmptyIdentifier['parameters'] = univ.OctetString(value='')


class RSAPublicKey(univ.Sequence):
    pass


RSAPublicKey.componentType = namedtype.NamedTypes(
    namedtype.NamedType('modulus', univ.Integer()),
    namedtype.NamedType('publicExponent', univ.Integer()))


class HashAlgorithm(rfc5280.AlgorithmIdentifier):
    pass


class MaskGenAlgorithm(rfc5280.AlgorithmIdentifier):
    pass


class RSAES_OAEP_params(univ.Sequence):
    pass

Exemplo n.º 5
0
 def setUp(self):
     BaseTestCase.setUp(self)
     self.s = univ.Sequence()
     self.s.setComponentByPosition(0, univ.Null(''))
     self.s.setComponentByPosition(1, univ.OctetString('quick brown'))
     self.s.setComponentByPosition(2, univ.Integer(1))
Exemplo n.º 6
0
 def __initWithOptionalAndDefaulted(self):
     self.s.clear()
     self.s.setComponentByPosition(0, univ.Null(''))
     self.s.setComponentByPosition(1, univ.OctetString('quick brown'))
     self.s.setComponentByPosition(2, univ.Integer(1))
Exemplo n.º 7
0
 def testNegLong(self):
     assert encoder.encode(univ.Integer(-0xffffffffffffffff)) == ints2octs(
         (2, 9, 255, 0, 0, 0, 0, 0, 0, 0, 1))
Exemplo n.º 8
0
 def setUp(self):
     self.s = univ.Choice(componentType=namedtype.NamedTypes(
         namedtype.NamedType('place-holder', univ.Null(null)),
         namedtype.NamedType('number', univ.Integer(0)),
         namedtype.NamedType('string', univ.OctetString())
     ))
Exemplo n.º 9
0
 def testMinusOne(self):
     assert encoder.encode(univ.Integer(-1)) == ints2octs((2, 1, 255))
Exemplo n.º 10
0
 def testPosLong(self):
     assert encoder.encode(univ.Integer(0xffffffffffffffff)) == ints2octs(
         (2, 9, 0, 255, 255, 255, 255, 255, 255, 255, 255))
Exemplo n.º 11
0
 def testCompactZero(self):
     encoder.IntegerEncoder.supportCompactZero = True
     substrate = encoder.encode(univ.Integer(0))
     encoder.IntegerEncoder.supportCompactZero = False
     assert substrate == ints2octs((2, 0))
Exemplo n.º 12
0
 def testZero(self):
     assert encoder.encode(univ.Integer(0)) == ints2octs((2, 1, 0))
Exemplo n.º 13
0
 def testNegInt(self):
     assert encoder.encode(univ.Integer(-12)) == ints2octs((2, 1, 244))
Exemplo n.º 14
0
 def testTagsEquivalence(self):
     integer = univ.Integer(2, tag.TagSet((), tag.Tag(tag.tagClassContext, 0, 0)))
     assert decoder.decode(ints2octs((0x9f, 0x80, 0x00, 0x02, 0x01, 0x02)), asn1Spec=integer) == decoder.decode(
         ints2octs((0x9f, 0x00, 0x02, 0x01, 0x02)), asn1Spec=integer)
Exemplo n.º 15
0
class ECPoint(univ.Sequence):
    """Helper type for encoding a EC point"""
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('x', univ.Integer()),
        namedtype.NamedType('y', univ.Integer()))
Exemplo n.º 16
0
 def __initWithDefaulted(self):
     self.s.clear()
     self.s.setComponentByPosition(0, univ.Null(null))
     self.s.setComponentByPosition(2, univ.Integer(1))
     self.s.setDefaultComponents()
Exemplo n.º 17
0

CMCStatus.namedValues = namedval.NamedValues(
    ('success', 0), ('failed', 2), ('pending', 3), ('noSupport', 4),
    ('confirmRequired', 5), ('popRequired', 6), ('partial', 7))


class PendInfo(univ.Sequence):
    pass


PendInfo.componentType = namedtype.NamedTypes(
    namedtype.NamedType('pendToken', univ.OctetString()),
    namedtype.NamedType('pendTime', useful.GeneralizedTime()))

bodyIdMax = univ.Integer(4294967295)


class BodyPartID(univ.Integer):
    pass


BodyPartID.subtypeSpec = constraint.ValueRangeConstraint(0, bodyIdMax)


class BodyPartPath(univ.SequenceOf):
    pass


BodyPartPath.componentType = BodyPartID()
BodyPartPath.subtypeSpec = constraint.ValueSizeConstraint(1, MAX)
Exemplo n.º 18
0
class DERSequenceOfIntegers(univ.SequenceOf):
    componentType = univ.Integer()
    def __init__(self, integers):
        univ.SequenceOf.__init__(self)
        for pos, i in enumerate(integers):
            self.setComponentByPosition(pos, i)
Exemplo n.º 19
0
 class ASN1_X9_63_DSA_Signature(univ.Sequence):
     componentType = namedtype.NamedTypes(
         namedtype.NamedType('r', univ.Integer()),
         namedtype.NamedType('s', univ.Integer()))
Exemplo n.º 20
0
 def setUp(self):
     BaseTestCase.setUp(self)
     self.s = univ.Sequence(componentType=namedtype.NamedTypes(
         namedtype.NamedType('place-holder', univ.Null('')),
         namedtype.OptionalNamedType('first-name', univ.OctetString()),
         namedtype.DefaultedNamedType('age', univ.Integer(33))))
Exemplo n.º 21
0
class RSAPublicKey(univ.Sequence):
    """Helper type for encoding an RSA public key"""
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('N', univ.Integer()),
        namedtype.NamedType('E', univ.Integer()))
    def testOpenTypes(self):
        openTypesMap = {
            rfc2985.pkcs_9_at_smimeCapabilities: rfc2985.SMIMECapabilities(),
        }
        openTypesMap.update(rfc5280.certificateAttributesMap)
        openTypesMap.update(rfc5652.cmsAttributesMap)

        substrate = pem.readBase64fromText(self.pem_text)
        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=self.asn1Spec,
                                       openTypes=openTypesMap,
                                       decodeOpenTypes=True)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        for attr in asn1Object:
            self.assertTrue(attr['type'], openTypesMap)

            if attr['type'] == rfc2985.pkcs_9_at_userPKCS12:

                self.assertEqual(univ.Integer(3), attr['values'][0]['version'])
                self.assertEqual(rfc5652.id_data,
                                 attr['values'][0]['authSafe']['contentType'])

                authsafe, rest = der_decoder(
                    attr['values'][0]['authSafe']['content'],
                    asn1Spec=rfc7292.AuthenticatedSafe())

                self.assertFalse(rest)

                for ci in authsafe:
                    self.assertEqual(rfc5652.id_data, ci['contentType'])

                    indata, rest = der_decoder(ci['content'],
                                               asn1Spec=univ.OctetString())

                    self.assertFalse(rest)

                    sc, rest = der_decoder(indata,
                                           asn1Spec=rfc7292.SafeContents(),
                                           decodeOpenTypes=True)

                    self.assertFalse(rest)

                    for sb in sc:
                        if sb['bagId'] in rfc7292.pkcs12BagTypeMap:
                            for bagattr in sb['bagAttributes']:
                                if bagattr['attrType'] in openTypesMap:

                                    if bagattr[
                                            'attrType'] == rfc2985.pkcs_9_at_friendlyName:
                                        self.assertEqual(
                                            "3f71af65-1687-444a-9f46-c8be194c3e8e",
                                            bagattr['attrValues'][0])

                                    if bagattr[
                                            'attrType'] == rfc2985.pkcs_9_at_localKeyId:
                                        self.assertEqual(
                                            univ.OctetString(
                                                hexValue='01000000'),
                                            bagattr['attrValues'][0])

            if attr['type'] == rfc2985.pkcs_9_at_pkcs7PDU:
                self.assertEqual(rfc5652.id_signedData,
                                 attr['values'][0]['contentType'])
                self.assertEqual(1, attr['values'][0]['content']['version'])

                for si in attr['values'][0]['content']['signerInfos']:
                    self.assertEqual(1, si['version'])

                    for siattr in si['signedAttrs']:
                        if siattr['attrType'] in openTypesMap:

                            if siattr[
                                    'attrType'] == rfc2985.pkcs_9_at_contentType:
                                self.assertEqual(rfc5652.id_data,
                                                 siattr['attrValues'][0])

                            if siattr[
                                    'attrType'] == rfc2985.pkcs_9_at_messageDigest:
                                self.assertEqual(
                                    'b6e422a4', siattr['attrValues']
                                    [0].prettyPrint()[2:10])

                            if siattr[
                                    'attrType'] == rfc2985.pkcs_9_at_signingTime:
                                self.assertEqual(
                                    '190529182319Z',
                                    siattr['attrValues'][0]['utcTime'])

                for choices in attr['values'][0]['content']['certificates']:
                    for rdn in choices[0]['tbsCertificate']['subject'][
                            'rdnSequence']:
                        if rdn[0]['type'] in openTypesMap:
                            if rdn[0][
                                    'type'] == rfc2985.pkcs_9_at_emailAddress:
                                self.assertEqual('*****@*****.**',
                                                 rdn[0]['value'])
Exemplo n.º 23
0
)


class AccessPointNameNI(char.IA5String):
    pass


AccessPointNameNI.subtypeSpec = constraint.ValueSizeConstraint(1, 63)


class AccessPointNameOI(char.IA5String):
    pass


AccessPointNameOI.subtypeSpec = constraint.ValueSizeConstraint(1, 37)
maxAddressLength = univ.Integer(20)


class AddressString(univ.OctetString):
    pass


AddressString.subtypeSpec = constraint.ValueSizeConstraint(1, maxAddressLength)


class CAMELAccessPointNameNI(AccessPointNameNI):
    pass


class CAMELAccessPointNameOI(AccessPointNameOI):
    pass
Exemplo n.º 24
0
class ACClearAttrs(univ.Sequence):
    componentType = namedtype.NamedTypes(
        namedtype.NamedType('acIssuer', GeneralName()),
        namedtype.NamedType('acSerial', univ.Integer()),
        namedtype.NamedType('attrs',
                            univ.SequenceOf(componentType=Attribute())))
Exemplo n.º 25
0
from pyasn1_alt_modules import rfc5280
from pyasn1_alt_modules import opentypemap

otherNamesMap = opentypemap.get('otherNamesMap')


# NAI Realm Name for Certificates

id_pkix = univ.ObjectIdentifier('1.3.6.1.5.5.7')

id_on = id_pkix + (8, )

id_on_naiRealm = id_on + (8, )


ub_naiRealm_length = univ.Integer(255)


class NAIRealm(char.UTF8String):
    subtypeSpec = constraint.ValueSizeConstraint(1, ub_naiRealm_length)


naiRealm = rfc5280.AnotherName()
naiRealm['type-id'] = id_on_naiRealm
naiRealm['value'] = NAIRealm()


# Update the Other Names Map

_otherNamesMapUpdate = {
    id_on_naiRealm: NAIRealm(),
Exemplo n.º 26
0
 def testPosInt(self):
     assert decoder.decode(12, asn1Spec=univ.Integer()) == univ.Integer(12)
Exemplo n.º 27
0
 def setUp(self):
     self.o = univ.Integer().subtype(value=1,
                                     explicitTag=tag.Tag(
                                         tag.tagClassApplication,
                                         tag.tagFormatSimple, 0xdeadbeaf))