Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3367932
D9957.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D9957.diff
View Options
diff --git a/services/identity/src/grpc_services/authenticated.rs b/services/identity/src/grpc_services/authenticated.rs
--- a/services/identity/src/grpc_services/authenticated.rs
+++ b/services/identity/src/grpc_services/authenticated.rs
@@ -1,4 +1,7 @@
+use std::collections::HashMap;
+
use crate::config::CONFIG;
+use crate::grpc_utils::DeviceInfoWithAuth;
use crate::{
client_service::{
handle_db_error, CacheExt, UpdateState, WorkflowInProgress,
@@ -15,9 +18,8 @@
// This must be named client, because generated code from the authenticated
// protobuf file references message structs from the client protobuf file
// with the client:: namespace
-pub mod client {
- tonic::include_proto!("identity.client");
-}
+use crate::client_service::client_proto as client;
+
pub mod auth_proto {
tonic::include_proto!("identity.authenticated");
}
@@ -28,7 +30,7 @@
UploadOneTimeKeysRequest,
};
use client::{Empty, IdentityKeyInfo};
-use tracing::debug;
+use tracing::{debug, error};
#[derive(derive_more::Constructor)]
pub struct AuthenticatedService {
@@ -123,6 +125,106 @@
Ok(response)
}
+ async fn get_outbound_keys_for_user(
+ &self,
+ request: tonic::Request<client::OutboundKeysForUserRequest>,
+ ) -> Result<tonic::Response<client::OutboundKeysForUserResponse>, tonic::Status>
+ {
+ let message = request.into_inner();
+
+ use client::outbound_keys_for_user_request::Identifier;
+ let (user_ident, auth_type) = match message.identifier {
+ None => {
+ return Err(tonic::Status::invalid_argument("no identifier provided"))
+ }
+ Some(Identifier::Username(username)) => (username, AuthType::Password),
+ Some(Identifier::WalletAddress(address)) => (address, AuthType::Wallet),
+ };
+
+ let devices_map = self
+ .db_client
+ .get_keys_for_user(user_ident, &auth_type, true)
+ .await
+ .map_err(handle_db_error)?
+ .ok_or_else(|| match auth_type {
+ AuthType::Password => tonic::Status::not_found("username not found"),
+ AuthType::Wallet => {
+ tonic::Status::not_found("wallet address not found")
+ }
+ })?;
+
+ let transformed_devices = devices_map
+ .into_iter()
+ .filter_map(|(key, device_info)| {
+ let device_info_with_auth = DeviceInfoWithAuth {
+ device_info,
+ auth_type: &auth_type,
+ };
+ match client::OutboundKeyInfo::try_from(device_info_with_auth) {
+ Ok(key_info) => Some((key, key_info)),
+ Err(_) => {
+ error!("Failed to transform device info for key {}", key);
+ None
+ }
+ }
+ })
+ .collect::<HashMap<_, _>>();
+
+ Ok(tonic::Response::new(client::OutboundKeysForUserResponse {
+ devices: transformed_devices,
+ }))
+ }
+
+ async fn get_inbound_keys_for_user(
+ &self,
+ request: tonic::Request<client::InboundKeysForUserRequest>,
+ ) -> Result<tonic::Response<client::InboundKeysForUserResponse>, tonic::Status>
+ {
+ let message = request.into_inner();
+
+ use client::inbound_keys_for_user_request::Identifier;
+ let (user_ident, auth_type) = match message.identifier {
+ None => {
+ return Err(tonic::Status::invalid_argument("no identifier provided"))
+ }
+ Some(Identifier::Username(username)) => (username, AuthType::Password),
+ Some(Identifier::WalletAddress(address)) => (address, AuthType::Wallet),
+ };
+
+ let devices_map = self
+ .db_client
+ .get_keys_for_user(user_ident, &auth_type, false)
+ .await
+ .map_err(handle_db_error)?
+ .ok_or_else(|| match auth_type {
+ AuthType::Password => tonic::Status::not_found("username not found"),
+ AuthType::Wallet => {
+ tonic::Status::not_found("wallet address not found")
+ }
+ })?;
+
+ let transformed_devices = devices_map
+ .into_iter()
+ .filter_map(|(key, device_info)| {
+ let device_info_with_auth = DeviceInfoWithAuth {
+ device_info,
+ auth_type: &auth_type,
+ };
+ match client::InboundKeyInfo::try_from(device_info_with_auth) {
+ Ok(key_info) => Some((key, key_info)),
+ Err(_) => {
+ error!("Failed to transform device info for key {}", key);
+ None
+ }
+ }
+ })
+ .collect::<HashMap<_, _>>();
+
+ Ok(tonic::Response::new(client::InboundKeysForUserResponse {
+ devices: transformed_devices,
+ }))
+ }
+
async fn get_keyserver_keys(
&self,
request: Request<OutboundKeysForUserRequest>,
diff --git a/shared/protos/identity_authenticated.proto b/shared/protos/identity_authenticated.proto
--- a/shared/protos/identity_authenticated.proto
+++ b/shared/protos/identity_authenticated.proto
@@ -19,6 +19,20 @@
rpc RefreshUserPreKeys(RefreshUserPreKeysRequest)
returns (identity.client.Empty) {}
+ // Called by clients to get all device keys associated with a user in order
+ // to open a new channel of communication on any of their devices.
+ // Specially, this will return the following per device:
+ // - Identity keys (both Content and Notif Keys)
+ // - PreKey (including preKey signature)
+ // - One-time PreKey
+ rpc GetOutboundKeysForUser(identity.client.OutboundKeysForUserRequest)
+ returns (identity.client.OutboundKeysForUserResponse) {}
+ // Called by receivers of a communication request. The reponse will only
+ // return identity keys (both content and notif keys) and related prekeys per
+ // device, but will not contain one-time keys.
+ rpc GetInboundKeysForUser(identity.client.InboundKeysForUserRequest)
+ returns (identity.client.InboundKeysForUserResponse) {}
+
// Called by user to update password and receive new access token
rpc UpdateUserPasswordStart(UpdateUserPasswordStartRequest) returns
(UpdateUserPasswordStartResponse) {}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 5:16 PM (21 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2585572
Default Alt Text
D9957.diff (5 KB)
Attached To
Mode
D9957: [identity] Move X3DH RPCs to auth proto
Attached
Detach File
Event Timeline
Log In to Comment