com.glub.secureftp.bean
Class SSLFTP

java.lang.Object
  extended by com.glub.secureftp.bean.FTP
      extended by com.glub.secureftp.bean.SSLFTP

public class SSLFTP
extends FTP

The SSLFTP class is responsible for handling the SSL extensions of the File Transfer Protocol.

Since:
2.5.1
Version:
$Revision: 47 $, $Date: 2009-12-04 00:33:29 -0800 (Fri, 04 Dec 2009) $

Field Summary
static short EXPLICIT_CONNECTION
          Used to set the connection type to explicit.
static short IMPLICIT_CONNECTION
          Used to set the connection type to implicit.
 
Fields inherited from class com.glub.secureftp.bean.FTP
ACTIVE_CONNECTION_TYPE, ASCII_TRANSFER_MODE, AUTO_TRANSFER_MODE, BINARY_TRANSFER_MODE, command, EBCDIC_TRANSFER_MODE, isConnected, isLoggedIn, lastPortFromRange, maxPortInRange, minPortInRange, modeZEnabled, PASSIVE_CONNECTION_TYPE, PASV_CONNECTION_TYPE, recvCmdStream, sendCmdStream
 
Constructor Summary
SSLFTP(SSLSessionManager sslSessionManager, HostInfo hostInfo, File keyStoreFile, String keyStorePass, SecureRandom random, short connectionType, OutputStream sendCmdStream, OutputStream recvCmdStream)
          Create a new SSLFTP object with a key store, response notification, and an overridden SecureRandom object.
SSLFTP(SSLSessionManager sslSessionManager, HostInfo hostInfo, File keyStoreFile, String keyStorePass, short connectionType)
          Create a new SSLFTP object with a key store but without response notification.
SSLFTP(SSLSessionManager sslSessionManager, HostInfo hostInfo, File keyStoreFile, String keyStorePass, short connectionType, OutputStream sendCmdStream, OutputStream recvCmdStream)
          Create a new SSLFTP object with a key store and response notification.
SSLFTP(SSLSessionManager sslSessionManager, HostInfo hostInfo, short connectionType)
          Create a new SSLFTP object without a key store nor response notification.
SSLFTP(SSLSessionManager sslSessionManager, HostInfo hostInfo, short connectionType, OutputStream sendCmdStream, OutputStream recvCmdStream)
          Create a new SSLFTP object without a key store but with response notification.
SSLFTP(SSLSessionManager sslSessionManager, String host, int port, File keyStoreFile, String keyStorePass, SecureRandom random, short connectionType, OutputStream sendCmdStream, OutputStream recvCmdStream)
          Create a new SSLFTP object with a key store, response notification, and an overridden SecureRandom object.
SSLFTP(SSLSessionManager sslSessionManager, String host, int port, File keyStoreFile, String keyStorePass, short connectionType)
          Create a new SSLFTP object with a key store but without response notification.
SSLFTP(SSLSessionManager sslSessionManager, String host, int port, File keyStoreFile, String keyStorePass, short connectionType, OutputStream sendCmdStream, OutputStream recvCmdStream)
          Create a new SSLFTP object with a key store and response notification.
SSLFTP(SSLSessionManager sslSessionManager, String host, int port, short connectionType)
          Create a new SSLFTP object without a key store nor response notification.
SSLFTP(SSLSessionManager sslSessionManager, String host, int port, short connectionType, OutputStream sendCmdStream, OutputStream recvCmdStream)
          Create a new SSLFTP object without a key store but with response notification.
 
Method Summary
protected  void aboutToTransferData()
          Called before data transfers begin.
 void clearClientAuthentication()
          Clear the client key from the keystore (if it exists)
 void connect()
          Connect to the FTP host and port with data encyption off by default.
 void connect(boolean encryptData)
          Connect to the FTP host and port.
protected  void doExplicitHandshake()
          This handles an explicit SSL connection by sending the AUTH command to the FTP server and converting the plaintext control socket into an SSL control socket.
 void forceDataEncryptionOn(boolean on)
          Forces the encryption of the data channel on or off.
 String getAuthType()
          Get the AUTH type we are sending during the AUTH command.
static ArrayList getCertificates(File keyStoreFile, String keyStorePass)
          This allows the list of SSLCertificate objects to be returned from the KeyStore.
 boolean isDataEncryptionOn()
          Whether or not data encryption is being done.
 void logout()
          Logout from the FTP server.
