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!

IAIK to JSSE migration

843811Nov 19 2003 — edited Nov 19 2003
Greetings, security gurus !

Can anybody help me to convert the code in IAIK to JSSE ? I have know idea about it ! I didn't find corresponding classes for EncryptedPrivateKeyInfo in JSSE.

import iaik.protokol.https.*;
import iaik.security.ssl.*;
import iaik.x509.*;
import iaik.pkcs.pkcs8.EncryptedPrivateKeyInfo;

public static void initSecurity() throws Exception {
// build certificate chain
SSLClientContext context = new SSLClientContext();
iaik.x509.X509Certificate[] certChain =
new iaik.x509.X509Certificate[ certFiles.length ];
int i = 0;
try {
for( i = 0; i < certChain.length; i++ )
certChain[ i ] = new iaik.x509.X509Certificate
( new FileInputStream( new File( certFiles[ i ] ) ) );
} catch( Exception exc ) {
log( "Can't load certificate chain from file " + certFiles[ i ] );
throw exc;
}
// Read in an PKCS#8 key. Encrypted with an empty string.
PrivateKey clientKey = null;
try {
FileInputStream keyfis = new FileInputStream( KEY_FILE );
byte[] encKey = new byte[ keyfis.available() ];
keyfis.read( encKey );
keyfis.close();
EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo( encKey );
clientKey = epki.decrypt( "" );
} catch( Exception exc ) {
log( "Can't load private key from file " + KEY_FILE );
throw exc;
}
// set SSL context
context.addClientCredentials( certChain, clientKey );
context.setEnabledCipherSuiteList
( new CipherSuiteList( CipherSuiteList.L_IMPLEMENTED ) );
iaik.protocol.https.HttpsURLConnection.setDefaultSSLContext( context );
// extract certificate id
String commaList = certChain[ 0 ].getSubjectDN().getName();
StringTokenizer stComma = new StringTokenizer( commaList, "," );
while( stComma.hasMoreTokens() ) {
StringTokenizer stEquals = new StringTokenizer( stComma.nextToken(), "=" );
if( stEquals.countTokens() < 2 ) continue;
if( "CN".equals( stEquals.nextToken() ) ) {
CERT_ID = stEquals.nextToken();
return; }
stEquals.nextToken();
}
throw new Exception( "No ItraSend site id in certificate chain" );
}

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 17 2003
Added on Nov 19 2003
1 comment
310 views