non-blocking SSL update
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > Perlbal > non-blocking SSL update




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    non-blocking SSL update  
Greg Thornton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-26-07 12:11 AM

Ok so where might one find Danga::Socket::SSL right now? Maybe I just  
can't operate CPAN correctly, but it doesn't seem to be in there. I'd  
LOVE to give this a shot. Granted I haven't touched PERL in a while,  
but it sounds like the hard part is done. Coincidentally I'd try to  
tackle the OPTIONAL ssl dependency route described by Brad. Thanks  
dudes.

Greg Thornton

Senior Developer | Emma®
greg@myemma.com
800.595.4401 or 615.292.5888 x112
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com

P please consider the environment before printing this e-mail








[ Post a follow-up to this message ]



    Re: non-blocking SSL update  
Robin H. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-26-07 12:11 AM

On Tue, Sep 25, 2007 at 03:53:21PM -0500, Greg Thornton wrote:
> Ok so where might one find Danga::Socket::SSL right now? Maybe I just can'
t 
> operate CPAN correctly, but it doesn't seem to be in there. I'd LOVE to 
> give this a shot. Granted I haven't touched PERL in a while, but it sounds
 
> like the hard part is done. Coincidentally I'd try to tackle the OPTIONAL 
> ssl dependency route described by Brad. Thanks dudes.
http://code.sixapart.com/svn/Danga-Socket-SSL/
I don't know if there is any more recent version. bradfitz might be able
to say more canonically.

[url]http://code.sixapart.com/trac/Danga-Socket-SSL/log/trunk/lib/Danga/Socket/SSL.pm[/
url]

-- 
Robin Hugh Johnson
Gentoo Linux Developer & Infra Guy
E-Mail     : robbat2@gentoo.org
GnuPG FP   : 11AC BA4F 4778 E3F6 E4ED  F38E B27B 944E 3488 4E85






[ Post a follow-up to this message ]



    Re: non-blocking SSL update  
Ask Bjørn Hansen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-26-07 12:11 AM


On Sep 25, 2007, at 13:53, Greg Thornton wrote:

> Ok so where might one find Danga::Socket::SSL right now? Maybe I
> just can't operate CPAN correctly, but it doesn't seem to be in
> there. I'd LOVE to give this a shot. Granted I haven't touched perl
> in a while, but it sounds like the hard part is done.
> Coincidentally I'd try to tackle the OPTIONAL ssl dependency route
> described by Brad. Thanks dudes.

I don't think Danga::Socket::SSL exists, yet.  The code is in
DJabberd::Stanza::StartTLS and DJabberd::Connection::OldSSLClientIn
and needs to be generalized into Danga::Socket::SSL (or whatever).


- ask

--
http://develooper.com/ - http://askask.com/








[ Post a follow-up to this message ]



    Re: non-blocking SSL update  
Ask Bjørn Hansen


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-26-07 12:11 AM


On Sep 25, 2007, at 14:51, Robin H. Johnson wrote:

> http://code.sixapart.com/svn/Danga-Socket-SSL/
> I don't know if there is any more recent version. bradfitz might be
> able
> to say more canonically.

Ah, very cool!


- ask

--
http://develooper.com/ - http://askask.com/








[ Post a follow-up to this message ]



    Re: non-blocking SSL update  
Brad Fitzpatrick


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-26-07 06:12 AM

On Tue, 25 Sep 2007, Robin H. Johnson wrote:

> On Tue, Sep 25, 2007 at 03:53:21PM -0500, Greg Thornton wrote: 
> http://code.sixapart.com/svn/Danga-Socket-SSL/
> I don't know if there is any more recent version. bradfitz might be able
> to say more canonically.

That's it, but I can't recall if I ever fully got it working... it seems I
would've released it if I had.  Use with caution.

- Brad







[ Post a follow-up to this message ]



    Re: non-blocking SSL update  
Greg Thornton


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
09-27-07 06:11 AM

