startHandshake() hangs on FTPS Client implementation

Hi,

I'm working on developing a small FTPS client test program that connects to an FTP server using explicit SSL. I first connect with a standard socket, then send the message"AUTH TLS"

I get back"234 AUTH TLS-C/TLS OK."

meaning the server is ready to switch to a secure connection. Immediately after, I call the startHandshake() method and that's where the process gets stuck (or if I set the timeout interval to a minute it'll eventually time out.) I can connect fine with SecureFTP (based on Java) to the FTP Server using the same host, port, and with explicit SSL. Any ideas on what could cause this?

Here's a relevant portion of the code based off of the Apache FTPClient source:

From my test file:

FtpsClient peoplesFTP =new FtpsClient();

peoplesFTP.connect(HOST, PORT);

Which calls this inside FtpsClient.java

publicvoid connect(String address,int port)throws SocketException, IOException

{

super.connect(address, port);

System.out.println(this.getReplyString());

this.secure();

}

And the secure method inside Ftpsclient.java

publicvoid secure()throws IOException

{

this.sendCommand("AUTH","TLS");

System.out.println(this.getReplyString());

SSLSocket socket = (SSLSocket) this.context.getSocketFactory().createSocket(this._socket_, this.getRemoteAddress().getHostAddress(), this.getRemotePort(),true);

socket.setSoTimeout(10000);

try{

socket.startHandshake();

}catch (SocketTimeoutException e){

System.out.println("Socket timed out");

}

this._socket_ = socket;

this._controlInput =new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()));

this._controlOutput =new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), getControlEncoding()));

this.setSocketFactory(new FtpsSocketFactory(this.context));

this.sendCommand("PBSZ","0");

this.sendCommand("PROT","P");

}

[3001 byte] By [Strecka] at [2007-10-3 8:26:30]
# 1

Additionally, with -Djavax.net.debug=all, I can see all the certificates getting added to the trust store...but there's no sort of handshake debug displayed

Where usually you would get something like...

%% No cached client session

*** ClientHello, TLSv1

RandomCookie: GMT: 1134825562 bytes = { 144, 209, 196, 45, 65, 26, 3, 223, 78, 234, 60, 127, 116, 101, 198, 95, 194, 227, 66, 75, 94, 141, 98, 110, 249, 205, 120, 46 }

Strecka at 2007-7-15 3:32:54 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 2
Did you find any solution on this, as I am facing the same problem.Thanks.-S
sagarshirguppia at 2007-7-15 3:32:54 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 3
If nothing happens during the handshake at all I would suspect that both the server and the client are in TLS 'server' mode where they are both waiting for a TLS ClientHello. Make sure the client is in client mode.
ejpa at 2007-7-15 3:32:54 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...
# 4

I used to have similar problem when implementing HTTPS server.

Tried to initiate rehandshake after receiving HTTP request to ask for a client certificate only when really needed.

Problem was caused by the fact that SSL implementation does not have its own thread to do the handshake work on. I needed to have my thread inside SSLSocket's read() for the handshake to acutally happen, even though I had nothing to receive (request was already received). But reading 0 bytes did help ;)

hlavaca at 2007-7-15 3:32:54 > top of Java-index,Security,Java Secure Socket Extension (JSSE)...