Codebase list libpoe-component-sslify-perl / fb1c1a1
fix some nits reported by PerlCritic Apocalypse 11 years ago
4 changed file(s) with 18 addition(s) and 19 deletion(s). Raw diff Collapse all Expand all
44 We now load certificate files via CTX_use_certificate_chain_file(), thanks Zephaniah E. Loss-Cutler-Hull <warp-spam_perl@aehallh.com>
55 OpenSSL docs suggest it - http://www.openssl.org/docs/ssl/SSL_CTX_use_certificate.html#NOTES
66 PLEASE yell at me if you need the old functionality - the docs suggest this is the "better" way to do it...
7
87 Add the ability to pass a subref to call on connection/negotiation success, thanks Zephaniah E. Loss-Cutler-Hull <warp-spam_perl@aehallh.com>
98 NOTE: This will not work if you do renegotiation or any other zany SSL stuff!
109 Add the SSLify_GetStatus function to get the status of the connection
55 use Net::SSLeay 1.36 qw( die_now die_if_ssl_error );
66
77 # We inherit from ServerHandle
8 require POE::Component::SSLify::ServerHandle;
9 our @ISA = qw( POE::Component::SSLify::ServerHandle );
8 use parent 'POE::Component::SSLify::ServerHandle';
109
1110 # Override TIEHANDLE because we create a CTX
1211 sub TIEHANDLE {
9999 }
100100
101101 # Insert what we just read into the buffer
102 substr( $$buf, $$offset ) = $read;
102 substr( $$buf, $$offset, 1, $read );
103103
104104 # All done!
105105 return length( $read );
152152 my $self = shift;
153153 if ( defined $self->{'socket'} ) {
154154 Net::SSLeay::free( $self->{'ssl'} );
155 close( $self->{'socket'} );
155
156 # TODO we ignore any close errors because there's no way to sanely propagate it up the stack...
157 close( $self->{'socket'} ); ## no critic ( InputOutput::RequireCheckedClose )
156158 undef $self->{'socket'};
157159
158160 # do we need to do CTX_free?
44 # We need Net::SSLeay or all's a failure!
55 BEGIN {
66 # We need >= 1.36 because it contains a lot of important fixes
7 eval "use Net::SSLeay 1.36 qw( die_now die_if_ssl_error )";
7 eval "use Net::SSLeay 1.36 qw( die_now die_if_ssl_error FILETYPE_PEM )";
88
99 # Check for errors...
1010 if ( $@ ) {
2626 }
2727
2828 # Do the exporting magic...
29 require Exporter;
30 our @ISA = qw( Exporter );
29 use parent 'Exporter';
3130 our @EXPORT_OK = qw(
3231 Client_SSLify Server_SSLify
3332 SSLify_Options SSLify_GetCTX SSLify_GetCipher SSLify_GetSocket SSLify_GetSSL SSLify_ContextCreate SSLify_GetStatus
4544 use Task::Weaken 1.03; # to make sure it actually works!
4645
4746 # The server-side CTX stuff
48 my $ctx = undef;
47 my $ctx;
4948
5049 # global so users of this module can override it locally
5150 our $IGNORE_SSL_ERRORS = 0;
9089
9190 sub Client_SSLify {
9291 # Get the socket + version + options + ctx + callback
93 my( $socket, $version, $options, $ctx, $callback ) = @_;
92 my( $socket, $version, $options, $custom_ctx, $callback ) = @_;
9493
9594 # Validation...
9695 if ( ! defined $socket ) {
10099 # Mangle the callback stuff
101100 if ( defined $version and ref $version and ref( $version ) eq 'CODE' ) {
102101 $callback = $version;
103 $version = $options = $ctx = undef;
102 $version = $options = $custom_ctx = undef;
104103 } elsif ( defined $options and ref $options and ref( $options ) eq 'CODE' ) {
105104 $callback = $options;
106 $options = $ctx = undef;
107 } elsif ( defined $ctx and ref $ctx and ref( $ctx ) eq 'CODE' ) {
108 $callback = $ctx;
109 $ctx = undef;
105 $options = $custom_ctx = undef;
106 } elsif ( defined $custom_ctx and ref $custom_ctx and ref( $custom_ctx ) eq 'CODE' ) {
107 $callback = $custom_ctx;
108 $custom_ctx = undef;
110109 }
111110
112111 # From IO::Handle POD
117116
118117 # Now, we create the new socket and bind it to our subclass of Net::SSLeay::Handle
119118 my $newsock = gensym();
120 tie( *$newsock, 'POE::Component::SSLify::ClientHandle', $socket, $version, $options, $ctx, $callback ) or die "Unable to tie to our subclass: $!";
119 tie( *$newsock, 'POE::Component::SSLify::ClientHandle', $socket, $version, $options, $custom_ctx, $callback ) or die "Unable to tie to our subclass: $!";
121120
122121 # argh, store the newsock in the tied class to use for callback
123122 if ( defined $callback ) {
250249
251250 By default we use the version: default
252251
253 By default we use the options: &Net::SSLeay::OP_ALL
252 By default we use the options: Net::SSLeay::OP_ALL
254253
255254 Please look at L</SSLify_ContextCreate> for more info on the available versions/options.
256255 =cut
266265
267266 # Set the default
268267 if ( ! defined $options ) {
269 $options = &Net::SSLeay::OP_ALL;
268 $options = Net::SSLeay::OP_ALL();
270269 }
271270
272271 # set the context, possibly overwriting the previous one
315314 # do we need to set key/etc?
316315 if ( defined $key ) {
317316 # Following will ask password unless private key is not encrypted
318 Net::SSLeay::CTX_use_RSAPrivateKey_file( $context, $key, &Net::SSLeay::FILETYPE_PEM );
317 Net::SSLeay::CTX_use_RSAPrivateKey_file( $context, $key, FILETYPE_PEM );
319318 die_if_ssl_error( 'private key' ) if ! $IGNORE_SSL_ERRORS;
320319 }
321320