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

remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new fb26ae7b82 Add two more macros
fb26ae7b82 is described below

commit fb26ae7b82cab011aabaa8bccb7d51db9c1a411e
Author: remm <r...@apache.org>
AuthorDate: Wed Oct 18 14:49:01 2023 +0200

    Add two more macros
---
 .../util/net/openssl/panama/OpenSSLContext.java    | 16 +++------
 .../tomcat/util/openssl/openssl_h_Macros.java      | 39 ++++++++++++++++++++++
 2 files changed, 43 insertions(+), 12 deletions(-)

diff --git 
a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java
 
b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java
index c0bb643e4f..d81c688efd 100644
--- 
a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java
+++ 
b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java
@@ -986,9 +986,7 @@ public class OpenSSLContext implements 
org.apache.tomcat.util.net.SSLContext {
             if (certificate.getCertificateFile().endsWith(".pkcs12")) {
                 // Load pkcs12
                 bio = BIO_new(BIO_s_file());
-                //#  define BIO_read_filename(b,name)
-                //        (int)BIO_ctrl(b,BIO_C_SET_FILENAME, 
BIO_CLOSE|BIO_FP_READ,(char *)(name))
-                if (BIO_ctrl(bio, BIO_C_SET_FILENAME(), BIO_CLOSE() | 
BIO_FP_READ(), certificateFileNative) <= 0) {
+                if (BIO_read_filename(bio, certificateFileNative) <= 0) {
                     BIO_free(bio);
                     log.error(sm.getString("openssl.errorLoadingCertificate", 
"[0]:" + certificate.getCertificateFile()));
                     return;
@@ -1025,9 +1023,7 @@ public class OpenSSLContext implements 
org.apache.tomcat.util.net.SSLContext {
             } else {
                 // Load key
                 bio = BIO_new(BIO_s_file());
-                //#  define BIO_read_filename(b,name)
-                //        (int)BIO_ctrl(b,BIO_C_SET_FILENAME, 
BIO_CLOSE|BIO_FP_READ,(char *)(name))
-                if (BIO_ctrl(bio, BIO_C_SET_FILENAME(), BIO_CLOSE() | 
BIO_FP_READ(), certificateKeyFileNative) <= 0) {
+                if (BIO_read_filename(bio, certificateKeyFileNative) <= 0) {
                     BIO_free(bio);
                     log.error(sm.getString("openssl.errorLoadingCertificate", 
certificate.getCertificateKeyFile()));
                     return;
@@ -1110,10 +1106,8 @@ public class OpenSSLContext implements 
org.apache.tomcat.util.net.SSLContext {
                 if (OpenSSL_version_num() < 0x3000000fL) {
                     var dh = PEM_read_bio_DHparams(bio, MemorySegment.NULL, 
MemorySegment.NULL, MemorySegment.NULL);
                     BIO_free(bio);
-                    // #  define SSL_CTX_set_tmp_dh(sslCtx,dh) \
-                    //           
SSL_CTX_ctrl(sslCtx,SSL_CTRL_SET_TMP_DH,0,(char *)(dh))
                     if (!MemorySegment.NULL.equals(dh)) {
-                        SSL_CTX_ctrl(state.sslCtx, SSL_CTRL_SET_TMP_DH(), 0, 
dh);
+                        SSL_CTX_set_tmp_dh(state.sslCtx, dh);
                         DH_free(dh);
                     }
                 } else {
@@ -1138,9 +1132,7 @@ public class OpenSSLContext implements 
org.apache.tomcat.util.net.SSLContext {
                 if (!MemorySegment.NULL.equals(ecparams)) {
                     int nid = EC_GROUP_get_curve_name(ecparams);
                     var eckey = EC_KEY_new_by_curve_name(nid);
-                    // #  define SSL_CTX_set_tmp_ecdh(sslCtx,ecdh) \
-                    //           
SSL_CTX_ctrl(sslCtx,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh))
-                    SSL_CTX_ctrl(state.sslCtx, SSL_CTRL_SET_TMP_ECDH(), 0, 
eckey);
+                    SSL_CTX_set_tmp_ecdh(state.sslCtx, eckey);
                     EC_KEY_free(eckey);
                     EC_GROUP_free(ecparams);
                 }
diff --git 
a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/openssl_h_Macros.java
 
b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/openssl_h_Macros.java
index 03f55e2a4b..5d11bdf628 100644
--- 
a/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/openssl_h_Macros.java
+++ 
b/modules/openssl-foreign/src/main/java/org/apache/tomcat/util/openssl/openssl_h_Macros.java
@@ -131,6 +131,45 @@ public class openssl_h_Macros {
     }
 
 
+    /**
+     * Read the specified file.
+     * #  define BIO_read_filename(b,name) \
+     *           (int)BIO_ctrl(b,BIO_C_SET_FILENAME, 
BIO_CLOSE|BIO_FP_READ,(char *)(name))
+     * @param bio The BIO to read into
+     * @param name the file name
+     * @return > 0 if successful
+     */
+    public static long BIO_read_filename(MemorySegment bio, MemorySegment 
name) {
+        return BIO_ctrl(bio, BIO_C_SET_FILENAME(), BIO_CLOSE() | 
BIO_FP_READ(), name);
+    }
+
+
+    /**
+     * Set tmp dh.
+     * #  define SSL_CTX_set_tmp_dh(sslCtx,dh) \
+     *           SSL_CTX_ctrl(sslCtx,SSL_CTRL_SET_TMP_DH,0,(char *)(dh))
+     * @param sslCtx the SSL context
+     * @param dh the dh
+     * @return > 0 if successful
+     */
+    public static long SSL_CTX_set_tmp_dh(MemorySegment sslCtx, MemorySegment 
dh) {
+        return SSL_CTX_ctrl(sslCtx, SSL_CTRL_SET_TMP_DH(), 0, dh);
+    }
+
+
+    /**
+     * Set tmp ecdh.
+     * #  define SSL_CTX_set_tmp_ecdh(sslCtx,ecdh) \
+     *           SSL_CTX_ctrl(sslCtx,SSL_CTRL_SET_TMP_ECDH,0,(char *)(ecdh))
+     * @param sslCtx the SSL context
+     * @param ecdh the ecdh
+     * @return > 0 if successful
+     */
+    public static long SSL_CTX_set_tmp_ecdh(MemorySegment sslCtx, 
MemorySegment ecdh) {
+        return SSL_CTX_ctrl(sslCtx, SSL_CTRL_SET_TMP_ECDH(), 0, ecdh);
+    }
+
+
 }
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to