• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PKCS12 Certificate and Keystore

 
Janaki Raju
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am using a PKCS12 certificate file. I am running java 1.5

The following is the code that I use to create a SSL socket and send data.

SSLSocketFactory factory = null;
try {
SSLContext ctx;
KeyManagerFactory kmf;
KeyStore ks;

char[] passphrase = this.keyStorePassword.toCharArray();

ctx = SSLContext.getInstance("SSL");
kmf = KeyManagerFactory.getInstance(keyManagerInstance);

if (keyStoreInstance.length() > 0) {
ks = KeyStore.getInstance(this.keyType, keyStoreInstance);
} else {
ks = KeyStore.getInstance(this.keyType);
}


ks.load(new FileInputStream(this.keyStore),passphrase);
kmf.init(ks, passphrase);
ctx.init(kmf.getKeyManagers(),null,null);

factory = ctx.getSocketFactory();
} catch (Exception e) {
throw new IOException(e.getMessage());
}
SSLSocket socket = (SSLSocket)factory.createSocket(path.getHost(),path.getPort());
//Connect using Socket
socket.startHandshake();
// This is followed by code to write out the data and then read in the response.

When I run this code, I get an exception - " SSL HandShake Exception - No trusted certificate found". I am not sure how to proceed beyond this. Is there a way I can add the certificate to the keystore? I have tried importing the file to the java truststore- does not seem to work.

Thanks,
Nan

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic