Search in sources :

Example 1 with Secret

use of com.github.tomakehurst.wiremock.crypto.Secret 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);
}
Also used : Secret(com.github.tomakehurst.wiremock.crypto.Secret) KeyPair(java.security.KeyPair) KeyStoreSettings(com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings) CertificateSpecification(com.github.tomakehurst.wiremock.crypto.CertificateSpecification) X509CertificateSpecification(com.github.tomakehurst.wiremock.crypto.X509CertificateSpecification) InMemoryKeyStore(com.github.tomakehurst.wiremock.crypto.InMemoryKeyStore) X509CertificateSpecification(com.github.tomakehurst.wiremock.crypto.X509CertificateSpecification) File(java.io.File) Date(java.util.Date) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) Certificate(java.security.cert.Certificate)

Example 2 with Secret

use of com.github.tomakehurst.wiremock.crypto.Secret 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;
}
Also used : Secret(com.github.tomakehurst.wiremock.crypto.Secret) KeyPair(java.security.KeyPair) CertificateSpecification(com.github.tomakehurst.wiremock.crypto.CertificateSpecification) X509CertificateSpecification(com.github.tomakehurst.wiremock.crypto.X509CertificateSpecification) InMemoryKeyStore(com.github.tomakehurst.wiremock.crypto.InMemoryKeyStore) X509CertificateSpecification(com.github.tomakehurst.wiremock.crypto.X509CertificateSpecification) File(java.io.File) Date(java.util.Date)

Aggregations

CertificateSpecification (com.github.tomakehurst.wiremock.crypto.CertificateSpecification)2 InMemoryKeyStore (com.github.tomakehurst.wiremock.crypto.InMemoryKeyStore)2 Secret (com.github.tomakehurst.wiremock.crypto.Secret)2 X509CertificateSpecification (com.github.tomakehurst.wiremock.crypto.X509CertificateSpecification)2 File (java.io.File)2 KeyPair (java.security.KeyPair)2 Date (java.util.Date)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 KeyStoreSettings (com.github.tomakehurst.wiremock.common.ssl.KeyStoreSettings)1 Certificate (java.security.cert.Certificate)1