Skip to content

Commit

Permalink
Stop depending on bitwarden for internal crates
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton committed Oct 10, 2024
1 parent 7ae040c commit c2a4c85
Show file tree
Hide file tree
Showing 14 changed files with 20 additions and 189 deletions.
8 changes: 3 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crates/bitwarden-json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
14 changes: 0 additions & 14 deletions crates/bitwarden-json/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#[cfg(feature = "internal")]
use bitwarden::vault::ClientVaultExt;
use bitwarden::ClientSettings;
#[cfg(feature = "secrets")]
use bitwarden::{
Expand Down Expand Up @@ -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 {
Expand Down
46 changes: 0 additions & 46 deletions crates/bitwarden-json/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -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")]
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-wasm-internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions crates/bitwarden-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 0 additions & 20 deletions crates/bitwarden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -47,12 +31,8 @@ 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]
Expand Down
49 changes: 0 additions & 49 deletions crates/bitwarden/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,13 @@
use std::{borrow::Cow, 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>),
}
Expand Down
29 changes: 1 addition & 28 deletions crates/bitwarden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Expand Down
4 changes: 3 additions & 1 deletion crates/bw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions crates/bw/src/auth/login.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
15 changes: 7 additions & 8 deletions crates/bw/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Check warning on line 159 in crates/bw/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bw/src/main.rs#L159

Added line #L159 was not covered by tests

match args.command {
// FIXME: Rust CLI will not support password login!
Expand Down Expand Up @@ -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);

Check warning on line 190 in crates/bw/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bw/src/main.rs#L190

Added line #L190 was not covered by tests

let email = text_prompt_when_none("Email", email)?;
let password = Password::new("Password").prompt()?;
Expand All @@ -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);

Check warning on line 209 in crates/bw/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bw/src/main.rs#L209

Added line #L209 was not covered by tests

// And finally we process all the commands which require authentication
match command {
Expand Down
1 change: 0 additions & 1 deletion crates/sdk-schemas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ license-file.workspace = true
keywords.workspace = true

[features]
internal = ["bitwarden/internal", "bitwarden-json/internal"]

[dependencies]
anyhow = "1.0.82"
Expand Down
7 changes: 0 additions & 7 deletions crates/sdk-schemas/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,6 @@ struct SchemaTypes {
projects: Response<bitwarden::secrets_manager::projects::ProjectsResponse>,
projects_delete: Response<bitwarden::secrets_manager::projects::ProjectsDeleteResponse>,
password: Response<String>,

#[cfg(feature = "internal")]
fingerprint: Response<bitwarden::platform::FingerprintResponse>,
#[cfg(feature = "internal")]
sync: Response<bitwarden::vault::SyncResponse>,
#[cfg(feature = "internal")]
user_api_key: Response<bitwarden::platform::UserApiKeyResponse>,
}

fn main() -> Result<()> {
Expand Down

0 comments on commit c2a4c85

Please sign in to comment.