annotate ssl_ocsp.t @ 1728:6d5ecf445e57

Tests: added HTTP/2 test with big request body. Notably, it is useful with body buffering in filters, in which case the stream window is flow controlled based on the preread buffer.
author Sergey Kandaurov <pluknet@nginx.com>
date Sat, 04 Sep 2021 14:50:02 +0300
parents 5ac6efbe5552
children 9d98c2ad3126
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));
1693
5ac6efbe5552 Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1636
diff changeset
290 $t->run()->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 like(get('RSA', 'end', sni => 'resolver'),
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
304 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
305 'ocsp many failed request');
804a7409bc63 Tests: added ssl_ocsp test with failing request.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1570
diff changeset
306
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
307 # 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
308
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
309 like(get('RSA', 'end', port => 8444),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
310 qr/400 Bad.*FAILED:certificate status request failed/s,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
311 'ocsp many failed');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
312
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
313 # now prepare valid ocsp int 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 system("openssl ocsp -issuer $d/root.crt -cert $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
316 . "-reqout $d/int-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
317 or die "Can't create OCSP request: $!\n";
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 system("openssl ocsp -index $d/certindex -CA $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
320 . "-rsigner $d/root.crt -rkey $d/root.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
321 . "-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
322 . ">>$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 response: $!\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 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
326
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
327 # store into ssl_ocsp_cache
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
328
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
329 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
330
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
331 # revoke
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
332
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
333 system("openssl ca -config $d/ca.conf -revoke $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
334 . "-keyfile $d/root.key -cert $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
335 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
336 or die "Can't revoke end.crt: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
337
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
338 system("openssl ocsp -issuer $d/int.crt -cert $d/end.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
339 . "-reqout $d/req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
340 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
341
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
342 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
343 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
344 . "-reqin $d/req.der -respout $d/revoked.der -ndays 1 "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
345 . ">>$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 response: $!\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 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
349
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
350 # with different responder where it's still valid
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
351
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
352 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
353
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
354 # with different context to responder where it's still valid
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 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
357
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
358 # with cached ocsp response it's still valid
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 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
361
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
362 # ocsp end response signed with invalid (root) cert, expect HTTP 400
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 like(get('ECDSA', 'ec-end'),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
365 qr/400 Bad.*FAILED:certificate status request failed/s,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
366 'root ca not trusted');
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 # now sign ocsp end response with valid int cert
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 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
371 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
372 . "-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
373 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
374 or die "Can't create EC OCSP response: $!\n";
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 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
377
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
378 my ($s, $ssl) = get('ECDSA', 'ec-end');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
379 my $ses = Net::SSLeay::get_session($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
380
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
381 like(get('ECDSA', 'ec-end', ses => $ses),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
382 qr/200 OK.*SUCCESS:r/s, 'session reused');
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 # revoke with saved session
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
385
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
386 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
387 . "-keyfile $d/root.key -cert $d/root.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
388 . ">>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
389 or die "Can't revoke end.crt: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
390
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
391 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
392 . "-reqout $d/ec-req.der >>$d/openssl.out 2>&1") == 0
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
393 or die "Can't create OCSP request: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
394
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
395 system("openssl ocsp -index $d/certindex -CA $d/int.crt "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
396 . "-rsigner $d/int.crt -rkey $d/int.key "
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
397 . "-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
398 . ">>$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 response: $!\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 # reusing session with revoked certificate
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
402
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
403 like(get('ECDSA', 'ec-end', ses => $ses),
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
404 qr/400 Bad.*FAILED:certificate revoked:r/s, 'session reused - revoked');
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
405
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
406 # regression test for self-signed
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
407
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
408 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
409
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
410 ###############################################################################
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
411
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
412 sub get {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
413 my ($type, $cert, %extra) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
414 $type = 'PSS' if $type eq 'RSA' && $version > 0x0303;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
415 my ($s, $ssl) = get_ssl_socket($type, $cert, %extra);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
416 my $cipher = Net::SSLeay::get_cipher($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
417 Test::Nginx::log_core('||', "cipher: $cipher");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
418 my $host = $extra{sni} ? $extra{sni} : 'localhost';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
419 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
420 my $r = Net::SSLeay::read($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
421 Test::Nginx::log_core($r);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
422 $s->close();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
423 return $r unless wantarray();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
424 return ($s, $ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
425 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
426
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
427 sub get_ssl_socket {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
428 my ($type, $cert, %extra) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
429 my $ses = $extra{ses};
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
430 my $sni = $extra{sni};
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
431 my $port = $extra{port} || 8443;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
432 my $s;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
433
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
434 eval {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
435 local $SIG{ALRM} = sub { die "timeout\n" };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
436 local $SIG{PIPE} = sub { die "sigpipe\n" };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
437 alarm(8);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
438 $s = IO::Socket::INET->new('127.0.0.1:' . port($port));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
439 alarm(0);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
440 };
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
441 alarm(0);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
442
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
443 if ($@) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
444 log_in("died: $@");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
445 return undef;
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
448 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
449
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
450 if (defined $type) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
451 my $ssleay = Net::SSLeay::SSLeay();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
452 if ($ssleay < 0x1000200f || $ssleay == 0x20000000) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
453 Net::SSLeay::CTX_set_cipher_list($ctx, $type)
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
454 or die("Failed to set cipher list");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
455 } else {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
456 # SSL_CTRL_SET_SIGALGS_LIST
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
457 Net::SSLeay::CTX_ctrl($ctx, 98, 0, $type . '+SHA256')
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
458 or die("Failed to set sigalgs");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
459 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
460 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
461
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
462 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
463 or die if $cert;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
464 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
465 Net::SSLeay::set_session($ssl, $ses) if defined $ses;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
466 Net::SSLeay::set_tlsext_host_name($ssl, $sni) if $sni;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
467 Net::SSLeay::set_fd($ssl, fileno($s));
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
468 Net::SSLeay::connect($ssl) or die("ssl connect");
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
469 return ($s, $ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
470 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
471
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
472 sub get_version {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
473 my ($s, $ssl) = get_ssl_socket();
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
474 return Net::SSLeay::version($ssl);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
475 }
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
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
479 sub http_daemon {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
480 my ($t, $port) = @_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
481 my $server = IO::Socket::INET->new(
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
482 Proto => 'tcp',
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
483 LocalHost => "127.0.0.1:$port",
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
484 Listen => 5,
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
485 Reuse => 1
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
486 )
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
487 or die "Can't create listening socket: $!\n";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
488
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
489 local $SIG{PIPE} = 'IGNORE';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
490
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
491 while (my $client = $server->accept()) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
492 $client->autoflush(1);
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 my $headers = '';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
495 my $uri = '';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
496 my $resp;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
497
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
498 while (<$client>) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
499 $headers .= $_;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
500 last if (/^\x0d?\x0a?$/);
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
501 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
502
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
503 $uri = $1 if $headers =~ /^\S+\s+\/([^ ]+)\s+HTTP/i;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
504 next unless $uri;
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 $uri =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
507 my $req = decode_base64($uri);
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 if (index($req, $serial_int) > 0) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
510 $resp = 'int-resp';
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 } elsif (index($req, $serial) > 0) {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
513 $resp = 'resp';
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 # used to differentiate ssl_ocsp_responder
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
516
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
517 if ($port == port(8081) && -e "$d/revoked.der") {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
518 $resp = 'revoked';
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
519 }
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 } else {
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
522 $resp = 'ec-resp';
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
1636
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
525 next unless -s "$d/$resp.der";
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
526
1570
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
527 # ocsp dummy handler
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
528
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
529 select undef, undef, undef, 0.02;
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 $headers = <<"EOF";
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
532 HTTP/1.1 200 OK
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
533 Connection: close
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
534 Content-Type: application/ocsp-response
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
535
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
536 EOF
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
537
1636
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
538 local $/;
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
539 open my $fh, '<', "$d/$resp.der"
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
540 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
541 binmode $fh;
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
542 my $content = <$fh>;
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
543 close $fh;
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
544
2d371452658c Tests: fixed serving binary OCSP responses on win32.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1577
diff changeset
545 print $client $headers . $content;
1570
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 }
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
548
0077b80ef745 Tests: ssl_ocsp tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff changeset
549 ###############################################################################