Skip to content

Ensure init_key and encryption_key are different - #1177

Merged
franziskuskiefer merged 8 commits into
mainfrom
franziskus/issue885
Jan 5, 2023
Merged

franziskuskiefer merged 8 commits into
mainfrom
franziskus/issue885

Conversation

@franziskuskiefer

Copy link
Copy Markdown
Member

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

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
@franziskuskiefer
franziskuskiefer requested a review from a team as a code owner January 4, 2023 13:22
@franziskuskiefer franziskuskiefer self-assigned this Jan 4, 2023
@github-actions github-actions Bot added the size/l label Jan 4, 2023

@kkohbrok kkohbrok left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Leftover FIXME: Is this meant for a follow-up?

Comment thread openmls/src/treesync/mod.rs Resolved
Comment thread openmls/src/treesync/node/leaf_node.rs Resolved
Comment thread openmls/src/treesync/node/leaf_node.rs Outdated
config: CryptoConfig,
credential_bundle: &CredentialBundle,
lifetime: Lifetime,
init_key: &[u8],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't panic!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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)?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be worth extending the key store with a read-and-delete operation?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe note that this tests ValSem114 only partially with the rest of the test being a little ways below?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you mean here? Is this meant to be for a follow-up?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@github-actions github-actions Bot added size/xl and removed size/l labels Jan 5, 2023
@github-actions

github-actions Bot commented Jan 5, 2023

Copy link
Copy Markdown

This PR is so big! Please, split it 😊

@github-actions

github-actions Bot commented Jan 5, 2023

Copy link
Copy Markdown

This PR is so big! Please, split it 😊

@kkohbrok kkohbrok left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for addressing my comments. Let's get this in and get started with the follow-ups!

@franziskuskiefer
franziskuskiefer merged commit 4d25dfd into main Jan 5, 2023
@franziskuskiefer
franziskuskiefer deleted the franziskus/issue885 branch January 5, 2023 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MLS Spec change] Require init key and leaf key to be different (#618)

2 participants