Note: this question has been asked numerous times for Java HTTPS clients; my question is about configuring a server.
I'm trying to use MockWebServer to test my OkHttpClient configuration. The real web server my code hits just dropped TLS v1.0 support, so I'm changing my code to use TLS v1.2 and use the server's preferred cipher suites. I'd like to test this change with an in-memory web server that mimics the real server, but I can't figure out how to configure a SSLContext
in my test with a specific list of cipher suites. (All the methods I need to access are pretty well protected inside of SSLContextImpl
and its inner classes.)
The best I've been able to figure out is completely wrapping a SSLServerSocketFactory, overriding the 4 createServerSocket() methods, and calling setEnabledCipherSuites()
on the SSLServerSocket
before returning it, similar to how this answer did with SSLSocketFactoryEx on the client: https://stackoverflow.com/a/23365536/278800
It's frustrating that using a specific TLS version is as simple as calling e.g. SSLContext.getInstance("TLSv1.2")
, but there isn't a similarly easy way to configure the cipher suites.