Search in sources :

Example 1 with KeyStoreSettings

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

the class CommandLineOptions method toString.

@Override
public String toString() {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    if (actualHttpPort != null) {
        builder.put(PORT, actualHttpPort);
    }
    if (actualHttpsPort != null) {
        builder.put(HTTPS_PORT, actualHttpsPort);
    }
    if (httpsSettings().enabled()) {
        builder.put(HTTPS_KEYSTORE, nullToString(httpsSettings().keyStorePath()));
    }
    if (!(proxyVia() == NO_PROXY)) {
        builder.put(PROXY_VIA, proxyVia());
    }
    if (proxyUrl() != null) {
        builder.put(PROXY_ALL, nullToString(proxyUrl())).put(PRESERVE_HOST_HEADER, shouldPreserveHostHeader());
    }
    BrowserProxySettings browserProxySettings = browserProxySettings();
    builder.put(ENABLE_BROWSER_PROXYING, browserProxySettings.enabled());
    if (browserProxySettings.enabled()) {
        KeyStoreSettings keyStoreSettings = browserProxySettings.caKeyStore();
        builder.put(TRUST_ALL_PROXY_TARGETS, browserProxySettings.trustAllProxyTargets());
        List<String> trustedProxyTargets = browserProxySettings.trustedProxyTargets();
        if (!trustedProxyTargets.isEmpty()) {
            builder.put(TRUST_PROXY_TARGET, Joiner.on(", ").join(trustedProxyTargets));
        }
        builder.put(HTTPS_CA_KEYSTORE, keyStoreSettings.path());
        builder.put(HTTPS_CA_KEYSTORE_TYPE, keyStoreSettings.type());
    }
    builder.put(DISABLE_BANNER, bannerDisabled());
    if (recordMappingsEnabled()) {
        builder.put(RECORD_MAPPINGS, recordMappingsEnabled()).put(MATCH_HEADERS, matchingHeaders());
    }
    builder.put(DISABLE_REQUEST_JOURNAL, requestJournalDisabled()).put(VERBOSE, verboseLoggingEnabled());
    if (jettySettings().getAcceptQueueSize().isPresent()) {
        builder.put(JETTY_ACCEPT_QUEUE_SIZE, jettySettings().getAcceptQueueSize().get());
    }
    if (jettySettings().getAcceptors().isPresent()) {
        builder.put(JETTY_ACCEPTOR_THREAD_COUNT, jettySettings().getAcceptors().get());
    }
    if (jettySettings().getRequestHeaderSize().isPresent()) {
        builder.put(JETTY_HEADER_BUFFER_SIZE, jettySettings().getRequestHeaderSize().get());
    }
    if (!(getAdminAuthenticator() instanceof NoAuthenticator)) {
        builder.put(ADMIN_API_BASIC_AUTH, "enabled");
    }
    if (getHttpsRequiredForAdminApi()) {
        builder.put(ADMIN_API_REQUIRE_HTTPS, "true");
    }
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, Object> param : builder.build().entrySet()) {
        int paddingLength = 29 - param.getKey().length();
        sb.append(param.getKey()).append(":").append(Strings.repeat(" ", paddingLength)).append(nullToString(param.getValue())).append("\n");
    }
    return sb.toString();
}
Also used : NoAuthenticator(com.github.tomakehurst.wiremock.security.NoAuthenticator) KeyStoreSettings(com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings) Map(java.util.Map)

Example 2 with KeyStoreSettings

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

the class GetCaCertTask method execute.

@Override
public ResponseDefinition execute(Admin admin, Request request, PathParams pathParams) {
    BrowserProxySettings browserProxySettings = admin.getOptions().browserProxySettings();
    KeyStoreSettings caKeyStore = browserProxySettings.caKeyStore();
    try {
        X509KeyStore x509KeyStore = new X509KeyStore(caKeyStore.loadStore(), caKeyStore.password().toCharArray());
        X509Certificate certificate = x509KeyStore.getCertificateAuthority().certificateChain()[0];
        return new ResponseDefinitionBuilder().withStatus(HTTP_OK).withHeader("Content-Type", "application/x-pem-file").withBody("-----BEGIN CERTIFICATE-----\r\n" + BASE64_ENCODER.encodeToString(certificate.getEncoded()) + "\r\n" + "-----END CERTIFICATE-----").build();
    } catch (Exception e) {
        String message = "Failed to export certificate authority cert from " + caKeyStore.path();
        admin.getOptions().notifier().error(message, e);
        return new ResponseDefinition(HTTP_INTERNAL_ERROR, message);
    }
}
Also used : ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) KeyStoreSettings(com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings) X509KeyStore(com.github.tomakehurst.wiremock.http.ssl.X509KeyStore) ResponseDefinition(com.github.tomakehurst.wiremock.http.ResponseDefinition) BrowserProxySettings(com.github.tomakehurst.wiremock.common.BrowserProxySettings) X509Certificate(java.security.cert.X509Certificate)

Example 3 with KeyStoreSettings

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

the class SslContexts method buildManInTheMiddleSslContextFactory.

public static SslContextFactory.Server buildManInTheMiddleSslContextFactory(HttpsSettings httpsSettings, BrowserProxySettings browserProxySettings, final Notifier notifier) {
    KeyStoreSettings browserProxyCaKeyStore = browserProxySettings.caKeyStore();
    SslContextFactory.Server sslContextFactory = buildSslContextFactory(notifier, browserProxyCaKeyStore, httpsSettings.keyStore());
    setupClientAuth(sslContextFactory, httpsSettings);
    return sslContextFactory;
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) KeyStoreSettings(com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings)

Example 4 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 5 with KeyStoreSettings

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

the class CommandLineOptionsTest method setsCaKeyStorePathAndPassword.

@Test
public void setsCaKeyStorePathAndPassword() {
    CommandLineOptions options = new CommandLineOptions("--enable-browser-proxying", "--ca-keystore", "/my/keystore", "--ca-keystore-password", "someotherpwd", "--ca-keystore-type", "pkcs12");
    KeyStoreSettings caKeyStore = options.browserProxySettings().caKeyStore();
    assertThat(caKeyStore.path(), is("/my/keystore"));
    assertThat(caKeyStore.password(), is("someotherpwd"));
    assertThat(caKeyStore.type(), is("pkcs12"));
}
Also used : KeyStoreSettings(com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings) Test(org.junit.jupiter.api.Test)

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