Search in sources :

Example 6 with KeyStoreSettings

use of com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings in project wiremock by wiremock.

the class CommandLineOptionsTest method defaultsCaKeyStorePathAndPassword.

@Test
public void defaultsCaKeyStorePathAndPassword() {
    CommandLineOptions options = new CommandLineOptions("--enable-browser-proxying");
    KeyStoreSettings caKeyStore = options.browserProxySettings().caKeyStore();
    assertThat(caKeyStore.path(), is(DEFAULT_CA_KEYSTORE_PATH));
    assertThat(caKeyStore.password(), is(DEFAULT_CA_KESTORE_PASSWORD));
    assertThat(caKeyStore.type(), is("jks"));
}
Also used : KeyStoreSettings(com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings) Test(org.junit.jupiter.api.Test)

Example 7 with KeyStoreSettings

use of com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings in project wiremock by wiremock.

the class HttpClientFactory method createClient.

public static CloseableHttpClient createClient(int maxConnections, int timeoutMilliseconds, ProxySettings proxySettings, KeyStoreSettings trustStoreSettings, boolean trustSelfSignedCertificates, final List<String> trustedHosts, boolean useSystemProperties) {
    HttpClientBuilder builder = HttpClientBuilder.create().disableAuthCaching().disableAutomaticRetries().disableCookieManagement().disableRedirectHandling().disableContentCompression().setConnectionManager(PoolingHttpClientConnectionManagerBuilder.create().setMaxConnPerRoute(maxConnections).setMaxConnTotal(maxConnections).setValidateAfterInactivity(// TODO Verify duration
    TimeValue.ofSeconds(5)).setConnectionFactory(new ManagedHttpClientConnectionFactory(null, CharCodingConfig.custom().setCharset(UTF_8).build(), null)).build()).setDefaultRequestConfig(RequestConfig.custom().setResponseTimeout(Timeout.ofMilliseconds(timeoutMilliseconds)).build()).setConnectionReuseStrategy((request, response, context) -> false).setKeepAliveStrategy((response, context) -> TimeValue.ZERO_MILLISECONDS);
    if (useSystemProperties) {
        builder.useSystemProperties();
    }
    if (proxySettings != NO_PROXY) {
        HttpHost proxyHost = new HttpHost(proxySettings.host(), proxySettings.port());
        builder.setProxy(proxyHost);
        if (!isEmpty(proxySettings.getUsername()) && !isEmpty(proxySettings.getPassword())) {
            // TODO Verify
            builder.setProxyAuthenticationStrategy(new DefaultAuthenticationStrategy());
            BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(new AuthScope(proxySettings.host(), proxySettings.port()), new UsernamePasswordCredentials(proxySettings.getUsername(), proxySettings.getPassword().toCharArray()));
            builder.setDefaultCredentialsProvider(credentialsProvider);
        }
    }
    final SSLContext sslContext = buildSslContext(trustStoreSettings, trustSelfSignedCertificates, trustedHosts);
    LayeredConnectionSocketFactory sslSocketFactory = buildSslConnectionSocketFactory(sslContext);
    PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create().setSSLSocketFactory(sslSocketFactory).build();
    builder.setConnectionManager(connectionManager);
    return builder.build();
}
Also used : SSLContext(javax.net.ssl.SSLContext) AuthScope(org.apache.hc.client5.http.auth.AuthScope) Enumeration(java.util.Enumeration) CharCodingConfig(org.apache.hc.core5.http.config.CharCodingConfig) LayeredConnectionSocketFactory(org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory) Exceptions.throwUnchecked(com.github.tomakehurst.wiremock.common.Exceptions.throwUnchecked) BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) TextUtils(org.apache.hc.core5.util.TextUtils) ManagedHttpClientConnectionFactory(org.apache.hc.client5.http.impl.io.ManagedHttpClientConnectionFactory) PoolingHttpClientConnectionManagerBuilder(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder) LocalNotifier.notifier(com.github.tomakehurst.wiremock.common.LocalNotifier.notifier) org.apache.hc.client5.http.classic.methods(org.apache.hc.client5.http.classic.methods) URI(java.net.URI) RequestConfig(org.apache.hc.client5.http.config.RequestConfig) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) java.security(java.security) HttpClientBuilder(org.apache.hc.client5.http.impl.classic.HttpClientBuilder) TimeValue(org.apache.hc.core5.util.TimeValue) UsernamePasswordCredentials(org.apache.hc.client5.http.auth.UsernamePasswordCredentials) UTF_8(java.nio.charset.StandardCharsets.UTF_8) DefaultAuthenticationStrategy(org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy) NoopHostnameVerifier(org.apache.hc.client5.http.ssl.NoopHostnameVerifier) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager) Timeout(org.apache.hc.core5.util.Timeout) SSLConnectionSocketFactory(org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory) com.github.tomakehurst.wiremock.http.ssl(com.github.tomakehurst.wiremock.http.ssl) List(java.util.List) HttpHost(org.apache.hc.core5.http.HttpHost) NO_STORE(com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings.NO_STORE) RequestMethod(com.github.tomakehurst.wiremock.http.RequestMethod) KeyStoreSettings(com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings) CloseableHttpClient(org.apache.hc.client5.http.impl.classic.CloseableHttpClient) ProxySettings(com.github.tomakehurst.wiremock.common.ProxySettings) Collections(java.util.Collections) NO_PROXY(com.github.tomakehurst.wiremock.common.ProxySettings.NO_PROXY) BasicCredentialsProvider(org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider) LayeredConnectionSocketFactory(org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory) HttpHost(org.apache.hc.core5.http.HttpHost) AuthScope(org.apache.hc.client5.http.auth.AuthScope) ManagedHttpClientConnectionFactory(org.apache.hc.client5.http.impl.io.ManagedHttpClientConnectionFactory) HttpClientBuilder(org.apache.hc.client5.http.impl.classic.HttpClientBuilder) DefaultAuthenticationStrategy(org.apache.hc.client5.http.impl.DefaultAuthenticationStrategy) SSLContext(javax.net.ssl.SSLContext) UsernamePasswordCredentials(org.apache.hc.client5.http.auth.UsernamePasswordCredentials) PoolingHttpClientConnectionManager(org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager)

