Results 1 to 2 of 2
  1. #1
    RealWotan is offline Member
    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Default 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.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default 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

  1. servlet,connection,bean
    By tanu in forum New To Java
    Replies: 2
    Last Post: 01-13-2012, 02:47 PM
  2. Replies: 2
    Last Post: 01-24-2010, 04:41 PM
  3. Servlet to Servlet connection through URLConnection
    By bsrjavaforum in forum Networking
    Replies: 0
    Last Post: 04-01-2009, 05:12 PM
  4. Replies: 1
    Last Post: 12-02-2008, 01:23 AM
  5. Connection the sql server
    By Preethi in forum New To Java
    Replies: 7
    Last Post: 06-26-2008, 04:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •