-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #338 from B3Partners/pki-cert-fix
Gebruik default truststore van de JRE
- Loading branch information
Showing
2 changed files
with
99 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
46 changes: 46 additions & 0 deletions
46
brmo-service/src/main/java/nl/b3p/brmo/service/util/TrustManagerDelegate.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2017 B3Partners B.V. | ||
*/ | ||
package nl.b3p.brmo.service.util; | ||
|
||
import javax.net.ssl.X509TrustManager; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.X509Certificate; | ||
|
||
/** | ||
* | ||
* @author mprins | ||
*/ | ||
public class TrustManagerDelegate implements X509TrustManager { | ||
|
||
private final X509TrustManager mainTrustManager; | ||
private final X509TrustManager fallbackTrustManager; | ||
|
||
public TrustManagerDelegate(X509TrustManager mainTrustManager, X509TrustManager fallbackTrustManager) { | ||
this.mainTrustManager = mainTrustManager; | ||
this.fallbackTrustManager = fallbackTrustManager; | ||
} | ||
|
||
@Override | ||
public void checkClientTrusted(final X509Certificate[] x509Certificates, final String authType) throws CertificateException { | ||
try { | ||
mainTrustManager.checkClientTrusted(x509Certificates, authType); | ||
} catch (CertificateException ignored) { | ||
this.fallbackTrustManager.checkClientTrusted(x509Certificates, authType); | ||
} | ||
} | ||
|
||
@Override | ||
public void checkServerTrusted(final X509Certificate[] x509Certificates, final String authType) throws CertificateException { | ||
try { | ||
mainTrustManager.checkServerTrusted(x509Certificates, authType); | ||
} catch (CertificateException ignored) { | ||
this.fallbackTrustManager.checkServerTrusted(x509Certificates, authType); | ||
} | ||
} | ||
|
||
@Override | ||
public X509Certificate[] getAcceptedIssuers() { | ||
return this.fallbackTrustManager.getAcceptedIssuers(); | ||
} | ||
} |