Skip to content

Commit 545bf71

Browse files
committed
Tests: reworked ssl_verify_depth tests.
Full matrix of various verify depths and chains is now tested. Incompatible behaviour of OpenSSL 1.1.0+, which now limits the total length of a chain instead of maximum number of signatures checked, is explained in the comments. Attempts to incorrectly use client-provided intermediate certificates, introduced in aa5a61d1254b, are removed.
1 parent 30c8f7b commit 545bf71

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

ssl_verify_depth.t

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
2828
plan(skip_all => 'IO::Socket::SSL too old') if $@;
2929

3030
my $t = Test::Nginx->new()->has(qw/http http_ssl/)
31-
->has_daemon('openssl')->plan(2);
31+
->has_daemon('openssl')->plan(9);
3232

3333
$t->write_file_expand('nginx.conf', <<'EOF');
3434
@@ -42,23 +42,31 @@ events {
4242
http {
4343
%%TEST_GLOBALS_HTTP%%
4444
45-
ssl_certificate_key localhost.key;
4645
ssl_certificate localhost.crt;
46+
ssl_certificate_key localhost.key;
4747
4848
ssl_verify_client on;
49-
ssl_client_certificate root.crt;
49+
ssl_client_certificate root-int.crt;
5050
51+
add_header X-Client $ssl_client_s_dn always;
5152
add_header X-Verify $ssl_client_verify always;
5253
5354
server {
5455
listen 127.0.0.1:8080 ssl;
5556
server_name localhost;
56-
ssl_verify_depth 3;
57+
ssl_verify_depth 0;
5758
}
5859
5960
server {
6061
listen 127.0.0.1:8081 ssl;
6162
server_name localhost;
63+
ssl_verify_depth 1;
64+
}
65+
66+
server {
67+
listen 127.0.0.1:8082 ssl;
68+
server_name localhost;
69+
ssl_verify_depth 2;
6270
}
6371
}
6472
@@ -102,7 +110,7 @@ foreach my $name ('root', 'localhost') {
102110
or die "Can't create certificate for $name: $!\n";
103111
}
104112

105-
foreach my $name ('int', 'int2', 'end') {
113+
foreach my $name ('int', 'end') {
106114
system("openssl req -new "
107115
. "-config $d/openssl.conf -subj /CN=$name/ "
108116
. "-out $d/$name.csr -keyout $d/$name.key "
@@ -121,35 +129,54 @@ system("openssl ca -batch -config $d/ca.conf "
121129

122130
system("openssl ca -batch -config $d/ca.conf "
123131
. "-keyfile $d/int.key -cert $d/int.crt "
124-
. "-subj /CN=int2/ -in $d/int2.csr -out $d/int2.crt "
125-
. ">>$d/openssl.out 2>&1") == 0
126-
or die "Can't sign certificate for int2: $!\n";
127-
128-
system("openssl ca -batch -config $d/ca.conf "
129-
. "-keyfile $d/int2.key -cert $d/int2.crt "
130132
. "-subj /CN=end/ -in $d/end.csr -out $d/end.crt "
131133
. ">>$d/openssl.out 2>&1") == 0
132134
or die "Can't sign certificate for end: $!\n";
133135

134-
$t->write_file('client.key', $t->read_file('end.key') .
135-
$t->read_file('int.key') . $t->read_file('int2.key'));
136-
$t->write_file('client.crt', $t->read_file('end.crt') .
137-
$t->read_file('int.crt') . $t->read_file('int2.crt'));
136+
$t->write_file('root-int.crt', $t->read_file('root.crt')
137+
. $t->read_file('int.crt'));
138138

139139
$t->write_file('t', '');
140140
$t->run();
141141

142142
###############################################################################
143143

144-
like(get(8080, 'client'), qr/SUCCESS/, 'verify depth');
145-
like(get(8081, 'client'), qr/FAILED/, 'verify depth limited');
144+
# with verify depth 0, only self-signed certificates should
145+
# be allowed
146+
147+
# OpenSSL 1.1.0+ instead limits the number of intermediate certs allowed;
148+
# as a result, it is not possible to limit certificate checking
149+
# to self-signed certificates only when using OpenSSL 1.1.0+
150+
151+
like(get(8080, 'root'), qr/SUCCESS/, 'verify depth 0 - root');
152+
like(get(8080, 'int'), qr/FAI|SUC/, 'verify depth 0 - no int');
153+
like(get(8080, 'end'), qr/FAILED/, 'verify depth 0 - no end');
154+
155+
# with verify depth 1 (the default), one signature is
156+
# expected to be checked, so certificates directly signed
157+
# by the root cert are allowed, but nothing more
158+
159+
# OpenSSL 1.1.0+ instead limits the number of intermediate certs allowed;
160+
# so with depth 1 it is possible to validate not only directly signed
161+
# certificates, but also chains with one intermediate certificate
162+
163+
like(get(8081, 'root'), qr/SUCCESS/, 'verify depth 1 - root');
164+
like(get(8081, 'int'), qr/SUCCESS/, 'verify depth 1 - int');
165+
like(get(8081, 'end'), qr/FAI|SUC/, 'verify depth 1 - no end');
166+
167+
# with verify depth 2 it is also possible to validate up to two signatures,
168+
# so chains with one intermediate certificate are allowed
169+
170+
like(get(8082, 'root'), qr/SUCCESS/, 'verify depth 2 - root');
171+
like(get(8082, 'int'), qr/SUCCESS/, 'verify depth 2 - int');
172+
like(get(8082, 'end'), qr/SUCCESS/, 'verify depth 2 - end');
146173

147174
###############################################################################
148175

149176
sub get {
150177
my ($port, $cert) = @_;
151178
my $s = get_ssl_socket($port, $cert) or return;
152-
http_get('/t', socket => $s);
179+
http_get("/t?$cert", socket => $s);
153180
}
154181

155182
sub get_ssl_socket {

0 commit comments

Comments
 (0)