Skip to content

Commit

Permalink
refactor(MaltegoOAuth): use inbuilt primitives_padding.PKCS7() unpadding
Browse files Browse the repository at this point in the history
  • Loading branch information
tendai-zw committed Jan 19, 2021
1 parent 11ac443 commit 1885caa
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions maltego_trx/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import base64

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives import serialization, padding as primitives_padding
from cryptography.hazmat.primitives.asymmetric import padding as asymmetric_padding
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from requests.auth import AuthBase

Expand Down Expand Up @@ -32,7 +32,7 @@ def _rsa_decrypt(private_key_path=None, ciphertext=None, password=None):
private_key = serialization.load_pem_private_key(key_file.read(),
password,
backend=None)
plaintext = private_key.decrypt(ciphertext, padding.PKCS1v15())
plaintext = private_key.decrypt(ciphertext, asymmetric_padding.PKCS1v15())

return plaintext

Expand All @@ -46,9 +46,8 @@ def _aes_decrypt(key=None, ciphertext=None):
decryptor = cipher.decryptor();
ciphertext = base64.b64decode(ciphertext)
padded_b64_plaintext = decryptor.update(ciphertext) + decryptor.finalize()

unpad = lambda data: data[:-ord(data[len(data) - 1:])]
plaintext = unpad(padded_b64_plaintext).decode('utf8')
unpadder = primitives_padding.PKCS7(128).unpadder()
plaintext = (unpadder.update(padded_b64_plaintext) + unpadder.finalize()).decode('utf8')
return plaintext

@classmethod
Expand Down

0 comments on commit 1885caa

Please sign in to comment.