From 89a73161cbe9887526928a223758d2009162216b Mon Sep 17 00:00:00 2001 From: DAB Date: Fri, 25 Mar 2016 22:10:36 -0500 Subject: [PATCH 1/6] set publicExponent to false instead of unsetting --- phpseclib/Crypt/RSA.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index ac9101ae..48192c58 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -966,7 +966,7 @@ class RSA if (!$rsa->load($key, $type)) { return false; } - unset($rsa->publicExponent); + $rsa->publicExponent = false; // don't overwrite the old key if the new key is invalid $this->load($rsa); From 3b37619279bcb8f8d232d60292b6088dd6cf2a33 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 3 Apr 2016 21:16:37 -0500 Subject: [PATCH 2/6] Tests/RSA: add unit test for setPrivateKey --- phpseclib/Crypt/RSA.php | 2 +- tests/Unit/Crypt/RSA/LoadKeyTest.php | 34 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 48192c58..20883ee1 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -958,7 +958,7 @@ class RSA function setPrivateKey($key = false, $type = false) { if ($key === false && !empty($this->publicExponent)) { - unset($this->publicExponent); + $rsa->publicExponent = false; return true; } diff --git a/tests/Unit/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php index 85de2b3c..5f84e698 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -500,4 +500,38 @@ ILaEujU= $this->assertGreaterThanOrEqual(1, strlen("$rsa")); } + + /** + * @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 RSA(); + $rsa->setPrivateKey($key); + $rsa->load($key); + + $rsa = new RSA(); + $rsa->load($key); + $rsa->setPrivateKey(); + $rsa->load($rsa); + } } From ac97ce5d69888f785b1db37d1c4d4dc34e942aff Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 3 Apr 2016 21:34:11 -0500 Subject: [PATCH 3/6] 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 4/6] 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); From 383bceb1a9e4683df2b5c32b6ae783d8c7c4823f Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 3 Apr 2016 22:07:49 -0500 Subject: [PATCH 5/6] Tests/RSA: fix bad merge --- tests/Unit/Crypt/RSA/LoadKeyTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php index 6cc79b21..9d78f78f 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -350,7 +350,6 @@ Z2sKniRCcDT1ZP4= $this->assertTrue($result); } -<<<<<<< HEAD public function testPKCS1EncryptionChange() { $rsa = new RSA(); @@ -536,3 +535,4 @@ Private-MAC: 35134b7434bf828b21404099861d455e660e8740'; $rsa->load($rsa); } } + From a3000aac28e7c5165105f3ebf487371d58d859a6 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 3 Apr 2016 22:56:48 -0500 Subject: [PATCH 6/6] Tests/RSA: CS adjustment --- tests/Unit/Crypt/RSA/LoadKeyTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php index 9d78f78f..5f84e698 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -535,4 +535,3 @@ Private-MAC: 35134b7434bf828b21404099861d455e660e8740'; $rsa->load($rsa); } } -