use of com.github.tomakehurst.wiremock.crypto.CertificateSpecification in project wiremock by wiremock.
the class HttpClientFactoryCertificateVerificationTest method startServerAndBuildClient.
public void startServerAndBuildClient(List<String> trustedHosts, String certificateCN, boolean validCertificate) throws Exception {
InMemoryKeyStore ks = new InMemoryKeyStore(JKS, new Secret("password"));
KeyPair keyPair = generateKeyPair();
CertificateSpecification certificateSpecification = new X509CertificateSpecification(/* version = */
V3, /* subject = */
"CN=" + certificateCN, /* issuer = */
"CN=wiremock.org", /* notBefore = */
new Date(), /* notAfter = */
new Date(System.currentTimeMillis() + (365L * 24 * 60 * 60 * 1000)));
Certificate certificate = certificateSpecification.certificateFor(keyPair);
ks.addPrivateKey("wiremock", keyPair, certificate);
File serverKeyStoreFile = File.createTempFile("wiremock-server", "jks");
ks.saveAs(serverKeyStoreFile);
server = new WireMockServer(options().httpDisabled(true).dynamicHttpsPort().keystorePath(serverKeyStoreFile.getAbsolutePath()));
server.start();
InMemoryKeyStore clientTrustStore = new InMemoryKeyStore(JKS, new Secret("password"));
if (validCertificate) {
clientTrustStore.addCertificate("wiremock", certificate);
}
File clientTrustStoreFile = File.createTempFile("wiremock-client", "jks");
clientTrustStore.saveAs(clientTrustStoreFile);
KeyStoreSettings clientTrustStoreSettings = new KeyStoreSettings(clientTrustStoreFile.getAbsolutePath(), "password", "jks");
client = HttpClientFactory.createClient(1000, 5 * 1000 * 60, NO_PROXY, clientTrustStoreSettings, /* trustSelfSignedCertificates = */
false, trustedHosts, false);
}
use of com.github.tomakehurst.wiremock.crypto.CertificateSpecification in project wiremock by wiremock.
the class ProxyResponseRendererTest method generateKeystore.
private File generateKeystore() throws Exception {
InMemoryKeyStore ks = new InMemoryKeyStore(InMemoryKeyStore.KeyStoreType.JKS, new Secret("password"));
CertificateSpecification certificateSpecification = new X509CertificateSpecification(/* version = */
V3, /* subject = */
"CN=localhost", /* issuer = */
"CN=wiremock.org", /* notBefore = */
new Date(), /* notAfter = */
new Date(System.currentTimeMillis() + (365L * 24 * 60 * 60 * 1000)));
KeyPair keyPair = generateKeyPair();
ks.addPrivateKey("wiremock", keyPair, certificateSpecification.certificateFor(keyPair));
File keystoreFile = File.createTempFile("wiremock-test", "keystore");
ks.saveAs(keystoreFile);
return keystoreFile;
}
Aggregations