pjfanning commented on code in PR #3528:
URL: https://github.com/apache/pekko/pull/3528#discussion_r3943857106


##########
remote/src/main/scala/org/apache/pekko/remote/artery/tcp/ssl/PemManagersProvider.scala:
##########
@@ -90,4 +93,46 @@ private[ssl] object PemManagersProvider {
     certFactory.generateCertificate(Files.newInputStream(new 
File(filename).toPath))
   }
 
+  /**
+   * Loads every certificate found in the given PEM file. A file may bundle 
more than one
+   * certificate, e.g. a root CA together with the intermediates it delegates 
to, or several
+   * roots while a CA is being rotated.
+   *
+   * INTERNAL API
+   */
+  @InternalApi
+  private[ssl] def loadCertificates(filename: String): Seq[Certificate] = 
blocking {
+    val stream = Files.newInputStream(new File(filename).toPath)
+    try certFactory.generateCertificates(stream).asScala.toList
+    finally stream.close()
+  }
+
+  private def caCertAlias(idx: Int): String = if (idx == 0) "cacert" else 
s"cacert-$idx"
+
+  /**
+   * Builds the certificate chain to present during the handshake: `cert` 
followed by the
+   * certificates from `cacerts` that actually issued it, ordered from the 
issuer of `cert` up
+   * to the root. Certificates in `cacerts` that are not part of that chain 
(an unrelated root
+   * kept around for a CA rotation, say) are trusted but not sent to the peer.
+   *
+   * Falls back to sending all of `cacerts` when none of them matches the 
issuer of `cert`, which
+   * keeps the behaviour of a single, non-matching CA certificate unchanged.
+   */
+  private def buildCertificateChain(cert: X509Certificate, cacerts: 
Seq[Certificate]): Array[Certificate] = {
+    val bySubject: Map[X500Principal, X509Certificate] =

Review Comment:
   I'll look into adding test coverage in this area and seeing which solution 
makes most sense



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to