Repository navigation
Make wolfJCE and filtered provider services read-only after construction - #306
Conversation
|
@claude review |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
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
There was a problem hiding this comment.
🟡 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
There was a problem hiding this comment.
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 throughsuper.put/super.remove, so it never turns the lock off.- Deserialization.
readObjectlocks the services after the default read, andreadResolvereturns 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.
93ef12c to
68fb272
Compare
There was a problem hiding this comment.
🟡 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
68fb272 to
016ca80
Compare
|
@cconlon looks good. Please resolve the merge conflict. |
016ca80 to
9d853c0
Compare


WolfCryptProviderand the filtered providers (FilteredSun,FilteredSunEC,FilteredSunRsaSign, via a newReadOnlyProviderbase class) now reject everyProvider/Propertiesmethod that adds, changes or removes a service after construction, withSecurityException. This stops application code from registering a non-wolfCrypt implementation under the wolfJCE/filtered provider name, for exampleput("MessageDigest.MD5", "sun.security.provider.MD5"). Before JDK 24, the Security Manager blocked this.refreshServices()now only re-applies thewolfjce.mapJKStoWKS/wolfjce.mapPKCS12toWKSKeyStore 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.WolfCryptProviderTest, plus additions toFilteredProviderNegativeTest.README_JCE.mdand the filtered-providers README.ReadOnlyProvider.javaadded toscripts/infer.shand to thefiltered-providers.ymljar-content checks.Tested with
ant teston JDK 8, 11, 17 and 24.