Correctly set the data connection as protected when using AUTH SSL
authorNiklas Gustavsson <ngn@apache.org>
Tue, 1 May 2012 21:52:58 +0000 (21:52 +0000)
committerNiklas Gustavsson <ngn@apache.org>
Tue, 1 May 2012 21:52:58 +0000 (21:52 +0000)
Fixes FTPSERVER-431

Also adds support for the TLS-C and TLS-P auth types

git-svn-id: https://svn.apache.org/repos/asf/mina/ftpserver/trunk@1332855 13f79535-47bb-0310-9956-ffa450edef68

core/src/main/java/org/apache/ftpserver/command/impl/AUTH.java
core/src/test/java/org/apache/ftpserver/ssl/ExplicitSecurityTestTemplate.java
core/src/test/java/org/apache/ftpserver/ssl/MinaImplicitDataChannelTest.java

index 06e030c..070ef48 100644 (file)
@@ -50,7 +50,7 @@ public class AUTH extends AbstractCommand {
 
     private final Logger LOG = LoggerFactory.getLogger(AUTH.class);
 
-    private static final List<String> VALID_AUTH_TYPES = Arrays.asList("SSL", "TLS");
+    private static final List<String> VALID_AUTH_TYPES = Arrays.asList("SSL", "TLS", "TLS-C", "TLS-P");
 
     /**
      * Execute command
@@ -100,6 +100,12 @@ public class AUTH extends AbstractCommand {
         // check parameter
         String authType = request.getArgument().toUpperCase();
         if (VALID_AUTH_TYPES.contains(authType)) {
+            if(authType.equals("TLS-C")) {
+                authType = "TLS";
+            } else if(authType.equals("TLS-P")) {
+                authType = "SSL";
+            }
+
             try {
                 secureSession(session, authType);
                 session.write(LocalizedFtpReply.translate(session, request, context,
@@ -141,6 +147,9 @@ public class AUTH extends AbstractCommand {
             session.getFilterChain().addFirst(SSL_SESSION_FILTER_NAME,
                     sslFilter);
 
+            if("SSL".equals(type)) {
+                session.getDataConnection().setSecure(true);
+            }
         } else {
             throw new FtpException("Socket factory SSL not configured");
         }
index a8bd82d..69b0df0 100644 (file)
@@ -47,12 +47,19 @@ public abstract class ExplicitSecurityTestTemplate extends SSLTestTemplate {
         client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
     }
 
+    protected boolean expectDataConnectionSecure() {
+        return getAuthValue().equals("SSL") && !useImplicit();
+    }
+
     /**
      * Tests that we can send command over the command channel. This is, in fact
      * already tested by login in setup but an explicit test is good anyways.
      */
     public void testCommandChannel() throws Exception {
         assertTrue(getActiveSession().isSecure());
+
+        assertEquals(expectDataConnectionSecure(), getActiveSession().getDataConnection().isSecure());
+
         assertTrue(FTPReply.isPositiveCompletion(client.noop()));
     }
 
index 2f34be7..e9d0355 100644 (file)
@@ -61,6 +61,10 @@ public class MinaImplicitDataChannelTest extends ImplicitSecurityTestTemplate {
         return true;
     }
 
+    protected boolean expectDataConnectionSecure() {
+        return true;
+    }
+
     /**
      * Simple test that the {@link ServerDataConnectionFactory#isSecure()} 
      * works as expected