java.security.cert.CertificateException: Couldn't find trusted certificate
I had the following code to connect to a site on a server. The server is using https, which causes the error
javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Couldn't find trusted certificate
I have saved the certificate for reference and I assume to I need to tell the program to look at that but this will happen every time there is a new certificate
Changing the HttpURLConnection object to HttpsURLConnection throws up a 'java.lang.ClassCastException' error coz its an abstract class..
Code:
java.util.Properties propSy = System.getProperties();
propSy.put("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
System.setProperties(propSy);
java.security.Security.insertProviderAt(new sun.security.provider.Sun(),2);
java.security.Security.addProvider(new sun.security.provider.Sun());
java.security.Security.insertProviderAt(new com.sun.net.ssl.internal.ssl.Provider(),1);
System.setProperty("javax.net.ssl.trustStore", "keystore_filename");
java.security.Provider myprov = java.security.Security.getProvider("SunJSSE");
HttpsURLConnection c;
try {
URL url = new URL ( rptUrl );
c = (HttpsURLConnection)url.openConnection();
//set cache and request method settings
c.setUseCaches(false);
//set other headers
c.setRequestProperty ("Content-Type", "application/pdf");
//connect to the server..
c.connect();
}
Any ideas? Thanks.
Marcus:cool:
import javax.net.ssl.*;import javax.net.*; :all these are not recognized!!!
Dear Eric and all members, am unable to run the selfsign.zip codes...am having same errors with other java applications using SSL.
In my codes itself, import.javax.net; import.net.SSL; import javax.security.cert.X509Certificate; all these are underlined red and is not recognized!
It says cannot be resolved to a type..do i need to include any package and library?!
I have done some research and am getting lots of different things on EAServer Client machine, jaguar server and so on..am quite confused!
Please help!
Thanking you in advance and waiting for an early response!
kind Regards
kevina