Skip to content

Commit

Permalink
RSA: changes to putty plugin and rm comment methods from rsa etc
Browse files Browse the repository at this point in the history
  • Loading branch information
terrafrost committed Oct 2, 2015
1 parent fb22529 commit 2420d7a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 32 deletions.
28 changes: 1 addition & 27 deletions phpseclib/Crypt/RSA.php
Expand Up @@ -661,8 +661,7 @@ function load($key, $type = false)
$this->mgfHLen = $key->mgfHLen;
$this->encryptionMode = $key->encryptionMode;
$this->signatureMode = $key->signatureMode;
$this->password = $key->password;
$this->comment = $key->comment;
$this->password = $key->password

if (is_object($key->hash)) {
$this->hash = new Hash($key->hash->getHash());
Expand Down Expand Up @@ -728,9 +727,6 @@ function load($key, $type = false)
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'];
Expand Down Expand Up @@ -2022,28 +2018,6 @@ function setSignatureMode($mode)
$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
*
Expand Down
11 changes: 8 additions & 3 deletions phpseclib/Crypt/RSA/PuTTY.php
Expand Up @@ -16,6 +16,7 @@

use phpseclib\Math\BigInteger;
use phpseclib\Crypt\AES;
use phpseclib\Crypt\Hash;

/**
* PuTTY Formatted RSA Key Handler
Expand Down Expand Up @@ -75,6 +76,11 @@ static function generateSymmetricKey($password, $length)
*/
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]));
Expand Down Expand Up @@ -126,9 +132,9 @@ static function load($key, $password = '')
}
$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)));
Expand Down Expand Up @@ -177,7 +183,6 @@ static function savePrivateKey(BigInteger $n, BigInteger $e, BigInteger $d, $pri
}

$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),
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Crypt/RSA/LoadKeyTest.php
Expand Up @@ -6,6 +6,7 @@
*/

use phpseclib\Crypt\RSA;
use phpseclib\Crypt\RSA\PKCS1;

class Unit_Crypt_RSA_LoadKeyTest extends PhpseclibTestCase
{
Expand Down Expand Up @@ -347,8 +348,7 @@ public function testPKCS1EncryptionChange()

$encryptedKey = (string) $key;

// 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');
Expand Down

0 comments on commit 2420d7a

Please sign in to comment.