annotate ssl_ocsp.t @ 1570:0077b80ef745

Tests: ssl_ocsp tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 20 May 2020 15:04:50 +0300
parents
children 804a7409bc63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
2
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
3 # (C) Sergey Kandaurov
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
5
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
6 # Tests for OCSP with client certificates.
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
7
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
8 ###############################################################################
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
9
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
10 use warnings;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
11 use strict;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
12
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
13 use Test::More;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
14
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
15 use MIME::Base64 qw/ decode_base64 /;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
16
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
17 BEGIN { use FindBin; chdir($FindBin::Bin); }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
18
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
19 use lib 'lib';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
20 use Test::Nginx;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
21
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
22 ###############################################################################
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
23
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
24 select STDERR; $| = 1;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
25 select STDOUT; $| = 1;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
26
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
27 eval {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
28 require Net::SSLeay;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
29 Net::SSLeay::load_error_strings();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
30 Net::SSLeay::SSLeay_add_ssl_algorithms();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
31 Net::SSLeay::randomize();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
32 Net::SSLeay::SSLeay();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
33 defined &Net::SSLeay::set_tlsext_status_type or die;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
34 };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
35 plan(skip_all => 'Net::SSLeay not installed or too old') if $@;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
36
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
37 eval {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
38 my $ctx = Net::SSLeay::CTX_new() or die;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
39 my $ssl = Net::SSLeay::new($ctx) or die;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
40 Net::SSLeay::set_tlsext_host_name($ssl, 'example.org') == 1 or die;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
41 };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
42 plan(skip_all => 'Net::SSLeay with OpenSSL SNI support required') if $@;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
43
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
44 my $t = Test::Nginx->new()->has(qw/http http_ssl sni/)->has_daemon('openssl');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
45
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
46 plan(skip_all => 'no OCSP stapling') if $t->has_module('BoringSSL');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
47
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48 $t->write_file_expand('nginx.conf', <<'EOF');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50 %%TEST_GLOBALS%%
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52 daemon off;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54 events {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
56
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
57 http {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 %%TEST_GLOBALS_HTTP%%
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60 ssl_ocsp leaf;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 ssl_verify_client on;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 ssl_verify_depth 2;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 ssl_client_certificate trusted.crt;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65 ssl_ciphers DEFAULT:ECCdraft;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67 ssl_certificate_key ec.key;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 ssl_certificate ec.crt;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70 ssl_certificate_key rsa.key;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 ssl_certificate rsa.crt;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73 ssl_session_cache shared:SSL:1m;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 ssl_session_tickets off;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76 add_header X-Verify x${ssl_client_verify}:${ssl_session_reused}x always;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
78 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 listen 127.0.0.1:8443 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
82
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
83 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 listen 127.0.0.1:8443 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 server_name sni;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87 ssl_ocsp_responder http://127.0.0.1:8082;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
89
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
90 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 listen 127.0.0.1:8444 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
92 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
93
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
94 ssl_ocsp on;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
95 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
96
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
97 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 listen 127.0.0.1:8445 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101 ssl_ocsp_responder http://127.0.0.1:8082;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
104 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 listen 127.0.0.1:8446 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 ssl_ocsp_cache shared:OCSP:1m;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
110
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
111 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 listen 127.0.0.1:8447 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 ssl_ocsp_responder http://127.0.0.1:8082;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 ssl_client_certificate root.crt;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
118 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
119
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 my $d = $t->testdir();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 my $p = port(8081);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 $t->write_file('openssl.conf', <<EOF);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 [ req ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127 default_bits = 2048
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 encrypt_key = no
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 distinguished_name = req_distinguished_name
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 [ req_distinguished_name ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133 $t->write_file('ca.conf', <<EOF);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 [ ca ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 default_ca = myca
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 [ myca ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 new_certs_dir = $d
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 database = $d/certindex
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 default_md = sha256
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 policy = myca_policy
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 serial = $d/certserial
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 default_days = 1
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 x509_extensions = myca_extensions
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 [ myca_policy ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 commonName = supplied
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 [ myca_extensions ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 basicConstraints = critical,CA:TRUE
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 authorityInfoAccess = OCSP;URI:http://127.0.0.1:$p
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154 foreach my $name ('root') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 system('openssl req -x509 -new '
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 . "-out $d/$name.crt -keyout $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 or die "Can't create certificate for $name: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162 foreach my $name ('int', 'end') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
163 system("openssl req -new "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
164 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
165 . "-out $d/$name.csr -keyout $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
166 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
167 or die "Can't create certificate for $name: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
168 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
169
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
170 foreach my $name ('ec-end') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
171 system("openssl ecparam -genkey -out $d/$name.key -name prime256v1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
172 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
173 or die "Can't create EC param: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
174 system("openssl req -new -key $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
175 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
176 . "-out $d/$name.csr "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
177 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
178 or die "Can't create certificate for $name: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
179 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
180
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
181 $t->write_file('certserial', '1000');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
182 $t->write_file('certindex', '');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
183
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
184 system("openssl ca -batch -config $d/ca.conf "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 . "-keyfile $d/root.key -cert $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 . "-subj /CN=int/ -in $d/int.csr -out $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 or die "Can't sign certificate for int: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 system("openssl ca -batch -config $d/ca.conf "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 . "-keyfile $d/int.key -cert $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192 . "-subj /CN=ec-end/ -in $d/ec-end.csr -out $d/ec-end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 or die "Can't sign certificate for ec-end: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 system("openssl ca -batch -config $d/ca.conf "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197 . "-keyfile $d/int.key -cert $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 . "-subj /CN=end/ -in $d/end.csr -out $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200 or die "Can't sign certificate for end: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 # RFC 6960, serialNumber
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204 system("openssl x509 -in $d/int.crt -serial -noout "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 . ">>$d/serial_int 2>>$d/openssl.out") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206 or die "Can't obtain serial for end: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208 my $serial_int = pack("n2", 0x0202, hex $1)
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209 if $t->read_file('serial_int') =~ /(\d+)/;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
211 system("openssl x509 -in $d/end.crt -serial -noout "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
212 . ">>$d/serial 2>>$d/openssl.out") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213 or die "Can't obtain serial for end: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
215 my $serial = pack("n2", 0x0202, hex $1) if $t->read_file('serial') =~ /(\d+)/;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
216
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217 # ocsp end
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219 system("openssl ocsp -issuer $d/int.crt -cert $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220 . "-reqout $d/req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
221 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
222
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
224 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
225 . "-reqin $d/req.der -respout $d/resp.der -ndays 1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227 or die "Can't create OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229 system("openssl ocsp -issuer $d/int.crt -cert $d/ec-end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
230 . "-reqout $d/ec-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 or die "Can't create EC OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
233 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
234 . "-rsigner $d/root.crt -rkey $d/root.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235 . "-reqin $d/ec-req.der -respout $d/ec-resp.der -ndays 1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237 or die "Can't create EC OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
238
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
239 $t->write_file('trusted.crt',
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 $t->read_file('int.crt') . $t->read_file('root.crt'));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
241
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
242 # server cert/key
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 system("openssl ecparam -genkey -out $d/ec.key -name prime256v1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245 . ">>$d/openssl.out 2>&1") == 0 or die "Can't create EC pem: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
246 system("openssl genrsa -out $d/rsa.key 2048 >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
247 or die "Can't create RSA pem: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
248
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
249 foreach my $name ('ec', 'rsa') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250 system("openssl req -x509 -new -key $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252 . "-out $d/$name.crt -keyout $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
253 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254 or die "Can't create certificate for $name: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 $t->run_daemon(\&http_daemon, $t, port(8081));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
258 $t->run_daemon(\&http_daemon, $t, port(8082));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259 $t->try_run('no ssl_ocsp')->plan(13);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
260
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
261 $t->waitforsocket("127.0.0.1:" . port(8081));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
262 $t->waitforsocket("127.0.0.1:" . port(8082));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
263
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
264 my $version = get_version();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
265
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
266 ###############################################################################
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
267
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
268 like(get('RSA', 'end'), qr/200 OK.*SUCCESS/s, 'ocsp leaf');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
269
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
270 # demonstrate that ocsp int request is actually made by failing ocsp response
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
271
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
272 like(get('RSA', 'end', port => 8444),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
273 qr/400 Bad.*FAILED:certificate status request failed/s,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
274 'ocsp many failed');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
275
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
276 # now prepare valid ocsp int response
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
277
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
278 system("openssl ocsp -issuer $d/root.crt -cert $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
279 . "-reqout $d/int-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
280 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
281
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
282 system("openssl ocsp -index $d/certindex -CA $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
283 . "-rsigner $d/root.crt -rkey $d/root.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
284 . "-reqin $d/int-req.der -respout $d/int-resp.der -ndays 1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
285 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
286 or die "Can't create OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
287
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
288 like(get('RSA', 'end', port => 8444), qr/200 OK.*SUCCESS/s, 'ocsp many');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
289
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
290 # store into ssl_ocsp_cache
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
291
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
292 like(get('RSA', 'end', port => 8446), qr/200 OK.*SUCCESS/s, 'cache store');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
293
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
294 # revoke
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
295
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
296 system("openssl ca -config $d/ca.conf -revoke $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
297 . "-keyfile $d/root.key -cert $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
298 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
299 or die "Can't revoke end.crt: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
300
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
301 system("openssl ocsp -issuer $d/int.crt -cert $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
302 . "-reqout $d/req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
303 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
304
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
305 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
306 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
307 . "-reqin $d/req.der -respout $d/revoked.der -ndays 1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
308 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
309 or die "Can't create OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311 like(get('RSA', 'end'), qr/400 Bad.*FAILED:certificate revoked/s, 'revoked');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313 # with different responder where it's still valid
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
314
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315 like(get('RSA', 'end', port => 8445), qr/200 OK.*SUCCESS/s, 'ocsp responder');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 # with different context to responder where it's still valid
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
318
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
319 like(get('RSA', 'end', sni => 'sni'), qr/200 OK.*SUCCESS/s, 'ocsp context');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
320
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
321 # with cached ocsp response it's still valid
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
322
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
323 like(get('RSA', 'end', port => 8446), qr/200 OK.*SUCCESS/s, 'cache lookup');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
324
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
325 # ocsp end response signed with invalid (root) cert, expect HTTP 400
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
326
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
327 like(get('ECDSA', 'ec-end'),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328 qr/400 Bad.*FAILED:certificate status request failed/s,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329 'root ca not trusted');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
330
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
331 # now sign ocsp end response with valid int cert
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335 . "-reqin $d/ec-req.der -respout $d/ec-resp.der -ndays 1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
336 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
337 or die "Can't create EC OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
338
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
339 like(get('ECDSA', 'ec-end'), qr/200 OK.*SUCCESS/s, 'ocsp ecdsa');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
340
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
341 my ($s, $ssl) = get('ECDSA', 'ec-end');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
342 my $ses = Net::SSLeay::get_session($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
343
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
344 like(get('ECDSA', 'ec-end', ses => $ses),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
345 qr/200 OK.*SUCCESS:r/s, 'session reused');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
346
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
347 # revoke with saved session
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
348
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
349 system("openssl ca -config $d/ca.conf -revoke $d/ec-end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
350 . "-keyfile $d/root.key -cert $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
351 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
352 or die "Can't revoke end.crt: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
353
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
354 system("openssl ocsp -issuer $d/int.crt -cert $d/ec-end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
355 . "-reqout $d/ec-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
356 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
357
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
358 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
359 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
360 . "-reqin $d/ec-req.der -respout $d/ec-resp.der -ndays 1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
361 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
362 or die "Can't create OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
363
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
364 # reusing session with revoked certificate
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
365
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
366 like(get('ECDSA', 'ec-end', ses => $ses),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
367 qr/400 Bad.*FAILED:certificate revoked:r/s, 'session reused - revoked');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
368
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
369 # regression test for self-signed
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
370
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
371 like(get('RSA', 'root', port => 8447), qr/200 OK.*SUCCESS/s, 'ocsp one');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
372
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
373 ###############################################################################
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
374
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
375 sub get {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
376 my ($type, $cert, %extra) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
377 $type = 'PSS' if $type eq 'RSA' && $version > 0x0303;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
378 my ($s, $ssl) = get_ssl_socket($type, $cert, %extra);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
379 my $cipher = Net::SSLeay::get_cipher($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
380 Test::Nginx::log_core('||', "cipher: $cipher");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
381 my $host = $extra{sni} ? $extra{sni} : 'localhost';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
382 Net::SSLeay::write($ssl, "GET /serial HTTP/1.0\nHost: $host\n\n");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
383 my $r = Net::SSLeay::read($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
384 Test::Nginx::log_core($r);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
385 $s->close();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
386 return $r unless wantarray();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
387 return ($s, $ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
388 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
389
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
390 sub get_ssl_socket {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
391 my ($type, $cert, %extra) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
392 my $ses = $extra{ses};
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
393 my $sni = $extra{sni};
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
394 my $port = $extra{port} || 8443;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
395 my $s;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
396
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
397 eval {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
398 local $SIG{ALRM} = sub { die "timeout\n" };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
399 local $SIG{PIPE} = sub { die "sigpipe\n" };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
400 alarm(8);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
401 $s = IO::Socket::INET->new('127.0.0.1:' . port($port));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
402 alarm(0);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
403 };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
404 alarm(0);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
405
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
406 if ($@) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
407 log_in("died: $@");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
408 return undef;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
409 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
410
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
411 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
412
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
413 if (defined $type) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
414 my $ssleay = Net::SSLeay::SSLeay();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
415 if ($ssleay < 0x1000200f || $ssleay == 0x20000000) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
416 Net::SSLeay::CTX_set_cipher_list($ctx, $type)
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
417 or die("Failed to set cipher list");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
418 } else {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
419 # SSL_CTRL_SET_SIGALGS_LIST
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
420 Net::SSLeay::CTX_ctrl($ctx, 98, 0, $type . '+SHA256')
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
421 or die("Failed to set sigalgs");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
422 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
423 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
424
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
425 Net::SSLeay::set_cert_and_key($ctx, "$d/$cert.crt", "$d/$cert.key")
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
426 or die if $cert;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
427 my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
428 Net::SSLeay::set_session($ssl, $ses) if defined $ses;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
429 Net::SSLeay::set_tlsext_host_name($ssl, $sni) if $sni;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
430 Net::SSLeay::set_fd($ssl, fileno($s));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
431 Net::SSLeay::connect($ssl) or die("ssl connect");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
432 return ($s, $ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
433 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
434
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
435 sub get_version {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
436 my ($s, $ssl) = get_ssl_socket();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
437 return Net::SSLeay::version($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
438 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
439
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
440 ###############################################################################
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
441
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
442 sub http_daemon {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
443 my ($t, $port) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
444 my $server = IO::Socket::INET->new(
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
445 Proto => 'tcp',
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
446 LocalHost => "127.0.0.1:$port",
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
447 Listen => 5,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
448 Reuse => 1
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
449 )
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
450 or die "Can't create listening socket: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
451
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
452 local $SIG{PIPE} = 'IGNORE';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
453
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
454 while (my $client = $server->accept()) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
455 $client->autoflush(1);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
456
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
457 my $headers = '';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
458 my $uri = '';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
459 my $resp;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
460
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
461 while (<$client>) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
462 $headers .= $_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
463 last if (/^\x0d?\x0a?$/);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
464 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
465
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
466 $uri = $1 if $headers =~ /^\S+\s+\/([^ ]+)\s+HTTP/i;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
467 next unless $uri;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
468
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
469 $uri =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
470 my $req = decode_base64($uri);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
471
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
472 if (index($req, $serial_int) > 0) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
473 $resp = 'int-resp';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
474
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
475 } elsif (index($req, $serial) > 0) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
476 $resp = 'resp';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
477
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
478 # used to differentiate ssl_ocsp_responder
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
479
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
480 if ($port == port(8081) && -e "$d/revoked.der") {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
481 $resp = 'revoked';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
482 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
483
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
484 } else {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
485 $resp = 'ec-resp';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
486 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
487
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
488 # ocsp dummy handler
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
489
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
490 select undef, undef, undef, 0.02;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
491
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
492 $headers = <<"EOF";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
493 HTTP/1.1 200 OK
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
494 Connection: close
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
495 Content-Type: application/ocsp-response
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
496
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
497 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
498
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
499 print $client $headers . $t->read_file("$resp.der")
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
500 if -e "$d/$resp.der";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
501 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
502 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
503
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
504 ###############################################################################