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


##########
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:
   The duplicate-subject case was real, the chain is now picked by signature. 
There is now the exampleca-rotated-bundle.crt test.
   
   These cert files are expected to be carefully created by trusted people 
involved in the deployment. There is no expectation that someone would load a 
badly formatted cert file. Still no harm in trying to make the code 
deterministic.



-- 
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