Fenrir fixes#237
Open
cconlon wants to merge 13 commits into
Open
Conversation
581cd03 to
cd39f6c
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses a batch of Fenrir findings by hardening crypto behavior (key validation, padding/unwrapping uniformity, nonce/IV reuse rejection), and improving thread-safety in JNI callbacks, with new/updated unit tests to cover the fixes.
Changes:
- Add DH/ECC peer public key validation in key agreement and DH public-key range checks on import paths.
- Enforce uniform failure behavior for PKCS#7 unpadding and RSA PKCS#1 v1.5 unwrap, and reject AES-GCM/AES-GMAC nonce reuse for encryption/MAC operations.
- Fix JNI thread-safety issues around verify/FIPS callbacks and strengthen certpath disabled-algorithm parsing + OCSP revoked handling (plus tests).
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/java/com/wolfssl/wolfcrypt/test/WolfSSLCertManagerVerifyCallbackTest.java | Adds concurrency-focused tests for CertManager verify callback registration/clearing. |
| src/test/java/com/wolfssl/wolfcrypt/test/WolfCryptTestSuite.java | Registers the new CertManager verify-callback test in the suite. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptUtilTest.java | Adds regression coverage for qualified jdk.certpath.disabledAlgorithms entries. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptPKIXRevocationCheckerTest.java | Adds test ensuring OCSP revoked hard-fails even under SOFT_FAIL. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptMacTest.java | Updates GMAC reset behavior test and adds IV-reuse rejection coverage. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptKeyAgreementTest.java | Adds negative tests for DH/ECDH invalid peer public key rejection. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptDHKeyFactoryTest.java | Adds tests for DH public-key range validation in X.509 and DHPublicKeySpec paths. |
| src/test/java/com/wolfssl/provider/jce/test/WolfCryptCipherTest.java | Adds tests for RSA unwrap uniform failures, CBC padding message uniformity, and GCM nonce-reuse rejection. |
| src/main/java/com/wolfssl/wolfcrypt/Dh.java | Adds checkPublicKey() wrapper over native wc_DhCheckPubKey(). |
| src/main/java/com/wolfssl/wolfcrypt/Curve25519.java | Adjusts release locking to avoid split-lock race during native free. |
| src/main/java/com/wolfssl/wolfcrypt/BlockCipher.java | Implements constant-time PKCS#7 unpadding with uniform error behavior. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptUtil.java | Improves parsing/matching of qualified disabled-algorithm entries; ignores keySize constraints here. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptPKIXRevocationChecker.java | Treats OCSP revoked as a hard failure with BasicReason.REVOKED regardless of SOFT_FAIL. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptMac.java | Rejects AES-GMAC operations that would reuse key+IV without re-init. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptKeyAgreement.java | Validates DH/ECC peer public keys before use in engineDoPhase(). |
| src/main/java/com/wolfssl/provider/jce/WolfCryptDHPublicKey.java | Adds DH public-key Y range validation during X.509 parsing. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptDHKeyFactory.java | Adds DH public-key Y range validation for DHPublicKeySpec generation. |
| src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java | Adds AES-GCM nonce reuse rejection; makes unwrap/padding failures less distinguishable. |
| jni/jni_wolfssl_cert_manager.c | Fixes verify-callback use-after-free by taking a local ref under mutex. |
| jni/jni_native_struct.c | Initializes FIPS callback mutex during JNI_OnLoad. |
| jni/jni_fips.c | Adds mutex-protected storage/use of FIPS error callback global ref. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cd39f6c to
cd2cd90
Compare
cd2cd90 to
fee50d8
Compare
Member
Author
|
Retest this please Jenkins |
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 resolves a batch of 13 findings from Fenrir. Changes are hardening, input validation, consistency, and thread-safety improvements. No public API changes.
Changes
Public key validation on key agreement and import
WolfCryptKeyAgreement.engineDoPhase()WolfCryptKeyAgreement.engineDoPhase()1 < Y < p-1range on DH public key in the KeyFactory import path1 < Y < p-1range on DH public key in the X.509 import pathConsistent exception and unpadding behavior
BadPaddingExceptionKey and IV reuse handling
WolfCryptCipherWolfCryptMacThread-safety and object lifecycle
CertManagernativeVerifyCallbackjni_fips.cCertificate path and revocation handling
jdk.certpath.disabledAlgorithmsentries by algorithm name