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 @@ -84,7 +84,7 @@ &self, user_id: String, registration: ServerRegistration, - ) -> Result> { + ) -> Result { let input = PutItemInput { table_name: "identity-pake-registration".to_string(), item: HashMap::from([ @@ -105,7 +105,7 @@ ]), ..PutItemInput::default() }; - self.client.put_item(input).await + self.client.put_item(input).await.map_err(Error::RusotoPut) } pub async fn get_token( diff --git a/services/identity/src/service.rs b/services/identity/src/service.rs --- a/services/identity/src/service.rs +++ b/services/identity/src/service.rs @@ -1,14 +1,19 @@ use futures_core::Stream; use opaque_ke::{ errors::ProtocolError, keypair::Key, - RegistrationRequest as PakeRegistrationRequest, ServerRegistration, + RegistrationRequest as PakeRegistrationRequest, RegistrationUpload, + ServerRegistration, }; use rand::{CryptoRng, Rng}; use std::pin::Pin; use tokio::sync::mpsc::{error::SendError, Sender}; use tonic::{Request, Response, Status}; -use crate::{config::Config, database::DatabaseClient, opaque::Cipher}; +use crate::{ + config::Config, + database::{DatabaseClient, Error as DatabaseError}, + opaque::Cipher, +}; pub use proto::identity_service_server::IdentityServiceServer; use proto::{ @@ -64,26 +69,46 @@ } } -async fn pake_registration_start( - pake_registration_request: Vec, - rng: &mut (impl Rng + CryptoRng), - server_secret_key: &Key, - tx: Sender>, -) -> Result<(), Error> { - let server_registration_start_result = ServerRegistration::::start( - rng, - PakeRegistrationRequest::deserialize(&pake_registration_request)?, - &server_secret_key, - ) - .map_err(Error::Pake)?; - tx.send(Ok(RegistrationResponse { - data: Some(PakeRegistrationResponse( - server_registration_start_result.message.serialize(), - )), - })) - .await - .map_err(Error::Channel)?; - Ok(()) +impl MyIdentityService { + async fn pake_registration_start( + pake_registration_request: &Vec, + rng: &mut (impl Rng + CryptoRng), + server_secret_key: &Key, + tx: Sender>, + ) -> Result<(), Error> { + let server_registration_start_result = ServerRegistration::::start( + rng, + PakeRegistrationRequest::deserialize(pake_registration_request)?, + &server_secret_key, + ) + .map_err(Error::Pake)?; + tx.send(Ok(RegistrationResponse { + data: Some(PakeRegistrationResponse( + server_registration_start_result.message.serialize(), + )), + })) + .await + .map_err(Error::Channel)?; + Ok(()) + } + + async fn pake_registration_finish( + &self, + user_id: String, + pake_registration_upload: &Vec, + server_registration: ServerRegistration, + rng: &mut (impl Rng + CryptoRng), + ) -> Result<(), Error> { + let server_registration_finish_result = server_registration.finish( + RegistrationUpload::::deserialize(pake_registration_upload)?, + )?; + self + .client + .put_pake_registration(user_id, server_registration_finish_result) + .await + .map_err(Error::Database)?; + Ok(()) + } } #[derive( @@ -94,4 +119,6 @@ Pake(ProtocolError), #[display(...)] Channel(SendError>), + #[display(...)] + Database(DatabaseError), }