fix: implement PKCS#7 signature verification using Node.js crypto#212
Open
bryan-anthropic wants to merge 1 commit intomainfrom
Open
fix: implement PKCS#7 signature verification using Node.js crypto#212bryan-anthropic wants to merge 1 commit intomainfrom
bryan-anthropic wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.
Once credits are available, reopen this pull request to trigger a review.
node-forge's pkcs7.verify() is not implemented and always throws, causing mcpb verify and mcpb info to report all signed bundles as unsigned. Replace with a custom verification function that: 1. Parses the PKCS#7 ASN.1 structure with node-forge 2. Verifies the messageDigest attribute matches the content hash using Node.js crypto.createHash() 3. Verifies the RSA signature over the authenticated attributes using Node.js crypto.createVerify(), per RFC 5652 Section 5.4 Also handles the EOCD comment_length update from the signing flow: the signer modifies the ZIP EOCD after signing, so the verifier restores the original content before checking the signature. Self-signed certificates now return "self-signed" status without attempting OS chain verification (which would always fail for them). Fixes #21 Co-authored-by: vcolin7 <victor.y.asi@gmail.com>
564621d to
85a0260
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21
Related: #71
Summary
node-forge'spkcs7.verify()is not implemented and always throws, causingmcpb verifyandmcpb infoto report all signed bundles as unsigned — regardless of whether they were signed with a local key or via PKCS#11.This PR replaces the broken verification with a custom
verifyPkcs7DetachedSignature()function that:node-forge(for structure traversal only)messageDigestauthenticated attribute matches the content hash using Node.jscrypto.createHash()crypto.createVerify(), per RFC 5652 Section 5.4Additionally:
"self-signed"status directly, without attempting OS chain verification (which would always fail for them)comment_lengthupdate introduced in fix: update ZIP EOCD comment_length when signing #204 — the signer modifies the ZIP EOCD after computing the signature, so the verifier restores the original content before checkingThe verification handles both bundles signed with
mcpb signand bundles signed externally (e.g., via PKCS#11/HSM pipelines), as the function operates on standard PKCS#7/CMS structures.Attribution
This is based on @vcolin7's work in #195, rebased onto current
main(post-#204 merge) with the EOCD compatibility fix added. Thank you @vcolin7 for the thorough implementation and RFC 5652 research.How Has This Been Tested?
pack→sign→verify→infoall work correctlyBefore / After
Before:
After: