-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
I just discovered this issue because there was a book in my library that appeared to successfully decrypt, but when I tried to open it the book was still encrypted gibberish (or I guess technically wrongly decrypted gibberish). I then tried decrypting the same book from the command line with the obok.py script, and it succeeded. Looking at the logs (see below), it was clear that the plugin was finding a key that passed the plaintext check for the first encrypted file, but the CLI ruled that same key out because the next encrypted file check failed.
You can see in the code, the plugin decryption short-circuits the check after the first file passes, while the CLI script checks every file.
At first I assumed the check was short-circuited for performance reasons, but looking at the code it doesn't seem like it's very expensive, it's probably marginal compared to the cost of the actual decryption. So I think the fix is probably just to perform the check on every encrypted file, just like the CLI script.
Relevant logs from plugin:
...
Trying key: b'41ce833dca23272df38e57accbe88474'
Checking text:b'OC21-\x85\xd86%\x1b':
Perhaps utf-8 without BOM
Seems to be good text
Success!
Relevant logs from CLI (starting from the same key the plugin settled on, you can see how the very next test fails):
...
Trying key: 41ce833dca23272df38e57accbe88474
Checking text:b'OC21-\x85\xd86%\x1b':
Perhaps utf-8 without BOM
Seems to be good text
Checking text:b'\xfa\xad\xebsANN\x0b\xbf\xc7':
Perhaps utf-8 without BOM
Bad character at 0, value 250
Decryption failed.
Trying key: 77d78e5f9b92faa9441d043336abd571
Checking text:b'>\xb3\xef\xed\x1a9\xc4\x9auP':
Perhaps utf-8 without BOM
Bad character at 1, value 179
Decryption failed.
Trying key: 8ae806b963060ba6ee0f26ae497d1384
Checking text:b'\xe5w\x01\xae\xc31\xcc\x8dx\xde':
Perhaps utf-8 without BOM
Bad character at 0, value 229
Decryption failed.
Trying key: 7fc3649e345cdb8b29d957ccc360687b
Checking text:b'<?xml vers':
Perhaps utf-8 without BOM
Seems to be good text
Checking text:b'<?xml vers':
Perhaps utf-8 without BOM
Seems to be good text
... (Testing all the other files which also pass)
Decryption succeeded.