user373201
user373201

Reputation: 11425

java ssl connection using truststore

I have a web application that connects to a https site. For that I have to install the certificate in the cacerts in lib/security folder. I would like to create a truststore and place it within the application and while connecting to the other site make the app refer to this truststore so that when the application is moved the certificates move with it.

The way I connect to the https site is using a form post. How do I go about doing this. Also, when doing a form post rather than using a HttpsURLConnection, how to configure to look into custom truststore instead of cacerts.

Upvotes: 2

Views: 2442

Answers (2)

queeg
queeg

Reputation: 9372

While the link in the other answer is a good reference, it refers to the already outdated JDK 1.5. Here is something more up to date, and the documentation has been improved as well:

https://docs.oracle.com/en/java/javase/18/security/java-secure-socket-extension-jsse-reference-guide.html#GUID-E1205974-3249-4E40-83C0-5F89C7375CF4

Upvotes: 0

GeertPt
GeertPt

Reputation: 17846

The easiest way is to set a system property when launching the java process: -Djavax.net.ssl.trustStore=...

This is used by the default TrustManager, as described in http://docs.oracle.com/javase/1.5.0/docs/guide/security/jsse/JSSERefGuide.html#X509TrustManager

Alternatively, override the TrustManager as described in the next paragraph in the same document.

Upvotes: 2

Related Questions