From 0278d4c65427df9a7ec96abe811c60a86a31d393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20F=C3=A9ron?= Date: Wed, 22 Nov 2023 18:20:11 +0100 Subject: [PATCH] Bump presage to 23c157b (#253) In particular, this auto-trusts new identity keys. --- Cargo.lock | 10 ++++----- Cargo.toml | 4 ++-- src/app.rs | 17 ++++++++-------- src/data.rs | 5 +++-- src/main.rs | 2 +- src/receipt.rs | 2 +- src/signal/impl.rs | 47 ++++++++++++++++++++++++++++++------------- src/signal/manager.rs | 6 ++++-- src/signal/mod.rs | 12 +++++++---- src/signal/test.rs | 8 +++++--- src/util.rs | 2 +- 11 files changed, 71 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 13f77e8..25007d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2223,7 +2223,7 @@ dependencies = [ [[package]] name = "libsignal-service" version = "0.1.0" -source = "git+https://github.com/whisperfish/libsignal-service-rs?rev=f40eb4f#f40eb4f74ba102a08e103fb517461ab150788128" +source = "git+https://github.com/whisperfish/libsignal-service-rs?rev=6fc62c8#6fc62c8c67817886560dd2eb99ab5e90f451bd67" dependencies = [ "aes 0.7.5", "aes-gcm", @@ -2256,7 +2256,7 @@ dependencies = [ [[package]] name = "libsignal-service-hyper" version = "0.1.0" -source = "git+https://github.com/whisperfish/libsignal-service-rs?rev=f40eb4f#f40eb4f74ba102a08e103fb517461ab150788128" +source = "git+https://github.com/whisperfish/libsignal-service-rs?rev=6fc62c8#6fc62c8c67817886560dd2eb99ab5e90f451bd67" dependencies = [ "async-trait", "async-tungstenite", @@ -3100,7 +3100,7 @@ checksum = "94e851c7654eed9e68d7d27164c454961a616cf8c203d500607ef22c737b51bb" [[package]] name = "presage" version = "0.6.0-dev" -source = "git+https://github.com/whisperfish/presage?rev=de23104#de2310438618f6fd30534211984b0846fde5fb08" +source = "git+https://github.com/whisperfish/presage?rev=23c157b#23c157b0ad1e369b3e0318c22b1a45b2a0eefacc" dependencies = [ "base64 0.21.5", "futures", @@ -3119,7 +3119,7 @@ dependencies = [ [[package]] name = "presage-store-cipher" version = "0.1.0" -source = "git+https://github.com/whisperfish/presage?rev=de23104#de2310438618f6fd30534211984b0846fde5fb08" +source = "git+https://github.com/whisperfish/presage?rev=23c157b#23c157b0ad1e369b3e0318c22b1a45b2a0eefacc" dependencies = [ "blake3", "chacha20poly1305", @@ -3136,7 +3136,7 @@ dependencies = [ [[package]] name = "presage-store-sled" version = "0.6.0-dev" -source = "git+https://github.com/whisperfish/presage?rev=de23104#de2310438618f6fd30534211984b0846fde5fb08" +source = "git+https://github.com/whisperfish/presage?rev=23c157b#23c157b0ad1e369b3e0318c22b1a45b2a0eefacc" dependencies = [ "async-trait", "base64 0.12.3", diff --git a/Cargo.toml b/Cargo.toml index b1d8125..ed35368 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,8 +28,8 @@ debug = true dev = ["prost", "base64"] [dependencies] -presage = { git = "https://github.com/whisperfish/presage", rev = "de23104" } -presage-store-sled = { git = "https://github.com/whisperfish/presage", rev = "de23104" } +presage = { git = "https://github.com/whisperfish/presage", rev = "23c157b" } +presage-store-sled = { git = "https://github.com/whisperfish/presage", rev = "23c157b" } anyhow = "1.0.66" async-trait = "0.1.58" diff --git a/src/app.rs b/src/app.rs index fb45e2b..501bd31 100644 --- a/src/app.rs +++ b/src/app.rs @@ -21,16 +21,15 @@ use image::{ImageBuffer, ImageEncoder, Rgba}; use itertools::Itertools; use notify_rust::Notification; use phonenumber::Mode; -use presage::prelude::proto::{AttachmentPointer, ReceiptMessage, TypingMessage}; -use presage::prelude::{ - content::{ContentBody, DataMessage, Metadata, SyncMessage}, - proto::{ - data_message::{Reaction, Sticker}, - sync_message::Sent, - GroupContextV2, - }, - AttachmentSpec, Content, ServiceAddress, +use presage::libsignal_service::content::{Content, ContentBody, Metadata}; +use presage::libsignal_service::sender::AttachmentSpec; +use presage::libsignal_service::ServiceAddress; +use presage::proto::{ + data_message::{Reaction, Sticker}, + sync_message::Sent, + GroupContextV2, }; +use presage::proto::{AttachmentPointer, DataMessage, ReceiptMessage, SyncMessage, TypingMessage}; use regex_automata::Regex; use tokio::sync::mpsc; use tracing::{error, info, trace, warn}; diff --git a/src/data.rs b/src/data.rs index b68cc6c..5762444 100644 --- a/src/data.rs +++ b/src/data.rs @@ -3,8 +3,9 @@ use std::collections::HashSet; use anyhow::anyhow; -use presage::prelude::proto::data_message::Quote; -use presage::prelude::{proto, GroupMasterKey, GroupSecretParams}; +use presage::libsignal_service::zkgroup::groups::{GroupMasterKey, GroupSecretParams}; +use presage::proto; +use presage::proto::data_message::Quote; use serde::{Deserialize, Serialize}; use tracing::error; use uuid::Uuid; diff --git a/src/main.rs b/src/main.rs index 34297f9..aba0afb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ use crossterm::{ use gurk::app::App; use gurk::storage::{sync_from_signal, JsonStorage, MemCache, SqliteStorage, Storage}; use gurk::{config, signal, ui}; -use presage::prelude::Content; +use presage::libsignal_service::content::Content; use ratatui::{backend::CrosstermBackend, Terminal}; use tokio::select; use tokio_stream::StreamExt; diff --git a/src/receipt.rs b/src/receipt.rs index 45a57e8..f5238cf 100644 --- a/src/receipt.rs +++ b/src/receipt.rs @@ -133,7 +133,7 @@ impl ReceiptHandler { // over the current session self.receipt_set .entry(event.uuid) - .or_insert_with(ReceiptQueues::new) + .or_default() .add(event.timestamp, event.receipt_type); } diff --git a/src/signal/impl.rs b/src/signal/impl.rs index 0d9b37e..ea73b1f 100644 --- a/src/signal/impl.rs +++ b/src/signal/impl.rs @@ -5,14 +5,14 @@ use std::pin::Pin; use anyhow::{anyhow, Context}; use async_trait::async_trait; use chrono::Utc; +use presage::libsignal_service::content::{Content, ContentBody}; +use presage::libsignal_service::models::Contact; use presage::libsignal_service::prelude::{Group, ProfileKey}; -use presage::prelude::content::Reaction; -use presage::prelude::proto::data_message::Quote; -use presage::prelude::proto::{AttachmentPointer, ReceiptMessage}; -use presage::prelude::{ - AttachmentSpec, Contact, Content, ContentBody, DataMessage, GroupContextV2, -}; -use presage::Registered; +use presage::libsignal_service::sender::AttachmentSpec; +use presage::manager::{ReceivingMode, Registered}; +use presage::proto::data_message::{Quote, Reaction}; +use presage::proto::{AttachmentPointer, DataMessage, GroupContextV2, ReceiptMessage}; +use presage::store::ContentsStore; use presage_store_sled::SledStore; use tokio::sync::oneshot; use tokio_stream::Stream; @@ -42,7 +42,7 @@ impl SignalManager for PresageManager { } fn user_id(&self) -> Uuid { - self.manager.state().service_ids.aci + self.manager.registration_data().service_ids.aci } async fn resolve_group( @@ -51,7 +51,8 @@ impl SignalManager for PresageManager { ) -> anyhow::Result { let decrypted_group = self .manager - .group(&master_key_bytes)? + .store() + .group(master_key_bytes)? .context("no group found")?; let mut members = Vec::with_capacity(decrypted_group.members.len()); @@ -308,23 +309,41 @@ impl SignalManager for PresageManager { } async fn request_contacts_sync(&self) -> anyhow::Result<()> { - Ok(self.manager.clone().request_contacts_sync().await?) + Ok(self.manager.clone().sync_contacts().await?) } fn contact_by_id(&self, id: Uuid) -> anyhow::Result> { - Ok(self.manager.contact_by_id(&id)?) + Ok(self.manager.store().contact_by_id(&id)?) } async fn receive_messages(&mut self) -> anyhow::Result>>> { - Ok(Box::pin(self.manager.receive_messages().await?)) + Ok(Box::pin( + self.manager + .receive_messages(ReceivingMode::Forever) + .await?, + )) } fn contacts(&self) -> Box> { - Box::new(self.manager.contacts().into_iter().flatten().flatten()) + Box::new( + self.manager + .store() + .contacts() + .into_iter() + .flatten() + .flatten(), + ) } fn groups(&self) -> Box> { - Box::new(self.manager.groups().into_iter().flatten().flatten()) + Box::new( + self.manager + .store() + .groups() + .into_iter() + .flatten() + .flatten(), + ) } } diff --git a/src/signal/manager.rs b/src/signal/manager.rs index 21d162f..1b24956 100644 --- a/src/signal/manager.rs +++ b/src/signal/manager.rs @@ -4,9 +4,11 @@ use std::path::PathBuf; use std::pin::Pin; use async_trait::async_trait; +use presage::libsignal_service::content::Content; +use presage::libsignal_service::models::Contact; use presage::libsignal_service::prelude::Group; -use presage::prelude::proto::AttachmentPointer; -use presage::prelude::{AttachmentSpec, Contact, Content}; +use presage::libsignal_service::sender::AttachmentSpec; +use presage::proto::AttachmentPointer; use serde::{Deserialize, Serialize}; use tokio::sync::oneshot; use tokio_stream::Stream; diff --git a/src/signal/mod.rs b/src/signal/mod.rs index 4490ec1..c752480 100644 --- a/src/signal/mod.rs +++ b/src/signal/mod.rs @@ -3,8 +3,8 @@ mod manager; pub mod test; use anyhow::{bail, Context as _}; -use presage::prelude::SignalServers; -use presage_store_sled::{MigrationConflictStrategy, SledStore}; +use presage::libsignal_service::configuration::SignalServers; +use presage_store_sled::{MigrationConflictStrategy, OnNewIdentity, SledStore}; use crate::config::{self, Config}; @@ -36,7 +36,11 @@ pub async fn ensure_linked_device( .as_ref() .map(|c| c.signal_db_path.clone()) .unwrap_or_else(config::default_signal_db_path); - let store = SledStore::open(db_path, MigrationConflictStrategy::BackupAndDrop)?; + let store = SledStore::open( + db_path, + MigrationConflictStrategy::BackupAndDrop, + OnNewIdentity::Trust, + )?; if !relink { if let Some(config) = config.clone() { @@ -84,7 +88,7 @@ pub async fn ensure_linked_device( // get profile let phone_number = manager - .state() + .registration_data() .phone_number .format() .mode(phonenumber::Mode::E164) diff --git a/src/signal/test.rs b/src/signal/test.rs index c2ae3e6..25204c0 100644 --- a/src/signal/test.rs +++ b/src/signal/test.rs @@ -2,10 +2,12 @@ use std::pin::Pin; use std::{cell::RefCell, rc::Rc}; use async_trait::async_trait; +use presage::libsignal_service::content::Content; +use presage::libsignal_service::models::Contact; use presage::libsignal_service::prelude::{AttachmentIdentifier, Group}; -use presage::prelude::proto::data_message::Quote; -use presage::prelude::proto::AttachmentPointer; -use presage::prelude::{AttachmentSpec, Contact, Content}; +use presage::libsignal_service::sender::AttachmentSpec; +use presage::proto::data_message::Quote; +use presage::proto::AttachmentPointer; use tokio::sync::oneshot; use tokio_stream::Stream; use uuid::Uuid; diff --git a/src/util.rs b/src/util.rs index 7e3098c..d92206a 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,5 +1,5 @@ use chrono::{DateTime, Local, NaiveDateTime, TimeZone as _, Utc}; -use presage::prelude::PhoneNumber; +use phonenumber::PhoneNumber; use ratatui::widgets::ListState; use regex_automata::Regex; use serde::{Deserialize, Serialize};