This commit is contained in:
terrafrost 2016-04-28 10:29:11 -05:00
commit a521bd405f
8 changed files with 63 additions and 10 deletions

View File

@ -387,7 +387,7 @@ class Crypt_RC2 extends Crypt_Base
/**
* Sets the key length.
*
* Valid key lengths are 1 to 1024.
* Valid key lengths are 8 to 1024.
* Calling this function after setting the key has no effect until the next
* Crypt_RC2::setKey() call.
*
@ -396,9 +396,16 @@ class Crypt_RC2 extends Crypt_Base
*/
function setKeyLength($length)
{
if ($length >= 1 && $length <= 1024) {
if ($length < 8) {
$this->default_key_length = 8;
} elseif ($length > 1024) {
$this->default_key_length = 128;
} else {
$this->default_key_length = $length;
}
$this->current_key_length = $this->default_key_length;
parent::setKeyLength($length);
}
/**
@ -415,7 +422,7 @@ class Crypt_RC2 extends Crypt_Base
/**
* Sets the key.
*
* Keys can be of any length. RC2, itself, uses 1 to 1024 bit keys (eg.
* Keys can be of any length. RC2, itself, uses 8 to 1024 bit keys (eg.
* strlen($key) <= 128), however, we only use the first 128 bytes if $key
* has more then 128 bytes in it, and set $key to a single null byte if
* it is empty.

View File

@ -234,7 +234,7 @@ class Crypt_RC4 extends Crypt_Base
if ($length < 8) {
$this->key_length = 1;
} elseif ($length > 2048) {
$this->key_length = 248;
$this->key_length = 256;
} else {
$this->key_length = $length >> 3;
}

View File

@ -1786,7 +1786,7 @@ class Crypt_RSA
function setPrivateKey($key = false, $type = false)
{
if ($key === false && !empty($this->publicExponent)) {
unset($this->publicExponent);
$this->publicExponent = false;
return true;
}
@ -1794,7 +1794,7 @@ class Crypt_RSA
if (!$rsa->loadKey($key, $type)) {
return false;
}
unset($rsa->publicExponent);
$rsa->publicExponent = false;
// don't overwrite the old key if the new key is invalid
$this->loadKey($rsa);

View File

@ -1842,7 +1842,7 @@ class Math_BigInteger
// calculate the appropriate window size.
// $window_size == 3 if $window_ranges is between 25 and 81, for example.
for ($i = 0, $window_size = 1; $e_length > $window_ranges[$i] && $i < count($window_ranges); ++$window_size, ++$i) {
for ($i = 0, $window_size = 1; $i < count($window_ranges) && $e_length > $window_ranges[$i]; ++$window_size, ++$i) {
}
$n_value = $n->value;

View File

@ -789,7 +789,7 @@ class Net_SFTP extends Net_SSH2
{
$files = $this->_list($dir, false);
if (!$recursive) {
if (!$recursive || $files === false) {
return $files;
}

View File

@ -320,9 +320,10 @@ class System_SSH_Agent
for ($i = 0; $i < $keyCount; $i++) {
$length = current(unpack('N', fread($this->fsock, 4)));
$key_blob = fread($this->fsock, $length);
$key_str = 'ssh-rsa ' . base64_encode($key_blob);
$length = current(unpack('N', fread($this->fsock, 4)));
if ($length) {
$key_comment = fread($this->fsock, $length);
$key_str.= ' ' . fread($this->fsock, $length);
}
$length = current(unpack('N', substr($key_blob, 0, 4)));
$key_type = substr($key_blob, 4, $length);
@ -332,7 +333,7 @@ class System_SSH_Agent
include_once 'Crypt/RSA.php';
}
$key = new Crypt_RSA();
$key->loadKey('ssh-rsa ' . base64_encode($key_blob) . ' ' . $key_comment);
$key->loadKey($key_str);
break;
case 'ssh-dss':
// not currently supported

View File

@ -345,4 +345,38 @@ Z2sKniRCcDT1ZP4=
$this->assertTrue($result);
}
/**
* @group github960
*/
public function testSetLoad()
{
$key = 'PuTTY-User-Key-File-2: ssh-rsa
Encryption: aes256-cbc
Comment: phpseclib-generated-key
Public-Lines: 4
AAAAB3NzaC1yc2EAAAADAQABAAAAgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4
eCZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RK
NUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDy
R4e9T04ZZw==
Private-Lines: 8
llx04QMegql0/nE5RvcJSrGrodxt6ytuv/JX2caeZBUyQwQc2WBNYagLHyHPM9jI
9OUWz59FLhjFXZMDNMoUXxVmjwQpOAaVPYNxxFM9AF6/NXFji64K7huD9n4A+kLn
sHwMLWPR5a/tZA0r05DZNz9ULA3mQu7Hz4EQ8ifu3uTPJuTmL51x6RmudYKysb20
fM8VzC3ukvzzRh0pujUVTr/yQdmciASVFnZlt4xQy+ZEOVUAOfwjd//AFfXTvk6x
7A45rNlU/uicHwLgoY1APvRHCFxw7F+uVW5L4mSX7NNzqBKkZ+1qpQTAfQvIfEIb
444+CXsgIyOpqt6VxJH2u6elAtE1wau3YaFR8Alm8m97rFYzRi3oDP5NZYkTCWSV
EOpSeghXSs7IilJu8I6/sB1w5dakdeBSFkIynrlFXkO0uUw+QJJWjxY8SypzgIuP
DzduF6XsQrCyo6dnIpGQCQ==
Private-MAC: 35134b7434bf828b21404099861d455e660e8740';
$rsa = new Crypt_RSA();
$rsa->setPrivateKey($key);
$rsa->loadKey($key);
$rsa = new Crypt_RSA();
$rsa->loadKey($key);
$rsa->setPrivateKey();
$rsa->loadKey($rsa);
}
}

View File

@ -374,4 +374,15 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
$this->assertContains('[value] => 0x32', $str);
return $str;
}
/**
* @group github954
*/
public function testSlidingWindow()
{
$e = $this->getInstance(str_repeat('1', 1794), 2);
$x = $this->getInstance(1);
$n = $this->getInstance(2);
$x->powMod($e, $n);
}
}