diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 186fcc08..defb464d 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -662,7 +662,6 @@ class RSA $this->encryptionMode = $key->encryptionMode; $this->signatureMode = $key->signatureMode; $this->password = $key->password; - $this->comment = $key->comment; if (is_object($key->hash)) { $this->hash = new Hash($key->hash->getHash()); @@ -728,9 +727,6 @@ class RSA return false; } - if (isset($components['comment']) && $components['comment'] !== false) { - $this->comment = $components['comment']; - } $this->modulus = $components['modulus']; $this->k = strlen($this->modulus->toBytes()); $this->exponent = isset($components['privateExponent']) ? $components['privateExponent'] : $components['publicExponent']; @@ -2022,28 +2018,6 @@ class RSA $this->signatureMode = $mode; } - /** - * Set public key comment. - * - * @access public - * @param string $comment - */ - function setComment($comment) - { - $this->comment = $comment; - } - - /** - * Get public key comment. - * - * @access public - * @return string - */ - function getComment() - { - return $this->comment; - } - /** * Encryption * diff --git a/phpseclib/Crypt/RSA/PuTTY.php b/phpseclib/Crypt/RSA/PuTTY.php index 014eaa47..a4d804bc 100644 --- a/phpseclib/Crypt/RSA/PuTTY.php +++ b/phpseclib/Crypt/RSA/PuTTY.php @@ -16,6 +16,7 @@ namespace phpseclib\Crypt\RSA; use phpseclib\Math\BigInteger; use phpseclib\Crypt\AES; +use phpseclib\Crypt\Hash; /** * PuTTY Formatted RSA Key Handler @@ -75,6 +76,11 @@ class PuTTY */ static function load($key, $password = '') { + static $one; + if (!isset($one)) { + $one = new BigInteger(1); + } + $components = array('isPublicKey' => false); $key = preg_split('#\r\n|\r|\n#', $key); $type = trim(preg_replace('#PuTTY-User-Key-File-2: (.+)#', '$1', $key[0])); @@ -126,9 +132,9 @@ class PuTTY } $components['primes'][] = new BigInteger(self::_string_shift($private, $length), -256); - $temp = $components['primes'][1]->subtract(self::$one); + $temp = $components['primes'][1]->subtract($one); $components['exponents'] = array(1 => $components['publicExponent']->modInverse($temp)); - $temp = $components['primes'][2]->subtract(self::$one); + $temp = $components['primes'][2]->subtract($one); $components['exponents'][] = $components['publicExponent']->modInverse($temp); extract(unpack('Nlength', self::_string_shift($private, 4))); @@ -177,7 +183,6 @@ class PuTTY } $raw = array( - 'version' => $num_primes == 2 ? chr(0) : chr(1), // two-prime vs. multi 'modulus' => $n->toBytes(true), 'publicExponent' => $e->toBytes(true), 'privateExponent' => $d->toBytes(true), diff --git a/tests/Unit/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php index e6739e05..ee28863d 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -6,6 +6,7 @@ */ use phpseclib\Crypt\RSA; +use phpseclib\Crypt\RSA\PKCS1; class Unit_Crypt_RSA_LoadKeyTest extends PhpseclibTestCase { @@ -339,16 +340,17 @@ rmfPwIGm63ilAAAAQQDEIvkdBvZtCvgHKitwxab+EQ/YxnNE5XvfIXjWE+xEL2br oquF470c9Mm6jf/2zmn6yobE6UUvQ0O3hKSiyOAbAAAAQBGoiuSoSjafUhV7i1cE Gpb88h5NBYZzWXGZ37sJ5QsW+sJyoNde3xH8vdXhzU7eT82D6X/scw9RZz+/6rCJ 4p0= -Private-MAC: 03e2cb74e1d67652fbad063d2ed0478f31bdf256'; +Private-MAC: 03e2cb74e1d67652fbad063d2ed0478f31bdf256 +'; + $key = preg_replace('#(?assertTrue($rsa->load($key)); PKCS1::setEncryptionAlgorithm('AES-256-CBC'); $rsa->setPassword('demo'); - $encryptedKey = (string) $key; + $encryptedKey = (string) $rsa; - // change back to the original format to demonstrate that this doesn't break anything - PKCS1::setEncryptionAlgorithm('DES-EDE3-CBC'); + $this->assertRegExp('#AES-256-CBC#', $encryptedKey); $rsa = new RSA(); $rsa->setPassword('demo');