Skip to content

Commit

Permalink
new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ElDavoo authored Apr 3, 2024
1 parent 7db69ad commit 16f0340
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
35 changes: 35 additions & 0 deletions tests/test_createkey.py
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions tests/test_decrypt.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion tests/test_waencrypt.py → tests/test_encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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
assert new_check == orig_check
os.remove("tests/res/msgstore-new.db.crypt12")

0 comments on commit 16f0340

Please sign in to comment.