Skip to content

Commit

Permalink
Fix openssl error reporting (#512)
Browse files Browse the repository at this point in the history
Fix openssl error reporting
  • Loading branch information
Spomky authored Feb 1, 2024
1 parent 80361f4 commit bc76770
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Library/KeyManagement/KeyConverter/KeyConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +50,7 @@ public static function loadKeyFromCertificate(string $certificate): array
throw new RuntimeException('Please install the OpenSSL extension');
}

$errorReporting = error_reporting(E_ERROR | E_PARSE);
try {
$res = openssl_x509_read($certificate);
if ($res === false) {
Expand All @@ -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.');
Expand Down

0 comments on commit bc76770

Please sign in to comment.