[Bps-public-commit] Net-Server-Coro branch, master, updated. 0.5-4-g3e27f29

Alex M Vandiver alexmv at bestpractical.com
Fri Oct 16 10:56:43 EDT 2009


The branch, master has been updated
       via  3e27f291687c99cbab971e91ed54ed5c8ee3f940 (commit)
       via  c61f2fab8350a0ae1afeab5704fca50cfe118293 (commit)
       via  6c99dbc261ff69193529f66f079b1ab144586f33 (commit)
      from  f9da376fb90a6cc527acc5e7aab828f1e306c434 (commit)

Summary of changes:
 Changes                      |    5 +++
 MANIFEST                     |    2 +
 META.yml                     |    2 +-
 SIGNATURE                    |   18 ++++++----
 certs/server-cert.pem        |   62 +++++++++++++++++++++++++++++++++++
 certs/server-key.pem         |   15 ++++++++
 lib/Net/Server/Coro.pm       |   73 ++++++++++++++++++++++++++++++++++++++++-
 lib/Net/Server/Proto/Coro.pm |   24 +++++++++----
 8 files changed, 182 insertions(+), 19 deletions(-)
 create mode 100644 certs/server-cert.pem
 create mode 100644 certs/server-key.pem

- Log -----------------------------------------------------------------
commit 6c99dbc261ff69193529f66f079b1ab144586f33
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Oct 16 10:35:27 2009 -0400

    Save certificate and key paths on the server object
    
    By saving certificate and key paths as part of the server and handle
    objects, both SSL and TLS can be used with specific certificate and
    key paths.  Based on a patch by Dan Keder.

diff --git a/lib/Net/Server/Coro.pm b/lib/Net/Server/Coro.pm
index c30cc83..922a334 100644
--- a/lib/Net/Server/Coro.pm
+++ b/lib/Net/Server/Coro.pm
@@ -42,11 +42,43 @@ usage details.
 
 =cut
 
+=head2 new
+
+Create new Net::Server::Coro object. It accepts these parameters (in
+addition to L<Net::Server> parameters):
+
+=item server_cert
+
+Path to the SSL certificate that the server should use. This can be
+either relative or absolute path.  Defaults to
+F<certs/server-cert.pem>
+
+=item server_key
+
+Path to the SSL certificate key that the server should use. This can
+be either relative or absolute path.  Defaults to
+F<certs/server-key.pem>
+
+=cut
+
+sub new {
+    my $class = shift;
+    my %args = @_;
+    my $self = $class->SUPER::new(@_);
+
+    # Set up certificates
+    $self->server_cert($args{'server_cert'}) if exists $args{'server_cert'};
+    $self->server_key($args{'server_key'})   if exists $args{'server_key'};
+
+    return $self;
+}
+
 sub post_bind_hook {
     my $self = shift;
     my $prop = $self->{server};
     delete $prop->{select};
-    $prop->{sock} = [ map { make_coro_socket($_) } @{ $prop->{sock} } ];
+
+    $prop->{sock} = [ map { $self->make_coro_socket($_) } @{ $prop->{sock} } ];
 }
 
 =head2 make_coro_socket SOCKET
