Skip to content
Open
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
24 changes: 16 additions & 8 deletions lib/SimpleSAML/Utils/Crypto.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,28 @@ public static function loadPrivateKey(
bool $full_path = false
): ?array {
$file = $metadata->getString($prefix . 'privatekey', null);

if ($file === null) {
// no private key found
if ($required) {
throw new Error\Exception('No private key found in metadata.');
} else {
return null;
// try getting the privatekeydata
$data = $metadata->getString($prefix . 'privatekeydata', null);
if ($data === null) {
if ($required) {
throw new Error\Exception('No private key found in metadata.');
} else {
return null;
}
}
}

if (!$full_path) {
$file = Config::getCertPath($file);
// file could be still null if privateKey was passed as string in configuration throutgh privatekeydata
if ($file !== null) {
if (!$full_path) {
$file = Config::getCertPath($file);
}
$data = @file_get_contents($file);
}

$data = @file_get_contents($file);

if ($data === false) {
throw new Error\Exception('Unable to load private key from file "' . $file . '"');
}
Expand Down