1

I have a client which sends handshake request to wiremock by specifying TLS 1.2 but wiremock replies back with TLS version 1.0. How Do I get wiremock to use version 1.2

1 Answers1

4

Did you ever find out how to make WireMock use TLS 1.2?

EDIT: To set up a WireMock that only supports TLS 1.2 you have to implement your own HttpServerFactory that builds an instance of your custom HttpServer. The WireMock setup would be something like this:

WireMockServer server = new WireMockServer(
    WireMockConfiguration.options()
        .httpServerFactory(new CustomHttpServerFactory())
        .dynamicHttpsPort()
        .dynamicPort());

ORIGINAL: I found that the standard WireMock implementation uses the JettyHttpServerFactory which looks for the following classes: com.github.tomakehurst.wiremock.jetty94.Jetty94HttpServer and com.github.tomakehurst.wiremock.jetty92.Jetty92HttpServer. If one of them are found, it creates an instance of the class.

The Jetty94HttpStarter has higher precedence than the Jetty92HttpStarter.

My solution was to create a copy of the Jetty92HttpServer and place it in the com.github.tomakehurst.wiremock.jetty92 package in my project.

package com.github.tomakehurst.wiremock.jetty92;

import com.github.tomakehurst.wiremock.core.Options;
import com.github.tomakehurst.wiremock.http.AdminRequestHandler;
import com.github.tomakehurst.wiremock.http.StubRequestHandler;
import com.github.tomakehurst.wiremock.jetty9.JettyHttpServer;
import com.github.tomakehurst.wiremock.servlet.MultipartRequestConfigurer;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Jetty92HttpServer extends JettyHttpServer {
    private final Logger logger = LoggerFactory.getLogger(JettyStarter.class);

    public Jetty92HttpServer(final Options options, final AdminRequestHandler adminRequestHandler, final StubRequestHandler stubRequestHandler) {
        super(options, adminRequestHandler, stubRequestHandler);
    }

    @Override
    public SslContextFactory buildSslContextFactory() {
        logger.debug("Creates CustomizedSslContextFactory");
        final SslContextFactory factory = new CustomizedSslContextFactory();

        logger.debug("Exclude protocols TLS, TLSv1 and TLSv1.1");
        factory.addExcludeProtocols("TLS", "TLSv1", "TLSv1.1");

        logger.debug("Set protocol=TLSv1.2");
        factory.setProtocol("TLSv1.2");

        return factory;
    }

    @Override
    public MultipartRequestConfigurer buildMultipartRequestConfigurer() {
        return new Jetty92MultipartRequestConfigurer();
    }
}

I know that this works for Java 7, and it should work for Java 8. However, I'm unsure if it works with Java 9 and above, but I think it should work as expected.

I recommend the following SO posts as they contain some links that helped me:

HJahre
  • 61
  • 1
  • 6