Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Java SSL Connection: Certificate not Trusted, when connecting to server.

Posted on 2008-01-07
Last Modified: 2010-04-21
Hi there,

I'm trying to create a secure connection to a server. However, when I connect I get the following error:

javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Certificate not Trusted
at com.ibm.jsse.bf.a(Unknown Source)
      at com.ibm.jsse.bf.checkServerTrusted(Unknown Source)
Now, the URL I connect to (say provides a certificate for url ( - a different URL, but it's been signed by a certificate authority whose certificate exists in my truststore, so I'd like to trust it anyway.

Here's my code:

URL url = new URL(getUrl());
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestProperty ("Content-Type", "text/xml");
PrintWriter out = new PrintWriter (conn.getOutputStream());

Can someone point out where I'm going wrong?

Question by:stevebeech
  • 4
  • 3
LVL 23

Expert Comment

ID: 20598059
Import the certificate ... using keytool command..
LVL 23

Expert Comment

ID: 20598067
command is..

keytool -import -alias "SomeIdentifier" -keystore $JAVA_HOME/lib/security/cacerts -file certificate_file

Author Comment

ID: 20598079
I don't want to import the certificate, as I'll be providing this app to someone else, who may then connect to a different server. As long as the cert has been signed by the CA I trust, then I want it to be trusted by my app.

Does that make sense?
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

LVL 23

Expert Comment

ID: 20598122
You can try running your java with ssl debug enabled.. like..

java -Djavax.net.debug=all ......

Also check whether the filenames you are specifying for the properties can be found or not..

Author Comment

ID: 20598211
Ok, running in debug mode gives me the following error:

java.io.IOException: HTTPS hostname wrong:  should be <>

As I suspected, it's the address causing the problem. I'd like to bypass this, as the cert has been signed by a trusted CA.

LVL 23

Accepted Solution

cmalakar earned 250 total points
ID: 20598222

Author Closing Comment

ID: 31419439
Thanks cmalakar. That provided the answer. I was missing a hostname verifier!

Cheers (and keep up the good work)


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
web application structure 18 96
java imports not found 4 20
Setup GlassFish 4 21
Using jdbcTemplate.batchUpdate to improve INSERT performance 6 20
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question