Skip to main content

bitwarden_shared_unlock/
drivers.rs

1//! Drivers that need to be implemented per platform for the shared unlock system.
2
3use bitwarden_core::UserId;
4use bitwarden_crypto::SymmetricCryptoKey;
5
6use crate::LockState;
7
8/// Trait that implmeents the device's shared unlock driver. These functions need to be implemented
9/// in order to allow the shared unlock system to function.
10#[async_trait::async_trait]
11pub trait SharedUnlockDriver {
12    /// Lock the user with the given ID.
13    async fn lock_user(&self, user_id: UserId) -> Result<(), ()>;
14    /// Unlock the user with the given ID.
15    async fn unlock_user(&self, user_id: UserId, user_key: SymmetricCryptoKey) -> Result<(), ()>;
16    /// List all users that are currently locked or unlocked.
17    async fn list_users(&self) -> Vec<UserId>;
18    /// Get the lock state of the user with the given ID.
19    async fn get_user_lock_state(&self, user_id: UserId) -> LockState;
20    /// Get vault_url for the user with the given ID, if available. This is used to verify IPC
21    /// message sources
22    async fn get_vault_url(&self, user_id: UserId) -> Option<String>;
23    /// Suppress the vault timeout for the given user for the specified duration.
24    /// Called when a heartbeat response is received, keeping the shared session active.
25    async fn suppress_vault_timeout(
26        &self,
27        user_id: UserId,
28        suppression_duration: std::time::Duration,
29    );
30    /// Discovers the devices leader's IPC endpoint, given the current platform. There should only
31    /// be one possible leader for any given device. For web clients, there is only one browser
32    /// extension, for browser extensions there is only one desktop device, and for CLI clients
33    /// there is also only one desktop device.
34    async fn discover_leader(&self) -> Option<bitwarden_ipc::Endpoint>;
35}