[GH-ISSUE #6574] [Bug] PE certificate inspection calls valid BER SignedData malformed #3962

Closed
opened 2026-10-31 00:45:37 +00:00 by bsakaguchi · 0 comments
Owner

Originally created by @coygeek on GitHub (Oct 23, 2026).
Original GitHub issue: https://github.com/morluto/rea/issues/6574

Before submitting

  • I searched the open and closed issues for a related report.
  • I removed credentials, tokens, private paths, and sensitive target data.

Area

Native analysis or decompilation

Observed behavior

Source-only finding; runtime reproduction NOT RUN. inspect_pe_certificates classifies a structurally valid PKCS#7 SignedData ContentInfo with an indefinite-length outer SEQUENCE as invalid input. Its source-derived diagnostic is PKCS#7 signedData is malformed: Unsupported DER length form. No certificate-table inventory is returned, even though only the outer BER length encoding differs from an otherwise supported payload.

Reproduction

Actually performed: source inspection, format-reference review, and open/closed issue searches. No fixture, provider, CLI, or MCP runtime was run.

Proposed public replay, unexecuted:

  1. Obtain the repository's pkcs7SignedDataFixture() payload. Preserve its ContentInfo children exactly; replace only the outer SEQUENCE's definite length with 0x80 and append the end-of-contents bytes 00 00. This is 30 80 || original SEQUENCE content || 00 00; do not retain the original outer length bytes.
  2. Pass that payload to peCertificateFixture(false, payload, 2), which updates WIN_CERTIFICATE length, alignment, and the PE security directory. Save the returned regular-file bytes as /artifacts/ber-example.exe.
  3. Request MCP inspect_pe_certificates with {"path":"/artifacts/ber-example.exe"}. Source predicts an input-format failure before the first certificate entry is retained. The original definite-length fixture is the proposed control.

Frequency: NOT_ENOUGH_INFO; no runtime reproduction was performed.

Expected behavior

Decode the same structural SignedData and X.509 facts for these equivalent outer encodings, preserving each selected artifact's own bytes, ranges, and digest. Alternatively, an intentionally DER-only profile should identify a valid but unsupported encoding rather than call the PKCS#7 malformed and should disclose that restriction.

RFC 5652 section 2 permits indefinite-length BER for ContentInfo/SignedData and reserves DER requirements for signed/authenticated attributes. The proposed change affects only the outer ContentInfo SEQUENCE; certificate and signer contents remain unchanged. REA's documented structural inspection contract does not exclude this length form. Windows trust acceptance is not claimed or required by this static structural check.

Impact and scope

A valid BER envelope prevents the entire requested table and certificate inventory from being returned. This is a bounded format-compatibility and diagnostic defect; target bytes are not changed. Source reach includes PE32 and PE32+ type-2 WIN_CERTIFICATE payloads routed to the same parser. Real artifact prevalence and Windows trust behavior are NOT_ENOUGH_INFO. No practical same-artifact REA workaround was demonstrated.

REA version

Source package 6.7.0, main revision 46111dd091f2ae01baab9eb119b53b9bd309a05b; latest npm release supplied for the investigation: 6.7.0.

Runtime and platform

Source-only inspection; no provider runtime run. Linux workspace; Node.js was not invoked. Windows, CLR, Hopper, and Ghidra execution: NOT RUN.

Target and artifact context

A PE32 or PE32+ image with one type-2 WIN_CERTIFICATE containing a structurally supported SignedData payload. Only the outer ContentInfo SEQUENCE uses BER indefinite length; existing X.509 and SignerInfo fields retain their original definite encodings. The proposed fixture is inert structural test data, not a cryptographically valid Authenticode signature.

Interface

MCP

Earliest failure stage

Native analysis or reconstruction

Relevant output or evidence

All failure output below is source-derived, not captured runtime output.

Evidence provenance: source-derived. Local verification: NOT RUN. Reproduction completeness: concrete public trigger and source trace; runtime output and real-world prevalence unavailable.

Typed outcome or recovery expected

Return structural certificate Evidence for the valid envelope, or accurately identify an unsupported BER encoding with a precise declared limitation. Increasing the file or entry budget cannot change this rejection.

Analysis or suspected cause

Source-derived: one parser named readDer handles the complete PKCS#7 envelope and treats an encoding outside definite-length DER as malformed, although ContentInfo/SignedData permits BER. The wrapper then converts that rejection into a file-format error. This is independent of signature validation or trust policy.

Additional context

Deduplication searched supplied open issue/PR titles for PKCS, BER, DER, indefinite, certificate, Teletex, and T61. No related title was present. Closed-issue searches for "indefinite" and "PKCS" found no corresponding certificate report; the indefinite search's unrelated doctor-cancellation result was excluded by subject. No regression interval or introducing revision was established.

Triage assessment

  • Impact level: P2
  • Assessment status: provisional
  • Impact basis: Source shows that a valid alternate outer encoding loses the entire requested static table/certificate inventory and receives an invalid-format diagnosis. Runtime reproduction and real artifact frequency were not measured.
  • Workaround status: unverified
  • Workaround basis: Re-encoding a copy would change the selected artifact and digest; no demonstrated REA workflow preserves the original artifact identity while recovering these structural facts.
Originally created by @coygeek on GitHub (Oct 23, 2026). Original GitHub issue: https://github.com/morluto/rea/issues/6574 ### Before submitting - [x] I searched the open and closed issues for a related report. - [x] I removed credentials, tokens, private paths, and sensitive target data. ### Area Native analysis or decompilation ### Observed behavior Source-only finding; runtime reproduction **NOT RUN**. `inspect_pe_certificates` classifies a structurally valid PKCS#7 SignedData ContentInfo with an indefinite-length outer SEQUENCE as invalid input. Its source-derived diagnostic is `PKCS#7 signedData is malformed: Unsupported DER length form.` No certificate-table inventory is returned, even though only the outer BER length encoding differs from an otherwise supported payload. ### Reproduction Actually performed: source inspection, format-reference review, and open/closed issue searches. No fixture, provider, CLI, or MCP runtime was run. Proposed public replay, **unexecuted**: 1. Obtain the repository's `pkcs7SignedDataFixture()` payload. Preserve its ContentInfo children exactly; replace only the outer SEQUENCE's definite length with `0x80` and append the end-of-contents bytes `00 00`. This is `30 80 || original SEQUENCE content || 00 00`; do not retain the original outer length bytes. 2. Pass that payload to `peCertificateFixture(false, payload, 2)`, which updates WIN_CERTIFICATE length, alignment, and the PE security directory. Save the returned regular-file bytes as `/artifacts/ber-example.exe`. 3. Request MCP `inspect_pe_certificates` with `{"path":"/artifacts/ber-example.exe"}`. Source predicts an input-format failure before the first certificate entry is retained. The original definite-length fixture is the proposed control. Frequency: NOT_ENOUGH_INFO; no runtime reproduction was performed. ### Expected behavior Decode the same structural SignedData and X.509 facts for these equivalent outer encodings, preserving each selected artifact's own bytes, ranges, and digest. Alternatively, an intentionally DER-only profile should identify a valid but unsupported encoding rather than call the PKCS#7 malformed and should disclose that restriction. [RFC 5652 section 2](https://www.rfc-editor.org/rfc/rfc5652.html#section-2) permits indefinite-length BER for ContentInfo/SignedData and reserves DER requirements for signed/authenticated attributes. The proposed change affects only the outer ContentInfo SEQUENCE; certificate and signer contents remain unchanged. REA's [documented structural inspection contract](https://github.com/morluto/rea/blob/46111dd091f2ae01baab9eb119b53b9bd309a05b/docs/pe-certificates.md#L28-L53) does not exclude this length form. Windows trust acceptance is not claimed or required by this static structural check. ### Impact and scope A valid BER envelope prevents the entire requested table and certificate inventory from being returned. This is a bounded format-compatibility and diagnostic defect; target bytes are not changed. Source reach includes PE32 and PE32+ type-2 WIN_CERTIFICATE payloads routed to the same parser. Real artifact prevalence and Windows trust behavior are NOT_ENOUGH_INFO. No practical same-artifact REA workaround was demonstrated. ### REA version Source package 6.7.0, main revision `46111dd091f2ae01baab9eb119b53b9bd309a05b`; latest npm release supplied for the investigation: 6.7.0. ### Runtime and platform Source-only inspection; no provider runtime run. Linux workspace; Node.js was not invoked. Windows, CLR, Hopper, and Ghidra execution: NOT RUN. ### Target and artifact context A PE32 or PE32+ image with one type-2 WIN_CERTIFICATE containing a structurally supported SignedData payload. Only the outer ContentInfo SEQUENCE uses BER indefinite length; existing X.509 and SignerInfo fields retain their original definite encodings. The proposed fixture is inert structural test data, not a cryptographically valid Authenticode signature. ### Interface MCP ### Earliest failure stage Native analysis or reconstruction ### Relevant output or evidence All failure output below is source-derived, not captured runtime output. - [The public tool contract](https://github.com/morluto/rea/blob/46111dd091f2ae01baab9eb119b53b9bd309a05b/src/contracts/native/binaryDiagnosticsToolContracts.ts#L92-L98) advertises structural PKCS#7 SignedData inspection. [The provider](https://github.com/morluto/rea/blob/46111dd091f2ae01baab9eb119b53b9bd309a05b/src/native/pe/PeCertificatesProvider.ts#L57-L80) passes stable file bytes to the parser. - [Type-2 dispatch](https://github.com/morluto/rea/blob/46111dd091f2ae01baab9eb119b53b9bd309a05b/src/native/pe/PeCertificateParser.ts#L110-L115) calls `parsePkcs7SignedData`; [that function](https://github.com/morluto/rea/blob/46111dd091f2ae01baab9eb119b53b9bd309a05b/src/native/pe/PeCertificateDer.ts#L598-L617) starts with `readDer(bytes)`. - [The length reader](https://github.com/morluto/rea/blob/46111dd091f2ae01baab9eb119b53b9bd309a05b/src/native/pe/PeCertificateDer.ts#L68-L88) computes `width = 0x80 & 0x7f`, then rejects width zero as `Unsupported DER length form.` It never examines the preserved ContentInfo children. - [The enclosing catch](https://github.com/morluto/rea/blob/46111dd091f2ae01baab9eb119b53b9bd309a05b/src/native/pe/PeCertificateParser.ts#L160-L164) labels every `PeCertificateDerFailure` as malformed PKCS#7. [The provider error mapping](https://github.com/morluto/rea/blob/46111dd091f2ae01baab9eb119b53b9bd309a05b/src/native/pe/PeCertificatesProvider.ts#L137-L144) returns an input issue with reason `invalid_format`. - [The fixture producers](https://github.com/morluto/rea/blob/46111dd091f2ae01baab9eb119b53b9bd309a05b/src/native/pe/PeCertificates.fixture.ts#L72-L141) supply the concrete reduced-input recipe above. Evidence provenance: source-derived. Local verification: NOT RUN. Reproduction completeness: concrete public trigger and source trace; runtime output and real-world prevalence unavailable. ### Typed outcome or recovery expected Return structural certificate Evidence for the valid envelope, or accurately identify an unsupported BER encoding with a precise declared limitation. Increasing the file or entry budget cannot change this rejection. ### Analysis or suspected cause Source-derived: one parser named `readDer` handles the complete PKCS#7 envelope and treats an encoding outside definite-length DER as malformed, although ContentInfo/SignedData permits BER. The wrapper then converts that rejection into a file-format error. This is independent of signature validation or trust policy. ### Additional context Deduplication searched supplied open issue/PR titles for PKCS, BER, DER, indefinite, certificate, Teletex, and T61. No related title was present. Closed-issue searches for `"indefinite"` and `"PKCS"` found no corresponding certificate report; the indefinite search's unrelated doctor-cancellation result was excluded by subject. No regression interval or introducing revision was established. ## Triage assessment - Impact level: P2 - Assessment status: provisional - Impact basis: Source shows that a valid alternate outer encoding loses the entire requested static table/certificate inventory and receives an invalid-format diagnosis. Runtime reproduction and real artifact frequency were not measured. - Workaround status: unverified - Workaround basis: Re-encoding a copy would change the selected artifact and digest; no demonstrated REA workflow preserves the original artifact identity while recovering these structural facts.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
morluto/rea#3962
No description provided.