File: connectSSL-timeout.t

package info (click to toggle)
libio-socket-ssl-perl 2.002-2%2Bdeb8u3
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 1,348 kB
  • sloc: perl: 14,412; makefile: 4
file content (75 lines) | stat: -rw-r--r-- 2,012 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use strict;
use warnings;
use IO::Socket::SSL;
do './testlib.pl' || do './t/testlib.pl' || die "no testlib";

$|=1;
print "1..16\n";


{
    # first use SSL client
    my ($server,$saddr) = create_listen_socket();
    ok( 1, "listening \@$saddr" );
    my $srv = fork_sub( 'server','ssl',$server );
    close($server);
    fd_grep_ok( 'Waiting', $srv );
    my $cl = fork_sub( 'client',$saddr );
    fd_grep_ok( 'Connect from',$srv );
    fd_grep_ok( 'Connected', $cl );
    fd_grep_ok( 'Server SSL Handshake OK', $srv );
    fd_grep_ok( 'Client SSL Handshake OK', $cl );
    fd_grep_ok( 'Hi!', $cl );
}

if ( $^O =~m{mswin32}i ) {
    # skip
    ok( 1, "skip - TODO on win32" ) for(1..7);
} else {
    # then try bad non-SSL client
    my ($server,$saddr) = create_listen_socket();
    ok( 1, "listening \@$saddr" );
    my $srv = fork_sub( 'server','nossl',$server );
    close($server);
    fd_grep_ok( 'Waiting', $srv );
    my $cl = fork_sub( 'client',$saddr );
    fd_grep_ok( 'Connect from',$srv );
    fd_grep_ok( 'Connected', $cl );
    fd_grep_ok( 'Client SSL Handshake FAILED', $cl );
}


sub server {
    my ($behavior,$server) = @_;
    print "Waiting\n";
    my $client = $server->accept || die "accept failed: $!";
    print "Connect from ".$client->peerhost.':'.$client->peerport."\n";
    if ( $behavior eq 'ssl' ) {
	if ( IO::Socket::SSL->start_SSL( $client,
	    SSL_server => 1,
	    Timeout => 30,
	    SSL_cert_file => 'certs/server-cert.pem',
	    SSL_key_file => 'certs/server-key.pem',
	)) {
	    print "Server SSL Handshake OK\n";
	    print $client "Hi!\n";
	}
    } else {
	while ( sysread( $client, my $buf,8000 )) {}
    }
}

sub client {
    my $saddr = shift;
    my $c = IO::Socket::INET->new( $saddr ) || die "connect failed: $!";
    print "Connected\n";
    if ( IO::Socket::SSL->start_SSL( $c,
	Timeout => 5,
	SSL_ca_file => 'certs/my-ca.pem',
    )) {
	print "Client SSL Handshake OK\n";
	print <$c>
    } else {
	print "Client SSL Handshake FAILED - $SSL_ERROR\n";
    }
}