Repository navigation
Dynamically modify truststore at runtime #98
|
I was wondering whether or not it is possible to modify the trusted certificates at runtime. I have tried modifying the file that the truststore uses by doing the following: File file = new File("src/main/resources/truststore.jks");
KeyStore keystore = KeyStore.getInstance("JKS");
if (!file.exists()) {
keystore.load(null, password);
} else {
FileInputStream in = new FileInputStream(file);
keystore.load(in, password);
in.close();
}
// If the certificate does not already exist.
if (!keystore.containsAlias(alias)) {
FileOutputStream out = new FileOutputStream(file);
keystore.setCertificateEntry(alias, certificate);
LOGGER.info("Adding file to truststore");
keystore.store(out, password);
out.close();
}This results in I also thought that this might not update the file used by phase4 before the program is restarted. Is it possible to dynamically add a new X509Certificate to the truststore at runtime? Would this approach then include defining the OBS. |
Replies: 2 comments 8 replies
|
Hi, try this for line 4 above (no password needed): keystore.load(null, null);Setting the truststore dynamically is possible in phase4, it just matters if you need it for sending and receiving, and if receiving is affected, how you enable the dynamic truststore. For sending (assuming you use the builder), you need to set a different |
|
Dear @MakakWasTaken, Do you solve tthis question? May you share the solution with me?
Thanks. Best Regards, |
Hi, try this for line 4 above (no password needed):
Setting the truststore dynamically is possible in phase4, it just matters if you need it for sending and receiving, and if receiving is affected, how you enable the dynamic truststore.
For sending (assuming you use the builder), you need to set a different
cryptoFactoryusing an instance ofAS4CryptoFactoryInMemoryKeyStorewhere you pass in keystore and truststore dyanmically. The same can be done for receiving as well, just that the point for interception is a bit tricky ;-)