Results 1 to 5 of 5
  1. #1
    Felissa is offline Member
    Join Date
    Jun 2007
    Posts
    95
    Rep Power
    0

    Default java.security.cert.CertificateException: Couldn't find trusted certificate

    I had the following code to connect to a site on a server. It worked fine, now the server is using https, which causes the error:

    javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Couldn't find trusted certificate.

    Java 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 a lot.
    Felissa:p

  2. #2
    Eric is offline Senior Member
    Join Date
    Jun 2007
    Posts
    111
    Rep Power
    0

    Default

    Perphas its something to do with this line
    Java Code:
    url = new URL("https", rptUrl, 443, "/");
    even when changed to
    Java Code:
    url = new URL("https", rptUrl, "/");
    I got the same error. Doing all the steps in the example but still setting the URL like
    Java Code:
    URL url = new URL ( rptUrl );
    Eric

  3. #3
    sathish_2111 is offline Member
    Join Date
    Jul 2007
    Posts
    17
    Rep Power
    0

    Default

    HTTPS connection uses certificates. Certificates validation are done during HTTPS connection establish......so you need to install/use the trusted certificate......trusted certificate can be the certificate which send be server or the CA(certificate authority) which signs the certificates of the server....

  4. #4
    sathish_2111 is offline Member
    Join Date
    Jul 2007
    Posts
    17
    Rep Power
    0

    Default

    we don't want to specify 443 port number because for https connection the default port is 443.....like http is 80 which we are not mentioning ...

  5. #5
    abhishekjoshi is offline Member
    Join Date
    Aug 2007
    Posts
    1
    Rep Power
    0

    Smile

    This exception is thrown because you have not configured to accept the certificate of the website. The one-way SSL connections works in this way:
    The web server hosting the URL in question will create a certificate and get it signed by a Certification Authority like Verisign.
    when you try to connect to this URL, the server will provide this certificate.
    If you trust this certificate then only the connection will be established.
    Usually the CA assigned certificates wont throw this error as the identity of the server will be verified by the certificate authority, only self signed certificates will create problem. If they do then you have to add this certificate to your trusted certificate Keystore. Once you have added this certificate to the keystore this exception will not be thrown. To get the certificate use a web browser or ask the web server hosting the url to provide the certificate.

    In your case you are using a custom keystore file,
    "System.setProperty("javax.net.ssl.trustStore" , "keystore_filename");"

    Please make sure you have imported the certificate to this keystore file.
    Last edited by abhishekjoshi; 08-10-2007 at 11:14 PM.

Similar Threads

  1. Replies: 3
    Last Post: 01-14-2010, 08:45 PM
  2. Java certificate
    By Nick15 in forum Java Certification
    Replies: 2
    Last Post: 11-12-2007, 07:02 AM
  3. java.security.AccessControlException
    By cecily in forum Java Applets
    Replies: 1
    Last Post: 08-06-2007, 03:49 AM
  4. Replies: 1
    Last Post: 07-24-2007, 12:59 AM
  5. Java cert exam samples
    By orchid in forum New To Java
    Replies: 5
    Last Post: 06-04-2007, 10:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •