diff --git a/akd/Cargo.lock b/akd/Cargo.lock index 3df4902844..af85061eb3 100644 --- a/akd/Cargo.lock +++ b/akd/Cargo.lock @@ -711,6 +711,7 @@ dependencies = [ "akd_storage", "async-trait", "bitwarden-akd-configuration", + "bitwarden-encoding", "config", "hex", "serde", diff --git a/akd/crates/common/Cargo.toml b/akd/crates/common/Cargo.toml index 50670fbbf6..207df98ef7 100644 --- a/akd/crates/common/Cargo.toml +++ b/akd/crates/common/Cargo.toml @@ -11,6 +11,7 @@ akd.workspace = true async-trait = { workspace = true } akd_storage = { workspace = true } bitwarden-akd-configuration = { workspace = true } +bitwarden-encoding = { workspace = true } config = { workspace = true } serde = { workspace = true } thiserror.workspace = true diff --git a/akd/crates/common/src/lib.rs b/akd/crates/common/src/lib.rs index f5ef419aae..645c71ade7 100644 --- a/akd/crates/common/src/lib.rs +++ b/akd/crates/common/src/lib.rs @@ -1,7 +1,26 @@ use akd::{directory::ReadOnlyDirectory, Directory}; use akd_storage::{AkdDatabase, VrfKeyDatabase}; use bitwarden_akd_configuration::BitwardenV1Configuration; +use serde::{Deserialize, Serialize}; pub type BitAkdDirectory = Directory; pub type ReadOnlyBitAkdDirectory = ReadOnlyDirectory; + +#[derive(Debug, Serialize, Deserialize)] +pub struct AkdLabelB64(pub(crate) bitwarden_encoding::B64); + +impl From for akd::AkdLabel { + fn from(label_b64: AkdLabelB64) -> Self { + akd::AkdLabel(label_b64.0.into_bytes()) + } +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct AkdValueB64(pub(crate) bitwarden_encoding::B64); + +impl From for akd::AkdValue { + fn from(value_b64: AkdValueB64) -> Self { + akd::AkdValue(value_b64.0.into_bytes()) + } +} diff --git a/akd/crates/publisher/src/routes/publish.rs b/akd/crates/publisher/src/routes/publish.rs index 5b5634ea5c..0b85320c31 100644 --- a/akd/crates/publisher/src/routes/publish.rs +++ b/akd/crates/publisher/src/routes/publish.rs @@ -1,14 +1,14 @@ use super::AppState; -use akd::{AkdLabel, AkdValue}; use akd_storage::PublishQueue; use axum::{extract::State, http::StatusCode, response::IntoResponse, Json}; +use common::{AkdLabelB64, AkdValueB64}; use serde::{Deserialize, Serialize}; use tracing::{error, info, instrument}; #[derive(Debug, Serialize, Deserialize)] pub struct PublishRequest { - pub akd_label_b64: bitwarden_encoding::B64, - pub akd_value_b64: bitwarden_encoding::B64, + pub label_b64: AkdLabelB64, + pub value_b64: AkdValueB64, } #[derive(Debug, Serialize)] @@ -19,14 +19,17 @@ pub struct PublishResponse { #[instrument(skip_all)] pub async fn publish_handler( State(AppState { publish_queue, .. }): State, - Json(request): Json, + Json(PublishRequest { + label_b64, + value_b64, + }): Json, ) -> impl IntoResponse { info!("Handling publish request"); - let akd_label: AkdLabel = AkdLabel(request.akd_label_b64.into_bytes()); - let akd_value: AkdValue = AkdValue(request.akd_value_b64.into_bytes()); - - if let Err(e) = publish_queue.enqueue(akd_label, akd_value).await { + if let Err(e) = publish_queue + .enqueue(label_b64.into(), value_b64.into()) + .await + { error!("Failed to enqueue publish request: {:?}", e); return ( StatusCode::INTERNAL_SERVER_ERROR, diff --git a/akd/crates/reader/src/routes/batch_lookup.rs b/akd/crates/reader/src/routes/batch_lookup.rs index ac7cebfbc1..ebb06e15db 100644 --- a/akd/crates/reader/src/routes/batch_lookup.rs +++ b/akd/crates/reader/src/routes/batch_lookup.rs @@ -1,10 +1,11 @@ use axum::{extract::State, http::StatusCode, Json}; +use common::AkdLabelB64; use serde::{Deserialize, Serialize}; use tracing::{error, info, instrument}; use crate::{ error::ReaderError, - routes::{get_epoch_hash::EpochData, lookup::AkdLabelB64, Response}, + routes::{get_epoch_hash::EpochData, Response}, AppState, }; diff --git a/akd/crates/reader/src/routes/key_history.rs b/akd/crates/reader/src/routes/key_history.rs index e4d84e3813..f2326132a9 100644 --- a/akd/crates/reader/src/routes/key_history.rs +++ b/akd/crates/reader/src/routes/key_history.rs @@ -1,4 +1,5 @@ use axum::{extract::State, http::StatusCode, Json}; +use common::AkdLabelB64; use serde::{Deserialize, Serialize}; use tracing::{error, info, instrument}; @@ -10,8 +11,8 @@ use crate::{ #[derive(Debug, Serialize, Deserialize)] pub struct KeyHistoryRequest { + pub label_b64: AkdLabelB64, /// the label to look up encoded as an uppercase hex string - pub label: akd::AkdLabel, pub history_params: HistoryParams, } @@ -45,12 +46,14 @@ pub struct HistoryData { pub async fn key_history_handler( State(AppState { directory, .. }): State, Json(KeyHistoryRequest { - label, + label_b64, history_params, }): Json, ) -> (StatusCode, Json>) { info!("Handling get key history request"); - let history_proof = directory.key_history(&label, history_params.into()).await; + let history_proof = directory + .key_history(&label_b64.into(), history_params.into()) + .await; match history_proof { Ok((history_proof, epoch_hash)) => ( diff --git a/akd/crates/reader/src/routes/lookup.rs b/akd/crates/reader/src/routes/lookup.rs index 21f8557e4a..7d19ab250c 100644 --- a/akd/crates/reader/src/routes/lookup.rs +++ b/akd/crates/reader/src/routes/lookup.rs @@ -1,4 +1,5 @@ use axum::{extract::State, http::StatusCode, Json}; +use common::AkdLabelB64; use serde::{Deserialize, Serialize}; use tracing::{error, info, instrument}; @@ -8,15 +9,6 @@ use crate::{ AppState, }; -#[derive(Debug, Serialize, Deserialize)] -pub struct AkdLabelB64(pub(crate) bitwarden_encoding::B64); - -impl From for akd::AkdLabel { - fn from(label_b64: AkdLabelB64) -> Self { - akd::AkdLabel(label_b64.0.into_bytes()) - } -} - #[derive(Debug, Serialize, Deserialize)] pub struct LookupRequest { /// the label to look up encoded as base64