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!

SSL: Importing PEM files into KeyStore?...

843811Feb 14 2008 — edited Jul 29 2010
I have a Java application that is trying to connect to C++ server using an SSLSocket connection.

I have all the details necessary for creating the SSLSocket object except... I have no idea how to load keys and certs into my KeyStore object.

I have 2 certs (CA and Client) and a Client Private Key - ALL of which are in PEM file format.

Any ideas how I would go about adding the PEM certs & key to my KeyStore? I think I'll need to first convert from PEM format to some format that KeyTool will be able to read and then run KeyTool....

Any info would be appreciated!



C++ Server Encryption Details (OpenSSL)
Encryption method used - TLSv1
Using self-signed certificates
Using both server and clients certificates
Private keys of server and clients certificates are encrypted with a pass phrase for extra security


Client Socket Connection Code:
        Socket mySocket = null;
        SSLSocketFactory sslFactory = null;
        SSLContext sslCtx = SSLContext.getInstance( "TLS" );  //TLS?
        KeyManagerFactory kMF = KeyManagerFactory.getInstance( "SunX509" ); //"SunX509"??
        KeyStore kS = KeyStore.getInstance( "JKS") ; //"JKS"??
    
        //Hard-coded password for decrypting Client Key
        char[] passWord= "myPassword".toCharArray();
        
        kS .load(new FileInputStream("InputFile"), passWord= ); //"InputFile" from PEM Files?
        kMF.init(kS, passWord);
        
        TrustManagerFactory tMF = TrustManagerFactory.getInstance("SunX509");
        tMF.init( ks );
        sslCtx.init(tMF.getKeyManagers(), tMF.getTrustManagers(), null);
        sslFactory = sslCtx.getSocketFactory();

        mySocket = factory.createSocket(inetAddress, commandPort);
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 26 2010
Added on Feb 14 2008
5 comments
3,879 views