From 7e90f52cfd9fe3741816962cb3555cac40627ad4 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Fri, 11 Oct 2024 13:09:52 +0200 Subject: [PATCH] [PM-13371] Repository split - Avoid depdending on Bitwarden (#1124) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 🎟️ Tracking Epic: https://bitwarden.atlassian.net/browse/PM-13370 Phase: https://bitwarden.atlassian.net/browse/PM-13371 ## 📔 Objective Decouples our internal crates from depending on the public `bitwarden` crate. `uniffi`, `wasm-internal` and `bw` now depends directly on feature crates. --- .github/workflows/build-rust-crates.yml | 6 -- Cargo.lock | 12 +--- crates/bitwarden-json/Cargo.toml | 3 +- crates/bitwarden-json/src/client.rs | 14 ---- crates/bitwarden-json/src/command.rs | 46 ------------- crates/bitwarden-uniffi/Cargo.toml | 4 +- crates/bitwarden-uniffi/src/auth/mod.rs | 2 +- crates/bitwarden-uniffi/src/crypto.rs | 2 +- crates/bitwarden-uniffi/src/error.rs | 52 +++++++++++++-- crates/bitwarden-uniffi/src/lib.rs | 10 +-- crates/bitwarden-uniffi/src/platform/fido2.rs | 41 ++++++------ crates/bitwarden-uniffi/src/platform/mod.rs | 2 +- crates/bitwarden-uniffi/src/tool/mod.rs | 18 ++--- crates/bitwarden-uniffi/src/tool/sends.rs | 2 +- crates/bitwarden-uniffi/src/uniffi_support.rs | 8 ++- .../bitwarden-uniffi/src/vault/attachments.rs | 2 +- crates/bitwarden-uniffi/src/vault/ciphers.rs | 8 +-- .../bitwarden-uniffi/src/vault/collections.rs | 2 +- crates/bitwarden-uniffi/src/vault/folders.rs | 2 +- crates/bitwarden-uniffi/src/vault/mod.rs | 11 ++-- .../src/vault/password_history.rs | 2 +- crates/bitwarden-wasm-internal/Cargo.toml | 2 +- crates/bitwarden-wasm/Cargo.toml | 5 +- crates/bitwarden/Cargo.toml | 23 ------- crates/bitwarden/src/error.rs | 66 +------------------ crates/bitwarden/src/lib.rs | 29 +------- crates/bw/Cargo.toml | 4 +- crates/bw/src/auth/login.rs | 6 +- crates/bw/src/main.rs | 15 ++--- crates/sdk-schemas/Cargo.toml | 1 - crates/sdk-schemas/src/main.rs | 7 -- support/scripts/schemas.ts | 12 ---- 32 files changed, 124 insertions(+), 295 deletions(-) diff --git a/.github/workflows/build-rust-crates.yml b/.github/workflows/build-rust-crates.yml index d4116bcf9..8400fcbf6 100644 --- a/.github/workflows/build-rust-crates.yml +++ b/.github/workflows/build-rust-crates.yml @@ -49,12 +49,6 @@ jobs: env: RUSTFLAGS: "-D warnings" - - name: Build Internal - if: ${{ matrix.package == 'bitwarden' }} - run: cargo build -p ${{ matrix.package }} --features internal --release - env: - RUSTFLAGS: "-D warnings" - release-dry-run: name: Release dry-run runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index 5397271ce..024abbe00 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -362,16 +362,9 @@ checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" name = "bitwarden" version = "1.0.0" dependencies = [ - "bitwarden-api-api", - "bitwarden-api-identity", "bitwarden-core", - "bitwarden-crypto", - "bitwarden-exporters", - "bitwarden-fido", "bitwarden-generators", - "bitwarden-send", "bitwarden-sm", - "bitwarden-vault", "thiserror", "uuid", ] @@ -623,7 +616,6 @@ version = "0.1.0" dependencies = [ "android_logger", "async-trait", - "bitwarden", "bitwarden-core", "bitwarden-crypto", "bitwarden-exporters", @@ -746,9 +738,11 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" name = "bw" version = "0.0.2" dependencies = [ - "bitwarden", "bitwarden-cli", + "bitwarden-core", "bitwarden-crypto", + "bitwarden-generators", + "bitwarden-vault", "clap", "color-eyre", "env_logger", diff --git a/crates/bitwarden-json/Cargo.toml b/crates/bitwarden-json/Cargo.toml index ed1b39580..b5b8052b0 100644 --- a/crates/bitwarden-json/Cargo.toml +++ b/crates/bitwarden-json/Cargo.toml @@ -16,8 +16,7 @@ repository.workspace = true license-file.workspace = true [features] -internal = ["bitwarden/internal"] # Internal testing methods -secrets = ["bitwarden/secrets"] # Secrets manager API +secrets = ["bitwarden/secrets"] # Secrets manager API [dependencies] bitwarden = { workspace = true } diff --git a/crates/bitwarden-json/src/client.rs b/crates/bitwarden-json/src/client.rs index dc84c559d..8da635a29 100644 --- a/crates/bitwarden-json/src/client.rs +++ b/crates/bitwarden-json/src/client.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "internal")] -use bitwarden::vault::ClientVaultExt; use bitwarden::ClientSettings; #[cfg(feature = "secrets")] use bitwarden::{ @@ -54,22 +52,10 @@ impl Client { let client = &self.0; match cmd { - #[cfg(feature = "internal")] - Command::PasswordLogin(req) => client.auth().login_password(&req).await.into_string(), #[cfg(feature = "secrets")] Command::LoginAccessToken(req) => { client.auth().login_access_token(&req).await.into_string() } - #[cfg(feature = "internal")] - Command::GetUserApiKey(req) => { - client.platform().get_user_api_key(req).await.into_string() - } - #[cfg(feature = "internal")] - Command::ApiKeyLogin(req) => client.auth().login_api_key(&req).await.into_string(), - #[cfg(feature = "internal")] - Command::Sync(req) => client.vault().sync(&req).await.into_string(), - #[cfg(feature = "internal")] - Command::Fingerprint(req) => client.platform().fingerprint(&req).into_string(), #[cfg(feature = "secrets")] Command::Secrets(cmd) => match cmd { diff --git a/crates/bitwarden-json/src/command.rs b/crates/bitwarden-json/src/command.rs index 7483b90cf..faaa81776 100644 --- a/crates/bitwarden-json/src/command.rs +++ b/crates/bitwarden-json/src/command.rs @@ -13,38 +13,12 @@ use bitwarden::{ }, }, }; -#[cfg(feature = "internal")] -use bitwarden::{ - auth::login::{ApiKeyLoginRequest, PasswordLoginRequest}, - platform::{FingerprintRequest, SecretVerificationRequest}, - vault::SyncRequest, -}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, JsonSchema, Debug)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub enum Command { - #[cfg(feature = "internal")] - /// Login with username and password - /// - /// This command is for initiating an authentication handshake with Bitwarden. - /// Authorization may fail due to requiring 2fa or captcha challenge completion - /// despite accurate credentials. - /// - /// This command is not capable of handling authentication requiring 2fa or captcha. - /// - /// Returns: [PasswordLoginResponse](bitwarden::auth::login::PasswordLoginResponse) - PasswordLogin(PasswordLoginRequest), - - #[cfg(feature = "internal")] - /// Login with API Key - /// - /// This command is for initiating an authentication handshake with Bitwarden. - /// - /// Returns: [ApiKeyLoginResponse](bitwarden::auth::login::ApiKeyLoginResponse) - ApiKeyLogin(ApiKeyLoginRequest), - #[cfg(feature = "secrets")] /// Login with Secrets Manager Access Token /// @@ -53,26 +27,6 @@ pub enum Command { /// Returns: [ApiKeyLoginResponse](bitwarden::auth::login::ApiKeyLoginResponse) LoginAccessToken(AccessTokenLoginRequest), - #[cfg(feature = "internal")] - /// > Requires Authentication - /// Get the API key of the currently authenticated user - /// - /// Returns: [UserApiKeyResponse](bitwarden::platform::UserApiKeyResponse) - GetUserApiKey(SecretVerificationRequest), - - #[cfg(feature = "internal")] - /// Get the user's passphrase - /// - /// Returns: String - Fingerprint(FingerprintRequest), - - #[cfg(feature = "internal")] - /// > Requires Authentication - /// Retrieve all user data, ciphers and organizations the user is a part of - /// - /// Returns: [SyncResponse](bitwarden::vault::SyncResponse) - Sync(SyncRequest), - #[cfg(feature = "secrets")] Secrets(SecretsCommand), #[cfg(feature = "secrets")] diff --git a/crates/bitwarden-uniffi/Cargo.toml b/crates/bitwarden-uniffi/Cargo.toml index 822ed0d38..2e57e23b5 100644 --- a/crates/bitwarden-uniffi/Cargo.toml +++ b/crates/bitwarden-uniffi/Cargo.toml @@ -11,7 +11,6 @@ repository.workspace = true license-file.workspace = true [features] -docs = ["dep:schemars"] # Docs [lib] crate-type = ["lib", "staticlib", "cdylib"] @@ -19,7 +18,6 @@ bench = false [dependencies] async-trait = "0.1.80" -bitwarden = { workspace = true, features = ["internal", "uniffi"] } bitwarden-core = { workspace = true, features = ["uniffi"] } bitwarden-crypto = { workspace = true, features = ["uniffi"] } bitwarden-exporters = { workspace = true, features = ["uniffi"] } @@ -28,8 +26,8 @@ bitwarden-generators = { workspace = true, features = ["uniffi"] } bitwarden-send = { workspace = true, features = ["uniffi"] } bitwarden-vault = { workspace = true, features = ["uniffi"] } chrono = { workspace = true, features = ["std"] } -log = { workspace = true } env_logger = "0.11.1" +log = { workspace = true } schemars = { workspace = true, optional = true } thiserror = { workspace = true } uniffi = { workspace = true } diff --git a/crates/bitwarden-uniffi/src/auth/mod.rs b/crates/bitwarden-uniffi/src/auth/mod.rs index d036991e3..43496080a 100644 --- a/crates/bitwarden-uniffi/src/auth/mod.rs +++ b/crates/bitwarden-uniffi/src/auth/mod.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use bitwarden::{ +use bitwarden_core::{ auth::{ password::MasterPasswordPolicyOptions, AuthRequestResponse, KeyConnectorResponse, RegisterKeyResponse, RegisterTdeKeyResponse, diff --git a/crates/bitwarden-uniffi/src/crypto.rs b/crates/bitwarden-uniffi/src/crypto.rs index 608698fc6..6404d62f6 100644 --- a/crates/bitwarden-uniffi/src/crypto.rs +++ b/crates/bitwarden-uniffi/src/crypto.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use bitwarden::{ +use bitwarden_core::{ mobile::crypto::{ DeriveKeyConnectorRequest, DerivePinKeyResponse, InitOrgCryptoRequest, InitUserCryptoRequest, UpdatePasswordResponse, diff --git a/crates/bitwarden-uniffi/src/error.rs b/crates/bitwarden-uniffi/src/error.rs index 5a1dfe43a..889e3c7fb 100644 --- a/crates/bitwarden-uniffi/src/error.rs +++ b/crates/bitwarden-uniffi/src/error.rs @@ -1,21 +1,24 @@ use std::fmt::{Display, Formatter}; +use bitwarden_exporters::ExportError; +use bitwarden_generators::{PassphraseError, PasswordError, UsernameError}; + // Name is converted from *Error to *Exception, so we can't just name the enum Error because // Exception already exists #[derive(uniffi::Error, Debug)] #[uniffi(flat_error)] pub enum BitwardenError { - E(bitwarden::error::Error), + E(Error), } -impl From for BitwardenError { - fn from(e: bitwarden::Error) -> Self { +impl From for BitwardenError { + fn from(e: bitwarden_core::Error) -> Self { Self::E(e.into()) } } -impl From for BitwardenError { - fn from(e: bitwarden::error::Error) -> Self { +impl From for BitwardenError { + fn from(e: Error) -> Self { Self::E(e) } } @@ -37,3 +40,42 @@ impl std::error::Error for BitwardenError { } pub type Result = std::result::Result; + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error(transparent)] + Core(#[from] bitwarden_core::Error), + + // Generators + #[error(transparent)] + UsernameError(#[from] UsernameError), + #[error(transparent)] + PassphraseError(#[from] PassphraseError), + #[error(transparent)] + PasswordError(#[from] PasswordError), + + // Vault + #[error(transparent)] + Cipher(#[from] bitwarden_vault::CipherError), + #[error(transparent)] + Totp(#[from] bitwarden_vault::TotpError), + + #[error(transparent)] + ExportError(#[from] ExportError), + + // Fido + #[error(transparent)] + MakeCredential(#[from] bitwarden_fido::MakeCredentialError), + #[error(transparent)] + GetAssertion(#[from] bitwarden_fido::GetAssertionError), + #[error(transparent)] + SilentlyDiscoverCredentials(#[from] bitwarden_fido::SilentlyDiscoverCredentialsError), + #[error(transparent)] + CredentialsForAutofillError(#[from] bitwarden_fido::CredentialsForAutofillError), + #[error(transparent)] + DecryptFido2AutofillCredentialsError( + #[from] bitwarden_fido::DecryptFido2AutofillCredentialsError, + ), + #[error(transparent)] + Fido2Client(#[from] bitwarden_fido::Fido2ClientError), +} diff --git a/crates/bitwarden-uniffi/src/lib.rs b/crates/bitwarden-uniffi/src/lib.rs index a9eb6a3e0..aae35c37a 100644 --- a/crates/bitwarden-uniffi/src/lib.rs +++ b/crates/bitwarden-uniffi/src/lib.rs @@ -3,7 +3,7 @@ uniffi::setup_scaffolding!(); use std::sync::Arc; use auth::ClientAuth; -use bitwarden::ClientSettings; +use bitwarden_core::ClientSettings; pub mod auth; pub mod crypto; @@ -23,7 +23,7 @@ use tool::{ClientExporters, ClientGenerators, ClientSends}; use vault::ClientVault; #[derive(uniffi::Object)] -pub struct Client(bitwarden::Client); +pub struct Client(bitwarden_core::Client); #[uniffi::export(async_runtime = "tokio")] impl Client { @@ -35,7 +35,7 @@ impl Client { #[cfg(target_os = "android")] android_support::init(); - Arc::new(Self(bitwarden::Client::new(settings))) + Arc::new(Self(bitwarden_core::Client::new(settings))) } /// Crypto operations @@ -84,9 +84,9 @@ impl Client { .get(&url) .send() .await - .map_err(bitwarden::Error::Reqwest)?; + .map_err(bitwarden_core::Error::Reqwest)?; - Ok(res.text().await.map_err(bitwarden::Error::Reqwest)?) + Ok(res.text().await.map_err(bitwarden_core::Error::Reqwest)?) } } diff --git a/crates/bitwarden-uniffi/src/platform/fido2.rs b/crates/bitwarden-uniffi/src/platform/fido2.rs index f483ff346..99c998648 100644 --- a/crates/bitwarden-uniffi/src/platform/fido2.rs +++ b/crates/bitwarden-uniffi/src/platform/fido2.rs @@ -1,19 +1,18 @@ use std::sync::Arc; -use bitwarden::{ - error::Error, - fido::{ - CheckUserOptions, ClientData, ClientFido2Ext, Fido2CallbackError as BitFido2CallbackError, - GetAssertionRequest, GetAssertionResult, MakeCredentialRequest, MakeCredentialResult, - PublicKeyCredentialAuthenticatorAssertionResponse, - PublicKeyCredentialAuthenticatorAttestationResponse, PublicKeyCredentialRpEntity, - PublicKeyCredentialUserEntity, - }, - vault::{Cipher, CipherView, Fido2CredentialNewView}, +use bitwarden_fido::{ + CheckUserOptions, ClientData, ClientFido2Ext, Fido2CallbackError as BitFido2CallbackError, + Fido2CredentialAutofillView, GetAssertionRequest, GetAssertionResult, MakeCredentialRequest, + MakeCredentialResult, Origin, PublicKeyCredentialAuthenticatorAssertionResponse, + PublicKeyCredentialAuthenticatorAttestationResponse, PublicKeyCredentialRpEntity, + PublicKeyCredentialUserEntity, }; -use bitwarden_fido::{Fido2CredentialAutofillView, Origin}; +use bitwarden_vault::{Cipher, CipherView, Fido2CredentialNewView}; -use crate::{error::Result, Client}; +use crate::{ + error::{Error, Result}, + Client, +}; #[derive(uniffi::Object)] pub struct ClientFido2(pub(crate) Arc); @@ -180,7 +179,7 @@ pub struct CheckUserResult { user_verified: bool, } -impl From for bitwarden::fido::CheckUserResult { +impl From for bitwarden_fido::CheckUserResult { fn from(val: CheckUserResult) -> Self { Self { user_present: val.user_present, @@ -268,7 +267,7 @@ pub trait Fido2CredentialStore: Send + Sync { struct UniffiTraitBridge(T); #[async_trait::async_trait] -impl bitwarden::fido::Fido2CredentialStore for UniffiTraitBridge<&dyn Fido2CredentialStore> { +impl bitwarden_fido::Fido2CredentialStore for UniffiTraitBridge<&dyn Fido2CredentialStore> { async fn find_credentials( &self, ids: Option>>, @@ -306,9 +305,9 @@ pub enum UIHint { RequestExistingCredential(CipherView), } -impl From> for UIHint { - fn from(hint: bitwarden::fido::UIHint<'_, CipherView>) -> Self { - use bitwarden::fido::UIHint as BWUIHint; +impl From> for UIHint { + fn from(hint: bitwarden_fido::UIHint<'_, CipherView>) -> Self { + use bitwarden_fido::UIHint as BWUIHint; match hint { BWUIHint::InformExcludedCredentialFound(cipher) => { UIHint::InformExcludedCredentialFound(cipher.clone()) @@ -333,12 +332,12 @@ impl From> for UIHint { } #[async_trait::async_trait] -impl bitwarden::fido::Fido2UserInterface for UniffiTraitBridge<&dyn Fido2UserInterface> { +impl bitwarden_fido::Fido2UserInterface for UniffiTraitBridge<&dyn Fido2UserInterface> { async fn check_user<'a>( &self, options: CheckUserOptions, - hint: bitwarden::fido::UIHint<'a, CipherView>, - ) -> Result { + hint: bitwarden_fido::UIHint<'a, CipherView>, + ) -> Result { self.0 .check_user(options.clone(), hint.into()) .await @@ -359,7 +358,7 @@ impl bitwarden::fido::Fido2UserInterface for UniffiTraitBridge<&dyn Fido2UserInt &self, options: CheckUserOptions, new_credential: Fido2CredentialNewView, - ) -> Result<(CipherView, bitwarden::fido::CheckUserResult), BitFido2CallbackError> { + ) -> Result<(CipherView, bitwarden_fido::CheckUserResult), BitFido2CallbackError> { self.0 .check_user_and_pick_credential_for_creation(options, new_credential) .await diff --git a/crates/bitwarden-uniffi/src/platform/mod.rs b/crates/bitwarden-uniffi/src/platform/mod.rs index 63ff6e183..b5d944152 100644 --- a/crates/bitwarden-uniffi/src/platform/mod.rs +++ b/crates/bitwarden-uniffi/src/platform/mod.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use bitwarden::platform::FingerprintRequest; +use bitwarden_core::platform::FingerprintRequest; use crate::{error::Result, Client}; diff --git a/crates/bitwarden-uniffi/src/tool/mod.rs b/crates/bitwarden-uniffi/src/tool/mod.rs index 1fd439a4f..498884218 100644 --- a/crates/bitwarden-uniffi/src/tool/mod.rs +++ b/crates/bitwarden-uniffi/src/tool/mod.rs @@ -1,16 +1,16 @@ use std::sync::Arc; -use bitwarden::{ - error::Error, - exporters::{ClientExportersExt, ExportFormat}, - generators::{ - ClientGeneratorExt, PassphraseGeneratorRequest, PasswordGeneratorRequest, - UsernameGeneratorRequest, - }, - vault::{Cipher, Collection, Folder}, +use bitwarden_exporters::{ClientExportersExt, ExportFormat}; +use bitwarden_generators::{ + ClientGeneratorExt, PassphraseGeneratorRequest, PasswordGeneratorRequest, + UsernameGeneratorRequest, }; +use bitwarden_vault::{Cipher, Collection, Folder}; -use crate::{error::Result, Client}; +use crate::{ + error::{Error, Result}, + Client, +}; mod sends; pub use sends::ClientSends; diff --git a/crates/bitwarden-uniffi/src/tool/sends.rs b/crates/bitwarden-uniffi/src/tool/sends.rs index 1d5a056a3..18732f57c 100644 --- a/crates/bitwarden-uniffi/src/tool/sends.rs +++ b/crates/bitwarden-uniffi/src/tool/sends.rs @@ -1,6 +1,6 @@ use std::{path::Path, sync::Arc}; -use bitwarden::send::{ClientSendsExt, Send, SendListView, SendView}; +use bitwarden_send::{ClientSendsExt, Send, SendListView, SendView}; use crate::{Client, Result}; diff --git a/crates/bitwarden-uniffi/src/uniffi_support.rs b/crates/bitwarden-uniffi/src/uniffi_support.rs index 74f484869..282b03460 100644 --- a/crates/bitwarden-uniffi/src/uniffi_support.rs +++ b/crates/bitwarden-uniffi/src/uniffi_support.rs @@ -4,6 +4,10 @@ use uuid::Uuid; // Forward the type definitions to the main bitwarden crate type DateTime = chrono::DateTime; uniffi::ffi_converter_forward!(DateTime, bitwarden_core::UniFfiTag, crate::UniFfiTag); -uniffi::ffi_converter_forward!(EncString, bitwarden::UniFfiTag, crate::UniFfiTag); -uniffi::ffi_converter_forward!(AsymmetricEncString, bitwarden::UniFfiTag, crate::UniFfiTag); +uniffi::ffi_converter_forward!(EncString, bitwarden_core::UniFfiTag, crate::UniFfiTag); +uniffi::ffi_converter_forward!( + AsymmetricEncString, + bitwarden_core::UniFfiTag, + crate::UniFfiTag +); uniffi::ffi_converter_forward!(Uuid, bitwarden_core::UniFfiTag, crate::UniFfiTag); diff --git a/crates/bitwarden-uniffi/src/vault/attachments.rs b/crates/bitwarden-uniffi/src/vault/attachments.rs index e8bddd124..cb2a011a0 100644 --- a/crates/bitwarden-uniffi/src/vault/attachments.rs +++ b/crates/bitwarden-uniffi/src/vault/attachments.rs @@ -1,6 +1,6 @@ use std::{path::Path, sync::Arc}; -use bitwarden::vault::{ +use bitwarden_vault::{ Attachment, AttachmentEncryptResult, AttachmentView, Cipher, ClientVaultExt, }; diff --git a/crates/bitwarden-uniffi/src/vault/ciphers.rs b/crates/bitwarden-uniffi/src/vault/ciphers.rs index 1195cf81a..64751b37c 100644 --- a/crates/bitwarden-uniffi/src/vault/ciphers.rs +++ b/crates/bitwarden-uniffi/src/vault/ciphers.rs @@ -1,13 +1,9 @@ use std::sync::Arc; -use bitwarden::{ - error::Error, - vault::{Cipher, CipherListView, CipherView, ClientVaultExt}, -}; -use bitwarden_vault::Fido2CredentialView; +use bitwarden_vault::{Cipher, CipherListView, CipherView, ClientVaultExt, Fido2CredentialView}; use uuid::Uuid; -use crate::{Client, Result}; +use crate::{error::Error, Client, Result}; #[derive(uniffi::Object)] pub struct ClientCiphers(pub Arc); diff --git a/crates/bitwarden-uniffi/src/vault/collections.rs b/crates/bitwarden-uniffi/src/vault/collections.rs index 84d928e64..250588e8d 100644 --- a/crates/bitwarden-uniffi/src/vault/collections.rs +++ b/crates/bitwarden-uniffi/src/vault/collections.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use bitwarden::vault::{ClientVaultExt, Collection, CollectionView}; +use bitwarden_vault::{ClientVaultExt, Collection, CollectionView}; use crate::{Client, Result}; diff --git a/crates/bitwarden-uniffi/src/vault/folders.rs b/crates/bitwarden-uniffi/src/vault/folders.rs index 2efeb1f11..758d09173 100644 --- a/crates/bitwarden-uniffi/src/vault/folders.rs +++ b/crates/bitwarden-uniffi/src/vault/folders.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use bitwarden::vault::{ClientVaultExt, Folder, FolderView}; +use bitwarden_vault::{ClientVaultExt, Folder, FolderView}; use crate::{Client, Result}; diff --git a/crates/bitwarden-uniffi/src/vault/mod.rs b/crates/bitwarden-uniffi/src/vault/mod.rs index 4cf840868..cec625e33 100644 --- a/crates/bitwarden-uniffi/src/vault/mod.rs +++ b/crates/bitwarden-uniffi/src/vault/mod.rs @@ -1,13 +1,12 @@ use std::sync::Arc; -use bitwarden::{ - error::Error, - vault::{ClientVaultExt, TotpResponse}, -}; -use bitwarden_vault::CipherListView; +use bitwarden_vault::{CipherListView, ClientVaultExt, TotpResponse}; use chrono::{DateTime, Utc}; -use crate::{error::Result, Client}; +use crate::{ + error::{Error, Result}, + Client, +}; pub mod attachments; pub mod ciphers; diff --git a/crates/bitwarden-uniffi/src/vault/password_history.rs b/crates/bitwarden-uniffi/src/vault/password_history.rs index 3fa0fd3bc..330e91214 100644 --- a/crates/bitwarden-uniffi/src/vault/password_history.rs +++ b/crates/bitwarden-uniffi/src/vault/password_history.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use bitwarden::vault::{ClientVaultExt, PasswordHistory, PasswordHistoryView}; +use bitwarden_vault::{ClientVaultExt, PasswordHistory, PasswordHistoryView}; use crate::{Client, Result}; diff --git a/crates/bitwarden-wasm-internal/Cargo.toml b/crates/bitwarden-wasm-internal/Cargo.toml index df69015cf..4f68c08d6 100644 --- a/crates/bitwarden-wasm-internal/Cargo.toml +++ b/crates/bitwarden-wasm-internal/Cargo.toml @@ -15,7 +15,7 @@ keywords.workspace = true crate-type = ["cdylib"] [dependencies] -bitwarden = { workspace = true, features = ["internal", "wasm"] } +bitwarden = { workspace = true, features = ["wasm"] } console_error_panic_hook = "0.1.7" console_log = { version = "1.0.0", features = ["color"] } js-sys = "0.3.68" diff --git a/crates/bitwarden-wasm/Cargo.toml b/crates/bitwarden-wasm/Cargo.toml index c4be614d3..fd3c278f8 100644 --- a/crates/bitwarden-wasm/Cargo.toml +++ b/crates/bitwarden-wasm/Cargo.toml @@ -19,10 +19,7 @@ argon2 = { version = ">=0.5.0, <0.6", features = [ "alloc", "zeroize", ], default-features = false } -bitwarden-json = { path = "../bitwarden-json", features = [ - "secrets", - "internal", -] } +bitwarden-json = { path = "../bitwarden-json", features = ["secrets"] } console_error_panic_hook = "0.1.7" console_log = { version = "1.0.0", features = ["color"] } js-sys = "0.3.68" diff --git a/crates/bitwarden/Cargo.toml b/crates/bitwarden/Cargo.toml index 1d09377cf..3626f9d11 100644 --- a/crates/bitwarden/Cargo.toml +++ b/crates/bitwarden/Cargo.toml @@ -16,25 +16,9 @@ license-file.workspace = true [features] default = ["secrets"] -internal = [ - "bitwarden-core/internal", - "dep:bitwarden-exporters", - "dep:bitwarden-generators", - "dep:bitwarden-send", - "dep:bitwarden-vault", -] # Internal testing methods no-memory-hardening = [ "bitwarden-core/no-memory-hardening", ] # Disable memory hardening features -uniffi = [ - "bitwarden-core/uniffi", - "bitwarden-crypto/uniffi", - "bitwarden-exporters/uniffi", - "bitwarden-fido/uniffi", - "bitwarden-generators/uniffi", - "bitwarden-send/uniffi", - "bitwarden-vault/uniffi", -] # Uniffi bindings secrets = [ "bitwarden-core/secrets", "dep:bitwarden-sm", @@ -43,16 +27,9 @@ secrets = [ wasm = ["bitwarden-core/wasm"] # WASM support [dependencies] -bitwarden-api-api = { workspace = true } -bitwarden-api-identity = { workspace = true } bitwarden-core = { workspace = true } -bitwarden-crypto = { workspace = true } -bitwarden-exporters = { workspace = true, optional = true } -bitwarden-fido = { workspace = true, optional = true } bitwarden-generators = { workspace = true, optional = true } -bitwarden-send = { workspace = true, optional = true } bitwarden-sm = { workspace = true, optional = true } -bitwarden-vault = { workspace = true, optional = true } thiserror = { workspace = true } [dev-dependencies] diff --git a/crates/bitwarden/src/error.rs b/crates/bitwarden/src/error.rs index 06ef09648..163ccc208 100644 --- a/crates/bitwarden/src/error.rs +++ b/crates/bitwarden/src/error.rs @@ -1,77 +1,13 @@ //! Errors that can occur when using this SDK -use std::{borrow::Cow, fmt::Debug}; +use std::fmt::Debug; -#[cfg(feature = "internal")] -use bitwarden_exporters::ExportError; -#[cfg(feature = "internal")] -use bitwarden_generators::{PassphraseError, PasswordError, UsernameError}; use thiserror::Error; #[derive(Debug, Error)] pub enum Error { #[error(transparent)] Core(#[from] bitwarden_core::Error), - - // Generators - #[cfg(feature = "internal")] - #[error(transparent)] - UsernameError(#[from] UsernameError), - #[cfg(feature = "internal")] - #[error(transparent)] - PassphraseError(#[from] PassphraseError), - #[cfg(feature = "internal")] - #[error(transparent)] - PasswordError(#[from] PasswordError), - - // Vault - #[cfg(feature = "internal")] - #[error(transparent)] - Cipher(#[from] bitwarden_vault::CipherError), - #[cfg(feature = "internal")] - #[error(transparent)] - Totp(#[from] bitwarden_vault::TotpError), - - #[cfg(feature = "internal")] - #[error(transparent)] - ExportError(#[from] ExportError), - - // Fido - #[cfg(all(feature = "uniffi", feature = "internal"))] - #[error(transparent)] - MakeCredential(#[from] bitwarden_fido::MakeCredentialError), - #[cfg(all(feature = "uniffi", feature = "internal"))] - #[error(transparent)] - GetAssertion(#[from] bitwarden_fido::GetAssertionError), - #[cfg(all(feature = "uniffi", feature = "internal"))] - #[error(transparent)] - SilentlyDiscoverCredentials(#[from] bitwarden_fido::SilentlyDiscoverCredentialsError), - #[cfg(all(feature = "uniffi", feature = "internal"))] - #[error(transparent)] - CredentialsForAutofillError(#[from] bitwarden_fido::CredentialsForAutofillError), - #[cfg(all(feature = "uniffi", feature = "internal"))] - #[error(transparent)] - DecryptFido2AutofillCredentialsError( - #[from] bitwarden_fido::DecryptFido2AutofillCredentialsError, - ), - #[cfg(all(feature = "uniffi", feature = "internal"))] - #[error(transparent)] - Fido2Client(#[from] bitwarden_fido::Fido2ClientError), - - #[error("Internal error: {0}")] - Internal(Cow<'static, str>), -} - -impl From for Error { - fn from(s: String) -> Self { - Self::Internal(s.into()) - } -} - -impl From<&'static str> for Error { - fn from(s: &'static str) -> Self { - Self::Internal(s.into()) - } } // Ensure that the error messages implement Send and Sync diff --git a/crates/bitwarden/src/lib.rs b/crates/bitwarden/src/lib.rs index c87693ce7..77a063f52 100644 --- a/crates/bitwarden/src/lib.rs +++ b/crates/bitwarden/src/lib.rs @@ -61,34 +61,7 @@ mod readme {} pub use bitwarden_core::*; pub mod error; -#[cfg(feature = "internal")] -pub mod internal { - pub mod generators { - pub use bitwarden_generators::*; - } - - pub mod exporters { - pub use bitwarden_exporters::*; - } - - pub mod send { - pub use bitwarden_send::*; - } - - pub mod vault { - pub use bitwarden_vault::*; - } - - #[cfg(feature = "uniffi")] - pub mod fido { - pub use bitwarden_fido::*; - } -} -#[cfg(feature = "internal")] -pub use internal::*; - -// Re-export generators used for secrets-manager, internal flag already exports all generators -#[cfg(all(feature = "secrets", not(feature = "internal")))] +#[cfg(feature = "secrets")] pub mod generators { pub use bitwarden_generators::{ClientGeneratorExt, PasswordError, PasswordGeneratorRequest}; } diff --git a/crates/bw/Cargo.toml b/crates/bw/Cargo.toml index cb8e02ba1..a2ba807c3 100644 --- a/crates/bw/Cargo.toml +++ b/crates/bw/Cargo.toml @@ -14,9 +14,11 @@ repository.workspace = true license-file.workspace = true [dependencies] -bitwarden = { workspace = true, features = ["internal"] } bitwarden-cli = { workspace = true } +bitwarden-core = { workspace = true } bitwarden-crypto = { workspace = true } +bitwarden-generators = { workspace = true } +bitwarden-vault = { workspace = true } clap = { version = "4.5.4", features = ["derive", "env"] } color-eyre = "0.6.3" env_logger = "0.11.1" diff --git a/crates/bw/src/auth/login.rs b/crates/bw/src/auth/login.rs index 51fe64a39..131d39f02 100644 --- a/crates/bw/src/auth/login.rs +++ b/crates/bw/src/auth/login.rs @@ -1,12 +1,12 @@ -use bitwarden::{ +use bitwarden_cli::text_prompt_when_none; +use bitwarden_core::{ auth::login::{ ApiKeyLoginRequest, PasswordLoginRequest, TwoFactorEmailRequest, TwoFactorProvider, TwoFactorRequest, }, - vault::{ClientVaultExt, SyncRequest}, Client, }; -use bitwarden_cli::text_prompt_when_none; +use bitwarden_vault::{ClientVaultExt, SyncRequest}; use color_eyre::eyre::{bail, Result}; use inquire::{Password, Text}; use log::{debug, error, info}; diff --git a/crates/bw/src/main.rs b/crates/bw/src/main.rs index a9a7eeea2..06d5d0bd5 100644 --- a/crates/bw/src/main.rs +++ b/crates/bw/src/main.rs @@ -1,9 +1,8 @@ -use bitwarden::{ - auth::RegisterRequest, - generators::{ClientGeneratorExt, PassphraseGeneratorRequest, PasswordGeneratorRequest}, - ClientSettings, -}; use bitwarden_cli::{install_color_eyre, text_prompt_when_none, Color}; +use bitwarden_core::{auth::RegisterRequest, ClientSettings}; +use bitwarden_generators::{ + ClientGeneratorExt, PassphraseGeneratorRequest, PasswordGeneratorRequest, +}; use clap::{command, Args, CommandFactory, Parser, Subcommand}; use color_eyre::eyre::Result; use inquire::Password; @@ -157,7 +156,7 @@ async fn process_commands() -> Result<()> { identity_url: format!("{}/identity", server), ..Default::default() }); - let client = bitwarden::Client::new(settings); + let client = bitwarden_core::Client::new(settings); match args.command { // FIXME: Rust CLI will not support password login! @@ -188,7 +187,7 @@ async fn process_commands() -> Result<()> { identity_url: format!("{}/identity", server), ..Default::default() }); - let client = bitwarden::Client::new(settings); + let client = bitwarden_core::Client::new(settings); let email = text_prompt_when_none("Email", email)?; let password = Password::new("Password").prompt()?; @@ -207,7 +206,7 @@ async fn process_commands() -> Result<()> { } // Not login, assuming we have a config - let client = bitwarden::Client::new(None); + let client = bitwarden_core::Client::new(None); // And finally we process all the commands which require authentication match command { diff --git a/crates/sdk-schemas/Cargo.toml b/crates/sdk-schemas/Cargo.toml index b4dd496a4..13a664873 100644 --- a/crates/sdk-schemas/Cargo.toml +++ b/crates/sdk-schemas/Cargo.toml @@ -12,7 +12,6 @@ license-file.workspace = true keywords.workspace = true [features] -internal = ["bitwarden/internal", "bitwarden-json/internal"] [dependencies] anyhow = "1.0.82" diff --git a/crates/sdk-schemas/src/main.rs b/crates/sdk-schemas/src/main.rs index 66683256b..2db3ce5fe 100644 --- a/crates/sdk-schemas/src/main.rs +++ b/crates/sdk-schemas/src/main.rs @@ -109,13 +109,6 @@ struct SchemaTypes { projects: Response, projects_delete: Response, password: Response, - - #[cfg(feature = "internal")] - fingerprint: Response, - #[cfg(feature = "internal")] - sync: Response, - #[cfg(feature = "internal")] - user_api_key: Response, } fn main() -> Result<()> { diff --git a/support/scripts/schemas.ts b/support/scripts/schemas.ts index 3eaad1903..873a9de7d 100644 --- a/support/scripts/schemas.ts +++ b/support/scripts/schemas.ts @@ -7,18 +7,6 @@ import { } from "quicktype-core"; import fs from "fs"; -import path from "path"; - -async function* walk(dir: string): AsyncIterable { - for await (const d of await fs.promises.opendir(dir)) { - const entry = path.join(dir, d.name); - if (d.isDirectory()) { - yield* walk(entry); - } else if (d.isFile()) { - yield entry; - } - } -} async function main() { const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore());