Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

No trusted certificate found

843811Dec 21 2005 — edited Feb 7 2007
Hi,
I've a problem calling an https secure url. I've read some messages at this forums but I didn't find the solution.

This is my code:
    public static void main(String[] args) {
        try {
            System.err.println("*** " + doSecureSocketHttpGet(new URL("https://secureurl.com)));
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    }
    
    public static final String doSecureSocketHttpGet(URL url) {
        ByteArrayOutputStream bos = null;
        BufferedInputStream httpResponseStream = null;
        String sResult = null;
        try {
            //HTTP-S
            System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
            Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
            URLConnection conn = url.openConnection();

            // Retrieve information from HTTPS: GET

            httpResponseStream = new BufferedInputStream(conn.getInputStream());

            bos = new ByteArrayOutputStream();

            byte[] data = new byte[1024];
            int iBytesRead;
            while ((iBytesRead = httpResponseStream.read(data, 0, 1024)) != -1) {
                bos.write(data, 0, iBytesRead);
                bos.flush();
            }

            sResult = new String(bos.toByteArray());

            httpResponseStream.close();
            //HTTP-S END
            //System.out.println("sSupermotorXml = " + sSupermotorXml);
        } catch (Exception e) {
            e.printStackTrace();
        } catch (Throwable t) {
            t.printStackTrace();
        } finally {
            try {
                if (bos != null) {
                    bos.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            try {
                if (httpResponseStream != null) {
                    httpResponseStream.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return sResult;
    }
I obtain this exception:

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found

The other part sent me the CA Root certificate and I tried using keytool like this

keytool -import -trustcacerts -alias myalias -file CARoot.cer

and cert is imported correctly, but exception continues raising.

I also have a certificate obtained by exporting to file the certificate recieved by the browser at https://secureurl.com.



Any one can tell me exactly what must I write for keytool or also modify at my code?

Thank you very much.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2007
Added on Dec 21 2005
6 comments
579 views