[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-commons-dev
Subject: svn commit: r1087508 - in /commons/proper/net/trunk/src: changes/changes.xml
From: sebb () apache ! org
Date: 2011-03-31 23:35:11
Message-ID: 20110331233511.B5CA42388A38 () eris ! apache ! org
[Download RAW message or body]
Author: sebb
Date: Thu Mar 31 23:35:11 2011
New Revision: 1087508
URL: http://svn.apache.org/viewvc?rev=1087508&view=rev
Log:
NET-397 FTPSClient does not handle AUTH or ADAT and only partially handles PBSZ. \
FTPSCommand should be deprecated.
Modified:
commons/proper/net/trunk/src/changes/changes.xml
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPReply.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSCommand.java
Modified: commons/proper/net/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/changes/changes.xml?rev=1087508&r1=1087507&r2=1087508&view=diff
==============================================================================
--- commons/proper/net/trunk/src/changes/changes.xml (original)
+++ commons/proper/net/trunk/src/changes/changes.xml Thu Mar 31 23:35:11 2011
@@ -57,6 +57,9 @@ The <action> type attribute can be add,u
<body>
<release version="3.0" date="TBA" description="TBA">
+ <action issue="NET-397" dev="sebb" type="update" due-to="Bogdan \
Drozdowski" due-to-email="bogdandr # op . pl"> + FTPSClient does not \
handle AUTH or ADAT and only partially handles PBSZ. FTPSCommand should be \
deprecated. + </action>
<action issue="NET-268" dev="sebb" type="fix">
Better handling of CIDR/31 and CIDR/32 where isInclusive = false.
Return 0 for address count, and 0.0.0.0 for each of the addresses
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPReply.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPReply.java?rev=1087508&r1=1087507&r2=1087508&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPReply.java \
(original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPReply.java \
Thu Mar 31 23:35:11 2011 @@ -250,4 +250,19 @@ public final class FTPReply
return (reply >= 500 && reply < 600);
}
+ /**
+ * Determine if a reply code is a protected response.
+ * @param reply The reply code to test.
+ * @return True if a reply code is a protected response, false
+ * if not.
+ * @since 3.0
+ */
+ public static boolean isProtectedReplyCode(int reply)
+ {
+ // actually, only 3 protected reply codes are
+ // defined in RFC 2228: 631, 632 and 633.
+ return (reply >= 600 && reply < 700);
+ }
+
+
}
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSClient.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSClient.java?rev=1087508&r1=1087507&r2=1087508&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSClient.java \
(original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSClient.java \
Thu Mar 31 23:35:11 2011 @@ -30,6 +30,7 @@ import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
+import org.apache.commons.net.util.Base64;
import org.apache.commons.net.util.SSLContextUtils;
/**
@@ -58,6 +59,23 @@ public class FTPSClient extends FTPClien
/** Default secure socket protocol name, i.e. TLS */
private static final String DEFAULT_PROTOCOL = "TLS";
+ /** The AUTH (Authentication/Security Mechanism) command. */
+ private static final String CMD_AUTH = "AUTH";
+ /** The ADAT (Authentication/Security Data) command. */
+ private static final String CMD_ADAT = "ADAT";
+ /** The PROT (Data Channel Protection Level) command. */
+ private static final String CMD_PROT = "PROT";
+ /** The PBSZ (Protection Buffer Size) command. */
+ private static final String CMD_PBSZ = "PBSZ";
+ /** The MIC (Integrity Protected Command) command. */
+ private static final String CMD_MIC = "MIC";
+ /** The CONF (Confidentiality Protected Command) command. */
+ private static final String CMD_CONF = "CONF";
+ /** The ENC (Privacy Protected Command) command. */
+ private static final String CMD_ENC = "ENC";
+ /** The CCC (Clear Command Channel) command. */
+ private static final String CMD_CCC = "CCC";
+
/** The security mode. (True - Implicit Mode / False - Explicit Mode) */
private final boolean isImplicit;
/** The secure socket protocol to be used, e.g. SSL/TLS. */
@@ -194,8 +212,7 @@ public class FTPSClient extends FTPClien
* the command.
*/
private void execAUTH() throws SSLException, IOException {
- int replyCode = sendCommand(
- FTPSCommand.getCommand(FTPSCommand.AUTH), auth);
+ int replyCode = sendCommand(CMD_AUTH, auth);
if (FTPReply.SECURITY_MECHANISM_IS_OK == replyCode) {
// replyCode = 334
// I carry out an ADAT command.
@@ -402,16 +419,43 @@ public class FTPSClient extends FTPClien
* @throws SSLException If the server reply code does not equal "200".
* @throws IOException If an I/O error occurs while sending
* the command.
+ * @see #parsePBSZ(long)
*/
public void execPBSZ(long pbsz) throws SSLException, IOException {
- if (pbsz < 0 || 4294967295L < pbsz)
+ if (pbsz < 0 || 4294967295L < pbsz) // 32-bit unsigned number
throw new IllegalArgumentException();
- if (FTPReply.COMMAND_OK != sendCommand(
- FTPSCommand.getCommand(FTPSCommand.PBSZ),String.valueOf(pbsz)))
+ int status = sendCommand(CMD_PBSZ, String.valueOf(pbsz));
+ if (FTPReply.COMMAND_OK != status) {
throw new SSLException(getReplyString());
+ }
}
/**
+ * PBSZ command. pbsz value: 0 to (2^32)-1 decimal integer.
+ * Issues the command and parses the response to return the negotiated value.
+ *
+ * @param pbsz Protection Buffer Size.
+ * @throws SSLException If the server reply code does not equal "200".
+ * @throws IOException If an I/O error occurs while sending
+ * the command.
+ * @return the negotiated value.
+ * @see #execPBSZ(long)
+ * @since 3.0
+ */
+ public long parsePBSZ(long pbsz) throws SSLException, IOException {
+ execPBSZ(pbsz);
+ long minvalue = pbsz;
+ String remainder = extractPrefixedData("PBSZ=", getReplyString());
+ if (remainder != null) {
+ long replysz = Long.parseLong(remainder);
+ if (replysz < minvalue) {
+ minvalue = replysz;
+ }
+ }
+ return minvalue;
+ }
+
+ /**
* PROT command.</br>
* C - Clear</br>
* S - Safe(SSL protocol only)</br>
@@ -430,8 +474,7 @@ public class FTPSClient extends FTPClien
public void execPROT(String prot) throws SSLException, IOException {
if (prot == null) prot = DEFAULT_PROT;
if (!checkPROTValue(prot)) throw new IllegalArgumentException();
- if (FTPReply.COMMAND_OK != sendCommand(
- FTPSCommand.getCommand(FTPSCommand.PROT), prot))
+ if (FTPReply.COMMAND_OK != sendCommand(CMD_PROT, prot))
throw new SSLException(getReplyString());
if (DEFAULT_PROT.equals(prot)) {
setSocketFactory(null);
@@ -465,11 +508,12 @@ public class FTPSClient extends FTPClien
* the command.
* @see org.apache.commons.net.ftp.FTP#sendCommand(java.lang.String)
*/
+ // Would like to remove this method, but that will break any existing clients \
that are using CCC @Override
public int sendCommand(String command, String args) throws IOException {
int repCode = super.sendCommand(command, args);
/* If CCC is issued, restore socket i/o streams to unsecured versions */
- if (FTPSCommand.getCommand(FTPSCommand.CCC).equals(command)) {
+ if (CMD_CCC.equals(command)) {
if (FTPReply.COMMAND_OK == repCode) {
_socket_.close();
_socket_ = plainSocket;
@@ -561,6 +605,154 @@ public class FTPSClient extends FTPClien
setServerSocketFactory(null);
}
+ /**
+ * Send the AUTH command with the specified mechanism.
+ * @param mechanism The mechanism name to send with the command.
+ * @return server reply.
+ * @throws IOException If an I/O error occurs while sending
+ * the command.
+ * @since 3.0
+ */
+ public int execAUTH(String mechanism) throws IOException
+ {
+ return sendCommand(CMD_AUTH, mechanism);
+ }
+
+ /**
+ * Send the ADAT command with the specified authentication data.
+ * @param data The data to send with the command.
+ * @return server reply.
+ * @throws IOException If an I/O error occurs while sending
+ * the command.
+ * @since 3.0
+ */
+ public int execADAT(byte[] data) throws IOException
+ {
+ if (data != null)
+ {
+ return sendCommand(CMD_ADAT, new String(Base64.encodeBase64(data)));
+ }
+ else
+ {
+ return sendCommand(CMD_ADAT);
+ }
+ }
+
+ /**
+ * Send the CCC command to the server.
+ * The CCC (Clear Command Channel) command causes the underlying {@link \
SSLSocket} instance to be assigned + * to a plain {@link Socket} instances
+ * @return server reply.
+ * @throws IOException If an I/O error occurs while sending
+ * the command.
+ * @since 3.0
+ */
+ public int execCCC() throws IOException
+ {
+ int repCode = sendCommand(CMD_CCC);
+// This will be performed by sendCommand(String, String)
+// if (FTPReply.isPositiveCompletion(repCode)) {
+// _socket_.close();
+// _socket_ = plainSocket;
+// _controlInput_ = new BufferedReader(
+// new InputStreamReader(
+// _socket_.getInputStream(), getControlEncoding()));
+// _controlOutput_ = new BufferedWriter(
+// new OutputStreamWriter(
+// _socket_.getOutputStream(), getControlEncoding()));
+// }
+ return repCode;
+ }
+
+ /**
+ * Send the MIC command with the specified data.
+ * @param data The data to send with the command.
+ * @return server reply.
+ * @throws IOException If an I/O error occurs while sending
+ * the command.
+ * @since 3.0
+ */
+ public int execMIC(byte[] data) throws IOException
+ {
+ if (data != null)
+ {
+ return sendCommand(CMD_MIC, new String(Base64.encodeBase64(data)));
+ }
+ else
+ {
+ return sendCommand(CMD_MIC, ""); // perhaps "=" or just \
sendCommand(String)? + }
+ }
+
+ /**
+ * Send the CONF command with the specified data.
+ * @param data The data to send with the command.
+ * @return server reply.
+ * @throws IOException If an I/O error occurs while sending
+ * the command.
+ * @since 3.0
+ */
+ public int execCONF(byte[] data) throws IOException
+ {
+ if (data != null)
+ {
+ return sendCommand(CMD_CONF, new String(Base64.encodeBase64(data)));
+ }
+ else
+ {
+ return sendCommand(CMD_CONF, ""); // perhaps "=" or just \
sendCommand(String)? + }
+ }
+
+ /**
+ * Send the ENC command with the specified data.
+ * @param data The data to send with the command.
+ * @return server reply.
+ * @throws IOException If an I/O error occurs while sending
+ * the command.
+ * @since 3.0
+ */
+ public int execENC(byte[] data) throws IOException
+ {
+ if (data != null)
+ {
+ return sendCommand(CMD_ENC, new String(Base64.encodeBase64(data)));
+ }
+ else
+ {
+ return sendCommand(CMD_ENC, ""); // perhaps "=" or just \
sendCommand(String)? + }
+ }
+
+ /**
+ * Parses the given ADAT response line and base64-decodes the data.
+ * @param reply The ADAT reply to parse.
+ * @return the data in the reply, base64-decoded.
+ * @since 3.0
+ */
+ public byte[] parseADATReply(String reply)
+ {
+ if (reply == null) return null;
+ else {
+ return Base64.decodeBase64(extractPrefixedData("ADAT=", reply));
+ }
+ }
+
+ /**
+ * Extract the data from a reply with a prefix, e.g. PBSZ=1234 => 1234
+ * @param prefix the prefix to find
+ * @param reply where to find the prefix
+ * @return the remainder of the string after the prefix, or null if the prefix \
was not present. + */
+ private String extractPrefixedData(String prefix, String reply) {
+ int idx = reply.indexOf(prefix);
+ if (idx == -1) {
+ return null;
+ }
+ // N.B. Cannot use trim before substring as leading space would affect the \
offset. + return reply.substring(idx+prefix.length()).trim();
+ }
+
// DEPRECATED - for API compatibility only - DO NOT USE
/** @deprecated - not used - may be removed in a future release */
Modified: commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSCommand.java
URL: http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSCommand.java?rev=1087508&r1=1087507&r2=1087508&view=diff
==============================================================================
--- commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSCommand.java \
(original)
+++ commons/proper/net/trunk/src/main/java/org/apache/commons/net/ftp/FTPSCommand.java \
Thu Mar 31 23:35:11 2011 @@ -18,9 +18,11 @@
package org.apache.commons.net.ftp;
/**
- * FTPS-specific command
+ * FTPS-specific commands.
* @since 2.0
+ * @deprecated 3.0 DO NOT USE
*/
+@Deprecated
public final class FTPSCommand {
public static final int AUTH = 0;
public static final int ADAT = 1;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic