Skip to content

Commit

Permalink
Bugfix: only append prefix for files, not PEM-encoded keys
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Sep 3, 2024
1 parent ef11095 commit 1007102
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Key/PrivateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ public static function fromFile(
#[\SensitiveParameter]
string $passphrase = '',
): static {
if (preg_match('/^(file:\/\/)/i', $file) !== 1) {
$file = preg_filter('/^/', 'file://', $file);
if (preg_match(PEM::PEM_REGEX, $file) !== 1) {
// Not a PEM-encoded key. Must be a file
if (preg_match('/^(file:\/\/)/i', $file) !== 1) {
$file = preg_filter('/^/', 'file://', $file);
}
}

if (($key = openssl_pkey_get_private($file, $passphrase)) === false) {
Expand Down

0 comments on commit 1007102

Please sign in to comment.