MCPcopy Create free account
hub / github.com/modelcontextprotocol/mcpb / signMcpbFile

Function signMcpbFile

src/node/sign.ts:26–95  ·  view source on GitHub ↗
(
  mcpbPath: string,
  certPath: string,
  keyPath: string,
  intermediates?: string[],
)

Source from the content-addressed store, hash-verified

24 * @param intermediates Optional array of intermediate certificate paths
25 */
26export function signMcpbFile(
27 mcpbPath: string,
28 certPath: string,
29 keyPath: string,
30 intermediates?: string[],
31): void {
32 // Read the original MCPB file
33 const mcpbContent = readFileSync(mcpbPath);
34
35 // Read certificate and key
36 const certificatePem = readFileSync(certPath, "utf-8");
37 const privateKeyPem = readFileSync(keyPath, "utf-8");
38
39 // Read intermediate certificates if provided
40 const intermediatePems = intermediates?.map((path) =>
41 readFileSync(path, "utf-8"),
42 );
43
44 // Create PKCS#7 signed data
45 const p7 = forge.pkcs7.createSignedData();
46 p7.content = forge.util.createBuffer(mcpbContent);
47
48 // Parse and add certificates
49 const signingCert = forge.pki.certificateFromPem(certificatePem);
50 const privateKey = forge.pki.privateKeyFromPem(privateKeyPem);
51
52 p7.addCertificate(signingCert);
53
54 // Add intermediate certificates
55 if (intermediatePems) {
56 for (const pem of intermediatePems) {
57 p7.addCertificate(forge.pki.certificateFromPem(pem));
58 }
59 }
60
61 // Add signer
62 p7.addSigner({
63 key: privateKey,
64 certificate: signingCert,
65 digestAlgorithm: forge.pki.oids.sha256,
66 authenticatedAttributes: [
67 {
68 type: forge.pki.oids.contentType,
69 value: forge.pki.oids.data,
70 },
71 {
72 type: forge.pki.oids.messageDigest,
73 // Value will be auto-populated
74 },
75 {
76 type: forge.pki.oids.signingTime,
77 // Value will be auto-populated with current time
78 },
79 ],
80 });
81
82 // Sign with detached signature
83 p7.sign({ detached: true });

Callers 5

testSelfSignedSigningFunction · 0.85
testCASignedSigningFunction · 0.85
testTamperingDetectionFunction · 0.85
testSignatureRemovalFunction · 0.85
cli.tsFile · 0.85

Calls 1

createSignatureBlockFunction · 0.85

Tested by 4

testSelfSignedSigningFunction · 0.68
testCASignedSigningFunction · 0.68
testTamperingDetectionFunction · 0.68
testSignatureRemovalFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…