Skip to content

Accept the manifest of a re-signed provider jar - #2137

Merged
Mikola Lysenko (mikolalysenko) merged 14 commits into
mainfrom
fix/jvm-resigned-provider-manifest
Nov 19, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 14 commits into
mainfrom
fix/jvm-resigned-provider-manifest

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #2132. Lets agent mode and vendored mode accept a signed jar that the patch service patched and signed again, and nothing else that touches the manifest.

Why

A signed jar's META-INF/MANIFEST.MF holds a section per entry with that entry's digests, and the signature files vouch for the manifest. A JVM that requires a valid signature, as it does for a JCE provider such as Bouncy Castle's bcprov, refuses the jar once a class changes. So the patch service signs a patched provider again, as a whole, the way jarsigner does: upstream's signature files go, META-INF/SOCKET.SF and SOCKET.RSA are added, and every file entry is listed in the manifest under the signing digest. A current JDK ignores SHA-1 digests, so a manifest that holds only those gains a SHA-256 line in every section, and an entry upstream never listed gains a section of its own.

Signature files were already outside the "everything else is the original's" comparison. The manifest was not, so the agent swap refused such a jar with jvm_agent_service_jar_mismatch and vendoring with vendor_prebuilt_integrity_mismatch.

The rule

The served jar must carry a signature file, and its manifest may differ from the installed (agent) or upstream (vendored) manifest only as follows:

  1. The main-attributes section is byte for byte the same.
  2. The section of a member the record does not touch keeps every line, byte for byte and in order. It may gain digest attributes, each recomputed from that member in the served jar.
  3. The section of a member the record changes may also change the values of its digest attributes. Every digest in it is recomputed from the served member, and no other attribute may change.
  4. A section is added only for a member the record adds or changes, or for an entry both jars hold with identical bytes that the original manifest did not list. It holds a Name and verified digests alone.
  5. No section is removed.

A digest attribute is one the JDK reads when it verifies a jar: SHA-256-Digest, SHA-384-Digest, SHA-512-Digest, SHA1-Digest, SHA-1-Digest, MD5-Digest. They are matched without regard to case. An added or changed attribute of any other name is a refusal. Anything else is the existing coded refusal; for a signed jar the reason is appended, and an unsigned jar whose manifest differs keeps the plain wrong-base message.

The manifest is parsed as the JAR specification lays it out, and sections are compared as the byte ranges in the file. Blank lines are not compared, so a terminator added before appended sections changes nothing; a last line of the original with no terminator, which a JVM ignores, is dropped before the comparison. Members are matched by the raw bytes of their names. The manifest has no size limit of its own below the jar limits, and a jar past a limit while it is read is jvm_jar_too_large or vendor_artifact_too_large, never a mismatch. The signature itself is not verified; that stays the JVM's job.

One function (difference_outside_patch) backs the agent swap, the vendored comparison, and the rollback's search for the original of a patched copy.

One thing goes past the five points as first written: a new section is also accepted for a member the record changes, not only for one it adds. The service's output needs it: in its unlisted fixture the changed class had no section upstream and gets one.

Limitation

A jar whose patch record itself lists META-INF/MANIFEST.MF is refused for now when the service signed it again. The manifest is then a member the record changes, held to its afterHash, and the signed manifest is that blob with its digests completed, not the blob. Accepting it needs the record's blob wherever a member is held to its afterHash, and rollback, vex and the vendored check do not have it at hand. It is a follow-up; CLI_CONTRACT.md states the limitation.

Review findings

All ten were confirmed. Nine are fixed; one is fixed in part.

  1. Member lookup by decoded name. Fixed: members are found by the raw bytes of their names (a_member_is_found_by_the_raw_bytes_of_its_name, a_member_with_a_non_ascii_name_and_no_utf8_flag_is_verified).
  2. Hidden manifest cap and too-large reported as a mismatch. Fixed both (a_large_manifest_is_read_and_a_limit_is_a_limit).
  3. SHA-256 recomputed. Fixed: the known digest is used (a_sha256_digest_is_checked_without_inflating_the_member_again).
  4. MD5 from f64::sin. Fixed: a constant table, fed block by block, checked against the RFC 1321 suite including the 62- and 80-character vectors and members of several blocks (member_digests_are_the_algorithms_a_manifest_names). No MD5 crate was in the lockfile, so none was added.
  5. Docs contradicting the rule. Fixed in all three places.
  6. Section removal for a deleted member. Unreachable in the vendored path too: the download check requires every record member at its afterHash. The branch, its test and the contract sentence are removed.
  7. Unused record-manifest baseline. Removed, with its test; see Limitation (a_record_that_lists_the_manifest_is_not_accepted_yet).
  8. Jars opened and sections parsed more than once. Fixed. No test: the behaviour is unchanged.
  9. Re-signing named for unsigned jars. Fixed (signing_is_named_only_for_a_signed_jar).
  10. Case-sensitive attribute match. Fixed (a_digest_attribute_is_matched_whatever_its_case).

