Skip to content

Commit

Permalink
Remove FIXME
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon committed Apr 27, 2021
1 parent 3419aa9 commit 66b8969
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 127 deletions.
4 changes: 0 additions & 4 deletions libsignal-service-actix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ version = "0.1.0"
authors = ["Ruben De Smet <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libsignal-service = { path = "../libsignal-service" }
libsignal-protocol = { git = "https://github.com/signalapp/libsignal-client", version = "0.1.0", tag = "v0.4.0"}


awc = { version = "3.0.0-beta.5", features=["rustls"] }
actix = "0.11.1"
Expand Down
14 changes: 5 additions & 9 deletions libsignal-service-actix/examples/link.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
use failure::Error;
use futures::{channel::mpsc::channel, future, StreamExt};
use image::Luma;
use libsignal_service::configuration::SignalServers;
use libsignal_service::{
configuration::SignalServers, provisioning::LinkingManager,
provisioning::SecondaryDeviceProvisioning, USER_AGENT,
};
use libsignal_service_actix::prelude::AwcPushService;
use log::LevelFilter;
use qrcode::QrCode;
use rand::{distributions::Alphanumeric, Rng, RngCore};
use structopt::StructOpt;

use libsignal_protocol::Context;

use libsignal_service::{
provisioning::LinkingManager, provisioning::SecondaryDeviceProvisioning,
USER_AGENT,
};
use libsignal_service_actix::prelude::AwcPushService;

#[derive(Debug, StructOpt)]
struct Args {
#[structopt(long = "servers", short = "s", default_value = "staging")]
Expand Down
3 changes: 0 additions & 3 deletions libsignal-service-hyper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ version = "0.1.0"
authors = ["Gabriel Féron <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libsignal-service = { path = "../libsignal-service" }
libsignal-protocol = { git = "https://github.com/signalapp/libsignal-client", version = "0.1.0", tag = "v0.4.0"}

async-trait = "0.1"
base64 = "0.13"
Expand Down
8 changes: 3 additions & 5 deletions libsignal-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ license = "GPLv3"
readme = "../README.md"

[dependencies]
#libsignal-protocol = { git = "https://github.com/signalapp/libsignal-client", version = "0.1.0", tag = "v0.4.0"}
libsignal-protocol = { path = "../../libsignal-client/rust/protocol", version = "0.1.0", tag = "v0.4.0"}
zkgroup = { git = "https://github.com/signalapp/zkgroup" }
libsignal-protocol = { git = "https://github.com/whisperfish/libsignal-client", branch = "make-error-sync" }
zkgroup = { git = "https://github.com/signalapp/zkgroup", tag = "v0.7.2" }
async-trait = "0.1.30"
url = { version = "2.1.1", features = ["serde"] }
base64 = "0.13"
Expand All @@ -36,13 +35,12 @@ rand = "0.7"
uuid = { version = "0.8", features = [ "serde" ] }
phonenumber = "0.3"

tokio = { version = "1.0", features = [ "macros" ] }

[build-dependencies]
prost-build = "0.7"

[dev-dependencies]
anyhow = "1.0"
tokio = { version = "1.0", features = [ "macros" ] }

[features]
prefer-e164 = []
45 changes: 20 additions & 25 deletions libsignal-service/src/account_manager.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::time::SystemTime;

use libsignal_protocol::{
IdentityKeyStore, KeyPair, PreKeyRecord, PreKeyStore, PublicKey,
SignalProtocolError, SignedPreKeyRecord, SignedPreKeyStore,
};
use zkgroup::profiles::ProfileKey;

use crate::{
configuration::{Endpoint, ServiceCredentials},
pre_keys::{PreKeyEntity, PreKeyState},
Expand All @@ -11,16 +21,6 @@ use crate::{
},
};

use std::collections::HashMap;
use std::convert::{TryFrom, TryInto};
use std::time::SystemTime;

use libsignal_protocol::{
IdentityKeyStore, KeyPair, PreKeyRecord, PreKeyStore, PublicKey,
SignedPreKeyRecord, SignedPreKeyStore,
};
use zkgroup::profiles::ProfileKey;

pub struct AccountManager<Service> {
service: Service,
profile_key: Option<[u8; 32]>,
Expand All @@ -43,7 +43,7 @@ pub enum LinkError {
#[error("TsUrl has an invalid pub_key field")]
InvalidPublicKey,
#[error("Protocol error {0}")]
ProtocolError(#[from] libsignal_protocol::error::SignalProtocolError),
ProtocolError(#[from] SignalProtocolError),
#[error(transparent)]
ProvisioningError(#[from] ProvisioningError),
}
Expand Down Expand Up @@ -75,16 +75,11 @@ impl<Service: PushService> AccountManager<Service> {
/// Equivalent to Java's RefreshPreKeysJob
///
/// Returns the next pre-key offset and next signed pre-key offset as a tuple.
pub async fn update_pre_key_bundle<
I: IdentityKeyStore,
P: PreKeyStore,
S: SignedPreKeyStore,
R: rand::Rng + rand::CryptoRng,
>(
pub async fn update_pre_key_bundle<R: rand::Rng + rand::CryptoRng>(
&mut self,
identity_store: &I,
prekey_store: &mut P,
signed_prekey_store: &mut S,
identity_store: &dyn IdentityKeyStore,
pre_key_store: &mut dyn PreKeyStore,
signed_pre_key_store: &mut dyn SignedPreKeyStore,
csprng: &mut R,
pre_keys_offset_id: u32,
signed_pre_key_id: u32,
Expand Down Expand Up @@ -113,7 +108,7 @@ impl<Service: PushService> AccountManager<Service> {
let pre_key_id =
((pre_keys_offset_id + i) % (PRE_KEY_MEDIUM_MAX_VALUE - 1)) + 1;
let pre_key_record = PreKeyRecord::new(pre_key_id, &key_pair);
prekey_store
pre_key_store
.save_pre_key(pre_key_id, &pre_key_record, None)
.await?;

Expand All @@ -131,7 +126,7 @@ impl<Service: PushService> AccountManager<Service> {

let unix_time = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.expect("clock went backwards before UNIX EPOCH");
.unwrap();

let signed_prekey_record = SignedPreKeyRecord::new(
signed_pre_key_id + 1,
Expand All @@ -140,7 +135,7 @@ impl<Service: PushService> AccountManager<Service> {
&signed_pre_key_signature,
);

signed_prekey_store
signed_pre_key_store
.save_signed_pre_key(
signed_pre_key_id + 1,
&signed_prekey_record,
Expand Down Expand Up @@ -257,10 +252,10 @@ impl<Service: PushService> AccountManager<Service> {

let msg = ProvisionMessage {
identity_key_public: Some(
identity_key_pair.public_key().serialize().to_vec(),
identity_key_pair.public_key().serialize().into_vec(),
),
identity_key_private: Some(
identity_key_pair.private_key().serialize().to_vec(),
identity_key_pair.private_key().serialize(),
),
number: Some(credentials.e164()),
uuid: credentials.uuid.as_ref().map(|u| u.to_string()),
Expand Down
43 changes: 21 additions & 22 deletions libsignal-service/src/cipher.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
use std::convert::TryFrom;

use block_modes::block_padding::{Iso7816, Padding};
use libsignal_protocol::{
message_decrypt_prekey, message_decrypt_signal, message_encrypt,
CiphertextMessageType, IdentityKeyStore, PreKeySignalMessage, PreKeyStore,
ProtocolAddress, SessionStore, SignalMessage, SignalProtocolError,
SignedPreKeyStore,
};
use prost::Message;
use rand::{CryptoRng, Rng};

use crate::{
content::{Content, Metadata},
envelope::Envelope,
Expand All @@ -10,47 +22,40 @@ use crate::{
ServiceAddress,
};

use block_modes::block_padding::{Iso7816, Padding};
use libsignal_protocol::{
message_decrypt_prekey, message_decrypt_signal, message_encrypt,
CiphertextMessageType, Context, IdentityKeyStore, PreKeySignalMessage,
PreKeyStore, ProtocolAddress, SessionStore, SignalMessage,
SignalProtocolError, SignedPreKeyStore,
};
use prost::Message;

use std::convert::TryFrom;

/// Decrypts incoming messages and encrypts outgoing messages.
///
/// Equivalent of SignalServiceCipher in Java.
pub struct ServiceCipher {
pub struct ServiceCipher<R: Rng + CryptoRng + Clone> {
session_store: Box<dyn SessionStore>,
identity_key_store: Box<dyn IdentityKeyStore>,
signed_pre_key_store: Box<dyn SignedPreKeyStore>,
pre_key_store: Box<dyn PreKeyStore>,
sealed_session_cipher: SealedSessionCipher,
csprng: R,
sealed_session_cipher: SealedSessionCipher<R>,
}

impl ServiceCipher {
impl<R: Rng + CryptoRng + Clone> ServiceCipher<R> {
pub fn new(
session_store: impl SessionStore + Clone + 'static,
identity_key_store: impl IdentityKeyStore + Clone + 'static,
signed_pre_key_store: impl SignedPreKeyStore + Clone + 'static,
pre_key_store: impl PreKeyStore + Clone + 'static,
certificate_validator: CertificateValidator,
csprng: R,
) -> Self {
Self {
session_store: Box::new(session_store.clone()),
identity_key_store: Box::new(identity_key_store.clone()),
signed_pre_key_store: Box::new(signed_pre_key_store.clone()),
pre_key_store: Box::new(pre_key_store.clone()),
csprng: csprng.clone(),
sealed_session_cipher: SealedSessionCipher::new(
session_store,
identity_key_store,
signed_pre_key_store,
pre_key_store,
certificate_validator,
csprng,
),
}
}
Expand Down Expand Up @@ -114,17 +119,14 @@ impl ServiceCipher {
needs_receipt: false,
};

// FIXME: what
let mut csprng = rand::rngs::OsRng;

let mut data = message_decrypt_prekey(
&PreKeySignalMessage::try_from(&ciphertext[..]).unwrap(),
&sender,
self.session_store.as_mut(),
self.identity_key_store.as_mut(),
self.pre_key_store.as_mut(),
self.signed_pre_key_store.as_mut(),
&mut csprng,
&mut self.csprng,
None,
)
.await?
Expand Down Expand Up @@ -159,15 +161,12 @@ impl ServiceCipher {
needs_receipt: false,
};

// FIXME: what
let mut csprng = rand::rngs::OsRng;

let mut data = message_decrypt_signal(
&SignalMessage::try_from(&ciphertext[..])?,
&sender,
self.session_store.as_mut(),
self.identity_key_store.as_mut(),
&mut csprng,
&mut self.csprng,
None,
)
.await?
Expand Down
3 changes: 1 addition & 2 deletions libsignal-service/src/provisioning/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ use aes::Aes256;
use block_modes::{block_padding::Pkcs7, BlockMode, Cbc};
use bytes::Bytes;
use hmac::{Hmac, Mac, NewMac};
use libsignal_protocol::{KeyPair, PublicKey};
use prost::Message;
use rand::Rng;
use sha2::Sha256;

use libsignal_protocol::{KeyPair, PublicKey};

pub use crate::proto::{
ProvisionEnvelope, ProvisionMessage, ProvisioningVersion,
};
Expand Down
Loading

0 comments on commit 66b8969

Please sign in to comment.