From ac97ce5d69888f785b1db37d1c4d4dc34e942aff Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 3 Apr 2016 21:34:11 -0500 Subject: [PATCH 1/2] RSA: backport macdabby's changes --- phpseclib/Crypt/RSA.php | 4 ++-- tests/Unit/Crypt/RSA/LoadKeyTest.php | 34 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 9369d437..997d2d86 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -1786,7 +1786,7 @@ class Crypt_RSA function setPrivateKey($key = false, $type = false) { if ($key === false && !empty($this->publicExponent)) { - unset($this->publicExponent); + $this->publicExponent = false; return true; } @@ -1794,7 +1794,7 @@ class Crypt_RSA if (!$rsa->loadKey($key, $type)) { return false; } - unset($rsa->publicExponent); + $rsa->publicExponent = false; // don't overwrite the old key if the new key is invalid $this->loadKey($rsa); diff --git a/tests/Unit/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php index 7c09a890..91539bc0 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -345,4 +345,38 @@ Z2sKniRCcDT1ZP4= $this->assertTrue($result); } + + /** + * @group github960 + */ + public function testSetLoad() + { + $key = 'PuTTY-User-Key-File-2: ssh-rsa +Encryption: aes256-cbc +Comment: phpseclib-generated-key +Public-Lines: 4 +AAAAB3NzaC1yc2EAAAADAQABAAAAgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4 +eCZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RK +NUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDy +R4e9T04ZZw== +Private-Lines: 8 +llx04QMegql0/nE5RvcJSrGrodxt6ytuv/JX2caeZBUyQwQc2WBNYagLHyHPM9jI +9OUWz59FLhjFXZMDNMoUXxVmjwQpOAaVPYNxxFM9AF6/NXFji64K7huD9n4A+kLn +sHwMLWPR5a/tZA0r05DZNz9ULA3mQu7Hz4EQ8ifu3uTPJuTmL51x6RmudYKysb20 +fM8VzC3ukvzzRh0pujUVTr/yQdmciASVFnZlt4xQy+ZEOVUAOfwjd//AFfXTvk6x +7A45rNlU/uicHwLgoY1APvRHCFxw7F+uVW5L4mSX7NNzqBKkZ+1qpQTAfQvIfEIb +444+CXsgIyOpqt6VxJH2u6elAtE1wau3YaFR8Alm8m97rFYzRi3oDP5NZYkTCWSV +EOpSeghXSs7IilJu8I6/sB1w5dakdeBSFkIynrlFXkO0uUw+QJJWjxY8SypzgIuP +DzduF6XsQrCyo6dnIpGQCQ== +Private-MAC: 35134b7434bf828b21404099861d455e660e8740'; + + $rsa = new Crypt_RSA(); + $rsa->setPrivateKey($key); + $rsa->loadKey($key); + + $rsa = new Crypt_RSA(); + $rsa->loadKey($key); + $rsa->setPrivateKey(); + $rsa->loadKey($rsa); + } } From 8f614a053810e8dfac4f2aad6af59a7b369cfd8e Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 3 Apr 2016 21:35:33 -0500 Subject: [PATCH 2/2] RSA: update macdabby's changes to work on 2.0 branch --- tests/Unit/Crypt/RSA/LoadKeyTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php index f4698f83..a535fd44 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -371,11 +371,11 @@ EOpSeghXSs7IilJu8I6/sB1w5dakdeBSFkIynrlFXkO0uUw+QJJWjxY8SypzgIuP DzduF6XsQrCyo6dnIpGQCQ== Private-MAC: 35134b7434bf828b21404099861d455e660e8740'; - $rsa = new Crypt_RSA(); + $rsa = new RSA(); $rsa->setPrivateKey($key); $rsa->loadKey($key); - $rsa = new Crypt_RSA(); + $rsa = new RSA(); $rsa->loadKey($key); $rsa->setPrivateKey(); $rsa->loadKey($rsa);