Ejemplo n.º 1
0
    def testOpenTypes(self):
        cmsAttributesMap = opentypemap.get('cmsAttributesMap')
        cmsContentTypesMap = opentypemap.get('cmsContentTypesMap')

        substrate = pem.readBase64fromText(self.pem_text)
        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=rfc5652.ContentInfo(),
                                       decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        self.assertEqual(rfc4073.id_ct_contentCollection, asn1Object['contentType'])

        for ci in asn1Object['content']:
            self.assertIn(ci['contentType'], cmsContentTypesMap)
            self.assertEqual(rfc4073.id_ct_contentWithAttrs, ci['contentType'])

            next_ci = ci['content']['content']

            self.assertIn(next_ci['contentType'], cmsContentTypesMap)
            self.assertEqual(rfc5652.id_data, next_ci['contentType'])
            self.assertIn(str2octs('Content-Type: text'), next_ci['content'])

            for attr in ci['content']['attrs']:
                self.assertIn(attr['attrType'], cmsAttributesMap)
                if attr['attrType'] == rfc2634.id_aa_contentHint:
                    self.assertIn('RFC 4073', attr['attrValues'][0]['contentDescription'])
Ejemplo n.º 2
0
    def testDerCodec(self):
        ocspResponseMap = opentypemap.get('ocspResponseMap')
        certificateExtensionsMap = opentypemap.get('certificateExtensionsMap')

        substrate = pem.readBase64fromText(self.ocsp_resp_pem_text)
        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))
        self.assertEqual(0, asn1Object['responseStatus'])

        rb = asn1Object['responseBytes']
        self.assertIn(rb['responseType'], ocspResponseMap)

        resp, rest = der_decoder(rb['response'],
                                 asn1Spec=ocspResponseMap[rb['responseType']])
        self.assertFalse(rest)
        self.assertTrue(resp.prettyPrint())
        self.assertEqual(rb['response'], der_encoder(resp))
        self.assertEqual(0, resp['tbsResponseData']['version'])

        count = 0
        for extn in resp['tbsResponseData']['responseExtensions']:
            self.assertIn(extn['extnID'], certificateExtensionsMap)
            ev, rest = der_decoder(
                extn['extnValue'],
                asn1Spec=certificateExtensionsMap[extn['extnID']])
            self.assertFalse(rest)
            self.assertTrue(ev.prettyPrint())
            self.assertEqual(extn['extnValue'], der_encoder(ev))
            count += 1

        self.assertEqual(1, count)
Ejemplo n.º 3
0
    def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.cert_pem_text)
        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=self.asn1Spec,
                                       decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        cat_value_found = False
        certificateExtensionsMap = opentypemap.get('certificateExtensionsMap')
        securityCategoryMap = opentypemap.get('securityCategoryMap')

        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc5913.id_pe_clearanceConstraints:
                self.assertIn(extn['extnID'], certificateExtensionsMap)
                ev, rest = der_decoder(
                    extn['extnValue'],
                    asn1Spec=certificateExtensionsMap[extn['extnID']],
                    decodeOpenTypes=True)
                self.assertFalse(rest)
                self.assertTrue(ev.prettyPrint())
                self.assertEqual(extn['extnValue'], der_encoder(ev))

                for c in ev:
                    if c['policyId'] == rfc3114.id_tsp_TEST_Whirlpool:
                        for sc in c['securityCategories']:
                            self.assertIn(sc['type'], securityCategoryMap)
                            for cat in sc['value']:
                                self.assertIn('USE ONLY', cat)
                                cat_value_found = True

        self.assertTrue(cat_value_found)
Ejemplo n.º 4
0
    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))
        self.assertEqual(1, asn1Object['acinfo']['version'])

        certificateExtensionsMap = opentypemap.get('certificateExtensionsMap')
        policyQualifierInfosMap = opentypemap.get('policyQualifierInfosMap')
        found_ac_policy_qualifier1 = False
        found_ac_policy_qualifier2 = False
        for extn in asn1Object['acinfo']['extensions']:
            self.assertIn(extn['extnID'], certificateExtensionsMap)
            if extn['extnID'] == rfc4476.id_pe_acPolicies:
                ev, rest = der_decoder(
                    extn['extnValue'],
                    asn1Spec=certificateExtensionsMap[extn['extnID']])
                self.assertFalse(rest)
                self.assertTrue(ev.prettyPrint())
                self.assertEqual(extn['extnValue'], der_encoder(ev))

                oid = univ.ObjectIdentifier((
                    1,
                    3,
                    6,
                    1,
                    4,
                    1,
                    22112,
                    48,
                    10,
                ))
                self.assertEqual(oid, ev[0]['policyIdentifier'])

                for pq in ev[0]['policyQualifiers']:
                    self.assertIn(pq['policyQualifierId'],
                                  policyQualifierInfosMap)

                    pqv, rest = der_decoder(pq['qualifier'],
                                            asn1Spec=policyQualifierInfosMap[
                                                pq['policyQualifierId']])
                    self.assertFalse(rest)
                    self.assertTrue(pqv.prettyPrint())
                    self.assertEqual(pq['qualifier'], der_encoder(pqv))

                    if pq['policyQualifierId'] == rfc4476.id_qt_acps:
                        self.assertIn('example.com', pqv)
                        found_ac_policy_qualifier1 = True

                    if pq['policyQualifierId'] == rfc4476.id_qt_acunotice:
                        self.assertIn(20, pqv[0]['noticeNumbers'])
                        found_ac_policy_qualifier2 = True

        assert found_ac_policy_qualifier1
        assert found_ac_policy_qualifier2
Ejemplo n.º 5
0
    def testDerCodec(self):
        layers = {}
        layers.update(opentypemap.get('cmsContentTypesMap'))
        self.assertIn(rfc5055.id_ct_scvp_certValResponse, layers)

        getNextLayer = {
            rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
            rfc5652.id_signedData:
            lambda x: x['encapContentInfo']['eContentType'],
        }

        getNextSubstrate = {
            rfc5652.id_ct_contentInfo: lambda x: x['content'],
            rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'],
        }

        substrate = pem.readBase64fromText(self.cvresponse_pem_text)

        layer = rfc5652.id_ct_contentInfo
        while layer in getNextLayer:
            asn1Object, rest = der_decoder(substrate, asn1Spec=layers[layer])
            self.assertFalse(rest)
            self.assertTrue(asn1Object.prettyPrint())
            self.assertEqual(substrate, der_encoder(asn1Object))

            substrate = getNextSubstrate[layer](asn1Object)
            layer = getNextLayer[layer](asn1Object)

        asn1Object, rest = der_decoder(substrate, asn1Spec=layers[layer])
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        self.assertEqual(
            'URN:VSSAPI:vss-dv-rs-p11',
            asn1Object['requestorName'][0]['uniformResourceIdentifier'])

        scvpWantBackMap = opentypemap.get('scvpWantBackMap')
        found = False
        for cr in asn1Object['replyObjects']:
            for rwb in cr['replyWantBacks']:
                if rwb['wb'] in scvpWantBackMap:
                    wbv, rest = der_decoder(
                        rwb['value'], asn1Spec=scvpWantBackMap[rwb['wb']])
                    self.assertFalse(rest)
                    self.assertTrue(wbv.prettyPrint())
                    self.assertEqual(rwb['value'], der_encoder(wbv))

                    self.assertEqual(2, wbv[0]['tbsCertificate']['version'])
                    found = True

        self.assertTrue(found)
Ejemplo n.º 6
0
    def testDerCodec(self):

        def test_layer(substrate, content_type, attrMap):
            asn1Object, rest = der_decoder(substrate, asn1Spec=layers[content_type])
            self.assertFalse(rest)
            self.assertTrue(asn1Object.prettyPrint())
            self.assertEqual(substrate, der_encoder(asn1Object))

            if content_type == rfc4073.id_ct_contentWithAttrs:
                for attr in asn1Object['attrs']:
                    self.assertIn(attr['attrType'], attrMap)
    
            return asn1Object

        attrMap = opentypemap.get('cmsAttributesMap')

        layers = opentypemap.get('cmsContentTypesMap')

        getNextLayer = {
            rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
            rfc4073.id_ct_contentCollection: lambda x: x[0]['contentType'],
            rfc4073.id_ct_contentWithAttrs: lambda x: x['content']['contentType'],
            rfc5652.id_data: lambda x: None,
        }

        getNextSubstrate = {
            rfc5652.id_ct_contentInfo: lambda x: x['content'],
            rfc4073.id_ct_contentCollection: lambda x: x[0]['content'],
            rfc4073.id_ct_contentWithAttrs: lambda x: x['content']['content'],
            rfc5652.id_data: lambda x: None,
        }

        substrate = pem.readBase64fromText(self.pem_text)

        this_layer = rfc5652.id_ct_contentInfo

        while this_layer != rfc5652.id_data:
            if this_layer == rfc4073.id_ct_contentCollection:
                asn1Object = test_layer(substrate, this_layer, attrMap)
                for ci in asn1Object:
                    substrate = ci['content']
                    this_layer = ci['contentType']
                    while this_layer != rfc5652.id_data:
                        asn1Object = test_layer(substrate, this_layer, attrMap)
                        substrate = getNextSubstrate[this_layer](asn1Object)
                        this_layer = getNextLayer[this_layer](asn1Object)
            else:
                asn1Object = test_layer(substrate, this_layer, attrMap)
                substrate = getNextSubstrate[this_layer](asn1Object)
                this_layer = getNextLayer[this_layer](asn1Object)
Ejemplo n.º 7
0
    def testDerCodec(self):
        blake_oids = [
            rfc7693.id_blake2b160,
            rfc7693.id_blake2b256,
            rfc7693.id_blake2b384,
            rfc7693.id_blake2b512,
            rfc7693.id_blake2s128,
            rfc7693.id_blake2s160,
            rfc7693.id_blake2s224,
            rfc7693.id_blake2s256,
        ]

        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))

        count = 0
        algorithmIdentifierMap = opentypemap.get('algorithmIdentifierMap')
        for cap in asn1Object:
            if cap['capabilityID'] in blake_oids:
                count += 1
                self.assertIn(cap['capabilityID'], algorithmIdentifierMap)

        self.assertEqual(len(blake_oids), count)
Ejemplo n.º 8
0
    def testDerCodec(self):
        layers = {}
        layers.update(opentypemap.get('cmsContentTypesMap'))

        getNextLayer = {
            rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
        }

        getNextSubstrate = {
            rfc5652.id_ct_contentInfo: lambda x: x['content'],
        }

        substrate = pem.readBase64fromText(self.cvrequest_pem_text)

        layer = rfc5652.id_ct_contentInfo
        while layer in getNextLayer:
            asn1Object, rest = der_decoder(substrate, asn1Spec=layers[layer])
            self.assertFalse(rest)
            self.assertTrue(asn1Object.prettyPrint())
            self.assertEqual(substrate, der_encoder(asn1Object))

            substrate = getNextSubstrate[layer](asn1Object)
            layer = getNextLayer[layer](asn1Object)

        asn1Object, rest = der_decoder(substrate, asn1Spec=layers[layer])
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        self.assertIn(rfc5276.id_swb_ers_all, asn1Object['query']['wantBack'])
Ejemplo n.º 9
0
    def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.cert_pem_text)
        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=self.asn1Spec,
                                       decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        found_dev_owner = False
        certificateExtensionsMap = opentypemap.get('certificateExtensionsMap')
        dev_own_oid = univ.ObjectIdentifier('1.3.6.1.4.1.22112.48.24')

        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc5280.id_ce_subjectDirectoryAttributes:
                self.assertIn(extn['extnID'], certificateExtensionsMap)
                ev, rest = der_decoder(
                    extn['extnValue'],
                    asn1Spec=certificateExtensionsMap[extn['extnID']],
                    decodeOpenTypes=True)
                self.assertFalse(rest)
                self.assertTrue(ev.prettyPrint())
                self.assertEqual(extn['extnValue'], der_encoder(ev))

                for attr in ev:
                    if attr['type'] == rfc5916.id_deviceOwner:
                        self.assertEqual(dev_own_oid, attr['values'][0])
                        found_dev_owner = True

        self.assertTrue(found_dev_owner)
Ejemplo n.º 10
0
    def testDerCodec(self):
        substrate = pem.readBase64fromText(self.cert_pem_text)
        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        found_PEPSI = False
        otherNamesMap = opentypemap.get('otherNamesMap')
        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc5280.id_ce_subjectAltName:
                extnValue, rest = der_decoder(
                    extn['extnValue'], asn1Spec=rfc5280.SubjectAltName())
                self.assertFalse(rest)
                self.assertTrue(extnValue.prettyPrint())
                self.assertEqual(extn['extnValue'], der_encoder(extnValue))

                for gn in extnValue:
                    if gn['otherName'].hasValue():
                        gn_on = gn['otherName']
                        if gn_on['type-id'] == rfc4683.id_on_SIM:
                            self.assertIn(gn_on['type-id'], otherNamesMap)
                            on, rest = der_decoder(
                                gn_on['value'],
                                asn1Spec=otherNamesMap[gn_on['type-id']])
                            self.assertFalse(rest)
                            self.assertTrue(on.prettyPrint())
                            self.assertEqual(gn_on['value'], der_encoder(on))

                            self.assertEqual('e6809ff3ea',
                                             on['pEPSI'].prettyPrint()[2:12])

                            found_PEPSI = True

        self.assertTrue(found_PEPSI)
Ejemplo n.º 11
0
    def testOpenTypes(self):
        asn1Spec = rfc5652.ContentInfo()
        substrate = pem.readBase64fromText(self.pem_text)
        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=asn1Spec,
                                       decodeOpenTypes=True)

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

        substrate = asn1Object['content']['encapContentInfo']['eContent']
        oid = asn1Object['content']['encapContentInfo']['eContentType']
        cmsContentTypesMap = opentypemap.get('cmsContentTypesMap')
        self.assertIn(oid, cmsContentTypesMap)

        tac_token, rest = der_decoder(substrate,
                                      asn1Spec=cmsContentTypesMap[oid],
                                      decodeOpenTypes=True)

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

        self.assertEqual('2019', tac_token['timeout'][:4])
        self.assertEqual('5dcdf44e', tac_token['userKey'].prettyPrint()[-8:])
Ejemplo n.º 12
0
    def testOpenTypes(self):
        ocspResponseMap = opentypemap.get('ocspResponseMap')

        substrate = pem.readBase64fromText(self.ocsp_resp_pem_text)
        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=self.asn1Spec,
                                       decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))
        self.assertEqual(0, asn1Object['responseStatus'])

        rb = asn1Object['responseBytes']
        self.assertIn(rb['responseType'], ocspResponseMap)

        resp, rest = der_decoder(rb['response'],
                                 asn1Spec=ocspResponseMap[rb['responseType']],
                                 decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(resp.prettyPrint())
        self.assertEqual(rb['response'], der_encoder(resp))
        self.assertEqual(0, resp['tbsResponseData']['version'])

        for rdn in resp['tbsResponseData']['responderID']['byName'][
                'rdnSequence']:
            for attr in rdn:
                if attr['type'] == rfc5280.id_emailAddress:
                    self.assertEqual('*****@*****.**', attr['value'])

        for r in resp['tbsResponseData']['responses']:
            ha = r['certID']['hashAlgorithm']
            self.assertEqual(rfc4055.id_sha1, ha['algorithm'])
            self.assertEqual(univ.Null(""), ha['parameters'])
Ejemplo n.º 13
0
    def testDerCodec(self):
        layers = {}
        layers.update(opentypemap.get('cmsContentTypesMap'))
        self.assertIn(rfc5544.id_ct_timestampedData, layers)

        getNextLayer = {
            rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
        }

        getNextSubstrate = {
            rfc5652.id_ct_contentInfo: lambda x: x['content'],
        }

        substrate = pem.readBase64fromText(self.pem_text)

        layer = rfc5652.id_ct_contentInfo
        while layer in getNextLayer:
            asn1Object, rest = der_decoder(substrate, asn1Spec=layers[layer])
            self.assertFalse(rest)
            self.assertTrue(asn1Object.prettyPrint())
            self.assertEqual(substrate, der_encoder(asn1Object))

            substrate = getNextSubstrate[layer](asn1Object)
            layer = getNextLayer[layer](asn1Object)

        asn1Object, rest = der_decoder(substrate, asn1Spec=layers[layer])
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        self.assertIn(b'come here', asn1Object['content'])
Ejemplo n.º 14
0
    def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.manifest_pem_text)
        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=rfc5652.ContentInfo(),
                                       decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        oid = asn1Object['content']['encapContentInfo']['eContentType']
        substrate = asn1Object['content']['encapContentInfo']['eContent']

        cmsContentTypesMap = opentypemap.get('cmsContentTypesMap')
        self.assertIn(oid, cmsContentTypesMap)

        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=cmsContentTypesMap[oid],
                                       decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))
        self.assertEqual(0, asn1Object['version'])

        counter = 0
        for f in asn1Object['fileList']:
            self.assertEqual('ZXSGBDBkL82TFGHuE4VOYtJP-E4.crl', f['file'])
            counter += 1

        self.assertEqual(1, counter)