Review findings not fixed

  • Digest algorithms beyond SHA-1, SHA-256, SHA-384, SHA-512 and MD5 (finding 10, second half). The JDK also reads SHA-224-Digest and the SHA-3 ones. An added or changed attribute of that kind stays a refusal: it fails closed, and the service writes none of them.

Exit status

Case Before After
Agent apply of a re-signed provider jar exit 1, jvm_agent_service_jar_mismatch exit 0
Vendoring a re-signed provider jar refused, vendor_prebuilt_integrity_mismatch exit 0
Any other manifest change refused refused, same codes, with the reason

CLI_CONTRACT.md states the rule under agent mode and points to it from the vendored JVM section.

Tests

The fixtures under crates/socket-patch-core/tests/data/resigned-provider/service/ are the patch service's own output for five upstream shapes, upstream and served jar for each (4 to 6 KB). The jarsigner pair from the first commit stays as the one-digest-changed case.

  • Accepted: one digest value changed (sha256); a SHA-256 line inserted in every section of a SHA-1-only manifest (sha1-only); sections appended for entries upstream never listed (unlisted); an unterminated last line dropped and a section appended for an added member (unterminated-line); \n line endings; a non-ASCII member name without the UTF-8 flag; a 17 MiB manifest; a digest attribute in another case.
  • Refused, each with its reason: an inserted digest that is not the member's; an inserted non-digest attribute on an untouched section; an inserted SHA-224-Digest; an appended section for an entry that is not in the installed jar or the record; a changed existing line on an untouched section; a non-digest attribute or a stale digest on the changed member; a main attribute changed; a dropped section; an unsigned jar; a record that does not change the member.
  • The agent swap and its rollback, and the vendored comparison, over the jarsigner pair.

I also ran the rule by hand over the service's re-signed bcprov-jdk15on-1.47 (SHA-1 only, 1,718 sections gain a SHA-256 line) and bcprov-jdk18on-1.78. Both are accepted, and both are refused without the record, naming the changed class.

Results on macOS (arm64), after merging the base branch, which now includes main and vendors a jar without the upstream registry:

  • Jar, manifest, vendor and local-repository tests (patch::jar_manifest, patch::jar_members, patch::jvm_jar, vendor::maven_repo, vendor::jvm, vendor::verify, vendor::redownload, crawlers::maven): 597 pass.
  • cargo clippy --locked --workspace --all-features -- -D warnings and cargo fmt --all -- --check: clean.
  • Run on the base branch at the commit merged here: cargo test -p socket-patch-core --tests (8,692 pass), the touched CLI suites (89 pass), the real-Maven vendored suite (6 pass) and the production legs (hosted, vendored and agent pass, Java 26 only).
  • Not run at this head: the full socket-patch-core --tests, the CLI suites, cargo check --all-targets, the real-Maven suites, the production legs, and anything on Linux or Windows.

The vendored comparison is now with the jar in the build's local repository, where there is one, not with a jar downloaded from the registry; the manifest rule applies to that comparison unchanged.

For the owner

  • The manifest-in-record case is a follow-up (see Limitation).
  • Twelve small binary jars are committed as fixtures (about 55 KB in all). The repository had no binary fixtures before.

Generated by Claude Code

…ream

Agent mode and vendored mode read jars through the zip reader written for
Python wheels: 10,000 entries and 64 MiB inflated at most, regular-file
entries only, both jars held whole in memory. Released jars are past
those caps (hive-exec-3.1.3: 23,728 entries, 93 MiB), so agent mode
refused them as "the patch service's jar is unreadable", and a vendored
one could not be attested, re-vendored online or repaired.

Jars now have their own reader (patch/jar_members): member by member,
hashing as it inflates, bounded by what is actually inflated and by the
archive's own entry count rather than by declared sizes. The limits are
200,000 entries, and per pass 1 GiB inflated and 100 times the jar's
size (64 MiB for a small jar). A jar past one is jvm_jar_too_large
(agent) or vendor_artifact_too_large (vendored), and the message names
the limit.

The comparison of a patched jar with the original covers every entry the
JVM would load, whatever unix mode it carries: an entry with a symlink's
mode bits was skipped, so a class added that way went unseen. Directory
entries and signature files stay exempt.

