SSL connection from the servlet to the server
Hello,
i want to establish an SSL connection within a servlet (Tomcat) to another JAVA server. The server has integrated the test.jks File as keystore and uses it well. In a small servlet I try an SSL connection to that server, the problem is to set the truststore on client side (in this case the servlet). I tried 2 ways to announce the truststore:
1.
Code:
System.setProperty("javax.net.ssl.trustStore", context.getRealPath("WEB-INF/" + getKeystoreFileName()));
System.setProperty("javax.net.ssl.trustStorePasswo rd", getKeypass());
getKeystoreFileName() liefert einfach nur den Namen des Keystores/Truststore:
so dass die erste property dann so lautet:
"/baan/webtop/8680/ese/apache-tomcat-6.0.32/webapps/ownservlet/WEB-INF/test.jks"
and the other one:
"secret"
I always get the error message:
"Connecting to ownserver via sslport (server123:3337): java.io.IOException: Keystore was tampered with, or password was incorrect"
2. I tried to load the jks file dynamically:
Code:
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(new FileInputStream(ksName), ksPass.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactor y.getDefaultAlgorithm());
tmf.init(trustStore);
// get the trust managers from the factory
TrustManager[] trustManagers = tmf.getTrustManagers();
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustManagers, null);
SSLContext.setDefault(sslContext);
SSLSocketFactory sslFact = sslContext.getSocketFactory();
sslSocket = (SSLSocket) sslFact.createSocket();
It should be noted that both exaples in a small client-test-main()-program works fine, the announce of the truststore in a servlet does not working (the central keystore cacerts is not avaiblabe for me).
Do someone has an idea? Thanks for reading.
Re: SSL connection from the servlet to the server