annotate ssl_ocsp.t @ 1846:9d98c2ad3126

Tests: cleaned up ssl_ocsp.t. Fixed verbose logging, added $SIG{PIPE} handling to avoid hangs if the server closes connection, fixed SKIP message for BoringSSL.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 23 Mar 2023 19:50:24 +0300
parents 5ac6efbe5552
children a9704b9ed7a2
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
1846
9d98c2ad3126 Tests: cleaned up ssl_ocsp.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1693
diff changeset
46 plan(skip_all => 'no OCSP support in BoringSSL')
9d98c2ad3126 Tests: cleaned up ssl_ocsp.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1693
diff changeset
47 if $t->has_module('BoringSSL');
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
48
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
49 $t->write_file_expand('nginx.conf', <<'EOF');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
50
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
51 %%TEST_GLOBALS%%
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
52
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
53 daemon off;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
54
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
55 events {
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
58 http {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
59 %%TEST_GLOBALS_HTTP%%
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
60
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
61 ssl_ocsp leaf;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
62 ssl_verify_client on;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
63 ssl_verify_depth 2;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
64 ssl_client_certificate trusted.crt;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
65
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
66 ssl_ciphers DEFAULT:ECCdraft;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
67
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
68 ssl_certificate_key ec.key;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
69 ssl_certificate ec.crt;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
70
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
71 ssl_certificate_key rsa.key;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
72 ssl_certificate rsa.crt;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
73
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
74 ssl_session_cache shared:SSL:1m;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
75 ssl_session_tickets off;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
76
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
77 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
78
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
79 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
80 listen 127.0.0.1:8443 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
81 server_name localhost;
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
84 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
85 listen 127.0.0.1:8443 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
86 server_name sni;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
87
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
88 ssl_ocsp_responder http://127.0.0.1:8082;
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
91 server {
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
92 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
93 server_name resolver;
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
94
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
95 ssl_ocsp on;
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
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
98 server {
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
99 listen 127.0.0.1:8444 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
100 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
101
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
102 ssl_ocsp_responder http://127.0.0.1:8081;
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
103 ssl_ocsp on;
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
106 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
107 listen 127.0.0.1:8445 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
108 server_name localhost;
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 ssl_ocsp_responder http://127.0.0.1:8082;
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
113 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
114 listen 127.0.0.1:8446 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
115 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
116
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
117 ssl_ocsp_cache shared:OCSP:1m;
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 server {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
121 listen 127.0.0.1:8447 ssl;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
122 server_name localhost;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
123
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
124 ssl_ocsp_responder http://127.0.0.1:8082;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
125 ssl_client_certificate root.crt;
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
129 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
130
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
131 my $d = $t->testdir();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
132 my $p = port(8081);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
133
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
134 $t->write_file('openssl.conf', <<EOF);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
135 [ req ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
136 default_bits = 2048
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
137 encrypt_key = no
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
138 distinguished_name = req_distinguished_name
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
139 [ req_distinguished_name ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
140 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
141
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
142 $t->write_file('ca.conf', <<EOF);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
143 [ ca ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
144 default_ca = myca
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 ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
147 new_certs_dir = $d
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
148 database = $d/certindex
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
149 default_md = sha256
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
150 policy = myca_policy
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
151 serial = $d/certserial
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
152 default_days = 1
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
153 x509_extensions = myca_extensions
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
154
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
155 [ myca_policy ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
156 commonName = supplied
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
157
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
158 [ myca_extensions ]
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
159 basicConstraints = critical,CA:TRUE
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
160 authorityInfoAccess = OCSP;URI:http://127.0.0.1:$p
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
161 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
162
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
163 # 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
164
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
165 $t->write_file('ca2.conf', <<EOF);
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
166 [ ca ]
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
167 default_ca = myca
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
168
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
169 [ myca ]
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
170 new_certs_dir = $d
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
171 database = $d/certindex
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
172 default_md = sha256
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
173 policy = myca_policy
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
174 serial = $d/certserial
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
175 default_days = 1
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
176 x509_extensions = myca_extensions
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
177
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
178 [ myca_policy ]
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
179 commonName = supplied
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
180
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
181 [ myca_extensions ]
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
182 basicConstraints = critical,CA:TRUE
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
183 authorityInfoAccess = OCSP;URI:http://localhost:$p
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
184 EOF
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
185
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
186 foreach my $name ('root') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
187 system('openssl req -x509 -new '
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
188 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
189 . "-out $d/$name.crt -keyout $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
190 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
191 or die "Can't create certificate for $name: $!\n";
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
194 foreach my $name ('int', 'end') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
195 system("openssl req -new "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
196 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
197 . "-out $d/$name.csr -keyout $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
198 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
199 or die "Can't create certificate for $name: $!\n";
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
202 foreach my $name ('ec-end') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
203 system("openssl ecparam -genkey -out $d/$name.key -name prime256v1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
204 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
205 or die "Can't create EC param: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
206 system("openssl req -new -key $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
207 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
208 . "-out $d/$name.csr "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
209 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
210 or die "Can't create certificate for $name: $!\n";
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
213 $t->write_file('certserial', '1000');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
214 $t->write_file('certindex', '');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
215
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
216 system("openssl ca -batch -config $d/ca2.conf "
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
217 . "-keyfile $d/root.key -cert $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
218 . "-subj /CN=int/ -in $d/int.csr -out $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
219 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
220 or die "Can't sign certificate for int: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
221
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
222 system("openssl ca -batch -config $d/ca.conf "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
223 . "-keyfile $d/int.key -cert $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
224 . "-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
225 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
226 or die "Can't sign certificate for ec-end: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
227
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
228 system("openssl ca -batch -config $d/ca.conf "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
229 . "-keyfile $d/int.key -cert $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
230 . "-subj /CN=end/ -in $d/end.csr -out $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
231 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
232 or die "Can't sign certificate for end: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
233
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
234 # RFC 6960, serialNumber
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
235
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
236 system("openssl x509 -in $d/int.crt -serial -noout "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
237 . ">>$d/serial_int 2>>$d/openssl.out") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
238 or die "Can't obtain serial for end: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
239
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
240 my $serial_int = pack("n2", 0x0202, hex $1)
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
241 if $t->read_file('serial_int') =~ /(\d+)/;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
242
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
243 system("openssl x509 -in $d/end.crt -serial -noout "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
244 . ">>$d/serial 2>>$d/openssl.out") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
245 or die "Can't obtain serial for end: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
246
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
247 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
248
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
249 # ocsp end
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
250
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
251 system("openssl ocsp -issuer $d/int.crt -cert $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
252 . "-reqout $d/req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
253 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
254
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
255 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
256 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
257 . "-reqin $d/req.der -respout $d/resp.der -ndays 1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
258 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
259 or die "Can't create OCSP response: $!\n";
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 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
262 . "-reqout $d/ec-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
263 or die "Can't create EC OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
264
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
265 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
266 . "-rsigner $d/root.crt -rkey $d/root.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
267 . "-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
268 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
269 or die "Can't create EC OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
270
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
271 $t->write_file('trusted.crt',
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
272 $t->read_file('int.crt') . $t->read_file('root.crt'));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
273
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
274 # server cert/key
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 system("openssl ecparam -genkey -out $d/ec.key -name prime256v1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
277 . ">>$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
278 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
279 or die "Can't create RSA pem: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
280
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
281 foreach my $name ('ec', 'rsa') {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
282 system("openssl req -x509 -new -key $d/$name.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
283 . "-config $d/openssl.conf -subj /CN=$name/ "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
284 . "-out $d/$name.crt -keyout $d/$name.key "
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 certificate for $name: $!\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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
289 $t->run_daemon(\&http_daemon, $t, port(8081));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
290 $t->run_daemon(\&http_daemon, $t, port(8082));
1693
5ac6efbe5552 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1636
diff changeset
291 $t->run()->plan(14);
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
292
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
293 $t->waitforsocket("127.0.0.1:" . port(8081));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
294 $t->waitforsocket("127.0.0.1:" . port(8082));
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 my $version = get_version();
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
300 like(get('RSA', 'end'), qr/200 OK.*SUCCESS/s, 'ocsp leaf');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
301
1577
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
302 # 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
303
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
304 like(get('RSA', 'end', sni => 'resolver'),
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
305 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
306 'ocsp many failed request');
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
307
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
308 # 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
309
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310 like(get('RSA', 'end', port => 8444),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311 qr/400 Bad.*FAILED:certificate status request failed/s,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312 'ocsp many failed');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
314 # now prepare valid ocsp int response
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
315
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 system("openssl ocsp -issuer $d/root.crt -cert $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 . "-reqout $d/int-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
318 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
319
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
320 system("openssl ocsp -index $d/certindex -CA $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
321 . "-rsigner $d/root.crt -rkey $d/root.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
322 . "-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
323 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
324 or die "Can't create OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
325
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
326 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
327
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328 # store into ssl_ocsp_cache
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
330 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
331
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332 # revoke
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334 system("openssl ca -config $d/ca.conf -revoke $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335 . "-keyfile $d/root.key -cert $d/root.crt "
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 revoke end.crt: $!\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 system("openssl ocsp -issuer $d/int.crt -cert $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
340 . "-reqout $d/req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
341 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
342
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
343 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
344 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
345 . "-reqin $d/req.der -respout $d/revoked.der -ndays 1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
346 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
347 or die "Can't create OCSP response: $!\n";
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 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
350
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
351 # with different responder where it's still valid
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
352
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
353 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
354
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
355 # with different context to responder where it's still valid
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
356
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
357 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
358
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
359 # with cached ocsp response it's still valid
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
360
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
361 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
362
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
363 # ocsp end response signed with invalid (root) cert, expect HTTP 400
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
364
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
365 like(get('ECDSA', 'ec-end'),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
366 qr/400 Bad.*FAILED:certificate status request failed/s,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
367 'root ca not trusted');
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 # now sign ocsp end response with valid int cert
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 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
372 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
373 . "-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
374 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
375 or die "Can't create EC OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
376
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
377 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
378
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
379 my ($s, $ssl) = get('ECDSA', 'ec-end');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
380 my $ses = Net::SSLeay::get_session($ssl);
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', ses => $ses),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
383 qr/200 OK.*SUCCESS:r/s, 'session reused');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
384
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
385 # revoke with saved session
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 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
388 . "-keyfile $d/root.key -cert $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
389 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
390 or die "Can't revoke end.crt: $!\n";
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 ocsp -issuer $d/int.crt -cert $d/ec-end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
393 . "-reqout $d/ec-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
394 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
395
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
396 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
397 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
398 . "-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
399 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
400 or die "Can't create OCSP response: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
401
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
402 # reusing session with revoked certificate
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 like(get('ECDSA', 'ec-end', ses => $ses),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
405 qr/400 Bad.*FAILED:certificate revoked:r/s, 'session reused - revoked');
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 # regression test for self-signed
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('RSA', 'root', port => 8447), qr/200 OK.*SUCCESS/s, 'ocsp one');
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 ###############################################################################
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 sub get {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
414 my ($type, $cert, %extra) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
415 $type = 'PSS' if $type eq 'RSA' && $version > 0x0303;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
416 my ($s, $ssl) = get_ssl_socket($type, $cert, %extra);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
417 my $cipher = Net::SSLeay::get_cipher($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
418 Test::Nginx::log_core('||', "cipher: $cipher");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
419 my $host = $extra{sni} ? $extra{sni} : 'localhost';
1846
9d98c2ad3126 Tests: cleaned up ssl_ocsp.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1693
diff changeset
420 local $SIG{PIPE} = 'IGNORE';
9d98c2ad3126 Tests: cleaned up ssl_ocsp.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1693
diff changeset
421 log_out("GET /serial HTTP/1.0\nHost: $host\n\n");
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
422 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
423 my $r = Net::SSLeay::read($ssl);
1846
9d98c2ad3126 Tests: cleaned up ssl_ocsp.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1693
diff changeset
424 log_in($r);
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
425 $s->close();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
426 return $r unless wantarray();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
427 return ($s, $ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
428 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
429
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
430 sub get_ssl_socket {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
431 my ($type, $cert, %extra) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
432 my $ses = $extra{ses};
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
433 my $sni = $extra{sni};
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
434 my $port = $extra{port} || 8443;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
435 my $s;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
436
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
437 eval {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
438 local $SIG{ALRM} = sub { die "timeout\n" };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
439 local $SIG{PIPE} = sub { die "sigpipe\n" };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
440 alarm(8);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
441 $s = IO::Socket::INET->new('127.0.0.1:' . port($port));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
442 alarm(0);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
443 };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
444 alarm(0);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
445
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
446 if ($@) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
447 log_in("died: $@");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
448 return undef;
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
451 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
452
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
453 if (defined $type) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
454 my $ssleay = Net::SSLeay::SSLeay();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
455 if ($ssleay < 0x1000200f || $ssleay == 0x20000000) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
456 Net::SSLeay::CTX_set_cipher_list($ctx, $type)
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
457 or die("Failed to set cipher list");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
458 } else {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
459 # SSL_CTRL_SET_SIGALGS_LIST
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
460 Net::SSLeay::CTX_ctrl($ctx, 98, 0, $type . '+SHA256')
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
461 or die("Failed to set sigalgs");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
462 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
463 }
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 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
466 or die if $cert;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
467 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
468 Net::SSLeay::set_session($ssl, $ses) if defined $ses;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
469 Net::SSLeay::set_tlsext_host_name($ssl, $sni) if $sni;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
470 Net::SSLeay::set_fd($ssl, fileno($s));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
471 Net::SSLeay::connect($ssl) or die("ssl connect");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
472 return ($s, $ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
473 }
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 sub get_version {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
476 my ($s, $ssl) = get_ssl_socket();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
477 return Net::SSLeay::version($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
478 }
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 ###############################################################################
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 sub http_daemon {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
483 my ($t, $port) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
484 my $server = IO::Socket::INET->new(
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
485 Proto => 'tcp',
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
486 LocalHost => "127.0.0.1:$port",
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
487 Listen => 5,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
488 Reuse => 1
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 or die "Can't create listening socket: $!\n";
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 local $SIG{PIPE} = 'IGNORE';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
493
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
494 while (my $client = $server->accept()) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
495 $client->autoflush(1);
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 my $headers = '';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
498 my $uri = '';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
499 my $resp;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
500
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
501 while (<$client>) {
1846
9d98c2ad3126 Tests: cleaned up ssl_ocsp.t.
Maxim Dounin <mdounin@mdounin.ru>
parents: 1693
diff changeset
502 Test::Nginx::log_core('||', $_);
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
503 $headers .= $_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
504 last if (/^\x0d?\x0a?$/);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
505 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
506
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
507 $uri = $1 if $headers =~ /^\S+\s+\/([^ ]+)\s+HTTP/i;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
508 next unless $uri;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
509
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
510 $uri =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
511 my $req = decode_base64($uri);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
512
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
513 if (index($req, $serial_int) > 0) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
514 $resp = 'int-resp';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
515
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
516 } elsif (index($req, $serial) > 0) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
517 $resp = 'resp';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
518
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
519 # used to differentiate ssl_ocsp_responder
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 if ($port == port(8081) && -e "$d/revoked.der") {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
522 $resp = 'revoked';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
523 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
524
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
525 } else {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
526 $resp = 'ec-resp';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
527 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
528
1636
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
529 next unless -s "$d/$resp.der";
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
530
1570
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
1636
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
542 local $/;
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
543 open my $fh, '<', "$d/$resp.der"
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
544 or die "Can't open $resp.der: $!";
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
545 binmode $fh;
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
546 my $content = <$fh>;
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
547 close $fh;
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
548
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
549 print $client $headers . $content;
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
550 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
551 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
552
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
553 ###############################################################################