private void addSSLConfiguration(ClientBuilder clientBuilder) { try { if (systemSSL) { clientBuilder.sslContext(SSLContext.getDefault()); } else if (trustStoreFileName != null) { KeyStore trustStore = KeyStore.getInstance(KEY_STORE_TYPE); FileInputStream fin = new FileInputStream(trustStoreFileName); trustStore.load(fin, trustStorePassword.toCharArray()); clientBuilder.trustStore(trustStore); } else if (sslContext != null) { clientBuilder.sslContext(sslContext); } } catch (Exception ex) { throw new IllegalArgumentException("Cannot setup SSL for Jersey2 client", ex); } }
public HttpClientBuilder trustStore(String trustStoreName) { delegate.trustStore(namedTrustStore(trustStoreName)); return this; } }
/** * Registers the trust store. * * @param trustStore the trust store * @return the builder instance */ public ClientBuilderConfigurer trustStore(KeyStore trustStore) { builder().trustStore(trustStore); return this; }
private void addSSLConfiguration(ClientBuilder clientBuilder) { try { if (systemSSL) { clientBuilder.sslContext(SSLContext.getDefault()); } else if (trustStoreFileName != null) { KeyStore trustStore = KeyStore.getInstance(KEY_STORE_TYPE); FileInputStream fin = new FileInputStream(trustStoreFileName); trustStore.load(fin, trustStorePassword.toCharArray()); clientBuilder.trustStore(trustStore); } else if (sslContext != null) { clientBuilder.sslContext(sslContext); } } catch (Exception ex) { throw new IllegalArgumentException("Cannot setup SSL for Jersey2 client", ex); } }
@Override public HttpClientBuilder newBuilder() { ClientBuilder builderDelegate = ClientBuilder.newBuilder().withConfig(config); if (trustStore != null) { builderDelegate.trustStore(trustStore); } return new DefaultHttpClientBuilder(builderDelegate); }
/** * Create custom client with specific keystores. * * @param clientKeyStore Client (BOT) keystore file * @param clientKeyStorePass Client (BOT) keystore password * @param trustStore Truststore file * @param trustStorePass Truststore password * @return Custom HttpClient * @throws Exception Generally IOExceptions thrown from instantiation. */ public static Client getClient(String clientKeyStore, String clientKeyStorePass, String trustStore, String trustStorePass) throws Exception { KeyStore cks = KeyStore.getInstance("PKCS12"); KeyStore tks = KeyStore.getInstance("JKS"); loadKeyStore(cks, clientKeyStore, clientKeyStorePass); loadKeyStore(tks, trustStore, trustStorePass); return ClientBuilder.newBuilder().keyStore(cks, clientKeyStorePass.toCharArray()).trustStore(tks).build(); }
/** * Create custom client with specific keystores. * * @param clientKeyStore Client (BOT) keystore * @param clientKeyStorePass Client (BOT) keystore password * @param trustStore Truststore * @param trustStorePass Truststore password * @param clientConfig - HttpClient configuration to use when constructing the client * @return Custom HttpClient * @throws Exception Generally IOExceptions thrown from instantiation. */ public static Client getClient(KeyStore clientKeyStore, String clientKeyStorePass, KeyStore trustStore, String trustStorePass, ClientConfig clientConfig) throws Exception { return ClientBuilder.newBuilder().keyStore(clientKeyStore, clientKeyStorePass.toCharArray()).trustStore(trustStore).withConfig(clientConfig).build(); }
/** * Create custom client with specific keystores. * * @param clientKeyStore Client (BOT) keystore file * @param clientKeyStorePass Client (BOT) keystore password * @param trustStore Truststore file * @param trustStorePass Truststore password * @return Custom HttpClient * @throws Exception Generally IOExceptions thrown from instantiation. */ public static Client getClient(String clientKeyStore, String clientKeyStorePass, String trustStore, String trustStorePass) throws Exception { KeyStore cks = KeyStore.getInstance("PKCS12"); KeyStore tks = KeyStore.getInstance("JKS"); loadKeyStore(cks, clientKeyStore, clientKeyStorePass); loadKeyStore(tks, trustStore, trustStorePass); return ClientBuilder.newBuilder().keyStore(cks, clientKeyStorePass.toCharArray()).trustStore(tks).build(); }
/** * Create custom client with specific keystores. * * @param clientKeyStore Client (BOT) keystore * @param clientKeyStorePass Client (BOT) keystore password * @param trustStore Truststore * @param trustStorePass Truststore password * @param clientConfig - HttpClient configuration to use when constructing the client * @return Custom HttpClient * @throws Exception Generally IOExceptions thrown from instantiation. */ public static Client getClient(KeyStore clientKeyStore, String clientKeyStorePass, KeyStore trustStore, String trustStorePass, ClientConfig clientConfig) throws Exception { return ClientBuilder.newBuilder().keyStore(clientKeyStore, clientKeyStorePass.toCharArray()).trustStore(trustStore).withConfig(clientConfig).build(); }
private static WebTarget createDockerTarget(final String dockerApiRoot) { String encrypted = System.getenv(ENV_DOCKER_TLS_VERIFY); if (!"1".equals(encrypted)) { return ClientBuilder.newClient() .target("http://" + dockerApiRoot); } Security.addProvider(new BouncyCastleProvider()); String certPath = System.getenv("DOCKER_CERT_PATH"); if (certPath == null) { certPath = System.getProperty("USER_HOME") + File.separator + ".docker"; } ensureThatCertificatesExist(certPath); KeyStore keyStore; KeyStore trustStore; try { keyStore = HttpsHelper.createKeyStore(certPath); trustStore = HttpsHelper.createTrustStore(certPath); } catch (Exception e) { throw new DockerException("Can't load docker certificates", e); } return ClientBuilder.newBuilder() .keyStore(keyStore, HttpsHelper.KEYSTORE_PWD) .trustStore(trustStore) .build() .target("https://" + dockerApiRoot); }
public static <T> ClientWrapper<T> httpsInstance(KeyStore keystore, KeyStore truststore, String password, HostnameVerifier hostnameVerifier, Class<T> resultClass) { Client client = ClientBuilder.newBuilder().trustStore(truststore).keyStore(keystore, password.toCharArray()). hostnameVerifier(hostnameVerifier).build(); return new ClientWrapper(client, resultClass); }
private void setTrustStore(ClientBuilder clientBuilder, DACConfig dacConfig) throws IOException, GeneralSecurityException { Optional<KeyStore> trustStore = Optional.empty(); if (checkCertificates) { trustStore = new SSLConfigurator(dacConfig.getConfig(), DremioConfig.WEB_SSL_PREFIX, "web").getTrustStore(); if (trustStore.isPresent()) { clientBuilder.trustStore(trustStore.get()); } } else { SSLContext sslContext = SSLHelper.newAllTrustingSSLContext("SSL"); HostnameVerifier verifier = SSLHelper.newAllValidHostnameVerifier(); clientBuilder.hostnameVerifier(verifier); clientBuilder.sslContext(sslContext); } }
.trustStore(trustStore) .hostnameVerifier(InsecureHostnameVerifier.INSTANCE) .build();
@Before public void createClient() throws Exception { final KeyStore trustStore = KeyStore.getInstance("JKS"); trustStore.load(keystore.openStream(), PASSWORD.toCharArray()); client = JaxRsClientFactory.testBuilder() .trustStore(trustStore) .build(); }
bld.trustStore(trust);
protected static void initClient(final String hostname) { client = ClientBuilder.newBuilder() .trustStore(currentDremioDaemon.getWebServer().getTrustStore()) .register(MultiPartFeature.class) .build(); apiV2 = client .target(String.format("https://%s:%d", hostname, currentDremioDaemon.getWebServer().getPort())) .path("apiv2"); }
@Test public void testGetBook() throws Exception { ClientBuilder builder = ClientBuilder.newBuilder(); try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", this.getClass())) { KeyStore trustStore = loadStore(keystore, "password"); builder.trustStore(trustStore); } builder.hostnameVerifier(new AllowAllHostnameVerifier()); try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Morpit.jks", this.getClass())) { KeyStore keyStore = loadStore(keystore, "password"); builder.keyStore(keyStore, "password"); } Client client = builder.build(); client.register(new LoggingFeature()); WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123"); Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class); assertEquals(123, b.getId()); }