55 | 55 |
|
56 | 56 |
my $socket = shift;
|
57 | 57 |
$socket = Client_SSLify( $socket, $version, $options, $ctx, $callback );
|
58 | |
$socket is the non-ssl socket you got from somewhere ( probably SocketFactory )
|
|
58 |
$socket is the non-ssl socket you got from somewhere ( probably POE::Wheel::SocketFactory )
|
59 | 59 |
$version is the SSL version you want to use, see SSLify_ContextCreate
|
60 | 60 |
$options is the SSL options you want to use, see SSLify_ContextCreate
|
61 | 61 |
$ctx is the custom SSL context you want to use, see SSLify_ContextCreate
|
62 | 62 |
$callback is the callback hook on success/failure of sslification
|
63 | 63 |
|
|
64 |
# This is an example of the callback and you should pass it as Client_SSLify( ... \&callback );
|
64 | 65 |
sub callback {
|
65 | 66 |
my( $socket, $status, $errval ) = @_;
|
66 | 67 |
# $socket is the original sslified socket in case you need to play with it
|
67 | |
# $status is either 'OK' or 'ERR'
|
68 | |
# $errval will be defined if $status eq 'ERR' - it's the numeric SSL error code
|
|
68 |
# $status is either 1 or 0; with 1 signifying success and 0 failure
|
|
69 |
# $errval will be defined if $status == 0; it's the numeric SSL error code
|
|
70 |
# check http://www.openssl.org/docs/ssl/SSL_get_error.html for the possible error values ( and import them from Net::SSLeay! )
|
|
71 |
|
|
72 |
# The return value from the callback is discarded
|
69 | 73 |
}
|
70 | 74 |
|
71 | 75 |
If $ctx is defined, SSLify will ignore $version and $options. Otherwise, it will be created from the $version and
|
|
83 | 87 |
NOTE: You can pass the callback anywhere in the arguments, we'll figure it out for you! If you want to call a POE event, please look
|
84 | 88 |
into the postback/callback stuff in L<POE::Session>.
|
85 | 89 |
|
86 | |
$socket = Client_SSLify( $socket, $session->callback( 'got_connect' => @args ) );
|
87 | |
|
|
90 |
# we got this from POE::Wheel::SocketFactory
|
|
91 |
sub event_SuccessEvent {
|
|
92 |
my $socket = $_[ARG0];
|
|
93 |
$socket = Client_SSLify( $socket, $_[SESSION]->callback( 'sslify_result' ) );
|
|
94 |
$_[HEAP]->{client} = POE::Wheel::ReadWrite->new(
|
|
95 |
Handle => $socket,
|
|
96 |
...
|
|
97 |
);
|
|
98 |
return;
|
|
99 |
}
|
|
100 |
|
|
101 |
# the callback event
|
|
102 |
sub event_sslify_result {
|
|
103 |
my ($creation_args, $called_args) = @_[ARG0, ARG1];
|
|
104 |
my( $socket, $status, $errval ) = @$called_args;
|
|
105 |
|
|
106 |
if ( $status ) {
|
|
107 |
print "Yay, SSLification worked!";
|
|
108 |
} else {
|
|
109 |
print "Aw, SSLification failed with error $errval";
|
|
110 |
}
|
|
111 |
}
|
88 | 112 |
=cut
|
89 | 113 |
|
90 | 114 |
sub Client_SSLify {
|
|
138 | 162 |
$ctx is the custom SSL context you want to use, see SSLify_ContextCreate ( overrides the global set in SSLify_Options )
|
139 | 163 |
$callback is the callback hook on success/failure of sslification
|
140 | 164 |
|
141 | |
sub callback {
|
142 | |
my( $socket, $status, $errval ) = @_;
|
143 | |
# $socket is the original sslified socket in case you need to play with it
|
144 | |
# $status is either 'OK' or 'ERR'
|
145 | |
# $errval will be defined if $status eq 'ERR' - it's the numeric SSL error code
|
146 | |
}
|
147 | |
|
148 | |
NOTE: SSLify_Options must be set first if you aren't passing a $ctx. If you want to set some options per-connection, do this:
|
|
165 |
Please look at L</Client_SSLify> for more details on the callback hook.
|
|
166 |
|
|
167 |
SSLify_Options must be set first if you aren't passing a $ctx. If you want to set some options per-connection, do this:
|
149 | 168 |
|
150 | 169 |
my $socket = shift; # get the socket from somewhere
|
151 | 170 |
my $ctx = SSLify_ContextCreate();
|
|
154 | 173 |
|
155 | 174 |
NOTE: You can use SSLify_GetCTX to modify the global, and avoid doing this on every connection if the
|
156 | 175 |
options are the same...
|
157 | |
|
158 | |
NOTE: You can pass the callback anywhere in the arguments, we'll figure it out for you! If you want to call a POE event, please look
|
159 | |
into the postback/callback stuff in POE::Session.
|
160 | |
|
161 | |
$socket = Server_SSLify( $socket, $session->callback( 'got_connect' => @args ) );
|
162 | 176 |
=cut
|
163 | 177 |
|
164 | 178 |
sub Server_SSLify {
|