Adhesive icon indicating copy to clipboard operation
Adhesive copied to clipboard

MacOS: `sqlite3.DatabaseError: file is not a database`

Open xanoni opened this issue 3 years ago • 1 comments

The below may help people who can't get Adhesive to run. I suspect it's related to the sqlcipher3 dependency , which appears problematic on MacOS.

Trying to get the credentials (fails)

$ python3 -m venv .venv
$ . .venv/bin/activate
$ python3 -m adhesive.signal_auth
Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/Cellar/[email protected]/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Volumes/path/to/signal-adhesive/adhesive/signal_auth.py", line 78, in <module>
    username, password = get_credentials()
  File "/Volumes/path/to/signal-adhesive/adhesive/signal_auth.py", line 68, in get_credentials
    username = get_config_item('uuid_id')
  File "/Volumes/path/to/signal-adhesive/adhesive/signal_auth.py", line 56, in get_config_item
    row = fetchval(db(), 'SELECT json FROM items WHERE id = ?', (key,))
  File "/Volumes/path/to/signal-adhesive/adhesive/signal_auth.py", line 50, in fetchval
    row = db.execute(query, *args).fetchone()
sqlite3.DatabaseError: file is not a database

Dependencies

(Had some trouble installing sqlcipher3 and compiled it manually)

(.venv) > $ python --version
Python 3.9.7

(.venv) > $ pip freeze
anyio==2.2.0
asqlite==1.0.0
attrs==18.2.0
certifi==2021.5.30
cffi==1.14.6
cryptography==3.4.8
h11==0.12.0
httpcore==0.12.3
httpx==0.16.1
humanize==3.11.0
idna==3.2
Pillow==8.3.2
protobuf==3.17.3
pyaes==1.6.1
pyasn1==0.4.8
pycparser==2.20
pysqlcipher3==1.0.4
python-dateutil==2.8.1
rfc3986==1.5.0
rsa==4.7.2
semaphore-bot==0.10.1
signalstickers-client==3.0.0
six==1.16.0
sniffio==1.2.0
Telethon==1.23.0
toml==0.10.2

My workaround/solution

  1. Open Signal's db.sqlite in sqlitebrowser, decrypt it with the hex-encoded password from config.json (make sure to select "raw" and to prefix the key with "0x" image
  2. Save the full db as plaintext.sqlite ... (alternatively, you can just extract the required credentials via sqlitebrowser and skip steps 3-4)
  3. Patch adhesive/signal_auth.py to remove the decryption logic and point it at the plaintext db instead
diff --git a/adhesive/signal_auth.py b/adhesive/signal_auth.py
index 13b186c..41d9732 100644
--- a/adhesive/signal_auth.py
+++ b/adhesive/signal_auth.py
@@ -36,13 +36,12 @@ def db():
 		return _db.get()
 
 	config_path = get_config_path()
-	db_path = config_path / 'sql' / 'db.sqlite'
+	db_path = config_path / 'sql' / 'plaintext.sqlite'
 	if not db_path.is_file():
 		raise FileNotFoundError(db_path, 'not found')
 
 	db = sqlcipher.connect(db_path)
 	key = json.loads((config_path / 'config.json').read_text())['key']
-	db.execute(f'''PRAGMA key="x'{key}'"''')
 	_db.set(db)
 	return db
  1. Run it again (works)

xanoni avatar Sep 11 '21 11:09 xanoni

Please try this branch https://github.com/signalstickers/Adhesive/tree/pr/fix-adhesive-auth-on-mac

ioistired avatar Apr 16 '23 03:04 ioistired