From 8919aafc19d7dd5d73ff25e4bf813a8663032257 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Mon, 17 Oct 2022 11:26:20 -0700 Subject: [PATCH] Use correct cert and key file when there is a hostname-specific cert --- miniserv.pl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/miniserv.pl b/miniserv.pl index 3f5211f5c..8663ca2ca 100755 --- a/miniserv.pl +++ b/miniserv.pl @@ -4698,6 +4698,15 @@ Net::SSLeay::set_fd($ssl_con, fileno($sock)); if (!Net::SSLeay::accept($ssl_con)) { return undef; } +# Check for a per-hostname SSL context and use that instead +my $h = Net::SSLeay::get_servername($ssl_con); +if ($h) { + my $c = $ssl_contexts{$h} || + $h =~ /^[^\.]+\.(.*)$/ && $ssl_contexts{"*.$1"}; + if ($c) { + $ssl_ctx = $c; + } + } return ($ssl_con, $ssl_ctx->{'certfile'}, $ssl_ctx->{'keyfile'}); } @@ -5642,6 +5651,7 @@ elsif ($ws->{'cmd'}) { my $pid = fork(); if (!$pid) { # Run command in a forked process + # XXX todo here exit(1); } $ptyfh->close_slave();