A first vendoring makes that comparison too, against the registry-verified
upstream jar and before anything is written. It used to run only on an
online re-run over a committed tree, so a service jar built from another
base was committed and wired.

A copy that differs outside the patch now fails with
jvm_agent_service_jar_mismatch, naming the members; the per-copy error
carried no code.

A ~/.m2 jar that another project (or an earlier workspace over a cached
repository) patched has no backup in this project. Its rollback now
restores the registry's jar when the download matches the registry's
checksum and is the jar the copy was patched from, and otherwise says
what happened and how to recover, as does an apply over a copy that
holds another revision of the patch.

-Dmaven.repo.local in the project's .mvn/maven.config names the local
repository, between the command line (MAVEN_ARGS) and MAVEN_OPTS, as in
Maven 3.6.3, 3.8.9, 3.9.16 and 4.0.0-rc-7.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Read `.mvn/maven.config` only for a Maven build, and as its Maven reads
it. A Gradle or Scala-tool build's mavenLocal() never reads the file, so
such a project keeps the environment's repository. Maven before 3.9
splits the file on whitespace and interpolates nothing; 3.9 and later
take a line as one argument. The Maven Wrapper says which applies;
without one the reading whose directory exists is used, and when both
exist no repository is guessed at (maven_local_repository_undetermined).
An empty value and an undefined placeholder resolve as Maven resolves
them, instead of falling through to the settings.

A first vendoring no longer fails when the registry cannot be reached
while the patch service can. The baseline is the registry-verified jar,
else the local repository's jar, else none; the last two are reported
(vendor_jvm_upstream_unverified). A mismatch is still a refusal.

A rollback reads the copy before it looks for a backup or downloads
anything: a `~/.m2` copy past the jar limits fails as that, not as a
missing backup, and a Gradle copy's backup is found by its hash
directory without reading the copy. The copy is hashed once.

The central directory is bounded by what the archive's end records
declare, before the zip reader parses it: 200,000 entries, 64 MiB.

Also: the Gradle classifier check fails closed on a jar it cannot read;
`vendor --check` names the limit a jar is past; the digest passes run on
the blocking pool and identical copies are read once; a copy's refusal
code travels beside its result instead of being parsed out of the text.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A signed jar's manifest holds each entry's digests, and its signature
files vouch for the manifest. Patching a class of a signed security
provider therefore means re-signing the jar: the patch service drops
upstream's signature files, adds its own, and gives the manifest
sections of the patched members new digests. The agent swap and the
vendored comparison refused that jar, since META-INF/MANIFEST.MF is a
member outside the patch that changed.

The manifest may now differ in exactly that way and no other: the jar
is signed, the main attributes are byte for byte the original's, every
section of a member the record does not touch is present and identical,
a changed member's section differs only in its <ALG>-Digest values and
each digest is the digest of that member in the patched jar, and a
section is added or removed only with a member the record adds or
deletes. Anything else stays the coded refusal, now with the reason.
A rollback finds the original of a re-signed copy by the same rule.

The manifest is parsed as the JAR specification lays it out and its
sections are compared as the bytes in the file. The tests use a jar
signed by jarsigner and the same jar patched and signed again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The patch service's signer now signs a patched provider as a whole, as
jarsigner does, because a current JDK ignores SHA-1 digests: a jar whose
manifest held only those left one signed class among unsigned siblings.
Untouched sections therefore gain a digest line for the signing digest,
and an entry upstream never listed gains a section. The rule required
untouched sections to be byte-identical, so it refused those jars.

An untouched member's section now keeps every line, byte for byte and in
order, and may gain digest attributes, each recomputed from the member
in the patched jar. A changed member's section may also change its
digest values. A section is added only for a member the record adds or
changes, or for an entry both jars hold with the same bytes; it is
removed only for a member the record deletes. Only the digest attributes
the JDK reads count (SHA-256, SHA-384, SHA-512, SHA-1, MD5). A last line
of the original with no terminator is dropped before the comparison.

The fixtures are the service's own output for five upstream shapes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
apply_jar_swap and rollback_jar_swap verified a copy's patched members
through the zip reader directly, before the bounded reader saw the jar:
the central directory was parsed, and allocated for, whatever the end
records declared, and a member was inflated with no budget. A copy past
the limits, or one with a hostile end record, could exhaust memory there
instead of failing as jvm_jar_too_large, and a ~/.m2 rollback could go
on to the registry afterwards.

