Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

SecretStore: use random key to encrypt channel + session-level nonce #6470

Merged
merged 4 commits into from
Sep 14, 2017

Conversation

svyatonik
Copy link
Collaborator

Given: SecretStore = set of KeyServers. Third-party KeyServer can't just 'enter' this set - it must be added to the set, using some administrative protocol. To ensure that we're connecting to servers from this set only, every KeyServer has its own KeyPair. By signing some_data with this KeyPair, KS can prove that it is the one that we're trying to connect.

Previously: during handshake, KS1 && KS2 a new Channel.KeyPair was computed from KS1.KeyPair && KS2.KeyPair. This Channel.KeyPair was used to encrypt the channel between these two key servers. So even after restart key was the same => it was possible to successfully replay previously captured messages.

This PR outline:

  1. random encryption keys: during handshake random keys are generated and these are used to compute shared KeyPair
  2. naive inter-session replay protection: every node has its own session_counter: usize, which is used as session-level nonce. When session is created on master node, session_counter is increased, and passed along with every session message. Every message for the same session must contain this number, or else session will fail. When node receives next session initialization message, it checks if its nonce is larger than previous nonce, received from the same node: if so, session is created, else creation fails (this implies that this KeyServer could be master for at most usize::MAX sessions between consequent KeyServer restarts, which I suppose is enough).
  3. added missing header version check

So, in assumption that trying to replay same-session messages could only lead to session failure (this is out of scope of this PR, but mostly true), there's no way to successfully use messages from previous sessions.

@svyatonik svyatonik added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Sep 5, 2017
@svyatonik svyatonik force-pushed the secretstore_session_key branch from cb3af5e to 1639785 Compare September 6, 2017 09:21
@@ -317,6 +342,21 @@ impl ClusterSessions {
}
Ok(encrypted_data)
}

/// Check or generate new session nonce.
fn check_session_nonce(&self, master: &NodeId, session_nonce: Option<u64>) -> Result<u64, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's already in a session-ish mod, could be named just check_nonce

@@ -59,6 +59,8 @@ struct SessionCore {
pub key_share: DocumentKeyShare,
/// Cluster which allows this node to send messages to other nodes in the cluster.
pub cluster: Arc<Cluster>,
/// Session-level nonce.
pub session_nonce: u64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be named just nonce, since it's inside a SessionCore struct

pub cluster: Arc<Cluster>,
/// Session nonce.
pub session_nonce: u64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -71,6 +73,8 @@ pub struct SessionParams {
pub key_storage: Arc<KeyStorage>,
/// Cluster
pub cluster: Arc<Cluster>,
/// Session nonce.
pub session_nonce: u64,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here also

@@ -252,6 +265,14 @@ impl SessionImpl {

Ok(())
}

/// Check session nonce.
fn check_session_nonce(&self, message_session_nonce: u64) -> Result<(), Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's SessionImpl, makes sense to call method just check_nonce

@NikVolf
Copy link
Contributor

NikVolf commented Sep 6, 2017

Small grumble about avoiding long naming, logic looks ok, but would like another look from @keorn maybe

@NikVolf NikVolf added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 6, 2017
@svyatonik svyatonik added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Sep 7, 2017
@NikVolf NikVolf added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 13, 2017
@gavofyork gavofyork merged commit e3fc3cc into master Sep 14, 2017
@gavofyork gavofyork deleted the secretstore_session_key branch September 14, 2017 17:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants