NAME
POE::Component::SSLify - Makes using SSL in the world of POE easy!
SYNOPSIS
Client-side usage
# 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...
Server-side usage
# !!! 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...
ABSTRACT
Makes SSL use in POE a breeze!
DESCRIPTION
This component represents the standard way to do SSL in POE.
NOTES
Socket methods doesn't work
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.
Dying everywhere...
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...
}
}
FUNCTIONS
Client_SSLify
Accepts a socket, returns a brand new socket SSLified
Server_SSLify
Accepts a socket, returns a brand new socket SSLified
NOTE: SSLify_Options must be set first!
SSLify_Options
Accepts the location of the SSL key + certificate files and does it's job
SSLify_GetCTX
Returns the server-side CTX in case you wanted to play around with it :)
SSLify_GetCipher
Returns the cipher used by the SSLified socket
Example:
print "SSL Cipher is: " . SSLify_GetCipher( $sslified_sock ) . "\n";
SSLify_GetSocket
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";
EXPORT
Stuffs all the 4 functions in @EXPORT_OK so you have to request them directly
BUGS
On Win32 platforms SSL support is pretty shaky, please help me out with detailed error descriptions if it happens to you!
SEE ALSO
AUTHOR
Apocalypse <apocal@cpan.org>
PROPS
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 AND LICENSE
Copyright 2006 by Apocalypse/Rocco Caputo
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.