protected  Socket makeControlSocket(HostInfo hostInfo)
          Make a new control socket.
protected  ServerSocket makeDataServerSocket(HostInfo hostInfo)
          Make a new data server socket.
protected  Socket makeDataSocket(HostInfo hostInfo)
          Make a new data socket.
protected  FTPCommand makeFTPCommand(BufferedReader inputReader, PrintWriter outputWriter)
          Set the FTPCommand object.
static void preSeed()
          This allows the SecureRandom object to be generated prior to being used.
 void setAuthType(String authType)
          This allows the default AUTH type to be set from SSL to some other type (such as TLS).
 void setClearCommandChannel()
          Revert a secure connection back to a clear control connection.
 void setClientAuthentication(File privateKey, File[] certList)
          Specify a private key and public certificate chain to use for client authentication.
 void setClientAuthentication(File privateKey, File[] certList, String password)
          Specify a private key and public certificate chain to use for client authentication.
 void setClientAuthentication(PrivateKey privateKey, X509Certificate[] certList)
          Specify a private key and public certificate chain to use for client authentication.
protected  void setControlSocket(Socket controlSocket, boolean saveInsecureSocket)
          Set the control socket.
 void setDataEncryptionOn(boolean on)
          Set the encryption of the data channel on or off.
 
Methods inherited from class com.glub.secureftp.bean.FTP
abort, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, append, ascii, auto, binary, cdup, chdir, chdir, delete, delete, ebcdic, forcePasvToUseControlIP, getAccount, getConnectionType, getControlSocket, getDateStamp, getFTPCommand, getHostName, getListStyle, getPassword, getPort, getPortFromRange, getTransferMode, getUser, getVersion, help, isConnected, isLoggedIn, isTransferRestartable, list, list, list, list, list, list, listAll, listAll, login, login, mkdir, modeZ, noop, pasv, port, pwd, raw, rename, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, retrieve, rmdir, rmdir, sendAccount, sendPassword, sendUserName, setAccount, setActivePortRange, setConnectionType, setControlSocket, setHostName, setListStyle, setPassword, setPort, setRecvCmdStream, setSendCmdStream, setSocksIVProxy, setSocksVProxy, setStringDataAsUTF8, setUser, size, size, store, store, store, store, store, store, store, store, store, store, store, store, store, store, store, store, stringDataAsUTF8, time, time
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMPLICIT_CONNECTION

public static final short IMPLICIT_CONNECTION
Used to set the connection type to implicit.

See Also:
Constant Field Values

EXPLICIT_CONNECTION

public static final short EXPLICIT_CONNECTION
Used to set the connection type to explicit.

See Also:
Constant Field Values
Constructor Detail

SSLFTP

public SSLFTP(SSLSessionManager sslSessionManager,
              HostInfo hostInfo,
              short connectionType)
Create a new SSLFTP object without a key store nor response notification.

Parameters:
sslSessionManager - the Object that handles certificate information and decisions that are made based on these certificates.
hostInfo - the HostInfo to connect to.
connectionType - the type of connection to make (implicit or explicit).
See Also:
IMPLICIT_CONNECTION, EXPLICIT_CONNECTION

SSLFTP

public SSLFTP(SSLSessionManager sslSessionManager,
              String host,
              int port,
              short connectionType)
Create a new SSLFTP object without a key store nor response notification.

Parameters:
sslSessionManager - the Object that handles certificate information and decisions that are made based on these certificates.
host - the hostname to connect to.
port - the port to connect to.
connectionType - the type of connection to make (implicit or explicit).
See Also:
IMPLICIT_CONNECTION, EXPLICIT_CONNECTION

SSLFTP

public SSLFTP(SSLSessionManager sslSessionManager,
              HostInfo hostInfo,
              short connectionType,
              OutputStream sendCmdStream,
              OutputStream recvCmdStream)
Create a new SSLFTP object without a key store but with response notification.

Parameters:
sslSessionManager - the Object that handles certificate information and decisions that are made based on these certificates.
hostInfo - the HostInfo to connect to.
connectionType - the type of connection to make (implicit or explicit).
sendCmdStream - the commands sent to the server. Pass null if not interested in this data.
recvCmdStream - the responses returned from the server. Pass null if not interested in this data.
See Also:
IMPLICIT_CONNECTION, EXPLICIT_CONNECTION

