服务器应用程序需要共享SSL证书。第一步:
我的问题是:
我有一个弹簧引导应用程序。是否需要对我生成的证书的代码进行任何更改。如果是,那么变化是什么。
发布于 2020-02-05 12:48:00
是的,您需要对代码进行更改。您需要加载您的密钥存储库(带键盘),如果需要,还需要将您的信任存储加载到您的http客户机中。大多数http客户端都需要一个SSLContext,因此这对您来说就足够了:
KeyStore keyStore = ...;
TrustStore trustStore = ...;
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyStorePassword);
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
// Spring provides by default RestTemplate as HTTP Client, this client is an Apache HTTP Client wrapper
// The setup would be:
HttpClient httpClient = HttpClient.newBuilder();
.sslContext(sslFactory.getSslContext());
.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
RestTemplate restTemplate = new RestTemplate(requestFactory)https://stackoverflow.com/questions/60053827
复制相似问题