From 9a95d3a04b7890d1341f38579cb2cd6c8c84c5c4 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Sat, 12 Oct 2024 14:24:17 +0200 Subject: [PATCH] Allow PNI in PendingMember --- libsignal-service/src/groups_v2/model.rs | 9 +++++---- libsignal-service/src/groups_v2/operations.rs | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/libsignal-service/src/groups_v2/model.rs b/libsignal-service/src/groups_v2/model.rs index 3fa3e6417..ea51df19d 100644 --- a/libsignal-service/src/groups_v2/model.rs +++ b/libsignal-service/src/groups_v2/model.rs @@ -1,6 +1,7 @@ use std::{convert::TryFrom, convert::TryInto}; use derivative::Derivative; +use libsignal_protocol::ServiceId; use serde::{Deserialize, Serialize}; use uuid::Uuid; use zkgroup::profiles::ProfileKey; @@ -30,15 +31,15 @@ impl PartialEq for Member { } } -#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct PendingMember { - pub uuid: Uuid, + pub service_id: ServiceId, pub role: Role, pub added_by_uuid: Uuid, pub timestamp: u64, } -#[derive(Derivative, Clone, Deserialize, Serialize)] +#[derive(Derivative, Clone)] #[derivative(Debug)] pub struct RequestingMember { pub uuid: Uuid, @@ -69,7 +70,7 @@ pub struct AccessControl { pub add_from_invite_link: AccessRequired, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq)] pub struct Group { pub title: String, pub avatar: String, diff --git a/libsignal-service/src/groups_v2/operations.rs b/libsignal-service/src/groups_v2/operations.rs index 9c3279ab1..404d827eb 100644 --- a/libsignal-service/src/groups_v2/operations.rs +++ b/libsignal-service/src/groups_v2/operations.rs @@ -58,6 +58,19 @@ impl From for GroupDecodingError { } impl GroupOperations { + fn decrypt_service_id( + &self, + ciphertext: &[u8], + ) -> Result { + match self + .group_secret_params + .decrypt_service_id(bincode::deserialize(ciphertext)?)? + { + ServiceId::Aci(aci) => Ok(ServiceId::from(aci)), + ServiceId::Pni(pni) => Ok(ServiceId::from(pni)), + } + } + fn decrypt_aci( &self, ciphertext: &[u8], @@ -131,11 +144,11 @@ impl GroupOperations { ) -> Result { let inner_member = member.member.ok_or(GroupDecodingError::WrongBlob)?; - let aci = self.decrypt_aci(&inner_member.user_id)?; + let service_id = self.decrypt_service_id(&inner_member.user_id)?; let added_by_uuid = self.decrypt_aci(&member.added_by_user_id)?; Ok(PendingMember { - uuid: aci.into(), + service_id, role: inner_member.role.try_into()?, added_by_uuid: added_by_uuid.into(), timestamp: member.timestamp,