The member check now goes through the bounded reader, so the limits on
the entry count and the central directory are held to the end records
before anything parses the directory, and members are inflated within
the pass's budget. A copy past a limit is refused there: jvm_jar_too_large
on apply, with the run warning, and on rollback, before any backup is
read or anything is downloaded. The unbounded member hasher has no
caller left and is removed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ovider-manifest

# Conflicts:
#	crates/socket-patch-core/src/patch/jvm_jar.rs
Look a member up by the raw bytes of its name. The zip reader's own
lookup is by a name it decodes as CP437 when an entry lacks the UTF-8
flag, so a UTF-8 name written without it was missed and a valid jar
refused as holding a section for a member it does not hold.

Read the manifest within the jar limits alone: the 16 MiB cap of its
own was below them. A jar past a limit while the manifest is read is
the caller's too-large refusal, not a difference.

Replace the MD5 that computed its constants with f64::sin and held the
whole member: a constant table, fed block by block, checked against the
RFC 1321 vectors.

Take a member's SHA-256 from the digests the comparison already holds
instead of inflating it again, open each jar once and parse each section
once.

Match a changed digest line without regard to the case of its name.
Name signing in a refusal only when the patched jar is signed: an
unsigned jar whose manifest differs is the ordinary wrong-base case.

Remove what no caller reaches: a section dropped with a member the
record deletes (every path requires a record member at its afterHash),
and the baseline taken from a record that lists the manifest. Such a
jar is refused for now, and the contract says so. The docs state the
rule as implemented.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 18, 2026 22:50
@cursor

cursor Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes JVM jar integrity checks used in agent apply and vendoring; the rule is tightly scoped to re-signing-shaped manifest diffs but is security-adjacent for signed providers.

Overview
Patches re-signed JVM provider jars (e.g. Bouncy Castle) so agent swap, Maven vendoring, and rollback no longer treat legitimate post-signing META-INF/MANIFEST.MF changes as integrity failures.

A new jar_manifest module defines when a signed served jar’s manifest may differ from upstream—main section unchanged, digest lines added or updated only for patched or newly listed entries, with digest values verified against jar members. difference_outside_patch in jar_members applies that rule on top of the existing member-by-member comparison and is wired into agent apply, vendored upstream checks, and original-jar detection.

Jar lookup and hashing are extended so members match JVM raw entry names, manifest digests (including MD5) can be checked without extra full inflates, and oversized jars surface as too-large errors rather than mismatches. CLI contract and ecosystem docs document the rule; patches that list MANIFEST.MF in the record are still refused.

Reviewed by Cursor Bugbot for commit 6ea9c11. Configure here.

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 18, 2026
@mikolalysenko

Mikola Lysenko (mikolalysenko) commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. Agent mode and vendored mode now accept a provider jar (such as bcprov) that the patch service patched and signed again. Its manifest may differ from the original only by digest lines, each recomputed from the served member, and by sections for members the record adds or changes. Any other manifest change is still refused with the existing codes, and the refusal now gives the reason. One function backs the agent swap, the vendored check and the rollback.

Risk: medium. It relaxes an integrity check, but the relaxation is narrow and fails closed. I probed it with CR-only line endings, duplicate sections, re-wrapped lines, case tricks, extra sections for entries outside the record, and a changed main section. Every probe was refused. It doesn't verify the signature itself; that stays the JVM's job.