Aggregations

KeyStoreSettings (com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings)7 Test (org.junit.jupiter.api.Test)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)1 BrowserProxySettings (com.github.tomakehurst.wiremock.common.BrowserProxySettings)1 Exceptions.throwUnchecked (com.github.tomakehurst.wiremock.common.Exceptions.throwUnchecked)1 LocalNotifier.notifier (com.github.tomakehurst.wiremock.common.LocalNotifier.notifier)1 ProxySettings (com.github.tomakehurst.wiremock.common.ProxySettings)1 NO_PROXY (com.github.tomakehurst.wiremock.common.ProxySettings.NO_PROXY)1 NO_STORE (com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings.NO_STORE)1 CertificateSpecification (com.github.tomakehurst.wiremock.crypto.CertificateSpecification)1 InMemoryKeyStore (com.github.tomakehurst.wiremock.crypto.InMemoryKeyStore)1 Secret (com.github.tomakehurst.wiremock.crypto.Secret)1 X509CertificateSpecification (com.github.tomakehurst.wiremock.crypto.X509CertificateSpecification)1 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)1 ResponseDefinition (com.github.tomakehurst.wiremock.http.ResponseDefinition)1 com.github.tomakehurst.wiremock.http.ssl (com.github.tomakehurst.wiremock.http.ssl)1 X509KeyStore (com.github.tomakehurst.wiremock.http.ssl.X509KeyStore)1 NoAuthenticator (com.github.tomakehurst.wiremock.security.NoAuthenticator)1 File (java.io.File)1