Registering multiple keystores in JVM

前端 未结 4 535
盖世英雄少女心
盖世英雄少女心 2020-11-27 11:07

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

4条回答
  •  醉酒成梦
    2020-11-27 12:12

    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.

提交回复
热议问题