Skip to content

Commit 05f22af

Browse files
committed
Merge branch 'main' of github.com:bitwarden/sdk-internal into arch/bw-uuid
# Conflicts: # crates/bitwarden-uniffi/src/vault/ciphers.rs # crates/bitwarden-wasm-internal/src/vault/ciphers.rs
2 parents 4cccada + 1a31a1f commit 05f22af

File tree

36 files changed

+646
-22
lines changed

36 files changed

+646
-22
lines changed

.cargo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ rustflags = ["--cfg", "aes_armv8"]
66

77
[target.wasm32-unknown-unknown]
88
rustflags = ['--cfg', 'getrandom_backend="wasm_js"']
9+
runner = 'wasm-bindgen-test-runner'
910

1011
# Enable support for 16k pages on Android, JNA is using these same flags
1112
# https://android-developers.googleblog.com/2024/08/adding-16-kb-page-size-to-android.html

.github/workflows/build-wasm-internal.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ jobs:
6060
RUST_TOOLCHAIN="$(grep -oP '^channel.*"(\K.*?)(?=")' ../../rust-toolchain.toml)"
6161
echo "RUST_TOOLCHAIN=${RUST_TOOLCHAIN}" | tee -a "${GITHUB_OUTPUT}"
6262
63+
- name: NPM setup
64+
run: npm ci
65+
6366
- name: Install rust
6467
uses: dtolnay/rust-toolchain@56f84321dbccf38fb67ce29ab63e4754056677e0 # stable
6568
with:

.github/workflows/rust-test.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,37 @@ jobs:
4545
- name: Test
4646
run: cargo test --workspace --all-features
4747

48+
test-wasm:
49+
name: WASM
50+
runs-on: ubuntu-24.04
51+
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
55+
56+
- name: Set Rust Toolchain
57+
id: toolchain
58+
shell: bash
59+
run: |
60+
RUST_TOOLCHAIN="$(grep -oP '^channel.*"(\K.*?)(?=")' rust-toolchain.toml)"
61+
echo "RUST_TOOLCHAIN=${RUST_TOOLCHAIN}" | tee -a "${GITHUB_OUTPUT}"
62+
63+
- name: Install rust
64+
uses: dtolnay/rust-toolchain@56f84321dbccf38fb67ce29ab63e4754056677e0 # stable
65+
with:
66+
toolchain: "${{ steps.toolchain.outputs.RUST_TOOLCHAIN }}"
67+
targets: wasm32-unknown-unknown
68+
components: rust-src
69+
70+
- name: Cache cargo registry
71+
uses: Swatinem/rust-cache@f0deed1e0edfc6a9be95417288c0e1099b1eeec3 # v2.7.7
72+
73+
- name: Install wasm-bindgen-cli
74+
run: cargo install wasm-bindgen-cli --version 0.2.100
75+
76+
- name: Test WASM
77+
run: cargo test --target wasm32-unknown-unknown -p bitwarden-wasm-internal -p bitwarden-threading -p bitwarden-error --all-features
78+
4879
coverage:
4980
name: Coverage
5081
runs-on: ubuntu-24.04

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ bitwarden-fido = { path = "crates/bitwarden-fido", version = "=1.0.0" }
3131
bitwarden-generators = { path = "crates/bitwarden-generators", version = "=1.0.0" }
3232
bitwarden-ipc = { path = "crates/bitwarden-ipc", version = "=1.0.0" }
3333
bitwarden-send = { path = "crates/bitwarden-send", version = "=1.0.0" }
34+
bitwarden-threading = { path = "crates/bitwarden-threading", version = "=1.0.0" }
3435
bitwarden-sm = { path = "bitwarden_license/bitwarden-sm", version = "=1.0.0" }
3536
bitwarden-ssh = { path = "crates/bitwarden-ssh", version = "=1.0.0" }
3637
bitwarden-uuid = { path = "crates/bitwarden-uuid", version = "=1.0.0" }
@@ -68,6 +69,7 @@ uuid = { version = ">=1.3.3, <2.0", features = ["serde", "v4", "js"] }
6869
validator = { version = ">=0.18.1, <0.20", features = ["derive"] }
6970
wasm-bindgen = { version = ">=0.2.91, <0.3", features = ["serde-serialize"] }
7071
wasm-bindgen-futures = "0.4.41"
72+
wasm-bindgen-test = "0.3.45"
7173

7274
# There is an incompatibility when using pkcs5 and chacha20 on wasm builds. This can be removed once a new
7375
# rustcrypto-formats crate version is released since the fix has been upstreamed.

crates/bitwarden-core/src/auth/auth_request.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ mod tests {
243243
new_device
244244
.crypto()
245245
.initialize_user_crypto(InitUserCryptoRequest {
246+
user_id: Some(uuid::Uuid::new_v4()),
246247
kdf_params: kdf,
247248
email: email.to_owned(),
248249
private_key: private_key.to_owned(),

crates/bitwarden-core/src/auth/login/auth_request.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub(crate) async fn complete_auth_request(
115115
client
116116
.crypto()
117117
.initialize_user_crypto(InitUserCryptoRequest {
118+
user_id: None,
118119
kdf_params: kdf,
119120
email: auth_req.email,
120121
private_key: require!(r.private_key),

crates/bitwarden-core/src/client/client.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::{Arc, RwLock};
1+
use std::sync::{Arc, OnceLock, RwLock};
22

33
use bitwarden_crypto::KeyStore;
44
use reqwest::header::{self, HeaderValue};
@@ -75,6 +75,7 @@ impl Client {
7575

7676
Self {
7777
internal: Arc::new(InternalClient {
78+
user_id: OnceLock::new(),
7879
tokens: RwLock::new(Tokens::default()),
7980
login_method: RwLock::new(None),
8081
#[cfg(feature = "internal")]

crates/bitwarden-core/src/client/encryption_settings.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use thiserror::Error;
66
use uuid::Uuid;
77

88
use crate::{
9+
error::UserIdAlreadySetError,
910
key_management::{AsymmetricKeyId, KeyIds, SymmetricKeyId},
1011
MissingPrivateKeyError, VaultLockedError,
1112
};
@@ -27,6 +28,9 @@ pub enum EncryptionSettingsError {
2728

2829
#[error(transparent)]
2930
MissingPrivateKey(#[from] MissingPrivateKeyError),
31+
32+
#[error(transparent)]
33+
UserIdAlreadySetError(#[from] UserIdAlreadySetError),
3034
}
3135

3236
pub struct EncryptionSettings {}

crates/bitwarden-core/src/client/internal.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::{Arc, RwLock};
1+
use std::sync::{Arc, OnceLock, RwLock};
22

33
use bitwarden_crypto::KeyStore;
44
#[cfg(any(feature = "internal", feature = "secrets"))]
@@ -13,6 +13,7 @@ use super::login_method::ServiceAccountLoginMethod;
1313
use crate::{
1414
auth::renew::renew_token,
1515
client::{encryption_settings::EncryptionSettings, login_method::LoginMethod},
16+
error::UserIdAlreadySetError,
1617
key_management::KeyIds,
1718
DeviceType,
1819
};
@@ -44,6 +45,7 @@ pub(crate) struct Tokens {
4445

4546
#[derive(Debug)]
4647
pub struct InternalClient {
48+
pub(crate) user_id: OnceLock<Uuid>,
4749
pub(crate) tokens: RwLock<Tokens>,
4850
pub(crate) login_method: RwLock<Option<Arc<LoginMethod>>>,
4951

@@ -172,6 +174,14 @@ impl InternalClient {
172174
&self.key_store
173175
}
174176

177+
pub fn init_user_id(&self, user_id: Uuid) -> Result<(), UserIdAlreadySetError> {
178+
self.user_id.set(user_id).map_err(|_| UserIdAlreadySetError)
179+
}
180+
181+
pub fn get_user_id(&self) -> Option<Uuid> {
182+
self.user_id.get().copied()
183+
}
184+
175185
#[cfg(feature = "internal")]
176186
pub(crate) fn initialize_user_crypto_master_key(
177187
&self,

0 commit comments

Comments
 (0)