Pin JCE KeyFactory lookups to wolfJCE and accept opaque CRT-encoded RSA keys#215
Open
cconlon wants to merge 1 commit into
Open
Pin JCE KeyFactory lookups to wolfJCE and accept opaque CRT-encoded RSA keys#215cconlon wants to merge 1 commit into
cconlon wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
Pins several internal KeyFactory.getInstance(...) lookups to the wolfJCE provider to avoid degraded key material when other JCE providers have higher priority, and relaxes RSA signing initialization to accept non-RSAPrivateCrtKey inputs when the PKCS#8 encoding still contains CRT components.
Changes:
- Pin RSA/EC/DH
KeyFactoryusage inWolfCryptKeyPairGeneratorand RSA/EC inWolfSSLKeyStoreto"wolfJCE"to avoid higher-priority provider interference. - Update
WolfCryptSignature.engineInitSign()to attempt native import for non-CRT-typed RSA keys and produce clearer CRT-specific failures only when import fails. - Add
MockNonCrtProviderplus new unit tests covering RSA/RSASSA-PSS/EC/DH and keystore/signature behavior under a degraded higher-priority provider.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java | Pins RSA/EC/DH KeyFactory lookups to wolfJCE; adjusts RSASSA-PSS fallback behavior. |
| src/main/java/com/wolfssl/provider/jce/WolfSSLKeyStore.java | Pins RSA/EC key reconstruction KeyFactory lookups to wolfJCE. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptSignature.java | Relaxes RSA initSign acceptance; improves error mapping when native import fails. |
| src/test/java/com/wolfssl/provider/jce/test/MockNonCrtProvider.java | Adds a test-only provider that returns intentionally degraded RSA/EC/DH keys. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptKeyPairGeneratorTest.java | Adds tests verifying generated keys remain usable under a degraded higher-priority provider. |
| src/test/java/com/wolfssl/provider/jce/test/WolfSSLKeyStoreTest.java | Adds tests ensuring WKS load/getKey remains correct under a degraded higher-priority provider. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptSignatureTest.java | Adds tests for accepting opaque/non-CRT-typed RSA keys with CRT-containing encodings and provider-priority scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ped RSA keys with CRT PKCS#8 encodings
b41742c to
582a009
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #215
Scan targets checked: wolfcrypt-jni-bugs, wolfcrypt-jni-src
No new issues found in the changed files. ✅
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes two issues that show up when a non-wolfSSL JCE Provider is registered above wolfJCE in the Provider list and returns RSA/EC/DH keys that wolfCrypt cannot consume directly.
KeyFactory.getInstance("RSA"|"EC"|"DH")lookups inWolfCryptKeyPairGeneratorandWolfSSLKeyStorethrough a newWolfCryptUtil.getKeyFactoryPreferWolfJCE()helper that prefers wolfJCE by name (so generated/loaded keys retain CRT parameters and full encodings regardless of Provider priority order), and falls back to default Provider lookup in builds where wolfJCE does not register that KeyFactory (e.g.KeyFactory.RSAwhen!WOLFSSL_PUBLIC_MP).WolfCryptKeyPairGenerator, only use the PSSKeyFactoryoutput when it preservesRSAPrivateCrtKey, and broaden the fallback to also catchInvalidKeySpecExceptionandClassCastExceptionso a non-wolfSSL PSS factory cannot fail key generation.WolfCryptSignature.engineInitSign()to accept anRSAPrivateKeythat does not implementRSAPrivateCrtKeyas long as its PKCS#8 encoding still contains the CRT components.Additional unit tests are added here to cover these changes, including:
MockNonCrtProvidertest helper and JUnit tests inWolfCryptKeyPairGeneratorTest,WolfSSLKeyStoreTest, andWolfCryptSignatureTestcovering RSA, RSASSA-PSS, EC, and DH paths under a degraded higher-priority Provider.ZD 21784