From d5acfc76bd5dd38186cb83590d66d8f9b5ea25ab Mon Sep 17 00:00:00 2001 From: Schmiddiii Date: Tue, 16 Jan 2024 17:25:06 +0100 Subject: [PATCH 1/3] Update libsignal-service-rs --- presage-store-sled/src/lib.rs | 14 ++++++++------ presage-store-sled/src/protobuf.rs | 5 +++++ presage/Cargo.toml | 4 ++-- presage/src/manager/confirmation.rs | 3 ++- presage/src/manager/registered.rs | 23 ++++++++++++++--------- presage/src/store.rs | 1 + 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/presage-store-sled/src/lib.rs b/presage-store-sled/src/lib.rs index 6dec38e8d..760b46007 100644 --- a/presage-store-sled/src/lib.rs +++ b/presage-store-sled/src/lib.rs @@ -605,41 +605,42 @@ impl ContentsStore for SledStore { } } +#[async_trait(?Send)] impl PreKeysStore for SledStore { - fn pre_keys_offset_id(&self) -> Result { + async fn next_pre_key_id(&self) -> Result { Ok(self .get(SLED_TREE_STATE, SLED_KEY_PRE_KEYS_OFFSET_ID) .map_err(|_| SignalProtocolError::InvalidPreKeyId)? .unwrap_or(0)) } - fn set_pre_keys_offset_id(&mut self, id: u32) -> Result<(), SignalProtocolError> { + async fn set_next_pre_key_id(&mut self, id: u32) -> Result<(), SignalProtocolError> { self.insert(SLED_TREE_STATE, SLED_KEY_PRE_KEYS_OFFSET_ID, id) .map_err(|_| SignalProtocolError::InvalidPreKeyId)?; Ok(()) } - fn next_signed_pre_key_id(&self) -> Result { + async fn next_signed_pre_key_id(&self) -> Result { Ok(self .get(SLED_TREE_STATE, SLED_KEY_NEXT_SIGNED_PRE_KEY_ID) .map_err(|_| SignalProtocolError::InvalidSignedPreKeyId)? .unwrap_or(0)) } - fn set_next_signed_pre_key_id(&mut self, id: u32) -> Result<(), SignalProtocolError> { + async fn set_next_signed_pre_key_id(&mut self, id: u32) -> Result<(), SignalProtocolError> { self.insert(SLED_TREE_STATE, SLED_KEY_NEXT_SIGNED_PRE_KEY_ID, id) .map_err(|_| SignalProtocolError::InvalidSignedPreKeyId)?; Ok(()) } - fn next_pq_pre_key_id(&self) -> Result { + async fn next_pq_pre_key_id(&self) -> Result { Ok(self .get(SLED_TREE_STATE, SLED_KEY_NEXT_PQ_PRE_KEY_ID) .map_err(|_| SignalProtocolError::InvalidKyberPreKeyId)? .unwrap_or(0)) } - fn set_next_pq_pre_key_id(&mut self, id: u32) -> Result<(), SignalProtocolError> { + async fn set_next_pq_pre_key_id(&mut self, id: u32) -> Result<(), SignalProtocolError> { self.insert(SLED_TREE_STATE, SLED_KEY_NEXT_PQ_PRE_KEY_ID, id) .map_err(|_| SignalProtocolError::InvalidKyberPreKeyId)?; Ok(()) @@ -1205,6 +1206,7 @@ mod tests { uuid: *g.choose(&contacts).unwrap(), }, sender_device: Arbitrary::arbitrary(g), + server_guid: None, timestamp, needs_receipt: Arbitrary::arbitrary(g), unidentified_sender: Arbitrary::arbitrary(g), diff --git a/presage-store-sled/src/protobuf.rs b/presage-store-sled/src/protobuf.rs index b1502d08a..a83038d6e 100644 --- a/presage-store-sled/src/protobuf.rs +++ b/presage-store-sled/src/protobuf.rs @@ -4,6 +4,8 @@ mod textsecure { include!(concat!(env!("OUT_DIR"), "/textsecure.rs")); } +use std::str::FromStr; + use presage::libsignal_service::content::Content; use presage::libsignal_service::content::ContentBody; use presage::libsignal_service::content::Metadata; @@ -61,6 +63,9 @@ impl TryFrom for Metadata { .sender_device .and_then(|m| m.try_into().ok()) .unwrap_or_default(), + server_guid: metadata + .server_guid + .and_then(|u| crate::Uuid::from_str(&u).ok()), timestamp: metadata .timestamp .and_then(|m| m.try_into().ok()) diff --git a/presage/Cargo.toml b/presage/Cargo.toml index 93c4d698a..bccc76c34 100644 --- a/presage/Cargo.toml +++ b/presage/Cargo.toml @@ -6,8 +6,8 @@ authors = ["Gabriel Féron "] edition = "2021" [dependencies] -libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "9d55addebe010f0acbcabdfc02ab41979c1863e0" } -libsignal-service-hyper = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "9d55addebe010f0acbcabdfc02ab41979c1863e0" } +libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "54ce3c44d706ef8af6f2620734e4041602333a5e" } +libsignal-service-hyper = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "54ce3c44d706ef8af6f2620734e4041602333a5e" } base64 = "0.21" futures = "0.3" diff --git a/presage/src/manager/confirmation.rs b/presage/src/manager/confirmation.rs index b99cfa910..badde9bee 100644 --- a/presage/src/manager/confirmation.rs +++ b/presage/src/manager/confirmation.rs @@ -51,7 +51,8 @@ impl Manager { } = self.state; let credentials = ServiceCredentials { - uuid: None, + aci: None, + pni: None, phonenumber: phone_number.clone(), password: Some(password.clone()), signaling_key: None, diff --git a/presage/src/manager/registered.rs b/presage/src/manager/registered.rs index 4949abbf7..c3c2b044b 100644 --- a/presage/src/manager/registered.rs +++ b/presage/src/manager/registered.rs @@ -23,8 +23,8 @@ use libsignal_service::protocol::SenderCertificate; use libsignal_service::protocol::{PrivateKey, PublicKey}; use libsignal_service::provisioning::generate_registration_id; use libsignal_service::push_service::{ - AccountAttributes, DeviceCapabilities, PushService, ServiceError, ServiceIds, WhoAmIResponse, - DEFAULT_DEVICE_ID, + AccountAttributes, DeviceCapabilities, PushService, ServiceError, ServiceIdType, ServiceIds, + WhoAmIResponse, DEFAULT_DEVICE_ID, }; use libsignal_service::receiver::MessageReceiver; use libsignal_service::sender::{AttachmentSpec, AttachmentUploadError}; @@ -268,21 +268,23 @@ impl Manager { Some(self.state.data.profile_key), ); + // TODO: Do the same for PNI once implemented upstream. let (pre_keys_offset_id, next_signed_pre_key_id, next_pq_pre_key_id) = account_manager .update_pre_key_bundle( &mut self.store.clone(), + ServiceIdType::AccountIdentity, &mut self.rng, - self.store.pre_keys_offset_id()?, - self.store.next_signed_pre_key_id()?, - self.store.next_pq_pre_key_id()?, true, ) .await?; - self.store.set_pre_keys_offset_id(pre_keys_offset_id)?; + self.store.set_next_pre_key_id(pre_keys_offset_id).await?; self.store - .set_next_signed_pre_key_id(next_signed_pre_key_id)?; - self.store.set_next_pq_pre_key_id(next_pq_pre_key_id)?; + .set_next_signed_pre_key_id(next_signed_pre_key_id) + .await?; + self.store + .set_next_pq_pre_key_id(next_pq_pre_key_id) + .await?; trace!("registered pre keys"); Ok(()) @@ -719,6 +721,7 @@ impl Manager { metadata: Metadata { sender: self.state.data.service_ids.aci.into(), sender_device: self.state.device_id(), + server_guid: None, timestamp, needs_receipt: false, unidentified_sender: false, @@ -823,6 +826,7 @@ impl Manager { metadata: Metadata { sender: self.state.data.service_ids.aci.into(), sender_device: self.state.device_id(), + server_guid: None, timestamp, needs_receipt: false, // TODO: this is just wrong unidentified_sender: false, @@ -895,7 +899,8 @@ impl Manager { fn credentials(&self) -> Option { Some(ServiceCredentials { - uuid: Some(self.state.data.service_ids.aci), + aci: Some(self.state.data.service_ids.aci), + pni: Some(self.state.data.service_ids.pni), phonenumber: self.state.data.phone_number.clone(), password: Some(self.state.data.password.clone()), signaling_key: Some(self.state.data.signaling_key), diff --git a/presage/src/store.rs b/presage/src/store.rs index 207831c58..c64de2414 100644 --- a/presage/src/store.rs +++ b/presage/src/store.rs @@ -94,6 +94,7 @@ pub trait ContentsStore { metadata: Metadata { sender: sender.into(), sender_device: 0, + server_guid: None, timestamp: SystemTime::now() .duration_since(SystemTime::UNIX_EPOCH) .unwrap_or_default() From 221276ba131eababeaf0a01bffd8906233acec81 Mon Sep 17 00:00:00 2001 From: Schmiddiii Date: Wed, 17 Jan 2024 11:27:57 +0100 Subject: [PATCH 2/3] Update dependencies --- presage-cli/Cargo.toml | 12 ++++++------ presage-cli/src/main.rs | 4 +++- presage-store-cipher/Cargo.toml | 2 +- presage-store-sled/Cargo.toml | 12 ++++++------ presage-store-sled/src/lib.rs | 10 ++++++++-- presage/Cargo.toml | 11 +++++------ 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/presage-cli/Cargo.toml b/presage-cli/Cargo.toml index 8f3f7c9b5..efb62dfc0 100644 --- a/presage-cli/Cargo.toml +++ b/presage-cli/Cargo.toml @@ -9,7 +9,7 @@ presage = { path = "../presage" } presage-store-sled = { path = "../presage-store-sled" } anyhow = { version = "1.0", features = ["backtrace"] } -base64 = "0.12" +base64 = "0.21" chrono = { version = "0.4", default-features = false, features = ["serde", "clock"] } clap = { version = ">=4.2.4", features = ["derive"] } directories = "3.0" @@ -18,8 +18,8 @@ futures = "0.3" hex = "0.4" log = "0.4" mime_guess = "2.0" -tempfile = "3.3" -tokio = { version = "1.0", features = ["macros", "rt-multi-thread", "io-std", "io-util"] } -qr2term = { version = "0.2.2" } -notify-rust = "4.6.0" -url = "2.2" +tempfile = "3.9" +tokio = { version = "1.35", features = ["macros", "rt-multi-thread", "io-std", "io-util"] } +qr2term = { version = "0.2.3" } +notify-rust = "4.10.0" +url = "2.5" diff --git a/presage-cli/src/main.rs b/presage-cli/src/main.rs index 8b3565f29..dfbacb2d2 100644 --- a/presage-cli/src/main.rs +++ b/presage-cli/src/main.rs @@ -5,6 +5,7 @@ use std::path::PathBuf; use std::time::UNIX_EPOCH; use anyhow::{anyhow, bail, Context as _}; +use base64::prelude::*; use chrono::Local; use clap::{ArgGroup, Parser, Subcommand}; use directories::ProjectDirs; @@ -677,7 +678,8 @@ async fn run(subcommand: Cmd, config_store: S) -> anyhow::Re } fn parse_base64_profile_key(s: &str) -> anyhow::Result { - let bytes = base64::decode(s)? + let bytes = BASE64_STANDARD + .decode(s)? .try_into() .map_err(|_| anyhow!("profile key of invalid length"))?; Ok(ProfileKey::create(bytes)) diff --git a/presage-store-cipher/Cargo.toml b/presage-store-cipher/Cargo.toml index 1f0d75f63..9a93a9d79 100644 --- a/presage-store-cipher/Cargo.toml +++ b/presage-store-cipher/Cargo.toml @@ -13,4 +13,4 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" sha2 = "0.10" thiserror = "1.0" -zeroize = { version = "1.6.0", features = ["derive"] } +zeroize = { version = "1.7.0", features = ["derive"] } diff --git a/presage-store-sled/Cargo.toml b/presage-store-sled/Cargo.toml index c58470091..79fcb5789 100644 --- a/presage-store-sled/Cargo.toml +++ b/presage-store-sled/Cargo.toml @@ -5,21 +5,21 @@ edition = "2021" authors = ["Gabriel Féron "] [build-dependencies] -prost-build = "0.10" +prost-build = "> 0.10, <= 0.12" [dependencies] presage = { path = "../presage" } presage-store-cipher = { path = "../presage-store-cipher", optional = true } async-trait = "0.1" -base64 = "0.12" -fs_extra = "1.2" -log = "0.4.8" +base64 = "0.21" +fs_extra = "1.3" +log = "0.4.20" sled = { version = "0.34" } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" -prost = "0.10" +prost = "> 0.10, <= 0.12" sha2 = "0.10" quickcheck_macros = "1.0.0" @@ -29,7 +29,7 @@ futures = "0.3" quickcheck = "1.0.3" quickcheck_async = "0.1" rand = "0.8" -tokio = { version = "1.0", default-features = false, features = ["time"] } +tokio = { version = "1.35", default-features = false, features = ["time"] } [features] default = ["encryption"] diff --git a/presage-store-sled/src/lib.rs b/presage-store-sled/src/lib.rs index 760b46007..d603d17aa 100644 --- a/presage-store-sled/src/lib.rs +++ b/presage-store-sled/src/lib.rs @@ -6,6 +6,7 @@ use std::{ }; use async_trait::async_trait; +use base64::prelude::*; use log::{debug, error, trace, warn}; use presage::libsignal_service::zkgroup::GroupMasterKeyBytes; use presage::libsignal_service::{ @@ -290,7 +291,7 @@ impl SledStore { } Thread::Group(group_id) => format!( "{SLED_TREE_THREADS_PREFIX}:group:{}", - base64::encode(group_id) + BASE64_STANDARD.encode(group_id) ), }; let mut hasher = Sha256::new(); @@ -1145,6 +1146,7 @@ impl DoubleEndedIterator for SledMessagesIter { mod tests { use core::fmt; + use base64::prelude::*; use presage::libsignal_service::{ content::{ContentBody, Metadata}, prelude::Uuid, @@ -1174,7 +1176,11 @@ mod tests { impl fmt::Debug for KeyPair { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - writeln!(f, "{}", base64::encode(self.0.public_key.serialize())) + writeln!( + f, + "{}", + BASE64_STANDARD.encode(self.0.public_key.serialize()) + ) } } diff --git a/presage/Cargo.toml b/presage/Cargo.toml index bccc76c34..4da98c394 100644 --- a/presage/Cargo.toml +++ b/presage/Cargo.toml @@ -6,19 +6,18 @@ authors = ["Gabriel Féron "] edition = "2021" [dependencies] -libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "54ce3c44d706ef8af6f2620734e4041602333a5e" } -libsignal-service-hyper = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "54ce3c44d706ef8af6f2620734e4041602333a5e" } +libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "0ad842f7646b21feca3c79d1e7f73d052529314d" } +libsignal-service-hyper = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "0ad842f7646b21feca3c79d1e7f73d052529314d" } base64 = "0.21" futures = "0.3" -log = "0.4.8" +log = "0.4.20" rand = "0.8" serde = "1.0" serde_json = "1.0" thiserror = "1.0" -url = "2.2" -parking_lot = "0.11" -tokio = { version = "1.0", default-features = false, features = ["sync", "time"] } +url = "2.5" +tokio = { version = "1.35", default-features = false, features = ["sync", "time"] } sha2 = "0.10.8" [dev-dependencies] From 053a25ecd5bb6f282af6075db986ede169081062 Mon Sep 17 00:00:00 2001 From: Schmiddiii Date: Wed, 17 Jan 2024 11:52:56 +0100 Subject: [PATCH 3/3] Add protobuf to CI --- .github/workflows/build.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 81c1a6e17..c251102b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,6 +32,11 @@ jobs: with: toolchain: stable + - name: Install protobuf + run: | + sudo apt-get update + sudo apt-get install -y libprotobuf-dev libprotobuf-c-dev protobuf-compiler protobuf-c-compiler + - name: Configure CI cache uses: Swatinem/rust-cache@v2 @@ -87,6 +92,11 @@ jobs: toolchain: stable components: clippy + - name: Install protobuf + run: | + sudo apt-get update + sudo apt-get install -y libprotobuf-dev libprotobuf-c-dev protobuf-compiler protobuf-c-compiler + - name: Setup CI cache uses: Swatinem/rust-cache@v2