1

I'm trying to create a JVM HTTP client which will not send server_name in the Client Handshake (long story, but I'm simulating a legacy system which doesn't support SNI).

Setting the serverNames SSLParameters doesn't do the trick, I can still see the "Server Name Indication extension" in Wireshark.

fun run() {
    val keyStore = keyStore()
    val trustFactory =
        TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
    trustFactory.init(keyStore)
    val sslContext = SSLContext.getInstance("SSL")
    sslContext.init(null, trustFactory.trustManagers, null)

    val httpClient = HttpClient.newBuilder()
        .sslContext(sslContext)
        .sslParameters(sslContext.defaultSSLParameters.apply {
            serverNames = null
        })
        .build()

    val request = HttpRequest.newBuilder()
        .uri(URI.create("https://example.com/hello"))
        .GET()
        .build()

    httpClient.send(request, HttpResponse.BodyHandlers.ofString())
}

Full code in this gist.

How can I stop the client from sending the SNI extension?

Niel de Wet
  • 7,806
  • 9
  • 63
  • 100

1 Answers1

1

If you don't mind the setting applying to the whole JVM, try

jsse.enableSNIExtension=false
Kevin Boone
  • 4,092
  • 1
  • 11
  • 15