Я новичок в ssl в java и мне нужна помощь. Моему приложению необходимо вызвать сервер поставщика платежей с предоставленными им сертификатами и моим ключом publi c.
Что я сделал: 1. создал закрытый ключ и ключ publi c с использованием openssl и предоставил publi c ключ к поставщику услуг (серверу) 2. полученный файл сертификата (crt) с сервера 3. создал файл jks с помощью keytool 4. добавил файл сертификата в хранилище доверенных сертификатов 5. импортировал файл хранилища ключей в мою весеннюю загрузку application.
мой код:
final String password = "password";
SSLContext sslContext = SSLContextBuilder
.create()
.loadTrustMaterial(ResourceUtils.getFile("/home/workspace/gop/javaclient.jks"), password.toCharArray())
.build();
CloseableHttpClient client = HttpClients.custom()
.setSSLContext(sslContext)
.build();
HttpComponentsClientHttpRequestFactory requestFactory
= new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(client);
RestTemplate restTemplate = new RestTemplate(requestFactory);
String url = "https://someurl.com/rndpoint"; // Web Service endpoint that requires SSL
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, HttpEntity.EMPTY, String.class);
ResponseEntity<String> response2 = restTemplate.exchange(url, HttpMethod.GET, HttpEntity.EMPTY, String.class);
System.out.println("Result = " + response.getBody());
return response.getBody() + response2.getBody();
Я дважды проверил, и я наверняка импортировал сертификат в cacerts.
Мой вывод:
{
"timestamp": "2020-04-19T08:28:18.871+0000",
"status": 500,
"error": "Internal Server Error",
"message": "I/O error on POST request for \"https://nabiltest.compassplus.com:8444/Exec\":
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to
requested target",
"path": "/nabil-payment"
}