mirror of
https://github.com/danog/phpseclib.git
synced 2025-01-05 20:28:27 +01:00
Merge branch '3.0'
This commit is contained in:
commit
11ece32b3f
@ -1119,7 +1119,11 @@ class X509
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (!feof($fsock)) {
|
while (!feof($fsock)) {
|
||||||
$data.= fread($fsock, 1024);
|
$temp = fread($fsock, 1024);
|
||||||
|
if ($temp === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$data.= $temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
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) {
|
if (strlen($temp) == 255) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ($temp === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$line.= "$temp\n";
|
$line.= "$temp\n";
|
||||||
|
|
||||||
|
@ -50,6 +50,8 @@ use phpseclib3\Crypt\PublicKeyLoader;
|
|||||||
*/
|
*/
|
||||||
class Agent
|
class Agent
|
||||||
{
|
{
|
||||||
|
use Common\Traits\ReadBytes;
|
||||||
|
|
||||||
/**#@+
|
/**#@+
|
||||||
* Message numbers
|
* Message numbers
|
||||||
*
|
*
|
||||||
@ -177,11 +179,8 @@ class Agent
|
|||||||
throw new \RuntimeException('Connection closed while requesting identities');
|
throw new \RuntimeException('Connection closed while requesting identities');
|
||||||
}
|
}
|
||||||
|
|
||||||
$length = current(unpack('N', fread($this->fsock, 4)));
|
$length = current(unpack('N', $this->readBytes(4)));
|
||||||
$packet = fread($this->fsock, $length);
|
$packet = $this->readBytes($length);
|
||||||
if (strlen($packet) != $length) {
|
|
||||||
throw new \LengthException("Expected $length bytes; got " . strlen($packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
list($type, $keyCount) = Strings::unpackSSH2('CN', $packet);
|
list($type, $keyCount) = Strings::unpackSSH2('CN', $packet);
|
||||||
if ($type != self::SSH_AGENT_IDENTITIES_ANSWER) {
|
if ($type != self::SSH_AGENT_IDENTITIES_ANSWER) {
|
||||||
@ -295,9 +294,9 @@ class Agent
|
|||||||
$this->socket_buffer = '';
|
$this->socket_buffer = '';
|
||||||
$this->expected_bytes = 0;
|
$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));
|
$agent_reply_data = current(unpack('a*', $agent_reply_data));
|
||||||
|
|
||||||
return pack('Na*', $agent_reply_bytes, $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\RSA;
|
||||||
use phpseclib3\Crypt\DSA;
|
use phpseclib3\Crypt\DSA;
|
||||||
use phpseclib3\Crypt\ECDSA;
|
use phpseclib3\Crypt\EC;
|
||||||
use phpseclib3\Exception\UnsupportedAlgorithmException;
|
use phpseclib3\Exception\UnsupportedAlgorithmException;
|
||||||
use phpseclib3\System\SSH\Agent;
|
use phpseclib3\System\SSH\Agent;
|
||||||
use phpseclib3\Common\Functions\Strings;
|
use phpseclib3\Common\Functions\Strings;
|
||||||
use phpseclib3\Crypt\Common\PrivateKey;
|
use phpseclib3\Crypt\Common\PrivateKey;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pure-PHP ssh-agent client identity object
|
* Pure-PHP ssh-agent client identity object
|
||||||
*
|
*
|
||||||
@ -40,6 +39,8 @@ use phpseclib3\Crypt\Common\PrivateKey;
|
|||||||
*/
|
*/
|
||||||
class Identity implements PrivateKey
|
class Identity implements PrivateKey
|
||||||
{
|
{
|
||||||
|
use \phpseclib3\System\SSH\Common\Traits\ReadBytes;
|
||||||
|
|
||||||
/**@+
|
/**@+
|
||||||
* Signature Flags
|
* Signature Flags
|
||||||
*
|
*
|
||||||
@ -191,7 +192,7 @@ class Identity implements PrivateKey
|
|||||||
throw new UnsupportedAlgorithmException('The only supported hashes for RSA are sha1, sha256 and sha512');
|
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()) {
|
switch ($this->key->getCurve()) {
|
||||||
case 'secp256r1':
|
case 'secp256r1':
|
||||||
$expectedHash = 'sha256';
|
$expectedHash = 'sha256';
|
||||||
@ -246,7 +247,7 @@ class Identity implements PrivateKey
|
|||||||
public function withSignatureFormat($format)
|
public function withSignatureFormat($format)
|
||||||
{
|
{
|
||||||
if ($this->key instanceof RSA) {
|
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') {
|
if ($format != 'SSH2') {
|
||||||
throw new UnsupportedAlgorithmException('Only SSH2-formatted signatures are currently supported');
|
throw new UnsupportedAlgorithmException('Only SSH2-formatted signatures are currently supported');
|
||||||
@ -265,8 +266,8 @@ class Identity implements PrivateKey
|
|||||||
*/
|
*/
|
||||||
public function getCurve()
|
public function getCurve()
|
||||||
{
|
{
|
||||||
if (!$this->key instanceof ECDSA) {
|
if (!$this->key instanceof EC) {
|
||||||
throw new UnsupportedAlgorithmException('Only ECDSA keys have curves');
|
throw new UnsupportedAlgorithmException('Only EC keys have curves');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->key->getCurve();
|
return $this->key->getCurve();
|
||||||
@ -299,8 +300,8 @@ class Identity implements PrivateKey
|
|||||||
throw new \RuntimeException('Connection closed during signing');
|
throw new \RuntimeException('Connection closed during signing');
|
||||||
}
|
}
|
||||||
|
|
||||||
$length = current(unpack('N', fread($this->fsock, 4)));
|
$length = current(unpack('N', $this->readBytes(4)));
|
||||||
$packet = fread($this->fsock, $length);
|
$packet = $this->readBytes($length);
|
||||||
|
|
||||||
list($type, $signature_blob) = Strings::unpackSSH2('Cs', $packet);
|
list($type, $signature_blob) = Strings::unpackSSH2('Cs', $packet);
|
||||||
if ($type != Agent::SSH_AGENT_SIGN_RESPONSE) {
|
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