Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix openssl error reporting #512

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading