Skip to content

Commit 7e90f52

Browse files
authored
[PM-13371] Repository split - Avoid depdending on Bitwarden (#1124)
## 🎟️ Tracking <!-- Paste the link to the Jira or GitHub issue or otherwise describe / point to where this change is coming from. --> Epic: https://bitwarden.atlassian.net/browse/PM-13370 Phase: https://bitwarden.atlassian.net/browse/PM-13371 ## 📔 Objective <!-- Describe what the purpose of this PR is, for example what bug you're fixing or new feature you're adding. --> Decouples our internal crates from depending on the public `bitwarden` crate. `uniffi`, `wasm-internal` and `bw` now depends directly on feature crates.
1 parent 0ae6d73 commit 7e90f52

File tree

32 files changed

+124
-295
lines changed

32 files changed

+124
-295
lines changed

.github/workflows/build-rust-crates.yml

-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ jobs:
4949
env:
5050
RUSTFLAGS: "-D warnings"
5151

52-
- name: Build Internal
53-
if: ${{ matrix.package == 'bitwarden' }}
54-
run: cargo build -p ${{ matrix.package }} --features internal --release
55-
env:
56-
RUSTFLAGS: "-D warnings"
57-
5852
release-dry-run:
5953
name: Release dry-run
6054
runs-on: ubuntu-latest

Cargo.lock

+3-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bitwarden-json/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ repository.workspace = true
1616
license-file.workspace = true
1717

1818
[features]
19-
internal = ["bitwarden/internal"] # Internal testing methods
20-
secrets = ["bitwarden/secrets"] # Secrets manager API
19+
secrets = ["bitwarden/secrets"] # Secrets manager API
2120

2221
[dependencies]
2322
bitwarden = { workspace = true }

crates/bitwarden-json/src/client.rs

-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#[cfg(feature = "internal")]
2-
use bitwarden::vault::ClientVaultExt;
31
use bitwarden::ClientSettings;
42
#[cfg(feature = "secrets")]
53
use bitwarden::{
@@ -54,22 +52,10 @@ impl Client {
5452
let client = &self.0;
5553

5654
match cmd {
57-
#[cfg(feature = "internal")]
58-
Command::PasswordLogin(req) => client.auth().login_password(&req).await.into_string(),
5955
#[cfg(feature = "secrets")]
6056
Command::LoginAccessToken(req) => {
6157
client.auth().login_access_token(&req).await.into_string()
6258
}
63-
#[cfg(feature = "internal")]
64-
Command::GetUserApiKey(req) => {
65-
client.platform().get_user_api_key(req).await.into_string()
66-
}
67-
#[cfg(feature = "internal")]
68-
Command::ApiKeyLogin(req) => client.auth().login_api_key(&req).await.into_string(),
69-
#[cfg(feature = "internal")]
70-
Command::Sync(req) => client.vault().sync(&req).await.into_string(),
71-
#[cfg(feature = "internal")]
72-
Command::Fingerprint(req) => client.platform().fingerprint(&req).into_string(),
7359

7460
#[cfg(feature = "secrets")]
7561
Command::Secrets(cmd) => match cmd {

crates/bitwarden-json/src/command.rs

-46
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,12 @@ use bitwarden::{
1313
},
1414
},
1515
};
16-
#[cfg(feature = "internal")]
17-
use bitwarden::{
18-
auth::login::{ApiKeyLoginRequest, PasswordLoginRequest},
19-
platform::{FingerprintRequest, SecretVerificationRequest},
20-
vault::SyncRequest,
21-
};
2216
use schemars::JsonSchema;
2317
use serde::{Deserialize, Serialize};
2418

2519
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
2620
#[serde(rename_all = "camelCase", deny_unknown_fields)]
2721
pub enum Command {
28-
#[cfg(feature = "internal")]
29-
/// Login with username and password
30-
///
31-
/// This command is for initiating an authentication handshake with Bitwarden.
32-
/// Authorization may fail due to requiring 2fa or captcha challenge completion
33-
/// despite accurate credentials.
34-
///
35-
/// This command is not capable of handling authentication requiring 2fa or captcha.
36-
///
37-
/// Returns: [PasswordLoginResponse](bitwarden::auth::login::PasswordLoginResponse)
38-
PasswordLogin(PasswordLoginRequest),
39-
40-
#[cfg(feature = "internal")]
41-
/// Login with API Key
42-
///
43-
/// This command is for initiating an authentication handshake with Bitwarden.
44-
///
45-
/// Returns: [ApiKeyLoginResponse](bitwarden::auth::login::ApiKeyLoginResponse)
46-
ApiKeyLogin(ApiKeyLoginRequest),
47-
4822
#[cfg(feature = "secrets")]
4923
/// Login with Secrets Manager Access Token
5024
///
@@ -53,26 +27,6 @@ pub enum Command {
5327
/// Returns: [ApiKeyLoginResponse](bitwarden::auth::login::ApiKeyLoginResponse)
5428
LoginAccessToken(AccessTokenLoginRequest),
5529

56-
#[cfg(feature = "internal")]
57-
/// > Requires Authentication
58-
/// Get the API key of the currently authenticated user
59-
///
60-
/// Returns: [UserApiKeyResponse](bitwarden::platform::UserApiKeyResponse)
61-
GetUserApiKey(SecretVerificationRequest),
62-
63-
#[cfg(feature = "internal")]
64-
/// Get the user's passphrase
65-
///
66-
/// Returns: String
67-
Fingerprint(FingerprintRequest),
68-
69-
#[cfg(feature = "internal")]
70-
/// > Requires Authentication
71-
/// Retrieve all user data, ciphers and organizations the user is a part of
72-
///
73-
/// Returns: [SyncResponse](bitwarden::vault::SyncResponse)
74-
Sync(SyncRequest),
75-
7630
#[cfg(feature = "secrets")]
7731
Secrets(SecretsCommand),
7832
#[cfg(feature = "secrets")]

crates/bitwarden-uniffi/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ repository.workspace = true
1111
license-file.workspace = true
1212

1313
[features]
14-
docs = ["dep:schemars"] # Docs
1514

1615
[lib]
1716
crate-type = ["lib", "staticlib", "cdylib"]
1817
bench = false
1918

2019
[dependencies]
2120
async-trait = "0.1.80"
22-
bitwarden = { workspace = true, features = ["internal", "uniffi"] }
2321
bitwarden-core = { workspace = true, features = ["uniffi"] }
2422
bitwarden-crypto = { workspace = true, features = ["uniffi"] }
2523
bitwarden-exporters = { workspace = true, features = ["uniffi"] }
@@ -28,8 +26,8 @@ bitwarden-generators = { workspace = true, features = ["uniffi"] }
2826
bitwarden-send = { workspace = true, features = ["uniffi"] }
2927
bitwarden-vault = { workspace = true, features = ["uniffi"] }
3028
chrono = { workspace = true, features = ["std"] }
31-
log = { workspace = true }
3229
env_logger = "0.11.1"
30+
log = { workspace = true }
3331
schemars = { workspace = true, optional = true }
3432
thiserror = { workspace = true }
3533
uniffi = { workspace = true }

crates/bitwarden-uniffi/src/auth/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use bitwarden::{
3+
use bitwarden_core::{
44
auth::{
55
password::MasterPasswordPolicyOptions, AuthRequestResponse, KeyConnectorResponse,
66
RegisterKeyResponse, RegisterTdeKeyResponse,

crates/bitwarden-uniffi/src/crypto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use bitwarden::{
3+
use bitwarden_core::{
44
mobile::crypto::{
55
DeriveKeyConnectorRequest, DerivePinKeyResponse, InitOrgCryptoRequest,
66
InitUserCryptoRequest, UpdatePasswordResponse,

crates/bitwarden-uniffi/src/error.rs

+47-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
use std::fmt::{Display, Formatter};
22

3+
use bitwarden_exporters::ExportError;
4+
use bitwarden_generators::{PassphraseError, PasswordError, UsernameError};
5+
36
// Name is converted from *Error to *Exception, so we can't just name the enum Error because
47
// Exception already exists
58
#[derive(uniffi::Error, Debug)]
69
#[uniffi(flat_error)]
710
pub enum BitwardenError {
8-
E(bitwarden::error::Error),
11+
E(Error),
912
}
1013

11-
impl From<bitwarden::Error> for BitwardenError {
12-
fn from(e: bitwarden::Error) -> Self {
14+
impl From<bitwarden_core::Error> for BitwardenError {
15+
fn from(e: bitwarden_core::Error) -> Self {
1316
Self::E(e.into())
1417
}
1518
}
1619

17-
impl From<bitwarden::error::Error> for BitwardenError {
18-
fn from(e: bitwarden::error::Error) -> Self {
20+
impl From<Error> for BitwardenError {
21+
fn from(e: Error) -> Self {
1922
Self::E(e)
2023
}
2124
}
@@ -37,3 +40,42 @@ impl std::error::Error for BitwardenError {
3740
}
3841

3942
pub type Result<T, E = BitwardenError> = std::result::Result<T, E>;
43+
44+
#[derive(thiserror::Error, Debug)]
45+
pub enum Error {
46+
#[error(transparent)]
47+
Core(#[from] bitwarden_core::Error),
48+
49+
// Generators
50+
#[error(transparent)]
51+
UsernameError(#[from] UsernameError),
52+
#[error(transparent)]
53+
PassphraseError(#[from] PassphraseError),
54+
#[error(transparent)]
55+
PasswordError(#[from] PasswordError),
56+
57+
// Vault
58+
#[error(transparent)]
59+
Cipher(#[from] bitwarden_vault::CipherError),
60+
#[error(transparent)]
61+
Totp(#[from] bitwarden_vault::TotpError),
62+
63+
#[error(transparent)]
64+
ExportError(#[from] ExportError),
65+
66+
// Fido
67+
#[error(transparent)]
68+
MakeCredential(#[from] bitwarden_fido::MakeCredentialError),
69+
#[error(transparent)]
70+
GetAssertion(#[from] bitwarden_fido::GetAssertionError),
71+
#[error(transparent)]
72+
SilentlyDiscoverCredentials(#[from] bitwarden_fido::SilentlyDiscoverCredentialsError),
73+
#[error(transparent)]
74+
CredentialsForAutofillError(#[from] bitwarden_fido::CredentialsForAutofillError),
75+
#[error(transparent)]
76+
DecryptFido2AutofillCredentialsError(
77+
#[from] bitwarden_fido::DecryptFido2AutofillCredentialsError,
78+
),
79+
#[error(transparent)]
80+
Fido2Client(#[from] bitwarden_fido::Fido2ClientError),
81+
}

crates/bitwarden-uniffi/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uniffi::setup_scaffolding!();
33
use std::sync::Arc;
44

55
use auth::ClientAuth;
6-
use bitwarden::ClientSettings;
6+
use bitwarden_core::ClientSettings;
77

88
pub mod auth;
99
pub mod crypto;
@@ -23,7 +23,7 @@ use tool::{ClientExporters, ClientGenerators, ClientSends};
2323
use vault::ClientVault;
2424

2525
#[derive(uniffi::Object)]
26-
pub struct Client(bitwarden::Client);
26+
pub struct Client(bitwarden_core::Client);
2727

2828
#[uniffi::export(async_runtime = "tokio")]
2929
impl Client {
@@ -35,7 +35,7 @@ impl Client {
3535
#[cfg(target_os = "android")]
3636
android_support::init();
3737

38-
Arc::new(Self(bitwarden::Client::new(settings)))
38+
Arc::new(Self(bitwarden_core::Client::new(settings)))
3939
}
4040

4141
/// Crypto operations
@@ -84,9 +84,9 @@ impl Client {
8484
.get(&url)
8585
.send()
8686
.await
87-
.map_err(bitwarden::Error::Reqwest)?;
87+
.map_err(bitwarden_core::Error::Reqwest)?;
8888

89-
Ok(res.text().await.map_err(bitwarden::Error::Reqwest)?)
89+
Ok(res.text().await.map_err(bitwarden_core::Error::Reqwest)?)
9090
}
9191
}
9292

crates/bitwarden-uniffi/src/platform/fido2.rs

+20-21
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
use std::sync::Arc;
22

3-
use bitwarden::{
4-
error::Error,
5-
fido::{
6-
CheckUserOptions, ClientData, ClientFido2Ext, Fido2CallbackError as BitFido2CallbackError,
7-
GetAssertionRequest, GetAssertionResult, MakeCredentialRequest, MakeCredentialResult,
8-
PublicKeyCredentialAuthenticatorAssertionResponse,
9-
PublicKeyCredentialAuthenticatorAttestationResponse, PublicKeyCredentialRpEntity,
10-
PublicKeyCredentialUserEntity,
11-
},
12-
vault::{Cipher, CipherView, Fido2CredentialNewView},
3+
use bitwarden_fido::{
4+
CheckUserOptions, ClientData, ClientFido2Ext, Fido2CallbackError as BitFido2CallbackError,
5+
Fido2CredentialAutofillView, GetAssertionRequest, GetAssertionResult, MakeCredentialRequest,
6+
MakeCredentialResult, Origin, PublicKeyCredentialAuthenticatorAssertionResponse,
7+
PublicKeyCredentialAuthenticatorAttestationResponse, PublicKeyCredentialRpEntity,
8+
PublicKeyCredentialUserEntity,
139
};
14-
use bitwarden_fido::{Fido2CredentialAutofillView, Origin};
10+
use bitwarden_vault::{Cipher, CipherView, Fido2CredentialNewView};
1511

16-
use crate::{error::Result, Client};
12+
use crate::{
13+
error::{Error, Result},
14+
Client,
15+
};
1716

1817
#[derive(uniffi::Object)]
1918
pub struct ClientFido2(pub(crate) Arc<Client>);
@@ -180,7 +179,7 @@ pub struct CheckUserResult {
180179
user_verified: bool,
181180
}
182181

183-
impl From<CheckUserResult> for bitwarden::fido::CheckUserResult {
182+
impl From<CheckUserResult> for bitwarden_fido::CheckUserResult {
184183
fn from(val: CheckUserResult) -> Self {
185184
Self {
186185
user_present: val.user_present,
@@ -268,7 +267,7 @@ pub trait Fido2CredentialStore: Send + Sync {
268267
struct UniffiTraitBridge<T>(T);
269268

270269
#[async_trait::async_trait]
271-
impl bitwarden::fido::Fido2CredentialStore for UniffiTraitBridge<&dyn Fido2CredentialStore> {
270+
impl bitwarden_fido::Fido2CredentialStore for UniffiTraitBridge<&dyn Fido2CredentialStore> {
272271
async fn find_credentials(
273272
&self,
274273
ids: Option<Vec<Vec<u8>>>,
@@ -306,9 +305,9 @@ pub enum UIHint {
306305
RequestExistingCredential(CipherView),
307306
}
308307

309-
impl From<bitwarden::fido::UIHint<'_, CipherView>> for UIHint {
310-
fn from(hint: bitwarden::fido::UIHint<'_, CipherView>) -> Self {
311-
use bitwarden::fido::UIHint as BWUIHint;
308+
impl From<bitwarden_fido::UIHint<'_, CipherView>> for UIHint {
309+
fn from(hint: bitwarden_fido::UIHint<'_, CipherView>) -> Self {
310+
use bitwarden_fido::UIHint as BWUIHint;
312311
match hint {
313312
BWUIHint::InformExcludedCredentialFound(cipher) => {
314313
UIHint::InformExcludedCredentialFound(cipher.clone())
@@ -333,12 +332,12 @@ impl From<bitwarden::fido::UIHint<'_, CipherView>> for UIHint {
333332
}
334333

335334
#[async_trait::async_trait]
336-
impl bitwarden::fido::Fido2UserInterface for UniffiTraitBridge<&dyn Fido2UserInterface> {
335+
impl bitwarden_fido::Fido2UserInterface for UniffiTraitBridge<&dyn Fido2UserInterface> {
337336
async fn check_user<'a>(
338337
&self,
339338
options: CheckUserOptions,
340-
hint: bitwarden::fido::UIHint<'a, CipherView>,
341-
) -> Result<bitwarden::fido::CheckUserResult, BitFido2CallbackError> {
339+
hint: bitwarden_fido::UIHint<'a, CipherView>,
340+
) -> Result<bitwarden_fido::CheckUserResult, BitFido2CallbackError> {
342341
self.0
343342
.check_user(options.clone(), hint.into())
344343
.await
@@ -359,7 +358,7 @@ impl bitwarden::fido::Fido2UserInterface for UniffiTraitBridge<&dyn Fido2UserInt
359358
&self,
360359
options: CheckUserOptions,
361360
new_credential: Fido2CredentialNewView,
362-
) -> Result<(CipherView, bitwarden::fido::CheckUserResult), BitFido2CallbackError> {
361+
) -> Result<(CipherView, bitwarden_fido::CheckUserResult), BitFido2CallbackError> {
363362
self.0
364363
.check_user_and_pick_credential_for_creation(options, new_credential)
365364
.await

0 commit comments

Comments
 (0)