Package list libpoe-component-sslify-perl / 07f4c22
dzilification and insitu test and remove old crufty NBIO code Apocalypse 10 years ago
59 changed file(s) with 621 addition(s) and 772 deletion(s). Raw diff Collapse all Expand all
0 LICENSE
1 META.yml
2 README
3 Makefile.PL
0 /POE-Component-SSLify-*
1 /.build/
+0
-49
Build.PL less more
0 # Build.PL
1 use strict; use warnings;
2 use Module::Build;
3
4 my $build = Module::Build->new(
5 # look up Module::Build::API for the info!
6 'dynamic_config' => 0,
7 'module_name' => 'POE::Component::SSLify',
8 'license' => 'perl',
9
10 'dist_abstract' => 'SSL in the world of POE made easy',
11 'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
12
13 'create_packlist' => 1,
14 'create_makefile_pl' => 'traditional',
15 'create_readme' => 1,
16 'create_license' => 1,
17 'sign' => 0,
18
19 'test_files' => 't/*.t',
20
21 'requires' => {
22 # Networking
23 'Net::SSLeay' => '1.36',
24
25 # minimum perl version
26 'perl' => '5.006',
27 },
28
29 'build_requires' => {
30 # For the t/simple.t test
31 'POE' => '1.267',
32 'POE::Component::Client::TCP' => 0,
33 'POE::Component::Server::TCP' => 0,
34 },
35
36 # include the standard stuff in META.yml
37 'meta_merge' => {
38 'resources' => {
39 'license' => 'http://dev.perl.org/licenses/',
40 'homepage' => 'http://search.cpan.org/dist/POE-Component-SSLify',
41 'bugtracker' => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-SSLify',
42 'repository' => 'http://github.com/apocalypse/perl-poe-sslify',
43 },
44 },
45 );
46
47 # all done!
48 $build->create_build_script;
00 Revision history for Perl extension POE::Component::SSLify.
11
2 * 0.20
2 {{$NEXT}}
3
4 Converted to Dist::Zilla for the release process!
5 Add a test for in-situ sslification, thanks mordy@irc!
6 Add prereq for IO::Handle 1.28 to get sane $socket->blocking( 0 ) behavior on MSWin32
7 Remove crufty old code for nonblocking and use $socket->blocking() instead
8
9 0.20
310
411 Split up the simple.t test into 2 tests for clarity, and added more diag messages for renegotiate, thanks HMBRAND!
512
6 * 0.19
13 0.19
714
815 Fixed a warning generated by POE::Component::Client::TCP in t/simple.t, thanks HMBRAND!
916
10 * 0.18
17 0.18
1118
1219 Bumped POE dep to at least 1.267 for t/simple.t - thanks CPANTesters!
1320 Minor typo fixes in POD/Build.PL
1421
15 * 0.17
22 0.17
1623
1724 Fixed the t/simple.t test to PASS on FreeBSD because Net::SSLeay::renegotiate was buggy on it, thanks CPANTesters!
1825 Added note about OpenSSL functions in the POD.
1926
20 * 0.16
27 0.16
2128
2229 Updated the nonblocking code to be production-ready, thanks ASCENT!
2330 Removed the NONBLOCKING() sub, this module is now always nonblocking.
2633 Misc kwalitee and POD fixes.
2734 Bumped Net::SSLeay prereq to 1.36 so we have the latest SSL stuff to ensure sanity :)
2835
29 * 0.15
36 0.15
3037
3138 Added "examples/serverclient.pl" to track down same-process sslification problems, thanks LotR!
3239
3643
3744 Added experimental NONBLOCKING code, thanks ASCENT for the motivation!
3845
39 * 0.14
46 0.14
4047
4148 removed Test::* modules from dependency list, thanks BINGOS - RT #36725
4249
4451
4552 added Build.PL
4653
47 * 0.13
54 0.13
4855
4956 POD typo errors in SSLify_ContextCreate - thanks ASCENT!
5057
51 * 0.12
58 0.12
5259
5360 Kwalitee-related fixes
5461
55 * 0.11
62 0.11
5663
5764 allowed setting of client-side context ( $ctx ) object - thanks RT #34442
5865
6471
6572 backported Net::SSLeay's removal of %Filenum_Objects hash
6673
67 * 0.10
74 0.10
6875
6976 More tweaks of POD - finally close RT #31238
7077 Added SSL version support - thanks RT #31492
7178 Added SSL CTX option support as a side effect
7279 Added client.pl example with ReadLine support
7380
74 * 0.09
81 0.09
7582
7683 Minor tweak of POD to enable better distro building - thanks RT #31238
7784
78 * 0.08
85 0.08
7986
8087 Added support for BINMODE - thanks RT #27117
8188
82 * 0.07
89 0.07
8390
8491 Fixed undefined $info - thanks RT #22372
8592
86 * 0.06
93 0.06
8794
8895 Kwalitee-related fixes
8996
90 * 0.05
97 0.05
9198
9299 Finally use a Changes file - thanks RT #18981
93100 Documentation tweaks
94101 Upgraded Net::SSLeay requirement to 1.30 to help Win32 problems
95102
96 * 0.04
103 0.04
97104
98105 Added new functions to extract data from the SSL socket -> GetCipher and GetSocket
99106 In the case somebody knows Net::SSLeay more than me, added GetCTX to return the server-side CTX object
100107 Removed the dependency on Net::SSLeay::Handle
101108
102 * 0.03
109 0.03
103110
104111 First stab at the server-side code, help me test it out!
105112 Refactored SSLify() into client/server side, so update your program accordingly!
106113
107 * 0.02
114 0.02
108115
109116 Made sure the IO::Handle way was used only on MSWin32
110117
113120 Oops, forgot to override _get_self and _get_ssl
114121 Fixed a nasty leak issue
115122
116 * 0.01
123 0.01
117124
118125 Initial release
+0
-24
MANIFEST less more
0 Build.PL
1 MANIFEST
2 MANIFEST.SKIP
3 README
4 Makefile.PL
5 META.yml
6 Changes
7 LICENSE
8
9 lib/POE/Component/SSLify.pm
10 lib/POE/Component/SSLify/ClientHandle.pm
11 lib/POE/Component/SSLify/ServerHandle.pm
12
13 examples/client.pl
14 examples/server.pl
15 examples/serverclient.pl
16
17 mylib/example.crt
18 mylib/example.key
19
20 t/1_load.t
21 t/2_simple.t
22 t/3_renegotiate.t
23 t/apocalypse.t
+0
-30
MANIFEST.SKIP less more
0 # skip Eclipse IDE stuff
1 \.includepath$
2 \.project$
3 \.settings/
4
5 # Avoid version control files.
6 \B\.svn\b
7 \B\.git\b
8 ^\.gitignore$
9
10 # Avoid Makemaker generated and utility files.
11 \bMakefile$
12 \bblib/
13 \bMakeMaker-\d
14 \bpm_to_blib$
15
16 # Avoid Module::Build generated and utility files.
17 \bBuild$
18 \b_build/
19 ^MYMETA.yml$
20
21 # Avoid temp and backup files.
22 ~$
23 \.old$
24 \#$
25 \b\.#
26 \.bak$
27
28 # our tarballs
29 \.tar\.gz$
POE-Component-SSLify-0.01.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.02.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.03.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.04.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.05.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.06.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.07.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.08.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.09.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.10.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.11.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.12.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.13.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.14.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.15.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.16.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.17.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.18.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.19.tar.gz less more
Binary diff not shown
POE-Component-SSLify-0.20.tar.gz less more
Binary diff not shown
0 name = POE-Component-SSLify
1 [@Apocalyptic]
00 #!/usr/bin/perl
1 use strict; use warnings;
21
32 use POE;
43 use POE::Component::SSLify qw( Client_SSLify );
00 #!/usr/bin/perl
1 use strict; use warnings;
21
32 use POE;
43 use Socket qw( inet_ntoa unpack_sockaddr_in );
00 #!/usr/bin/perl
1 use strict; use warnings;
21
32 use POE;
43 use Socket qw( inet_ntoa unpack_sockaddr_in );
00 package POE::Component::SSLify::ClientHandle;
1 use strict; use warnings;
21
3 # Initialize our version
4 use vars qw( $VERSION );
5 $VERSION = '0.20';
2 # ABSTRACT: Client-side handle for SSLify
63
74 # Import the SSL death routines
85 use Net::SSLeay qw( die_now die_if_ssl_error );
4441 return $self;
4542 }
4643
47 # End of module
4844 1;
4945
50 __END__
51
52 =head1 NAME
53
54 POE::Component::SSLify::ClientHandle - client object for POE::Component::SSLify
55
56 =head1 ABSTRACT
57
58 See POE::Component::SSLify::ServerHandle
46 =pod
5947
6048 =head1 DESCRIPTION
6149
6250 This is a subclass of ServerHandle to accomodate clients setting custom context objects.
6351
6452 =head1 SEE ALSO
65
66 L<POE::Component::SSLify>
67
68 L<POE::Component::SSLify::ServerHandle>
69
70 =head1 AUTHOR
71
72 Apocalypse E<lt>apocal@cpan.orgE<gt>
73
74 =head1 COPYRIGHT AND LICENSE
75
76 Copyright 2010 by Apocalypse
77
78 This library is free software; you can redistribute it and/or modify
79 it under the same terms as Perl itself.
53 POE::Component::SSLify::ServerHandle
8054
8155 =cut
00 package POE::Component::SSLify::ServerHandle;
1 use strict; use warnings;
21
3 # Initialize our version
4 use vars qw( $VERSION );
5 $VERSION = '0.20';
2 # ABSTRACT: Server-side handle for SSLify
63
74 # Import the SSL death routines
85 use Net::SSLeay qw( die_now die_if_ssl_error );
156153 die 'Not Implemented';
157154 }
158155
159 # End of module
160156 1;
161157
162 __END__
163
164 =head1 NAME
165
166 POE::Component::SSLify::ServerHandle - server object for POE::Component::SSLify
167
168 =head1 ABSTRACT
169
170 See POE::Component::SSLify
158 =pod
171159
172160 =head1 DESCRIPTION
173161
181169
182170 This subclass doesn't know what to do with PRINT/READLINE, as they usually are not used in POE::Wheel operations...
183171
184 =head1 SEE ALSO
185
186 L<POE::Component::SSLify>
187
188 =head1 AUTHOR
189
190 Apocalypse E<lt>apocal@cpan.orgE<gt>
191
192 =head1 COPYRIGHT AND LICENSE
193
194 Copyright 2010 by Apocalypse
195
196 This library is free software; you can redistribute it and/or modify
197 it under the same terms as Perl itself.
198
199172 =cut
00 package POE::Component::SSLify;
1 use strict; use warnings;
2
3 # Initialize our version
4 use vars qw( $VERSION );
5 $VERSION = '0.20';
1
2 # ABSTRACT: Makes using SSL in the world of POE easy!
63
74 # We need Net::SSLeay or all's a failure!
85 BEGIN {
96 eval {
10 require Net::SSLeay;
11
127 # We need >= 1.36 because it contains a lot of important fixes
13 Net::SSLeay->import( 1.36 );
8 use Net::SSLeay 1.36 qw( die_now die_if_ssl_error );
149 };
1510
1611 # Check for errors...
1813 # Oh boy!
1914 die $@;
2015 } else {
21 # Finally, load our subclass :)
16 # Finally, load our subclasses :)
2217 # ClientHandle isa ServerHandle so it will get loaded automatically
2318 require POE::Component::SSLify::ClientHandle;
2419
3833
3934 # Bring in some socket-related stuff
4035 use Symbol qw( gensym );
41 use POSIX qw( F_GETFL F_SETFL O_NONBLOCK EAGAIN EWOULDBLOCK );
42
43 # We need the server-side stuff
44 use Net::SSLeay qw( die_now die_if_ssl_error );
36
37 # we need IO 1.24 for it's win32 fixes but it includes IO::Handle 1.27_02 which is dev...
38 # unfortunately we have to jump to IO 1.25 which includes IO::Handle 1.28... argh!
39 use IO::Handle 1.28;
4540
4641 # The server-side CTX stuff
4742 my $ctx = undef;
48
49 # Helper sub to set nonblocking on a handle
50 sub _NonBlocking {
51 my $socket = shift;
52
53 # ActiveState Perl 5.8.0 dislikes the Win32-specific code to make
54 # a socket blocking, so we use IO::Handle's blocking(0) method.
55 # Perl 5.005_03 doesn't like blocking(), so we only use it in
56 # 5.8.0 and beyond.
57 if ( $] >= 5.008 and $^O eq 'MSWin32' ) {
58 # TODO investigate this?
59 # <kmx> kthakore: Apocalypse: FYI - as regards no-blocking socket dark magic commited to FB while ago - IO::Socket 1.24 (=May/2009) and later supports on Win32 simply $socket->blocking(0);
60 # <Apocalypse> kmx: Ah didn't know that - maybe I can use that :)
61 # <kmx> Apocalypse: I uderstand that used workaround is from pre IO::Socket 1.24 times
62 # <Apocalypse> Ah, my code already did that eh
63 # <Apocalypse> if ( $] >= 5.008 and $^O eq 'MSWin32' ) {
64 # <Apocalypse> But maybe 5.008 check isn't enough?
65 # <kmx> Apocalypse: You'd better check version of IO - see changelog http://cpansearch.perl.org/src/GBARR/IO-1.25/ChangeLog
66 # <Apocalypse> Hmm yeah
67 # <Apocalypse> * Make non-blocking mode work on Windows in IO::Socket::INET
68 # <kmx> Apocalypse: exactly
69 # <Apocalypse> Thanks for the tip! I'll go and add a TODO to the sslify code to investigate that :)
70
71
72 # From IO::Handle POD
73 # If an error occurs blocking will return undef and $! will be set.
74 if ( ! $socket->blocking( 0 ) ) {
75 die "Unable to set nonblocking mode on socket: $!";
76 }
77 } else {
78 # Make the handle nonblocking, the POSIX way.
79 if ( $^O ne 'MSWin32' ) {
80 # Get the old flags
81 my $flags = fcntl( $socket, F_GETFL, 0 ) or die "fcntl( $socket, F_GETFL, 0 ) fails: $!";
82
83 # Okay, we patiently wait until the socket turns nonblocking mode
84 until( fcntl( $socket, F_SETFL, $flags | O_NONBLOCK ) ) {
85 # What was the error?
86 if ( ! ( $! == EAGAIN or $! == EWOULDBLOCK ) ) {
87 # Fatal error...
88 die "fcntl( $socket, FSETFL, etc ) fails: $!";
89 }
90 }
91 } else {
92 # Darned MSWin32 way...
93 # Do some ioctl magic here
94 # 126 is FIONBIO ( some docs say 0x7F << 16 )
95 my $flag = "1";
96 ioctl( $socket, 0x80000000 | ( 4 << 16 ) | ( ord( 'f' ) << 8 ) | 126, $flag ) or die "ioctl( $socket, FIONBIO, $flag ) fails: $!";
97 }
98 }
99
100 # All done!
101 return $socket;
102 }
10343
10444 # Okay, the main routine here!
10545 sub Client_SSLify {
11151 die "Did not get a defined socket";
11252 }
11353
114 # Set non-blocking
115 $socket = _NonBlocking( $socket );
54 # From IO::Handle POD
55 # If an error occurs blocking will return undef and $! will be set.
56 if ( ! defined $socket->blocking( 0 ) ) {
57 die "Unable to set nonblocking mode on socket: $!";
58 }
11659
11760 # Now, we create the new socket and bind it to our subclass of Net::SSLeay::Handle
11861 my $newsock = gensym();
13881 die 'Please do SSLify_Options() first ( or pass in a $ctx object )';
13982 }
14083
141 # Set non-blocking
142 $socket = _NonBlocking( $socket );
84 # From IO::Handle POD
85 # If an error occurs blocking will return undef and $! will be set.
86 if ( ! defined $socket->blocking( 0 ) ) {
87 die "Unable to set nonblocking mode on socket: $!";
88 }
14389
14490 # Now, we create the new socket and bind it to our subclass of Net::SSLeay::Handle
14591 my $newsock = gensym();
249195 return tied( *$sock )->{'socket'};
250196 }
251197
252 # End of module
253198 1;
254 __END__
255
256 =for stopwords AnnoCPAN CPAN CPANTS Kwalitee RT SSL com diff github FreeBSD OpenSSL
257
258 =head1 NAME
259
260 POE::Component::SSLify - Makes using SSL in the world of POE easy!
199
200 =pod
261201
262202 =head1 SYNOPSIS
263203
290230
291231 # SERVER-side usage
292232
293 # !!! Make sure you have a public key + certificate generated via Net::SSLeay's makecert.pl
233 # !!! Make sure you have a public key + certificate
294234 # excellent howto: http://www.akadia.com/services/ssh_test_certificate.html
295235
296236 # Import the module
322262 # Use it as you wish...
323263 # End of example
324264
325 =head1 ABSTRACT
326
327 Makes SSL use in POE a breeze!
328
329265 =head1 DESCRIPTION
330266
331267 This component represents the standard way to do SSL in POE.
365301
366302 =head3 Net::SSLeay::renegotiate
367303
368 This function has been tested ( it's in t/3_renegotiate.t ) but it doesn't work on FreeBSD! I tracked it down to this security advisory:
304 This function has been tested ( it's in C<t/2_renegotiate.t> ) but it doesn't work on FreeBSD! I tracked it down to this security advisory:
369305 L<http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc> which explains it in detail. The test will skip this function
370306 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.
307
308 =head3 In-Situ sslification
309
310 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
311 at the same time, or they will be waiting on each other forever! See C<t/3_insitu.t> for an example of how this works.
371312
372313 =head1 FUNCTIONS
373314
495436
496437 Stuffs all of the above functions in @EXPORT_OK so you have to request them directly
497438
498 =head1 SUPPORT
499
500 You can find documentation for this module with the perldoc command.
501
502 perldoc POE::Component::SSLify
503
504 =head2 Websites
505
506 =over 4
507
508 =item * Search CPAN
509
510 L<http://search.cpan.org/dist/POE-Component-SSLify>
511
512 =item * AnnoCPAN: Annotated CPAN documentation
513
514 L<http://annocpan.org/dist/POE-Component-SSLify>
515
516 =item * CPAN Ratings
517
518 L<http://cpanratings.perl.org/d/POE-Component-SSLify>
519
520 =item * CPAN Forum
521
522 L<http://cpanforum.com/dist/POE-Component-SSLify>
523
524 =item * RT: CPAN's Request Tracker
525
526 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-SSLify>
527
528 =item * CPANTS Kwalitee
529
530 L<http://cpants.perl.org/dist/overview/POE-Component-SSLify>
531
532 =item * CPAN Testers Results
533
534 L<http://cpantesters.org/distro/P/POE-Component-SSLify.html>
535
536 =item * CPAN Testers Matrix
537
538 L<http://matrix.cpantesters.org/?dist=POE-Component-SSLify>
539
540 =item * Git Source Code Repository
541
542 This code is currently hosted on github.com under the account "apocalypse". Please feel free to browse it
543 and pull from it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
544 from your repository :)
545
546 L<http://github.com/apocalypse/perl-poe-sslify>
547
548 =back
549
550 =head2 Bugs
551
552 Please report any bugs or feature requests to C<bug-poe-component-sslify at rt.cpan.org>, or through
553 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-SSLify>. I will be
554 notified, and then you'll automatically be notified of progress on your bug as I make changes.
555
556439 =head1 SEE ALSO
557
558 L<POE>
559
560 L<Net::SSLeay>
561
562 =head1 AUTHOR
563
564 Apocalypse E<lt>apocal@cpan.orgE<gt>
440 POE
441 Net::SSLeay
442
443 =head1 ACKNOWLEDGEMENTS
565444
566445 Original code is entirely Rocco Caputo ( Creator of POE ) -> I simply
567446 packaged up the code into something everyone could use and accepted the burden
575454 ASCENT also helped a lot with the nonblocking mode, without his hard work this
576455 module would still be stuck in the stone age :)
577456
578 =head1 COPYRIGHT AND LICENSE
579
580 Copyright 2010 by Apocalypse/Rocco Caputo/Dariusz Jackowski
581
582 This library is free software; you can redistribute it and/or modify
583 it under the same terms as Perl itself.
584
585 The full text of the license can be found in the LICENSE file included with this module.
586
587457 =cut
+0
-20
t/1_load.t less more
0 #!/usr/bin/perl
1 use strict; use warnings;
2
3 my $numtests;
4 BEGIN {
5 $numtests = 3;
6
7 eval "use Test::NoWarnings";
8 if ( ! $@ ) {
9 # increment by one
10 $numtests++;
11
12 }
13 }
14
15 use Test::More tests => $numtests;
16
17 use_ok( 'POE::Component::SSLify::ServerHandle' );
18 use_ok( 'POE::Component::SSLify::ClientHandle' );
19 use_ok( 'POE::Component::SSLify' );
0 #!/usr/bin/perl
1
2 # Thanks to ASCENT for this test!
3
4 use strict; use warnings;
5
6 my $numtests;
7 BEGIN {
8 $numtests = 16;
9
10 eval "use Test::NoWarnings";
11 if ( ! $@ ) {
12 # increment by one
13 $numtests++;
14
15 }
16 }
17
18 use Test::More tests => $numtests;
19
20 use POE 1.267;
21 use POE::Component::Client::TCP;
22 use POE::Component::Server::TCP;
23 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate SSLify_GetSocket/;
24
25 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
26
27 my $port;
28
29 POE::Component::Server::TCP->new
30 (
31 Alias => 'myserver',
32 Address => '127.0.0.1',
33 Port => 0,
34
35 Started => sub
36 {
37 use Socket qw/sockaddr_in/;
38 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
39 },
40 ClientConnected => sub
41 {
42 ok(1, 'SERVER: accepted');
43 },
44 ClientDisconnected => sub
45 {
46 ok(1, 'SERVER: client disconnected');
47 $_[KERNEL]->post(myserver => 'shutdown');
48 },
49 ClientPreConnect => sub
50 {
51 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
52 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
53 ok(!$@, "SERVER: SSLify_Options $@");
54
55 my $socket = eval { Server_SSLify($_[ARG0]) };
56 ok(!$@, "SERVER: Server_SSLify $@");
57 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
58
59 # We pray that IO::Handle is sane...
60 ok( SSLify_GetSocket( $socket )->blocking == 0, 'SERVER: SSLified socket is non-blocking?');
61
62 return ($socket);
63 },
64 ClientInput => sub
65 {
66 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
67
68 if ( $line eq 'ping' ) {
69 ok(1, "SERVER: recv: $line");
70
71 ## At this point, connection MUST be encrypted.
72 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
73 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
74
75 $heap->{client}->put("pong");
76 } else {
77 die "Unknown line from CLIENT: $line";
78 }
79 },
80 ClientError => sub
81 {
82 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
83 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
84 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
85
86 # TODO are there other "errors" that is harmless?
87 $error = "Normal disconnection" unless $error;
88 my $msg = "Got SERVER $syscall error $errno: $error";
89 unless ( $syscall eq 'read' and $errno == 0 ) {
90 fail( $msg );
91 } else {
92 diag( $msg ) if $ENV{TEST_VERBOSE};
93 }
94 },
95 );
96
97 POE::Component::Client::TCP->new
98 (
99 Alias => 'myclient',
100 RemoteAddress => '127.0.0.1',
101 RemotePort => $port,
102 Connected => sub
103 {
104 ok(1, 'CLIENT: connected');
105
106 $_[HEAP]->{server}->put("ping");
107 },
108 PreConnect => sub
109 {
110 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
111 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
112 my $socket = eval { Client_SSLify($_[ARG0], undef, undef, $ctx) };
113 ok(!$@, "CLIENT: Client_SSLify $@");
114 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
115
116 # We pray that IO::Handle is sane...
117 ok( SSLify_GetSocket( $socket )->blocking == 0, 'CLIENT: SSLified socket is non-blocking?');
118
119 return ($socket);
120 },
121 ServerInput => sub
122 {
123 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
124
125 if ($line eq 'pong') {
126 ok(1, "CLIENT: recv: $line");
127
128 ## At this point, connection MUST be encrypted.
129 my $cipher = SSLify_GetCipher($heap->{server}->get_output_handle);
130 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
131
132 $kernel->yield('shutdown');
133 } else {
134 die "Unknown line from SERVER: $line";
135 }
136 },
137 ServerError => sub
138 {
139 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
140 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
141 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
142
143 # TODO are there other "errors" that is harmless?
144 $error = "Normal disconnection" unless $error;
145 my $msg = "Got CLIENT $syscall error $errno: $error";
146 unless ( $syscall eq 'read' and $errno == 0 ) {
147 fail( $msg );
148 } else {
149 diag( $msg ) if $ENV{TEST_VERBOSE};
150 }
151 },
152 );
153
154 $poe_kernel->run();
155
156 pass( 'shut down sanely' );
157
158 exit 0;
0 #!/usr/bin/perl
1
2 # Thanks to ASCENT for this test!
3
4 # This test adds renegotiation to the connection
5 # Since this is not supported on all platforms, it's marked TODO and adds custom logic
6 # to make sure it doesn't FAIL if it's not supported.
7
8 use strict; use warnings;
9
10 my $numtests;
11 BEGIN {
12 $numtests = 23;
13
14 eval "use Test::NoWarnings";
15 if ( ! $@ ) {
16 # increment by one
17 $numtests++;
18
19 }
20 }
21
22 use Test::More tests => $numtests;
23
24 use POE 1.267;
25 use POE::Component::Client::TCP;
26 use POE::Component::Server::TCP;
27 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate SSLify_GetSocket/;
28 use Net::SSLeay qw/ERROR_WANT_READ ERROR_WANT_WRITE/;
29
30 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
31
32 my $port;
33 my $server_ping2;
34 my $client_ping2;
35
36 POE::Component::Server::TCP->new
37 (
38 Alias => 'myserver',
39 Address => '127.0.0.1',
40 Port => 0,
41
42 Started => sub
43 {
44 use Socket qw/sockaddr_in/;
45 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
46 },
47 ClientConnected => sub
48 {
49 ok(1, 'SERVER: accepted');
50 },
51 ClientDisconnected => sub
52 {
53 ok(1, 'SERVER: client disconnected');
54 $_[KERNEL]->post(myserver => 'shutdown');
55 },
56 ClientPreConnect => sub
57 {
58 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
59 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
60 ok(!$@, "SERVER: SSLify_Options $@");
61
62 my $socket = eval { Server_SSLify($_[ARG0]) };
63 ok(!$@, "SERVER: Server_SSLify $@");
64 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
65
66 # We pray that IO::Handle is sane...
67 ok( SSLify_GetSocket( $socket )->blocking == 0, 'SERVER: SSLified socket is non-blocking?');
68
69 return ($socket);
70 },
71 ClientInput => sub
72 {
73 my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0];
74
75 ## At this point, connection MUST be encrypted.
76 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
77 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
78
79 if ($request eq 'ping')
80 {
81 ok(1, "SERVER: recv: $request");
82 $heap->{client}->put("pong");
83 }
84 elsif ($request eq 'ping2')
85 {
86 ok(1, "SERVER: recv: $request");
87 $server_ping2++;
88 $heap->{client}->put("pong2");
89 }
90 },
91 ClientError => sub
92 {
93 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
94 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
95 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
96
97 # TODO are there other "errors" that is harmless?
98 $error = "Normal disconnection" unless $error;
99 my $msg = "Got SERVER $syscall error $errno: $error";
100 unless ( $syscall eq 'read' and $errno == 0 ) {
101 fail( $msg );
102 } else {
103 diag( $msg ) if $ENV{TEST_VERBOSE};
104 }
105 },
106 );
107
108 POE::Component::Client::TCP->new
109 (
110 Alias => 'myclient',
111 RemoteAddress => '127.0.0.1',
112 RemotePort => $port,
113 Connected => sub
114 {
115 ok(1, 'CLIENT: connected');
116
117 $_[HEAP]->{server}->put("ping");
118 },
119 PreConnect => sub
120 {
121 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
122 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
123 my $socket = eval { Client_SSLify($_[ARG0], undef, undef, $ctx) };
124 ok(!$@, "CLIENT: Client_SSLify $@");
125 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
126
127 # We pray that IO::Handle is sane...
128 ok( SSLify_GetSocket( $socket )->blocking == 0, 'CLIENT: SSLified socket is non-blocking?');
129
130 return ($socket);
131 },
132 ServerInput => sub
133 {
134 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
135
136 ## At this point, connection MUST be encrypted.
137 my $cipher = SSLify_GetCipher($heap->{server}->get_output_handle);
138 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
139
140 if ($line eq 'pong')
141 {
142 ok(1, "CLIENT: recv: $line");
143
144 # Skip 2 Net::SSLeay::renegotiate() tests on FreeBSD because of
145 # http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc
146 TODO: {
147 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
148
149 ## Force SSL renegotiation
150 my $ssl = tied(*{$heap->{server}->get_output_handle})->{ssl};
151 my $reneg_num = Net::SSLeay::num_renegotiations($ssl);
152
153 ok(1 == Net::SSLeay::renegotiate($ssl), 'CLIENT: SSL renegotiation');
154 my $handshake = Net::SSLeay::do_handshake($ssl);
155 my $err = Net::SSLeay::get_error($ssl, $handshake);
156
157 ## 1 == Successful handshake, ERROR_WANT_(READ|WRITE) == non-blocking.
158 ok($handshake == 1 || $err == ERROR_WANT_READ || $err == ERROR_WANT_WRITE, 'CLIENT: SSL handshake');
159 ok($reneg_num < Net::SSLeay::num_renegotiations($ssl), 'CLIENT: Increased number of negotiations');
160 }
161
162 $heap->{server}->put('ping2');
163 }
164
165 elsif ($line eq 'pong2')
166 {
167 ok(1, "CLIENT: recv: $line");
168 $client_ping2++;
169 $kernel->yield('shutdown');
170 }
171 },
172 ServerError => sub
173 {
174 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
175 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
176 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
177
178 # TODO are there other "errors" that is harmless?
179 $error = "Normal disconnection" unless $error;
180 my $msg = "Got CLIENT $syscall error $errno: $error";
181 unless ( $syscall eq 'read' and $errno == 0 ) {
182 fail( $msg );
183 } else {
184 diag( $msg ) if $ENV{TEST_VERBOSE};
185 }
186 },
187 );
188
189 $poe_kernel->run();
190
191 # Add extra pass() to make the test harness happy if renegotiate did not work
192 if ( ! $server_ping2 ) {
193 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
194 fail( "SERVER: Failed SSL renegotiation" );
195 }
196 if ( ! $client_ping2 ) {
197 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
198 fail( "CLIENT: Failed SSL renegotiation" );
199 }
200 if ( ! $server_ping2 or ! $client_ping2 ) {
201 diag( "WARNING: Your platform/SSL library does not support renegotiation of the SSL socket." );
202 diag( "This test harness detected that trying to renegotiate resulted in a disconnected socket." );
203 diag( "POE::Component::SSLify will work on your system, but please do not attempt a SSL renegotiate." );
204 diag( "Please talk with the author to figure out if this issue can be worked around, thank you!" );
205 }
206
207 pass( 'shut down sanely' );
208
209 exit 0;
+0
-168
t/2_simple.t less more
0 #!/usr/bin/perl
1
2 # Thanks to ASCENT for this test!
3
4 use strict; use warnings;
5
6 my $numtests;
7 BEGIN {
8 $numtests = 16;
9
10 eval "use Test::NoWarnings";
11 if ( ! $@ ) {
12 # increment by one
13 $numtests++;
14
15 }
16 }
17
18 use Test::More tests => $numtests;
19
20 use POE;
21 use POE::Component::Client::TCP;
22 use POE::Component::Server::TCP;
23 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate/;
24 use POSIX qw/F_GETFL O_NONBLOCK/;
25
26 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
27
28 my $port;
29
30 POE::Component::Server::TCP->new
31 (
32 Alias => 'myserver',
33 Address => '127.0.0.1',
34 Port => 0,
35
36 Started => sub
37 {
38 use Socket qw/sockaddr_in/;
39 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
40 },
41 ClientConnected => sub
42 {
43 ok(1, 'SERVER: accepted');
44 },
45 ClientDisconnected => sub
46 {
47 ok(1, 'SERVER: client disconnected');
48 $_[KERNEL]->post(myserver => 'shutdown');
49 },
50 ClientPreConnect => sub
51 {
52 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
53 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
54 ok(!$@, "SERVER: SSLify_Options $@");
55
56 my $socket = eval { Server_SSLify($_[ARG0]) };
57 ok(!$@, "SERVER: Server_SSLify $@");
58 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
59
60 # MSWin32 doesn't have F_GETFL and friends
61 if ( $^O eq 'MSWin32' ) {
62 # We pray that IO::Handle is sane...
63 ok( ! $_[ARG0]->blocking, 'SERVER: SSLified socket is non-blocking?');
64 } else {
65 my $flags = fcntl($_[ARG0], F_GETFL, 0);
66 ok($flags & O_NONBLOCK, 'SERVER: SSLified socket is non-blocking?');
67 }
68
69 return ($socket);
70 },
71 ClientInput => sub
72 {
73 my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0];
74
75 ## At this point, connection MUST be encrypted.
76 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
77 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
78
79 if ($request eq 'ping')
80 {
81 ok(1, "SERVER: recv: $request");
82 $heap->{client}->put("pong");
83 }
84 },
85 ClientError => sub
86 {
87 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
88 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
89 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
90
91 # TODO are there other "errors" that is harmless?
92 $error = "Normal disconnection" unless $error;
93 my $msg = "Got SERVER $syscall error $errno: $error";
94 unless ( $syscall eq 'read' and $errno == 0 ) {
95 fail( $msg );
96 } else {
97 diag( $msg ) if $ENV{TEST_VERBOSE};
98 }
99 },
100 );
101
102 POE::Component::Client::TCP->new
103 (
104 Alias => 'myclient',
105 RemoteAddress => '127.0.0.1',
106 RemotePort => $port,
107 Connected => sub
108 {
109 ok(1, 'CLIENT: connected');
110
111 $_[HEAP]->{server}->put("ping");
112 },
113 PreConnect => sub
114 {
115 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
116 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
117 my $socket = eval { Client_SSLify($_[ARG0], undef, undef, $ctx) };
118 ok(!$@, "CLIENT: Client_SSLify $@");
119 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
120
121 # MSWin32 doesn't have F_GETFL and friends
122 if ( $^O eq 'MSWin32' ) {
123 # We pray that IO::Handle is sane...
124 ok( ! $_[ARG0]->blocking, 'CLIENT: SSLified socket is non-blocking?');
125 } else {
126 my $flags = fcntl($_[ARG0], F_GETFL, 0);
127 ok($flags & O_NONBLOCK, 'CLIENT: SSLified socket is non-blocking?');
128 }
129
130 return ($socket);
131 },
132 ServerInput => sub
133 {
134 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
135
136 ## At this point, connection MUST be encrypted.
137 my $cipher = SSLify_GetCipher($heap->{server}->get_output_handle);
138 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
139
140 if ($line eq 'pong')
141 {
142 ok(1, "CLIENT: recv: $line");
143 $kernel->yield('shutdown');
144 }
145 },
146 ServerError => sub
147 {
148 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
149 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
150 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
151
152 # TODO are there other "errors" that is harmless?
153 $error = "Normal disconnection" unless $error;
154 my $msg = "Got CLIENT $syscall error $errno: $error";
155 unless ( $syscall eq 'read' and $errno == 0 ) {
156 fail( $msg );
157 } else {
158 diag( $msg ) if $ENV{TEST_VERBOSE};
159 }
160 },
161 );
162
163 $poe_kernel->run();
164
165 pass( 'shut down sanely' );
166
167 exit 0;
0 #!/usr/bin/perl
1
2 # Thanks to ASCENT for this test!
3
4 use strict; use warnings;
5
6 my $numtests;
7 BEGIN {
8 $numtests = 18;
9
10 eval "use Test::NoWarnings";
11 if ( ! $@ ) {
12 # increment by one
13 $numtests++;
14
15 }
16 }
17
18 use Test::More tests => $numtests;
19
20 use POE 1.267;
21 use POE::Component::Client::TCP;
22 use POE::Component::Server::TCP;
23 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate SSLify_GetSocket/;
24
25 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
26
27 my $port;
28
29 POE::Component::Server::TCP->new
30 (
31 Alias => 'myserver',
32 Address => '127.0.0.1',
33 Port => 0,
34
35 Started => sub
36 {
37 use Socket qw/sockaddr_in/;
38 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
39 },
40 ClientConnected => sub
41 {
42 ok(1, 'SERVER: accepted');
43 },
44 ClientDisconnected => sub
45 {
46 ok(1, 'SERVER: client disconnected');
47 $_[KERNEL]->post(myserver => 'shutdown');
48 },
49 ClientInput => sub
50 {
51 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
52
53 if ( $line eq 'plaintext_ping' ) {
54 ok(1, "SERVER: recv: $line");
55 $heap->{client}->put('plaintext_pong');
56 $heap->{client}->flush; # make sure we sent the pong
57
58 # sslify it in-situ!
59 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
60 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
61 ok(!$@, "SERVER: SSLify_Options $@");
62 my $socket = eval { Server_SSLify($heap->{client}->get_output_handle) };
63 ok(!$@, "SERVER: Server_SSLify $@");
64 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
65
66 # We pray that IO::Handle is sane...
67 ok( SSLify_GetSocket( $socket )->blocking == 0, 'SERVER: SSLified socket is non-blocking?');
68
69 # TODO evil code here, ha!
70 # Should I ask rcaputo to add a $rw->replace_handle($socket) method?
71 # if you don't do the undef and just replace it - you'll get a bad file descriptor error from POE!
72 # <fh> select error: Bad file descriptor (hits=-1)
73 undef $heap->{client};
74 $heap->{client} = POE::Wheel::ReadWrite->new(
75 Handle => $socket,
76 InputEvent => 'tcp_server_got_input',
77 ErrorEvent => 'tcp_server_got_error',
78 FlushedEvent => 'tcp_server_got_flush',
79 );
80 } elsif ( $line eq 'ssl_ping' ) {
81 ok(1, "SERVER: recv: $line");
82
83 ## At this point, connection MUST be encrypted.
84 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
85 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
86
87 $heap->{client}->put('ssl_pong');
88 } else {
89 die "Unknown line from CLIENT: $line";
90 }
91 },
92 ClientError => sub
93 {
94 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
95 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
96 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
97
98 # TODO are there other "errors" that is harmless?
99 $error = "Normal disconnection" unless $error;
100 my $msg = "Got SERVER $syscall error $errno: $error";
101 unless ( $syscall eq 'read' and $errno == 0 ) {
102 fail( $msg );
103 } else {
104 diag( $msg ) if $ENV{TEST_VERBOSE};
105 }
106 },
107 );
108
109 POE::Component::Client::TCP->new
110 (
111 Alias => 'myclient',
112 RemoteAddress => '127.0.0.1',
113 RemotePort => $port,
114 Connected => sub
115 {
116 ok(1, 'CLIENT: connected');
117
118 $_[HEAP]->{server}->put("plaintext_ping");
119 },
120 ServerInput => sub
121 {
122 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
123
124 if ( $line eq 'plaintext_pong' ) {
125 ok(1, "CLIENT: recv: $line");
126
127 # sslify it in-situ!
128 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
129 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
130 my $socket = eval { Client_SSLify($heap->{server}->get_output_handle, undef, undef, $ctx) };
131 ok(!$@, "CLIENT: Client_SSLify $@");
132 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
133
134 # We pray that IO::Handle is sane...
135 ok( SSLify_GetSocket( $socket )->blocking == 0, 'CLIENT: SSLified socket is non-blocking?');
136
137 # TODO evil code here, ha!
138 # Should I ask rcaputo to add a $rw->replace_handle($socket) method?
139 # if you don't do the undef and just replace it - you'll get a bad file descriptor error from POE!
140 # <fh> select error: Bad file descriptor (hits=-1)
141 undef $heap->{server};
142 $heap->{server} = POE::Wheel::ReadWrite->new(
143 Handle => $socket,
144 InputEvent => 'got_server_input',
145 ErrorEvent => 'got_server_error',
146 FlushedEvent => 'got_server_flush',
147 );
148
149 # Send the ssl ping!
150 $heap->{server}->put('ssl_ping');
151 } elsif ( $line eq 'ssl_pong' ) {
152 ok(1, "CLIENT: recv: $line");
153
154 ## At this point, connection MUST be encrypted.
155 my $cipher = SSLify_GetCipher($heap->{server}->get_output_handle);
156 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
157
158 $kernel->yield('shutdown');
159 } else {
160 die "Unknown line from SERVER: $line";
161 }
162 },
163 ServerError => sub
164 {
165 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
166 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
167 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
168
169 # TODO are there other "errors" that is harmless?
170 $error = "Normal disconnection" unless $error;
171 my $msg = "Got CLIENT $syscall error $errno: $error";
172 unless ( $syscall eq 'read' and $errno == 0 ) {
173 fail( $msg );
174 } else {
175 diag( $msg ) if $ENV{TEST_VERBOSE};
176 }
177 },
178 );
179
180 $poe_kernel->run();
181
182 pass( 'shut down sanely' );
183
184 exit 0;
+0
-223
t/3_renegotiate.t less more
0 #!/usr/bin/perl
1
2 # Thanks to ASCENT for this test!
3
4 # This test adds renegotiation to the connection
5 # Since this is not supported on all platforms, it's marked TODO and adds custom logic
6 # to make sure it doesn't FAIL if it's not supported.
7
8 use strict; use warnings;
9
10 my $numtests;
11 BEGIN {
12 $numtests = 23;
13
14 eval "use Test::NoWarnings";
15 if ( ! $@ ) {
16 # increment by one
17 $numtests++;
18
19 }
20 }
21
22 use Test::More tests => $numtests;
23
24 use POE;
25 use POE::Component::Client::TCP;
26 use POE::Component::Server::TCP;
27 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate/;
28 use Net::SSLeay qw/ERROR_WANT_READ ERROR_WANT_WRITE/;
29 use POSIX qw/F_GETFL O_NONBLOCK/;
30
31 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
32
33 my $port;
34 my $server_ping2;
35 my $client_ping2;
36
37 POE::Component::Server::TCP->new
38 (
39 Alias => 'myserver',
40 Address => '127.0.0.1',
41 Port => 0,
42
43 Started => sub
44 {
45 use Socket qw/sockaddr_in/;
46 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
47 },
48 ClientConnected => sub
49 {
50 ok(1, 'SERVER: accepted');
51 },
52 ClientDisconnected => sub
53 {
54 ok(1, 'SERVER: client disconnected');
55 $_[KERNEL]->post(myserver => 'shutdown');
56 },
57 ClientPreConnect => sub
58 {
59 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
60 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
61 ok(!$@, "SERVER: SSLify_Options $@");
62
63 my $socket = eval { Server_SSLify($_[ARG0]) };
64 ok(!$@, "SERVER: Server_SSLify $@");
65 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
66
67 # MSWin32 doesn't have F_GETFL and friends
68 if ( $^O eq 'MSWin32' ) {
69 # We pray that IO::Handle is sane...
70 ok( ! $_[ARG0]->blocking, 'SERVER: SSLified socket is non-blocking?');
71 } else {
72 my $flags = fcntl($_[ARG0], F_GETFL, 0);
73 ok($flags & O_NONBLOCK, 'SERVER: SSLified socket is non-blocking?');
74 }
75
76 return ($socket);
77 },
78 ClientInput => sub
79 {
80 my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0];
81
82 ## At this point, connection MUST be encrypted.
83 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
84 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
85
86 if ($request eq 'ping')
87 {
88 ok(1, "SERVER: recv: $request");
89 $heap->{client}->put("pong");
90 }
91 elsif ($request eq 'ping2')
92 {
93 ok(1, "SERVER: recv: $request");
94 $server_ping2++;
95 $heap->{client}->put("pong2");
96 }
97 },
98 ClientError => sub
99 {
100 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
101 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
102 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
103
104 # TODO are there other "errors" that is harmless?
105 $error = "Normal disconnection" unless $error;
106 my $msg = "Got SERVER $syscall error $errno: $error";
107 unless ( $syscall eq 'read' and $errno == 0 ) {
108 fail( $msg );
109 } else {
110 diag( $msg ) if $ENV{TEST_VERBOSE};
111 }
112 },
113 );
114
115 POE::Component::Client::TCP->new
116 (
117 Alias => 'myclient',
118 RemoteAddress => '127.0.0.1',
119 RemotePort => $port,
120 Connected => sub
121 {
122 ok(1, 'CLIENT: connected');
123
124 $_[HEAP]->{server}->put("ping");
125 },
126 PreConnect => sub
127 {
128 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
129 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
130 my $socket = eval { Client_SSLify($_[ARG0], undef, undef, $ctx) };
131 ok(!$@, "CLIENT: Client_SSLify $@");
132 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
133
134 # MSWin32 doesn't have F_GETFL and friends
135 if ( $^O eq 'MSWin32' ) {
136 # We pray that IO::Handle is sane...
137 ok( ! $_[ARG0]->blocking, 'CLIENT: SSLified socket is non-blocking?');
138 } else {
139 my $flags = fcntl($_[ARG0], F_GETFL, 0);
140 ok($flags & O_NONBLOCK, 'CLIENT: SSLified socket is non-blocking?');
141 }
142
143 return ($socket);
144 },
145 ServerInput => sub
146 {
147 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
148
149 ## At this point, connection MUST be encrypted.
150 my $cipher = SSLify_GetCipher($heap->{server}->get_output_handle);
151 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
152
153 if ($line eq 'pong')
154 {
155 ok(1, "CLIENT: recv: $line");
156
157 # Skip 2 Net::SSLeay::renegotiate() tests on FreeBSD because of
158 # http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc
159 TODO: {
160 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
161
162 ## Force SSL renegotiation
163 my $ssl = tied(*{$heap->{server}->get_output_handle})->{ssl};
164 my $reneg_num = Net::SSLeay::num_renegotiations($ssl);
165
166 ok(1 == Net::SSLeay::renegotiate($ssl), 'CLIENT: SSL renegotiation');
167 my $handshake = Net::SSLeay::do_handshake($ssl);
168 my $err = Net::SSLeay::get_error($ssl, $handshake);
169
170 ## 1 == Successful handshake, ERROR_WANT_(READ|WRITE) == non-blocking.
171 ok($handshake == 1 || $err == ERROR_WANT_READ || $err == ERROR_WANT_WRITE, 'CLIENT: SSL handshake');
172 ok($reneg_num < Net::SSLeay::num_renegotiations($ssl), 'CLIENT: Increased number of negotiations');
173 }
174
175 $heap->{server}->put('ping2');
176 }
177
178 elsif ($line eq 'pong2')
179 {
180 ok(1, "CLIENT: recv: $line");
181 $client_ping2++;
182 $kernel->yield('shutdown');
183 }
184 },
185 ServerError => sub
186 {
187 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
188 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
189 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
190
191 # TODO are there other "errors" that is harmless?
192 $error = "Normal disconnection" unless $error;
193 my $msg = "Got CLIENT $syscall error $errno: $error";
194 unless ( $syscall eq 'read' and $errno == 0 ) {
195 fail( $msg );
196 } else {
197 diag( $msg ) if $ENV{TEST_VERBOSE};
198 }
199 },
200 );
201
202 $poe_kernel->run();
203
204 # Add extra pass() to make the test harness happy if renegotiate did not work
205 if ( ! $server_ping2 ) {
206 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
207 fail( "SERVER: Failed SSL renegotiation" );
208 }
209 if ( ! $client_ping2 ) {
210 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
211 fail( "CLIENT: Failed SSL renegotiation" );
212 }
213 if ( ! $server_ping2 or ! $client_ping2 ) {
214 diag( "WARNING: Your platform/SSL library does not support renegotiation of the SSL socket." );
215 diag( "This test harness detected that trying to renegotiate resulted in a disconnected socket." );
216 diag( "POE::Component::SSLify will work on your system, but please do not attempt a SSL renegotiate." );
217 diag( "Please talk with the author to figure out if this issue can be worked around, thank you!" );
218 }
219
220 pass( 'shut down sanely' );
221
222 exit 0;
+0
-12
t/apocalypse.t less more
0 #!/usr/bin/perl
1 use strict; use warnings;
2
3 use Test::More;
4 eval "use Test::Apocalypse 0.10";
5 if ( $@ ) {
6 plan skip_all => 'Test::Apocalypse required for validating the distribution';
7 } else {
8 # lousy hack for kwalitee
9 require Test::NoWarnings; require Test::Pod; require Test::Pod::Coverage;
10 is_apocalypse_here();
11 }