help: ValidatorException: No trusted certificate found

I am writing a client application that would load a .p12 certificate with a private key, establish an SSL/TLS connection, and then HTTPS connection over it.

However, I keep getting this error:

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

If anyone can help that would be great.

Here's my code:

public class Main {

// create an SSL contect with the keystore

static SSLContext createSSLContext() throws Exception

{

// set up a key manager for our local credentials

KeyManagerFactory mgrFact = KeyManagerFactory.getInstance("SunX509");

KeyStore clientStore = KeyStore.getInstance("PKCS12", "BC");

String filename = "MyCertificate.p12";

clientStore.load(new FileInputStream(filename), "myPassWord".toCharArray());

mgrFact.init(clientStore, "myPassWord".toCharArray());

// create a context and set up a socket factory

SSLContext sslContext = SSLContext.getInstance("TLS");

sslContext.init(mgrFact.getKeyManagers(), null, null);

return sslContext;

}

/**

* Verifier to check host has identified itself using "Test CA Certificate".

* ? into this part further

*/

private static class Validator implements HostnameVerifier

{

public boolean verify(String hostName, SSLSession session)

{

try

{

return true;

}

catch (Exception e)

{

return false;

}

}

}

public static void main(String[] args) {

try {

SSLContextsslContext = createSSLContext();

SSLSocketFactory fact = sslContext.getSocketFactory();

int HTTPS_PORT = 9020;

URL myURL = new URL ("https://www.someplace.com/" + ":" + HTTPS_PORT);

HttpsURLConnection httpsConn = (HttpsURLConnection) myURL.openConnection();

httpsConn.setSSLSocketFactory(fact);

httpsConn.setHostnameVerifier(new Validator());

httpsConn.connect();

httpsConn.setDoOutput(true);

BufferedReader in = new BufferedReader(new InputStreamReader(httpsConn.getInputStream()));

String line;

while ((line = in.readLine()) != null)

{

System.out.println(line);

}

in.close();

}

catch (Exception e)

{

e.printStackTrace();

}

}

[2362 byte] By [Ewon799a] at [2007-10-3 3:06:38]
# 1
Could you please re-post your code using the tags.Thanks.
djalfirevica at 2007-7-14 20:56:54 > top of Java-index,Security,Cryptography...
# 2

The error message indicates that the self-signed certificate of a trusted Certificate Authority (CA) is not in the default keystore in use by your application. You didn't specify whether the error was on the client or the server side, but you should check the keystores of the side on which the error manifests itself, to ensure that you have the CA certificate of the client (or server) certificate that is used in the SSL connection.

arshad.noora at 2007-7-14 20:56:54 > top of Java-index,Security,Cryptography...