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 44087b688a8abd81fa7856f630838b360a129688 Author: Mark Thomas <[email protected]> AuthorDate: Mon Sep 21 15:07:15 2026 +0100 Align with recent Native changes to add PSK support Still requires changes in OpenSSLContext for this to be usable. --- .../apache/tomcat/jni/PreSharedKeySelector.java | 25 ++++++++++++++++++++-- java/org/apache/tomcat/jni/SSLContext.java | 9 ++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/java/org/apache/tomcat/jni/PreSharedKeySelector.java b/java/org/apache/tomcat/jni/PreSharedKeySelector.java index 0cafc2a90a..1b4f738f78 100644 --- a/java/org/apache/tomcat/jni/PreSharedKeySelector.java +++ b/java/org/apache/tomcat/jni/PreSharedKeySelector.java @@ -17,7 +17,9 @@ package org.apache.tomcat.jni; /** - * Is called during a TLSv1.2 handshake and hooked into OpenSSL via {@code SSL_CTX_set_psk_server_callback}. + * The interface for the Tomcat code that responds to the callback from the OpenSSL layer in Tomcat Native to allow + * Tomcat to select a pre-shared key. It supports TLSv1.2 {@code SSL_CTX_set_psk_server_callback} and TLSv1.3 + * {@code SSL_CTX_set_psk_find_session_callback}. */ public interface PreSharedKeySelector { @@ -27,7 +29,26 @@ public interface PreSharedKeySelector { * @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 + * @return the pre-shared key, or {@code null} if the identity is not recognized. OpenSSL limits the key to between + * 1 and 512 bytes long (inclusive). If the byte sequence is truly random then 16 bytes are recommended + * for 128-bit ciphers and 32 bytes for 256-bit ciphers. */ byte[] select(long ssl, String identity); + + /** + * Selects the TLSv1.3 pre-shared key and digest for the provided identity. + * <p> + * The callback is a little more complex for TLSv1.3. The return value is still the pre-shared key but OpenSSL also + * needs to know which digest to use. Because the OpenSSL API only exposes a cipher for this, that is what Tomcat + * populates the {@code cipherSuite} array with but only the digest is relevant. + * + * @param ssl the SSL instance + * @param identity the PSK identity provided by the client + * @param cipherSuite a single-element array that must be populated with a IANA TLSv1.3 cipher suite identifier + * + * @return the pre-shared key (strictly the input to the KDF), or {@code null} if the identity is not recognized. + * OpenSSL limits the key to between 1 and 48 bytes long (inclusive). If the byte sequence is truly + * random then 16 bytes are recommended for 128-bit ciphers and 32 bytes for 256-bit ciphers. + */ + byte[] select(long ssl, byte[] identity, int[] cipherSuite); } diff --git a/java/org/apache/tomcat/jni/SSLContext.java b/java/org/apache/tomcat/jni/SSLContext.java index ea3ef2c7ab..1a01d947cc 100644 --- a/java/org/apache/tomcat/jni/SSLContext.java +++ b/java/org/apache/tomcat/jni/SSLContext.java @@ -480,6 +480,15 @@ public final class SSLContext { */ public static native void setPskServerCallback(long ctx, PreSharedKeySelector selector); + /** + * Allow to hook {@link PreSharedKeySelector} into the TLSv1.3 handshake processing. This will call + * {@code SSL_CTX_set_psk_find_session_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 setPskFindSessionCallback(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]
