JNI/JSSE: fix certificate order of array returned from WolfSSLX509StoreCtx.getCerts()#282
Merged
rlm2002 merged 1 commit intowolfSSL:masterfrom Jul 31, 2025
Merged
Conversation
… cert first, then rest of chain
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the certificate order returned by WolfSSLX509StoreCtx.getCerts() to match Java/JSSE expectations. The native wolfSSL returns certificates in root-to-peer order, but JSSE requires peer-to-root order for proper hostname verification and trust manager operations.
- Reverses certificate array order in native C code to return peer certificate first
- Updates documentation to clarify the expected certificate ordering
- Fixes hostname verification failures that occurred due to incorrect certificate chain ordering
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/java/com/wolfssl/provider/jsse/WolfSSLInternalVerifyCb.java |
Updates comment to clarify expected certificate ordering from getCerts() |
src/java/com/wolfssl/WolfSSLX509StoreCtx.java |
Adds documentation explaining the peer-to-root certificate ordering |
native/com_wolfssl_WolfSSLX509StoreCtx.c |
Implements array index reversal to return certificates in peer-to-root order |
rlm2002
approved these changes
Jul 31, 2025
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 the
WolfSSLX509StoreCtx.freeCerts()method to correctly return the certificate chain with peer cert first, followed by the rest of the chain.Native wolfSSL
wolfSSL_X509_STORE_GetCerts()returns certs in order of root to peer, but JSSE layer expects peer to root for internal verify callback and X509TrustManager.checkClient/ServerTrusted().This showed up in a test against
httpbin.org:443, where the reversed certificate order caused hostname verification to fail:This can be tested using the example JSSE client against httpbin.org. This fails before this PR, and passes with it: