POE::C...SSLify(3pm)

πŸ“¦
version 1.012 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– POE::Component::SSLify πŸ’–

okay bestie, so this is the manual page for POE::Component::SSLify β€” yeah it's filed under the User Contributed Perl Documentation for POE::C...SSLify(3pm), we don't make the filenames, we just live in them πŸ’…. Sit down, get comfy, this one's a chonker.


✨ NAME ✨

POE::Component::SSLify β€” makes using SSL in the world of POE easy! fr fr, that's the whole pitch, no cap. πŸŽ€


πŸ¦‹ VERSION πŸ¦‹

This document describes v1.012 of POE::Component::SSLify β€” released November 14, 2014 as part of POE-Component-SSLify.


🌸 SYNOPSIS 🌸

# look at the DESCRIPTION for client and server example code

πŸ‘‘ DESCRIPTION πŸ‘‘

So this component is basically a method to simplify the SSLification of a socket before it gets passed to a POE::Wheel::ReadWrite wheel in your application. That's it. That's the job. And it ate. πŸ’…


πŸ’œ Client usage πŸ’œ

# Import the module
use POE::Component::SSLify qw( Client_SSLify );

# Create a normal SocketFactory wheel and connect to a SSL-enabled server
my $factory = POE::Wheel::SocketFactory->new;

# Time passes, SocketFactory gives you a socket when it connects in SuccessEvent
# Convert the socket into a SSL socket POE can communicate with
my $socket = shift;
eval { $socket = Client_SSLify( $socket ) };
if ( $@ ) {
        # Unable to SSLify it...
}

# Now, hand it off to ReadWrite
my $rw = POE::Wheel::ReadWrite->new(
        Handle  =>      $socket,
        # other options as usual
);

πŸ’™ Server usage πŸ’™

# !!! Make sure you have a public key + certificate
# excellent howto: http://www.akadia.com/services/ssh_test_certificate.html

# Import the module
use POE::Component::SSLify qw( Server_SSLify SSLify_Options );

# Set the key + certificate file
eval { SSLify_Options( 'server.key', 'server.crt' ) };
if ( $@ ) {
        # Unable to load key or certificate file...
}

# Create a normal SocketFactory wheel to listen for connections
my $factory = POE::Wheel::SocketFactory->new;

# Time passes, SocketFactory gives you a socket when it gets a connection in SuccessEvent
# Convert the socket into a SSL socket POE can communicate with
my $socket = shift;
eval { $socket = Server_SSLify( $socket ) };
if ( $@ ) {
        # Unable to SSLify it...
}

# Now, hand it off to ReadWrite
my $rw = POE::Wheel::ReadWrite->new(
        Handle  =>      $socket,
        # other options as usual
);

🧚 FUNCTIONS 🧚


πŸŽ€ Client_SSLify πŸŽ€

This one sslifies a client-side socket. And you can pass a whole lil squad of options to it, bestie:

my $socket = shift;
$socket = Client_SSLify( $socket, $version, $options, $ctx, $callback );
        $socket is the non-ssl socket you got from somewhere ( required )
        $version is the SSL version you want to use
        $options is the SSL options you want to use
        $ctx is the custom SSL context you want to use
        $callback is the callback hook on success/failure of sslification

        # This is an example of the callback and you should pass it as Client_SSLify( $socket, ... , \&callback );
        sub callback {
                my( $socket, $status, $errval ) = @_;
                # $socket is the original sslified socket in case you need to play with it
                # $status is either 1 or 0; with 1 signifying success and 0 failure
                # $errval will be defined if $status == 0; it's the numeric SSL error code
                # check http://www.openssl.org/docs/ssl/SSL_get_error.html for the possible error values ( and import them from Net::SSLeay! )

                # The return value from the callback is discarded
        }

So like β€” if $ctx is defined, SSLify will ignore $version and $options. Otherwise it'll get created from the $version and $options parameters. And if all of them are undefined, it just follows the defaults in "SSLify_ContextCreate". Easy.

BEWARE: If you passed in a CTX, SSLify will do Net::SSLeay::CTX_free( $ctx ) when the socket is destroyed. Which means you cannot reuse contexts! Like, none. Zero. Don't do it. πŸ’€

NOTE: the way to have a client socket with proper certificates set up is:

my $socket = shift;     # get the socket from somewhere
my $ctx = SSLify_ContextCreate( 'server.key', 'server.crt' );
$socket = Client_SSLify( $socket, undef, undef, $ctx );

NOTE: you can pass the callback anywhere in the arguments, we'll figure it out for you! (obsessed with that honestly 🫢) If you want to call a POE event, please look into the postback/callback stuff in POE::Session.

# we got this from POE::Wheel::SocketFactory
sub event_SuccessEvent {
        my $socket = $_[ARG0];
        $socket = Client_SSLify( $socket, $_[SESSION]->callback( 'sslify_result' ) );
        $_[HEAP]->{client} = POE::Wheel::ReadWrite->new(
                Handle => $socket,
                ...
        );
        return;
}

# the callback event
sub event_sslify_result {
        my ($creation_args, $called_args) = @_[ARG0, ARG1];
        my( $socket, $status, $errval ) = @$called_args;

        if ( $status ) {
                print "Yay, SSLification worked!";
        } else {
                print "Aw, SSLification failed with error $errval";
        }
}

🌈 Server_SSLify 🌈

This one sslifies a server-side socket. Also takes a lil squad of options:

my $socket = shift;
$socket = Server_SSLify( $socket, $ctx, $callback );
        $socket is the non-ssl socket you got from somewhere ( required )
        $ctx is the custom SSL context you want to use; overrides the global ctx set in SSLify_Options
        $callback is the callback hook on success/failure of sslification
BEWARE: "SSLify_Options" must be called first if you aren't passing a $ctx. If you wanna set some options per-connection instead, do this:
my $socket = shift;     # get the socket from somewhere
my $ctx = SSLify_ContextCreate();
# set various options on $ctx as desired
$socket = Server_SSLify( $socket, $ctx );

NOTE: you can use "SSLify_GetCTX" to modify the global, and avoid doing this on every single connection if the options are all the same... just saying πŸ‘€

Please look at "Client_SSLify" for more details on the callback hook. Same energy, different side of the handshake.


πŸ¦‹ SSLify_ContextCreate πŸ¦‹

Accepts some options, and returns a brand-new Net::SSLeay context object ( $ctx ). Fresh out the box, iconic.

my $ctx = SSLify_ContextCreate( $key, $cert, $version, $options );
        $key is the certificate key file
        $cert is the certificate file
        $version is the SSL version to use
        $options is the SSL options to use

You can then call various Net::SSLeay methods on the context, go off:

my $mode = Net::SSLeay::CTX_get_mode( $ctx );

By default we don't use the SSL key + certificate files.

By default we use the version: default. Known versions of the SSL connection β€” look at <http://www.openssl.org/docs/ssl/SSL_CTX_new.html> for more info.

  • sslv2
  • sslv3
  • tlsv1
  • sslv23
  • default ( sslv23 )

By default we don't set any options β€” look at <http://www.openssl.org/docs/ssl/SSL_CTX_set_options.html> for more info.


πŸ’… SSLify_Options πŸ’…

Call this function to initialize the global server-side context object. This will be the default context whenever you call "Server_SSLify" without passing a custom context to it.

SSLify_Options( $key, $cert, $version, $options );
        $key is the certificate key file ( required )
        $cert is the certificate file ( required )
        $version is the SSL version to use
        $options is the SSL options to use

By default we use the version: default

By default we use the options: Net::SSLeay::OP_ALL

Please look at "SSLify_ContextCreate" for more info on the available versions/options. It's all connected bestie, iykyk.


πŸ“ SSLify_GetCTX πŸ“

Returns the actual Net::SSLeay context object in case you wanted to play with it :) go ahead, it's yours.

If passed in a socket, it will return that socket's $ctx instead of the global.

my $ctx = SSLify_GetCTX();                      # get the one set via SSLify_Options
my $ctx = SSLify_GetCTX( $sslified_sock );      # get the one in the object

⭐ SSLify_GetCipher ⭐

Returns the cipher used by the SSLified socket. Slay.

print "SSL Cipher is: " . SSLify_GetCipher( $sslified_sock ) . "\n";

NOTE: doing this immediately after Client_SSLify or Server_SSLify will result in "(NONE)" because the SSL handshake is not done yet. The socket is nonblocking, so you will have to wait a little bit for it to get ready. Patience, queen. 🧘

