mirror of
https://github.com/danog/tgseclib.git
synced 2025-01-21 21:41:14 +01:00
Merge remote-tracking branch 'upstream/master' into dsa-test-2
This commit is contained in:
commit
42def63b00
65
README.md
65
README.md
@ -6,17 +6,37 @@ MIT-licensed pure-PHP implementations of an arbitrary-precision integer
|
||||
arithmetic library, fully PKCS#1 (v2.1) compliant RSA, DES, 3DES, RC4, Rijndael,
|
||||
AES, Blowfish, Twofish, SSH-1, SSH-2, SFTP, and X.509
|
||||
|
||||
* [Download (1.0.5)](http://sourceforge.net/projects/phpseclib/files/phpseclib1.0.5.zip/download)
|
||||
* [Browse Git](https://github.com/phpseclib/phpseclib)
|
||||
* [Code Coverage Report](http://phpseclib.bantux.org/code_coverage/master/latest/)
|
||||
|
||||
<img src="http://phpseclib.sourceforge.net/pear-icon.png" alt="PEAR Channel" width="16" height="16">
|
||||
PEAR Channel: [phpseclib.sourceforge.net](http://phpseclib.sourceforge.net/pear.htm)
|
||||
* [Code Coverage Report](https://coverage.phpseclib.org/master/latest/)
|
||||
|
||||
## Documentation
|
||||
|
||||
* [Documentation / Manual](http://phpseclib.sourceforge.net/)
|
||||
* [API Documentation](http://phpseclib.bantux.org/api/master/) (generated by Sami)
|
||||
* [API Documentation](https://api.phpseclib.org/master/) (generated by Sami)
|
||||
|
||||
## Branches
|
||||
|
||||
### master
|
||||
|
||||
* Development Branch
|
||||
* Unstable API
|
||||
* Do not use in production
|
||||
|
||||
### 2.0
|
||||
|
||||
* Modernized version of 1.0
|
||||
* Minimum PHP version: 5.3.3
|
||||
* PSR-4 autoloading with namespace rooted at `\phpseclib`
|
||||
* Install via Composer: `composer require phpseclib/phpseclib ~2.0`
|
||||
|
||||
### 1.0
|
||||
|
||||
* Long term support (LTS) release
|
||||
* PHP4 compatible
|
||||
* Composer compatible (PSR-0 autoloading)
|
||||
* Install using Composer: `composer require phpseclib/phpseclib ~1.0`
|
||||
* Install using PEAR: See [phpseclib PEAR Channel Documentation](http://phpseclib.sourceforge.net/pear.htm)
|
||||
* [Download 1.0.5 as ZIP](http://sourceforge.net/projects/phpseclib/files/phpseclib1.0.5.zip/download)
|
||||
|
||||
## Support
|
||||
|
||||
@ -26,40 +46,29 @@ Need Support?
|
||||
* [Create a Support Ticket on GitHub](https://github.com/phpseclib/phpseclib/issues/new)
|
||||
* [Browse the Support Forum](http://www.frostjedi.com/phpbb/viewforum.php?f=46) (no longer in use)
|
||||
|
||||
## Installing Development Dependencies
|
||||
|
||||
Dependencies are managed via Composer.
|
||||
|
||||
1. Download the [`composer.phar`](https://getcomposer.org/composer.phar) executable as per the
|
||||
[Composer Download Instructions](https://getcomposer.org/download/), e.g. by running
|
||||
|
||||
``` sh
|
||||
curl -sS https://getcomposer.org/installer | php
|
||||
```
|
||||
|
||||
2. Install Dependencies
|
||||
|
||||
``` sh
|
||||
php composer.phar install
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
1. Fork the Project
|
||||
|
||||
2. Install Development Dependencies
|
||||
2. Ensure you have Composer installed (see [Composer Download Instructions](https://getcomposer.org/download/))
|
||||
|
||||
3. Create a Feature Branch
|
||||
3. Install Development Dependencies
|
||||
|
||||
4. (Recommended) Run the Test Suite
|
||||
``` sh
|
||||
composer install
|
||||
```
|
||||
|
||||
4. Create a Feature Branch
|
||||
|
||||
5. (Recommended) Run the Test Suite
|
||||
|
||||
``` sh
|
||||
vendor/bin/phpunit
|
||||
```
|
||||
5. (Recommended) Check whether your code conforms to our Coding Standards by running
|
||||
6. (Recommended) Check whether your code conforms to our Coding Standards by running
|
||||
|
||||
``` sh
|
||||
vendor/bin/phing -f build/build.xml sniff
|
||||
```
|
||||
|
||||
6. Send us a Pull Request
|
||||
7. Send us a Pull Request
|
||||
|
75
phpseclib/Common/Functions/Objects.php
Normal file
75
phpseclib/Common/Functions/Objects.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Common Object Functions
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Common
|
||||
* @package Functions\Objects
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
* @copyright 2016 Jim Wigginton
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link http://phpseclib.sourceforge.net
|
||||
*/
|
||||
|
||||
namespace phpseclib\Common\Functions;
|
||||
|
||||
/**
|
||||
* Common Object Functions
|
||||
*
|
||||
* @package Functions\Objects
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
abstract class Objects
|
||||
{
|
||||
/**
|
||||
* Accesses a private variable from an object
|
||||
*
|
||||
* @param Object $obj
|
||||
* @param string $var
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public static function getVar($obj, $var)
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($obj));
|
||||
$prop = $reflection->getProperty($var);
|
||||
$prop->setAccessible(true);
|
||||
return $prop->getValue($obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of a private variable in an object
|
||||
*
|
||||
* @param Object $obj
|
||||
* @param string $var
|
||||
* @param mixed $val
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public static function setVar($obj, $var, $val)
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($obj));
|
||||
$prop = $reflection->getProperty($var);
|
||||
$prop->setAccessible(true);
|
||||
return $prop->setValue($obj, $val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accesses a private method from an object
|
||||
*
|
||||
* @param Object $obj
|
||||
* @param string $func
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
public static function callFunc($obj, $func, $params = array())
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($obj));
|
||||
$method = $reflection->getMethod($func);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($obj, $params);
|
||||
}
|
||||
}
|
@ -333,7 +333,7 @@ class Blowfish extends BlockCipher
|
||||
public function isValidEngine($engine)
|
||||
{
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
if ($this->key_length != 16) {
|
||||
if ($this->key_length < 16) {
|
||||
return false;
|
||||
}
|
||||
$this->cipher_name_openssl_ecb = 'bf-ecb';
|
||||
|
@ -144,21 +144,8 @@ class RC4 extends StreamCipher
|
||||
*/
|
||||
public function isValidEngine($engine)
|
||||
{
|
||||
switch ($engine) {
|
||||
case self::ENGINE_OPENSSL:
|
||||
switch (strlen($this->key)) {
|
||||
case 5:
|
||||
$this->cipher_name_openssl = 'rc4-40';
|
||||
break;
|
||||
case 8:
|
||||
$this->cipher_name_openssl = 'rc4-64';
|
||||
break;
|
||||
case 16:
|
||||
$this->cipher_name_openssl = 'rc4';
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if ($engine == self::ENGINE_OPENSSL) {
|
||||
$this->cipher_name_openssl = 'rc4-40';
|
||||
}
|
||||
|
||||
return parent::isValidEngine($engine);
|
||||
|
@ -885,6 +885,9 @@ class X509
|
||||
// "SET Secure Electronic Transaction Specification"
|
||||
// http://www.maithean.com/docs/set_bk3.pdf
|
||||
case '2.23.42.7.0': // id-set-hashedRootKey
|
||||
// "Certificate Transparency"
|
||||
// https://tools.ietf.org/html/rfc6962
|
||||
case '1.3.6.1.4.1.11129.2.4.2':
|
||||
return true;
|
||||
|
||||
// CSR attributes
|
||||
|
@ -167,23 +167,23 @@ class BigInteger
|
||||
*
|
||||
* @see __construct()
|
||||
*/
|
||||
protected static $base;
|
||||
protected static $baseFull;
|
||||
protected static $maxDigit;
|
||||
protected static $msb;
|
||||
private static $base;
|
||||
private static $baseFull;
|
||||
private static $maxDigit;
|
||||
private static $msb;
|
||||
|
||||
/**
|
||||
* $max10 in greatest $max10Len satisfying
|
||||
* $max10 = 10**$max10Len <= 2**$base.
|
||||
*/
|
||||
protected static $max10;
|
||||
private static $max10;
|
||||
|
||||
/**
|
||||
* $max10Len in greatest $max10Len satisfying
|
||||
* $max10 = 10**$max10Len <= 2**$base.
|
||||
*/
|
||||
protected static $max10Len;
|
||||
protected static $maxDigit2;
|
||||
private static $max10Len;
|
||||
private static $maxDigit2;
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
@ -192,7 +192,7 @@ class BigInteger
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $value;
|
||||
private $value;
|
||||
|
||||
/**
|
||||
* Holds the BigInteger's magnitude.
|
||||
@ -200,7 +200,7 @@ class BigInteger
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $is_negative = false;
|
||||
private $is_negative = false;
|
||||
|
||||
/**
|
||||
* Precision
|
||||
@ -208,7 +208,7 @@ class BigInteger
|
||||
* @see self::setPrecision()
|
||||
* @access private
|
||||
*/
|
||||
var $precision = -1;
|
||||
private $precision = -1;
|
||||
|
||||
/**
|
||||
* Precision Bitmask
|
||||
@ -216,7 +216,7 @@ class BigInteger
|
||||
* @see self::setPrecision()
|
||||
* @access private
|
||||
*/
|
||||
var $bitmask = false;
|
||||
private $bitmask = false;
|
||||
|
||||
/**
|
||||
* Mode independent value used for serialization.
|
||||
@ -230,7 +230,7 @@ class BigInteger
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $hex;
|
||||
private $hex;
|
||||
|
||||
/**
|
||||
* Converts base-2, base-10, base-16, and binary strings (base-256) to BigIntegers.
|
||||
@ -252,7 +252,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
function __construct($x = 0, $base = 10)
|
||||
public function __construct($x = 0, $base = 10)
|
||||
{
|
||||
if (!defined('MATH_BIGINTEGER_MODE')) {
|
||||
switch (true) {
|
||||
@ -491,7 +491,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal Converts a base-2**26 number to base-2**8
|
||||
*/
|
||||
function toBytes($twos_compliment = false)
|
||||
public function toBytes($twos_compliment = false)
|
||||
{
|
||||
if ($twos_compliment) {
|
||||
$comparison = $this->compare(new static());
|
||||
@ -584,7 +584,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal Converts a base-2**26 number to base-2**8
|
||||
*/
|
||||
function toHex($twos_compliment = false)
|
||||
public function toHex($twos_compliment = false)
|
||||
{
|
||||
return Hex::encode($this->toBytes($twos_compliment));
|
||||
}
|
||||
@ -609,7 +609,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal Converts a base-2**26 number to base-2**2
|
||||
*/
|
||||
function toBits($twos_compliment = false)
|
||||
public function toBits($twos_compliment = false)
|
||||
{
|
||||
$hex = $this->toHex($twos_compliment);
|
||||
$bits = '';
|
||||
@ -644,7 +644,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal Converts a base-2**26 number to base-10**7 (which is pretty much base-10)
|
||||
*/
|
||||
function toString()
|
||||
public function toString()
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -692,7 +692,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal Implemented per a suggestion by Techie-Michael - thanks!
|
||||
*/
|
||||
function __toString()
|
||||
public function __toString()
|
||||
{
|
||||
return $this->toString();
|
||||
}
|
||||
@ -705,7 +705,7 @@ class BigInteger
|
||||
* @see self::__wakeup()
|
||||
* @access public
|
||||
*/
|
||||
function __sleep()
|
||||
public function __sleep()
|
||||
{
|
||||
$this->hex = $this->toHex(true);
|
||||
$vars = ['hex'];
|
||||
@ -723,7 +723,7 @@ class BigInteger
|
||||
* @see self::__sleep()
|
||||
* @access public
|
||||
*/
|
||||
function __wakeup()
|
||||
public function __wakeup()
|
||||
{
|
||||
$temp = new static($this->hex, -16);
|
||||
$this->value = $temp->value;
|
||||
@ -741,7 +741,7 @@ class BigInteger
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function __debugInfo()
|
||||
public function __debugInfo()
|
||||
{
|
||||
$opts = [];
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
@ -787,7 +787,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal Performs base-2**52 addition
|
||||
*/
|
||||
function add(BigInteger $y)
|
||||
public function add(BigInteger $y)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -821,7 +821,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _add($x_value, $x_negative, $y_value, $y_negative)
|
||||
private static function _add($x_value, $x_negative, $y_value, $y_negative)
|
||||
{
|
||||
$x_size = count($x_value);
|
||||
$y_size = count($y_value);
|
||||
@ -916,7 +916,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal Performs base-2**52 subtraction
|
||||
*/
|
||||
function subtract(BigInteger $y)
|
||||
public function subtract(BigInteger $y)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -950,7 +950,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _subtract($x_value, $x_negative, $y_value, $y_negative)
|
||||
private static function _subtract($x_value, $x_negative, $y_value, $y_negative)
|
||||
{
|
||||
$x_size = count($x_value);
|
||||
$y_size = count($y_value);
|
||||
@ -1049,7 +1049,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
function multiply(BigInteger $x)
|
||||
public function multiply(BigInteger $x)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -1083,7 +1083,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _multiply($x_value, $x_negative, $y_value, $y_negative)
|
||||
private static function _multiply($x_value, $x_negative, $y_value, $y_negative)
|
||||
{
|
||||
//if ( $x_value == $y_value ) {
|
||||
// return [
|
||||
@ -1120,7 +1120,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _regularMultiply($x_value, $y_value)
|
||||
private static function _regularMultiply($x_value, $y_value)
|
||||
{
|
||||
$x_length = count($x_value);
|
||||
$y_length = count($y_value);
|
||||
@ -1184,7 +1184,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _karatsuba($x_value, $y_value)
|
||||
private static function _karatsuba($x_value, $y_value)
|
||||
{
|
||||
$m = min(count($x_value) >> 1, count($y_value) >> 1);
|
||||
|
||||
@ -1222,7 +1222,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _square($x = false)
|
||||
private static function _square($x = false)
|
||||
{
|
||||
return count($x) < 2 * self::KARATSUBA_CUTOFF ?
|
||||
self::_trim(self::_baseSquare($x)) :
|
||||
@ -1240,7 +1240,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _baseSquare($value)
|
||||
private static function _baseSquare($value)
|
||||
{
|
||||
if (empty($value)) {
|
||||
return [];
|
||||
@ -1279,7 +1279,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _karatsubaSquare($value)
|
||||
private static function _karatsubaSquare($value)
|
||||
{
|
||||
$m = count($value) >> 1;
|
||||
|
||||
@ -1334,7 +1334,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal This function is based off of {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=9 HAC 14.20}.
|
||||
*/
|
||||
function divide(BigInteger $y)
|
||||
public function divide(BigInteger $y)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -1515,7 +1515,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _divide_digit($dividend, $divisor)
|
||||
private static function _divide_digit($dividend, $divisor)
|
||||
{
|
||||
$carry = 0;
|
||||
$result = [];
|
||||
@ -1569,7 +1569,7 @@ class BigInteger
|
||||
* the other, a power of two - and recombine them, later. This is the method that this modPow function uses.
|
||||
* {@link http://islab.oregonstate.edu/papers/j34monex.pdf Montgomery Reduction with Even Modulus} elaborates.
|
||||
*/
|
||||
function modPow(BigInteger $e, BigInteger $n)
|
||||
public function modPow(BigInteger $e, BigInteger $n)
|
||||
{
|
||||
$n = $this->bitmask !== false && $this->bitmask->compare($n) < 0 ? $this->bitmask : $n->abs();
|
||||
|
||||
@ -1720,7 +1720,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
function powMod(BigInteger $e, BigInteger $n)
|
||||
public function powMod(BigInteger $e, BigInteger $n)
|
||||
{
|
||||
return $this->modPow($e, $n);
|
||||
}
|
||||
@ -1739,7 +1739,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access private
|
||||
*/
|
||||
function _slidingWindow($e, $n, $mode)
|
||||
private function _slidingWindow($e, $n, $mode)
|
||||
{
|
||||
static $window_ranges = [7, 25, 81, 241, 673, 1793]; // from BigInteger.java's oddModPow function
|
||||
//static $window_ranges = [0, 7, 36, 140, 450, 1303, 3529]; // from MPM 7.3.1
|
||||
@ -1816,7 +1816,7 @@ class BigInteger
|
||||
* @param int $mode
|
||||
* @return array
|
||||
*/
|
||||
static function _reduce($x, $n, $mode)
|
||||
private static function _reduce($x, $n, $mode)
|
||||
{
|
||||
switch ($mode) {
|
||||
case self::MONTGOMERY:
|
||||
@ -1853,7 +1853,7 @@ class BigInteger
|
||||
* @param int $mode
|
||||
* @return array
|
||||
*/
|
||||
static function _prepareReduce($x, $n, $mode)
|
||||
private static function _prepareReduce($x, $n, $mode)
|
||||
{
|
||||
if ($mode == self::MONTGOMERY) {
|
||||
return self::_prepMontgomery($x, $n);
|
||||
@ -1872,7 +1872,7 @@ class BigInteger
|
||||
* @param int $mode
|
||||
* @return array
|
||||
*/
|
||||
static function _multiplyReduce($x, $y, $n, $mode)
|
||||
private static function _multiplyReduce($x, $y, $n, $mode)
|
||||
{
|
||||
if ($mode == self::MONTGOMERY) {
|
||||
return self::_montgomeryMultiply($x, $y, $n);
|
||||
@ -1891,7 +1891,7 @@ class BigInteger
|
||||
* @param int $mode
|
||||
* @return array
|
||||
*/
|
||||
static function _squareReduce($x, $n, $mode)
|
||||
private static function _squareReduce($x, $n, $mode)
|
||||
{
|
||||
if ($mode == self::MONTGOMERY) {
|
||||
return self::_montgomeryMultiply($x, $x, $n);
|
||||
@ -1910,7 +1910,7 @@ class BigInteger
|
||||
* @param \phpseclib\Math\BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
function _mod2($n)
|
||||
private function _mod2($n)
|
||||
{
|
||||
$temp = new static();
|
||||
$temp->value = [1];
|
||||
@ -1941,7 +1941,7 @@ class BigInteger
|
||||
* @param array $m
|
||||
* @return array
|
||||
*/
|
||||
static function _barrett($n, $m)
|
||||
private static function _barrett($n, $m)
|
||||
{
|
||||
static $cache = [
|
||||
self::VARIABLE => [],
|
||||
@ -2038,7 +2038,7 @@ class BigInteger
|
||||
* @param array $n
|
||||
* @return array
|
||||
*/
|
||||
static function _regularBarrett($x, $n)
|
||||
private static function _regularBarrett($x, $n)
|
||||
{
|
||||
static $cache = [
|
||||
self::VARIABLE => [],
|
||||
@ -2112,7 +2112,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _multiplyLower($x_value, $x_negative, $y_value, $y_negative, $stop)
|
||||
private static function _multiplyLower($x_value, $x_negative, $y_value, $y_negative, $stop)
|
||||
{
|
||||
$x_length = count($x_value);
|
||||
$y_length = count($y_value);
|
||||
@ -2191,7 +2191,7 @@ class BigInteger
|
||||
* @param array $n
|
||||
* @return array
|
||||
*/
|
||||
static function _montgomery($x, $n)
|
||||
private static function _montgomery($x, $n)
|
||||
{
|
||||
static $cache = [
|
||||
self::VARIABLE => [],
|
||||
@ -2239,7 +2239,7 @@ class BigInteger
|
||||
* @param array $m
|
||||
* @return array
|
||||
*/
|
||||
static function _montgomeryMultiply($x, $y, $m)
|
||||
private static function _montgomeryMultiply($x, $y, $m)
|
||||
{
|
||||
$temp = self::_multiply($x, false, $y, false);
|
||||
return self::_montgomery($temp[self::VALUE], $m);
|
||||
@ -2290,7 +2290,7 @@ class BigInteger
|
||||
* @param array $n
|
||||
* @return array
|
||||
*/
|
||||
static function _prepMontgomery($x, $n)
|
||||
private static function _prepMontgomery($x, $n)
|
||||
{
|
||||
$lhs = new static();
|
||||
$lhs->value = array_merge(self::_array_repeat(0, count($n)), $x);
|
||||
@ -2327,7 +2327,7 @@ class BigInteger
|
||||
* @param array $x
|
||||
* @return int
|
||||
*/
|
||||
function _modInverse67108864($x) // 2**26 == 67,108,864
|
||||
private function _modInverse67108864($x) // 2**26 == 67,108,864
|
||||
{
|
||||
$x = -$x[0];
|
||||
$result = $x & 0x3; // x**-1 mod 2**2
|
||||
@ -2365,7 +2365,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=21 HAC 14.64} for more information.
|
||||
*/
|
||||
function modInverse(BigInteger $n)
|
||||
public function modInverse(BigInteger $n)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -2429,7 +2429,7 @@ class BigInteger
|
||||
* {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap14.pdf#page=19 HAC 14.61}. As the text above 14.61 notes,
|
||||
* the more traditional algorithim requires "relatively costly multiple-precision divisions".
|
||||
*/
|
||||
function extendedGCD(BigInteger $n)
|
||||
public function extendedGCD(BigInteger $n)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -2558,7 +2558,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
function gcd(BigInteger $n)
|
||||
public function gcd(BigInteger $n)
|
||||
{
|
||||
extract($this->extendedGCD($n));
|
||||
return $gcd;
|
||||
@ -2570,7 +2570,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
function abs()
|
||||
public function abs()
|
||||
{
|
||||
$temp = new static();
|
||||
|
||||
@ -2606,7 +2606,7 @@ class BigInteger
|
||||
* @see self::equals()
|
||||
* @internal Could return $this->subtract($x), but that's not as fast as what we do do.
|
||||
*/
|
||||
function compare(BigInteger $y)
|
||||
public function compare(BigInteger $y)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -2629,7 +2629,7 @@ class BigInteger
|
||||
* @see self::compare()
|
||||
* @access private
|
||||
*/
|
||||
static function _compare($x_value, $x_negative, $y_value, $y_negative)
|
||||
private static function _compare($x_value, $x_negative, $y_value, $y_negative)
|
||||
{
|
||||
if ($x_negative != $y_negative) {
|
||||
return (!$x_negative && $y_negative) ? 1 : -1;
|
||||
@ -2664,7 +2664,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @see self::compare()
|
||||
*/
|
||||
function equals(BigInteger $x)
|
||||
public function equals(BigInteger $x)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -2683,7 +2683,7 @@ class BigInteger
|
||||
* @param int $bits
|
||||
* @access public
|
||||
*/
|
||||
function setPrecision($bits)
|
||||
public function setPrecision($bits)
|
||||
{
|
||||
if ($bits < 1) {
|
||||
$this->precision = -1;
|
||||
@ -2709,7 +2709,7 @@ class BigInteger
|
||||
* @see self::setPrecision()
|
||||
* @access public
|
||||
*/
|
||||
function getPrecision()
|
||||
public function getPrecision()
|
||||
{
|
||||
return $this->precision;
|
||||
}
|
||||
@ -2722,7 +2722,7 @@ class BigInteger
|
||||
* @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
function bitwise_and(BigInteger $x)
|
||||
public function bitwise_and(BigInteger $x)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -2763,7 +2763,7 @@ class BigInteger
|
||||
* @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
function bitwise_or(BigInteger $x)
|
||||
public function bitwise_or(BigInteger $x)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -2803,7 +2803,7 @@ class BigInteger
|
||||
* @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
function bitwise_xor(BigInteger $x)
|
||||
public function bitwise_xor(BigInteger $x)
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -2842,7 +2842,7 @@ class BigInteger
|
||||
* @internal Implemented per a request by Lluis Pamies i Juarez <lluis _a_ pamies.cat>
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
function bitwise_not()
|
||||
public function bitwise_not()
|
||||
{
|
||||
// calculuate "not" without regard to $this->precision
|
||||
// (will always result in a smaller number. ie. ~1 isn't 1111 1110 - it's 0)
|
||||
@ -2885,7 +2885,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal The only version that yields any speed increases is the internal version.
|
||||
*/
|
||||
function bitwise_rightShift($shift)
|
||||
public function bitwise_rightShift($shift)
|
||||
{
|
||||
$temp = new static();
|
||||
|
||||
@ -2923,7 +2923,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal The only version that yields any speed increases is the internal version.
|
||||
*/
|
||||
function bitwise_leftShift($shift)
|
||||
public function bitwise_leftShift($shift)
|
||||
{
|
||||
$temp = new static();
|
||||
|
||||
@ -2960,7 +2960,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
function bitwise_leftRotate($shift)
|
||||
public function bitwise_leftRotate($shift)
|
||||
{
|
||||
$bits = $this->toBytes();
|
||||
|
||||
@ -3005,7 +3005,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
function bitwise_rightRotate($shift)
|
||||
public function bitwise_rightRotate($shift)
|
||||
{
|
||||
return $this->bitwise_leftRotate(-$shift);
|
||||
}
|
||||
@ -3017,7 +3017,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
static function minMaxBits($bits)
|
||||
public static function minMaxBits($bits)
|
||||
{
|
||||
$bytes = $bits >> 3;
|
||||
$min = str_repeat(chr(0), $bytes);
|
||||
@ -3044,7 +3044,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
static function random($size)
|
||||
public static function random($size)
|
||||
{
|
||||
extract(self::minMaxBits($size));
|
||||
return self::randomRange($min, $max);
|
||||
@ -3064,7 +3064,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
static function randomRange(BigInteger $min, BigInteger $max)
|
||||
public static function randomRange(BigInteger $min, BigInteger $max)
|
||||
{
|
||||
$compare = $max->compare($min);
|
||||
|
||||
@ -3130,7 +3130,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access public
|
||||
*/
|
||||
static function randomPrime($size)
|
||||
public static function randomPrime($size)
|
||||
{
|
||||
extract(self::minMaxBits($size));
|
||||
return self::randomRangePrime($min, $max);
|
||||
@ -3147,7 +3147,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @internal See {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=15 HAC 4.44}.
|
||||
*/
|
||||
static function randomRangePrime(BigInteger $min, BigInteger $max)
|
||||
public static function randomRangePrime(BigInteger $min, BigInteger $max)
|
||||
{
|
||||
$compare = $max->compare($min);
|
||||
|
||||
@ -3229,7 +3229,7 @@ class BigInteger
|
||||
* @see self::randomPrime()
|
||||
* @access private
|
||||
*/
|
||||
function _make_odd()
|
||||
private function _make_odd()
|
||||
{
|
||||
switch (MATH_BIGINTEGER_MODE) {
|
||||
case self::MODE_GMP:
|
||||
@ -3259,7 +3259,7 @@ class BigInteger
|
||||
* {@link http://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test Miller-Rabin primality test}. See
|
||||
* {@link http://www.cacr.math.uwaterloo.ca/hac/about/chap4.pdf#page=8 HAC 4.24}.
|
||||
*/
|
||||
function isPrime($t = false)
|
||||
public function isPrime($t = false)
|
||||
{
|
||||
$length = strlen($this->toBytes());
|
||||
|
||||
@ -3408,7 +3408,7 @@ class BigInteger
|
||||
* @param int $shift
|
||||
* @access private
|
||||
*/
|
||||
function _lshift($shift)
|
||||
private function _lshift($shift)
|
||||
{
|
||||
if ($shift == 0) {
|
||||
return;
|
||||
@ -3443,7 +3443,7 @@ class BigInteger
|
||||
* @param int $shift
|
||||
* @access private
|
||||
*/
|
||||
function _rshift($shift)
|
||||
private function _rshift($shift)
|
||||
{
|
||||
if ($shift == 0) {
|
||||
return;
|
||||
@ -3479,7 +3479,7 @@ class BigInteger
|
||||
* @see self::_trim()
|
||||
* @access private
|
||||
*/
|
||||
function _normalize($result)
|
||||
private function _normalize($result)
|
||||
{
|
||||
$result->precision = $this->precision;
|
||||
$result->bitmask = $this->bitmask;
|
||||
@ -3528,7 +3528,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @access private
|
||||
*/
|
||||
static function _trim($value)
|
||||
private static function _trim($value)
|
||||
{
|
||||
for ($i = count($value) - 1; $i >= 0; --$i) {
|
||||
if ($value[$i]) {
|
||||
@ -3548,7 +3548,7 @@ class BigInteger
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
static function _array_repeat($input, $multiplier)
|
||||
private static function _array_repeat($input, $multiplier)
|
||||
{
|
||||
return ($multiplier) ? array_fill(0, $multiplier, $input) : [];
|
||||
}
|
||||
@ -3563,7 +3563,7 @@ class BigInteger
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
static function _base256_lshift(&$x, $shift)
|
||||
private static function _base256_lshift(&$x, $shift)
|
||||
{
|
||||
if ($shift == 0) {
|
||||
return;
|
||||
@ -3592,7 +3592,7 @@ class BigInteger
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
static function _base256_rshift(&$x, $shift)
|
||||
private static function _base256_rshift(&$x, $shift)
|
||||
{
|
||||
if ($shift == 0) {
|
||||
$x = ltrim($x, chr(0));
|
||||
@ -3633,7 +3633,7 @@ class BigInteger
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
static function _int2bytes($x)
|
||||
private static function _int2bytes($x)
|
||||
{
|
||||
return ltrim(pack('N', $x), chr(0));
|
||||
}
|
||||
@ -3645,7 +3645,7 @@ class BigInteger
|
||||
* @return int
|
||||
* @access private
|
||||
*/
|
||||
static function _bytes2int($x)
|
||||
private static function _bytes2int($x)
|
||||
{
|
||||
$temp = unpack('Nint', str_pad($x, 4, chr(0), STR_PAD_LEFT));
|
||||
return $temp['int'];
|
||||
@ -3664,7 +3664,7 @@ class BigInteger
|
||||
* @param int $y
|
||||
* @return int
|
||||
*/
|
||||
static function _safe_divide($x, $y)
|
||||
private static function _safe_divide($x, $y)
|
||||
{
|
||||
if (self::$base === 26) {
|
||||
return (int) ($x / $y);
|
||||
@ -3695,7 +3695,7 @@ class BigInteger
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
* @internal This function is based off of {@link http://mathforum.org/library/drmath/view/52605.html this page} and {@link http://stackoverflow.com/questions/11242920/calculating-nth-root-with-bcmath-in-php this stackoverflow question}.
|
||||
*/
|
||||
function root($n = null)
|
||||
public function root($n = null)
|
||||
{
|
||||
static $zero, $one, $two;
|
||||
if (!isset($one)) {
|
||||
@ -3777,7 +3777,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
function pow($n)
|
||||
public function pow($n)
|
||||
{
|
||||
$zero = new static(0);
|
||||
if ($n->compare($zero) == 0) {
|
||||
@ -3813,7 +3813,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
static function min()
|
||||
public static function min()
|
||||
{
|
||||
$args = func_get_args();
|
||||
if (count($args) == 1) {
|
||||
@ -3833,7 +3833,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @return \phpseclib\Math\BigInteger
|
||||
*/
|
||||
static function max()
|
||||
public static function max()
|
||||
{
|
||||
$args = func_get_args();
|
||||
if (count($args) == 1) {
|
||||
@ -3852,7 +3852,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getLength()
|
||||
public function getLength()
|
||||
{
|
||||
return strlen($this->toBits());
|
||||
}
|
||||
@ -3863,7 +3863,7 @@ class BigInteger
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getLengthInBytes()
|
||||
public function getLengthInBytes()
|
||||
{
|
||||
return strlen($this->toBytes());
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ namespace phpseclib\Net;
|
||||
|
||||
use phpseclib\Exception\FileNotFoundException;
|
||||
use phpseclib\Common\Functions\Strings;
|
||||
use phpseclib\Common\Functions\Objects;
|
||||
|
||||
/**
|
||||
* Pure-PHP implementations of SCP.
|
||||
@ -79,7 +80,7 @@ class SCP
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $ssh;
|
||||
private $ssh;
|
||||
|
||||
/**
|
||||
* Packet Size
|
||||
@ -87,7 +88,7 @@ class SCP
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $packet_size;
|
||||
private $packet_size;
|
||||
|
||||
/**
|
||||
* Mode
|
||||
@ -95,7 +96,7 @@ class SCP
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $mode;
|
||||
private $mode;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -106,7 +107,7 @@ class SCP
|
||||
* @return \phpseclib\Net\SCP
|
||||
* @access public
|
||||
*/
|
||||
function __construct($ssh)
|
||||
public function __construct($ssh)
|
||||
{
|
||||
if ($ssh instanceof SSH2) {
|
||||
$this->mode = self::MODE_SSH2;
|
||||
@ -142,7 +143,7 @@ class SCP
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function put($remote_file, $data, $mode = self::SOURCE_STRING, $callback = null)
|
||||
public function put($remote_file, $data, $mode = self::SOURCE_STRING, $callback = null)
|
||||
{
|
||||
if (!isset($this->ssh)) {
|
||||
return false;
|
||||
@ -152,13 +153,13 @@ class SCP
|
||||
return false;
|
||||
}
|
||||
|
||||
$temp = $this->_receive();
|
||||
$temp = $this->receive();
|
||||
if ($temp !== chr(0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->mode == self::MODE_SSH2) {
|
||||
$this->packet_size = $this->ssh->packet_size_client_to_server[SSH2::CHANNEL_EXEC] - 4;
|
||||
$this->packet_size = Objects::getVar($this->ssh, 'packet_size_client_to_server')[SSH2::CHANNEL_EXEC] - 4;
|
||||
}
|
||||
|
||||
$remote_file = basename($remote_file);
|
||||
@ -177,9 +178,9 @@ class SCP
|
||||
$size = filesize($data);
|
||||
}
|
||||
|
||||
$this->_send('C0644 ' . $size . ' ' . $remote_file . "\n");
|
||||
$this->send('C0644 ' . $size . ' ' . $remote_file . "\n");
|
||||
|
||||
$temp = $this->_receive();
|
||||
$temp = $this->receive();
|
||||
if ($temp !== chr(0)) {
|
||||
return false;
|
||||
}
|
||||
@ -187,14 +188,14 @@ class SCP
|
||||
$sent = 0;
|
||||
while ($sent < $size) {
|
||||
$temp = $mode & self::SOURCE_STRING ? substr($data, $sent, $this->packet_size) : fread($fp, $this->packet_size);
|
||||
$this->_send($temp);
|
||||
$this->send($temp);
|
||||
$sent+= strlen($temp);
|
||||
|
||||
if (is_callable($callback)) {
|
||||
call_user_func($callback, $sent);
|
||||
}
|
||||
}
|
||||
$this->_close();
|
||||
$this->close();
|
||||
|
||||
if ($mode != self::SOURCE_STRING) {
|
||||
fclose($fp);
|
||||
@ -215,7 +216,7 @@ class SCP
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function get($remote_file, $local_file = false)
|
||||
public function get($remote_file, $local_file = false)
|
||||
{
|
||||
if (!isset($this->ssh)) {
|
||||
return false;
|
||||
@ -225,13 +226,13 @@ class SCP
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_send("\0");
|
||||
$this->send("\0");
|
||||
|
||||
if (!preg_match('#(?<perms>[^ ]+) (?<size>\d+) (?<name>.+)#', rtrim($this->_receive()), $info)) {
|
||||
if (!preg_match('#(?<perms>[^ ]+) (?<size>\d+) (?<name>.+)#', rtrim($this->receive()), $info)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->_send("\0");
|
||||
$this->send("\0");
|
||||
|
||||
$size = 0;
|
||||
|
||||
@ -244,7 +245,7 @@ class SCP
|
||||
|
||||
$content = '';
|
||||
while ($size < $info['size']) {
|
||||
$data = $this->_receive();
|
||||
$data = $this->receive();
|
||||
// SCP usually seems to split stuff out into 16k chunks
|
||||
$size+= strlen($data);
|
||||
|
||||
@ -255,7 +256,7 @@ class SCP
|
||||
}
|
||||
}
|
||||
|
||||
$this->_close();
|
||||
$this->close();
|
||||
|
||||
if ($local_file !== false) {
|
||||
fclose($fp);
|
||||
@ -271,15 +272,15 @@ class SCP
|
||||
* @param string $data
|
||||
* @access private
|
||||
*/
|
||||
function _send($data)
|
||||
private function send($data)
|
||||
{
|
||||
switch ($this->mode) {
|
||||
case self::MODE_SSH2:
|
||||
$this->ssh->_send_channel_packet(SSH2::CHANNEL_EXEC, $data);
|
||||
Objects::callFunc($this->ssh, 'send_channel_packet', [SSH2::CHANNEL_EXEC, $data]);
|
||||
break;
|
||||
case self::MODE_SSH1:
|
||||
$data = pack('CNa*', NET_SSH1_CMSG_STDIN_DATA, strlen($data), $data);
|
||||
$this->ssh->_send_binary_packet($data);
|
||||
Objects::callFunc($this->ssh, 'send_binary_packet', [$data]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -290,27 +291,30 @@ class SCP
|
||||
* @throws \UnexpectedValueException on receipt of an unexpected packet
|
||||
* @access private
|
||||
*/
|
||||
function _receive()
|
||||
private function receive()
|
||||
{
|
||||
switch ($this->mode) {
|
||||
case self::MODE_SSH2:
|
||||
return $this->ssh->_get_channel_packet(SSH2::CHANNEL_EXEC, true);
|
||||
return Objects::callFunc($this->ssh, 'get_channel_packet', [SSH2::CHANNEL_EXEC, true]);
|
||||
case self::MODE_SSH1:
|
||||
if (!$this->ssh->bitmap) {
|
||||
if (!Objects::getVar($this->ssh, 'bitmap')) {
|
||||
return false;
|
||||
}
|
||||
while (true) {
|
||||
$response = $this->ssh->_get_binary_packet();
|
||||
$response = Objects::getFunc($this->ssh, 'get_binary_packet');
|
||||
switch ($response[SSH1::RESPONSE_TYPE]) {
|
||||
case NET_SSH1_SMSG_STDOUT_DATA:
|
||||
if (strlen($response[SSH1::RESPONSE_DATA]) < 4) {
|
||||
return false;
|
||||
}
|
||||
extract(unpack('Nlength', $response[SSH1::RESPONSE_DATA]));
|
||||
return Strings::shift($response[SSH1::RESPONSE_DATA], $length);
|
||||
case NET_SSH1_SMSG_STDERR_DATA:
|
||||
break;
|
||||
case NET_SSH1_SMSG_EXITSTATUS:
|
||||
$this->ssh->_send_binary_packet(chr(NET_SSH1_CMSG_EXIT_CONFIRMATION));
|
||||
fclose($this->ssh->fsock);
|
||||
$this->ssh->bitmap = 0;
|
||||
Objects::callFunc($this->ssh, 'send_binary_packet', [chr(NET_SSH1_CMSG_EXIT_CONFIRMATION)]);
|
||||
fclose(Objects::getVar($this->ssh, 'fsock'));
|
||||
Objects::setVar($this->ssh, 'bitmap', 0);
|
||||
return false;
|
||||
default:
|
||||
throw new \UnexpectedValueException('Unknown packet received');
|
||||
@ -324,14 +328,14 @@ class SCP
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
function _close()
|
||||
private function close()
|
||||
{
|
||||
switch ($this->mode) {
|
||||
case self::MODE_SSH2:
|
||||
$this->ssh->_close_channel(SSH2::CHANNEL_EXEC, true);
|
||||
Objects::callFunc($this->ssh, 'close_channel', [SSH2::CHANNEL_EXEC, true]);
|
||||
break;
|
||||
case self::MODE_SSH1:
|
||||
$this->ssh->disconnect();
|
||||
Objects::callFunc($this->ssh, 'disconnect');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -45,7 +45,7 @@ class Stream
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $sftp;
|
||||
private $sftp;
|
||||
|
||||
/**
|
||||
* Path
|
||||
@ -53,7 +53,7 @@ class Stream
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $path;
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* Mode
|
||||
@ -61,7 +61,7 @@ class Stream
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $mode;
|
||||
private $mode;
|
||||
|
||||
/**
|
||||
* Position
|
||||
@ -69,7 +69,7 @@ class Stream
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $pos;
|
||||
private $pos;
|
||||
|
||||
/**
|
||||
* Size
|
||||
@ -77,7 +77,7 @@ class Stream
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $size;
|
||||
private $size;
|
||||
|
||||
/**
|
||||
* Directory entries
|
||||
@ -85,7 +85,7 @@ class Stream
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $entries;
|
||||
private $entries;
|
||||
|
||||
/**
|
||||
* EOF flag
|
||||
@ -93,7 +93,7 @@ class Stream
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $eof;
|
||||
private $eof;
|
||||
|
||||
/**
|
||||
* Context resource
|
||||
@ -103,7 +103,7 @@ class Stream
|
||||
* @var resource
|
||||
* @access public
|
||||
*/
|
||||
var $context;
|
||||
public $context;
|
||||
|
||||
/**
|
||||
* Notification callback function
|
||||
@ -111,7 +111,7 @@ class Stream
|
||||
* @var callable
|
||||
* @access public
|
||||
*/
|
||||
var $notification;
|
||||
private $notification;
|
||||
|
||||
/**
|
||||
* Registers this class as a URL wrapper.
|
||||
@ -120,7 +120,7 @@ class Stream
|
||||
* @return bool True on success, false otherwise.
|
||||
* @access public
|
||||
*/
|
||||
static function register($protocol = 'sftp')
|
||||
public static function register($protocol = 'sftp')
|
||||
{
|
||||
if (in_array($protocol, stream_get_wrappers(), true)) {
|
||||
return false;
|
||||
@ -133,7 +133,7 @@ class Stream
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
if (defined('NET_SFTP_STREAM_LOGGING')) {
|
||||
echo "__construct()\r\n";
|
||||
@ -152,7 +152,7 @@ class Stream
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function _parse_path($path)
|
||||
private function parse_path($path)
|
||||
{
|
||||
$orig = $path;
|
||||
extract(parse_url($path) + ['port' => 22]);
|
||||
@ -257,9 +257,9 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _stream_open($path, $mode, $options, &$opened_path)
|
||||
private function _stream_open($path, $mode, $options, &$opened_path)
|
||||
{
|
||||
$path = $this->_parse_path($path);
|
||||
$path = $this->parse_path($path);
|
||||
|
||||
if ($path === false) {
|
||||
return false;
|
||||
@ -299,7 +299,7 @@ class Stream
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function _stream_read($count)
|
||||
private function _stream_read($count)
|
||||
{
|
||||
switch ($this->mode) {
|
||||
case 'w':
|
||||
@ -341,7 +341,7 @@ class Stream
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function _stream_write($data)
|
||||
private function _stream_write($data)
|
||||
{
|
||||
switch ($this->mode) {
|
||||
case 'r':
|
||||
@ -375,7 +375,7 @@ class Stream
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
function _stream_tell()
|
||||
private function _stream_tell()
|
||||
{
|
||||
return $this->pos;
|
||||
}
|
||||
@ -393,7 +393,7 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _stream_eof()
|
||||
private function _stream_eof()
|
||||
{
|
||||
return $this->eof;
|
||||
}
|
||||
@ -406,7 +406,7 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _stream_seek($offset, $whence)
|
||||
private function _stream_seek($offset, $whence)
|
||||
{
|
||||
switch ($whence) {
|
||||
case SEEK_SET:
|
||||
@ -435,9 +435,9 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _stream_metadata($path, $option, $var)
|
||||
private function _stream_metadata($path, $option, $var)
|
||||
{
|
||||
$path = $this->_parse_path($path);
|
||||
$path = $this->parse_path($path);
|
||||
if ($path === false) {
|
||||
return false;
|
||||
}
|
||||
@ -467,7 +467,7 @@ class Stream
|
||||
* @return resource
|
||||
* @access public
|
||||
*/
|
||||
function _stream_cast($cast_as)
|
||||
private function _stream_cast($cast_as)
|
||||
{
|
||||
return $this->sftp->fsock;
|
||||
}
|
||||
@ -479,7 +479,7 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _stream_lock($operation)
|
||||
private function _stream_lock($operation)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -496,7 +496,7 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _rename($path_from, $path_to)
|
||||
private function _rename($path_from, $path_to)
|
||||
{
|
||||
$path1 = parse_url($path_from);
|
||||
$path2 = parse_url($path_to);
|
||||
@ -505,7 +505,7 @@ class Stream
|
||||
return false;
|
||||
}
|
||||
|
||||
$path_from = $this->_parse_path($path_from);
|
||||
$path_from = $this->parse_path($path_from);
|
||||
$path_to = parse_url($path_to);
|
||||
if ($path_from === false) {
|
||||
return false;
|
||||
@ -548,9 +548,9 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _dir_opendir($path, $options)
|
||||
private function _dir_opendir($path, $options)
|
||||
{
|
||||
$path = $this->_parse_path($path);
|
||||
$path = $this->parse_path($path);
|
||||
if ($path === false) {
|
||||
return false;
|
||||
}
|
||||
@ -565,7 +565,7 @@ class Stream
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function _dir_readdir()
|
||||
private function _dir_readdir()
|
||||
{
|
||||
if (isset($this->entries[$this->pos])) {
|
||||
return $this->entries[$this->pos++];
|
||||
@ -579,7 +579,7 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _dir_rewinddir()
|
||||
private function _dir_rewinddir()
|
||||
{
|
||||
$this->pos = 0;
|
||||
return true;
|
||||
@ -591,7 +591,7 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _dir_closedir()
|
||||
private function _dir_closedir()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -607,9 +607,9 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _mkdir($path, $mode, $options)
|
||||
private function _mkdir($path, $mode, $options)
|
||||
{
|
||||
$path = $this->_parse_path($path);
|
||||
$path = $this->parse_path($path);
|
||||
if ($path === false) {
|
||||
return false;
|
||||
}
|
||||
@ -631,9 +631,9 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _rmdir($path, $options)
|
||||
private function _rmdir($path, $options)
|
||||
{
|
||||
$path = $this->_parse_path($path);
|
||||
$path = $this->parse_path($path);
|
||||
if ($path === false) {
|
||||
return false;
|
||||
}
|
||||
@ -649,7 +649,7 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _stream_flush()
|
||||
private function _stream_flush()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -660,7 +660,7 @@ class Stream
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function _stream_stat()
|
||||
private function _stream_stat()
|
||||
{
|
||||
$results = $this->sftp->stat($this->path);
|
||||
if ($results === false) {
|
||||
@ -676,9 +676,9 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _unlink($path)
|
||||
private function _unlink($path)
|
||||
{
|
||||
$path = $this->_parse_path($path);
|
||||
$path = $this->parse_path($path);
|
||||
if ($path === false) {
|
||||
return false;
|
||||
}
|
||||
@ -698,9 +698,9 @@ class Stream
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function _url_stat($path, $flags)
|
||||
private function _url_stat($path, $flags)
|
||||
{
|
||||
$path = $this->_parse_path($path);
|
||||
$path = $this->parse_path($path);
|
||||
if ($path === false) {
|
||||
return false;
|
||||
}
|
||||
@ -720,7 +720,7 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _stream_truncate($new_size)
|
||||
private function _stream_truncate($new_size)
|
||||
{
|
||||
if (!$this->sftp->truncate($this->path, $new_size)) {
|
||||
return false;
|
||||
@ -744,7 +744,7 @@ class Stream
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function _stream_set_option($option, $arg1, $arg2)
|
||||
private function _stream_set_option($option, $arg1, $arg2)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -754,7 +754,7 @@ class Stream
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function _stream_close()
|
||||
private function _stream_close()
|
||||
{
|
||||
}
|
||||
|
||||
@ -773,7 +773,7 @@ class Stream
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function __call($name, $arguments)
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (defined('NET_SFTP_STREAM_LOGGING')) {
|
||||
echo $name . '(';
|
||||
|
@ -229,7 +229,7 @@ class SSH1
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $identifier = 'SSH-1.5-phpseclib';
|
||||
private $identifier = 'SSH-1.5-phpseclib';
|
||||
|
||||
/**
|
||||
* The Socket Object
|
||||
@ -237,7 +237,7 @@ class SSH1
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $fsock;
|
||||
private $fsock;
|
||||
|
||||
/**
|
||||
* The cryptography object
|
||||
@ -245,7 +245,7 @@ class SSH1
|
||||
* @var object
|
||||
* @access private
|
||||
*/
|
||||
var $crypto = false;
|
||||
private $crypto = false;
|
||||
|
||||
/**
|
||||
* Execution Bitmap
|
||||
@ -256,7 +256,7 @@ class SSH1
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $bitmap = 0;
|
||||
private $bitmap = 0;
|
||||
|
||||
/**
|
||||
* The Server Key Public Exponent
|
||||
@ -267,7 +267,7 @@ class SSH1
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $server_key_public_exponent;
|
||||
private $server_key_public_exponent;
|
||||
|
||||
/**
|
||||
* The Server Key Public Modulus
|
||||
@ -278,7 +278,7 @@ class SSH1
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $server_key_public_modulus;
|
||||
private $server_key_public_modulus;
|
||||
|
||||
/**
|
||||
* The Host Key Public Exponent
|
||||
@ -289,7 +289,7 @@ class SSH1
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $host_key_public_exponent;
|
||||
private $host_key_public_exponent;
|
||||
|
||||
/**
|
||||
* The Host Key Public Modulus
|
||||
@ -300,7 +300,7 @@ class SSH1
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $host_key_public_modulus;
|
||||
private $host_key_public_modulus;
|
||||
|
||||
/**
|
||||
* Supported Ciphers
|
||||
@ -311,7 +311,7 @@ class SSH1
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $supported_ciphers = [
|
||||
private $supported_ciphers = [
|
||||
self::CIPHER_NONE => 'No encryption',
|
||||
self::CIPHER_IDEA => 'IDEA in CFB mode',
|
||||
self::CIPHER_DES => 'DES in CBC mode',
|
||||
@ -330,7 +330,7 @@ class SSH1
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $supported_authentications = [
|
||||
private $supported_authentications = [
|
||||
self::AUTH_RHOSTS => '.rhosts or /etc/hosts.equiv',
|
||||
self::AUTH_RSA => 'pure RSA authentication',
|
||||
self::AUTH_PASSWORD => 'password authentication',
|
||||
@ -344,7 +344,7 @@ class SSH1
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $server_identification = '';
|
||||
private $server_identification = '';
|
||||
|
||||
/**
|
||||
* Protocol Flags
|
||||
@ -353,7 +353,7 @@ class SSH1
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $protocol_flags = [];
|
||||
private $protocol_flags = [];
|
||||
|
||||
/**
|
||||
* Protocol Flag Log
|
||||
@ -362,7 +362,7 @@ class SSH1
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $protocol_flag_log = [];
|
||||
private $protocol_flag_log = [];
|
||||
|
||||
/**
|
||||
* Message Log
|
||||
@ -371,7 +371,7 @@ class SSH1
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $message_log = [];
|
||||
private $message_log = [];
|
||||
|
||||
/**
|
||||
* Real-time log file pointer
|
||||
@ -380,7 +380,7 @@ class SSH1
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $realtime_log_file;
|
||||
private $realtime_log_file;
|
||||
|
||||
/**
|
||||
* Real-time log file size
|
||||
@ -389,7 +389,7 @@ class SSH1
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $realtime_log_size;
|
||||
private $realtime_log_size;
|
||||
|
||||
/**
|
||||
* Real-time log file wrap boolean
|
||||
@ -398,7 +398,7 @@ class SSH1
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $realtime_log_wrap;
|
||||
private $realtime_log_wrap;
|
||||
|
||||
/**
|
||||
* Interactive Buffer
|
||||
@ -407,7 +407,7 @@ class SSH1
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $interactiveBuffer = '';
|
||||
private $interactiveBuffer = '';
|
||||
|
||||
/**
|
||||
* Timeout
|
||||
@ -415,7 +415,7 @@ class SSH1
|
||||
* @see self::setTimeout()
|
||||
* @access private
|
||||
*/
|
||||
var $timeout;
|
||||
private $timeout;
|
||||
|
||||
/**
|
||||
* Current Timeout
|
||||
@ -423,7 +423,7 @@ class SSH1
|
||||
* @see self::_get_channel_packet()
|
||||
* @access private
|
||||
*/
|
||||
var $curTimeout;
|
||||
private $curTimeout;
|
||||
|
||||
/**
|
||||
* Log Boundary
|
||||
@ -431,7 +431,7 @@ class SSH1
|
||||
* @see self::_format_log()
|
||||
* @access private
|
||||
*/
|
||||
var $log_boundary = ':';
|
||||
private $log_boundary = ':';
|
||||
|
||||
/**
|
||||
* Log Long Width
|
||||
@ -439,7 +439,7 @@ class SSH1
|
||||
* @see self::_format_log()
|
||||
* @access private
|
||||
*/
|
||||
var $log_long_width = 65;
|
||||
private $log_long_width = 65;
|
||||
|
||||
/**
|
||||
* Log Short Width
|
||||
@ -447,7 +447,7 @@ class SSH1
|
||||
* @see self::_format_log()
|
||||
* @access private
|
||||
*/
|
||||
var $log_short_width = 16;
|
||||
private $log_short_width = 16;
|
||||
|
||||
/**
|
||||
* Hostname
|
||||
@ -457,7 +457,7 @@ class SSH1
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $host;
|
||||
private $host;
|
||||
|
||||
/**
|
||||
* Port Number
|
||||
@ -467,7 +467,7 @@ class SSH1
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $port;
|
||||
private $port;
|
||||
|
||||
/**
|
||||
* Timeout for initial connection
|
||||
@ -482,7 +482,7 @@ class SSH1
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $connectionTimeout;
|
||||
private $connectionTimeout;
|
||||
|
||||
/**
|
||||
* Default cipher
|
||||
@ -492,7 +492,7 @@ class SSH1
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $cipher;
|
||||
private $cipher;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -506,7 +506,7 @@ class SSH1
|
||||
* @return \phpseclib\Net\SSH1
|
||||
* @access public
|
||||
*/
|
||||
function __construct($host, $port = 22, $timeout = 10, $cipher = self::CIPHER_3DES)
|
||||
public function __construct($host, $port = 22, $timeout = 10, $cipher = self::CIPHER_3DES)
|
||||
{
|
||||
$this->protocol_flags = [
|
||||
1 => 'NET_SSH1_MSG_DISCONNECT',
|
||||
@ -527,7 +527,7 @@ class SSH1
|
||||
33 => 'NET_SSH1_CMSG_EXIT_CONFIRMATION'
|
||||
];
|
||||
|
||||
$this->_define_array($this->protocol_flags);
|
||||
$this->define_array($this->protocol_flags);
|
||||
|
||||
$this->host = $host;
|
||||
$this->port = $port;
|
||||
@ -543,7 +543,7 @@ class SSH1
|
||||
* @throws \RuntimeException on other errors
|
||||
* @access private
|
||||
*/
|
||||
function _connect()
|
||||
private function connect()
|
||||
{
|
||||
$this->fsock = @fsockopen($this->host, $this->port, $errno, $errstr, $this->connectionTimeout);
|
||||
if (!$this->fsock) {
|
||||
@ -553,8 +553,8 @@ class SSH1
|
||||
$this->server_identification = $init_line = fgets($this->fsock, 255);
|
||||
|
||||
if (defined('NET_SSH1_LOGGING')) {
|
||||
$this->_append_log('<-', $this->server_identification);
|
||||
$this->_append_log('->', $this->identifier . "\r\n");
|
||||
$this->append_log('<-', $this->server_identification);
|
||||
$this->append_log('->', $this->identifier . "\r\n");
|
||||
}
|
||||
|
||||
if (!preg_match('#SSH-([0-9\.]+)-(.+)#', $init_line, $parts)) {
|
||||
@ -566,7 +566,7 @@ class SSH1
|
||||
|
||||
fputs($this->fsock, $this->identifier."\r\n");
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
$response = $this->get_binary_packet();
|
||||
if ($response[self::RESPONSE_TYPE] != NET_SSH1_SMSG_PUBLIC_KEY) {
|
||||
throw new \UnexpectedValueException('Expected SSH_SMSG_PUBLIC_KEY');
|
||||
}
|
||||
@ -575,28 +575,46 @@ class SSH1
|
||||
|
||||
Strings::shift($response[self::RESPONSE_DATA], 4);
|
||||
|
||||
if (strlen($response[self::RESPONSE_DATA]) < 2) {
|
||||
return false;
|
||||
}
|
||||
$temp = unpack('nlen', Strings::shift($response[self::RESPONSE_DATA], 2));
|
||||
$server_key_public_exponent = new BigInteger(Strings::shift($response[self::RESPONSE_DATA], ceil($temp['len'] / 8)), 256);
|
||||
$this->server_key_public_exponent = $server_key_public_exponent;
|
||||
|
||||
if (strlen($response[self::RESPONSE_DATA]) < 2) {
|
||||
return false;
|
||||
}
|
||||
$temp = unpack('nlen', Strings::shift($response[self::RESPONSE_DATA], 2));
|
||||
$server_key_public_modulus = new BigInteger(Strings::shift($response[self::RESPONSE_DATA], ceil($temp['len'] / 8)), 256);
|
||||
|
||||
$this->server_key_public_modulus = $server_key_public_modulus;
|
||||
|
||||
Strings::shift($response[self::RESPONSE_DATA], 4);
|
||||
|
||||
if (strlen($response[self::RESPONSE_DATA]) < 2) {
|
||||
return false;
|
||||
}
|
||||
$temp = unpack('nlen', Strings::shift($response[self::RESPONSE_DATA], 2));
|
||||
$host_key_public_exponent = new BigInteger(Strings::shift($response[self::RESPONSE_DATA], ceil($temp['len'] / 8)), 256);
|
||||
$this->host_key_public_exponent = $host_key_public_exponent;
|
||||
|
||||
if (strlen($response[self::RESPONSE_DATA]) < 2) {
|
||||
return false;
|
||||
}
|
||||
$temp = unpack('nlen', Strings::shift($response[self::RESPONSE_DATA], 2));
|
||||
$host_key_public_modulus = new BigInteger(Strings::shift($response[self::RESPONSE_DATA], ceil($temp['len'] / 8)), 256);
|
||||
|
||||
$this->host_key_public_modulus = $host_key_public_modulus;
|
||||
|
||||
Strings::shift($response[self::RESPONSE_DATA], 4);
|
||||
|
||||
// get a list of the supported ciphers
|
||||
if (strlen($response[self::RESPONSE_DATA]) < 4) {
|
||||
return false;
|
||||
}
|
||||
extract(unpack('Nsupported_ciphers_mask', Strings::shift($response[self::RESPONSE_DATA], 4)));
|
||||
|
||||
foreach ($this->supported_ciphers as $mask => $name) {
|
||||
if (($supported_ciphers_mask & (1 << $mask)) == 0) {
|
||||
unset($this->supported_ciphers[$mask]);
|
||||
@ -604,6 +622,9 @@ class SSH1
|
||||
}
|
||||
|
||||
// get a list of the supported authentications
|
||||
if (strlen($response[self::RESPONSE_DATA]) < 4) {
|
||||
return false;
|
||||
}
|
||||
extract(unpack('Nsupported_authentications_mask', Strings::shift($response[self::RESPONSE_DATA], 4)));
|
||||
foreach ($this->supported_authentications as $mask => $name) {
|
||||
if (($supported_authentications_mask & (1 << $mask)) == 0) {
|
||||
@ -617,14 +638,14 @@ class SSH1
|
||||
$double_encrypted_session_key = $session_key ^ str_pad($session_id, 32, chr(0));
|
||||
|
||||
if ($server_key_public_modulus->compare($host_key_public_modulus) < 0) {
|
||||
$double_encrypted_session_key = $this->_rsa_crypt(
|
||||
$double_encrypted_session_key = $this->rsa_crypt(
|
||||
$double_encrypted_session_key,
|
||||
[
|
||||
$server_key_public_exponent,
|
||||
$server_key_public_modulus
|
||||
]
|
||||
);
|
||||
$double_encrypted_session_key = $this->_rsa_crypt(
|
||||
$double_encrypted_session_key = $this->rsa_crypt(
|
||||
$double_encrypted_session_key,
|
||||
[
|
||||
$host_key_public_exponent,
|
||||
@ -632,14 +653,14 @@ class SSH1
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$double_encrypted_session_key = $this->_rsa_crypt(
|
||||
$double_encrypted_session_key = $this->rsa_crypt(
|
||||
$double_encrypted_session_key,
|
||||
[
|
||||
$host_key_public_exponent,
|
||||
$host_key_public_modulus
|
||||
]
|
||||
);
|
||||
$double_encrypted_session_key = $this->_rsa_crypt(
|
||||
$double_encrypted_session_key = $this->rsa_crypt(
|
||||
$double_encrypted_session_key,
|
||||
[
|
||||
$server_key_public_exponent,
|
||||
@ -651,7 +672,7 @@ class SSH1
|
||||
$cipher = isset($this->supported_ciphers[$this->cipher]) ? $this->cipher : self::CIPHER_3DES;
|
||||
$data = pack('C2a*na*N', NET_SSH1_CMSG_SESSION_KEY, $cipher, $anti_spoofing_cookie, 8 * strlen($double_encrypted_session_key), $double_encrypted_session_key, 0);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
if (!$this->send_binary_packet($data)) {
|
||||
throw new \RuntimeException('Error sending SSH_CMSG_SESSION_KEY');
|
||||
}
|
||||
|
||||
@ -682,7 +703,7 @@ class SSH1
|
||||
// break;
|
||||
}
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
$response = $this->get_binary_packet();
|
||||
|
||||
if ($response[self::RESPONSE_TYPE] != NET_SSH1_SMSG_SUCCESS) {
|
||||
throw new \UnexpectedValueException('Expected SSH_SMSG_SUCCESS');
|
||||
@ -703,11 +724,11 @@ class SSH1
|
||||
* @throws \RuntimeException on other errors
|
||||
* @access public
|
||||
*/
|
||||
function login($username, $password = '')
|
||||
public function login($username, $password = '')
|
||||
{
|
||||
if (!($this->bitmap & self::MASK_CONSTRUCTOR)) {
|
||||
$this->bitmap |= self::MASK_CONSTRUCTOR;
|
||||
if (!$this->_connect()) {
|
||||
if (!$this->connect()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -718,11 +739,11 @@ class SSH1
|
||||
|
||||
$data = pack('CNa*', NET_SSH1_CMSG_USER, strlen($username), $username);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
if (!$this->send_binary_packet($data)) {
|
||||
throw new \RuntimeException('Error sending SSH_CMSG_USER');
|
||||
}
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
$response = $this->get_binary_packet();
|
||||
|
||||
if ($response === true) {
|
||||
return false;
|
||||
@ -736,7 +757,7 @@ class SSH1
|
||||
|
||||
$data = pack('CNa*', NET_SSH1_CMSG_AUTH_PASSWORD, strlen($password), $password);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
if (!$this->send_binary_packet($data)) {
|
||||
throw new \RuntimeException('Error sending SSH_CMSG_AUTH_PASSWORD');
|
||||
}
|
||||
|
||||
@ -746,7 +767,7 @@ class SSH1
|
||||
$this->message_log[count($this->message_log) - 1] = $data;
|
||||
}
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
$response = $this->get_binary_packet();
|
||||
|
||||
if ($response === true) {
|
||||
return false;
|
||||
@ -769,7 +790,7 @@ class SSH1
|
||||
*
|
||||
* @param mixed $timeout
|
||||
*/
|
||||
function setTimeout($timeout)
|
||||
public function setTimeout($timeout)
|
||||
{
|
||||
$this->timeout = $this->curTimeout = $timeout;
|
||||
}
|
||||
@ -795,7 +816,7 @@ class SSH1
|
||||
* @throws \RuntimeException on error sending command
|
||||
* @access public
|
||||
*/
|
||||
function exec($cmd, $block = true)
|
||||
public function exec($cmd, $block = true)
|
||||
{
|
||||
if (!($this->bitmap & self::MASK_LOGIN)) {
|
||||
throw new \RuntimeException('Operation disallowed prior to login()');
|
||||
@ -803,7 +824,7 @@ class SSH1
|
||||
|
||||
$data = pack('CNa*', NET_SSH1_CMSG_EXEC_CMD, strlen($cmd), $cmd);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
if (!$this->send_binary_packet($data)) {
|
||||
throw new \RuntimeException('Error sending SSH_CMSG_EXEC_CMD');
|
||||
}
|
||||
|
||||
@ -812,19 +833,19 @@ class SSH1
|
||||
}
|
||||
|
||||
$output = '';
|
||||
$response = $this->_get_binary_packet();
|
||||
$response = $this->get_binary_packet();
|
||||
|
||||
if ($response !== false) {
|
||||
do {
|
||||
$output.= substr($response[self::RESPONSE_DATA], 4);
|
||||
$response = $this->_get_binary_packet();
|
||||
$response = $this->get_binary_packet();
|
||||
} while (is_array($response) && $response[self::RESPONSE_TYPE] != NET_SSH1_SMSG_EXITSTATUS);
|
||||
}
|
||||
|
||||
$data = pack('C', NET_SSH1_CMSG_EXIT_CONFIRMATION);
|
||||
|
||||
// i don't think it's really all that important if this packet gets sent or not.
|
||||
$this->_send_binary_packet($data);
|
||||
$this->send_binary_packet($data);
|
||||
|
||||
fclose($this->fsock);
|
||||
|
||||
@ -844,18 +865,18 @@ class SSH1
|
||||
* @throws \RuntimeException on other errors
|
||||
* @access private
|
||||
*/
|
||||
function _initShell()
|
||||
private function initShell()
|
||||
{
|
||||
// connect using the sample parameters in protocol-1.5.txt.
|
||||
// according to wikipedia.org's entry on text terminals, "the fundamental type of application running on a text
|
||||
// terminal is a command line interpreter or shell". thus, opening a terminal session to run the shell.
|
||||
$data = pack('CNa*N4C', NET_SSH1_CMSG_REQUEST_PTY, strlen('vt100'), 'vt100', 24, 80, 0, 0, self::TTY_OP_END);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
if (!$this->send_binary_packet($data)) {
|
||||
throw new \RuntimeException('Error sending SSH_CMSG_REQUEST_PTY');
|
||||
}
|
||||
|
||||
$response = $this->_get_binary_packet();
|
||||
$response = $this->get_binary_packet();
|
||||
|
||||
if ($response === true) {
|
||||
return false;
|
||||
@ -866,7 +887,7 @@ class SSH1
|
||||
|
||||
$data = pack('C', NET_SSH1_CMSG_EXEC_SHELL);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
if (!$this->send_binary_packet($data)) {
|
||||
throw new \RuntimeException('Error sending SSH_CMSG_EXEC_SHELL');
|
||||
}
|
||||
|
||||
@ -885,7 +906,7 @@ class SSH1
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function write($cmd)
|
||||
public function write($cmd)
|
||||
{
|
||||
return $this->interactiveWrite($cmd);
|
||||
}
|
||||
@ -903,13 +924,13 @@ class SSH1
|
||||
* @throws \RuntimeException on connection error
|
||||
* @access public
|
||||
*/
|
||||
function read($expect, $mode = self::READ__SIMPLE)
|
||||
public function read($expect, $mode = self::READ__SIMPLE)
|
||||
{
|
||||
if (!($this->bitmap & self::MASK_LOGIN)) {
|
||||
throw new \RuntimeException('Operation disallowed prior to login()');
|
||||
}
|
||||
|
||||
if (!($this->bitmap & self::MASK_SHELL) && !$this->_initShell()) {
|
||||
if (!($this->bitmap & self::MASK_SHELL) && !$this->initShell()) {
|
||||
throw new \RuntimeException('Unable to initiate an interactive shell session');
|
||||
}
|
||||
|
||||
@ -923,7 +944,7 @@ class SSH1
|
||||
if ($pos !== false) {
|
||||
return Strings::shift($this->interactiveBuffer, $pos + strlen($match));
|
||||
}
|
||||
$response = $this->_get_binary_packet();
|
||||
$response = $this->get_binary_packet();
|
||||
|
||||
if ($response === true) {
|
||||
return Strings::shift($this->interactiveBuffer, strlen($this->interactiveBuffer));
|
||||
@ -941,19 +962,19 @@ class SSH1
|
||||
* @throws \RuntimeException on connection error
|
||||
* @access public
|
||||
*/
|
||||
function interactiveWrite($cmd)
|
||||
public function interactiveWrite($cmd)
|
||||
{
|
||||
if (!($this->bitmap & self::MASK_LOGIN)) {
|
||||
throw new \RuntimeException('Operation disallowed prior to login()');
|
||||
}
|
||||
|
||||
if (!($this->bitmap & self::MASK_SHELL) && !$this->_initShell()) {
|
||||
if (!($this->bitmap & self::MASK_SHELL) && !$this->initShell()) {
|
||||
throw new \RuntimeException('Unable to initiate an interactive shell session');
|
||||
}
|
||||
|
||||
$data = pack('CNa*', NET_SSH1_CMSG_STDIN_DATA, strlen($cmd), $cmd);
|
||||
|
||||
if (!$this->_send_binary_packet($data)) {
|
||||
if (!$this->send_binary_packet($data)) {
|
||||
throw new \RuntimeException('Error sending SSH_CMSG_STDIN');
|
||||
}
|
||||
|
||||
@ -974,20 +995,20 @@ class SSH1
|
||||
* @throws \RuntimeException on connection error
|
||||
* @access public
|
||||
*/
|
||||
function interactiveRead()
|
||||
public function interactiveRead()
|
||||
{
|
||||
if (!($this->bitmap & self::MASK_LOGIN)) {
|
||||
throw new \RuntimeException('Operation disallowed prior to login()');
|
||||
}
|
||||
|
||||
if (!($this->bitmap & self::MASK_SHELL) && !$this->_initShell()) {
|
||||
if (!($this->bitmap & self::MASK_SHELL) && !$this->initShell()) {
|
||||
throw new \RuntimeException('Unable to initiate an interactive shell session');
|
||||
}
|
||||
|
||||
$read = [$this->fsock];
|
||||
$write = $except = null;
|
||||
if (stream_select($read, $write, $except, 0)) {
|
||||
$response = $this->_get_binary_packet();
|
||||
$response = $this->get_binary_packet();
|
||||
return substr($response[self::RESPONSE_DATA], 4);
|
||||
} else {
|
||||
return '';
|
||||
@ -999,9 +1020,9 @@ class SSH1
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function disconnect()
|
||||
public function disconnect()
|
||||
{
|
||||
$this->_disconnect();
|
||||
$this->disconnect_helper();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1012,9 +1033,9 @@ class SSH1
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function __destruct()
|
||||
public function __destruct()
|
||||
{
|
||||
$this->_disconnect();
|
||||
$this->disconnect_helper();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1023,13 +1044,13 @@ class SSH1
|
||||
* @param string $msg
|
||||
* @access private
|
||||
*/
|
||||
function _disconnect($msg = 'Client Quit')
|
||||
private function disconnect_helper($msg = 'Client Quit')
|
||||
{
|
||||
if ($this->bitmap) {
|
||||
$data = pack('C', NET_SSH1_CMSG_EOF);
|
||||
$this->_send_binary_packet($data);
|
||||
$this->send_binary_packet($data);
|
||||
/*
|
||||
$response = $this->_get_binary_packet();
|
||||
$response = $this->get_binary_packet();
|
||||
if ($response === true) {
|
||||
$response = [self::RESPONSE_TYPE => -1];
|
||||
}
|
||||
@ -1043,7 +1064,7 @@ class SSH1
|
||||
*/
|
||||
$data = pack('CNa*', NET_SSH1_MSG_DISCONNECT, strlen($msg), $msg);
|
||||
|
||||
$this->_send_binary_packet($data);
|
||||
$this->send_binary_packet($data);
|
||||
fclose($this->fsock);
|
||||
$this->bitmap = 0;
|
||||
}
|
||||
@ -1061,7 +1082,7 @@ class SSH1
|
||||
* @return array
|
||||
* @access private
|
||||
*/
|
||||
function _get_binary_packet()
|
||||
private function get_binary_packet()
|
||||
{
|
||||
if (feof($this->fsock)) {
|
||||
//user_error('connection closed prematurely');
|
||||
@ -1077,7 +1098,7 @@ class SSH1
|
||||
$usec = 1000000 * ($this->curTimeout - $sec);
|
||||
// on windows this returns a "Warning: Invalid CRT parameters detected" error
|
||||
if (!@stream_select($read, $write, $except, $sec, $usec) && !count($read)) {
|
||||
//$this->_disconnect('Timeout');
|
||||
//$this->disconnect_helper('Timeout');
|
||||
return true;
|
||||
}
|
||||
$elapsed = strtok(microtime(), ' ') + strtok('') - $start;
|
||||
@ -1085,7 +1106,11 @@ class SSH1
|
||||
}
|
||||
|
||||
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838
|
||||
$temp = unpack('Nlength', fread($this->fsock, 4));
|
||||
$data = fread($this->fsock, 4);
|
||||
if (strlen($data) < 4) {
|
||||
return false;
|
||||
}
|
||||
$temp = unpack('Nlength', $data);
|
||||
|
||||
$padding_length = 8 - ($temp['length'] & 7);
|
||||
$length = $temp['length'] + $padding_length;
|
||||
@ -1106,9 +1131,12 @@ class SSH1
|
||||
$type = $raw[$padding_length];
|
||||
$data = substr($raw, $padding_length + 1, -4);
|
||||
|
||||
if (strlen($raw) < 4) {
|
||||
return false;
|
||||
}
|
||||
$temp = unpack('Ncrc', substr($raw, -4));
|
||||
|
||||
//if ( $temp['crc'] != $this->_crc($padding . $type . $data) ) {
|
||||
//if ( $temp['crc'] != $this->crc($padding . $type . $data) ) {
|
||||
// user_error('Bad CRC in packet from server');
|
||||
// return false;
|
||||
//}
|
||||
@ -1119,7 +1147,7 @@ class SSH1
|
||||
$temp = isset($this->protocol_flags[$type]) ? $this->protocol_flags[$type] : 'UNKNOWN';
|
||||
$temp = '<- ' . $temp .
|
||||
' (' . round($stop - $start, 4) . 's)';
|
||||
$this->_append_log($temp, $data);
|
||||
$this->append_log($temp, $data);
|
||||
}
|
||||
|
||||
return [
|
||||
@ -1138,7 +1166,7 @@ class SSH1
|
||||
* @return bool
|
||||
* @access private
|
||||
*/
|
||||
function _send_binary_packet($data)
|
||||
private function send_binary_packet($data)
|
||||
{
|
||||
if (feof($this->fsock)) {
|
||||
//user_error('connection closed prematurely');
|
||||
@ -1151,7 +1179,7 @@ class SSH1
|
||||
|
||||
$orig = $data;
|
||||
$data = $padding . $data;
|
||||
$data.= pack('N', $this->_crc($data));
|
||||
$data.= pack('N', $this->crc($data));
|
||||
|
||||
if ($this->crypto !== false) {
|
||||
$data = $this->crypto->encrypt($data);
|
||||
@ -1167,7 +1195,7 @@ class SSH1
|
||||
$temp = isset($this->protocol_flags[ord($orig[0])]) ? $this->protocol_flags[ord($orig[0])] : 'UNKNOWN';
|
||||
$temp = '-> ' . $temp .
|
||||
' (' . round($stop - $start, 4) . 's)';
|
||||
$this->_append_log($temp, $orig);
|
||||
$this->append_log($temp, $orig);
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -1186,7 +1214,7 @@ class SSH1
|
||||
* @return int
|
||||
* @access private
|
||||
*/
|
||||
function _crc($data)
|
||||
private function crc($data)
|
||||
{
|
||||
static $crc_lookup_table = [
|
||||
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
|
||||
@ -1286,7 +1314,7 @@ class SSH1
|
||||
* @return BigInteger
|
||||
* @access private
|
||||
*/
|
||||
function _rsa_crypt($m, $key)
|
||||
private function rsa_crypt($m, $key)
|
||||
{
|
||||
/*
|
||||
$rsa = new RSA();
|
||||
@ -1334,7 +1362,7 @@ class SSH1
|
||||
* @param array $array
|
||||
* @access private
|
||||
*/
|
||||
function _define_array()
|
||||
private function define_array()
|
||||
{
|
||||
$args = func_get_args();
|
||||
foreach ($args as $arg) {
|
||||
@ -1356,7 +1384,7 @@ class SSH1
|
||||
* @access public
|
||||
* @return array|false|string
|
||||
*/
|
||||
function getLog()
|
||||
public function getLog()
|
||||
{
|
||||
if (!defined('NET_SSH1_LOGGING')) {
|
||||
return false;
|
||||
@ -1367,7 +1395,7 @@ class SSH1
|
||||
return $this->message_number_log;
|
||||
break;
|
||||
case self::LOG_COMPLEX:
|
||||
return $this->_format_log($this->message_log, $this->protocol_flags_log);
|
||||
return $this->format_log($this->message_log, $this->protocol_flags_log);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
@ -1382,7 +1410,7 @@ class SSH1
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _format_log($message_log, $message_number_log)
|
||||
private function format_log($message_log, $message_number_log)
|
||||
{
|
||||
$output = '';
|
||||
for ($i = 0; $i < count($message_log); $i++) {
|
||||
@ -1394,7 +1422,7 @@ class SSH1
|
||||
$output.= str_pad(dechex($j), 7, '0', STR_PAD_LEFT) . '0 ';
|
||||
}
|
||||
$fragment = Strings::shift($current_log, $this->log_short_width);
|
||||
$hex = substr(preg_replace_callback('#.#s', [$this, '_format_log_helper'], $fragment), strlen($this->log_boundary));
|
||||
$hex = substr(preg_replace_callback('#.#s', [$this, 'format_log_helper'], $fragment), strlen($this->log_boundary));
|
||||
// replace non ASCII printable characters with dots
|
||||
// http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
|
||||
// also replace < with a . since < messes up the output on web browsers
|
||||
@ -1417,7 +1445,7 @@ class SSH1
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
function _format_log_helper($matches)
|
||||
private function format_log_helper($matches)
|
||||
{
|
||||
return $this->log_boundary . str_pad(dechex(ord($matches[0])), 2, '0', STR_PAD_LEFT);
|
||||
}
|
||||
@ -1432,7 +1460,7 @@ class SSH1
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getServerKeyPublicExponent($raw_output = false)
|
||||
public function getServerKeyPublicExponent($raw_output = false)
|
||||
{
|
||||
return $raw_output ? $this->server_key_public_exponent->toBytes() : $this->server_key_public_exponent->toString();
|
||||
}
|
||||
@ -1447,7 +1475,7 @@ class SSH1
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getServerKeyPublicModulus($raw_output = false)
|
||||
public function getServerKeyPublicModulus($raw_output = false)
|
||||
{
|
||||
return $raw_output ? $this->server_key_public_modulus->toBytes() : $this->server_key_public_modulus->toString();
|
||||
}
|
||||
@ -1462,7 +1490,7 @@ class SSH1
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getHostKeyPublicExponent($raw_output = false)
|
||||
public function getHostKeyPublicExponent($raw_output = false)
|
||||
{
|
||||
return $raw_output ? $this->host_key_public_exponent->toBytes() : $this->host_key_public_exponent->toString();
|
||||
}
|
||||
@ -1477,7 +1505,7 @@ class SSH1
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getHostKeyPublicModulus($raw_output = false)
|
||||
public function getHostKeyPublicModulus($raw_output = false)
|
||||
{
|
||||
return $raw_output ? $this->host_key_public_modulus->toBytes() : $this->host_key_public_modulus->toString();
|
||||
}
|
||||
@ -1493,7 +1521,7 @@ class SSH1
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function getSupportedCiphers($raw_output = false)
|
||||
public function getSupportedCiphers($raw_output = false)
|
||||
{
|
||||
return $raw_output ? array_keys($this->supported_ciphers) : array_values($this->supported_ciphers);
|
||||
}
|
||||
@ -1509,7 +1537,7 @@ class SSH1
|
||||
* @return array
|
||||
* @access public
|
||||
*/
|
||||
function getSupportedAuthentications($raw_output = false)
|
||||
public function getSupportedAuthentications($raw_output = false)
|
||||
{
|
||||
return $raw_output ? array_keys($this->supported_authentications) : array_values($this->supported_authentications);
|
||||
}
|
||||
@ -1520,7 +1548,7 @@ class SSH1
|
||||
* @return string
|
||||
* @access public
|
||||
*/
|
||||
function getServerIdentification()
|
||||
public function getServerIdentification()
|
||||
{
|
||||
return rtrim($this->server_identification);
|
||||
}
|
||||
@ -1533,7 +1561,7 @@ class SSH1
|
||||
* @param string $data
|
||||
* @access private
|
||||
*/
|
||||
function _append_log($protocol_flags, $message)
|
||||
private function append_log($protocol_flags, $message)
|
||||
{
|
||||
switch (NET_SSH1_LOGGING) {
|
||||
// useful for benchmarks
|
||||
@ -1555,7 +1583,7 @@ class SSH1
|
||||
// passwords won't be filtered out and select other packets may not be correctly
|
||||
// identified
|
||||
case self::LOG_REALTIME:
|
||||
echo "<pre>\r\n" . $this->_format_log([$message], [$protocol_flags]) . "\r\n</pre>\r\n";
|
||||
echo "<pre>\r\n" . $this->format_log([$message], [$protocol_flags]) . "\r\n</pre>\r\n";
|
||||
@flush();
|
||||
@ob_flush();
|
||||
break;
|
||||
@ -1573,7 +1601,7 @@ class SSH1
|
||||
if (!is_resource($this->realtime_log_file)) {
|
||||
break;
|
||||
}
|
||||
$entry = $this->_format_log([$message], [$protocol_flags]);
|
||||
$entry = $this->format_log([$message], [$protocol_flags]);
|
||||
if ($this->realtime_log_wrap) {
|
||||
$temp = "<<< START >>>\r\n";
|
||||
$entry.= $temp;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -37,6 +37,7 @@ use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib\Crypt\RSA;
|
||||
use phpseclib\Exception\BadConfigurationException;
|
||||
use phpseclib\System\SSH\Agent\Identity;
|
||||
use phpseclib\Common\Functions\Objects;
|
||||
|
||||
/**
|
||||
* Pure-PHP ssh-agent client identity factory
|
||||
@ -88,30 +89,43 @@ class Agent
|
||||
* @var resource
|
||||
* @access private
|
||||
*/
|
||||
var $fsock;
|
||||
private $fsock;
|
||||
|
||||
/**
|
||||
* Agent forwarding status
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $forward_status = self::FORWARD_NONE;
|
||||
private $forward_status = self::FORWARD_NONE;
|
||||
|
||||
/**
|
||||
* Buffer for accumulating forwarded authentication
|
||||
* agent data arriving on SSH data channel destined
|
||||
* for agent unix socket
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $socket_buffer = '';
|
||||
private $socket_buffer = '';
|
||||
|
||||
/**
|
||||
* Tracking the number of bytes we are expecting
|
||||
* to arrive for the agent socket on the SSH data
|
||||
* channel
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $expected_bytes = 0;
|
||||
private $expected_bytes = 0;
|
||||
|
||||
/**
|
||||
* The current request channel
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
private $request_channel;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
@ -121,7 +135,7 @@ class Agent
|
||||
* @throws \RuntimeException on connection errors
|
||||
* @access public
|
||||
*/
|
||||
function __construct()
|
||||
public function __construct()
|
||||
{
|
||||
switch (true) {
|
||||
case isset($_SERVER['SSH_AUTH_SOCK']):
|
||||
@ -150,7 +164,7 @@ class Agent
|
||||
* @throws \RuntimeException on receipt of unexpected packets
|
||||
* @access public
|
||||
*/
|
||||
function requestIdentities()
|
||||
public function requestIdentities()
|
||||
{
|
||||
if (!$this->fsock) {
|
||||
return [];
|
||||
@ -209,7 +223,7 @@ class Agent
|
||||
* @return bool
|
||||
* @access public
|
||||
*/
|
||||
function startSSHForwarding($ssh)
|
||||
public function startSSHForwarding($ssh)
|
||||
{
|
||||
if ($this->forward_status == self::FORWARD_NONE) {
|
||||
$this->forward_status = self::FORWARD_REQUEST;
|
||||
@ -223,34 +237,33 @@ class Agent
|
||||
* @return bool
|
||||
* @access private
|
||||
*/
|
||||
function _request_forwarding($ssh)
|
||||
private function request_forwarding($ssh)
|
||||
{
|
||||
$request_channel = $ssh->_get_open_channel();
|
||||
if ($request_channel === false) {
|
||||
$this->request_channel = Objects::callFunc($ssh, 'get_open_channel');
|
||||
if ($this->request_channel === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$packet = pack(
|
||||
'CNNa*C',
|
||||
NET_SSH2_MSG_CHANNEL_REQUEST,
|
||||
$ssh->server_channels[$request_channel],
|
||||
Objects::getVar($ssh, 'server_channels')[$this->request_channel],
|
||||
strlen('auth-agent-req@openssh.com'),
|
||||
'auth-agent-req@openssh.com',
|
||||
1
|
||||
);
|
||||
|
||||
$ssh->channel_status[$request_channel] = NET_SSH2_MSG_CHANNEL_REQUEST;
|
||||
|
||||
if (!$ssh->_send_binary_packet($packet)) {
|
||||
$this->update_channel_status($ssh, NET_SSH2_MSG_CHANNEL_REQUEST);
|
||||
if (!Objects::callFunc($ssh, 'send_binary_packet', [$packet])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = $ssh->_get_channel_packet($request_channel);
|
||||
$response = Objects::callFunc($ssh, 'get_channel_packet', [$this->request_channel]);
|
||||
if ($response === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$ssh->channel_status[$request_channel] = NET_SSH2_MSG_CHANNEL_OPEN;
|
||||
$this->update_channel_status($ssh, NET_SSH2_MSG_CHANNEL_OPEN);
|
||||
$this->forward_status = self::FORWARD_ACTIVE;
|
||||
|
||||
return true;
|
||||
@ -266,10 +279,10 @@ class Agent
|
||||
* @param Net_SSH2 $ssh
|
||||
* @access private
|
||||
*/
|
||||
function _on_channel_open($ssh)
|
||||
private function on_channel_open($ssh)
|
||||
{
|
||||
if ($this->forward_status == self::FORWARD_REQUEST) {
|
||||
$this->_request_forwarding($ssh);
|
||||
$this->request_forwarding($ssh);
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,7 +294,7 @@ class Agent
|
||||
* @throws \RuntimeException on connection errors
|
||||
* @access private
|
||||
*/
|
||||
function _forward_data($data)
|
||||
private function forward_data($data)
|
||||
{
|
||||
if ($this->expected_bytes > 0) {
|
||||
$this->socket_buffer.= $data;
|
||||
@ -310,4 +323,18 @@ class Agent
|
||||
|
||||
return pack('Na*', $agent_reply_bytes, $agent_reply_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward data to SSH Agent and return data reply
|
||||
*
|
||||
* @param \phpseclib\Net\SSH2 $ssh
|
||||
* @param integer $status
|
||||
* @access private
|
||||
*/
|
||||
private function update_channel_status($ssh, $status)
|
||||
{
|
||||
$temp = Objects::getVar($ssh, 'channel_status');
|
||||
$temp[$this->request_channel] = $status;
|
||||
Objects::setVar($ssh, 'channel_status', $temp);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class Identity
|
||||
* @access private
|
||||
* @see self::getPublicKey()
|
||||
*/
|
||||
var $key;
|
||||
private $key;
|
||||
|
||||
/**
|
||||
* Key Blob
|
||||
@ -51,7 +51,7 @@ class Identity
|
||||
* @access private
|
||||
* @see self::sign()
|
||||
*/
|
||||
var $key_blob;
|
||||
private $key_blob;
|
||||
|
||||
/**
|
||||
* Socket Resource
|
||||
@ -60,7 +60,7 @@ class Identity
|
||||
* @access private
|
||||
* @see self::sign()
|
||||
*/
|
||||
var $fsock;
|
||||
private $fsock;
|
||||
|
||||
/**
|
||||
* Default Constructor.
|
||||
@ -69,7 +69,7 @@ class Identity
|
||||
* @return \phpseclib\System\SSH\Agent\Identity
|
||||
* @access private
|
||||
*/
|
||||
function __construct($fsock)
|
||||
public function __construct($fsock)
|
||||
{
|
||||
$this->fsock = $fsock;
|
||||
}
|
||||
@ -82,7 +82,7 @@ class Identity
|
||||
* @param \phpseclib\Crypt\RSA $key
|
||||
* @access private
|
||||
*/
|
||||
function setPublicKey($key)
|
||||
public function setPublicKey($key)
|
||||
{
|
||||
$this->key = $key;
|
||||
$this->key->setPublicKey();
|
||||
@ -97,7 +97,7 @@ class Identity
|
||||
* @param string $key_blob
|
||||
* @access private
|
||||
*/
|
||||
function setPublicKeyBlob($key_blob)
|
||||
public function setPublicKeyBlob($key_blob)
|
||||
{
|
||||
$this->key_blob = $key_blob;
|
||||
}
|
||||
@ -111,7 +111,7 @@ class Identity
|
||||
* @return mixed
|
||||
* @access public
|
||||
*/
|
||||
function getPublicKey($type = 'PKCS8')
|
||||
public function getPublicKey($type = 'PKCS8')
|
||||
{
|
||||
return $this->key->getPublicKey($type);
|
||||
}
|
||||
@ -125,7 +125,7 @@ class Identity
|
||||
* @throws \phpseclib\Exception\UnsupportedAlgorithmException if the algorithm is unsupported
|
||||
* @access public
|
||||
*/
|
||||
function setHash($hash = 'sha1')
|
||||
public function setHash($hash = 'sha1')
|
||||
{
|
||||
if ($hash != 'sha1') {
|
||||
throw new UnsupportedAlgorithmException('ssh-agent can only be used with the sha1 hash');
|
||||
@ -144,7 +144,7 @@ class Identity
|
||||
* @throws \phpseclib\Exception\UnsupportedAlgorithmException if the algorithm is unsupported
|
||||
* @access public
|
||||
*/
|
||||
function sign($message, $padding = RSA::PADDING_PKCS1)
|
||||
public function sign($message, $padding = RSA::PADDING_PKCS1)
|
||||
{
|
||||
if ($padding != RSA::PADDING_PKCS1 && $padding != RSA::PADDING_RELAXED_PKCS1) {
|
||||
throw new UnsupportedAlgorithmException('ssh-agent can only create PKCS1 signatures');
|
||||
|
@ -101,4 +101,20 @@ abstract class PhpseclibTestCase extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getVar($obj, $var)
|
||||
{
|
||||
$reflection = new ReflectionClass(get_class($obj));
|
||||
$prop = $reflection->getProperty($var);
|
||||
$prop->setAccessible(true);
|
||||
return $prop->getValue($obj);
|
||||
}
|
||||
|
||||
public static function callFunc($obj, $func, $params = array())
|
||||
{
|
||||
$reflection = new ReflectionClass(get_class($obj));
|
||||
$method = $reflection->getMethod($func);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($obj, $params);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
use phpseclib\Crypt\Common\BlockCipher;
|
||||
use phpseclib\Crypt\Blowfish;
|
||||
use phpseclib\Crypt\Random;
|
||||
|
||||
class Unit_Crypt_BlowfishTest extends PhpseclibTestCase
|
||||
{
|
||||
@ -86,4 +87,47 @@ class Unit_Crypt_BlowfishTest extends PhpseclibTestCase
|
||||
$plaintext = bin2hex($plaintext);
|
||||
$this->assertEquals($result, $expected, "Failed asserting that $plaintext yielded expected output in $engineName engine");
|
||||
}
|
||||
|
||||
public function testKeySizes()
|
||||
{
|
||||
$objects = $engines = array();
|
||||
$temp = new Blowfish(Blowfish::MODE_CTR);
|
||||
$temp->setPreferredEngine(Blowfish::ENGINE_INTERNAL);
|
||||
$objects[] = $temp;
|
||||
$engines[] = 'internal';
|
||||
|
||||
if ($temp->isValidEngine(Blowfish::ENGINE_MCRYPT)) {
|
||||
$temp = new Blowfish(Blowfish::MODE_CTR);
|
||||
$temp->setPreferredEngine(Blowfish::ENGINE_MCRYPT);
|
||||
$objects[] = $temp;
|
||||
$engines[] = 'mcrypt';
|
||||
}
|
||||
|
||||
if ($temp->isValidEngine(Blowfish::ENGINE_OPENSSL)) {
|
||||
$temp = new Blowfish(Blowfish::MODE_CTR);
|
||||
$temp->setPreferredEngine(Blowfish::ENGINE_OPENSSL);
|
||||
$objects[] = $temp;
|
||||
$engines[] = 'OpenSSL';
|
||||
}
|
||||
|
||||
if (count($objects) < 2) {
|
||||
self::markTestSkipped('Unable to initialize two or more engines');
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($objects); $i++) {
|
||||
$objects[$i]->setIV(str_repeat('x', $objects[$i]->getBlockLength() >> 3));
|
||||
}
|
||||
|
||||
$plaintext = str_repeat('.', 100);
|
||||
|
||||
for ($keyLen = 4; $keyLen <= 56; $keyLen++) {
|
||||
$key = Random::string($keyLen);
|
||||
$objects[0]->setKey($key);
|
||||
$ref = $objects[0]->encrypt($plaintext);
|
||||
for ($i = 1; $i < count($objects); $i++) {
|
||||
$objects[$i]->setKey($key);
|
||||
$this->assertEquals($ref, $objects[$i]->encrypt($plaintext), "Failed asserting that {$engines[$i]} yields the same output as the internal engine with a key size of $keyLen");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
use phpseclib\Crypt\Common\StreamCipher;
|
||||
use phpseclib\Crypt\RC4;
|
||||
use phpseclib\Crypt\Random;
|
||||
|
||||
class Unit_Crypt_RC4Test extends PhpseclibTestCase
|
||||
{
|
||||
@ -209,4 +210,43 @@ class Unit_Crypt_RC4Test extends PhpseclibTestCase
|
||||
$result = $rc4->encrypt(str_repeat("\0", $offset + 16));
|
||||
$this->assertEquals(bin2hex(substr($result, -16)), $expected, "Failed asserting that key $key yielded expected output at offset $offset in $engineName engine");
|
||||
}
|
||||
|
||||
public function testKeySizes()
|
||||
{
|
||||
$objects = $engines = array();
|
||||
$temp = new RC4(RC4::MODE_CTR);
|
||||
$temp->setPreferredEngine(RC4::ENGINE_INTERNAL);
|
||||
$objects[] = $temp;
|
||||
$engines[] = 'internal';
|
||||
|
||||
if ($temp->isValidEngine(RC4::ENGINE_MCRYPT)) {
|
||||
$temp = new RC4(RC4::MODE_CTR);
|
||||
$temp->setPreferredEngine(RC4::ENGINE_MCRYPT);
|
||||
$objects[] = $temp;
|
||||
$engines[] = 'mcrypt';
|
||||
}
|
||||
|
||||
if ($temp->isValidEngine(RC4::ENGINE_OPENSSL)) {
|
||||
$temp = new RC4(RC4::MODE_CTR);
|
||||
$temp->setPreferredEngine(RC4::ENGINE_OPENSSL);
|
||||
$objects[] = $temp;
|
||||
$engines[] = 'OpenSSL';
|
||||
}
|
||||
|
||||
if (count($objects) < 2) {
|
||||
self::markTestSkipped('Unable to initialize two or more engines');
|
||||
}
|
||||
|
||||
$plaintext = str_repeat('.', 100);
|
||||
|
||||
for ($keyLen = 5; $keyLen <= 256; $keyLen++) {
|
||||
$key = Random::string($keyLen);
|
||||
$objects[0]->setKey($key);
|
||||
$ref = $objects[0]->encrypt($plaintext);
|
||||
for ($i = 1; $i < count($objects); $i++) {
|
||||
$objects[$i]->setKey($key);
|
||||
$this->assertEquals($ref, $objects[$i]->encrypt($plaintext), "Failed asserting that {$engines[$i]} yields the same output as the internal engine with a key size of $keyLen");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ class Unit_Math_BigInteger_InternalTest extends Unit_Math_BigInteger_TestCase
|
||||
{
|
||||
$x = new \phpseclib\Math\BigInteger('FFFFFFFFFFFFFFFFC90FDA', 16);
|
||||
$y = new \phpseclib\Math\BigInteger("$x");
|
||||
$this->assertSame($x->value, $y->value);
|
||||
|
||||
$this->assertSame(self::getVar($x, 'value'), self::getVar($y, 'value'));
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class Unit_Net_SSH1Test extends PhpseclibTestCase
|
||||
->setMethods(null)
|
||||
->getMock();
|
||||
|
||||
$result = $ssh->_format_log($message_log, $message_number_log);
|
||||
$result = self::callFunc($ssh, 'format_log', array($message_log, $message_number_log));
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
@ -32,13 +32,13 @@ class Unit_Net_SSH2Test extends PhpseclibTestCase
|
||||
{
|
||||
$ssh = $this->createSSHMock();
|
||||
|
||||
$result = $ssh->_format_log($message_log, $message_number_log);
|
||||
$result = self::callFunc($ssh, 'format_log', array($message_log, $message_number_log));
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testGenerateIdentifier()
|
||||
{
|
||||
$identifier = $this->createSSHMock()->_generate_identifier();
|
||||
$identifier = self::callFunc($this->createSSHMock(), 'generate_identifier');
|
||||
$this->assertStringStartsWith('SSH-2.0-phpseclib_2.0', $identifier);
|
||||
|
||||
if (extension_loaded('libsodium')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user