-
Notifications
You must be signed in to change notification settings - Fork 1.7k
SecretStore: use random key to encrypt channel + session-level nonce #6470
Conversation
cb3af5e
to
1639785
Compare
@@ -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> { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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
Small grumble about avoiding long naming, logic looks ok, but would like another look from @keorn maybe |
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:
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 mostusize::MAX
sessions between consequent KeyServer restarts, which I suppose is enough).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.