15

我正在尝试基于 EventMachine 编写一个简单的 FTPS 服务器。

控制插座正常工作。使用数据套接字进行数据传输时,似乎一切正常(TLS 握手成功完成并接收到数据),但随后我收到一条错误消息。这是我在 Filezilla 中得到的:

Command:    LIST
Response:   150 Opening ASCII mode data connection for file list
Trace:  CFtpControlSocket::TransferParseResponse()
Trace:    code = 1
Trace:    state = 4
Trace:  CFtpControlSocket::SendNextCommand()
Trace:  CFtpControlSocket::TransferSend()
Trace:    state = 5
Trace:  CTransferSocket::OnConnect
Trace:  CTlsSocket::Handshake()
Trace:  gnutls_session_get_data on primary socket failed: -51
Trace:  CTlsSocket::ContinueHandshake()
Trace:  CTlsSocket::OnSend()
Trace:  CTlsSocket::OnSend()
Trace:  CTlsSocket::OnRead()
Trace:  CTlsSocket::ContinueHandshake()
Trace:  CTlsSocket::OnRead()
Trace:  CTlsSocket::ContinueHandshake()
Trace:  Handshake successful
Trace:  Cipher: AES-256-CBC, MAC: SHA1
Trace:  CTlsSocket::OnRead()
Trace:  CTransferSocket::OnConnect
Trace:  CTransferSocket::OnReceive(), m_transferMode=0
Listing:    -rwxrwxrwx 1 owner  group         1011 Dec 12 23:05 a.tmp
Trace:  CTlsSocket::Failure(-9, 0)
Error:  GnuTLS error -9: A TLS packet with unexpected length was received.
Status: Server did not properly shut down TLS connection
Error:  Could not read from transfer socket: ECONNABORTED - Connection aborted
Trace:  CTransferSocket::TransferEnd(3)
Trace:  CFtpControlSocket::OnReceive()
Response:   226 Closing data connection, sent 70 bytes
Trace:  CFtpControlSocket::TransferParseResponse()
Trace:    code = 2
Trace:    state = 5
Trace:  CFtpControlSocket::SendNextCommand()
Trace:  CFtpControlSocket::TransferSend()
Trace:    state = 8
Trace:  CFtpControlSocket::TransferEnd()
Trace:  CFtpControlSocket::ResetOperation(2)
Trace:  CControlSocket::ResetOperation(2)
Trace:  CFtpControlSocket::ParseSubcommandResult(2)
Trace:  CFtpControlSocket::ListSubcommandResult()
Trace:    state = 3
Trace:  CFtpControlSocket::ResetOperation(2)
Trace:  CControlSocket::ResetOperation(2)
Error:  Failed to retrieve directory listing
Trace:  CFileZillaEnginePrivate::ResetOperation(2)

ftp-ssl 也会发出错误,尽管有些不同

--> LIST
150 Opening ASCII mode data connection for file list
===>START SSL connect on DATA
ftp: SSL_connect DATA error 0 - error:00000000:lib(0):func(0):reason(0)
226 Closing data connection, sent 70 bytes
421 Service not available, remote server has closed connection

从我在网上发现的情况来看,我怀疑这种行为是因为 close_notify 在连接结束时没有发出?如果是这样,是否有任何已知的基于 Ruby 的解决方案(例如使用 OpenSSL::SSL::SSLSocket)?

4

2 回答 2

0

答案很简短:不,如果运行 tls_start,EventMachine 不会在 close_connection 上发出 close_notify。

于 2013-08-27T20:28:57.513 回答
0

我在阅读证书后发现 SSL '重新打开'一个连接,所以这里的解决方法是:

def receive_data bitOfData
if (self.class isSomeSortOfTLSreadingClass && bitOfData.length == 1) then
 @headBuff << bitOfData
 return
 end
 # TLS connection closes on first byte, then re-opens.
end
于 2013-12-12T01:47:57.117 回答