Created
July 25, 2021 13:50
-
-
Save xperylab/c780b207f0b5f0d8b8a1af7b17c86f56 to your computer and use it in GitHub Desktop.
PM : Decrypt Message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pgpy | |
mainKey = keychainVal['NoneProtection'] | |
IVsize = 16 | |
def decryptWithMainKey(encrypted): | |
iv = encrypted[:IVsize] | |
cipher = AES.new(mainKey, AES.MODE_CTR, initial_value=iv, nonce=b'') | |
return cipher.decrypt(encrypted[IVsize:]) | |
with open('group.ch.protonmail.protonmail.plist','rb') as p : | |
prefplist = plistlib.load(p) | |
enc_val = prefplist['authKeychainStoreKeyProtectedWithMainKey'] | |
dec_val = decryptWithMainKey(enc_val) | |
keychainStorePlist1 = ccl_bplist.load(BytesIO(dec_val)) | |
keychainStorePlist = ccl_bplist.load(BytesIO(keychainStorePlist1[0])) | |
keychainStore = ccl_bplist.deserialise_NsKeyedArchiver(keychainStorePlist, parse_whole_structure=True) | |
privateKeyCoderKey = keychainStore['root']['NS.objects'][0]['privateKeyCoderKey'] | |
key, _ = pgpy.PGPKey.from_blob(privateKeyCoderKey) | |
pwdKey = keychainStore['root']['NS.objects'][0]['AuthCredential.Password'] | |
def decrypt_message(encm): | |
if('-----BEGIN PGP MESSAGE-----') in encm: | |
with key.unlock(pwdKey): | |
assert key.is_unlocked | |
message_from_blob = pgpy.PGPMessage.from_blob(encm) | |
decm = key.decrypt(message_from_blob).message | |
#print(decm) | |
return html.unescape(decm.encode('cp1252', errors='ignore').decode('utf8', errors='ignore')) | |
else: | |
return encm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment