From 3c415cd73421fe064f3e39991fcfa83c0ec5f00a Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Thu, 18 Apr 2024 15:04:47 +0100 Subject: [PATCH] [1.x] Improve TLS check (#158) * improve tls check * wip --- src/Servers/Reverb/Factory.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Servers/Reverb/Factory.php b/src/Servers/Reverb/Factory.php index 0648c2f1..5d9a7c9b 100644 --- a/src/Servers/Reverb/Factory.php +++ b/src/Servers/Reverb/Factory.php @@ -53,7 +53,7 @@ public static function make( $options['tls'] = static::configureTls($options['tls'] ?? [], $hostname); - $uri = empty($options['tls']) ? "{$host}:{$port}" : "tls://{$host}:{$port}"; + $uri = static::usesTls($options['tls']) ? "tls://{$host}:{$port}" : "{$host}:{$port}"; return new HttpServer( new SocketServer($uri, $options, $loop), @@ -115,9 +115,7 @@ protected static function configureTls(array $context, ?string $hostname): array { $context = array_filter($context, fn ($value) => $value !== null); - $usesTls = ($context['local_cert'] ?? false) || ($context['local_pk'] ?? false); - - if (! $usesTls && $hostname && Certificate::exists($hostname)) { + if (! static::usesTls($context) && $hostname && Certificate::exists($hostname)) { [$certificate, $key] = Certificate::resolve($hostname); $context['local_cert'] = $certificate; @@ -127,4 +125,14 @@ protected static function configureTls(array $context, ?string $hostname): array return $context; } + + /** + * Determine whether the server uses TLS. + * + * @param array $context + */ + protected static function usesTls(array $context): bool + { + return ($context['local_cert'] ?? false) || ($context['local_pk'] ?? false); + } }