]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
t/httpd-https: test SSL session reuse
authorEric Wong <e@80x24.org>
Thu, 3 Apr 2025 08:46:19 +0000 (08:46 +0000)
committerEric Wong <e@80x24.org>
Fri, 4 Apr 2025 19:52:45 +0000 (19:52 +0000)
Reusing SSL sessions is one avenue to improve performance on
high-latency networks.  For now, we can support the built-in
session cache of OpenSSL.  For multi-process setups, using
using Cache::FastMmap will likely be the way to go...

t/httpd-corner.psgi
t/httpd-https.t

index f4c8c51f1f0bc27b754adceb7aae153f6621e6c2..0dd840a013a97c90a103a121d8d1ef4a56d76ab6 100644 (file)
@@ -80,6 +80,10 @@ my $app = sub {
        } elsif ($path eq '/host-port') {
                $code = 200;
                push @$body, "$env->{REMOTE_ADDR} $env->{REMOTE_PORT}";
+       } elsif ($path eq '/session_reused') {
+               my $http = $env->{'psgix.io'}; # PublicInbox::HTTP
+               $body = [ $http->{sock}->get_session_reused ? "y\n" : "n\n" ];
+               $code = 200;
        } elsif ($path eq '/callback') {
                return sub {
                        my ($res) = @_;
index 46a2c8644a402533e62336d3a46ad7ac3c974fc7..3fdb850f177849637f137189b1c592ec371408db 100644 (file)
@@ -123,9 +123,26 @@ for my $args (
 
        $d = tcp_connect($https);
        $o{SSL_hostname} = $o{SSL_verifycn_name} = 'server2.local';
+       my $ctx = IO::Socket::SSL::SSL_Context->new(%o,
+                       SSL_session_cache_size => 128);
+       $o{SSL_reuse_ctx} = $ctx;
        is(IO::Socket::SSL->start_SSL($d, %o), $d,
                'new hostname to match cert works after HUP');
+       ok !$d->get_session_reused, 'initial client session not reused';
        $check_url_scheme->($d, __LINE__);
+       $d->stop_SSL;
+
+       $d = tcp_connect($https);
+       IO::Socket::SSL->start_SSL($d, %o) or xbail "reconnect: $!";
+       print $d "GET /session_reused HTTP/1.1\r\nHost: example.com\r\n\r\n"
+               or xbail "print $!";
+       ok $d->get_session_reused, 'client session reused';
+       my $hdr = do { local $/ = "\r\n\r\n"; <$d> };
+       like $hdr , qr!\AHTTP/1\.1 200!, 'session_reused request';
+       chomp(my $bool = <$d>);
+       is $bool, 'y', 'server session reused';
+
+       # TODO: session tickets and TLS-PSK
 
        # existing connection w/ old cert still works:
        $check_url_scheme->($c, __LINE__);