diff --git a/src/java/com/wolfssl/provider/jsse/WolfSSLImplementSSLSession.java b/src/java/com/wolfssl/provider/jsse/WolfSSLImplementSSLSession.java index 6659b3e..da2a317 100644 --- a/src/java/com/wolfssl/provider/jsse/WolfSSLImplementSSLSession.java +++ b/src/java/com/wolfssl/provider/jsse/WolfSSLImplementSSLSession.java @@ -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 */ diff --git a/src/test/com/wolfssl/provider/jsse/test/WolfSSLSessionTest.java b/src/test/com/wolfssl/provider/jsse/test/WolfSSLSessionTest.java index 2855eee..9a7593b 100644 --- a/src/test/com/wolfssl/provider/jsse/test/WolfSSLSessionTest.java +++ b/src/test/com/wolfssl/provider/jsse/test/WolfSSLSessionTest.java @@ -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 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;