From 3b018527c1b541329d11ac2cf8eaf9db37f7a9c3 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Thu, 1 Feb 2024 15:46:00 +0100 Subject: [PATCH 1/2] Fix openssl error reporting --- src/Library/KeyManagement/KeyConverter/KeyConverter.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Library/KeyManagement/KeyConverter/KeyConverter.php b/src/Library/KeyManagement/KeyConverter/KeyConverter.php index 9acd843c..19335f7b 100644 --- a/src/Library/KeyManagement/KeyConverter/KeyConverter.php +++ b/src/Library/KeyManagement/KeyConverter/KeyConverter.php @@ -18,6 +18,8 @@ use function in_array; use function is_array; use function is_string; +use const E_ERROR; +use const E_PARSE; use const OPENSSL_KEYTYPE_EC; use const OPENSSL_KEYTYPE_RSA; use const OPENSSL_RAW_DATA; @@ -49,6 +51,7 @@ public static function loadKeyFromCertificate(string $certificate): array } try { + $errorReporting = error_reporting(E_ERROR | E_PARSE); $res = openssl_x509_read($certificate); if ($res === false) { throw new InvalidArgumentException('Unable to load the certificate.'); @@ -56,6 +59,8 @@ public static function loadKeyFromCertificate(string $certificate): array } catch (Throwable) { $certificate = self::convertDerToPem($certificate); $res = openssl_x509_read($certificate); + } finally { + error_reporting($errorReporting); } if ($res === false) { throw new InvalidArgumentException('Unable to load the certificate.'); From 2b9ae6d39a84ad1b3c3f83931c1fe0f149af40ba Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Thu, 1 Feb 2024 15:47:41 +0100 Subject: [PATCH 2/2] Fix openssl error reporting --- src/Library/KeyManagement/KeyConverter/KeyConverter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Library/KeyManagement/KeyConverter/KeyConverter.php b/src/Library/KeyManagement/KeyConverter/KeyConverter.php index 19335f7b..d9c3bd72 100644 --- a/src/Library/KeyManagement/KeyConverter/KeyConverter.php +++ b/src/Library/KeyManagement/KeyConverter/KeyConverter.php @@ -50,8 +50,8 @@ public static function loadKeyFromCertificate(string $certificate): array throw new RuntimeException('Please install the OpenSSL extension'); } + $errorReporting = error_reporting(E_ERROR | E_PARSE); try { - $errorReporting = error_reporting(E_ERROR | E_PARSE); $res = openssl_x509_read($certificate); if ($res === false) { throw new InvalidArgumentException('Unable to load the certificate.');