apoc@blackhole:~/mygit/perl-poe-sslify/examples$ perl serverclient.pl
got connection from: 127.0.0.1 - commencing Server_SSLify()
SSLified: 127.0.0.1 cipher type: ((NONE))
Connected to server, commencing Client_SSLify()
SSLified the connection to the server
Connected to SSL server
Input: hola
got input from: 127.0.0.1 cipher type: (AES256-SHA) input: 'hola'
Got Reply: hola
Input: ^C
stopped at serverclient.pl line 126.

🌸 SSLify_GetSocket 🌸

Returns the actual socket used by the SSLified socket β€” useful for stuff like getpeername()/getsockname().

print "Remote IP is: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $sslified_sock ) ) ) )[1] ) . "\n";

πŸ’œ SSLify_GetSSL πŸ’œ

Returns the actual Net::SSLeay object so you can call methods on it. It's giving ✨full access✨.

print Net::SSLeay::dump_peer_certificate( SSLify_GetSSL( $sslified_sock ) );

πŸ”₯ SSLify_GetStatus πŸ”₯

Returns the status of the SSL negotiation/handshake/connection. See <http://www.openssl.org/docs/ssl/SSL_connect.html#RETURN_VALUES> for more info.

my $status = SSLify_GetStatus( $socket );
        -1 = still in negotiation stage ( or error )
         0 = internal SSL error, connection will be dead
         1 = negotiation successful

NOTES πŸ’œ

Socket methods doesn't work 🫠

okay so the new socket this module hands you? it's literally tied socket magic. so you cannot do cute little things like getpeername() or getsockname(). nope. the only way is to grab the real one with SSLify_GetSocket and then do your thing on the socket it gives back. that's it, that's the whole workaround ✨


Dying everywhere... πŸ’€

bestie this module will die() if Net::SSLeay couldn't be loaded, or if it's not the version we want. so the move is to check for errors and just... 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...
                }
        }

$IGNORE_SSL_ERRORS

as of SSLify v1.003 you can override this variable to temporarily ignore some SSL errors. it's giving very useful when you're doing crazy things with the underlying Net::SSLeay stuff and you don't want to die. but heads up β€” it won't ignore all errors, because some are still considered fatal. here's an example:

        {
                local $POE::Component::SSLify::IGNORE_SSL_ERRORS=1;
                my $ctx = SSLify_CreateContext(...);
                #Some more stuff
        }

OpenSSL functions 🌈

theoretically you can do anything that Net::SSLeay exports from the OpenSSL libs on the socket. but ngl, I have not tested every possible function against SSLify, so use them carefully bestie! πŸ™ˆ

Net::SSLeay::renegotiate

