From f125520417a1a81456e6c66d35cb173c180847c4 Mon Sep 17 00:00:00 2001 From: Gonen Radai Date: Tue, 8 Aug 2017 15:31:07 +0300 Subject: [PATCH] add support to get private key as string instead of file path/name from SP metadata configuration --- lib/SimpleSAML/Utils/Crypto.php | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/SimpleSAML/Utils/Crypto.php b/lib/SimpleSAML/Utils/Crypto.php index c5578055d9..c8f6e79625 100644 --- a/lib/SimpleSAML/Utils/Crypto.php +++ b/lib/SimpleSAML/Utils/Crypto.php @@ -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.'"'); }