use of com.github.tomakehurst.wiremock.http.ssl.X509KeyStore in project wiremock by wiremock.
the class SslContexts method buildKeyStore.
private static X509KeyStore buildKeyStore(KeyStoreSettings browserProxyCaKeyStore) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, CertificateGenerationUnsupportedException {
final CertificateAuthority certificateAuthority = CertificateAuthority.generateCertificateAuthority();
KeyStore keyStore = KeyStore.getInstance(browserProxyCaKeyStore.type());
char[] password = browserProxyCaKeyStore.password().toCharArray();
keyStore.load(null, password);
keyStore.setKeyEntry("wiremock-ca", certificateAuthority.key(), password, certificateAuthority.certificateChain());
browserProxyCaKeyStore.getSource().save(keyStore);
return new X509KeyStore(keyStore, password);
}
use of com.github.tomakehurst.wiremock.http.ssl.X509KeyStore 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.http.ssl.X509KeyStore in project wiremock by wiremock.
the class HttpsBrowserProxyAcceptanceTest method certificateAuthorityCertCanBeDownloaded.
@Test
@DisabledForJreRange(min = JRE.JAVA_17, disabledReason = "does not support generating certificates at runtime")
public void certificateAuthorityCertCanBeDownloaded() throws Exception {
WireMockTestClient proxyTestClient = new WireMockTestClient(proxy.getPort());
WireMockResponse certResponse = proxyTestClient.get("/__admin/certs/wiremock-ca.crt");
assertEquals(200, certResponse.statusCode());
assertEquals("application/x-pem-file", certResponse.firstHeader("Content-Type"));
Certificate cert = decode(certResponse.content());
X509KeyStore keyStore = new X509KeyStore(HttpsAcceptanceTest.readKeyStore(NO_PREEXISTING_KEYSTORE_PATH, "password"), "password".toCharArray());
assertEquals(keyStore.getCertificateAuthority().certificateChain()[0], cert);
}
Aggregations