Page MenuHomePhabricator

D10048.id33698.diff
No OneTemporary

D10048.id33698.diff

diff --git a/services/identity/src/client_service.rs b/services/identity/src/client_service.rs
--- a/services/identity/src/client_service.rs
+++ b/services/identity/src/client_service.rs
@@ -593,7 +593,7 @@
let devices_map = self
.client
- .get_keys_for_user(user_ident, &auth_type, true)
+ .get_keys_for_user_info(user_ident, &auth_type, true)
.await
.map_err(handle_db_error)?
.ok_or_else(|| match auth_type {
@@ -608,7 +608,7 @@
.filter_map(|(key, device_info)| {
let device_info_with_auth = DeviceInfoWithAuth {
device_info,
- auth_type: &auth_type,
+ auth_type: Some(&auth_type),
};
match OutboundKeyInfo::try_from(device_info_with_auth) {
Ok(key_info) => Some((key, key_info)),
@@ -642,7 +642,7 @@
let devices_map = self
.client
- .get_keys_for_user(user_ident, &auth_type, false)
+ .get_keys_for_user_info(user_ident, &auth_type, false)
.await
.map_err(handle_db_error)?
.ok_or_else(|| match auth_type {
@@ -657,7 +657,7 @@
.filter_map(|(key, device_info)| {
let device_info_with_auth = DeviceInfoWithAuth {
device_info,
- auth_type: &auth_type,
+ auth_type: Some(&auth_type),
};
match InboundKeyInfo::try_from(device_info_with_auth) {
Ok(key_info) => Some((key, key_info)),
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
@@ -951,18 +951,40 @@
}
}
- pub async fn get_keys_for_user(
+ pub async fn get_keys_for_user_info(
&self,
user_info: String,
auth_type: &AuthType,
get_one_time_keys: bool,
) -> Result<Option<Devices>, Error> {
- let Some(mut user) =
+ let Some(user) =
self.get_user_from_user_info(user_info, auth_type).await?
else {
return Ok(None);
};
+ self.get_keys_for_user(user, get_one_time_keys).await
+ }
+
+ pub async fn get_keys_for_user_id(
+ &self,
+ user_id: &str,
+ get_one_time_keys: bool,
+ ) -> Result<Option<Devices>, Error> {
+ let Some(user) =
+ self.get_item_from_users_table(user_id).await?.item
+ else {
+ return Ok(None);
+ };
+
+ self.get_keys_for_user(user, get_one_time_keys).await
+ }
+
+ async fn get_keys_for_user(
+ &self,
+ mut user: HashMap<String, AttributeValue>,
+ get_one_time_keys: bool,
+ ) -> Result<Option<Devices>, Error> {
let devices = parse_map_attribute(
USERS_TABLE_DEVICES_ATTRIBUTE,
user.remove(USERS_TABLE_DEVICES_ATTRIBUTE),
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
@@ -127,38 +127,24 @@
async fn get_outbound_keys_for_user(
&self,
- request: tonic::Request<client::OutboundKeysForUserRequest>,
+ request: tonic::Request<auth_proto::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)
+ .get_keys_for_user_id(&message.user_id, 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")
- }
- })?;
+ .ok_or_else(|| tonic::Status::not_found("user 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,
+ auth_type: None,
};
match client::OutboundKeyInfo::try_from(device_info_with_auth) {
Ok(key_info) => Some((key, key_info)),
@@ -177,38 +163,24 @@
async fn get_inbound_keys_for_user(
&self,
- request: tonic::Request<client::InboundKeysForUserRequest>,
+ request: tonic::Request<auth_proto::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)
+ .get_keys_for_user_id(&message.user_id, 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")
- }
- })?;
+ .ok_or_else(|| tonic::Status::not_found("user 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,
+ auth_type: None,
};
match client::InboundKeyInfo::try_from(device_info_with_auth) {
Ok(key_info) => Some((key, key_info)),
diff --git a/services/identity/src/grpc_utils.rs b/services/identity/src/grpc_utils.rs
--- a/services/identity/src/grpc_utils.rs
+++ b/services/identity/src/grpc_utils.rs
@@ -26,7 +26,7 @@
pub struct DeviceInfoWithAuth<'a> {
pub device_info: HashMap<String, String>,
- pub auth_type: &'a AuthType,
+ pub auth_type: Option<&'a AuthType>,
}
impl TryFrom<DeviceInfoWithAuth<'_>> for InboundKeyInfo {
@@ -96,7 +96,7 @@
fn extract_identity_info(
device_info: &mut HashMap<String, String>,
- auth_type: &AuthType,
+ auth_type: Option<&AuthType>,
) -> Result<IdentityKeyInfo, Status> {
let payload = extract_key(
device_info,
@@ -108,7 +108,7 @@
)?;
let social_proof =
device_info.remove(USERS_TABLE_DEVICES_MAP_SOCIAL_PROOF_ATTRIBUTE_NAME);
- if social_proof.is_none() && auth_type == &AuthType::Wallet {
+ if social_proof.is_none() && auth_type == Some(&AuthType::Wallet) {
error!("Social proof missing for wallet user");
return Err(Status::failed_precondition("Database item malformed"));
}
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
@@ -25,12 +25,12 @@
// - Identity keys (both Content and Notif Keys)
// - PreKey (including preKey signature)
// - One-time PreKey
- rpc GetOutboundKeysForUser(identity.client.OutboundKeysForUserRequest)
+ rpc GetOutboundKeysForUser(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)
+ rpc GetInboundKeysForUser(InboundKeysForUserRequest)
returns (identity.client.InboundKeysForUserResponse) {}
// Called by user to update password and receive new access token
@@ -91,6 +91,10 @@
string userID = 1;
}
+message InboundKeysForUserRequest {
+ string userID = 1;
+}
+
// FindUserID
message FindUserIDRequest {

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 30, 4:26 AM (20 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2599304
Default Alt Text
D10048.id33698.diff (8 KB)

Event Timeline