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();
}
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);
}
}
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;
}
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"));
}
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"));
}
Aggregations