*
The moose likes Security and the fly likes Could not find trusted certificate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Could not find trusted certificate" Watch "Could not find trusted certificate" New topic
Author

Could not find trusted certificate

Hongqing Lu
Greenhorn

Joined: Jan 14, 2004
Posts: 13
I run an java application to validate address in www.desertsoft.com.
But it throws following exceptions:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Could not find trusted certificate
at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SunJSSE_az.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SunJSSE_ax.a(DashoA6275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.a(DashoA6275)IO Exception
Because www.desertsoft.com use SSL connection....
What can I do to solve the problem? Is there any stuff or example?
Next code is example code from www.desertsoft.com:
import java.net.*;
import java.io.*;
import java.security.Security;
import java.security.Provider;
import org.w3c.dom.*;
import javax.xml.parsers.*;
public class AddressValidator {
private static final String baseUrl =
"https://sws.desertsoft.com/AddVal/AddVal.asmx/AddVal?";
// values to validate
private static String addressLine = "1600 Pennsylvania Avenue";
private static String city = "Washington";
private static String state = "DC";
private static String zip = "20500";
private static String username = "desertsoft";
private static String password = "desertsoft";
private static String version = "1.1";
public static void main(String args[]) {
String requestUrl, nodeName, nodeValue; ;
try {
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
Class clsFactory = Class.forName(
"com.sun.net.ssl.internal.ssl.Provider");
if ( (null != clsFactory) &&
(null == Security.getProvider("SunJSSE"))) {
Security.addProvider( (Provider) clsFactory.newInstance());
}
// build request url
requestUrl = baseUrl + "strAdd1=" + URLEncoder.encode(addressLine);
requestUrl = requestUrl + "&strCity=" + URLEncoder.encode(city);
requestUrl = requestUrl + "&strState=" + URLEncoder.encode(state);
requestUrl = requestUrl + "&strZip=" + URLEncoder.encode(zip);
requestUrl = requestUrl + "&strUser=" + URLEncoder.encode(username);
requestUrl = requestUrl + "&strPass=" + URLEncoder.encode(password);
requestUrl = requestUrl + "&strVersion=" +
URLEncoder.encode(version);
System.out.println(requestUrl);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setIgnoringComments(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(requestUrl);
// parse returned XML
Node n;
Node addressNode = doc.getFirstChild();
NodeList nodes = addressNode.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
nodeName = n.getNodeName();
nodeValue = n.getFirstChild().getNodeValue();
System.out.println(nodeName + ": " + nodeValue);
}
}
}
catch (IOException ioe) {
System.out.println("IO Exception");
ioe.printStackTrace();
}
catch (ClassNotFoundException cfe) {
System.out.println("Unable to load the JSSE SSL stream handler.");
}
catch (InstantiationException ie) {
System.out.println("InstantiationException occured.");
}
catch (IllegalAccessException iae) {
System.out.println("IllegalAccessException occured.");
}
catch (org.xml.sax.SAXException saxe) {
System.out.println("org.xml.sax.SAXException occured.");
}
catch (ParserConfigurationException pce) {
System.out.println("ParserConfigurationException occured.");
}
}
}
Please help
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Could not find trusted certificate
 
Similar Threads
Https problem when accessing through java programs
IDEA couldn't find trusted certificate.
Exception while trying to connect to FTP server
Suppress text nodes in output when empty
Need Advice on creating a server that uses SSL!