Пример #1
0
    def testOpenTypes(self):
        substrate = pem.readBase64fromText(self.signed_receipt_pem_text)
        asn1Object, rest = der_decode(substrate,
                                      asn1Spec=self.asn1Spec,
                                      decodeOpenTypes=True)
        assert not rest
        assert asn1Object.prettyPrint()
        assert der_encode(asn1Object) == substrate

        assert asn1Object['contentType'] in rfc5652.cmsContentTypesMap.keys()
        assert asn1Object['contentType'] == rfc5652.id_signedData

        sd = asn1Object['content']
        assert sd['version'] == rfc5652.CMSVersion().subtype(value='v3')
        assert sd['encapContentInfo'][
            'eContentType'] in rfc5652.cmsContentTypesMap.keys()
        assert sd['encapContentInfo']['eContentType'] == rfc2634.id_ct_receipt

        for sa in sd['signerInfos'][0]['signedAttrs']:
            assert sa['attrType'] in rfc5652.cmsAttributesMap.keys()
            if sa['attrType'] == rfc2634.id_aa_msgSigDigest:
                sa['attrValues'][0].prettyPrint()[:10] == '0x167378'

        # Since receipt is inside an OCTET STRING, decodeOpenTypes=True cannot
        # automatically decode it
        receipt, rest = der_decode(sd['encapContentInfo']['eContent'],
                                   asn1Spec=rfc5652.cmsContentTypesMap[
                                       sd['encapContentInfo']['eContentType']])
        assert receipt['version'] == rfc2634.ESSVersion().subtype(value='v1')
Пример #2
0
    def testDerCodec(self):
        substrate = pem.readBase64fromText(self.signed_receipt_pem_text)
        asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec)
        assert not rest
        assert asn1Object.prettyPrint()
        assert der_encode(asn1Object) == substrate

        assert asn1Object['contentType'] == rfc5652.id_signedData
        sd, rest = der_decode(asn1Object['content'],
                              asn1Spec=rfc5652.SignedData())
        assert not rest
        assert sd.prettyPrint()
        assert der_encode(sd) == asn1Object['content']

        assert sd['encapContentInfo']['eContentType'] == rfc2634.id_ct_receipt
        receipt, rest = der_decode(sd['encapContentInfo']['eContent'],
                                   asn1Spec=rfc2634.Receipt())
        assert not rest
        assert receipt.prettyPrint()
        assert der_encode(receipt) == sd['encapContentInfo']['eContent']
        assert receipt['version'] == rfc2634.ESSVersion().subtype(value='v1')

        for sa in sd['signerInfos'][0]['signedAttrs']:
            sat = sa['attrType']
            sav0 = sa['attrValues'][0]

            if sat in rfc5652.cmsAttributesMap.keys():
                sav, rest = der_decode(sav0,
                                       asn1Spec=rfc5652.cmsAttributesMap[sat])
                assert not rest
                assert sav.prettyPrint()
                assert der_encode(sav) == sav0