Page MenuHomePhabricator

D3921.id12968.diff
No OneTemporary

D3921.id12968.diff

diff --git a/services/identity/src/database.rs b/services/identity/src/database.rs
--- a/services/identity/src/database.rs
+++ b/services/identity/src/database.rs
@@ -1,7 +1,14 @@
use std::collections::HashMap;
-use rusoto_core::Region;
-use rusoto_dynamodb::{AttributeValue, DynamoDbClient};
+use opaque_ke::{errors::ProtocolError, ServerRegistration};
+use rusoto_core::{Region, RusotoError};
+use rusoto_dynamodb::{
+ AttributeValue, DynamoDb, DynamoDbClient, GetItemError, GetItemInput,
+ GetItemOutput,
+};
+use tracing::{error, info};
+
+use crate::opaque::Cipher;
pub struct DatabaseClient {
client: DynamoDbClient,
@@ -13,6 +20,74 @@
client: DynamoDbClient::new(region),
}
}
+
+ pub async fn get_pake_registration(
+ &self,
+ user_id: String,
+ ) -> Result<Option<ServerRegistration<Cipher>>, Error> {
+ let primary_key =
+ create_simple_primary_key(("userID".to_string(), user_id.clone()));
+ let get_item_input = GetItemInput {
+ table_name: "identity-pake-registration".to_string(),
+ key: primary_key,
+ consistent_read: Some(true),
+ ..GetItemInput::default()
+ };
+ let get_item_result = self.client.get_item(get_item_input).await;
+ match get_item_result {
+ Ok(GetItemOutput {
+ item: Some(item), ..
+ }) => {
+ if let Some(AttributeValue {
+ b: Some(server_registration_bytes),
+ ..
+ }) = item.get("pakeRegistrationData")
+ {
+ match ServerRegistration::<Cipher>::deserialize(
+ server_registration_bytes,
+ ) {
+ Ok(server_registration) => Ok(Some(server_registration)),
+ Err(e) => {
+ error!(
+ "Failed to deserialize ServerRegistration struct for user {}: {}",
+ user_id, e
+ );
+ Err(Error::Pake(e))
+ }
+ }
+ } else {
+ error!("No registration data found for registered user {}", user_id);
+ Err(Error::MissingAttribute)
+ }
+ }
+ Ok(_) => {
+ info!(
+ "No item found for user {} in PAKE registration table",
+ user_id
+ );
+ Ok(None)
+ }
+ Err(e) => {
+ error!(
+ "DynamoDB client failed to get registration data for user {}: {}",
+ user_id, e
+ );
+ Err(Error::Rusoto(e))
+ }
+ }
+ }
+}
+
+#[derive(
+ Debug, derive_more::Display, derive_more::From, derive_more::Error,
+)]
+pub enum Error {
+ #[display(...)]
+ Rusoto(RusotoError<GetItemError>),
+ #[display(...)]
+ Pake(ProtocolError),
+ #[display(...)]
+ MissingAttribute,
}
type AttributeName = String;

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 1, 6:34 PM (18 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2399451
Default Alt Text
D3921.id12968.diff (2 KB)

Event Timeline