comparison h3_ssl_early_data.t @ 1917:24fea64f233f

Tests: TLS early data tests with HTTP/3.
author Sergey Kandaurov <pluknet@nginx.com>
date Thu, 22 Jun 2023 15:35:19 +0400
parents
children 22f45bf99a9e
comparison
equal deleted inserted replaced
1916:6ab08c255dd3 1917:24fea64f233f
1 #!/usr/bin/perl
2
3 # (C) Sergey Kandaurov
4 # (C) Nginx, Inc.
5
6 # Tests for TLS early data with HTTP/3.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14
15 BEGIN { use FindBin; chdir($FindBin::Bin); }
16
17 use lib 'lib';
18 use Test::Nginx;
19 use Test::Nginx::HTTP3;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 my $t = Test::Nginx->new()->has(qw/http http_v3 cryptx/)
27 ->has_daemon('openssl')->plan(5)
28 ->write_file_expand('nginx.conf', <<'EOF');
29
30 %%TEST_GLOBALS%%
31
32 daemon off;
33
34 events {
35 }
36
37 http {
38 %%TEST_GLOBALS_HTTP%%
39
40 ssl_certificate_key localhost.key;
41 ssl_certificate localhost.crt;
42 ssl_early_data on;
43
44 add_header X-Session $ssl_session_reused always;
45 add_header X-Early $ssl_early_data always;
46
47 server {
48 listen 127.0.0.1:%%PORT_8980_UDP%% quic;
49 server_name localhost;
50 }
51 }
52
53 EOF
54
55 $t->write_file('openssl.conf', <<EOF);
56 [ req ]
57 default_bits = 2048
58 encrypt_key = no
59 distinguished_name = req_distinguished_name
60 [ req_distinguished_name ]
61 EOF
62
63 my $d = $t->testdir();
64
65 foreach my $name ('localhost') {
66 system('openssl req -x509 -new '
67 . "-config $d/openssl.conf -subj /CN=$name/ "
68 . "-out $d/$name.crt -keyout $d/$name.key "
69 . ">>$d/openssl.out 2>&1") == 0
70 or die "Can't create certificate for $name: $!\n";
71 }
72
73 $t->run();
74
75 ###############################################################################
76
77 my $s = Test::Nginx::HTTP3->new(8980);
78 my $frames = $s->read(all => [{ sid => $s->new_stream(), fin => 1 }]);
79
80 my ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
81 is($frame->{headers}->{'x-session'}, '.', 'new session');
82
83 local $TODO = 'no TLSv1.3 sessions in LibreSSL' if $t->has_module('LibreSSL');
84
85 my $psk_list = $s->{psk_list};
86 my $ed = $s->build_new_stream();
87
88 $s = Test::Nginx::HTTP3->new(8980, psk_list => $psk_list, early_data => {});
89
90 TODO: {
91 local $TODO = 'no 0-RTT in OpenSSL compat layer'
92 unless $t->has_module('OpenSSL [.0-9]+\+quic')
93 or $t->has_module('BoringSSL')
94 or $t->has_module('LibreSSL');
95
96 $frames = $s->read(all => [{ sid => 0, fin => 1 }]);
97 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
98 is($frame->{headers}->{'x-session'}, 'r', 'reused session 0rtt');
99 is($frame->{headers}->{'x-early'}, '1', 'reused session is early');
100
101 }
102
103 $frames = $s->read(all => [{ sid => $s->new_stream(), fin => 1 }]);
104 ($frame) = grep { $_->{type} eq "HEADERS" } @$frames;
105 is($frame->{headers}->{'x-session'}, 'r', 'reused session 1rtt');
106 is($frame->{headers}->{'x-early'}, undef, 'reused session not early');
107
108 ###############################################################################