my
$port
;
POE::Component::Server::TCP->new
(
Alias
=>
'myserver'
,
Address
=>
'127.0.0.1'
,
Port
=> 0,
Started
=>
sub
{
$port
= (sockaddr_in(
$_
[HEAP]->{listener}->
getsockname
))[0];
},
ClientConnected
=>
sub
{
ok(1,
'SERVER: accepted'
);
},
ClientDisconnected
=>
sub
{
ok(1,
'SERVER: client disconnected'
);
$_
[KERNEL]->post(
myserver
=>
'shutdown'
);
},
ClientPreConnect
=>
sub
{
my
$args
= {
SSL_cert_file
=>
'mylib/ircd.crt'
,
SSL_key_file
=>
'mylib/ircd.key'
,
};
my
$socket
=
eval
{ Server_TLSify(
$_
[ARG0],
$args
) };
ok(!$@,
"SERVER: Server_TLSify $@"
);
ok(1,
'SERVER: TLSify_GetCipher: '
. TLSify_GetCipher(
$socket
));
ok( TLSify_GetSocket(
$socket
)->blocking == 0,
'SERVER: SSLified socket is non-blocking?'
)
if
$^O ne
'MSWin32'
;
return
(
$socket
);
},
ClientInput
=>
sub
{
my
(
$kernel
,
$heap
,
$line
) =
@_
[KERNEL, HEAP, ARG0];
if
(
$line
eq
'ping'
) {
ok(1,
"SERVER: recv: $line"
);
my
$cipher
= TLSify_GetCipher(
$heap
->{client}->get_output_handle);
ok(
$cipher
ne
'(NONE)'
,
"SERVER: TLSify_GetCipher: $cipher"
);
$heap
->{client}->put(
"pong"
);
}
else
{
die
"Unknown line from CLIENT: $line"
;
}
},
ClientError
=>
sub
{
my
(
$syscall
,
$errno
,
$error
) =
@_
[ ARG0..ARG2 ];
$error
=
"Normal disconnection"
unless
$error
;
my
$msg
=
"Got SERVER $syscall error $errno: $error"
;
unless
(
$syscall
eq
'read'
and
$errno
== 0 ) {
fail(
$msg
);
}
else
{
diag(
$msg
)
if
$ENV
{TEST_VERBOSE};
}
},
);
POE::Component::Client::TCP->new
(
Alias
=>
'myclient'
,
RemoteAddress
=>
'127.0.0.1'
,
RemotePort
=>
$port
,
Connected
=>
sub
{
ok(1,
'CLIENT: connected'
);
$_
[HEAP]->{server}->put(
"ping"
);
},
PreConnect
=>
sub
{
my
$args
= {
SSL_verify_mode
=> IO::Socket::SSL::SSL_VERIFY_PEER(),
SSL_verify_callback
=>
sub
{
return
1; },
SSL_verifycn_name
=>
'poco.server.irc'
,
SSL_ocsp_mode
=> IO::Socket::SSL::SSL_OCSP_NO_STAPLE(),
};
my
$socket
=
eval
{ Client_TLSify(
$_
[ARG0],
$args
) };
ok(!$@,
"CLIENT: Client_TLSify $@"
);
ok(1,
'CLIENT: TLSify_GetCipher: '
. TLSify_GetCipher(
$socket
));
ok( TLSify_GetSocket(
$socket
)->blocking == 0,
'CLIENT: SSLified socket is non-blocking?'
)
if
$^O ne
'MSWin32'
;
return
(
$socket
);
},
ServerInput
=>
sub
{
my
(
$kernel
,
$heap
,
$line
) =
@_
[KERNEL, HEAP, ARG0];
if
(
$line
eq
'pong'
) {
ok(1,
"CLIENT: recv: $line"
);
my
$cipher
= TLSify_GetCipher(
$heap
->{server}->get_output_handle);
ok(
$cipher
ne
'(NONE)'
,
"CLIENT: TLSify_GetCipher: $cipher"
);
diag( TLSify_GetSocket(
$heap
->{server}->get_output_handle )->dump_peer_certificate() )
if
$ENV
{TEST_VERBOSE};
$kernel
->yield(
'shutdown'
);
}
else
{
die
"Unknown line from SERVER: $line"
;
}
},
ServerError
=>
sub
{
my
(
$syscall
,
$errno
,
$error
) =
@_
[ ARG0..ARG2 ];
$error
=
"Normal disconnection"
unless
$error
;
my
$msg
=
"Got CLIENT $syscall error $errno: $error"
;
unless
(
$syscall
eq
'read'
and
$errno
== 0 ) {
fail(
$msg
);
}
else
{
diag(
$msg
)
if
$ENV
{TEST_VERBOSE};
}
},
);
$poe_kernel
->run();
done_testing;