def test_kms_basic(self): if oss2.compat.is_py33: return id, key, token = self.get_sts() kms = AliKMSProvider(id, key, OSS_REGION, OSS_CMK, token, passphrase='1234') plain_key = kms.get_key() iv = kms.get_start() header = kms.build_header() self.assertEqual(plain_key, kms.decrypt_oss_meta_data(header, 'x-oss-meta-oss-crypto-key')) self.assertEqual(iv, kms.decrypt_oss_meta_data(header, 'x-oss-meta-oss-crypto-start', lambda x: int(x))) self.assertEqual(None, kms.decrypt_oss_meta_data(header, '1231'))
def test_kms_adapter(self): if oss2.compat.is_py33: return content = b'1234'*10 kms = AliKMSProvider(OSS_ID, OSS_SECRET, OSS_REGION, OSS_CMK) key = kms.get_key() start = kms.get_start() adapter = kms.make_encrypt_adapter(content, key, start) encrypt_content = adapter.read() self.assertNotEqual(content, encrypt_content) adapter1 = kms.make_decrypt_adapter(encrypt_content, key, start) self.assertEqual(content, adapter1.read())
def test_kms_adapter(self): if oss2.compat.is_py33: return content = b'1234' * 10 kms = AliKMSProvider(OSS_ID, OSS_SECRET, OSS_REGION, OSS_CMK) key = kms.get_key() start = kms.get_start() adapter = kms.make_encrypt_adapter(content, key, start) encrypt_content = adapter.read() self.assertNotEqual(content, encrypt_content) adapter1 = kms.make_decrypt_adapter(encrypt_content, key, start) self.assertEqual(content, adapter1.read())
def test_kms_basic(self): if oss2.compat.is_py33: return id, key, token = self.get_sts() kms = AliKMSProvider(id, key, OSS_REGION, OSS_CMK, token, passphrase='1234') plain_key = kms.get_key() iv = kms.get_start() header = kms.build_header() self.assertEqual( plain_key, kms.decrypt_oss_meta_data(header, 'x-oss-meta-oss-crypto-key')) self.assertEqual( iv, kms.decrypt_oss_meta_data(header, 'x-oss-meta-oss-crypto-start', lambda x: int(x))) self.assertEqual(None, kms.decrypt_oss_meta_data(header, '1231'))