Skip to content

Commit

Permalink
Update libsignal-service-rs (whisperfish#230)
Browse files Browse the repository at this point in the history
* Update libsignal-service-rs
* Update dependencies
* Add protobuf to CI
  • Loading branch information
Schmiddiii committed Jan 24, 2024
1 parent dac9b35 commit 85580bb
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 38 deletions.
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::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};
Expand Down Expand Up @@ -268,21 +268,23 @@ impl<S: Store> Manager<S, Registered> {
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 @@ -719,6 +721,7 @@ impl<S: Store> Manager<S, Registered> {
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 @@ impl<S: Store> Manager<S, Registered> {
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 @@ impl<S: Store> Manager<S, Registered> {

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

0 comments on commit 85580bb

Please sign in to comment.