I am trying to understand what TrustStrategy is to adopt for the method loadTrustMaterial.
public SSLContextBuilder loadTrustMaterial(KeyStore truststore,
TrustStrategy trustStrategy)
throws NoSuchAlgorithmException,
KeyStoreException
I found four different examples and I am very curious to know the difference between these four as the description is too little to understand the differences/usages/advantages/disadvantages.
Here are the four different code examples:
TrustStrategy: This seems like here we are overriding the standard JSSE certificate verification process but it always returning true so does it trust invalid certificates too?
TrustStrategy trustStrategy = new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String authType) throws CertificateException {
return true;
}
};
SSLContextBuilder sslContextBuilder = SSLContexts.custom()
.loadTrustMaterial(trustStore, trustStrategy);
NULL: We are NOT giving any Strategy so what it will do?
SSLContextBuilder sslContextBuilder = SSLContexts.custom()
.loadTrustMaterial(trustStore, null);
TrustAllStrategy: It will trust all singed certificate so is that secure though?
SSLContextBuilder sslContextBuilder = SSLContexts.custom()
.loadTrustMaterial(trustStore, new TrustAllStrategy());
TrustSelfSignedStrategy: What is the difference between this and TrustAllStrategy?
SSLContextBuilder sslContextBuilder = SSLContexts.custom()
.loadTrustMaterial(trustStore, new TrustSelfSignedStrategy());
Help me to understand the difference between these four versions of the example, please? Thanks in Advance.