Mercurial > hg > nginx-tests
annotate stream_ssl_preread_protocol.t @ 1571:1b4ceab9cb1c
Tests: fixed ssl_certificate.t with LibreSSL client.
Net::SSLeay::connect() that manages TLS handshake could return unexpected
error when receiving server alert, as seen in server certificate tests if
it could not been selected. Typically, it returns the expected error -1,
but with certain libssl implementations it can be 0, as explained below.
The error is propagated from libssl's SSL_connect(), which is usually -1.
In modern OpenSSL versions, it is the default error code used in the state
machine returned when something went wrong with parsing TLS message header.
In versions up to OpenSSL 1.0.2, with SSLv23_method() used by default, -1
is the only error code in the ssl_connect() method implementation which is
used as well if receiving alert while parsing ServerHello. BoringSSL also
seems to return -1. But it is not so with LibreSSL that returns zero.
Previously, tests failed with client built with LibreSSL with SSLv3 removed.
Here, the error is propagated directly from ssl_read_bytes() method, which
is always implemented as ssl3_read_bytes() in all TLS methods. It could be
also seen with OpenSSL up to 1.0.2 with non-default methods explicitly set.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Fri, 29 May 2020 23:10:20 +0300 |
parents | 144c6ce732e4 |
children | f3ba4c74de31 |
rev | line source |
---|---|
1357
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream_ssl_preread module, protocol preread. |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/stream stream_ssl_preread stream_return/) |
1535
144c6ce732e4
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1358
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF')->plan(7)->run(); |
1357
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 events { |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 } |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 stream { |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 server { |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 listen 127.0.0.1:8080; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 ssl_preread on; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 return $ssl_preread_protocol; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 } |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 } |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 EOF |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 ############################################################################### |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 is(get('SSLv3'), 'SSLv3', 'client hello SSLv3'); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 is(get('TLSv1'), 'TLSv1', 'client hello TLSv1'); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 is(get('TLSv1.1'), 'TLSv1.1', 'client hello TLSv1.1'); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 is(get('TLSv1.2'), 'TLSv1.2', 'client hello TLSv1.2'); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 is(get_tls13(), 'TLSv1.3', 'client hello supported_versions'); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
1358
71f964c077bf
Tests: adjusted ssl_preread_protocol tests with V2ClientHello.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1357
diff
changeset
|
54 is(get_ssl2('SSLv2'), 'SSLv2', 'client hello version 2'); |
71f964c077bf
Tests: adjusted ssl_preread_protocol tests with V2ClientHello.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1357
diff
changeset
|
55 is(get_ssl2('TLSv1'), 'TLSv1', 'client hello version 2 - TLSv1'); |
1357
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 ############################################################################### |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 sub get { |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 my $v = shift; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 my ($re, $ch); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 $re = 0x0300, $ch = 0x0300 if $v eq 'SSLv3'; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 $re = 0x0301, $ch = 0x0301 if $v eq 'TLSv1'; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 $re = 0x0301, $ch = 0x0302 if $v eq 'TLSv1.1'; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 $re = 0x0301, $ch = 0x0303 if $v eq 'TLSv1.2'; |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 my $r = pack("CnNn2C", 0x16, $re, 0x00380100, 0x0034, $ch, 0xeb); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 $r .= pack("N*", 0x6357cdba, 0xa6b8d853, 0xf1f6ac0f); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 $r .= pack("N*", 0xdf03178c, 0x0ae41824, 0xe7643682); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 $r .= pack("N*", 0x3c1b273f, 0xbfde4b00, 0x00000000); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 $r .= pack("CN3", 0x0c, 0x00000008, 0x00060000, 0x03666f6f); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 http($r); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 } |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 sub get_tls13 { |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 my $r = pack("N*", 0x16030100, 0x33010000, 0x2f0303eb); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 $r .= pack("N*", 0x6357cdba, 0xa6b8d853, 0xf1f6ac0f); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 $r .= pack("N*", 0xdf03178c, 0x0ae41824, 0xe7643682); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 $r .= pack("N*", 0x3c1b273f, 0xbfde4b00, 0x00000000); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 $r .= pack("CNCn", 0x07, 0x002b0007, 0x02, 0x7f1c); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 http($r); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 } |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 sub get_ssl2 { |
1358
71f964c077bf
Tests: adjusted ssl_preread_protocol tests with V2ClientHello.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1357
diff
changeset
|
88 my $v = shift; |
71f964c077bf
Tests: adjusted ssl_preread_protocol tests with V2ClientHello.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1357
diff
changeset
|
89 my $ch; |
71f964c077bf
Tests: adjusted ssl_preread_protocol tests with V2ClientHello.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1357
diff
changeset
|
90 |
71f964c077bf
Tests: adjusted ssl_preread_protocol tests with V2ClientHello.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1357
diff
changeset
|
91 $ch = 0x0002 if $v eq 'SSLv2'; |
71f964c077bf
Tests: adjusted ssl_preread_protocol tests with V2ClientHello.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1357
diff
changeset
|
92 $ch = 0x0301 if $v eq 'TLSv1'; |
71f964c077bf
Tests: adjusted ssl_preread_protocol tests with V2ClientHello.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1357
diff
changeset
|
93 |
71f964c077bf
Tests: adjusted ssl_preread_protocol tests with V2ClientHello.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1357
diff
changeset
|
94 my $r = pack("nCn4", 0x801c, 0x01, $ch, 0x0003, 0x0000, 0x0010); |
1357
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 $r .= pack("C3", 0x01, 0x00, 0x80); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 $r .= pack("N4", 0x322dd95c, 0x4749ef17, 0x3d5f0916, 0xf0b730f8); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 http($r); |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 } |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
2415ef05a282
Tests: stream_ssl_preread module tests, protocol preread.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
101 ############################################################################### |