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!
This component represents the standard way to do SSL in POE.
The new socket this module gives you actually is some tied socket magic, so you cannot do stuff like getpeername() or getsockname(). The only way to do it is to use SSLify_GetSocket and then operate on the socket it returns.
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... } }
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 :)
Returns the cipher used by the SSLified socket Example: print "SSL Cipher is: " . SSLify_GetCipher( $sslified_sock ) . "\n";
Returns the actual socket used by the SSLified socket, useful for stuff like getpeername()/getsockname() Example: print "Remote IP is: " . ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $sslified_sock ) ) ) )[0] . "\n";
Stuffs all the 4 functions in @EXPORT_OK so you have to request them directly
On Win32 platforms SSL support is pretty shaky, please help me out with detailed error descriptions if it happens to you!
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 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.
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.