Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. curl --cert client.cert.pem --key client.key.pem ...
  2.  
  3. final char[] JKS_PASSWORD = "password".toCharArray();
  4.  
  5. SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(
  6. new File("ssl/keystore.jks"), JKS_PASSWORD, new TrustSelfSignedStrategy()).build();
  7.  
  8. HttpClient httpsClient = HttpClients.custom().setSSLContext(sslContext).build();
  9. HttpResponse rResponse = httpsClient.execute(new HttpGet(MY_URL));
  10.  
  11. java.lang.NoSuchMethodError: org.apache.http.impl.client.HttpClientBuilder.setSSLContext(Ljavax/net/ssl/SSLContext;)Lorg/apache/http/impl/client/HttpClientBuilder;
  12.  
  13. ...
  14.  
  15. SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
  16. sslContext,
  17. new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" },
  18. null,
  19. SSLConnectionSocketFactory.getDefaultHostnameVerifier());
  20.  
  21.  
  22. HttpClient httpsClient = HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();
  23. HttpResponse rResponse = httpsClient.execute(new HttpGet(MY_URL));
  24.  
  25. 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
  26.  
  27. String keyPhrase = "your_key_there";
  28.  
  29. KeyStore keyStore = KeyStore.getInstance("PKCS12");
  30. keyStore.load(getClass().getClassLoader().getResourceAsStream("your_cert"), keyPhrase
  31. .toCharArray());
  32.  
  33. SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(keyStore, keyPhrase.toCharArray()).build();
  34.  
  35. HttpGet httpGet = new HttpGet("your_url_there");
  36.  
  37. HttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build();
  38. HttpResponse response = httpClient.execute(httpGet);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement