CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2012
    Posts
    2

    SSL/JSSE Client authentication problem

    Hello,

    I am a total SSL newbie. I have to connect to a 3rd party app via a SSL/TCP connection (not https). They vendor provided example code that works under C#. I need to emulate the same connection method, but in Java. The C# code looks something like this:

    client = new TcpClient(hostName, int.Parse(clientPort));
    sslStream = new SslStream(client.GetStream(), ...);
    sslStream.AuthenticateAsClient(serverName);

    So, I am provided with only three input parameters - host name, port, and a "server name". It appears that the .net runtime function, AuthenticateAsClient, lets you authenticate the connection with just the service name (not sure if that is the correct designation). There is no certificate of any kind on the client machine that is connection to the SSL server. Although I have found many SSL/Java examples on the web, I don't know what the construct/function calls would be in a Java environment to emulate the behavior of this AuthenticateAsClient function. Any help ig greately appreciated.

    Here's some more detail. I looked at the JSSE tutorial.

    OK, I looked at the tutorials, and am still missing some key bit of knowledge. Here is my example code:

    SSLSocketFactory sslsocketfactory = (SSLSocketFactory)SSLSocketFactory.getDefault();
    SSLSocket sslsocket = (SSLSocket)sslsocketfactory.createSocket("usatl-w-100624", 11000);
    InputStream inputstream = System.in;
    InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
    BufferedReader in = new BufferedReader(inputstreamreader);
    OutputStream outputstream = sslsocket.getOutputStream();
    OutputStreamWriter ow = new OutputStreamWriter(outputstream);

    sslsocket.startHandshake();

    On the call to startHandshake(), I get this error: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

    Of couse, this is expected, as I do not have a certificate in the java keystore. If I look at the JSSE examples, here: http://docs.oracle.com/javase/1.4.2/...les/index.html
    The SSLSocketClientWithClientAuth.java example looked relevant. However, it also is requesting a file path. My C# example does not access any file on the client. So, how do you do the equivalent in Java?


    Thanks,Leor

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: SSL/JSSE Client authentication problem

    Not sure if this will help but I found this thread where one of the posts explains how to disable cert validation.

    http://stackoverflow.com/questions/8...over-https-ssl
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Apr 2012
    Posts
    2

    Smile Re: SSL/JSSE Client authentication problem

    Awesome! that link did the trick. Thanks.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured