feat: add prepare-for-signing and apply-signature for enterprise HSM signing#222
Open
bryan-anthropic wants to merge 1 commit intomainfrom
Open
feat: add prepare-for-signing and apply-signature for enterprise HSM signing#222bryan-anthropic wants to merge 1 commit intomainfrom
bryan-anthropic wants to merge 1 commit intomainfrom
Conversation
…rise HSM signing Enterprise signers (GaraSign, ESRP, SignServer, Venafi) produce MCPB bundles that Claude Desktop rejects because they append PKCS#7 signatures after the ZIP EOCD without updating comment_length. This adds a two-step workflow that pre-allocates the EOCD comment space before signing, so the delivered file is byte-identical to what was signed: 1. mcpb prepare-for-signing <bundle> — sets EOCD comment_length to 16384 2. Enterprise signer signs the prepared file (detached PKCS#7) 3. mcpb apply-signature <bundle> --signature <sig.p7s> — embeds signature Based on Microsoft's Azure MCP Server production pipeline (eng/scripts/Stage-McpbForSigning.ps1 + Apply-McpbSignatures.ps1) which has been shipping signed bundles successfully since beta.22. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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 at claude.ai/admin-settings/claude-code.
Once credits are available, reopen this pull request to trigger a review.
This was referenced Mar 27, 2026
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.
Summary
Enterprise HSM signers (GaraSign, ESRP, SignServer, Venafi) produce MCPB bundles that Claude Desktop rejects. The root cause: external signers append PKCS#7 signatures after the ZIP EOCD without updating
comment_length, causingadm-zipto reject the file with "Invalid comment length."This PR adds two new CLI commands that implement a pre-signing preparation workflow — the signer operates on content that already has the correct EOCD metadata, so no post-signing fixup is needed:
Supersedes #220. Complementary to #195 — once that verify fix merges,
mcpb verifywill validate bundles produced by this workflow with no additional changes needed (the signature covers content with the correctcomment_length, so no EOCD reversal is required).Why this works
The key insight is when the EOCD is modified relative to signing:
comment_length=0fix-signature(#220)comment_length=0comment_length=16384Reference implementation
This generalizes the pattern that Microsoft's Azure MCP Server team already ships in production:
eng/scripts/Stage-McpbForSigning.ps1→mcpb prepare-for-signingeng/scripts/Apply-McpbSignatures.ps1→mcpb apply-signatureMicrosoft's signed Azure MCP bundles (beta.22 through beta.33) have been installing successfully in Claude Desktop using this exact pattern. Our output is byte-for-byte format-compatible with theirs (16384-byte padded signature block,
MCPB_SIG_V1/MCPB_SIG_ENDmarkers, zero-padded DER PKCS#7).What's included
src/node/sign.ts:prepareForExternalSigning()— sets EOCDcomment_lengthto 16384, validates not already signed/preparedapplyExternalSignature()— embeds detached PKCS#7 into pre-allocated slot with zero-paddingMAX_SIG_BLOCK_SIZEconstant (16384, matching Microsoft's pipeline)src/cli/cli.ts:mcpb prepare-for-signing <file>— with-o/--outputoptionmcpb apply-signature <file> -s <sig.p7s>— with-o/--outputoptiontest/sign.e2e.test.ts:Test results
Test plan
npm test)prepare-for-signingsets EOCD comment_length to 16384apply-signatureproduces valid ZIP (Pythonzipfileaccepts)file_size == eocd_offset + 22 + comment_length(adm-zip check)🤖 Generated with Claude Code
/cc @asklar @vcolin7 — this generalizes the signing pattern from your Azure MCP Server pipeline (
eng/scripts/Stage-McpbForSigning.ps1+Apply-McpbSignatures.ps1) into the CLI. Would appreciate your review since your bundles are the reference implementation.