• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Java Swing/HttpClient to Tomcat SSL help

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a java swing client that connects to a tomcat server which connects to a database server. I need to encrypt the data that I am sending to the tomcat server but I am having issues trying to get it to work. My code to call the servlet is as follows:





I created a keystore and placed on the server. However, when I go to run the client, I get the following error:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLExceptio n(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(S SLSocketImpl.java:1611)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Ha ndshaker.java:187)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Ha ndshaker.java:181)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serv erCertificate(ClientHandshaker.java:1035)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.proc essMessage(ClientHandshaker.java:124)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoo p(Handshaker.java:516)
at com.sun.net.ssl.internal.ssl.Handshaker.process_re cord(Handshaker.java:454)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRec ord(SSLSocketImpl.java:884)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.perform InitialHandshake(SSLSocketImpl.java:1112)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.writeRe cord(SSLSocketImpl.java:623)
at com.sun.net.ssl.internal.ssl.AppOutputStream.write (AppOutputStream.java:59)
at java.io.BufferedOutputStream.flushBuffer(BufferedO utputStream.java:65)
at java.io.BufferedOutputStream.write(BufferedOutputS tream.java:104)
at java.io.FilterOutputStream.write(FilterOutputStrea m.java:80)
at org.apache.commons.httpclient.methods.ByteArrayReq uestEntity.writeRequest(ByteArrayRequestEntity.jav a:89)
at org.apache.commons.httpclient.methods.EntityEnclos ingMethod.writeRequestBody(EntityEnclosingMethod.j ava:495)
at org.apache.commons.httpclient.HttpMethodBase.write Request(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.execu te(HttpMethodBase.java:993)
at org.apache.commons.httpclient.HttpMethodDirector.e xecuteWithRetry(HttpMethodDirector.java:397)
at org.apache.commons.httpclient.HttpMethodDirector.e xecuteMethod(HttpMethodDirector.java:170)
at org.apache.commons.httpclient.HttpClient.executeMe thod(HttpClient.java:396)
at org.apache.commons.httpclient.HttpClient.executeMe thod(HttpClient.java:324)........

I'm kind of at a loss on how to fix this. The client is a stand alone swing program that is installed on multiple user's machines.
Thanks in advance for the help.
 
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

To help nail down which end the problem is on, I'd try hitting the URL with a browser and see if you get the expected result. If so, then you know the server end is OK. If not, then you know the server setup needs attention.
 
Greg Abel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am able to hit the server but I get the https crossed out like it is not trusted. Is there something I need to do with the client to accept it?
 
Bear Bibeault
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. because it is a POST, you likely need to set up an HTML page to hit the URL with a form set up to do a POST. Just typing the URL into the browser bar will send a GET request.
 
Bear Bibeault
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, I'm no SSL expert, but I believe that all the setup is on the server end. What servlet container are you using? Tomcat?
 
Greg Abel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Tomcat 7.
Is it possible to do SSL with a swing client? Or does this only work with a web application?
 
Bear Bibeault
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpClient should be able to handle it -- whether it's being used in a Swing client I think is not an issue.

I've copied this post to the Tomcat forum so that someone who is more savvy than I might see this and chime in.
 
Greg Abel
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate the help.
 
Bear Bibeault
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to try and help. I've also added some to your subject to help get the most attention.
 
Rancher
Posts: 43009
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the very last entry in the http://www.coderanch.com/how-to/java/SecurityFaq
 
Bartender
Posts: 20838
125
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm out of practice on the HttpClient/HttpURLConnection stuff, but do you really want to set a parameter for a POST request?

The difference between GET and POST is that in GET, you use parameters, which are encoded into the URL itself. If I'm not mistaken, POST requests would have an outputStream that the client writes the request data into.

As far as testing this stuff out, try this:

1. Add a simple JSP to your webapp. Let's call it "test.jsp". The contents of test.jsp are simple - just make it display "Hello, World!". Put it in your WAR, make sure that the web.xml specifies secure transport, and fire up a browser on the client machine.

2. Type "https://myserver:8443/mywebapp/test.jsp" into your browser's navigation bar (assuming you're going with Tomcat's default HTTPS port, 8443)

3. If all is OK, you should get "Hello, World!" displayed in your browser. AND the browser info should show a secured response.

4. If that works, your Swing app should be able (if coded properly) to use SSL/TLS.

You can also test a sample XML POST using a generic command-line client such as the "wget" program.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!