Ejemplo n.º 15
0
    def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.cert_pem_text)
        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=self.asn1Spec,
                                       decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        other_cert_found = False
        certificateExtensionsMap = opentypemap.get('certificateExtensionsMap')

        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc5697.id_pe_otherCerts:
                self.assertIn(extn['extnID'], certificateExtensionsMap)

                extnValue, rest = der_decoder(
                    extn['extnValue'],
                    asn1Spec=certificateExtensionsMap[extn['extnID']],
                    decodeOpenTypes=True)
                self.assertFalse(rest)
                self.assertTrue(extnValue.prettyPrint())
                self.assertEqual(extn['extnValue'], der_encoder(extnValue))

                self.assertEqual(11939979568329289287,
                                 extnValue[0]['issuerSerial']['serialNumber'])

                other_cert_found = True

        self.assertTrue(other_cert_found)
Ejemplo n.º 16
0
 def testExtensionsMap(self):
     certificateExtensionsMap = opentypemap.get('certificateExtensionsMap')
     substrate = pem.readBase64fromText(self.extn_pem_text)
     asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
     self.assertFalse(rest)
     self.assertEqual(rfc8649.id_ce_hashOfRootKey, asn1Object['extnID'])
     self.assertIn(asn1Object['extnID'], certificateExtensionsMap)
Ejemplo n.º 17
0
    def testDerCodec(self):
        substrate = pem.readBase64fromText(self.pem_text)

        layers = opentypemap.get('cmsContentTypesMap').copy()
        self.assertIn(rfc6492.id_ct_xml, layers)

        getNextLayer = {
            rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
            rfc5652.id_signedData:
            lambda x: x['encapContentInfo']['eContentType'],
        }

        getNextSubstrate = {
            rfc5652.id_ct_contentInfo: lambda x: x['content'],
            rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'],
        }

        layer = rfc5652.id_ct_contentInfo
        while layer in getNextLayer:
            asn1Object, rest = der_decoder(substrate, asn1Spec=layers[layer])
            self.assertFalse(rest)
            self.assertTrue(asn1Object.prettyPrint())
            self.assertEqual(substrate, der_encoder(asn1Object))

            substrate = getNextSubstrate[layer](asn1Object)
            layer = getNextLayer[layer](asn1Object)

        self.assertEqual(rfc6492.id_ct_xml, layer)

        oid = None
        for attr in asn1Object['signerInfos'][0]['signedAttrs']:
            if attr['attrType'] == rfc5652.id_contentType:
                oid = attr['attrValues'][0]

        self.assertEqual(der_encoder(rfc6492.id_ct_xml), oid)
Ejemplo n.º 18
0
    def testDerCodec(self):
        substrate = pem.readBase64fromText(self.xmpp_server_cert_pem_text)
        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        count = 0
        otherNamesMap = opentypemap.get('otherNamesMap')

        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc5280.id_ce_subjectAltName:
                extnValue, rest = der_decoder(
                    extn['extnValue'], asn1Spec=rfc5280.SubjectAltName())

                self.assertFalse(rest)
                self.assertTrue(extnValue.prettyPrint())
                self.assertEqual(extn['extnValue'], der_encoder(extnValue))

                for gn in extnValue:
                    if gn['otherName'].hasValue():
                        gn_on = gn['otherName']
                        if gn_on['type-id'] == rfc6120.id_on_xmppAddr:
                            self.assertIn(gn_on['type-id'], otherNamesMap)
                            on, rest = der_decoder(
                                gn_on['value'],
                                asn1Spec=otherNamesMap[gn['otherName']
                                                       ['type-id']])
                            self.assertFalse(rest)
                            self.assertTrue(on.prettyPrint())
                            self.assertEqual(gn_on['value'], der_encoder(on))
                            self.assertEqual('im.example.com', on)
                            count += 1

        self.assertEqual(1, count)
