Skip to content

Commit 0265a61

Browse files
authored
Merge pull request #190 from cconlon/certPathBuilder
Add JCE PKIX CertPathBuilder implementation
2 parents dcdcc1e + 6da2c37 commit 0265a61

20 files changed

Lines changed: 6342 additions & 9 deletions

IDE/Android/app/src/main/cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ add_library(wolfcryptjni SHARED
373373
${wolfcryptjni_DIR}/jni/jni_wolfcrypt.c
374374
${wolfcryptjni_DIR}/jni/jni_wolfobject.c
375375
${wolfcryptjni_DIR}/jni/jni_wolfssl_cert_manager.c
376+
${wolfcryptjni_DIR}/jni/jni_wolfssl_x509_store_ctx.c
376377
)
377378

378379
# set_target_properties(wolfcryptjni PROPERTIES LIBRARY_OUTPUT_DIRECTORY

IDE/WIN/wolfcryptjni.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<ClCompile Include="..\..\jni\jni_wolfcrypt.c" />
105105
<ClCompile Include="..\..\jni\jni_wolfobject.c" />
106106
<ClCompile Include="..\..\jni\jni_wolfssl_cert_manager.c" />
107+
<ClCompile Include="..\..\jni\jni_wolfssl_x509_store_ctx.c" />
107108
</ItemGroup>
108109
<PropertyGroup Label="Globals">
109110
<VCProjectVersion>16.0</VCProjectVersion>

IDE/WIN/wolfcryptjni.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@
215215
<ClCompile Include="..\..\jni\jni_wolfssl_cert_manager.c">
216216
<Filter>Source Files</Filter>
217217
</ClCompile>
218+
<ClCompile Include="..\..\jni\jni_wolfssl_x509_store_ctx.c">
219+
<Filter>Source Files</Filter>
220+
</ClCompile>
218221
<ClCompile Include="..\..\jni\jni_jce_wolfsslkeystore.c">
219222
<Filter>Source Files</Filter>
220223
</ClCompile>

README_JCE.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ The JCE provider currently supports the following algorithms:
239239
CertPathValidator Class
240240
PKIX (with PKIXRevocationChecker via getRevocationChecker())
241241

242+
CertPathBuilder Class
243+
PKIX
244+
242245
SecretKeyFactory
243246
PBKDF2WithHmacSHA1
244247
PBKDF2WithHmacSHA224
@@ -563,6 +566,77 @@ Applications should use TrustAnchors without explicit name constraints; if
563566
name constraint enforcement is needed, the constraints should be embedded in
564567
the trust anchor certificate itself.
565568

569+
### CertPathBuilder (PKIX) Implementation Notes
570+
---------
571+
572+
wolfJCE provides a PKIX CertPathBuilder implementation that builds and
573+
validates certificate chains using native wolfSSL's
574+
`wolfSSL_X509_verify_cert()` function.
575+
576+
#### Native Chain Building with Backtracking
577+
578+
The CertPathBuilder uses native wolfSSL `X509_STORE` APIs for certificate chain
579+
building. This provides automatic backtracking when a candidate issuer fails
580+
verification. wolfSSL will try alternative issuers until a valid path is found
581+
or all possibilities are exhausted.
582+
583+
#### Usage Example
584+
585+
```java
586+
/* Load certificates */
587+
X509Certificate targetCert = ...;
588+
X509Certificate intermediateCert = ...;
589+
X509Certificate rootCACert = ...;
590+
591+
/* Set up trust anchors */
592+
Set<TrustAnchor> anchors = new HashSet<>();
593+
anchors.add(new TrustAnchor(rootCACert, null));
594+
595+
/* Set up CertStore with available certificates */
596+
Collection<Certificate> certs = new ArrayList<>();
597+
certs.add(targetCert);
598+
certs.add(intermediateCert);
599+
CertStore certStore = CertStore.getInstance("Collection",
600+
new CollectionCertStoreParameters(certs));
601+
602+
/* Configure parameters */
603+
X509CertSelector selector = new X509CertSelector();
604+
selector.setCertificate(targetCert);
605+
PKIXBuilderParameters params = new PKIXBuilderParameters(anchors, selector);
606+
params.setRevocationEnabled(false);
607+
params.addCertStore(certStore);
608+
609+
/* Build certificate path */
610+
CertPathBuilder cpb = CertPathBuilder.getInstance("PKIX", "wolfJCE");
611+
PKIXCertPathBuilderResult result = (PKIXCertPathBuilderResult) cpb.build(params);
612+
613+
CertPath certPath = result.getCertPath();
614+
TrustAnchor trustAnchor = result.getTrustAnchor();
615+
```
616+
617+
#### Supported Features
618+
619+
- RSA and ECC certificate chains
620+
- Multiple intermediate certificates
621+
- Multiple trust anchors (correct one selected automatically)
622+
- Multiple CertStores
623+
- `maxPathLength` constraint enforcement
624+
- Target certificate selection by certificate or subject name
625+
- Target certificate as trust anchor (returns empty path)
626+
627+
#### Limitations
628+
629+
- **Date Override**: `PKIXBuilderParameters.setDate()` is not passed to native
630+
wolfSSL verification. Certificates are validated against current system time.
631+
- **TrustAnchor Name Constraints**: Name constraints on TrustAnchors are not
632+
supported. An `InvalidAlgorithmParameterException` is thrown if any
633+
TrustAnchor has name constraints set.
634+
- **Policy Processing**: Certificate policy processing is not supported.
635+
`PKIXCertPathBuilderResult.getPolicyTree()` returns null.
636+
- **Revocation Checking**: Revocation checking during path building is not
637+
currently integrated. Use `CertPathValidator` with `PKIXRevocationChecker`
638+
for revocation checking after path building.
639+
566640
### Behavior Discrepancies with SunJCE
567641
---------
568642

0 commit comments

Comments
 (0)