Skip to content

Commit

Permalink
[1.x] Improve TLS check (#158)
Browse files Browse the repository at this point in the history
* improve tls check

* wip
  • Loading branch information
joedixon authored Apr 18, 2024
1 parent 77fb819 commit 3c415cd
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']) ? "tls://{$host}:{$port}" : "{$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 @@ -127,4 +125,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 3c415cd

Please sign in to comment.