Stacked: the base is fix/jvm-jar-limits-and-checks (#2132), which now has its own brief and only needs an approval. This should land after #2132. I left auto-merge off, because an approval would otherwise squash it into #2132's branch rather than main.

Look here

Verified

  • cargo check -p socket-patch-core --tests passes.
  • cargo test -p socket-patch-core jar_: 44 passed. The patch::jvm_jar, vendor::maven_repo and patch::jar_ lib tests: 106 passed.
  • cargo test -p socket-patch-cli --test gradle_agent_cli --test vendor_jvm_cli: 37 + 37 passed.
  • cargo fmt --all -- --check is clean. I used stable Rust locally because the pinned toolchain failed to install.
  • MD5 matches the RFC 1321 vectors and a 1,000,000-byte known value. MD5 and SHA-1 of a 1,000,003-byte member match Python's hashlib.
  • Every committed fixture jar passes jarsigner -verify except sha1-only.upstream.jar, which the JDK treats as unsigned by design.
  • CHANGELOG.md is untouched.
  • CI on 6ea9c117: ci-ok and clippy are green, along with all 81 checks.

Changes I made: none.

Open questions

  1. Should the original also have to be signed? resigned checks only that the served jar carries a signature file. A probe was accepted: an unsigned upstream whose manifest has only a main section, served with per-entry digest sections and a signature. A jar that was unsigned would then arrive signed. If another jar on the classpath shares one of its packages, the JVM throws "signer information does not match" and the user's build breaks. The service only re-signs jars that were signed, so this can't happen today. Requiring a signature file in the original as well would be a small, fail-closed fix.
  2. Minor: the large-member MD5 test compares against md5(&long) itself rather than a known value (jar_members.rs). The known value is 061e54a2c394516de5111bc20625f03c for "1234567890"×100000.
  3. Minor: in rollback, is_original_of (jvm_jar.rs:886) turns a jar-limit error into "not the original" with .is_ok_and. Only the error message is affected.
  4. Docs nuance: the parser accepts a 17 MiB manifest, but a real JVM refuses manifest lines past about 512 bytes. The "accepted" in the description is about the parser.

Updated 2026-11-19: the head moved to a291ffd by merges from #2132 only (one conflict in the vendoring comparison and its contract text, resolved to keep both #2132's local-jar comparison and this PR's re-signed manifest rule). CI is green on a291ffd.


Generated by Claude Code

The check before the parse read the last 64 KiB of the file and the
56 bytes at the zip64 locator's offset. The zip reader does not take
the end record from there: it looks for one backwards through the whole
file, finds a zip64 record forwards from where the locator points, and
falls back to an earlier end record when a directory does not parse.
With bytes appended after the end record, an archive of 200,001 entries
passed the check and was parsed whole before the count refused it.

The check now walks as the reader does. It finds the last end record
the reader can take and holds it to the limits. The reader is then
shown zeros below that record's central directory while it opens the
archive, so the only records it can fall back to are in the directory
itself, and each of those is held to the limits as well. A record the
reader would pass over is passed over; after 64 of them the archive is
given up, since each costs a search of the file.

An end record in a member's data, as a jar stored inside a fat jar has,
is below the outer directory: the reader cannot take it, so it is not
looked at, whatever it declares.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ovider-manifest

# Conflicts:
#	crates/socket-patch-core/src/patch/jar_members.rs

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[agent] Reviewed at 080e243. The relaxation is narrow and fails closed: member-by-member comparison still runs first, only META-INF/MANIFEST.MF can be lifted out of the changed set, only for a served jar carrying a signature file, with the main section byte-identical and every added or changed digest recomputed from the served member; dropped or duplicate sections, unknown digest algorithms and bad base64 are refused. Non-blocking: resigned does not require the original to be signed, so an unsigned upstream served with a signature would be accepted (no tamper path, but a possible signer mismatch at runtime). Lands after #2132.

Vendoring a Maven or Gradle patch downloaded the original jar from the
registry to compare the patch service's jar with, and refused or warned
when it could not. It does not need the registry for that: the service's
jar is checked as it was served (transfer integrity, the record's
members at their afterHash) and committed.

One comparison stays, since it costs no network and protects the build.
When the original jar is already in the build's local repository, the
members the patch does not touch must be that jar's, as agent mode
requires before a swap. A difference means the project builds with a jar
that is not the one the patch was made from, and the refusal says so.
With no local copy nothing is compared and nothing is said.

An online re-run over a committed tree makes the same local comparison
and no longer needs the registry for the jar. Upstream metadata (pom,
parents, module metadata, classifier jars) is read as before.

Document that a project's .mvn/maven.config chooses where apply,
rollback and remove write, what they do there, and that
MAVEN_REPO_LOCAL takes the choice back.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ovider-manifest

# Conflicts:
#	crates/socket-patch-cli/CLI_CONTRACT.md
#	crates/socket-patch-core/src/vendor/maven_repo.rs
…d-checks

main moved wrapper_maven_version into formats::maven::declared_maven and
added shared answers to which Maven a project declares and how a
maven.config line is read. The local repository lookup now uses them:
DeclaredMaven (the wrapper's release, or a root pom only Maven 4 reads)
decides how .mvn/maven.config is read, maven_config_line_properties is
the reading for Maven 3.9 and later, and RootDirectory says which root
directory property the declared Maven fills in. The whitespace reading
of Maven before 3.9 and the choice between the two readings stay here.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Base automatically changed from fix/jvm-jar-limits-and-checks to main November 19, 2026 20:40
The base PR (#2132) was squash-merged into main, so the branch's copy of
its commits conflicted with the squash. Resolved by a three-way merge
over the base PR's last head, so the result carries main plus exactly
this PR's own changes.

Assisted-by: Claude Code:claude-opus-5-5
Merged via the queue into main with commit 43d1d64 Nov 19, 2026
50 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the fix/jvm-resigned-provider-manifest branch November 19, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants