From ca955c75d9aacb0ac8bd9a143667bfee32c0b1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20F=C3=A9ron?= Date: Thu, 17 Oct 2024 21:42:02 +0200 Subject: [PATCH] Adapt usage of PushService now that it's not a trait anymore (#272) * Change usage of HyperPushService to PushService * Print all type of content body in presage-cli --receive * Point to libsignal-service-rs 701ee93358b3fce75e26489b530e807a76254166 --- Cargo.toml | 3 +-- presage-cli/src/main.rs | 22 ++++++++++++++++--- presage/Cargo.toml | 3 +-- presage/src/manager/confirmation.rs | 7 +++--- presage/src/manager/linking.rs | 4 ++-- presage/src/manager/registered.rs | 34 ++++++++++++++--------------- presage/src/manager/registration.rs | 3 +-- 7 files changed, 43 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 848cd2d82..9beea6058 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,4 @@ resolver = "2" curve25519-dalek = { git = 'https://github.com/signalapp/curve25519-dalek', tag = 'signal-curve25519-4.1.3' } # [patch."https://github.com/whisperfish/libsignal-service-rs.git"] -# libsignal-service = { path = "../libsignal-service-rs/libsignal-service" } -# libsignal-service-hyper = { path = "../libsignal-service-rs/libsignal-service-hyper" } +# libsignal-service = { path = "../libsignal-service-rs" } diff --git a/presage-cli/src/main.rs b/presage-cli/src/main.rs index 112142e5b..3c31716e4 100644 --- a/presage-cli/src/main.rs +++ b/presage-cli/src/main.rs @@ -24,7 +24,9 @@ use presage::libsignal_service::zkgroup::GroupMasterKeyBytes; use presage::libsignal_service::ServiceAddress; use presage::libsignal_service::{groups_v2::Group, prelude::ProfileKey}; use presage::manager::ReceivingMode; +use presage::proto::receipt_message; use presage::proto::EditMessage; +use presage::proto::ReceiptMessage; use presage::proto::SyncMessage; use presage::store::ContentExt; use presage::{ @@ -403,6 +405,7 @@ fn print_message( data_message: Some(data_message), .. }) => format_data_message(&thread, data_message).map(|body| Msg::Received(&thread, body)), + ContentBody::EditMessage(EditMessage { .. }) => None, ContentBody::SynchronizeMessage(SyncMessage { sent: Some(Sent { @@ -423,11 +426,24 @@ fn print_message( }), .. }) => format_data_message(&thread, data_message).map(|body| Msg::Sent(&thread, body)), + ContentBody::SynchronizeMessage(SyncMessage { .. }) => None, ContentBody::CallMessage(_) => Some(Msg::Received(&thread, "is calling!".into())), ContentBody::TypingMessage(_) => Some(Msg::Received(&thread, "is typing...".into())), - content_body => { - warn!(?content_body, "unsupported message"); - None + ContentBody::ReceiptMessage(ReceiptMessage { + r#type: receipt_type, + timestamp, + }) => Some(Msg::Received( + &thread, + format!( + "got {:?} receipt for messages sent at {timestamp:?}", + receipt_message::Type::try_from(receipt_type.unwrap_or_default()).unwrap() + ), + )), + ContentBody::StoryMessage(story) => { + Some(Msg::Received(&thread, format!("new story: {story:?}"))) + } + ContentBody::PniSignatureMessage(_) => { + Some(Msg::Received(&thread, "got PNI signature message".into())) } } { let ts = content.timestamp(); diff --git a/presage/Cargo.toml b/presage/Cargo.toml index 809404f85..00837612f 100644 --- a/presage/Cargo.toml +++ b/presage/Cargo.toml @@ -7,8 +7,7 @@ edition = "2021" license = "AGPL-3.0-only" [dependencies] -libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "f99ff8324378ea653dbd5aa0c5d55e4414b34e23" } -libsignal-service-hyper = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "f99ff8324378ea653dbd5aa0c5d55e4414b34e23" } +libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "701ee93358b3fce75e26489b530e807a76254166" } base64 = "0.22" futures = "0.3" diff --git a/presage/src/manager/confirmation.rs b/presage/src/manager/confirmation.rs index dfd049696..60aaec22a 100644 --- a/presage/src/manager/confirmation.rs +++ b/presage/src/manager/confirmation.rs @@ -1,15 +1,14 @@ use libsignal_service::configuration::{ServiceConfiguration, SignalServers}; use libsignal_service::messagepipe::ServiceCredentials; use libsignal_service::prelude::phonenumber::PhoneNumber; +use libsignal_service::prelude::PushService; use libsignal_service::protocol::IdentityKeyPair; use libsignal_service::provisioning::generate_registration_id; use libsignal_service::push_service::{ - AccountAttributes, DeviceCapabilities, PushService, RegistrationMethod, ServiceIds, - VerifyAccountResponse, + AccountAttributes, DeviceCapabilities, RegistrationMethod, ServiceIds, VerifyAccountResponse, }; use libsignal_service::zkgroup::profiles::ProfileKey; use libsignal_service::AccountManager; -use libsignal_service_hyper::push_service::HyperPushService; use rand::RngCore; use tracing::trace; @@ -61,7 +60,7 @@ impl Manager { }; let service_configuration: ServiceConfiguration = signal_servers.into(); - let mut identified_push_service = HyperPushService::new( + let mut identified_push_service = PushService::new( service_configuration, Some(credentials), crate::USER_AGENT.to_string(), diff --git a/presage/src/manager/linking.rs b/presage/src/manager/linking.rs index d186b1d10..3d26c1253 100644 --- a/presage/src/manager/linking.rs +++ b/presage/src/manager/linking.rs @@ -1,11 +1,11 @@ use futures::channel::{mpsc, oneshot}; use futures::{future, StreamExt}; use libsignal_service::configuration::{ServiceConfiguration, SignalServers}; +use libsignal_service::prelude::PushService; use libsignal_service::protocol::IdentityKeyPair; use libsignal_service::provisioning::{ link_device, NewDeviceRegistration, SecondaryDeviceProvisioning, }; -use libsignal_service_hyper::push_service::HyperPushService; use rand::distributions::{Alphanumeric, DistString}; use rand::rngs::StdRng; use rand::{RngCore, SeedableRng}; @@ -76,7 +76,7 @@ impl Manager { let service_configuration: ServiceConfiguration = signal_servers.into(); let push_service = - HyperPushService::new(service_configuration, None, crate::USER_AGENT.to_string()); + PushService::new(service_configuration, None, crate::USER_AGENT.to_string()); let (tx, mut rx) = mpsc::channel(1); diff --git a/presage/src/manager/registered.rs b/presage/src/manager/registered.rs index 330a35c04..20c36b6c5 100644 --- a/presage/src/manager/registered.rs +++ b/presage/src/manager/registered.rs @@ -35,7 +35,6 @@ use libsignal_service::websocket::SignalWebSocket; use libsignal_service::zkgroup::groups::{GroupMasterKey, GroupSecretParams}; use libsignal_service::zkgroup::profiles::ProfileKey; use libsignal_service::{cipher, AccountManager, Profile, ServiceAddress}; -use libsignal_service_hyper::push_service::HyperPushService; use rand::rngs::StdRng; use rand::SeedableRng; use serde::{Deserialize, Serialize}; @@ -49,7 +48,7 @@ use crate::store::{ContentsStore, Sticker, StickerPack, StickerPackManifest, Sto use crate::{AvatarBytes, Error, Manager}; type ServiceCipher = cipher::ServiceCipher; -type MessageSender = libsignal_service::prelude::MessageSender; +type MessageSender = libsignal_service::prelude::MessageSender; #[derive(Clone, Debug, PartialEq, Eq)] pub enum RegistrationType { @@ -60,8 +59,8 @@ pub enum RegistrationType { /// Manager state when the client is registered and can send and receive messages from Signal #[derive(Clone)] pub struct Registered { - pub(crate) identified_push_service: OnceLock, - pub(crate) unidentified_push_service: OnceLock, + pub(crate) identified_push_service: OnceLock, + pub(crate) unidentified_push_service: OnceLock, pub(crate) identified_websocket: Arc>>, pub(crate) unidentified_websocket: Arc>>, pub(crate) unidentified_sender_certificate: Option, @@ -174,11 +173,11 @@ impl Manager { /// Returns a clone of a cached push service (with credentials). /// /// If no service is yet cached, it will create and cache one. - fn identified_push_service(&self) -> HyperPushService { + fn identified_push_service(&self) -> PushService { self.state .identified_push_service .get_or_init(|| { - HyperPushService::new( + PushService::new( self.state.service_configuration(), self.credentials(), crate::USER_AGENT.to_string(), @@ -190,11 +189,11 @@ impl Manager { /// Returns a clone of a cached push service (without credentials). /// /// If no service is yet cached, it will create and cache one. - fn unidentified_push_service(&self) -> HyperPushService { + fn unidentified_push_service(&self) -> PushService { self.state .unidentified_push_service .get_or_init(|| { - HyperPushService::new( + PushService::new( self.state.service_configuration(), None, crate::USER_AGENT.to_string(), @@ -590,9 +589,7 @@ impl Manager { self.receive_messages_stream(mode).await } - fn groups_manager( - &self, - ) -> Result, Error> { + fn groups_manager(&self) -> Result, Error> { let service_configuration = self.state.service_configuration(); let server_public_params = service_configuration.zkgroup_server_public_params; @@ -613,11 +610,11 @@ impl Manager { ) -> Result, Error> { struct StreamState { encrypted_messages: Receiver, - message_receiver: MessageReceiver, + message_receiver: MessageReceiver, service_cipher: ServiceCipher, - push_service: HyperPushService, + push_service: PushService, store: Store, - groups_manager: GroupsManager, + groups_manager: GroupsManager, mode: ReceivingMode, } @@ -1265,6 +1262,7 @@ impl Manager { &store.aci_protocol_store(), &store.pni_protocol_store(), credentials, + None, ) .await?; Ok(()) @@ -1351,7 +1349,7 @@ pub enum ReceivingMode { async fn upsert_group( store: &S, - groups_manager: &mut GroupsManager, + groups_manager: &mut GroupsManager, master_key_bytes: &[u8], revision: &u32, ) -> Result, Error> { @@ -1388,7 +1386,7 @@ async fn upsert_group( /// Download and decrypt a sticker manifest async fn download_sticker_pack( mut store: C, - mut push_service: HyperPushService, + mut push_service: PushService, operation: &StickerPackOperation, ) -> Result> { debug!("downloading sticker pack"); @@ -1438,7 +1436,7 @@ async fn download_sticker_pack( /// Downloads and decrypts a single sticker async fn download_sticker( _store: &mut C, - push_service: &mut HyperPushService, + push_service: &mut PushService, pack_id: &[u8], pack_key: &[u8], sticker_id: u32, @@ -1464,7 +1462,7 @@ async fn download_sticker( /// This is required when storing outgoing messages, as in this case the appropriate storage place cannot be derived from the message itself. async fn save_message( store: &mut S, - push_service: &mut HyperPushService, + push_service: &mut PushService, message: Content, override_thread: Option, ) -> Result<(), Error> { diff --git a/presage/src/manager/registration.rs b/presage/src/manager/registration.rs index db8d1cc52..cd1bdf759 100644 --- a/presage/src/manager/registration.rs +++ b/presage/src/manager/registration.rs @@ -1,7 +1,6 @@ use libsignal_service::configuration::{ServiceConfiguration, SignalServers}; use libsignal_service::prelude::phonenumber::PhoneNumber; use libsignal_service::push_service::{PushService, VerificationTransport}; -use libsignal_service_hyper::push_service::HyperPushService; use rand::distributions::{Alphanumeric, DistString}; use rand::rngs::StdRng; use rand::SeedableRng; @@ -86,7 +85,7 @@ impl Manager { let service_configuration: ServiceConfiguration = signal_servers.into(); let mut push_service = - HyperPushService::new(service_configuration, None, crate::USER_AGENT.to_string()); + PushService::new(service_configuration, None, crate::USER_AGENT.to_string()); trace!("creating registration verification session");