SSLFTP

public SSLFTP(SSLSessionManager sslSessionManager,
              String host,
              int port,
              short connectionType,
              OutputStream sendCmdStream,
              OutputStream recvCmdStream)
Create a new SSLFTP object without a key store but with response notification.

Parameters:
sslSessionManager - the Object that handles certificate information and decisions that are made based on these certificates.
host - the hostname to connect to.
port - the port to connect to.
connectionType - the type of connection to make (implicit or explicit).
sendCmdStream - the commands sent to the server. Pass null if not interested in this data.
recvCmdStream - the responses returned from the server. Pass null if not interested in this data.
See Also:
IMPLICIT_CONNECTION, EXPLICIT_CONNECTION

SSLFTP

public SSLFTP(SSLSessionManager sslSessionManager,
              HostInfo hostInfo,
              File keyStoreFile,
              String keyStorePass,
              short connectionType)
Create a new SSLFTP object with a key store but without response notification.

Parameters:
sslSessionManager - the Object that handles certificate information and decisions that are made based on these certificates.
hostInfo - the HostInfo to connect to.
keyStoreFile - the file that acts as the key store.
keyStorePass - the key store's password.
connectionType - the type of connection to make (implicit or explicit).
See Also:
IMPLICIT_CONNECTION, EXPLICIT_CONNECTION

SSLFTP

public SSLFTP(SSLSessionManager sslSessionManager,
              String host,
              int port,
              File keyStoreFile,
              String keyStorePass,
              short connectionType)
Create a new SSLFTP object with a key store but without response notification.

Parameters:
sslSessionManager - the Object that handles certificate information and decisions that are made based on these certificates.
host - the hostname to connect to.
port - the port to connect to.
keyStoreFile - the file that acts as the key store.
keyStorePass - the key store's password.
connectionType - the type of connection to make (implicit or explicit).
See Also:
IMPLICIT_CONNECTION, EXPLICIT_CONNECTION

SSLFTP

public SSLFTP(SSLSessionManager sslSessionManager,
              HostInfo hostInfo,
              File keyStoreFile,
              String keyStorePass,
              short connectionType,
              OutputStream sendCmdStream,
              OutputStream recvCmdStream)
Create a new SSLFTP object with a key store and response notification.

Parameters:
sslSessionManager - the Object that handles certificate information and decisions that are made based on these certificates.
hostInfo - the HostInfo to connect to.
keyStoreFile - the file that acts as the key store.
keyStorePass - the key store's password.
connectionType - the type of connection to make (implicit or explicit).
sendCmdStream - the commands sent to the server. Pass null if not interested in this data.
recvCmdStream - the responses returned from the server. Pass null if not interested in this data.
See Also:
IMPLICIT_CONNECTION, EXPLICIT_CONNECTION

SSLFTP

public SSLFTP(SSLSessionManager sslSessionManager,
              String host,
              int port,
              File keyStoreFile,
              String keyStorePass,
              short connectionType,
              OutputStream sendCmdStream,
              OutputStream recvCmdStream)
Create a new SSLFTP object with a key store and response notification.

Parameters:
sslSessionManager - the Object that handles certificate information and decisions that are made based on these certificates.
host - the hostname to connect to.
port - the port to connect to.
keyStoreFile - the file that acts as the key store.
keyStorePass - the key store's password.
connectionType - the type of connection to make (implicit or explicit).
sendCmdStream - the commands sent to the server. Pass null if not interested in this data.
recvCmdStream - the responses returned from the server. Pass null if not interested in this data.
See Also:
IMPLICIT_CONNECTION, EXPLICIT_CONNECTION

SSLFTP

public SSLFTP(SSLSessionManager sslSessionManager,
              HostInfo hostInfo,
              File keyStoreFile,
              String keyStorePass,
              SecureRandom random,
              short connectionType,
              OutputStream sendCmdStream,
              OutputStream recvCmdStream)
Create a new SSLFTP object with a key store, response notification, and an overridden SecureRandom object.

