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