OK this is actually very easy. The IO::Socket::SSL docs mention how  
to do non-blocking correctly, but it looks like the package was taken  
over and specifically improved in this arena around the time of this  
original discussion. So who knows, maybe it wasn't clear how to do  
this before now. Anyway, this simple patch fixes the issue and  
doesn't change the requirements or need danga::socket updates. The  
trick is to promote a normal IO::Socket::INET socket to an ssl socket  
with IO::Socket::SSL->start_SSL() after the accept(). I'm making the  
call in an eval, because if the start_SSL() call fails to establish  
an ssl socket, the socket silently remains a plain old non-ssl socket  
and would be handled the same as if you were missing the SSL module I  
believe. Thoughts? Haven't gotten a chance to test it extensively,  
but it looks to me like identical functionality. Here's the patch.  
Let me apologize in advance in case my mail client screws this up.

Index: TCPListener.pm
 ========================================
===========================
--- TCPListener.pm      (revision 699)
+++ TCPListener.pm      (working copy)
@@ -11,7 +11,7 @@
no  warnings qw(deprecated);
use base "Perlbal::Socket";
-use fields qw(service hostport);
+use fields qw(service hostport sslopts);
use Socket qw(IPPROTO_TCP SOL_SOCKET SO_SNDBUF);
# TCPListener
@@ -19,16 +19,12 @@
my ($class, $hostport, $service, $opts) = @_;
$opts ||= {};
-    my $sockclass = $opts->{ssl} ? "IO::Socket::SSL" :  
"IO::Socket::INET";
-    my $sock = eval {
-        $sockclass->new(
-                        LocalAddr => $hostport,
-                        Proto => IPPROTO_TCP,
-                        Listen => 1024,
-                        ReuseAddr => 1,
-                        ($opts->{ssl} ? %{$opts->{ssl}} : ()
),
-                        );
-    };
+    my $sock = IO::Socket::INET->new(
+                                     LocalAddr => $hostport,
+                                     Proto => IPPROTO_TCP,
+                                     Listen => 1024,
+                                     ReuseAddr => 1,
+                                     );
return Perlbal::error("Error creating listening socket: " . ($@  
|| $!))
unless $sock;
@@ -48,6 +44,7 @@
my $self = $class->SUPER::new($sock);
$self->{service} = $service;
$self->{hostport} = $hostport;
+    $self->{sslopts} = $opts->{ssl};
bless $self, ref $class || $class;
$self->watch_read(1);
return $self;
@@ -60,10 +57,10 @@
# accept as many connections as we can
while (my ($psock, $peeraddr) = $self->{sock}->accept) {
my $service_role = $self->{service}->role;
+        my ($pport, $pipr) = Socket::sockaddr_in($peeraddr);
+        my $pip = Socket::inet_ntoa($pipr);
if (Perlbal::DEBUG >= 1) {
-            my ($pport, $pipr) = Socket::sockaddr_in($peeraddr);
-            my $pip = Socket::inet_ntoa($pipr);
print "Got new conn: $psock ($pip:$pport) for  
$service_role\n";
}
@@ -73,6 +70,19 @@
my $rv = setsockopt($psock, SOL_SOCKET, SO_SNDBUF, pack 
("L", $sndbuf));
}
+        if ($self->{sslopts}) {
+            if (Perlbal::DEBUG >= 1) {
+                print "Promoting to SSL socket: $psock ($pip:$pport)  
for $service_role\n";
+            }
+            eval {
+                IO::Socket::SSL->start_SSL(
+                                           $psock,
+                                           SSL_server => 1,
+                                           %{$self->{sslopts}}
+                                           );
+            };
+        }
+
if ($service_role eq "reverse_proxy") {
Perlbal::ClientProxy->new($self->{service}, $psock);
} elsif ($service_role eq "management") {


On Sep 25, 2007, at 10:40 PM, Brad Fitzpatrick wrote:

> On Tue, 25 Sep 2007, Robin H. Johnson wrote:
> 
>
> That's it, but I can't recall if I ever fully got it working... it  
> seems I
> would've released it if I had.  Use with caution.
>
> - Brad
>

Greg Thornton

Senior Developer | Emma®
greg@myemma.com
800.595.4401 or 615.292.5888 x112
615.292.0777 (fax)

Emma helps organizations everywhere communicate & market in style.
Visit us online at http://www.myemma.com

P please consider the environment before printing this e-mail








[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:41 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register