Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JAVA TLS client application

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JAVA TLS client application

    I have a AudioCodes SIP gateway, and I am writing a lightweight SIP client in JAVA, I got this working for TCP, however I am trying to implement TLS. I have the certificates, however I cannot find an example of how to use JAVA sockets to connect over TLS using external certificates, can somebody please point me in the right direction. Thank you.

    Below is what I have, I imported the root CA in the truststore using keytool,

    keytool -import -trustcacerts -alias caroot2 -file ca-root-cert.pem -keystore keystore.jks

    I get the following error:

    > javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

    Can somebody please help me ??
    package atobtls;
    import javax.net.ssl.SSLSocket;
    import javax.net.ssl.SSLSocketFactory;
    import java.io.*;
     
    public class Atobtls {
        public
                static
        void
                main(String[] arstring) {
            try {
                String truststorePath = "keystore.jks";
                String truststorePass = "abc123";
     
                System.setProperty("javax.net.ssl.trustStore", truststorePath);
                System.setProperty("javax.net.ssl.trustStorePassword", truststorePass);
     
                SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
                SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("192.168.217.1", 443);
     
                InputStream inputstream = System.in;
                InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
                BufferedReader bufferedreader = new BufferedReader(inputstreamreader);
     
                OutputStream outputstream = sslsocket.getOutputStream();
                OutputStreamWriter outputstreamwriter = new OutputStreamWriter(outputstream);
                BufferedWriter bufferedwriter = new BufferedWriter(outputstreamwriter);
     
                String string = "test";
     
                    bufferedwriter.write(string + '\n');
                    bufferedwriter.flush();
     
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
    }


  2. #2
    Senior Member PhHein's Avatar
    Join Date
    Mar 2013
    Location
    Germany
    Posts
    609
    My Mood
    Sleepy
    Thanks
    10
    Thanked 93 Times in 86 Posts

    Default Re: JAVA TLS client application

    crosspost JAVA TLS client application

Similar Threads

  1. Replies: 0
    Last Post: April 5th, 2013, 07:16 PM
  2. Create Java Enterprise Application with Mobile Client
    By praveensingh18 in forum Java Servlet
    Replies: 2
    Last Post: August 18th, 2012, 06:02 PM
  3. server/client application fails when client closes
    By billykid in forum Java Networking
    Replies: 4
    Last Post: January 26th, 2012, 01:54 AM
  4. Embedding Java application into external client
    By 1372586 in forum Java Networking
    Replies: 3
    Last Post: November 3rd, 2011, 08:57 AM
  5. Client Socket on Application Server
    By xevimaresma in forum Java Theory & Questions
    Replies: 0
    Last Post: April 12th, 2010, 07:00 AM