Mercurial > hg > nginx-tests
annotate lib/Test/Nginx/HTTP3.pm @ 1960:e44ee916b959
Tests: adjusted http_headers_multi.t for $content_length changes.
The $content_length variable is going to be not available after discarding
the request body. As such, the relevant location is now proxied, so the
request body is not discarded.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 27 Apr 2024 18:55:21 +0300 |
parents | 9877dce42a59 |
children | c7315caf2110 |
rev | line source |
---|---|
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 package Test::Nginx::HTTP3; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Module for nginx QUIC tests. |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use IO::Socket::INET; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 use IO::Select; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 use Data::Dumper; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use Test::Nginx; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 sub new { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 my $self = {}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 bless $self, shift @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 my ($port, %extra) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 require Crypt::KeyDerivation; |
1934
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
26 require Crypt::PK::ECC; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 require Crypt::PK::X25519; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 require Crypt::PRNG; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 require Crypt::AuthEnc::GCM; |
1910
e0b53fbdb5cf
Tests: TLS_AES_128_CCM_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1909
diff
changeset
|
30 require Crypt::AuthEnc::CCM; |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
31 require Crypt::AuthEnc::ChaCha20Poly1305; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 require Crypt::Mode::CTR; |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
33 require Crypt::Stream::ChaCha; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 require Crypt::Digest; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 require Crypt::Mac::HMAC; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 $self->{socket} = IO::Socket::INET->new( |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 Proto => "udp", |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 PeerAddr => '127.0.0.1:' . port($port || 8980), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 ); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 $self->{repeat} = 0; |
1915
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
43 $self->{token} = $extra{token} || ''; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 $self->{psk_list} = $extra{psk_list} || []; |
1917
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
45 $self->{early_data} = $extra{early_data}; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 $self->{sni} = exists $extra{sni} ? $extra{sni} : 'localhost'; |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
48 $self->{cipher} = 0x1301; |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
49 $self->{ciphers} = $extra{ciphers} || "\x13\x01"; |
1934
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
50 $self->{group} = $extra{group} || 'x25519'; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 $self->{opts} = $extra{opts}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 $self->{zero} = pack("x5"); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
55 $self->{static_encode} = [ static_table() ]; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
56 $self->{static_decode} = [ static_table() ]; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
57 $self->{dynamic_encode} = []; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
58 $self->{last_stream} = -4; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 $self->{buf} = ''; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 $self->init(); |
1938
e1059682aeef
Tests: fixed ClientHello with resending Initial QUIC packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1934
diff
changeset
|
62 $self->init_key_schedule(); |
1915
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
63 $self->retry(%extra) or return; |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
64 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 return $self; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 sub init { |
1917
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
69 my ($self) = @_; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 $self->{keys} = []; |
1930
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
71 $self->{key_phase} = 0; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 $self->{pn} = [[-1, -1, -1, -1], [-1, -1, -1, -1]]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 $self->{crypto_in} = [[],[],[],[]]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 $self->{stream_in} = []; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 $self->{frames_in} = []; |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
76 $self->{frames_incomplete} = []; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 $self->{tlsm} = (); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 $self->{tlsm}{$_} = '' |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 for 'ch', 'sh', 'ee', 'cert', 'cv', 'sf', 'cf', 'nst'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 $self->{requests} = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 # Initial |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 $self->{odcid} = undef; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 $self->{scid} = Crypt::PRNG::random_bytes(17); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 $self->{dcid} = Crypt::PRNG::random_bytes(18); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
87 $self->{salt} = "\x38\x76\x2c\xf7\xf5\x59\x34\xb3\x4d\x17" |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
88 . "\x9a\xe6\xa4\xc8\x0c\xad\xcc\xbb\x7f\x0a"; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
89 $self->{ncid} = []; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
90 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
91 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
92 sub retry { |
1915
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
93 my ($self, %extra) = @_; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
94 my $prk = Crypt::KeyDerivation::hkdf_extract($self->{dcid}, |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
95 $self->{salt}, 'SHA256'); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
96 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
97 Test::Nginx::log_core('||', "scid = " . unpack("H*", $self->{scid})); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
98 Test::Nginx::log_core('||', "dcid = " . unpack("H*", $self->{dcid})); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
99 Test::Nginx::log_core('||', "prk = " . unpack("H*", $prk)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
100 |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
101 $self->set_traffic_keys('tls13 client in', 'SHA256', 32, 0, 'w', $prk); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
102 $self->set_traffic_keys('tls13 server in', 'SHA256', 32, 0, 'r', $prk); |
1915
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
103 |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
104 $self->initial(); |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
105 return $self if $extra{probe}; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
106 $self->handshake() or return; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
107 |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
108 # RFC 9204, 4.3.1. Set Dynamic Table Capacity |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
109 |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
110 my $buf = pack("B*", '001' . ipack(5, $extra{capacity} || 400)); |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
111 $self->{encoder_offset} = length($buf) + 1; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
112 $buf = "\x08\x02\x02" . $buf; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
113 |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
114 # RFC 9114, 6.2.1. Control Streams |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
115 |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
116 $buf = "\x0a\x06\x03\x00\x04\x00" . $buf; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
117 $self->{control_offset} = 3; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
118 |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
119 $self->raw_write($buf); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
120 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
121 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
122 sub init_key_schedule { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
123 my ($self) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
124 $self->{psk} = $self->{psk_list}[0]; |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
125 my ($hash, $hlen) = $self->{psk} && $self->{psk}{cipher} == 0x1302 ? |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
126 ('SHA384', 48) : ('SHA256', 32); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
127 $self->{es_prk} = Crypt::KeyDerivation::hkdf_extract( |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
128 $self->{psk}->{secret} || pack("x$hlen"), pack("x$hlen"), |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
129 $hash); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
130 Test::Nginx::log_core('||', "es = " . unpack("H*", $self->{es_prk})); |
1934
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
131 |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
132 $self->tls_generate_key(); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
133 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
134 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
135 sub initial { |
1917
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
136 my ($self) = @_; |
1938
e1059682aeef
Tests: fixed ClientHello with resending Initial QUIC packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1934
diff
changeset
|
137 $self->{tlsm}{ch} ||= $self->build_tls_client_hello(); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
138 my $ch = $self->{tlsm}{ch}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
139 my $crypto = build_crypto($ch); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
140 my $padding = 1200 - length($crypto); |
1917
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
141 $padding = 0 if $padding < 0; |
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
142 $padding = 0 if $self->{psk}{ed} && $self->{early_data}; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
143 my $payload = $crypto . pack("x$padding"); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
144 my $initial = $self->encrypt_aead($payload, 0); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
145 |
1917
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
146 if ($self->{early_data} && $self->{psk}->{ed}) { |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
147 my ($hash, $hlen) = $self->{psk}{cipher} == 0x1302 ? |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
148 ('SHA384', 48) : ('SHA256', 32); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
149 $self->set_traffic_keys('tls13 c e traffic', $hash, $hlen, 1, |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
150 'w', $self->{es_prk}, Crypt::Digest::digest_data($hash, |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
151 $self->{tlsm}{ch})); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
152 |
1917
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
153 $payload = $self->build_new_stream($self->{early_data}); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
154 $padding = 1200 - length($crypto) - length($payload); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
155 $payload .= pack("x$padding") if $padding > 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
156 $initial .= $self->encrypt_aead($payload, 1); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
157 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
158 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
159 $self->{socket}->syswrite($initial); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
160 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
161 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
162 sub handshake { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
163 my ($self) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
164 my $buf = ''; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
165 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
166 $self->read_tls_message(\$buf, \&parse_tls_server_hello) or return; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
167 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
168 my $sh = $self->{tlsm}{sh}; |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
169 $self->{cipher} = unpack("n", substr($sh, 6 + 32 + 1, 2)); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
170 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
171 my $extens_len = unpack("C*", substr($sh, 6 + 32 + 4, 2)) * 8 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
172 + unpack("C*", substr($sh, 6 + 32 + 5, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
173 my $extens = substr($sh, 6 + 32 + 4 + 2, $extens_len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
174 my $pub = key_share($extens); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
175 Test::Nginx::log_core('||', "pub = " . unpack("H*", $pub)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
176 |
1934
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
177 my $shared_secret = $self->tls_shared_secret($pub); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
178 Test::Nginx::log_core('||', "shared = " . unpack("H*", $shared_secret)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
179 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
180 # tls13_advance_key_schedule |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
181 |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
182 my ($hash, $hlen) = $self->{cipher} == 0x1302 ? |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
183 ('SHA384', 48) : ('SHA256', 32); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
184 |
1884
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
185 my $psk = pre_shared_key($extens); |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
186 $self->{psk} = (defined $psk && $self->{psk_list}[$psk]) || undef; |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
187 $self->{es_prk} = Crypt::KeyDerivation::hkdf_extract( |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
188 $self->{psk}->{secret} || pack("x$hlen"), pack("x$hlen"), |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
189 $hash); |
1884
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
190 |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
191 $self->{hs_prk} = hkdf_advance($hash, $hlen, $shared_secret, |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
192 $self->{es_prk}); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
193 Test::Nginx::log_core('||', "es = " . unpack("H*", $self->{es_prk})); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
194 Test::Nginx::log_core('||', "hs = " . unpack("H*", $self->{hs_prk})); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
195 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
196 # derive_secret_with_transcript |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
197 |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
198 my $digest = Crypt::Digest::digest_data($hash, $self->{tlsm}{ch} |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
199 . $self->{tlsm}{sh}); |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
200 $self->set_traffic_keys('tls13 c hs traffic', $hash, $hlen, 2, 'w', |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
201 $self->{hs_prk}, $digest); |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
202 $self->set_traffic_keys('tls13 s hs traffic', $hash, $hlen, 2, 'r', |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
203 $self->{hs_prk}, $digest); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
204 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
205 $self->read_tls_message(\$buf, \&parse_tls_encrypted_extensions); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
206 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
207 unless (keys %{$self->{psk}}) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
208 $self->read_tls_message(\$buf, \&parse_tls_certificate); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
209 $self->read_tls_message(\$buf, \&parse_tls_certificate_verify); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
210 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
211 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
212 $self->read_tls_message(\$buf, \&parse_tls_finished); |
1924
0e4ff5f83653
Tests: saved input buffer after processing QUIC long packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1917
diff
changeset
|
213 $self->{buf} = $buf; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
214 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
215 # tls13_advance_key_schedule(application) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
216 |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
217 $self->{ms_prk} = hkdf_advance($hash, $hlen, pack("x$hlen"), |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
218 $self->{hs_prk}); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
219 Test::Nginx::log_core('||', |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
220 "master = " . unpack("H*", $self->{ms_prk})); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
221 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
222 # derive_secret_with_transcript(application) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
223 |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
224 $digest = Crypt::Digest::digest_data($hash, $self->{tlsm}{ch} |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
225 . $self->{tlsm}{sh} . $self->{tlsm}{ee} . $self->{tlsm}{cert} |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
226 . $self->{tlsm}{cv} . $self->{tlsm}{sf}); |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
227 $self->set_traffic_keys('tls13 c ap traffic', $hash, $hlen, 3, 'w', |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
228 $self->{ms_prk}, $digest); |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
229 $self->set_traffic_keys('tls13 s ap traffic', $hash, $hlen, 3, 'r', |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
230 $self->{ms_prk}, $digest); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
231 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
232 # client finished |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
233 |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
234 my $finished = tls13_finished($hash, $hlen, $self->{keys}[2]{w}{prk}, |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
235 $digest); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
236 Test::Nginx::log_core('||', "finished = " . unpack("H*", $finished)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
237 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
238 $self->{tlsm}{cf} = $finished; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
239 |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
240 $digest = Crypt::Digest::digest_data($hash, $self->{tlsm}{ch} |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
241 . $self->{tlsm}{sh} . $self->{tlsm}{ee} . $self->{tlsm}{cert} |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
242 . $self->{tlsm}{cv} . $self->{tlsm}{sf} . $self->{tlsm}{cf}); |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
243 $self->{rms_prk} = hkdf_expand_label("tls13 res master", $hash, $hlen, |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
244 $self->{ms_prk}, $digest); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
245 Test::Nginx::log_core('||', |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
246 "resumption = " . unpack("H*", $self->{rms_prk})); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
247 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
248 my $crypto = build_crypto($finished); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
249 $self->{socket}->syswrite($self->encrypt_aead($crypto, 2)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
250 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
251 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
252 sub DESTROY { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
253 my ($self) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
254 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
255 return unless $self->{socket}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
256 return unless $self->{keys}[3]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
257 my $frame = build_cc(0, "graceful shutdown"); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
258 $self->{socket}->syswrite($self->encrypt_aead($frame, 3)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
259 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
260 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
261 sub ping { |
1941
2c4f1019ee0d
Tests: extended interface for sending QUIC PINGs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1940
diff
changeset
|
262 my ($self, $level, $pad) = @_; |
2c4f1019ee0d
Tests: extended interface for sending QUIC PINGs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1940
diff
changeset
|
263 $level = 3 if !defined $level; |
2c4f1019ee0d
Tests: extended interface for sending QUIC PINGs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1940
diff
changeset
|
264 $pad = 4 if !defined $pad; |
2c4f1019ee0d
Tests: extended interface for sending QUIC PINGs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1940
diff
changeset
|
265 my $frame = "\x01" . "\x00" x ($pad - 1); |
2c4f1019ee0d
Tests: extended interface for sending QUIC PINGs.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1940
diff
changeset
|
266 $self->{socket}->syswrite($self->encrypt_aead($frame, $level)); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
267 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
268 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
269 sub reset_stream { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
270 my ($self, $sid, $code) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
271 my $final_size = $self->{streams}{$sid}{sent}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
272 my $frame = "\x04" . build_int($sid) . build_int($code) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
273 . build_int($final_size); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
274 $self->{socket}->syswrite($self->encrypt_aead($frame, 3)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
275 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
276 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
277 sub stop_sending { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
278 my ($self, $sid, $code) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
279 my $frame = "\x05" . build_int($sid) . build_int($code); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
280 $self->{socket}->syswrite($self->encrypt_aead($frame, 3)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
281 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
282 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
283 sub new_connection_id { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
284 my ($self, $seqno, $ret, $id, $token) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
285 my $frame = "\x18" . build_int($seqno) . build_int($ret) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
286 . pack("C", length($id)) . $id . $token; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
287 $self->{socket}->syswrite($self->encrypt_aead($frame, 3)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
288 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
289 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
290 sub path_challenge { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
291 my ($self, $data) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
292 my $frame = "\x1a" . $data; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
293 $self->{socket}->syswrite($self->encrypt_aead($frame, 3)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
294 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
295 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
296 sub path_response { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
297 my ($self, $data) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
298 my $frame = "\x1b" . $data; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
299 $self->{socket}->syswrite($self->encrypt_aead($frame, 3)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
300 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
301 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
302 ############################################################################### |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
303 |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
304 # HTTP/3 routines |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
305 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
306 # 4.3.2. Insert with Name Reference |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
307 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
308 sub insert_reference { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
309 my ($self, $name, $value, %extra) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
310 my $table = $extra{dyn} |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
311 ? $self->{dynamic_encode} |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
312 : $self->{static_encode}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
313 my $huff = $extra{huff}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
314 my $hbit = $huff ? '1' : '0'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
315 my $dbit = $extra{dyn} ? '0' : '1'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
316 my ($index, $buf) = 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
317 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
318 ++$index until $index > $#$table |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
319 or $table->[$index][0] eq $name; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
320 $table = $self->{dynamic_encode}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
321 splice @$table, 0, 0, [ $name, $value ]; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
322 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
323 $value = $huff ? huff($value) : $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
324 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
325 $buf = pack('B*', '1' . $dbit . ipack(6, $index)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
326 $buf .= pack('B*', $hbit . ipack(7, length($value))) . $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
327 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
328 my $offset = $self->{encoder_offset}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
329 my $length = length($buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
330 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
331 $self->{encoder_offset} += $length; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
332 $self->raw_write("\x0e\x02" |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
333 . build_int($offset) . build_int($length) . $buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
334 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
335 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
336 # 4.3.3. Insert with Literal Name |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
337 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
338 sub insert_literal { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
339 my ($self, $name, $value, %extra) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
340 my $table = $self->{dynamic_encode}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
341 my $huff = $extra{huff}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
342 my $hbit = $huff ? '1' : '0'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
343 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
344 splice @$table, 0, 0, [ $name, $value ]; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
345 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
346 $name = $huff ? huff($name) : $name; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
347 $value = $huff ? huff($value) : $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
348 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
349 my $buf = pack('B*', '01' . $hbit . ipack(5, length($name))) . $name; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
350 $buf .= pack('B*', $hbit . ipack(7, length($value))) . $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
351 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
352 my $offset = $self->{encoder_offset}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
353 my $length = length($buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
354 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
355 $self->{encoder_offset} += $length; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
356 $self->raw_write("\x0e\x02" |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
357 . build_int($offset) . build_int($length) . $buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
358 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
359 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
360 # 4.3.4. Duplicate |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
361 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
362 sub duplicate { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
363 my ($self, $name, $value, %extra) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
364 my $table = $self->{dynamic_encode}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
365 my $index = 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
366 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
367 ++$index until $index > $#$table |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
368 or $table->[$index][0] eq $name; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
369 splice @$table, 0, 0, [ $table->[$index][0], $table->[$index][1] ]; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
370 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
371 my $buf = pack('B*', '000' . ipack(5, $index)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
372 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
373 my $offset = $self->{encoder_offset}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
374 my $length = length($buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
375 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
376 $self->{encoder_offset} += $length; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
377 $self->raw_write("\x0e\x02" |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
378 . build_int($offset) . build_int($length) . $buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
379 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
380 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
381 sub max_push_id { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
382 my ($self, $val) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
383 $val = build_int($val); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
384 my $buf = "\x0d" . build_int(length($val)) . $val; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
385 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
386 my $offset = $self->{control_offset}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
387 my $length = length($buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
388 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
389 $self->{control_offset} += $length; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
390 $self->raw_write("\x0e\x06" |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
391 . build_int($offset) . build_int($length) . $buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
392 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
393 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
394 sub cancel_push { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
395 my ($self, $val) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
396 $val = build_int($val); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
397 my $buf = "\x03" . build_int(length($val)) . $val; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
398 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
399 my $offset = $self->{control_offset}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
400 my $length = length($buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
401 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
402 $self->{control_offset} += $length; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
403 $self->raw_write("\x0e\x06" |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
404 . build_int($offset) . build_int($length) . $buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
405 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
406 |
1917
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
407 sub build_new_stream { |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
408 my ($self, $uri, $stream) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
409 my ($input, $buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
410 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
411 $self->{headers} = ''; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
412 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
413 my $host = $uri->{host} || 'localhost'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
414 my $method = $uri->{method} || 'GET'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
415 my $scheme = $uri->{scheme} || 'http'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
416 my $path = $uri->{path} || '/'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
417 my $headers = $uri->{headers}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
418 my $body = $uri->{body}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
419 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
420 if ($stream) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
421 $self->{last_stream} = $stream; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
422 } else { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
423 $self->{last_stream} += 4; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
424 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
425 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
426 unless ($headers) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
427 $input = qpack($self, ":method", $method); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
428 $input .= qpack($self, ":scheme", $scheme); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
429 $input .= qpack($self, ":path", $path); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
430 $input .= qpack($self, ":authority", $host); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
431 $input .= qpack($self, "content-length", length($body)) |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
432 if $body; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
433 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
434 } else { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
435 $input = join '', map { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
436 qpack($self, $_->{name}, $_->{value}, |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
437 mode => $_->{mode}, huff => $_->{huff}, |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
438 idx => $_->{idx}, dyn => $_->{dyn}) |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
439 } @$headers if $headers; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
440 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
441 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
442 # encoded field section prefix |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
443 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
444 my $table = $self->{dynamic_encode}; |
1883
ff50c265a5ac
Tests: HTTP/3 tests with streams blocked on insert count.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1875
diff
changeset
|
445 my $ric = $uri->{ric} ? $uri->{ric} : @$table ? @$table + 1 : 0; |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
446 my $base = $uri->{base} || 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
447 $base = $base < 0 ? 0x80 + abs($base) - 1 : $base; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
448 $input = pack("CC", $ric, $base) . $input; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
449 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
450 # set length, attach headers, body |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
451 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
452 $buf = pack("C", 1); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
453 $buf .= build_int(length($input)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
454 $buf .= $input; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
455 $buf .= pack_body($self, $body) if defined $body; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
456 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
457 $self->{streams}{$self->{last_stream}}{sent} = length($buf); |
1917
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
458 $self->build_stream($buf, start => $uri->{body_more}); |
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
459 } |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
460 |
1917
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
461 sub new_stream { |
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
462 my ($self, $uri, $stream) = @_; |
24fea64f233f
Tests: TLS early data tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1915
diff
changeset
|
463 $self->raw_write($self->build_new_stream($uri, $stream)); |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
464 return $self->{last_stream}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
465 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
466 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
467 sub h3_body { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
468 my ($self, $body, $sid, $extra) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
469 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
470 my $buf = pack_body($self, $body) if defined $body; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
471 my $offset = $self->{streams}{$sid}{sent}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
472 |
1958
70302d2090ad
Tests: fixed HTTP/3 stream offset adjustment when sending body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1941
diff
changeset
|
473 $self->{streams}{$sid}{sent} += length($buf); |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
474 $self->raw_write($self->build_stream($buf, |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
475 start => $extra->{body_more}, sid => $sid, offset => $offset)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
476 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
477 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
478 sub pack_body { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
479 my ($self, $body) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
480 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
481 my $buf .= pack("C", 0); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
482 $buf .= build_int(length($body)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
483 $buf .= $body; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
484 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
485 |
1889
8303f3633f65
Tests: added HTTP/3 proxy_max_temp_file_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1887
diff
changeset
|
486 sub h3_max_data { |
8303f3633f65
Tests: added HTTP/3 proxy_max_temp_file_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1887
diff
changeset
|
487 my ($self, $val, $stream) = @_; |
8303f3633f65
Tests: added HTTP/3 proxy_max_temp_file_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1887
diff
changeset
|
488 |
8303f3633f65
Tests: added HTTP/3 proxy_max_temp_file_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1887
diff
changeset
|
489 my $buf = defined $stream |
8303f3633f65
Tests: added HTTP/3 proxy_max_temp_file_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1887
diff
changeset
|
490 ? "\x11" . build_int($stream) . build_int($val) |
8303f3633f65
Tests: added HTTP/3 proxy_max_temp_file_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1887
diff
changeset
|
491 : "\x10" . build_int($val); |
8303f3633f65
Tests: added HTTP/3 proxy_max_temp_file_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1887
diff
changeset
|
492 return $self->raw_write($buf); |
8303f3633f65
Tests: added HTTP/3 proxy_max_temp_file_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1887
diff
changeset
|
493 } |
8303f3633f65
Tests: added HTTP/3 proxy_max_temp_file_size tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1887
diff
changeset
|
494 |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
495 my %cframe = ( |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
496 0 => { name => 'DATA', value => \&data }, |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
497 1 => { name => 'HEADERS', value => \&headers }, |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
498 # 3 => { name => 'CANCEL_PUSH', value => \&cancel_push }, |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
499 4 => { name => 'SETTINGS', value => \&settings }, |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
500 5 => { name => 'PUSH_PROMISE', value => \&push_promise }, |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
501 7 => { name => 'GOAWAY', value => \&goaway }, |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
502 ); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
503 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
504 sub read { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
505 my ($self, %extra) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
506 my (@got); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
507 my $s = $self->{socket}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
508 my $wait = $extra{wait}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
509 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
510 local $Data::Dumper::Terse = 1; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
511 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
512 while (1) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
513 my ($frame, $length, $uni); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
514 my ($stream, $buf, $eof) = $self->read_stream_message($wait); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
515 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
516 unless (defined $stream) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
517 return \@got unless scalar @{$self->{frames_in}}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
518 goto frames; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
519 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
520 |
1927
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
521 if (!length($buf) && $eof) { |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
522 # emulate empty DATA frame |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
523 $length = 0; |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
524 $frame->{length} = $length; |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
525 $frame->{type} = 'DATA'; |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
526 $frame->{data} = ''; |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
527 $frame->{flags} = $eof; |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
528 $frame->{sid} = $stream; |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
529 $frame->{uni} = $uni if defined $uni; |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
530 goto push_me; |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
531 } |
55e0dee863e2
Tests: handled receiving QUIC STREAM FIN in a separate packet.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1926
diff
changeset
|
532 |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
533 if (length($self->{frames_incomplete}[$stream]{buf})) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
534 $buf = $self->{frames_incomplete}[$stream]{buf} . $buf; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
535 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
536 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
537 again: |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
538 if (($stream % 4) == 3) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
539 unless (defined $self->{stream_uni}{$stream}{stream}) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
540 (my $len, $uni) = parse_int(substr($buf, 0)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
541 $self->{stream_uni}{$stream}{stream} = $uni; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
542 $buf = substr($buf, $len); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
543 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
544 } else { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
545 $uni = $self->{stream_uni}{$stream}{stream}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
546 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
547 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
548 # push stream |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
549 if ($uni == 1 && !$self->{stream_uni}{$stream}{push}) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
550 $self->{stream_uni}{$stream}{push} = 1; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
551 ($frame, $length) = push_stream($buf, $stream); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
552 goto push_me; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
553 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
554 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
555 # decoder |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
556 if ($uni == 3) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
557 ($frame, $length) = push_decoder($buf, $stream); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
558 goto push_me; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
559 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
560 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
561 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
562 my $offset = 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
563 my ($len, $type); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
564 |
1928
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
565 ($len, $type) = parse_int(substr($buf, $offset)); |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
566 |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
567 if (!defined $len) { |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
568 $self->{frames_incomplete}[$stream]{buf} = $buf; |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
569 next; |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
570 } |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
571 |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
572 $offset += $len; |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
573 |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
574 ($len, $length) = parse_int(substr($buf, $offset)); |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
575 |
1928
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
576 if (!defined $len) { |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
577 $self->{frames_incomplete}[$stream]{buf} = $buf; |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
578 next; |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
579 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
580 |
1928
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
581 $offset += $len; |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
582 |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
583 $self->{frames_incomplete}[$stream]{type} = $type; |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
584 $self->{frames_incomplete}[$stream]{length} = $length; |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
585 $self->{frames_incomplete}[$stream]{offset} = $offset; |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
586 |
1875
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
587 if (length($buf) < $self->{frames_incomplete}[$stream]{length} |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
588 + $self->{frames_incomplete}[$stream]{offset}) |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
589 { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
590 $self->{frames_incomplete}[$stream]{buf} = $buf; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
591 next; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
592 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
593 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
594 $type = $self->{frames_incomplete}[$stream]{type}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
595 $length = $self->{frames_incomplete}[$stream]{length}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
596 $offset = $self->{frames_incomplete}[$stream]{offset}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
597 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
598 $buf = substr($buf, $offset); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
599 $self->{frames_incomplete}[$stream]{buf} = ""; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
600 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
601 $frame = $cframe{$type}{value}($self, $buf, $length); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
602 $frame->{length} = $length; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
603 $frame->{type} = $cframe{$type}{name}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
604 $frame->{flags} = $eof && length($buf) == $length; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
605 $frame->{sid} = $stream; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
606 $frame->{uni} = $uni if defined $uni; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
607 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
608 push_me: |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
609 push @got, $frame; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
610 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
611 Test::Nginx::log_core('||', $_) for split "\n", Dumper $frame; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
612 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
613 $buf = substr($buf, $length); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
614 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
615 last unless $extra{all} && test_fin($frame, $extra{all}); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
616 goto again if length($buf) > 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
617 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
618 frames: |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
619 while ($frame = shift @{$self->{frames_in}}) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
620 push @got, $frame; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
621 Test::Nginx::log_core('||', $_) for split "\n", |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
622 Dumper $frame; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
623 return \@got unless test_fin($frame, $extra{all}); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
624 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
625 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
626 return \@got; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
627 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
628 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
629 sub push_stream { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
630 my ($buf, $stream) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
631 my $frame = { sid => $stream, uni => 1, type => 'PUSH header' }; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
632 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
633 my ($len, $id) = parse_int($buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
634 $frame->{push_id} = $id; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
635 $frame->{length} = $len; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
636 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
637 return ($frame, $len); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
638 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
639 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
640 sub push_decoder { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
641 my ($buf, $stream) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
642 my ($skip, $val) = 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
643 my $frame = { sid => $stream, uni => 3 }; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
644 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
645 if ($skip < length($buf)) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
646 my $bits = unpack("\@$skip B8", $buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
647 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
648 if (substr($bits, 0, 1) eq '1') { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
649 ($val, $skip) = iunpack(7, $buf, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
650 $frame->{type} = 'DECODER_SA'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
651 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
652 } elsif (substr($bits, 0, 2) eq '01') { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
653 ($val, $skip) = iunpack(6, $buf, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
654 $frame->{type} = 'DECODER_C'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
655 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
656 } elsif (substr($bits, 0, 2) eq '00') { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
657 ($val, $skip) = iunpack(6, $buf, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
658 $frame->{type} = 'DECODER_ICI'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
659 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
660 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
661 $frame->{val} = $val; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
662 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
663 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
664 return ($frame, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
665 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
666 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
667 sub test_fin { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
668 my ($frame, $all) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
669 my @test = @{$all}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
670 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
671 # wait for the specified DATA length |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
672 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
673 for (@test) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
674 if ($_->{length} && $frame->{type} eq 'DATA') { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
675 # check also for StreamID if needed |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
676 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
677 if (!$_->{sid} || $_->{sid} == $frame->{sid}) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
678 $_->{length} -= $frame->{length}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
679 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
680 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
681 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
682 @test = grep { !(defined $_->{length} && $_->{length} == 0) } @test; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
683 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
684 # wait for the fin flag |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
685 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
686 @test = grep { !(defined $_->{fin} |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
687 && (!defined $_->{sid} || $_->{sid} == $frame->{sid}) |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
688 && $_->{fin} & $frame->{flags}) |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
689 } @test if defined $frame->{flags}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
690 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
691 # wait for the specified frame |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
692 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
693 @test = grep { !($_->{type} && $_->{type} eq $frame->{type}) } @test; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
694 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
695 @{$all} = @test; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
696 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
697 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
698 sub data { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
699 my ($self, $buf, $len) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
700 return { data => substr($buf, 0, $len) }; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
701 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
702 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
703 sub headers { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
704 my ($self, $buf, $len) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
705 my ($ric, $base); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
706 $self->{headers} = substr($buf, 0, $len); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
707 my $skip = 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
708 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
709 ($ric, $skip) = iunpack(8, $buf, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
710 ($base, $skip) = iunpack(7, $buf, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
711 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
712 $buf = substr($buf, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
713 $len -= $skip; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
714 { headers => qunpack($self, $buf, $len) }; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
715 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
716 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
717 sub settings { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
718 my ($self, $buf, $length) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
719 my %payload; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
720 my ($offset, $len) = 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
721 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
722 while ($offset < $length) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
723 my ($id, $val); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
724 ($len, $id) = parse_int(substr($buf, $offset)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
725 $offset += $len; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
726 ($len, $val) = parse_int(substr($buf, $offset)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
727 $offset += $len; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
728 $payload{$id} = $val; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
729 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
730 return \%payload; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
731 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
732 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
733 sub push_promise { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
734 my ($self, $buf, $length) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
735 my %payload; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
736 my ($offset, $len, $id) = 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
737 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
738 ($len, $id) = parse_int($buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
739 $offset += $len; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
740 $payload{push_id} = $id; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
741 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
742 my ($ric, $base); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
743 my $skip = $offset; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
744 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
745 ($ric, $skip) = iunpack(8, $buf, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
746 ($base, $skip) = iunpack(7, $buf, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
747 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
748 $buf = substr($buf, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
749 $length -= $skip; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
750 $payload{headers} = qunpack($self, $buf, $length); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
751 return \%payload; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
752 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
753 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
754 sub goaway { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
755 my ($self, $buf, $length) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
756 my ($len, $stream) = parse_int($buf); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
757 { last_sid => $stream } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
758 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
759 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
760 # RFC 7541, 5.1. Integer Representation |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
761 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
762 sub ipack { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
763 my ($base, $d) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
764 return sprintf("%.*b", $base, $d) if $d < 2**$base - 1; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
765 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
766 my $o = sprintf("%${base}b", 2**$base - 1); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
767 $d -= 2**$base - 1; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
768 while ($d >= 128) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
769 $o .= sprintf("%8b", $d % 128 + 128); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
770 $d /= 128; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
771 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
772 $o .= sprintf("%08b", $d); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
773 return $o; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
774 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
775 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
776 sub iunpack { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
777 my ($base, $b, $s) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
778 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
779 my $len = unpack("\@$s B8", $b); $s++; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
780 my $huff = substr($len, 8 - $base - 1, 1); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
781 $len = '0' x (8 - $base) . substr($len, 8 - $base); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
782 $len = unpack("C", pack("B8", $len)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
783 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
784 return ($len, $s, $huff) if $len < 2**$base - 1; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
785 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
786 my $m = 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
787 my $d; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
788 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
789 do { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
790 $d = unpack("\@$s C", $b); $s++; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
791 $len += ($d & 127) * 2**$m; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
792 $m += $base; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
793 } while (($d & 128) == 128); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
794 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
795 return ($len, $s, $huff); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
796 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
797 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
798 sub qpack { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
799 my ($ctx, $name, $value, %extra) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
800 my $mode = defined $extra{mode} ? $extra{mode} : 4; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
801 my $huff = $extra{huff}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
802 my $hbit = $huff ? '1' : '0'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
803 my $ibit = $extra{ni} ? '1' : '0'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
804 my $dbit = $extra{dyn} ? '0' : '1'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
805 my $table = $extra{dyn} ? $ctx->{dynamic_encode} : $ctx->{static_encode}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
806 my ($index, $buf) = 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
807 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
808 # 4.5.2. Indexed Field Line |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
809 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
810 if ($mode == 0) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
811 ++$index until $index > $#$table |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
812 or $table->[$index][0] eq $name |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
813 and $table->[$index][1] eq $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
814 $buf = pack('B*', '1' . $dbit . ipack(6, $index)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
815 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
816 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
817 # 4.5.3. Indexed Field Line with Post-Base Index |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
818 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
819 if ($mode == 1) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
820 $table = $ctx->{dynamic_encode}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
821 ++$index until $index > $#$table |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
822 or $table->[$index][0] eq $name |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
823 and $table->[$index][1] eq $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
824 $buf = pack('B*', '0001' . ipack(4, 0)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
825 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
826 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
827 # 4.5.4. Literal Field Line with Name Reference |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
828 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
829 if ($mode == 2) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
830 ++$index until $index > $#$table |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
831 or $table->[$index][0] eq $name; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
832 $value = $huff ? huff($value) : $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
833 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
834 $buf = pack('B*', '01' . $ibit . $dbit . ipack(4, $index)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
835 $buf .= pack('B*', $hbit . ipack(7, length($value))) . $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
836 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
837 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
838 # 4.5.5. Literal Field Line with Post-Base Name Reference |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
839 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
840 if ($mode == 3) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
841 $table = $ctx->{dynamic_encode}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
842 ++$index until $index > $#$table |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
843 or $table->[$index][0] eq $name; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
844 $value = $huff ? huff($value) : $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
845 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
846 $buf = pack('B*', '0000' . $ibit . ipack(3, $index)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
847 $buf .= pack('B*', $hbit . ipack(7, length($value))) . $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
848 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
849 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
850 # 4.5.6. Literal Field Line with Literal Name |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
851 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
852 if ($mode == 4) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
853 $name = $huff ? huff($name) : $name; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
854 $value = $huff ? huff($value) : $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
855 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
856 $buf = pack('B*', '001' . $ibit . |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
857 $hbit . ipack(3, length($name))) . $name; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
858 $buf .= pack('B*', $hbit . ipack(7, length($value))) . $value; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
859 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
860 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
861 return $buf; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
862 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
863 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
864 sub qunpack { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
865 my ($ctx, $data, $length) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
866 my $table = $ctx->{static_decode}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
867 my %headers; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
868 my $skip = 0; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
869 my ($index, $name, $value, $size); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
870 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
871 my $field = sub { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
872 my ($base, $b) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
873 my ($len, $s, $huff) = iunpack(@_); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
874 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
875 my $field = substr($b, $s, $len); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
876 $field = $huff ? dehuff($field) : $field; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
877 $s += $len; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
878 return ($field, $s); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
879 }; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
880 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
881 my $add = sub { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
882 my ($h, $n, $v) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
883 return $h->{$n} = $v unless exists $h->{$n}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
884 $h->{$n} = [ $h->{$n} ] unless ref $h->{$n}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
885 push @{$h->{$n}}, $v; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
886 }; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
887 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
888 while ($skip < $length) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
889 my $ib = unpack("\@$skip B8", $data); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
890 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
891 # 4.5.2. Indexed Field Line |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
892 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
893 if (substr($ib, 0, 2) eq '11') { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
894 ($index, $skip) = iunpack(6, $data, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
895 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
896 $add->(\%headers, |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
897 $table->[$index][0], $table->[$index][1]); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
898 next; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
899 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
900 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
901 # 4.5.4. Literal Field Line with Name Reference |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
902 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
903 if (substr($ib, 0, 4) eq '0101') { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
904 ($index, $skip) = iunpack(4, $data, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
905 $name = $table->[$index][0]; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
906 ($value, $skip) = $field->(7, $data, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
907 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
908 $add->(\%headers, $name, $value); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
909 next; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
910 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
911 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
912 # 4.5.6. Literal Field Line with Literal Name |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
913 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
914 if (substr($ib, 0, 4) eq '0010') { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
915 ($name, $skip) = $field->(3, $data, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
916 ($value, $skip) = $field->(7, $data, $skip); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
917 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
918 $add->(\%headers, $name, $value); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
919 next; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
920 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
921 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
922 last; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
923 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
924 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
925 return \%headers; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
926 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
927 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
928 sub static_table { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
929 [ ':authority', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
930 [ ':path', '/' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
931 [ 'age', '0' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
932 [ 'content-disposition', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
933 [ 'content-length', '0' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
934 [ 'cookie', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
935 [ 'date', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
936 [ 'etag', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
937 [ 'if-modified-since', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
938 [ 'if-none-match', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
939 [ 'last-modified', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
940 [ 'link', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
941 [ 'location', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
942 [ 'referer', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
943 [ 'set-cookie', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
944 [ ':method', 'CONNECT' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
945 [ ':method', 'DELETE' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
946 [ ':method', 'GET' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
947 [ ':method', 'HEAD' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
948 [ ':method', 'OPTIONS' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
949 [ ':method', 'POST' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
950 [ ':method', 'PUT' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
951 [ ':scheme', 'http' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
952 [ ':scheme', 'https' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
953 [ ':status', '103' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
954 [ ':status', '200' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
955 [ ':status', '304' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
956 [ ':status', '404' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
957 [ ':status', '503' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
958 [ 'accept', '*/*' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
959 [ 'accept', 'application/dns-message' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
960 [ 'accept-encoding', 'gzip, deflate, br' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
961 [ 'accept-ranges', 'bytes' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
962 [ 'access-control-allow-headers', 'cache-control' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
963 [ 'access-control-allow-headers', 'content-type' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
964 [ 'access-control-allow-origin', '*' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
965 [ 'cache-control', 'max-age=0' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
966 [ 'cache-control', 'max-age=2592000' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
967 [ 'cache-control', 'max-age=604800' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
968 [ 'cache-control', 'no-cache' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
969 [ 'cache-control', 'no-store' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
970 [ 'cache-control', 'public, max-age=31536000' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
971 [ 'content-encoding', 'br' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
972 [ 'content-encoding', 'gzip' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
973 [ 'content-type', 'application/dns-message' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
974 [ 'content-type', 'application/javascript' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
975 [ 'content-type', 'application/json' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
976 [ 'content-type', 'application/x-www-form-urlencoded' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
977 [ 'content-type', 'image/gif' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
978 [ 'content-type', 'image/jpeg' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
979 [ 'content-type', 'image/png' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
980 [ 'content-type', 'text/css' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
981 [ 'content-type', 'text/html; charset=utf-8' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
982 [ 'content-type', 'text/plain' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
983 [ 'content-type', 'text/plain;charset=utf-8' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
984 [ 'range', 'bytes=0-' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
985 [ 'strict-transport-security', 'max-age=31536000' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
986 [ 'strict-transport-security', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
987 'max-age=31536000; includesubdomains' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
988 [ 'strict-transport-security', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
989 'max-age=31536000; includesubdomains; preload' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
990 [ 'vary', 'accept-encoding' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
991 [ 'vary', 'origin' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
992 [ 'x-content-type-options', 'nosniff' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
993 [ 'x-xss-protection', '1; mode=block' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
994 [ ':status', '100' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
995 [ ':status', '204' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
996 [ ':status', '206' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
997 [ ':status', '302' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
998 [ ':status', '400' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
999 [ ':status', '403' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1000 [ ':status', '421' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1001 [ ':status', '425' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1002 [ ':status', '500' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1003 [ 'accept-language', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1004 [ 'access-control-allow-credentials', 'FALSE' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1005 [ 'access-control-allow-credentials', 'TRUE' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1006 [ 'access-control-allow-headers', '*' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1007 [ 'access-control-allow-methods', 'get' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1008 [ 'access-control-allow-methods', 'get, post, options' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1009 [ 'access-control-allow-methods', 'options' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1010 [ 'access-control-expose-headers', 'content-length' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1011 [ 'access-control-request-headers', 'content-type' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1012 [ 'access-control-request-method', 'get' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1013 [ 'access-control-request-method', 'post' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1014 [ 'alt-svc', 'clear' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1015 [ 'authorization', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1016 [ 'content-security-policy', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1017 "script-src 'none'; object-src 'none'; base-uri 'none'" ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1018 [ 'early-data', '1' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1019 [ 'expect-ct', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1020 [ 'forwarded', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1021 [ 'if-range', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1022 [ 'origin', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1023 [ 'purpose', 'prefetch' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1024 [ 'server', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1025 [ 'timing-allow-origin', '*' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1026 [ 'upgrade-insecure-requests', '1' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1027 [ 'user-agent', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1028 [ 'x-forwarded-for', '' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1029 [ 'x-frame-options', 'deny' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1030 [ 'x-frame-options', 'sameorigin' ], |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1031 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1032 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1033 sub huff_code { scalar { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1034 pack('C', 0) => '1111111111000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1035 pack('C', 1) => '11111111111111111011000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1036 pack('C', 2) => '1111111111111111111111100010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1037 pack('C', 3) => '1111111111111111111111100011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1038 pack('C', 4) => '1111111111111111111111100100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1039 pack('C', 5) => '1111111111111111111111100101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1040 pack('C', 6) => '1111111111111111111111100110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1041 pack('C', 7) => '1111111111111111111111100111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1042 pack('C', 8) => '1111111111111111111111101000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1043 pack('C', 9) => '111111111111111111101010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1044 pack('C', 10) => '111111111111111111111111111100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1045 pack('C', 11) => '1111111111111111111111101001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1046 pack('C', 12) => '1111111111111111111111101010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1047 pack('C', 13) => '111111111111111111111111111101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1048 pack('C', 14) => '1111111111111111111111101011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1049 pack('C', 15) => '1111111111111111111111101100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1050 pack('C', 16) => '1111111111111111111111101101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1051 pack('C', 17) => '1111111111111111111111101110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1052 pack('C', 18) => '1111111111111111111111101111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1053 pack('C', 19) => '1111111111111111111111110000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1054 pack('C', 20) => '1111111111111111111111110001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1055 pack('C', 21) => '1111111111111111111111110010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1056 pack('C', 22) => '111111111111111111111111111110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1057 pack('C', 23) => '1111111111111111111111110011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1058 pack('C', 24) => '1111111111111111111111110100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1059 pack('C', 25) => '1111111111111111111111110101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1060 pack('C', 26) => '1111111111111111111111110110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1061 pack('C', 27) => '1111111111111111111111110111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1062 pack('C', 28) => '1111111111111111111111111000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1063 pack('C', 29) => '1111111111111111111111111001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1064 pack('C', 30) => '1111111111111111111111111010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1065 pack('C', 31) => '1111111111111111111111111011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1066 pack('C', 32) => '010100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1067 pack('C', 33) => '1111111000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1068 pack('C', 34) => '1111111001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1069 pack('C', 35) => '111111111010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1070 pack('C', 36) => '1111111111001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1071 pack('C', 37) => '010101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1072 pack('C', 38) => '11111000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1073 pack('C', 39) => '11111111010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1074 pack('C', 40) => '1111111010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1075 pack('C', 41) => '1111111011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1076 pack('C', 42) => '11111001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1077 pack('C', 43) => '11111111011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1078 pack('C', 44) => '11111010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1079 pack('C', 45) => '010110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1080 pack('C', 46) => '010111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1081 pack('C', 47) => '011000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1082 pack('C', 48) => '00000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1083 pack('C', 49) => '00001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1084 pack('C', 50) => '00010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1085 pack('C', 51) => '011001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1086 pack('C', 52) => '011010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1087 pack('C', 53) => '011011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1088 pack('C', 54) => '011100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1089 pack('C', 55) => '011101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1090 pack('C', 56) => '011110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1091 pack('C', 57) => '011111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1092 pack('C', 58) => '1011100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1093 pack('C', 59) => '11111011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1094 pack('C', 60) => '111111111111100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1095 pack('C', 61) => '100000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1096 pack('C', 62) => '111111111011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1097 pack('C', 63) => '1111111100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1098 pack('C', 64) => '1111111111010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1099 pack('C', 65) => '100001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1100 pack('C', 66) => '1011101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1101 pack('C', 67) => '1011110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1102 pack('C', 68) => '1011111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1103 pack('C', 69) => '1100000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1104 pack('C', 70) => '1100001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1105 pack('C', 71) => '1100010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1106 pack('C', 72) => '1100011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1107 pack('C', 73) => '1100100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1108 pack('C', 74) => '1100101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1109 pack('C', 75) => '1100110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1110 pack('C', 76) => '1100111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1111 pack('C', 77) => '1101000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1112 pack('C', 78) => '1101001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1113 pack('C', 79) => '1101010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1114 pack('C', 80) => '1101011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1115 pack('C', 81) => '1101100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1116 pack('C', 82) => '1101101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1117 pack('C', 83) => '1101110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1118 pack('C', 84) => '1101111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1119 pack('C', 85) => '1110000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1120 pack('C', 86) => '1110001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1121 pack('C', 87) => '1110010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1122 pack('C', 88) => '11111100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1123 pack('C', 89) => '1110011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1124 pack('C', 90) => '11111101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1125 pack('C', 91) => '1111111111011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1126 pack('C', 92) => '1111111111111110000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1127 pack('C', 93) => '1111111111100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1128 pack('C', 94) => '11111111111100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1129 pack('C', 95) => '100010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1130 pack('C', 96) => '111111111111101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1131 pack('C', 97) => '00011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1132 pack('C', 98) => '100011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1133 pack('C', 99) => '00100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1134 pack('C', 100) => '100100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1135 pack('C', 101) => '00101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1136 pack('C', 102) => '100101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1137 pack('C', 103) => '100110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1138 pack('C', 104) => '100111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1139 pack('C', 105) => '00110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1140 pack('C', 106) => '1110100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1141 pack('C', 107) => '1110101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1142 pack('C', 108) => '101000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1143 pack('C', 109) => '101001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1144 pack('C', 110) => '101010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1145 pack('C', 111) => '00111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1146 pack('C', 112) => '101011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1147 pack('C', 113) => '1110110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1148 pack('C', 114) => '101100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1149 pack('C', 115) => '01000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1150 pack('C', 116) => '01001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1151 pack('C', 117) => '101101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1152 pack('C', 118) => '1110111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1153 pack('C', 119) => '1111000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1154 pack('C', 120) => '1111001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1155 pack('C', 121) => '1111010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1156 pack('C', 122) => '1111011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1157 pack('C', 123) => '111111111111110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1158 pack('C', 124) => '11111111100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1159 pack('C', 125) => '11111111111101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1160 pack('C', 126) => '1111111111101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1161 pack('C', 127) => '1111111111111111111111111100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1162 pack('C', 128) => '11111111111111100110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1163 pack('C', 129) => '1111111111111111010010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1164 pack('C', 130) => '11111111111111100111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1165 pack('C', 131) => '11111111111111101000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1166 pack('C', 132) => '1111111111111111010011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1167 pack('C', 133) => '1111111111111111010100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1168 pack('C', 134) => '1111111111111111010101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1169 pack('C', 135) => '11111111111111111011001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1170 pack('C', 136) => '1111111111111111010110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1171 pack('C', 137) => '11111111111111111011010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1172 pack('C', 138) => '11111111111111111011011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1173 pack('C', 139) => '11111111111111111011100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1174 pack('C', 140) => '11111111111111111011101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1175 pack('C', 141) => '11111111111111111011110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1176 pack('C', 142) => '111111111111111111101011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1177 pack('C', 143) => '11111111111111111011111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1178 pack('C', 144) => '111111111111111111101100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1179 pack('C', 145) => '111111111111111111101101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1180 pack('C', 146) => '1111111111111111010111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1181 pack('C', 147) => '11111111111111111100000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1182 pack('C', 148) => '111111111111111111101110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1183 pack('C', 149) => '11111111111111111100001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1184 pack('C', 150) => '11111111111111111100010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1185 pack('C', 151) => '11111111111111111100011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1186 pack('C', 152) => '11111111111111111100100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1187 pack('C', 153) => '111111111111111011100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1188 pack('C', 154) => '1111111111111111011000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1189 pack('C', 155) => '11111111111111111100101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1190 pack('C', 156) => '1111111111111111011001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1191 pack('C', 157) => '11111111111111111100110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1192 pack('C', 158) => '11111111111111111100111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1193 pack('C', 159) => '111111111111111111101111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1194 pack('C', 160) => '1111111111111111011010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1195 pack('C', 161) => '111111111111111011101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1196 pack('C', 162) => '11111111111111101001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1197 pack('C', 163) => '1111111111111111011011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1198 pack('C', 164) => '1111111111111111011100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1199 pack('C', 165) => '11111111111111111101000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1200 pack('C', 166) => '11111111111111111101001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1201 pack('C', 167) => '111111111111111011110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1202 pack('C', 168) => '11111111111111111101010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1203 pack('C', 169) => '1111111111111111011101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1204 pack('C', 170) => '1111111111111111011110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1205 pack('C', 171) => '111111111111111111110000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1206 pack('C', 172) => '111111111111111011111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1207 pack('C', 173) => '1111111111111111011111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1208 pack('C', 174) => '11111111111111111101011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1209 pack('C', 175) => '11111111111111111101100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1210 pack('C', 176) => '111111111111111100000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1211 pack('C', 177) => '111111111111111100001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1212 pack('C', 178) => '1111111111111111100000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1213 pack('C', 179) => '111111111111111100010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1214 pack('C', 180) => '11111111111111111101101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1215 pack('C', 181) => '1111111111111111100001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1216 pack('C', 182) => '11111111111111111101110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1217 pack('C', 183) => '11111111111111111101111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1218 pack('C', 184) => '11111111111111101010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1219 pack('C', 185) => '1111111111111111100010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1220 pack('C', 186) => '1111111111111111100011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1221 pack('C', 187) => '1111111111111111100100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1222 pack('C', 188) => '11111111111111111110000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1223 pack('C', 189) => '1111111111111111100101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1224 pack('C', 190) => '1111111111111111100110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1225 pack('C', 191) => '11111111111111111110001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1226 pack('C', 192) => '11111111111111111111100000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1227 pack('C', 193) => '11111111111111111111100001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1228 pack('C', 194) => '11111111111111101011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1229 pack('C', 195) => '1111111111111110001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1230 pack('C', 196) => '1111111111111111100111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1231 pack('C', 197) => '11111111111111111110010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1232 pack('C', 198) => '1111111111111111101000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1233 pack('C', 199) => '1111111111111111111101100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1234 pack('C', 200) => '11111111111111111111100010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1235 pack('C', 201) => '11111111111111111111100011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1236 pack('C', 202) => '11111111111111111111100100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1237 pack('C', 203) => '111111111111111111111011110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1238 pack('C', 204) => '111111111111111111111011111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1239 pack('C', 205) => '11111111111111111111100101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1240 pack('C', 206) => '111111111111111111110001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1241 pack('C', 207) => '1111111111111111111101101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1242 pack('C', 208) => '1111111111111110010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1243 pack('C', 209) => '111111111111111100011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1244 pack('C', 210) => '11111111111111111111100110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1245 pack('C', 211) => '111111111111111111111100000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1246 pack('C', 212) => '111111111111111111111100001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1247 pack('C', 213) => '11111111111111111111100111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1248 pack('C', 214) => '111111111111111111111100010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1249 pack('C', 215) => '111111111111111111110010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1250 pack('C', 216) => '111111111111111100100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1251 pack('C', 217) => '111111111111111100101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1252 pack('C', 218) => '11111111111111111111101000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1253 pack('C', 219) => '11111111111111111111101001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1254 pack('C', 220) => '1111111111111111111111111101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1255 pack('C', 221) => '111111111111111111111100011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1256 pack('C', 222) => '111111111111111111111100100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1257 pack('C', 223) => '111111111111111111111100101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1258 pack('C', 224) => '11111111111111101100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1259 pack('C', 225) => '111111111111111111110011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1260 pack('C', 226) => '11111111111111101101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1261 pack('C', 227) => '111111111111111100110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1262 pack('C', 228) => '1111111111111111101001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1263 pack('C', 229) => '111111111111111100111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1264 pack('C', 230) => '111111111111111101000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1265 pack('C', 231) => '11111111111111111110011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1266 pack('C', 232) => '1111111111111111101010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1267 pack('C', 233) => '1111111111111111101011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1268 pack('C', 234) => '1111111111111111111101110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1269 pack('C', 235) => '1111111111111111111101111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1270 pack('C', 236) => '111111111111111111110100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1271 pack('C', 237) => '111111111111111111110101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1272 pack('C', 238) => '11111111111111111111101010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1273 pack('C', 239) => '11111111111111111110100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1274 pack('C', 240) => '11111111111111111111101011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1275 pack('C', 241) => '111111111111111111111100110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1276 pack('C', 242) => '11111111111111111111101100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1277 pack('C', 243) => '11111111111111111111101101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1278 pack('C', 244) => '111111111111111111111100111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1279 pack('C', 245) => '111111111111111111111101000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1280 pack('C', 246) => '111111111111111111111101001', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1281 pack('C', 247) => '111111111111111111111101010', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1282 pack('C', 248) => '111111111111111111111101011', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1283 pack('C', 249) => '1111111111111111111111111110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1284 pack('C', 250) => '111111111111111111111101100', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1285 pack('C', 251) => '111111111111111111111101101', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1286 pack('C', 252) => '111111111111111111111101110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1287 pack('C', 253) => '111111111111111111111101111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1288 pack('C', 254) => '111111111111111111111110000', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1289 pack('C', 255) => '11111111111111111111101110', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1290 '_eos' => '111111111111111111111111111111', |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1291 }}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1292 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1293 sub huff { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1294 my ($string) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1295 my $code = &huff_code; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1296 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1297 my $ret = join '', map { $code->{$_} } (split //, $string); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1298 my $len = length($ret) + (8 - length($ret) % 8); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1299 $ret .= $code->{_eos}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1300 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1301 return pack("B$len", $ret); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1302 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1303 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1304 sub dehuff { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1305 my ($string) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1306 my $code = &huff_code; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1307 my %decode = reverse %$code; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1308 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1309 my $ret = ''; my $c = ''; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1310 for (split //, unpack('B*', $string)) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1311 $c .= $_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1312 next unless exists $decode{$c}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1313 last if $decode{$c} eq '_eos'; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1314 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1315 $ret .= $decode{$c}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1316 $c = ''; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1317 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1318 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1319 return $ret; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1320 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1321 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1322 sub raw_write { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1323 my ($self, $message) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1324 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1325 if ($self->{chaining}) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1326 return add_chain($self, $message); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1327 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1328 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1329 $self->{socket}->syswrite($self->encrypt_aead($message, 3)); |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1330 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1331 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1332 sub start_chain { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1333 my ($self) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1334 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1335 $self->{chaining} = 1; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1336 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1337 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1338 sub add_chain { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1339 my ($self, $buf) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1340 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1341 if ($self->{chained_buf}) { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1342 $self->{chained_buf} .= $buf; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1343 } else { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1344 $self->{chained_buf} = $buf; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1345 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1346 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1347 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1348 sub send_chain { |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1349 my ($self) = @_; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1350 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1351 undef $self->{chaining}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1352 $self->raw_write($self->{chained_buf}) if $self->{chained_buf}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1353 undef $self->{chained_buf}; |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1354 } |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1355 |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1356 ############################################################################### |
f50c2a65ccc0
Tests: basic HTTP/3 support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1874
diff
changeset
|
1357 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1358 sub parse_frames { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1359 my ($buf) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1360 my @frames; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1361 my $offset = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1362 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1363 while ($offset < length($buf)) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1364 my ($tlen, $type) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1365 $offset += $tlen; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1366 next if $type == 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1367 my $frame = { type => $type }; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1368 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1369 if ($type == 1) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1370 $frame->{type} = 'PING'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1371 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1372 if ($type == 2) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1373 $frame->{type} = 'ACK'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1374 my ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1375 $frame->{largest} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1376 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1377 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1378 $frame->{delay} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1379 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1380 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1381 $frame->{count} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1382 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1383 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1384 $frame->{first} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1385 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1386 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1387 if ($type == 4) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1388 $frame->{type} = 'RESET_STREAM'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1389 my ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1390 $frame->{sid} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1391 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1392 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1393 $frame->{code} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1394 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1395 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1396 $frame->{final_size} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1397 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1398 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1399 if ($type == 5) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1400 $frame->{type} = 'STOP_SENDING'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1401 my ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1402 $frame->{sid} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1403 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1404 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1405 $frame->{code} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1406 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1407 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1408 if ($type == 6) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1409 my ($olen, $off) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1410 $offset += $olen; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1411 my ($llen, $len) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1412 $offset += $llen; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1413 $frame->{type} = 'CRYPTO'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1414 $frame->{length} = $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1415 $frame->{offset} = $off; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1416 $frame->{payload} = substr($buf, $offset, $len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1417 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1418 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1419 if ($type == 7) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1420 $frame->{type} = 'NEW_TOKEN'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1421 my ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1422 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1423 $frame->{token} = substr($buf, $offset, $val); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1424 $offset += $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1425 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1426 if (($type & 0xf8) == 0x08) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1427 $frame->{type} = 'STREAM'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1428 my ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1429 $frame->{id} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1430 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1431 if ($type & 0x4) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1432 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1433 $frame->{offset} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1434 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1435 } else { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1436 $frame->{offset} = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1437 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1438 if ($type & 0x2) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1439 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1440 $frame->{length} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1441 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1442 } else { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1443 $frame->{length} = length($buf) - $offset; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1444 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1445 if ($type & 0x1) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1446 $frame->{fin} = 1; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1447 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1448 $frame->{payload} = |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1449 substr($buf, $offset, $frame->{length}); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1450 $offset += $frame->{length}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1451 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1452 if ($type == 18 || $type == 19) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1453 $frame->{type} = 'MAX_STREAMS'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1454 my ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1455 $frame->{val} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1456 $frame->{uni} = 1 if $type == 19; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1457 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1458 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1459 if ($type == 24) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1460 $frame->{type} = 'NCID'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1461 my ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1462 $frame->{seqno} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1463 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1464 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1465 $frame->{rpt} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1466 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1467 $len = unpack("C", substr($buf, $offset, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1468 $frame->{length} = $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1469 $offset += 1; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1470 $frame->{cid} = substr($buf, $offset, $len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1471 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1472 $frame->{token} = substr($buf, $offset, 16); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1473 $offset += 16; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1474 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1475 if ($type == 26) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1476 $frame->{type} = 'PATH_CHALLENGE'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1477 $frame->{data} = substr($buf, $offset, 8); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1478 $offset += 8; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1479 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1480 if ($type == 27) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1481 $frame->{type} = 'PATH_RESPONSE'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1482 $frame->{data} = substr($buf, $offset, 8); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1483 $offset += 8; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1484 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1485 if ($type == 28 || $type == 29) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1486 $frame->{type} = 'CONNECTION_CLOSE'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1487 my ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1488 $frame->{error} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1489 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1490 if ($type == 28) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1491 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1492 $frame->{frame_type} = $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1493 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1494 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1495 ($len, $val) = parse_int(substr($buf, $offset)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1496 $offset += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1497 $frame->{phrase} = substr($buf, $offset, $val); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1498 $offset += $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1499 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1500 if ($type == 30) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1501 $frame->{type} = 'HANDSHAKE_DONE'; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1502 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1503 push @frames, $frame; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1504 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1505 return \@frames; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1506 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1507 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1508 sub handle_frames { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1509 my ($self, $frames, $level) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1510 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1511 my @frames = grep { $_->{type} eq 'CRYPTO' } @$frames; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1512 while (my $frame = shift @frames) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1513 insert_crypto($self->{crypto_in}[$level], [ |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1514 $frame->{offset}, |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1515 $frame->{length}, |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1516 $frame->{payload}, |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1517 ]); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1518 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1519 $self->parse_tls_nst() if $level == 3; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1520 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1521 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1522 @frames = grep { $_->{type} eq 'STREAM' } @$frames; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1523 while (my $frame = shift @frames) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1524 $self->{stream_in}[$frame->{id}] ||= { buf => [], pos => 0 }; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1525 insert_crypto($self->{stream_in}[$frame->{id}]->{buf}, [ |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1526 $frame->{offset}, |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1527 $frame->{length}, |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1528 $frame->{payload}, |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1529 $frame->{fin}, |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1530 ]); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1531 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1532 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1533 @frames = grep { $_->{type} eq 'NCID' } @$frames; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1534 while (my $frame = shift @frames) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1535 push @{$self->{ncid}}, $frame; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1536 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1537 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1538 my $ack = $self->{ack}[$level]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1539 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1540 # stop tracking acknowledged ACK ranges |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1541 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1542 @frames = grep { $_->{type} eq 'ACK' } @$frames; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1543 while (my $frame = shift @frames) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1544 my $max = $frame->{largest}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1545 my $min = $max - $frame->{first}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1546 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1547 for my $num ($min .. $max) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1548 for my $pn (keys %$ack) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1549 delete $ack->{$pn} if $ack->{$pn} == $num; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1550 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1551 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1552 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1553 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1554 $self->{socket}->syswrite($self->encrypt_aead(build_ack($ack), $level)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1555 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1556 for my $pn (keys %$ack) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1557 $ack->{$pn} = $self->{pn}[0][$level] if $ack->{$pn} == -1; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1558 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1559 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1560 my ($frame) = grep { $_->{type} eq 'NEW_TOKEN' } @$frames; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1561 $self->{token} = $frame->{token} || ''; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1562 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1563 push @{$self->{frames_in}}, grep { $_->{type} ne 'CRYPTO' |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1564 && $_->{type} ne 'STREAM' } @$frames; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1565 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1566 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1567 sub insert_crypto { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1568 my ($crypto, $frame) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1569 my $i; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1570 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1571 for ($i = 0; $i < scalar @$crypto; $i++) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1572 # frame][crypto][frame |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1573 my $this = @$crypto[$i]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1574 if (@$frame[0] <= @$this[0] && |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1575 @$frame[0] + @$frame[1] >= @$this[0] + @$this[1]) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1576 { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1577 my $old = substr(@$frame[2], @$this[0] - @$frame[0], |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1578 @$this[1]); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1579 die "bad inner" if $old ne @$this[2]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1580 splice @$crypto, $i, 1; $i--; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1581 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1582 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1583 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1584 return push @$crypto, $frame if !@$crypto; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1585 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1586 for ($i = 0; $i < @$crypto; $i++) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1587 if (@$frame[0] <= @{@$crypto[$i]}[0] + @{@$crypto[$i]}[1]) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1588 last; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1589 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1590 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1591 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1592 return push @$crypto, $frame if $i == @$crypto; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1593 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1594 my $this = @$crypto[$i]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1595 my $next = @$crypto[$i + 1]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1596 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1597 if (@$frame[0] + @$frame[1] == @$this[0]) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1598 # frame][crypto |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1599 @$this[0] = @$frame[0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1600 @$this[1] += @$frame[1]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1601 @$this[2] = @$frame[2] . @$this[2]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1602 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1603 } elsif (@$this[0] + @$this[1] == @$frame[0]) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1604 # crypto][frame |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1605 @$this[1] += @$frame[1]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1606 @$this[2] .= @$frame[2]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1607 @$this[3] = @$frame[3]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1608 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1609 } elsif (@$frame[0] + @$frame[1] < @$this[0]) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1610 # frame..crypto |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1611 return splice @$crypto, $i, 0, $frame; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1612 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1613 } else { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1614 # overlay |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1615 my ($b1, $b2) = @$this[0] < @$frame[0] |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1616 ? ($this, $frame) : ($frame, $this); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1617 my ($o1, $o2) = @$this[0] + @$this[1] < @$frame[0] + @$frame[1] |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1618 ? ($this, $frame) : ($frame, $this); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1619 my $offset = @$b2[0] - @$b1[0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1620 my $length = @$o1[0] + @$o1[1] - @$b2[0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1621 my $old = substr @$b1[2], $offset, $length, @$b2[2]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1622 die "bad repl" if substr(@$b1[2], $offset, $length) ne $old; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1623 @$this = (@$b1[0], @$o2[0] + @$o2[1] - @$b1[0], @$b1[2]); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1624 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1625 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1626 return if !defined $next; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1627 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1628 # combine with next overlay if any |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1629 if (@$this[0] + @$this[1] >= @$next[0]) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1630 my $offset = @$next[0] - @$this[0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1631 my $length = @$this[0] + @$this[1] - @$next[0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1632 my $old = substr @$this[2], $offset, $length, @$next[2]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1633 die "bad repl2" if substr(@$this[2], $offset, $length) ne $old; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1634 @$this[1] = @$next[0] + @$next[1] - @$this[0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1635 splice @$crypto, $i + 1, 1; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1636 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1637 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1638 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1639 ############################################################################### |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1640 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1641 sub save_session_tickets { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1642 my ($self, $content) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1643 |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1644 my ($hash, $hlen) = $self->{cipher} == 0x1302 ? |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1645 ('SHA384', 48) : ('SHA256', 32); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1646 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1647 my $nst_len = unpack("n", substr($content, 2, 2)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1648 my $nst = substr($content, 4, $nst_len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1649 |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1650 my $psk = { cipher => $self->{cipher} }; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1651 my $lifetime = substr($nst, 0, 4); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1652 $psk->{age_add} = substr($nst, 4, 4); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1653 my $nonce_len = unpack("C", substr($nst, 8, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1654 my $nonce = substr($nst, 9, $nonce_len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1655 my $len = unpack("n", substr($nst, 8 + 1 + $nonce_len, 2)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1656 $psk->{ticket} = substr($nst, 11 + $nonce_len, $len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1657 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1658 my $extens_len = unpack("n", substr($nst, 11 + $nonce_len + $len, 2)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1659 my $extens = substr($nst, 11 + $nonce_len + $len + 2, $extens_len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1660 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1661 $psk->{ed} = early_data($extens); |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1662 $psk->{secret} = hkdf_expand_label("tls13 resumption", $hash, $hlen, |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1663 $self->{rms_prk}, $nonce); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1664 push @{$self->{psk_list}}, $psk; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1665 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1666 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1667 sub decode_pn { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1668 my ($self, $pn, $pnl, $level) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1669 my $expected = $self->{pn}[1][$level] + 1; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1670 my $pn_win = 1 << $pnl * 8; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1671 my $pn_hwin = $pn_win / 2; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1672 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1673 $pn |= $expected & ~($pn_win - 1); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1674 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1675 if ($pn <= $expected - $pn_hwin && $pn < (1 << 62) - $pn_win) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1676 $pn += $pn_win; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1677 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1678 } elsif ($pn > $expected + $pn_hwin && $pn >= $pn_win) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1679 $pn -= $pn_win; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1680 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1681 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1682 return $pn; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1683 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1684 |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1685 sub decrypt_aead_f { |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1686 my ($level, $cipher) = @_; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1687 if ($level == 0 || $cipher == 0x1301 || $cipher == 0x1302) { |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1688 return \&Crypt::AuthEnc::GCM::gcm_decrypt_verify, 'AES'; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1689 } |
1910
e0b53fbdb5cf
Tests: TLS_AES_128_CCM_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1909
diff
changeset
|
1690 if ($cipher == 0x1304) { |
e0b53fbdb5cf
Tests: TLS_AES_128_CCM_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1909
diff
changeset
|
1691 return \&Crypt::AuthEnc::CCM::ccm_decrypt_verify, 'AES'; |
e0b53fbdb5cf
Tests: TLS_AES_128_CCM_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1909
diff
changeset
|
1692 } |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1693 \&Crypt::AuthEnc::ChaCha20Poly1305::chacha20poly1305_decrypt_verify; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1694 } |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1695 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1696 sub decrypt_aead { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1697 my ($self, $buf) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1698 my $flags = unpack("C", substr($buf, 0, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1699 return 0, $self->decrypt_retry($buf) if ($flags & 0xf0) == 0xf0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1700 my $level = $flags & 0x80 ? $flags - 0xc0 >> 4 : 3; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1701 my $offpn = 1 + length($self->{scid}) if $level == 3; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1702 $offpn = ( |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1703 $offpn = unpack("C", substr($buf, 5, 1)), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1704 $self->{scid} = substr($buf, 6, $offpn), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1705 $offpn = unpack("C", substr($buf, 6 + length($self->{scid}), 1)), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1706 $self->{dcid} = |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1707 substr($buf, 6 + length($self->{scid}) + 1, $offpn), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1708 7 + ($level == 0) + length($self->{scid}) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1709 + length($self->{dcid})) if $level != 3; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1710 my ($len, $val) = $level != 3 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1711 ? parse_int(substr($buf, $offpn)) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1712 : (0, length($buf) - $offpn); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1713 $offpn += $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1714 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1715 my $sample = substr($buf, $offpn + 4, 16); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1716 my ($ad, $pnl, $pn) = $self->decrypt_ad($buf, |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1717 $self->{keys}[$level]{r}{hp}, $sample, $offpn, $level); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1718 Test::Nginx::log_core('||', "ad = " . unpack("H*", $ad)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1719 $pn = $self->decode_pn($pn, $pnl, $level); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1720 my $nonce = substr(pack("x12") . pack("N", $pn), -12) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1721 ^ $self->{keys}[$level]{r}{iv}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1722 my $ciphertext = substr($buf, $offpn + $pnl, $val - 16 - $pnl); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1723 my $tag = substr($buf, $offpn + $val - 16, 16); |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1724 my ($f, @args) = decrypt_aead_f($level, $self->{cipher}); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1725 my $plaintext = $f->(@args, |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1726 $self->{keys}[$level]{r}{key}, $nonce, $ad, $ciphertext, $tag); |
1933
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1727 if ($level == 3 && $self->{keys}[4]) { |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1728 if (!defined $plaintext) { |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1729 # in-flight packets might be protected with old keys |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1730 $nonce = substr(pack("x12") . pack("N", $pn), -12) |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1731 ^ $self->{keys}[4]{r}{iv}; |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1732 $plaintext = $f->(@args, $self->{keys}[4]{r}{key}, |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1733 $nonce, $ad, $ciphertext, $tag); |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1734 } else { |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1735 # remove old keys after unprotected with new keys |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1736 splice @{$self->{keys}}, 4, 1; |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1737 } |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1738 } |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1739 return if !defined $plaintext; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1740 Test::Nginx::log_core('||', |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1741 "pn = $pn, level = $level, length = " . length($plaintext)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1742 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1743 $self->{pn}[1][$level] = $pn; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1744 $self->{ack}[$level]{$pn} = -1; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1745 $self->{ack}[$_] = undef for (0 .. $level - 1); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1746 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1747 return ($level, $plaintext, |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1748 substr($buf, length($ad . $ciphertext . $tag)), ''); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1749 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1750 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1751 sub decrypt_ad { |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1752 my ($self, $buf, $hp, $sample, $offset, $level) = @_; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1753 |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1754 goto aes if $level == 0 || $self->{cipher} != 0x1303; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1755 |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1756 my $counter = unpack("V", substr($sample, 0, 4)); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1757 my $nonce = substr($sample, 4, 12); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1758 my $stream = Crypt::Stream::ChaCha->new($hp, $nonce, $counter); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1759 my $mask = $stream->crypt($self->{zero}); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1760 goto mask; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1761 aes: |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1762 my $m = Crypt::Mode::CTR->new('AES'); |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1763 $mask = $m->encrypt($self->{zero}, $hp, $sample); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1764 mask: |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1765 substr($buf, 0, 1) ^= substr($mask, 0, 1) |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1766 & ($level == 3 ? "\x1f" : "\x0f"); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1767 my $pnl = unpack("C", substr($buf, 0, 1) & "\x03") + 1; |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1768 substr($buf, $offset, $pnl) ^= substr($mask, 1); |
1925
a4f1cbd87f0d
Tests: fixed decoding QUIC packet numbers with PNL bits set.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1924
diff
changeset
|
1769 |
a4f1cbd87f0d
Tests: fixed decoding QUIC packet numbers with PNL bits set.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1924
diff
changeset
|
1770 my $pn = 0; |
a4f1cbd87f0d
Tests: fixed decoding QUIC packet numbers with PNL bits set.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1924
diff
changeset
|
1771 for my $n (1 .. $pnl) { |
a4f1cbd87f0d
Tests: fixed decoding QUIC packet numbers with PNL bits set.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1924
diff
changeset
|
1772 $pn += unpack("C", substr($buf, $offset + $n - 1, 1)) |
a4f1cbd87f0d
Tests: fixed decoding QUIC packet numbers with PNL bits set.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1924
diff
changeset
|
1773 << ($pnl - $n) * 8; |
a4f1cbd87f0d
Tests: fixed decoding QUIC packet numbers with PNL bits set.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1924
diff
changeset
|
1774 } |
a4f1cbd87f0d
Tests: fixed decoding QUIC packet numbers with PNL bits set.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1924
diff
changeset
|
1775 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1776 my $ad = substr($buf, 0, $offset + $pnl); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1777 return ($ad, $pnl, $pn); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1778 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1779 |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1780 sub encrypt_aead_f { |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1781 my ($level, $cipher) = @_; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1782 if ($level == 0 || $cipher == 0x1301 || $cipher == 0x1302) { |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1783 return \&Crypt::AuthEnc::GCM::gcm_encrypt_authenticate, 'AES'; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1784 } |
1910
e0b53fbdb5cf
Tests: TLS_AES_128_CCM_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1909
diff
changeset
|
1785 if ($cipher == 0x1304) { |
e0b53fbdb5cf
Tests: TLS_AES_128_CCM_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1909
diff
changeset
|
1786 return \&Crypt::AuthEnc::CCM::ccm_encrypt_authenticate, 'AES'; |
e0b53fbdb5cf
Tests: TLS_AES_128_CCM_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1909
diff
changeset
|
1787 } |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1788 \&Crypt::AuthEnc::ChaCha20Poly1305::chacha20poly1305_encrypt_authenticate; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1789 } |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1790 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1791 sub encrypt_aead { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1792 my ($self, $payload, $level) = @_; |
1940
aec72dcee93b
Tests: unconditional QUIC datagram expansion with Initial packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1938
diff
changeset
|
1793 |
aec72dcee93b
Tests: unconditional QUIC datagram expansion with Initial packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1938
diff
changeset
|
1794 if ($level == 0) { |
aec72dcee93b
Tests: unconditional QUIC datagram expansion with Initial packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1938
diff
changeset
|
1795 my $padding = 1200 - length($payload); |
aec72dcee93b
Tests: unconditional QUIC datagram expansion with Initial packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1938
diff
changeset
|
1796 $padding = 0 if $padding < 0; |
aec72dcee93b
Tests: unconditional QUIC datagram expansion with Initial packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1938
diff
changeset
|
1797 $payload = $payload . pack("x$padding"); |
aec72dcee93b
Tests: unconditional QUIC datagram expansion with Initial packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1938
diff
changeset
|
1798 } |
aec72dcee93b
Tests: unconditional QUIC datagram expansion with Initial packets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1938
diff
changeset
|
1799 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1800 my $pn = ++$self->{pn}[0][$level]; |
1930
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1801 my $ad = pack("C", $level == 3 |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1802 ? 0x40 | ($self->{key_phase} << 2) |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1803 : 0xc + $level << 4) | "\x03"; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1804 $ad .= "\x00\x00\x00\x01" unless $level == 3; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1805 $ad .= $level == 3 ? $self->{dcid} : |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1806 pack("C", length($self->{dcid})) . $self->{dcid} |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1807 . pack("C", length($self->{scid})) . $self->{scid}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1808 $ad .= build_int(length($self->{token})) . $self->{token} |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1809 if $level == 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1810 $ad .= build_int(length($payload) + 16 + 4) unless $level == 3; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1811 $ad .= pack("N", $pn); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1812 my $nonce = substr(pack("x12") . pack("N", $pn), -12) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1813 ^ $self->{keys}[$level]{w}{iv}; |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1814 my ($f, @args) = encrypt_aead_f($level, $self->{cipher}); |
1914
afbf4c06c014
Tests: fixed croak sending QUIC Initial with CCM cipher negotiated.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1910
diff
changeset
|
1815 my @taglen = ($level != 0 && $self->{cipher} == 0x1304) ? 16 : (); |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1816 my ($ciphertext, $tag) = $f->(@args, |
1914
afbf4c06c014
Tests: fixed croak sending QUIC Initial with CCM cipher negotiated.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1910
diff
changeset
|
1817 $self->{keys}[$level]{w}{key}, $nonce, $ad, @taglen, $payload); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1818 my $sample = substr($ciphertext . $tag, 0, 16); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1819 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1820 $ad = $self->encrypt_ad($ad, $self->{keys}[$level]{w}{hp}, |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1821 $sample, $level); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1822 return $ad . $ciphertext . $tag; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1823 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1824 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1825 sub encrypt_ad { |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1826 my ($self, $ad, $hp, $sample, $level) = @_; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1827 |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1828 goto aes if $level == 0 || $self->{cipher} != 0x1303; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1829 |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1830 my $counter = unpack("V", substr($sample, 0, 4)); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1831 my $nonce = substr($sample, 4, 12); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1832 my $stream = Crypt::Stream::ChaCha->new($hp, $nonce, $counter); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1833 my $mask = $stream->crypt($self->{zero}); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1834 goto mask; |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1835 aes: |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1836 my $m = Crypt::Mode::CTR->new('AES'); |
1909
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1837 $mask = $m->encrypt($self->{zero}, $hp, $sample); |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1838 mask: |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1839 substr($ad, 0, 1) ^= substr($mask, 0, 1) |
46bb1ffbb960
Tests: TLS_CHACHA20_POLY1305_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1908
diff
changeset
|
1840 & ($level == 3 ? "\x1f" : "\x0f"); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1841 substr($ad, -4) ^= substr($mask, 1); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1842 return $ad; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1843 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1844 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1845 sub decrypt_retry { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1846 my ($self, $buf) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1847 my $off = unpack("C", substr($buf, 5, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1848 $self->{scid} = substr($buf, 6, $off); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1849 $self->{odcid} = $self->{dcid}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1850 $self->{dcid} = unpack("C", substr($buf, 6 + $off, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1851 $self->{dcid} = substr($buf, 6 + $off + 1, $self->{dcid}); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1852 my $token = substr($buf, 6 + $off + 1 + length($self->{dcid}), -16); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1853 my $tag = substr($buf, -16); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1854 my $pseudo = pack("C", length($self->{odcid})) . $self->{odcid} |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1855 . substr($buf, 0, -16); |
1915
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1856 $self->{retry} = { token => $token, tag => $tag, pseudo => $pseudo }; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1857 return $tag, '', $token; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1858 } |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1859 |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1860 sub retry_token { |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1861 my ($self) = @_; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1862 return $self->{retry}{token}; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1863 } |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1864 |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1865 sub retry_tag { |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1866 my ($self) = @_; |
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1867 return $self->{retry}{tag}; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1868 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1869 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1870 sub retry_verify_tag { |
1915
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1871 my ($self) = @_; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1872 my $key = "\xbe\x0c\x69\x0b\x9f\x66\x57\x5a" |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1873 . "\x1d\x76\x6b\x54\xe3\x68\xc8\x4e"; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1874 my $nonce = "\x46\x15\x99\xd3\x5d\x63\x2b\xf2\x23\x98\x25\xbb"; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1875 my (undef, $tag) = Crypt::AuthEnc::GCM::gcm_encrypt_authenticate('AES', |
1915
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
1876 $key, $nonce, $self->{retry}{pseudo}, ''); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1877 return $tag; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1878 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1879 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1880 sub set_traffic_keys { |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1881 my ($self, $label, $hash, $hlen, $level, $direction, $secret, $digest) |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1882 = @_; |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1883 my $prk = hkdf_expand_label($label, $hash, $hlen, $secret, $digest); |
1910
e0b53fbdb5cf
Tests: TLS_AES_128_CCM_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1909
diff
changeset
|
1884 my $klen = $self->{cipher} == 0x1301 || $self->{cipher} == 0x1304 |
e0b53fbdb5cf
Tests: TLS_AES_128_CCM_SHA256 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1909
diff
changeset
|
1885 ? 16 : 32; |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1886 my $key = hkdf_expand_label("tls13 quic key", $hash, $klen, $prk); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1887 my $iv = hkdf_expand_label("tls13 quic iv", $hash, 12, $prk); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1888 my $hp = hkdf_expand_label("tls13 quic hp", $hash, $klen, $prk); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1889 $self->{keys}[$level]{$direction}{prk} = $prk; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1890 $self->{keys}[$level]{$direction}{key} = $key; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1891 $self->{keys}[$level]{$direction}{iv} = $iv; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1892 $self->{keys}[$level]{$direction}{hp} = $hp; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1893 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1894 |
1930
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1895 sub key_update { |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1896 my ($self) = @_; |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1897 my ($prk, $key, $iv); |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1898 my $klen = $self->{cipher} == 0x1301 || $self->{cipher} == 0x1304 |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1899 ? 16 : 32; |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1900 my ($hash, $hlen) = $self->{cipher} == 0x1302 ? |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1901 ('SHA384', 48) : ('SHA256', 32); |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1902 $self->{key_phase} ^= 1; |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1903 |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1904 for my $direction ('r', 'w') { |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1905 $prk = $self->{keys}[3]{$direction}{prk}; |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1906 $prk = hkdf_expand_label("tls13 quic ku", $hash, $hlen, $prk); |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1907 $key = hkdf_expand_label("tls13 quic key", $hash, $klen, $prk); |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1908 $iv = hkdf_expand_label("tls13 quic iv", $hash, 12, $prk); |
1933
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1909 $self->{keys}[4]{$direction}{key} = |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1910 $self->{keys}[3]{$direction}{key}; |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1911 $self->{keys}[4]{$direction}{iv} = |
9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1930
diff
changeset
|
1912 $self->{keys}[3]{$direction}{iv}; |
1930
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1913 $self->{keys}[3]{$direction}{prk} = $prk; |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1914 $self->{keys}[3]{$direction}{key} = $key; |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1915 $self->{keys}[3]{$direction}{iv} = $iv; |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1916 } |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1917 } |
0e8b5b442b1d
Tests: basic QUIC key update tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1929
diff
changeset
|
1918 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1919 sub hmac_finished { |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1920 my ($hash, $hlen, $key, $digest) = @_; |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1921 my $expand = hkdf_expand_label("tls13 finished", $hash, $hlen, $key); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1922 Crypt::Mac::HMAC::hmac($hash, $expand, $digest); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1923 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1924 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1925 sub tls13_finished { |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1926 my $hmac = hmac_finished(@_); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1927 "\x14\x00" . pack('n', length($hmac)) . $hmac; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1928 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1929 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1930 sub binders { |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1931 my $hmac = hmac_finished(@_); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1932 pack('n', length($hmac) + 1) . pack('C', length($hmac)) . $hmac; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1933 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1934 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1935 sub hkdf_advance { |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1936 my ($hash, $hlen, $secret, $prk) = @_; |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1937 my $expand = hkdf_expand_label("tls13 derived", $hash, $hlen, $prk, |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1938 Crypt::Digest::digest_data($hash, '')); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1939 Crypt::KeyDerivation::hkdf_extract($secret, $expand, $hash); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1940 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1941 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1942 sub hkdf_expand_label { |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1943 my ($label, $hash, $len, $prk, $context) = @_; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1944 $context = '' if !defined $context; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1945 my $info = pack("C3", 0, $len, length($label)) . $label |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1946 . pack("C", length($context)) . $context; |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
1947 Crypt::KeyDerivation::hkdf_expand($prk, $hash, $len, $info); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1948 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1949 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1950 sub key_share { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1951 my ($extens) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1952 my $offset = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1953 while ($offset < length($extens)) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1954 my $ext = substr($extens, $offset, 2); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1955 my $len = unpack("C", substr($extens, $offset + 2, 1)) * 8 + |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1956 unpack("C", substr($extens, $offset + 3, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1957 if ($ext eq "\x00\x33") { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1958 return substr($extens, $offset + 4 + 4, $len - 4); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1959 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1960 $offset += 4 + $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1961 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1962 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1963 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1964 sub early_data { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1965 my ($extens) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1966 my $offset = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1967 while ($offset < length($extens)) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1968 my $ext = substr($extens, $offset, 2); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1969 my $len = unpack("C", substr($extens, $offset + 2, 1)) * 8 + |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1970 unpack("C", substr($extens, $offset + 3, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1971 if ($ext eq "\x00\x2a") { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1972 return substr($extens, $offset + 4, $len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1973 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1974 $offset += 4 + $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1975 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1976 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1977 |
1884
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1978 sub pre_shared_key { |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1979 my ($extens) = @_; |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1980 my $offset = 0; |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1981 while ($offset < length($extens)) { |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1982 my $ext = substr($extens, $offset, 2); |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1983 my $len = unpack("C", substr($extens, $offset + 2, 1)) * 8 + |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1984 unpack("C", substr($extens, $offset + 3, 1)); |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1985 if ($ext eq "\x00\x29") { |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1986 return unpack("n", substr($extens, $offset + 4, $len)); |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1987 } |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1988 $offset += 4 + $len; |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1989 } |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1990 return; |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1991 } |
6f1508d53a26
Tests: fixed extracting QUIC early secret if PSK is not in use.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1883
diff
changeset
|
1992 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1993 ############################################################################### |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1994 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1995 sub build_cc { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1996 my ($code, $reason) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1997 "\x1d" . build_int($code) . build_int(length($reason)) . $reason; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1998 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1999 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2000 sub build_ack { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2001 my ($ack) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2002 my @keys = sort { $b <=> $a } keys %$ack; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2003 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2004 return "\x02" . build_int($keys[0]) . "\x00\x00\x00" if @keys == 1; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2005 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2006 my $min = my $max = shift @keys; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2007 my @acks = (); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2008 for my $next (@keys) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2009 if ($next == $min - 1) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2010 $min = $next; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2011 next if $next != $keys[-1]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2012 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2013 push @acks, $max, $min; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2014 $min = $max = $next; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2015 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2016 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2017 ($max, $min) = splice @acks, 0, 2; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2018 my $ranges = @acks / 2; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2019 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2020 $ack = "\x02" . build_int($max) . "\x00" . build_int($ranges) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2021 . build_int($max - $min); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2022 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2023 for (my $smallest = $min; $ranges--; ) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2024 my ($max, $min) = splice @acks, 0, 2; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2025 $ack .= build_int($smallest - $max - 2); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2026 $ack .= build_int($max - $min); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2027 $smallest = $min; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2028 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2029 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2030 return $ack; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2031 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2032 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2033 sub build_crypto { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2034 my ($tlsm) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2035 "\x06\x00" . build_int(length($tlsm)) . $tlsm; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2036 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2037 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2038 sub build_stream { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2039 my ($self, $r, %extra) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2040 my $stream = $extra{start} ? 0xe : 0xf; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2041 my $length = $extra{length} ? $extra{length} : build_int(length($r)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2042 my $offset = build_int($extra{offset} ? $extra{offset} : 0); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2043 my $sid = defined $extra{sid} ? $extra{sid} : $self->{requests}++; |
1926
0fb9ca9046bf
Tests: fixed variable-length encoding of QUIC Stream ID.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1925
diff
changeset
|
2044 $sid = build_int(4 * $sid); |
0fb9ca9046bf
Tests: fixed variable-length encoding of QUIC Stream ID.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1925
diff
changeset
|
2045 pack("C", $stream) . $sid . $offset . $length . $r; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2046 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2047 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2048 sub parse_int { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2049 my ($buf) = @_; |
1928
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
2050 return undef if length($buf) < 1; |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
2051 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2052 my $val = unpack("C", substr($buf, 0, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2053 my $len = my $plen = 1 << ($val >> 6); |
1928
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
2054 return undef if length($buf) < $len; |
2df7d700518f
Tests: fixed parsing STREAM frames split on inner frame headers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1927
diff
changeset
|
2055 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2056 $val = $val & 0x3f; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2057 while (--$len) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2058 $val = ($val << 8) + unpack("C", substr($buf, $plen - $len, 1)) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2059 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2060 return ($plen, $val); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2061 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2062 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2063 sub build_int { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2064 my ($value) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2065 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2066 my $build_int_set = sub { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2067 my ($value, $len, $bits) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2068 (($value >> ($len * 8)) & 0xff) | ($bits << 6); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2069 }; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2070 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2071 if ($value < 1 << 6) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2072 pack("C", $build_int_set->($value, 0, 0)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2073 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2074 } elsif ($value < 1 << 14) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2075 pack("C*", |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2076 $build_int_set->($value, 1, 1), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2077 $build_int_set->($value, 0, 0), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2078 ); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2079 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2080 } elsif ($value < 1 << 30) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2081 pack("C*", |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2082 $build_int_set->($value, 3, 2), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2083 $build_int_set->($value, 2, 0), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2084 $build_int_set->($value, 1, 0), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2085 $build_int_set->($value, 0, 0), |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2086 ); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2087 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2088 } else { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2089 pack("C*", |
1959
9877dce42a59
Tests: fixed HTTP/3 build_int() for large integers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1958
diff
changeset
|
2090 $build_int_set->($value, 7, 3), |
9877dce42a59
Tests: fixed HTTP/3 build_int() for large integers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1958
diff
changeset
|
2091 $build_int_set->($value, 6, 0), |
9877dce42a59
Tests: fixed HTTP/3 build_int() for large integers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1958
diff
changeset
|
2092 $build_int_set->($value, 5, 0), |
9877dce42a59
Tests: fixed HTTP/3 build_int() for large integers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1958
diff
changeset
|
2093 $build_int_set->($value, 4, 0), |
9877dce42a59
Tests: fixed HTTP/3 build_int() for large integers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1958
diff
changeset
|
2094 $build_int_set->($value, 3, 0), |
9877dce42a59
Tests: fixed HTTP/3 build_int() for large integers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1958
diff
changeset
|
2095 $build_int_set->($value, 2, 0), |
9877dce42a59
Tests: fixed HTTP/3 build_int() for large integers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1958
diff
changeset
|
2096 $build_int_set->($value, 1, 0), |
9877dce42a59
Tests: fixed HTTP/3 build_int() for large integers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
1958
diff
changeset
|
2097 $build_int_set->($value, 0, 0), |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2098 ); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2099 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2100 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2101 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2102 ############################################################################### |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2103 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2104 sub read_stream_message { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2105 my ($self, $timo) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2106 my ($level, $plaintext, @data); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2107 my $s = $self->{socket}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2108 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2109 while (1) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2110 @data = $self->parse_stream(); |
1905
f35824e75b66
Tests: fixed reading QUIC streams on Perl < 5.24.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1889
diff
changeset
|
2111 return @data if @data; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2112 return if scalar @{$self->{frames_in}}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2113 |
1886
90a310f3cee6
Tests: workaround for QUIC routing while reloading nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1884
diff
changeset
|
2114 again: |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2115 my $txt; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2116 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2117 if (!length($self->{buf})) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2118 return unless IO::Select->new($s)->can_read($timo || 3); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2119 $s->sysread($self->{buf}, 65527); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2120 $txt = "recv"; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2121 } else { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2122 $txt = "remaining"; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2123 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2124 my $len = length $self->{buf}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2125 Test::Nginx::log_core('||', sprintf("$txt = [%d]", $len)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2126 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2127 while ($self->{buf}) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2128 ($level, $plaintext, $self->{buf}, $self->{token}) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2129 = $self->decrypt_aead($self->{buf}); |
1886
90a310f3cee6
Tests: workaround for QUIC routing while reloading nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1884
diff
changeset
|
2130 if (!defined $plaintext) { |
90a310f3cee6
Tests: workaround for QUIC routing while reloading nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1884
diff
changeset
|
2131 $self->{buf} = ''; |
90a310f3cee6
Tests: workaround for QUIC routing while reloading nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1884
diff
changeset
|
2132 goto again; |
90a310f3cee6
Tests: workaround for QUIC routing while reloading nginx.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1884
diff
changeset
|
2133 } |
1915
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
2134 $self->retry(), return if $self->{token}; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2135 $self->handle_frames(parse_frames($plaintext), $level); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2136 @data = $self->parse_stream(); |
1905
f35824e75b66
Tests: fixed reading QUIC streams on Perl < 5.24.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1889
diff
changeset
|
2137 return @data if @data; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2138 return if scalar @{$self->{frames_in}}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2139 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2140 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2141 return; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2142 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2143 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2144 sub parse_stream { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2145 my ($self) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2146 my $data; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2147 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2148 for my $i (0 .. $#{$self->{stream_in}}) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2149 my $stream = $self->{stream_in}[$i]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2150 next if !defined $stream; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2151 |
1929
3408c20d2f24
Tests: unbreak reading QUIC stream received not from the beginning.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1928
diff
changeset
|
2152 my $offset = $stream->{buf}[0][0]; |
3408c20d2f24
Tests: unbreak reading QUIC stream received not from the beginning.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1928
diff
changeset
|
2153 next if $offset != 0; |
3408c20d2f24
Tests: unbreak reading QUIC stream received not from the beginning.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1928
diff
changeset
|
2154 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2155 my $buf = $stream->{buf}[0][2]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2156 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2157 if ($stream->{buf}[0][3]) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2158 $stream->{buf}[0][3] = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2159 $stream->{eof} = 1; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2160 $data = ''; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2161 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2162 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2163 if (length($buf) > $stream->{pos}) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2164 $data = substr($buf, $stream->{pos}); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2165 $stream->{pos} = length($buf); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2166 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2167 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2168 next if !defined $data; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2169 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2170 return ($i, $data, $stream->{eof} ? 1 : 0); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2171 } |
1905
f35824e75b66
Tests: fixed reading QUIC streams on Perl < 5.24.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1889
diff
changeset
|
2172 return; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2173 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2174 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2175 ############################################################################### |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2176 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2177 sub read_tls_message { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2178 my ($self, $buf, $type) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2179 my $s = $self->{socket}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2180 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2181 while (!$type->($self)) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2182 my $txt; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2183 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2184 if (!length($$buf)) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2185 return unless IO::Select->new($s)->can_read(3); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2186 $s->sysread($$buf, 65527); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2187 $txt = "recv"; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2188 } else { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2189 $txt = "remaining"; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2190 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2191 my $len = length $$buf; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2192 Test::Nginx::log_core('||', sprintf("$txt = [%d]", $len)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2193 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2194 while ($$buf) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2195 (my $level, my $plaintext, $$buf, $self->{token}) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2196 = $self->decrypt_aead($$buf); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2197 return if !defined $plaintext; |
1915
15131dd931a0
Tests: QUIC address validation tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1914
diff
changeset
|
2198 $self->retry(), return 1 if $self->{token}; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2199 $self->handle_frames(parse_frames($plaintext), $level); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2200 return 1 if $type->($self); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2201 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2202 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2203 return; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2204 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2205 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2206 sub parse_tls_server_hello { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2207 my ($self) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2208 my $buf = $self->{crypto_in}[0][0][2] if $self->{crypto_in}[0][0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2209 return 0 if !$buf || length($buf) < 4; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2210 my $type = unpack("C", substr($buf, 0, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2211 my $len = unpack("n", substr($buf, 2, 2)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2212 my $content = substr($buf, 4, $len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2213 return 0 if length($content) < $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2214 $self->{tlsm}{sh} = substr($buf, 0, 4) . $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2215 return $self->{tlsm}{sh}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2216 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2217 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2218 sub parse_tls_encrypted_extensions { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2219 my ($self) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2220 my $buf = $self->{crypto_in}[2][0][2] if $self->{crypto_in}[2][0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2221 return 0 if !$buf; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2222 my $off = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2223 my $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2224 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2225 while ($off < length($buf)) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2226 return 0 if length($buf) < 4; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2227 my $type = unpack("C", substr($buf, $off, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2228 my $len = unpack("n", substr($buf, $off + 2, 2)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2229 $content = substr($buf, $off + 4, $len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2230 return 0 if length($content) < $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2231 last if $type == 8; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2232 $off += 4 + $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2233 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2234 $self->{tlsm}{ee} = substr($buf, $off, 4) . $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2235 return $self->{tlsm}{ee}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2236 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2237 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2238 sub parse_tls_certificate { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2239 my ($self) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2240 my $buf = $self->{crypto_in}[2][0][2] if $self->{crypto_in}[2][0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2241 return 0 if !$buf; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2242 my $off = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2243 my $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2244 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2245 while ($off < length($buf)) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2246 return 0 if length($buf) < 4; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2247 my $type = unpack("C", substr($buf, $off, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2248 my $len = unpack("n", substr($buf, $off + 2, 2)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2249 $content = substr($buf, $off + 4, $len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2250 return 0 if length($content) < $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2251 last if $type == 11; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2252 $off += 4 + $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2253 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2254 $self->{tlsm}{cert} = substr($buf, $off, 4) . $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2255 return $self->{tlsm}{cert}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2256 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2257 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2258 sub parse_tls_certificate_verify { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2259 my ($self) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2260 my $buf = $self->{crypto_in}[2][0][2] if $self->{crypto_in}[2][0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2261 return 0 if !$buf; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2262 my $off = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2263 my $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2264 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2265 while ($off < length($buf)) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2266 return 0 if length($buf) < 4; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2267 my $type = unpack("C", substr($buf, $off, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2268 my $len = unpack("n", substr($buf, $off + 2, 2)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2269 $content = substr($buf, $off + 4, $len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2270 return 0 if length($content) < $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2271 last if $type == 15; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2272 $off += 4 + $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2273 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2274 $self->{tlsm}{cv} = substr($buf, $off, 4) . $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2275 return $self->{tlsm}{cv}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2276 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2277 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2278 sub parse_tls_finished { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2279 my ($self) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2280 my $buf = $self->{crypto_in}[2][0][2] if $self->{crypto_in}[2][0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2281 return 0 if !$buf; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2282 my $off = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2283 my $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2284 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2285 while ($off < length($buf)) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2286 return 0 if length($buf) < 4; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2287 my $type = unpack("C", substr($buf, $off, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2288 my $len = unpack("n", substr($buf, $off + 2, 2)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2289 $content = substr($buf, $off + 4, $len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2290 return 0 if length($content) < $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2291 last if $type == 20; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2292 $off += 4 + $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2293 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2294 $self->{tlsm}{sf} = substr($buf, $off, 4) . $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2295 return $self->{tlsm}{sf}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2296 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2297 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2298 sub parse_tls_nst { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2299 my ($self) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2300 my $buf = $self->{crypto_in}[3][0][2] if $self->{crypto_in}[3][0]; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2301 return 0 if !$buf; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2302 my $off = 0; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2303 my $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2304 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2305 while ($off < length($buf)) { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2306 return 0 if length($buf) < 4; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2307 my $type = unpack("C", substr($buf, $off, 1)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2308 my $len = unpack("n", substr($buf, $off + 2, 2)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2309 $content = substr($buf, $off + 4, $len); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2310 return 0 if length($content) < $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2311 $self->{tlsm}{nst} .= substr($buf, $off, 4) . $content; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2312 $self->save_session_tickets(substr($buf, $off, 4) . $content); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2313 $off += 4 + $len; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2314 substr($self->{crypto_in}[3][0][2], 0, $off) = ''; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2315 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2316 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2317 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2318 sub build_tls_client_hello { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2319 my ($self) = @_; |
1934
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2320 my $named_group = $self->tls_named_group(); |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2321 my $key_share = $self->tls_public_key(); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2322 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2323 my $version = "\x03\x03"; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2324 my $random = Crypt::PRNG::random_bytes(32); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2325 my $session = "\x00"; |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2326 my $cipher = pack('n', length($self->{ciphers})) . $self->{ciphers}; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2327 my $compr = "\x01\x00"; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2328 my $ext = build_tlsext_server_name($self->{sni}) |
1934
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2329 . build_tlsext_supported_groups($named_group) |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2330 . build_tlsext_alpn("h3", "hq-interop") |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2331 . build_tlsext_sigalgs(0x0804, 0x0805, 0x0806) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2332 . build_tlsext_supported_versions(0x0304) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2333 . build_tlsext_ke_modes(1) |
1934
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2334 . build_tlsext_key_share($named_group, $key_share) |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2335 . build_tlsext_quic_tp($self->{scid}, $self->{opts}); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2336 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2337 $ext .= build_tlsext_early_data($self->{psk}) |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2338 . build_tlsext_psk($self->{psk}) if keys %{$self->{psk}}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2339 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2340 my $len = pack('n', length($ext)); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2341 my $ch = $version . $random . $session . $cipher . $compr . $len . $ext; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2342 $ch = "\x01\x00" . pack('n', length($ch)) . $ch; |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2343 $ch = build_tls_ch_with_binder($ch, $self->{psk}, $self->{es_prk}) |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2344 if keys %{$self->{psk}}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2345 return $ch; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2346 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2347 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2348 sub build_tlsext_server_name { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2349 my ($name) = @_; |
1887
1023354f3a41
Tests: ssl_reject_handshake tests with HTTP/3.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1886
diff
changeset
|
2350 return '' if !defined $name; |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2351 my $sname = pack('xn', length($name)) . $name; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2352 my $snamelist = pack('n', length($sname)) . $sname; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2353 pack('n2', 0, length($snamelist)) . $snamelist; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2354 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2355 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2356 sub build_tlsext_supported_groups { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2357 my $ngrouplist = pack('n*', @_ * 2, @_); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2358 pack('n2', 10, length($ngrouplist)) . $ngrouplist; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2359 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2360 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2361 sub build_tlsext_alpn { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2362 my $protoname = pack('(C/a*)*', @_); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2363 my $protonamelist = pack('n', length($protoname)) . $protoname; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2364 pack('n2', 16, length($protonamelist)) . $protonamelist; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2365 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2366 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2367 sub build_tlsext_sigalgs { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2368 my $sschemelist = pack('n*', @_ * 2, @_); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2369 pack('n2', 13, length($sschemelist)) . $sschemelist; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2370 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2371 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2372 sub build_tlsext_supported_versions { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2373 my $versions = pack('Cn*', @_ * 2, @_); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2374 pack('n2', 43, length($versions)) . $versions; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2375 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2376 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2377 sub build_tlsext_ke_modes { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2378 my $versions = pack('C*', scalar(@_), @_); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2379 pack('n2', 45, length($versions)) . $versions; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2380 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2381 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2382 sub build_tlsext_key_share { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2383 my ($group, $share) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2384 my $kse = pack("n2", $group, length($share)) . $share; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2385 my $ksch = pack("n", length($kse)) . $kse; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2386 pack('n2', 51, length($ksch)) . $ksch; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2387 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2388 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2389 sub build_tlsext_quic_tp { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2390 my ($scid, $opts) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2391 my $tp = ''; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2392 my $quic_tp_tlv = sub { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2393 my ($id, $val) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2394 $val = $opts->{$id} // $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2395 $val = build_int($val) unless $id == 15; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2396 $tp .= build_int($id) . pack("C*", length($val)) . $val; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2397 }; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2398 $quic_tp_tlv->(1, 30000); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2399 $quic_tp_tlv->(4, 1048576); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2400 $quic_tp_tlv->(5, 262144); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2401 $quic_tp_tlv->(7, 262144); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2402 $quic_tp_tlv->(9, 100); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2403 $quic_tp_tlv->(15, $scid); |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2404 pack('n2', 57, length($tp)) . $tp; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2405 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2406 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2407 sub build_tlsext_early_data { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2408 my ($psk) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2409 $psk->{ed} ? pack('n2', 42, 0) : ''; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2410 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2411 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2412 sub build_tlsext_psk { |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2413 my ($psk) = @_; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2414 my $identity = pack('n', length($psk->{ticket})) . $psk->{ticket} |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2415 . $psk->{age_add}; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2416 my $identities = pack('n', length($identity)) . $identity; |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2417 my $hash = $psk->{cipher} == 0x1302 ? pack('x48') : pack('x32'); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2418 my $binder = pack('C', length($hash)) . $hash; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2419 my $binders = pack('n', length($binder)) . $binder; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2420 pack('n2', 41, length($identities . $binders)) . $identities . $binders; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2421 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2422 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2423 sub build_tls_ch_with_binder { |
1908
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2424 my ($ch, $psk, $prk) = @_; |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2425 my ($hash, $hlen) = $psk->{cipher} == 0x1302 ? |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2426 ('SHA384', 48) : ('SHA256', 32); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2427 my $key = hkdf_expand_label("tls13 res binder", $hash, $hlen, $prk, |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2428 Crypt::Digest::digest_data($hash, '')); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2429 my $truncated = substr($ch, 0, -3 - $hlen); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2430 my $context = Crypt::Digest::digest_data($hash, $truncated); |
1baf5fe1d86c
Tests: TLS_AES_256_GCM_SHA384 support in QUIC handshake.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1905
diff
changeset
|
2431 $truncated . binders($hash, $hlen, $key, $context); |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2432 } |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2433 |
1934
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2434 sub tls_generate_key { |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2435 my ($self) = @_; |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2436 $self->{sk} = $self->{group} eq 'x25519' |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2437 ? Crypt::PK::X25519->new->generate_key |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2438 : Crypt::PK::ECC->new->generate_key($self->{group}); |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2439 } |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2440 |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2441 sub tls_public_key { |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2442 my ($self) = @_; |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2443 $self->{sk}->export_key_raw('public'); |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2444 } |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2445 |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2446 sub tls_shared_secret { |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2447 my ($self, $pub) = @_; |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2448 my $pk = $self->{group} eq 'x25519' |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2449 ? Crypt::PK::X25519->new : Crypt::PK::ECC->new; |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2450 $pk->import_key_raw($pub, $self->{group} eq 'x25519' |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2451 ? 'public' : $self->{group}); |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2452 $self->{sk}->shared_secret($pk); |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2453 } |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2454 |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2455 sub tls_named_group { |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2456 my ($self) = @_; |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2457 my $name = $self->{group}; |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2458 return 0x17 if $name eq 'secp256r1'; |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2459 return 0x18 if $name eq 'secp384r1'; |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2460 return 0x19 if $name eq 'secp521r1'; |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2461 return 0x1d if $name eq 'x25519'; |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2462 } |
4d13c9e74d04
Tests: added ability to setup QUIC TLS named group.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1933
diff
changeset
|
2463 |
1874
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2464 ############################################################################### |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2465 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2466 1; |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2467 |
d57a0fd293a3
Tests: basic QUIC support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2468 ############################################################################### |