У меня есть соединение ssl (двухстороннее рукопожатие), и я не могу понять, почему следующие процедуры кода 400 (openJdk 11, файл p12 и пароль, предоставленные сервером, файл cer, предоставленный сервером),
Я создал файл jks из файла cer с помощью следующей команды:
keytool -importcert -file example-api.cer -keystore example-api.jks
Код
File keyFile = new File(Objects.requireNonNull(exampleController.class.getClassLoader().
getResource("example-client-api1.p12")).getFile());
File trustFile = new File(Objects.requireNonNull(exampleController.class.getClassLoader().
getResource("example-api.jks")).getFile());
KeyStore keyStore = KeyStore.getInstance("PKCS12");
try(FileInputStream inStream = new FileInputStream(keyFile)) {
keyStore.load(inStream, "password".toCharArray());
}
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(trustFile, "password".toCharArray() ,new TrustAllStrategy()).
loadKeyMaterial(keyStore , "password".toCharArray()).build();
HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
SSLConnectionSocketFactory socketFactory =
new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
CloseableHttpClient httpclient = HttpClients.custom()
.setSSLHostnameVerifier(hostnameVerifier)
.setSSLSocketFactory(socketFactory)
.useSystemProperties()
.build();
HttpGet httpget = new HttpGet("https://example-api/link?token=@Secret_Token@");
System.out.println("executing request" + httpget.getRequestLine());
return httpclient.execute(httpget);
Приведенный выше код всегда возвращает 400 (не требуется сертификат SSL былотправлено).
, но работает следующий curl (на IOS):
curl https://example-api/link?token=@secret_token@ --cacert ./example-api-ca.crt --cert ./example-client-api1.p12:password
Любая помощь будет принята с благодарностью