Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-1724] Sqlite WASM #924

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
21e6143
Explore using sqlite
Hinton Mar 5, 2024
87a736d
Wire up repository to sync
Hinton Mar 11, 2024
9423eb6
Merge branch 'main' of github.com:bitwarden/sdk into ps/sqlite
Hinton May 30, 2024
04dd9ff
Refactor interface into vault module
Hinton May 30, 2024
41ed412
Improve error handling
Hinton May 30, 2024
e447bbb
Resolve linting and remove an expect
Hinton May 30, 2024
ea9f4e1
Create a DB Migrator
Hinton Jun 3, 2024
9e2d3a2
Clean up migrator
Hinton Jun 3, 2024
99cb6ac
Use DatabaseError
Hinton Jun 3, 2024
4bd0be9
Format
Hinton Jun 3, 2024
e2b06a6
Merge branch 'main' of github.com:bitwarden/sdk into ps/sqlite
Hinton Jun 28, 2024
017055b
Fix compile
Hinton Jul 2, 2024
e12e6cb
Initial wasm effort
Hinton Jul 15, 2024
0c3c558
Abstract out a database trait + implementations
Hinton Jul 22, 2024
b9af5ef
Fix tests
Hinton Jul 23, 2024
4e33c91
"Working" wrapper
Hinton Jul 23, 2024
37733d5
Benchmark logic
Hinton Jul 25, 2024
431f3a5
Support rusqlite params in wasm
Hinton Jul 26, 2024
4dfc556
Implement select
Hinton Jul 29, 2024
40f9b68
fmt
Hinton Jul 29, 2024
0c8097c
Remove unused feature, fix bw
Hinton Jul 29, 2024
2cb7e9d
Fix bws
Hinton Jul 29, 2024
adf7b09
Remove duplicated files
Hinton Jul 29, 2024
65da8b8
Implement versions for wasm
Hinton Jul 29, 2024
286eb96
Switch to using tokio mutex
Hinton Jul 29, 2024
3bc91ee
Merge branch 'main' of github.com:bitwarden/sdk into sqlite-wasm
Hinton Jul 29, 2024
c69e5e7
Fix tests
Hinton Jul 29, 2024
cd105f7
Fix compile for all crates
Hinton Jul 29, 2024
defac68
Add missing feature to tokio
Hinton Jul 29, 2024
e5fdbbf
Remove old sqlite test
Hinton Aug 2, 2024
6b188e6
Fix repository implementation
Hinton Aug 2, 2024
2569b57
Start cleaning up
Hinton Aug 12, 2024
31d5886
Merge branch 'main' of github.com:bitwarden/sdk into sqlite-wasm
Hinton Aug 12, 2024
3d24452
Make tokio optional
Hinton Aug 12, 2024
e59263d
Cleanup and fix compile
Hinton Aug 13, 2024
2cf9146
Cleanup db crate, introduce explicit RowError type
Hinton Aug 13, 2024
36ea4ba
Cleanup cargo files
Hinton Aug 13, 2024
e186a60
Remove file from old conflict
Hinton Aug 13, 2024
ad7f5c2
Restore build.sh
Hinton Aug 13, 2024
aa83130
Format
Hinton Aug 13, 2024
3fafd17
Bump MSRV to 1.75
Hinton Aug 13, 2024
f52ea60
Use bundled rusqlite
Hinton Aug 13, 2024
05f6407
Bump wasm bindgen
Hinton Aug 13, 2024
b7ca853
Merge branch 'main' of github.com:bitwarden/sdk into sqlite-wasm
Hinton Aug 13, 2024
1bbea33
Document params
Hinton Aug 13, 2024
eeeef18
Fix clippy
Hinton Aug 13, 2024
3a8129a
Update android example
Hinton Aug 13, 2024
8bcd963
Update swift
Hinton Aug 13, 2024
6ee3844
Tweak rustsqlite macros
Hinton Aug 19, 2024
0c0c4a7
Merge branch 'main' of github.com:bitwarden/sdk into sqlite-wasm
Hinton Aug 30, 2024
d9e470e
Resolve some review feedback
Hinton Sep 2, 2024
914f016
Adjust migrator syntax
Hinton Sep 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/minimum-rust-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: dtolnay/rust-toolchain@7b1c307e0dcbda6122208f10795a713336a9b35a # stable
with:
# Important: When updating this, make sure to update the Readme file
# and also the `rust-version` field in all the `Cargo.toml`.
# and also the `rust-version` field in the workspace `Cargo.toml`.
toolchain: 1.75.0
targets: ${{ matrix.settings.target }}

