Mercurial > hg > nginx-tests
comparison lib/Test/Nginx/HTTP3.pm @ 1933:9bafe7cddd3c
Tests: improved QUIC key update tests with old keys.
On unsuccessful protection removal, it is now retried with old keys.
Otherwise, old keys are removed to ensure they're no longer in use.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 21 Aug 2023 17:26:47 +0400 |
parents | 0e8b5b442b1d |
children | 4d13c9e74d04 |
comparison
equal
deleted
inserted
replaced
1932:b68471aee5ad | 1933:9bafe7cddd3c |
---|---|
1719 my $ciphertext = substr($buf, $offpn + $pnl, $val - 16 - $pnl); | 1719 my $ciphertext = substr($buf, $offpn + $pnl, $val - 16 - $pnl); |
1720 my $tag = substr($buf, $offpn + $val - 16, 16); | 1720 my $tag = substr($buf, $offpn + $val - 16, 16); |
1721 my ($f, @args) = decrypt_aead_f($level, $self->{cipher}); | 1721 my ($f, @args) = decrypt_aead_f($level, $self->{cipher}); |
1722 my $plaintext = $f->(@args, | 1722 my $plaintext = $f->(@args, |
1723 $self->{keys}[$level]{r}{key}, $nonce, $ad, $ciphertext, $tag); | 1723 $self->{keys}[$level]{r}{key}, $nonce, $ad, $ciphertext, $tag); |
1724 if ($level == 3 && $self->{keys}[4]) { | |
1725 if (!defined $plaintext) { | |
1726 # in-flight packets might be protected with old keys | |
1727 $nonce = substr(pack("x12") . pack("N", $pn), -12) | |
1728 ^ $self->{keys}[4]{r}{iv}; | |
1729 $plaintext = $f->(@args, $self->{keys}[4]{r}{key}, | |
1730 $nonce, $ad, $ciphertext, $tag); | |
1731 } else { | |
1732 # remove old keys after unprotected with new keys | |
1733 splice @{$self->{keys}}, 4, 1; | |
1734 } | |
1735 } | |
1724 return if !defined $plaintext; | 1736 return if !defined $plaintext; |
1725 Test::Nginx::log_core('||', | 1737 Test::Nginx::log_core('||', |
1726 "pn = $pn, level = $level, length = " . length($plaintext)); | 1738 "pn = $pn, level = $level, length = " . length($plaintext)); |
1727 | 1739 |
1728 $self->{pn}[1][$level] = $pn; | 1740 $self->{pn}[1][$level] = $pn; |
1882 for my $direction ('r', 'w') { | 1894 for my $direction ('r', 'w') { |
1883 $prk = $self->{keys}[3]{$direction}{prk}; | 1895 $prk = $self->{keys}[3]{$direction}{prk}; |
1884 $prk = hkdf_expand_label("tls13 quic ku", $hash, $hlen, $prk); | 1896 $prk = hkdf_expand_label("tls13 quic ku", $hash, $hlen, $prk); |
1885 $key = hkdf_expand_label("tls13 quic key", $hash, $klen, $prk); | 1897 $key = hkdf_expand_label("tls13 quic key", $hash, $klen, $prk); |
1886 $iv = hkdf_expand_label("tls13 quic iv", $hash, 12, $prk); | 1898 $iv = hkdf_expand_label("tls13 quic iv", $hash, 12, $prk); |
1899 $self->{keys}[4]{$direction}{key} = | |
1900 $self->{keys}[3]{$direction}{key}; | |
1901 $self->{keys}[4]{$direction}{iv} = | |
1902 $self->{keys}[3]{$direction}{iv}; | |
1887 $self->{keys}[3]{$direction}{prk} = $prk; | 1903 $self->{keys}[3]{$direction}{prk} = $prk; |
1888 $self->{keys}[3]{$direction}{key} = $key; | 1904 $self->{keys}[3]{$direction}{key} = $key; |
1889 $self->{keys}[3]{$direction}{iv} = $iv; | 1905 $self->{keys}[3]{$direction}{iv} = $iv; |
1890 } | 1906 } |
1891 } | 1907 } |