1

使用 Apache FTPSClient 列出文件(字符串)....

在恢复 SSL 会话然后从 Apache FTPSClient 代码调用 sslSocketImpl.startHandshake() 后,应用程序有时会崩溃。

我设置 javax.net.debug 打印 ssl 信息... System.setProperty("javax.net.debug", "all");

这就是我得到的。

%% Client cached [Session-3, SSL_RSA_WITH_3DES_EDE_CBC_SHA]
%% Try resuming [Session-3, SSL_RSA_WITH_3DES_EDE_CBC_SHA] from port 4149
*** ClientHello, TLSv1
....
main, received EOFException: error
main, handling exception: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
main, SEND TLSv1 ALERT:  fatal, description = handshake_failure
main, WRITE: TLSv1 Alert, length = 2
[Raw write]: length = 7
0000: 15 03 01 00 02 02 28                               ......(
main, called closeSocket()
[Mon Aug 30 17:41:52 PDT 2010][class com.smgtec.sff.fileupload.poller.BasicFTPAccess] - Could not list directory: sqjavax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
 at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:808)
 at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1096)
 at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123)
 at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1107)
 at com.smgtec.sff.fileupload.poller.FixedFTPSClient._openDataConnection_(FixedFTPSClient.java:525)
 at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2296)
 at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2269)

Padded plaintext before ENCRYPTION:  len = 32
0000: 50 41  at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2046)
 at com.smgtec.sff.fileupload.poller.BasicFTPAccess.listFiles(BasicFTPAccess.java:100)
 at com.smgtec.sff.fileupload.poller.FTPPoller.addFileForProcessing(FTPPoller.java:67)
 at com.smgtec.sff.fileupload.poller.FTPPoller.main(FTPPoller.java:385)
Caused by: java.io.EOFException: SSL peer shut down incorrectly
 at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:333)
 at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:789)
 ... 10 more

我们这里也有 jscape FTPS 客户端,它产生了同样的问题。

4

2 回答 2

0

我建议您在您的中包含一些重试逻辑FTPPoller- 看起来主机正在关闭连接而不是您的代码。我们曾经看到偶尔会因远程主机错误而关闭连接,最好通过简单的重试来处理。

于 2010-08-31T08:47:13.860 回答
0

我使用 SSLSession.invalidate() 像这样解决了它,它现在似乎可以工作了……尽管我们不再使用 FTPS。如果这是一个真正的解决方案,那么 Apache commons-net FTPSClient 或我们正在连接的 FTP 服务器存在问题。

ftp = new FTPSClient() 
      {
        private Socket socket;

        protected Socket _openDataConnection_(int command, String arg) throws IOException
        {
          if (socket != null && socket instanceof SSLSocket)
          {
            // We have problems resuming cached SSL Sessions. Exceptions are
            // thrown and the system crashes... So we invalidate each SSL
            // session we used last.
            SSLSocket sslSocket = (SSLSocket) socket;
            sslSocket.getSession().invalidate();
          }
          socket = super._openDataConnection_(command, arg);
          return socket;
        }
      };

顺便说一句,我相信我们正在连接到 FileZilla FTP 服务器。我怀疑这个修复会导致更多的网络喋喋不休地来回传递密钥/证书等等。

于 2010-09-03T23:30:33.760 回答