this function has been tested ( it's in t/2_renegotiate_client.t ) but it doesn't work on FreeBSD! 😭 I tracked it down to this security advisory: http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc which explains it in detail. the test will skip this function if it detects that you're on a broken system. however, if you have the updated OpenSSL library that fixes this you can use it ✨

NOTE: calling this means the callback function you passed in Client_SSLify or Server_SSLify will not fire! if you need this please let me know and we can come up with a way to make it work 🫢

Upgrading a non-ssl socket to SSL πŸ¦‹

you can have a normal plaintext socket, and convert it to SSL anytime. just keep in mind that the client and the server must agree to sslify at the same time, or they will be waiting on each other forever! πŸ’€ see t/3_upgrade.t for an example of how this works.


Downgrading a SSL socket to non-ssl πŸ₯²

as of now this is unsupported. if you need this feature please let us know and we'll work on it together! 🌸


MSWin32 is not supported 🚫

this module doesn't work on MSWin32 platforms at all ( XP, Vista, 7, etc ) because of some weird underlying fd issues. since I'm not a windows developer, I'm unable to fix this. however, it seems like Cygwin on MSWin32 works just fine! please help me fix this if you can, thanks! πŸ’œ


LOAD_SSL_ENGINES βš™οΈ

OpenSSL supports loading ENGINEs to accelerate the crypto algorithms. SSLify v1.004 automatically loaded the engines, but there was some problems on certain platforms that caused coredumps. a big shout-out to BinGOs and CPANTesters for catching this! it's now disabled in v1.007 and you would need to explicitly enable it, like:

        sub POE::Component::SSLify::LOAD_SSL_ENGINES () { 1 }
        use POE::Component::SSLify qw( Client::SSLify );

EXPORT πŸŽ€

stuffs all of the functions in @EXPORT_OK so you have to request them directly. no free handouts here, ask for them by name periodt πŸ’…


SEE ALSO πŸ‘€

please see those modules/websites for more information related to this module.

  • POE
  • Net::SSLeay

SUPPORT 🫢

Perldoc

you can find documentation for this module with the perldoc command.

  perldoc POE::Component::SSLify

Websites

the following websites have more information about this module, and may be of help to you. as always, in addition to those websites please use your favorite search engine to discover more resources. πŸ”

  • MetaCPAN

a modern, open-source CPAN search engine, useful to view POD in HTML format.

http://metacpan.org/release/POE-Component-SSLify

  • Search CPAN

the default CPAN search engine, useful to view POD in HTML format.

http://search.cpan.org/dist/POE-Component-SSLify

  • RT: CPAN's Bug Tracker

the RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.

http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-SSLify

  • AnnoCPAN

the AnnoCPAN is a website that allows community annotations of Perl module documentation.

http://annocpan.org/dist/POE-Component-SSLify

  • CPAN Ratings

the CPAN Ratings is a website that allows community ratings and reviews of Perl modules.

http://cpanratings.perl.org/d/POE-Component-SSLify

  • CPAN Forum

the CPAN Forum is a web forum for discussing Perl modules.

http://cpanforum.com/dist/POE-Component-SSLify

  • CPANTS

the CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.

http://cpants.cpanauthors.org/dist/overview/POE-Component-SSLify

  • CPAN Testers

the CPAN Testers is a network of smokers who run automated tests on uploaded CPAN distributions.

http://www.cpantesters.org/distro/P/POE-Component-SSLify

  • CPAN Testers Matrix

the CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

http://matrix.cpantesters.org/?dist=POE-Component-SSLify

  • CPAN Testers Dependencies

the CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

http://deps.cpantesters.org/?module=POE::Component::SSLify

Email

you can email the author of this module at APOCAL at cpan.org asking for help with any problems you have. πŸ“§

Internet Relay Chat

you can get live help by using IRC ( Internet Relay Chat ). if you don't know what IRC is, please read this excellent guide: http://en.wikipedia.org/wiki/Internet_Relay_Chat. please be courteous and patient when talking to us, as we might be busy or sleeping! 😴 you can join those networks/channels and get help:

  • irc.perl.org

you can connect to the server at 'irc.perl.org' and join this channel: #perl-help then talk to this person for help: Apocalypse.

  • irc.freenode.net

you can connect to the server at 'irc.freenode.net' and join this channel: #perl then talk to this person for help: Apocal.

  • irc.efnet.org

you can connect to the server at 'irc.efnet.org' and join this channel: #perl then talk to this person for help: Ap0cal.

Bugs / Feature Requests

please report any bugs or feature requests by email to bug-poe-component-sslify at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-SSLify. you will be automatically notified of any progress on the request by the system. πŸ›

Source Code

the code is open to the world, and available for you to hack on. please feel free to browse it and play with it, or whatever. if you want to contribute patches, please send me a diff or prod me to pull from your repository :) πŸ’–

https://github.com/apocalypse/perl-poe-sslify

  git clone https://github.com/apocalypse/perl-poe-sslify.git

AUTHOR πŸ‘‘

Apocalypse <APOCAL@cpan.org>


ACKNOWLEDGEMENTS 🌸

        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 =]
        # This code should probably become a POE::Kernel method,
        # seeing as it's rather baroque and potentially useful in a number
        # of places.

ASCENT also helped a lot with the nonblocking mode, without his hard work this module would still be stuck in the stone age :) πŸ¦•

a lot of people helped add various features/functions β€” please look at the changelog for more detail.


this software is copyright (c) 2014 by Apocalypse.

this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

the full text of the license can be found in the LICENSE file included with this distribution.


DISCLAIMER OF WARRANTY 🚨

okay bestie, this part is the serious part, so I'm keeping it exactly as it is, no cap:

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

and that's a wrap on part 2, bestie!! πŸŽ€ this page ships as perl v5.34.0 and it was generated on 2022-05-27, which is giving very "a while ago but still iconic" energy πŸ’… go forth and SSLify responsibly πŸ¦‹βœ¨πŸ’–

πŸ“¦ where this page comes from