Skip to content

Commit e51eb4e

Browse files
committed
Add configurable TLS protocol versions
1 parent 704ee92 commit e51eb4e

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

docs/guides/implementing-mutual-tls.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ object ServerApp extends ZIOAppDefault {
182182
),
183183
includeClientCert = false,
184184
clientAuth = Some(ClientAuth.Required),
185+
protocols = Seq("TLSv1.3", "TLSv1.2"),
185186
)
186187

187188
private val serverConfig =
@@ -201,6 +202,8 @@ Please note that we enabled the `ClientAuth.Required` option in the SSL configur
201202

202203
If we want to access the client certificate, we can enable the `includeClientCert` option in the SSL configuration. This allows us to access the client certificate via `req.remoteCertificate` in the request handler.
203204

205+
The `protocols` parameter in `SSLConfig` allows configuring supported TLS protocol versions. This is useful for disabling older protocol versions for security reasons.
206+
204207
### Client Implementation
205208

206209
Similarly, the client implementation for mTLS requires both a keystore (containing the client's certificate and private key) and a truststore (containing the CA certificate used to verify the server's certificate). The client will automatically send its certificate during the TLS handshake if configured correctly:

project/MimaSettings.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ object MimaSettings {
4343
ProblemFilters.exclude[MissingClassProblem]("zio.http.netty.NettyHeaderEncoding"),
4444
ProblemFilters.exclude[MissingClassProblem]("zio.http.netty.NettyHeaderEncoding$"),
4545
exclude[Problem]("zio.http.template2.*"),
46+
ProblemFilters.exclude[DirectMissingMethodProblem]("zio.http.SSLConfig.apply"),
47+
ProblemFilters.exclude[DirectMissingMethodProblem]("zio.http.SSLConfig.copy"),
48+
ProblemFilters.exclude[DirectMissingMethodProblem]("zio.http.SSLConfig.this"),
49+
ProblemFilters.exclude[DirectMissingMethodProblem]("zio.http.SSLConfig.fromJavaxNetSsl"),
50+
ProblemFilters.exclude[DirectMissingMethodProblem]("zio.http.SSLConfig.fromJavaxNetSslKeyStoreResource"),
51+
ProblemFilters.exclude[DirectMissingMethodProblem]("zio.http.SSLConfig.fromJavaxNetSslKeyStoreFile"),
52+
ProblemFilters.exclude[DirectMissingMethodProblem]("zio.http.SSLConfig.fromResource"),
53+
ProblemFilters.exclude[DirectMissingMethodProblem]("zio.http.SSLConfig.fromFile"),
4654
),
4755
mimaFailOnProblem := failOnProblem,
4856
)

zio-http/jvm/src/main/scala/zio/http/netty/server/ServerSSLDecoder.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private[netty] object SSLUtil {
5252
clientAuthConfig.foreach(ca => self.clientAuth(getClientAuth(ca)))
5353
self
5454
.sslProvider(toNettyProvider(sslConfig.provider))
55+
.protocols(sslConfig.protocols: _*)
5556
.applicationProtocolConfig(
5657
new ApplicationProtocolConfig(
5758
Protocol.ALPN,

zio-http/shared/src/main/scala/zio/http/SSLConfig.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ final case class SSLConfig(
3636
provider: Provider,
3737
clientAuth: Option[ClientAuth] = None,
3838
includeClientCert: Boolean = false,
39+
protocols: Seq[String] = Seq("TLSv1.3", "TLSv1.2"),
3940
)
4041

4142
object SSLConfig {
@@ -68,13 +69,15 @@ object SSLConfig {
6869
clientAuth: Option[ClientAuth] = None,
6970
trustCertCollectionPath: Option[String] = None,
7071
includeClientCert: Boolean = false,
72+
protocols: Seq[String] = Seq("TLSv1.3", "TLSv1.2"),
7173
): SSLConfig =
7274
new SSLConfig(
7375
behaviour,
7476
Data.FromFile(certPath, keyPath, trustCertCollectionPath),
7577
Provider.JDK,
7678
clientAuth,
7779
includeClientCert,
80+
protocols,
7881
)
7982

8083
def fromResource(certPath: String, keyPath: String): SSLConfig =
@@ -90,13 +93,15 @@ object SSLConfig {
9093
clientAuth: Option[ClientAuth] = None,
9194
trustCertCollectionPath: Option[String] = None,
9295
includeClientCert: Boolean = false,
96+
protocols: Seq[String] = Seq("TLSv1.3", "TLSv1.2"),
9397
): SSLConfig =
9498
new SSLConfig(
9599
behaviour,
96100
Data.FromResource(certPath, keyPath, trustCertCollectionPath),
97101
Provider.JDK,
98102
clientAuth,
99103
includeClientCert,
104+
protocols,
100105
)
101106

102107
def fromJavaxNetSslKeyStoreFile(
@@ -107,6 +112,7 @@ object SSLConfig {
107112
trustManagerKeyStore: Option[Data.TrustManagerKeyStore] = None,
108113
clientAuth: Option[ClientAuth] = None,
109114
includeClientCert: Boolean = false,
115+
protocols: Seq[String] = Seq("TLSv1.3", "TLSv1.2"),
110116
): SSLConfig =
111117
new SSLConfig(
112118
behaviour,
@@ -119,6 +125,7 @@ object SSLConfig {
119125
Provider.JDK,
120126
clientAuth,
121127
includeClientCert,
128+
protocols,
122129
)
123130

124131
def fromJavaxNetSslKeyStoreFile(keyManagerFile: String, keyManagerPassword: Secret): SSLConfig =
@@ -131,6 +138,7 @@ object SSLConfig {
131138
trustManagerKeyStore: Option[Data.TrustManagerKeyStore] = None,
132139
clientAuth: Option[ClientAuth] = None,
133140
includeClientCert: Boolean = false,
141+
protocols: Seq[String] = Seq("TLSv1.3", "TLSv1.2"),
134142
): SSLConfig = {
135143
fromJavaxNetSsl(
136144
Data.FromJavaxNetSsl(
@@ -142,6 +150,7 @@ object SSLConfig {
142150
HttpBehaviour.Redirect,
143151
clientAuth,
144152
includeClientCert,
153+
protocols,
145154
)
146155
}
147156

@@ -150,13 +159,15 @@ object SSLConfig {
150159
behaviour: HttpBehaviour = HttpBehaviour.Redirect,
151160
clientAuth: Option[ClientAuth] = None,
152161
includeClientCert: Boolean = false,
162+
protocols: Seq[String] = Seq("TLSv1.3", "TLSv1.2"),
153163
): SSLConfig =
154164
new SSLConfig(
155165
behaviour,
156166
data,
157167
Provider.JDK,
158168
clientAuth,
159169
includeClientCert,
170+
protocols,
160171
)
161172

162173
def fromJavaxNetSslKeyStoreResource(keyManagerResource: String, keyManagerPassword: Secret): SSLConfig =

0 commit comments

Comments
 (0)