def test_from_metadata_missing_key(self): meta = { 'x-amz-matdesc': '{}', 'x-amz-iv': self.iv_64, } envelope = EncryptionEnvelope() envelope.from_metadata(meta)
def test_encoding(self): envelope = EncryptionEnvelope(self.mock_materials) envelope.iv = self.iv envelope.key = self.key assert_equal(envelope['x-amz-matdesc'], '{}') assert_equal(envelope.iv, self.iv) assert_equal(envelope['x-amz-iv'], self.iv_64) assert_equal(envelope.key, self.key) assert_equal(envelope['x-amz-key'], self.key_64)
def build_response_context(self, obj_metadata, context): self.envelope = EncryptionEnvelope() self.envelope.from_metadata(obj_metadata) self.deconstruct_envelope() cipher = crypto.aes_cipher(mode='CBC') cipher.iv = self.envelope.iv cipher.key = self.envelope.key context['cipher'] = cipher context['raw_body'] = cipher.decrypt(context['body']) return context
def test_from_metadata(self): meta = { 'x-amz-matdesc': '{}', 'x-amz-iv': self.iv_64, 'x-amz-key': self.key_64 } envelope = EncryptionEnvelope() envelope.from_metadata(meta) assert_equal(envelope['x-amz-matdesc'], '{}') assert_equal(envelope.iv, self.iv) assert_equal(envelope['x-amz-iv'], self.iv_64) assert_equal(envelope.key, self.key) assert_equal(envelope['x-amz-key'], self.key_64)
def test_from_metadata_empty(self): meta = {} envelope = EncryptionEnvelope() envelope.from_metadata(meta)
def test_from_metadata_missing_iv(self): meta = {'x-amz-matdesc': '{}', 'x-amz-key': self.key_64} envelope = EncryptionEnvelope() envelope.from_metadata(meta)
def test_from_metadata_missing_matdesc(self): meta = {'x-amz-iv': self.iv_64, 'x-amz-key': self.key_64} envelope = EncryptionEnvelope() envelope.from_metadata(meta)
def build_envelope(self, cipher): self.envelope = EncryptionEnvelope(self.provider.encryption_materials) self.envelope.iv = cipher.iv key = self.provider.key_for(self.provider.encryption_materials) self.envelope.key = crypto.aes_encrypt(key, cipher.key) return self.envelope