Repository navigation
Ensure init_key and encryption_key are different - #1177
Conversation
This PR separates the init_key from the key package and the encryption_key in the leaf node. Changes - Creating a new key package generates a fresh encryption key for the leaf node now. The key pair is stored in the key store with the labelled init_key as index. - When processing a welcome the encryption key is read from the key store and used to build the tree. - Remove ValSem105: init keys can't be checked anymore because they are not in the tree - Introduce ValSem113: init key and encryption key must be different (checks only in add proposal for now) - Introduce ValSem114: encryption keys must be unique in the tree (checks only in add proposal for now) Fixes #885
kkohbrok
left a comment
There was a problem hiding this comment.
Thanks for the PR! A few comments, but nothing big.
| // use later when creating a group with this key package. | ||
| let (leaf_node, _) = LeafNode::new( | ||
| config, | ||
| credential, // FIXME |
There was a problem hiding this comment.
Leftover FIXME: Is this meant for a follow-up?
| config: CryptoConfig, | ||
| credential_bundle: &CredentialBundle, | ||
| lifetime: Lifetime, | ||
| init_key: &[u8], |
There was a problem hiding this comment.
As discussed OOB, I think bubbling up the secret to store somewhere else would be a bit nicer as it allows us to keep the KeyPackage details out of the LeafNode. The same goes for the constructors below.
| vec![], | ||
| backend, | ||
| ) | ||
| .unwrap(); |
There was a problem hiding this comment.
This is test code and I'd actually prefer panicking here over bubling up the error to the test.
| .key_store() | ||
| .delete(key_package_bundle.key_package.hpke_init_key().as_slice()) | ||
| // This error really shouldn't happen. We just read the value. | ||
| .map_err(|_| WelcomeError::NoMatchingEncryptionKey)?; |
There was a problem hiding this comment.
Would it be worth extending the key store with a read-and-delete operation?
There was a problem hiding this comment.
Yes I think that would be nice. I added a comment here #337 (comment)
| if !public_key_set.insert(public_key) { | ||
| if !init_key_set.insert(proposal_init_key) { | ||
| return Err(ProposalValidationError::DuplicatePublicKeyAddProposal); | ||
| } |
There was a problem hiding this comment.
I don't think this check is strictly necessary in that it is not mandated by the spec. If I understand Section 10.1 correctly, it is technically okay for two KeyPackages to have the same init key. No need to remove it with this PR, though I guess.
There was a problem hiding this comment.
I agree. This is an old check and we might want to do it. But it needs to be discussed as part of #133.
| // ValSem114 | ||
| if !encryption_key_set.insert(proposal_encryption_key.as_slice().to_vec()) { | ||
| return Err(ProposalValidationError::DuplicatePublicKeyAddProposal); | ||
| } |
There was a problem hiding this comment.
Maybe note that this tests ValSem114 only partially with the rest of the test being a little ways below?
There was a problem hiding this comment.
Yeah, I actually think the way these checks are implemented here isn't great. It could all be checked here but I followed the way it's done for the others.
| /// HPKE init key and encryption key must be different | ||
| #[apply(ciphersuites_and_backends)] | ||
| fn test_valsem105(ciphersuite: Ciphersuite, backend: &impl OpenMlsCryptoProvider) { | ||
| fn test_valsem113(ciphersuite: Ciphersuite, backend: &impl OpenMlsCryptoProvider) { |
There was a problem hiding this comment.
Is there also a test for the new ValSem114? Or did I miss it? It would be nice to have at least a basic test.
There was a problem hiding this comment.
This actually tests both. I'll add a comment for that and change the name..
| // ValSem202: Path must be the right length | ||
| let direct_path_length = self.filtered_direct_path(params.sender_leaf_index).len(); | ||
| if direct_path_length != params.update_path.len() { | ||
| // XXX: Rewrite tests to allow for debug asserts. |
There was a problem hiding this comment.
What do you mean here? Is this meant to be for a follow-up?
There was a problem hiding this comment.
Generally it would be nice to be able to write debug asserts. But we test a lot for errors and hence can't use debug asserts without rewriting the tests.
This one here I used for testing and just left in for future reference to use once we can. But if you prefer, I can remove it.
|
This PR is so big! Please, split it 😊 |
|
This PR is so big! Please, split it 😊 |
kkohbrok
left a comment
There was a problem hiding this comment.
Thanks for addressing my comments. Let's get this in and get started with the follow-ups!
This PR separates the init_key from the key package and the encryption_key in the leaf node.
Changes
Fixes #885