POE::Component::SSLify - Makes using SSL in the world of POE easy!
# Import the module use POE::Component::SSLify qw( Client_SSLify ); # Create a normal SocketFactory wheel or something my $factory = POE::Wheel::SocketFactory->new( ... ); # Converts the socket into a SSL socket POE can communicate with eval { $socket = Client_SSLify( $socket ) }; if ( $@ ) { # Unable to SSLify it... } # Now, hand it off to ReadWrite my $rw = POE::Wheel::ReadWrite->new( Handle => $socket, ... ); # Use it as you wish...
# !!! Make sure you have a public key + certificate generated via Net::SSLeay's makecert.pl # Import the module use POE::Component::SSLify qw( Server_SSLify SSLify_Options SSLify_GetCTX ); # Set the key + certificate file eval { SSLify_Options( 'public-key.pem', 'public-cert.pem' ) }; 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( ... ); # Converts the socket into a SSL socket POE can communicate with eval { $socket = Server_SSLify( $socket ) }; if ( $@ ) { # Unable to SSLify it... } # Now, hand it off to ReadWrite my $rw = POE::Wheel::ReadWrite->new( Handle => $socket, ... ); # Use it as you wish...
Makes SSL use in POE a breeze!
First stab at the server-side code, help me test it out! Refactored SSLify() into client/server side, so update your program accordingly!
Made sure the IO::Handle way was used only on MSWin32
Initial release
This component represents the standard way to do SSL in POE.
This module will die() if Net::SSLeay could not be loaded or it is not the version we want. So, it is recommended that you check for errors and not use SSL, like so:
eval { use POE::Component::SSLify }; if ( $@ ) { $sslavailable = 0; } else { $sslavailable = 1; } # Make socket SSL! if ( $sslavailable ) { eval { $socket = POE::Component::SSLify::Client_SSLify( $socket ) }; if ( $@ ) { # Unable to SSLify the socket... } }
There's four functions one can use:
Accepts a socket, returns a brand new socket SSLified
Accepts a socket, returns a brand new socket SSLified NOTE: SSLify_Options must be set first!
Accepts the location of the SSL key + certificate files and does it's job
Returns the server-side CTX in case you wanted to play around with it :)
Stuffs all the 4 functions in @EXPORT_OK so you have to request them directly
POE
Net::SSLeay
Apocalypse <apocal@cpan.org>
Original code is entirely Rocco Caputo ( Creator of POE ) -> I simply packaged up the code into something everyone could use and accepted the burden of maintaining it :) From the PoCo::Client::HTTP code =] # TODO - This code should probably become a POE::Kernel method, # seeing as it's rather baroque and potentially useful in a number # of places.
Copyright 2004 by Apocalypse/Rocco Caputo
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install POE::Component::SSLify, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::Component::SSLify
CPAN shell
perl -MCPAN -e shell install POE::Component::SSLify
For more information on module installation, please visit the detailed CPAN module installation guide.