[PATCH 00 of 20] tests suite fixes for TLSv1.3

Maxim Dounin mdounin at mdounin.ru
Thu Mar 23 14:18:30 UTC 2023


Hello!

On Wed, Mar 22, 2023 at 03:43:12PM +0400, Sergey Kandaurov wrote:

> > On 18 Mar 2023, at 18:14, Maxim Dounin <mdounin at mdounin.ru> wrote:
> > 
> > Hello!
> > 
> > Here are patch series for the test suite to address test failures
> > observed with TLSv1.3 enabled with BoringSSL and LibreSSL.
> > 
> > Short summary of the issues seen:
> > 
> > - BoringSSL with TLSv1.3 does not support session reuse via server-side
> >  session cache, only with tickets.
> > 
> > - BoringSSL with TLSv1.3 does not provide $ssl_session_id.
> > 
> > - LibreSSL with TLSv1.3 does not support session reuse.
> > 
> > - LibreSSL with TLSv1.3 fails to negotiate certificates based on
> >  signature algorithms supported by the client, and fails with
> >  "missing rsa certificate" and "unknown pkey type" errors.
> > 
> > - LibreSSL with TLSv1.3 does not send CA lists to the client.
> > 
> 
> Missing peaces that allow me to run with LibreSSL:
> 
> # HG changeset patch
> # User Sergey Kandaurov <pluknet at nginx.com>
> # Date 1679485246 -14400
> #      Wed Mar 22 15:40:46 2023 +0400
> # Node ID dfe434f295d3da7e3b67bbbafeab245bb591f397
> # Parent  826e00e7c037d617781239963e8b868b6b0de225
> Tests: fixed upstream zone tests with LibreSSL and TLSv1.3.
> 
> LibreSSL does not support session reuse with TLSv1.3.
> 
> diff --git a/stream_upstream_zone_ssl.t b/stream_upstream_zone_ssl.t
> --- a/stream_upstream_zone_ssl.t
> +++ b/stream_upstream_zone_ssl.t

Thanks.  I've happen to compile nginx without upstream zone 
modules as a leftover from some previous tests, and missed these.  
Added a similar change with TODOs.

Full series with all the fixes:

# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679498636 -10800
#      Wed Mar 22 18:23:56 2023 +0300
# Node ID 8fb46a1a0f3e6ca94e2c59ce50e3043a67cde674
# Parent  1f125771f1a1014dcceb8b765f3dd3153d4552f9
Tests: separate SSL session reuse tests.

Instead of being mixed with generic SSL tests, session reuse variants
are now tested in a separate file.

