46 | 46 |
|
47 | 47 |
=func Client_SSLify
|
48 | 48 |
|
49 | |
Accepts a socket, returns a brand new socket SSLified. Optionally accepts SSL
|
50 | |
context data.
|
51 | |
my $socket = shift; # get the socket from somewhere
|
52 | |
$socket = Client_SSLify( $socket ); # the default
|
53 | |
$socket = Client_SSLify( $socket, $version, $options ); # sets more options for the context
|
54 | |
$socket = Client_SSLify( $socket, undef, undef, $ctx ); # pass in a custom context
|
55 | |
|
56 | |
If $ctx is defined, SSLify will ignore other args. If $ctx isn't defined, SSLify
|
57 | |
will create it from the $version + $options parameters.
|
58 | |
|
59 | |
Known versions:
|
60 | |
* sslv2
|
61 | |
* sslv3
|
62 | |
* tlsv1
|
63 | |
* default
|
64 | |
|
65 | |
By default we use the version: default
|
66 | |
|
67 | |
By default we don't set any options
|
68 | |
|
69 | |
NOTE: The way to have a client socket with proper certificates set up is:
|
70 | |
my $socket = shift; # get the socket from somewhere
|
71 | |
my $ctx = SSLify_ContextCreate( 'server.key', 'server.crt' );
|
72 | |
$socket = Client_SSLify( $socket, undef, undef, $ctx );
|
73 | |
|
74 | |
BEWARE: If you passed in a CTX, SSLify will do Net::SSLeay::CTX_free( $ctx ) when the
|
75 | |
socket is destroyed. This means you cannot reuse contexts!
|
|
49 |
Accepts a socket, returns a brand new socket SSLified. Optionally accepts SSL
|
|
50 |
context data. Also accepts a subref to call when connection/negotiation is done.
|
|
51 |
|
|
52 |
my $socket = shift; # get the socket from somewhere
|
|
53 |
$socket = Client_SSLify( $socket ); # the default
|
|
54 |
$socket = Client_SSLify( $socket, $version, $options ); # sets more options for the context
|
|
55 |
$socket = Client_SSLify( $socket, undef, undef, $ctx ); # pass in a custom context
|
|
56 |
$socket = Client_SSLify( $socket, sub { print "CONNECTED" } ); # call your connection function
|
|
57 |
|
|
58 |
If $ctx is defined, SSLify will ignore other args. If $ctx isn't defined, SSLify
|
|
59 |
will create it from the $version + $options parameters.
|
|
60 |
|
|
61 |
Known versions:
|
|
62 |
* sslv2
|
|
63 |
* sslv3
|
|
64 |
* tlsv1
|
|
65 |
* default
|
|
66 |
|
|
67 |
By default we use the version: default
|
|
68 |
|
|
69 |
By default we don't set any options
|
|
70 |
|
|
71 |
NOTE: The way to have a client socket with proper certificates set up is:
|
|
72 |
|
|
73 |
my $socket = shift; # get the socket from somewhere
|
|
74 |
my $ctx = SSLify_ContextCreate( 'server.key', 'server.crt' );
|
|
75 |
$socket = Client_SSLify( $socket, undef, undef, $ctx );
|
|
76 |
|
|
77 |
BEWARE: If you passed in a CTX, SSLify will do Net::SSLeay::CTX_free( $ctx ) when the
|
|
78 |
socket is destroyed. This means you cannot reuse contexts!
|
|
79 |
|
|
80 |
NOTE: You can pass the subref anywhere in the arguments, we'll figure it out for you! If you want to call a POE event, please look
|
|
81 |
into the postback/callback stuff in POE::Session. The subref will get the socket as the sole argument.
|
|
82 |
|
|
83 |
$socket = Client_SSLify( $socket, $session->callback( 'got_connect' => @args ) );
|
76 | 84 |
=cut
|
77 | 85 |
|
78 | 86 |
sub Client_SSLify {
|
79 | 87 |
# Get the socket + version + options + ctx
|
80 | |
my( $socket, $version, $options, $ctx ) = @_;
|
|
88 |
my( $socket, $version, $options, $ctx, $connref ) = @_;
|
81 | 89 |
|
82 | 90 |
# Validation...
|
83 | 91 |
if ( ! defined $socket ) {
|
84 | 92 |
die "Did not get a defined socket";
|
|
93 |
}
|
|
94 |
|
|
95 |
# Mangle the connref stuff
|
|
96 |
if ( defined $version and ref $version and ref( $version ) eq 'CODE' ) {
|
|
97 |
$connref = $version;
|
|
98 |
$version = $options = $ctx = undef;
|
|
99 |
} elsif ( defined $options and ref $options and ref( $options ) eq 'CODE' ) {
|
|
100 |
$connref = $options;
|
|
101 |
$options = $ctx = undef;
|
|
102 |
} elsif ( defined $ctx and ref $ctx and ref( $ctx ) eq 'CODE' ) {
|
|
103 |
$connref = $ctx;
|
|
104 |
$ctx = undef;
|
85 | 105 |
}
|
86 | 106 |
|
87 | 107 |
# From IO::Handle POD
|
|
92 | 112 |
|
93 | 113 |
# Now, we create the new socket and bind it to our subclass of Net::SSLeay::Handle
|
94 | 114 |
my $newsock = gensym();
|
95 | |
tie( *$newsock, 'POE::Component::SSLify::ClientHandle', $socket, $version, $options, $ctx ) or die "Unable to tie to our subclass: $!";
|
|
115 |
tie( *$newsock, 'POE::Component::SSLify::ClientHandle', $socket, $version, $options, $ctx, $connref ) or die "Unable to tie to our subclass: $!";
|
96 | 116 |
|
97 | 117 |
# All done!
|
98 | 118 |
return $newsock;
|
|
100 | 120 |
|
101 | 121 |
=func Server_SSLify
|
102 | 122 |
|
103 | |
Accepts a socket, returns a brand new socket SSLified
|
104 | |
my $socket = shift; # get the socket from somewhere
|
105 | |
$socket = Server_SSLify( $socket );
|
106 | |
|
107 | |
NOTE: SSLify_Options must be set first!
|
108 | |
|
109 | |
Furthermore, you can pass in your own $ctx object if you desire. This allows you to set custom parameters
|
110 | |
per-connection, for example.
|
111 | |
my $socket = shift; # get the socket from somewhere
|
112 | |
my $ctx = SSLify_ContextCreate();
|
113 | |
# set various options on $ctx as desired
|
114 | |
$socket = Server_SSLify( $socket, $ctx );
|
115 | |
|
116 | |
NOTE: You can use SSLify_GetCTX to modify the global, and avoid doing this on every connection if the
|
117 | |
options are the same...
|
|
123 |
Accepts a socket, returns a brand new socket SSLified. Also accepts a custom context. Also accepts a subref
|
|
124 |
to call when connection/negotiation is done.
|
|
125 |
|
|
126 |
my $socket = shift; # get the socket from somewhere
|
|
127 |
$socket = Server_SSLify( $socket );
|
|
128 |
$socket = Server_SSLify( $socket, $ctx ); # use your custom context
|
|
129 |
$socket = Server_SSLify( $socket, sub { print "CONNECTED" } ); # call your connection function
|
|
130 |
|
|
131 |
NOTE: SSLify_Options must be set first!
|
|
132 |
|
|
133 |
Furthermore, you can pass in your own $ctx object if you desire. This allows you to set custom parameters
|
|
134 |
per-connection, for example.
|
|
135 |
|
|
136 |
my $socket = shift; # get the socket from somewhere
|
|
137 |
my $ctx = SSLify_ContextCreate();
|
|
138 |
# set various options on $ctx as desired
|
|
139 |
$socket = Server_SSLify( $socket, $ctx );
|
|
140 |
|
|
141 |
NOTE: You can use SSLify_GetCTX to modify the global, and avoid doing this on every connection if the
|
|
142 |
options are the same...
|
|
143 |
|
|
144 |
NOTE: You can pass the subref anywhere in the arguments, we'll figure it out for you! If you want to call a POE event, please look
|
|
145 |
into the postback/callback stuff in POE::Session. The subref will get the socket as the sole argument.
|
|
146 |
|
|
147 |
$socket = Server_SSLify( $socket, $session->callback( 'got_connect' => @args ) );
|
118 | 148 |
=cut
|
119 | 149 |
|
120 | 150 |
sub Server_SSLify {
|
121 | 151 |
# Get the socket!
|
122 | |
my $socket = shift;
|
123 | |
my $custom_ctx = shift;
|
|
152 |
my( $socket, $custom_ctx, $connref ) = @_;
|
124 | 153 |
|
125 | 154 |
# Validation...
|
126 | 155 |
if ( ! defined $socket ) {
|
|
130 | 159 |
# If we don't have a ctx ready, we can't do anything...
|
131 | 160 |
if ( ! defined $ctx and ! defined $custom_ctx ) {
|
132 | 161 |
die 'Please do SSLify_Options() first ( or pass in a $ctx object )';
|
|
162 |
}
|
|
163 |
|
|
164 |
# mangle custom_ctx depending on connref
|
|
165 |
if ( ref $custom_ctx and ref( $custom_ctx ) eq 'CODE' ) {
|
|
166 |
$connref = $custom_ctx;
|
|
167 |
$custom_ctx = $ctx;
|
133 | 168 |
}
|
134 | 169 |
|
135 | 170 |
# From IO::Handle POD
|
|
140 | 175 |
|
141 | 176 |
# Now, we create the new socket and bind it to our subclass of Net::SSLeay::Handle
|
142 | 177 |
my $newsock = gensym();
|
143 | |
tie( *$newsock, 'POE::Component::SSLify::ServerHandle', $socket, ( $custom_ctx || $ctx ) ) or die "Unable to tie to our subclass: $!";
|
|
178 |
tie( *$newsock, 'POE::Component::SSLify::ServerHandle', $socket, $custom_ctx, $connref ) or die "Unable to tie to our subclass: $!";
|
144 | 179 |
|
145 | 180 |
# All done!
|
146 | 181 |
return $newsock;
|