annotate ssl_ocsp.t @ 1577:804a7409bc63

Tests: added ssl_ocsp test with failing request.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 19 Jun 2020 18:21:25 +0300
parents 0077b80ef745
children 2d371452658c
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 {
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
91 listen 127.0.0.1:8443 ssl;
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
92 server_name resolver;
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
93
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
94 ssl_ocsp on;
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
95 }
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
96
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
97 server {
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
98 listen 127.0.0.1:8444 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
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
101 ssl_ocsp_responder http://127.0.0.1:8081;
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
102 ssl_ocsp on;
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
105 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 listen 127.0.0.1:8445 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
109 ssl_ocsp_responder http://127.0.0.1:8082;
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
112 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 listen 127.0.0.1:8446 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116 ssl_ocsp_cache shared:OCSP:1m;
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 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
120 listen 127.0.0.1:8447 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123 ssl_ocsp_responder http://127.0.0.1:8082;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 ssl_client_certificate root.crt;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
126 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
127
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
128 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130 my $d = $t->testdir();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 my $p = port(8081);
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('openssl.conf', <<EOF);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 [ req ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 default_bits = 2048
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 encrypt_key = no
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 distinguished_name = req_distinguished_name
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 [ req_distinguished_name ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141 $t->write_file('ca.conf', <<EOF);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 [ ca ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 default_ca = myca
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
145 [ myca ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
146 new_certs_dir = $d
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 database = $d/certindex
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 default_md = sha256
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 policy = myca_policy
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 serial = $d/certserial
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 default_days = 1
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 x509_extensions = myca_extensions
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 [ myca_policy ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 commonName = supplied
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157 [ myca_extensions ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 basicConstraints = critical,CA:TRUE
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 authorityInfoAccess = OCSP;URI:http://127.0.0.1:$p
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
162 # variant for int.crt to trigger missing resolver
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
163
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
164 $t->write_file('ca2.conf', <<EOF);
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
165 [ ca ]
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
166 default_ca = myca
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
167
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
168 [ myca ]
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
169 new_certs_dir = $d
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
170 database = $d/certindex
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
171 default_md = sha256
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
172 policy = myca_policy
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
173 serial = $d/certserial
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
174 default_days = 1
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
175 x509_extensions = myca_extensions
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
176
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
177 [ myca_policy ]
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
178 commonName = supplied
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
179
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
180 [ myca_extensions ]
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
181 basicConstraints = critical,CA:TRUE
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
182 authorityInfoAccess = OCSP;URI:http://localhost:$p
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
183 EOF
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
184
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
185 foreach my $name ('root') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 system('openssl req -x509 -new '
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 . "-out $d/$name.crt -keyout $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 or die "Can't create certificate for $name: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
192
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
193 foreach my $name ('int', 'end') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 system("openssl req -new "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 . "-out $d/$name.csr -keyout $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 or die "Can't create certificate for $name: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
200
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
201 foreach my $name ('ec-end') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 system("openssl ecparam -genkey -out $d/$name.key -name prime256v1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204 or die "Can't create EC param: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 system("openssl req -new -key $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207 . "-out $d/$name.csr "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209 or die "Can't create certificate for $name: $!\n";
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
212 $t->write_file('certserial', '1000');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213 $t->write_file('certindex', '');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
215 system("openssl ca -batch -config $d/ca2.conf "
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
216 . "-keyfile $d/root.key -cert $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217 . "-subj /CN=int/ -in $d/int.csr -out $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219 or die "Can't sign certificate for int: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
221 system("openssl ca -batch -config $d/ca.conf "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
222 . "-keyfile $d/int.key -cert $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223 . "-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
224 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
225 or die "Can't sign certificate for ec-end: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227 system("openssl ca -batch -config $d/ca.conf "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228 . "-keyfile $d/int.key -cert $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229 . "-subj /CN=end/ -in $d/end.csr -out $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
230 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 or die "Can't sign certificate for end: $!\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 # RFC 6960, serialNumber
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
234
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235 system("openssl x509 -in $d/int.crt -serial -noout "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236 . ">>$d/serial_int 2>>$d/openssl.out") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237 or die "Can't obtain serial for end: $!\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 my $serial_int = pack("n2", 0x0202, hex $1)
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 if $t->read_file('serial_int') =~ /(\d+)/;
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 system("openssl x509 -in $d/end.crt -serial -noout "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243 . ">>$d/serial 2>>$d/openssl.out") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 or die "Can't obtain serial for end: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
246 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
247
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
248 # ocsp end
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
249
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250 system("openssl ocsp -issuer $d/int.crt -cert $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251 . "-reqout $d/req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
253
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256 . "-reqin $d/req.der -respout $d/resp.der -ndays 1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
258 or die "Can't create OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
260 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
261 . "-reqout $d/ec-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
262 or die "Can't create EC OCSP request: $!\n";
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 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
265 . "-rsigner $d/root.crt -rkey $d/root.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
266 . "-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
267 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
268 or die "Can't create EC OCSP response: $!\n";
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 $t->write_file('trusted.crt',
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
271 $t->read_file('int.crt') . $t->read_file('root.crt'));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
272
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
273 # server cert/key
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
274
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
275 system("openssl ecparam -genkey -out $d/ec.key -name prime256v1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
276 . ">>$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
277 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
278 or die "Can't create RSA pem: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
279
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
280 foreach my $name ('ec', 'rsa') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
281 system("openssl req -x509 -new -key $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
282 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
283 . "-out $d/$name.crt -keyout $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
284 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
285 or die "Can't create certificate for $name: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
286 }
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 $t->run_daemon(\&http_daemon, $t, port(8081));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
289 $t->run_daemon(\&http_daemon, $t, port(8082));
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
290 $t->try_run('no ssl_ocsp')->plan(14);
1570
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 $t->waitforsocket("127.0.0.1:" . port(8081));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
293 $t->waitforsocket("127.0.0.1:" . port(8082));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
294
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
295 my $version = get_version();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
296
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
297 ###############################################################################
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
298
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
299 like(get('RSA', 'end'), qr/200 OK.*SUCCESS/s, 'ocsp leaf');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
300
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
301 # demonstrate that ocsp int request is failed due to missing resolver
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
302
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
303 TODO: {
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
304 todo_skip 'leaves coredump', 1 unless $t->has_version('1.19.1')
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
305 or $ENV{TEST_NGINX_UNSAFE};
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
306
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
307 like(get('RSA', 'end', sni => 'resolver'),
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
308 qr/400 Bad.*FAILED:certificate status request failed/s,
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
309 'ocsp many failed request');
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
310
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
311 }
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
312
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313 # 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
314
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315 like(get('RSA', 'end', port => 8444),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 qr/400 Bad.*FAILED:certificate status request failed/s,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 'ocsp many failed');
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 # now prepare valid ocsp int response
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 system("openssl ocsp -issuer $d/root.crt -cert $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
322 . "-reqout $d/int-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
323 or die "Can't create OCSP request: $!\n";
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 system("openssl ocsp -index $d/certindex -CA $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
326 . "-rsigner $d/root.crt -rkey $d/root.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
327 . "-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
328 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329 or die "Can't create OCSP response: $!\n";
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 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
332
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333 # store into ssl_ocsp_cache
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335 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
336
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
337 # revoke
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 system("openssl ca -config $d/ca.conf -revoke $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
340 . "-keyfile $d/root.key -cert $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
341 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
342 or die "Can't revoke end.crt: $!\n";
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 system("openssl ocsp -issuer $d/int.crt -cert $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
345 . "-reqout $d/req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
346 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
347
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
348 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
349 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
350 . "-reqin $d/req.der -respout $d/revoked.der -ndays 1 "
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 create OCSP response: $!\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 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
355
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
356 # with different responder where it's still valid
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 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
359
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
360 # with different context to responder where it's still valid
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
361
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
362 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
363
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
364 # with cached ocsp response it's still valid
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('RSA', 'end', port => 8446), qr/200 OK.*SUCCESS/s, 'cache lookup');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
367
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
368 # ocsp end response signed with invalid (root) cert, expect HTTP 400
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
369
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
370 like(get('ECDSA', 'ec-end'),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
371 qr/400 Bad.*FAILED:certificate status request failed/s,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
372 'root ca not trusted');
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 # now sign ocsp end response with valid int cert
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
375
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
376 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
377 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
378 . "-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
379 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
380 or die "Can't create EC OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
381
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
382 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
383
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
384 my ($s, $ssl) = get('ECDSA', 'ec-end');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
385 my $ses = Net::SSLeay::get_session($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
386
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
387 like(get('ECDSA', 'ec-end', ses => $ses),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
388 qr/200 OK.*SUCCESS:r/s, 'session reused');
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 # revoke with saved session
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
391
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
392 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
393 . "-keyfile $d/root.key -cert $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
394 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
395 or die "Can't revoke end.crt: $!\n";
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 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
398 . "-reqout $d/ec-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
399 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
400
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
401 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
402 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
403 . "-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
404 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
405 or die "Can't create OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
406
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
407 # reusing session with revoked certificate
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
408
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
409 like(get('ECDSA', 'ec-end', ses => $ses),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
410 qr/400 Bad.*FAILED:certificate revoked:r/s, 'session reused - revoked');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
411
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
412 # regression test for self-signed
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
413
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
414 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
415
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
416 ###############################################################################
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
417
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
418 sub get {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
419 my ($type, $cert, %extra) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
420 $type = 'PSS' if $type eq 'RSA' && $version > 0x0303;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
421 my ($s, $ssl) = get_ssl_socket($type, $cert, %extra);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
422 my $cipher = Net::SSLeay::get_cipher($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
423 Test::Nginx::log_core('||', "cipher: $cipher");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
424 my $host = $extra{sni} ? $extra{sni} : 'localhost';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
425 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
426 my $r = Net::SSLeay::read($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
427 Test::Nginx::log_core($r);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
428 $s->close();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
429 return $r unless wantarray();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
430 return ($s, $ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
431 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
432
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
433 sub get_ssl_socket {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
434 my ($type, $cert, %extra) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
435 my $ses = $extra{ses};
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
436 my $sni = $extra{sni};
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
437 my $port = $extra{port} || 8443;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
438 my $s;
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 eval {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
441 local $SIG{ALRM} = sub { die "timeout\n" };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
442 local $SIG{PIPE} = sub { die "sigpipe\n" };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
443 alarm(8);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
444 $s = IO::Socket::INET->new('127.0.0.1:' . port($port));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
445 alarm(0);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
446 };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
447 alarm(0);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
448
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
449 if ($@) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
450 log_in("died: $@");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
451 return undef;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
452 }
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 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
455
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
456 if (defined $type) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
457 my $ssleay = Net::SSLeay::SSLeay();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
458 if ($ssleay < 0x1000200f || $ssleay == 0x20000000) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
459 Net::SSLeay::CTX_set_cipher_list($ctx, $type)
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
460 or die("Failed to set cipher list");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
461 } else {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
462 # SSL_CTRL_SET_SIGALGS_LIST
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
463 Net::SSLeay::CTX_ctrl($ctx, 98, 0, $type . '+SHA256')
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
464 or die("Failed to set sigalgs");
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 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
467
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
468 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
469 or die if $cert;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
470 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
471 Net::SSLeay::set_session($ssl, $ses) if defined $ses;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
472 Net::SSLeay::set_tlsext_host_name($ssl, $sni) if $sni;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
473 Net::SSLeay::set_fd($ssl, fileno($s));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
474 Net::SSLeay::connect($ssl) or die("ssl connect");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
475 return ($s, $ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
476 }
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 sub get_version {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
479 my ($s, $ssl) = get_ssl_socket();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
480 return Net::SSLeay::version($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
481 }
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
485 sub http_daemon {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
486 my ($t, $port) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
487 my $server = IO::Socket::INET->new(
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
488 Proto => 'tcp',
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
489 LocalHost => "127.0.0.1:$port",
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
490 Listen => 5,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
491 Reuse => 1
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
492 )
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
493 or die "Can't create listening socket: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
494
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
495 local $SIG{PIPE} = 'IGNORE';
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 while (my $client = $server->accept()) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
498 $client->autoflush(1);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
499
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
500 my $headers = '';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
501 my $uri = '';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
502 my $resp;
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 while (<$client>) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
505 $headers .= $_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
506 last if (/^\x0d?\x0a?$/);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
507 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
508
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
509 $uri = $1 if $headers =~ /^\S+\s+\/([^ ]+)\s+HTTP/i;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
510 next unless $uri;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
511
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
512 $uri =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
513 my $req = decode_base64($uri);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
514
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
515 if (index($req, $serial_int) > 0) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
516 $resp = 'int-resp';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
517
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
518 } elsif (index($req, $serial) > 0) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
519 $resp = 'resp';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
520
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
521 # used to differentiate ssl_ocsp_responder
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
522
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
523 if ($port == port(8081) && -e "$d/revoked.der") {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
524 $resp = 'revoked';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
525 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
526
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
527 } else {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
528 $resp = 'ec-resp';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
529 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
530
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
531 # ocsp dummy handler
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
532
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
533 select undef, undef, undef, 0.02;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
534
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
535 $headers = <<"EOF";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
536 HTTP/1.1 200 OK
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
537 Connection: close
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
538 Content-Type: application/ocsp-response
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
539
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
540 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
541
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
542 print $client $headers . $t->read_file("$resp.der")
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
543 if -e "$d/$resp.der";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
544 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
545 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
546
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
547 ###############################################################################