mirror of
https://github.com/danog/tgseclib.git
synced 2024-11-30 04:39:02 +01:00
RSA: changes to putty plugin and rm comment methods from rsa etc
This commit is contained in:
parent
fb22529c44
commit
cfcf554531
@ -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
|
||||
*
|
||||
|
@ -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),
|
||||
|
@ -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('#(?<!\r)\n#', "\r\n", $key);
|
||||
$this->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');
|
||||
|
Loading…
Reference in New Issue
Block a user