سؤال

I am trying to program a simple FTPS server based on EventMachine.

Control socket works properly. When using data socket for data transfer, it seems that everything works well (TLS handshake completes successfully and data is received), but then I get an error message. Here is what I get in 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 also issues an error although somewhat different

--> 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

From what I found on the web I suspect this behavior is because close_notify is not issued at the end of connection? If so, is there any known Ruby based solution for that (f.ex. using OpenSSL::SSL::SSLSocket)?

هل كانت مفيدة؟

المحلول

Answer is quite short: no, EventMachine doesn't issue close_notify on close_connection if tls_start was run.

نصائح أخرى

I found SSL 're-opens' a connection after reading the cert, so work around here is:

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top