Skip to content

Commit

Permalink
add support to get private key as string instead of file path/name fr…
Browse files Browse the repository at this point in the history
…om SP metadata configuration
  • Loading branch information
gonenradai authored and tvdijen committed Jun 6, 2019
1 parent f5989a7 commit f125520
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/SimpleSAML/Utils/Crypto.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,25 @@ public static function loadPrivateKey(Configuration $metadata, $required = false
$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

0 comments on commit f125520

Please sign in to comment.