You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2026/07/31 14:01:17 UTC
[PR] WIP: min TLS version setting [pekko-grpc]
pjfanning opened a new pull request, #823:
URL: https://github.com/apache/pekko-grpc/pull/823
work in progress - might be overkill, especially now that 2.0.0 has Java 17 min
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Minimum TLS version setting [pekko-grpc]
Posted by "nvollmar (via GitHub) via notifications" <no...@pekko.apache.org>.
nvollmar commented on code in PR #823:
URL: https://github.com/apache/pekko-grpc/pull/823#discussion_r4540943113
##########
runtime/src/main/scala/org/apache/pekko/grpc/SSLContextUtils.scala:
##########
@@ -44,4 +46,115 @@ object SSLContextUtils {
if (certStream == null) throw new IOException(s"Couldn't find '$certificateResourcePath' on the classpath")
trustManagerFromStream(certStream)
}
+
+ /**
+ * Known TLS protocol versions in ascending order of strength.
+ * Used to filter protocols based on a minimum version requirement.
+ */
+ private val TlsVersionOrder: List[String] =
+ List("TLSv1.2", "TLSv1.3")
+
+ /**
+ * INTERNAL API
+ *
+ * Returns `version` if it is a minimum TLS version this library accepts, so that a typo fails
+ * when the settings are built rather than when a channel is first created.
+ *
+ * @throws IllegalArgumentException if `version` is not one of the accepted names
+ */
+ @InternalApi
+ private[grpc] def requireKnownTlsVersion(version: String): String = {
+ tlsVersionIndex(version)
+ version
+ }
+
+ private def tlsVersionIndex(minimumVersion: String): Int = {
+ val minIndex = TlsVersionOrder.indexOf(minimumVersion)
+ if (minIndex < 0)
+ throw new IllegalArgumentException(
+ s"Unknown TLS version '$minimumVersion'. Expected one of: ${TlsVersionOrder.mkString(", ")}")
+ minIndex
+ }
+
+ /**
+ * INTERNAL API
+ *
+ * Returns the TLS protocols supported by the given SSLContext that are at or above
+ * the specified minimum version. Throws IllegalArgumentException if the minimum
+ * version is not a known TLS protocol name.
+ *
+ * Reads the *supported* parameters rather than the default (enabled) ones: the minimum
+ * version is a floor on what may be negotiated, so a version the JDK supports but does not
+ * enable by default should still be reachable by configuring it explicitly.
+ */
+ @InternalApi
+ private[grpc] def enabledProtocols(sslContext: SSLContext, minimumVersion: String): Array[String] = {
+ val minIndex = tlsVersionIndex(minimumVersion)
+ val supported = sslContext.getSupportedSSLParameters.getProtocols
Review Comment:
If on JDK level minimum is set to `-Djdk.tls.client.protocols=TLSv1.3`, this would allow to use TLSv1.2 if minimum is set to it.
`sslContext.getDefaultSSLParameters.getProtocols` would return only the protocols which are enabled
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Minimum TLS version setting [pekko-grpc]
Posted by "pjfanning (via GitHub) via notifications" <no...@pekko.apache.org>.
pjfanning merged PR #823:
URL: https://github.com/apache/pekko-grpc/pull/823
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Minimum TLS version setting [pekko-grpc]
Posted by "nvollmar (via GitHub) via notifications" <no...@pekko.apache.org>.
nvollmar commented on code in PR #823:
URL: https://github.com/apache/pekko-grpc/pull/823#discussion_r4540971008
##########
runtime/src/test/scala/org/apache/pekko/grpc/internal/MinimumTlsVersionSpec.scala:
##########
@@ -0,0 +1,351 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.grpc.internal
+
+import java.nio.charset.StandardCharsets.UTF_8
+import java.security.{ KeyFactory, KeyStore, SecureRandom }
+import java.security.cert.CertificateFactory
+import java.security.spec.PKCS8EncodedKeySpec
+import java.util.Base64
+
+import javax.net.ssl.{ KeyManagerFactory, SSLContext, SSLEngine, SSLHandshakeException }
+
+import scala.concurrent.Future
+import scala.concurrent.duration._
+import scala.util.{ Failure, Success, Try }
+
+import com.typesafe.config.ConfigFactory
+import io.grpc.netty.shaded.io.netty.buffer.ByteBufAllocator
+import org.apache.pekko
+import pekko.actor.ActorSystem
+import pekko.grpc.{ GrpcClientSettings, SSLContextUtils }
+import pekko.http.scaladsl.{ ConnectionContext, Http }
+import pekko.http.scaladsl.model.{ HttpRequest, HttpResponse, StatusCodes }
+import pekko.stream.scaladsl.{ Sink, Source }
+import pekko.testkit.TestKit
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.concurrent.ScalaFutures
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.time.Span
+import org.scalatest.wordspec.AnyWordSpecLike
+
+/**
+ * Covers `minimum-tls-version` end to end: the protocol filtering itself, the `SSLContext`
+ * wrapper built from it, that the floor reaches the pekko-http connection context on both the
+ * verifying and the opt-out path, and that a floor above what the server offers actually
+ * fails the handshake.
+ */
+class MinimumTlsVersionSpec
+ extends TestKit(ActorSystem())
+ with AnyWordSpecLike
+ with Matchers
+ with ScalaFutures
+ with BeforeAndAfterAll {
+
Review Comment:
Should terminate the actor system after tests finished:
```
override def afterAll(): Unit =
try {
binding.terminate(5.seconds).futureValue
} finally {
try TestKit.shutdownActorSystem(system)
finally super.afterAll()
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org
Re: [PR] Minimum TLS version setting [pekko-grpc]
Posted by "pjfanning (via GitHub) via notifications" <no...@pekko.apache.org>.
pjfanning commented on code in PR #823:
URL: https://github.com/apache/pekko-grpc/pull/823#discussion_r4541326298
##########
runtime/src/test/scala/org/apache/pekko/grpc/internal/MinimumTlsVersionSpec.scala:
##########
@@ -0,0 +1,351 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pekko.grpc.internal
+
+import java.nio.charset.StandardCharsets.UTF_8
+import java.security.{ KeyFactory, KeyStore, SecureRandom }
+import java.security.cert.CertificateFactory
+import java.security.spec.PKCS8EncodedKeySpec
+import java.util.Base64
+
+import javax.net.ssl.{ KeyManagerFactory, SSLContext, SSLEngine, SSLHandshakeException }
+
+import scala.concurrent.Future
+import scala.concurrent.duration._
+import scala.util.{ Failure, Success, Try }
+
+import com.typesafe.config.ConfigFactory
+import io.grpc.netty.shaded.io.netty.buffer.ByteBufAllocator
+import org.apache.pekko
+import pekko.actor.ActorSystem
+import pekko.grpc.{ GrpcClientSettings, SSLContextUtils }
+import pekko.http.scaladsl.{ ConnectionContext, Http }
+import pekko.http.scaladsl.model.{ HttpRequest, HttpResponse, StatusCodes }
+import pekko.stream.scaladsl.{ Sink, Source }
+import pekko.testkit.TestKit
+import org.scalatest.BeforeAndAfterAll
+import org.scalatest.concurrent.ScalaFutures
+import org.scalatest.matchers.should.Matchers
+import org.scalatest.time.Span
+import org.scalatest.wordspec.AnyWordSpecLike
+
+/**
+ * Covers `minimum-tls-version` end to end: the protocol filtering itself, the `SSLContext`
+ * wrapper built from it, that the floor reaches the pekko-http connection context on both the
+ * verifying and the opt-out path, and that a floor above what the server offers actually
+ * fails the handshake.
+ */
+class MinimumTlsVersionSpec
+ extends TestKit(ActorSystem())
+ with AnyWordSpecLike
+ with Matchers
+ with ScalaFutures
+ with BeforeAndAfterAll {
+
Review Comment:
fixed in new commit
##########
runtime/src/main/scala/org/apache/pekko/grpc/SSLContextUtils.scala:
##########
@@ -44,4 +46,115 @@ object SSLContextUtils {
if (certStream == null) throw new IOException(s"Couldn't find '$certificateResourcePath' on the classpath")
trustManagerFromStream(certStream)
}
+
+ /**
+ * Known TLS protocol versions in ascending order of strength.
+ * Used to filter protocols based on a minimum version requirement.
+ */
+ private val TlsVersionOrder: List[String] =
+ List("TLSv1.2", "TLSv1.3")
+
+ /**
+ * INTERNAL API
+ *
+ * Returns `version` if it is a minimum TLS version this library accepts, so that a typo fails
+ * when the settings are built rather than when a channel is first created.
+ *
+ * @throws IllegalArgumentException if `version` is not one of the accepted names
+ */
+ @InternalApi
+ private[grpc] def requireKnownTlsVersion(version: String): String = {
+ tlsVersionIndex(version)
+ version
+ }
+
+ private def tlsVersionIndex(minimumVersion: String): Int = {
+ val minIndex = TlsVersionOrder.indexOf(minimumVersion)
+ if (minIndex < 0)
+ throw new IllegalArgumentException(
+ s"Unknown TLS version '$minimumVersion'. Expected one of: ${TlsVersionOrder.mkString(", ")}")
+ minIndex
+ }
+
+ /**
+ * INTERNAL API
+ *
+ * Returns the TLS protocols supported by the given SSLContext that are at or above
+ * the specified minimum version. Throws IllegalArgumentException if the minimum
+ * version is not a known TLS protocol name.
+ *
+ * Reads the *supported* parameters rather than the default (enabled) ones: the minimum
+ * version is a floor on what may be negotiated, so a version the JDK supports but does not
+ * enable by default should still be reachable by configuring it explicitly.
+ */
+ @InternalApi
+ private[grpc] def enabledProtocols(sslContext: SSLContext, minimumVersion: String): Array[String] = {
+ val minIndex = tlsVersionIndex(minimumVersion)
+ val supported = sslContext.getSupportedSSLParameters.getProtocols
Review Comment:
fixed in new commit
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org