smswithoutborders / lib_signal_double_ratchet_python

GNU General Public License v3.0
3 stars 0 forks source link

[Bug Report] `AttributeError` on Reinitializing `x25519` Object with Existing Database #1

Closed PromiseFru closed 4 months ago

PromiseFru commented 4 months ago

When reinitializing an x25519 object with an existing database, the method agree raises an AttributeError. This issue arises when attempting to reinitialize and use the x25519 object in another instance.

Steps to Reproduce:

  1. Initialize an x25519 object and perform key exchange.
  2. Delete the x25519 objects.
  3. Reinitialize the x25519 objects with the existing databases.
  4. Attempt to agree on a shared key using the agree method.

Code to Reproduce:

import os
import tempfile
from keypairs import x25519

def test_x25519_reinitialization():
    with tempfile.TemporaryDirectory() as tmp_path:
        alice_db_path = os.path.join(tmp_path, "alices_keys.db")
        bob_db_path = os.path.join(tmp_path, "bobs_keys.db")

        # Initial creation and key exchange
        alice = x25519(alice_db_path)
        bob = x25519(bob_db_path)

        alice_public_key = alice.init()
        bob_public_key = bob.init()

        del alice
        del bob

        # Reinitialization with existing databases
        alice = x25519(alice_db_path)
        bob = x25519(bob_db_path)

        # Attempt to agree on a shared key
        try:
            alice_shared_key = alice.agree(bob_public_key)
            bob_shared_key = bob.agree(alice_public_key)

            assert alice_shared_key == bob_shared_key
        except AttributeError as e:
            print(f"Error: {e}")

test_x25519_reinitialization()

Expected Behavior:

The agree method should work correctly after reinitializing the x25519 objects, and the shared keys should match.

Actual Behavior:

An AttributeError is raised indicating that the x25519 object has no attribute pnt_keystore.

Error Traceback:

    def agree(self, public_key, info=b"x25591_key_exchange", salt=None) -> bytes:
>       x = self.load_keystore(self.pnt_keystore, self.secret_key)
E       AttributeError: 'x25519' object has no attribute 'pnt_keystore'
sherlockwisdom commented 4 months ago

Added some instructions on how to reinitialize with pnt_keystore and secret. Hindsight, they have to be stored and retrieved for later use:

https://github.com/smswithoutborders/lib_signal_double_ratchet_python/pull/3/commits/844183cda1f178432159cd3e798b64e1ea07ade9

PromiseFru commented 4 months ago

Added some instructions on how to reinitialize with pnt_keystore and secret. Hindsight, they have to be stored and retrieved for later use:

844183c

@sherlockwisdom, we would need to add support for pnt_keystore and secret_key in the x25519 class for this to work. I have opened a PR for that: https://github.com/smswithoutborders/lib_signal_double_ratchet_python/pull/4.

sherlockwisdom commented 4 months ago

you can also do

x = x25519()
x.pnt_keystore = ...
x.secret_key = ...

merging pr