diff --git a/composer.json b/composer.json index 081da7f..365900b 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "require": { "php": ">=8.0", "laminas/laminas-diagnostics": "^1.24", - "pimcore/pimcore": "^10.0" + "pimcore/pimcore": "^10.0", + "spatie/ssl-certificate": "^2.4" }, "require-dev": { "deployer/deployer": "^7.1", diff --git a/src/PimcoreMonitorBundle/Check/HttpsConnection.php b/src/PimcoreMonitorBundle/Check/HttpsConnection.php index 0e030c2..58ba868 100644 --- a/src/PimcoreMonitorBundle/Check/HttpsConnection.php +++ b/src/PimcoreMonitorBundle/Check/HttpsConnection.php @@ -22,6 +22,7 @@ use Laminas\Diagnostics\Result\Skip; use Laminas\Diagnostics\Result\Success; use Laminas\Diagnostics\Result\Warning; +use Spatie\SslCertificate\SslCertificate; class HttpsConnection extends AbstractCheck { @@ -44,24 +45,9 @@ public function check(): ResultInterface return new Warning('HTTPS encryption could not be checked'); } - // Create a stream context - $stream = \stream_context_create(['ssl' => ['capture_peer_cert' => true]]); - $url = \sprintf('https://%s', $host); + $certificate = SslCertificate::createForHostName($host); - try { - // Bind the resource $url to $stream - $read = \fopen($url, 'rb', false, $stream); - - // Get the stream parameters - $params = \stream_context_get_params($read); - } catch (\Exception) { - // Ignore exceptions thrown ... - } - - // Check if SSL certificate is present - $cert = $params['options']['ssl']['peer_certificate'] ?? null; - - if (null === $cert) { + if ($certificate->isValid() === false) { return new Failure('HTTPS encryption not activated', false); }