Ejemplo n.º 19
0
    def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.tsr_pem_text)
        asn1Object, rest = der_decoder(substrate,
                                       asn1Spec=rfc5652.ContentInfo(),
                                       decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        eci = asn1Object['content']['encapContentInfo']
        cmsContentTypesMap = opentypemap.get('cmsContentTypesMap')
        self.assertIn(eci['eContentType'], cmsContentTypesMap)
        self.assertEqual(rfc5934.id_ct_TAMP_statusResponse,
                         eci['eContentType'])

        tsr, rest = der_decoder(
            eci['eContent'],
            asn1Spec=cmsContentTypesMap[eci['eContentType']],
            decodeOpenTypes=True)
        self.assertFalse(rest)
        self.assertTrue(tsr.prettyPrint())
        self.assertEqual(eci['eContent'], der_encoder(tsr))
        self.assertEqual(2, tsr['version'])
        self.assertEqual(univ.Null(""), tsr['query']['target'])
        self.assertEqual(1568307071, tsr['query']['seqNum'])
        self.assertFalse(tsr['usesApex'])

        count = 0

        for tai in tsr['response']['verboseResponse']['taInfo']:
            count += 1
            self.assertEqual(1, tai['taInfo']['version'])

        self.assertEqual(3, count)
Ejemplo n.º 20
0
    def testDerCodec(self):
        # The id_ce_criticalPoison is not automatically added to the map.
        # Normally certificates that contiain it are rejected.
        certificateExtensionsMap = opentypemap.get('certificateExtensionsMap')
        self.assertNotIn(rfc6962.id_ce_criticalPoison, certificateExtensionsMap)

        extn_map = { rfc6962.id_ce_criticalPoison: univ.Null(""), }
        extn_map.update(certificateExtensionsMap)

        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))

        extn_list = []

        for extn in asn1Object['tbsCertificate']['extensions']:
            extn_list.append(extn['extnID'])
            ev, rest = der_decoder(extn['extnValue'],
                asn1Spec=extn_map[extn['extnID']])
            self.assertFalse(rest)
            if not ev == univ.Null(""):
                self.assertTrue(ev.prettyPrint())
            self.assertEqual(extn['extnValue'], der_encoder(ev))

        self.assertIn(rfc6962.id_ce_criticalPoison, extn_list)
Ejemplo n.º 21
0
    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))

        self.assertEqual(rfc5652.id_ct_authData, asn1Object['contentType'])

        ad, rest = der_decoder(asn1Object['content'],
                               asn1Spec=rfc5652.AuthenticatedData())
        self.assertFalse(rest)
        self.assertTrue(ad.prettyPrint())
        self.assertEqual(asn1Object['content'], der_encoder(ad))

        self.assertEqual(0, ad['version'])
        self.assertEqual(rfc6210.id_alg_MD5_XOR_EXPERIMENT,
                         ad['digestAlgorithm']['algorithm'])

        algorithmIdentifierMap = opentypemap.get('algorithmIdentifierMap')
        mac_alg_p, rest = der_decoder(ad['digestAlgorithm']['parameters'],
                                      asn1Spec=algorithmIdentifierMap[
                                          ad['digestAlgorithm']['algorithm']])
        self.assertFalse(rest)
        self.assertTrue(mac_alg_p.prettyPrint())
        self.assertEqual(ad['digestAlgorithm']['parameters'],
                         der_encoder(mac_alg_p))

        self.assertEqual("0x01020304", mac_alg_p.prettyPrint()[:10])
Ejemplo n.º 22
0
    def testDerCodec(self):
        substrate = pem.readBase64fromText(self.smime_capabilities_pem_text)
        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        expectedCaps = [
            rfc6664.rsaEncryption,
            rfc6664.id_RSAES_OAEP,
            rfc6664.id_RSASSA_PSS,
            rfc6664.id_dsa,
            rfc6664.dhpublicnumber,
            rfc6664.id_ecPublicKey,
            rfc6664.id_ecMQV,
        ]

        count = 0
        smimeCapabilityMap = opentypemap.get('smimeCapabilityMap')
        for cap in asn1Object:
            if cap['capabilityID'] in expectedCaps:
                self.assertIn(cap['capabilityID'], smimeCapabilityMap)
                cap_p, rest = der_decoder(
                    cap['parameters'],
                    asn1Spec=rfc5751.smimeCapabilityMap[cap['capabilityID']])
                self.assertFalse(rest)
                self.assertTrue(cap_p.prettyPrint())
                self.assertEqual(cap['parameters'], der_encoder(cap_p))
                count += 1

        self.assertEqual(len(expectedCaps), count)
