This is an automated email from the ASF dual-hosted git repository.

rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 071eaf463a1d04115c05137fac51e949afaa481f
Author: opencode <[email protected]>
AuthorDate: Fri Oct 16 09:22:08 2026 +0200

    Correct the cipher authentication method computation of the OpenSSL FFM 
implementation
    
    getCipherAuthenticationMethod() compared the key exchange and
    authentication values returned by SSL_CIPHER_get_kx_nid() and
    SSL_CIPHER_get_auth_nid(), which are NIDs, against the legacy OpenSSL
    SSL_k* and SSL_a* flag constants. Only NID_kx_rsa could ever match, so
    a custom X509TrustManager received UNKNOWN as the authentication type
    for virtually every cipher suite.
    
    The legacy constants trace back to the algorithm_mkey/algorithm_auth
    bitmask table of OpenSSL 1.0.x ssl_locl.h, as also carried by the
    LibreSSL compatibility branch of Tomcat Native. They were copied into
    the FFM port with the hex base dropped (0x10 became 10, 0x40 became 40,
    and so on) and then compared against NIDs, so they could not match
    anything.
    
    The constants now hold the real NID_kx_rsa, NID_kx_ecdhe, NID_kx_dhe,
    NID_auth_rsa, NID_auth_ecdsa, NID_auth_dss and NID_auth_null values,
    hard-coded because these macros are not present in the generated
    bindings, and the switch now mirrors SSL_CIPHER_authentication_method()
    of Tomcat Native byte for byte, including the UNKNOWN results for
    combinations without a JSSE authentication type such as the TLS 1.3
    kx-any value.
---
 .../util/net/openssl/panama/OpenSSLContext.java    | 73 ++++++++--------------
 webapps/docs/changelog.xml                         |  9 +++
 2 files changed, 34 insertions(+), 48 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java 
b/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java
index 48e4296632..4ad3b80801 100644
--- a/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java
+++ b/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java
@@ -836,66 +836,43 @@ public class OpenSSLContext implements 
org.apache.tomcat.util.net.SSLContext {
         }
     }
 
-    private static final int NID_kx_rsa = 1037/* NID_kx_rsa() */;
-    // private static final int NID_kx_dhe = NID_kx_dhe();
-    // private static final int NID_kx_ecdhe = NID_kx_ecdhe();
-
-    // private static final int NID_auth_rsa = NID_auth_rsa();
-    // private static final int NID_auth_dss = NID_auth_dss();
-    // private static final int NID_auth_null = NID_auth_null();
-    // private static final int NID_auth_ecdsa = NID_auth_ecdsa();
-
-    // private static final int SSL_kRSA = 1;
-    private static final int SSL_kDHr = 2;
-    private static final int SSL_kDHd = 4;
-    private static final int SSL_kEDH = 8;
-    private static final int SSL_kDHE = SSL_kEDH;
-    private static final int SSL_kKRB5 = 10;
-    private static final int SSL_kECDHr = 20;
-    private static final int SSL_kECDHe = 40;
-    private static final int SSL_kEECDH = 80;
-    private static final int SSL_kECDHE = SSL_kEECDH;
-    // private static final int SSL_kPSK = 100;
-    // private static final int SSL_kGOST = 200;
-    // private static final int SSL_kSRP = 400;
-
-    private static final int SSL_aRSA = 1;
-    private static final int SSL_aDSS = 2;
-    private static final int SSL_aNULL = 4;
-    // private static final int SSL_aDH = 8;
-    // private static final int SSL_aECDH = 10;
-    // private static final int SSL_aKRB5 = 20;
-    private static final int SSL_aECDSA = 40;
-    // private static final int SSL_aPSK = 80;
-    // private static final int SSL_aGOST94 = 100;
-    // private static final int SSL_aGOST01 = 200;
-    // private static final int SSL_aSRP = 400;
+    // Key exchange and authentication NIDs. The values are hard-coded since
+    // these OpenSSL constants are macros that are not present in the
+    // generated bindings. They are defined in OpenSSL's obj_mac.h.
+    private static final int NID_kx_rsa = 1037;
+    private static final int NID_kx_ecdhe = 1038;
+    private static final int NID_kx_dhe = 1039;
+
+    private static final int NID_auth_rsa = 1046;
+    private static final int NID_auth_ecdsa = 1047;
+    private static final int NID_auth_dss = 1049;
+    private static final int NID_auth_null = 1053;
 
     private static final String SSL_TXT_RSA = "RSA";
     private static final String SSL_TXT_DH = "DH";
     private static final String SSL_TXT_DSS = "DSS";
