Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libsignal-service-rs #230

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions presage-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
4 changes: 3 additions & 1 deletion presage-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -677,7 +678,8 @@ async fn run<S: Store + 'static>(subcommand: Cmd, config_store: S) -> anyhow::Re
}

fn parse_base64_profile_key(s: &str) -> anyhow::Result<ProfileKey> {
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))
Expand Down
2 changes: 1 addition & 1 deletion presage-store-cipher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
12 changes: 6 additions & 6 deletions presage-store-sled/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ edition = "2021"
authors = ["Gabriel Féron <g@leirbag.net>"]

[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"

Expand All @@ -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"]
Expand Down
24 changes: 16 additions & 8 deletions presage-store-sled/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -605,41 +606,42 @@ impl ContentsStore for SledStore {
}
}

#[async_trait(?Send)]
impl PreKeysStore for SledStore {
fn pre_keys_offset_id(&self) -> Result<u32, SignalProtocolError> {
async fn next_pre_key_id(&self) -> Result<u32, SignalProtocolError> {
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<u32, SignalProtocolError> {
async fn next_signed_pre_key_id(&self) -> Result<u32, SignalProtocolError> {
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<u32, SignalProtocolError> {
async fn next_pq_pre_key_id(&self) -> Result<u32, SignalProtocolError> {
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(())
Expand Down Expand Up @@ -1144,6 +1146,7 @@ impl DoubleEndedIterator for SledMessagesIter {
mod tests {
use core::fmt;

use base64::prelude::*;
use presage::libsignal_service::{
content::{ContentBody, Metadata},
prelude::Uuid,
Expand Down Expand Up @@ -1173,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())
)
}
}

Expand Down Expand Up @@ -1205,6 +1212,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),
Expand Down
5 changes: 5 additions & 0 deletions presage-store-sled/src/protobuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +63,9 @@ impl TryFrom<MetadataProto> 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())
Expand Down
11 changes: 5 additions & 6 deletions presage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ authors = ["Gabriel Féron <g@leirbag.net>"]
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 = "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]
Expand Down
3 changes: 2 additions & 1 deletion presage/src/manager/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ impl<S: Store> Manager<S, Confirmation> {
} = self.state;

let credentials = ServiceCredentials {
uuid: None,
aci: None,
pni: None,
phonenumber: phone_number.clone(),
password: Some(password.clone()),
signaling_key: None,
Expand Down
23 changes: 14 additions & 9 deletions presage/src/manager/registered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
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};
Expand Down Expand Up @@ -268,21 +268,23 @@
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(())
Expand Down Expand Up @@ -471,7 +473,7 @@
&self,
thread: &Thread,
range: impl RangeBounds<u64>,
) -> Result<S::MessagesIter, Error<S::Error>> {

Check warning on line 476 in presage/src/manager/registered.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large
Ok(self.store.messages(thread, range)?)
}

Expand Down Expand Up @@ -500,7 +502,7 @@

fn groups_manager(
&self,
) -> Result<GroupsManager<HyperPushService, InMemoryCredentialsCache>, Error<S::Error>> {

Check warning on line 505 in presage/src/manager/registered.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large
let service_configuration = self.state.service_configuration();
let server_public_params = service_configuration.zkgroup_server_public_params;

Expand Down Expand Up @@ -719,6 +721,7 @@
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,
Expand Down Expand Up @@ -823,6 +826,7 @@
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,
Expand Down Expand Up @@ -895,7 +899,8 @@

fn credentials(&self) -> Option<ServiceCredentials> {
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),
Expand Down Expand Up @@ -925,7 +930,7 @@
}

/// Creates a new service cipher.
fn new_service_cipher(&self) -> Result<ServiceCipher<S>, Error<S::Error>> {

Check warning on line 933 in presage/src/manager/registered.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large
let service_cipher = ServiceCipher::new(
self.store.clone(),
self.rng.clone(),
Expand Down Expand Up @@ -968,7 +973,7 @@
///
/// Note: this only currently works when linked as secondary device (the contacts are sent by the primary device at linking time)
#[deprecated = "use the store handle directly"]
pub fn contact_by_id(&self, id: &Uuid) -> Result<Option<Contact>, Error<S::Error>> {

Check warning on line 976 in presage/src/manager/registered.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large
Ok(self.store.contact_by_id(id)?)
}

Expand All @@ -976,20 +981,20 @@
#[deprecated = "use the store handle directly"]
pub fn contacts(
&self,
) -> Result<impl Iterator<Item = Result<Contact, Error<S::Error>>>, Error<S::Error>> {

Check warning on line 984 in presage/src/manager/registered.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large
let iter = self.store.contacts()?;
Ok(iter.map(|r| r.map_err(Into::into)))
}

/// Get a group (either from the local cache, or fetch it remotely) using its master key
#[deprecated = "use the store handle directly"]
pub fn group(&self, master_key_bytes: &[u8]) -> Result<Option<Group>, Error<S::Error>> {

Check warning on line 991 in presage/src/manager/registered.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large
Ok(self.store.group(master_key_bytes.try_into()?)?)
}

/// Returns an iterator on groups stored in the [Store].
#[deprecated = "use the store handle directly"]
pub fn groups(&self) -> Result<S::GroupsIter, Error<S::Error>> {

Check warning on line 997 in presage/src/manager/registered.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large
Ok(self.store.groups()?)
}

Expand All @@ -999,7 +1004,7 @@
&self,
thread: &Thread,
timestamp: u64,
) -> Result<Option<Content>, Error<S::Error>> {

Check warning on line 1007 in presage/src/manager/registered.rs

View workflow job for this annotation

GitHub Actions / clippy

the `Err`-variant returned from this function is very large
Ok(self.store.message(thread, timestamp)?)
}
}
Expand Down
1 change: 1 addition & 0 deletions presage/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading