【问题标题】:Java app to use two separate truststoresJava 应用程序使用两个单独的信任库
【发布时间】:2017-06-02 08:47:45
【问题描述】:

从一个 java 应用程序中,我想使用两个信任库,一个连接到 jms 代理,另一个连接到 Web 服务。我知道我可以将证书导入到一个信任库中,这很有效。但是,我在徘徊是否可以使用系统属性 javax.net.ssl.trustStore 传递不同信任库的列表?

【问题讨论】:

    标签: java ssl


    【解决方案1】:

    不,你不能。要使用不同的信任库,您应该以编程方式设置其中之一或两者。

    请参阅下面来自 post 的示例:

    SSLContext ssl = SSLContext.getInstance("SSLv3");
      KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
      String password = Configuration.getConfig("keyStorePassword");
      store.load(new FileInputStream(new File(Configuration.getConfig("keyStore"))), password.toCharArray());
      kmf.init(store, password.toCharArray());
      KeyManager[] keyManagers = new KeyManager[1];
      keyManagers = kmf.getKeyManagers();
      TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
      tmf.init(store);
      TrustManager[] trustManagers = tmf.getTrustManagers();
      ssl.init(keyManagers, trustManagers, new SecureRandom());
    
      HttpsConfigurator configurator = new HttpsConfigurator(ssl);
      Integer port = Integer.parseInt(Configuration.getConfig("port"));
      HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress(Configuration.getConfig("host"), port), 0);
      httpsServer.setHttpsConfigurator(configurator);
    
      Implementor implementor = new Implementor(); // class with @WebService etc.
      HttpContext context = (HttpContext) httpsServer.createContext("/EventWebService");
      Endpoint endpoint = Endpoint.create( implementor );
      endpoint.publish(context);
    

    【讨论】:

      猜你喜欢
      • 2010-12-13
      • 1970-01-01
      • 1970-01-01
      • 2015-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多