You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Javalin Support for Server Name Indication (SNI) #2596
Javalin does not seem to support SNI, even though the embedded Web Server Jetty does.
By "support SNI", I mean when the configured KeyStore contains multiple certificates, each for a different CN, the correct certificate should be returned to the client during the TLS handshake (assuming the client supports SNI).
In my tests with a Keystore with two certificates, the second certificate is always returned, regardless of which one the client requests.
The client is using SNI i.e. the Server Name Extension is present in the TLS Handshake ClientHello message.
When I debug, the SslContextFactory.Server constructor is called, but isSniRequired() is not called and defaults to false.
Creating the SslContext, is handled by nl.altindag.ssl.jetty.util.JettySslUtils which is part of ssl-content-kickstart-for-jetty
There is a java system property for sniRequired that I have set to true: -Djetty.sslContext.sniRequired=true
I have also set this one to true, but I don't think it is relevant to Jetty -Djsse.enableSNIExtension=true
The only SNI relevant property documented for Javalin is sniHostCheck. This does NOT enable / disable SNI. Instead it validates (or not) if the correct servername+port is present in the Http Request "Host" header.
Hi! I am having a look at this. SNI should work OOTB, the -Djetty.sslContext.sniRequired=true variable only enables the requirement to use SNI at TLS level, not the actual implementation:
When jetty.sslContext.sniRequired=true, clients that don’t send a valid SNI receive a TLS failure, and their attempt to connect to the server fails. The details of this failure may not be reported and could be difficult to figure out that the failure is related to an invalid SNI.
In any case, Javalin does not implement any virtual host/virtual domain, therefore SNI is not significantly useful when multiple certificates are there, except if you reuse the same keystore across multiple instances.
Sorry for not getting back to you sooner: a weekend, a Swiss public holiday Monday, and a heatwave got in the way!
At the moment we don't have a specific use-case. Instead we are trying to fully understand SNI from every direction.
Our application servers (which embed Javalin + Jetty) are highly integrated, and in the case of Http act in both client and server roles.
i.e. in addition to Javalin in the Http Server role we have multiple Http Clients, both the Apache Http Client called from our own code, and those embedded in 3rd Party libs such as Confluent or Nimbus OIDC.
Seemingly every 18 months or so we get hit by strange issues that turn out to be SNI related. This can happen either when we are calling something, or something is calling us.
For instance when we moved from Spark for Java + Jetty 9.x to Javalin + Jetty 11.x we rapidly discovered that we had to set sniHostCheck=false on some of our Javalin instances to support the 3rd party Clients calling those interfaces.
More recently the Http Client embedded in the Kafka Confluent jars could not access the Confluent Schema Registry fronted by a Kubernetes Http Ingress via Http Rest, even though other instances could.
The cause? The application server hosting that Http Client had (inadvertently) -Djsse.enableSNIExtension=false. This meant that the Kubernetes Ingress Controller returned the "Kubernetes Ingress Fake Certificate" during the TLS handshake rather than the expected one for the Schema Registry.
Focusing on Javalin + Jetty, the first thing for us is to clearly understand the extent of Javalin's support for SNI.
As for a concrete use-case, I think you have hit the nail on the head.
Most of our customers run multiple instances of our application server.
These are spread across multiple Linux Virtual Machines, with each VM hosting multiple instances of our app server.
It is possible that they may want to give the app server multiple DNS Hostnames, with each Hostname used by a different App Server instance.
... with a common Keystore per VM, holding all the certificates for that VM.
On reflection, that use case might be a little far fetched, but if it is not supported, then I would prefer to know and document this upfront.
And one instance of our app server can even host multiple Javalin instances, if so configured.
Hi @zugazagoitia, I think the reporter is right: with multiple certs in one keystore the plugin seems to always serve the same one, since SSLUtils loads the keystore as a single identity (if I'm reading it right). From a quick test, ayza picks correctly if each cert is added as its own identity with a route, so it might be fixable. Do you plan to look into this, or should we close it and document the limitation?
I am having a look with Claude's help. I see no reason why we shouldn't support it, let's see if I can come up with some quick way to tackle it bringing minimal change.
#2688 adds a public keyManager(...) loader, so you can build a key manager with ayza, with one identity per certificate and a route per hostname, and pass it to the plugin:
Activity
zugazagoitia commentedon May 23, 2026
Hi! I am having a look at this. SNI should work OOTB, the
-Djetty.sslContext.sniRequired=truevariable only enables the requirement to use SNI at TLS level, not the actual implementation:In any case, Javalin does not implement any virtual host/virtual domain, therefore SNI is not significantly useful when multiple certificates are there, except if you reuse the same keystore across multiple instances.
What is your use case here?
FlyingSheepOnSailfish commentedon May 25, 2026
Hi Alberto
Sorry for not getting back to you sooner: a weekend, a Swiss public holiday Monday, and a heatwave got in the way!
At the moment we don't have a specific use-case. Instead we are trying to fully understand SNI from every direction.
Our application servers (which embed Javalin + Jetty) are highly integrated, and in the case of Http act in both client and server roles.
i.e. in addition to Javalin in the Http Server role we have multiple Http Clients, both the Apache Http Client called from our own code, and those embedded in 3rd Party libs such as Confluent or Nimbus OIDC.
Seemingly every 18 months or so we get hit by strange issues that turn out to be SNI related. This can happen either when we are calling something, or something is calling us.
For instance when we moved from Spark for Java + Jetty 9.x to Javalin + Jetty 11.x we rapidly discovered that we had to set
sniHostCheck=falseon some of our Javalin instances to support the 3rd party Clients calling those interfaces.More recently the Http Client embedded in the Kafka Confluent jars could not access the Confluent Schema Registry fronted by a Kubernetes Http Ingress via Http Rest, even though other instances could.
The cause? The application server hosting that Http Client had (inadvertently)
-Djsse.enableSNIExtension=false. This meant that the Kubernetes Ingress Controller returned the "Kubernetes Ingress Fake Certificate" during the TLS handshake rather than the expected one for the Schema Registry.Focusing on Javalin + Jetty, the first thing for us is to clearly understand the extent of Javalin's support for SNI.
As for a concrete use-case, I think you have hit the nail on the head.
Most of our customers run multiple instances of our application server.
These are spread across multiple Linux Virtual Machines, with each VM hosting multiple instances of our app server.
It is possible that they may want to give the app server multiple DNS Hostnames, with each Hostname used by a different App Server instance.
... with a common Keystore per VM, holding all the certificates for that VM.
On reflection, that use case might be a little far fetched, but if it is not supported, then I would prefer to know and document this upfront.
And one instance of our app server can even host multiple Javalin instances, if so configured.
Just for fun here is an example of a Netty Server supporting SNI + keystore with multiple certs. I stumbled on this by chance while googling SNI + multiple certs.
tipsy commentedon Oct 24, 2026
Hi @zugazagoitia, I think the reporter is right: with multiple certs in one keystore the plugin seems to always serve the same one, since
SSLUtilsloads the keystore as a single identity (if I'm reading it right). From a quick test, ayza picks correctly if each cert is added as its own identity with a route, so it might be fixable. Do you plan to look into this, or should we close it and document the limitation?zugazagoitia commentedon Oct 26, 2026
I am having a look with Claude's help. I see no reason why we shouldn't support it, let's see if I can come up with some quick way to tackle it bringing minimal change.
zugazagoitia commentedon Oct 26, 2026
Hi! Let us know if the following works for you @FlyingSheepOnSailfish
#2688 adds a public
keyManager(...)loader, so you can build a key manager with ayza, with one identity per certificate and a route per hostname, and pass it to the plugin:This works with PEM, P12 and JKS files, mixed RSA/EC certificates, TLS 1.2/1.3 and hot reload.
Current limits from ayza:
:443).*.example.com) can't be routed.example.comandapi.example.com), since hostnames are matched by substring.Docs: javalin/website#320
FYI: For your Kafka/ingress case:
jsse.enableSNIExtensiononly controls whether a client sends SNI. It doesn't affect Javalin as a server.[ssl] Add a public keyManager loader to serve multiple certificates b…