Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
266785e
Add account cryptographic state
quexten Nov 18, 2025
410e63f
Fix
quexten Nov 18, 2025
b67d283
Cleanup and fix
quexten Nov 19, 2025
60b6998
Cleanup
quexten Nov 19, 2025
d681b50
Cleanup
quexten Nov 19, 2025
7299c24
Cleanup
quexten Nov 19, 2025
7a36ed1
Fix test
quexten Nov 19, 2025
8f555a9
Fix tests
quexten Nov 19, 2025
1863c0d
Cleanup
quexten Nov 19, 2025
1e875f2
Cleanup
quexten Nov 19, 2025
9db7b67
Fix sm build
quexten Nov 19, 2025
b81b603
Attempt to fix swift
quexten Nov 19, 2025
8534f4c
Attempt to fix android
quexten Nov 19, 2025
a6e8a96
Fix example
quexten Nov 19, 2025
855862d
Cleanup
quexten Nov 19, 2025
e7696d9
Attempt to fix android
quexten Nov 19, 2025
bbc19e3
Fix build on ios
quexten Nov 19, 2025
9d4b4fa
Expand docs
quexten Nov 19, 2025
c65aa26
Clean up comments
quexten Nov 19, 2025
f79bcc6
Attempt to fix android
quexten Nov 19, 2025
8e5c5ce
Cargo fmt
quexten Nov 19, 2025
5215147
Make signed public key optional
quexten Nov 20, 2025
0861024
Update signed public key
quexten Nov 20, 2025
60197b8
Clean up tests and add test for request model
quexten Nov 20, 2025
0013e68
Cargo fmt
quexten Nov 20, 2025
05b552c
Switch to using key ids
quexten Nov 20, 2025
2cf9f72
Cargo fmt
quexten Nov 20, 2025
87f53a5
Replace error for modified / tampered with data
quexten Nov 20, 2025
3e6abcb
Replace error messages and validate signed public key
quexten Nov 20, 2025
7795d17
Run cargo fmt
quexten Nov 20, 2025
d8ff670
Fix initialization
quexten Nov 20, 2025
b31c01d
Cargo fmt
quexten Nov 20, 2025
75cb175
Fix key id
quexten Nov 20, 2025
10be94b
Update crates/bitwarden-core/src/key_management/crypto.rs
quexten Nov 21, 2025
aff567c
Update crates/bitwarden-core/src/key_management/crypto.rs
quexten Nov 21, 2025
227bb54
Fix incorrect comment
quexten Nov 21, 2025
4d1a7b7
Merge branch 'km/account-cryptographic-state' of github.com:bitwardenโ€ฆ
quexten Nov 21, 2025
84fbd11
Cleanup
quexten Nov 21, 2025
cd157b7
Cleanup
quexten Nov 21, 2025
bc03d52
Make set-to_context pub(crate)
quexten Nov 21, 2025
7d35072
Cleanup
quexten Nov 21, 2025
0e3c14f
Cargo fmt
quexten Nov 21, 2025
77aaed5
Fix build
quexten Nov 21, 2025
1fd50d2
cargo fmt
quexten Nov 21, 2025
adfc0b7
Fix test
quexten Nov 21, 2025
8e786a4
Cargo format
quexten Nov 21, 2025
6aebfa0
Comment cleanup
quexten Nov 21, 2025
cafb42c
Migrate to new functions
quexten Nov 21, 2025
a66e520
Merge branch 'km/account-cryptographic-state' of github.com:bitwardenโ€ฆ
quexten Nov 21, 2025
a73adf3
Cleanup
quexten Nov 21, 2025
ce90219
Cargo fmt
quexten Nov 21, 2025
22f1488
Cleanup
quexten Nov 21, 2025
3d4f730
Fix tests
quexten Nov 21, 2025
f031cab
Run cargo fmt
quexten Nov 21, 2025
4dd06ce
Fix clippy issues
quexten Nov 21, 2025
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
12 changes: 6 additions & 6 deletions crates/bitwarden-collections/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl From<bitwarden_api_api::models::CollectionType> for CollectionType {
#[cfg(test)]
mod tests {
use bitwarden_core::key_management::{KeyIds, SymmetricKeyId};
use bitwarden_crypto::{KeyStore, PrimitiveEncryptable, SymmetricCryptoKey};
use bitwarden_crypto::{KeyStore, PrimitiveEncryptable, SymmetricKeyAlgorithm};

use super::*;

Expand All @@ -162,14 +162,14 @@ mod tests {
// Helper function to create a test key store with a symmetric key
fn create_test_key_store() -> KeyStore<KeyIds> {
let store = KeyStore::<KeyIds>::default();
let key = SymmetricCryptoKey::make_aes256_cbc_hmac_key();
let org_id = ORGANIZATION_ID.parse().unwrap();

#[allow(deprecated)]
store
.context_mut()
.set_symmetric_key(SymmetricKeyId::Organization(org_id), key)
let mut ctx = store.context_mut();

let local_key_id = ctx.make_symmetric_key(SymmetricKeyAlgorithm::Aes256CbcHmac);
ctx.persist_symmetric_key(local_key_id, SymmetricKeyId::Organization(org_id))
.unwrap();
drop(ctx);

store
}
Expand Down
18 changes: 6 additions & 12 deletions crates/bitwarden-core/src/auth/auth_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ mod tests {
use super::*;
use crate::{
UserId,
client::internal::UserKeyState,
key_management::{
SymmetricKeyId,
account_cryptographic_state::WrappedUserAccountCryptographicState,
crypto::{AuthRequestMethod, InitUserCryptoMethod, InitUserCryptoRequest},
},
};
Expand Down Expand Up @@ -165,11 +165,7 @@ mod tests {
.initialize_user_crypto_master_key(
master_key,
user_key,
UserKeyState {
private_key,
signing_key: None,
security_state: None,
},
WrappedUserAccountCryptographicState::V1 { private_key },
)
.unwrap();

Expand Down Expand Up @@ -240,10 +236,8 @@ mod tests {
.initialize_user_crypto_master_key(
master_key,
user_key,
UserKeyState {
WrappedUserAccountCryptographicState::V1 {
private_key: private_key.clone(),
signing_key: None,
security_state: None,
},
)
.unwrap();
Expand All @@ -262,9 +256,9 @@ mod tests {
user_id: Some(UserId::new_v4()),
kdf_params: kdf,
email: email.to_owned(),
private_key,
signing_key: None,
security_state: None,
account_cryptographic_state: WrappedUserAccountCryptographicState::V1 {
private_key,
},
method: InitUserCryptoMethod::AuthRequest {
request_private_key: auth_req.private_key,
method: AuthRequestMethod::UserKey {
Expand Down
12 changes: 5 additions & 7 deletions crates/bitwarden-core/src/auth/login/api_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ use crate::{
api::{request::ApiTokenRequest, response::IdentityTokenResponse},
login::{LoginError, PasswordLoginResponse, response::two_factor::TwoFactorProviders},
},
client::{LoginMethod, UserLoginMethod, internal::UserKeyState},
key_management::UserDecryptionData,
client::{LoginMethod, UserLoginMethod},
key_management::{
UserDecryptionData, account_cryptographic_state::WrappedUserAccountCryptographicState,
},
require,
};

Expand All @@ -31,11 +33,7 @@ pub(crate) async fn login_api_key(

let private_key: EncString = require!(&r.private_key).parse()?;

let user_key_state = UserKeyState {
private_key,
signing_key: None,
security_state: None,
};
let user_key_state = WrappedUserAccountCryptographicState::V1 { private_key };

let master_password_unlock = r
.user_decryption_options
Expand Down
7 changes: 4 additions & 3 deletions crates/bitwarden-core/src/auth/login/auth_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
},
key_management::{
UserDecryptionData,
account_cryptographic_state::WrappedUserAccountCryptographicState,
crypto::{AuthRequestMethod, InitUserCryptoMethod, InitUserCryptoRequest},
},
require,
Expand Down Expand Up @@ -127,9 +128,9 @@ pub(crate) async fn complete_auth_request(
user_id: None,
kdf_params: kdf,
email: salt,
private_key: require!(r.private_key).parse()?,
signing_key: None,
security_state: None,
account_cryptographic_state: WrappedUserAccountCryptographicState::V1 {
private_key: require!(r.private_key).parse()?,
},
method: InitUserCryptoMethod::AuthRequest {
request_private_key: auth_req.private_key,
method,
Expand Down
13 changes: 4 additions & 9 deletions crates/bitwarden-core/src/auth/login/password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ pub(crate) async fn login_password(
) -> Result<PasswordLoginResponse, LoginError> {
use bitwarden_crypto::EncString;

use crate::{
client::{UserLoginMethod, internal::UserKeyState},
require,
};
use crate::{client::UserLoginMethod, require};

info!("password logging in");

Expand All @@ -40,6 +37,8 @@ pub(crate) async fn login_password(
let response = request_identity_tokens(client, input, &password_hash).await?;

if let IdentityTokenResponse::Authenticated(r) = &response {
use crate::key_management::account_cryptographic_state::WrappedUserAccountCryptographicState;

client.internal.set_tokens(
r.access_token.clone(),
r.refresh_token.clone(),
Expand All @@ -48,11 +47,7 @@ pub(crate) async fn login_password(

let private_key: EncString = require!(&r.private_key).parse()?;

let user_key_state = UserKeyState {
private_key,
signing_key: None,
security_state: None,
};
let user_key_state = WrappedUserAccountCryptographicState::V1 { private_key };

let master_password_unlock = r
.user_decryption_options
Expand Down
14 changes: 3 additions & 11 deletions crates/bitwarden-core/src/auth/password/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod tests {

use crate::{
auth::password::{validate::validate_password_user_key, validate_password},
client::internal::UserKeyState,
key_management::account_cryptographic_state::WrappedUserAccountCryptographicState,
};

#[test]
Expand Down Expand Up @@ -149,11 +149,7 @@ mod tests {
.initialize_user_crypto_master_key(
master_key,
user_key.clone(),
UserKeyState {
private_key,
signing_key: None,
security_state: None,
},
WrappedUserAccountCryptographicState::V1 { private_key },
)
.unwrap();

Expand Down Expand Up @@ -203,11 +199,7 @@ mod tests {
.initialize_user_crypto_master_key(
master_key,
user_key.parse().unwrap(),
UserKeyState {
private_key,
signing_key: None,
security_state: None,
},
WrappedUserAccountCryptographicState::V1 { private_key },
)
.unwrap();

Expand Down
11 changes: 5 additions & 6 deletions crates/bitwarden-core/src/auth/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ mod tests {
use bitwarden_crypto::{Kdf, MasterKey};

use super::*;
use crate::client::{Client, LoginMethod, UserLoginMethod, internal::UserKeyState};
use crate::{
client::{Client, LoginMethod, UserLoginMethod},
key_management::account_cryptographic_state::WrappedUserAccountCryptographicState,
};

fn init_client() -> Client {
let client = Client::new(None);
Expand Down Expand Up @@ -78,11 +81,7 @@ mod tests {
.initialize_user_crypto_master_key(
master_key,
user_key.parse().unwrap(),
UserKeyState {
private_key,
signing_key: None,
security_state: None,
},
WrappedUserAccountCryptographicState::V1 { private_key },
)
.unwrap();

Expand Down
12 changes: 5 additions & 7 deletions crates/bitwarden-core/src/auth/tde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use bitwarden_crypto::{
use bitwarden_encoding::B64;

use crate::{
Client,
client::{encryption_settings::EncryptionSettingsError, internal::UserKeyState},
Client, client::encryption_settings::EncryptionSettingsError,
key_management::account_cryptographic_state::WrappedUserAccountCryptographicState,
};

/// This function generates a new user key and key pair, initializes the client's crypto with the
Expand Down Expand Up @@ -34,12 +34,10 @@ pub(super) fn make_register_tde_keys(

client.internal.initialize_user_crypto_decrypted_key(
user_key.0,
UserKeyState {
// TODO (https://bitwarden.atlassian.net/browse/PM-21771) Signing keys are not supported on registration yet. This needs to be changed as
// soon as registration is supported.
WrappedUserAccountCryptographicState::V1 {
private_key: key_pair.private.clone(),
// TODO (https://bitwarden.atlassian.net/browse/PM-21771) Signing keys are not supported on registration yet. This needs to be changed as
// soon as registration is supported.
signing_key: None,
security_state: None,
},
)?;

Expand Down
Loading
Loading