F-3911: copy SNI server names in the WolfSSLImplementSSLSession copy constructor

pull/413/head
Chris Conlon 2026-09-02 10:59:11 -06:00
parent 20b34ec340
commit 58a00109a7
2 changed files with 37 additions and 1 deletions

View File

@ -269,6 +269,9 @@ public class WolfSSLImplementSSLSession extends ExtendedSSLSession {
this.peerCerts = orig.peerCerts.clone();
}
this.protocol = orig.protocol;
if (orig.sniServerNames != null) {
this.sniServerNames = new ArrayList<>(orig.sniServerNames);
}
/* This session has been copied and is therefore not inside the
* WolfSSLAuthStore session cache table currently */

View File

@ -28,7 +28,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.Executors;
@ -51,6 +51,9 @@ import java.security.cert.CertificateException;
import java.net.InetSocketAddress;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SNIHostName;
import javax.net.ssl.SNIServerName;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLSession;
@ -70,6 +73,7 @@ import org.junit.rules.TestRule;
import com.wolfssl.WolfSSL;
import com.wolfssl.WolfSSLException;
import com.wolfssl.WolfSSLJNIException;
import com.wolfssl.provider.jsse.WolfSSLImplementSSLSession;
import com.wolfssl.provider.jsse.WolfSSLProvider;
import com.wolfssl.provider.jsse.WolfSSLX509X;
import com.wolfssl.test.TimedTestWatcher;
@ -1392,6 +1396,35 @@ public class WolfSSLSessionTest {
}
}
@Test
public void testCopyConstructorPreservesSNIServerNames()
throws NoSuchAlgorithmException, KeyManagementException,
KeyStoreException, CertificateException, IOException,
NoSuchProviderException, UnrecoverableKeyException {
SSLContext ctx = tf.createSSLContext("TLS", engineProvider);
SSLEngine engine = ctx.createSSLEngine("localhost", 12345);
if (engine == null) {
fail("failed to create engine");
}
engine.setUseClientMode(true);
/* setSSLParameters() stores server names in the engine session */
SSLParameters params = engine.getSSLParameters();
params.setServerNames(Arrays.asList(new SNIHostName("localhost")));
engine.setSSLParameters(params);
WolfSSLImplementSSLSession orig =
(WolfSSLImplementSSLSession)engine.getSession();
assertNotNull(orig);
List<SNIServerName> names = orig.getSNIServerNames();
assertNotNull(names);
assertEquals(1, names.size());
WolfSSLImplementSSLSession copy = new WolfSSLImplementSSLSession(orig);
assertEquals(names, copy.getSNIServerNames());
}
private class listner implements SSLSessionBindingListener {
private SSLSession ses;