I have two applications running in the same java virtual machine, and both use different keystores and truststores.
A viable option would be use a single keystore an
Maybe I am 10 years too late to answer this question, but it could be maybe helpful for other developers too. I also ran into the same challenge of loading multiple keystores as keymaterial/trustmaterial. I discovered this page and the answer which Cody A. Ray has provided. After using the same snippet for multiple projects, I thought it would be handy to create a library and also make it publicly available to contribute back to the community. Please have a look here: Github - SSLContext-Kickstart The code snippet of Cody A. Ray for the CompositeKeyManager and CompositeTrustManager are both included.
Usage:
import nl.altindag.sslcontext.SSLFactory;
import javax.net.ssl.SSLContext;
public class App {
public static void main(String[] args) {
String keyStorePathOne = ...;
String keyStorePathTwo = ...;
String trustStorePathOne = ...;
String trustStorePathTwo = ...;
char[] password = "password".toCharArray();
SSLFactory sslFactory = SSLFactory.builder()
.withIdentityMaterial(keyStorePathOne, password)
.withIdentityMaterial(keyStorePathTwo, password)
.withTrustMaterial(trustStorePathOne, password)
.withTrustMaterial(trustStorePathTwo, password)
.build();
SSLContext sslContext = sslFactory.getSslContext();
}
}
I wasn't quite sure if I should post this here, because it could also be seen as a way to promote "my library" but I thought it could be helpful for developers.