tweak example a bit and add note about SSLify_GetCipher
Apocalypse
13 years ago
38 | 38 |
$socket = Server_SSLify( $socket );
|
39 | 39 |
|
40 | 40 |
# testing stuff
|
41 | |
warn "got connection from: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $socket ) ) ) )[1] ) . " cipher type: " . SSLify_GetCipher( $socket );
|
|
41 |
warn "got connection from: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $socket ) ) ) )[1] ) . " cipher type: " . SSLify_GetCipher( $socket ) . "\n";
|
42 | 42 |
|
43 | 43 |
# Hand it off to ReadWrite
|
44 | 44 |
my $wheel = POE::Wheel::ReadWrite->new(
|
|
64 | 64 |
'Got_Input' => sub {
|
65 | 65 |
# ARG0: The Line, ARG1: Wheel ID
|
66 | 66 |
|
|
67 |
# testing stuff
|
|
68 |
my $socket = $_[HEAP]->{'WHEELS'}->{ $_[ARG1] }->get_output_handle();
|
|
69 |
warn "got input from: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $socket ) ) ) )[1] ) . " cipher type: (" . SSLify_GetCipher( $socket ) . ") input: '$_[ARG0]'\n";
|
|
70 |
|
67 | 71 |
# Send back to the client the line!
|
68 | 72 |
$_[HEAP]->{'WHEELS'}->{ $_[ARG1] }->put( $_[ARG0] );
|
69 | 73 |
return 1;
|
37 | 37 |
my $socket = $_[ ARG0 ];
|
38 | 38 |
|
39 | 39 |
# testing stuff
|
40 | |
warn "got connection from: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( $socket ) ) )[1] ) . " - commencing Server_SSLify()";
|
|
40 |
warn "got connection from: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( $socket ) ) )[1] ) . " - commencing Server_SSLify()\n";
|
41 | 41 |
|
42 | 42 |
# SSLify it!
|
43 | 43 |
$socket = Server_SSLify( $socket );
|
44 | 44 |
|
45 | 45 |
# testing stuff
|
46 | |
warn "SSLified: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $socket ) ) ) )[1] ) . " cipher type: " . SSLify_GetCipher( $socket );
|
|
46 |
warn "SSLified: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $socket ) ) ) )[1] ) . " cipher type: (" . SSLify_GetCipher( $socket ) . ")\n";
|
47 | 47 |
|
48 | 48 |
# Hand it off to ReadWrite
|
49 | 49 |
my $wheel = POE::Wheel::ReadWrite->new(
|
|
67 | 67 |
},
|
68 | 68 |
'Got_Input' => sub {
|
69 | 69 |
# ARG0: The Line, ARG1: Wheel ID
|
|
70 |
|
|
71 |
# testing stuff
|
|
72 |
my $socket = $_[HEAP]->{'WHEELS'}->{ $_[ARG1] }->get_output_handle();
|
|
73 |
warn "got input from: " . inet_ntoa( ( unpack_sockaddr_in( getpeername( SSLify_GetSocket( $socket ) ) ) )[1] ) . " cipher type: (" . SSLify_GetCipher( $socket ) . ") input: '$_[ARG0]'\n";
|
70 | 74 |
|
71 | 75 |
# Send back to the client the line!
|
72 | 76 |
$_[HEAP]->{'WHEELS'}->{ $_[ARG1] }->put( $_[ARG0] );
|
|
127 | 131 |
# ARG0 = Socket, ARG1 = Remote Address, ARG2 = Remote Port
|
128 | 132 |
my $socket = $_[ ARG0 ];
|
129 | 133 |
|
130 | |
warn "Connected to server, commencing Client_SSLify()";
|
|
134 |
warn "Connected to server, commencing Client_SSLify()\n";
|
131 | 135 |
|
132 | 136 |
# SSLify it!
|
133 | 137 |
$socket = Client_SSLify( $socket );
|
134 | 138 |
|
135 | |
warn "SSLified the connection to the server";
|
|
139 |
warn "SSLified the connection to the server\n";
|
136 | 140 |
|
137 | 141 |
# Hand it off to ReadWrite
|
138 | 142 |
my $wheel = POE::Wheel::ReadWrite->new(
|
18 | 18 |
|
19 | 19 |
# create a context, if necessary
|
20 | 20 |
if ( ! defined $ctx ) {
|
21 | |
$ctx = POE::Component::SSLify::createSSLcontext( undef, undef, $version, $options );
|
|
21 |
$ctx = POE::Component::SSLify::_createSSLcontext( undef, undef, $version, $options );
|
22 | 22 |
}
|
23 | 23 |
|
24 | 24 |
my $ssl = Net::SSLeay::new( $ctx ) or die_now( "Failed to create SSL $!" );
|
432 | 432 |
Example:
|
433 | 433 |
print "SSL Cipher is: " . SSLify_GetCipher( $sslified_sock ) . "\n";
|
434 | 434 |
|
|
435 |
NOTE: Doing this immediately after Client_SSLify or Server_SSLify will result in "(NONE)" because the SSL handshake
|
|
436 |
is not done yet. The socket is nonblocking, so you will have to wait a little bit for it to get ready.
|
|
437 |
apoc@blackhole:~/mygit/perl-poe-sslify/examples$ perl serverclient.pl
|
|
438 |
got connection from: 127.0.0.1 - commencing Server_SSLify()
|
|
439 |
SSLified: 127.0.0.1 cipher type: ((NONE))
|
|
440 |
Connected to server, commencing Client_SSLify()
|
|
441 |
SSLified the connection to the server
|
|
442 |
Connected to SSL server
|
|
443 |
Input: hola
|
|
444 |
got input from: 127.0.0.1 cipher type: (AES256-SHA) input: 'hola'
|
|
445 |
Got Reply: hola
|
|
446 |
Input: ^C
|
|
447 |
stopped at serverclient.pl line 126.
|
|
448 |
|
|
449 |
|
435 | 450 |
=head2 SSLify_GetSocket
|
436 | 451 |
|
437 | 452 |
Returns the actual socket used by the SSLified socket, useful for stuff like getpeername()/getsockname()
|
0 | 0 |
#!/usr/bin/perl
|
|
1 |
|
|
2 |
# Thanks to ASCENT for this test!
|
1 | 3 |
|
2 | 4 |
use strict;
|
3 | 5 |
use warnings;
|