Hakky54 / sslcontext-kickstart

🔐 A lightweight high level library for configuring a http client or server based on SSLContext or other properties such as TrustManager, KeyManager or Trusted Certificates to communicate over SSL TLS for one way authentication or two way authentication provided by the SSLFactory. Support for Java, Scala and Kotlin based clients with examples. Available client examples are: Apache HttpClient, OkHttp, Spring RestTemplate, Spring WebFlux WebClient Jetty and Netty, the old and the new JDK HttpClient, the old and the new Jersey Client, Google HttpClient, Unirest, Retrofit, Feign, Methanol, Vertx, Scala client Finagle, Featherbed, Dispatch Reboot, AsyncHttpClient, Sttp, Akka, Requests Scala, Http4s Blaze, Kotlin client Fuel, http4k Kohttp and Ktor. Also gRPC, WebSocket and ElasticSearch examples are included
https://sslcontext-kickstart.com/
Apache License 2.0
487 stars 76 forks source link

Allow multiple TrustManagers #522

Closed maxxedev closed 2 months ago

Hakky54 commented 2 months ago

Hi @maxxedev I appreciate your PR and I can understand that in your usecase you might need to have a single trustmanagerfactory out of multiple trustmanagers, however I think there is a cleaner way to have this working instead of supporting multiple trustmanagers in a trustmanager factory. I created a specific trustmanager which can manage multiple trustmanagers properly. So I would suggest the following:

import nl.altindag.ssl.util.TrustManagerUtils;

import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509ExtendedTrustManager;
import javax.net.ssl.X509TrustManager;

public class App {

    public static void main(String[] args) {
        X509TrustManager trustManagerOne = null;    //TODO initialize your trustmanager here
        X509TrustManager trustManagerTwo = null;    //TODO initialize your trustmanager here
        X509TrustManager trustManagerThree = null;  //TODO initialize your trustmanager here

        X509ExtendedTrustManager trustManager = TrustManagerUtils.combine(trustManagerOne, trustManagerTwo, trustManagerThree);
        TrustManagerFactory trustManagerFactory = TrustManagerUtils.createTrustManagerFactory(trustManager);
    }

}

The combine method will use these two classes to properly use multiple trustmanagers, see here:

maxxedev commented 2 months ago

Ok. Thanks!