matrix_sdk::encryption

Module recovery

Source
Expand description

The recovery module

The recovery module attempts to provide a unified and simplified view over the secret storage and backup subsystems.

Note: If you are using this module, do not use the SecretStorage and Backups subsystems directly. This module makes assumptions that might be broken by the direct usage of the respective lower level modules.

Note: The term Recovery used in this submodule is not the same as the Recovery key mentioned in the spec. The recovery key from the spec is solely about backups, while the term recovery in this file includes both the backups and the secret storage subsystems. The recovery key mentioned in this file is the secret storage key.

You should configure your client to bootstrap cross-signing automatically and may choose to let your client automatically create a backup, if it doesn’t exist, as well:

use matrix_sdk::{encryption::EncryptionSettings, Client};

let client = Client::builder()
    .homeserver_url(homeserver)
    .with_encryption_settings(EncryptionSettings {
        auto_enable_cross_signing: true,
        auto_enable_backups: true,
        ..Default::default()
    })
    .build()
    .await?;

§Examples

For a newly registered user you will want to enable recovery, either immediately or before the user logs out.

let recovery = client.encryption().recovery();

// Create a new recovery key, you can use the provided passphrase, or the returned recovery key
// to recover.
let recovery_key = recovery
    .enable()
    .wait_for_backups_to_upload()
    .with_passphrase("my passphrase")
    .await;

If the user logs in with another device, you’ll want to let the user recover its secrets by entering the recovery key or recovery passphrase.

let recovery = client.encryption().recovery();

// Create a new recovery key, you can use the provided passphrase, or the returned recovery key
// to recover.
recovery.recover("my recovery key or passphrase").await;

Modules§

  • Named futures for the recovery support.

Structs§

  • A helper struct that handles continues resetting a user’s crypto identity after authentication was required and re-enabling backups (if necessary) at the end of it
  • The recovery manager for the Client.

Enums§

Type Aliases§