mirror of
https://github.com/danog/phpseclib.git
synced 2024-12-15 02:17:04 +01:00
Merge branch '3.0'
This commit is contained in:
commit
11ece32b3f
@ -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
1645
phpseclib/Net/SSH1.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -1255,6 +1255,9 @@ class SSH2
|
||||
if (strlen($temp) == 255) {
|
||||
continue;
|
||||
}
|
||||
if ($temp === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$line.= "$temp\n";
|
||||
|
||||
|
@ -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);
|
||||
|
@ -18,13 +18,12 @@ namespace phpseclib3\System\SSH\Agent;
|
||||
|
||||
use phpseclib3\Crypt\RSA;
|
||||
use phpseclib3\Crypt\DSA;
|
||||
use phpseclib3\Crypt\ECDSA;
|
||||
use phpseclib3\Crypt\EC;
|
||||
use phpseclib3\Exception\UnsupportedAlgorithmException;
|
||||
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
|
||||
*
|
||||
@ -191,7 +192,7 @@ class Identity implements PrivateKey
|
||||
throw new UnsupportedAlgorithmException('The only supported hashes for RSA are sha1, sha256 and sha512');
|
||||
}
|
||||
}
|
||||
if ($this->key instanceof ECDSA) {
|
||||
if ($this->key instanceof EC) {
|
||||
switch ($this->key->getCurve()) {
|
||||
case 'secp256r1':
|
||||
$expectedHash = 'sha256';
|
||||
@ -246,7 +247,7 @@ class Identity implements PrivateKey
|
||||
public function withSignatureFormat($format)
|
||||
{
|
||||
if ($this->key instanceof RSA) {
|
||||
throw new UnsupportedAlgorithmException('Only DSA and ECDSA keys support signature format setting');
|
||||
throw new UnsupportedAlgorithmException('Only DSA and EC keys support signature format setting');
|
||||
}
|
||||
if ($format != 'SSH2') {
|
||||
throw new UnsupportedAlgorithmException('Only SSH2-formatted signatures are currently supported');
|
||||
@ -265,8 +266,8 @@ class Identity implements PrivateKey
|
||||
*/
|
||||
public function getCurve()
|
||||
{
|
||||
if (!$this->key instanceof ECDSA) {
|
||||
throw new UnsupportedAlgorithmException('Only ECDSA keys have curves');
|
||||
if (!$this->key instanceof EC) {
|
||||
throw new UnsupportedAlgorithmException('Only EC keys have curves');
|
||||
}
|
||||
|
||||
return $this->key->getCurve();
|
||||
@ -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) {
|
||||
|
43
phpseclib/System/SSH/Common/Traits/ReadBytes.php
Normal file
43
phpseclib/System/SSH/Common/Traits/ReadBytes.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user