Merge branch '2.0' into 3.0

This commit is contained in:
terrafrost 2020-02-01 22:50:28 -06:00
commit 7387d79a4f
6 changed files with 1706 additions and 11 deletions

View File

@ -1119,7 +1119,11 @@ class X509
}
while (!feof($fsock)) {
$data.= fread($fsock, 1024);
$temp = fread($fsock, 1024);
if ($temp === false) {
return false;
}
$data.= $temp;
}
break;

1645
phpseclib/Net/SSH1.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1255,6 +1255,9 @@ class SSH2
if (strlen($temp) == 255) {
continue;
}
if ($temp === false) {
return false;
}
$line.= "$temp\n";

View File

@ -50,6 +50,8 @@ use phpseclib3\Crypt\PublicKeyLoader;
*/
class Agent
{
use Common\Traits\ReadBytes;
/**#@+
* Message numbers
*
@ -177,11 +179,8 @@ class Agent
throw new \RuntimeException('Connection closed while requesting identities');
}
$length = current(unpack('N', fread($this->fsock, 4)));
$packet = fread($this->fsock, $length);
if (strlen($packet) != $length) {
throw new \LengthException("Expected $length bytes; got " . strlen($packet));
}
$length = current(unpack('N', $this->readBytes(4)));
$packet = $this->readBytes($length);
list($type, $keyCount) = Strings::unpackSSH2('CN', $packet);
if ($type != self::SSH_AGENT_IDENTITIES_ANSWER) {
@ -295,9 +294,9 @@ class Agent
$this->socket_buffer = '';
$this->expected_bytes = 0;
$agent_reply_bytes = current(unpack('N', fread($this->fsock, 4)));
$agent_reply_bytes = current(unpack('N', $this->readBytes(4)));
$agent_reply_data = fread($this->fsock, $agent_reply_bytes);
$agent_reply_data = $this->readBytes($agent_reply_bytes);
$agent_reply_data = current(unpack('a*', $agent_reply_data));
return pack('Na*', $agent_reply_bytes, $agent_reply_data);

View File

@ -24,7 +24,6 @@ use phpseclib3\System\SSH\Agent;
use phpseclib3\Common\Functions\Strings;
use phpseclib3\Crypt\Common\PrivateKey;
/**
* Pure-PHP ssh-agent client identity object
*
@ -40,6 +39,8 @@ use phpseclib3\Crypt\Common\PrivateKey;
*/
class Identity implements PrivateKey
{
use \phpseclib3\System\SSH\Common\Traits\ReadBytes;
/**@+
* Signature Flags
*
@ -299,8 +300,8 @@ class Identity implements PrivateKey
throw new \RuntimeException('Connection closed during signing');
}
$length = current(unpack('N', fread($this->fsock, 4)));
$packet = fread($this->fsock, $length);
$length = current(unpack('N', $this->readBytes(4)));
$packet = $this->readBytes($length);
list($type, $signature_blob) = Strings::unpackSSH2('Cs', $packet);
if ($type != Agent::SSH_AGENT_SIGN_RESPONSE) {

View File

@ -0,0 +1,43 @@
<?php
/**
* ReadBytes trait
*
* PHP version 5
*
* @category System
* @package SSH
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2015 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
*/
namespace phpseclib3\System\SSH\Common\Traits;
/**
* ReadBytes trait
*
* @package SSH
* @author Jim Wigginton <terrafrost@php.net>
* @access public
*/
trait ReadBytes
{
/**
* Read data
*
* @param string $data
* @return string Data from SSH Agent
* @throws \RuntimeException on connection errors
* @access public
*/
public function readBytes($length)
{
$temp = fread($this->fsock, $length);
if (strlen($temp) != $length) {
throw new \RuntimeException("Expected $length bytes; got " . strlen($temp));
}
return $temp;
}
}