Ejemplo n.º 23
0
    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))

        algorithmIdentifierMap = opentypemap.get('algorithmIdentifierMap')
        ea = asn1Object['encryptionAlgorithm']
        self.assertEqual(rfc8018.id_PBES2, ea['algorithm'])
        self.assertIn(ea['algorithm'], algorithmIdentifierMap)

        params, rest = der_decoder(
            ea['parameters'], asn1Spec=algorithmIdentifierMap[ea['algorithm']])
        self.assertFalse(rest)
        self.assertTrue(params.prettyPrint())
        self.assertEqual(ea['parameters'], der_encoder(params))

        kdf = params['keyDerivationFunc']
        self.assertEqual(rfc7914.id_scrypt, kdf['algorithm'])
        self.assertIn(kdf['algorithm'], algorithmIdentifierMap)

        kdfp, rest = der_decoder(
            kdf['parameters'],
            asn1Spec=algorithmIdentifierMap[kdf['algorithm']])
        self.assertFalse(rest)
        self.assertTrue(kdfp.prettyPrint())
        self.assertTrue(kdf['parameters'], der_encoder(kdfp))
        self.assertEqual(1048576, kdfp['costParameter'])
Ejemplo n.º 24
0
    def testOtherRecipientInfoMap(self):
        otherRecipientInfoMap = opentypemap.get('otherRecipientInfoMap')
        substrate = pem.readBase64fromText(self.key_trans_psk_pem_text)
        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))

        self.assertEqual(
            rfc5083.id_ct_authEnvelopedData, asn1Object['contentType'])

        aed, rest = der_decoder(
            asn1Object['content'],
            asn1Spec=rfc5083.AuthEnvelopedData())

        self.assertFalse(rest)
        self.assertTrue(aed.prettyPrint())
        self.assertEqual(asn1Object['content'], der_encoder(aed)) 
        self.assertEqual(0, aed['version'])

        ri = aed['recipientInfos'][0]
        self.assertIn(ri['ori']['oriType'], otherRecipientInfoMap)

        ori, rest = der_decoder(
            ri['ori']['oriValue'],
            asn1Spec=rfc5652.otherRecipientInfoMap[ri['ori']['oriType']])

        self.assertFalse(rest)
        self.assertTrue(ori.prettyPrint())
        self.assertEqual(ri['ori']['oriValue'], der_encoder(ori))
Ejemplo n.º 25
0
    def testDerCodec(self):

        substrate = pem.readBase64fromText(self.pem_text)

        layers = {}
        layers.update(opentypemap.get('cmsContentTypesMap'))

        getNextLayer = {
            rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
            rfc5652.id_signedData:
            lambda x: x['encapContentInfo']['eContentType'],
            rfc5636.id_kisa_tac_token: lambda x: None
        }

        getNextSubstrate = {
            rfc5652.id_ct_contentInfo: lambda x: x['content'],
            rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'],
            rfc5636.id_kisa_tac_token: lambda x: None
        }

        next_layer = rfc5652.id_ct_contentInfo
        while next_layer:
            asn1Object, rest = der_decoder(substrate,
                                           asn1Spec=layers[next_layer])

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

            substrate = getNextSubstrate[next_layer](asn1Object)
            next_layer = getNextLayer[next_layer](asn1Object)

        self.assertEqual('2019', asn1Object['timeout'][:4])
        self.assertEqual('5dcdf44e', asn1Object['userKey'].prettyPrint()[-8:])
Ejemplo n.º 26
0
    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))

        cmsAttributesMap = opentypemap.get('cmsAttributesMap')
        found_spid_oid = False

        for attr in asn1Object:
            if attr['attrType'] in cmsAttributesMap:
                av, rest = der_decoder(
                    attr['attrValues'][0],
                    asn1Spec=cmsAttributesMap[attr['attrType']])
                self.assertFalse(rest)
                self.assertTrue(av.prettyPrint())
                self.assertEqual(attr['attrValues'][0], der_encoder(av))

                if attr['attrType'] == rfc5126.id_aa_ets_sigPolicyId:
                    spid_oid = rfc5126.SigPolicyId('1.3.6.1.4.1.22112.48.20')

                    self.assertEqual(spid_oid,
                                     av['signaturePolicyId']['sigPolicyId'])

                    found_spid_oid = True

        self.assertTrue(found_spid_oid)
