smswithoutborders / lib_signal_double_ratchet_python

A Python library for implementing Signal's Double Ratchet algorithm and other cryptographic functions used in SMSWithoutBorders.
GNU General Public License v3.0
3 stars 0 forks source link

[Bug Report]: `Ratchets.decrypt` Method Raises `sqlcipher3.dbapi2.DatabaseError` #8

Closed PromiseFru closed 5 months ago

PromiseFru commented 5 months ago

When attempting to decrypt a message using the Ratchets.decrypt method, an sqlcipher3.dbapi2.DatabaseError is raised with the message "file is not a database."

Steps to Reproduce

from smswithoutborders_libsig.keypairs import x25519
from smswithoutborders_libsig.ratchets import States, Ratchets

alice_keystore_path = "/sample_alice.db"
bob_keystore_path = "/sample_bob.db"
client_keystore_path = "/sample_client.db"

alice_state = States()
bob_state = States()

alice = x25519(alice_keystore_path)
alice_public_key_original = alice.init()

bob = x25519(bob_keystore_path)
bob_public_key_original = bob.init()

SK = alice.agree(bob_public_key_original)
SK1 = bob.agree(alice_public_key_original)

original_plaintext = b"Hello world"

Ratchets.alice_init(
    alice_state,
    SK,
    bob_public_key_original,
    client_keystore_path,
)
header, client_ciphertext = Ratchets.encrypt(
    alice_state,
    original_plaintext,
    bob_public_key_original,
)

Ratchets.bob_init(bob_state, SK1, bob)
server_plaintext = Ratchets.decrypt(
    bob_state, header, client_ciphertext, bob_public_key_original
)

assert server_plaintext == original_plaintext

Stack Trace

Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tests/sample2.py", line 35, in <module>
    server_plaintext = Ratchets.decrypt(
  File "/venv/lib/python3.8/site-packages/smswithoutborders_libsig/ratchets.py", line 56, in decrypt
    DHRatchet(state, header)
  File "/venv/lib/python3.8/site-packages/smswithoutborders_libsig/protocols.py", line 118, in __init__
    state.DHs = GENERATE_DH(state.DHs.keystore_path)
  File "/venv/lib/python3.8/site-packages/smswithoutborders_libsig/protocols.py", line 125, in GENERATE_DH
    x.init()
  File "/venv/lib/python3.8/site-packages/smswithoutborders_libsig/keypairs.py", line 133, in init
    self.secret_key = Keypairs.store(pk, _pk, self.keystore_path, self.pnt_keystore)
  File "/venv/lib/python3.8/site-packages/smswithoutborders_libsig/keypairs.py", line 58, in store
    keystore = Keystore(keystore_path, secret_key)
  File "/venv/lib/python3.8/site-packages/smswithoutborders_libsig/keystore.py", line 18, in __init__
    self.create()
  File "/venv/lib/python3.8/site-packages/smswithoutborders_libsig/keystore.py", line 22, in create
    self.cursor.execute(f'''
sqlcipher3.dbapi2.DatabaseError: file is not a database
sherlockwisdom commented 5 months ago

Removing appended slash should solve the problem