コード例 #1
0
    def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.xmpp_server_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))

        count = 0

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

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

                for gn in extnValue:
                    if gn['otherName'].hasValue():
                        if gn['otherName']['type-id'] == rfc4985.id_on_dnsSRV:
                            self.assertIn('im.example.com',
                                          gn['otherName']['value'])
                            count += 1

        self.assertEqual(2, count)
コード例 #2
0
ファイル: test_rfc6120.py プロジェクト: hugovk/pyasn1-modules
    def testDerCodec(self):
        substrate = pem.readBase64fromText(self.xmpp_server_cert_pem_text)
        asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec)
        assert not rest
        assert asn1Object.prettyPrint()
        assert der_encode(asn1Object) == substrate

        count = 0
        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc5280.id_ce_subjectAltName:
                extnValue, rest = der_decode(extn['extnValue'],
                    asn1Spec=rfc5280.SubjectAltName())
                assert not rest
                assert extnValue.prettyPrint()
                assert der_encode(extnValue) == extn['extnValue']
                for gn in extnValue:
                    if gn['otherName'].hasValue():
                        gn_on = gn['otherName']
                        if gn_on['type-id'] == rfc6120.id_on_xmppAddr:
                            assert gn_on['type-id'] in rfc5280.anotherNameMap.keys()
                            spec = rfc5280.anotherNameMap[gn['otherName']['type-id']]
                            on, rest = der_decode(gn_on['value'], asn1Spec=spec)
                            assert not rest
                            assert on.prettyPrint()
                            assert der_encode(on) == gn_on['value']
                            assert on == u'im.example.com'
                            count += 1

        assert count == 1
コード例 #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))

        perm_id_oid = rfc4043.id_on_permanentIdentifier
        assigner_oid = univ.ObjectIdentifier('1.3.6.1.4.1.22112.48')
        permanent_identifier_found = False

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

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

                for gn in extnValue:
                    if gn['otherName'].hasValue():
                        on = gn['otherName']
                        self.assertEqual(perm_id_oid, on['type-id'])
                        self.assertEqual(assigner_oid, on['value']['assigner'])
                        permanent_identifier_found = True

        self.assertTrue(permanent_identifier_found)
コード例 #4
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))

        nai_realm_oid = rfc7585.id_on_naiRealm
        nai_realm_found = False

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

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

                for gn in extnValue:
                    if gn['otherName'].hasValue():
                        self.assertEqual(nai_realm_oid,
                                         gn['otherName']['type-id'])
                        self.assertIn('example', gn['otherName']['value'])

                        nai_realm_found = True

        self.assertTrue(nai_realm_found)
コード例 #5
0
    def testDerCodec(self):
        substrate = pem.readBase64fromText(self.cert_pem_text)
        asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec)
        assert not rest
        assert asn1Object.prettyPrint()
        assert der_encode(asn1Object) == substrate

        perm_id_oid = rfc4043.id_on_permanentIdentifier
        assigner_oid = univ.ObjectIdentifier('1.3.6.1.4.1.22112.48')
        permanent_identifier_found = False

        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc5280.id_ce_subjectAltName:
                extnValue, rest = der_decode(extn['extnValue'],
                                             asn1Spec=rfc5280.SubjectAltName())
                assert not rest
                assert extnValue.prettyPrint()
                assert der_encode(extnValue) == extn['extnValue']

                for gn in extnValue:
                    if gn['otherName'].hasValue():
                        assert gn['otherName']['type-id'] == perm_id_oid
                        onValue, rest = der_decode(
                            gn['otherName']['value'],
                            asn1Spec=rfc4043.PermanentIdentifier())
                        assert not rest
                        assert onValue.prettyPrint()
                        assert der_encode(onValue) == gn['otherName']['value']
                        assert onValue['assigner'] == assigner_oid
                        permanent_identifier_found = True

        assert permanent_identifier_found
コード例 #6
0
ファイル: test_rfc7585.py プロジェクト: hugovk/pyasn1-modules
    def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.cert_pem_text)
        asn1Object, rest = der_decode(substrate,
            asn1Spec=self.asn1Spec,
            decodeOpenTypes=True)
        assert not rest
        assert asn1Object.prettyPrint()
        assert der_encode(asn1Object) == substrate

        nai_realm_oid = rfc7585.id_on_naiRealm
        nai_realm_found = False

        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc5280.id_ce_subjectAltName:
                extnValue, rest = der_decode(extn['extnValue'],
                    asn1Spec=rfc5280.SubjectAltName(),
                    decodeOpenTypes=True)
                assert not rest
                assert extnValue.prettyPrint()
                assert der_encode(extnValue) == extn['extnValue']

                for gn in extnValue:
                    if gn['otherName'].hasValue():
                        assert gn['otherName']['type-id'] == nai_realm_oid
                        assert 'example' in gn['otherName']['value']
                        nai_realm_found = True

        assert nai_realm_found
コード例 #7
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_PEPSI = False
        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc5280.id_ce_subjectAltName:
                extnValue, rest = der_decoder(
                    extn['extnValue'],
                    asn1Spec=rfc5280.SubjectAltName(),
                    decodeOpenTypes=True)

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

                for gn in extnValue:
                    if gn['otherName'].hasValue():
                        pepsi = gn['otherName']['value']['pEPSI']
                        self.assertEqual('e6809ff3ea',
                                         pepsi.prettyPrint()[2:12])

                        found_PEPSI = True

        self.assertTrue(found_PEPSI)
コード例 #8
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
        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'],
                                          rfc5280.anotherNameMap)

                            spec = rfc5280.anotherNameMap[gn_on['type-id']]

                            on, rest = der_decoder(gn_on['value'],
                                                   asn1Spec=spec)

                            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)
コード例 #9
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

        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'],
                                          rfc5280.anotherNameMap)

                            spec = rfc5280.anotherNameMap[gn['otherName']
                                                          ['type-id']]
                            on, rest = der_decoder(gn_on['value'],
                                                   asn1Spec=spec)

                            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)
コード例 #10
0
ファイル: test_rfc6120.py プロジェクト: hugovk/pyasn1-modules
    def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.xmpp_server_cert_pem_text)
        asn1Object, rest = der_decode(substrate,
            asn1Spec=self.asn1Spec,
            decodeOpenTypes=True)
        assert not rest
        assert asn1Object.prettyPrint()
        assert der_encode(asn1Object) == substrate

        count = 0
        for extn in asn1Object['tbsCertificate']['extensions']:
            if extn['extnID'] == rfc5280.id_ce_subjectAltName:
                extnValue, rest = der_decode(extn['extnValue'],
                    asn1Spec=rfc5280.SubjectAltName(), decodeOpenTypes=True)
                assert not rest
                assert extnValue.prettyPrint()
                assert der_encode(extnValue) == extn['extnValue']
                for gn in extnValue:
                    if gn['otherName'].hasValue():
                        if gn['otherName']['type-id'] == rfc6120.id_on_xmppAddr:
                            assert gn['otherName']['value'] == u'im.example.com'
                            count += 1

        assert count == 1