r11257 - in /branches/upstream/libpoe-component-sslify-perl/current: Changes MANIFEST META.yml examples/client.pl examples/server.pl lib/POE/Component/SSLify.pm lib/POE/Component/SSLify/ClientHandle.pm lib/POE/Component/SSLify/ServerHandle.pm

tincho-guest at users.alioth.debian.org tincho-guest at users.alioth.debian.org
Mon Dec 17 01:27:43 UTC 2007


Author: tincho-guest
Date: Mon Dec 17 01:27:42 2007
New Revision: 11257

URL: http://svn.debian.org/wsvn/?sc=1&rev=11257
Log:
[svn-upgrade] Integrating new upstream version, libpoe-component-sslify-perl (0.10)

Added:
    branches/upstream/libpoe-component-sslify-perl/current/examples/client.pl
Modified:
    branches/upstream/libpoe-component-sslify-perl/current/Changes
    branches/upstream/libpoe-component-sslify-perl/current/MANIFEST
    branches/upstream/libpoe-component-sslify-perl/current/META.yml
    branches/upstream/libpoe-component-sslify-perl/current/examples/server.pl
    branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify.pm
    branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify/ClientHandle.pm
    branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify/ServerHandle.pm

Modified: branches/upstream/libpoe-component-sslify-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libpoe-component-sslify-perl/current/Changes?rev=11257&op=diff
==============================================================================
--- branches/upstream/libpoe-component-sslify-perl/current/Changes (original)
+++ branches/upstream/libpoe-component-sslify-perl/current/Changes Mon Dec 17 01:27:42 2007
@@ -1,4 +1,11 @@
 Revision history for Perl extension POE::Component::SSLify.
+
+* 0.10
+
+	More tweaks of POD - finally close RT #31238
+	Added SSL version support - thanks RT #31492
+	Added SSL CTX option support as a side effect
+	Added client.pl example with ReadLine support
 
 * 0.09
 

Modified: branches/upstream/libpoe-component-sslify-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libpoe-component-sslify-perl/current/MANIFEST?rev=11257&op=diff
==============================================================================
--- branches/upstream/libpoe-component-sslify-perl/current/MANIFEST (original)
+++ branches/upstream/libpoe-component-sslify-perl/current/MANIFEST Mon Dec 17 01:27:42 2007
@@ -9,3 +9,4 @@
 META.yml
 Changes
 examples/server.pl
+examples/client.pl

Modified: branches/upstream/libpoe-component-sslify-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libpoe-component-sslify-perl/current/META.yml?rev=11257&op=diff
==============================================================================
--- branches/upstream/libpoe-component-sslify-perl/current/META.yml (original)
+++ branches/upstream/libpoe-component-sslify-perl/current/META.yml Mon Dec 17 01:27:42 2007
@@ -1,6 +1,6 @@
 --- #YAML:1.0
 name:                POE-Component-SSLify
-version:             0.09
+version:             0.10
 abstract:            Makes using SSL in the world of POE easy!
 license:             perl
 generated_by:        ExtUtils::MakeMaker version 6.31

Added: branches/upstream/libpoe-component-sslify-perl/current/examples/client.pl
URL: http://svn.debian.org/wsvn/branches/upstream/libpoe-component-sslify-perl/current/examples/client.pl?rev=11257&op=file
==============================================================================
--- branches/upstream/libpoe-component-sslify-perl/current/examples/client.pl (added)
+++ branches/upstream/libpoe-component-sslify-perl/current/examples/client.pl Mon Dec 17 01:27:42 2007
@@ -1,0 +1,103 @@
+#!/usr/bin/perl
+use strict; use warnings;
+
+use POE;
+use POE::Component::SSLify qw( Client_SSLify );
+use POE::Wheel::ReadWrite;
+use POE::Wheel::SocketFactory;
+use POE::Driver::SysRW;
+use POE::Filter::Line;
+use POE::Wheel::ReadLine;
+
+POE::Session->create(
+	'inline_states'	=>	{
+		'_start'	=>	sub {
+			# Set the alias
+			$_[KERNEL]->alias_set( 'main' );
+
+			# Setup our ReadLine stuff
+			$_[HEAP]->{'RL'} = POE::Wheel::ReadLine->new(
+				'InputEvent'	=> 'Got_ReadLine',
+			);
+
+			# Connect to the server!
+			$_[KERNEL]->yield( 'do_connect' );
+			return 1;
+		},
+		'do_connect'		=>	sub {
+			# Create the socketfactory wheel to listen for requests
+			$_[HEAP]->{'SOCKETFACTORY'} = POE::Wheel::SocketFactory->new(
+				'RemotePort'	=>	5432,
+				'RemoteAddress'	=>	'localhost',
+				'Reuse'		=>	'yes',
+				'SuccessEvent'	=>	'Got_Connection',
+				'FailureEvent'	=>	'ConnectError',
+			);
+			return 1;
+		},
+		'Got_ReadLine'		=>	sub {
+			if ( defined $_[ARG0] ) {
+				if ( exists $_[HEAP]->{'WHEEL'} ) {
+					$_[HEAP]->{'WHEEL'}->put( $_[ARG0] );
+				}
+			} else {
+				if ( $_[ARG1] eq 'interrupt' ) {
+					die 'stopped';
+				}
+			}
+		},
+		'Got_Connection'	=>	sub {
+			# ARG0 = Socket, ARG1 = Remote Address, ARG2 = Remote Port
+			my $socket = $_[ ARG0 ];
+
+			# SSLify it!
+			$socket = Client_SSLify( $socket );
+
+			# Hand it off to ReadWrite
+			my $wheel = POE::Wheel::ReadWrite->new(
+				'Handle'	=>	$socket,
+				'Driver'	=>	POE::Driver::SysRW->new(),
+				'Filter'	=>	POE::Filter::Line->new(),
+				'InputEvent'	=>	'Got_Input',
+				'ErrorEvent'	=>	'Got_Error',
+			);
+
+			# Store it...
+			$_[HEAP]->{'WHEEL'} = $wheel;
+			$_[HEAP]->{'RL'}->put( 'Connected to SSL server' );
+			$_[HEAP]->{'RL'}->get( 'Input: ' );
+
+			return 1;
+		},
+		'ConnectError'	=>	sub {
+			# ARG0 = operation, ARG1 = error number, ARG2 = error string, ARG3 = wheel ID
+			my ( $operation, $errnum, $errstr, $wheel_id ) = @_[ ARG0 .. ARG3 ];
+			warn "SocketFactory Wheel $wheel_id generated $operation error $errnum: $errstr\n";
+			delete $_[HEAP]->{'SOCKETFACTORY'};
+			$_[HEAP]->{'RL'}->put( 'Unable to connect to SSL server...' );
+			$_[KERNEL]->delay_set( 'do_connect', 5 );
+			return 1;
+		},
+		'Got_Input'	=>	sub {
+			# ARG0: The Line, ARG1: Wheel ID
+
+			# Send back to the client the line!
+			$_[HEAP]->{'RL'}->put( 'Got Reply: ' . $_[ARG0] );
+			$_[HEAP]->{'RL'}->get( 'Input: ' );
+			return 1;
+		},
+		'Got_Error'	=>	sub {
+			# ARG0 = operation, ARG1 = error number, ARG2 = error string, ARG3 = wheel ID
+			my ( $operation, $errnum, $errstr, $id ) = @_[ ARG0 .. ARG3 ];
+			warn "Wheel $id generated $operation error $errnum: $errstr\n";
+			delete $_[HEAP]->{'WHEEL'};
+			$_[HEAP]->{'RL'}->put( 'Disconnected from SSL server...' );
+			$_[KERNEL]->delay_set( 'do_connect', 5 );
+			return 1;
+		},
+	},
+);
+
+# Start POE!
+POE::Kernel->run();
+exit 0;

Modified: branches/upstream/libpoe-component-sslify-perl/current/examples/server.pl
URL: http://svn.debian.org/wsvn/branches/upstream/libpoe-component-sslify-perl/current/examples/server.pl?rev=11257&op=diff
==============================================================================
--- branches/upstream/libpoe-component-sslify-perl/current/examples/server.pl (original)
+++ branches/upstream/libpoe-component-sslify-perl/current/examples/server.pl Mon Dec 17 01:27:42 2007
@@ -1,3 +1,6 @@
+#!/usr/bin/perl
+use strict; use warnings;
+
 use POE;
 use POE::Component::SSLify qw( Server_SSLify SSLify_Options );
 use POE::Wheel::ReadWrite;
@@ -5,23 +8,24 @@
 use POE::Driver::SysRW;
 use POE::Filter::Line;
 
-# Needs to generate the SSL certs before running this!
-
-POE::Session->new(
+POE::Session->create(
 	'inline_states'	=>	{
 		'_start'	=>	sub {
 			# Okay, set the SSL options
-			SSLify_Options( 'public-key.pem', 'public-cert.pem' );
+			SSLify_Options( 'server.key', 'server.crt', 'default' );
+
+			# Set the alias
+			$_[KERNEL]->alias_set( 'main' );
 
 			# Create the socketfactory wheel to listen for requests
 			$_[HEAP]->{'SOCKETFACTORY'} = POE::Wheel::SocketFactory->new(
 				'BindPort'	=>	5432,
-				'BindAddress'	=>	localhost,
+				'BindAddress'	=>	'localhost',
 				'Reuse'		=>	'yes',
 				'SuccessEvent'	=>	'Got_Connection',
 				'FailureEvent'	=>	'ListenerError',
 			);
-			return;
+			return 1;
 		},
 		'Got_Connection'	=>	sub {
 			# ARG0 = Socket, ARG1 = Remote Address, ARG2 = Remote Port
@@ -42,26 +46,25 @@
 
 			# Store it...
 			$_[HEAP]->{'WHEELS'}->{ $wheel->ID } = $wheel;
-			return;
+			return 1;
 		},
 		'ListenerError'	=>	sub {
 			# ARG0 = operation, ARG1 = error number, ARG2 = error string, ARG3 = wheel ID
 			my ( $operation, $errnum, $errstr, $wheel_id ) = @_[ ARG0 .. ARG3 ];
 			warn "SocketFactory Wheel $wheel_id generated $operation error $errnum: $errstr\n";
 
-			return;
+			return 1;
 		},
 		'Got_Input'	=>	sub {
 			# ARG0: The Line, ARG1: Wheel ID
 
 			# Send back to the client the line!
 			$_[HEAP]->{'WHEELS'}->{ $_[ARG1] }->put( $_[ARG0] );
-			return;
+			return 1;
 		},
 		'Got_Flush'	=>	sub {
-			# Done with a wheel
-			delete $_[HEAP]->{'WHEELS'}->{ $_[ARG0] };
-			return;
+			# We don't care about this event
+			return 1;
 		},
 		'Got_Error'	=>	sub {
 			# ARG0 = operation, ARG1 = error number, ARG2 = error string, ARG3 = wheel ID
@@ -70,7 +73,7 @@
 
 			# Done with a wheel
 			delete $_[HEAP]->{'WHEELS'}->{ $_[ARG0] };
-			return;
+			return 1;
 		},
 	},
 );

Modified: branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify.pm?rev=11257&op=diff
==============================================================================
--- branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify.pm (original)
+++ branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify.pm Mon Dec 17 01:27:42 2007
@@ -6,8 +6,8 @@
 use warnings FATAL => 'all';				# Enable warnings to catch errors
 
 # Initialize our version
-# $Revision: 1223 $
-our $VERSION = '0.09';
+# $Revision: 1248 $
+our $VERSION = '0.10';
 
 # We need Net::SSLeay or all's a failure!
 BEGIN {
@@ -97,8 +97,8 @@
 
 # Okay, the main routine here!
 sub Client_SSLify {
-	# Get the socket!
-	my $socket = shift;
+	# Get the socket + version + options
+	my( $socket, $version, $options ) = @_;
 
 	# Validation...
 	if ( ! defined $socket ) {
@@ -110,7 +110,7 @@
 
 	# Now, we create the new socket and bind it to our subclass of Net::SSLeay::Handle
 	my $newsock = gensym();
-	tie( *$newsock, 'POE::Component::SSLify::ClientHandle', $socket ) or die "Unable to tie to our subclass: $!";
+	tie( *$newsock, 'POE::Component::SSLify::ClientHandle', $socket, $version, $options ) or die "Unable to tie to our subclass: $!";
 
 	# All done!
 	return $newsock;
@@ -142,13 +142,35 @@
 	return $newsock;
 }
 
-# Sets the key + certificate
 sub SSLify_Options {
-	# Get the key + cert
-	my( $key, $cert ) = @_;
-
-	$ctx = Net::SSLeay::CTX_new() or die_now( "CTX_new($ctx): $!" );
-	Net::SSLeay::CTX_set_options( $ctx, &Net::SSLeay::OP_ALL ) and die_if_ssl_error( 'ssl ctx set options' );
+	# Get the key + cert + version + options
+	my( $key, $cert, $version, $options ) = @_;
+
+	if ( defined $version and ! ref $version ) {
+		if ( $version eq 'sslv2' ) {
+			$ctx = Net::SSLeay::CTX_v2_new();
+		} elsif ( $version eq 'sslv3' ) {
+			$ctx = Net::SSLeay::CTX_v3_new();
+		} elsif ( $version eq 'tlsv1' ) {
+			$ctx = Net::SSLeay::CTX_tlsv1_new();
+		} elsif ( $version eq 'default' ) {
+			$ctx = Net::SSLeay::CTX_new();
+		} else {
+			die "unknown SSL version: $version";
+		}
+	} else {
+		$ctx = Net::SSLeay::CTX_new();
+	}
+	if ( ! defined $ctx ) {
+		die_now( "Failed to create SSL_CTX $!" );
+	}
+
+	# Set the default
+	if ( ! defined $options ) {
+		$options = &Net::SSLeay::OP_ALL;
+	}
+
+	Net::SSLeay::CTX_set_options( $ctx, $options ) and die_if_ssl_error( 'ssl ctx set options' );
 
 	# Following will ask password unless private key is not encrypted
 	Net::SSLeay::CTX_use_RSAPrivateKey_file( $ctx, $key, &Net::SSLeay::FILETYPE_PEM );
@@ -183,6 +205,7 @@
 1;
 
 __END__
+
 =head1 NAME
 
 POE::Component::SSLify - Makes using SSL in the world of POE easy!
@@ -214,19 +237,16 @@
 =head2 Server-side usage
 
 	# !!! Make sure you have a public key + certificate generated via Net::SSLeay's makecert.pl
+	# excellent howto: http://www.akadia.com/services/ssh_test_certificate.html
 
 	# Import the module
-	use POE::Component::SSLify qw( Server_SSLify SSLify_Options SSLify_GetCTX );
+	use POE::Component::SSLify qw( Server_SSLify SSLify_Options );
 
 	# Set the key + certificate file
-	eval { SSLify_Options( 'public-key.pem', 'public-cert.pem' ) };
+	eval { SSLify_Options( 'server.key', 'server.crt' ) };
 	if ( $@ ) {
 		# Unable to load key or certificate file...
 	}
-
-	# Ah, I want to set some options ( not required )
-	# my $ctx = SSLify_GetCTX();
-	# Net::SSLeay::CTX_set_options( $ctx, foo );
 
 	# Create a normal SocketFactory wheel or something
 	my $factory = POE::Wheel::SocketFactory->new( ... );
@@ -287,6 +307,19 @@
 
 	Accepts a socket, returns a brand new socket SSLified
 
+	Optionally accepts the SSL version + CTX options
+		Client_SSLify( $socket, $version, $options );
+
+	Known versions:
+		* sslv2
+		* sslv3
+		* tlsv1
+		* default
+
+	By default we use the version: default
+
+	By default we don't set any options
+
 =head2 Server_SSLify
 
 	Accepts a socket, returns a brand new socket SSLified
@@ -296,6 +329,19 @@
 =head2 SSLify_Options
 
 	Accepts the location of the SSL key + certificate files and does it's job
+
+	Optionally accepts the SSL version + CTX options
+		SSLify_Options( $key, $cert, $version, $options );
+
+	Known versions:
+		* sslv2
+		* sslv3
+		* tlsv1
+		* default
+
+	By default we use the version: default
+
+	By default we use the options: &Net::SSLeay::OP_ALL
 
 =head2 SSLify_GetCTX
 

Modified: branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify/ClientHandle.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify/ClientHandle.pm?rev=11257&op=diff
==============================================================================
--- branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify/ClientHandle.pm (original)
+++ branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify/ClientHandle.pm Mon Dec 17 01:27:42 2007
@@ -6,9 +6,9 @@
 use warnings FATAL => 'all';				# Enable warnings to catch errors
 
 # Initialize our version
-# $Revision: 1223 $
+# $Revision: 1247 $
 use vars qw( $VERSION );
-$VERSION = '0.03';
+$VERSION = '0.04';
 
 # Import the SSL death routines
 use Net::SSLeay qw( die_now die_if_ssl_error );
@@ -19,9 +19,30 @@
 
 # Override TIEHANDLE because we create a CTX
 sub TIEHANDLE {
-	my ( $class, $socket ) = @_;
+	my ( $class, $socket, $version, $options ) = @_;
 
-	my $ctx = Net::SSLeay::CTX_new() or die_now( "Failed to create SSL_CTX $!" );
+	my $ctx;
+	if ( defined $version and ! ref $version ) {
+		if ( $version eq 'sslv2' ) {
+			$ctx = Net::SSLeay::CTX_v2_new();
+		} elsif ( $version eq 'sslv3' ) {
+			$ctx = Net::SSLeay::CTX_v3_new();
+		} elsif ( $version eq 'tlsv1' ) {
+			$ctx = Net::SSLeay::CTX_tlsv1_new();
+		} elsif ( $version eq 'default' ) {
+			$ctx = Net::SSLeay::CTX_new();
+		} else {
+			die "unknown SSL version: $version";
+		}
+	} else {
+		$ctx = Net::SSLeay::CTX_new();
+	}
+	$ctx || die_now( "Failed to create SSL_CTX $!" );
+
+	if ( defined $options ) {
+		Net::SSLeay::CTX_set_options( $ctx, $options ) and die_if_ssl_error( 'ssl ctx set options' );
+	}
+
 	my $ssl = Net::SSLeay::new( $ctx ) or die_now( "Failed to create SSL $!" );
 
 	my $fileno = fileno( $socket );
@@ -58,6 +79,7 @@
 1;
 
 __END__
+
 =head1 NAME
 
 POE::Component::SSLify::ClientHandle - client object for POE::Component::SSLify
@@ -94,7 +116,7 @@
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2006 by Apocalypse/Rocco Caputo
+Copyright 2007 by Apocalypse/Rocco Caputo
 
 This library is free software; you can redistribute it and/or modify
 it under the same terms as Perl itself.

Modified: branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify/ServerHandle.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify/ServerHandle.pm?rev=11257&op=diff
==============================================================================
--- branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify/ServerHandle.pm (original)
+++ branches/upstream/libpoe-component-sslify-perl/current/lib/POE/Component/SSLify/ServerHandle.pm Mon Dec 17 01:27:42 2007
@@ -6,7 +6,7 @@
 use warnings FATAL => 'all';				# Enable warnings to catch errors
 
 # Initialize our version
-# $Revision: 1223 $
+# $Revision: 1247 $
 use vars qw( $VERSION );
 $VERSION = '0.04';
 
@@ -161,6 +161,7 @@
 1;
 
 __END__
+
 =head1 NAME
 
 POE::Component::SSLify::ServerHandle - server object for POE::Component::SSLify




More information about the Pkg-perl-cvs-commits mailing list