diff --git a/Cargo.lock b/Cargo.lock index 9672d26e9..184066772 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3451,7 +3451,7 @@ checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" [[package]] name = "uniffi" version = "0.25.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" +source = "git+https://github.com/mozilla/uniffi-rs?rev=b369e7c15b1b7ebca34de9028209db11b7ff353d#b369e7c15b1b7ebca34de9028209db11b7ff353d" dependencies = [ "anyhow", "camino", @@ -3472,7 +3472,7 @@ dependencies = [ [[package]] name = "uniffi_bindgen" version = "0.25.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" +source = "git+https://github.com/mozilla/uniffi-rs?rev=b369e7c15b1b7ebca34de9028209db11b7ff353d#b369e7c15b1b7ebca34de9028209db11b7ff353d" dependencies = [ "anyhow", "askama", @@ -3495,7 +3495,7 @@ dependencies = [ [[package]] name = "uniffi_build" version = "0.25.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" +source = "git+https://github.com/mozilla/uniffi-rs?rev=b369e7c15b1b7ebca34de9028209db11b7ff353d#b369e7c15b1b7ebca34de9028209db11b7ff353d" dependencies = [ "anyhow", "camino", @@ -3505,7 +3505,7 @@ dependencies = [ [[package]] name = "uniffi_checksum_derive" version = "0.25.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" +source = "git+https://github.com/mozilla/uniffi-rs?rev=b369e7c15b1b7ebca34de9028209db11b7ff353d#b369e7c15b1b7ebca34de9028209db11b7ff353d" dependencies = [ "quote", "syn 2.0.38", @@ -3514,7 +3514,7 @@ dependencies = [ [[package]] name = "uniffi_core" version = "0.25.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" +source = "git+https://github.com/mozilla/uniffi-rs?rev=b369e7c15b1b7ebca34de9028209db11b7ff353d#b369e7c15b1b7ebca34de9028209db11b7ff353d" dependencies = [ "anyhow", "bytes", @@ -3529,7 +3529,7 @@ dependencies = [ [[package]] name = "uniffi_macros" version = "0.25.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" +source = "git+https://github.com/mozilla/uniffi-rs?rev=b369e7c15b1b7ebca34de9028209db11b7ff353d#b369e7c15b1b7ebca34de9028209db11b7ff353d" dependencies = [ "bincode", "camino", @@ -3547,7 +3547,7 @@ dependencies = [ [[package]] name = "uniffi_meta" version = "0.25.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" +source = "git+https://github.com/mozilla/uniffi-rs?rev=b369e7c15b1b7ebca34de9028209db11b7ff353d#b369e7c15b1b7ebca34de9028209db11b7ff353d" dependencies = [ "anyhow", "bytes", @@ -3558,7 +3558,7 @@ dependencies = [ [[package]] name = "uniffi_testing" version = "0.25.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" +source = "git+https://github.com/mozilla/uniffi-rs?rev=b369e7c15b1b7ebca34de9028209db11b7ff353d#b369e7c15b1b7ebca34de9028209db11b7ff353d" dependencies = [ "anyhow", "camino", @@ -3570,7 +3570,7 @@ dependencies = [ [[package]] name = "uniffi_udl" version = "0.25.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" +source = "git+https://github.com/mozilla/uniffi-rs?rev=b369e7c15b1b7ebca34de9028209db11b7ff353d#b369e7c15b1b7ebca34de9028209db11b7ff353d" dependencies = [ "anyhow", "uniffi_meta", @@ -3777,7 +3777,7 @@ dependencies = [ [[package]] name = "weedle2" version = "4.0.0" -source = "git+https://github.com/mozilla/uniffi-rs?rev=eb97592f8c48a7f5cf02a94662b8b7861a6544f3#eb97592f8c48a7f5cf02a94662b8b7861a6544f3" +source = "git+https://github.com/mozilla/uniffi-rs?rev=b369e7c15b1b7ebca34de9028209db11b7ff353d#b369e7c15b1b7ebca34de9028209db11b7ff353d" dependencies = [ "nom", ] diff --git a/Cargo.toml b/Cargo.toml index a192c14e5..da8805342 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,8 +24,8 @@ codegen-units = 1 # Using master until 0.25.1 is released to fix https://github.com/mozilla/uniffi-rs/issues/1798 [patch.crates-io] -uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "eb97592f8c48a7f5cf02a94662b8b7861a6544f3" } -uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "eb97592f8c48a7f5cf02a94662b8b7861a6544f3" } -uniffi_bindgen = { git = "https://github.com/mozilla/uniffi-rs", rev = "eb97592f8c48a7f5cf02a94662b8b7861a6544f3" } -uniffi_core = { git = "https://github.com/mozilla/uniffi-rs", rev = "eb97592f8c48a7f5cf02a94662b8b7861a6544f3" } -uniffi_macros = { git = "https://github.com/mozilla/uniffi-rs", rev = "eb97592f8c48a7f5cf02a94662b8b7861a6544f3" } +uniffi = { git = "https://github.com/mozilla/uniffi-rs", rev = "b369e7c15b1b7ebca34de9028209db11b7ff353d" } +uniffi_build = { git = "https://github.com/mozilla/uniffi-rs", rev = "b369e7c15b1b7ebca34de9028209db11b7ff353d" } +uniffi_bindgen = { git = "https://github.com/mozilla/uniffi-rs", rev = "b369e7c15b1b7ebca34de9028209db11b7ff353d" } +uniffi_core = { git = "https://github.com/mozilla/uniffi-rs", rev = "b369e7c15b1b7ebca34de9028209db11b7ff353d" } +uniffi_macros = { git = "https://github.com/mozilla/uniffi-rs", rev = "b369e7c15b1b7ebca34de9028209db11b7ff353d" } diff --git a/crates/bitwarden-napi/package-lock.json b/crates/bitwarden-napi/package-lock.json index 4a85cb304..65266d1e4 100644 --- a/crates/bitwarden-napi/package-lock.json +++ b/crates/bitwarden-napi/package-lock.json @@ -55,9 +55,9 @@ } }, "node_modules/@napi-rs/cli": { - "version": "2.16.3", - "resolved": "https://registry.npmjs.org/@napi-rs/cli/-/cli-2.16.3.tgz", - "integrity": "sha512-3mLNPlbbOhpbIUKicLrJtIearlHXUuXL3UeueYyRRplpVMNkdn8xCyzY6PcYZi3JXR8bmCOiWgkVmLnrSL7DKw==", + "version": "2.16.5", + "resolved": "https://registry.npmjs.org/@napi-rs/cli/-/cli-2.16.5.tgz", + "integrity": "sha512-mFEzwrg4IOLngGd2/P6yeqIWgwQNn59Z08n1rndu6kLDq1gg954NH9cM1O9Da0RJuybt46p43lqgSsnAY2mxqA==", "dev": true, "bin": { "napi": "scripts/index.js" diff --git a/crates/bitwarden-uniffi/src/vault/sends.rs b/crates/bitwarden-uniffi/src/vault/sends.rs index 696c4a861..6e2f1b879 100644 --- a/crates/bitwarden-uniffi/src/vault/sends.rs +++ b/crates/bitwarden-uniffi/src/vault/sends.rs @@ -1,6 +1,6 @@ use std::{path::Path, sync::Arc}; -use bitwarden::vault::{self, SendListView, SendView}; +use bitwarden::vault::{Send, SendListView, SendView}; use crate::{Client, Result}; @@ -10,12 +10,12 @@ pub struct ClientSends(pub Arc); #[uniffi::export] impl ClientSends { /// Encrypt send - pub async fn encrypt(&self, send: SendView) -> Result { + pub async fn encrypt(&self, send: SendView) -> Result { Ok(self.0 .0.read().await.vault().sends().encrypt(send).await?) } /// Encrypt a send file in memory - pub async fn encrypt_buffer(&self, send: vault::Send, buffer: Vec) -> Result> { + pub async fn encrypt_buffer(&self, send: Send, buffer: Vec) -> Result> { Ok(self .0 .0 @@ -30,7 +30,7 @@ impl ClientSends { /// Encrypt a send file located in the file system pub async fn encrypt_file( &self, - send: vault::Send, + send: Send, decrypted_file_path: String, encrypted_file_path: String, ) -> Result<()> { @@ -50,12 +50,12 @@ impl ClientSends { } /// Decrypt send - pub async fn decrypt(&self, send: vault::Send) -> Result { + pub async fn decrypt(&self, send: Send) -> Result { Ok(self.0 .0.read().await.vault().sends().decrypt(send).await?) } /// Decrypt send list - pub async fn decrypt_list(&self, sends: Vec) -> Result> { + pub async fn decrypt_list(&self, sends: Vec) -> Result> { Ok(self .0 .0 @@ -68,7 +68,7 @@ impl ClientSends { } /// Decrypt a send file in memory - pub async fn decrypt_buffer(&self, send: vault::Send, buffer: Vec) -> Result> { + pub async fn decrypt_buffer(&self, send: Send, buffer: Vec) -> Result> { Ok(self .0 .0 @@ -83,7 +83,7 @@ impl ClientSends { /// Decrypt a send file located in the file system pub async fn decrypt_file( &self, - send: vault::Send, + send: Send, encrypted_file_path: String, decrypted_file_path: String, ) -> Result<()> { diff --git a/crates/bitwarden/src/crypto/aes_ops.rs b/crates/bitwarden/src/crypto/aes_ops.rs index 734d3f760..3deedabd8 100644 --- a/crates/bitwarden/src/crypto/aes_ops.rs +++ b/crates/bitwarden/src/crypto/aes_ops.rs @@ -61,6 +61,7 @@ pub fn decrypt_aes256_hmac( /// ## Returns /// /// A AesCbc256_B64 EncString +#[allow(unused)] pub fn encrypt_aes256(data_dec: &[u8], key: GenericArray) -> ([u8; 16], Vec) { let rng = rand::thread_rng(); let (iv, data) = encrypt_aes256_internal(rng, data_dec, key); @@ -120,17 +121,28 @@ fn validate_mac(mac_key: &[u8], iv: &[u8], data: &[u8]) -> Result<[u8; 32]> { #[cfg(test)] mod tests { use aes::cipher::generic_array::sequence::GenericSequence; + use base64::Engine; use rand::SeedableRng; + use crate::util::BASE64_ENGINE; + use super::*; - fn generate_array(offset: u8, increment: u8) -> GenericArray { + /// Helper function for generating a `GenericArray` of size 32 with each element being + /// a multiple of a given increment, starting from a given offset. + fn generate_generic_array(offset: u8, increment: u8) -> GenericArray { GenericArray::generate(|i| offset + i as u8 * increment) } + /// Helper function for generating a vector of a given size with each element being + /// a multiple of a given increment, starting from a given offset. + fn generate_vec(length: usize, offset: u8, increment: u8) -> Vec { + (0..length).map(|i| offset + i as u8 * increment).collect() + } + #[test] fn test_encrypt_aes256_internal() { - let key = generate_array(0, 1); + let key = generate_generic_array(0, 1); let rng = rand_chacha::ChaCha8Rng::from_seed([0u8; 32]); let result = encrypt_aes256_internal(rng, "EncryptMe!".as_bytes(), key); @@ -143,16 +155,12 @@ mod tests { ); } - fn generate_array2(length: usize, offset: u8, increment: u8) -> Vec { - (0..length).map(|i| offset + i as u8 * increment).collect() - } - #[test] fn test_validate_mac() { - let mac_key = generate_array2(16, 0, 16); + let mac_key = generate_vec(16, 0, 16); - let iv = generate_array2(16, 0, 16); - let data = generate_array2(16, 0, 16); + let iv = generate_vec(16, 0, 16); + let data = generate_vec(16, 0, 16); let result = validate_mac(&mac_key, &iv, &data); @@ -160,4 +168,27 @@ mod tests { let mac = result.unwrap(); assert_eq!(mac.len(), 32); } + + #[test] + fn test_decrypt_aes256() { + let iv = generate_vec(16, 0, 1); + let iv: &[u8; 16] = iv.as_slice().try_into().unwrap(); + let key = generate_generic_array(0, 1); + let data = BASE64_ENGINE.decode("ByUF8vhyX4ddU9gcooznwA==").unwrap(); + + let decrypted = decrypt_aes256(iv, data, key).unwrap(); + + assert_eq!(String::from_utf8(decrypted).unwrap(), "EncryptMe!"); + } + + #[test] + fn test_encrypt_decrypt_aes256() { + let key = generate_generic_array(0, 1); + let data = "EncryptMe!"; + + let (iv, encrypted) = encrypt_aes256(data.as_bytes(), key); + let decrypted = decrypt_aes256(&iv, encrypted, key).unwrap(); + + assert_eq!(String::from_utf8(decrypted).unwrap(), "EncryptMe!"); + } } diff --git a/crates/bitwarden/src/crypto/mod.rs b/crates/bitwarden/src/crypto/mod.rs index d8a1f0557..b030a5107 100644 --- a/crates/bitwarden/src/crypto/mod.rs +++ b/crates/bitwarden/src/crypto/mod.rs @@ -33,7 +33,7 @@ pub use encryptable::{Decryptable, Encryptable, LocateKey}; mod key_encryptable; pub use key_encryptable::{KeyDecryptable, KeyEncryptable}; mod aes_ops; -pub use aes_ops::{decrypt_aes256, decrypt_aes256_hmac, encrypt_aes256, encrypt_aes256_hmac}; +use aes_ops::{decrypt_aes256_hmac, encrypt_aes256_hmac}; mod symmetric_crypto_key; pub use symmetric_crypto_key::SymmetricCryptoKey; mod shareable_key; diff --git a/crates/bitwarden/src/mobile/mod.rs b/crates/bitwarden/src/mobile/mod.rs index ad2d794af..fe3083aa8 100644 --- a/crates/bitwarden/src/mobile/mod.rs +++ b/crates/bitwarden/src/mobile/mod.rs @@ -3,8 +3,11 @@ pub mod crypto; pub mod kdf; pub mod vault; -pub(crate) mod client_crypto; -pub(crate) mod client_kdf; +mod client_crypto; +mod client_kdf; + +pub use client_crypto::ClientCrypto; +pub use client_kdf::ClientKdf; // Usually we wouldn't want to expose EncStrings in the API or the schemas, // but we need them in the mobile API, so define it here to limit the scope diff --git a/crates/bitwarden/src/mobile/vault/mod.rs b/crates/bitwarden/src/mobile/vault/mod.rs index f22f004ce..97f9556af 100644 --- a/crates/bitwarden/src/mobile/vault/mod.rs +++ b/crates/bitwarden/src/mobile/vault/mod.rs @@ -5,3 +5,10 @@ mod client_password_history; mod client_sends; mod client_totp; mod client_vault; + +pub use client_ciphers::ClientCiphers; +pub use client_collection::ClientCollections; +pub use client_folders::ClientFolders; +pub use client_password_history::ClientPasswordHistory; +pub use client_sends::ClientSends; +pub use client_vault::ClientVault; diff --git a/crates/bitwarden/src/secrets_manager/mod.rs b/crates/bitwarden/src/secrets_manager/mod.rs index 0afbfe38c..27b84121e 100644 --- a/crates/bitwarden/src/secrets_manager/mod.rs +++ b/crates/bitwarden/src/secrets_manager/mod.rs @@ -3,3 +3,6 @@ pub mod secrets; mod client_projects; mod client_secrets; + +pub use client_projects::ClientProjects; +pub use client_secrets::ClientSecrets; diff --git a/crates/bitwarden/src/tool/exporters/mod.rs b/crates/bitwarden/src/tool/exporters/mod.rs index 508aae8fb..1170dbd38 100644 --- a/crates/bitwarden/src/tool/exporters/mod.rs +++ b/crates/bitwarden/src/tool/exporters/mod.rs @@ -6,6 +6,7 @@ use crate::{ }; mod client_exporter; +pub use client_exporter::ClientExporters; #[derive(JsonSchema)] #[cfg_attr(feature = "mobile", derive(uniffi::Enum))] diff --git a/crates/bitwarden/src/tool/generators/mod.rs b/crates/bitwarden/src/tool/generators/mod.rs index bdc0fb260..4d991b765 100644 --- a/crates/bitwarden/src/tool/generators/mod.rs +++ b/crates/bitwarden/src/tool/generators/mod.rs @@ -1,4 +1,5 @@ mod client_generator; mod password; +pub use client_generator::ClientGenerator; pub use password::{PassphraseGeneratorRequest, PasswordGeneratorRequest}; diff --git a/crates/bitwarden/src/tool/mod.rs b/crates/bitwarden/src/tool/mod.rs index 2130a6b0c..212ce4bf7 100644 --- a/crates/bitwarden/src/tool/mod.rs +++ b/crates/bitwarden/src/tool/mod.rs @@ -1,5 +1,5 @@ mod exporters; mod generators; -pub use exporters::ExportFormat; -pub use generators::{PassphraseGeneratorRequest, PasswordGeneratorRequest}; +pub use exporters::{ClientExporters, ExportFormat}; +pub use generators::{ClientGenerator, PassphraseGeneratorRequest, PasswordGeneratorRequest}; diff --git a/package-lock.json b/package-lock.json index 2ee17dd0a..7791b3b69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,8 +11,8 @@ "devDependencies": { "@openapitools/openapi-generator-cli": "2.7.0", "handlebars": "^4.7.8", - "prettier": "3.0.3", - "quicktype-core": "23.0.76", + "prettier": "3.1.0", + "quicktype-core": "23.0.77", "rimraf": "5.0.5", "ts-node": "10.9.1", "typescript": "5.2.2" @@ -1470,9 +1470,9 @@ } }, "node_modules/prettier": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.3.tgz", - "integrity": "sha512-L/4pUDMxcNa8R/EthV08Zt42WBO4h1rarVtK0K+QJG0X187OLo7l699jWw0GKuwzkPQ//jMFA/8Xm6Fh3J/DAg==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.0.tgz", + "integrity": "sha512-TQLvXjq5IAibjh8EpBIkNKxO749UEWABoiIZehEPiY4GNpVdhaFKqSTu+QrlU6D2dPAfubRmtJTi4K4YkQ5eXw==", "dev": true, "bin": { "prettier": "bin/prettier.cjs" @@ -1494,9 +1494,9 @@ } }, "node_modules/quicktype-core": { - "version": "23.0.76", - "resolved": "https://registry.npmjs.org/quicktype-core/-/quicktype-core-23.0.76.tgz", - "integrity": "sha512-QinZRNovSTQcFuhRKxeHb22eFmyucbG96EPaQDSbz9qvIPxUhs1BZviNc8HAkHWYFqTSET/xZcEoHpm1DeDbRg==", + "version": "23.0.77", + "resolved": "https://registry.npmjs.org/quicktype-core/-/quicktype-core-23.0.77.tgz", + "integrity": "sha512-QABFgMHVsyW7CAcLGWvIQXgjZ7ehPnebfV/3x9c5HtuJVXgYLrEG/+zyQd1O+OPWpQrhbwU97doJTZRw+acA6A==", "dev": true, "dependencies": { "@glideapps/ts-necessities": "2.1.3", diff --git a/package.json b/package.json index fdeb8fe58..ad38f3a10 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,8 @@ "devDependencies": { "@openapitools/openapi-generator-cli": "2.7.0", "handlebars": "^4.7.8", - "prettier": "3.0.3", - "quicktype-core": "23.0.76", + "prettier": "3.1.0", + "quicktype-core": "23.0.77", "rimraf": "5.0.5", "ts-node": "10.9.1", "typescript": "5.2.2"