mirror of
https://github.com/signalapp/libsignal.git
synced 2026-04-29 19:17:29 +02:00
MAC sender ID
This commit is contained in:
@@ -143,10 +143,16 @@ impl super::LibSignalProtocolStore for LibSignalProtocolCurrent {
|
||||
.expect("can process pre-key bundles")
|
||||
}
|
||||
|
||||
fn encrypt(&mut self, remote: &str, msg: &[u8]) -> (Vec<u8>, CiphertextMessageType) {
|
||||
fn encrypt(
|
||||
&mut self,
|
||||
remote: &str,
|
||||
local: &str,
|
||||
msg: &[u8],
|
||||
) -> (Vec<u8>, CiphertextMessageType) {
|
||||
let encrypted = message_encrypt(
|
||||
msg,
|
||||
&address(remote),
|
||||
&address(local),
|
||||
&mut self.0.session_store,
|
||||
&mut self.0.identity_store,
|
||||
SystemTime::now(),
|
||||
|
||||
@@ -13,7 +13,12 @@ pub trait LibSignalProtocolStore {
|
||||
fn version(&self) -> &'static str;
|
||||
fn create_pre_key_bundle(&mut self) -> PreKeyBundle;
|
||||
fn process_pre_key_bundle(&mut self, remote: &str, pre_key_bundle: PreKeyBundle);
|
||||
fn encrypt(&mut self, remote: &str, msg: &[u8]) -> (Vec<u8>, CiphertextMessageType);
|
||||
fn encrypt(
|
||||
&mut self,
|
||||
remote: &str,
|
||||
local: &str,
|
||||
msg: &[u8],
|
||||
) -> (Vec<u8>, CiphertextMessageType);
|
||||
fn decrypt(
|
||||
&mut self,
|
||||
remote: &str,
|
||||
|
||||
@@ -170,7 +170,12 @@ impl super::LibSignalProtocolStore for LibSignalProtocolV70 {
|
||||
.expect("can process pre-key bundles")
|
||||
}
|
||||
|
||||
fn encrypt(&mut self, remote: &str, msg: &[u8]) -> (Vec<u8>, super::CiphertextMessageType) {
|
||||
fn encrypt(
|
||||
&mut self,
|
||||
remote: &str,
|
||||
_local: &str,
|
||||
msg: &[u8],
|
||||
) -> (Vec<u8>, super::CiphertextMessageType) {
|
||||
let encrypted = message_encrypt(
|
||||
msg,
|
||||
&address(remote),
|
||||
|
||||
@@ -21,7 +21,7 @@ fn test_basic_prekey() {
|
||||
|
||||
let original_message = "L'homme est condamné à être libre".as_bytes();
|
||||
let (outgoing_message, outgoing_message_type) =
|
||||
alice_store.encrypt(bob_name, original_message);
|
||||
alice_store.encrypt(bob_name, alice_name, original_message);
|
||||
assert_eq!(outgoing_message_type, CiphertextMessageType::PreKey);
|
||||
|
||||
let ptext = bob_store.decrypt(
|
||||
@@ -33,7 +33,8 @@ fn test_basic_prekey() {
|
||||
assert_eq!(&ptext, original_message);
|
||||
|
||||
let bobs_response = "Who watches the watchers?".as_bytes();
|
||||
let (bob_outgoing, bob_outgoing_type) = bob_store.encrypt(alice_name, bobs_response);
|
||||
let (bob_outgoing, bob_outgoing_type) =
|
||||
bob_store.encrypt(alice_name, bob_name, bobs_response);
|
||||
assert_eq!(bob_outgoing_type, CiphertextMessageType::Whisper);
|
||||
|
||||
let alice_decrypts =
|
||||
@@ -52,7 +53,8 @@ fn run_interaction(
|
||||
) {
|
||||
let alice_ptext = b"It's rabbit season";
|
||||
|
||||
let (alice_message, alice_message_type) = alice_store.encrypt(bob_name, alice_ptext);
|
||||
let (alice_message, alice_message_type) =
|
||||
alice_store.encrypt(bob_name, alice_name, alice_ptext);
|
||||
assert_eq!(alice_message_type, CiphertextMessageType::Whisper);
|
||||
assert_eq!(
|
||||
&bob_store.decrypt(alice_name, bob_name, &alice_message, alice_message_type),
|
||||
@@ -61,7 +63,7 @@ fn run_interaction(
|
||||
|
||||
let bob_ptext = b"It's duck season";
|
||||
|
||||
let (bob_message, bob_message_type) = bob_store.encrypt(alice_name, bob_ptext);
|
||||
let (bob_message, bob_message_type) = bob_store.encrypt(alice_name, bob_name, bob_ptext);
|
||||
assert_eq!(bob_message_type, CiphertextMessageType::Whisper);
|
||||
assert_eq!(
|
||||
&alice_store.decrypt(bob_name, alice_name, &bob_message, bob_message_type),
|
||||
@@ -71,7 +73,7 @@ fn run_interaction(
|
||||
for i in 0..10 {
|
||||
let alice_ptext = format!("A->B message {}", i);
|
||||
let (alice_message, alice_message_type) =
|
||||
alice_store.encrypt(bob_name, alice_ptext.as_bytes());
|
||||
alice_store.encrypt(bob_name, alice_name, alice_ptext.as_bytes());
|
||||
assert_eq!(alice_message_type, CiphertextMessageType::Whisper);
|
||||
assert_eq!(
|
||||
&bob_store.decrypt(alice_name, bob_name, &alice_message, alice_message_type),
|
||||
@@ -81,7 +83,8 @@ fn run_interaction(
|
||||
|
||||
for i in 0..10 {
|
||||
let bob_ptext = format!("B->A message {}", i);
|
||||
let (bob_message, bob_message_type) = bob_store.encrypt(alice_name, bob_ptext.as_bytes());
|
||||
let (bob_message, bob_message_type) =
|
||||
bob_store.encrypt(alice_name, bob_name, bob_ptext.as_bytes());
|
||||
assert_eq!(bob_message_type, CiphertextMessageType::Whisper);
|
||||
assert_eq!(
|
||||
&alice_store.decrypt(bob_name, alice_name, &bob_message, bob_message_type),
|
||||
@@ -93,13 +96,13 @@ fn run_interaction(
|
||||
|
||||
for i in 0..10 {
|
||||
let alice_ptext = format!("A->B OOO message {}", i);
|
||||
let (alice_message, _) = alice_store.encrypt(bob_name, alice_ptext.as_bytes());
|
||||
let (alice_message, _) = alice_store.encrypt(bob_name, alice_name, alice_ptext.as_bytes());
|
||||
alice_ooo_messages.push((alice_ptext, alice_message));
|
||||
}
|
||||
|
||||
for i in 0..10 {
|
||||
let alice_ptext = format!("A->B post-OOO message {}", i);
|
||||
let (alice_message, _) = alice_store.encrypt(bob_name, alice_ptext.as_bytes());
|
||||
let (alice_message, _) = alice_store.encrypt(bob_name, alice_name, alice_ptext.as_bytes());
|
||||
assert_eq!(
|
||||
&bob_store.decrypt(
|
||||
alice_name,
|
||||
@@ -113,7 +116,7 @@ fn run_interaction(
|
||||
|
||||
for i in 0..10 {
|
||||
let bob_ptext = format!("B->A message post-OOO {}", i);
|
||||
let (bob_message, _) = bob_store.encrypt(alice_name, bob_ptext.as_bytes());
|
||||
let (bob_message, _) = bob_store.encrypt(alice_name, bob_name, bob_ptext.as_bytes());
|
||||
assert_eq!(
|
||||
&alice_store.decrypt(
|
||||
bob_name,
|
||||
|
||||
Reference in New Issue
Block a user