This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Security and the fly likes PKCS12 Certificate and Keystore Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "PKCS12 Certificate and Keystore" Watch "PKCS12 Certificate and Keystore" New topic
Author

PKCS12 Certificate and Keystore

Janaki Raju
Greenhorn

Joined: Apr 14, 2008
Posts: 8
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

 
 
subject: PKCS12 Certificate and Keystore