From 21b3f96d7807d09f503ef409626ab5b21a663c7a Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Mon, 4 Sep 2023 15:57:52 +0200 Subject: [PATCH 1/2] Add server_guid to Metadata This is unlike Signal Android, where the Envelope is also continously passed while processing the already decrypted content. In Rust, we logically would *consume* the envelope to yield the Metadata and Content, so I prefer the Metadata to contain this information. --- libsignal-service/src/cipher.rs | 13 +++++++++++++ libsignal-service/src/content.rs | 3 +++ 2 files changed, 16 insertions(+) diff --git a/libsignal-service/src/cipher.rs b/libsignal-service/src/cipher.rs index 8154cad54..1448b69b1 100644 --- a/libsignal-service/src/cipher.rs +++ b/libsignal-service/src/cipher.rs @@ -103,6 +103,15 @@ where }); }; + let server_guid = + envelope.server_guid.as_ref().and_then(|g| match g.parse() { + Ok(uuid) => Some(uuid), + Err(e) => { + log::error!("Unparseable server_guid ({})", e); + None + }, + }); + use crate::proto::envelope::Type; let plaintext = match envelope.r#type() { Type::PrekeyBundle => { @@ -118,6 +127,7 @@ where timestamp: envelope.server_timestamp(), needs_receipt: false, unidentified_sender: false, + server_guid, }; let mut data = message_decrypt_prekey( @@ -154,6 +164,7 @@ where timestamp: envelope.server_timestamp(), needs_receipt: false, unidentified_sender: false, + server_guid, }; Plaintext { metadata, @@ -173,6 +184,7 @@ where timestamp: envelope.timestamp(), needs_receipt: false, unidentified_sender: false, + server_guid, }; let mut data = message_decrypt_signal( @@ -241,6 +253,7 @@ where timestamp: envelope.timestamp(), unidentified_sender: true, needs_receipt, + server_guid, }; strip_padding(&mut message)?; diff --git a/libsignal-service/src/content.rs b/libsignal-service/src/content.rs index 6804b9dff..d4a377eba 100644 --- a/libsignal-service/src/content.rs +++ b/libsignal-service/src/content.rs @@ -1,4 +1,5 @@ use libsignal_protocol::ProtocolAddress; +use uuid::Uuid; pub use crate::{ proto::{ @@ -22,6 +23,8 @@ pub struct Metadata { pub timestamp: u64, pub needs_receipt: bool, pub unidentified_sender: bool, + + pub server_guid: Option, } impl Metadata { From 6a8b73af9775e68f47f169d158f40a802ec7e349 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Thu, 26 Oct 2023 11:21:28 +0200 Subject: [PATCH 2/2] document server guid --- libsignal-service/src/content.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libsignal-service/src/content.rs b/libsignal-service/src/content.rs index d4a377eba..16c83dcf2 100644 --- a/libsignal-service/src/content.rs +++ b/libsignal-service/src/content.rs @@ -24,6 +24,9 @@ pub struct Metadata { pub needs_receipt: bool, pub unidentified_sender: bool, + /// A unique UUID for this specific message, produced by the Signal servers. + /// + /// The server GUID is used to report spam messages. pub server_guid: Option, }