I use currently the following code to get a public key from a certificate from keystore in WebSphere Application Server Full Profile:
KeySetManager keySetMgr = KeySetManager.getInstance();
WSKeySet keySet = keySetMgr.getKeySet(KEY_SET_NAME);
KeyReference[] allKeyReferences = keySet.getAllKeyReferences();
for (int i = 0; i < allKeyReferences.length; ++i) {
try {
KeyReference kref = allKeyReferences[i];
String keyAlias = kref.getKeyAlias();
if (!SIGNER_CERT_ALIAS.equals(keyAlias)) { continue; }
WSKeyStore wsKeyStore = kref.getWSKeyStore();
String location = wsKeyStore.getLocation();
String type = wsKeyStore.getProperty("com.ibm.ssl.keyStoreType");
String name = wsKeyStore.getProperty("com.ibm.ssl.keyStoreName");
String provider = wsKeyStore.getProperty("com.ibm.ssl.keyStoreProvider");
String password = wsKeyStore.getProperty("com.ibm.ssl.keyStorePassword");
String scope = wsKeyStore.getProperty("com.ibm.ssl.keyStoreScope");
KeyStore keyStore = KeyStoreManager.getInstance().getKeyStore(name, type, provider, location, password, scope, true, null);
Certificate certificate = keyStore.getCertificate(keyAlias);
PublicKey publicKey = certificate.getPublicKey();
return publicKey;
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
The code above uses proprietary IBM WAS ND classes:
import com.ibm.ws.crypto.config.KeyReference;
import com.ibm.ws.crypto.config.KeySetManager;
import com.ibm.ws.crypto.config.WSKeySet;
import com.ibm.ws.ssl.config.KeyStoreManager;
import com.ibm.ws.ssl.config.WSKeyStore;
Now I need to migrate the application to WebSphere Liberty Profile (WLP), and these classes com.ibm.ws.crypto.config.*
not exist in WLP, and the code is not portable, unfortunately.
From what I learned I cannot programmatically access keystores on WLP, is that statement acurate?
I did not find any example how to implement similar approach in WLP.
My understanding at the moment is that I must simply use KeyStore.load(inputStream, password)
and store somewhere (or hard code) key store file name and password. Is that the commonly used approach for WLP?
The ultimate goal of migration is Dockerizing the application and migrate to the cloud (OpenShift), so the question is: where to store the keystore ? Inside application, or inside WLP install? I guess the difference is not a big deal, since if the certificate expires, I would need to rebuild the whole Docker image which will include WLP and the application.
Or maybe it's possible to store in cloud and somehow access from inside Docker container. That would be probably the best approach as expiring of certificate won't require image rebuild, simply update the cloud environment.
Any suggestions or experiences or hints are highly appreciated.