Skip to content

Commit

Permalink
Add server_guid to Metadata
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rubdos committed Sep 4, 2023
1 parent 37cf26a commit d1fae81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions libsignal-service/src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,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 => {
Expand All @@ -119,6 +128,7 @@ where
timestamp: envelope.server_timestamp(),
needs_receipt: false,
unidentified_sender: false,
server_guid,
};

let mut data = message_decrypt_prekey(
Expand Down Expand Up @@ -156,6 +166,7 @@ where
timestamp: envelope.server_timestamp(),
needs_receipt: false,
unidentified_sender: false,
server_guid,
};
Plaintext {
metadata,
Expand All @@ -175,6 +186,7 @@ where
timestamp: envelope.timestamp(),
needs_receipt: false,
unidentified_sender: false,
server_guid,
};

let mut data = message_decrypt_signal(
Expand Down Expand Up @@ -245,6 +257,7 @@ where
timestamp: envelope.timestamp(),
unidentified_sender: true,
needs_receipt,
server_guid,
};

strip_padding(&mut message)?;
Expand Down
3 changes: 3 additions & 0 deletions libsignal-service/src/content.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use libsignal_protocol::ProtocolAddress;
use uuid::Uuid;

use crate::proto::PniSignatureMessage;
pub use crate::{
Expand All @@ -22,6 +23,8 @@ pub struct Metadata {
pub timestamp: u64,
pub needs_receipt: bool,
pub unidentified_sender: bool,

pub server_guid: Option<Uuid>,
}

impl Metadata {
Expand Down

0 comments on commit d1fae81

Please sign in to comment.