Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- curl --cert client.cert.pem --key client.key.pem ...
- final char[] JKS_PASSWORD = "password".toCharArray();
- SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(
- new File("ssl/keystore.jks"), JKS_PASSWORD, new TrustSelfSignedStrategy()).build();
- HttpClient httpsClient = HttpClients.custom().setSSLContext(sslContext).build();
- HttpResponse rResponse = httpsClient.execute(new HttpGet(MY_URL));
- java.lang.NoSuchMethodError: org.apache.http.impl.client.HttpClientBuilder.setSSLContext(Ljavax/net/ssl/SSLContext;)Lorg/apache/http/impl/client/HttpClientBuilder;
- ...
- SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
- sslContext,
- new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" },
- null,
- SSLConnectionSocketFactory.getDefaultHostnameVerifier());
- HttpClient httpsClient = HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();
- HttpResponse rResponse = httpsClient.execute(new HttpGet(MY_URL));
- 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
- String keyPhrase = "your_key_there";
- KeyStore keyStore = KeyStore.getInstance("PKCS12");
- keyStore.load(getClass().getClassLoader().getResourceAsStream("your_cert"), keyPhrase
- .toCharArray());
- SSLContext sslContext = SSLContexts.custom().loadKeyMaterial(keyStore, keyPhrase.toCharArray()).build();
- HttpGet httpGet = new HttpGet("your_url_there");
- HttpClient httpClient = HttpClients.custom().setSSLContext(sslContext).build();
- HttpResponse response = httpClient.execute(httpGet);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement