示例#1
0
    def _deserialize_entity(self, ctxt, entity):
        try:
            if self._key is not None:
                estr = cu.decrypt_data(cu.decode_data(entity), self._key)
                entity = jsonutils.loads(estr)
        except (ValueError, TypeError):
            return entity

        return entity
示例#2
0
    def _deserialize_context(self, ctxt):
        try:
            if self._key is not None:
                cstr = cu.decrypt_data(cu.decode_data(ctxt['context']),
                                       self._key)
                ctxt = jsonutils.loads(cstr)
        except (ValueError, TypeError):
            return ctxt

        return ctxt
示例#3
0
    def test_encryp_decrypt(self):
        key = 'my_secure_key'
        for size in range(1, 100):
            orig_data = Random.new().read(size)
            orig_encoded = crypto_utils.encode_data(orig_data)
            encrypted = crypto_utils.encrypt_data(orig_encoded, key)
            encoded = crypto_utils.encode_data(encrypted)
            decoded = crypto_utils.decode_data(encoded)
            decrypted = crypto_utils.decrypt_data(decoded, key)
            final_decoded = crypto_utils.decode_data(decrypted)

            self.assertEqual(orig_data, final_decoded,
                             "Decrypted data did not match original")
示例#4
0
    def test_encryp_decrypt(self):
        key = 'my_secure_key'
        for size in range(1, 100):
            orig_data = os.urandom(size)
            orig_encoded = crypto_utils.encode_data(orig_data)
            encrypted = crypto_utils.encrypt_data(orig_encoded, key)
            encoded = crypto_utils.encode_data(encrypted)
            decoded = crypto_utils.decode_data(encoded)
            decrypted = crypto_utils.decrypt_data(decoded, key)
            final_decoded = crypto_utils.decode_data(decrypted)

            self.assertEqual(orig_data, final_decoded,
                             "Decrypted data did not match original")
示例#5
0
    def _deserialize_entity(self, ctxt, entity):
        try:
            entity = jsonutils.loads(entity)
            instance_id = entity['csz-instance-id']
        except (ValueError, TypeError):
            return entity

        instance_key = get_instance_encryption_key(instance_id)

        estr = cu.decrypt_data(cu.decode_data(entity['entity']), instance_key)
        entity = jsonutils.loads(estr)

        return entity
    def _deserialize_entity(self, ctxt, entity):
        try:
            entity = jsonutils.loads(entity)
            instance_id = entity['csz-instance-id']
        except (ValueError, TypeError):
            return entity

        instance_key = get_instance_encryption_key(instance_id)

        estr = cu.decrypt_data(cu.decode_data(entity['entity']),
                               instance_key)
        entity = jsonutils.loads(estr)

        return entity
    def _deserialize_context(self, ctxt):
        try:
            instance_id = ctxt.get('csz-instance-id', None)

            if instance_id is not None:
                instance_key = get_instance_encryption_key(instance_id)

                cstr = cu.decrypt_data(cu.decode_data(ctxt['context']),
                                       instance_key)
                ctxt = jsonutils.loads(cstr)
        except (ValueError, TypeError):
            return ctxt

        ctxt['instance_id'] = instance_id
        return ctxt
示例#8
0
    def _deserialize_context(self, ctxt):
        try:
            instance_id = ctxt.get('csz-instance-id', None)

            if instance_id is not None:
                instance_key = get_instance_encryption_key(instance_id)

                cstr = cu.decrypt_data(cu.decode_data(ctxt['context']),
                                       instance_key)
                ctxt = jsonutils.loads(cstr)
        except (ValueError, TypeError):
            return ctxt

        ctxt['instance_id'] = instance_id
        return ctxt
示例#9
0
    def test_decrypt(self):
        key = 'my_secure_key'

        for encoded, expected in (
                # byte string: b'Hello World!'
            ('ZUhoNGVIaDRlSGg0ZUhoNL9PmM70hVcQ7j/kYF7Pw+BT7VSfsht0VsCIxy'
             'KNN0NH', b'Hello World!'),

                # Unicoded string: u'Unicode:\u20ac'
            ('ZUhoNGVIaDRlSGg0ZUhoNIHZLIuIcQCRwWY7PR2y7JcqoDf4ViqXIfh0uE'
             'Rbg9BA', b'Unicode:\xe2\x82\xac'),
        ):
            decoded = crypto_utils.decode_data(encoded)
            decrypted = crypto_utils.decrypt_data(decoded, key)
            final_decoded = crypto_utils.decode_data(decrypted)
            self.assertEqual(expected, final_decoded)
示例#10
0
    def test_decrypt(self):
        key = 'my_secure_key'

        for encoded, expected in (
            # byte string: b'Hello World!'
            ('ZUhoNGVIaDRlSGg0ZUhoNL9PmM70hVcQ7j/kYF7Pw+BT7VSfsht0VsCIxy'
                'KNN0NH',
             b'Hello World!'),

            # Unicoded string: u'Unicode:\u20ac'
            ('ZUhoNGVIaDRlSGg0ZUhoNIHZLIuIcQCRwWY7PR2y7JcqoDf4ViqXIfh0uE'
                'Rbg9BA',
             b'Unicode:\xe2\x82\xac'),
        ):
            decoded = crypto_utils.decode_data(encoded)
            decrypted = crypto_utils.decrypt_data(decoded, key)
            final_decoded = crypto_utils.decode_data(decrypted)
            self.assertEqual(expected, final_decoded)
示例#11
0
 def deprocess_contents(processed_contents):
     encrypted_contents = crypto_utils.decode_data(processed_contents)
     return crypto_utils.decrypt_data(
         encrypted_contents, Modules.ENCRYPT_KEY)
示例#12
0
 def deprocess_contents(processed_contents):
     encrypted_contents = crypto_utils.decode_data(processed_contents)
     return crypto_utils.decrypt_data(
         encrypted_contents, Modules.ENCRYPT_KEY)