Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatabaseError: file is encrypted or is not a database #13

Open
PLNech opened this issue Mar 11, 2020 · 2 comments
Open

DatabaseError: file is encrypted or is not a database #13

PLNech opened this issue Mar 11, 2020 · 2 comments

Comments

@PLNech
Copy link

PLNech commented Mar 11, 2020

Hi @mattsta, first of all thanks for your work on this very-needed tool!

I'm hitting an issue when processing my encrypted backup according to the instructions. When I run ../scab.py, I get the following error:

Traceback (most recent call last):
  File "../scab.py", line 42, in <module>
    c.execute("SELECT json, id, name, profileName, type, members FROM conversations")
pysqlcipher3.dbapi2.DatabaseError: file is encrypted or is not a database

Thanks for your help 🙏

@MatejKovacic
Copy link

The same error here. Under Ubuntu Linux.

@501st-alpha1
Copy link

This error is probably caused by a mismatched cipher version. I ran into the same error when doing a manual export and posted my solution in the Signal-Desktop repo:

I tried the new export method again, and I was still getting the error that @ ywwg and @ rph8 have reported:

Error: file is encrypted or is not a database

I tried the cipher_compatibility command, but that didn't work either, and after digging around in the source code it seems like it shouldn't be needed anyway.

This was after installing the latest version of the Debian package from updates.signal.org (shows as version 1.39.4). I had Signal installed before, but when it launched it prompted me to delete the old data, so the database should be freshly created.

The error occurred after issuing any command after opening the database, even a simple SELECT query or .databases command. I know it wasn't an error copy/pasting the key, because this didn't work either:

sqlcipher ~/.config/Signal/sql/db.sqlite \
  "PRAGMA key = \"x'$(jq -r '.key' ~/.config/Signal/config.json)'\"; select * from messages limit 1;"

(I also tried the old export method, and it looks like the exportToDirectory function still exists, but even if I disable the test mode check, it gives an error on the key, so the old solution of {key: true} doesn't work.)

Finally I noticed that Debian only has SQLCipher 3, while Signal now uses SQLCipher 4. Rather than compile it from source, I found this Docker image, which contains version 4. I ran it like this:

docker run --rm --volume="$HOME/.config/Signal/sql/db.sqlite:/db.sqlite:rw" \
  --entrypoint sqlcipher yspreen/sqlcipher /db.sqlite \
  "PRAGMA key = \"x'$(jq -r '.key' ~/.config/Signal/config.json)'\"; select * from messages limit 1;"

and it worked for me. So the complete export command becomes:

docker run --rm --volume="$HOME/.config/Signal/sql/db.sqlite:/db.sqlite" \
  --volume="$(pwd)/plaintext.db:/plaintext.db" --entrypoint sqlcipher yspreen/sqlcipher db.sqlite \
  "PRAGMA key = \"x'$(jq -r '.key' ~/.config/Signal/config.json)'\"; attach database 'plaintext.db' as plaintext key ''; SELECT sqlcipher_export('plaintext'); DETACH DATABASE plaintext;"

(Note that the file plaintext.db must exist beforehand or it will be mounted as a directory. Do that with touch plaintext.db.)

In particular here, I see the error references pysqlcipher3, while current versions of Signal use SQLCipher 4, so that library probably needs to be updated.

I see this same error was reported in #10, and the associated pull request (#14) comments out a few lines that were added for compatibility with SQLCipher 3, so presumably that causes the library to fall back to the default of SQLCipher 4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants