From eb659a5544bf244b98d2e7f098c18bc56e8c1fa1 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 28 Jun 2019 08:58:20 -0500 Subject: [PATCH] set password in load methods for each pubkey instead of in loader --- phpseclib/Crypt/Common/AsymmetricKey.php | 10 +++++++-- phpseclib/Crypt/PublicKeyLoader.php | 26 ++++++++---------------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/phpseclib/Crypt/Common/AsymmetricKey.php b/phpseclib/Crypt/Common/AsymmetricKey.php index 82e15cdf..4bd532e4 100644 --- a/phpseclib/Crypt/Common/AsymmetricKey.php +++ b/phpseclib/Crypt/Common/AsymmetricKey.php @@ -171,7 +171,10 @@ abstract class AsymmetricKey $components['format'] = $format; - return static::onLoad($components); + $new = static::onLoad($components); + return $new instanceof PrivateKey ? + $new->withPassword($password) : + $new; } /** @@ -199,7 +202,10 @@ abstract class AsymmetricKey $components['format'] = $format; - return static::onLoad($components); + $new = static::onLoad($components); + return $new instanceof PrivateKey ? + $new->withPassword($password) : + $new; } /** diff --git a/phpseclib/Crypt/PublicKeyLoader.php b/phpseclib/Crypt/PublicKeyLoader.php index b65c5b2b..a1fdee98 100644 --- a/phpseclib/Crypt/PublicKeyLoader.php +++ b/phpseclib/Crypt/PublicKeyLoader.php @@ -39,26 +39,16 @@ abstract class PublicKeyLoader public static function load($key, $password = false) { try { - $new = EC::load($key, $password); - } catch (\Exception $e) {} + return EC::load($key, $password); + } catch (NoKeyLoadedException $e) {} - if (!isset($new)) { - try { - $new = RSA::load($key, $password); - } catch (\Exception $e) {} - } + try { + return RSA::load($key, $password); + } catch (NoKeyLoadedException $e) {} - if (!isset($new)) { - try { - $new = DSA::load($key, $password); - } catch (\Exception $e) {} - } - - if (isset($new)) { - return $new instanceof PrivateKey ? - $new->withPassword($password) : - $new; - } + try { + return DSA::load($key, $password); + } catch (NoKeyLoadedException $e) {} try { $x509 = new X509();