diff --git a/tests/test_createkey.py b/tests/test_createkey.py new file mode 100644 index 0000000..b78e9c5 --- /dev/null +++ b/tests/test_createkey.py @@ -0,0 +1,35 @@ +import os +import zlib + +from wa_crypt_tools.lib.key.key15 import Key15 +from wa_crypt_tools.lib.key.key14 import Key14 +from wa_crypt_tools.lib.key.keyfactory import KeyFactory +from wa_crypt_tools.lib.props import Props +from hashlib import sha512 + +class Test_CreateKey: + def test_createkey(self): + key: Key15 = Key15(key= + bytes.fromhex( + '6730a595a1484d0c39c101dc0ac82ec5e401bb6f0e1b8ee2dc104a6b3687f017' + )) + keyb: bytes = key.dump() + keyb_digest = sha512(keyb).digest() + with open("tests/res/encrypted_backup.key", 'rb') as f: + orig_check = sha512(f.read()).digest() + assert keyb_digest == orig_check + + def test_createkey14(self): + key: Key14 = Key14(key= + bytes.fromhex( + '3a146d9bbd8b6311d962c71619c0c2cce3ce694ea4a0f3f600e271380e1226c6' + ), + serversalt=bytes.fromhex('cd788b1b4625f50d3fccdeac94e1ff638899733b77a224ff614918363901f044'), + googleid=bytes.fromhex('92683e735c88727eef9486911f3ac6fa'), + key_version=b'\x02', + cipher_version=b'\x00\x01') + keyb: bytes = key.dump() + keyb_digest = sha512(keyb).digest() + with open("tests/res/key", 'rb') as f: + orig_check = sha512(f.read()).digest() + assert keyb_digest == orig_check \ No newline at end of file diff --git a/tests/test_decrypt.py b/tests/test_decrypt.py new file mode 100644 index 0000000..59a5d10 --- /dev/null +++ b/tests/test_decrypt.py @@ -0,0 +1,47 @@ +import os +import zlib + +from wa_crypt_tools.lib.db.db12 import Database12 +from wa_crypt_tools.lib.db.db14 import Database14 +from wa_crypt_tools.lib.db.db15 import Database15 +from wa_crypt_tools.lib.db.dbfactory import DatabaseFactory +from wa_crypt_tools.lib.key.keyfactory import KeyFactory +from wa_crypt_tools.lib.props import Props +from hashlib import sha512 + +class Test_Decryption: + def test_decryption15(self): + key = KeyFactory.new("tests/res/encrypted_backup.key") + f = open("tests/res/msgstore.db.crypt15",'rb') + db = DatabaseFactory.from_file(f) + encrypted = f.read() + decrypted_db = db.decrypt(key, encrypted) + decrypted_db = zlib.decompress(decrypted_db) + new_check = sha512(decrypted_db).digest() + with open("tests/res/msgstore.db", 'rb') as f: + orig_check = sha512(f.read()).digest() + assert new_check == orig_check + + def test_decryption14(self): + key = KeyFactory.new("tests/res/key") + f = open("tests/res/msgstore.db.crypt14",'rb') + db = DatabaseFactory.from_file(f) + encrypted = f.read() + decrypted_db = db.decrypt(key, encrypted) + decrypted_db = zlib.decompress(decrypted_db) + new_check = sha512(decrypted_db).digest() + with open("tests/res/msgstore.db", 'rb') as f: + orig_check = sha512(f.read()).digest() + assert new_check == orig_check + + def test_decryption12(self): + key = KeyFactory.new("tests/res/key") + f = open("tests/res/msgstore.db.crypt12",'rb') + db = DatabaseFactory.from_file(f) + encrypted = f.read() + decrypted_db = db.decrypt(key, encrypted) + decrypted_db = zlib.decompress(decrypted_db) + new_check = sha512(decrypted_db).digest() + with open("tests/res/msgstore.db", 'rb') as f: + orig_check = sha512(f.read()).digest() + assert new_check == orig_check \ No newline at end of file diff --git a/tests/test_waencrypt.py b/tests/test_encrypt.py similarity index 92% rename from tests/test_waencrypt.py rename to tests/test_encrypt.py index 2a5349c..0c72ef5 100644 --- a/tests/test_waencrypt.py +++ b/tests/test_encrypt.py @@ -27,6 +27,7 @@ def test_encryption15(self): with open("tests/res/msgstore.db.crypt15", 'rb') as f: orig_check = sha512(f.read()).digest() assert new_check == orig_check + os.remove("tests/res/msgstore-new.db.crypt15") def test_encryption14(self): key = KeyFactory.new("tests/res/key") @@ -46,6 +47,7 @@ def test_encryption14(self): with open("tests/res/msgstore.db.crypt14", 'rb') as f: orig_check = sha512(f.read()).digest() assert new_check == orig_check + os.remove("tests/res/msgstore-new.db.crypt14") def test_encryption14_noexpiry(self): key = KeyFactory.new("tests/res/key") @@ -65,6 +67,7 @@ def test_encryption14_noexpiry(self): with open("tests/res/msgstore-noexpiry.db.crypt14", 'rb') as f: orig_check = sha512(f.read()).digest() assert new_check == orig_check + os.remove("tests/res/msgstore-new.db.crypt14") def test_encryption12(self): key = KeyFactory.new("tests/res/key") @@ -83,4 +86,5 @@ def test_encryption12(self): f.write(data) with open("tests/res/msgstore.db.crypt12", 'rb') as f: orig_check = sha512(f.read()).digest() - assert new_check == orig_check \ No newline at end of file + assert new_check == orig_check + os.remove("tests/res/msgstore-new.db.crypt12") \ No newline at end of file