From fb9be8f05a9622e296ec5412f6d6130f64e99159 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 13:59:29 -0700 Subject: [PATCH 01/12] define Key newtype, use it in just one place to start We implement PartialEq/Eq so unit tests can compare state objects that contain one, Clone so they can be passed around easily, and Debug (which redacts the actual key) so Events can be printed with {:?}. We implement Deref to return the underlying vector, so any place that actually needs the vector (like for decryption) will get it automatically. --- core/src/events.rs | 15 +++++++++++++++ core/src/key.rs | 25 ++++++++++++------------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/core/src/events.rs b/core/src/events.rs index f0a54656..63c34733 100644 --- a/core/src/events.rs +++ b/core/src/events.rs @@ -1,6 +1,7 @@ use hex; use std::fmt; use std::iter::FromIterator; +use std::ops::Deref; use std::sync::Arc; // Events come into the core, Actions go out of it (to the IO glue layer) use api::{APIAction, IOAction, Mood}; @@ -8,6 +9,20 @@ use util::maybe_utf8; pub use wordlist::Wordlist; +#[derive(PartialEq, Eq, Clone)] +pub struct Key(pub Vec); +impl Deref for Key { + type Target = Vec; + fn deref(&self) -> &Vec { + &self.0 + } +} +impl fmt::Debug for Key { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Key(REDACTED)") + } +} + // machines (or IO, or the API) emit these events, and each is routed to a // specific machine (or IO or the API) #[allow(dead_code)] // TODO: Drop dead code directive once core is complete diff --git a/core/src/key.rs b/core/src/key.rs index 5481b797..3d26d4aa 100644 --- a/core/src/key.rs +++ b/core/src/key.rs @@ -8,7 +8,7 @@ use sodiumoxide::crypto::secretbox; use spake2::{Ed25519Group, SPAKE2}; use std::mem; -use events::Events; +use events::{Events, Key}; use util; // we process these use events::KeyEvent; @@ -72,16 +72,16 @@ impl KeyMachine { S1KnowCode(_) => panic!("already got code"), S2KnowPake(ref their_pake_msg) => { let (pake_state, pake_msg_ser) = start_pake(&code, &self.appid); - let key = finish_pake(pake_state, their_pake_msg.clone()); + let key: Key = finish_pake(pake_state, their_pake_msg.clone()); let versions = json!({"app_versions": {}}); // TODO: self.versions let (version_phase, version_msg) = build_version_msg(&self.side, &key, &versions); - self.state = Some(S3KnowBoth(key.clone())); + self.state = Some(S3KnowBoth(key.to_vec())); events![ M_AddMessage("pake".to_string(), pake_msg_ser), M_AddMessage(version_phase, version_msg), - B_GotKey(key.clone()), - R_GotKey(key.clone()) + B_GotKey(key.to_vec()), + R_GotKey(key.to_vec()) ] } S3KnowBoth(_) => panic!("already got code"), @@ -99,15 +99,15 @@ impl KeyMachine { events![] } S1KnowCode(pake_state) => { - let key = finish_pake(pake_state, pake); + let key: Key = finish_pake(pake_state, pake); let versions = json!({"app_versions": {}}); // TODO: self.versions let (version_phase, version_msg) = build_version_msg(&self.side, &key, &versions); - self.state = Some(S3KnowBoth(key.clone())); + self.state = Some(S3KnowBoth(key.to_vec())); events![ M_AddMessage(version_phase, version_msg), - B_GotKey(key.clone()), - R_GotKey(key.clone()) + B_GotKey(key.to_vec()), + R_GotKey(key.to_vec()) ] } S2KnowPake(_) => panic!("already got pake"), @@ -131,12 +131,11 @@ fn start_pake(appid: &str, code: &str) -> (SPAKE2, Vec) { (pake_state, pake_msg_ser) } -fn finish_pake(pake_state: SPAKE2, peer_msg: Vec) -> Vec { +fn finish_pake(pake_state: SPAKE2, peer_msg: Vec) -> Key { let msg2 = extract_pake_msg(peer_msg).unwrap(); - let key = pake_state + Key(pake_state .finish(&hex::decode(msg2).unwrap()) - .unwrap(); - key + .unwrap()) } fn build_version_msg( From c52afc771fb664c56a9747230d0b32744b5d82fd Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:27:30 -0700 Subject: [PATCH 02/12] use Key for internal KeyMachine states and functions --- core/src/key.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/key.rs b/core/src/key.rs index 3d26d4aa..77aaf6a5 100644 --- a/core/src/key.rs +++ b/core/src/key.rs @@ -22,7 +22,7 @@ enum State { S0KnowNothing, S1KnowCode(SPAKE2), // pake_state S2KnowPake(Vec), // their_pake - S3KnowBoth(Vec), // key + S3KnowBoth(Key), // key #[allow(dead_code)] // TODO: if PAKE is somehow bad, land here S4Scared, } @@ -76,7 +76,7 @@ impl KeyMachine { let versions = json!({"app_versions": {}}); // TODO: self.versions let (version_phase, version_msg) = build_version_msg(&self.side, &key, &versions); - self.state = Some(S3KnowBoth(key.to_vec())); + self.state = Some(S3KnowBoth(key.clone())); events![ M_AddMessage("pake".to_string(), pake_msg_ser), M_AddMessage(version_phase, version_msg), @@ -103,7 +103,7 @@ impl KeyMachine { let versions = json!({"app_versions": {}}); // TODO: self.versions let (version_phase, version_msg) = build_version_msg(&self.side, &key, &versions); - self.state = Some(S3KnowBoth(key.to_vec())); + self.state = Some(S3KnowBoth(key.clone())); events![ M_AddMessage(version_phase, version_msg), B_GotKey(key.to_vec()), @@ -140,7 +140,7 @@ fn finish_pake(pake_state: SPAKE2, peer_msg: Vec) -> Key { fn build_version_msg( side: &str, - key: &Vec, + key: &Key, versions: &Value, ) -> (String, Vec) { let phase = "version"; From 1ce69c7cf82a889f97bc0e5d44f254610f1a5c9b Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:29:27 -0700 Subject: [PATCH 03/12] SendMachine: rename states to be more informative --- core/src/send.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/send.rs b/core/src/send.rs index 7c1747d1..5d3beb10 100644 --- a/core/src/send.rs +++ b/core/src/send.rs @@ -15,8 +15,8 @@ pub struct SendMachine { #[derive(Debug, PartialEq)] enum State { - S0, - S1(Vec), + S0NoKey, + S1HaveVerifiedKey(Vec), } enum QueueStatus { @@ -28,7 +28,7 @@ enum QueueStatus { impl SendMachine { pub fn new(side: &str) -> SendMachine { SendMachine { - state: State::S0, + state: State::S0NoKey, side: side.to_string(), key: Vec::new(), queue: Vec::new(), @@ -41,8 +41,8 @@ impl SendMachine { self.state, event ); let (newstate, actions, queue_status) = match self.state { - State::S0 => self.do_s0(event), - State::S1(ref key) => self.do_s1(key.to_vec(), event), + State::S0NoKey => self.do_s0(event), + State::S1HaveVerifiedKey(ref key) => self.do_s1(key.to_vec(), event), }; // process the queue @@ -85,13 +85,13 @@ impl SendMachine { use events::SendEvent::*; match event { GotVerifiedKey(ref key) => ( - State::S1(key.to_vec()), + State::S1HaveVerifiedKey(key.to_vec()), self.drain(key.to_vec()), QueueStatus::Drain, ), // we don't have a verified key, yet we got messages to send, so queue it up. Send(phase, plaintext) => ( - State::S0, + State::S0NoKey, events![], QueueStatus::Enqueue((phase, plaintext)), ), @@ -110,7 +110,7 @@ impl SendMachine { let deliver_events = self.deliver(key.clone(), phase, plaintext); ( - State::S1(key), + State::S1HaveVerifiedKey(key), deliver_events, QueueStatus::NoAction, ) From a3fab4d7fdbbe64bd4e9d5eb2b44ba50d92ee0a0 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:32:27 -0700 Subject: [PATCH 04/12] use Key in BossEvent::GotKey --- core/src/boss.rs | 2 +- core/src/events.rs | 2 +- core/src/key.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/boss.rs b/core/src/boss.rs index 631539a8..8fa3c2c8 100644 --- a/core/src/boss.rs +++ b/core/src/boss.rs @@ -88,7 +88,7 @@ impl BossMachine { use events::BossEvent::*; match event { GotCode(code) => self.got_code(&code), - GotKey(key) => events![APIAction::GotUnverifiedKey(key)], + GotKey(key) => events![APIAction::GotUnverifiedKey(key.to_vec())], Happy => self.happy(), GotVerifier(verifier) => events![APIAction::GotVerifier(verifier)], GotMessage(phase, plaintext) => self.got_message(&phase, plaintext), diff --git a/core/src/events.rs b/core/src/events.rs index 63c34733..b8f7b9cf 100644 --- a/core/src/events.rs +++ b/core/src/events.rs @@ -41,7 +41,7 @@ pub enum BossEvent { Error, Closed, GotCode(String), - GotKey(Vec), // TODO: fixed length? + GotKey(Key), // TODO: fixed length? Scared, Happy, GotVerifier(Vec), // TODO: fixed length (sha256) diff --git a/core/src/key.rs b/core/src/key.rs index 77aaf6a5..f935d227 100644 --- a/core/src/key.rs +++ b/core/src/key.rs @@ -80,7 +80,7 @@ impl KeyMachine { events![ M_AddMessage("pake".to_string(), pake_msg_ser), M_AddMessage(version_phase, version_msg), - B_GotKey(key.to_vec()), + B_GotKey(key.clone()), R_GotKey(key.to_vec()) ] } @@ -106,7 +106,7 @@ impl KeyMachine { self.state = Some(S3KnowBoth(key.clone())); events![ M_AddMessage(version_phase, version_msg), - B_GotKey(key.to_vec()), + B_GotKey(key.clone()), R_GotKey(key.to_vec()) ] } From 4b6b5393a79cb17b751027ebffe0b3da5c6ec348 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:33:54 -0700 Subject: [PATCH 05/12] use Key in ReceiveEvent::GotKey --- core/src/events.rs | 2 +- core/src/key.rs | 4 ++-- core/src/receive.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/events.rs b/core/src/events.rs index b8f7b9cf..4991ff6d 100644 --- a/core/src/events.rs +++ b/core/src/events.rs @@ -189,7 +189,7 @@ impl fmt::Debug for OrderEvent { #[derive(PartialEq)] pub enum ReceiveEvent { GotMessage(String, String, Vec), // side, phase, body - GotKey(Vec), // key + GotKey(Key), } impl fmt::Debug for ReceiveEvent { diff --git a/core/src/key.rs b/core/src/key.rs index f935d227..f099b436 100644 --- a/core/src/key.rs +++ b/core/src/key.rs @@ -81,7 +81,7 @@ impl KeyMachine { M_AddMessage("pake".to_string(), pake_msg_ser), M_AddMessage(version_phase, version_msg), B_GotKey(key.clone()), - R_GotKey(key.to_vec()) + R_GotKey(key.clone()) ] } S3KnowBoth(_) => panic!("already got code"), @@ -107,7 +107,7 @@ impl KeyMachine { events![ M_AddMessage(version_phase, version_msg), B_GotKey(key.clone()), - R_GotKey(key.to_vec()) + R_GotKey(key.clone()) ] } S2KnowPake(_) => panic!("already got pake"), diff --git a/core/src/receive.rs b/core/src/receive.rs index c4878267..05b8c5b7 100644 --- a/core/src/receive.rs +++ b/core/src/receive.rs @@ -51,7 +51,7 @@ impl ReceiveMachine { use events::ReceiveEvent::*; match event { GotMessage(..) => panic!(), - GotKey(key) => (State::S1UnverifiedKey(key), events![]), + GotKey(key) => (State::S1UnverifiedKey(key.to_vec()), events![]), } } From 205a9361aafb51388a3d730312a79bf7d20f28ef Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:39:00 -0700 Subject: [PATCH 06/12] use Key in ReceiveMachine states --- core/src/receive.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/src/receive.rs b/core/src/receive.rs index 05b8c5b7..d5829eb7 100644 --- a/core/src/receive.rs +++ b/core/src/receive.rs @@ -1,4 +1,4 @@ -use events::Events; +use events::{Key, Events}; use key; use std::str; // we process these @@ -12,8 +12,8 @@ use events::SendEvent::GotVerifiedKey as S_GotVerifiedKey; #[derive(Debug, PartialEq)] enum State { S0UnknownKey, - S1UnverifiedKey(Vec), - S2VerifiedKey(Vec), + S1UnverifiedKey(Key), + S2VerifiedKey(Key), S3Scared, } @@ -51,7 +51,7 @@ impl ReceiveMachine { use events::ReceiveEvent::*; match event { GotMessage(..) => panic!(), - GotKey(key) => (State::S1UnverifiedKey(key.to_vec()), events![]), + GotKey(key) => (State::S1UnverifiedKey(key.clone()), events![]), } } @@ -68,7 +68,7 @@ impl ReceiveMachine { fn in_unverified_key( &self, - key: &[u8], + key: &Key, event: ReceiveEvent, ) -> (State, Events) { use events::ReceiveEvent::*; @@ -81,7 +81,7 @@ impl ReceiveMachine { let msg = key::derive_key(&key, b"wormhole:verifier", 32); // TODO: replace 32 with KEY_SIZE const ( - State::S2VerifiedKey(key.to_vec()), + State::S2VerifiedKey(key.clone()), events![ S_GotVerifiedKey(key.to_vec()), B_Happy, @@ -101,7 +101,7 @@ impl ReceiveMachine { fn in_verified_key( &self, - key: &[u8], + key: &Key, event: ReceiveEvent, ) -> (State, Events) { use events::ReceiveEvent::*; @@ -112,7 +112,7 @@ impl ReceiveMachine { Some(plaintext) => { // got_message_good ( - State::S2VerifiedKey(key.to_vec()), + State::S2VerifiedKey(key.clone()), events![B_GotMessage(phase, plaintext)], ) } From d3ffd7c1baf75b1974b0409118a953f5f5b00814 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:41:19 -0700 Subject: [PATCH 07/12] use Key in ReceiveMachine internal functions --- core/src/receive.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/receive.rs b/core/src/receive.rs index d5829eb7..f004d7f9 100644 --- a/core/src/receive.rs +++ b/core/src/receive.rs @@ -57,11 +57,11 @@ impl ReceiveMachine { fn derive_key_and_decrypt( side: &str, - key: &[u8], + key: &Key, phase: &str, body: Vec, ) -> Option> { - let data_key = key::derive_phase_key(&side, &key, &phase); + let data_key = key::derive_phase_key(&side, &key.to_vec(), &phase); key::decrypt_data(data_key.clone(), &body) } From c5f1dc8909aa0cef7cf6fb1a21b87045162d5a1e Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:42:57 -0700 Subject: [PATCH 08/12] use Key in SendEvent::GotVerifiedKey --- core/src/events.rs | 2 +- core/src/receive.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/events.rs b/core/src/events.rs index 4991ff6d..1a8973cf 100644 --- a/core/src/events.rs +++ b/core/src/events.rs @@ -250,7 +250,7 @@ impl fmt::Debug for RendezvousEvent { #[derive(PartialEq)] pub enum SendEvent { Send(String, Vec), // phase, plaintext - GotVerifiedKey(Vec), + GotVerifiedKey(Key), } impl fmt::Debug for SendEvent { diff --git a/core/src/receive.rs b/core/src/receive.rs index f004d7f9..b55588bd 100644 --- a/core/src/receive.rs +++ b/core/src/receive.rs @@ -83,7 +83,7 @@ impl ReceiveMachine { ( State::S2VerifiedKey(key.clone()), events![ - S_GotVerifiedKey(key.to_vec()), + S_GotVerifiedKey(key.clone()), B_Happy, B_GotVerifier(msg), B_GotMessage(phase, plaintext) From 5fc4882696f7d73f1585b4b4c996cc02617430bd Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:47:01 -0700 Subject: [PATCH 09/12] use Key in SendMachine internals remove unused .key in the KeyMachine struct: the key is only stored inside the state enum --- core/src/send.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/core/src/send.rs b/core/src/send.rs index 5d3beb10..cddd3298 100644 --- a/core/src/send.rs +++ b/core/src/send.rs @@ -1,4 +1,4 @@ -use events::Events; +use events::{Key, Events}; use key; // we process these use events::SendEvent; @@ -9,14 +9,13 @@ use events::MailboxEvent::AddMessage as M_AddMessage; pub struct SendMachine { state: State, side: String, - key: Vec, queue: Vec<(String, Vec)>, } #[derive(Debug, PartialEq)] enum State { S0NoKey, - S1HaveVerifiedKey(Vec), + S1HaveVerifiedKey(Key), } enum QueueStatus { @@ -30,7 +29,6 @@ impl SendMachine { SendMachine { state: State::S0NoKey, side: side.to_string(), - key: Vec::new(), queue: Vec::new(), } } @@ -42,7 +40,7 @@ impl SendMachine { ); let (newstate, actions, queue_status) = match self.state { State::S0NoKey => self.do_s0(event), - State::S1HaveVerifiedKey(ref key) => self.do_s1(key.to_vec(), event), + State::S1HaveVerifiedKey(ref key) => self.do_s1(&key, event), }; // process the queue @@ -58,11 +56,11 @@ impl SendMachine { actions } - fn drain(&self, key: Vec) -> Events { + fn drain(&self, key: Key) -> Events { let mut es = Events::new(); for &(ref phase, ref plaintext) in &self.queue { - let data_key = key::derive_phase_key(&self.side, &key, phase); + let data_key = key::derive_phase_key(&self.side, &key.to_vec(), phase); let (_nonce, encrypted) = key::encrypt_data(data_key, plaintext); es.push(M_AddMessage(phase.to_string(), encrypted)); } @@ -72,11 +70,11 @@ impl SendMachine { fn deliver( &self, - key: Vec, + key: Key, phase: String, plaintext: Vec, ) -> Events { - let data_key = key::derive_phase_key(&self.side, &key, &phase); + let data_key = key::derive_phase_key(&self.side, &key.to_vec(), &phase); let (_nonce, encrypted) = key::encrypt_data(data_key, &plaintext); events![M_AddMessage(phase, encrypted)] } @@ -85,8 +83,8 @@ impl SendMachine { use events::SendEvent::*; match event { GotVerifiedKey(ref key) => ( - State::S1HaveVerifiedKey(key.to_vec()), - self.drain(key.to_vec()), + State::S1HaveVerifiedKey(key.clone()), + self.drain(key.clone()), QueueStatus::Drain, ), // we don't have a verified key, yet we got messages to send, so queue it up. @@ -100,7 +98,7 @@ impl SendMachine { fn do_s1( &self, - key: Vec, + key: &Key, event: SendEvent, ) -> (State, Events, QueueStatus) { use events::SendEvent::*; @@ -110,7 +108,7 @@ impl SendMachine { let deliver_events = self.deliver(key.clone(), phase, plaintext); ( - State::S1HaveVerifiedKey(key), + State::S1HaveVerifiedKey(key.clone()), deliver_events, QueueStatus::NoAction, ) From b1937fa3206728755f689ad4ef54a52690925089 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:50:39 -0700 Subject: [PATCH 10/12] use Key in key::derive_phase_key() --- core/src/key.rs | 14 +++++++------- core/src/receive.rs | 2 +- core/src/send.rs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/key.rs b/core/src/key.rs index f099b436..d3e7fe0c 100644 --- a/core/src/key.rs +++ b/core/src/key.rs @@ -144,7 +144,7 @@ fn build_version_msg( versions: &Value, ) -> (String, Vec) { let phase = "version"; - let data_key = derive_phase_key(side, key, &phase); + let data_key = derive_phase_key(side, &key, &phase); let plaintext = versions.to_string(); let (_nonce, encrypted) = encrypt_data(data_key, &plaintext.as_bytes()); (phase.to_string(), encrypted) @@ -195,7 +195,7 @@ pub fn derive_key(key: &[u8], purpose: &[u8], length: usize) -> Vec { hk.expand(purpose, length) } -pub fn derive_phase_key(side: &str, key: &[u8], phase: &str) -> Vec { +pub fn derive_phase_key(side: &str, key: &Key, phase: &str) -> Vec { let side_bytes = side.as_bytes(); let phase_bytes = phase.as_bytes(); let side_digest: Vec = sha256_digest(side_bytes) @@ -215,7 +215,7 @@ pub fn derive_phase_key(side: &str, key: &[u8], phase: &str) -> Vec { purpose_vec.extend(phase_digest); let length = sodiumoxide::crypto::secretbox::KEYBYTES; - derive_key(key, &purpose_vec, length) + derive_key(&key.to_vec(), &purpose_vec, length) } #[cfg(test)] @@ -245,10 +245,10 @@ mod test { // hexlified output: fe9315729668a6278a97449dc99a5f4c2102a668c6853338152906bb75526a96 let _k = KeyMachine::new("appid1", "side"); - let key = "key".as_bytes(); + let key = Key("key".as_bytes().to_vec()); let side = "side"; let phase = "phase1"; - let phase1_key = derive_phase_key(side, key, phase); + let phase1_key = derive_phase_key(side, &key, phase); assert_eq!( hex::encode(phase1_key), @@ -260,10 +260,10 @@ mod test { fn test_encrypt_data_decrypt_data_roundtrip() { use super::*; - let key = "key".as_bytes(); + let key = Key("key".as_bytes().to_vec()); let side = "side"; let phase = "phase"; - let data_key = derive_phase_key(side, key, phase); + let data_key = derive_phase_key(side, &key, phase); let plaintext = "hello world"; let (_nonce, encrypted) = diff --git a/core/src/receive.rs b/core/src/receive.rs index b55588bd..0aa22047 100644 --- a/core/src/receive.rs +++ b/core/src/receive.rs @@ -61,7 +61,7 @@ impl ReceiveMachine { phase: &str, body: Vec, ) -> Option> { - let data_key = key::derive_phase_key(&side, &key.to_vec(), &phase); + let data_key = key::derive_phase_key(&side, &key, &phase); key::decrypt_data(data_key.clone(), &body) } diff --git a/core/src/send.rs b/core/src/send.rs index cddd3298..63205712 100644 --- a/core/src/send.rs +++ b/core/src/send.rs @@ -60,7 +60,7 @@ impl SendMachine { let mut es = Events::new(); for &(ref phase, ref plaintext) in &self.queue { - let data_key = key::derive_phase_key(&self.side, &key.to_vec(), phase); + let data_key = key::derive_phase_key(&self.side, &key, phase); let (_nonce, encrypted) = key::encrypt_data(data_key, plaintext); es.push(M_AddMessage(phase.to_string(), encrypted)); } @@ -74,7 +74,7 @@ impl SendMachine { phase: String, plaintext: Vec, ) -> Events { - let data_key = key::derive_phase_key(&self.side, &key.to_vec(), &phase); + let data_key = key::derive_phase_key(&self.side, &key, &phase); let (_nonce, encrypted) = key::encrypt_data(data_key, &plaintext); events![M_AddMessage(phase, encrypted)] } From 820a42e68d14a83334342edadfaae4b635687eef Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:53:33 -0700 Subject: [PATCH 11/12] use Key in APIEvent::GotUnverifiedKey --- core/src/api.rs | 3 ++- core/src/boss.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/api.rs b/core/src/api.rs index 58583a67..b0484540 100644 --- a/core/src/api.rs +++ b/core/src/api.rs @@ -3,6 +3,7 @@ use std::collections::HashMap; use std::error::Error; use std::fmt; use util::maybe_utf8; +use events::Key; #[derive(PartialEq)] pub enum APIEvent { @@ -119,7 +120,7 @@ pub enum APIAction { // from WormholeCore out through IO glue to application GotWelcome(HashMap), // actually anything JSON-able: Value GotCode(String), // must be easy to canonically encode into UTF-8 bytes - GotUnverifiedKey(Vec), + GotUnverifiedKey(Key), GotVerifier(Vec), GotVersions(HashMap), // actually anything JSON-able GotMessage(Vec), diff --git a/core/src/boss.rs b/core/src/boss.rs index 8fa3c2c8..f90a9444 100644 --- a/core/src/boss.rs +++ b/core/src/boss.rs @@ -88,7 +88,7 @@ impl BossMachine { use events::BossEvent::*; match event { GotCode(code) => self.got_code(&code), - GotKey(key) => events![APIAction::GotUnverifiedKey(key.to_vec())], + GotKey(key) => events![APIAction::GotUnverifiedKey(key.clone())], Happy => self.happy(), GotVerifier(verifier) => events![APIAction::GotVerifier(verifier)], GotMessage(phase, plaintext) => self.got_message(&phase, plaintext), From f18861d8501e47da5a5d157d6f671070d25660f8 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 May 2018 14:54:26 -0700 Subject: [PATCH 12/12] cargo fmt --- core/src/api.rs | 2 +- core/src/receive.rs | 2 +- core/src/send.rs | 9 ++------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/core/src/api.rs b/core/src/api.rs index b0484540..743a03de 100644 --- a/core/src/api.rs +++ b/core/src/api.rs @@ -1,9 +1,9 @@ +use events::Key; use hex; use std::collections::HashMap; use std::error::Error; use std::fmt; use util::maybe_utf8; -use events::Key; #[derive(PartialEq)] pub enum APIEvent { diff --git a/core/src/receive.rs b/core/src/receive.rs index 0aa22047..b8291754 100644 --- a/core/src/receive.rs +++ b/core/src/receive.rs @@ -1,4 +1,4 @@ -use events::{Key, Events}; +use events::{Events, Key}; use key; use std::str; // we process these diff --git a/core/src/send.rs b/core/src/send.rs index 63205712..05e911b6 100644 --- a/core/src/send.rs +++ b/core/src/send.rs @@ -1,4 +1,4 @@ -use events::{Key, Events}; +use events::{Events, Key}; use key; // we process these use events::SendEvent; @@ -68,12 +68,7 @@ impl SendMachine { es } - fn deliver( - &self, - key: Key, - phase: String, - plaintext: Vec, - ) -> Events { + fn deliver(&self, key: Key, phase: String, plaintext: Vec) -> Events { let data_key = key::derive_phase_key(&self.side, &key, &phase); let (_nonce, encrypted) = key::encrypt_data(data_key, &plaintext); events![M_AddMessage(phase, encrypted)]