0

I use PFX file in postman like this but I want to use in spring boot as like postman.`

I tried:

System.setProperty("javax.net.ssl.trustStore", AccessTokenService.class.getClassLoader().getResource("security/XXX.pfx").getFile());
System.setProperty("javax.net.ssl.trustStorePassword", "XXX");
System.setProperty("javax.net.ssl.keyStore", AccessTokenService.class.getClassLoader().getResource("security/XXX.pfx").getFile());
System.setProperty("javax.net.ssl.keyStorePassword", "XXX");

and

System.setProperty("javax.net.ssl.trustStore", "C:/XX/XX.pfx");
System.setProperty("javax.net.ssl.trustStorePassword", "XXX");
System.setProperty("javax.net.ssl.keyStore", "C:/XX/XX.pfx");
System.setProperty("javax.net.ssl.keyStorePassword", "XXX");
final String allPassword = "XXX";
TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
SSLContext sslContext = SSLContextBuilder
    .create()
    .loadKeyMaterial(ResourceUtils.getFile("classpath:XX.pfx"),
                     allPassword.toCharArray(), allPassword.toCharArray())
    //.loadTrustMaterial(ResourceUtils.getFile("classpath:XX.jks"), allPassword.toCharArray())
    .loadTrustMaterial(null, acceptingTrustStrategy)
    .build();
HttpClient client = HttpClients.custom()
    .setSSLContext(sslContext)
    .build();
HttpComponentsClientHttpRequestFactory requestFactory =
    new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(client);
RestTemplate restTemplate = new RestTemplate(requestFactory);
return restTemplate;

but

I/O error on GET request for "https://XX.bkm.com.tr/oauth-provider/": Connect to XX.com.tr:443 [XX.com.tr/XX.XXX.XXX.55] failed: Connection timed out: connect

I can telnet XX.XXX.XXX.55 443 and when use postman with client sertificate everytinhs successfull but when I use spring boot I am getting Connection Timed out

K.Mat
  • 1,341
  • 11
  • 17
  • "Connection timed out" is a network-level error and has nothing to do with your use of certificates. Is this Java on the same machine as the postman and telnet? Is there any kind of firewall on your system or in your network (although that usually should affect telnet too)? Are you using any kind of virtualization like docker or WSL? – dave_thompson_085 Jul 19 '23 at 14:16

0 Answers0