Skip to content

Commit

Permalink
Merge pull request #373 from tox-rs/drop_peer_session_pk
Browse files Browse the repository at this point in the history
Do not store peer_session_pk
  • Loading branch information
kpp authored May 14, 2019
2 parents b161708 + b8c634c commit fefeff0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 59 deletions.
19 changes: 2 additions & 17 deletions src/toxcore/net_crypto/crypto_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ pub enum ConnectionStatus {
sent_nonce: Nonce,
/// Nonce that should be used to decrypt incoming packets
received_nonce: Nonce,
/// `PublicKey` of the other side for this session
peer_session_pk: PublicKey,
/// `PrecomputedKey` for this session that is used to encrypt and
/// decrypt data packets
session_precomputed_key: PrecomputedKey,
Expand All @@ -189,8 +187,6 @@ pub enum ConnectionStatus {
sent_nonce: Nonce,
/// Nonce that should be used to decrypt incoming packets
received_nonce: Nonce,
/// `PublicKey` of the other side for this session
peer_session_pk: PublicKey,
/// `PrecomputedKey` for this session that is used to encrypt and
/// decrypt data packets
session_precomputed_key: PrecomputedKey,
Expand Down Expand Up @@ -401,7 +397,6 @@ impl CryptoConnection {
let status = ConnectionStatus::NotConfirmed {
sent_nonce,
received_nonce,
peer_session_pk,
session_precomputed_key: precompute(&peer_session_pk, &session_sk),
packet: StatusPacket::new_crypto_handshake(handshake)
};
Expand Down Expand Up @@ -771,28 +766,20 @@ mod tests {
let connection_c = connection.clone();
assert_eq!(connection_c, connection);

let (peer_session_pk, _peer_session_sk) = gen_keypair();
let (_session_pk, session_sk) = gen_keypair();
let session_precomputed_key = precompute(&peer_session_pk, &session_sk);
connection.status = ConnectionStatus::NotConfirmed {
sent_nonce: gen_nonce(),
received_nonce: gen_nonce(),
peer_session_pk,
session_precomputed_key,
session_precomputed_key: precompute(&gen_keypair().0, &gen_keypair().1),
packet: StatusPacket::new_crypto_handshake(crypto_handshake),
};

let connection_c = connection.clone();
assert_eq!(connection_c, connection);

let (peer_session_pk, _peer_session_sk) = gen_keypair();
let (_session_pk, session_sk) = gen_keypair();
let session_precomputed_key = precompute(&peer_session_pk, &session_sk);
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce: gen_nonce(),
peer_session_pk,
session_precomputed_key,
session_precomputed_key: precompute(&gen_keypair().0, &gen_keypair().1),
};

let connection_c = connection.clone();
Expand Down Expand Up @@ -871,7 +858,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce: gen_nonce(),
peer_session_pk: gen_keypair().0,
session_precomputed_key: precompute(&gen_keypair().0, &gen_keypair().1),
};

Expand Down Expand Up @@ -900,7 +886,6 @@ mod tests {
connection.status = ConnectionStatus::NotConfirmed {
sent_nonce: gen_nonce(),
received_nonce: gen_nonce(),
peer_session_pk: gen_keypair().0,
session_precomputed_key: precompute(&gen_keypair().0, &gen_keypair().1),
packet: StatusPacket::new_crypto_handshake(crypto_handshake),
};
Expand Down
47 changes: 5 additions & 42 deletions src/toxcore/net_crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ impl NetCrypto {
ConnectionStatus::NotConfirmed {
sent_nonce,
received_nonce: payload.base_nonce,
peer_session_pk: payload.session_pk,
session_precomputed_key: precompute(&payload.session_pk, &connection.session_sk),
packet: StatusPacket::new_crypto_handshake(handshake)
}
Expand All @@ -459,7 +458,6 @@ impl NetCrypto {
| ConnectionStatus::NotConfirmed { sent_nonce, ref packet, .. } => ConnectionStatus::NotConfirmed {
sent_nonce,
received_nonce: payload.base_nonce,
peer_session_pk: payload.session_pk,
session_precomputed_key: precompute(&payload.session_pk, &connection.session_sk),
packet: packet.clone()
},
Expand Down Expand Up @@ -636,10 +634,10 @@ impl NetCrypto {
*/
fn handle_crypto_data(&self, connection: &mut CryptoConnection, packet: &CryptoData, udp: bool)
-> impl Future<Item = (), Error = HandlePacketError> + Send {
let (sent_nonce, mut received_nonce, peer_session_pk, session_precomputed_key) = match connection.status {
ConnectionStatus::NotConfirmed { sent_nonce, received_nonce, peer_session_pk, ref session_precomputed_key, .. }
| ConnectionStatus::Established { sent_nonce, received_nonce, peer_session_pk, ref session_precomputed_key } => {
(sent_nonce, received_nonce, peer_session_pk, session_precomputed_key.clone())
let (sent_nonce, mut received_nonce, session_precomputed_key) = match connection.status {
ConnectionStatus::NotConfirmed { sent_nonce, received_nonce, ref session_precomputed_key, .. }
| ConnectionStatus::Established { sent_nonce, received_nonce, ref session_precomputed_key } => {
(sent_nonce, received_nonce, session_precomputed_key.clone())
},
_ => {
return Box::new(future::err(HandlePacketError::from(HandlePacketErrorKind::CannotHandleCryptoData)))
Expand Down Expand Up @@ -688,7 +686,6 @@ impl NetCrypto {
connection.status = ConnectionStatus::Established {
sent_nonce,
received_nonce,
peer_session_pk,
session_precomputed_key
};

Expand Down Expand Up @@ -1417,10 +1414,7 @@ mod tests {
net_crypto.handle_crypto_handshake(&mut connection, &crypto_handshake).wait().unwrap();

let received_nonce = unpack!(connection.status, ConnectionStatus::NotConfirmed, received_nonce);
let peer_session_pk = unpack!(connection.status, ConnectionStatus::NotConfirmed, peer_session_pk);

assert_eq!(received_nonce, base_nonce);
assert_eq!(peer_session_pk, session_pk);

let packet = unpack!(connection.status, ConnectionStatus::NotConfirmed, packet);
let packet = unpack!(packet.dht_packet(), Packet::CryptoHandshake);
Expand Down Expand Up @@ -1486,12 +1480,9 @@ mod tests {

net_crypto.handle_crypto_handshake(&mut connection, &crypto_handshake).wait().unwrap();

// Nonce and session pk should be taken from the packet
// Nonce should be taken from the packet
let received_nonce = unpack!(connection.status, ConnectionStatus::NotConfirmed, received_nonce);
let peer_session_pk = unpack!(connection.status, ConnectionStatus::NotConfirmed, peer_session_pk);

assert_eq!(received_nonce, base_nonce);
assert_eq!(peer_session_pk, session_pk);

// cookie should not be updated
let packet = unpack!(connection.status, ConnectionStatus::NotConfirmed, packet);
Expand Down Expand Up @@ -1534,7 +1525,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce: gen_nonce(),
peer_session_pk,
session_precomputed_key,
};

Expand Down Expand Up @@ -1816,10 +1806,7 @@ mod tests {
let connection = connections.get(&peer_real_pk).unwrap().read().clone();

let received_nonce = unpack!(connection.status, ConnectionStatus::NotConfirmed, received_nonce);
let peer_session_pk = unpack!(connection.status, ConnectionStatus::NotConfirmed, peer_session_pk);

assert_eq!(received_nonce, base_nonce);
assert_eq!(peer_session_pk, session_pk);

let packet = unpack!(connection.status, ConnectionStatus::NotConfirmed, packet);
let packet = unpack!(packet.dht_packet(), Packet::CryptoHandshake);
Expand Down Expand Up @@ -1882,10 +1869,7 @@ mod tests {
assert_eq!(connection.get_udp_addr_v4(), Some(addr));

let received_nonce = unpack!(connection.status, ConnectionStatus::NotConfirmed, received_nonce);
let peer_session_pk = unpack!(connection.status, ConnectionStatus::NotConfirmed, peer_session_pk);

assert_eq!(received_nonce, base_nonce);
assert_eq!(peer_session_pk, session_pk);

let packet = unpack!(connection.status, ConnectionStatus::NotConfirmed, packet);
let packet = unpack!(packet.dht_packet(), Packet::CryptoHandshake);
Expand Down Expand Up @@ -1976,7 +1960,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2037,7 +2020,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2115,7 +2097,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2187,7 +2168,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2243,7 +2223,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2333,7 +2312,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2392,7 +2370,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2469,7 +2446,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2539,7 +2515,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2592,7 +2567,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2648,7 +2622,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -2746,7 +2719,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -3128,7 +3100,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce,
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -3186,7 +3157,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce,
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -3253,7 +3223,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce: gen_nonce(),
received_nonce,
peer_session_pk,
session_precomputed_key,
};

Expand Down Expand Up @@ -3303,7 +3272,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce,
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -3366,7 +3334,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce,
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -3439,7 +3406,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce,
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -3496,7 +3462,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce,
received_nonce,
peer_session_pk,
session_precomputed_key,
};

Expand Down Expand Up @@ -3576,7 +3541,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce,
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down Expand Up @@ -3884,7 +3848,6 @@ mod tests {
connection.status = ConnectionStatus::Established {
sent_nonce,
received_nonce,
peer_session_pk,
session_precomputed_key: session_precomputed_key.clone(),
};

Expand Down

0 comments on commit fefeff0

Please sign in to comment.