Parameters:
sslSessionManager - the Object that handles certificate information and decisions that are made based on these certificates.
hostInfo - the HostInfo to connect to.
keyStoreFile - the file that acts as the key store.
keyStorePass - the key store's password.
random - you can override our randomizer with your own.
connectionType - the type of connection to make (implicit or explicit).
sendCmdStream - the commands sent to the server. Pass null if not interested in this data.
recvCmdStream - the responses returned from the server. Pass null if not interested in this data.
See Also:
IMPLICIT_CONNECTION, EXPLICIT_CONNECTION

SSLFTP

public SSLFTP(SSLSessionManager sslSessionManager,
              String host,
              int port,
              File keyStoreFile,
              String keyStorePass,
              SecureRandom random,
              short connectionType,
              OutputStream sendCmdStream,
              OutputStream recvCmdStream)
Create a new SSLFTP object with a key store, response notification, and an overridden SecureRandom object.

Parameters:
sslSessionManager - the Object that handles certificate information and decisions that are made based on these certificates.
host - the hostname to connect to.
port - the port to connect to.
keyStoreFile - the file that acts as the key store.
keyStorePass - the key store's password.
random - you can override our randomizer with your own.
connectionType - the type of connection to make (implicit or explicit).
sendCmdStream - the commands sent to the server. Pass null if not interested in this data.
recvCmdStream - the responses returned from the server. Pass null if not interested in this data.
See Also:
IMPLICIT_CONNECTION, EXPLICIT_CONNECTION
Method Detail

setClientAuthentication

public void setClientAuthentication(File privateKey,
                                    File[] certList)
                             throws FileNotFoundException,
                                    IOException,
                                    InvalidKeySpecException,
                                    CertificateException,
                                    KeyStoreException
Specify a private key and public certificate chain to use for client authentication.

Parameters:
privateKey - The private key for the client
certList - The public certificates for the client
Throws:
FileNotFoundException
IOException
InvalidKeySpecException
CertificateException
KeyStoreException

setClientAuthentication

public void setClientAuthentication(File privateKey,
                                    File[] certList,
                                    String password)
                             throws FileNotFoundException,
                                    IOException,
                                    InvalidKeySpecException,
                                    CertificateException,
                                    KeyStoreException
Specify a private key and public certificate chain to use for client authentication.

Parameters:
privateKey - The private key for the client
certList - The public certificates for the client
password - The password to access the key/certifificate
Throws:
FileNotFoundException
IOException
InvalidKeySpecException
CertificateException
KeyStoreException

setClientAuthentication

public void setClientAuthentication(PrivateKey privateKey,
                                    X509Certificate[] certList)
                             throws KeyStoreException
Specify a private key and public certificate chain to use for client authentication.

Parameters:
privateKey - The private key for the client
certList - The public certificates for the client
Throws:
KeyStoreException

clearClientAuthentication

public void clearClientAuthentication()
                               throws KeyStoreException
Clear the client key from the keystore (if it exists)

Throws:
KeyStoreException

connect

public void connect()
             throws FTPConnectException,
                    FTPException,
                    IOException,
                    UnknownHostException,
                    IllegalArgumentException
Connect to the FTP host and port with data encyption off by default. If the port was not set, we default to 21. If you are doing an explicit SSL connection, the AUTH command is sent here. By default we attempt an implicit connection.

Overrides:
connect in class FTP
Throws:
FTPConnectException - if the connection fails.
FTPException - if the FTP server returns an error code.
IOException - if there are socket problems.
UnknownHostException - if the host could not be found.
IllegalArgumentException - if hostName is null.
See Also:
doExplicitHandshake(), SSLFTPCommand.auth(String)

connect

public void connect(boolean encryptData)
             throws FTPConnectException,
                    FTPException,
                    IOException,
                    UnknownHostException,
                    IllegalArgumentException
Connect to the FTP host and port. If the port was not set, we default to 21. If you are doing an explicit SSL connection, the AUTH command is sent here. By default we attempt an implicit connection.

Parameters:
encryptData - the default encryption state of the data channel
Throws:
FTPConnectException - if the connection fails.
FTPException - if the FTP server returns an error code.
IOException - if there are socket problems.
UnknownHostException - if the host could not be found.
IllegalArgumentException - if hostName is null.
See Also:
doExplicitHandshake(), SSLFTPCommand.auth(String)

doExplicitHandshake

protected void doExplicitHandshake()
                            throws FTPAuthNotSupportedException,
                                   FTPException,
                                   IOException,
                                   IllegalArgumentException
This handles an explicit SSL connection by sending the AUTH command to the FTP server and converting the plaintext control socket into an SSL control socket.

Throws:
FTPAuthNotSupportedException - if the auth command is not supported.
FTPException - if the FTP server returns an error code.
IOException - if there are socket problems.
IllegalArgumentException - if the auth type is null.

setClearCommandChannel

public void setClearCommandChannel()
                            throws FTPException,
                                   IOException
Revert a secure connection back to a clear control connection.

Throws:
FTPException - if the FTP server returns an error code.
IOException

aboutToTransferData

protected void aboutToTransferData()
Called before data transfers begin.

Overrides:
aboutToTransferData in class FTP

setControlSocket

protected void setControlSocket(Socket controlSocket,
                                boolean saveInsecureSocket)
                         throws IOException
Set the control socket.

Parameters:
controlSocket - the control socket.
saveInsecureSocket - allow the old socket to be saved so CCC can be used.
Throws:
IOException

makeControlSocket

protected Socket makeControlSocket(HostInfo hostInfo)
                            throws IOException
Make a new control socket.

Overrides:
makeControlSocket in class FTP
Parameters:
hostInfo - a HostInfo object that describes where to make the socket.
Returns:
a new instance of a socket.
Throws:
IOException - if there is a socket problem.

makeDataSocket

protected Socket makeDataSocket(HostInfo hostInfo)
                         throws IOException
Make a new data socket.

Overrides:
makeDataSocket in class FTP
Parameters:
hostInfo - a HostInfo object that describes where to make the socket.
Returns:
a new instance of a socket.
Throws:
IOException - if there is a socket problem.

makeDataServerSocket

protected ServerSocket makeDataServerSocket(HostInfo hostInfo)
                                     throws IOException
Make a new data server socket.

Overrides:
makeDataServerSocket in class FTP
Parameters:
hostInfo - a HostInfo object that describes where to make the socket.
Returns:
a new instance of a server socket.
Throws:
IOException - if there is a socket problem.

makeFTPCommand

protected FTPCommand makeFTPCommand(BufferedReader inputReader,
                                    PrintWriter outputWriter)
Set the FTPCommand object.

Overrides:
makeFTPCommand in class FTP
Parameters:
inputReader - the BufferedReader comes from the input stream of the control socket.
outputWriter - the PrintWriter comes from the output stream of the control socket.
Returns:
a new instance of an FTPCommand object.

logout

public void logout()
            throws IOException,
                   FTPException
Logout from the FTP server.

Overrides:
logout in class FTP
Throws:
IOException - if there is a socket problem.
FTPException - if the FTP server returns an error code.

isDataEncryptionOn

public boolean isDataEncryptionOn()
Whether or not data encryption is being done.

Returns:
true if data encryption is on.

forceDataEncryptionOn

public void forceDataEncryptionOn(boolean on)
                           throws FTPException
Forces the encryption of the data channel on or off. Note: this method is NOT recommended as it doesn't check the status of the server and just makes assumptions that the data connection is on/off.

Parameters:
on - true if data encrytion is to be on, false if off.
Throws:
FTPException - if the FTP server returns an error code.

setDataEncryptionOn

public void setDataEncryptionOn(boolean on)
                         throws FTPException
Set the encryption of the data channel on or off.

Parameters:
on - true if data encrytion is to be on, false if off.
Throws:
FTPException - if the FTP server returns an error code.

getAuthType

public String getAuthType()
Get the AUTH type we are sending during the AUTH command.

Returns:
the AUTH type (e.g. SSL).
See Also:
SSLFTPCommand.auth(String)

setAuthType

public void setAuthType(String authType)
This allows the default AUTH type to be set from SSL to some other type (such as TLS).

Parameters:
authType - the AUTH type to send during the AUTH command.
See Also:
SSLFTPCommand.auth(String)

preSeed

public static void preSeed()
This allows the SecureRandom object to be generated prior to being used. This object takes a significant amount of time to be generated and it is advised that this call be done on program initialization. It is threaded for performance.

See Also:
SecureRandom

getCertificates

public static ArrayList getCertificates(File keyStoreFile,
                                        String keyStorePass)
This allows the list of SSLCertificate objects to be returned from the KeyStore.

Returns:
an ArrayList of SSLCertificate objects
See Also:
SSLCertificate


Copyright © 2000-08 Glub Tech, Inc. All Rights Reserved.