Add ARM files
[dh-make-perl] / dev / arm / libio-socket-ssl-perl / libio-socket-ssl-perl-1.16 / t / auto_verify_hostname.t
1 #!perl -w
2
3 use strict;
4 use Net::SSLeay;
5 use Socket;
6 use IO::Socket::SSL;
7
8 print "1..0 # Skipped: test cert has expired\n";
9 exit;
10
11 if ( grep { $^O =~m{$_} } qw( MacOS VOS vmesa riscos amigaos ) ) {
12         print "1..0 # Skipped: fork not implemented on this platform\n";
13         exit
14 }
15
16 # subjectAltNames are not supported or buggy in older versions,
17 # so certificates cannot be checked
18 if ( $Net::SSLeay::VERSION < 1.33 ) {
19         print "1..0 # Skipped because of \$Net::SSLeay::VERSION= $Net::SSLeay::VERSION <1.33\n";
20         exit;
21 }
22
23 use vars qw( $SSL_SERVER_ADDR );
24 do "t/ssl_settings.req" || do "ssl_settings.req";
25
26 $|=1;
27 print "1..30\n";
28
29 my $server = IO::Socket::SSL->new(
30         LocalAddr => $SSL_SERVER_ADDR,
31         Listen => 2,
32         ReuseAddr => 1,
33         SSL_server => 1,
34         SSL_ca_file => "certs/test-ca.pem",
35         SSL_cert_file => "certs/server-wildcard.pem",
36         SSL_key_file => "certs/server-wildcard.pem",
37 );
38 warn "\$!=$!, \$\@=$@, S\$SSL_ERROR=$SSL_ERROR" if ! $server;
39 print "not ok\n", exit if !$server;
40 ok("Server Initialization");
41 my $SSL_SERVER_PORT = $server->sockport;
42
43 defined( my $pid = fork() ) || die $!;
44 if ( $pid == 0 ) {
45         while (1) {
46                 my $csock = $server->accept || next;
47                 print $csock "hallo\n";
48         }
49 }
50
51 close($server);
52 my @tests = qw(
53         example.com      www FAIL
54         server.local     ldap OK
55         server.local     www FAIL
56         bla.server.local www OK
57         www7.other.local www OK
58         www7.other.local ldap FAIL
59         bla.server.local ldap OK
60 );
61
62 for( my $i=0;$i<@tests;$i+=3 ) {
63         my ($name,$scheme,$result) = @tests[$i,$i+1,$i+2];
64         my $cl = IO::Socket::SSL->new(
65                 SSL_ca_file => 'certs/test-ca.pem',
66                 PeerAddr => "$SSL_SERVER_ADDR:$SSL_SERVER_PORT",
67                 SSL_verify_mode => 1,
68                 SSL_verifycn_scheme => $scheme,
69                 SSL_verifycn_name => $name,
70         );
71         if ( $result eq 'FAIL' ) {
72                 print "not " if $cl;
73                 ok( "connection to $name/$scheme failed" );
74         } else {
75                 print "not " if !$cl;
76                 ok( "connection to $name/$scheme succeeded" );
77         }
78         $cl || next;
79         print "not " if <$cl> ne "hallo\n";
80         ok( "received hallo" );
81 }
82
83 for( my $i=0;$i<@tests;$i+=3 ) {
84         my ($name,$scheme,$result) = @tests[$i,$i+1,$i+2];
85         my $cl = IO::Socket::INET->new(
86                 PeerAddr => "$SSL_SERVER_ADDR:$SSL_SERVER_PORT",
87         ) || print "not ";
88         ok( "tcp connect" );
89         $cl = IO::Socket::SSL->start_SSL( $cl,
90                 SSL_ca_file => 'certs/test-ca.pem',
91                 SSL_verify_mode => 1,
92                 SSL_verifycn_scheme => $scheme,
93                 SSL_verifycn_name => $name,
94         );
95         if ( $result eq 'FAIL' ) {
96                 print "not " if $cl;
97                 ok( "ssl upgrade of connection to $name/$scheme failed" );
98         } else {
99                 print "not " if !$cl;
100                 ok( "ssl upgrade of connection to $name/$scheme succeeded" );
101         }
102         $cl || next;
103         print "not " if <$cl> ne "hallo\n";
104         ok( "received hallo" );
105 }
106
107 kill(9,$pid);
108 wait;
109
110 sub ok { print "ok #$_[0]\n"; }
111