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

Introduce capability to import an existing registration #174

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Blackoverflow
Copy link

This should add the capability to import an existing registration.

I don't have deeper understanding of presage and only build what looked right.

Please comment if this is in the right direction and point out issues.

The examples do not compile, because SledStore is no module of the crate presage (anymore?).

@Schmiddiii
Copy link
Contributor

Just a few ideas:

I think it would be better to import that directly into the store instead of into the manager. The flow would therefore be:

  • Create an empty SledStore.
  • Import the registration into the SledStore.
  • Create the Manager from the new store (use from_registered).
  • Maybe some Manager-method to repopulate the contacts and other things in the new store.

I think it would also be even better to instead of just importing the registration to create a general "import from some store into another new store", and then not only import the registration but also contacts, messages, .... But that would certainly be more work.

@Blackoverflow
Copy link
Author

Thank you for your feedback!

I heavily borrowed from link_secondary_device and confirm_verification_code which are the other two functions which create registrations.

I think the registration of pre keys and setting of account capabilities are also vital parts of the import. Are there other things to do in order to get a working registration?

I understand your idea is to replace the block

let state = Registered::from_import(signal_servers, registration_info);

let rng = StdRng::from_entropy();

let mut manager = Manager {
    rng,
    config_store,
    state,
};

manager.config_store.save_state(&manager.state)?;

with

let state = Registered::from_import(signal_servers, registration_info);

config_store.save_state(&state)?;

let mut manager = Manager::load_registered(config_store)?;

correct?

Regarding the import of contacts and messages:
I had to start somewhere and prefer to work in small iterations.
When this MR is done, I continue with messages and at last contacts (because contacts can also be rediscovered).
Importing groups would also be useful, am I right?

@Schmiddiii
Copy link
Contributor

What I would suggest to do is something like:

let old_store = AStoreBasedOnYourCurrentData::new(some_old_path);
let new_store = SledStore::new(some_new_path, optional_passphrase);
migrate_stores(old_store, new_store);
let mut manager = Manager::load_registered(new_store)?;

Here AStoreBasedOnYourCurrentData is an implementation of presage::Store (possibly read-only if you don't plan to use that anymore) and migrate_stores takes all the data from the old_store (as a start, only the registration data, but can be expanded in the future to include everything else) and copies it into new_store (where the parameters are just general presage::Store, which can then be used to construct the manager.

While certainly more work then what you currently are doing, this will make general migration between stores possible, e.g. also in the future from SledStore to SqliteStore or anything else.

I think the registration of pre keys and setting of account capabilities are also vital parts of the import. Are there other things to do in order to get a working registration?

I am not that familiar with the Signal protocol, I would think that you will want to migrate:

  • Registration-struct (state)
  • (Signed) Pre-Keys (including offset)
  • (Sub-device) Sessions
  • Identity key pair
  • Sender Keys

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

Successfully merging this pull request may close these issues.

2 participants