Changeset View
Changeset View
Standalone View
Standalone View
services/identity/src/client_service.rs
Show All 31 Lines | |||||
use moka::future::Cache; | use moka::future::Cache; | ||||
use rand::rngs::OsRng; | use rand::rngs::OsRng; | ||||
use tonic::Response; | use tonic::Response; | ||||
use tracing::error; | use tracing::error; | ||||
#[derive(Clone)] | #[derive(Clone)] | ||||
pub enum WorkflowInProgress { | pub enum WorkflowInProgress { | ||||
Registration(UserRegistrationInfo), | Registration(UserRegistrationInfo), | ||||
Login(UserLoginInfo), | |||||
} | } | ||||
#[derive(Clone)] | #[derive(Clone)] | ||||
pub struct UserRegistrationInfo { | pub struct UserRegistrationInfo { | ||||
pub username: String, | pub username: String, | ||||
pub flattened_device_key_upload: FlattenedDeviceKeyUpload, | |||||
} | |||||
#[derive(Clone)] | |||||
pub struct UserLoginInfo(FlattenedDeviceKeyUpload); | |||||
#[derive(Clone)] | |||||
pub struct FlattenedDeviceKeyUpload { | |||||
pub device_id_key: String, | pub device_id_key: String, | ||||
pub key_payload: String, | pub key_payload: String, | ||||
pub key_payload_signature: String, | pub key_payload_signature: String, | ||||
pub identity_prekey: String, | pub identity_prekey: String, | ||||
pub identity_prekey_signature: String, | pub identity_prekey_signature: String, | ||||
pub identity_onetime_keys: Vec<String>, | pub identity_onetime_keys: Vec<String>, | ||||
pub notif_prekey: String, | pub notif_prekey: String, | ||||
pub notif_prekey_signature: String, | pub notif_prekey_signature: String, | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if let client_proto::RegistrationStartRequest { | ||||
let server_registration = comm_opaque2::server::Registration::new(); | let server_registration = comm_opaque2::server::Registration::new(); | ||||
let server_message = server_registration | let server_message = server_registration | ||||
.start(&CONFIG.server_setup, ®ister_message, username.as_bytes()) | .start(&CONFIG.server_setup, ®ister_message, username.as_bytes()) | ||||
.map_err(comm_opaque2::grpc::protocol_error_to_grpc_status)?; | .map_err(comm_opaque2::grpc::protocol_error_to_grpc_status)?; | ||||
let key_info = KeyPayload::from_str(&payload) | let key_info = KeyPayload::from_str(&payload) | ||||
.map_err(|_| tonic::Status::invalid_argument("malformed payload"))?; | .map_err(|_| tonic::Status::invalid_argument("malformed payload"))?; | ||||
let registration_state = UserRegistrationInfo { | let registration_state = UserRegistrationInfo { | ||||
username, | username, | ||||
flattened_device_key_upload: FlattenedDeviceKeyUpload { | |||||
device_id_key: key_info.primary_identity_public_keys.curve25519, | device_id_key: key_info.primary_identity_public_keys.curve25519, | ||||
key_payload: payload, | key_payload: payload, | ||||
key_payload_signature: payload_signature, | key_payload_signature: payload_signature, | ||||
identity_prekey, | identity_prekey, | ||||
identity_prekey_signature, | identity_prekey_signature, | ||||
identity_onetime_keys: onetime_identity_prekeys, | identity_onetime_keys: onetime_identity_prekeys, | ||||
notif_prekey, | notif_prekey, | ||||
notif_prekey_signature, | notif_prekey_signature, | ||||
notif_onetime_keys: onetime_notif_prekeys, | notif_onetime_keys: onetime_notif_prekeys, | ||||
}, | |||||
}; | }; | ||||
let session_id = generate_uuid(); | let session_id = generate_uuid(); | ||||
self | self | ||||
.cache | .cache | ||||
.insert( | .insert( | ||||
session_id.clone(), | session_id.clone(), | ||||
WorkflowInProgress::Registration(registration_state), | WorkflowInProgress::Registration(registration_state), | ||||
) | ) | ||||
Show All 20 Lines | ) -> Result<tonic::Response<RegistrationFinishResponse>, tonic::Status> { | ||||
{ | { | ||||
self.cache.invalidate(&message.session_id).await; | self.cache.invalidate(&message.session_id).await; | ||||
let server_registration = comm_opaque2::server::Registration::new(); | let server_registration = comm_opaque2::server::Registration::new(); | ||||
let password_file = server_registration | let password_file = server_registration | ||||
.finish(&message.opaque_registration_upload) | .finish(&message.opaque_registration_upload) | ||||
.map_err(comm_opaque2::grpc::protocol_error_to_grpc_status)?; | .map_err(comm_opaque2::grpc::protocol_error_to_grpc_status)?; | ||||
let device_id = state.device_id_key.clone(); | let device_id = state.flattened_device_key_upload.device_id_key.clone(); | ||||
let user_id = self | let user_id = self | ||||
.client | .client | ||||
.add_user_to_users_table(state, password_file) | .add_user_to_users_table(state, password_file) | ||||
.await | .await | ||||
.map_err(handle_db_error)?; | .map_err(handle_db_error)?; | ||||
// Create access token | // Create access token | ||||
let token = AccessTokenData::new( | let token = AccessTokenData::new( | ||||
▲ Show 20 Lines • Show All 143 Lines • Show Last 20 Lines |