Java SSL Context initialization without a truststore?

274 Views Asked by At

Is there a way to initialize ssl context in java without a trust store?

private static SSLContext getSSLContext(
    final KeyManager[] keyManagers, final TrustManager[] trustManagers)
    throws KeyManagementException, NoSuchAlgorithmException {
  final SSLContext sslContext = SSLContext.getInstance("TLS");
  sslContext.init(keyManagers, trustManagers, new SecureRandom());

  return sslContext;
}

I want the above code to not throw a null pointer exception when TrustManager[] is null or empty, as my application does not require a trust store in certain cases, in those cases I dont want to add a trust store.

I tried looking for an overloaded sslContext.init() where it does not ask for a trust manager as a parameter, but I did not find any.

0

There are 0 best solutions below