Skip to content

Commit a8582e5

Browse files
authored
Bump libsignal-service with adjustments (#291)
1 parent ff708a1 commit a8582e5

File tree

14 files changed

+197
-200
lines changed

14 files changed

+197
-200
lines changed

presage-cli/src/main.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use presage::libsignal_service::prelude::ProfileKey;
2121
use presage::libsignal_service::prelude::Uuid;
2222
use presage::libsignal_service::proto::data_message::Quote;
2323
use presage::libsignal_service::proto::sync_message::Sent;
24+
use presage::libsignal_service::protocol::ServiceId;
2425
use presage::libsignal_service::sender::AttachmentSpec;
2526
use presage::libsignal_service::zkgroup::GroupMasterKeyBytes;
26-
use presage::libsignal_service::ServiceAddress;
2727
use presage::manager::ReceivingMode;
2828
use presage::model::contacts::Contact;
2929
use presage::model::groups::Group;
@@ -264,7 +264,7 @@ async fn send<S: Store>(
264264
Recipient::Contact(uuid) => {
265265
info!(recipient =% uuid, "sending message to contact");
266266
manager
267-
.send_message(ServiceAddress::from_aci(uuid), content_body, timestamp)
267+
.send_message(ServiceId::Aci(uuid.into()), content_body, timestamp)
268268
.await
269269
.expect("failed to send message");
270270
}
@@ -292,7 +292,7 @@ async fn process_incoming_message<S: Store>(
292292
) {
293293
print_message(manager, notifications, content).await;
294294

295-
let sender = content.metadata.sender.uuid;
295+
let sender = content.metadata.sender.raw_uuid();
296296
if let ContentBody::DataMessage(DataMessage { attachments, .. }) = &content.body {
297297
for attachment_pointer in attachments {
298298
let Ok(attachment_data) = manager.get_attachment(attachment_pointer).await else {
@@ -481,7 +481,7 @@ async fn print_message<S: Store>(
481481
(format!("To {contact} @ {ts}"), body)
482482
}
483483
Msg::Received(Thread::Group(key), body) => {
484-
let sender = format_contact(&content.metadata.sender.uuid, manager).await;
484+
let sender = format_contact(&content.metadata.sender.raw_uuid(), manager).await;
485485
let group = format_group(*key, manager).await;
486486
(format!("From {sender} to group {group} @ {ts}: "), body)
487487
}
@@ -559,8 +559,8 @@ async fn run<S: Store>(subcommand: Cmd, config_store: S) -> anyhow::Result<()> {
559559
let registered_manager =
560560
manager.confirm_verification_code(confirmation_code).await?;
561561
println!(
562-
"Account identifier: {}",
563-
registered_manager.registration_data().aci()
562+
"Account identifiers: {}",
563+
registered_manager.registration_data().service_ids
564564
);
565565
}
566566
}
@@ -591,16 +591,16 @@ async fn run<S: Store>(subcommand: Cmd, config_store: S) -> anyhow::Result<()> {
591591

592592
match manager {
593593
(Ok(manager), _) => {
594-
let uuid = manager.whoami().await.unwrap().uuid;
595-
println!("{uuid:?}");
594+
let whoami = manager.whoami().await.unwrap();
595+
println!("{whoami:?}");
596596
}
597597
(Err(err), _) => {
598598
println!("{err:?}");
599599
}
600600
}
601601
}
602602
Cmd::AddDevice { url } => {
603-
let manager = Manager::load_registered(config_store).await?;
603+
let mut manager = Manager::load_registered(config_store).await?;
604604
manager.link_secondary(url).await?;
605605
println!("Added new secondary device");
606606
}

presage-store-sled/src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,7 @@ mod tests {
540540
content::{ContentBody, Metadata},
541541
prelude::Uuid,
542542
proto::DataMessage,
543-
protocol::PreKeyId,
544-
ServiceAddress, ServiceIdType,
543+
protocol::{PreKeyId, ServiceId},
545544
};
546545
use presage::store::ContentsStore;
547546
use protocol::SledPreKeyId;
@@ -581,15 +580,11 @@ mod tests {
581580
Uuid::from_u128(Arbitrary::arbitrary(g)),
582581
Uuid::from_u128(Arbitrary::arbitrary(g)),
583582
];
583+
let sender_uuid: Uuid = *g.choose(&contacts).unwrap();
584+
let destination_uuid: Uuid = *g.choose(&contacts).unwrap();
584585
let metadata = Metadata {
585-
sender: ServiceAddress {
586-
uuid: *g.choose(&contacts).unwrap(),
587-
identity: ServiceIdType::AccountIdentity,
588-
},
589-
destination: ServiceAddress {
590-
uuid: *g.choose(&contacts).unwrap(),
591-
identity: ServiceIdType::AccountIdentity,
592-
},
586+
sender: ServiceId::Aci(sender_uuid.into()),
587+
destination: ServiceId::Aci(destination_uuid.into()),
593588
sender_device: Arbitrary::arbitrary(g),
594589
server_guid: None,
595590
timestamp,

presage-store-sled/src/protobuf.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@ use presage::libsignal_service::content::ContentBody;
1111
use presage::libsignal_service::content::Metadata;
1212
use presage::libsignal_service::prelude::Uuid;
1313
use presage::libsignal_service::proto;
14-
use presage::libsignal_service::ServiceAddress;
14+
use presage::libsignal_service::protocol::ServiceId;
1515

1616
use crate::SledStoreError;
1717

1818
use self::textsecure::AddressProto;
1919
use self::textsecure::MetadataProto;
2020

21-
impl From<ServiceAddress> for AddressProto {
22-
fn from(s: ServiceAddress) -> Self {
21+
impl From<ServiceId> for AddressProto {
22+
fn from(s: ServiceId) -> Self {
2323
AddressProto {
24-
uuid: Some(s.uuid.as_bytes().to_vec()),
24+
uuid: Some(s.raw_uuid().as_bytes().to_vec()),
2525
}
2626
}
2727
}
2828

29-
impl TryFrom<AddressProto> for ServiceAddress {
29+
impl TryFrom<AddressProto> for ServiceId {
3030
type Error = SledStoreError;
3131

3232
fn try_from(address: AddressProto) -> Result<Self, Self::Error> {
3333
address
3434
.uuid
3535
.and_then(|bytes| Some(Uuid::from_bytes(bytes.try_into().ok()?)))
3636
.ok_or_else(|| SledStoreError::NoUuid)
37-
.map(Self::from_aci)
37+
.map(|u| ServiceId::Aci(u.into()))
3838
}
3939
}
4040

@@ -49,7 +49,7 @@ impl From<Metadata> for MetadataProto {
4949
needs_receipt: Some(m.needs_receipt),
5050
server_guid: None,
5151
group_id: None,
52-
destination_uuid: Some(m.destination.uuid.to_string()),
52+
destination_uuid: Some(m.destination.raw_uuid().to_string()),
5353
}
5454
}
5555
}
@@ -60,10 +60,13 @@ impl TryFrom<MetadataProto> for Metadata {
6060
fn try_from(metadata: MetadataProto) -> Result<Self, Self::Error> {
6161
Ok(Metadata {
6262
sender: metadata.address.ok_or(SledStoreError::NoUuid)?.try_into()?,
63-
destination: ServiceAddress::from_aci(match metadata.destination_uuid.as_deref() {
64-
Some(value) => value.parse().map_err(|_| SledStoreError::NoUuid),
65-
None => Ok(Uuid::nil()),
66-
}?),
63+
destination: ServiceId::Aci(
64+
match metadata.destination_uuid.as_deref() {
65+
Some(value) => value.parse().map_err(|_| SledStoreError::NoUuid),
66+
None => Ok(Uuid::nil()),
67+
}?
68+
.into(),
69+
),
6770
sender_device: metadata
6871
.sender_device
6972
.and_then(|m| m.try_into().ok())

presage-store-sled/src/protocol.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ use presage::{
99
Direction, GenericSignedPreKey, IdentityKey, IdentityKeyPair, IdentityKeyStore,
1010
KyberPreKeyId, KyberPreKeyRecord, KyberPreKeyStore, PreKeyId, PreKeyRecord,
1111
PreKeyStore, ProtocolAddress, ProtocolStore, SenderKeyRecord, SenderKeyStore,
12-
SessionRecord, SessionStore, SignalProtocolError, SignedPreKeyId, SignedPreKeyRecord,
13-
SignedPreKeyStore,
12+
ServiceId, SessionRecord, SessionStore, SignalProtocolError, SignedPreKeyId,
13+
SignedPreKeyRecord, SignedPreKeyStore,
1414
},
1515
push_service::DEFAULT_DEVICE_ID,
1616
session_store::SessionStoreExt,
17-
ServiceAddress,
1817
},
1918
proto::verified,
2019
store::{save_trusted_identity_message, StateStore},
@@ -464,9 +463,9 @@ impl<T: SledTrees> SessionStore for SledProtocolStore<T> {
464463
impl<T: SledTrees> SessionStoreExt for SledProtocolStore<T> {
465464
async fn get_sub_device_sessions(
466465
&self,
467-
address: &ServiceAddress,
466+
address: &ServiceId,
468467
) -> Result<Vec<u32>, SignalProtocolError> {
469-
let session_prefix = format!("{}.", address.uuid);
468+
let session_prefix = format!("{}.", address.raw_uuid());
470469
trace!(session_prefix, "get_sub_device_sessions");
471470
let session_ids: Vec<u32> = self
472471
.store
@@ -496,16 +495,13 @@ impl<T: SledTrees> SessionStoreExt for SledProtocolStore<T> {
496495
Ok(())
497496
}
498497

499-
async fn delete_all_sessions(
500-
&self,
501-
address: &ServiceAddress,
502-
) -> Result<usize, SignalProtocolError> {
498+
async fn delete_all_sessions(&self, address: &ServiceId) -> Result<usize, SignalProtocolError> {
503499
let db = self.store.write();
504500
let sessions_tree = db.open_tree(T::sessions()).map_err(SledStoreError::Db)?;
505501

506502
let mut batch = Batch::default();
507503
sessions_tree
508-
.scan_prefix(address.uuid.to_string())
504+
.scan_prefix(address.raw_uuid().to_string())
509505
.filter_map(|r| {
510506
let (key, _) = r.ok()?;
511507
Some(key)

presage-store-sqlite/src/protocol.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ use presage::libsignal_service::{
66
protocol::{
77
Direction, IdentityKey, IdentityKeyPair, KyberPreKeyId, KyberPreKeyRecord,
88
KyberPreKeyStore, PreKeyId, PreKeyRecord, PreKeyStore, ProtocolAddress, ProtocolStore,
9-
SenderKeyRecord, SenderKeyStore, SessionRecord, SessionStore,
9+
SenderKeyRecord, SenderKeyStore, ServiceId, SessionRecord, SessionStore,
1010
SignalProtocolError as ProtocolError, SignedPreKeyId, SignedPreKeyRecord,
1111
SignedPreKeyStore,
1212
},
13-
ServiceAddress,
1413
};
1514

1615
use crate::SqliteStore;
@@ -47,10 +46,7 @@ impl SessionStoreExt for SqliteProtocolStore {
4746
/// Get the IDs of all known sub devices with active sessions for a recipient.
4847
///
4948
/// This should return every device except for the main device [DEFAULT_DEVICE_ID].
50-
async fn get_sub_device_sessions(
51-
&self,
52-
name: &ServiceAddress,
53-
) -> Result<Vec<u32>, ProtocolError> {
49+
async fn get_sub_device_sessions(&self, name: &ServiceId) -> Result<Vec<u32>, ProtocolError> {
5450
todo!()
5551
}
5652

@@ -63,7 +59,7 @@ impl SessionStoreExt for SqliteProtocolStore {
6359
/// ID.
6460
///
6561
/// Returns the number of deleted sessions.
66-
async fn delete_all_sessions(&self, address: &ServiceAddress) -> Result<usize, ProtocolError> {
62+
async fn delete_all_sessions(&self, address: &ServiceId) -> Result<usize, ProtocolError> {
6763
todo!()
6864
}
6965
}

presage/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77
license = "AGPL-3.0-only"
88

99
[dependencies]
10-
libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "468fa6f84cce0db3bdf11609d165758291da99df" }
10+
libsignal-service = { git = "https://github.com/whisperfish/libsignal-service-rs", rev = "6401dc34872a5f0c2fba32c1f136d98ccf3dd418" }
1111

1212
base64 = "0.22"
1313
futures = "0.3"

presage/src/manager/confirmation.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ impl<S: Store> Manager<S, Confirmation> {
4040
) -> Result<Manager<S, Registered>, Error<S::Error>> {
4141
trace!("confirming verification code");
4242

43-
let registration_id = generate_registration_id(&mut self.rng);
44-
let pni_registration_id = generate_registration_id(&mut self.rng);
43+
let registration_id = generate_registration_id(&mut self.csprng);
44+
let pni_registration_id = generate_registration_id(&mut self.csprng);
4545

4646
let Confirmation {
4747
signal_servers,
@@ -75,19 +75,19 @@ impl<S: Store> Manager<S, Confirmation> {
7575

7676
// generate a 52 bytes signaling key
7777
let mut signaling_key = [0u8; 52];
78-
self.rng.fill_bytes(&mut signaling_key);
78+
self.csprng.fill_bytes(&mut signaling_key);
7979

8080
// generate a 32 bytes profile key
8181
let mut profile_key = [0u8; 32];
82-
self.rng.fill_bytes(&mut profile_key);
82+
self.csprng.fill_bytes(&mut profile_key);
8383
let profile_key = ProfileKey::generate(profile_key);
8484

8585
// generate new identity keys used in `register_account` and below
8686
self.store
87-
.set_aci_identity_key_pair(IdentityKeyPair::generate(&mut self.rng))
87+
.set_aci_identity_key_pair(IdentityKeyPair::generate(&mut self.csprng))
8888
.await?;
8989
self.store
90-
.set_pni_identity_key_pair(IdentityKeyPair::generate(&mut self.rng))
90+
.set_pni_identity_key_pair(IdentityKeyPair::generate(&mut self.csprng))
9191
.await?;
9292

9393
let skip_device_transfer = true;
@@ -100,7 +100,7 @@ impl<S: Store> Manager<S, Confirmation> {
100100
number: _,
101101
} = account_manager
102102
.register_account(
103-
&mut self.rng,
103+
&mut self.csprng,
104104
RegistrationMethod::SessionId(&session.id),
105105
AccountAttributes {
106106
signaling_key: Some(signaling_key.to_vec()),
@@ -126,7 +126,7 @@ impl<S: Store> Manager<S, Confirmation> {
126126
trace!("confirmed! (and registered)");
127127

128128
let mut manager = Manager {
129-
rng: self.rng,
129+
csprng: self.csprng,
130130
store: self.store,
131131
state: Registered::with_data(RegistrationData {
132132
signal_servers: self.state.signal_servers,

presage/src/manager/linking.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<S: Store> Manager<S, Linking> {
158158
);
159159

160160
let mut manager = Manager {
161-
rng,
161+
csprng: rng,
162162
store: store.clone(),
163163
state: Registered::with_data(registration_data),
164164
};

presage/src/manager/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct Manager<Store, State> {
2828
/// Part of the manager which is persisted in the store.
2929
state: State,
3030
/// Random number generator
31-
rng: StdRng,
31+
csprng: StdRng,
3232
}
3333

3434
impl<Store, State: fmt::Debug> fmt::Debug for Manager<Store, State> {

0 commit comments

Comments
 (0)