From: "Iñaki Baz Castillo" Date: 2011-12-07T06:32:03+09:00 Subject: Re: Using OpenSSL for making a network TLS server Any suggestion about this please? Maybe the only response is that "there is no way" (hope not) :) Thanks a lot. 2011/12/5 Iñaki Baz Castillo : > Hi, unfortunatelly the above solution is not valid for me. What I want > to do is using OpenSSL on top of a EventMachine TCP connection. > > EventMachine manages all the sockets and connections internally (at > C++ level), and creates an instance of EM::Connection Ruby class for > each TCP connection (a server connection). Such EM::Connection class > provides some callbacks: > > ------------------ > class MyTcpServer < EM::Connection >  def receive_data data >    puts "data reveiced on this connection: #{data}" >  end > end > ------------------ > > And includes a method "send_data(data)" to send data over the connection. > > > So I don't have a Ruby Socket instance. Instead I receive the raw TCP > data in that connection. In my case, such TCP data initially contains > the client's SSL handshake, so I need a way to pass such handshake to > a Ruby OpenSSL::XXX instance. I also need a way to encrypt data based > on the SSL handshake and write it into a raw string, so I can call > EM::Connection#send_data(data) over the TLS connection. > > Unfortunatelly it seems that Ruby OpenSSL does not provide a mechanism > for that, and it requires passing a real Ruby Socket as argument for > OpenSSL::SSL::SSLSocket and OpenSSL::SSL::SSLServer. Any suggestion > please? > > A workaround I'm thinking about is using an intermediary like-socket, > so when I receive TCP data over the EM::Connection#receive_data(data) > method, I send such raw data to the intermediary socket, and > previously I passed such intermediary socket during the initialitation > of the OpenSSL::SSL::SSLSocket instance (so the SSL handshake and > decryption is done by OpenSSL as usual). But I don't know how to > implement this "concept", and I would prefer not to deal with an > "intermediary socket". > > Thanks a lot for any suggestion. -- Iñaki Baz Castillo