Skip to content

Commit

Permalink
Update libsignal-service-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Schmiddiii committed Jan 16, 2024
1 parent dac9b35 commit 0f96270
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
14 changes: 8 additions & 6 deletions presage-store-sled/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,41 +605,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 @@ -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),
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
4 changes: 2 additions & 2 deletions presage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = ["Gabriel Féron <[email protected]>"]
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"
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
22 changes: 13 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 @@ -271,18 +271,19 @@ impl<S: Store> Manager<S, Registered> {
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, // TODO: What about PNI?
&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 +720,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, // TODO: What value should this have?
timestamp,
needs_receipt: false,
unidentified_sender: false,
Expand Down Expand Up @@ -823,6 +825,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, // TODO: What value should this have?
timestamp,
needs_receipt: false, // TODO: this is just wrong
unidentified_sender: false,
Expand Down Expand Up @@ -895,7 +898,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 0f96270

Please sign in to comment.