Skip to content

Commit

Permalink
Fix some occurences of not using PNI correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon committed Oct 21, 2024
1 parent 8fcd6e3 commit ddbcd3b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/push_service/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl PushService {
device_id: u32,
) -> Result<PreKeyBundle, ServiceError> {
let path = format!(
"/v2/keys/{}/{}?pq=true",
destination.raw_uuid(),
"/v2/keys/{}/{}",
destination.service_id_string(),
device_id
);

Expand Down Expand Up @@ -101,9 +101,13 @@ impl PushService {
device_id: u32,
) -> Result<Vec<PreKeyBundle>, ServiceError> {
let path = if device_id == 1 {
format!("/v2/keys/{}/*?pq=true", destination.raw_uuid())
format!("/v2/keys/{}/*", destination.service_id_string())
} else {
format!("/v2/keys/{}/{}?pq=true", destination.raw_uuid(), device_id)
format!(
"/v2/keys/{}/{}",
destination.service_id_string(),
device_id
)
};
let pre_key_response: PreKeyResponse = self
.request(
Expand Down
6 changes: 4 additions & 2 deletions src/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::{
service_address::ServiceIdExt,
session_store::SessionStoreExt,
unidentified_access::UnidentifiedAccess,
utils::serde_service_id,
websocket::SignalWebSocket,
};

Expand All @@ -44,7 +45,8 @@ pub struct OutgoingPushMessage {

#[derive(serde::Serialize, Debug)]
pub struct OutgoingPushMessages {
pub destination: uuid::Uuid,
#[serde(with = "serde_service_id")]
pub destination: ServiceId,
pub timestamp: u64,
pub messages: Vec<OutgoingPushMessage>,
pub online: bool,
Expand Down Expand Up @@ -551,7 +553,7 @@ where
.await?;

let messages = OutgoingPushMessages {
destination: recipient.raw_uuid(),
destination: recipient,
timestamp,
messages,
online,
Expand Down
25 changes: 25 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,28 @@ pub mod serde_phone_number {
.map_err(serde::de::Error::custom)
}
}

pub mod serde_service_id {
use libsignal_protocol::ServiceId;
use serde::{Deserialize, Deserializer, Serializer};

pub fn serialize<S>(
service_id: &ServiceId,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&service_id.service_id_string())
}

pub fn deserialize<'de, D>(deserializer: D) -> Result<ServiceId, D::Error>
where
D: Deserializer<'de>,
{
ServiceId::parse_from_service_id_string(&String::deserialize(
deserializer,
)?)
.ok_or_else(|| serde::de::Error::custom("invalid service ID string"))
}
}
10 changes: 8 additions & 2 deletions src/websocket/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ impl SignalWebSocket {
messages: OutgoingPushMessages,
) -> Result<SendMessageResponse, ServiceError> {
let request = WebSocketRequestMessage::new(Method::PUT)
.path(format!("/v1/messages/{}", messages.destination))
.path(format!(
"/v1/messages/{}",
messages.destination.service_id_string()
))
.json(&messages)?;
self.request_json(request).await
}
Expand All @@ -24,7 +27,10 @@ impl SignalWebSocket {
access: &UnidentifiedAccess,
) -> Result<SendMessageResponse, ServiceError> {
let request = WebSocketRequestMessage::new(Method::PUT)
.path(format!("/v1/messages/{}", messages.destination))
.path(format!(
"/v1/messages/{}",
messages.destination.service_id_string()
))
.header(
"Unidentified-Access-Key",
BASE64_RELAXED.encode(&access.key),
Expand Down

0 comments on commit ddbcd3b

Please sign in to comment.