Replies: 2 comments 2 replies
-
Hi Julien, This is an interesting usecase. I think it can be made possible to work in your situation with the current version however the setup would be slightly different. You already mentioned that recreating the OS and JDK trustmaterial is waste of resources as it needs to be recreated, but that can be cached and you don't need to recreate it actually. But I will give you an example.
Yes, it will be ignored as the underlying utility will skip empty trustmanagers. A workaround for that kind of use case would be having an initial trustmanager with a dummy certificate, but I can also provide an alternative for your use casse.
Yess, this is also valid. Although it is not a performance hit it is a waste of resources. So coming back to provide a solution for you, I might be able to add this special type of Trustmanager to the library. That will save you the verbosity. An alternative if you just want to proceed on your side without waiting on the changes of the library would be something like this, beaware it will be more low-level coding. Optional<X509ExtendedTrustManager> systemTrustManager = TrustManagerUtils.createTrustManagerWithSystemTrustedCertificates();
X509ExtendedTrustManager jdKTrustManager = TrustManagerUtils.createTrustManagerWithJdkTrustedCertificates();
X509TrustManager confirmingTrustManager = new X509TrustManager() {
// your custom logic
};
X509ExtendedTrustManager combinedTrustManager = TrustManagerUtils.combine(systemTrustManager.get(), jdKTrustManager, confirmingTrustManager);
SSLFactory sslFactory = SSLFactory.builder()
.withTrustMaterial(combinedTrustManager)
.build(); In the above example you don't need the swappable option as you have your own trustmanager which is able to include new trusted certificates on the fly. Can you give it a try on your side? I will also check wether I can implement a way to provide a similar behaviour as what Intellij does.. Update I added a basic mechanism within an inflatable trustmanager which has the capability of trusting additional single or more certificates on the fly. I only need to create an abstract layer within SSLFactory and TrustManagerUtils. Please have a look at it, I would love to get your feedback on it. Basically it can look like this: SSLFactory sslFactory = SSLFactory.builder()
.withDefaultTrustMaterial()
.withSystemTrustMaterial()
.withInflatableTrustMaterial()
.build();
// After some point in time
List<X509Certificate> certificates = ...; // List containing your additional newly trusted certificates
TrustManagerUtils.addCertificate(sslFactory.getTrustManager().get(), certificates); |
Beta Was this translation helpful? Give feedback.
-
This option is now available in the latest version, so I am closing this discussion. If anyone else is founding out this discussion, the documentation of the usage can be found here: Trust additional new certificates at runtime |
Beta Was this translation helpful? Give feedback.
-
Hi,
First of all thanks for this library, this looks really useful.
We have started using it, and trying to implement the following use case: we want our (Apache) Http client to trust JDK and OS certificates by default. Then if a request is made on a server having an untrusted certificate, then we want to interactively prompt the user if the certificate should be trusted. If the user says yes, then we want to proceed with the request, and that all other requests to the same server work. We will also save the certificate in our application truststore, to not ask again the next time.
My source of inspiration is the ConfirmingTrustManager from the IntelliJ Platform.
We were trying to do something like:
We faced the following problems:
getAcceptedIssuers
. This was really difficult to debug, and we ended up returning a fake one.Is there a better way to handle this use case?
Beta Was this translation helpful? Give feedback.
All reactions