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
commit 2e2897dcb82308019bdd40be3b5eede7918a572d Author: Gary Gregory <[email protected]> AuthorDate: Sun Sep 20 12:22:10 2020 -0400 [NET-687][FTPS] javax.net.ssl.SSLException: Unsupported or unrecognized SSL message, #59. --- src/changes/changes.xml | 4 ++ .../org/apache/commons/net/ftp/FTPSClient.java | 1 - .../org/apache/commons/net/ftp/FTPSClientTest.java | 48 ++++++++++++++++++---- .../apache/commons/net/ftpsserver/users.properties | 6 +-- .../org/apache/commons/net/test-data/file.txt | 20 +++++++++ 5 files changed, 67 insertions(+), 12 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index c5a826d..7b8a13b 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -64,6 +64,10 @@ The <action> type attribute can be add,update,fix,remove. <body> <release version="3.8" date="20YY-MM-DD" description="TBD"> + <action issue="NET-687" type="fix" dev="ggregory" due-to="Gary Gregory, Mikael, j-verse"> + Update actions/checkout from v2.3.1 to v2.3.2 #56. + </action> + <!-- UPDATES --> <action issue="NET-673" type="fix" dev="ggregory" due-to="Dependabot"> Update actions/checkout from v2.3.1 to v2.3.2 #56. </action> 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 02cf59a..504915e 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java @@ -620,7 +620,6 @@ public class FTPSClient extends FTPClient { protected Socket _openDataConnection_(String command, String arg) throws IOException { Socket socket = super._openDataConnection_(command, arg); - socket = createSSLSocket(socket); _prepareDataSocket_(socket); if (socket instanceof SSLSocket) { SSLSocket sslSocket = (SSLSocket)socket; 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 004c968..e781541 100644 --- a/src/test/java/org/apache/commons/net/ftp/FTPSClientTest.java +++ b/src/test/java/org/apache/commons/net/ftp/FTPSClientTest.java @@ -27,6 +27,7 @@ import java.net.SocketException; import java.net.URL; import org.apache.commons.io.FileUtils; +import org.apache.commons.io.output.NullOutputStream; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.ftplet.FtpException; @@ -56,13 +57,10 @@ public class FTPSClientTest { /** * Returns the test directory as a String. - * <p> - * {@link #getTestDirectoryFile()} should be preferred. - * * @return the test directory as a String */ - private static String getTestDirectory() { - return System.getProperty("test.basedir", "target/test-classes/test-data"); + private static String getTestHomeDirectory() { + return System.getProperty("test.basedir", "target/test-classes/org/apache/commons/net/test-data"); } private static final boolean implicit = false; @@ -83,6 +81,7 @@ public class FTPSClientTest { if (Server != null) { return; } + // Use an ephemeral port. SocketPort = 0; final FtpServerFactory serverFactory = new FtpServerFactory(); final PropertiesUserManagerFactory propertiesUserManagerFactory = new PropertiesUserManagerFactory(); @@ -93,7 +92,7 @@ public class FTPSClientTest { final BaseUser user = (BaseUser) userManager.getUserByName("test"); // Pickup the home dir value at runtime even though we have it set in the user prop file // The user prop file requires the "homedirectory" to be set - user.setHomeDirectory(getTestDirectory()); + user.setHomeDirectory(getTestHomeDirectory()); serverFactory.setUserManager(userManager); final ListenerFactory factory = new ListenerFactory(); // set the port of the listener @@ -125,13 +124,28 @@ public class FTPSClientTest { private FTPSClient loginClient() throws SocketException, IOException { FTPSClient client = new FTPSClient(implicit); client.connect("localhost", SocketPort); + assertClientCode(client); assertEquals(SocketPort, client.getRemotePort()); - final int replyCode = client.getReplyCode(); - assertTrue(FTPReply.isPositiveCompletion(replyCode)); + // assertTrue(client.login("test", "test")); + assertClientCode(client); + // + client.setFileType(FTP.BINARY_FILE_TYPE); + assertClientCode(client); + // + client.execPBSZ(0); + assertClientCode(client); + // + client.execPROT("P"); + assertClientCode(client); return client; } + private void assertClientCode(FTPSClient client) { + final int replyCode = client.getReplyCode(); + assertTrue(FTPReply.isPositiveCompletion(replyCode)); + } + @Test public void testOpenClose() throws SocketException, IOException { loginClient().disconnect(); @@ -148,12 +162,29 @@ public class FTPSClientTest { } } + private void retrieveFile(String pathname) throws SocketException, IOException { + FTPSClient client = loginClient(); + try { + // Do it twice. + // Just testing that we are not getting an SSL error (the file MUST be present). + assertTrue(pathname, client.retrieveFile(pathname, NullOutputStream.NULL_OUTPUT_STREAM)); + assertTrue(pathname, client.retrieveFile(pathname, NullOutputStream.NULL_OUTPUT_STREAM)); + } finally { + client.disconnect(); + } + } + @Test public void testListFilesPathNameRoot() throws SocketException, IOException { testListFiles("/"); } @Test + public void testRetrieveFilePathNameRoot() throws SocketException, IOException { + retrieveFile("/file.txt"); + } + + @Test public void testListFilesPathNameEmpty() throws SocketException, IOException { testListFiles(""); } @@ -168,3 +199,4 @@ public class FTPSClientTest { testListFiles(" Junk "); } } + diff --git a/src/test/resources/org/apache/commons/net/ftpsserver/users.properties b/src/test/resources/org/apache/commons/net/ftpsserver/users.properties index 59fe696..521c443 100644 --- a/src/test/resources/org/apache/commons/net/ftpsserver/users.properties +++ b/src/test/resources/org/apache/commons/net/ftpsserver/users.properties @@ -17,7 +17,7 @@ # Password is "admin" ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3 -ftpserver.user.admin.homedirectory=target/test-classes/test-data +ftpserver.user.admin.homedirectory=target/test-classes/org/apache/commons/net/test-data ftpserver.user.admin.enableflag=true ftpserver.user.admin.writepermission=true ftpserver.user.admin.maxloginnumber=0 @@ -27,7 +27,7 @@ ftpserver.user.admin.uploadrate=0 ftpserver.user.admin.downloadrate=0 ftpserver.user.anonymous.userpassword= -ftpserver.user.anonymous.homedirectory=target/test-classes/test-data +ftpserver.user.anonymous.homedirectory=target/test-classes/org/apache/commons/net/test-data ftpserver.user.anonymous.enableflag=true ftpserver.user.anonymous.writepermission=false ftpserver.user.anonymous.maxloginnumber=20 @@ -38,6 +38,6 @@ ftpserver.user.anonymous.downloadrate=4800 # password is "test" ftpserver.user.test.userpassword=098f6bcd4621d373cade4e832627b4f6 -ftpserver.user.test.homedirectory=target/test-classes/test-data +ftpserver.user.test.homedirectory=target/test-classes/org/apache/commons/net/test-data ftpserver.user.test.enableflag=true ftpserver.user.test.writepermission=true diff --git a/src/test/resources/org/apache/commons/net/test-data/file.txt b/src/test/resources/org/apache/commons/net/test-data/file.txt new file mode 100644 index 0000000..eba8c13 --- /dev/null +++ b/src/test/resources/org/apache/commons/net/test-data/file.txt @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +“We are all in the gutter, but some of us are looking at the stars.” + +― Oscar Wilde, Lady Windermere's Fan