Ejemplo n.º 27
0
    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))

        certificateExtensionsMap = opentypemap.get('certificateExtensionsMap')
        self.assertIn(rfc3820.id_pe_proxyCertInfo, certificateExtensionsMap)

        found_ppl = False
        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc3820.id_pe_proxyCertInfo:
                pci, rest = der_decoder(extn['extnValue'],
                                        asn1Spec=certificateExtensionsMap[
                                            rfc3820.id_pe_proxyCertInfo])
                self.assertFalse(rest)
                self.assertTrue(pci.prettyPrint())
                self.assertEqual(extn['extnValue'], der_encoder(pci))

                self.assertEqual(rfc3820.id_ppl_inheritAll,
                                 pci['proxyPolicy']['policyLanguage'])
                found_ppl = True

        self.assertTrue(found_ppl)
Ejemplo n.º 28
0
    def testDerCodec(self):
        substrate = pem.readBase64fromText(self.signed_message_pem_text)
        asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)

        self.assertFalse(rest)
        self.assertTrue(asn1Object.prettyPrint())
        self.assertEqual(substrate, der_encoder(asn1Object))
        self.assertEqual(rfc5652.id_signedData, asn1Object['contentType'])

        sd, rest = der_decoder(asn1Object['content'],
                               asn1Spec=rfc5652.SignedData())
        self.assertFalse(rest)
        self.assertTrue(sd.prettyPrint())
        self.assertEqual(asn1Object['content'], der_encoder(sd))

        cmsAttributesMap = opentypemap.get('cmsAttributesMap')
        for sa in sd['signerInfos'][0]['signedAttrs']:
            sat = sa['attrType']
            sav0 = sa['attrValues'][0]

            if sat in cmsAttributesMap:
                sav, rest = der_decoder(sav0, asn1Spec=cmsAttributesMap[sat])
                self.assertFalse(rest)
                self.assertTrue(sav.prettyPrint())
                self.assertEqual(sav0, der_encoder(sav))
Ejemplo n.º 29
0
    def testOpenTypes(self):
        openTypesMap = opentypemap.get('cmsAttributesMap').copy()
        for at in self.the_attrTypes:
            openTypesMap.update({at: univ.ObjectIdentifier()})

        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_or_oid in asn1Object:
            if attr_or_oid.getName() == 'attribute':
                valString = attr_or_oid['attribute']['attrValues'][
                    0].prettyPrint()

                if attr_or_oid['attribute']['attrType'] == self.the_attrTypes[
                        0]:
                    self.assertEqual(self.the_attrVals[0], valString)

                if attr_or_oid['attribute']['attrType'] == self.the_attrTypes[
                        1]:
                    self.assertEqual(self.the_attrVals[1], valString)
Ejemplo n.º 30
0
    def testDerCodec(self):
        substrate = pem.readBase64fromText(self.roa_pem_text)

        layers = {}
        layers.update(opentypemap.get('cmsContentTypesMap'))

        getNextLayer = {
            rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
            rfc5652.id_signedData:
            lambda x: x['encapContentInfo']['eContentType'],
            rfc6482.id_ct_routeOriginAuthz: lambda x: None
        }

        getNextSubstrate = {
            rfc5652.id_ct_contentInfo: lambda x: x['content'],
            rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'],
            rfc6482.id_ct_routeOriginAuthz: lambda x: None
        }

        next_layer = rfc5652.id_ct_contentInfo
        while next_layer:
            asn1Object, rest = der_decoder(substrate,
                                           asn1Spec=layers[next_layer])
            self.assertFalse(rest)
            self.assertTrue(asn1Object.prettyPrint())
            self.assertEqual(substrate, der_encoder(asn1Object))

            substrate = getNextSubstrate[next_layer](asn1Object)
            next_layer = getNextLayer[next_layer](asn1Object)

        self.assertEqual(0, asn1Object['version'])
        self.assertEqual(58363, asn1Object['asID'])