Exemple #1
0
def _generate_encryption_data_dict(kek, cek, iv):
    '''
    Generates and returns the encryption metadata as a dict.

    :param object kek: The key encryption key. See calling functions for more information.
    :param bytes cek: The content encryption key.
    :param bytes iv: The initialization vector.
    :return: A dict containing all the encryption metadata.
    :rtype: dict
    '''
    # Encrypt the cek.
    wrapped_cek = kek.wrap_key(cek)

    # Build the encryption_data dict.
    # Use OrderedDict to comply with Java's ordering requirement.
    wrapped_content_key = OrderedDict()
    wrapped_content_key['KeyId'] = kek.get_kid()
    wrapped_content_key['EncryptedKey'] = _encode_base64(wrapped_cek)
    wrapped_content_key['Algorithm'] = kek.get_key_wrap_algorithm()

    encryption_agent = OrderedDict()
    encryption_agent['Protocol'] = _ENCRYPTION_PROTOCOL_V1
    encryption_agent['EncryptionAlgorithm'] = _EncryptionAlgorithm.AES_CBC_256

    encryption_data_dict = OrderedDict()
    encryption_data_dict['WrappedContentKey'] = wrapped_content_key
    encryption_data_dict['EncryptionAgent'] = encryption_agent
    encryption_data_dict['ContentEncryptionIV'] = _encode_base64(iv)
    encryption_data_dict['KeyWrappingMetadata'] = {'EncryptionLibrary': 'Python ' + __version__}

    return encryption_data_dict
Exemple #2
0
 def _assert_default_entity_json_no_metadata(self, entity):
     '''
     Asserts that the entity passed in matches the default entity.
     '''
     self.assertEqual(entity.age, '39')
     self.assertEqual(entity.sex, 'male')
     self.assertEqual(entity.married, True)
     self.assertEqual(entity.deceased, False)
     self.assertFalse(hasattr(entity, "optional"))
     self.assertFalse(hasattr(entity, "aquarius"))
     self.assertEqual(entity.ratio, 3.1)
     self.assertEqual(entity.evenratio, 3.0)
     self.assertEqual(entity.large, '933311100')
     self.assertEqual(entity.Birthday, '1973-10-04T00:00:00Z')
     self.assertEqual(entity.birthday, '1970-10-04T00:00:00Z')
     self.assertEqual(entity.binary, _encode_base64(b'binary'))
     self.assertIsInstance(entity.other, EntityProperty)
     self.assertEqual(entity.other.type, EdmType.INT32)
     self.assertEqual(entity.other.value, 20)
     self.assertEqual(entity.clsid, 'c9da6455-213d-42c9-9a79-3e9149a57833')
     self.assertTrue(hasattr(entity, "Timestamp"))
     self.assertIsInstance(entity.Timestamp, datetime)
     self.assertIsNotNone(entity.etag)
Exemple #3
0
def _to_entity_binary(value):
    return EdmType.BINARY, _encode_base64(value)