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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

No trusted certificate found or remote host closed connection at handshake

843811Jun 14 2006 — edited Jun 20 2006
hello,
i am trying to write the java code to connect to existing production server over SSL using the keys and certificates from server which i already have...

Following are steps which i have already done:-

1.i have two files key.der (private key) and ca.der(containing chain of certificates along with public key).

2.i have created keystore "tribecakeystore.keystore" using above two files.i imported ca.der using the keytool and imported key.der using java code.Now tribecakeystore.keystore has key entry in it.

3.I also imported ca.der(containing chain of certificates) into jre keystore c:\java\lib\security\cacerts(containing list of trusted certificates).This keystore now contains trusted certificate entry.
and
i wrote the code as :
KeyStore tribecaKeystore=KeyStore.getInstance("JKS");
tribecaKeystore.load(new FileInputStream("c:/tribecakeystore.keystore"),"tribeca".toCharArray());
System.out.println("1.Keystore created and loaded");

//and trust store
KeyStore tribecaTruststore=KeyStore.getInstance("JKS");
// tribecaTruststore.load(new FileInputStream("c:/tribecatruststore.keystore"),"tribeca".toCharArray());
tribecaTruststore.load(new FileInputStream("C:/Program Files/Java/jre1.5.0_06/lib/security/cacerts"),"changeit".toCharArray());
System.out.println("2.Truststore created and loaded");

//load keyManagers
KeyManagerFactory keyManagerFactory=KeyManagerFactory.getInstance("SunX509");
keyManagerFactory.init(tribecaKeystore,"tribeca".toCharArray());


//load trustManagers
TrustManagerFactory tmf =TrustManagerFactory.getInstance("SunX509");
tmf.init(tribecaTruststore);

System.out.println("Key manager and Trust manager init");


// Define SSLContext
SSLContext sslContext=SSLContext.getInstance("SSLv3");
sslContext.init(keyManagerFactory.getKeyManagers(),tmf.getTrustManagers(),null);
System.out.println("2.SSL Context created over keystore using protocol "+sslContext.getProtocol());

//Create SSL Engine
SSLEngine sslEngine=sslContext.createSSLEngine("10.10.10.189",15001);
sslEngine.setUseClientMode(true);

//Create SSL socket factory
SSLSocketFactory sslfactory=sslContext.getSocketFactory();
System.out.println("3.SSL engine and SSLFactory created over Above SSLContext");

//1.Create SSLSocket
SSLSocket SSLsocket=(SSLSocket)sslfactory.createSocket("10.10.10.189",15001);
System.out.println("SSL SOCKET Connected "+SSLsocket.isConnected());
System.out.println("4.SSLSocket created using above SSLSocketFactory");

//create socket streams
OutputStream socketOut=SSLsocket.getOutputStream();
InputStream socketIn=SSLsocket.getInputStream();
System.out.println("5.Socket Streams created");


//create session and data buffers over it
SSLSession session = sslEngine.getSession();

// DO Handshake here
SSLsocket.addHandshakeCompletedListener(new HandshakeComplete());
SSLsocket.startHandshake();//Handshake cannot found trusted certificate on my system
//OR Remote Host closing connection here

The exception is generated at this point showing no trusted certificate found and sometimes showing remote server closed connection while handshake..

please help me in it..i have right key.pem and server certificate ca.pem.i have both files in der format also.

Message was edited by:
miryaver
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 18 2006
Added on Jun 14 2006
16 comments
432 views