Expand Down
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ bld/
.idea
xcuserdata/

# Added by cargo
#
# already existing elements were commented out
# Databases
*.sqlite
crates/bitwarden-db-tests/pkg

#/target
node_modules/
clients/python/env/

Expand Down
97 changes: 97 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ bitwarden-api-identity = { path = "crates/bitwarden-api-identity", version = "=0
bitwarden-cli = { path = "crates/bitwarden-cli", version = "=0.5.0" }
bitwarden-core = { path = "crates/bitwarden-core", version = "=0.5.0" }
bitwarden-crypto = { path = "crates/bitwarden-crypto", version = "=0.5.0" }
bitwarden-db = { path = "crates/bitwarden-db", version = "=0.5.0" }
bitwarden-exporters = { path = "crates/bitwarden-exporters", version = "=0.5.0" }
bitwarden-fido = { path = "crates/bitwarden-fido", version = "=0.5.0" }
bitwarden-generators = { path = "crates/bitwarden-generators", version = "=0.5.0" }
bitwarden-send = { path = "crates/bitwarden-send", version = "=0.5.0" }
bitwarden-sm = { path = "crates/bitwarden-sm", version = "=0.5.0" }
bitwarden-vault = { path = "crates/bitwarden-vault", version = "=0.5.0" }

tokio = { version = "1.36.0", features = ["rt", "macros", "sync"] }

[workspace.lints.clippy]
unused_async = "deny"
unwrap_used = "deny"
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-c/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ crate-type = ["staticlib", "cdylib"]
bench = false

[target.'cfg(not(target_arch="wasm32"))'.dependencies]
tokio = { version = ">=1.28.2, <2.0", features = ["rt-multi-thread", "macros"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
bitwarden-json = { path = "../bitwarden-json", features = ["secrets"] }

[dependencies]
Expand Down
4 changes: 3 additions & 1 deletion crates/bitwarden-c/src/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
.build()
.expect("Failed to build tokio runtime");

let client = if c_str_ptr.is_null() {
let client_future = if c_str_ptr.is_null() {

Check warning on line 42 in crates/bitwarden-c/src/c.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-c/src/c.rs#L42

Added line #L42 was not covered by tests
Client::new(None)
} else {
let input_string = str::from_utf8(unsafe { CStr::from_ptr(c_str_ptr) }.to_bytes())
Expand All @@ -48,6 +48,8 @@
Client::new(Some(input_string))
};

let client = runtime.block_on(client_future);

Check warning on line 52 in crates/bitwarden-c/src/c.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-c/src/c.rs#L51-L52

Added lines #L51 - L52 were not covered by tests
box_ptr!(CClient { runtime, client })
}

Expand Down
6 changes: 4 additions & 2 deletions crates/bitwarden-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ uniffi = [
"dep:p256",
] # Uniffi bindings
secrets = [] # Secrets manager API
state = ["dep:bitwarden-db", "dep:tokio"] # Persistent state

[dependencies]
async-trait = ">=0.1.80, <0.2"
base64 = ">=0.22.1, <0.23"
bitwarden-api-api = { workspace = true }
bitwarden-api-identity = { workspace = true }
bitwarden-crypto = { workspace = true }
bitwarden-db = { workspace = true, optional = true }
chrono = { version = ">=0.4.26, <0.5", features = [
"clock",
"serde",
Expand All @@ -58,6 +60,7 @@ serde_repr = ">=0.1.12, <0.2"
sha1 = ">=0.10.5, <0.11"
sha2 = ">=0.10.6, <0.11"
thiserror = ">=1.0.40, <2.0"
tokio = { workspace = true, optional = true }
uniffi = { version = "=0.28.1", optional = true, features = ["tokio"] }
uuid = { version = ">=1.3.3, <2.0", features = ["serde"] }
validator = { version = "0.18.1", features = ["derive"] }
Expand All @@ -79,9 +82,8 @@ reqwest = { version = ">=0.12.5, <0.13", features = [
], default-features = false }

[dev-dependencies]
bitwarden-crypto = { workspace = true }
rand_chacha = "0.3.1"
tokio = { version = "1.36.0", features = ["rt", "macros"] }
tokio = { workspace = true }
wiremock = "0.6.0"
zeroize = { version = ">=1.7.0, <2.0", features = ["derive", "aarch64"] }

Expand Down
10 changes: 5 additions & 5 deletions crates/bitwarden-core/src/auth/auth_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ mod tests {
use super::*;
use crate::mobile::crypto::{AuthRequestMethod, InitUserCryptoMethod, InitUserCryptoRequest};

#[test]
fn test_approve() {
let client = Client::new(None);
#[tokio::test]
async fn test_approve() {
let client = Client::new(None).await;

let master_key = MasterKey::derive(
"asdfasdfasdf",
Expand Down Expand Up @@ -198,7 +198,7 @@ mod tests {
let private_key = "2.yN7l00BOlUE0Sb0M//Q53w==|EwKG/BduQRQ33Izqc/ogoBROIoI5dmgrxSo82sgzgAMIBt3A2FZ9vPRMY+GWT85JiqytDitGR3TqwnFUBhKUpRRAq4x7rA6A1arHrFp5Tp1p21O3SfjtvB3quiOKbqWk6ZaU1Np9HwqwAecddFcB0YyBEiRX3VwF2pgpAdiPbSMuvo2qIgyob0CUoC/h4Bz1be7Qa7B0Xw9/fMKkB1LpOm925lzqosyMQM62YpMGkjMsbZz0uPopu32fxzDWSPr+kekNNyLt9InGhTpxLmq1go/pXR2uw5dfpXc5yuta7DB0EGBwnQ8Vl5HPdDooqOTD9I1jE0mRyuBpWTTI3FRnu3JUh3rIyGBJhUmHqGZvw2CKdqHCIrQeQkkEYqOeJRJVdBjhv5KGJifqT3BFRwX/YFJIChAQpebNQKXe/0kPivWokHWwXlDB7S7mBZzhaAPidZvnuIhalE2qmTypDwHy22FyqV58T8MGGMchcASDi/QXI6kcdpJzPXSeU9o+NC68QDlOIrMVxKFeE7w7PvVmAaxEo0YwmuAzzKy9QpdlK0aab/xE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iXv9oWzYtzK2LBT6Yht4IT4MijEkk0fwFdrVQ4=";

// Initialize an existing client which is unlocked
let existing_device = Client::new(None);
let existing_device = Client::new(None).await;

let master_key = MasterKey::derive("asdfasdfasdf", email, &kdf).unwrap();

Expand All @@ -208,7 +208,7 @@ mod tests {
.unwrap();

// Initialize a new device which will request to be logged in
let new_device = Client::new(None);
let new_device = Client::new(None).await;

// Initialize an auth request, and approve it on the existing device
let auth_req = new_auth_request(email).unwrap();
Expand Down
18 changes: 9 additions & 9 deletions crates/bitwarden-core/src/auth/password/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ mod tests {

use crate::auth::password::{validate::validate_password_user_key, validate_password};

#[test]
fn test_validate_password() {
#[tokio::test]
async fn test_validate_password() {
use std::num::NonZeroU32;

use crate::client::{Client, LoginMethod, UserLoginMethod};

let client = Client::new(None);
let client = Client::new(None).await;
client
.internal
.set_login_method(LoginMethod::User(UserLoginMethod::Username {
Expand All @@ -108,15 +108,15 @@ mod tests {
}

#[cfg(feature = "internal")]
#[test]
fn test_validate_password_user_key() {
#[tokio::test]
async fn test_validate_password_user_key() {
use std::num::NonZeroU32;

use bitwarden_crypto::{Kdf, MasterKey};

use crate::client::{Client, LoginMethod, UserLoginMethod};

let client = Client::new(None);
let client = Client::new(None).await;

let password = "asdfasdfasdf";
let email = "[email protected]";
Expand Down Expand Up @@ -151,15 +151,15 @@ mod tests {
}

#[cfg(feature = "internal")]
#[test]
fn test_validate_password_user_key_wrong_password() {
#[tokio::test]
async fn test_validate_password_user_key_wrong_password() {
use std::num::NonZeroU32;

use bitwarden_crypto::{Kdf, MasterKey};

use crate::client::{Client, LoginMethod, UserLoginMethod};

let client = Client::new(None);
let client = Client::new(None).await;

let password = "asdfasdfasdf";
let email = "[email protected]";
Expand Down
Loading
Loading