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
commit 9d987288967e3bf103dec090f2fb0e2148be010a Author: remm <r...@apache.org> AuthorDate: Fri Jan 26 15:04:50 2024 +0100 jextract now avoids generating redundant classes But the typedef has to be listed. --- .../util/net/openssl/panama/OpenSSLContext.java | 13 ++--- .../util/openssl/PEM_read_bio_PrivateKey$cb.java | 68 ---------------------- .../openssl/SSL_CTX_set_default_passwd_cb$cb.java | 68 ---------------------- ...d_bio_X509_AUX$cb.java => pem_password_cb.java} | 23 ++++++-- res/openssl/openssl-tomcat.conf | 4 ++ 5 files changed, 27 insertions(+), 149 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 1939e465a8..1699054894 100644 --- a/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java +++ b/java/org/apache/tomcat/util/net/openssl/panama/OpenSSLContext.java @@ -64,11 +64,9 @@ import org.apache.tomcat.util.net.openssl.OpenSSLConf; import org.apache.tomcat.util.net.openssl.OpenSSLConfCmd; import org.apache.tomcat.util.net.openssl.OpenSSLStatus; import org.apache.tomcat.util.net.openssl.OpenSSLUtil; -import org.apache.tomcat.util.openssl.PEM_read_bio_PrivateKey$cb; -import org.apache.tomcat.util.openssl.PEM_read_bio_X509_AUX$cb; +import org.apache.tomcat.util.openssl.pem_password_cb; import org.apache.tomcat.util.openssl.SSL_CTX_set_alpn_select_cb$cb; import org.apache.tomcat.util.openssl.SSL_CTX_set_cert_verify_callback$cb; -import org.apache.tomcat.util.openssl.SSL_CTX_set_default_passwd_cb$cb; import org.apache.tomcat.util.openssl.SSL_CTX_set_tmp_dh_callback$dh; import org.apache.tomcat.util.openssl.SSL_CTX_set_verify$callback; import org.apache.tomcat.util.res.StringManager; @@ -267,7 +265,7 @@ public class OpenSSLContext implements org.apache.tomcat.util.net.SSLContext { // Set int pem_password_cb(char *buf, int size, int rwflag, void *u) callback SSL_CTX_set_default_passwd_cb(sslCtx, - SSL_CTX_set_default_passwd_cb$cb.allocate(new PasswordCallback(null), contextArena)); + pem_password_cb.allocate(new PasswordCallback(null), contextArena)); if (negotiableProtocols != null && negotiableProtocols.size() > 0) { alpn = true; @@ -867,8 +865,7 @@ public class OpenSSLContext implements org.apache.tomcat.util.net.SSLContext { } } - private static class PasswordCallback implements SSL_CTX_set_default_passwd_cb$cb.Function, - PEM_read_bio_X509_AUX$cb.Function, PEM_read_bio_PrivateKey$cb.Function { + private static class PasswordCallback implements pem_password_cb.Function { private final String callbackPassword; PasswordCallback(String callbackPassword) { this.callbackPassword = callbackPassword; @@ -995,7 +992,7 @@ public class OpenSSLContext implements org.apache.tomcat.util.net.SSLContext { key = MemorySegment.NULL; for (int i = 0; i < 3; i++) { key = PEM_read_bio_PrivateKey(keyBIO, MemorySegment.NULL, - PEM_read_bio_PrivateKey$cb.allocate(new PasswordCallback(keyPassToUse), contextArena), + pem_password_cb.allocate(new PasswordCallback(keyPassToUse), contextArena), MemorySegment.NULL); if (!MemorySegment.NULL.equals(key)) { break; @@ -1020,7 +1017,7 @@ public class OpenSSLContext implements org.apache.tomcat.util.net.SSLContext { } // Load certificate cert = PEM_read_bio_X509_AUX(certificateBIO, MemorySegment.NULL, - PEM_read_bio_X509_AUX$cb.allocate(new PasswordCallback(keyPassToUse), contextArena), + pem_password_cb.allocate(new PasswordCallback(keyPassToUse), contextArena), MemorySegment.NULL); if (MemorySegment.NULL.equals(cert) && // Missing ERR_GET_REASON(ERR_peek_last_error()) diff --git a/java/org/apache/tomcat/util/openssl/PEM_read_bio_PrivateKey$cb.java b/java/org/apache/tomcat/util/openssl/PEM_read_bio_PrivateKey$cb.java deleted file mode 100644 index 2898cc734f..0000000000 --- a/java/org/apache/tomcat/util/openssl/PEM_read_bio_PrivateKey$cb.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - */ - -// Generated by jextract - -package org.apache.tomcat.util.openssl; - -import java.lang.foreign.Arena; -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.Linker; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; - -/** - * {@snippet lang=c : - * pem_password_cb *cb - * } - */ -@SuppressWarnings("javadoc") -public class PEM_read_bio_PrivateKey$cb { - - public interface Function { - int apply(MemorySegment buf, int size, int rwflag, MemorySegment userdata); - } - - private static final FunctionDescriptor $DESC = FunctionDescriptor.of( - openssl_h.C_INT, - openssl_h.C_POINTER, - openssl_h.C_INT, - openssl_h.C_INT, - openssl_h.C_POINTER - ); - - public static FunctionDescriptor descriptor() { - return $DESC; - } - - private static final MethodHandle UP$MH = openssl_h.upcallHandle(PEM_read_bio_PrivateKey$cb.Function.class, "apply", $DESC); - - public static MemorySegment allocate(PEM_read_bio_PrivateKey$cb.Function fi, Arena scope) { - return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, scope); - } - - private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); - - public static int invoke(MemorySegment funcPtr,MemorySegment buf, int size, int rwflag, MemorySegment userdata) { - try { - return (int) DOWN$MH.invokeExact(funcPtr, buf, size, rwflag, userdata); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - } -} - diff --git a/java/org/apache/tomcat/util/openssl/SSL_CTX_set_default_passwd_cb$cb.java b/java/org/apache/tomcat/util/openssl/SSL_CTX_set_default_passwd_cb$cb.java deleted file mode 100644 index 8e31d141a5..0000000000 --- a/java/org/apache/tomcat/util/openssl/SSL_CTX_set_default_passwd_cb$cb.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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. - */ - -// Generated by jextract - -package org.apache.tomcat.util.openssl; - -import java.lang.foreign.Arena; -import java.lang.foreign.FunctionDescriptor; -import java.lang.foreign.Linker; -import java.lang.foreign.MemorySegment; -import java.lang.invoke.MethodHandle; - -/** - * {@snippet lang=c : - * pem_password_cb *cb - * } - */ -@SuppressWarnings("javadoc") -public class SSL_CTX_set_default_passwd_cb$cb { - - public interface Function { - int apply(MemorySegment buf, int size, int rwflag, MemorySegment userdata); - } - - private static final FunctionDescriptor $DESC = FunctionDescriptor.of( - openssl_h.C_INT, - openssl_h.C_POINTER, - openssl_h.C_INT, - openssl_h.C_INT, - openssl_h.C_POINTER - ); - - public static FunctionDescriptor descriptor() { - return $DESC; - } - - private static final MethodHandle UP$MH = openssl_h.upcallHandle(SSL_CTX_set_default_passwd_cb$cb.Function.class, "apply", $DESC); - - public static MemorySegment allocate(SSL_CTX_set_default_passwd_cb$cb.Function fi, Arena scope) { - return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, scope); - } - - private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); - - public static int invoke(MemorySegment funcPtr,MemorySegment buf, int size, int rwflag, MemorySegment userdata) { - try { - return (int) DOWN$MH.invokeExact(funcPtr, buf, size, rwflag, userdata); - } catch (Throwable ex$) { - throw new AssertionError("should not reach here", ex$); - } - } -} - diff --git a/java/org/apache/tomcat/util/openssl/PEM_read_bio_X509_AUX$cb.java b/java/org/apache/tomcat/util/openssl/pem_password_cb.java similarity index 76% rename from java/org/apache/tomcat/util/openssl/PEM_read_bio_X509_AUX$cb.java rename to java/org/apache/tomcat/util/openssl/pem_password_cb.java index 982422edf7..888c3c3f4b 100644 --- a/java/org/apache/tomcat/util/openssl/PEM_read_bio_X509_AUX$cb.java +++ b/java/org/apache/tomcat/util/openssl/pem_password_cb.java @@ -27,12 +27,15 @@ import java.lang.invoke.MethodHandle; /** * {@snippet lang=c : - * pem_password_cb *cb + * typedef int (pem_password_cb)(char *, int, int, void *) * } */ @SuppressWarnings("javadoc") -public class PEM_read_bio_X509_AUX$cb { +public class pem_password_cb { + /** + * The function pointer signature, expressed as a functional interface + */ public interface Function { int apply(MemorySegment buf, int size, int rwflag, MemorySegment userdata); } @@ -45,18 +48,28 @@ public class PEM_read_bio_X509_AUX$cb { openssl_h.C_POINTER ); + /** + * The descriptor of this function pointer + */ public static FunctionDescriptor descriptor() { return $DESC; } - private static final MethodHandle UP$MH = openssl_h.upcallHandle(PEM_read_bio_X509_AUX$cb.Function.class, "apply", $DESC); + private static final MethodHandle UP$MH = openssl_h.upcallHandle(pem_password_cb.Function.class, "apply", $DESC); - public static MemorySegment allocate(PEM_read_bio_X509_AUX$cb.Function fi, Arena scope) { - return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, scope); + /** + * Allocates a new upcall stub, whose implementation is defined by {@code fi}. + * The lifetime of the returned segment is managed by {@code arena} + */ + public static MemorySegment allocate(pem_password_cb.Function fi, Arena arena) { + return Linker.nativeLinker().upcallStub(UP$MH.bindTo(fi), $DESC, arena); } private static final MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC); + /** + * Invoke the upcall stub {@code funcPtr}, with given parameters + */ public static int invoke(MemorySegment funcPtr,MemorySegment buf, int size, int rwflag, MemorySegment userdata) { try { return (int) DOWN$MH.invokeExact(funcPtr, buf, size, rwflag, userdata); diff --git a/res/openssl/openssl-tomcat.conf b/res/openssl/openssl-tomcat.conf index 74bc18545f..66ebe76847 100644 --- a/res/openssl/openssl-tomcat.conf +++ b/res/openssl/openssl-tomcat.conf @@ -321,6 +321,10 @@ --include-function OPENSSL_sk_num # header: /usr/include/openssl/stack.h --include-function OPENSSL_sk_value # header: /usr/include/openssl/stack.h +#### Extracted from: /usr/include/openssl/types.h + +--include-typedef pem_password_cb + #### Extracted from: /usr/include/openssl/x509.h --include-function i2d_X509 # header: /usr/include/openssl/x509.h --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org