Package list libpoe-component-sslify-perl / upstream/1.008
[svn-upgrade] new version libpoe-component-sslify-perl (1.008) Ansgar Burchardt 10 years ago
22 changed file(s) with 1456 addition(s) and 306 deletion(s). Raw diff Collapse all Expand all
2323 'Apocalypse <APOCAL@cpan.org>'
2424 ],
2525 'dist_name' => 'POE-Component-SSLify',
26 'dist_version' => '1.005',
26 'dist_version' => '1.008',
2727 'license' => 'perl',
2828 'module_name' => 'POE::Component::SSLify',
2929 'recommends' => {},
3232 'Exporter' => '0',
3333 'IO::Handle' => '1.28',
3434 'Net::SSLeay' => '1.36',
35 'POE' => '0',
3536 'Scalar::Util' => '0',
3637 'Symbol' => '0',
3738 'Task::Weaken' => '1.03',
00 Revision history for Perl extension POE::Component::SSLify.
1
2 1.008
3 Released: 2011-05-04 21:55:27 UTC
4
5 Bazerka@irc noticed that POE wasn't even listed as a runtime prereq, d0h!
6
7 1.007
8 Released: 2011-05-04 21:36:32 UTC
9
10 Revert the ENGINE load logic added in 1.004 because it was causing coredumps on netbsd ( thanks BINGOS! )
11 Add the constant LOAD_SSL_ENGINES sub if you need to load the ssl engines
12 Tweak the renegotiate tests to be more tolerant of failures, thanks RCAPUTO - RT#66741
13
14 1.006
15 Released: 2011-04-22 00:21:51 UTC
16
17 Fix a heinous bug where openssl will randomly+reliably close a connection ( thanks MIRE )
18 Tweak the hook tests so they test the case where no data is sent over the connection
19 Tweak the connfail tests so they work better
120
221 1.005
322 Released: 2011-03-10 07:55:30 UTC
11 9999-99-99 99:99:99 +0000 HEAD
22 ==============================
33
4 commit 4fa0a44b7f0a9b37ef5fcbcb07ad6e45dd50b265
5 Author: Apocalypse <perl@0ne.us>
6 Date: Wed May 4 14:53:14 2011 -0700
7
8 actually require POE as a runtime prereq, thanks Bazerka@irc
9
10 =======================================
11 2011-05-04 14:37:11 -0700 release-1.007
12 =======================================
13
14 commit 5ada288a8ab2b24c6472e5a8fb3f43958fa22445
15 Author: Apocalypse <perl@0ne.us>
16 Date: Wed May 4 14:37:11 2011 -0700
17
18 New CPAN release of POE-Component-SSLify - v1.007
19
20 Released: 2011-05-04 21:36:32 UTC
21
22 Revert the ENGINE load logic added in 1.004 because it was causing
23 coredumps on netbsd ( thanks BINGOS! )
24
25 Add the constant LOAD_SSL_ENGINES sub if you need to load the ssl
26 engines
27
28 Tweak the renegotiate tests to be more tolerant of failures, thanks
29 RCAPUTO - RT#66741
30
31 commit 958b153b6d09773230336793b1a3f2f2848a55dc
32 Author: Apocalypse <perl@0ne.us>
33 Date: Wed May 4 14:34:15 2011 -0700
34
35 rename some POD for pod::coverage tests
36
37 commit 125745d00aa051e13a18ac207a618c50913bbd57
38 Author: Apocalypse <perl@0ne.us>
39 Date: Wed May 4 14:21:22 2011 -0700
40
41 rewrite the renegotiate tests in hope of fixing RT#66741
42
43 commit 393337624aef50602f4f2e9ff4ec412e1cbe7d76
44 Author: Apocalypse <perl@0ne.us>
45 Date: Wed May 4 14:02:59 2011 -0700
46
47 fix netbsd coredumps by not loading ENGINEs, reported by BINGOS
48
49 =======================================
50 2011-04-21 17:22:30 -0700 release-1.006
51 =======================================
52
53 commit 0096f51336380c31d99e87cf93a63ed650e60aff
54 Author: Apocalypse <perl@0ne.us>
55 Date: Thu Apr 21 17:22:30 2011 -0700
56
57 New CPAN release of POE-Component-SSLify - v1.006
58
59 Released: 2011-04-22 00:21:51 UTC
60
61 Fix a heinous bug where openssl will randomly+reliably close a
62 connection ( thanks MIRE )
63
64 Tweak the hook tests so they test the case where no data is sent over
65 the connection
66
67 Tweak the connfail tests so they work better
68
69 commit df65edee2621f55f347db2c70d779e44d93b87d2
70 Author: Apocalypse <perl@0ne.us>
71 Date: Thu Apr 21 17:16:15 2011 -0700
72
73 mire@irc is now MIRE, congrats
74
75 commit 853522b575570c997d3c8ff70c530cd45cde1e40
76 Author: Apocalypse <perl@0ne.us>
77 Date: Thu Apr 21 14:54:08 2011 -0700
78
79 tweak mires test a bit
80
81 commit e745765e01f9c07e0b195b2c49be40bea2e916f4
82 Author: Apocalypse <perl@0ne.us>
83 Date: Thu Apr 21 08:28:42 2011 -0700
84
85 start of work on mire's testcase
86
87 commit 15e3d473b68e6e0ac36673bbc71b7125fd49ed2f
88 Author: Apocalypse <perl@0ne.us>
89 Date: Thu Apr 21 00:03:23 2011 -0700
90
91 add mire test to be worked into a proper AUTHOR test
92
93 commit ad5c8c95dce50c051d8c54ade4c90b45f49103c3
94 Author: Apocalypse <perl@0ne.us>
95 Date: Wed Apr 20 20:44:15 2011 -0700
96
97 update changelog for the fixes
98
99 commit ed9e2b33c10572df76e790ffad68d3d7ecb820f9
100 Author: Apocalypse <perl@0ne.us>
101 Date: Wed Apr 20 20:11:17 2011 -0700
102
103 fix random SSL failures, spotted by mire
104
105 commit 5a9b28e587a3dace6ed71bd93691215b47cbc348
106 Author: Apocalypse <perl@0ne.us>
107 Date: Wed Apr 20 20:09:00 2011 -0700
108
109 tweak the connfail tests and make the server test work
110
111 commit 806d4c4df5ca108c8cfacbb19babcfebc8b05cdc
112 Author: Apocalypse <perl@0ne.us>
113 Date: Wed Apr 20 20:08:18 2011 -0700
114
115 tweak the hook tests to cover the case where there is no data sent
116 over the wire
117
118 =======================================
119 2011-03-10 00:56:13 -0700 release-1.005
120 =======================================
121
122 commit bc1a271e1f6e597f42cf03723ef6525a21281bea
123 Author: Apocalypse <perl@0ne.us>
124 Date: Thu Mar 10 00:56:13 2011 -0700
125
126 New CPAN release of POE-Component-SSLify - v1.005
127
128 Released: 2011-03-10 07:55:30 UTC
129
130 Fix the connfail tests due to an incorrect assumption regards socket
131 close value, thanks CPANTesters!
132
4133 commit d8b4c0e354acf683f17fd63186810226e101b54e
5134 Author: Apocalypse <perl@0ne.us>
6135 Date: Thu Mar 10 00:54:05 2011 -0700
2121 t/00-compile.t
2222 t/000-report-versions-tiny.t
2323 t/1_simple.t
24 t/2_renegotiate.t
24 t/2_renegotiate_client.t
2525 t/3_upgrade.t
2626 t/4_connect_hook.t
2727 t/5_connfail_client.t
2828 t/6_connfail_server.t
29 t/7_connect_hook_nodata.t
30 t/8_renegotiate_server.t
31 t/98_renegotiate.t
32 t/99_mire_test.t
2933 t/apocalypse.t
3535 "Exporter" : 0,
3636 "IO::Handle" : "1.28",
3737 "Net::SSLeay" : "1.36",
38 "POE" : 0,
3839 "Scalar::Util" : 0,
3940 "Symbol" : 0,
4041 "Task::Weaken" : "1.03",
5758 "provides" : {
5859 "POE::Component::SSLify" : {
5960 "file" : "lib/POE/Component/SSLify.pm",
60 "version" : "1.005"
61 "version" : "1.008"
6162 },
6263 "POE::Component::SSLify::ClientHandle" : {
6364 "file" : "lib/POE/Component/SSLify/ClientHandle.pm",
64 "version" : "1.005"
65 "version" : "1.008"
6566 },
6667 "POE::Component::SSLify::ServerHandle" : {
6768 "file" : "lib/POE/Component/SSLify/ServerHandle.pm",
68 "version" : "1.005"
69 "version" : "1.008"
6970 }
7071 },
7172 "release_status" : "stable",
8485 "web" : "http://github.com/apocalypse/perl-poe-sslify"
8586 }
8687 },
87 "version" : "1.005",
88 "version" : "1.008",
8889 "x_BuiltWith" : {
8990 "modules" : {
9091 "Exporter" : "5.63",
9394 "IO::Handle" : "1.28",
9495 "Module::Build" : "0.3607",
9596 "Net::SSLeay" : "1.36",
96 "POE" : "1.299",
97 "POE" : "1.310",
9798 "POE::Component::Client::TCP" : "1.299",
9899 "POE::Component::Server::TCP" : "1.299",
99100 "Scalar::Util" : "1.23",
161162 {
162163 "class" : "Dist::Zilla::Plugin::ReportVersions::Tiny",
163164 "name" : "@Apocalyptic/ReportVersions::Tiny",
164 "version" : "1.02"
165 "version" : "1.03"
165166 },
166167 {
167168 "class" : "Dist::Zilla::Plugin::Prepender",
171172 {
172173 "class" : "Dist::Zilla::Plugin::Authority",
173174 "name" : "@Apocalyptic/Authority",
174 "version" : "1.003"
175 "version" : "1.005"
175176 },
176177 {
177178 "class" : "Dist::Zilla::Plugin::PkgVersion",
196197 {
197198 "class" : "Dist::Zilla::Plugin::MinimumPerl",
198199 "name" : "@Apocalyptic/MinimumPerl",
199 "version" : "1.001"
200 "version" : "1.003"
200201 },
201202 {
202203 "class" : "Dist::Zilla::Plugin::Bugtracker",
2727 provides:
2828 POE::Component::SSLify:
2929 file: lib/POE/Component/SSLify.pm
30 version: 1.005
30 version: 1.008
3131 POE::Component::SSLify::ClientHandle:
3232 file: lib/POE/Component/SSLify/ClientHandle.pm
33 version: 1.005
33 version: 1.008
3434 POE::Component::SSLify::ServerHandle:
3535 file: lib/POE/Component/SSLify/ServerHandle.pm
36 version: 1.005
36 version: 1.008
3737 requires:
3838 Exporter: 0
3939 IO::Handle: 1.28
4040 Net::SSLeay: 1.36
41 POE: 0
4142 Scalar::Util: 0
4243 Symbol: 0
4344 Task::Weaken: 1.03
4849 homepage: http://search.cpan.org/dist/POE-Component-SSLify/
4950 license: http://dev.perl.org/licenses/
5051 repository: git://github.com/apocalypse/perl-poe-sslify.git
51 version: 1.005
52 version: 1.008
5253 x_BuiltWith:
5354 modules:
5455 Exporter: 5.63
5758 IO::Handle: 1.28
5859 Module::Build: 0.3607
5960 Net::SSLeay: 1.36
60 POE: 1.299
61 POE: 1.310
6162 POE::Component::Client::TCP: 1.299
6263 POE::Component::Server::TCP: 1.299
6364 Scalar::Util: 1.23
113114 -
114115 class: Dist::Zilla::Plugin::ReportVersions::Tiny
115116 name: '@Apocalyptic/ReportVersions::Tiny'
116 version: 1.02
117 version: 1.03
117118 -
118119 class: Dist::Zilla::Plugin::Prepender
119120 name: '@Apocalyptic/Prepender'
121122 -
122123 class: Dist::Zilla::Plugin::Authority
123124 name: '@Apocalyptic/Authority'
124 version: 1.003
125 version: 1.005
125126 -
126127 class: Dist::Zilla::Plugin::PkgVersion
127128 name: '@Apocalyptic/PkgVersion'
141142 -
142143 class: Dist::Zilla::Plugin::MinimumPerl
143144 name: '@Apocalyptic/MinimumPerl'
144 version: 1.001
145 version: 1.003
145146 -
146147 class: Dist::Zilla::Plugin::Bugtracker
147148 name: '@Apocalyptic/Bugtracker'
3131 'Exporter' => '0',
3232 'IO::Handle' => '1.28',
3333 'Net::SSLeay' => '1.36',
34 'POE' => '0',
3435 'Scalar::Util' => '0',
3536 'Symbol' => '0',
3637 'Task::Weaken' => '1.03',
3738 'parent' => '0'
3839 },
39 'VERSION' => '1.005',
40 'VERSION' => '1.008',
4041 'test' => {
4142 'TESTS' => 't/*.t'
4243 }
11 POE::Component::SSLify - Makes using SSL in the world of POE easy!
22
33 VERSION
4 This document describes v1.005 of POE::Component::SSLify - released March 10, 2011 as part of POE-Component-SSLify.
4 This document describes v1.008 of POE::Component::SSLify - released May 04, 2011 as part of POE-Component-SSLify.
55
66 SYNOPSIS
77 # CLIENT-side usage
298298 function against SSLify, so use them carefully!
299299
300300 Net::SSLeay::renegotiate
301 This function has been tested ( it's in "t/2_renegotiate.t" ) but it
302 doesn't work on FreeBSD! I tracked it down to this security advisory:
301 This function has been tested ( it's in "t/2_renegotiate_client.t" ) but
302 it doesn't work on FreeBSD! I tracked it down to this security advisory:
303303 <http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc> which
304304 explains it in detail. The test will skip this function if it detects
305305 that you're on a broken system. However, if you have the updated OpenSSL
325325 developer, I'm unable to fix this. However, it seems like Cygwin on
326326 MSWin32 works just fine! Please help me fix this if you can, thanks!
327327
328 LOAD_SSL_ENGINES
329 OpenSSL supports loading ENGINEs to accelerate the crypto algorithms.
330 SSLify v1.004 automatically loaded the engines, but there was some
331 problems on certain platforms that caused coredumps. A big shout-out to
332 BinGOs and CPANTesters for catching this! It's now disabled in v1.007
333 and you would need to explicitly enable it.
334
335 sub POE::Component::SSLify::LOAD_SSL_ENGINES () { 1 }
336 use POE::Component::SSLify qw( Client::SSLify );
337
328338 EXPORT
329339 Stuffs all of the functions in @EXPORT_OK so you have to request them
330340 directly.
350360
351361 * Search CPAN
352362
363 The default CPAN search engine, useful to view POD in HTML format.
364
353365 <http://search.cpan.org/dist/POE-Component-SSLify>
354366
355367 * RT: CPAN's Bug Tracker
356368
369 The RT ( Request Tracker ) website is the default bug/issue tracking
370 system for CPAN.
371
357372 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-SSLify>
358373
359 * AnnoCPAN: Annotated CPAN documentation
374 * AnnoCPAN
375
376 The AnnoCPAN is a website that allows community annonations of Perl
377 module documentation.
360378
361379 <http://annocpan.org/dist/POE-Component-SSLify>
362380
363381 * CPAN Ratings
364382
383 The CPAN Ratings is a website that allows community ratings and
384 reviews of Perl modules.
385
365386 <http://cpanratings.perl.org/d/POE-Component-SSLify>
366387
367388 * CPAN Forum
368389
390 The CPAN Forum is a web forum for discussing Perl modules.
391
369392 <http://cpanforum.com/dist/POE-Component-SSLify>
370393
371 * CPANTS Kwalitee
394 * CPANTS
395
396 The CPANTS is a website that analyzes the Kwalitee ( code metrics )
397 of a distribution.
372398
373399 <http://cpants.perl.org/dist/overview/POE-Component-SSLify>
374400
375 * CPAN Testers Results
376
377 <http://cpantesters.org/distro/P/POE-Component-SSLify.html>
401 * CPAN Testers
402
403 The CPAN Testers is a network of smokers who run automated tests on
404 uploaded CPAN distributions.
405
406 <http://www.cpantesters.org/distro/P/POE-Component-SSLify>
378407
379408 * CPAN Testers Matrix
380409
410 The CPAN Testers Matrix is a website that provides a visual way to
411 determine what Perls/platforms PASSed for a distribution.
412
381413 <http://matrix.cpantesters.org/?dist=POE-Component-SSLify>
414
415 * CPAN Testers Dependencies
416
417 The CPAN Testers Dependencies is a website that shows a chart of the
418 test results of all dependencies for a distribution.
419
420 <http://deps.cpantesters.org/?module=POE::Component::SSLify>
382421
383422 Email
384423 You can email the author of this module at "APOCAL at cpan.org" asking
1313 -----BEGIN PGP SIGNED MESSAGE-----
1414 Hash: SHA1
1515
16 SHA1 74d0a53111acfd4b4b7f9c269175a06e77309d86 Build.PL
17 SHA1 0e7543ad72ae31c532a8298fae8a3c98cdc87e86 Changes
18 SHA1 375fe756ad481b99709cf16d1a5378a7dee530ef CommitLog
16 SHA1 db814b600c64a9dbf43916f952d61724c9cb5629 Build.PL
17 SHA1 6f3f477a7be6adda1715f4f6232d1c23f1b0c73a Changes
18 SHA1 6a0020176172c6097eb86b34ef42014654df64f3 CommitLog
1919 SHA1 e3edc44697d1770c65fec99f6ebdb6ea55fb3050 INSTALL
2020 SHA1 263360e99a0de4d587fedefe1a919dcf61af1d10 LICENSE
21 SHA1 1baae2c8b4d91da92fdf35c5542137380f00c9e4 MANIFEST
21 SHA1 3117aae7a178cf1a5ef1c6fbbd9af19a36462dbc MANIFEST
2222 SHA1 9dfc07c5655b958e800189837f3ddd37ca050bfe MANIFEST.SKIP
23 SHA1 bfa76e8e9cf9ce09d4b4fd98883f6d1b0639a4f6 META.json
24 SHA1 5a4ea0cc9966848930db2129a75c3cf6bea77a45 META.yml
25 SHA1 842e80effc5a192dd7d9ca2176d58985abb70a4c Makefile.PL
26 SHA1 781198b6246cacc4b4c336bbacb47320a658f024 README
23 SHA1 e248fce45784dc1e74a6632ae73dab4408806755 META.json
24 SHA1 b7979650243be1fb48f457c7f3ad7ec6ee9fd424 META.yml
25 SHA1 88399f5f9ea5f4cff1f2899fde9b6434fa6525fb Makefile.PL
26 SHA1 013286bba5f5a9bdbefd457b13cb150f53c87711 README
2727 SHA1 41a5da1356107d097f6bbf72c62ee4da83e4119f dist.ini
2828 SHA1 96decb1c51052f9b024b6d069e428b4ccc19e909 examples/client.pl
2929 SHA1 d8f9b44df461cdcf6cbd7cffd79a9d49aade3947 examples/server.pl
3030 SHA1 c4a936c75d1d566e936dfb1776c9a01ea244c618 examples/serverclient.pl
31 SHA1 21353f9c92b51a2a27604af460d08f6993da9a28 lib/POE/Component/SSLify.pm
32 SHA1 620bcbd8febf6eb4d4f066479c895b90302dedfd lib/POE/Component/SSLify/ClientHandle.pm
33 SHA1 444dbb2e912dc3d94494ddb316b1950612d38288 lib/POE/Component/SSLify/ServerHandle.pm
31 SHA1 7c470b55e86d0fc80ca4b60ba3dfb0ab1781591d lib/POE/Component/SSLify.pm
32 SHA1 ee5c6b2eb8109cc96d9f60c2eb993da305f959cf lib/POE/Component/SSLify/ClientHandle.pm
33 SHA1 9ee769ea86ff4ad984bfba8c643e74cc0bcfaaba lib/POE/Component/SSLify/ServerHandle.pm
3434 SHA1 59afa28f138a14b956443f915d60a891d5b306b8 mylib/example.crt
3535 SHA1 f2ba02d28cfb207e0a86be7cb4f3c570f257bf93 mylib/example.key
3636 SHA1 fd48b12e3df15fb55695e7d1b4ee95dc3c0cd766 t/00-compile.t
37 SHA1 9df6d0a549121f4e7db1cabbdb703d59aa821f85 t/000-report-versions-tiny.t
37 SHA1 4788d9aa069d03cc4c94ef15e11e8a0e0527561c t/000-report-versions-tiny.t
3838 SHA1 9ade9d7296a3511f42ce3010dd7d215630d51c80 t/1_simple.t
39 SHA1 0d6e08c744e377933f75c6d9fa25c37e3506d1a5 t/2_renegotiate.t
39 SHA1 949de479ef156e3845bf64adb21a9556af0420a6 t/2_renegotiate_client.t
4040 SHA1 73790060e55b0189540d898a97c485e187f05ae9 t/3_upgrade.t
41 SHA1 f8ba954e2a5bf546c3932eb9cc1ba9bf89a57385 t/4_connect_hook.t
42 SHA1 4c7ecc5d6221a593b5961f53205eb016a1eee3bd t/5_connfail_client.t
43 SHA1 89fa487c62b3e6aadc33bd1025bec93f2aabdc1d t/6_connfail_server.t
41 SHA1 3c6e64d27262d54d7b31c2d4f2e65f5d6cab87cf t/4_connect_hook.t
42 SHA1 520cb166745d10fa749372ce686240dafd0da543 t/5_connfail_client.t
43 SHA1 295f221b5001822ac23244030fb1b8be1bd838e8 t/6_connfail_server.t
44 SHA1 156f6b65482911b3be5c8f3ce8c07071c5308d1b t/7_connect_hook_nodata.t
45 SHA1 377a10c6d96cd1a23922526c44c43cd723dafcfd t/8_renegotiate_server.t
46 SHA1 5bb02868a0a8d995272800bc945f6db2669d291e t/98_renegotiate.t
47 SHA1 8f73eec992bcb37639f49945d986ff5a59a1ca36 t/99_mire_test.t
4448 SHA1 e3b390873d4de642e25fcfb4b7d16c00b096d24a t/apocalypse.t
4549 -----BEGIN PGP SIGNATURE-----
4650 Version: GnuPG v1.4.9 (GNU/Linux)
4751
48 iEYEARECAAYFAk14g/0ACgkQGfr7vsGKgxzbqQCfVAAlTNCFi81uhNCljGXLGqOp
49 BC4AoIytDbvdcMRaIj3mHDJP7ugIZyd9
50 =rNNR
52 iEYEARECAAYFAk3By1oACgkQGfr7vsGKgxx47ACfTzDqglDL4xb266x3RMOBG3AJ
53 xj0AoNyF1h2KqHOYNVVImQmGy6UIw8D5
54 =qxVp
5155 -----END PGP SIGNATURE-----
88 use strict; use warnings;
99 package POE::Component::SSLify::ClientHandle;
1010 BEGIN {
11 $POE::Component::SSLify::ClientHandle::VERSION = '1.005';
11 $POE::Component::SSLify::ClientHandle::VERSION = '1.008';
1212 }
1313 BEGIN {
1414 $POE::Component::SSLify::ClientHandle::AUTHORITY = 'cpan:APOCAL';
7272
7373 =head1 VERSION
7474
75 This document describes v1.005 of POE::Component::SSLify::ClientHandle - released March 10, 2011 as part of POE-Component-SSLify.
75 This document describes v1.008 of POE::Component::SSLify::ClientHandle - released May 04, 2011 as part of POE-Component-SSLify.
7676
7777 =head1 DESCRIPTION
7878
88 use strict; use warnings;
99 package POE::Component::SSLify::ServerHandle;
1010 BEGIN {
11 $POE::Component::SSLify::ServerHandle::VERSION = '1.005';
11 $POE::Component::SSLify::ServerHandle::VERSION = '1.008';
1212 }
1313 BEGIN {
1414 $POE::Component::SSLify::ServerHandle::AUTHORITY = 'cpan:APOCAL';
4242 'fileno' => $fileno,
4343 'status' => $res,
4444 'on_connect' => $connref,
45 'ssl_started' => 0,
4546 }, $class;
4647
4748 return $self;
4849 }
50
51 # TODO should we make a convenience function to convert retval to string equivalents for easier debugging?
52 # From OpenSSL 1.0.0d
53 #define SSL_ERROR_NONE 0
54 #define SSL_ERROR_SSL 1
55 #define SSL_ERROR_WANT_READ 2
56 #define SSL_ERROR_WANT_WRITE 3
57 #define SSL_ERROR_WANT_X509_LOOKUP 4
58 #define SSL_ERROR_SYSCALL 5 /* look at error stack/return value/errno */
59 #define SSL_ERROR_ZERO_RETURN 6
60 #define SSL_ERROR_WANT_CONNECT 7
61 #define SSL_ERROR_WANT_ACCEPT 8
4962
5063 sub _check_status {
5164 my $self = shift;
5871 $self->{'status'} = Net::SSLeay::accept( $self->{'ssl'} );
5972 }
6073
61 # Only process the stuff if we actually have a callback!
62 return unless defined $self->{'on_connect'};
63
6474 if ( $self->{'status'} <= 0 ) {
6575 # http://www.openssl.org/docs/ssl/SSL_get_error.html
6676 my $errval = Net::SSLeay::get_error( $self->{'ssl'}, $self->{'status'} );
6777
78 # Handle the case of ERROR_WANT_READ and ERROR_WANT_WRITE
6879 # TODO should we skip ERROR_WANT_ACCEPT and ERROR_WANT_CONNECT ?
6980 # also, ERROR_WANT_ACCEPT isn't exported by Net::SSLeay, huh?
70 if ( $errval != ERROR_WANT_READ and $errval != ERROR_WANT_WRITE ) {
81 if ( $errval == ERROR_WANT_READ or $errval == ERROR_WANT_WRITE ) {
82 # continue reading/writing from the socket until we connect or not...
83 return 1;
84 } else {
7185 # call the hook function for error connect
72 $self->{'on_connect'}->( $self->{'orig_socket'}, 0, $errval );
86 if ( defined $self->{'on_connect'} ) {
87 $self->{'on_connect'}->( $self->{'orig_socket'}, 0, $errval );
88 }
89
90 # don't try to read/write from the socket anymore!
91 return 0;
7392 }
7493 } elsif ( $self->{'status'} == 1 ) {
94 # SSL handshake is done!
95 $self->{'ssl_started'} = 1;
96
7597 # call the hook function for successful connect
76 $self->{'on_connect'}->( $self->{'orig_socket'}, 1 );
98 if ( defined $self->{'on_connect'} ) {
99 $self->{'on_connect'}->( $self->{'orig_socket'}, 1 );
100 }
101
102 # we can now read/write from the socket!
103 return 1;
77104 }
78105 }
79106
85112 # Get the pointers to buffer, length, and the offset
86113 my( $buf, $len, $offset ) = \( @_ );
87114
88 # Check connection status
89 $self->_check_status if $self->{'status'} <= 0;
115 # Check the status of the SSL handshake
116 if ( ! $self->{'ssl_started'} ) {
117 return if $self->_check_status == 0;
118 }
90119
91120 # If we have no offset, replace the buffer with some input
92121 if ( ! defined $$offset ) {
94123
95124 # Are we done?
96125 if ( defined $$buf ) {
126 # TODO do we need the same "flush is success" logic in WRITE?
127
97128 return length( $$buf );
98129 } else {
99130 # Nah, clear the buffer too...
105136 # Now, actually read the data
106137 defined( my $read = Net::SSLeay::read( $self->{'ssl'}, $$len ) ) or return;
107138
139 # TODO do we need the same "flush is success" logic in WRITE?
140
108141 # Figure out the buffer and offset
109142 my $buf_len = length( $$buf );
110143
125158 # Get ourself + buffer + length + offset to write
126159 my( $self, $buf, $len, $offset ) = @_;
127160
128 # Check connection status
129 $self->_check_status if $self->{'status'} <= 0;
161 # Check the status of the SSL handshake
162 if ( ! $self->{'ssl_started'} ) {
163 # The normal syswrite() POE uses expects 0 here.
164 return 0 if $self->_check_status == 0;
165 }
130166
131167 # If we have nothing to offset, then start from the beginning
132168 if ( ! defined $offset ) {
143179 # The normal syswrite() POE uses expects 0 here.
144180 return 0;
145181 } else {
182 # We flushed some data, which means we finished the handshake!
183 # This is IMPORTANT, as MIRE found out!
184 # Otherwise openssl will zonk out and give us SSL_ERROR_SSL and things randomly break :(
185 # this is because we tried to connect() or accept() and the handshake was done... or something like that hah
186 if ( ! $self->{'ssl_started'} ) {
187 $self->{'ssl_started'} = 1;
188 $self->{'status'} = 1;
189
190 # call the hook function for successful connect
191 if ( defined $self->{'on_connect'} ) {
192 $self->{'on_connect'}->( $self->{'orig_socket'}, 1 );
193 }
194 }
195
146196 # All done!
147197 return $wrote_len;
148198 }
224274
225275 =head1 VERSION
226276
227 This document describes v1.005 of POE::Component::SSLify::ServerHandle - released March 10, 2011 as part of POE-Component-SSLify.
277 This document describes v1.008 of POE::Component::SSLify::ServerHandle - released May 04, 2011 as part of POE-Component-SSLify.
228278
229279 =head1 DESCRIPTION
230280
88 use strict; use warnings;
99 package POE::Component::SSLify;
1010 BEGIN {
11 $POE::Component::SSLify::VERSION = '1.005';
11 $POE::Component::SSLify::VERSION = '1.008';
1212 }
1313 BEGIN {
1414 $POE::Component::SSLify::AUTHORITY = 'cpan:APOCAL';
1515 }
1616
1717 # ABSTRACT: Makes using SSL in the world of POE easy!
18
19 BEGIN {
20 # should fix netbsd smoke failures, thanks BinGOs!
21 # <BinGOs> Apocal: okay cores with a 0.9.7d I've built myself from source. Doesn't if I comment out engine lines.
22 # BinGOs did an awesome job building various versions of openssl to try and track down the problem, it seems like
23 # newer versions of openssl worked fine on netbsd, but I don't want to do crazy stuff like probing openssl versions
24 # as it's fragile - best to let the user figure it out :)
25 #
26 # see http://www.cpantesters.org/cpan/report/1a660280-6eb1-11e0-a462-e9956c33433b
27 # http://www.cpantesters.org/cpan/report/49a9f2aa-6df2-11e0-a462-e9956c33433b
28 # http://www.cpantesters.org/cpan/report/78d9a234-6df5-11e0-a462-e9956c33433b
29 # and many other reports :(
30 #
31 #(gdb) bt
32 ##0 0xbd9d3e7e in engine_table_select () from /usr/lib/libcrypto.so.2
33 ##1 0xbd9b3bed in ENGINE_get_default_RSA () from /usr/lib/libcrypto.so.2
34 ##2 0xbd9b1f6d in RSA_new_method () from /usr/lib/libcrypto.so.2
35 ##3 0xbd9b1cf6 in RSA_new () from /usr/lib/libcrypto.so.2
36 ##4 0xbd9cf8a1 in RSAPrivateKey_asn1_meth () from /usr/lib/libcrypto.so.2
37 ##5 0xbd9da64b in ASN1_item_ex_new () from /usr/lib/libcrypto.so.2
38 ##6 0xbd9da567 in ASN1_item_ex_new () from /usr/lib/libcrypto.so.2
39 ##7 0xbd9d88cc in ASN1_item_ex_d2i () from /usr/lib/libcrypto.so.2
40 ##8 0xbd9d8437 in ASN1_item_d2i () from /usr/lib/libcrypto.so.2
41 ##9 0xbd9cf8d5 in d2i_RSAPrivateKey () from /usr/lib/libcrypto.so.2
42 ##10 0xbd9ad546 in d2i_PrivateKey () from /usr/lib/libcrypto.so.2
43 ##11 0xbd995e63 in PEM_read_bio_PrivateKey () from /usr/lib/libcrypto.so.2
44 ##12 0xbd980430 in PEM_read_bio_RSAPrivateKey () from /usr/lib/libcrypto.so.2
45 ##13 0xbda2e9dc in SSL_CTX_use_RSAPrivateKey_file () from /usr/lib/libssl.so.3
46 ##14 0xbda5aabe in XS_Net__SSLeay_CTX_use_RSAPrivateKey_file (cv=0x8682c80)
47 # at SSLeay.c:1716
48 ##15 0x08115401 in Perl_pp_entersub () at pp_hot.c:2885
49 ##16 0x080e0ab7 in Perl_runops_debug () at dump.c:2049
50 ##17 0x08078624 in S_run_body (oldscope=1) at perl.c:2308
51 ##18 0x08077ef2 in perl_run (my_perl=0x823f030) at perl.c:2233
52 ##19 0x0805e321 in main (argc=3, argv=0xbfbfe6a0, env=0xbfbfe6b0)
53 # at perlmain.c:117
54 ##20 0x0805e0c6 in ___start ()
55 #(gdb)
56 if ( ! defined &LOAD_SSL_ENGINES ) { *LOAD_SSL_ENGINES = sub () { 0 } }
57 }
1858
1959 # We need Net::SSLeay or all's a failure!
2060 BEGIN {
3474 # Taken from http://search.cpan.org/~flora/Net-SSLeay-1.36/lib/Net/SSLeay.pm#Low_level_API
3575 Net::SSLeay::load_error_strings();
3676 Net::SSLeay::SSLeay_add_ssl_algorithms();
37 Net::SSLeay::ENGINE_load_builtin_engines();
38 Net::SSLeay::ENGINE_register_all_complete();
77 if ( LOAD_SSL_ENGINES ) {
78 Net::SSLeay::ENGINE_load_builtin_engines();
79 Net::SSLeay::ENGINE_register_all_complete();
80 }
3981 Net::SSLeay::randomize();
4082 }
4183 }
5799 # Use Scalar::Util's weaken() for the connref stuff
58100 use Scalar::Util qw( weaken );
59101 use Task::Weaken 1.03; # to make sure it actually works!
102
103 # load POE ( just to fool dzil AutoPrereqs :)
104 require POE;
60105
61106 # The server-side CTX stuff
62107 my $ctx;
281326
282327 =head1 VERSION
283328
284 This document describes v1.005 of POE::Component::SSLify - released March 10, 2011 as part of POE-Component-SSLify.
329 This document describes v1.008 of POE::Component::SSLify - released May 04, 2011 as part of POE-Component-SSLify.
285330
286331 =head1 SYNOPSIS
287332
572617
573618 =head3 Net::SSLeay::renegotiate
574619
575 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:
576 L<http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc> which explains it in detail. The test will skip this function
620 This function has been tested ( it's in C<t/2_renegotiate_client.t> ) but it doesn't work on FreeBSD! I tracked it down to this security
621 advisory: L<http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc> which explains it in detail. The test will skip this function
577622 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.
578623
579624 NOTE: Calling this means the callback function you passed in L</Client_SSLify> or L</Server_SSLify> will not fire! If you need this
593638 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
594639 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!
595640
641 =head2 LOAD_SSL_ENGINES
642
643 OpenSSL supports loading ENGINEs to accelerate the crypto algorithms. SSLify v1.004 automatically loaded the engines, but there was some
644 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
645 and you would need to explicitly enable it.
646
647 sub POE::Component::SSLify::LOAD_SSL_ENGINES () { 1 }
648 use POE::Component::SSLify qw( Client::SSLify );
649
596650 =head1 EXPORT
597651
598652 Stuffs all of the functions in @EXPORT_OK so you have to request them directly.
632686
633687 Search CPAN
634688
689 The default CPAN search engine, useful to view POD in HTML format.
690
635691 L<http://search.cpan.org/dist/POE-Component-SSLify>
636692
637693 =item *
638694
639695 RT: CPAN's Bug Tracker
640696
697 The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.
698
641699 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-SSLify>
642700
643701 =item *
644702
645 AnnoCPAN: Annotated CPAN documentation
703 AnnoCPAN
704
705 The AnnoCPAN is a website that allows community annonations of Perl module documentation.
646706
647707 L<http://annocpan.org/dist/POE-Component-SSLify>
648708
650710
651711 CPAN Ratings
652712
713 The CPAN Ratings is a website that allows community ratings and reviews of Perl modules.
714
653715 L<http://cpanratings.perl.org/d/POE-Component-SSLify>
654716
655717 =item *
656718
657719 CPAN Forum
658720
721 The CPAN Forum is a web forum for discussing Perl modules.
722
659723 L<http://cpanforum.com/dist/POE-Component-SSLify>
660724
661725 =item *
662726
663 CPANTS Kwalitee
727 CPANTS
728
729 The CPANTS is a website that analyzes the Kwalitee ( code metrics ) of a distribution.
664730
665731 L<http://cpants.perl.org/dist/overview/POE-Component-SSLify>
666732
667733 =item *
668734
669 CPAN Testers Results
670
671 L<http://cpantesters.org/distro/P/POE-Component-SSLify.html>
735 CPAN Testers
736
737 The CPAN Testers is a network of smokers who run automated tests on uploaded CPAN distributions.
738
739 L<http://www.cpantesters.org/distro/P/POE-Component-SSLify>
672740
673741 =item *
674742
675743 CPAN Testers Matrix
676744
745 The CPAN Testers Matrix is a website that provides a visual way to determine what Perls/platforms PASSed for a distribution.
746
677747 L<http://matrix.cpantesters.org/?dist=POE-Component-SSLify>
748
749 =item *
750
751 CPAN Testers Dependencies
752
753 The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.
754
755 L<http://deps.cpantesters.org/?module=POE::Component::SSLify>
678756
679757 =back
680758
88 END { $success && done_testing; }
99
1010 my $v = "\n";
11
12 # List our own version used to generate this
13 $v .= "Generated by Dist::Zilla::Plugin::ReportVersions::Tiny v1.03\n";
1114
1215 eval { # no excuses!
1316 # report our Perl details
7073
7174 Thanks for using my code. I hope it works for you.
7275 If not, please try and include this output in the bug report.
73 That will help me reproduce the issue and solve you problem.
76 That will help me reproduce the issue and solve your problem.
7477
7578 EOT
7679
+0
-217
t/2_renegotiate.t less more
0 #!/usr/bin/perl
1 #
2 # This file is part of POE-Component-SSLify
3 #
4 # This software is copyright (c) 2011 by Apocalypse.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 use strict; use warnings;
10 use strict; use warnings;
11
12 # Thanks to ASCENT for this test!
13 # This test adds renegotiation to the connection from client-side
14 # Since this is not supported on all platforms, it's marked TODO and adds custom logic
15 # to make sure it doesn't FAIL if it's not supported.
16
17 my $numtests;
18 BEGIN {
19 $numtests = 23;
20
21 eval "use Test::NoWarnings";
22 if ( ! $@ ) {
23 # increment by one
24 $numtests++;
25 }
26 }
27
28 use Test::More tests => $numtests;
29
30 use POE 1.267;
31 use POE::Component::Client::TCP;
32 use POE::Component::Server::TCP;
33 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate SSLify_GetSocket SSLify_GetSSL/;
34 use Net::SSLeay qw/ERROR_WANT_READ ERROR_WANT_WRITE/;
35
36 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
37
38 my $port;
39 my $server_ping2;
40 my $client_ping2;
41
42 POE::Component::Server::TCP->new
43 (
44 Alias => 'myserver',
45 Address => '127.0.0.1',
46 Port => 0,
47
48 Started => sub
49 {
50 use Socket qw/sockaddr_in/;
51 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
52 },
53 ClientConnected => sub
54 {
55 ok(1, 'SERVER: accepted');
56 },
57 ClientDisconnected => sub
58 {
59 ok(1, 'SERVER: client disconnected');
60 $_[KERNEL]->post(myserver => 'shutdown');
61 },
62 ClientPreConnect => sub
63 {
64 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
65 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
66 ok(!$@, "SERVER: SSLify_Options $@");
67
68 my $socket = eval { Server_SSLify($_[ARG0]) };
69 ok(!$@, "SERVER: Server_SSLify $@");
70 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
71
72 # We pray that IO::Handle is sane...
73 ok( SSLify_GetSocket( $socket )->blocking == 0, 'SERVER: SSLified socket is non-blocking?');
74
75 return ($socket);
76 },
77 ClientInput => sub
78 {
79 my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0];
80
81 ## At this point, connection MUST be encrypted.
82 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
83 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
84
85 if ($request eq 'ping')
86 {
87 ok(1, "SERVER: recv: $request");
88 $heap->{client}->put("pong");
89 }
90 elsif ($request eq 'ping2')
91 {
92 ok(1, "SERVER: recv: $request");
93 $server_ping2++;
94 $heap->{client}->put("pong2");
95 }
96 },
97 ClientError => sub
98 {
99 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
100 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
101 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
102
103 # TODO are there other "errors" that is harmless?
104 $error = "Normal disconnection" unless $error;
105 my $msg = "Got SERVER $syscall error $errno: $error";
106 unless ( $syscall eq 'read' and $errno == 0 ) {
107 fail( $msg );
108 } else {
109 diag( $msg ) if $ENV{TEST_VERBOSE};
110 }
111 },
112 );
113
114 POE::Component::Client::TCP->new
115 (
116 Alias => 'myclient',
117 RemoteAddress => '127.0.0.1',
118 RemotePort => $port,
119
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 # We pray that IO::Handle is sane...
135 ok( SSLify_GetSocket( $socket )->blocking == 0, 'CLIENT: SSLified socket is non-blocking?');
136
137 return ($socket);
138 },
139 ServerInput => sub
140 {
141 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
142
143 ## At this point, connection MUST be encrypted.
144 my $cipher = SSLify_GetCipher($heap->{server}->get_output_handle);
145 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
146
147 if ($line eq 'pong')
148 {
149 ok(1, "CLIENT: recv: $line");
150
151 # Skip 2 Net::SSLeay::renegotiate() tests on FreeBSD because of
152 # http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc
153 TODO: {
154 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
155
156 ## Force SSL renegotiation
157 my $ssl = SSLify_GetSSL( $heap->{server}->get_output_handle );
158 my $reneg_num = Net::SSLeay::num_renegotiations($ssl);
159
160 ok(1 == Net::SSLeay::renegotiate($ssl), 'CLIENT: SSL renegotiation');
161 my $handshake = Net::SSLeay::do_handshake($ssl);
162 my $err = Net::SSLeay::get_error($ssl, $handshake);
163
164 ## 1 == Successful handshake, ERROR_WANT_(READ|WRITE) == non-blocking.
165 ok($handshake == 1 || $err == ERROR_WANT_READ || $err == ERROR_WANT_WRITE, 'CLIENT: SSL handshake');
166 ok($reneg_num < Net::SSLeay::num_renegotiations($ssl), 'CLIENT: Increased number of negotiations');
167 }
168
169 $heap->{server}->put('ping2');
170 }
171
172 elsif ($line eq 'pong2')
173 {
174 ok(1, "CLIENT: recv: $line");
175 $client_ping2++;
176 $kernel->yield('shutdown');
177 }
178 },
179 ServerError => sub
180 {
181 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
182 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
183 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
184
185 # TODO are there other "errors" that is harmless?
186 $error = "Normal disconnection" unless $error;
187 my $msg = "Got CLIENT $syscall error $errno: $error";
188 unless ( $syscall eq 'read' and $errno == 0 ) {
189 fail( $msg );
190 } else {
191 diag( $msg ) if $ENV{TEST_VERBOSE};
192 }
193 },
194 );
195
196 $poe_kernel->run();
197
198 # Add extra pass() to make the test harness happy if renegotiate did not work
199 if ( ! $server_ping2 ) {
200 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
201 fail( "SERVER: Failed SSL renegotiation" );
202 }
203 if ( ! $client_ping2 ) {
204 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
205 fail( "CLIENT: Failed SSL renegotiation" );
206 }
207 if ( ! $server_ping2 or ! $client_ping2 ) {
208 diag( "WARNING: Your platform/SSL library does not support renegotiation of the SSL socket." );
209 diag( "This test harness detected that trying to renegotiate resulted in a disconnected socket." );
210 diag( "POE::Component::SSLify will work on your system, but please do not attempt a SSL renegotiate." );
211 diag( "Please talk with the author to figure out if this issue can be worked around, thank you!" );
212 }
213
214 pass( 'shut down sanely' );
215
216 exit 0;
0 #!/usr/bin/perl
1 #
2 # This file is part of POE-Component-SSLify
3 #
4 # This software is copyright (c) 2011 by Apocalypse.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 use strict; use warnings;
10 use strict; use warnings;
11
12 # Thanks to ASCENT for this test!
13 # This test adds renegotiation to the connection from client-side
14
15 # In an older version of this test, there was ok() littered everywhere
16 # but dngor replied in http://rt.cpan.org/Public/Bug/Display.html?id=66741
17 # that it's not going to work... how do I predict which ok() will fail and "simulate" them?
18 # the solution was to... only run a few tests and print the diag
19 # because the rest of the tests just redo what we already have in 1_simple.t and stuff...
20
21 my $numtests;
22 BEGIN {
23 $numtests = 16;
24
25 eval "use Test::NoWarnings";
26 if ( ! $@ ) {
27 # increment by one
28 $numtests++;
29 }
30 }
31
32 use Test::More tests => $numtests;
33
34 use POE 1.267;
35 use POE::Component::Client::TCP;
36 use POE::Component::Server::TCP;
37 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate SSLify_GetSocket SSLify_GetSSL/;
38 use Net::SSLeay qw/ERROR_WANT_READ ERROR_WANT_WRITE/;
39
40 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
41
42 my $port;
43 my $server_ping2;
44 my $client_ping2;
45
46 POE::Component::Server::TCP->new
47 (
48 Alias => 'myserver',
49 Address => '127.0.0.1',
50 Port => 0,
51
52 Started => sub
53 {
54 use Socket qw/sockaddr_in/;
55 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
56 },
57 ClientConnected => sub
58 {
59 ok(1, 'SERVER: accepted');
60 },
61 ClientDisconnected => sub
62 {
63 ok(1, 'SERVER: client disconnected');
64 $_[KERNEL]->post(myserver => 'shutdown');
65 },
66 ClientPreConnect => sub
67 {
68 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
69 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
70 ok(!$@, "SERVER: SSLify_Options $@");
71
72 my $socket = eval { Server_SSLify($_[ARG0]) };
73 ok(!$@, "SERVER: Server_SSLify $@");
74 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
75
76 # We pray that IO::Handle is sane...
77 ok( SSLify_GetSocket( $socket )->blocking == 0, 'SERVER: SSLified socket is non-blocking?');
78
79 return ($socket);
80 },
81 ClientInput => sub
82 {
83 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
84
85 if ($line eq 'ping') {
86 ok(1, "SERVER: recv: $line");
87
88 ## At this point, connection MUST be encrypted.
89 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
90 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
91
92 $heap->{client}->put("pong");
93 } elsif ($line eq 'ping2') {
94 $server_ping2++;
95 $heap->{client}->put("pong2");
96 } else {
97 die "Unknown line from CLIENT: $line";
98 }
99 },
100 ClientError => sub
101 {
102 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
103 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
104 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
105
106 # TODO are there other "errors" that is harmless?
107 $error = "Normal disconnection" unless $error;
108 my $msg = "Got SERVER $syscall error $errno: $error";
109 unless ( $syscall eq 'read' and $errno == 0 ) {
110 # fail( $msg );
111 } else {
112 diag( $msg ) if $ENV{TEST_VERBOSE};
113 }
114 },
115 );
116
117 POE::Component::Client::TCP->new
118 (
119 Alias => 'myclient',
120 RemoteAddress => '127.0.0.1',
121 RemotePort => $port,
122
123 Connected => sub
124 {
125 ok(1, 'CLIENT: connected');
126
127 $_[HEAP]->{server}->put("ping");
128 },
129 PreConnect => sub
130 {
131 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
132 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
133 my $socket = eval { Client_SSLify($_[ARG0], undef, undef, $ctx) };
134 ok(!$@, "CLIENT: Client_SSLify $@");
135 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
136
137 # We pray that IO::Handle is sane...
138 ok( SSLify_GetSocket( $socket )->blocking == 0, 'CLIENT: SSLified socket is non-blocking?');
139
140 return ($socket);
141 },
142 ServerInput => sub
143 {
144 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
145
146 if ($line eq 'pong') {
147 ok(1, "CLIENT: recv: $line");
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 # do the actual renegotiate
154 Net::SSLeay::renegotiate( SSLify_GetSSL( $heap->{server}->get_output_handle ) );
155
156 $heap->{server}->put('ping2');
157 } elsif ($line eq 'pong2') {
158 $client_ping2++;
159 $kernel->yield('shutdown');
160 } else {
161 die "Unknown line from SERVER: $line";
162 }
163 },
164 ServerError => sub
165 {
166 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
167 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
168 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
169
170 $error = "Normal disconnection" unless $error;
171 my $msg = "Got CLIENT $syscall error $errno: $error";
172 diag( $msg ) if $ENV{TEST_VERBOSE};
173 },
174 );
175
176 $poe_kernel->run();
177
178 if ( ! $server_ping2 or ! $client_ping2 ) {
179 diag( "WARNING: Your platform/SSL library does not support renegotiation of the SSL socket." );
180 diag( "This test harness detected that trying to renegotiate resulted in a disconnected socket." );
181 diag( "POE::Component::SSLify will work on your system, but please do not attempt a SSL renegotiate." );
182 diag( "Please talk with the author to figure out if this issue can be worked around, thank you!" );
183 }
184
185 pass( 'shut down sanely' );
186
187 exit 0;
1313
1414 my $numtests;
1515 BEGIN {
16 $numtests = 17;
16 $numtests = 19;
1717
1818 eval "use Test::NoWarnings";
1919 if ( ! $@ ) {
7979 {
8080 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
8181
82 die "Unknown line from CLIENT: $line";
82 if ( $line ne 'ping' ) {
83 die "Unknown line from CLIENT: $line";
84 } else {
85 ok(1, "SERVER: recv: $line");
86 $_[HEAP]->{client}->put("pong");
87 }
8388 },
8489 ClientError => sub
8590 {
107112 Connected => sub
108113 {
109114 ok(1, 'CLIENT: connected');
115 $_[HEAP]->{server}->put("ping");
110116 },
111117 PreConnect => sub
112118 {
113119 my $socket = eval { Client_SSLify($_[ARG0], sub {
114120 my( $socket, $status, $errval ) = @_;
115121
116 pass( "CLIENT: Got callback hook" );
122 pass( "CLIENT: Got callback hook status" );
117123 is( $status, 1, "CLIENT: Status received from callback is OK" );
118124
119125 ## At this point, connection MUST be encrypted.
120126 my $cipher = SSLify_GetCipher($socket);
121127 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
122128 ok( SSLify_GetStatus($socket) == 1, "CLIENT: SSLify_GetStatus is done" );
123
124 $poe_kernel->post( 'myclient' => 'shutdown' );
125129 }) };
126130 ok(!$@, "CLIENT: Client_SSLify $@");
127131 ok( SSLify_GetStatus($socket) == -1, "CLIENT: SSLify_GetStatus is pending" );
132136 {
133137 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
134138
135 die "Should have never got any input from the server!";
139 if ( $line ne 'pong' ) {
140 die "Unknown line from CLIENT: $line";
141 } else {
142 ok(1, "CLIENT: recv: $line");
143 $kernel->yield('shutdown');
144 }
136145 },
137146 ServerError => sub
138147 {
4747 ClientConnected => sub
4848 {
4949 ok(1, 'SERVER: accepted');
50
51 # purposefully send garbage so we screw up the ssl connect on the client-side
52 $_[HEAP]->{client}->put( 'garbage in, garbage out' );
5053 },
5154 ClientDisconnected => sub
5255 {
1313
1414 my $numtests;
1515 BEGIN {
16 $numtests = 8;
16 $numtests = 9;
1717
18 # eval "use Test::NoWarnings";
19 # if ( ! $@ ) {
20 # # increment by one
21 # $numtests++;
22 # }
18 eval "use Test::NoWarnings";
19 if ( ! $@ ) {
20 # increment by one
21 $numtests++;
22 }
2323 }
2424
25 # For some reason I can't get this to replicate 5_connfail_client.t - wonder why?!#?
26 # I tried to use POE::Filter::Stream to see if it made a difference, nope...
27 #use Test::More tests => $numtests;
28 use Test::More;
29 plan skip_all => "This test hangs for some reason";
25 use Test::More tests => $numtests;
3026
3127 use POE 1.267;
3228 use POE::Component::Client::TCP;
10096 Connected => sub
10197 {
10298 ok(1, 'CLIENT: connected');
99
100 # purposefully send garbage so we screw up the ssl connect on the client-side
101 $_[HEAP]->{server}->put( 'garbage in, garbage out' );
103102 },
104103 ServerInput => sub
105104 {
0 #!/usr/bin/perl
1 #
2 # This file is part of POE-Component-SSLify
3 #
4 # This software is copyright (c) 2011 by Apocalypse.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 use strict; use warnings;
10 use strict; use warnings;
11
12 # This tests the connection OK hook on both server/client
13
14 my $numtests;
15 BEGIN {
16 $numtests = 17;
17
18 eval "use Test::NoWarnings";
19 if ( ! $@ ) {
20 # increment by one
21 $numtests++;
22 }
23 }
24
25 use Test::More tests => $numtests;
26
27 use POE 1.267;
28 use POE::Component::Client::TCP;
29 use POE::Component::Server::TCP;
30 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_GetSocket SSLify_GetStatus/;
31
32 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
33
34 my $port;
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') };
59 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt') } if ($@);
60 ok(!$@, "SERVER: SSLify_Options $@");
61
62 my $socket = eval { Server_SSLify( $_[ARG0], sub {
63 my( $socket, $status, $errval ) = @_;
64
65 pass( "SERVER: Got callback hook" );
66 is( $status, 1, "SERVER: Status received from callback is OK" );
67
68 ## At this point, connection MUST be encrypted.
69 my $cipher = SSLify_GetCipher($socket);
70 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
71 ok( SSLify_GetStatus($socket) == 1, "SERVER: SSLify_GetStatus is done" );
72 } ) };
73 ok(!$@, "SERVER: Server_SSLify $@");
74 ok( SSLify_GetStatus($socket) == -1, "SERVER: SSLify_GetStatus is pending" );
75
76 return ($socket);
77 },
78 ClientInput => sub
79 {
80 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
81
82 die "Should have never got any input from the client!";
83 },
84 ClientError => sub
85 {
86 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
87 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
88 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
89
90 # TODO are there other "errors" that is harmless?
91 $error = "Normal disconnection" unless $error;
92 my $msg = "Got SERVER $syscall error $errno: $error";
93 unless ( $syscall eq 'read' and $errno == 0 ) {
94 fail( $msg );
95 } else {
96 diag( $msg ) if $ENV{TEST_VERBOSE};
97 }
98 },
99 );
100
101 POE::Component::Client::TCP->new
102 (
103 Alias => 'myclient',
104 RemoteAddress => '127.0.0.1',
105 RemotePort => $port,
106
107 Connected => sub
108 {
109 ok(1, 'CLIENT: connected');
110 },
111 PreConnect => sub
112 {
113 my $socket = eval { Client_SSLify($_[ARG0], sub {
114 my( $socket, $status, $errval ) = @_;
115
116 pass( "CLIENT: Got callback hook" );
117 is( $status, 1, "CLIENT: Status received from callback is OK" );
118
119 ## At this point, connection MUST be encrypted.
120 my $cipher = SSLify_GetCipher($socket);
121 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
122 ok( SSLify_GetStatus($socket) == 1, "CLIENT: SSLify_GetStatus is done" );
123
124 $poe_kernel->post( 'myclient' => 'shutdown' );
125 }) };
126 ok(!$@, "CLIENT: Client_SSLify $@");
127 ok( SSLify_GetStatus($socket) == -1, "CLIENT: SSLify_GetStatus is pending" );
128
129 return ($socket);
130 },
131 ServerInput => sub
132 {
133 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
134
135 die "Should have never got any input from the server!";
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 # This file is part of POE-Component-SSLify
3 #
4 # This software is copyright (c) 2011 by Apocalypse.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 use strict; use warnings;
10 use strict; use warnings;
11
12 # Thanks to ASCENT for this test!
13 # This test adds renegotiation to the connection from server-side
14
15 # In an older version of this test, there was ok() littered everywhere
16 # but dngor replied in http://rt.cpan.org/Public/Bug/Display.html?id=66741
17 # that it's not going to work... how do I predict which ok() will fail and "simulate" them?
18 # the solution was to... only run a few tests and print the diag
19 # because the rest of the tests just redo what we already have in 1_simple.t and stuff...
20
21 my $numtests;
22 BEGIN {
23 $numtests = 16;
24
25 eval "use Test::NoWarnings";
26 if ( ! $@ ) {
27 # increment by one
28 $numtests++;
29 }
30 }
31
32 use Test::More tests => $numtests;
33
34 use POE 1.267;
35 use POE::Component::Client::TCP;
36 use POE::Component::Server::TCP;
37 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate SSLify_GetSocket SSLify_GetSSL/;
38
39 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
40
41 my $port;
42 my $server_ping2;
43 my $client_ping2;
44
45 POE::Component::Server::TCP->new
46 (
47 Alias => 'myserver',
48 Address => '127.0.0.1',
49 Port => 0,
50
51 Started => sub
52 {
53 use Socket qw/sockaddr_in/;
54 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
55 },
56 ClientConnected => sub
57 {
58 ok(1, 'SERVER: accepted');
59 $_[HEAP]->{client}->put("ping");
60 },
61 ClientDisconnected => sub
62 {
63 ok(1, 'SERVER: client disconnected');
64 $_[KERNEL]->post(myserver => 'shutdown');
65 },
66 ClientPreConnect => sub
67 {
68 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
69 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
70 ok(!$@, "SERVER: SSLify_Options $@");
71
72 my $socket = eval { Server_SSLify($_[ARG0]) };
73 ok(!$@, "SERVER: Server_SSLify $@");
74 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
75
76 # We pray that IO::Handle is sane...
77 ok( SSLify_GetSocket( $socket )->blocking == 0, 'SERVER: SSLified socket is non-blocking?');
78
79 return ($socket);
80 },
81 ClientInput => sub
82 {
83 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
84
85 if ($line eq 'pong') {
86 ok(1, "SERVER: recv: $line");
87
88 ## At this point, connection MUST be encrypted.
89 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
90 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
91
92 Net::SSLeay::renegotiate( SSLify_GetSSL( $heap->{client}->get_output_handle ) );
93
94 $heap->{client}->put("ping2");
95 } elsif ($line eq 'pong2') {
96 $server_ping2++;
97 $kernel->yield( 'shutdown' );
98 } else {
99 die "Unknown line from CLIENT: $line";
100 }
101 },
102 ClientError => sub
103 {
104 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
105 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
106 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
107
108 # TODO are there other "errors" that is harmless?
109 $error = "Normal disconnection" unless $error;
110 my $msg = "Got SERVER $syscall error $errno: $error";
111 unless ( $syscall eq 'read' and $errno == 0 ) {
112 # fail( $msg );
113 } else {
114 diag( $msg ) if $ENV{TEST_VERBOSE};
115 }
116 },
117 );
118
119 POE::Component::Client::TCP->new
120 (
121 Alias => 'myclient',
122 RemoteAddress => '127.0.0.1',
123 RemotePort => $port,
124
125 Connected => sub
126 {
127 ok(1, 'CLIENT: connected');
128 },
129 PreConnect => sub
130 {
131 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
132 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
133 my $socket = eval { Client_SSLify($_[ARG0], undef, undef, $ctx) };
134 ok(!$@, "CLIENT: Client_SSLify $@");
135 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
136
137 # We pray that IO::Handle is sane...
138 ok( SSLify_GetSocket( $socket )->blocking == 0, 'CLIENT: SSLified socket is non-blocking?');
139
140 return ($socket);
141 },
142 ServerInput => sub
143 {
144 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
145
146 if ($line eq 'ping') {
147 ok(1, "CLIENT: recv: $line");
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 $_[HEAP]->{server}->put("pong");
154 } elsif ( $line eq 'ping2' ) {
155 $client_ping2++;
156 $_[HEAP]->{server}->put("pong2");
157 } else {
158 die "Unknown line from SERVER: $line";
159 }
160 },
161 ServerError => sub
162 {
163 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
164 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
165 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
166
167 $error = "Normal disconnection" unless $error;
168 my $msg = "Got CLIENT $syscall error $errno: $error";
169 diag( $msg ) if $ENV{TEST_VERBOSE};
170 },
171 );
172
173 $poe_kernel->run();
174
175 if ( ! $server_ping2 or ! $client_ping2 ) {
176 diag( "WARNING: Your platform/SSL library does not support renegotiation of the SSL socket." );
177 diag( "This test harness detected that trying to renegotiate resulted in a disconnected socket." );
178 diag( "POE::Component::SSLify will work on your system, but please do not attempt a SSL renegotiate." );
179 diag( "Please talk with the author to figure out if this issue can be worked around, thank you!" );
180 }
181
182 pass( 'shut down sanely' );
183
184 exit 0;
0 #!/usr/bin/perl
1 #
2 # This file is part of POE-Component-SSLify
3 #
4 # This software is copyright (c) 2011 by Apocalypse.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 use strict; use warnings;
10 use strict; use warnings;
11
12 # Thanks to ASCENT for this test!
13 # This test adds renegotiation to the connection from client-side
14 # Since this is not supported on all platforms, it's marked TODO and adds custom logic
15 # to make sure it doesn't FAIL if it's not supported.
16
17 # this version of the test doesn't work as reported in http://rt.cpan.org/Public/Bug/Display.html?id=66741
18 # renamed it to this version for posterity and in case I need it for future analysis...
19
20 #my $numtests;
21 #BEGIN {
22 # $numtests = 23;
23 #
24 # eval "use Test::NoWarnings";
25 # if ( ! $@ ) {
26 # # increment by one
27 # $numtests++;
28 # }
29 #}
30
31 #use Test::More tests => $numtests;
32 use Test::More;
33 BEGIN {
34 plan skip_all => "AUTHOR TEST";
35 }
36
37 use POE 1.267;
38 use POE::Component::Client::TCP;
39 use POE::Component::Server::TCP;
40 use POE::Component::SSLify qw/Client_SSLify Server_SSLify SSLify_Options SSLify_GetCipher SSLify_ContextCreate SSLify_GetSocket SSLify_GetSSL/;
41 use Net::SSLeay qw/ERROR_WANT_READ ERROR_WANT_WRITE/;
42
43 # TODO rewrite this to use Test::POE::Server::TCP and stuff :)
44
45 my $port;
46 my $server_ping2;
47 my $client_ping2;
48
49 POE::Component::Server::TCP->new
50 (
51 Alias => 'myserver',
52 Address => '127.0.0.1',
53 Port => 0,
54
55 Started => sub
56 {
57 use Socket qw/sockaddr_in/;
58 $port = (sockaddr_in($_[HEAP]->{listener}->getsockname))[0];
59 },
60 ClientConnected => sub
61 {
62 ok(1, 'SERVER: accepted');
63 },
64 ClientDisconnected => sub
65 {
66 ok(1, 'SERVER: client disconnected');
67 $_[KERNEL]->post(myserver => 'shutdown');
68 },
69 ClientPreConnect => sub
70 {
71 eval { SSLify_Options('mylib/example.key', 'mylib/example.crt', 'sslv3') };
72 eval { SSLify_Options('../mylib/example.key', '../mylib/example.crt', 'sslv3') } if ($@);
73 ok(!$@, "SERVER: SSLify_Options $@");
74
75 my $socket = eval { Server_SSLify($_[ARG0]) };
76 ok(!$@, "SERVER: Server_SSLify $@");
77 ok(1, 'SERVER: SSLify_GetCipher: '. SSLify_GetCipher($socket));
78
79 # We pray that IO::Handle is sane...
80 ok( SSLify_GetSocket( $socket )->blocking == 0, 'SERVER: SSLified socket is non-blocking?');
81
82 return ($socket);
83 },
84 ClientInput => sub
85 {
86 my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0];
87
88 ## At this point, connection MUST be encrypted.
89 my $cipher = SSLify_GetCipher($heap->{client}->get_output_handle);
90 ok($cipher ne '(NONE)', "SERVER: SSLify_GetCipher: $cipher");
91
92 if ($request eq 'ping')
93 {
94 ok(1, "SERVER: recv: $request");
95 $heap->{client}->put("pong");
96 }
97 elsif ($request eq 'ping2')
98 {
99 ok(1, "SERVER: recv: $request");
100 $server_ping2++;
101 $heap->{client}->put("pong2");
102 }
103 },
104 ClientError => sub
105 {
106 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
107 # The default PoCo::Server::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
108 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
109
110 # TODO are there other "errors" that is harmless?
111 $error = "Normal disconnection" unless $error;
112 my $msg = "Got SERVER $syscall error $errno: $error";
113 unless ( $syscall eq 'read' and $errno == 0 ) {
114 fail( $msg );
115 } else {
116 diag( $msg ) if $ENV{TEST_VERBOSE};
117 }
118 },
119 );
120
121 POE::Component::Client::TCP->new
122 (
123 Alias => 'myclient',
124 RemoteAddress => '127.0.0.1',
125 RemotePort => $port,
126
127 Connected => sub
128 {
129 ok(1, 'CLIENT: connected');
130
131 $_[HEAP]->{server}->put("ping");
132 },
133 PreConnect => sub
134 {
135 my $ctx = eval { SSLify_ContextCreate(undef, undef, 'sslv3') };
136 ok(!$@, "CLIENT: SSLify_ContextCreate $@");
137 my $socket = eval { Client_SSLify($_[ARG0], undef, undef, $ctx) };
138 ok(!$@, "CLIENT: Client_SSLify $@");
139 ok(1, 'CLIENT: SSLify_GetCipher: '. SSLify_GetCipher($socket));
140
141 # We pray that IO::Handle is sane...
142 ok( SSLify_GetSocket( $socket )->blocking == 0, 'CLIENT: SSLified socket is non-blocking?');
143
144 return ($socket);
145 },
146 ServerInput => sub
147 {
148 my ($kernel, $heap, $line) = @_[KERNEL, HEAP, ARG0];
149
150 ## At this point, connection MUST be encrypted.
151 my $cipher = SSLify_GetCipher($heap->{server}->get_output_handle);
152 ok($cipher ne '(NONE)', "CLIENT: SSLify_GetCipher: $cipher");
153
154 if ($line eq 'pong')
155 {
156 ok(1, "CLIENT: recv: $line");
157
158 # Skip 2 Net::SSLeay::renegotiate() tests on FreeBSD because of
159 # http://security.freebsd.org/advisories/FreeBSD-SA-09:15.ssl.asc
160 TODO: {
161 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
162
163 ## Force SSL renegotiation
164 my $ssl = SSLify_GetSSL( $heap->{server}->get_output_handle );
165 my $reneg_num = Net::SSLeay::num_renegotiations($ssl);
166
167 ok(1 == Net::SSLeay::renegotiate($ssl), 'CLIENT: SSL renegotiation');
168 my $handshake = Net::SSLeay::do_handshake($ssl);
169 my $err = Net::SSLeay::get_error($ssl, $handshake);
170
171 ## 1 == Successful handshake, ERROR_WANT_(READ|WRITE) == non-blocking.
172 ok($handshake == 1 || $err == ERROR_WANT_READ || $err == ERROR_WANT_WRITE, 'CLIENT: SSL handshake');
173 ok($reneg_num < Net::SSLeay::num_renegotiations($ssl), 'CLIENT: Increased number of negotiations');
174 }
175
176 $heap->{server}->put('ping2');
177 }
178
179 elsif ($line eq 'pong2')
180 {
181 ok(1, "CLIENT: recv: $line");
182 $client_ping2++;
183 $kernel->yield('shutdown');
184 }
185 },
186 ServerError => sub
187 {
188 # Thanks to H. Merijn Brand for spotting this FAIL in 5.12.0!
189 # The default PoCo::Client::TCP handler will throw a warning, which causes Test::NoWarnings to FAIL :(
190 my ($syscall, $errno, $error) = @_[ ARG0..ARG2 ];
191
192 # TODO are there other "errors" that is harmless?
193 $error = "Normal disconnection" unless $error;
194 my $msg = "Got CLIENT $syscall error $errno: $error";
195 unless ( $syscall eq 'read' and $errno == 0 ) {
196 fail( $msg );
197 } else {
198 diag( $msg ) if $ENV{TEST_VERBOSE};
199 }
200 },
201 );
202
203 $poe_kernel->run();
204
205 # Add extra pass() to make the test harness happy if renegotiate did not work
206 if ( ! $server_ping2 ) {
207 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
208 fail( "SERVER: Failed SSL renegotiation" );
209 }
210 if ( ! $client_ping2 ) {
211 local $TODO = "Net::SSLeay::renegotiate() does not work on all platforms";
212 fail( "CLIENT: Failed SSL renegotiation" );
213 }
214 if ( ! $server_ping2 or ! $client_ping2 ) {
215 diag( "WARNING: Your platform/SSL library does not support renegotiation of the SSL socket." );
216 diag( "This test harness detected that trying to renegotiate resulted in a disconnected socket." );
217 diag( "POE::Component::SSLify will work on your system, but please do not attempt a SSL renegotiate." );
218 diag( "Please talk with the author to figure out if this issue can be worked around, thank you!" );
219 }
220
221 pass( 'shut down sanely' );
222
223 exit 0;
0 #!/usr/bin/perl
1 #
2 # This file is part of POE-Component-SSLify
3 #
4 # This software is copyright (c) 2011 by Apocalypse.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 use strict; use warnings;
10
11 # Test contributed by mire@irc which used this to hit the WRITE_WANTS_READ case
12 # mire created package Ub because he couldn't reproduce it with poco-cl-http :(
13 # tweaked slightly to turn it into a real testcase ( not done yet )
14
15 BEGIN {
16 # sub POE::Kernel::ASSERT_DEFAULT () { 1 }
17 # sub POE::Kernel::TRACE_STATISTICS () { 0 } # makes POE hang, it's been removed in git but not in 1.299 heh
18 # sub POE::Kernel::TRACE_DEFAULT () { 1 }
19 # sub POE::Kernel::CATCH_EXCEPTIONS () { 0 } # make sure we die right away so it's easier to debug
20 }
21
22 use strict;
23 use warnings;
24 use POE;
25
26 use Test::More;
27 BEGIN {
28 plan skip_all => "AUTHOR TEST";
29 }
30
31 our $DEBUG=0;
32
33 package Ub;
34 use strict;
35 use warnings;
36 use POE qw( Component::Client::TCP Filter::Stream );
37 use POE::Component::SSLify qw( Client_SSLify );
38
39 # non-core deps
40 BEGIN {
41 eval "use POE::Filter::HTTPChunk; use HTTP::Parser; use HTTP::Response;";
42 if ( $@ ) {
43 use Test::More;
44 plan skip_all => "Unable to load deps: $@";
45 }
46 }
47
48 sub new {
49 my $this = shift;
50 my %p = @_;
51
52 my $class = ref($this) || $this;
53 my $self = {};
54 bless $self, $class;
55
56 $self->{'_p'} = \%p;
57
58 return $self;
59 }
60
61 sub spawn {
62 my $self = shift;
63
64 my $session_id = POE::Session->create(
65 inline_states => {
66 _child => sub {},
67 _start => sub {
68 my ($kernel, $heap) = @_[KERNEL, HEAP];
69 ($heap->{'self'}) = @_[ARG0..$#_];
70 print 'INFO: ' . __PACKAGE__ . "_start\n"
71 if $main::DEBUG;
72 $kernel->alias_set( 'ub' );
73 #$_[KERNEL]->refcount_increment($_[SESSION]->ID, 'ub');
74 },
75 _stop => sub {
76 my ($kernel, $heap) = @_[KERNEL, HEAP];
77 print 'INFO: ' . __PACKAGE__ . "_stop\n"
78 if $main::DEBUG;
79 $heap = {};
80 },
81 on_shutdown => sub {
82 print 'INFO: ' . __PACKAGE__ . "on_shutdown\n"
83 if $main::DEBUG;
84 },
85 _shutdown => sub {
86 print 'INFO: ' . __PACKAGE__ . "_shutdown\n"
87 if $main::DEBUG;
88 },
89 r => sub {
90 my ($kernel, $heap, $ev_res, $cont_ref, $host, $port, $do_ssl) = @_[KERNEL, HEAP, ARG0..$#_];
91
92 my $s_res = $_[SENDER]->ID;
93
94 # TODO pravi alarm za ubijanje konekcije
95 my $tcp_sid = POE::Component::Client::TCP->new(
96 #SessionParams => [ options => { debug => 1, trace => 1 } ],
97 # SessionParams => [ options => { debug => 1 } ],
98 Args => [$s_res, $ev_res, $cont_ref, $do_ssl],
99 Filter => "POE::Filter::Stream",
100 RemoteAddress => $host,
101 RemotePort => $port,
102 ConnectTimeout => 30,
103 Started => sub {
104 my ($kernel, $heap) = @_[KERNEL, HEAP];
105 print "INFO: Started\n"
106 if $main::DEBUG;
107 (@$heap{qw|s_res ev_res cont_ref do_ssl|}) = @_[ARG0..$#_];
108 },
109 PreConnect => sub {
110 my ($kernel, $heap) = @_[KERNEL, HEAP];
111
112 print "INFO: PreConnect\n"
113 if $main::DEBUG;
114
115 $heap->{'parser'} = HTTP::Parser->new(response => 1);
116
117 return $_[ARG0]
118 unless $heap->{'do_ssl'};
119
120 # Convert the socket into an SSL socket.
121 my $socket = eval { Client_SSLify($_[ARG0]) };
122
123 # Disconnect if SSL failed.
124 if ($@) {
125 warn $@ if $main::DEBUG;
126 return;
127 }
128 # Return the SSL-ified socket.
129 return $socket;
130 },
131 ConnectError => sub {
132 my ($kernel, $heap) = @_[KERNEL, HEAP];
133 #print Dumper $heap; exit;
134 my ($operation, $error_number, $error_string) = @_[ARG0..ARG2];
135 print "ERROR: ConnectError $operation error $error_number occurred: $error_string\n"
136 if $main::DEBUG;
137 my $dc = '';
138 $kernel->post($heap->{'s_res'}, $heap->{'ev_res'}, {'error' => 1, 'error_type' => 'connect_error', 'content' => \$dc});
139 $_[KERNEL]->yield('shutdown');
140 },
141 ServerError => sub {
142 my ($kernel, $heap) = @_[KERNEL, HEAP];
143 my ($operation, $error_number, $error_string) = @_[ARG0..ARG2];
144
145 print "not informing master session, ERROR: ServerError $operation error $error_number occurred: $error_string\n"
146 if $main::DEBUG;
147 $kernel->yield('shutdown');
148 },
149 Connected => sub {
150 my ($kernel, $heap) = @_[KERNEL, HEAP];
151 print "INFO: Connected\n"
152 if $main::DEBUG;
153 $heap->{server}->put(${$heap->{'cont_ref'}});
154 # start timeout thing
155 # za pravu shutdown funkciju
156 $heap->{'al_cest_id'} = $_[KERNEL]->alarm_set( shutdown => time + 60 );
157 },
158 ServerInput => sub {
159 my ($kernel, $heap) = @_[KERNEL, HEAP];
160 print "INFO: ServerInput\n"
161 if $main::DEBUG;
162 my $input = $_[ARG0];
163 #print 'from server: ' . Dumper $input;
164 eval {
165 $heap->{'parser'}->add($input);
166 };
167 # TODO error response
168 $kernel->yield('shutdown')
169 if $@;
170 },
171 ServerFlushed => sub {
172 print "INFO: ServerFlushed\n"
173 if $main::DEBUG;
174 },
175 Disconnected => sub {
176 my ($kernel, $heap) = @_[KERNEL, HEAP];
177 print "INFO: disconnected ;)\n"
178 if $main::DEBUG;
179 my $dc = '';
180 $dc = $heap->{'parser'}->object->decoded_content
181 if $heap->{'parser'}->object;
182 $kernel->post($heap->{'s_res'}, $heap->{'ev_res'}, {'error' => 0, 'error_type' => '', 'content' => \$dc});
183 $_[KERNEL]->alarm_remove(delete $heap->{'al_cest_id'})
184 if (exists $heap->{'al_cest_id'} and $heap->{'al_cest_id'});
185 $_[KERNEL]->yield('shutdown');
186 },
187
188 );
189 print "tcp_sid: $tcp_sid\n"
190 if $main::DEBUG;
191
192 },
193 },
194 'args' => [$self],
195 )->ID;
196
197 return $session_id;
198 }
199
200 1;
201
202 package main;
203
204 my $ub = Ub->new()->spawn();
205
206
207
208
209 my $session_id_test = POE::Session->create(
210 inline_states => {
211 _start => sub {
212 my ($kernel, $heap) = @_[KERNEL, HEAP];
213 ($heap->{'self'}) = @_[ARG0..$#_];
214 print 'INFO: ' . __PACKAGE__ . "_start\n"
215 if $main::DEBUG;
216 $kernel->yield('test');
217 },
218 _stop => sub {
219 my ($kernel, $heap) = @_[KERNEL, HEAP];
220 print 'INFO: ' . __PACKAGE__ . "_stop\n"
221 if $main::DEBUG;
222 $heap = {};
223 },
224 on_shutdown => sub {
225 print 'INFO: ' . __PACKAGE__ . "on_shutdown\n"
226 if $main::DEBUG;
227 },
228 _shutdown => sub {
229 print 'INFO: ' . __PACKAGE__ . "_shutdown\n"
230 if $main::DEBUG;
231 },
232 test => sub {
233 my ($kernel, $heap) = @_[KERNEL, HEAP];
234 my ($cont, $host, $port, $do_ssl);
235
236 $kernel->refcount_increment($_[SESSION]->ID, 'test');
237
238 if (1) {
239 $host = '0ne.us';
240 $port = 443;
241 $do_ssl = 1;
242
243 $cont = <<'EOF';
244 GET /get.php HTTP/1.1
245 Host: osadmin.com
246 User-Agent: proba 123
247 Connection: close
248
249
250 EOF
251
252 }
253 $kernel->post('ub', 'r', 'test_res', \$cont, $host, $port, $do_ssl);
254
255 },
256 test_res => sub {
257 my ($kernel, $heap, $dat) = @_[KERNEL, HEAP, ARG0..$#_];
258 $kernel->refcount_decrement($_[SESSION]->ID, 'test');
259 my $cont = ${$dat->{'content'}};
260 chomp $cont;
261 warn $cont;
262 die "HIT BUG" if length $cont == 0;
263 $kernel->yield('test');
264 return;
265 },
266 },)->ID;
267
268 POE::Kernel->run();
269 exit;