@@ -57,15 +89,20 @@ it into a L<Net::Server::Proto::Coro> object.
 =cut
 
 sub make_coro_socket {
+    my $self = shift;
     my $socket = shift;
+
     my @extra;
     if ( $socket->isa("IO::Socket::SSL") ) {
         $socket = bless $socket, "Net::Server::Proto::TCP";
         @extra = ( expects_ssl => 1 );
     }
+
     $socket = Net::Server::Proto::Coro->new_from_fh(
         $socket,
         forward_class => ref($socket),
+        server_cert => $self->server_cert,
+        server_key => $self->server_key,
         @extra
     );
     return $socket;
@@ -144,6 +181,38 @@ sub loop {
     schedule;
 }
 
+=head2 server_cert [PATH]
+
+Gets or sets the path fo the SSL certificate used by the server.
+
+=cut
+
+sub server_cert {
+    my $self = shift;
+    if (@_) {
+        my $cert = shift;
+        die "SSL certificate file ($cert) is not readable!" unless -r $cert;
+        $self->{'server_cert'} = $cert;
+    }
+    return $self->{'server_cert'};
+}
+
+=head2 server_key [PATH]
+
+Gets or sets the path fo the SSL key file used by the server.
+
+=cut
+
+sub server_key {
+    my $self = shift;
+    if (@_) {
+        my $key = shift;
+        die "SSL key file ($key) is not readable!" unless -r $key;
+        $self->{'server_key'} = $key;
+    }
+    return $self->{'server_key'};
+}
+
 =head1 DEPENDENCIES
 
 L<Coro>, L<EV>, L<Net::Server>
diff --git a/lib/Net/Server/Proto/Coro.pm b/lib/Net/Server/Proto/Coro.pm
index b9c5f9b..201f6cc 100644
--- a/lib/Net/Server/Proto/Coro.pm
+++ b/lib/Net/Server/Proto/Coro.pm
@@ -27,7 +27,9 @@ sub accept {
             my $socket = $self->new_from_fh(
                 $fh,
                 forward_class => tied( ${$self} )->[7],
-                expects_ssl   => tied( ${$self} )->[9]
+                expects_ssl   => tied( ${$self} )->[9],
+                server_cert   => tied( ${$self} )->[12],
+                server_key    => tied( ${$self} )->[13],
             );
             return wantarray ? ( $socket, $peername ) : $socket;
         }
@@ -47,7 +49,7 @@ sub is_ssl {
     return $self->[10] ? 1 : 0;
 }
 
-sub start_SSL   { Net::Server::Proto::Coro::FH::start_SSL( tied ${$_[0]}, $_[1], $_[2]) }
+sub start_SSL   { Net::Server::Proto::Coro::FH::start_SSL( tied ${+shift}, @_) }
 sub read        { Net::Server::Proto::Coro::FH::READ     ( tied ${$_[0]}, $_[1], $_[2], $_[3]) }
 sub sysread     { Net::Server::Proto::Coro::FH::READ     ( tied ${$_[0]}, $_[1], $_[2], $_[3]) }
 sub syswrite    { Net::Server::Proto::Coro::FH::WRITE    ( tied ${$_[0]}, $_[1], $_[2], $_[3]) }
@@ -70,7 +72,10 @@ sub TIEHANDLE {
 
     my $self = $class->SUPER::TIEHANDLE(%arg);
     $self->[9]  = $arg{expects_ssl};
-    $self->[10] = undef;
+    $self->[10] = undef; # SSLeay object
+    $self->[11] = undef; # SSL context object
+    $self->[12] = $arg{server_cert};
+    $self->[13] = $arg{server_key};
 
     return $self;
 }
@@ -102,8 +107,9 @@ sub READ_UNTIL {
 }
 
 sub READ {
+
     return Coro::Handle::FH::READ(@_) unless $_[0][9];
-    $_[0]->force_close and return unless $_[0][10] or $_[0]->start_SSL();
+    $_[0]->force_close and return unless $_[0][10] or $_[0]->start_SSL;
 
     my $len  = $_[2];
     my $ofs  = $_[3];
@@ -126,7 +132,7 @@ sub READ {
 
 sub READLINE {
     return Coro::Handle::FH::READLINE(@_) unless $_[0][9];
-    $_[0]->force_close and return unless $_[0][10] or $_[0]->start_SSL();
+    $_[0]->force_close and return unless $_[0][10] or $_[0]->start_SSL;
 
     my $irs = $_[1] || $/;
     my $stop = sub {
@@ -145,7 +151,7 @@ sub READLINE {
 
 sub WRITE {
     return Coro::Handle::FH::WRITE(@_) unless $_[0][9];
-    $_[0]->force_close and return unless $_[0][10] or $_[0]->start_SSL();
+    $_[0]->force_close and return unless $_[0][10] or $_[0]->start_SSL;
 
     my $len = defined $_[2] ? $_[2] : length $_[1];
     my $ofs = $_[3] || 0;
@@ -225,8 +231,10 @@ use vars qw/$CONTEXT/;
 sub start_SSL {
     my $ctx;
     $_[0][9] = 1;
-    my $server_cert = $_[1] || "certs/server-cert.pem";
-    my $server_key  = $_[2] || "certs/server-key.pem";
+    my $server_cert = $_[1] || $_[0][12] || "certs/server-cert.pem";
+    my $server_key  = $_[2] || $_[0][13] || "certs/server-key.pem";
+    die "Can't read certificates ($server_cert and $server_key)\n"
+        unless -r $server_cert and -r $server_key;
 
     unless ($CONTEXT) {
         $ctx = $CONTEXT = Net::SSLeay::CTX_new;

commit c61f2fab8350a0ae1afeab5704fca50cfe118293
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Oct 16 10:54:44 2009 -0400

    Include sample certificate and key files

diff --git a/certs/server-cert.pem b/certs/server-cert.pem
new file mode 100644
index 0000000..1fa0d6c
--- /dev/null
+++ b/certs/server-cert.pem
@@ -0,0 +1,62 @@
+Certificate:
+    Data:
+        Version: 3 (0x2)
+        Serial Number:
+            c2:fa:b9:08:d7:a1:e1:a5
+        Signature Algorithm: sha1WithRSAEncryption
+        Issuer: C=US, ST=Local Host, O=Internet Widgits Pty Ltd, CN=localhost
+        Validity
+            Not Before: Feb 18 02:25:22 2007 GMT
+            Not After : Mar 20 02:25:22 2007 GMT
+        Subject: C=US, ST=Local Host, O=Internet Widgits Pty Ltd, CN=localhost
+        Subject Public Key Info:
+            Public Key Algorithm: rsaEncryption
+            RSA Public Key: (1024 bit)
+                Modulus (1024 bit):
+                    00:ab:5c:51:5d:69:66:75:22:2b:d7:4b:5c:63:d3:
+                    f4:5e:ab:56:59:41:ac:41:5b:7c:89:42:8e:3b:44:
+                    88:cf:b4:0b:45:46:9e:ac:be:ab:cd:29:31:6b:6c:
+                    98:d6:67:5e:4b:7c:ec:66:6a:34:b8:20:84:21:fd:
+                    63:c5:da:f8:1c:63:68:f0:a4:2d:ca:e0:53:2d:9d:
+                    73:a7:90:88:eb:84:3e:c5:86:34:e1:4b:59:6c:f3:
+                    24:a0:4d:cb:27:85:b2:a2:f2:01:e2:e5:84:78:17:
+                    8a:45:02:41:4c:1a:43:d4:7b:b1:a7:be:b0:0c:db:
+                    e4:b3:8b:fa:41:2a:b7:b0:59
+                Exponent: 65537 (0x10001)
+        X509v3 extensions:
+            X509v3 Subject Key Identifier: 
+                49:71:2C:CC:28:DA:84:6C:D7:42:E1:8C:1D:28:BD:0A:CB:4E:7D:38
+            X509v3 Authority Key Identifier: 
+                keyid:49:71:2C:CC:28:DA:84:6C:D7:42:E1:8C:1D:28:BD:0A:CB:4E:7D:38
+                DirName:/C=US/ST=Local Host/O=Internet Widgits Pty Ltd/CN=localhost
+                serial:C2:FA:B9:08:D7:A1:E1:A5
+
+            X509v3 Basic Constraints: 
+                CA:TRUE
+    Signature Algorithm: sha1WithRSAEncryption
+        2b:8a:5a:04:15:2c:52:dd:09:e3:5a:2a:8e:37:29:d4:f1:fe:
+        6d:88:fe:bf:91:84:b9:25:ba:ac:8d:ad:27:30:96:00:79:eb:
+        cb:fa:a0:df:4d:66:ee:9a:96:80:c1:81:49:db:37:86:c8:7c:
+        16:04:8c:3d:4c:25:c4:0a:94:f5:32:f3:59:67:2c:74:8f:93:
+        f6:b0:8e:3f:d6:49:49:48:a6:49:d1:c8:e6:01:5b:ca:89:a0:
+        5d:f3:6a:8e:2d:4a:87:31:81:93:93:4d:b2:4d:46:62:f8:35:
+        c1:03:7a:fc:2e:8f:60:59:ff:14:29:52:e2:52:5b:97:50:ab:
+        a7:24
+-----BEGIN CERTIFICATE-----
+MIIC7zCCAligAwIBAgIJAML6uQjXoeGlMA0GCSqGSIb3DQEBBQUAMFkxCzAJBgNV
+BA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b/certs/server-key.pem
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICWwIBAAKBgQCrXFFdaWZ1IivXS1xj0/Req1ZZQaxBW3yJQo47RIjPtAtFRp6s
+vqvNKTFrbJjWZ15LfOxmajS4IIQh/WPF2vgcY2jwpC3K4FMtnXOnkIjrhD7FhjTh
+S1ls8ySgTcsnhbKi8gHi5YR4F4pFAkFMGkPUe7GnvrAM2+Szi/pBKrewWQIDAQAB
+AoGAaEez1A6yJRH4b/oSbUWs7neCAqsuck+ER9tSxsp8HznHqg7BvQoDbsRkqKTb
+lY4uGe4ZxnFXR72x6yVSNDN+zHjP29aSDNRl4Pn8mrQIfAL9hjHVwoi8rmWYjrKa
+hRsfBX+uSyVvcRwum+1xmsEXIMaDLhqI3i7Dj3aEyUIgzAECQQDWCezB/xpGLUur
+GN58deg0a9i1I0MvzTdhiduqjUFUlnrBDcp12bBITpsE5MIwF/+qpIWX7wFr2DR5
+LFBSO/dBAkEAzPR7endHbnF9JQP782g3tN+w7p80QZQY5mfJe6EPjsmAt3hVQ4bY
+A2hxGtCHErbGxjdnkU1bpqz0momlDszLGQJAO5mN5MMtRMdOH7mQEmYen6I8OMw1
+5DSnrDBgC5DD1VMFoYY+jyxryuagge9VJ2E3XwPq81CpO6d7jRZK02tBQQJAKavn
+0z2fU3BVvonx10qwUOFOayYJjO/cpDQj/jQAIssLlcIsq98l2oOIw6f0XrS086Ze
+M2fkI5502Vr1KW4wOQJASDFHxVXz3zN/2d8By93EA1ZuXe5YcX3zzPmpKkIQtO62
+dINHo+M2BYP4Ku3wME++dp4E29BNsIopoLILWHSCow==
+-----END RSA PRIVATE KEY-----

commit 3e27f291687c99cbab971e91ed54ed5c8ee3f940
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Oct 16 10:55:56 2009 -0400

    Version 0.6 releng

diff --git a/Changes b/Changes
index 4227af1..88d0160 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,10 @@
 Revision history for Net-Server-Coro
 
+0.6    Fri Oct 16 10:55:17 2009
+        * Allow ->new to take paths to server certificate and key
+          files, and propagate them down to both SSL and TLS
+          connections.
+
 0.5    Thu Oct 15 23:45:42 2009
         * Allow start_SSL to take paths to server certificate and key
           files (thanks to Dan Keder for the patch).
diff --git a/MANIFEST b/MANIFEST
index efd97af..8214f76 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,3 +1,5 @@
+certs/server-cert.pem
+certs/server-key.pem
 Changes
 inc/Module/Install.pm
 inc/Module/Install/Base.pm
diff --git a/META.yml b/META.yml
index 81c8b0f..743d41c 100644
--- a/META.yml
+++ b/META.yml
@@ -21,4 +21,4 @@ requires:
   EV: 0
   Net::SSLeay: 0
   Net::Server: 0
-version: 0.5
+version: 0.6
diff --git a/SIGNATURE b/SIGNATURE
index 891d7a5..63eb343 100644
--- a/SIGNATURE
+++ b/SIGNATURE
@@ -14,10 +14,12 @@ not run its Makefile.PL or Build.PL.
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-SHA1 65b9e4b55520525d4ea8de55a8f842decb492a61 Changes
-SHA1 bb31f89cfbb2ad6292be17274f6fb6fa2c40616b MANIFEST
-SHA1 02476a865e14c4d1aa9680b0646d0c85ac15e18c META.yml
+SHA1 50e74a4e334e28f4f1a05fb43db9a7402e5df410 Changes
+SHA1 6560e9fb53ffae9afbaddb4919987a778d7cfd88 MANIFEST
+SHA1 9a61d9819eaae6cba301a65661094c77ef1439f3 META.yml
 SHA1 bc22590cf5cc348fedc293e8ea39bcdc72ad897f Makefile.PL
+SHA1 f5333026061a6f347e7f2a3ce8bb6847081c200c certs/server-cert.pem
+SHA1 4b963cd4c2b0a7e073241b4bac727cb6f96276f8 certs/server-key.pem
 SHA1 fd5f3c4f0418efee3b9b16cf8c3902e8374909df inc/Module/Install.pm
 SHA1 7cd7c349afdf3f012e475507b1017bdfa796bfbd inc/Module/Install/Base.pm
 SHA1 ba186541bbf6439111f01fc70769cf24d22869bf inc/Module/Install/Can.pm
@@ -26,12 +28,12 @@ SHA1 3e83972921d54198d1246f7278f08664006cd65d inc/Module/Install/Makefile.pm
 SHA1 12bf1867955480d47d5171a9e9c6a96fabe0b58f inc/Module/Install/Metadata.pm
 SHA1 f7ee667e878bd2faf22ee9358a7b5a2cc8e91ba4 inc/Module/Install/Win32.pm
 SHA1 8ed29d6cf217e0977469575d788599cbfb53a5ca inc/Module/Install/WriteAll.pm
-SHA1 08783a8b2c71dceaab5a2a59c33f75a3f204ddbb lib/Net/Server/Coro.pm
-SHA1 472129b076d9ca798887a2204df2e47081f07e85 lib/Net/Server/Proto/Coro.pm
+SHA1 9df303a2ca773bf78ceec82caed16f65d3578a6e lib/Net/Server/Coro.pm
+SHA1 69a2e815f007e90e230c8ed36b670a6a9cb16948 lib/Net/Server/Proto/Coro.pm
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.11 (GNU/Linux)
 
-iEYEARECAAYFAkrX6/0ACgkQMflWJZZAbqC2qACdEp1wXCOTQbdpCYqP6/wsNtyC
-h1AAoLXSTjHkdu7XMTWPU39i2pwm7A37
-=fq3c
+iEYEARECAAYFAkrYiWEACgkQMflWJZZAbqBPgACgxMl6Cl7nYRWVIZgi1NqVfaMR
+oDgAnjnlT2A6AULV1HAEMt20gEm0zaJD
+=s4Nl
 -----END PGP SIGNATURE-----
diff --git a/lib/Net/Server/Coro.pm b/lib/Net/Server/Coro.pm
index 922a334..20b95dd 100644
--- a/lib/Net/Server/Coro.pm
+++ b/lib/Net/Server/Coro.pm
@@ -9,7 +9,7 @@ use Coro;
 use base qw(Net::Server);
 use Net::Server::Proto::Coro;
 
-$VERSION = 0.5;
+$VERSION = 0.6;
 
 =head1 NAME
 

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list