You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/10/03 13:38:43 UTC

[commons-net] branch master updated: [NET-689] Hostname is not set on the SSLSocket causing isEndpointCheckingEnabled to fail. The main side of this commit is from https://github.com/apache/commons-net/pull/63 but the test side has been rewritten to test endpoint checking as both enabled and disabled.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new 7827f05  [NET-689] Hostname is not set on the SSLSocket causing isEndpointCheckingEnabled to fail. The main side of this commit is from https://github.com/apache/commons-net/pull/63 but the test side has been rewritten to test endpoint checking as both enabled and disabled.
7827f05 is described below

commit 7827f0549526920b91aa2e62d2a1e7682c36e1e7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Oct 3 09:38:39 2020 -0400

    [NET-689] Hostname is not set on the SSLSocket causing
    isEndpointCheckingEnabled to fail.
    The main side of this commit is from
    https://github.com/apache/commons-net/pull/63 but the test side has been
    rewritten to test endpoint checking as both enabled and disabled.
---
 src/changes/changes.xml                            |   3 ++
 .../org/apache/commons/net/ftp/FTPSClient.java     |   4 +--
 .../org/apache/commons/net/ftp/FTPSClientTest.java |  31 +++++++++++++++------
 .../apache/commons/net/ftpsserver/ftpserver.jks    | Bin 1961 -> 3051 bytes
 4 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b7b25b2..7d9d9e7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -64,6 +64,9 @@ The <action> type attribute can be add,update,fix,remove.
 
     <body>
         <release version="3.7.2" date="20YY-MM-DD" description="Maintenance and bug fix release.">
+            <action issue="NET-689" type="update" dev="ggregory" due-to="Charlie, Gary Gregory">
+            Hostname is not set on the SSLSocket causing isEndpointCheckingEnabled to fail.
+            </action>
             <!--  UPDATES -->
             <action type="update" dev="ggregory" due-to="Dependabot">
             Bump actions/setup-java from v1.4.2 to v1.4.3 #62.
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
index c2f0983..6f5d6c4 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
@@ -291,7 +291,7 @@ public class FTPSClient extends FTPClient {
 
         if (isClientMode) {
             if (hostnameVerifier != null &&
-                !hostnameVerifier.verify(socket.getInetAddress().getHostAddress(), socket.getSession())) {
+                !hostnameVerifier.verify(_hostname_, socket.getSession())) {
                 throw new SSLHandshakeException("Hostname doesn't match certificate");
             }
         }
@@ -895,7 +895,7 @@ public class FTPSClient extends FTPClient {
     private Socket createSSLSocket(final Socket socket) throws IOException {
         if (socket != null) {
             final SSLSocketFactory f = context.getSocketFactory();
-            return f.createSocket(socket, socket.getInetAddress().getHostAddress(), socket.getPort(), false);
+            return f.createSocket(socket, _hostname_, socket.getPort(), false);
         }
         return null;
     }
diff --git a/src/test/java/org/apache/commons/net/ftp/FTPSClientTest.java b/src/test/java/org/apache/commons/net/ftp/FTPSClientTest.java
index c8ca7eb..37a2655 100644
--- a/src/test/java/org/apache/commons/net/ftp/FTPSClientTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/FTPSClientTest.java
@@ -40,13 +40,16 @@ import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
 
 /**
  * Tests {@link FTPSClient}.
  * <p>
  * To get our test cert to work on Java 11, this test must be run with:
  * </p>
- * 
+ *
  * <pre>
  * -Djdk.tls.client.protocols="TLSv1.1"
  * </pre>
@@ -54,8 +57,16 @@ import org.junit.Test;
  * This test does the above programmatically.
  * </p>
  */
+@RunWith(Parameterized.class)
 public class FTPSClientTest {
 
+    private final boolean endpointCheckingEnabled;
+
+    public FTPSClientTest(final boolean endpointCheckingEnabled) {
+        super();
+        this.endpointCheckingEnabled = endpointCheckingEnabled;
+    }
+
     private static final String JDK_TLS_CLIENT_PROTOCOLS = "jdk.tls.client.protocols";
 
     private static int SocketPort;
@@ -72,6 +83,11 @@ public class FTPSClientTest {
 
     private static String TlsProtocols;
 
+    @Parameters(name = "endpointCheckingEnabled={0}")
+    public static Boolean[] testConstructurData() {
+        return new Boolean[] {Boolean.FALSE, Boolean.TRUE};
+    }
+
     @AfterClass
     public static void afterClass() {
         if (TlsProtocols == null) {
@@ -83,7 +99,7 @@ public class FTPSClientTest {
 
     /**
      * Returns the test directory as a String.
-     * 
+     *
      * @return the test directory as a String
      */
     private static String getTestHomeDirectory() {
@@ -91,14 +107,10 @@ public class FTPSClientTest {
     }
 
     @BeforeClass
-    public static void setUp() throws Exception {
-        setUpClass(implicit);
-    }
-
-    @BeforeClass
-    public static void setUpClass() {
+    public static void setUpClass() throws Exception {
         TlsProtocols = System.getProperty(JDK_TLS_CLIENT_PROTOCOLS);
         System.setProperty(JDK_TLS_CLIENT_PROTOCOLS, "TLSv1");
+        setUpClass(implicit);
     }
 
     /**
@@ -152,7 +164,7 @@ public class FTPSClientTest {
         Server.start();
         SocketPort = ((org.apache.ftpserver.impl.DefaultFtpServer) Server).getListener("default").getPort();
         ConnectionUri = "ftps://test:test@localhost:" + SocketPort;
-        System.out.printf("jdk.tls.disabledAlgorithms = %s%n", System.getProperty("jdk.tls.disabledAlgorithms"));
+        // System.out.printf("jdk.tls.disabledAlgorithms = %s%n", System.getProperty("jdk.tls.disabledAlgorithms"));
     }
 
     private void assertClientCode(final FTPSClient client) {
@@ -162,6 +174,7 @@ public class FTPSClientTest {
 
     private FTPSClient loginClient() throws SocketException, IOException {
         final FTPSClient client = new FTPSClient(implicit);
+        client.setEndpointCheckingEnabled(endpointCheckingEnabled);
         client.connect("localhost", SocketPort);
         assertClientCode(client);
         assertEquals(SocketPort, client.getRemotePort());
diff --git a/src/test/resources/org/apache/commons/net/ftpsserver/ftpserver.jks b/src/test/resources/org/apache/commons/net/ftpsserver/ftpserver.jks
index 28f294b..53e9ee6 100644
Binary files a/src/test/resources/org/apache/commons/net/ftpsserver/ftpserver.jks and b/src/test/resources/org/apache/commons/net/ftpsserver/ftpserver.jks differ