I work on webApi base on spring boot 2.0.3, and already enable ssl with self-signed certificates through application.properties, I add a new feature to validate local CRL and customized trustManager, but spring boot doesn't pick the code.
could you help to figure out where the problem is? if someone could show how to check local CRL file, that's also helpful.
config properties like this.
application.properties:
server.ssl.key-alias=server
server.ssl.key-password=123456
server.ssl.key-store=classpath:serverStore.keystore
server.ssl.key-store-type=jks
server.ssl.client-auth=NEED
server.ssl.trust-store= classpath:trustStore.keystore
server.ssl.trust-store-password=123456
server.ssl.trust-store-type=jks
inject customized trust manager like this:
@Configuration
public class CRLChecker {
@PostConstruct
public void check() throws Exception{
TrustManagerFactory tmf = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
// Initialise the TMF as you normally would, for example:
tmf.init((KeyStore)null);
TrustManager[] trustManagers = tmf.getTrustManagers();
final X509TrustManager origTrustmanager = (X509TrustManager)trustManagers[0];
TrustManager[] wrappedTrustManagers = new TrustManager[] {
new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return origTrustmanager.getAcceptedIssuers();
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
origTrustmanager.checkClientTrusted(certs, authType);
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
//add more my logical code to validate CRL
origTrustmanager.checkServerTrusted(certs, authType);
}
}
};
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, wrappedTrustManagers, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
}