1POE::Component::SSLify(U3s)er Contributed Perl DocumentatPiOoEn::Component::SSLify(3)
2
3
4
6 Client-side usage
7
8 # Import the module
9 use POE::Component::SSLify qw( Client_SSLify );
10
11 # Create a normal SocketFactory wheel or something
12 my $factory = POE::Wheel::SocketFactory->new( ... );
13
14 # Converts the socket into a SSL socket POE can communicate with
15 eval { $socket = Client_SSLify( $socket ) };
16 if ( $@ ) {
17 # Unable to SSLify it...
18 }
19
20 # Now, hand it off to ReadWrite
21 my $rw = POE::Wheel::ReadWrite->new(
22 Handle => $socket,
23 ...
24 );
25
26 # Use it as you wish...
27
28 Server-side usage
29
30 # !!! Make sure you have a public key + certificate generated via Net::SSLeay's makecert.pl
31
32 # Import the module
33 use POE::Component::SSLify qw( Server_SSLify SSLify_Options SSLify_GetCTX );
34
35 # Set the key + certificate file
36 eval { SSLify_Options( 'public-key.pem', 'public-cert.pem' ) };
37 if ( $@ ) {
38 # Unable to load key or certificate file...
39 }
40
41 # Ah, I want to set some options ( not required )
42 # my $ctx = SSLify_GetCTX();
43 # Net::SSLeay::CTX_set_options( $ctx, foo );
44
45 # Create a normal SocketFactory wheel or something
46 my $factory = POE::Wheel::SocketFactory->new( ... );
47
48 # Converts the socket into a SSL socket POE can communicate with
49 eval { $socket = Server_SSLify( $socket ) };
50 if ( $@ ) {
51 # Unable to SSLify it...
52 }
53
54 # Now, hand it off to ReadWrite
55 my $rw = POE::Wheel::ReadWrite->new(
56 Handle => $socket,
57 ...
58 );
59
60 # Use it as you wish...
61
63 Makes SSL use in POE a breeze!
64
66 This component represents the standard way to do SSL in POE.
67
69 Socket methods doesn't work
70
71 The new socket this module gives you actually is some tied socket
72 magic, so you cannot do stuff like getpeername() or getsockname(). The
73 only way to do it is to use SSLify_GetSocket and then operate on the
74 socket it returns.
75
76 Dying everywhere...
77
78 This module will die() if Net::SSLeay could not be loaded or it is not
79 the version we want. So, it is recommended that you check for errors
80 and not use SSL, like so:
81
82 eval { use POE::Component::SSLify };
83 if ( $@ ) {
84 $sslavailable = 0;
85 } else {
86 $sslavailable = 1;
87 }
88
89 # Make socket SSL!
90 if ( $sslavailable ) {
91 eval { $socket = POE::Component::SSLify::Client_SSLify( $socket ) };
92 if ( $@ ) {
93 # Unable to SSLify the socket...
94 }
95 }
96
98 Client_SSLify
99
100 Accepts a socket, returns a brand new socket SSLified
101
102 Server_SSLify
103
104 Accepts a socket, returns a brand new socket SSLified
105
106 NOTE: SSLify_Options must be set first!
107
108 SSLify_Options
109
110 Accepts the location of the SSL key + certificate files and does it's job
111
112 SSLify_GetCTX
113
114 Returns the server-side CTX in case you wanted to play around with it :)
115
116 SSLify_GetCipher
117
118 Returns the cipher used by the SSLified socket
119
120 Example:
121 print "SSL Cipher is: " . SSLify_GetCipher( $sslified_sock ) . "\n";
122
123 SSLify_GetSocket
124
125 Returns the actual socket used by the SSLified socket, useful for stuff like getpeername()/getsockname()
126
127 Example:
128 print "Remote IP is: " . ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $sslified_sock ) ) ) )[0] . "\n";
129
131 Stuffs all the 4 functions in @EXPORT_OK so you have to request them directly
132
134 On Win32 platforms SSL support is pretty shaky, please help me out with
135 detailed error descriptions if it happens to you!
136
138 POE
139
140 Net::SSLeay
141
143 Apocalypse <apocal@cpan.org>
144
146 Original code is entirely Rocco Caputo ( Creator of POE ) -> I simply
147 packaged up the code into something everyone could use and accepted the burden
148 of maintaining it :)
149
150 From the PoCo::Client::HTTP code =]
151 # TODO - This code should probably become a POE::Kernel method,
152 # seeing as it's rather baroque and potentially useful in a number
153 # of places.
154
156 Copyright 2007 by Apocalypse/Rocco Caputo
157
158 This library is free software; you can redistribute it and/or modify it
159 under the same terms as Perl itself.
160
161
162
163perl v5.8.8 2007-05-02 POE::Component::SSLify(3)