Results 1 to 2 of 2
- 12-11-2012, 05:14 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 1
- Rep Power
- 0
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.
- 12-11-2012, 07:32 PM #2
Re: SSL connection from the servlet to the server
If you're forever cleaning cobwebs, it's time to get rid of the spiders.
Similar Threads
-
servlet,connection,bean
By tanu in forum New To JavaReplies: 2Last Post: 01-13-2012, 02:47 PM -
email servlet ( java.net.SocketException: Connection reset)
By anthrax in forum Advanced JavaReplies: 2Last Post: 01-24-2010, 04:41 PM -
Servlet to Servlet connection through URLConnection
By bsrjavaforum in forum NetworkingReplies: 0Last Post: 04-01-2009, 05:12 PM -
Servlet - apache tomcat/glassfish server shuts down on servlet usage
By StewS in forum Java ServletReplies: 1Last Post: 12-02-2008, 01:23 AM -
Connection the sql server
By Preethi in forum New To JavaReplies: 7Last Post: 06-26-2008, 04:05 PM
Bookmarks