Skip to content

Commit

Permalink
improve tls check
Browse files Browse the repository at this point in the history
  • Loading branch information
joedixon committed Apr 18, 2024
1 parent bf6b6f8 commit 9c12e2d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Servers/Reverb/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) ? "{$host}:{$port}" : "tls://{$host}:{$port}";

return new HttpServer(
new SocketServer($uri, $options, $loop),
Expand Down Expand Up @@ -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;
Expand All @@ -126,4 +124,14 @@ protected static function configureTls(array $context, ?string $hostname): array

return $context;
}

/**
* Determine whether the server uses TLS.
*
* @param array $context<string, mixed>
*/
protected static function usesTls(array $context): bool
{
return ($context['local_cert'] ?? false) || ($context['local_pk'] ?? false);
}
}

0 comments on commit 9c12e2d

Please sign in to comment.