TLS server using AnyEvent::Handle

R bob rb_newsletter at yahoo.com
Thu Jan 13 22:42:42 CET 2011


Hello,

Greetings of the day!

I am facing trouble in getting up a TLS server using AnyEvent::Handle module.

Is there any sample working code? I searched on google with all kind of related 
key words with no luck. Any help is appreciated and thanks in advance.

I am using the below code and getting error "AnyEvent::Handle uncaught error: 
ssl3_get_client_hello: no shared cipher at 
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/AnyEvent/Impl/Perl.pm 
line 238". 

Here what I want to achieve is, I want to test a box which send some request 
over SSL and expects some response. So I want to write a server script which 
listens on TLS handshake and respond for the request received. I am not worried 
about security as long the server can understand "TLS_RSA_WITH_AES_128_CBC_SHA 
AES128-SHA" ciphers from the client.

If I take the tls stuffs out from the below code, then this code listens to the 
defined port ( $ListenPor) and just works fine.

==========================================
#!/usr/bin/perl

use AnyEvent;
use AnyEvent::Handle;
use AnyEvent::Socket;
use AnyEvent::TLS;
use Net::SSLeay qw(die_now die_if_ssl_error) ;

my $ListenPort = 8900;
my $cert_path = "/root/ssld/server.crt";
my $key_path = "/root/ssld/server.key";


 

my $data_ready = AnyEvent->condvar;

my $gaurd = tcp_server undef, 8900, sub {my ($fh, $host, $port) = @_
                                                or die "unable to connect: $!";
                                                
                                                 $wait_for_input;
                                                 $wait_for_input = new 
AnyEvent::Handle (
                                                                                 
     fh => $fh,
                                                                                 
    tls => "accept",
                                                                         
cert_file => $cert_path,
                                                                         
 key_file => $key_path,
                                                                                 
     debug => "5",
                                                                       
 tls_cipher_list => "ALL",

                                                                                 
     tls_ctx => { },
                                                                 on_read => sub 
{
                                                                           
 #print response body
                                                                               
print $_[0]->rbuf;
                                                                          $body 
.= $_[0]->rbuf;
                                                                               
 $_[0]->rbuf = "";
                                                                                 
 },
                                                                  on_eof => sub 
{
                                                                           
($recvData) = @_;
                                                                  $name = 
$recvData->rbuf;
                                                                 
 $data_ready->send ;
                                                                                 
                   },

                                                                                 
            );

                                        };

print "TLS server ... \n";

$data_ready->recv;

print "body = $body \n";
===================================

Regards,
Rob


      



More information about the anyevent mailing list