diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 567f9b6e58..75a199a8c7 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -89,6 +89,9 @@ "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], + "options": { + "cwd": "${workspaceFolder}" + }, "problemMatcher": "$msCompile" }, { @@ -102,6 +105,9 @@ "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], + "options": { + "cwd": "${workspaceFolder}" + }, "problemMatcher": "$msCompile" }, { @@ -115,6 +121,9 @@ "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], + "options": { + "cwd": "${workspaceFolder}" + }, "problemMatcher": "$msCompile" }, { @@ -128,6 +137,9 @@ "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], + "options": { + "cwd": "${workspaceFolder}" + }, "problemMatcher": "$msCompile" }, { @@ -141,6 +153,9 @@ "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], + "options": { + "cwd": "${workspaceFolder}" + }, "problemMatcher": "$msCompile" }, { @@ -154,6 +169,9 @@ "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], + "options": { + "cwd": "${workspaceFolder}" + }, "problemMatcher": "$msCompile" }, { @@ -167,6 +185,9 @@ "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], + "options": { + "cwd": "${workspaceFolder}" + }, "problemMatcher": "$msCompile" }, { @@ -180,6 +201,9 @@ "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], + "options": { + "cwd": "${workspaceFolder}" + }, "problemMatcher": "$msCompile", "group": { "kind": "build", @@ -197,6 +221,9 @@ "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], + "options": { + "cwd": "${workspaceFolder}" + }, "problemMatcher": "$msCompile", "group": { "kind": "build", @@ -214,6 +241,9 @@ "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], + "options": { + "cwd": "${workspaceFolder}" + }, "problemMatcher": "$msCompile", "group": { "kind": "build", @@ -224,6 +254,9 @@ "label": "test", "type": "shell", "command": "dotnet test", + "options": { + "cwd": "${workspaceFolder}" + }, "group": { "kind": "test", "isDefault": true diff --git a/akd/Cargo.lock b/akd/Cargo.lock index e9af85112d..67a409f2a4 100644 --- a/akd/Cargo.lock +++ b/akd/Cargo.lock @@ -418,6 +418,8 @@ version = "0.1.0" dependencies = [ "akd", "blake3", + "config", + "serde", "uuid", ] @@ -2635,6 +2637,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" dependencies = [ "js-sys", + "serde", "wasm-bindgen", ] diff --git a/akd/crates/bitwarden-akd-configuration/Cargo.toml b/akd/crates/bitwarden-akd-configuration/Cargo.toml index a638a86b49..5a8dbae381 100644 --- a/akd/crates/bitwarden-akd-configuration/Cargo.toml +++ b/akd/crates/bitwarden-akd-configuration/Cargo.toml @@ -7,9 +7,15 @@ license-file.workspace = true keywords.workspace = true [dependencies] -akd = { workspace = true } +akd.workspace = true blake3 = "1.8.2" -uuid = "1.18.1" +config = { workspace = true, optional = true } +serde = { workspace = true, optional = true } +uuid = { version = "1.18.1", features = ["serde"] } [lints] workspace = true + +[features] +config = ["dep:config", "dep:serde"] +default = ["config"] diff --git a/akd/crates/bitwarden-akd-configuration/src/config.rs b/akd/crates/bitwarden-akd-configuration/src/config.rs new file mode 100644 index 0000000000..ca3d14819d --- /dev/null +++ b/akd/crates/bitwarden-akd-configuration/src/config.rs @@ -0,0 +1,19 @@ +use serde::{Deserialize, Serialize}; + +use crate::INSTALLATION_CONTEXT; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct BitwardenAkdConfiguration { + pub installation_id: uuid::Uuid, +} + +impl BitwardenAkdConfiguration { + /// Initialize the global installation context for Bitwarden AKD. + /// Must be called once before any use. + /// + /// # Errors + /// Returns an error like [`OnceLock>`](std::sync::OnceLock) if called more than once. + pub fn init(&self) -> Result<(), Vec> { + INSTALLATION_CONTEXT.set(self.installation_id.into_bytes().into()) + } +} diff --git a/akd/crates/bitwarden-akd-configuration/src/lib.rs b/akd/crates/bitwarden-akd-configuration/src/lib.rs index 01b0f990c7..ca81bb21d8 100644 --- a/akd/crates/bitwarden-akd-configuration/src/lib.rs +++ b/akd/crates/bitwarden-akd-configuration/src/lib.rs @@ -29,13 +29,14 @@ //! Define the Bitwarden V1 configuration +#[cfg(feature = "config")] +pub mod config; + use akd::configuration::Configuration; use akd::hash::{Digest, DIGEST_BYTES}; -use akd::{ - AkdLabel, AkdValue, AzksValue, AzksValueWithEpoch, NodeLabel, VersionFreshness, -}; -use uuid::Uuid; +use akd::{AkdLabel, AkdValue, AzksValue, AzksValueWithEpoch, NodeLabel, VersionFreshness}; use std::sync::OnceLock; +use uuid::Uuid; /// Bitwarden installation ID for instance separation static INSTALLATION_CONTEXT: OnceLock> = OnceLock::new(); @@ -99,11 +100,7 @@ impl Configuration for BitwardenV1Configuration { AzksValue([0u8; 32]) } - fn hash_leaf_with_value( - value: &akd::AkdValue, - epoch: u64, - nonce: &[u8], - ) -> AzksValueWithEpoch { + fn hash_leaf_with_value(value: &akd::AkdValue, epoch: u64, nonce: &[u8]) -> AzksValueWithEpoch { let commitment = Self::generate_commitment_from_nonce_client(value, nonce); Self::hash_leaf_with_commitment(commitment, epoch) }