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

refactor merkle tree inclusion proof verification #579

Merged
merged 2 commits into from
Jun 30, 2023

Conversation

bdehamer
Copy link
Collaborator

@bdehamer bdehamer commented Jun 30, 2023

Summary

Clean-up the merkle tree inclusion proof verification logic (see sigstore/protobuf-specs#82) . This was originally implemented before the Sigstore bundle format was even defined and was never integrated into the verification workflow. The change here refactors the merkle verification logic into a form that can be applied to the TransparenclyLogEntrys found in the bundle.

This logic is still NOT integrated into the verification workflow (which is why I'm not adding a changeset entry with this PR) but does prepare us for adding this in the future.

@bdehamer bdehamer requested a review from a team as a code owner June 30, 2023 00:49
@changeset-bot
Copy link

changeset-bot bot commented Jun 30, 2023

🦋 Changeset detected

Latest commit: 434f533

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

);

// Calculated hash should match the root hash in the inclusion proof
return calculatedHash.equals(inclusionProof.rootHash);
Copy link
Member

Choose a reason for hiding this comment

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

Poking around with copilot.. it's suggesting we rewrite this as a constant time comparison function to prevent timing attacks :)

googling around, looks like there's a function in node to do this but throws on mismatch so we could wrap it like:

const { timingSafeEqual } = require('crypto');

const compare = (a, b) => {
    try {
        return timingSafeEqual(a, b);
    } catch {
        return false;
    }
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a nice find! I suspect that this is being used internally as part of the crypto signature verification logic, but I'm wondering if there are other places where I should employ this 🤔

Copy link
Member

Choose a reason for hiding this comment

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

being used internally as part of the crypto signature verification logic

Yeah would hope so!

Maybe worth a quick audit to see if we do any manual comparisons?

Signed-off-by: Brian DeHamer <bdehamer@github.com>
@bdehamer bdehamer force-pushed the bdehamer/merkle-inclusion branch from b23451c to 710ac53 Compare June 30, 2023 14:24
@bdehamer bdehamer requested a review from feelepxyz June 30, 2023 14:25
@bdehamer bdehamer merged commit 369a519 into main Jun 30, 2023
@bdehamer bdehamer deleted the bdehamer/merkle-inclusion branch June 30, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants