Skip to content

Commit 77e3467

Browse files
committed
fix: handle invalid or wrong e2e key with a clear error message
KeyFactory.new() returns None for an unrecognised key file, and the library raises AttributeError when decrypt() is called with a None key. Validate the key object before decrypting and wrap db.decrypt() in a try/except so any decryption failure (wrong key, corrupt backup) exits with a clear message instead of a raw traceback.
1 parent 32cd0ec commit 77e3467

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎wa_media_archiver.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,20 @@ def _wa_root_resolver(fp):
10581058
db = DatabaseFactory.from_file(msg)
10591059
raw = msg.read() # payload only — from_file already consumed the header
10601060
key = KeyFactory.new(args.e2e_key)
1061-
decrypted = db.decrypt(key, raw)
1061+
if key is None:
1062+
logger.error(
1063+
f"Could not load decryption key from: {args.e2e_key}\n"
1064+
" Make sure --e2e_key points to a valid WhatsApp key file."
1065+
)
1066+
raise SystemExit(1)
1067+
try:
1068+
decrypted = db.decrypt(key, raw)
1069+
except Exception as e:
1070+
logger.error(
1071+
f"Decryption failed: {e}\n"
1072+
" The key file may not match this backup."
1073+
)
1074+
raise SystemExit(1)
10621075
try:
10631076
output_file = zlib.decompress(decrypted)
10641077
except zlib.error:

0 commit comments

Comments
 (0)