Merge pull request #111 from cconlon/sslSocketNullHost

Support null host with createSocket(Socket, String, int, boolean)
pull/112/head
JacobBarthelmeh 2022-11-22 10:13:39 -07:00 committed by GitHub
commit f515a3e60c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 2 deletions

View File

@ -333,7 +333,6 @@ public class WolfSSLSocket extends SSLSocket {
this.params = params.copy();
this.socket = s;
this.autoClose = autoClose;
this.address = new InetSocketAddress(host, port);
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
"creating new WolfSSLSocket(clientMode: " +

View File

@ -528,7 +528,8 @@ public class WolfSSLServerSocketTest {
/* Expected. Different versions of wolfSSL can display
* varying error strings. Check for either here. */
if (!e.toString().contains("ASN no signer") &&
!e.toString().contains("certificate verify failed")) {
!e.toString().contains("certificate verify failed") &&
!e.toString().contains("ASN self-signed certificate error")) {
System.out.println("\t\t... failed");
fail();
}

View File

@ -89,6 +89,7 @@ import com.wolfssl.WolfSSLException;
public void testGetSetEnabledProtocols();
public void testClientServerThreaded();
public void testPreConsumedSocket();
public void testCreateSocketNullHost();
public void testEnableSessionCreation();
public void testSetUseClientMode();
public void testGetSSLParameters();
@ -530,6 +531,36 @@ public class WolfSSLSocketTest {
System.out.println("\t... passed");
}
@Test
public void testCreateSocketNullHost() throws Exception {
System.out.print("\tcreateSocket(null host)");
/* create new CTX */
this.ctx = tf.createSSLContext("TLS", ctxProvider);
/* create new ServerSocket first to get ephemeral port */
ServerSocket ss = new ServerSocket(0);
/* create new Socket, connect() to server */
Socket cs = new Socket();
cs.connect(new InetSocketAddress(ss.getLocalPort()));
/* accept client connection, normal java.net.Socket */
final Socket socket = ss.accept();
/* Try to convert client Socket to SSLSocket, with null hostname.
* This should not throw any Exceptions, null host is ok. */
SSLSocket ssc = (SSLSocket)ctx.getSocketFactory().createSocket(
cs, null, cs.getPort(), false);
ssc.close();
cs.close();
socket.close();
ss.close();
System.out.println("\t\t... passed");
}
@Test
public void testEnableSessionCreation() throws Exception {