This is an automated email from the ASF dual-hosted git repository. markt-asf pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit ea10b19d5c4fc8b6e07d33e776e39110221d9285 Author: Mark Thomas <[email protected]> AuthorDate: Mon Sep 21 12:01:00 2026 +0100 Mirror changes in Native for PSK support with TLS 1.2 --- .../apache/tomcat/jni/PreSharedKeySelector.java | 33 ++++++++++++++++++++++ java/org/apache/tomcat/jni/SSLContext.java | 9 ++++++ 2 files changed, 42 insertions(+) diff --git a/java/org/apache/tomcat/jni/PreSharedKeySelector.java b/java/org/apache/tomcat/jni/PreSharedKeySelector.java new file mode 100644 index 0000000000..0cafc2a90a --- /dev/null +++ b/java/org/apache/tomcat/jni/PreSharedKeySelector.java @@ -0,0 +1,33 @@ +/* + * 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. + */ +package org.apache.tomcat.jni; + +/** + * Is called during a TLSv1.2 handshake and hooked into OpenSSL via {@code SSL_CTX_set_psk_server_callback}. + */ +public interface PreSharedKeySelector { + + /** + * Selects the pre-shared key for the provided identity. + * + * @param ssl the SSL instance + * @param identity the PSK identity provided by the client + * + * @return the pre-shared key, or {@code null} if the identity is not recognized + */ + byte[] select(long ssl, String identity); +} diff --git a/java/org/apache/tomcat/jni/SSLContext.java b/java/org/apache/tomcat/jni/SSLContext.java index 24dbbfdd64..ea3ef2c7ab 100644 --- a/java/org/apache/tomcat/jni/SSLContext.java +++ b/java/org/apache/tomcat/jni/SSLContext.java @@ -471,6 +471,15 @@ public final class SSLContext { */ public static native void setCertVerifyCallback(long ctx, CertificateVerifier verifier); + /** + * Allow to hook {@link PreSharedKeySelector} into the TLSv1.2 handshake processing. This will call + * {@code SSL_CTX_set_psk_server_callback}. + * + * @param ctx Server context to use. + * @param selector the selector to call during handshake, or {@code null} to remove the current selector + */ + public static native void setPskServerCallback(long ctx, PreSharedKeySelector selector); + /** * Set application layer protocol for application layer protocol negotiation extension * --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
