From f089aa4eb9ca6cf23542ef4285e6e2cdc15fc576 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 29 May 2017 06:20:46 -0500 Subject: [PATCH 1/3] Tests/RSA: add unit test for loading bad key after loading good key --- tests/Unit/Crypt/RSA/LoadKeyTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Unit/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php index 11bf750c..b5095ca7 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -400,4 +400,23 @@ AAIBAAIBAAIBAAIBAA== $rsa->sign('zzzz'); } + + public function testGoodBad() + { + $rsa = new Crypt_RSA(); + + $key = '-----BEGIN RSA PUBLIC KEY----- +MIIBCgKCAQEA61BjmfXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa +D1MVlcrYG6XRKfkcxnaXGfFDWHLEvNBSEVCgJjtHAGZIm5GL/KA86KDp/CwDFMSw +luowcXwDwoyinmeOY9eKyh6aY72xJh7noLBBq1N0bWi1e2i+83txOCg4yV2oVXhB +o8pYEJ8LT3el6Smxol3C1oFMVdwPgc0vTl25XucMcG/ALE/KNY6pqC2AQ6R2ERlV +gPiUWOPatVkt7+Bs3h5Ramxh7XjBOXeulmCpGSynXNcpZ/06+vofGi/2MlpQZNhH +Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB +-----END RSA PUBLIC KEY-----'; + + $this->assertTrue($rsa->loadKey($key)); + $this->assertInternalType('string', $rsa->getPublicKey()); + $this->assertFalse($rsa->loadKey('zzz')); + $this->assertFalse($rsa->getPublicKey()); + } } From a451dd69f85dd3c8c1c9b6542a6c0393a9f6b0b9 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 29 May 2017 06:31:54 -0500 Subject: [PATCH 2/3] RSA: reset variables if bad key was loaded --- phpseclib/Crypt/RSA.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 3eacfe16..b734c9f8 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -1661,6 +1661,15 @@ class Crypt_RSA } if ($components === false) { + $this->comment = null; + $this->modulus = null; + $this->k = null; + $this->exponent = null; + $this->primes = null; + $this->exponents = null; + $this->coefficients = null; + $this->publicExponent = null; + return false; } From fe8f1bba7b822646c7ad3dc22fd6ec561e7fff32 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 29 May 2017 06:33:01 -0500 Subject: [PATCH 3/3] Tests/RSA: update unit test for 2.0 branch --- 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 c0d43848..7890b7ef 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -404,7 +404,7 @@ AAIBAAIBAAIBAAIBAA== public function testGoodBad() { - $rsa = new Crypt_RSA(); + $rsa = new RSA(); $key = '-----BEGIN RSA PUBLIC KEY----- MIIBCgKCAQEA61BjmfXGEvWmegnBGSuS+rU9soUg2FnODva32D1AqhwdziwHINFa