Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(pe): reject unsupported certificate name encodings
morluto055d1a9e1bd9
diff --git a/docs/pe-certificates.md b/docs/pe-certificates.mdindex 2d542567b..5f10522d2 100644--- a/docs/pe-certificates.md+++ b/docs/pe-certificates.md@@ -48,7 +48,9 @@ fails the same way. SignedData must contain at least one `SignerInfo`, andeach `SignerInfo` must carry a non-empty signature value. Each embedded X.509certificate must include `subjectPublicKeyInfo` and `signatureValue`. Decodedcertificate name text, serials, validity spellings, and subject key identifiers-share a 64 KiB budget per PKCS#7 payload.+share a 64 KiB budget per PKCS#7 payload. Unsupported certificate name+encodings, including TeletexString (T.61) and GeneralString, fail explicitly+rather than returning names decoded with an assumed character set.This workflow does not verify signatures, certificate chains, timestamps, orAuthenticode digest coverage of image bytes.diff --git a/src/native/pe/PeCertificateDer.ts b/src/native/pe/PeCertificateDer.tsindex 6a31522a8..8d903a3da 100644--- a/src/native/pe/PeCertificateDer.ts+++ b/src/native/pe/PeCertificateDer.ts@@ -222,11 +222,11 @@ const decodeDirectoryString = (case 0x16:case 0x17:case 0x18:- case 0x1b:return decodeUtf8(node.content, budget);default:- chargeDecodedName(budget, node.content.length);- return node.content.toString("latin1");+ return fail(+ `Unsupported certificate name encoding (DER tag 0x${node.tag.toString(16).padStart(2, "0")}).`,+ );}};diff --git a/src/native/pe/PeCertificateParser.test.ts b/src/native/pe/PeCertificateParser.test.tsindex 12f15ca62..8fd6e8188 100644--- a/src/native/pe/PeCertificateParser.test.ts+++ b/src/native/pe/PeCertificateParser.test.ts@@ -445,6 +445,27 @@ it("rejects a UTF8String name that is not valid UTF-8", () => {).toBe("commonName=é");});+it.each([+ ["TeletexString", 0x14, Buffer.from([0xc2, 0x65])],+ ["GeneralString", 0x1b, Buffer.from("name")],+ ["OCTET STRING", 0x04, Buffer.from("name")],+] as const)(+ "rejects unsupported %s certificate names",+ (_encoding, tag, bytes) => {+ const certificate = readDer(+ namedCertificate(+ directoryName(der(0x0c, Buffer.from("Issuer"))),+ directoryName(der(tag, bytes)),+ ),+ );+ expect(() => parseCertificate(certificate)).toThrow(+ new PeCertificateDerFailure(+ `Unsupported certificate name encoding (DER tag 0x${tag.toString(16).padStart(2, "0")}).`,+ ),+ );+ },+);+it("decodes BMPString names once and shares the decoded-byte budget", () => {const bmp = (text: string) => {const content = Buffer.alloc(text.length * 2);diff --git a/tests/acceptance/peCertificatesCli.test.ts b/tests/acceptance/peCertificatesCli.test.tsindex 0a20398c4..6525ff3ba 100644--- a/tests/acceptance/peCertificatesCli.test.ts+++ b/tests/acceptance/peCertificatesCli.test.ts@@ -5,6 +5,7 @@ import { toolContract } from "../../src/contracts/toolContracts.js";import {peCertificateFixture,peWithoutCertificateTableFixture,+ pkcs7SignedDataFixture,} from "../../src/native/pe/PeCertificates.fixture.js";import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";import { cliTest } from "../support/cli/cliFixture.js";@@ -62,3 +63,34 @@ cliTest("reports a truncated PE as invalid input", async ({ cli }) => {details: { operation: "inspect_pe_certificates" },});});++cliTest(+ "rejects TeletexString names without returning corrupted identity text",+ async ({ cli }) => {+ const root = await createTestTempDirectory("rea-pe-cert-cli-teletex-");+ const path = join(root, "teletex.exe");+ const payload = pkcs7SignedDataFixture("é");+ const nameAt = payload.indexOf(Buffer.from([0x0c, 0x02, 0xc3, 0xa9]));+ expect(nameAt).toBeGreaterThanOrEqual(0);+ // Replace an equal-length UTF8String with T.61's acute accent plus 'e'.+ Buffer.from([0x14, 0x02, 0xc2, 0x65]).copy(payload, nameAt);+ await writeFile(path, peCertificateFixture(false, payload));+ const result = await cli.run({+ arguments: ["inspect-pe-certificates", path, "--json"],+ });+ expect(result.exitCode).toBe(1);+ expect(result.json).toMatchObject({+ code: "invalid_request",+ details: {+ operation: "inspect_pe_certificates",+ issues: [+ {+ message: expect.stringContaining(+ "Unsupported certificate name encoding (DER tag 0x14)",+ ),+ },+ ],+ },+ });+ },+);