In the generic SSL tests only basic session reuse is now tested,
notably with session tickets enabled and a shared SSL session cache.
This should make it possible to reuse sessions in all cases (except
when it's not supported, such as with LibreSSL with TLSv1.3).

Note that session reuse with tickets implies that $ssl_session_id
is selected by the client and therefore is not available on the
initial connection.  Relevant test is modified to handle this.

Further, BoringSSL does not use legacy session ID with TLSv1.3 even
if it is sent by the client.  In contrast, OpenSSL always generates
an unique legacy session id, so it is available with TLSv1.3 even if
session resumption does not work (such as with old Net::SSLeay and
IO::Socket::SSL modules).

diff --git a/ssl.t b/ssl.t
--- a/ssl.t
+++ b/ssl.t
@@ -31,7 +31,7 @@ eval { IO::Socket::SSL::SSL_VERIFY_NONE(
 plan(skip_all => 'IO::Socket::SSL too old') if $@;
 
 my $t = Test::Nginx->new()->has(qw/http http_ssl rewrite proxy/)
-	->has_daemon('openssl')->plan(28);
+	->has_daemon('openssl')->plan(21);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -47,7 +47,6 @@ http {
 
     ssl_certificate_key localhost.key;
     ssl_certificate localhost.crt;
-    ssl_session_tickets off;
 
     log_format ssl $ssl_protocol;
 
@@ -59,6 +58,7 @@ http {
         ssl_certificate_key inner.key;
         ssl_certificate inner.crt;
         ssl_session_cache shared:SSL:1m;
+        ssl_session_tickets on;
         ssl_verify_client optional_no_ca;
 
         keepalive_requests 1000;
@@ -100,57 +100,11 @@ http {
     }
 
     server {
-        listen       127.0.0.1:8081;
-        server_name  localhost;
-
-        # Special case for enabled "ssl" directive.
-
-        ssl on;
-        ssl_session_cache builtin;
-
-        location / {
-            return 200 "body $ssl_session_reused";
-        }
-    }
-
-    server {
-        listen       127.0.0.1:8082 ssl;
-        server_name  localhost;
-
-        ssl_session_cache builtin:1000;
-
-        location / {
-            return 200 "body $ssl_session_reused";
-        }
-    }
-
-    server {
-        listen       127.0.0.1:8083 ssl;
-        server_name  localhost;
-
-        ssl_session_cache none;
-
-        location / {
-            return 200 "body $ssl_session_reused";
-        }
-    }
-
-    server {
-        listen       127.0.0.1:8084 ssl;
-        server_name  localhost;
-
-        ssl_session_cache off;
-
-        location / {
-            return 200 "body $ssl_session_reused";
-        }
-    }
-
-    server {
         listen       127.0.0.1:8086 ssl;
         server_name  localhost;
 
         ssl_session_cache shared:SSL:1m;
+        ssl_session_tickets on;
         ssl_session_timeout 1;
 
         location / {
@@ -216,59 +170,34 @@ foreach my $name ('localhost', 'inner') 
 		or die "Can't create certificate for $name: $!\n";
 }
 
-# suppress deprecation warning
-
-open OLDERR, ">&", \*STDERR; close STDERR;
 $t->run();
-open STDERR, ">&", \*OLDERR;
 
 ###############################################################################
 
-my $ctx;
+# ssl session reuse
 
-SKIP: {
-skip 'no TLS 1.3 sessions', 6 if get('/protocol', 8085) =~ /TLSv1.3/
-	&& ($Net::SSLeay::VERSION < 1.88 || $IO::Socket::SSL::VERSION < 2.061);
+my $ctx = get_ssl_context();
 
-$ctx = get_ssl_context();
+like(get('/', 8085, $ctx), qr/^body \.$/m, 'session');
 
-like(get('/', 8085, $ctx), qr/^body \.$/m, 'cache shared');
-like(get('/', 8085, $ctx), qr/^body r$/m, 'cache shared reused');
-
-$ctx = get_ssl_context();
+TODO: {
+local $TODO = 'no TLSv1.3 sessions, old Net::SSLeay'
+	if $Net::SSLeay::VERSION < 1.88 && test_tls13();
+local $TODO = 'no TLSv1.3 sessions, old IO::Socket::SSL'
+	if $IO::Socket::SSL::VERSION < 2.061 && test_tls13();
 
-like(get('/', 8081, $ctx), qr/^body \.$/m, 'cache builtin');
-like(get('/', 8081, $ctx), qr/^body r$/m, 'cache builtin reused');
-
-$ctx = get_ssl_context();
-
-like(get('/', 8082, $ctx), qr/^body \.$/m, 'cache builtin size');
-like(get('/', 8082, $ctx), qr/^body r$/m, 'cache builtin size reused');
+like(get('/', 8085, $ctx), qr/^body r$/m, 'session reused');
 
 }
 
-$ctx = get_ssl_context();
-
-like(get('/', 8083, $ctx), qr/^body \.$/m, 'cache none');
-like(get('/', 8083, $ctx), qr/^body \.$/m, 'cache none not reused');
-
-$ctx = get_ssl_context();
-
-like(get('/', 8084, $ctx), qr/^body \.$/m, 'cache off');
-like(get('/', 8084, $ctx), qr/^body \.$/m, 'cache off not reused');
-
 # ssl certificate inheritance
 
-my $s = get_ssl_socket(8081);
+my $s = get_ssl_socket(8086);
 like($s->dump_peer_certificate(), qr/CN=localhost/, 'CN');
 
-$s->close();
-
 $s = get_ssl_socket(8085);
 like($s->dump_peer_certificate(), qr/CN=inner/, 'CN inner');
 
-$s->close();
-
 # session timeout
 
 $ctx = get_ssl_context();
@@ -280,8 +209,12 @@ like(get('/', 8086, $ctx), qr/^body \.$/
 
 # embedded variables
 
-like(get('/id', 8085), qr/^body \w{64}$/m, 'session id');
+$ctx = get_ssl_context();
+like(get('/id', 8085, $ctx), qr/^body (\w{64})?$/m, 'session id');
+like(get('/id', 8085, $ctx), qr/^body \w{64}$/m, 'session id reused');
+
 unlike(http_get('/id'), qr/body \w/, 'session id no ssl');
+
 like(get('/cipher', 8085), qr/^body [\w-]+$/m, 'cipher');
 
 SKIP: {
@@ -334,6 +267,10 @@ like(`grep -F '[crit]' ${\($t->testdir()
 
 ###############################################################################
 
+sub test_tls13 {
+	return get('/protocol', 8085) =~ /TLSv1.3/;
+}
+
 sub get {
 	my ($uri, $port, $ctx) = @_;
 	my $s = get_ssl_socket($port, $ctx) or return;
diff --git a/ssl.t b/ssl_session_reuse.t
copy from ssl.t
copy to ssl_session_reuse.t
--- a/ssl.t
+++ b/ssl_session_reuse.t
@@ -1,10 +1,10 @@
 #!/usr/bin/perl
 
-# (C) Sergey Kandaurov
 # (C) Andrey Zelenkov
+# (C) Maxim Dounin
 # (C) Nginx, Inc.
 
-# Tests for http ssl module.
+# Tests for http ssl module, session reuse.
 
 ###############################################################################
 
@@ -13,8 +13,6 @@ use strict;
 
 use Test::More;
 
-use Socket qw/ CRLF /;
-
 BEGIN { use FindBin; chdir($FindBin::Bin); }
 
 use lib 'lib';
@@ -30,8 +28,8 @@ plan(skip_all => 'IO::Socket::SSL not in
 eval { IO::Socket::SSL::SSL_VERIFY_NONE(); };
 plan(skip_all => 'IO::Socket::SSL too old') if $@;
 
-my $t = Test::Nginx->new()->has(qw/http http_ssl rewrite proxy/)
-	->has_daemon('openssl')->plan(28);
+my $t = Test::Nginx->new()->has(qw/http http_ssl rewrite/)
+	->has_daemon('openssl')->plan(8);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -47,66 +45,37 @@ http {
 
     ssl_certificate_key localhost.key;
     ssl_certificate localhost.crt;
-    ssl_session_tickets off;
-
-    log_format ssl $ssl_protocol;
 
     server {
-        listen       127.0.0.1:8085 ssl;
-        listen       127.0.0.1:8080;
+        listen       127.0.0.1:8443 ssl;
         server_name  localhost;
 
-        ssl_certificate_key inner.key;
-        ssl_certificate inner.crt;
-        ssl_session_cache shared:SSL:1m;
-        ssl_verify_client optional_no_ca;
-
-        keepalive_requests 1000;
-
         location / {
             return 200 "body $ssl_session_reused";
         }
-        location /id {
-            return 200 "body $ssl_session_id";
-        }
-        location /cipher {
-            return 200 "body $ssl_cipher";
-        }
-        location /ciphers {
-            return 200 "body $ssl_ciphers";
-        }
-        location /client_verify {
-            return 200 "body $ssl_client_verify";
-        }
         location /protocol {
             return 200 "body $ssl_protocol";
         }
-        location /issuer {
-            return 200 "body $ssl_client_i_dn:$ssl_client_i_dn_legacy";
-        }
-        location /subject {
-            return 200 "body $ssl_client_s_dn:$ssl_client_s_dn_legacy";
-        }
-        location /time {
-            return 200 "body $ssl_client_v_start!$ssl_client_v_end!$ssl_client_v_remain";
-        }
-
-        location /body {
-            add_header X-Body $request_body always;
-            proxy_pass http://127.0.0.1:8080/;
-
-            access_log %%TESTDIR%%/ssl.log ssl;
-        }
     }
 
     server {
-        listen       127.0.0.1:8081;
+        listen       127.0.0.1:8444 ssl;
         server_name  localhost;
 
-        # Special case for enabled "ssl" directive.
+        ssl_session_cache shared:SSL:1m;
+        ssl_session_tickets on;
 
-        ssl on;
-        ssl_session_cache builtin;
+        location / {
+            return 200 "body $ssl_session_reused";
+        }
+    }
+
+    server {
+        listen       127.0.0.1:8445 ssl;
+        server_name  localhost;
+
+        ssl_session_cache shared:SSL:1m;
+        ssl_session_tickets off;
 
         location / {
             return 200 "body $ssl_session_reused";
@@ -114,10 +83,11 @@ http {
     }
 
     server {
-        listen       127.0.0.1:8082 ssl;
+        listen       127.0.0.1:8446 ssl;
         server_name  localhost;
 
-        ssl_session_cache builtin:1000;
+        ssl_session_cache builtin;
+        ssl_session_tickets off;
 
         location / {
             return 200 "body $ssl_session_reused";
@@ -125,10 +95,11 @@ http {
     }
 
     server {
-        listen       127.0.0.1:8083 ssl;
+        listen       127.0.0.1:8447 ssl;
         server_name  localhost;
 
-        ssl_session_cache none;
+        ssl_session_cache builtin:1000;
+        ssl_session_tickets off;
 
         location / {
             return 200 "body $ssl_session_reused";
@@ -136,10 +107,11 @@ http {
     }
 
     server {
-        listen       127.0.0.1:8084 ssl;
+        listen       127.0.0.1:8448 ssl;
         server_name  localhost;
 
-        ssl_session_cache off;
+        ssl_session_cache none;
+        ssl_session_tickets off;
 
         location / {
             return 200 "body $ssl_session_reused";
@@ -147,11 +119,11 @@ http {
     }
 
     server {
-        listen       127.0.0.1:8086 ssl;
+        listen       127.0.0.1:8449 ssl;
         server_name  localhost;
 
-        ssl_session_cache shared:SSL:1m;
-        ssl_session_timeout 1;
+        ssl_session_cache off;
+        ssl_session_tickets off;
 
         location / {
             return 200 "body $ssl_session_reused";
@@ -171,44 +143,7 @@ EOF
 
 my $d = $t->testdir();
 
-$t->write_file('ca.conf', <<EOF);
-[ ca ]
-default_ca = myca
-
-[ myca ]
-new_certs_dir = $d
-database = $d/certindex
-default_md = sha256
-policy = myca_policy
-serial = $d/certserial
-default_days = 3
-
-[ myca_policy ]
-commonName = supplied
-EOF
-
-$t->write_file('certserial', '1000');
-$t->write_file('certindex', '');
-
-system('openssl req -x509 -new '
-	. "-config $d/openssl.conf -subj /CN=issuer/ "
-	. "-out $d/issuer.crt -keyout $d/issuer.key "
-	. ">>$d/openssl.out 2>&1") == 0
-	or die "Can't create certificate for issuer: $!\n";
-
-system("openssl req -new "
-	. "-config $d/openssl.conf -subj /CN=subject/ "
-	. "-out $d/subject.csr -keyout $d/subject.key "
-	. ">>$d/openssl.out 2>&1") == 0
-	or die "Can't create certificate for subject: $!\n";
-
-system("openssl ca -batch -config $d/ca.conf "
-	. "-keyfile $d/issuer.key -cert $d/issuer.crt "
-	. "-subj /CN=subject/ -in $d/subject.csr -out $d/subject.crt "
-	. ">>$d/openssl.out 2>&1") == 0
-	or die "Can't sign certificate for subject: $!\n";
-
-foreach my $name ('localhost', 'inner') {
+foreach my $name ('localhost') {
 	system('openssl req -x509 -new '
 		. "-config $d/openssl.conf -subj /CN=$name/ "
 		. "-out $d/$name.crt -keyout $d/$name.key "
@@ -216,124 +151,54 @@ foreach my $name ('localhost', 'inner') 
 		or die "Can't create certificate for $name: $!\n";
 }
 
-# suppress deprecation warning
-
-open OLDERR, ">&", \*STDERR; close STDERR;
 $t->run();
-open STDERR, ">&", \*OLDERR;
 
 ###############################################################################
 
-my $ctx;
-
-SKIP: {
-skip 'no TLS 1.3 sessions', 6 if get('/protocol', 8085) =~ /TLSv1.3/
-	&& ($Net::SSLeay::VERSION < 1.88 || $IO::Socket::SSL::VERSION < 2.061);
-
-$ctx = get_ssl_context();
+# session reuse:
+#
+# - only tickets, the default
+# - tickets and shared cache, should work always
+# - only shared cache
+# - only builtin cache
+# - only builtin cache with explicitly configured size
+# - only cache none
+# - only cache off
 
-like(get('/', 8085, $ctx), qr/^body \.$/m, 'cache shared');
-like(get('/', 8085, $ctx), qr/^body r$/m, 'cache shared reused');
-
-$ctx = get_ssl_context();
+TODO: {
+local $TODO = 'no TLSv1.3 sessions, old Net::SSLeay'
+	if $Net::SSLeay::VERSION < 1.88 && test_tls13();
+local $TODO = 'no TLSv1.3 sessions, old IO::Socket::SSL'
+	if $IO::Socket::SSL::VERSION < 2.061 && test_tls13();
 
-like(get('/', 8081, $ctx), qr/^body \.$/m, 'cache builtin');
-like(get('/', 8081, $ctx), qr/^body r$/m, 'cache builtin reused');
-
-$ctx = get_ssl_context();
-
-like(get('/', 8082, $ctx), qr/^body \.$/m, 'cache builtin size');
-like(get('/', 8082, $ctx), qr/^body r$/m, 'cache builtin size reused');
+is(test_reuse(8443), 1, 'tickets reused');
+is(test_reuse(8444), 1, 'tickets and cache reused');
+is(test_reuse(8445), 1, 'cache shared reused');
+is(test_reuse(8446), 1, 'cache builtin reused');
+is(test_reuse(8447), 1, 'cache builtin size reused');
 
 }
 
-$ctx = get_ssl_context();
-
-like(get('/', 8083, $ctx), qr/^body \.$/m, 'cache none');
-like(get('/', 8083, $ctx), qr/^body \.$/m, 'cache none not reused');
-
-$ctx = get_ssl_context();
-
-like(get('/', 8084, $ctx), qr/^body \.$/m, 'cache off');
-like(get('/', 8084, $ctx), qr/^body \.$/m, 'cache off not reused');
-
-# ssl certificate inheritance
-
-my $s = get_ssl_socket(8081);
-like($s->dump_peer_certificate(), qr/CN=localhost/, 'CN');
-
-$s->close();
-
-$s = get_ssl_socket(8085);
-like($s->dump_peer_certificate(), qr/CN=inner/, 'CN inner');
-
-$s->close();
-
-# session timeout
-
-$ctx = get_ssl_context();
-
-get('/', 8086, $ctx);
-select undef, undef, undef, 2.1;
-
-like(get('/', 8086, $ctx), qr/^body \.$/m, 'session timeout');
-
-# embedded variables
-
-like(get('/id', 8085), qr/^body \w{64}$/m, 'session id');
-unlike(http_get('/id'), qr/body \w/, 'session id no ssl');
-like(get('/cipher', 8085), qr/^body [\w-]+$/m, 'cipher');
-
-SKIP: {
-skip 'BoringSSL', 1 if $t->has_module('BoringSSL');
-
-like(get('/ciphers', 8085), qr/^body [:\w-]+$/m, 'ciphers');
-
-}
-
-like(get('/client_verify', 8085), qr/^body NONE$/m, 'client verify');
-like(get('/protocol', 8085), qr/^body (TLS|SSL)v(\d|\.)+$/m, 'protocol');
-like(cert('/issuer', 8085), qr!^body CN=issuer:/CN=issuer$!m, 'issuer');
-like(cert('/subject', 8085), qr!^body CN=subject:/CN=subject$!m, 'subject');
-like(cert('/time', 8085), qr/^body [:\s\w]+![:\s\w]+![23]$/m, 'time');
-
-# c->read->ready handling bug in ngx_ssl_recv(), triggered with chunked body
-
-like(get_body('/body', '0123456789', 20, 5), qr/X-Body: (0123456789){100}/,
-	'request body chunked');
-
-# pipelined requests
-
-$s = get_ssl_socket(8085);
-my $req = <<EOF;
-GET / HTTP/1.1
-Host: localhost
-
-EOF
-
-$req x= 1000;
-
-my $r = http($req, socket => $s) || "";
-$s = undef;
-is(() = $r =~ /(200 OK)/g, 1000, 'pipelined requests');
-
-# OpenSSL 3.0 error "unexpected eof while reading" seen as a critical error
-
-ok(get_ssl_socket(8085), 'ssl unexpected eof');
-
-# close_notify is sent before lingering close
-
-is(get_ssl_shutdown(8085), 1, 'ssl shutdown on lingering close');
+is(test_reuse(8448), 0, 'cache none not reused');
+is(test_reuse(8449), 0, 'cache off not reused');
 
 $t->stop();
 
-like($t->read_file('ssl.log'), qr/^(TLS|SSL)v(\d|\.)+$/m,
-	'log ssl variable on lingering close');
-
 like(`grep -F '[crit]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no crit');
 
 ###############################################################################
 
+sub test_tls13 {
+	return get('/protocol', 8443) =~ /TLSv1.3/;
+}
+
+sub test_reuse {
+	my ($port) = @_;
+	my $ctx = get_ssl_context();
+	get('/', $port, $ctx);
+	return (get('/', $port, $ctx) =~ qr/^body r$/m) ? 1 : 0;
+}
+
 sub get {
 	my ($uri, $port, $ctx) = @_;
 	my $s = get_ssl_socket($port, $ctx) or return;
@@ -342,30 +207,6 @@ sub get {
 	return $r;
 }
 
-sub get_body {
-	my ($uri, $body, $len, $n) = @_;
-	my $s = get_ssl_socket(8085) or return;
-	http("GET /body HTTP/1.1" . CRLF
-		. "Host: localhost" . CRLF
-		. "Connection: close" . CRLF
-		. "Transfer-Encoding: chunked" . CRLF . CRLF,
-		socket => $s, start => 1);
-	my $chs = unpack("H*", pack("C", length($body) * $len));
-	http($chs . CRLF . $body x $len . CRLF, socket => $s, start => 1)
-		for 1 .. $n;
-	my $r = http("0" . CRLF . CRLF, socket => $s);
-	$s->close();
-	return $r;
-}
-
-sub cert {
-	my ($uri, $port) = @_;
-	my $s = get_ssl_socket($port, undef,
-		SSL_cert_file => "$d/subject.crt",
-		SSL_key_file => "$d/subject.key") or return;
-	http_get($uri, socket => $s);
-}
-
 sub get_ssl_context {
 	return IO::Socket::SSL::SSL_Context->new(
 		SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
@@ -402,18 +243,4 @@ sub get_ssl_socket {
 	return $s;
 }
 
-sub get_ssl_shutdown {
-	my ($port) = @_;
-
-	my $s = IO::Socket::INET->new('127.0.0.1:' . port($port));
-	my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!");
-	my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!");
-	Net::SSLeay::set_fd($ssl, fileno($s));
-	Net::SSLeay::connect($ssl) or die("ssl connect");
-	Net::SSLeay::write($ssl, 'GET /' . CRLF . 'extra');
-	Net::SSLeay::read($ssl);
-	Net::SSLeay::set_shutdown($ssl, 1);
-	Net::SSLeay::shutdown($ssl);
-}
-
 ###############################################################################
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679518794 -10800
#      Wed Mar 22 23:59:54 2023 +0300
# Node ID 670dec53c4cd9ad2f64ff09d9094c44d49998726
# Parent  8fb46a1a0f3e6ca94e2c59ce50e3043a67cde674
Tests: LibreSSL and BoringSSL session reuse with TLSv1.3.

LibreSSL does not support session reuse with TLSv1.3 at all.  BoringSSL
with TLSv1.3 only supports session tickets, but not server-side session
cache.

diff --git a/ssl.t b/ssl.t
--- a/ssl.t
+++ b/ssl.t
@@ -185,6 +185,8 @@ local $TODO = 'no TLSv1.3 sessions, old 
 	if $Net::SSLeay::VERSION < 1.88 && test_tls13();
 local $TODO = 'no TLSv1.3 sessions, old IO::Socket::SSL'
 	if $IO::Socket::SSL::VERSION < 2.061 && test_tls13();
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
 
 like(get('/', 8085, $ctx), qr/^body r$/m, 'session reused');
 
@@ -211,8 +213,17 @@ like(get('/', 8086, $ctx), qr/^body \.$/
 
 $ctx = get_ssl_context();
 like(get('/id', 8085, $ctx), qr/^body (\w{64})?$/m, 'session id');
+
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
+local $TODO = 'no TLSv1.3 sessions ids in BoringSSL'
+	if $t->has_module('BoringSSL') && test_tls13();
+
 like(get('/id', 8085, $ctx), qr/^body \w{64}$/m, 'session id reused');
 
+}
+
 unlike(http_get('/id'), qr/body \w/, 'session id no ssl');
 
 like(get('/cipher', 8085), qr/^body [\w-]+$/m, 'cipher');
diff --git a/ssl_session_reuse.t b/ssl_session_reuse.t
--- a/ssl_session_reuse.t
+++ b/ssl_session_reuse.t
@@ -170,14 +170,22 @@ local $TODO = 'no TLSv1.3 sessions, old 
 	if $Net::SSLeay::VERSION < 1.88 && test_tls13();
 local $TODO = 'no TLSv1.3 sessions, old IO::Socket::SSL'
 	if $IO::Socket::SSL::VERSION < 2.061 && test_tls13();
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
 
 is(test_reuse(8443), 1, 'tickets reused');
 is(test_reuse(8444), 1, 'tickets and cache reused');
+
+TODO: {
+local $TODO = 'no TLSv1.3 session cache in BoringSSL'
+	if $t->has_module('BoringSSL') && test_tls13();
+
 is(test_reuse(8445), 1, 'cache shared reused');
 is(test_reuse(8446), 1, 'cache builtin reused');
 is(test_reuse(8447), 1, 'cache builtin size reused');
 
 }
+}
 
 is(test_reuse(8448), 0, 'cache none not reused');
 is(test_reuse(8449), 0, 'cache off not reused');
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527437 -10800
#      Thu Mar 23 02:23:57 2023 +0300
# Node ID ebef8c3ce0aee7886826da353e285c430ce949cd
# Parent  670dec53c4cd9ad2f64ff09d9094c44d49998726
Tests: separate SSL session reuse tests in mail.

Instead of being mixed with generic SSL tests, session reuse variants
are now tested in a separate file.

diff --git a/mail_ssl.t b/mail_ssl.t
--- a/mail_ssl.t
+++ b/mail_ssl.t
@@ -37,7 +37,7 @@ eval { exists &Net::SSLeay::P_alpn_selec
 plan(skip_all => 'Net::SSLeay with OpenSSL ALPN support required') if $@;
 
 my $t = Test::Nginx->new()->has(qw/mail mail_ssl imap pop3 smtp/)
-	->has_daemon('openssl')->plan(22);
+	->has_daemon('openssl')->plan(18);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -51,44 +51,25 @@ events {
 mail {
     ssl_certificate_key localhost.key;
     ssl_certificate localhost.crt;
-    ssl_session_tickets off;
 
     ssl_password_file password;
 
     auth_http  http://127.0.0.1:8080;	# unused
 
-    ssl_session_cache none;
-
     server {
         listen             127.0.0.1:8143;
         listen             127.0.0.1:8145 ssl;
         protocol           imap;
-
-        ssl_session_cache  builtin;
     }
 
     server {
-        listen             127.0.0.1:8146 ssl;
-        protocol           imap;
-
-        ssl_session_cache  off;
-    }
-
-    server {
-        listen             127.0.0.1:8147;
+        listen             127.0.0.1:8148;
         protocol           imap;
 
         # Special case for enabled "ssl" directive.
 
         ssl on;
-        ssl_session_cache  builtin:1000;
-    }
 
-    server {
-        listen             127.0.0.1:8148 ssl;
-        protocol           imap;
-
-        ssl_session_cache shared:SSL:1m;
         ssl_certificate_key inherits.key;
         ssl_certificate inherits.crt;
     }
@@ -169,46 +150,16 @@ open STDERR, ">&", \*OLDERR;
 
 ###############################################################################
 
+my ($s, $ssl);
+
 # simple tests to ensure that nothing broke with ssl_password_file directive
 
-my $s = Test::Nginx::IMAP->new();
+$s = Test::Nginx::IMAP->new();
 $s->ok('greeting');
 
 $s->send('1 AUTHENTICATE LOGIN');
 $s->check(qr/\+ VXNlcm5hbWU6/, 'login');
 
-# ssl_session_cache
-
-my ($ssl, $ses);
-
-($s, $ssl) = get_ssl_socket(8145);
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(8145, $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'builtin session reused');
-
-($s, $ssl) = get_ssl_socket(8146);
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(8146, $ses);
-is(Net::SSLeay::session_reused($ssl), 0, 'session not reused');
-
-($s, $ssl) = get_ssl_socket(8147);
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(8147, $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'builtin size session reused');
-
-($s, $ssl) = get_ssl_socket(8148);
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(8148, $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'shared session reused');
-
 # ssl_certificate inheritance
 
 ($s, $ssl) = get_ssl_socket(8145);
@@ -219,7 +170,7 @@ like(Net::SSLeay::dump_peer_certificate(
 
 # alpn
 
-ok(get_ssl_socket(8148, undef, ['imap']), 'alpn');
+ok(get_ssl_socket(8148, ['imap']), 'alpn');
 
 SKIP: {
 $t->{_configure_args} =~ /LibreSSL ([\d\.]+)/;
@@ -230,7 +181,7 @@ skip 'OpenSSL too old', 1 if defined $1 
 TODO: {
 local $TODO = 'not yet' unless $t->has_version('1.21.4');
 
-ok(!get_ssl_socket(8148, undef, ['unknown']), 'alpn rejected');
+ok(!get_ssl_socket(8148, ['unknown']), 'alpn rejected');
 
 }
 
@@ -317,11 +268,10 @@ ok(!get_ssl_socket(8148, undef, ['unknow
 ###############################################################################
 
 sub get_ssl_socket {
-	my ($port, $ses, $alpn) = @_;
+	my ($port, $alpn) = @_;
 
 	my $s = IO::Socket::INET->new('127.0.0.1:' . port($port));
 	my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!");
-	Net::SSLeay::set_session($ssl, $ses) if defined $ses;
 	Net::SSLeay::set_alpn_protos($ssl, $alpn) if defined $alpn;
 	Net::SSLeay::set_fd($ssl, fileno($s));
 	Net::SSLeay::connect($ssl) == 1 or return;
diff --git a/mail_ssl.t b/mail_ssl_session_reuse.t
copy from mail_ssl.t
copy to mail_ssl_session_reuse.t
--- a/mail_ssl.t
+++ b/mail_ssl_session_reuse.t
@@ -1,9 +1,10 @@
 #!/usr/bin/perl
 
 # (C) Andrey Zelenkov
+# (C) Maxim Dounin
 # (C) Nginx, Inc.
 
-# Tests for mail ssl module.
+# Tests for mail ssl module, session reuse.
 
 ###############################################################################
 
@@ -16,9 +17,6 @@ BEGIN { use FindBin; chdir($FindBin::Bin
 
 use lib 'lib';
 use Test::Nginx;
-use Test::Nginx::IMAP;
-use Test::Nginx::POP3;
-use Test::Nginx::SMTP;
 
 ###############################################################################
 
@@ -33,11 +31,8 @@ eval {
 };
 plan(skip_all => 'Net::SSLeay not installed') if $@;
 
-eval { exists &Net::SSLeay::P_alpn_selected or die; };
-plan(skip_all => 'Net::SSLeay with OpenSSL ALPN support required') if $@;
-
-my $t = Test::Nginx->new()->has(qw/mail mail_ssl imap pop3 smtp/)
-	->has_daemon('openssl')->plan(22);
+my $t = Test::Nginx->new()->has(qw/mail mail_ssl imap/)
+	->has_daemon('openssl')->plan(7);
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -49,90 +44,62 @@ events {
 }
 
 mail {
-    ssl_certificate_key localhost.key;
-    ssl_certificate localhost.crt;
-    ssl_session_tickets off;
+    auth_http  http://127.0.0.1:8080;
 
-    ssl_password_file password;
-
-    auth_http  http://127.0.0.1:8080;	# unused
-
-    ssl_session_cache none;
+    ssl_certificate localhost.crt;
+    ssl_certificate_key localhost.key;
 
     server {
-        listen             127.0.0.1:8143;
-        listen             127.0.0.1:8145 ssl;
-        protocol           imap;
-
-        ssl_session_cache  builtin;
+        listen    127.0.0.1:8993 ssl;
+        protocol  imap;
     }
 
     server {
-        listen             127.0.0.1:8146 ssl;
-        protocol           imap;
+        listen    127.0.0.1:8994 ssl;
+        protocol  imap;
 
-        ssl_session_cache  off;
+        ssl_session_cache shared:SSL:1m;
+        ssl_session_tickets on;
     }
 
     server {
-        listen             127.0.0.1:8147;
-        protocol           imap;
+        listen    127.0.0.1:8995 ssl;
+        protocol  imap;
 
-        # Special case for enabled "ssl" directive.
-
-        ssl on;
-        ssl_session_cache  builtin:1000;
+        ssl_session_cache shared:SSL:1m;
+        ssl_session_tickets off;
     }
 
     server {
-        listen             127.0.0.1:8148 ssl;
-        protocol           imap;
-
-        ssl_session_cache shared:SSL:1m;
-        ssl_certificate_key inherits.key;
-        ssl_certificate inherits.crt;
-    }
+        listen    127.0.0.1:8996 ssl;
+        protocol  imap;
 
-    server {
-        listen             127.0.0.1:8149;
-        protocol           imap;
-
-        starttls           on;
-    }
-
-    server {
-        listen             127.0.0.1:8150;
-        protocol           imap;
-
-        starttls           only;
+        ssl_session_cache builtin;
+        ssl_session_tickets off;
     }
 
     server {
-        listen             127.0.0.1:8151;
-        protocol           pop3;
+        listen    127.0.0.1:8997 ssl;
+        protocol  imap;
 
-        starttls           on;
+        ssl_session_cache builtin:1000;
+        ssl_session_tickets off;
     }
 
     server {
-        listen             127.0.0.1:8152;
-        protocol           pop3;
+        listen    127.0.0.1:8998 ssl;
+        protocol  imap;
 
-        starttls           only;
+        ssl_session_cache none;
+        ssl_session_tickets off;
     }
 
     server {
-        listen             127.0.0.1:8153;
-        protocol           smtp;
-
-        starttls           on;
-    }
+        listen    127.0.0.1:8999 ssl;
+        protocol  imap;
 
-    server {
-        listen             127.0.0.1:8154;
-        protocol           smtp;
-
-        starttls           only;
+        ssl_session_cache off;
+        ssl_session_tickets off;
     }
 }
 
@@ -148,181 +115,55 @@ EOF
 
 my $d = $t->testdir();
 
-foreach my $name ('localhost', 'inherits') {
-	system("openssl genrsa -out $d/$name.key -passout pass:localhost "
-		. "-aes128 2048 >>$d/openssl.out 2>&1") == 0
-		or die "Can't create private key: $!\n";
+foreach my $name ('localhost') {
 	system('openssl req -x509 -new '
 		. "-config $d/openssl.conf -subj /CN=$name/ "
-		. "-out $d/$name.crt "
-		. "-key $d/$name.key -passin pass:localhost"
+		. "-out $d/$name.crt -keyout $d/$name.key "
 		. ">>$d/openssl.out 2>&1") == 0
 		or die "Can't create certificate for $name: $!\n";
 }
 
 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!");
-$t->write_file('password', 'localhost');
 
-open OLDERR, ">&", \*STDERR; close STDERR;
 $t->run();
-open STDERR, ">&", \*OLDERR;
 
 ###############################################################################
 
-# simple tests to ensure that nothing broke with ssl_password_file directive
-
-my $s = Test::Nginx::IMAP->new();
-$s->ok('greeting');
-
-$s->send('1 AUTHENTICATE LOGIN');
-$s->check(qr/\+ VXNlcm5hbWU6/, 'login');
-
-# ssl_session_cache
-
-my ($ssl, $ses);
-
-($s, $ssl) = get_ssl_socket(8145);
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(8145, $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'builtin session reused');
-
-($s, $ssl) = get_ssl_socket(8146);
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(8146, $ses);
-is(Net::SSLeay::session_reused($ssl), 0, 'session not reused');
-
-($s, $ssl) = get_ssl_socket(8147);
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(8147, $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'builtin size session reused');
-
-($s, $ssl) = get_ssl_socket(8148);
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(8148, $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'shared session reused');
-
-# ssl_certificate inheritance
-
-($s, $ssl) = get_ssl_socket(8145);
-like(Net::SSLeay::dump_peer_certificate($ssl), qr/CN=localhost/, 'CN');
-
-($s, $ssl) = get_ssl_socket(8148);
-like(Net::SSLeay::dump_peer_certificate($ssl), qr/CN=inherits/, 'CN inner');
-
-# alpn
-
-ok(get_ssl_socket(8148, undef, ['imap']), 'alpn');
-
-SKIP: {
-$t->{_configure_args} =~ /LibreSSL ([\d\.]+)/;
-skip 'LibreSSL too old', 1 if defined $1 and $1 lt '3.4.0';
-$t->{_configure_args} =~ /OpenSSL ([\d\.]+)/;
-skip 'OpenSSL too old', 1 if defined $1 and $1 lt '1.1.0';
-
-TODO: {
-local $TODO = 'not yet' unless $t->has_version('1.21.4');
-
-ok(!get_ssl_socket(8148, undef, ['unknown']), 'alpn rejected');
-
-}
-
-}
-
-# starttls imap
-
-$s = Test::Nginx::IMAP->new(PeerAddr => '127.0.0.1:' . port(8149));
-$s->read();
+# session reuse:
+#
+# - only tickets, the default
+# - tickets and shared cache, should work always
+# - only shared cache
+# - only builtin cache
+# - only builtin cache with explicitly configured size
+# - only cache none
+# - only cache off
 
-$s->send('1 AUTHENTICATE LOGIN');
-$s->check(qr/\+ VXNlcm5hbWU6/, 'imap auth before startls on');
-
-$s = Test::Nginx::IMAP->new(PeerAddr => '127.0.0.1:' . port(8149));
-$s->read();
-
-$s->send('1 STARTTLS');
-$s->ok('imap starttls on');
-
-$s = Test::Nginx::IMAP->new(PeerAddr => '127.0.0.1:' . port(8150));
-$s->read();
-
-$s->send('1 AUTHENTICATE LOGIN');
-$s->check(qr/^\S+ BAD/, 'imap auth before startls only');
-
-$s = Test::Nginx::IMAP->new(PeerAddr => '127.0.0.1:' . port(8150));
-$s->read();
-
-$s->send('1 STARTTLS');
-$s->ok('imap starttls only');
-
-# starttls pop3
-
-$s = Test::Nginx::POP3->new(PeerAddr => '127.0.0.1:' . port(8151));
-$s->read();
-
-$s->send('AUTH LOGIN');
-$s->check(qr/\+ VXNlcm5hbWU6/, 'pop3 auth before startls on');
-
-$s = Test::Nginx::POP3->new(PeerAddr => '127.0.0.1:' . port(8151));
-$s->read();
-
-$s->send('STLS');
-$s->ok('pop3 starttls on');
-
-$s = Test::Nginx::POP3->new(PeerAddr => '127.0.0.1:' . port(8152));
-$s->read();
-
-$s->send('AUTH LOGIN');
-$s->check(qr/^-ERR/, 'pop3 auth before startls only');
-
-$s = Test::Nginx::POP3->new(PeerAddr => '127.0.0.1:' . port(8152));
-$s->read();
-
-$s->send('STLS');
-$s->ok('pop3 starttls only');
-
-# starttls smtp
-
-$s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8153));
-$s->read();
-
-$s->send('AUTH LOGIN');
-$s->check(qr/^334 VXNlcm5hbWU6/, 'smtp auth before startls on');
-
-$s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8153));
-$s->read();
-
-$s->send('STARTTLS');
-$s->ok('smtp starttls on');
-
-$s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8154));
-$s->read();
-
-$s->send('AUTH LOGIN');
-$s->check(qr/^5.. /, 'smtp auth before startls only');
-
-$s = Test::Nginx::SMTP->new(PeerAddr => '127.0.0.1:' . port(8154));
-$s->read();
-
-$s->send('STARTTLS');
-$s->ok('smtp starttls only');
+is(test_reuse(8993), 1, 'tickets reused');
+is(test_reuse(8994), 1, 'tickets and cache reused');
+is(test_reuse(8995), 1, 'cache shared reused');
+is(test_reuse(8996), 1, 'cache builtin reused');
+is(test_reuse(8997), 1, 'cache builtin size reused');
+is(test_reuse(8998), 0, 'cache none not reused');
+is(test_reuse(8999), 0, 'cache off not reused');
 
 ###############################################################################
 
+sub test_reuse {
+	my ($port) = @_;
+	my ($s, $ssl) = get_ssl_socket($port);
+	Net::SSLeay::read($ssl);
+	my $ses = Net::SSLeay::get_session($ssl);
+	($s, $ssl) = get_ssl_socket($port, $ses);
+	return Net::SSLeay::session_reused($ssl);
+}
+
 sub get_ssl_socket {
-	my ($port, $ses, $alpn) = @_;
+	my ($port, $ses) = @_;
 
 	my $s = IO::Socket::INET->new('127.0.0.1:' . port($port));
 	my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!");
 	Net::SSLeay::set_session($ssl, $ses) if defined $ses;
-	Net::SSLeay::set_alpn_protos($ssl, $alpn) if defined $alpn;
 	Net::SSLeay::set_fd($ssl, fileno($s));
 	Net::SSLeay::connect($ssl) == 1 or return;
 	return ($s, $ssl);
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID 28de0345b5cf67a4956a84a8adcbd1c59078ea9e
# Parent  ebef8c3ce0aee7886826da353e285c430ce949cd
Tests: LibreSSL and BoringSSL session reuse with TLSv1.3 in mail.

LibreSSL does not support session reuse with TLSv1.3 at all.  BoringSSL
with TLSv1.3 only supports session tickets, but not server-side session
cache.

diff --git a/mail_ssl_session_reuse.t b/mail_ssl_session_reuse.t
--- a/mail_ssl_session_reuse.t
+++ b/mail_ssl_session_reuse.t
@@ -139,16 +139,34 @@ my $ctx = Net::SSLeay::CTX_new() or die(
 # - only cache none
 # - only cache off
 
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
+
 is(test_reuse(8993), 1, 'tickets reused');
 is(test_reuse(8994), 1, 'tickets and cache reused');
+
+TODO: {
+local $TODO = 'no TLSv1.3 session cache in BoringSSL'
+	if $t->has_module('BoringSSL') && test_tls13();
+
 is(test_reuse(8995), 1, 'cache shared reused');
 is(test_reuse(8996), 1, 'cache builtin reused');
 is(test_reuse(8997), 1, 'cache builtin size reused');
+
+}
+}
+
 is(test_reuse(8998), 0, 'cache none not reused');
 is(test_reuse(8999), 0, 'cache off not reused');
 
 ###############################################################################
 
+sub test_tls13 {
+	my ($s, $ssl) = get_ssl_socket(8993);
+	return (Net::SSLeay::version($ssl) > 0x303);
+}
+
 sub test_reuse {
 	my ($port) = @_;
 	my ($s, $ssl) = get_ssl_socket($port);
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID 376c1b24119098b673c5ba1b1b7f09ad7d5511fd
# Parent  28de0345b5cf67a4956a84a8adcbd1c59078ea9e
Tests: separate SSL session reuse tests in stream.

Instead of being mixed with generic SSL tests, session reuse variants
are now tested in a separate file.

diff --git a/stream_ssl.t b/stream_ssl.t
--- a/stream_ssl.t
+++ b/stream_ssl.t
@@ -37,7 +37,7 @@ plan(skip_all => 'win32') if $^O eq 'MSW
 
 my $t = Test::Nginx->new()->has(qw/stream stream_ssl/)->has_daemon('openssl');
 
-$t->plan(7)->write_file_expand('nginx.conf', <<'EOF');
+$t->plan(5)->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
 
@@ -51,40 +51,35 @@ stream {
 
     ssl_certificate_key localhost.key;
     ssl_certificate localhost.crt;
-    ssl_session_tickets off;
 
     # inherited by server "inherits"
     ssl_password_file password_stream;
 
     server {
-        listen      127.0.0.1:8080 ssl;
+        listen      127.0.0.1:8443 ssl;
         proxy_pass  127.0.0.1:8081;
 
-        ssl_session_cache builtin;
         ssl_password_file password;
     }
 
     server {
-        listen      127.0.0.1:8082 ssl;
+        listen      127.0.0.1:8444 ssl;
         proxy_pass  127.0.0.1:8081;
 
-        ssl_session_cache off;
         ssl_password_file password_many;
     }
 
     server {
-        listen      127.0.0.1:8083 ssl;
+        listen      127.0.0.1:8445 ssl;
         proxy_pass  127.0.0.1:8081;
 
-        ssl_session_cache builtin:1000;
         ssl_password_file password_fifo;
     }
 
     server {
-        listen      127.0.0.1:8084 ssl;
+        listen      127.0.0.1:8446 ssl;
         proxy_pass  127.0.0.1:8081;
 
-        ssl_session_cache shared:SSL:1m;
         ssl_certificate_key inherits.key;
         ssl_certificate inherits.crt;
     }
@@ -115,7 +110,6 @@ foreach my $name ('localhost', 'inherits
 		or die "Can't create certificate for $name: $!\n";
 }
 
-
 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!");
 
 $t->write_file('password', 'localhost');
@@ -138,62 +132,35 @@ kill 'INT', $p if $@;
 
 ###############################################################################
 
-my ($s, $ssl, $ses);
+my ($s, $ssl);
 
-($s, $ssl) = get_ssl_socket(port(8080));
+($s, $ssl) = get_ssl_socket(8443);
 Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
 like(Net::SSLeay::read($ssl), qr/200 OK/, 'ssl');
 
-# ssl_session_cache
-
-($s, $ssl) = get_ssl_socket(port(8080));
+($s, $ssl) = get_ssl_socket(8444);
 Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(port(8080), $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'builtin session reused');
-
-($s, $ssl) = get_ssl_socket(port(8082));
-Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
+like(Net::SSLeay::read($ssl), qr/200 OK/, 'ssl password many');
 
-($s, $ssl) = get_ssl_socket(port(8082), $ses);
-isnt(Net::SSLeay::session_reused($ssl), 1, 'session not reused');
-
-($s, $ssl) = get_ssl_socket(port(8083));
+($s, $ssl) = get_ssl_socket(8445);
 Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(port(8083), $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'builtin size session reused');
-
-($s, $ssl) = get_ssl_socket(port(8084));
-Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(port(8084), $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'shared session reused');
+like(Net::SSLeay::read($ssl), qr/200 OK/, 'ssl password fifo');
 
 # ssl_certificate inheritance
 
-($s, $ssl) = get_ssl_socket(port(8080));
+($s, $ssl) = get_ssl_socket(8443);
 like(Net::SSLeay::dump_peer_certificate($ssl), qr/CN=localhost/, 'CN');
 
-($s, $ssl) = get_ssl_socket(port(8084));
+($s, $ssl) = get_ssl_socket(8446);
 like(Net::SSLeay::dump_peer_certificate($ssl), qr/CN=inherits/, 'CN inner');
 
 ###############################################################################
 
 sub get_ssl_socket {
-	my ($port, $ses) = @_;
+	my ($port) = @_;
 
-	my $s = IO::Socket::INET->new('127.0.0.1:' . $port);
+	my $s = IO::Socket::INET->new('127.0.0.1:' . port($port));
 	my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!");
-	Net::SSLeay::set_session($ssl, $ses) if defined $ses;
 	Net::SSLeay::set_fd($ssl, fileno($s));
 	Net::SSLeay::connect($ssl) or die("ssl connect");
 	return ($s, $ssl);
diff --git a/stream_ssl.t b/stream_ssl_session_reuse.t
copy from stream_ssl.t
copy to stream_ssl_session_reuse.t
--- a/stream_ssl.t
+++ b/stream_ssl_session_reuse.t
@@ -1,9 +1,10 @@
 #!/usr/bin/perl
 
 # (C) Sergey Kandaurov
+# (C) Maxim Dounin
 # (C) Nginx, Inc.
 
-# Tests for stream ssl module.
+# Tests for stream ssl module, session reuse.
 
 ###############################################################################
 
@@ -12,7 +13,6 @@ use strict;
 
 use Test::More;
 
-use POSIX qw/ mkfifo /;
 use Socket qw/ $CRLF /;
 
 BEGIN { use FindBin; chdir($FindBin::Bin); }
@@ -33,8 +33,6 @@ eval {
 };
 plan(skip_all => 'Net::SSLeay not installed') if $@;
 
-plan(skip_all => 'win32') if $^O eq 'MSWin32';
-
 my $t = Test::Nginx->new()->has(qw/stream stream_ssl/)->has_daemon('openssl');
 
 $t->plan(7)->write_file_expand('nginx.conf', <<'EOF');
@@ -49,44 +47,60 @@ events {
 stream {
     %%TEST_GLOBALS_STREAM%%
 
+    ssl_certificate localhost.crt;
     ssl_certificate_key localhost.key;
-    ssl_certificate localhost.crt;
-    ssl_session_tickets off;
 
-    # inherited by server "inherits"
-    ssl_password_file password_stream;
+    server {
+        listen      127.0.0.1:8443 ssl;
+        proxy_pass  127.0.0.1:8081;
+    }
 
     server {
-        listen      127.0.0.1:8080 ssl;
+        listen      127.0.0.1:8444 ssl;
         proxy_pass  127.0.0.1:8081;
 
-        ssl_session_cache builtin;
-        ssl_password_file password;
+        ssl_session_cache shared:SSL:1m;
+        ssl_session_tickets on;
+    }
+
+    server {
+        listen      127.0.0.1:8445 ssl;
+        proxy_pass  127.0.0.1:8081;
+
+        ssl_session_cache shared:SSL:1m;
+        ssl_session_tickets off;
     }
 
     server {
-        listen      127.0.0.1:8082 ssl;
+        listen      127.0.0.1:8446 ssl;
         proxy_pass  127.0.0.1:8081;
 
-        ssl_session_cache off;
-        ssl_password_file password_many;
+        ssl_session_cache builtin;
+        ssl_session_tickets off;
     }
 
     server {
-        listen      127.0.0.1:8083 ssl;
+        listen      127.0.0.1:8447 ssl;
         proxy_pass  127.0.0.1:8081;
 
         ssl_session_cache builtin:1000;
-        ssl_password_file password_fifo;
+        ssl_session_tickets off;
     }
 
     server {
-        listen      127.0.0.1:8084 ssl;
+        listen      127.0.0.1:8448 ssl;
         proxy_pass  127.0.0.1:8081;
 
-        ssl_session_cache shared:SSL:1m;
-        ssl_certificate_key inherits.key;
-        ssl_certificate inherits.crt;
+        ssl_session_cache none;
+        ssl_session_tickets off;
+    }
+
+    server {
+        listen      127.0.0.1:8449 ssl;
+        proxy_pass  127.0.0.1:8081;
+
+        ssl_session_cache off;
+        ssl_session_tickets off;
     }
 }
 
@@ -101,97 +115,59 @@ distinguished_name = req_distinguished_n
 EOF
 
 my $d = $t->testdir();
-mkfifo("$d/password_fifo", 0700);
 
-foreach my $name ('localhost', 'inherits') {
-	system("openssl genrsa -out $d/$name.key -passout pass:$name "
-		. "-aes128 2048 >>$d/openssl.out 2>&1") == 0
-		or die "Can't create private key: $!\n";
+foreach my $name ('localhost') {
 	system('openssl req -x509 -new '
 		. "-config $d/openssl.conf -subj /CN=$name/ "
-		. "-out $d/$name.crt "
-		. "-key $d/$name.key -passin pass:$name"
+		. "-out $d/$name.crt -keyout $d/$name.key "
 		. ">>$d/openssl.out 2>&1") == 0
 		or die "Can't create certificate for $name: $!\n";
 }
 
-
 my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!");
 
-$t->write_file('password', 'localhost');
-$t->write_file('password_many', "wrong$CRLF" . "localhost$CRLF");
-$t->write_file('password_stream', 'inherits');
-
-my $p = fork();
-exec("echo localhost > $d/password_fifo") if $p == 0;
-
 $t->run_daemon(\&http_daemon);
 
-eval {
-	open OLDERR, ">&", \*STDERR; close STDERR;
-	$t->run();
-	open STDERR, ">&", \*OLDERR;
-};
-kill 'INT', $p if $@;
+$t->run();
 
 $t->waitforsocket('127.0.0.1:' . port(8081));
 
 ###############################################################################
 
-my ($s, $ssl, $ses);
-
-($s, $ssl) = get_ssl_socket(port(8080));
-Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
-like(Net::SSLeay::read($ssl), qr/200 OK/, 'ssl');
-
-# ssl_session_cache
-
-($s, $ssl) = get_ssl_socket(port(8080));
-Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(port(8080), $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'builtin session reused');
-
-($s, $ssl) = get_ssl_socket(port(8082));
-Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(port(8082), $ses);
-isnt(Net::SSLeay::session_reused($ssl), 1, 'session not reused');
+# session reuse:
+#
+# - only tickets, the default
+# - tickets and shared cache, should work always
+# - only shared cache
+# - only builtin cache
+# - only builtin cache with explicitly configured size
+# - only cache none
+# - only cache off
 
-($s, $ssl) = get_ssl_socket(port(8083));
-Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(port(8083), $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'builtin size session reused');
-
-($s, $ssl) = get_ssl_socket(port(8084));
-Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
-Net::SSLeay::read($ssl);
-$ses = Net::SSLeay::get_session($ssl);
-
-($s, $ssl) = get_ssl_socket(port(8084), $ses);
-is(Net::SSLeay::session_reused($ssl), 1, 'shared session reused');
-
-# ssl_certificate inheritance
-
-($s, $ssl) = get_ssl_socket(port(8080));
-like(Net::SSLeay::dump_peer_certificate($ssl), qr/CN=localhost/, 'CN');
-
-($s, $ssl) = get_ssl_socket(port(8084));
-like(Net::SSLeay::dump_peer_certificate($ssl), qr/CN=inherits/, 'CN inner');
+is(test_reuse(8443), 1, 'tickets reused');
+is(test_reuse(8444), 1, 'tickets and cache reused');
+is(test_reuse(8445), 1, 'cache shared reused');
+is(test_reuse(8446), 1, 'cache builtin reused');
+is(test_reuse(8447), 1, 'cache builtin size reused');
+is(test_reuse(8448), 0, 'cache none not reused');
+is(test_reuse(8449), 0, 'cache off not reused');
 
 ###############################################################################
 
+sub test_reuse {
+	my ($port) = @_;
+	my ($s, $ssl) = get_ssl_socket($port);
+	Net::SSLeay::write($ssl, "GET / HTTP/1.0$CRLF$CRLF");
+	Net::SSLeay::read($ssl);
+	my $ses = Net::SSLeay::get_session($ssl);
+	($s, $ssl) = get_ssl_socket($port, $ses);
+	return Net::SSLeay::session_reused($ssl);
+}
+
 sub get_ssl_socket {
 	my ($port, $ses) = @_;
 
-	my $s = IO::Socket::INET->new('127.0.0.1:' . $port);
+	my $s = IO::Socket::INET->new('127.0.0.1:' . port($port));
 	my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!");
 	Net::SSLeay::set_session($ssl, $ses) if defined $ses;
 	Net::SSLeay::set_fd($ssl, fileno($s));
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID b0db313bf025b7647e31355cb41c7fb3563a6c68
# Parent  376c1b24119098b673c5ba1b1b7f09ad7d5511fd
Tests: LibreSSL and BoringSSL session reuse with TLSv1.3 in stream.

LibreSSL does not support session reuse with TLSv1.3 at all.  BoringSSL
with TLSv1.3 only supports session tickets, but not server-side session
cache.

diff --git a/stream_ssl_session_reuse.t b/stream_ssl_session_reuse.t
--- a/stream_ssl_session_reuse.t
+++ b/stream_ssl_session_reuse.t
@@ -144,16 +144,34 @@ my $ctx = Net::SSLeay::CTX_new() or die(
 # - only cache none
 # - only cache off
 
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
+
 is(test_reuse(8443), 1, 'tickets reused');
 is(test_reuse(8444), 1, 'tickets and cache reused');
+
+TODO: {
+local $TODO = 'no TLSv1.3 session cache in BoringSSL'
+	if $t->has_module('BoringSSL') && test_tls13();
+
 is(test_reuse(8445), 1, 'cache shared reused');
 is(test_reuse(8446), 1, 'cache builtin reused');
 is(test_reuse(8447), 1, 'cache builtin size reused');
+
+}
+}
+
 is(test_reuse(8448), 0, 'cache none not reused');
 is(test_reuse(8449), 0, 'cache off not reused');
 
 ###############################################################################
 
+sub test_tls13 {
+	my ($s, $ssl) = get_ssl_socket(8443);
+	return (Net::SSLeay::version($ssl) > 0x303);
+}
+
 sub test_reuse {
 	my ($port) = @_;
 	my ($s, $ssl) = get_ssl_socket($port);
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID 04ce263b25a6e591d39df2eaf2ff5c4ce0fa633e
# Parent  b0db313bf025b7647e31355cb41c7fb3563a6c68
Tests: BoringSSL does not provide session ids with TLSv1.3.

diff --git a/stream_ssl_variables.t b/stream_ssl_variables.t
--- a/stream_ssl_variables.t
+++ b/stream_ssl_variables.t
@@ -103,7 +103,7 @@ like(Net::SSLeay::read($ssl), qr/^\.:(\w
 
 my $ses = Net::SSLeay::get_session($ssl);
 ($s, $ssl) = get_ssl_socket(port(8081), $ses);
-like(Net::SSLeay::read($ssl), qr/^r:\w{64}:[\w-]+:(TLS|SSL)v(\d|\.)+$/,
+like(Net::SSLeay::read($ssl), qr/^r:(\w{64})?:[\w-]+:(TLS|SSL)v(\d|\.)+$/,
 	'ssl variables - session reused');
 
 SKIP: {
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID dc59b11f23b2a0df9355efa614f47a21b8786e0e
# Parent  04ce263b25a6e591d39df2eaf2ff5c4ce0fa633e
Tests: enabled session reuse via TLS session tickets.

This fixes tests with TLSv1.3 enabled when using BoringSSL, since
for TLSv1.3 it only supports session reuse via TLS session tickets,
and not server-side session cache.

diff --git a/ssl_certificate.t b/ssl_certificate.t
--- a/ssl_certificate.t
+++ b/ssl_certificate.t
@@ -71,7 +71,7 @@ http {
 
     add_header X-SSL $ssl_server_name:$ssl_session_reused;
     ssl_session_cache shared:SSL:1m;
-    ssl_session_tickets off;
+    ssl_session_tickets on;
 
     server {
         listen       127.0.0.1:8080 ssl;
diff --git a/stream_ssl_certificate.t b/stream_ssl_certificate.t
--- a/stream_ssl_certificate.t
+++ b/stream_ssl_certificate.t
@@ -68,7 +68,7 @@ stream {
     }
 
     ssl_session_cache shared:SSL:1m;
-    ssl_session_tickets off;
+    ssl_session_tickets on;
 
     server {
         listen       127.0.0.1:8080 ssl;
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID 28bf82cdf8718b131510ee511812919626ac603c
# Parent  dc59b11f23b2a0df9355efa614f47a21b8786e0e
Tests: restored proper port numbers in ssl_sni_sessions.t.

While using port 8080 for SSL connection works, it's usually a bad idea,
since 8080 implies plain HTTP, much like 80.  For HTTPS we generally use
port 8443 instead.

Unfortunately, proper port numbers were lost in 952:e9064d691790 and
974:882267679006, while converting tests to run in parallel.

diff --git a/ssl_sni_sessions.t b/ssl_sni_sessions.t
--- a/ssl_sni_sessions.t
+++ b/ssl_sni_sessions.t
@@ -39,7 +39,7 @@ http {
     ssl_certificate localhost.crt;
 
     server {
-        listen       127.0.0.1:8080 ssl;
+        listen       127.0.0.1:8443 ssl;
         server_name  default;
 
         ssl_session_tickets off;
@@ -51,7 +51,7 @@ http {
     }
 
     server {
-        listen       127.0.0.1:8080;
+        listen       127.0.0.1:8443;
         server_name  nocache;
 
         ssl_session_tickets off;
@@ -63,7 +63,7 @@ http {
     }
 
     server {
-        listen       127.0.0.1:8081 ssl;
+        listen       127.0.0.1:8444 ssl;
         server_name  default;
 
         ssl_session_ticket_key ticket1.key;
@@ -74,7 +74,7 @@ http {
     }
 
     server {
-        listen       127.0.0.1:8081;
+        listen       127.0.0.1:8444;
         server_name  tickets;
 
         ssl_session_ticket_key ticket2.key;
@@ -128,7 +128,7 @@ foreach my $name ('localhost') {
 $t->run();
 
 plan(skip_all => 'no TLS 1.3 sessions')
-	if get('default', port(8080), get_ssl_context()) =~ /TLSv1.3/
+	if get('default', port(8443), get_ssl_context()) =~ /TLSv1.3/
 	&& ($Net::SSLeay::VERSION < 1.88 || $IO::Socket::SSL::VERSION < 2.061);
 
 $t->plan(6);
@@ -139,8 +139,8 @@ plan(skip_all => 'no TLS 1.3 sessions')
 
 my $ctx = get_ssl_context();
 
-like(get('default', port(8080), $ctx), qr!default:\.!, 'default server');
-like(get('default', port(8080), $ctx), qr!default:r!, 'default server reused');
+like(get('default', port(8443), $ctx), qr!default:\.!, 'default server');
+like(get('default', port(8443), $ctx), qr!default:r!, 'default server reused');
 
 # check that sessions are still properly saved and restored
 # when using an SNI-based virtual server with different session cache;
@@ -154,16 +154,16 @@ like(get('default', port(8080), $ctx), q
 
 $ctx = get_ssl_context();
 
-like(get('nocache', port(8080), $ctx), qr!nocache:\.!, 'without cache');
-like(get('nocache', port(8080), $ctx), qr!nocache:r!, 'without cache reused');
+like(get('nocache', port(8443), $ctx), qr!nocache:\.!, 'without cache');
+like(get('nocache', port(8443), $ctx), qr!nocache:r!, 'without cache reused');
 
 # make sure tickets can be used if an SNI-based virtual server
 # uses a different set of session ticket keys explicitly set
 
 $ctx = get_ssl_context();
 
-like(get('tickets', port(8081), $ctx), qr!tickets:\.!, 'tickets');
-like(get('tickets', port(8081), $ctx), qr!tickets:r!, 'tickets reused');
+like(get('tickets', port(8444), $ctx), qr!tickets:\.!, 'tickets');
+like(get('tickets', port(8444), $ctx), qr!tickets:r!, 'tickets reused');
 
 ###############################################################################
 
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID 558bd1ebd0ef43b81484ad716ec25c349eee55e3
# Parent  28bf82cdf8718b131510ee511812919626ac603c
Tests: disabled ssl_sni_sessions.t with LibreSSL and BoringSSL.

With TLSv1.3, LibreSSL does not provide session reuse at all, and BoringSSL
only supports session tickets, and not server-side session cache.  Since
the test is focused on session cache usage, it is now skipped.

diff --git a/ssl_sni_sessions.t b/ssl_sni_sessions.t
--- a/ssl_sni_sessions.t
+++ b/ssl_sni_sessions.t
@@ -130,6 +130,12 @@ foreach my $name ('localhost') {
 plan(skip_all => 'no TLS 1.3 sessions')
 	if get('default', port(8443), get_ssl_context()) =~ /TLSv1.3/
 	&& ($Net::SSLeay::VERSION < 1.88 || $IO::Socket::SSL::VERSION < 2.061);
+plan(skip_all => 'no TLS 1.3 sessions in LibreSSL')
+	if get('default', port(8443), get_ssl_context()) =~ /TLSv1.3/
+	&& $t->has_module('LibreSSL');
+plan(skip_all => 'no TLS 1.3 session cache in BoringSSL')
+	if get('default', port(8443), get_ssl_context()) =~ /TLSv1.3/
+	&& $t->has_module('BoringSSL');
 
 $t->plan(6);
 
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID 9b77114bf006d95f5a1984776a6b375a092cbdfe
# Parent  558bd1ebd0ef43b81484ad716ec25c349eee55e3
Tests: fixed proxy_ssl.t with LibreSSL and TLSv1.3.

LibreSSL does not support session reuse with TLSv1.3.

diff --git a/proxy_ssl.t b/proxy_ssl.t
--- a/proxy_ssl.t
+++ b/proxy_ssl.t
@@ -46,6 +46,7 @@ http {
 
         location / {
             add_header X-Session $ssl_session_reused;
+            add_header X-Protocol $ssl_protocol;
         }
     }
 
@@ -109,9 +110,16 @@ foreach my $name ('localhost') {
 like(http_get('/ssl'), qr/200 OK.*X-Session: \./s, 'ssl');
 like(http_get('/ssl'), qr/200 OK.*X-Session: \./s, 'ssl 2');
 like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: \./s, 'ssl session new');
+
+TODO: {
+local $TODO = 'no TLS 1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') && http_get('/ssl') =~ /TLSv1.3/;
+
 like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: r/s, 'ssl session reused');
 like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: r/s, 'ssl session reused 2');
 
+}
+
 SKIP: {
 skip 'long test', 1 unless $ENV{TEST_NGINX_UNSAFE};
 
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID 5a58b9f2c5b33893dcdd67fbfe0231863a43846d
# Parent  9b77114bf006d95f5a1984776a6b375a092cbdfe
Tests: fixed ssl_session_ticket_key.t with LibreSSL and TLSv1.3.

LibreSSL does not support session reuse with TLSv1.3.

diff --git a/ssl_session_ticket_key.t b/ssl_session_ticket_key.t
--- a/ssl_session_ticket_key.t
+++ b/ssl_session_ticket_key.t
@@ -96,6 +96,10 @@ select undef, undef, undef, 0.5;
 is(get_ticket_key_name(), $key, 'ticket key match');
 
 select undef, undef, undef, 2.5;
+
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
+
 cmp_ok(get_ticket_key_name(), 'ne', $key, 'ticket key next');
 
 ###############################################################################
@@ -107,7 +111,7 @@ sub get_ticket_key_name {
 next:
 	# tag(10) | len{2} | OCTETSTRING(4) | len{2} | ticket(key_name|..)
 	$asn =~ /\xaa\x81($any)\x04\x81($any)($any{16})/g;
-	return if !defined $3;
+	return '' if !defined $3;
 	goto next if unpack("C", $1) - unpack("C", $2) != 3;
 	my $key = unpack "H*", $3;
 	Test::Nginx::log_core('||', "ticket key: $key");
@@ -126,6 +130,11 @@ EOF
 	Net::SSLeay::get_session($ssl);
 }
 
+sub test_tls13 {
+	my ($s, $ssl) = get_ssl_socket();
+	return (Net::SSLeay::version($ssl) > 0x303);
+}
+
 sub get_ssl_socket {
 	my $s = IO::Socket::INET->new('127.0.0.1:' . port(8080));
 	my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!");
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID ca3194d2a279bb9b468ce7a9e6628638d367fef1
# Parent  5a58b9f2c5b33893dcdd67fbfe0231863a43846d
Tests: fixed ssl_sni.t with LibreSSL and TLSv1.3.

LibreSSL does not support session reuse with TLSv1.3.

diff --git a/ssl_sni.t b/ssl_sni.t
--- a/ssl_sni.t
+++ b/ssl_sni.t
@@ -148,9 +148,13 @@ my $ctx = new IO::Socket::SSL::SSL_Conte
 
 like(get('/', 'localhost', 8081, $ctx), qr/^\.:localhost$/m, 'ssl server name');
 
-SKIP: {
-skip 'no TLS 1.3 sessions', 1 if get('/protocol', 'localhost') =~ /TLSv1.3/
-	&& ($Net::SSLeay::VERSION < 1.88 || $IO::Socket::SSL::VERSION < 2.061);
+TODO: {
+local $TODO = 'no TLSv1.3 sessions, old Net::SSLeay'
+	if $Net::SSLeay::VERSION < 1.88 && test_tls13();
+local $TODO = 'no TLSv1.3 sessions, old IO::Socket::SSL'
+	if $IO::Socket::SSL::VERSION < 2.061 && test_tls13();
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
 
 like(get('/', 'localhost', 8081, $ctx), qr/^r:localhost$/m,
 	'ssl server name - reused');
@@ -159,6 +163,10 @@ like(get('/', 'localhost', 8081, $ctx), 
 
 ###############################################################################
 
+sub test_tls13 {
+	get('/protocol', 'localhost') =~ /TLSv1.3/;
+}
+
 sub get_ssl_socket {
 	my ($host, $port, $ctx) = @_;
 	my $s;
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID 85e4f377674975634f1b2e34fc40a5d3b6e54fc0
# Parent  ca3194d2a279bb9b468ce7a9e6628638d367fef1
Tests: LibreSSL certificate negotiation with TLSv1.3.

LibreSSL fails to negotiate certificates based on signature algorithms
when using TLSv1.3, and fails with "missing rsa certificate" and
"unknown pkey type" errors.

diff --git a/ssl_stapling.t b/ssl_stapling.t
--- a/ssl_stapling.t
+++ b/ssl_stapling.t
@@ -38,7 +38,7 @@ my $t = Test::Nginx->new()->has(qw/http 
 
 plan(skip_all => 'no OCSP stapling') if $t->has_module('BoringSSL');
 
-$t->plan(9)->write_file_expand('nginx.conf', <<'EOF');
+$t->plan(10)->write_file_expand('nginx.conf', <<'EOF');
 
 %%TEST_GLOBALS%%
 
@@ -259,11 +259,25 @@ staple(8449, 'ECDSA');
 sleep 1;
 
 ok(!staple(8443, 'RSA'), 'staple revoked');
+
+TODO: {
+local $TODO = 'broken TLSv1.3 sigalgs in LibreSSL'
+	if $t->has_module('LibreSSL') && $version > 0x303;
+
 ok(staple(8443, 'ECDSA'), 'staple success');
 
+}
+
 ok(!staple(8444, 'RSA'), 'responder revoked');
+
+TODO: {
+local $TODO = 'broken TLSv1.3 sigalgs in LibreSSL'
+	if $t->has_module('LibreSSL') && $version > 0x303;
+
 ok(staple(8444, 'ECDSA'), 'responder success');
 
+}
+
 ok(!staple(8445, 'ECDSA'), 'verify - root not trusted');
 
 ok(staple(8446, 'ECDSA', "$d/int.crt"), 'cert store');
@@ -273,6 +287,14 @@ is(staple(8448, 'ECDSA'), '1 0', 'file s
 
 ok(!staple(8449, 'ECDSA'), 'ocsp error');
 
+TODO: {
+local $TODO = 'broken TLSv1.3 sigalgs in LibreSSL'
+	if $t->has_module('LibreSSL') && $version > 0x303;
+
+like(`grep -F '[crit]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no crit');
+
+}
+
 ###############################################################################
 
 sub staple {
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679527802 -10800
#      Thu Mar 23 02:30:02 2023 +0300
# Node ID 647be9c9c22aea06c5a28aa280856edaebd26e21
# Parent  85e4f377674975634f1b2e34fc40a5d3b6e54fc0
Tests: LibreSSL does not send CA lists with TLSv1.3.

diff --git a/ssl_verify_client.t b/ssl_verify_client.t
--- a/ssl_verify_client.t
+++ b/ssl_verify_client.t
@@ -55,6 +55,7 @@ http {
     %%TEST_GLOBALS_HTTP%%
 
     add_header X-Verify x$ssl_client_verify:${ssl_client_cert}x;
+    add_header X-Protocol $ssl_protocol;
 
     ssl_session_cache shared:SSL:1m;
     ssl_session_tickets off;
@@ -169,15 +170,24 @@ like(get('optional', '3.example.com'), q
 SKIP: {
 skip 'Net::SSLeay version >= 1.36 required', 1 if $Net::SSLeay::VERSION < 1.36;
 
+TODO: {
+local $TODO = 'broken TLSv1.3 CA list in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
+
 my $ca = join ' ', get('optional', '3.example.com');
 is($ca, '/CN=2.example.com', 'no trusted sent');
 
 }
+}
 
 like(get('optional', undef, 'localhost'), qr/421 Misdirected/, 'misdirected');
 
 ###############################################################################
 
+sub test_tls13 {
+	get('optional') =~ /TLSv1.3/;
+}
+
 sub get {
 	my ($sni, $cert, $host) = @_;
 
diff --git a/stream_ssl_verify_client.t b/stream_ssl_verify_client.t
--- a/stream_ssl_verify_client.t
+++ b/stream_ssl_verify_client.t
@@ -86,6 +86,11 @@ stream {
         ssl_verify_client optional_no_ca;
         ssl_client_certificate 2.example.com.crt;
     }
+
+    server {
+        listen  127.0.0.1:8084 ssl;
+        return  $ssl_protocol;
+    }
 }
 
 EOF
@@ -126,10 +131,15 @@ like(get(8082, '3.example.com'), qr/SUCC
 SKIP: {
 skip 'Net::SSLeay version >= 1.36 required', 1 if $Net::SSLeay::VERSION < 1.36;
 
+TODO: {
+local $TODO = 'broken TLSv1.3 CA list in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
+
 my $ca = join ' ', get(8082, '3.example.com');
 is($ca, '/CN=2.example.com', 'no trusted sent');
 
 }
+}
 
 $t->stop();
 
@@ -137,6 +147,10 @@ is($t->read_file('status.log'), "500\n20
 
 ###############################################################################
 
+sub test_tls13 {
+	get(8084) =~ /TLSv1.3/;
+}
+
 sub get {
 	my ($port, $cert) = @_;
 
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679531073 -10800
#      Thu Mar 23 03:24:33 2023 +0300
# Node ID 5e7b95544014db80e0d8c94ca8b6a9b2f14b75cd
# Parent  647be9c9c22aea06c5a28aa280856edaebd26e21
Tests: fixed stream_proxy_ssl.t with LibreSSL and TLSv1.3.

LibreSSL does not support session reuse with TLSv1.3.

diff --git a/stream_proxy_ssl.t b/stream_proxy_ssl.t
--- a/stream_proxy_ssl.t
+++ b/stream_proxy_ssl.t
@@ -78,6 +78,8 @@ http {
 
         ssl_certificate_key localhost.key;
         ssl_certificate localhost.crt;
+
+        add_header X-Protocol $ssl_protocol;
     }
 }
 
@@ -111,9 +113,16 @@ is(stream('127.0.0.1:' . port(8081))->re
 is(stream('127.0.0.1:' . port(8081))->read(), '.', 'ssl 2');
 
 is(stream('127.0.0.1:' . port(8082))->read(), '.', 'ssl session new');
+
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
+
 is(stream('127.0.0.1:' . port(8082))->read(), 'r', 'ssl session reused');
 is(stream('127.0.0.1:' . port(8082))->read(), 'r', 'ssl session reused 2');
 
+}
+
 my $s = http('', start => 1);
 
 sleep 3;
@@ -121,3 +130,9 @@ sleep 3;
 like(http_get('/', socket => $s), qr/200 OK/, 'proxy connect timeout');
 
 ###############################################################################
+
+sub test_tls13 {
+	http_get('/') =~ /TLSv1.3/;
+}
+
+###############################################################################
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679531122 -10800
#      Thu Mar 23 03:25:22 2023 +0300
# Node ID 8bec6f886e67e4b093112317cfdc4a97590e221a
# Parent  5e7b95544014db80e0d8c94ca8b6a9b2f14b75cd
Tests: fixed stream_ssl_variables.t.t with LibreSSL and TLSv1.3.

LibreSSL does not support session reuse with TLSv1.3.

diff --git a/stream_ssl_variables.t b/stream_ssl_variables.t
--- a/stream_ssl_variables.t
+++ b/stream_ssl_variables.t
@@ -101,11 +101,17 @@ is(stream('127.0.0.1:' . port(8080))->re
 like(Net::SSLeay::read($ssl), qr/^\.:(\w{64})?:[\w-]+:(TLS|SSL)v(\d|\.)+$/,
 	'ssl variables');
 
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') && test_tls13();
+
 my $ses = Net::SSLeay::get_session($ssl);
 ($s, $ssl) = get_ssl_socket(port(8081), $ses);
 like(Net::SSLeay::read($ssl), qr/^r:(\w{64})?:[\w-]+:(TLS|SSL)v(\d|\.)+$/,
 	'ssl variables - session reused');
 
+}
+
 SKIP: {
 skip 'no sni', 3 unless $t->has_module('sni');
 
@@ -123,6 +129,11 @@ is(Net::SSLeay::ssl_read_all($ssl), '', 
 
 ###############################################################################
 
+sub test_tls13 {
+	($s, $ssl) = get_ssl_socket(port(8081));
+	Net::SSLeay::read($ssl) =~ /TLSv1.3/;
+}
+
 sub get_ssl_socket {
 	my ($port, $ses, $name) = @_;
 
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679531124 -10800
#      Thu Mar 23 03:25:24 2023 +0300
# Node ID 1813c2bd9429bff39b8108e58fc4c06f7afe38f5
# Parent  8bec6f886e67e4b093112317cfdc4a97590e221a
Tests: cleaned up ssl_ocsp.t.

Fixed verbose logging, added $SIG{PIPE} handling to avoid hangs if
the server closes connection, fixed SKIP message for BoringSSL.

diff --git a/ssl_ocsp.t b/ssl_ocsp.t
--- a/ssl_ocsp.t
+++ b/ssl_ocsp.t
@@ -43,7 +43,8 @@ plan(skip_all => 'Net::SSLeay with OpenS
 
 my $t = Test::Nginx->new()->has(qw/http http_ssl sni/)->has_daemon('openssl');
 
-plan(skip_all => 'no OCSP stapling') if $t->has_module('BoringSSL');
+plan(skip_all => 'no OCSP support in BoringSSL')
+	if $t->has_module('BoringSSL');
 
 $t->write_file_expand('nginx.conf', <<'EOF');
 
@@ -416,9 +417,11 @@ sub get {
 	my $cipher = Net::SSLeay::get_cipher($ssl);
 	Test::Nginx::log_core('||', "cipher: $cipher");
 	my $host = $extra{sni} ? $extra{sni} : 'localhost';
+	local $SIG{PIPE} = 'IGNORE';
+	log_out("GET /serial HTTP/1.0\nHost: $host\n\n");
 	Net::SSLeay::write($ssl, "GET /serial HTTP/1.0\nHost: $host\n\n");
 	my $r = Net::SSLeay::read($ssl);
-	Test::Nginx::log_core($r);
+	log_in($r);
 	$s->close();
 	return $r unless wantarray();
 	return ($s, $ssl);
@@ -496,6 +499,7 @@ sub http_daemon {
 		my $resp;
 
 		while (<$client>) {
+			Test::Nginx::log_core('||', $_);
 			$headers .= $_;
 			last if (/^\x0d?\x0a?$/);
 		}
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679531124 -10800
#      Thu Mar 23 03:25:24 2023 +0300
# Node ID 0661a3c11e0fccb07f46b4c2878bcd8ee0f77db0
# Parent  1813c2bd9429bff39b8108e58fc4c06f7afe38f5
Tests: removed multiple server certificates from ssl_ocsp.t.

Multiple server certificates are not needed to test OCSP verification of
client certificates (in contrast to OCSP stapling, where server certificates
are verified, and different staples should be correctly returned with
different server certificates).  And using multiple server certificates
causes issues when testing with LibreSSL due to broken sigalgs-based
server certificate selection in LibreSSL with TLSv1.3.

Accordingly, the test is simplified to do not use multiple server
certificates.

diff --git a/ssl_ocsp.t b/ssl_ocsp.t
--- a/ssl_ocsp.t
+++ b/ssl_ocsp.t
@@ -63,11 +63,6 @@ http {
     ssl_verify_depth 2;
     ssl_client_certificate trusted.crt;
 
-    ssl_ciphers DEFAULT:ECCdraft;
-
-    ssl_certificate_key ec.key;
-    ssl_certificate ec.crt;
-
     ssl_certificate_key rsa.key;
     ssl_certificate rsa.crt;
 
@@ -273,13 +268,8 @@ system("openssl ocsp -index $d/certindex
 
 # server cert/key
 
-system("openssl ecparam -genkey -out $d/ec.key -name prime256v1 "
-	. ">>$d/openssl.out 2>&1") == 0 or die "Can't create EC pem: $!\n";
-system("openssl genrsa -out $d/rsa.key 2048 >>$d/openssl.out 2>&1") == 0
-	or die "Can't create RSA pem: $!\n";
-
-foreach my $name ('ec', 'rsa') {
-	system("openssl req -x509 -new -key $d/$name.key "
+foreach my $name ('rsa') {
+	system('openssl req -x509 -new '
 		. "-config $d/openssl.conf -subj /CN=$name/ "
 		. "-out $d/$name.crt -keyout $d/$name.key "
 		. ">>$d/openssl.out 2>&1") == 0
@@ -288,7 +278,7 @@ foreach my $name ('ec', 'rsa') {
 
 $t->run_daemon(\&http_daemon, $t, port(8081));
 $t->run_daemon(\&http_daemon, $t, port(8082));
-$t->run()->plan(14);
+$t->run()->plan(15);
 
 $t->waitforsocket("127.0.0.1:" . port(8081));
 $t->waitforsocket("127.0.0.1:" . port(8082));
@@ -297,17 +287,17 @@ my $version = get_version();
 
 ###############################################################################
 
-like(get('RSA', 'end'), qr/200 OK.*SUCCESS/s, 'ocsp leaf');
+like(get('end'), qr/200 OK.*SUCCESS/s, 'ocsp leaf');
 
 # demonstrate that ocsp int request is failed due to missing resolver
 
-like(get('RSA', 'end', sni => 'resolver'),
+like(get('end', sni => 'resolver'),
 	qr/400 Bad.*FAILED:certificate status request failed/s,
 	'ocsp many failed request');
 
 # demonstrate that ocsp int request is actually made by failing ocsp response
 
-like(get('RSA', 'end', port => 8444),
+like(get('end', port => 8444),
 	qr/400 Bad.*FAILED:certificate status request failed/s,
 	'ocsp many failed');
 
@@ -323,11 +313,11 @@ system("openssl ocsp -index $d/certindex
 	. ">>$d/openssl.out 2>&1") == 0
 	or die "Can't create OCSP response: $!\n";
 
-like(get('RSA', 'end', port => 8444), qr/200 OK.*SUCCESS/s, 'ocsp many');
+like(get('end', port => 8444), qr/200 OK.*SUCCESS/s, 'ocsp many');
 
 # store into ssl_ocsp_cache
 
-like(get('RSA', 'end', port => 8446), qr/200 OK.*SUCCESS/s, 'cache store');
+like(get('end', port => 8446), qr/200 OK.*SUCCESS/s, 'cache store');
 
 # revoke
 
@@ -346,23 +336,23 @@ system("openssl ocsp -index $d/certindex
 	. ">>$d/openssl.out 2>&1") == 0
 	or die "Can't create OCSP response: $!\n";
 
-like(get('RSA', 'end'), qr/400 Bad.*FAILED:certificate revoked/s, 'revoked');
+like(get('end'), qr/400 Bad.*FAILED:certificate revoked/s, 'revoked');
 
 # with different responder where it's still valid
 
-like(get('RSA', 'end', port => 8445), qr/200 OK.*SUCCESS/s, 'ocsp responder');
+like(get('end', port => 8445), qr/200 OK.*SUCCESS/s, 'ocsp responder');
 
 # with different context to responder where it's still valid
 
-like(get('RSA', 'end', sni => 'sni'), qr/200 OK.*SUCCESS/s, 'ocsp context');
+like(get('end', sni => 'sni'), qr/200 OK.*SUCCESS/s, 'ocsp context');
 
 # with cached ocsp response it's still valid
 
-like(get('RSA', 'end', port => 8446), qr/200 OK.*SUCCESS/s, 'cache lookup');
+like(get('end', port => 8446), qr/200 OK.*SUCCESS/s, 'cache lookup');
 
 # ocsp end response signed with invalid (root) cert, expect HTTP 400
 
-like(get('ECDSA', 'ec-end'),
+like(get('ec-end'),
 	qr/400 Bad.*FAILED:certificate status request failed/s,
 	'root ca not trusted');
 
@@ -374,12 +364,12 @@ system("openssl ocsp -index $d/certindex
 	. ">>$d/openssl.out 2>&1") == 0
 	or die "Can't create EC OCSP response: $!\n";
 
-like(get('ECDSA', 'ec-end'), qr/200 OK.*SUCCESS/s, 'ocsp ecdsa');
+like(get('ec-end'), qr/200 OK.*SUCCESS/s, 'ocsp ecdsa');
 
-my ($s, $ssl) = get('ECDSA', 'ec-end');
+my ($s, $ssl) = get('ec-end');
 my $ses = Net::SSLeay::get_session($ssl);
 
-like(get('ECDSA', 'ec-end', ses => $ses),
+like(get('ec-end', ses => $ses),
 	qr/200 OK.*SUCCESS:r/s, 'session reused');
 
 # revoke with saved session
@@ -401,19 +391,22 @@ system("openssl ocsp -index $d/certindex
 
 # reusing session with revoked certificate
 
-like(get('ECDSA', 'ec-end', ses => $ses),
+like(get('ec-end', ses => $ses),
 	qr/400 Bad.*FAILED:certificate revoked:r/s, 'session reused - revoked');
 
 # regression test for self-signed
 
-like(get('RSA', 'root', port => 8447), qr/200 OK.*SUCCESS/s, 'ocsp one');
+like(get('root', port => 8447), qr/200 OK.*SUCCESS/s, 'ocsp one');
+
+# check for errors
+
+like(`grep -F '[crit]' ${\($t->testdir())}/error.log`, qr/^$/s, 'no crit');
 
 ###############################################################################
 
 sub get {
-	my ($type, $cert, %extra) = @_;
-	$type = 'PSS' if $type eq 'RSA' && $version > 0x0303;
-	my ($s, $ssl) = get_ssl_socket($type, $cert, %extra);
+	my ($cert, %extra) = @_;
+	my ($s, $ssl) = get_ssl_socket($cert, %extra);
 	my $cipher = Net::SSLeay::get_cipher($ssl);
 	Test::Nginx::log_core('||', "cipher: $cipher");
 	my $host = $extra{sni} ? $extra{sni} : 'localhost';
@@ -428,7 +421,7 @@ sub get {
 }
 
 sub get_ssl_socket {
-	my ($type, $cert, %extra) = @_;
+	my ($cert, %extra) = @_;
 	my $ses = $extra{ses};
 	my $sni = $extra{sni};
 	my $port = $extra{port} || 8443;
@@ -450,18 +443,6 @@ sub get_ssl_socket {
 
 	my $ctx = Net::SSLeay::CTX_new() or die("Failed to create SSL_CTX $!");
 
-	if (defined $type) {
-		my $ssleay = Net::SSLeay::SSLeay();
-		if ($ssleay < 0x1000200f || $ssleay == 0x20000000) {
-			Net::SSLeay::CTX_set_cipher_list($ctx, $type)
-				or die("Failed to set cipher list");
-		} else {
-			# SSL_CTRL_SET_SIGALGS_LIST
-			Net::SSLeay::CTX_ctrl($ctx, 98, 0, $type . '+SHA256')
-				or die("Failed to set sigalgs");
-		}
-	}
-
 	Net::SSLeay::set_cert_and_key($ctx, "$d/$cert.crt", "$d/$cert.key")
 		or die if $cert;
 	my $ssl = Net::SSLeay::new($ctx) or die("Failed to create SSL $!");
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679531124 -10800
#      Thu Mar 23 03:25:24 2023 +0300
# Node ID 77957615f50b6ae8ac8ef4ffc2c86813c04c16e6
# Parent  0661a3c11e0fccb07f46b4c2878bcd8ee0f77db0
Tests: fixed ssl_ocsp.t with LibreSSL and TLSv1.3.

LibreSSL does not support session reuse with TLSv1.3.

diff --git a/ssl_ocsp.t b/ssl_ocsp.t
--- a/ssl_ocsp.t
+++ b/ssl_ocsp.t
@@ -369,9 +369,15 @@ like(get('ec-end'), qr/200 OK.*SUCCESS/s
 my ($s, $ssl) = get('ec-end');
 my $ses = Net::SSLeay::get_session($ssl);
 
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') and $version > 0x303;
+
 like(get('ec-end', ses => $ses),
 	qr/200 OK.*SUCCESS:r/s, 'session reused');
 
+}
+
 # revoke with saved session
 
 system("openssl ca -config $d/ca.conf -revoke $d/ec-end.crt "
@@ -391,9 +397,15 @@ system("openssl ocsp -index $d/certindex
 
 # reusing session with revoked certificate
 
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') and $version > 0x303;
+
 like(get('ec-end', ses => $ses),
 	qr/400 Bad.*FAILED:certificate revoked:r/s, 'session reused - revoked');
 
+}
+
 # regression test for self-signed
 
 like(get('root', port => 8447), qr/200 OK.*SUCCESS/s, 'ocsp one');
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1679531124 -10800
#      Thu Mar 23 03:25:24 2023 +0300
# Node ID fa4dd181b78754d69ef3f90a414232d347ecd6cb
# Parent  77957615f50b6ae8ac8ef4ffc2c86813c04c16e6
Tests: fixed upstream zone ssl tests with LibreSSL and TLSv1.3.

LibreSSL does not support session reuse with TLSv1.3.

diff --git a/stream_upstream_zone_ssl.t b/stream_upstream_zone_ssl.t
--- a/stream_upstream_zone_ssl.t
+++ b/stream_upstream_zone_ssl.t
@@ -82,6 +82,19 @@ stream {
         ssl_certificate localhost.crt;
         ssl_session_cache builtin;
     }
+
+    server {
+        listen      127.0.0.1:8085;
+        proxy_pass  127.0.0.1:8086;
+    }
+
+    server {
+        listen      127.0.0.1:8086 ssl;
+        return      $ssl_protocol;
+
+        ssl_certificate_key localhost.key;
+        ssl_certificate localhost.crt;
+    }
 }
 
 EOF
@@ -112,13 +125,33 @@ is(stream('127.0.0.1:' . port(8080))->re
 is(stream('127.0.0.1:' . port(8080))->read(), '.', 'ssl 2');
 
 is(stream('127.0.0.1:' . port(8081))->read(), '.', 'ssl session new');
+
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') and test_tls13();
+
 is(stream('127.0.0.1:' . port(8081))->read(), 'r', 'ssl session reused');
 is(stream('127.0.0.1:' . port(8081))->read(), 'r', 'ssl session reused 2');
 
+}
+
 is(stream('127.0.0.1:' . port(8082))->read(), '.', 'backup ssl');
 is(stream('127.0.0.1:' . port(8082))->read(), '.', 'backup ssl 2');
 
 is(stream('127.0.0.1:' . port(8083))->read(), '.', 'backup ssl session new');
+
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') and test_tls13();
+
 is(stream('127.0.0.1:' . port(8083))->read(), 'r', 'backup ssl session reused');
 
+}
+
 ###############################################################################
+
+sub test_tls13 {
+	stream('127.0.0.1:' . port(8085))->read() =~ /TLSv1.3/;
+}
+
+###############################################################################
diff --git a/upstream_zone_ssl.t b/upstream_zone_ssl.t
--- a/upstream_zone_ssl.t
+++ b/upstream_zone_ssl.t
@@ -56,6 +56,7 @@ http {
 
         location / {
             add_header X-Session $ssl_session_reused;
+            add_header X-Protocol $ssl_protocol;
         }
     }
 
@@ -114,12 +115,32 @@ foreach my $name ('localhost') {
 like(http_get('/ssl'), qr/200 OK.*X-Session: \./s, 'ssl');
 like(http_get('/ssl'), qr/200 OK.*X-Session: \./s, 'ssl 2');
 like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: \./s, 'ssl session new');
+
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') and test_tls13();
+
 like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: r/s, 'ssl session reused');
 like(http_get('/ssl_reuse'), qr/200 OK.*X-Session: r/s, 'ssl session reused 2');
 
+}
+
 like(http_get('/backup'), qr/200 OK.*X-Session: \./s, 'backup');
 like(http_get('/backup'), qr/200 OK.*X-Session: \./s, 'backup 2');
 like(http_get('/backup_reuse'), qr/200 OK.*X-Session: \./s, 'backup new');
+
+TODO: {
+local $TODO = 'no TLSv1.3 sessions in LibreSSL'
+	if $t->has_module('LibreSSL') and test_tls13();
+
 like(http_get('/backup_reuse'), qr/200 OK.*X-Session: r/s, 'backup reused');
 
+}
+
 ###############################################################################
+
+sub test_tls13 {
+	http_get('/ssl') =~ /TLSv1.3/;
+}
+
+###############################################################################

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx-devel mailing list