-    private static final String SSL_TXT_KRB5 = "KRB5";
     private static final String SSL_TXT_ECDH = "ECDH";
     private static final String SSL_TXT_ECDSA = "ECDSA";
 
     private static String getCipherAuthenticationMethod(int auth, int kx) {
+        // Mirrors the computation Tomcat Native performs for the JNI based
+        // implementation: a switch on the key exchange NID of the current
+        // cipher, using the authentication NID to disambiguate where
+        // required. Combinations without a JSSE authentication type,
+        // including the TLS 1.3 "any" values, result in "UNKNOWN" there and
+        // do so here.
         return switch (kx) {
             case NID_kx_rsa -> SSL_TXT_RSA;
-            case SSL_kDHr -> SSL_TXT_DH + "_" + SSL_TXT_RSA;
-            case SSL_kDHd -> SSL_TXT_DH + "_" + SSL_TXT_DSS;
-            case SSL_kDHE -> switch (auth) {
-                case SSL_aDSS -> "DHE_" + SSL_TXT_DSS;
-                case SSL_aRSA -> "DHE_" + SSL_TXT_RSA;
-                case SSL_aNULL -> SSL_TXT_DH + "_anon";
+            case NID_kx_dhe -> switch (auth) {
+                case NID_auth_dss -> "DHE_" + SSL_TXT_DSS;
+                case NID_auth_rsa -> "DHE_" + SSL_TXT_RSA;
+                case NID_auth_null -> SSL_TXT_DH + "_anon";
                 default -> "UNKNOWN";
             };
-            case SSL_kKRB5 -> SSL_TXT_KRB5;
-            case SSL_kECDHr -> SSL_TXT_ECDH + "_" + SSL_TXT_RSA;
-            case SSL_kECDHe -> SSL_TXT_ECDH + "_" + SSL_TXT_ECDSA;
-            case SSL_kECDHE -> switch (auth) {
-                case SSL_aECDSA -> "ECDHE_" + SSL_TXT_ECDSA;
-                case SSL_aRSA -> "ECDHE_" + SSL_TXT_RSA;
-                case SSL_aNULL -> SSL_TXT_ECDH + "_anon";
+            case NID_kx_ecdhe -> switch (auth) {
+                case NID_auth_ecdsa -> "ECDHE_" + SSL_TXT_ECDSA;
+                case NID_auth_rsa -> "ECDHE_" + SSL_TXT_RSA;
+                case NID_auth_null -> SSL_TXT_ECDH + "_anon";
                 default -> "UNKNOWN";
             };
             default -> "UNKNOWN";
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 10463defe3..b3b8d10afb 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -351,6 +351,15 @@
         than adding <code>null</code> to the lists of cipher suites they
         expose. (remm)
       </fix>
+      <fix>
+        Correct the computation of the authentication method passed to a custom
+        <code>X509TrustManager</code> by the FFM based OpenSSL implementation.
+        The key exchange and authentication NIDs of the negotiated cipher were
+        compared against legacy OpenSSL flag values rather than the actual NID
+        constants, so the trust manager received <code>UNKNOWN</code> as the
+        authentication type for almost every cipher suite. The computation now
+        matches the one performed by the JNI based implementation. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Web applications">


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

Reply via email to