Skip to content
This repository was archived by the owner on May 9, 2020. It is now read-only.

Commit 476123e

Browse files
committed
Replaced encrypted_data_bag_item AES encryption method to AES256Cipher
1 parent b5b6ea5 commit 476123e

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

chef/encrypted_data_bag_item.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from chef.exceptions import ChefUnsupportedEncryptionVersionError, ChefDecryptionError
2-
from M2Crypto.EVP import Cipher
2+
from chef.aes import AES256Cipher
33

44
import os
55
import hmac
@@ -52,14 +52,13 @@ def __init__(self, key, data):
5252
self.key = hashlib.sha256(key).digest()
5353
self.data = data
5454
self.iv = os.urandom(8).encode('hex')
55-
self.encryptor = Cipher(alg=EncryptedDataBagItem.AES_MODE, key=self.key, iv=self.iv, op=1)
55+
self.encryptor = AES256Cipher(key=self.key, iv=self.iv)
5656
self.encrypted_data = None
5757

5858
def encrypt(self):
5959
if self.encrypted_data is None:
6060
data = json.dumps({'json_wrapper': self.data})
61-
update_data = self.encryptor.update(data)
62-
self.encrypted_data = update_data + self.encryptor.final()
61+
self.encrypted_data = self.encryptor.encrypt(data)
6362
del self.encryptor
6463
return self.encrypted_data
6564

@@ -108,10 +107,10 @@ def __init__(self, key, data, iv):
108107
self.key = hashlib.sha256(key).digest()
109108
self.data = base64.standard_b64decode(data)
110109
self.iv = base64.standard_b64decode(iv)
111-
self.decryptor = Cipher(alg=EncryptedDataBagItem.AES_MODE, key=self.key, iv=self.iv, op=0)
110+
self.decryptor = AES256Cipher(key=self.key, iv=self.iv)
112111

113112
def decrypt(self):
114-
value = self.decryptor.update(self.data) + self.decryptor.final()
113+
value = self.decryptor.decrypt(self.data)
115114
del self.decryptor
116115
# Strip all the whitespace and sequence control characters
117116
value = value.strip(reduce(lambda x,y: "%s%s" % (x,y), EncryptedDataBagItem.Decryptors.STRIP_CHARS))

0 commit comments

Comments
 (0)