我目前正在使用我编写的代码在IBM Httpd服务器端口上安装SSL证书。代码安装证书如下:
创建一个密码保护的.p12文件,其中包含私钥对象和最终实体证书(作为1元素的X509Certificate数组传递)。
public static KeyStore createKeyStoreFromKeyAndCertChain(String encoding,
String friendlyName, X509Certificate[] certChain,
PrivateKey key, String password)
throws KeyStoreException, CertificateException,
NoSuchAlgorithmException, IOException {
KeyStore store = KeyStore.getInstance(encoding);
store.load(null, null);
store.setKeyEntry(friendlyName, key, password.toCharArray(), certChain);
return store;
这正确生成一个.p12文件,可以使用openssl和keytool解析。
" C:\ Program Files(x86)\ IBM \ HTTPServer2 \ java \ jre \ bin \ ikeycmd.exe" -keydb -create -db" C:\ Work \ Certs \ IBM certs \ test.kdb" -pw password -type cms -expire 60 -stash
" C:\ Program Files(x86)\ IBM \ HTTPServer2 \ java \ jre \ bin \ ikeycmd.exe" -cert -add -db" C:\ Work \ Certs \ IBM certs \ key1.kdb" -pw密码-label icacert -file" C:\ renewcert \ ica.cer" -trust enable
" C:\ Program Files(x86)\ IBM \ HTTPServer2 \ java \ jre \ bin \ ikeycmd.exe" -cert -add -db" C:\ Work \ Certs \ IBM certs \ key1.kdb" -pw password -label rootcert -file" C:\ renewcert \ rootCert.cer" -trust enable
" C:\ Program Files(x86)\ IBM \ HTTPServer2 \ java \ jre \ bin \ ikeycmd.exe" -cert -import -db" C:\ renewcert \ certWithPvtKey.p12" -pw password -target" C:\ Work \ Certs \ IBM certs \ httpdkey.kdb" -target_pw password -target_type cms
这会创建一个.kdb文件。
Listen 10.212.143.105:6042
<VirtualHost 10.212.143.105:6042>
SSLEnable
SSLProtocolDisable SSLv2
SSLServerCert ibmhttpdsslcert
KeyFile "C:\Work\Certs\IBM certs\key1.kdb"
SSLStashFile "C:\Work\Certs\IBM certs\key1.sth"
</VirtualHost>
用于标记SSLServerCert的标签与用于在步骤1中创建.p12的友好名称相同。
证书可通过我们的应用程序(使用基于Java的SSL证书发现)和openssl发现。
问题
我们现在需要从.kdb文件中导出原始.p12。同样,使用以下命令:
&#34; C:\ Program Files(x86)\ IBM \ HTTPServer2 \ java \ jre \ bin \ ikeycmd.exe&#34; -cert -export -db&#34; C:\ Work \ Certs \ IBM certs \ key1.kdb&#34; -pw password -label ibmhttpdsslcert -type cms -target&#34; C:\ Work \ Certs \ IBM certs \ certChain.p12&#34; -target_pw密码-target_type pkcs12
实质上发生的是,生成的.p12文件似乎已损坏,无法使用以下代码进行解析:
public static void main(String[] args) throws Exception {
String password = "password";
// Read the .p12 and convert it to Java objects
FileInputStream fm = new FileInputStream(new File("C:\\Work\\Certs\\IBM certs\\certChain.p12"));
KeyStore ks = KeyStore.getInstance("PKCS12");
try {
ks.load(fm, password.toCharArray());
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("Size- " +ks.size());
Enumeration aliases = ks.aliases();
while(aliases.hasMoreElements()){
String param = (String) aliases.nextElement();
System.out.println("Param- " +param);
}
KeyStore.ProtectionParameter protParam =
new KeyStore.PasswordProtection(password.toCharArray());
// Retrieve the key using the alias "IBMHttpdSSLCert"
KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)
ks.getEntry("IBMHttpdSSLcert", protParam);
PrivateKey myPrivateKey = pkEntry.getPrivateKey();
Object pemObject = myPrivateKey;
// Write the key to file
JcaPEMWriter pemWriter = new JcaPEMWriter(new FileWriter(new File("C:\\Work\\pvtKey.pem")));
pemWriter.writeObject(pemObject);
pemWriter.close();
System.out.println("Pvt key- " +myPrivateKey);
fm.close();
}
如果密钥库的大小报告为零(0),并且密钥库文件也无法使用keytool解析,则会发生什么。 但是,使用openssl可以解析相同但我们不能将openssl捆绑在代码二进制文件中。
知道这是否是IBM针对密钥库导出实现的已知错误?