Skip to content

Make wolfJCE and filtered provider services read-only after construction - #306

Merged
JacobBarthelmeh merged 1 commit into
wolfSSL:masterfrom
cconlon:lockProviderServices
Nov 14, 2026
Merged

JacobBarthelmeh merged 1 commit into
wolfSSL:masterfrom
cconlon:lockProviderServices

Conversation

@cconlon

@cconlon cconlon commented Nov 11, 2026

Copy link
Copy Markdown
Member

WolfCryptProvider and the filtered providers (FilteredSun, FilteredSunEC, FilteredSunRsaSign, via a new ReadOnlyProvider base class) now reject every Provider/Properties method that adds, changes or removes a service after construction, with SecurityException. This stops application code from registering a non-wolfCrypt implementation under the wolfJCE/filtered provider name, for example put("MessageDigest.MD5", "sun.security.provider.MD5"). Before JDK 24, the Security Manager blocked this.

  • refreshServices() now only re-applies the wolfjce.mapJKStoWKS / wolfjce.mapPKCS12toWKS KeyStore mappings, and never unlocks the provider.
  • readResolve() returns the registered provider (or a new one), so a deserialized provider never takes its services from the serialized stream.
  • Tests: new WolfCryptProviderTest, plus additions to FilteredProviderNegativeTest.
  • Docs: README_JCE.md and the filtered-providers README.
  • Build: ReadOnlyProvider.java added to scripts/infer.sh and to the filtered-providers.yml jar-content checks.

Tested with ant test on JDK 8, 11, 17 and 24.

@cconlon cconlon self-assigned this Nov 11, 2026
@cconlon
cconlon requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 11, 2026 22:13
@cconlon

cconlon commented Nov 11, 2026

Copy link
Copy Markdown
Member Author

@claude review

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #306

Scan targets checked: wolfcrypt-jni-src, wolfcrypt-jni-bugs
Not reviewed (no scan target covers them): .github/workflows/filtered-providers.yml, README_JCE.md, examples/filtered-providers/README.md, examples/filtered-providers/src/com/wolfssl/security/providers/FilteredSun.java, examples/filtered-providers/src/com/wolfssl/security/providers/FilteredSunEC.java, examples/filtered-providers/src/com/wolfssl/security/providers/FilteredSunRsaSign.java, examples/filtered-providers/src/com/wolfssl/security/providers/ReadOnlyProvider.java, scripts/infer.sh
Coverage: 2 of 4 in-scope changed file(s) opened by the reviewer; not opened: src/test/java/com/wolfssl/provider/jce/test/WolfCryptProviderTest.java, src/test/java/com/wolfssl/provider/jce/test/WolfJCETestSuite.java

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Critical deserialization and construction-time cloning flaws expose provider instances that can serve stream-supplied implementations or accept service registrations despite intended protections.

2 open issues
What changed in this PR

This PR hardens wolfJCE and the filtered Sun providers against runtime service replacement, keeping service registration under provider control.

Changes:

  • Rejects service mutations after construction and limits refreshServices() to the JKS/PKCS12-to-WKS mappings.
  • Adds deserialization replacement logic and tests for mutation, cloning, serialization, and refresh behavior.
  • Documents read-only services and updates static-analysis and packaging checks.
File Description
src/​test/​java/​com/​wolfssl/​security/​providers/​test/​FilteredProviderNegativeTest.java Adds filtered-provider mutation and serialization tests.
src/​test/​java/​com/​wolfssl/​provider/​jce/​test/​WolfJCETestSuite.java Registers the new provider test class.
src/​test/​java/​com/​wolfssl/​provider/​jce/​test/​WolfCryptProviderTest.java Tests wolfJCE service locking, serialization, and refresh.
src/​main/​java/​com/​wolfssl/​provider/​jce/​WolfCryptProvider.java Adds service locking, deserialization replacement, and mapping-only refresh.
scripts/​infer.sh Includes ReadOnlyProvider in static analysis.
README_JCE.md Documents wolfJCE’s read-only service behavior.
examples/​filtered-providers/​src/​com/​wolfssl/​security/​providers/​ReadOnlyProvider.java Introduces shared mutation guards and deserialization handling.
examples/​filtered-providers/​src/​com/​wolfssl/​security/​providers/​FilteredSunRsaSign.java Adopts the read-only base and locks services after registration.
examples/​filtered-providers/​src/​com/​wolfssl/​security/​providers/​FilteredSunEC.java Adopts the read-only base and locks services after registration.
examples/​filtered-providers/​src/​com/​wolfssl/​security/​providers/​FilteredSun.java Adopts the read-only base and locks services after registration.
examples/​filtered-providers/​README.md Documents filtered-provider mutation restrictions.
.github/​workflows/​filtered-providers.yml Adds JAR-content checks for ReadOnlyProvider.

Review effort: Balanced

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I reviewed this PR and didn't find any bugs. It changes how the wolfJCE crypto provider's service registration can be changed and adds a new base class for the filtered providers, so a human look is still worthwhile.

What was reviewed:

  • The overrides in WolfCryptProvider: put/putAll/putIfAbsent/remove/replace/replaceAll/compute*/merge/clear, setProperty, the load methods, putService and removeService. Every one checks servicesLocked.
  • refreshServices(). It now only re-applies the JKS/PKCS12 to WKS mappings through super.put/super.remove, so it never turns the lock off.
  • Deserialization. readObject locks the services after the default read, and readResolve returns the registered provider or a new one, so services never come from the serialized stream.
  • Tests and Java 8 were not run here. Java 8 compatibility was only checked by reading the code.
Extended reasoning...

The change is about 1.3k lines across the main WolfCryptProvider class, a new ReadOnlyProvider base class for the filtered providers, and large new test classes. It touches security-sensitive surface: the goal is to stop application code from registering a non-wolfCrypt implementation under the wolfJCE or filtered provider name. It also changes how refreshServices() and deserialization behave. Because it is crypto-provider and security code of this size, a human should review it before merge, even though no defects were found.

@cconlon
cconlon force-pushed the lockProviderServices branch 4 times, most recently from 93ef12c to 68fb272 Compare November 11, 2026 23:57
@cconlon
cconlon requested a balanced review from Copilot November 11, 2026 23:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

With mapping properties enabled, refreshServices() can grant KeyStore services to an unconstructed deserialized provider, bypassing its intended permanent deserialization lock.

2 open issues
2 resolved since last review

Review effort: Balanced

@cconlon
cconlon force-pushed the lockProviderServices branch from 68fb272 to 016ca80 Compare November 12, 2026 00:16
@cconlon cconlon assigned rlm2002 and wolfSSL-Bot and unassigned cconlon Nov 12, 2026
@JacobBarthelmeh

Copy link
Copy Markdown
Contributor

@cconlon looks good. Please resolve the merge conflict.

@JacobBarthelmeh
JacobBarthelmeh merged commit 95230c4 into wolfSSL:master Nov 14, 2026
189 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants