我正在尝试基于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的解决方案(f.ex.使用OpenSSL :: SSL :: SSLSocket)?
答案 0 :(得分:0)
答案非常简短:不,如果运行tls_start,EventMachine不会在close_connection上发出close_notify。
答案 1 :(得分: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