Skip to content

Commit f515a3e

Browse files
Merge pull request #111 from cconlon/sslSocketNullHost
Support null host with createSocket(Socket, String, int, boolean)
2 parents 2f70e8a + d643ee0 commit f515a3e

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@ public WolfSSLSocket(com.wolfssl.WolfSSLContext context,
333333
this.params = params.copy();
334334
this.socket = s;
335335
this.autoClose = autoClose;
336-
this.address = new InetSocketAddress(host, port);
337336

338337
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
339338
"creating new WolfSSLSocket(clientMode: " +

src/test/com/wolfssl/provider/jsse/test/WolfSSLServerSocketTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ public Void call() throws Exception {
528528
/* Expected. Different versions of wolfSSL can display
529529
* varying error strings. Check for either here. */
530530
if (!e.toString().contains("ASN no signer") &&
531-
!e.toString().contains("certificate verify failed")) {
531+
!e.toString().contains("certificate verify failed") &&
532+
!e.toString().contains("ASN self-signed certificate error")) {
532533
System.out.println("\t\t... failed");
533534
fail();
534535
}

src/test/com/wolfssl/provider/jsse/test/WolfSSLSocketTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
public void testGetSetEnabledProtocols();
9090
public void testClientServerThreaded();
9191
public void testPreConsumedSocket();
92+
public void testCreateSocketNullHost();
9293
public void testEnableSessionCreation();
9394
public void testSetUseClientMode();
9495
public void testGetSSLParameters();
@@ -530,6 +531,36 @@ public Void call() throws Exception {
530531
System.out.println("\t... passed");
531532
}
532533

534+
@Test
535+
public void testCreateSocketNullHost() throws Exception {
536+
537+
System.out.print("\tcreateSocket(null host)");
538+
539+
/* create new CTX */
540+
this.ctx = tf.createSSLContext("TLS", ctxProvider);
541+
542+
/* create new ServerSocket first to get ephemeral port */
543+
ServerSocket ss = new ServerSocket(0);
544+
545+
/* create new Socket, connect() to server */
546+
Socket cs = new Socket();
547+
cs.connect(new InetSocketAddress(ss.getLocalPort()));
548+
549+
/* accept client connection, normal java.net.Socket */
550+
final Socket socket = ss.accept();
551+
552+
/* Try to convert client Socket to SSLSocket, with null hostname.
553+
* This should not throw any Exceptions, null host is ok. */
554+
SSLSocket ssc = (SSLSocket)ctx.getSocketFactory().createSocket(
555+
cs, null, cs.getPort(), false);
556+
557+
ssc.close();
558+
cs.close();
559+
socket.close();
560+
ss.close();
561+
562+
System.out.println("\t\t... passed");
563+
}
533564

534565
@Test
535566
public void testEnableSessionCreation() throws Exception {

0 commit comments

Comments
 (0)