Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: parent hash error #71

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions openmls/src/treesync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub use node::encryption_keys::test_utils;
pub use node::encryption_keys::EncryptionKey;

// Public re-exports
use crate::treesync::node::leaf_node::LeafNodeIn;
pub use node::{leaf_node::LeafNode, parent_node::ParentNode, Node};

// Tests
Expand Down Expand Up @@ -437,10 +438,12 @@ impl TreeSync {
// Set the leaf indices in all the leaves and convert the node types.
for (node_index, node_option) in ratchet_tree.0.into_iter().enumerate() {
let ts_node_option: TreeNode<TreeSyncLeafNode, TreeSyncParentNode> = match node_option {
Some(node) => {
let node = node.clone();
TreeSyncNode::from(node).into()
Some(Node::LeafNode(ln)) => {
let ln = LeafNodeIn::from(ln).into_verifiable_leaf_node();
let ln = ln.validate(crypto, ciphersuite.signature_algorithm());
TreeSyncNode::from(Node::LeafNode(ln)).into()
}
Some(Node::ParentNode(pn)) => TreeSyncNode::from(Node::ParentNode(pn)).into(),
None => {
if node_index % 2 == 0 {
TreeNode::Leaf(TreeSyncLeafNode::blank())
Expand Down
46 changes: 46 additions & 0 deletions openmls/src/treesync/node/leaf_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ mod capabilities;
mod codec;

pub use capabilities::*;
use openmls_traits::crypto::OpenMlsCrypto;
use openmls_traits::types::SignatureScheme;

/// Private module to ensure protection.
mod private_mod {
Expand Down Expand Up @@ -745,6 +747,14 @@ impl VerifiableLeafNode {
VerifiableLeafNode::Commit(v) => v.signature_key(),
}
}

pub(crate) fn validate(self, crypto: &impl OpenMlsCrypto, sc: SignatureScheme) -> LeafNode {
match self {
VerifiableLeafNode::Commit(ln) => ln.standalone_validate(crypto, sc),
VerifiableLeafNode::KeyPackage(ln) => ln.standalone_validate(crypto, sc),
VerifiableLeafNode::Update(ln) => ln.standalone_validate(crypto, sc),
}
}
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand All @@ -757,6 +767,18 @@ impl VerifiableKeyPackageLeafNode {
pub(crate) fn signature_key(&self) -> &SignaturePublicKey {
&self.payload.signature_key
}

pub fn standalone_validate(
self,
crypto: &impl OpenMlsCrypto,
signature_scheme: SignatureScheme,
) -> LeafNode {
let pk = self
.signature_key()
.clone()
.into_signature_public_key_enriched(signature_scheme);
self.verify::<LeafNode>(crypto, &pk).unwrap()
}
}

impl Verifiable for VerifiableKeyPackageLeafNode {
Expand Down Expand Up @@ -799,6 +821,18 @@ impl VerifiableUpdateLeafNode {
pub(crate) fn signature_key(&self) -> &SignaturePublicKey {
&self.payload.signature_key
}

pub fn standalone_validate(
self,
crypto: &impl OpenMlsCrypto,
signature_scheme: SignatureScheme,
) -> LeafNode {
let pk = self
.signature_key()
.clone()
.into_signature_public_key_enriched(signature_scheme);
self.verify::<LeafNode>(crypto, &pk).unwrap()
}
}

impl Verifiable for VerifiableUpdateLeafNode {
Expand Down Expand Up @@ -849,6 +883,18 @@ impl VerifiableCommitLeafNode {
pub(crate) fn signature_key(&self) -> &SignaturePublicKey {
&self.payload.signature_key
}

pub fn standalone_validate(
self,
crypto: &impl OpenMlsCrypto,
signature_scheme: SignatureScheme,
) -> LeafNode {
let pk = self
.signature_key()
.clone()
.into_signature_public_key_enriched(signature_scheme);
self.verify::<LeafNode>(crypto, &pk).unwrap()
}
}

impl Verifiable for VerifiableCommitLeafNode {
Expand Down
Loading