Skip to content

Instantly share code, notes, and snippets.

@xperylab
Created July 25, 2021 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xperylab/c780b207f0b5f0d8b8a1af7b17c86f56 to your computer and use it in GitHub Desktop.
Save xperylab/c780b207f0b5f0d8b8a1af7b17c86f56 to your computer and use it in GitHub Desktop.
PM : Decrypt Message
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