Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Downloading files from a HTTPS server

 
Pranabesh Sinha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I want to download a file from a server over https, I get the following error


javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)

I have the URL of the file and I use URLConnection.

Thanks
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

please put code, stacktraces etc. in code tags.

Try this approach:

 
Pranabesh Sinha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Here is a code that I copied from the web



Because of line 33 I get this error


Now the reason for this error is of course that the certificate sent by my server is not already in my list of trusted certificates.
My question is how to get the certificate into the trusted list.

Thanks
 
Pranabesh Sinha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I made a mistake in the earlier post, the error occurs due to line 33 not 29.

Thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what happens if you try to connect using URL, URLConnection and HttpsURLConnection as Sebastian suggested?
 
Sunny X Narula
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hand shake exception is caused due to java not being to handle SSL connections by default.
As per my understanding when you open a secure internet connection over https you need to exchange certificates which the server uses to identify the caller and so that the security of the transferred information can be ensured.
Also this is a session specific thing.
I have had the problem when working with websphere and these are the settings I do to solve it.



You need to know who you are talking to and use an appropriate handler. May be there is some sort of generic handler that can be used for all https connections.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic