Skip to content

Commit

Permalink
Merge pull request #301 from boxdot/libsignal-v0.51.0
Browse files Browse the repository at this point in the history
upgrade libsignal-client to v0.51.0
  • Loading branch information
rubdos authored Jun 21, 2024
2 parents 1e04a65 + df06f23 commit 5a496fd
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 61 deletions.
5 changes: 2 additions & 3 deletions libsignal-service-hyper/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@ impl From<TungsteniteWebSocketError> 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<(), TungsteniteWebSocketError>
where
S: Unpin,
S: Stream<Item = Result<Message, TungsteniteError>>,
S: Stream<Item = Result<Message, TungsteniteError>> + Unpin,
{
let mut socket_stream = socket_stream.fuse();

Expand Down
4 changes: 2 additions & 2 deletions libsignal-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ license = "AGPL-3.0"
readme = "../README.md"

[dependencies]
libsignal-protocol = { git = "https://github.com/signalapp/libsignal", tag = "v0.40.1" }
zkgroup = { git = "https://github.com/signalapp/libsignal", tag = "v0.40.1" }
libsignal-protocol = { git = "https://github.com/signalapp/libsignal", tag = "v0.51.0" }
zkgroup = { git = "https://github.com/signalapp/libsignal", tag = "v0.51.0" }

aes = "0.8"
aes-gcm = "0.10"
Expand Down
3 changes: 2 additions & 1 deletion libsignal-service/examples/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use libsignal_service::protocol::{
SignedPreKeyStore,
};

#[derive(Default)]
pub struct ExampleStore {}

impl ExampleStore {
pub fn new() -> Self {
Self {}
Self::default()
}
}

Expand Down
22 changes: 7 additions & 15 deletions libsignal-service/src/account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ use base64::prelude::*;
use phonenumber::PhoneNumber;
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::time::SystemTime;

use aes::cipher::{KeyIvInit, StreamCipher as _};
use hmac::digest::Output;
use hmac::{Hmac, Mac};
use libsignal_protocol::{
kem, GenericSignedPreKey, IdentityKey, IdentityKeyPair, IdentityKeyStore,
KeyPair, KyberPreKeyRecord, PrivateKey, ProtocolStore, PublicKey,
SenderKeyStore, SignedPreKeyRecord,
SenderKeyStore, SignedPreKeyRecord, Timestamp,
};
use prost::Message;
use serde::{Deserialize, Serialize};
Expand All @@ -34,6 +33,7 @@ use crate::push_service::{
};
use crate::sender::OutgoingPushMessage;
use crate::session_store::SessionStoreExt;
use crate::timestamp::TimestampExt as _;
use crate::utils::{random_length_padding, BASE64_RELAXED};
use crate::ServiceAddress;
use crate::{
Expand Down Expand Up @@ -713,13 +713,9 @@ impl<Service: PushService> AccountManager<Service> {
csprng,
)?;

let unix_time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap();

let signed_prekey_record = SignedPreKeyRecord::new(
csprng.gen_range::<u32, _>(0..0xFFFFFF).into(),
unix_time.as_millis() as u64,
Timestamp::now(),
&signed_pre_key_pair,
&signed_pre_key_signature,
);
Expand All @@ -743,11 +739,7 @@ impl<Service: PushService> AccountManager<Service> {
} else {
loop {
let regid = generate_registration_id(csprng);
if pni_registration_ids
.iter()
.find(|(_k, v)| **v == regid)
.is_none()
{
if !pni_registration_ids.iter().any(|(_k, v)| *v == regid) {
break regid;
}
}
Expand Down Expand Up @@ -876,7 +868,7 @@ fn decrypt_device_name_from_device_info(
) -> Result<String, ServiceError> {
let data = BASE64_RELAXED.decode(string)?;
let name = DeviceName::decode(&*data)?;
Ok(crate::decrypt_device_name(&aci.private_key(), &name)?)
crate::decrypt_device_name(aci.private_key(), &name)
}

pub fn decrypt_device_name(
Expand Down Expand Up @@ -936,11 +928,11 @@ mod tests {
let device_name = super::encrypt_device_name(
&mut csprng,
input_device_name,
&identity.identity_key(),
identity.identity_key(),
)?;

let decrypted_device_name =
super::decrypt_device_name(&identity.private_key(), &device_name)?;
super::decrypt_device_name(identity.private_key(), &device_name)?;

assert_eq!(input_device_name, decrypted_device_name);

Expand Down
8 changes: 4 additions & 4 deletions libsignal-service/src/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use libsignal_protocol::{
PreKeySignalMessage, PreKeyStore, ProtocolAddress, ProtocolStore,
PublicKey, SealedSenderDecryptionResult, SenderCertificate,
SenderKeyDistributionMessage, SenderKeyStore, SessionStore, SignalMessage,
SignalProtocolError, SignedPreKeyStore,
SignalProtocolError, SignedPreKeyStore, Timestamp,
};
use prost::Message;
use rand::{CryptoRng, Rng};
Expand Down Expand Up @@ -182,7 +182,7 @@ where
&mut self.protocol_store.clone(),
&mut self.protocol_store.clone(),
&mut self.protocol_store.clone(),
&mut self.protocol_store.clone(),
&self.protocol_store.clone(),
&mut self.protocol_store.clone(),
&mut self.csprng,
)
Expand Down Expand Up @@ -265,7 +265,7 @@ where
} = sealed_sender_decrypt(
ciphertext,
&self.trust_root,
envelope.timestamp(),
Timestamp::from_epoch_millis(envelope.timestamp()),
None,
self.local_uuid.to_string(),
self.local_device_id.into(),
Expand Down Expand Up @@ -498,7 +498,7 @@ pub async fn get_preferred_protocol_address<S: SessionStore>(
async fn sealed_sender_decrypt(
ciphertext: &[u8],
trust_root: &PublicKey,
timestamp: u64,
timestamp: Timestamp,
local_e164: Option<String>,
local_uuid: String,
local_device_id: DeviceId,
Expand Down
14 changes: 7 additions & 7 deletions libsignal-service/src/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::fmt;
use std::{collections::HashMap, str::FromStr};

use crate::utils::BASE64_RELAXED;
Expand Down Expand Up @@ -96,13 +97,12 @@ impl FromStr for SignalServers {
}
}

impl ToString for SignalServers {
fn to_string(&self) -> String {
impl fmt::Display for SignalServers {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Staging => "staging",
Self::Production => "production",
Self::Staging => f.write_str("staging"),
Self::Production => f.write_str("production"),
}
.to_string()
}
}

Expand Down Expand Up @@ -132,7 +132,7 @@ impl From<&SignalServers> for ServiceConfiguration {
certificate_authority: include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/certs/staging-root-ca.pem")).to_string(),
unidentified_sender_trust_root:
PublicKey::deserialize(&BASE64_RELAXED.decode("BbqY1DzohE4NUZoVF+L18oUPrK3kILllLEJh2UnPSsEx").unwrap()).unwrap(),
zkgroup_server_public_params: bincode::deserialize(&BASE64_RELAXED.decode("ABSY21VckQcbSXVNCGRYJcfWHiAMZmpTtTELcDmxgdFbtp/bWsSxZdMKzfCp8rvIs8ocCU3B37fT3r4Mi5qAemeGeR2X+/YmOGR5ofui7tD5mDQfstAI9i+4WpMtIe8KC3wU5w3Inq3uNWVmoGtpKndsNfwJrCg0Hd9zmObhypUnSkfYn2ooMOOnBpfdanRtrvetZUayDMSC5iSRcXKpdlukrpzzsCIvEwjwQlJYVPOQPj4V0F4UXXBdHSLK05uoPBCQG8G9rYIGedYsClJXnbrgGYG3eMTG5hnx4X4ntARBgELuMWWUEEfSK0mjXg+/2lPmWcTZWR9nkqgQQP0tbzuiPm74H2wMO4u1Wafe+UwyIlIT9L7KLS19Aw8r4sPrXZSSsOZ6s7M1+rTJN0bI5CKY2PX29y5Ok3jSWufIKcgKOnWoP67d5b2du2ZVJjpjfibNIHbT/cegy/sBLoFwtHogVYUewANUAXIaMPyCLRArsKhfJ5wBtTminG/PAvuBdJ70Z/bXVPf8TVsR292zQ65xwvWTejROW6AZX6aqucUjlENAErBme1YHmOSpU6tr6doJ66dPzVAWIanmO/5mgjNEDeK7DDqQdB1xd03HT2Qs2TxY3kCK8aAb/0iM0HQiXjxZ9HIgYhbtvGEnDKW5ILSUydqH/KBhW4Pb0jZWnqN/YgbWDKeJxnDbYcUob5ZY5Lt5ZCMKuaGUvCJRrCtuugSMaqjowCGRempsDdJEt+cMaalhZ6gczklJB/IbdwENW9KeVFPoFNFzhxWUIS5ML9riVYhAtE6JE5jX0xiHNVIIPthb458cfA8daR0nYfYAUKogQArm0iBezOO+mPk5vCM=").unwrap()).unwrap(),
zkgroup_server_public_params: bincode::deserialize(&BASE64_RELAXED.decode("ABSY21VckQcbSXVNCGRYJcfWHiAMZmpTtTELcDmxgdFbtp/bWsSxZdMKzfCp8rvIs8ocCU3B37fT3r4Mi5qAemeGeR2X+/YmOGR5ofui7tD5mDQfstAI9i+4WpMtIe8KC3wU5w3Inq3uNWVmoGtpKndsNfwJrCg0Hd9zmObhypUnSkfYn2ooMOOnBpfdanRtrvetZUayDMSC5iSRcXKpdlukrpzzsCIvEwjwQlJYVPOQPj4V0F4UXXBdHSLK05uoPBCQG8G9rYIGedYsClJXnbrgGYG3eMTG5hnx4X4ntARBgELuMWWUEEfSK0mjXg+/2lPmWcTZWR9nkqgQQP0tbzuiPm74H2wMO4u1Wafe+UwyIlIT9L7KLS19Aw8r4sPrXZSSsOZ6s7M1+rTJN0bI5CKY2PX29y5Ok3jSWufIKcgKOnWoP67d5b2du2ZVJjpjfibNIHbT/cegy/sBLoFwtHogVYUewANUAXIaMPyCLRArsKhfJ5wBtTminG/PAvuBdJ70Z/bXVPf8TVsR292zQ65xwvWTejROW6AZX6aqucUjlENAErBme1YHmOSpU6tr6doJ66dPzVAWIanmO/5mgjNEDeK7DDqQdB1xd03HT2Qs2TxY3kCK8aAb/0iM0HQiXjxZ9HIgYhbtvGEnDKW5ILSUydqH/KBhW4Pb0jZWnqN/YgbWDKeJxnDbYcUob5ZY5Lt5ZCMKuaGUvCJRrCtuugSMaqjowCGRempsDdJEt+cMaalhZ6gczklJB/IbdwENW9KeVFPoFNFzhxWUIS5ML9riVYhAtE6JE5jX0xiHNVIIPthb458cfA8daR0nYfYAUKogQArm0iBezOO+mPk5vCNWI+wwkyFCqNDXz/qxl1gAntuCJtSfq9OC3NkdhQlgYQ==").unwrap()).unwrap(),
},
// configuration with the Signal API production endpoints
// https://github.com/signalapp/Signal-Desktop/blob/master/config/production.json
Expand All @@ -151,7 +151,7 @@ impl From<&SignalServers> for ServiceConfiguration {
unidentified_sender_trust_root:
PublicKey::deserialize(&BASE64_RELAXED.decode("BXu6QIKVz5MA8gstzfOgRQGqyLqOwNKHL6INkv3IHWMF").unwrap()).unwrap(),
zkgroup_server_public_params: bincode::deserialize(
&BASE64_RELAXED.decode("AMhf5ywVwITZMsff/eCyudZx9JDmkkkbV6PInzG4p8x3VqVJSFiMvnvlEKWuRob/1eaIetR31IYeAbm0NdOuHH8Qi+Rexi1wLlpzIo1gstHWBfZzy1+qHRV5A4TqPp15YzBPm0WSggW6PbSn+F4lf57VCnHF7p8SvzAA2ZZJPYJURt8X7bbg+H3i+PEjH9DXItNEqs2sNcug37xZQDLm7X36nOoGPs54XsEGzPdEV+itQNGUFEjY6X9Uv+Acuks7NpyGvCoKxGwgKgE5XyJ+nNKlyHHOLb6N1NuHyBrZrgtY/JYJHRooo5CEqYKBqdFnmbTVGEkCvJKxLnjwKWf+fEPoWeQFj5ObDjcKMZf2Jm2Ae69x+ikU5gBXsRmoF94GXTLfN0/vLt98KDPnxwAQL9j5V1jGOY8jQl6MLxEs56cwXN0dqCnImzVH3TZT1cJ8SW1BRX6qIVxEzjsSGx3yxF3suAilPMqGRp4ffyopjMD1JXiKR2RwLKzizUe5e8XyGOy9fplzhw3jVzTRyUZTRSZKkMLWcQ/gv0E4aONNqs4P+NameAZYOD12qRkxosQQP5uux6B2nRyZ7sAV54DgFyLiRcq1FvwKw2EPQdk4HDoePrO/RNUbyNddnM/mMgj4FW65xCoT1LmjrIjsv/Ggdlx46ueczhMgtBunx1/w8k8V+l8LVZ8gAT6wkU5J+DPQalQguMg12Jzug3q4TbdHiGCmD9EunCwOmsLuLJkz6EcSYXtrlDEnAM+hicw7iergYLLlMXpfTdGxJCWJmP4zqUFeTTmsmhsjGBt7NiEB/9pFFEB3pSbf4iiUukw63Eo8Aqnf4iwob6X1QviCWuc8t0I=").unwrap()).unwrap(),
&BASE64_RELAXED.decode("AMhf5ywVwITZMsff/eCyudZx9JDmkkkbV6PInzG4p8x3VqVJSFiMvnvlEKWuRob/1eaIetR31IYeAbm0NdOuHH8Qi+Rexi1wLlpzIo1gstHWBfZzy1+qHRV5A4TqPp15YzBPm0WSggW6PbSn+F4lf57VCnHF7p8SvzAA2ZZJPYJURt8X7bbg+H3i+PEjH9DXItNEqs2sNcug37xZQDLm7X36nOoGPs54XsEGzPdEV+itQNGUFEjY6X9Uv+Acuks7NpyGvCoKxGwgKgE5XyJ+nNKlyHHOLb6N1NuHyBrZrgtY/JYJHRooo5CEqYKBqdFnmbTVGEkCvJKxLnjwKWf+fEPoWeQFj5ObDjcKMZf2Jm2Ae69x+ikU5gBXsRmoF94GXTLfN0/vLt98KDPnxwAQL9j5V1jGOY8jQl6MLxEs56cwXN0dqCnImzVH3TZT1cJ8SW1BRX6qIVxEzjsSGx3yxF3suAilPMqGRp4ffyopjMD1JXiKR2RwLKzizUe5e8XyGOy9fplzhw3jVzTRyUZTRSZKkMLWcQ/gv0E4aONNqs4P+NameAZYOD12qRkxosQQP5uux6B2nRyZ7sAV54DgFyLiRcq1FvwKw2EPQdk4HDoePrO/RNUbyNddnM/mMgj4FW65xCoT1LmjrIjsv/Ggdlx46ueczhMgtBunx1/w8k8V+l8LVZ8gAT6wkU5J+DPQalQguMg12Jzug3q4TbdHiGCmD9EunCwOmsLuLJkz6EcSYXtrlDEnAM+hicw7iergYLLlMXpfTdGxJCWJmP4zqUFeTTmsmhsjGBt7NiEB/9pFFEB3pSbf4iiUukw63Eo8Aqnf4iwob6X1QviCWuc8t0LUlT9vALgh/f2DPVOOmR0RW6bgRvc7DSF20V/omg+YBw==").unwrap()).unwrap(),
},
}
}
Expand Down
8 changes: 4 additions & 4 deletions libsignal-service/src/groups_v2/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl CredentialResponse {
.into_iter()
.map(|c| {
let bytes = BASE64_RELAXED.decode(c.credential)?;
let data = bincode::deserialize(&bytes)?;
let data = AuthCredentialWithPniResponse::new(&bytes)?;
Ok((c.redemption_time, data))
})
.collect::<Result<_, ServiceError>>()
Expand Down Expand Up @@ -185,23 +185,23 @@ impl<S: PushService, C: CredentialsCache> GroupsManager<S, C> {

self.get_authorization_string(
group_secret_params,
auth_credential_response,
auth_credential_response.clone(),
today,
)
}

fn get_authorization_string(
&self,
group_secret_params: GroupSecretParams,
credential_response: &AuthCredentialWithPniResponse,
credential_response: AuthCredentialWithPniResponse,
today: u64,
) -> Result<HttpAuth, ServiceError> {
let auth_credential = self
.server_public_params
.receive_auth_credential_with_pni_as_service_id(
self.service_ids.aci(),
self.service_ids.pni(),
today,
zkgroup::Timestamp::from_epoch_seconds(today),
credential_response,
)
.map_err(|e| {
Expand Down
1 change: 1 addition & 0 deletions libsignal-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod receiver;
pub mod sender;
pub mod service_address;
pub mod session_store;
mod timestamp;
pub mod unidentified_access;
pub mod utils;
pub mod websocket;
Expand Down
15 changes: 7 additions & 8 deletions libsignal-service/src/pre_keys.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::{convert::TryFrom, time::SystemTime};
use std::convert::TryFrom;

use crate::utils::{serde_base64, serde_identity_key};
use crate::{
timestamp::TimestampExt as _,
utils::{serde_base64, serde_identity_key},
};
use async_trait::async_trait;
use libsignal_protocol::{
error::SignalProtocolError, kem, GenericSignedPreKey, IdentityKey,
IdentityKeyPair, IdentityKeyStore, KeyPair, KyberPreKeyId,
KyberPreKeyRecord, KyberPreKeyStore, PreKeyRecord, PreKeyStore,
SignedPreKeyRecord, SignedPreKeyStore,
SignedPreKeyRecord, SignedPreKeyStore, Timestamp,
};

use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -264,13 +267,9 @@ pub(crate) async fn replenish_pre_keys<
.private_key()
.calculate_signature(&signed_pre_key_public.serialize(), csprng)?;

let unix_time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap();

let signed_prekey_record = SignedPreKeyRecord::new(
next_signed_pre_key_id.into(),
unix_time.as_millis() as u64,
Timestamp::now(),
&signed_pre_key_pair,
&signed_pre_key_signature,
);
Expand Down
17 changes: 1 addition & 16 deletions libsignal-service/src/provisioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use libsignal_protocol::{
DeviceId, IdentityKey, IdentityKeyPair, PrivateKey, PublicKey,
};
use prost::Message;
use serde::{Deserialize, Serialize};
use serde::Deserialize;
use url::Url;
use uuid::Uuid;
use zkgroup::profiles::ProfileKey;
Expand All @@ -31,7 +31,6 @@ use crate::{
HttpAuth, LinkAccountAttributes, LinkCapabilities, LinkRequest,
LinkResponse, PushService, ServiceIds,
},
utils::serde_base64,
};

pub use crate::proto::{
Expand Down Expand Up @@ -102,20 +101,6 @@ pub fn generate_registration_id<R: rand::Rng + rand::CryptoRng>(
csprng.gen_range(1..16380)
}

/// Message received when linking a new secondary device.
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct ConfirmDeviceMessage {
#[serde(with = "serde_base64")]
pub signaling_key: Vec<u8>,
pub supports_sms: bool,
pub fetches_messages: bool,
pub registration_id: u32,
pub pni_registration_id: u32,
#[serde(with = "serde_base64", skip_serializing_if = "Vec::is_empty")]
pub name: Vec<u8>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConfirmCodeResponse {
Expand Down
8 changes: 7 additions & 1 deletion libsignal-service/src/push_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ use phonenumber::PhoneNumber;
use prost::Message as ProtobufMessage;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use zkgroup::profiles::{ProfileKeyCommitment, ProfileKeyVersion};
use zkgroup::{
profiles::{ProfileKeyCommitment, ProfileKeyVersion},
ZkGroupDeserializationFailure,
};

/**
Since we can't use format!() with constants, the URLs here are just for reference purposes
Expand Down Expand Up @@ -579,6 +582,9 @@ pub enum ServiceError {
#[error(transparent)]
GroupsV2DecryptionError(#[from] GroupDecodingError),

#[error(transparent)]
ZkGroupDeserializationFailure(#[from] ZkGroupDeserializationFailure),

#[error("unsupported content")]
UnsupportedContent,

Expand Down
16 changes: 16 additions & 0 deletions libsignal-service/src/timestamp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::{convert::TryInto, time::SystemTime};

pub(crate) trait TimestampExt {
fn now() -> Self;
}

impl TimestampExt for libsignal_protocol::Timestamp {
fn now() -> Self {
let unix_time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("unix epoch in the past");
Self::from_epoch_millis(
unix_time.as_millis().try_into().expect("millis overflow"),
)
}
}

0 comments on commit 5a496fd

Please sign in to comment.