Skip to content

Commit

Permalink
Merge branch 'main' into handle-pni-uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
direc85 committed Jul 11, 2024
2 parents c5e285b + 5a953e4 commit 8b967e9
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 65 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
members = ["libsignal-service", "libsignal-service-actix", "libsignal-service-hyper"]
default-members = ["libsignal-service", "libsignal-service-hyper"]

resolver = "2"

[patch.crates-io]
curve25519-dalek = { git = 'https://github.com/signalapp/curve25519-dalek', tag = 'signal-curve25519-4.1.3' }
2 changes: 1 addition & 1 deletion libsignal-service-actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libsignal-service-actix"
version = "0.1.0"
authors = ["Ruben De Smet <[email protected]>"]
edition = "2018"
edition = "2021"
license = "AGPL-3.0"
rust-version = "1.70.0"

Expand Down
2 changes: 1 addition & 1 deletion libsignal-service-actix/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl From<AwcWebSocketError> for ServiceError {
}

/// Process the WebSocket, until it times out.
async fn process<S: Stream>(
async fn process<S>(
socket_stream: S,
mut incoming_sink: Sender<WebSocketStreamItem>,
) -> Result<(), AwcWebSocketError>
Expand Down
2 changes: 1 addition & 1 deletion libsignal-service-hyper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libsignal-service-hyper"
version = "0.1.0"
authors = ["Gabriel Féron <[email protected]>"]
edition = "2018"
edition = "2021"
license = "AGPL-3.0"
rust-version = "1.70.0"

Expand Down
2 changes: 1 addition & 1 deletion libsignal-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "libsignal-service"
version = "0.1.0"
authors = ["Ruben De Smet <[email protected]>", "Gabriel Féron <[email protected]>", "Michael Bryan <[email protected]>", "Shady Khalifa <[email protected]>"]
edition = "2018"
edition = "2021"
license = "AGPL-3.0"
readme = "../README.md"

Expand Down
24 changes: 0 additions & 24 deletions libsignal-service/examples/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,30 +205,6 @@ impl PreKeysStore for ExampleStore {
todo!()
}

/// set the ID of the next pre key
async fn set_next_pre_key_id(
&mut self,
_id: u32,
) -> Result<(), SignalProtocolError> {
todo!()
}

/// set the ID of the next signed pre key
async fn set_next_signed_pre_key_id(
&mut self,
_id: u32,
) -> Result<(), SignalProtocolError> {
todo!()
}

/// set the ID of the next PQ pre key
async fn set_next_pq_pre_key_id(
&mut self,
_id: u32,
) -> Result<(), SignalProtocolError> {
todo!()
}

async fn signed_pre_keys_count(
&self,
) -> Result<usize, SignalProtocolError> {
Expand Down
85 changes: 77 additions & 8 deletions libsignal-service/protobuf/SignalService.proto
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,11 @@ message Verified {
message SyncMessage {
message Sent {
message UnidentifiedDeliveryStatus {
reserved /*destinationE164*/ 1;
optional string destinationServiceId = 3;
optional bool unidentified = 2;
reserved /*destinationE164*/ 1;
optional string destinationServiceId = 3;
optional bool unidentified = 2;
reserved /*destinationPni*/ 4;
optional bytes destinationIdentityKey = 5;
}

message StoryMessageRecipient {
Expand All @@ -460,6 +462,8 @@ message SyncMessage {
optional StoryMessage storyMessage = 8;
repeated StoryMessageRecipient storyMessageRecipients = 9;
optional EditMessage editMessage = 10;
reserved /*destinationPni*/ 11;
// NEXT ID: 12
}

message Contacts {
Expand Down Expand Up @@ -610,6 +614,7 @@ message SyncMessage {
ACCEPTED = 1;
NOT_ACCEPTED = 2;
DELETE = 3;
OBSERVED = 4;
}

optional bytes conversationId = 1;
Expand All @@ -621,17 +626,79 @@ message SyncMessage {
}

message CallLinkUpdate {
enum Type {
UPDATE = 0;
DELETE = 1;
}

optional bytes rootKey = 1;
optional bytes adminPassKey = 2;
optional Type type = 3;
}

message CallLogEvent {
enum Type {
CLEAR = 0;
CLEAR = 0;
MARKED_AS_READ = 1;
MARKED_AS_READ_IN_CONVERSATION = 2;
}

optional Type type = 1;
optional uint64 timestamp = 2;
/* Data identifying a conversation. The service ID for 1:1, the group ID for
* group, or the room ID for an ad-hoc call. See also
* `CallEvent/conversationId`. */
optional bytes conversationId = 3;
/* An identifier for a call. Generated directly for 1:1, or derived from
* the era ID for group and ad-hoc calls. See also `CallEvent/callId`. */
optional uint64 callId = 4;
}

message DeleteForMe {
message ConversationIdentifier {
oneof identifier {
string threadServiceId = 1;
bytes threadGroupId = 2;
string threadE164 = 3;
}
}

message AddressableMessage {
oneof author {
string authorServiceId = 1;
string authorE164 = 2;
}
optional uint64 sentTimestamp = 3;
}

message MessageDeletes {
optional ConversationIdentifier conversation = 1;
repeated AddressableMessage messages = 2;
}

message AttachmentDelete {
optional ConversationIdentifier conversation = 1;
optional AddressableMessage targetMessage = 2;
optional bytes uuid = 3; // The `uuid` from the `Attachment`.
optional bytes fallbackDigest = 4;
optional bytes fallbackPlaintextHash = 5;
}

message ConversationDelete {
optional ConversationIdentifier conversation = 1;
repeated AddressableMessage mostRecentMessages = 2;
repeated AddressableMessage mostRecentNonExpiringMessages = 4;
optional bool isFullDelete = 3;
}

message LocalOnlyConversationDelete {
optional ConversationIdentifier conversation = 1;
}

optional Type type = 1;
optional uint64 timestamp = 2;
repeated MessageDeletes messageDeletes = 1;
repeated ConversationDelete conversationDeletes = 2;
repeated LocalOnlyConversationDelete localOnlyConversationDeletes = 3;
repeated AttachmentDelete attachmentDeletes = 4;
}

optional Sent sent = 1;
Expand All @@ -655,6 +722,7 @@ message SyncMessage {
optional CallEvent callEvent = 19;
optional CallLinkUpdate callLinkUpdate = 20;
optional CallLogEvent callLogEvent = 21;
optional DeleteForMe deleteForMe = 22;
}

message AttachmentPointer {
Expand Down Expand Up @@ -686,7 +754,8 @@ message AttachmentPointer {
optional string blurHash = 12;
optional uint64 uploadTimestamp = 13;
optional uint32 cdnNumber = 14;
// Next ID: 19
optional bytes uuid = 20;
// Next ID: 21
}

message GroupContext {
Expand Down Expand Up @@ -730,7 +799,7 @@ message ContactDetails {
optional string color = 4;
optional Verified verified = 5;
optional bytes profileKey = 6;
optional bool blocked = 7;
reserved /*blocked*/ 7;
optional uint32 expireTimer = 8;
optional uint32 inboxPosition = 10;
optional bool archived = 11;
Expand Down
6 changes: 3 additions & 3 deletions libsignal-service/protobuf/update-protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ set -euo pipefail

update_proto() {
case "$1" in
Signal-Android)
git_revision="940cee0f30d6a2873ae08c65bb821c34302ccf5d"
Signal-Android)
git_revision="251cec5dee06d8d36f0177967d675e8eac2ba32f"
prefix="libsignal-service/src/main/protowire/";;
Signal-Desktop)
git_revision="70858d9063446b07b19c03ae7d0c01075a2849e3"
git_revision="f46872b6e980132e8045b3288eb88d803f365a10"
prefix="protos/";;
esac
curl -LOf https://raw.githubusercontent.com/signalapp/${1}/${git_revision}/${prefix}${2}
Expand Down
2 changes: 1 addition & 1 deletion libsignal-service/src/account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ impl<Service: PushService> AccountManager<Service> {
}

self.service
.put_json(
.put_json::<(), _>(
Endpoint::Service,
"/v1/accounts/name",
&[],
Expand Down
2 changes: 0 additions & 2 deletions libsignal-service/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ pub struct Contact {
#[serde(skip)]
pub verified: Verified,
pub profile_key: Vec<u8>,
pub blocked: bool,
pub expire_timer: u32,
pub inbox_position: u32,
pub archived: bool,
Expand Down Expand Up @@ -69,7 +68,6 @@ impl Contact {
color: contact_details.color.clone(),
verified: contact_details.verified.clone().unwrap_or_default(),
profile_key: contact_details.profile_key().to_vec(),
blocked: contact_details.blocked(),
expire_timer: contact_details.expire_timer(),
inbox_position: contact_details.inbox_position(),
archived: contact_details.archived(),
Expand Down
18 changes: 0 additions & 18 deletions libsignal-service/src/pre_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,6 @@ pub trait PreKeysStore:
/// ID of the next PQ pre key
async fn next_pq_pre_key_id(&self) -> Result<u32, SignalProtocolError>;

/// set the ID of the next pre key
async fn set_next_pre_key_id(
&mut self,
id: u32,
) -> Result<(), SignalProtocolError>;

/// set the ID of the next signed pre key
async fn set_next_signed_pre_key_id(
&mut self,
id: u32,
) -> Result<(), SignalProtocolError>;

/// set the ID of the next PQ pre key
async fn set_next_pq_pre_key_id(
&mut self,
id: u32,
) -> Result<(), SignalProtocolError>;

/// number of signed pre-keys we currently have in store
async fn signed_pre_keys_count(&self)
-> Result<usize, SignalProtocolError>;
Expand Down
25 changes: 20 additions & 5 deletions libsignal-service/src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::{collections::HashSet, time::SystemTime};

use chrono::prelude::*;
use libsignal_protocol::{
process_prekey_bundle, DeviceId, IdentityKeyPair, ProtocolStore,
SenderCertificate, SenderKeyStore, SignalProtocolError,
process_prekey_bundle, DeviceId, IdentityKey, IdentityKeyPair,
ProtocolStore, SenderCertificate, SenderKeyStore, SignalProtocolError,
};
use rand::{CryptoRng, Rng};
use tracing::{info, trace};
Expand Down Expand Up @@ -54,6 +54,7 @@ pub type SendMessageResult = Result<SentMessage, MessageSenderError>;
#[derive(Debug, Clone)]
pub struct SentMessage {
pub recipient: ServiceAddress,
pub used_identity_key: IdentityKey,
pub unidentified: bool,
pub needs_sync: bool,
}
Expand Down Expand Up @@ -489,7 +490,7 @@ where
let content_bytes = content.encode_to_vec();

for _ in 0..4u8 {
let messages = self
let (messages, used_identity_key) = self
.create_encrypted_messages(
&recipient,
unidentified_access.map(|x| &x.certificate),
Expand Down Expand Up @@ -519,6 +520,7 @@ where
tracing::debug!("message sent!");
return Ok(SentMessage {
recipient,
used_identity_key,
unidentified: unidentified_access.is_some(),
needs_sync,
});
Expand Down Expand Up @@ -703,7 +705,8 @@ where
recipient: &ServiceAddress,
unidentified_access: Option<&SenderCertificate>,
content: &[u8],
) -> Result<Vec<OutgoingPushMessage>, MessageSenderError> {
) -> Result<(Vec<OutgoingPushMessage>, IdentityKey), MessageSenderError>
{
let mut messages = vec![];

let mut devices: HashSet<DeviceId> = self
Expand Down Expand Up @@ -788,7 +791,15 @@ where
}
}

Ok(messages)
let identity_key = self
.protocol_store
.get_identity(&recipient.to_protocol_address(DEFAULT_DEVICE_ID))
.await?
.ok_or(MessageSenderError::UntrustedIdentity {
address: *recipient,
})?;

Ok((messages, identity_key))
}

/// Equivalent to `getEncryptedMessage`
Expand Down Expand Up @@ -895,13 +906,17 @@ where
let SentMessage {
recipient,
unidentified,
used_identity_key,
..
} = sent;
UnidentifiedDeliveryStatus {
destination_service_id: Some(
recipient.uuid.to_string(),
),
unidentified: Some(*unidentified),
destination_identity_key: Some(
used_identity_key.serialize().into(),
),
}
})
.collect();
Expand Down

0 comments on commit 8b967e9

Please sign in to comment.