You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-commits@incubator.apache.org by ng...@apache.org on 2006/11/25 10:56:31 UTC
svn commit: r479117 - in
/incubator/ftpserver/trunk/ssl-tests/src/test/org/apache:
commons/net/ftp/FTPSClient.java ftpserver/ssl/ClientAuthTest.java
ftpserver/ssl/SSLTestTemplate.java
Author: ngn
Date: Sat Nov 25 02:56:30 2006
New Revision: 479117
URL: http://svn.apache.org/viewvc?view=rev&rev=479117
Log:
Test for client authentication. Needs a patched FTPSClient to run.
Added:
incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ClientAuthTest.java (with props)
Modified:
incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/commons/net/ftp/FTPSClient.java
incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java
Modified: incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/commons/net/ftp/FTPSClient.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/commons/net/ftp/FTPSClient.java?view=diff&rev=479117&r1=479116&r2=479117
==============================================================================
--- incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/commons/net/ftp/FTPSClient.java (original)
+++ incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/commons/net/ftp/FTPSClient.java Sat Nov 25 02:56:30 2006
@@ -21,14 +21,20 @@
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.security.KeyManagementException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509KeyManager;
/**
* FTP over SSL processing. If desired, the JVM property -Djavax.net.debug=all can be used to
@@ -76,6 +82,10 @@
private String[] suites = null;
/** The protocol versions */
private String[] protocols = null;
+ /** Client keystore */
+ private KeyStore keystore;
+ /** Client keystore password */
+ private char[] keystorePassword;
/** The FTPS {@link TrustManager} implementation. */
private TrustManager trustManager = new FTPSTrustManager();
@@ -194,10 +204,22 @@
planeSocket = _socket_;
try {
- context.init(null, new TrustManager[] { getTrustManager() } , null);
+ if(keystore != null) {
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
+ kmf.init(keystore, keystorePassword);
+ context.init(kmf.getKeyManagers(), new TrustManager[] { getTrustManager() } , null);
+ } else {
+ context.init(null, new TrustManager[] { getTrustManager() } , null);
+ }
} catch (KeyManagementException e) {
e.printStackTrace();
- }
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (KeyStoreException e) {
+ e.printStackTrace();
+ } catch (UnrecoverableKeyException e) {
+ e.printStackTrace();
+ }
SSLSocketFactory ssf = context.getSocketFactory();
String ip = _socket_.getInetAddress().getHostAddress();
@@ -478,6 +500,34 @@
public void setTrustManager(TrustManager trustManager) {
this.trustManager = trustManager;
}
+
+ /**
+ * @return the keystore
+ */
+ public KeyStore getKeystore() {
+ return keystore;
+ }
+
+ /**
+ * @param keystore the keystore to set
+ */
+ public void setKeystore(KeyStore keystore) {
+ this.keystore = keystore;
+ }
+
+ /**
+ * @return the keystorePassword
+ */
+ public char[] getKeystorePassword() {
+ return keystorePassword;
+ }
+
+ /**
+ * @param keystorePassword the keystorePassword to set
+ */
+ public void setKeystorePassword(char[] keystorePassword) {
+ this.keystorePassword = keystorePassword;
+ }
Added: incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ClientAuthTest.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ClientAuthTest.java?view=auto&rev=479117
==============================================================================
--- incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ClientAuthTest.java (added)
+++ incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ClientAuthTest.java Sat Nov 25 02:56:30 2006
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+package org.apache.ftpserver.ssl;
+
+import java.io.FileInputStream;
+import java.security.KeyStore;
+
+import org.apache.commons.net.ftp.FTPReply;
+import org.apache.commons.net.ftp.FTPSClient;
+
+
+public class ClientAuthTest extends SSLTestTemplate {
+
+
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ client.login(ADMIN_USERNAME, ADMIN_PASSWORD);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.ftpserver.ssl.SSLTestTemplate#createFTPClient()
+ */
+ protected FTPSClient createFTPClient() throws Exception {
+ FTPSClient client = new FTPSClient();
+ client.setNeedClientAuth(true);
+ KeyStore ks = KeyStore.getInstance("JKS");
+ ks.load(new FileInputStream(FTPCLIENT_KEYSTORE), KEYSTORE_PASSWORD);
+ client.setKeystore(ks);
+ client.setKeystorePassword(KEYSTORE_PASSWORD);
+
+ return client;
+ }
+
+ protected String getAuthValue() {
+ return "TLS";
+ }
+
+ protected String getClientAuth() {
+ return "true";
+ }
+
+ public void testCommandChannel() throws Exception {
+ assertTrue(FTPReply.isPositiveCompletion(client.noop()));
+ }
+
+}
Propchange: incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/ClientAuthTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java
URL: http://svn.apache.org/viewvc/incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java?view=diff&rev=479117&r1=479116&r2=479117
==============================================================================
--- incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java (original)
+++ incubator/ftpserver/trunk/ssl-tests/src/test/org/apache/ftpserver/ssl/SSLTestTemplate.java Sat Nov 25 02:56:30 2006
@@ -41,7 +41,8 @@
public abstract class SSLTestTemplate extends TestCase {
private static final File USERS_FILE = new File(getBaseDir(), "src/test/users.gen");
- private static final File FTPCLIENT_KEYSTORE = new File(getBaseDir(), "src/test/client.jks");
+ protected static final File FTPCLIENT_KEYSTORE = new File(getBaseDir(), "src/test/client.jks");
+ protected static final char[] KEYSTORE_PASSWORD = "password".toCharArray();
private static final File FTPSERVER_KEYSTORE = new File(getBaseDir(), "src/test/ftpserver.jks");
@@ -71,7 +72,7 @@
if(basedir != null) {
return new File(basedir);
} else {
- return new File("");
+ return new File(".");
}
}