Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion crates/bitwarden-core/src/key_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
//! [CompositeEncryptable](bitwarden_crypto::CompositeEncryptable), and
//! [Decryptable](bitwarden_crypto::Decryptable).

use bitwarden_crypto::{EncString, KeyStore, SymmetricCryptoKey, key_ids};
use bitwarden_crypto::{
EncString, KeyStore, SymmetricCryptoKey, key_ids, safe::PasswordProtectedKeyEnvelope,
};

#[cfg(feature = "internal")]
pub mod account_cryptographic_state;
Expand Down Expand Up @@ -79,6 +81,16 @@ pub struct LocalUserDataKeyState {

bitwarden_state::register_repository_item!(UserId => LocalUserDataKeyState, "LocalUserDataKey");

/// Represents the PIN envelope in memory, when ephemeral PIN unlock is used.
#[derive(Serialize, Deserialize, Debug, Clone)]
#[cfg_attr(feature = "wasm", derive(Tsify), tsify(into_wasm_abi, from_wasm_abi))]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct EphemeralPinEnvelopeState {
pin_envelope: PasswordProtectedKeyEnvelope,
}

bitwarden_state::register_repository_item!(String => EphemeralPinEnvelopeState, "EphemeralPinEnvelope");

key_ids! {
#[symmetric]
pub enum SymmetricKeyId {
Expand Down
9 changes: 8 additions & 1 deletion crates/bitwarden-core/tests/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn test_register_initialize_crypto() {
use bitwarden_core::{
Client, UserId,
key_management::{
MasterPasswordUnlockData, UserKeyState,
EphemeralPinEnvelopeState, MasterPasswordUnlockData, UserKeyState,
account_cryptographic_state::WrappedAccountCryptographicState,
crypto::{InitUserCryptoMethod, InitUserCryptoRequest},
},
Expand All @@ -34,6 +34,13 @@ async fn test_register_initialize_crypto() {
MemoryRepository::<LocalUserDataKeyState>::default(),
));

client
.platform()
.state()
.register_client_managed(std::sync::Arc::new(MemoryRepository::<
EphemeralPinEnvelopeState,
>::default()));

let email = "test@bitwarden.com";
let password = "test123";
let kdf = Kdf::PBKDF2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const ENVELOPE_ARGON2_OUTPUT_KEY_SIZE: usize = 32;
/// be provided.
///
/// Internally, Argon2 is used as the KDF and XChaCha20-Poly1305 is used to encrypt the key.
#[derive(Clone)]
pub struct PasswordProtectedKeyEnvelope {
cose_encrypt: coset::CoseEncrypt,
}
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden-pm/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ macro_rules! create_client_managed_repositories {
::bitwarden_vault::Folder, Folder, folder, FolderRepository;
::bitwarden_core::key_management::UserKeyState, UserKeyState, user_key_state, UserKeyStateRepository;
::bitwarden_core::key_management::LocalUserDataKeyState, LocalUserDataKeyState, local_user_data_key_state, LocalUserDataKeyStateRepository;
::bitwarden_core::key_management::EphemeralPinEnvelopeState, EphemeralPinEnvelopeState, ephemeral_pin_envelope_state, EphemeralPinEnvelopeStateRepository;
}
};
}
Loading