From b65bad4a1d9f9ccca1b55a14ec29667f34ffc2e1 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 18 Jan 2020 21:58:48 -0600 Subject: [PATCH 1/2] Tests/RSA: add unit test for PuTTY public keys --- tests/Unit/Crypt/RSA/LoadKeyTest.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Unit/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php index 4c3c3449..9c9173d4 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -980,4 +980,18 @@ Vyaqr/WTPzxdXJAAAADHJvb3RAdmFncmFudAECAwQFBg== $this->assertTrue($key->verify('zzz', $sig)); } + + public function testPuTTYPublic() + { + $orig = '---- BEGIN SSH2 PUBLIC KEY ---- +Comment: "phpseclib-generated-key" +AAAAB3NzaC1yc2EAAAADAQABAAAAQQCo9+BpMRYQ/dL3DS2CyJxRF+j6ctbT3/Qp +84+KeFhnii7NT7fELilKUSnxS30WAvQCCo2yU1orfgqr41mM70MB +---- END SSH2 PUBLIC KEY ----'; + + $orig = preg_replace('#(?assertSame($orig, $key->toString('PuTTY')); + } } From 0afd386114f567f19806af7142406b5f6c1ca5e7 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 18 Jan 2020 22:12:00 -0600 Subject: [PATCH 2/2] RSA: PuTTY public keys couldn't be saved --- phpseclib/Crypt/RSA/Formats/Keys/PuTTY.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Crypt/RSA/Formats/Keys/PuTTY.php b/phpseclib/Crypt/RSA/Formats/Keys/PuTTY.php index 30acd328..4c93b873 100644 --- a/phpseclib/Crypt/RSA/Formats/Keys/PuTTY.php +++ b/phpseclib/Crypt/RSA/Formats/Keys/PuTTY.php @@ -125,6 +125,6 @@ abstract class PuTTY extends Progenitor */ public static function savePublicKey(BigInteger $n, BigInteger $e) { - return self::wrapPublicKey(Strings::packSSH2($e, $n), 'ssh-rsa'); + return self::wrapPublicKey(Strings::packSSH2('ii', $e, $n), 'ssh-rsa'); } }