Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

PKCS12 Certificate and Keystore

 
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

 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic