Renamed confirmed -> initator on keypair

Done to reflect that the property is immutable,
unlike the "confirmed" field on the decryption state.
This commit is contained in:
Mathias Hall-Andersen
2019-08-28 12:14:32 +02:00
parent 10e6436e6b
commit 8e1a2cabd3
5 changed files with 13 additions and 11 deletions

View File

@@ -442,7 +442,7 @@ mod tests {
// 4. device-2 : responds with noise response
let msg_response = match dev2.process(&mut rng, &msg_init, Some(&src1)).unwrap() {
(Some(_), Some(msg), Some(kp)) => {
assert_eq!(kp.confirmed, false);
assert_eq!(kp.initiator, false);
msg
}
_ => panic!("unexpected response"),
@@ -469,7 +469,7 @@ mod tests {
// 7. device-2 : responds with noise response
let (msg_response, kp1) = match dev2.process(&mut rng, &msg_init, Some(&src1)).unwrap() {
(Some(_), Some(msg), Some(kp)) => {
assert_eq!(kp.confirmed, false);
assert_eq!(kp.initiator, false);
(msg, kp)
}
_ => panic!("unexpected response"),
@@ -478,7 +478,7 @@ mod tests {
// device-1 : process noise response
let kp2 = match dev1.process(&mut rng, &msg_response, Some(&src2)).unwrap() {
(Some(_), None, Some(kp)) => {
assert_eq!(kp.confirmed, true);
assert_eq!(kp.initiator, true);
kp
}
_ => panic!("unexpected response"),
@@ -515,7 +515,7 @@ mod tests {
println!("msg2 = {} : {} bytes", hex::encode(&msg2[..]), msg2.len());
println!("msg2 = {:?}", Response::parse(&msg2[..]).unwrap());
assert!(!ks_r.confirmed, "Responders key-pair is confirmed");
assert!(!ks_r.initiator, "Responders key-pair is confirmed");
// process response and obtain confirmed key-pair
@@ -523,7 +523,7 @@ mod tests {
let ks_i = ks_i.unwrap();
assert!(msg3.is_none(), "Returned message after response");
assert!(ks_i.confirmed, "Initiators key-pair is not confirmed");
assert!(ks_i.initiator, "Initiators key-pair is not confirmed");
assert_eq!(ks_i.send, ks_r.recv, "KeyI.send != KeyR.recv");
assert_eq!(ks_i.recv, ks_r.send, "KeyI.recv != KeyR.send");

View File

@@ -457,7 +457,7 @@ pub fn create_response<T: Copy, R: RngCore + CryptoRng>(
Ok(KeyPair {
birth: Instant::now(),
confirmed: false,
initiator: false,
send: Key {
id: sender,
key: key_send.into(),
@@ -532,7 +532,7 @@ pub fn consume_response<T: Copy>(
None, // no response message
Some(KeyPair {
birth: Instant::now(),
confirmed: true,
initiator: true,
send: Key {
id: sender,
key: key_send.into(),

View File

@@ -243,7 +243,7 @@ impl<T: Opaque, S: Callback<T>, R: Callback<T>, K: KeyCallback<T>> Peer<T, S, R,
keys.previous.as_ref().map(|k| release.push(k.recv.id));
// update key-wheel
if new.confirmed {
if new.initiator {
// start using key for encryption
*self.0.ekey.lock() = Some(EncryptionState {
id: new.send.id,
@@ -276,7 +276,7 @@ impl<T: Opaque, S: Callback<T>, R: Callback<T>, K: KeyCallback<T>> Peer<T, S, R,
recv.insert(
new.recv.id,
DecryptionState {
confirmed: AtomicBool::new(new.confirmed),
confirmed: AtomicBool::new(new.initiator),
keypair: Arc::downgrade(&new),
key: new.recv.key,
protector: spin::Mutex::new(AntiReplay::new()),

View File

@@ -125,6 +125,8 @@ pub fn worker_inbound<T: Opaque, S: Callback<T>, R: Callback<T>, K: KeyCallback<
peer.confirm_key(state.keypair.clone());
}
// update enpoint, TODO
// write packet to TUN device, TODO
// trigger callback

View File

@@ -20,7 +20,7 @@ impl PartialEq for Key {
#[derive(Debug, Clone, Copy)]
pub struct KeyPair {
pub birth: Instant, // when was the key-pair created
pub confirmed: bool, // has the key-pair been confirmed?
pub initiator: bool, // has the key-pair been confirmed?
pub send: Key, // key for outbound messages
pub recv: Key, // key for inbound messages
}