Update phpseclib

This commit is contained in:
RainLoop Team 2019-03-28 01:51:23 +03:00
parent 909cd45769
commit 71ac99f517
26 changed files with 35671 additions and 32243 deletions

View file

@ -61,7 +61,10 @@ class Utils
if (!\class_exists('Crypt_RSA', false)) if (!\class_exists('Crypt_RSA', false))
{ {
include_once 'Crypt/RSA.php'; include_once 'Crypt/RSA.php';
\defined('CRYPT_RSA_MODE') || \define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL); if (!\defined('CRYPT_RSA_MODE') && \defined('CRYPT_RSA_MODE_INTERNAL'))
{
\define('CRYPT_RSA_MODE', CRYPT_RSA_MODE_INTERNAL);
}
} }
if (\class_exists('Crypt_RSA')) if (\class_exists('Crypt_RSA'))

46
rainloop/v/0.0.0/app/libraries/phpseclib/Crypt/AES.php Normal file → Executable file
View file

@ -7,13 +7,17 @@
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
* *
* If {@link Crypt_AES::setKeyLength() setKeyLength()} isn't called, it'll be calculated from * NOTE: Since AES.php is (for compatibility and phpseclib-historical reasons) virtually
* {@link Crypt_AES::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits * just a wrapper to Rijndael.php you may consider using Rijndael.php instead of
* it'll be null-padded to 192-bits and 192 bits will be the key length until {@link Crypt_AES::setKey() setKey()} * to save one include_once().
*
* If {@link self::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
* {@link self::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's 136-bits
* it'll be null-padded to 192-bits and 192 bits will be the key length until {@link self::setKey() setKey()}
* is called, again, at which point, it'll be recalculated. * is called, again, at which point, it'll be recalculated.
* *
* Since Crypt_AES extends Crypt_Rijndael, some functions are available to be called that, in the context of AES, don't * Since Crypt_AES extends Crypt_Rijndael, some functions are available to be called that, in the context of AES, don't
* make a whole lot of sense. {@link Crypt_AES::setBlockLength() setBlockLength()}, for instance. Calling that function, * make a whole lot of sense. {@link self::setBlockLength() setBlockLength()}, for instance. Calling that function,
* however possible, won't do anything (AES has a fixed block length whereas Rijndael has a variable one). * however possible, won't do anything (AES has a fixed block length whereas Rijndael has a variable one).
* *
* Here's a short example of how to use this library: * Here's a short example of how to use this library:
@ -70,8 +74,8 @@ if (!class_exists('Crypt_Rijndael')) {
/**#@+ /**#@+
* @access public * @access public
* @see Crypt_AES::encrypt() * @see self::encrypt()
* @see Crypt_AES::decrypt() * @see self::decrypt()
*/ */
/** /**
* Encrypt / decrypt using the Counter mode. * Encrypt / decrypt using the Counter mode.
@ -107,20 +111,6 @@ define('CRYPT_AES_MODE_CFB', CRYPT_MODE_CFB);
define('CRYPT_AES_MODE_OFB', CRYPT_MODE_OFB); define('CRYPT_AES_MODE_OFB', CRYPT_MODE_OFB);
/**#@-*/ /**#@-*/
/**#@+
* @access private
* @see Crypt_Base::Crypt_Base()
*/
/**
* Toggles the internal implementation
*/
define('CRYPT_AES_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
/**
* Toggles the mcrypt implementation
*/
define('CRYPT_AES_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
/**#@-*/
/** /**
* Pure-PHP implementation of AES. * Pure-PHP implementation of AES.
* *
@ -134,7 +124,7 @@ class Crypt_AES extends Crypt_Rijndael
* The namespace used by the cipher for its constants. * The namespace used by the cipher for its constants.
* *
* @see Crypt_Base::const_namespace * @see Crypt_Base::const_namespace
* @var String * @var string
* @access private * @access private
*/ */
var $const_namespace = 'AES'; var $const_namespace = 'AES';
@ -146,7 +136,7 @@ class Crypt_AES extends Crypt_Rijndael
* *
* @see Crypt_Rijndael::setBlockLength() * @see Crypt_Rijndael::setBlockLength()
* @access public * @access public
* @param Integer $length * @param int $length
*/ */
function setBlockLength($length) function setBlockLength($length)
{ {
@ -161,7 +151,7 @@ class Crypt_AES extends Crypt_Rijndael
* *
* @see Crypt_Rijndael:setKeyLength() * @see Crypt_Rijndael:setKeyLength()
* @access public * @access public
* @param Integer $length * @param int $length
*/ */
function setKeyLength($length) function setKeyLength($length)
{ {
@ -183,7 +173,7 @@ class Crypt_AES extends Crypt_Rijndael
* @see Crypt_Rijndael:setKey() * @see Crypt_Rijndael:setKey()
* @see setKeyLength() * @see setKeyLength()
* @access public * @access public
* @param String $key * @param string $key
*/ */
function setKey($key) function setKey($key)
{ {
@ -193,15 +183,15 @@ class Crypt_AES extends Crypt_Rijndael
$length = strlen($key); $length = strlen($key);
switch (true) { switch (true) {
case $length <= 16: case $length <= 16:
$this->key_size = 16; $this->key_length = 16;
break; break;
case $length <= 24: case $length <= 24:
$this->key_size = 24; $this->key_length = 24;
break; break;
default: default:
$this->key_size = 32; $this->key_length = 32;
} }
$this->_setupEngine(); $this->_setEngine();
} }
} }
} }

1217
rainloop/v/0.0.0/app/libraries/phpseclib/Crypt/Base.php Normal file → Executable file

File diff suppressed because it is too large Load diff

View file

@ -64,8 +64,8 @@ if (!class_exists('Crypt_Base')) {
/**#@+ /**#@+
* @access public * @access public
* @see Crypt_Blowfish::encrypt() * @see self::encrypt()
* @see Crypt_Blowfish::decrypt() * @see self::decrypt()
*/ */
/** /**
* Encrypt / decrypt using the Counter mode. * Encrypt / decrypt using the Counter mode.
@ -101,20 +101,6 @@ define('CRYPT_BLOWFISH_MODE_CFB', CRYPT_MODE_CFB);
define('CRYPT_BLOWFISH_MODE_OFB', CRYPT_MODE_OFB); define('CRYPT_BLOWFISH_MODE_OFB', CRYPT_MODE_OFB);
/**#@-*/ /**#@-*/
/**#@+
* @access private
* @see Crypt_Base::Crypt_Base()
*/
/**
* Toggles the internal implementation
*/
define('CRYPT_BLOWFISH_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
/**
* Toggles the mcrypt implementation
*/
define('CRYPT_BLOWFISH_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
/**#@-*/
/** /**
* Pure-PHP implementation of Blowfish. * Pure-PHP implementation of Blowfish.
* *
@ -129,26 +115,16 @@ class Crypt_Blowfish extends Crypt_Base
* Block Length of the cipher * Block Length of the cipher
* *
* @see Crypt_Base::block_size * @see Crypt_Base::block_size
* @var Integer * @var int
* @access private * @access private
*/ */
var $block_size = 8; var $block_size = 8;
/**
* The default password key_size used by setPassword()
*
* @see Crypt_Base::password_key_size
* @see Crypt_Base::setPassword()
* @var Integer
* @access private
*/
var $password_key_size = 56;
/** /**
* The namespace used by the cipher for its constants. * The namespace used by the cipher for its constants.
* *
* @see Crypt_Base::const_namespace * @see Crypt_Base::const_namespace
* @var String * @var string
* @access private * @access private
*/ */
var $const_namespace = 'BLOWFISH'; var $const_namespace = 'BLOWFISH';
@ -157,7 +133,7 @@ class Crypt_Blowfish extends Crypt_Base
* The mcrypt specific name of the cipher * The mcrypt specific name of the cipher
* *
* @see Crypt_Base::cipher_name_mcrypt * @see Crypt_Base::cipher_name_mcrypt
* @var String * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'blowfish'; var $cipher_name_mcrypt = 'blowfish';
@ -166,7 +142,7 @@ class Crypt_Blowfish extends Crypt_Base
* Optimizing value while CFB-encrypting * Optimizing value while CFB-encrypting
* *
* @see Crypt_Base::cfb_init_len * @see Crypt_Base::cfb_init_len
* @var Integer * @var int
* @access private * @access private
*/ */
var $cfb_init_len = 500; var $cfb_init_len = 500;
@ -174,7 +150,7 @@ class Crypt_Blowfish extends Crypt_Base
/** /**
* The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each * The fixed subkeys boxes ($sbox0 - $sbox3) with 256 entries each
* *
* S-Box 1 * S-Box 0
* *
* @access private * @access private
* @var array * @var array
@ -340,7 +316,7 @@ class Crypt_Blowfish extends Crypt_Base
/** /**
* P-Array consists of 18 32-bit subkeys * P-Array consists of 18 32-bit subkeys
* *
* @var array $parray * @var array
* @access private * @access private
*/ */
var $parray = array( var $parray = array(
@ -354,7 +330,7 @@ class Crypt_Blowfish extends Crypt_Base
* *
* Holds the expanded key [p] and the key-depended s-boxes [sb] * Holds the expanded key [p] and the key-depended s-boxes [sb]
* *
* @var array $bctx * @var array
* @access private * @access private
*/ */
var $bctx; var $bctx;
@ -362,37 +338,69 @@ class Crypt_Blowfish extends Crypt_Base
/** /**
* Holds the last used key * Holds the last used key
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $kl; var $kl;
/** /**
* Sets the key. * The Key Length (in bytes)
* *
* Keys can be of any length. Blowfish, itself, requires the use of a key between 32 and max. 448-bits long. * @see Crypt_Base::setKeyLength()
* If the key is less than 32-bits we NOT fill the key to 32bit but let the key as it is to be compatible * @var int
* with mcrypt because mcrypt act this way with blowfish key's < 32 bits. * @access private
* @internal The max value is 256 / 8 = 32, the min value is 128 / 8 = 16. Exists in conjunction with $Nk
* because the encryption / decryption / key schedule creation requires this number and not $key_length. We could
* derive this from $key_length or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu
* of that, we'll just precompute it once.
*/
var $key_length = 16;
/**
* Sets the key length.
* *
* If the key is more than 448-bits, we trim the excess bits. * Key lengths can be between 32 and 448 bits.
*
* If the key is not explicitly set, or empty, it'll be assumed a 128 bits key to be all null bytes.
* *
* @access public * @access public
* @see Crypt_Base::setKey() * @param int $length
* @param String $key
*/ */
function setKey($key) function setKeyLength($length)
{ {
$keylength = strlen($key); if ($length < 32) {
$this->key_length = 4;
if (!$keylength) { } elseif ($length > 448) {
$key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; $this->key_length = 56;
} elseif ($keylength > 56) { } else {
$key = substr($key, 0, 56); $this->key_length = $length >> 3;
} }
parent::setKey($key); parent::setKeyLength($length);
}
/**
* Test for engine validity
*
* This is mainly just a wrapper to set things up for Crypt_Base::isValidEngine()
*
* @see Crypt_Base::isValidEngine()
* @param int $engine
* @access public
* @return bool
*/
function isValidEngine($engine)
{
if ($engine == CRYPT_ENGINE_OPENSSL) {
if (version_compare(PHP_VERSION, '5.3.7') < 0 && $this->key_length != 16) {
return false;
}
if ($this->key_length < 16) {
return false;
}
$this->cipher_name_openssl_ecb = 'bf-ecb';
$this->cipher_name_openssl = 'bf-' . $this->_openssl_translate_mode();
}
return parent::isValidEngine($engine);
} }
/** /**
@ -455,8 +463,8 @@ class Crypt_Blowfish extends Crypt_Base
* Encrypts a block * Encrypts a block
* *
* @access private * @access private
* @param String $in * @param string $in
* @return String * @return string
*/ */
function _encryptBlock($in) function _encryptBlock($in)
{ {
@ -473,16 +481,14 @@ class Crypt_Blowfish extends Crypt_Base
for ($i = 0; $i < 16; $i+= 2) { for ($i = 0; $i < 16; $i+= 2) {
$l^= $p[$i]; $l^= $p[$i];
$r^= ($sb_0[$l >> 24 & 0xff] + $r^= $this->safe_intval(($this->safe_intval($sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]) ^
$sb_1[$l >> 16 & 0xff] ^
$sb_2[$l >> 8 & 0xff]) + $sb_2[$l >> 8 & 0xff]) +
$sb_3[$l & 0xff]; $sb_3[$l & 0xff]);
$r^= $p[$i + 1]; $r^= $p[$i + 1];
$l^= ($sb_0[$r >> 24 & 0xff] + $l^= $this->safe_intval(($this->safe_intval($sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]) ^
$sb_1[$r >> 16 & 0xff] ^
$sb_2[$r >> 8 & 0xff]) + $sb_2[$r >> 8 & 0xff]) +
$sb_3[$r & 0xff]; $sb_3[$r & 0xff]);
} }
return pack("N*", $r ^ $p[17], $l ^ $p[16]); return pack("N*", $r ^ $p[17], $l ^ $p[16]);
} }
@ -491,8 +497,8 @@ class Crypt_Blowfish extends Crypt_Base
* Decrypts a block * Decrypts a block
* *
* @access private * @access private
* @param String $in * @param string $in
* @return String * @return string
*/ */
function _decryptBlock($in) function _decryptBlock($in)
{ {
@ -508,18 +514,15 @@ class Crypt_Blowfish extends Crypt_Base
for ($i = 17; $i > 2; $i-= 2) { for ($i = 17; $i > 2; $i-= 2) {
$l^= $p[$i]; $l^= $p[$i];
$r^= ($sb_0[$l >> 24 & 0xff] + $r^= $this->safe_intval(($this->safe_intval($sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]) ^
$sb_1[$l >> 16 & 0xff] ^
$sb_2[$l >> 8 & 0xff]) + $sb_2[$l >> 8 & 0xff]) +
$sb_3[$l & 0xff]; $sb_3[$l & 0xff]);
$r^= $p[$i - 1]; $r^= $p[$i - 1];
$l^= ($sb_0[$r >> 24 & 0xff] + $l^= $this->safe_intval(($this->safe_intval($sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]) ^
$sb_1[$r >> 16 & 0xff] ^
$sb_2[$r >> 8 & 0xff]) + $sb_2[$r >> 8 & 0xff]) +
$sb_3[$r & 0xff]; $sb_3[$r & 0xff]);
} }
return pack("N*", $r ^ $p[0], $l ^ $p[1]); return pack("N*", $r ^ $p[0], $l ^ $p[1]);
} }
@ -534,17 +537,18 @@ class Crypt_Blowfish extends Crypt_Base
$lambda_functions =& Crypt_Blowfish::_getLambdaFunctions(); $lambda_functions =& Crypt_Blowfish::_getLambdaFunctions();
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
// (Currently, for Crypt_Blowfish, one generated $lambda_function cost on php5.5@32bit ~100kb unfreeable mem and ~180kb on php5.5@64bit)
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one. // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one.
$gen_hi_opt_code = (bool)(count($lambda_functions) < 10); $gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
switch (true) { // Generation of a unique hash for our generated code
case $gen_hi_opt_code:
$code_hash = md5(str_pad("Crypt_Blowfish, {$this->mode}, ", 32, "\0") . $this->key);
break;
default:
$code_hash = "Crypt_Blowfish, {$this->mode}"; $code_hash = "Crypt_Blowfish, {$this->mode}";
if ($gen_hi_opt_code) {
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
} }
$safeint = $this->safe_intval_inline();
if (!isset($lambda_functions[$code_hash])) { if (!isset($lambda_functions[$code_hash])) {
switch (true) { switch (true) {
case $gen_hi_opt_code: case $gen_hi_opt_code:
@ -580,16 +584,14 @@ class Crypt_Blowfish extends Crypt_Base
for ($i = 0; $i < 16; $i+= 2) { for ($i = 0; $i < 16; $i+= 2) {
$encrypt_block.= ' $encrypt_block.= '
$l^= ' . $p[$i] . '; $l^= ' . $p[$i] . ';
$r^= ($sb_0[$l >> 24 & 0xff] + $r^= ' . sprintf($safeint, '(' . sprintf($safeint, '$sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]') . ' ^
$sb_1[$l >> 16 & 0xff] ^
$sb_2[$l >> 8 & 0xff]) + $sb_2[$l >> 8 & 0xff]) +
$sb_3[$l & 0xff]; $sb_3[$l & 0xff]') . ';
$r^= ' . $p[$i + 1] . '; $r^= ' . $p[$i + 1] . ';
$l^= ($sb_0[$r >> 24 & 0xff] + $l^= ' . sprintf($safeint, '(' . sprintf($safeint, '$sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]') . ' ^
$sb_1[$r >> 16 & 0xff] ^
$sb_2[$r >> 8 & 0xff]) + $sb_2[$r >> 8 & 0xff]) +
$sb_3[$r & 0xff]; $sb_3[$r & 0xff]') . ';
'; ';
} }
$encrypt_block.= ' $encrypt_block.= '
@ -609,16 +611,14 @@ class Crypt_Blowfish extends Crypt_Base
for ($i = 17; $i > 2; $i-= 2) { for ($i = 17; $i > 2; $i-= 2) {
$decrypt_block.= ' $decrypt_block.= '
$l^= ' . $p[$i] . '; $l^= ' . $p[$i] . ';
$r^= ($sb_0[$l >> 24 & 0xff] + $r^= ' . sprintf($safeint, '(' . sprintf($safeint, '$sb_0[$l >> 24 & 0xff] + $sb_1[$l >> 16 & 0xff]') . ' ^
$sb_1[$l >> 16 & 0xff] ^
$sb_2[$l >> 8 & 0xff]) + $sb_2[$l >> 8 & 0xff]) +
$sb_3[$l & 0xff]; $sb_3[$l & 0xff]') . ';
$r^= ' . $p[$i - 1] . '; $r^= ' . $p[$i - 1] . ';
$l^= ($sb_0[$r >> 24 & 0xff] + $l^= ' . sprintf($safeint, '(' . sprintf($safeint, '$sb_0[$r >> 24 & 0xff] + $sb_1[$r >> 16 & 0xff]') . ' ^
$sb_1[$r >> 16 & 0xff] ^
$sb_2[$r >> 8 & 0xff]) + $sb_2[$r >> 8 & 0xff]) +
$sb_3[$r & 0xff]; $sb_3[$r & 0xff]') . ';
'; ';
} }

170
rainloop/v/0.0.0/app/libraries/phpseclib/Crypt/DES.php Normal file → Executable file
View file

@ -69,8 +69,8 @@ if (!class_exists('Crypt_Base')) {
/**#@+ /**#@+
* @access private * @access private
* @see Crypt_DES::_setupKey() * @see self::_setupKey()
* @see Crypt_DES::_processBlock() * @see self::_processBlock()
*/ */
/** /**
* Contains $keys[CRYPT_DES_ENCRYPT] * Contains $keys[CRYPT_DES_ENCRYPT]
@ -84,8 +84,8 @@ define('CRYPT_DES_DECRYPT', 1);
/**#@+ /**#@+
* @access public * @access public
* @see Crypt_DES::encrypt() * @see self::encrypt()
* @see Crypt_DES::decrypt() * @see self::decrypt()
*/ */
/** /**
* Encrypt / decrypt using the Counter mode. * Encrypt / decrypt using the Counter mode.
@ -121,20 +121,6 @@ define('CRYPT_DES_MODE_CFB', CRYPT_MODE_CFB);
define('CRYPT_DES_MODE_OFB', CRYPT_MODE_OFB); define('CRYPT_DES_MODE_OFB', CRYPT_MODE_OFB);
/**#@-*/ /**#@-*/
/**#@+
* @access private
* @see Crypt_Base::Crypt_Base()
*/
/**
* Toggles the internal implementation
*/
define('CRYPT_DES_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
/**
* Toggles the mcrypt implementation
*/
define('CRYPT_DES_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
/**#@-*/
/** /**
* Pure-PHP implementation of DES. * Pure-PHP implementation of DES.
* *
@ -148,36 +134,25 @@ class Crypt_DES extends Crypt_Base
* Block Length of the cipher * Block Length of the cipher
* *
* @see Crypt_Base::block_size * @see Crypt_Base::block_size
* @var Integer * @var int
* @access private * @access private
*/ */
var $block_size = 8; var $block_size = 8;
/** /**
* The Key * Key Length (in bytes)
* *
* @see Crypt_Base::key * @see Crypt_Base::setKeyLength()
* @see setKey() * @var int
* @var String
* @access private * @access private
*/ */
var $key = "\0\0\0\0\0\0\0\0"; var $key_length = 8;
/**
* The default password key_size used by setPassword()
*
* @see Crypt_Base::password_key_size
* @see Crypt_Base::setPassword()
* @var Integer
* @access private
*/
var $password_key_size = 8;
/** /**
* The namespace used by the cipher for its constants. * The namespace used by the cipher for its constants.
* *
* @see Crypt_Base::const_namespace * @see Crypt_Base::const_namespace
* @var String * @var string
* @access private * @access private
*/ */
var $const_namespace = 'DES'; var $const_namespace = 'DES';
@ -186,16 +161,31 @@ class Crypt_DES extends Crypt_Base
* The mcrypt specific name of the cipher * The mcrypt specific name of the cipher
* *
* @see Crypt_Base::cipher_name_mcrypt * @see Crypt_Base::cipher_name_mcrypt
* @var String * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'des'; var $cipher_name_mcrypt = 'des';
/**
* The OpenSSL names of the cipher / modes
*
* @see Crypt_Base::openssl_mode_names
* @var array
* @access private
*/
var $openssl_mode_names = array(
CRYPT_MODE_ECB => 'des-ecb',
CRYPT_MODE_CBC => 'des-cbc',
CRYPT_MODE_CFB => 'des-cfb',
CRYPT_MODE_OFB => 'des-ofb'
// CRYPT_MODE_CTR is undefined for DES
);
/** /**
* Optimizing value while CFB-encrypting * Optimizing value while CFB-encrypting
* *
* @see Crypt_Base::cfb_init_len * @see Crypt_Base::cfb_init_len
* @var Integer * @var int
* @access private * @access private
*/ */
var $cfb_init_len = 500; var $cfb_init_len = 500;
@ -205,9 +195,9 @@ class Crypt_DES extends Crypt_Base
* *
* Used only if $engine == CRYPT_DES_MODE_INTERNAL * Used only if $engine == CRYPT_DES_MODE_INTERNAL
* *
* @see Crypt_DES::_setupKey() * @see self::_setupKey()
* @see Crypt_DES::_processBlock() * @see self::_processBlock()
* @var Integer * @var int
* @access private * @access private
*/ */
var $des_rounds = 1; var $des_rounds = 1;
@ -215,17 +205,17 @@ class Crypt_DES extends Crypt_Base
/** /**
* max possible size of $key * max possible size of $key
* *
* @see Crypt_DES::setKey() * @see self::setKey()
* @var String * @var string
* @access private * @access private
*/ */
var $key_size_max = 8; var $key_length_max = 8;
/** /**
* The Key Schedule * The Key Schedule
* *
* @see Crypt_DES::_setupKey() * @see self::_setupKey()
* @var Array * @var array
* @access private * @access private
*/ */
var $keys; var $keys;
@ -237,9 +227,9 @@ class Crypt_DES extends Crypt_Base
* with each byte containing all bits in the same state as the * with each byte containing all bits in the same state as the
* corresponding bit in the index value. * corresponding bit in the index value.
* *
* @see Crypt_DES::_processBlock() * @see self::_processBlock()
* @see Crypt_DES::_setupKey() * @see self::_setupKey()
* @var Array * @var array
* @access private * @access private
*/ */
var $shuffle = array( var $shuffle = array(
@ -378,7 +368,7 @@ class Crypt_DES extends Crypt_Base
* *
* Indexing this table with each source byte performs the initial bit permutation. * Indexing this table with each source byte performs the initial bit permutation.
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $ipmap = array( var $ipmap = array(
@ -420,7 +410,7 @@ class Crypt_DES extends Crypt_Base
* Inverse IP mapping helper table. * Inverse IP mapping helper table.
* Indexing this table with a byte value reverses the bit order. * Indexing this table with a byte value reverses the bit order.
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $invipmap = array( var $invipmap = array(
@ -464,7 +454,7 @@ class Crypt_DES extends Crypt_Base
* Each box ($sbox1-$sbox8) has been vectorized, then each value pre-permuted using the * Each box ($sbox1-$sbox8) has been vectorized, then each value pre-permuted using the
* P table: concatenation can then be replaced by exclusive ORs. * P table: concatenation can then be replaced by exclusive ORs.
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $sbox1 = array( var $sbox1 = array(
@ -489,7 +479,7 @@ class Crypt_DES extends Crypt_Base
/** /**
* Pre-permuted S-box2 * Pre-permuted S-box2
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $sbox2 = array( var $sbox2 = array(
@ -514,7 +504,7 @@ class Crypt_DES extends Crypt_Base
/** /**
* Pre-permuted S-box3 * Pre-permuted S-box3
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $sbox3 = array( var $sbox3 = array(
@ -539,7 +529,7 @@ class Crypt_DES extends Crypt_Base
/** /**
* Pre-permuted S-box4 * Pre-permuted S-box4
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $sbox4 = array( var $sbox4 = array(
@ -564,7 +554,7 @@ class Crypt_DES extends Crypt_Base
/** /**
* Pre-permuted S-box5 * Pre-permuted S-box5
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $sbox5 = array( var $sbox5 = array(
@ -589,7 +579,7 @@ class Crypt_DES extends Crypt_Base
/** /**
* Pre-permuted S-box6 * Pre-permuted S-box6
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $sbox6 = array( var $sbox6 = array(
@ -614,7 +604,7 @@ class Crypt_DES extends Crypt_Base
/** /**
* Pre-permuted S-box7 * Pre-permuted S-box7
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $sbox7 = array( var $sbox7 = array(
@ -639,7 +629,7 @@ class Crypt_DES extends Crypt_Base
/** /**
* Pre-permuted S-box8 * Pre-permuted S-box8
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $sbox8 = array( var $sbox8 = array(
@ -661,6 +651,28 @@ class Crypt_DES extends Crypt_Base
0x00000820, 0x00020020, 0x08000000, 0x08020800 0x00000820, 0x00020020, 0x08000000, 0x08020800
); );
/**
* Test for engine validity
*
* This is mainly just a wrapper to set things up for Crypt_Base::isValidEngine()
*
* @see Crypt_Base::isValidEngine()
* @param int $engine
* @access public
* @return bool
*/
function isValidEngine($engine)
{
if ($this->key_length_max == 8) {
if ($engine == CRYPT_ENGINE_OPENSSL) {
$this->cipher_name_openssl_ecb = 'des-ecb';
$this->cipher_name_openssl = 'des-' . $this->_openssl_translate_mode();
}
}
return parent::isValidEngine($engine);
}
/** /**
* Sets the key. * Sets the key.
* *
@ -674,14 +686,14 @@ class Crypt_DES extends Crypt_Base
* *
* @see Crypt_Base::setKey() * @see Crypt_Base::setKey()
* @access public * @access public
* @param String $key * @param string $key
*/ */
function setKey($key) function setKey($key)
{ {
// We check/cut here only up to max length of the key. // We check/cut here only up to max length of the key.
// Key padding to the proper length will be done in _setupKey() // Key padding to the proper length will be done in _setupKey()
if (strlen($key) > $this->key_size_max) { if (strlen($key) > $this->key_length_max) {
$key = substr($key, 0, $this->key_size_max); $key = substr($key, 0, $this->key_length_max);
} }
// Sets the key // Sets the key
@ -693,10 +705,10 @@ class Crypt_DES extends Crypt_Base
* *
* @see Crypt_Base::_encryptBlock() * @see Crypt_Base::_encryptBlock()
* @see Crypt_Base::encrypt() * @see Crypt_Base::encrypt()
* @see Crypt_DES::encrypt() * @see self::encrypt()
* @access private * @access private
* @param String $in * @param string $in
* @return String * @return string
*/ */
function _encryptBlock($in) function _encryptBlock($in)
{ {
@ -708,10 +720,10 @@ class Crypt_DES extends Crypt_Base
* *
* @see Crypt_Base::_decryptBlock() * @see Crypt_Base::_decryptBlock()
* @see Crypt_Base::decrypt() * @see Crypt_Base::decrypt()
* @see Crypt_DES::decrypt() * @see self::decrypt()
* @access private * @access private
* @param String $in * @param string $in
* @return String * @return string
*/ */
function _decryptBlock($in) function _decryptBlock($in)
{ {
@ -725,12 +737,12 @@ class Crypt_DES extends Crypt_Base
* {@link http://en.wikipedia.org/wiki/Image:Feistel.png Feistel.png} to get a general * {@link http://en.wikipedia.org/wiki/Image:Feistel.png Feistel.png} to get a general
* idea of what this function does. * idea of what this function does.
* *
* @see Crypt_DES::_encryptBlock() * @see self::_encryptBlock()
* @see Crypt_DES::_decryptBlock() * @see self::_decryptBlock()
* @access private * @access private
* @param String $block * @param string $block
* @param Integer $mode * @param int $mode
* @return String * @return string
*/ */
function _processBlock($block, $mode) function _processBlock($block, $mode)
{ {
@ -1358,21 +1370,20 @@ class Crypt_DES extends Crypt_Base
$des_rounds = $this->des_rounds; $des_rounds = $this->des_rounds;
// We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function. // We create max. 10 hi-optimized code for memory reason. Means: For each $key one ultra fast inline-crypt function.
// (Currently, for Crypt_DES, one generated $lambda_function cost on php5.5@32bit ~135kb unfreeable mem and ~230kb on php5.5@64bit)
// (Currently, for Crypt_TripleDES, one generated $lambda_function cost on php5.5@32bit ~240kb unfreeable mem and ~340kb on php5.5@64bit)
// After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one // After that, we'll still create very fast optimized code but not the hi-ultimative code, for each $mode one
$gen_hi_opt_code = (bool)( count($lambda_functions) < 10 ); $gen_hi_opt_code = (bool)( count($lambda_functions) < 10 );
// Generation of a uniqe hash for our generated code // Generation of a unique hash for our generated code
switch (true) { $code_hash = "Crypt_DES, $des_rounds, {$this->mode}";
case $gen_hi_opt_code: if ($gen_hi_opt_code) {
// For hi-optimized code, we create for each combination of // For hi-optimized code, we create for each combination of
// $mode, $des_rounds and $this->key its own encrypt/decrypt function. // $mode, $des_rounds and $this->key its own encrypt/decrypt function.
$code_hash = md5(str_pad("Crypt_DES, $des_rounds, {$this->mode}, ", 32, "\0") . $this->key);
break;
default:
// After max 10 hi-optimized functions, we create generic // After max 10 hi-optimized functions, we create generic
// (still very fast.. but not ultra) functions for each $mode/$des_rounds // (still very fast.. but not ultra) functions for each $mode/$des_rounds
// Currently 2 * 5 generic functions will be then max. possible. // Currently 2 * 5 generic functions will be then max. possible.
$code_hash = "Crypt_DES, $des_rounds, {$this->mode}"; $code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
} }
// Is there a re-usable $lambda_functions in there? If not, we have to create it. // Is there a re-usable $lambda_functions in there? If not, we have to create it.
@ -1427,7 +1438,6 @@ class Crypt_DES extends Crypt_Base
// Creating code for en- and decryption. // Creating code for en- and decryption.
$crypt_block = array(); $crypt_block = array();
foreach (array(CRYPT_DES_ENCRYPT, CRYPT_DES_DECRYPT) as $c) { foreach (array(CRYPT_DES_ENCRYPT, CRYPT_DES_DECRYPT) as $c) {
/* Do the initial IP permutation. */ /* Do the initial IP permutation. */
$crypt_block[$c] = ' $crypt_block[$c] = '
$in = unpack("N*", $in); $in = unpack("N*", $in);

226
rainloop/v/0.0.0/app/libraries/phpseclib/Crypt/Hash.php Normal file → Executable file
View file

@ -7,7 +7,7 @@
* *
* md2, md5, md5-96, sha1, sha1-96, sha256, sha256-96, sha384, and sha512, sha512-96 * md2, md5, md5-96, sha1, sha1-96, sha256, sha256-96, sha384, and sha512, sha512-96
* *
* If {@link Crypt_Hash::setKey() setKey()} is called, {@link Crypt_Hash::hash() hash()} will return the HMAC as opposed to * If {@link self::setKey() setKey()} is called, {@link self::hash() hash()} will return the HMAC as opposed to
* the hash. If no valid algorithm is provided, sha1 will be used. * the hash. If no valid algorithm is provided, sha1 will be used.
* *
* PHP versions 4 and 5 * PHP versions 4 and 5
@ -56,7 +56,7 @@
/**#@+ /**#@+
* @access private * @access private
* @see Crypt_Hash::Crypt_Hash() * @see self::Crypt_Hash()
*/ */
/** /**
* Toggles the internal implementation * Toggles the internal implementation
@ -84,8 +84,8 @@ class Crypt_Hash
/** /**
* Hash Parameter * Hash Parameter
* *
* @see Crypt_Hash::setHash() * @see self::setHash()
* @var Integer * @var int
* @access private * @access private
*/ */
var $hashParam; var $hashParam;
@ -93,8 +93,8 @@ class Crypt_Hash
/** /**
* Byte-length of compression blocks / key (Internal HMAC) * Byte-length of compression blocks / key (Internal HMAC)
* *
* @see Crypt_Hash::setAlgorithm() * @see self::setAlgorithm()
* @var Integer * @var int
* @access private * @access private
*/ */
var $b; var $b;
@ -102,8 +102,8 @@ class Crypt_Hash
/** /**
* Byte-length of hash output (Internal HMAC) * Byte-length of hash output (Internal HMAC)
* *
* @see Crypt_Hash::setHash() * @see self::setHash()
* @var Integer * @var int
* @access private * @access private
*/ */
var $l = false; var $l = false;
@ -111,8 +111,8 @@ class Crypt_Hash
/** /**
* Hash Algorithm * Hash Algorithm
* *
* @see Crypt_Hash::setHash() * @see self::setHash()
* @var String * @var string
* @access private * @access private
*/ */
var $hash; var $hash;
@ -120,17 +120,26 @@ class Crypt_Hash
/** /**
* Key * Key
* *
* @see Crypt_Hash::setKey() * @see self::setKey()
* @var String * @var string
* @access private * @access private
*/ */
var $key = false; var $key = false;
/**
* Computed Key
*
* @see self::_computeKey()
* @var string
* @access private
*/
var $computedKey = false;
/** /**
* Outer XOR (Internal HMAC) * Outer XOR (Internal HMAC)
* *
* @see Crypt_Hash::setKey() * @see self::setKey()
* @var String * @var string
* @access private * @access private
*/ */
var $opad; var $opad;
@ -138,20 +147,29 @@ class Crypt_Hash
/** /**
* Inner XOR (Internal HMAC) * Inner XOR (Internal HMAC)
* *
* @see Crypt_Hash::setKey() * @see self::setKey()
* @var String * @var string
* @access private * @access private
*/ */
var $ipad; var $ipad;
/**
* Engine
*
* @see self::setHash()
* @var string
* @access private
*/
var $engine;
/** /**
* Default Constructor. * Default Constructor.
* *
* @param optional String $hash * @param string $hash
* @return Crypt_Hash * @return Crypt_Hash
* @access public * @access public
*/ */
function Crypt_Hash($hash = 'sha1') function __construct($hash = 'sha1')
{ {
if (!defined('CRYPT_HASH_MODE')) { if (!defined('CRYPT_HASH_MODE')) {
switch (true) { switch (true) {
@ -169,17 +187,66 @@ class Crypt_Hash
$this->setHash($hash); $this->setHash($hash);
} }
/**
* PHP4 compatible Default Constructor.
*
* @see self::__construct()
* @param int $mode
* @access public
*/
function Crypt_Hash($hash = 'sha1')
{
$this->__construct($hash);
}
/** /**
* Sets the key for HMACs * Sets the key for HMACs
* *
* Keys can be of any length. * Keys can be of any length.
* *
* @access public * @access public
* @param optional String $key * @param string $key
*/ */
function setKey($key = false) function setKey($key = false)
{ {
$this->key = $key; $this->key = $key;
$this->_computeKey();
}
/**
* Pre-compute the key used by the HMAC
*
* Quoting http://tools.ietf.org/html/rfc2104#section-2, "Applications that use keys longer than B bytes
* will first hash the key using H and then use the resultant L byte string as the actual key to HMAC."
*
* As documented in https://www.reddit.com/r/PHP/comments/9nct2l/symfonypolyfill_hash_pbkdf2_correct_fix_for/
* when doing an HMAC multiple times it's faster to compute the hash once instead of computing it during
* every call
*
* @access private
*/
function _computeKey()
{
if ($this->key === false) {
$this->computedKey = false;
return;
}
if (strlen($this->key) <= $this->b) {
$this->computedKey = $this->key;
return;
}
switch ($this->engine) {
case CRYPT_HASH_MODE_MHASH:
$this->computedKey = mhash($this->hash, $this->key);
break;
case CRYPT_HASH_MODE_HASH:
$this->computedKey = hash($this->hash, $this->key, true);
break;
case CRYPT_HASH_MODE_INTERNAL:
$this->computedKey = call_user_func($this->hash, $this->key);
}
} }
/** /**
@ -188,7 +255,7 @@ class Crypt_Hash
* As set by the constructor or by the setHash() method. * As set by the constructor or by the setHash() method.
* *
* @access public * @access public
* @return String * @return string
*/ */
function getHash() function getHash()
{ {
@ -199,7 +266,7 @@ class Crypt_Hash
* Sets the hash function. * Sets the hash function.
* *
* @access public * @access public
* @param String $hash * @param string $hash
*/ */
function setHash($hash) function setHash($hash)
{ {
@ -230,19 +297,38 @@ class Crypt_Hash
} }
switch ($hash) { switch ($hash) {
case 'md2-96':
case 'md2': case 'md2':
$mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_HASH && in_array('md2', hash_algos()) ? $this->b = 16;
case 'md5-96':
case 'sha1-96':
case 'sha224-96':
case 'sha256-96':
case 'md2':
case 'md5':
case 'sha1':
case 'sha224':
case 'sha256':
$this->b = 64;
break;
default:
$this->b = 128;
}
switch ($hash) {
case 'md2':
$this->engine = CRYPT_HASH_MODE == CRYPT_HASH_MODE_HASH && in_array('md2', hash_algos()) ?
CRYPT_HASH_MODE_HASH : CRYPT_HASH_MODE_INTERNAL; CRYPT_HASH_MODE_HASH : CRYPT_HASH_MODE_INTERNAL;
break; break;
case 'sha384': case 'sha384':
case 'sha512': case 'sha512':
$mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_MHASH ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE; $this->engine = CRYPT_HASH_MODE == CRYPT_HASH_MODE_MHASH ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
break; break;
default: default:
$mode = CRYPT_HASH_MODE; $this->engine = CRYPT_HASH_MODE;
} }
switch ( $mode ) { switch ($this->engine) {
case CRYPT_HASH_MODE_MHASH: case CRYPT_HASH_MODE_MHASH:
switch ($hash) { switch ($hash) {
case 'md5': case 'md5':
@ -255,6 +341,7 @@ class Crypt_Hash
default: default:
$this->hash = MHASH_SHA1; $this->hash = MHASH_SHA1;
} }
$this->_computeKey();
return; return;
case CRYPT_HASH_MODE_HASH: case CRYPT_HASH_MODE_HASH:
switch ($hash) { switch ($hash) {
@ -271,64 +358,54 @@ class Crypt_Hash
default: default:
$this->hash = 'sha1'; $this->hash = 'sha1';
} }
$this->_computeKey();
return; return;
} }
switch ($hash) { switch ($hash) {
case 'md2': case 'md2':
$this->b = 16;
$this->hash = array($this, '_md2'); $this->hash = array($this, '_md2');
break; break;
case 'md5': case 'md5':
$this->b = 64;
$this->hash = array($this, '_md5'); $this->hash = array($this, '_md5');
break; break;
case 'sha256': case 'sha256':
$this->b = 64;
$this->hash = array($this, '_sha256'); $this->hash = array($this, '_sha256');
break; break;
case 'sha384': case 'sha384':
case 'sha512': case 'sha512':
$this->b = 128;
$this->hash = array($this, '_sha512'); $this->hash = array($this, '_sha512');
break; break;
case 'sha1': case 'sha1':
default: default:
$this->b = 64;
$this->hash = array($this, '_sha1'); $this->hash = array($this, '_sha1');
} }
$this->ipad = str_repeat(chr(0x36), $this->b); $this->ipad = str_repeat(chr(0x36), $this->b);
$this->opad = str_repeat(chr(0x5C), $this->b); $this->opad = str_repeat(chr(0x5C), $this->b);
$this->_computeKey();
} }
/** /**
* Compute the HMAC. * Compute the HMAC.
* *
* @access public * @access public
* @param String $text * @param string $text
* @return String * @return string
*/ */
function hash($text) function hash($text)
{ {
$mode = is_array($this->hash) ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
if (!empty($this->key) || is_string($this->key)) { if (!empty($this->key) || is_string($this->key)) {
switch ( $mode ) { switch ($this->engine) {
case CRYPT_HASH_MODE_MHASH: case CRYPT_HASH_MODE_MHASH:
$output = mhash($this->hash, $text, $this->key); $output = mhash($this->hash, $text, $this->computedKey);
break; break;
case CRYPT_HASH_MODE_HASH: case CRYPT_HASH_MODE_HASH:
$output = hash_hmac($this->hash, $text, $this->key, true); $output = hash_hmac($this->hash, $text, $this->computedKey, true);
break; break;
case CRYPT_HASH_MODE_INTERNAL: case CRYPT_HASH_MODE_INTERNAL:
/* "Applications that use keys longer than B bytes will first hash the key using H and then use the $key = str_pad($this->computedKey, $this->b, chr(0)); // step 1
resultant L byte string as the actual key to HMAC."
-- http://tools.ietf.org/html/rfc2104#section-2 */
$key = strlen($this->key) > $this->b ? call_user_func($this->hash, $this->key) : $this->key;
$key = str_pad($key, $this->b, chr(0)); // step 1
$temp = $this->ipad ^ $key; // step 2 $temp = $this->ipad ^ $key; // step 2
$temp .= $text; // step 3 $temp .= $text; // step 3
$temp = call_user_func($this->hash, $temp); // step 4 $temp = call_user_func($this->hash, $temp); // step 4
@ -337,7 +414,7 @@ class Crypt_Hash
$output = call_user_func($this->hash, $output); // step 7 $output = call_user_func($this->hash, $output); // step 7
} }
} else { } else {
switch ( $mode ) { switch ($this->engine) {
case CRYPT_HASH_MODE_MHASH: case CRYPT_HASH_MODE_MHASH:
$output = mhash($this->hash, $text); $output = mhash($this->hash, $text);
break; break;
@ -356,7 +433,7 @@ class Crypt_Hash
* Returns the hash length (in bytes) * Returns the hash length (in bytes)
* *
* @access public * @access public
* @return Integer * @return int
*/ */
function getLength() function getLength()
{ {
@ -367,7 +444,7 @@ class Crypt_Hash
* Wrapper for MD5 * Wrapper for MD5
* *
* @access private * @access private
* @param String $m * @param string $m
*/ */
function _md5($m) function _md5($m)
{ {
@ -378,7 +455,7 @@ class Crypt_Hash
* Wrapper for SHA1 * Wrapper for SHA1
* *
* @access private * @access private
* @param String $m * @param string $m
*/ */
function _sha1($m) function _sha1($m)
{ {
@ -391,7 +468,7 @@ class Crypt_Hash
* See {@link http://tools.ietf.org/html/rfc1319 RFC1319}. * See {@link http://tools.ietf.org/html/rfc1319 RFC1319}.
* *
* @access private * @access private
* @param String $m * @param string $m
*/ */
function _md2($m) function _md2($m)
{ {
@ -467,7 +544,7 @@ class Crypt_Hash
* See {@link http://en.wikipedia.org/wiki/SHA_hash_functions#SHA-256_.28a_SHA-2_variant.29_pseudocode SHA-256 (a SHA-2 variant) pseudocode - Wikipedia}. * See {@link http://en.wikipedia.org/wiki/SHA_hash_functions#SHA-256_.28a_SHA-2_variant.29_pseudocode SHA-256 (a SHA-2 variant) pseudocode - Wikipedia}.
* *
* @access private * @access private
* @param String $m * @param string $m
*/ */
function _sha256($m) function _sha256($m)
{ {
@ -511,14 +588,15 @@ class Crypt_Hash
// Extend the sixteen 32-bit words into sixty-four 32-bit words // Extend the sixteen 32-bit words into sixty-four 32-bit words
for ($i = 16; $i < 64; $i++) { for ($i = 16; $i < 64; $i++) {
// @codingStandardsIgnoreStart
$s0 = $this->_rightRotate($w[$i - 15], 7) ^ $s0 = $this->_rightRotate($w[$i - 15], 7) ^
$this->_rightRotate($w[$i - 15], 18) ^ $this->_rightRotate($w[$i - 15], 18) ^
$this->_rightShift( $w[$i - 15], 3); $this->_rightShift( $w[$i - 15], 3);
$s1 = $this->_rightRotate($w[$i - 2], 17) ^ $s1 = $this->_rightRotate($w[$i - 2], 17) ^
$this->_rightRotate($w[$i - 2], 19) ^ $this->_rightRotate($w[$i - 2], 19) ^
$this->_rightShift( $w[$i - 2], 10); $this->_rightShift( $w[$i - 2], 10);
// @codingStandardsIgnoreEnd
$w[$i] = $this->_add($w[$i - 16], $s0, $w[$i - 7], $s1); $w[$i] = $this->_add($w[$i - 16], $s0, $w[$i - 7], $s1);
} }
// Initialize hash value for this chunk // Initialize hash value for this chunk
@ -572,7 +650,7 @@ class Crypt_Hash
* Pure-PHP implementation of SHA384 and SHA512 * Pure-PHP implementation of SHA384 and SHA512
* *
* @access private * @access private
* @param String $m * @param string $m
*/ */
function _sha512($m) function _sha512($m)
{ {
@ -755,10 +833,10 @@ class Crypt_Hash
* Right Rotate * Right Rotate
* *
* @access private * @access private
* @param Integer $int * @param int $int
* @param Integer $amt * @param int $amt
* @see _sha256() * @see self::_sha256()
* @return Integer * @return int
*/ */
function _rightRotate($int, $amt) function _rightRotate($int, $amt)
{ {
@ -771,10 +849,10 @@ class Crypt_Hash
* Right Shift * Right Shift
* *
* @access private * @access private
* @param Integer $int * @param int $int
* @param Integer $amt * @param int $amt
* @see _sha256() * @see self::_sha256()
* @return Integer * @return int
*/ */
function _rightShift($int, $amt) function _rightShift($int, $amt)
{ {
@ -786,9 +864,9 @@ class Crypt_Hash
* Not * Not
* *
* @access private * @access private
* @param Integer $int * @param int $int
* @see _sha256() * @see self::_sha256()
* @return Integer * @return int
*/ */
function _not($int) function _not($int)
{ {
@ -801,9 +879,9 @@ class Crypt_Hash
* _sha256() adds multiple unsigned 32-bit integers. Since PHP doesn't support unsigned integers and since the * _sha256() adds multiple unsigned 32-bit integers. Since PHP doesn't support unsigned integers and since the
* possibility of overflow exists, care has to be taken. Math_BigInteger() could be used but this should be faster. * possibility of overflow exists, care has to be taken. Math_BigInteger() could be used but this should be faster.
* *
* @param Integer $... * @param int $...
* @return Integer * @return int
* @see _sha256() * @see self::_sha256()
* @access private * @access private
*/ */
function _add() function _add()
@ -819,17 +897,27 @@ class Crypt_Hash
$result+= $argument < 0 ? ($argument & 0x7FFFFFFF) + 0x80000000 : $argument; $result+= $argument < 0 ? ($argument & 0x7FFFFFFF) + 0x80000000 : $argument;
} }
switch (true) {
case is_int($result):
// PHP 5.3, per http://php.net/releases/5_3_0.php, introduced "more consistent float rounding"
case version_compare(PHP_VERSION, '5.3.0') >= 0 && (php_uname('m') & "\xDF\xDF\xDF") != 'ARM':
// PHP_OS & "\xDF\xDF\xDF" == strtoupper(substr(PHP_OS, 0, 3)), but a lot faster
case (PHP_OS & "\xDF\xDF\xDF") === 'WIN':
return fmod($result, $mod); return fmod($result, $mod);
} }
return (fmod($result, 0x80000000) & 0x7FFFFFFF) |
((fmod(floor($result / 0x80000000), 2) & 1) << 31);
}
/** /**
* String Shift * String Shift
* *
* Inspired by array_shift * Inspired by array_shift
* *
* @param String $string * @param string $string
* @param optional Integer $index * @param int $index
* @return String * @return string
* @access private * @access private
*/ */
function _string_shift(&$string, $index = 1) function _string_shift(&$string, $index = 1)

259
rainloop/v/0.0.0/app/libraries/phpseclib/Crypt/RC2.php Normal file → Executable file
View file

@ -62,8 +62,8 @@ if (!class_exists('Crypt_Base')) {
/**#@+ /**#@+
* @access public * @access public
* @see Crypt_RC2::encrypt() * @see self::encrypt()
* @see Crypt_RC2::decrypt() * @see self::decrypt()
*/ */
/** /**
* Encrypt / decrypt using the Counter mode. * Encrypt / decrypt using the Counter mode.
@ -99,20 +99,6 @@ define('CRYPT_RC2_MODE_CFB', CRYPT_MODE_CFB);
define('CRYPT_RC2_MODE_OFB', CRYPT_MODE_OFB); define('CRYPT_RC2_MODE_OFB', CRYPT_MODE_OFB);
/**#@-*/ /**#@-*/
/**#@+
* @access private
* @see Crypt_RC2::Crypt_RC2()
*/
/**
* Toggles the internal implementation
*/
define('CRYPT_RC2_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
/**
* Toggles the mcrypt implementation
*/
define('CRYPT_RC2_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
/**#@-*/
/** /**
* Pure-PHP implementation of RC2. * Pure-PHP implementation of RC2.
* *
@ -125,7 +111,7 @@ class Crypt_RC2 extends Crypt_Base
* Block Length of the cipher * Block Length of the cipher
* *
* @see Crypt_Base::block_size * @see Crypt_Base::block_size
* @var Integer * @var int
* @access private * @access private
*/ */
var $block_size = 8; var $block_size = 8;
@ -134,27 +120,47 @@ class Crypt_RC2 extends Crypt_Base
* The Key * The Key
* *
* @see Crypt_Base::key * @see Crypt_Base::key
* @see setKey() * @see self::setKey()
* @var String * @var string
* @access private * @access private
*/ */
var $key = "\0"; var $key;
/** /**
* The default password key_size used by setPassword() * The Original (unpadded) Key
* *
* @see Crypt_Base::password_key_size * @see Crypt_Base::key
* @see Crypt_Base::setPassword() * @see self::setKey()
* @var Integer * @see self::encrypt()
* @see self::decrypt()
* @var string
* @access private * @access private
*/ */
var $password_key_size = 16; // = 128 bits var $orig_key;
/**
* Don't truncate / null pad key
*
* @see Crypt_Base::_clearBuffers()
* @var bool
* @access private
*/
var $skip_key_adjustment = true;
/**
* Key Length (in bytes)
*
* @see Crypt_RC2::setKeyLength()
* @var int
* @access private
*/
var $key_length = 16; // = 128 bits
/** /**
* The namespace used by the cipher for its constants. * The namespace used by the cipher for its constants.
* *
* @see Crypt_Base::const_namespace * @see Crypt_Base::const_namespace
* @var String * @var string
* @access private * @access private
*/ */
var $const_namespace = 'RC2'; var $const_namespace = 'RC2';
@ -163,7 +169,7 @@ class Crypt_RC2 extends Crypt_Base
* The mcrypt specific name of the cipher * The mcrypt specific name of the cipher
* *
* @see Crypt_Base::cipher_name_mcrypt * @see Crypt_Base::cipher_name_mcrypt
* @var String * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'rc2'; var $cipher_name_mcrypt = 'rc2';
@ -172,7 +178,7 @@ class Crypt_RC2 extends Crypt_Base
* Optimizing value while CFB-encrypting * Optimizing value while CFB-encrypting
* *
* @see Crypt_Base::cfb_init_len * @see Crypt_Base::cfb_init_len
* @var Integer * @var int
* @access private * @access private
*/ */
var $cfb_init_len = 500; var $cfb_init_len = 500;
@ -180,20 +186,31 @@ class Crypt_RC2 extends Crypt_Base
/** /**
* The key length in bits. * The key length in bits.
* *
* @see Crypt_RC2::setKeyLength() * @see self::setKeyLength()
* @see Crypt_RC2::setKey() * @see self::setKey()
* @var Integer * @var int
* @access private * @access private
* @internal Should be in range [1..1024]. * @internal Should be in range [1..1024].
* @internal Changing this value after setting the key has no effect. * @internal Changing this value after setting the key has no effect.
*/ */
var $default_key_length = 1024; var $default_key_length = 1024;
/**
* The key length in bits.
*
* @see self::isValidEnine()
* @see self::setKey()
* @var int
* @access private
* @internal Should be in range [1..1024].
*/
var $current_key_length;
/** /**
* The Key Schedule * The Key Schedule
* *
* @see Crypt_RC2::_setupKey() * @see self::_setupKey()
* @var Array * @var array
* @access private * @access private
*/ */
var $keys; var $keys;
@ -202,8 +219,8 @@ class Crypt_RC2 extends Crypt_Base
* Key expansion randomization table. * Key expansion randomization table.
* Twice the same 256-value sequence to save a modulus in key expansion. * Twice the same 256-value sequence to save a modulus in key expansion.
* *
* @see Crypt_RC2::setKey() * @see self::setKey()
* @var Array * @var array
* @access private * @access private
*/ */
var $pitable = array( var $pitable = array(
@ -276,8 +293,8 @@ class Crypt_RC2 extends Crypt_Base
/** /**
* Inverse key expansion randomization table. * Inverse key expansion randomization table.
* *
* @see Crypt_RC2::setKey() * @see self::setKey()
* @var Array * @var array
* @access private * @access private
*/ */
var $invpitable = array( var $invpitable = array(
@ -316,55 +333,68 @@ class Crypt_RC2 extends Crypt_Base
); );
/** /**
* Default Constructor. * Test for engine validity
* *
* Determines whether or not the mcrypt extension should be used. * This is mainly just a wrapper to set things up for Crypt_Base::isValidEngine()
*
* $mode could be:
*
* - CRYPT_RC2_MODE_ECB
*
* - CRYPT_RC2_MODE_CBC
*
* - CRYPT_RC2_MODE_CTR
*
* - CRYPT_RC2_MODE_CFB
*
* - CRYPT_RC2_MODE_OFB
*
* If not explicitly set, CRYPT_RC2_MODE_CBC will be used.
* *
* @see Crypt_Base::Crypt_Base() * @see Crypt_Base::Crypt_Base()
* @param optional Integer $mode * @param int $engine
* @access public * @access public
* @return bool
*/ */
function Crypt_RC2($mode = CRYPT_RC2_MODE_CBC) function isValidEngine($engine)
{ {
parent::Crypt_Base($mode); switch ($engine) {
$this->setKey(''); case CRYPT_ENGINE_OPENSSL:
if ($this->current_key_length != 128 || strlen($this->orig_key) < 16) {
return false;
}
$this->cipher_name_openssl_ecb = 'rc2-ecb';
$this->cipher_name_openssl = 'rc2-' . $this->_openssl_translate_mode();
}
return parent::isValidEngine($engine);
} }
/** /**
* Sets the key length * Sets the key length.
* *
* Valid key lengths are 1 to 1024. * Valid key lengths are 8 to 1024.
* Calling this function after setting the key has no effect until the next * Calling this function after setting the key has no effect until the next
* Crypt_RC2::setKey() call. * Crypt_RC2::setKey() call.
* *
* @access public * @access public
* @param Integer $length in bits * @param int $length in bits
*/ */
function setKeyLength($length) function setKeyLength($length)
{ {
if ($length >= 1 && $length <= 1024) { if ($length < 8) {
$this->default_key_length = 1;
} elseif ($length > 1024) {
$this->default_key_length = 128;
} else {
$this->default_key_length = $length; $this->default_key_length = $length;
} }
$this->current_key_length = $this->default_key_length;
parent::setKeyLength($length);
}
/**
* Returns the current key length
*
* @access public
* @return int
*/
function getKeyLength()
{
return $this->current_key_length;
} }
/** /**
* Sets the key. * Sets the key.
* *
* Keys can be of any length. RC2, itself, uses 1 to 1024 bit keys (eg. * Keys can be of any length. RC2, itself, uses 8 to 1024 bit keys (eg.
* strlen($key) <= 128), however, we only use the first 128 bytes if $key * strlen($key) <= 128), however, we only use the first 128 bytes if $key
* has more then 128 bytes in it, and set $key to a single null byte if * has more then 128 bytes in it, and set $key to a single null byte if
* it is empty. * it is empty.
@ -374,16 +404,19 @@ class Crypt_RC2 extends Crypt_Base
* *
* @see Crypt_Base::setKey() * @see Crypt_Base::setKey()
* @access public * @access public
* @param String $key * @param string $key
* @param Integer $t1 optional Effective key length in bits. * @param int $t1 optional Effective key length in bits.
*/ */
function setKey($key, $t1 = 0) function setKey($key, $t1 = 0)
{ {
$this->orig_key = $key;
if ($t1 <= 0) { if ($t1 <= 0) {
$t1 = $this->default_key_length; $t1 = $this->default_key_length;
} elseif ($t1 > 1024) { } elseif ($t1 > 1024) {
$t1 = 1024; $t1 = 1024;
} }
$this->current_key_length = $t1;
// Key byte count should be 1..128. // Key byte count should be 1..128.
$key = strlen($key) ? substr($key, 0, 128) : "\x00"; $key = strlen($key) ? substr($key, 0, 128) : "\x00";
$t = strlen($key); $t = strlen($key);
@ -413,17 +446,64 @@ class Crypt_RC2 extends Crypt_Base
// Prepare the key for mcrypt. // Prepare the key for mcrypt.
$l[0] = $this->invpitable[$l[0]]; $l[0] = $this->invpitable[$l[0]];
array_unshift($l, 'C*'); array_unshift($l, 'C*');
parent::setKey(call_user_func_array('pack', $l)); parent::setKey(call_user_func_array('pack', $l));
} }
/**
* Encrypts a message.
*
* Mostly a wrapper for Crypt_Base::encrypt, with some additional OpenSSL handling code
*
* @see self::decrypt()
* @access public
* @param string $plaintext
* @return string $ciphertext
*/
function encrypt($plaintext)
{
if ($this->engine == CRYPT_ENGINE_OPENSSL) {
$temp = $this->key;
$this->key = $this->orig_key;
$result = parent::encrypt($plaintext);
$this->key = $temp;
return $result;
}
return parent::encrypt($plaintext);
}
/**
* Decrypts a message.
*
* Mostly a wrapper for Crypt_Base::decrypt, with some additional OpenSSL handling code
*
* @see self::encrypt()
* @access public
* @param string $ciphertext
* @return string $plaintext
*/
function decrypt($ciphertext)
{
if ($this->engine == CRYPT_ENGINE_OPENSSL) {
$temp = $this->key;
$this->key = $this->orig_key;
$result = parent::decrypt($ciphertext);
$this->key = $temp;
return $result;
}
return parent::decrypt($ciphertext);
}
/** /**
* Encrypts a block * Encrypts a block
* *
* @see Crypt_Base::_encryptBlock() * @see Crypt_Base::_encryptBlock()
* @see Crypt_Base::encrypt() * @see Crypt_Base::encrypt()
* @access private * @access private
* @param String $in * @param string $in
* @return String * @return string
*/ */
function _encryptBlock($in) function _encryptBlock($in)
{ {
@ -467,8 +547,8 @@ class Crypt_RC2 extends Crypt_Base
* @see Crypt_Base::_decryptBlock() * @see Crypt_Base::_decryptBlock()
* @see Crypt_Base::decrypt() * @see Crypt_Base::decrypt()
* @access private * @access private
* @param String $in * @param string $in
* @return String * @return string
*/ */
function _decryptBlock($in) function _decryptBlock($in)
{ {
@ -506,6 +586,21 @@ class Crypt_RC2 extends Crypt_Base
return pack('vvvv', $r0, $r1, $r2, $r3); return pack('vvvv', $r0, $r1, $r2, $r3);
} }
/**
* Setup the CRYPT_ENGINE_MCRYPT $engine
*
* @see Crypt_Base::_setupMcrypt()
* @access private
*/
function _setupMcrypt()
{
if (!isset($this->key)) {
$this->setKey('');
}
parent::_setupMcrypt();
}
/** /**
* Creates the key schedule * Creates the key schedule
* *
@ -514,6 +609,10 @@ class Crypt_RC2 extends Crypt_Base
*/ */
function _setupKey() function _setupKey()
{ {
if (!isset($this->key)) {
$this->setKey('');
}
// Key has already been expanded in Crypt_RC2::setKey(): // Key has already been expanded in Crypt_RC2::setKey():
// Only the first value must be altered. // Only the first value must be altered.
$l = unpack('Ca/Cb/v*', $this->key); $l = unpack('Ca/Cb/v*', $this->key);
@ -536,14 +635,14 @@ class Crypt_RC2 extends Crypt_Base
// The first 10 generated $lambda_functions will use the $keys hardcoded as integers // The first 10 generated $lambda_functions will use the $keys hardcoded as integers
// for the mixing rounds, for better inline crypt performance [~20% faster]. // for the mixing rounds, for better inline crypt performance [~20% faster].
// But for memory reason we have to limit those ultra-optimized $lambda_functions to an amount of 10. // But for memory reason we have to limit those ultra-optimized $lambda_functions to an amount of 10.
$keys = $this->keys; // (Currently, for Crypt_RC2, one generated $lambda_function cost on php5.5@32bit ~60kb unfreeable mem and ~100kb on php5.5@64bit)
if (count($lambda_functions) >= 10) { $gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
foreach ($this->keys as $k => $v) {
$keys[$k] = '$keys[' . $k . ']';
}
}
$code_hash = md5(str_pad("Crypt_RC2, {$this->mode}, ", 32, "\0") . implode(',', $keys)); // Generation of a unique hash for our generated code
$code_hash = "Crypt_RC2, {$this->mode}";
if ($gen_hi_opt_code) {
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
}
// Is there a re-usable $lambda_functions in there? // Is there a re-usable $lambda_functions in there?
// If not, we have to create it. // If not, we have to create it.
@ -551,6 +650,16 @@ class Crypt_RC2 extends Crypt_Base
// Init code for both, encrypt and decrypt. // Init code for both, encrypt and decrypt.
$init_crypt = '$keys = $self->keys;'; $init_crypt = '$keys = $self->keys;';
switch (true) {
case $gen_hi_opt_code:
$keys = $this->keys;
default:
$keys = array();
foreach ($this->keys as $k => $v) {
$keys[$k] = '$keys[' . $k . ']';
}
}
// $in is the current 8 bytes block which has to be en/decrypt // $in is the current 8 bytes block which has to be en/decrypt
$encrypt_block = $decrypt_block = ' $encrypt_block = $decrypt_block = '
$in = unpack("v4", $in); $in = unpack("v4", $in);

139
rainloop/v/0.0.0/app/libraries/phpseclib/Crypt/RC4.php Normal file → Executable file
View file

@ -71,21 +71,7 @@ if (!class_exists('Crypt_Base')) {
/**#@+ /**#@+
* @access private * @access private
* @see Crypt_RC4::Crypt_RC4() * @see self::_crypt()
*/
/**
* Toggles the internal implementation
*/
define('CRYPT_RC4_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
/**
* Toggles the mcrypt implementation
*/
define('CRYPT_RC4_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
/**#@-*/
/**#@+
* @access private
* @see Crypt_RC4::_crypt()
*/ */
define('CRYPT_RC4_ENCRYPT', 0); define('CRYPT_RC4_ENCRYPT', 0);
define('CRYPT_RC4_DECRYPT', 1); define('CRYPT_RC4_DECRYPT', 1);
@ -107,26 +93,25 @@ class Crypt_RC4 extends Crypt_Base
* so we the block_size to 0 * so we the block_size to 0
* *
* @see Crypt_Base::block_size * @see Crypt_Base::block_size
* @var Integer * @var int
* @access private * @access private
*/ */
var $block_size = 0; var $block_size = 0;
/** /**
* The default password key_size used by setPassword() * Key Length (in bytes)
* *
* @see Crypt_Base::password_key_size * @see Crypt_RC4::setKeyLength()
* @see Crypt_Base::setPassword() * @var int
* @var Integer
* @access private * @access private
*/ */
var $password_key_size = 128; // = 1024 bits var $key_length = 128; // = 1024 bits
/** /**
* The namespace used by the cipher for its constants. * The namespace used by the cipher for its constants.
* *
* @see Crypt_Base::const_namespace * @see Crypt_Base::const_namespace
* @var String * @var string
* @access private * @access private
*/ */
var $const_namespace = 'RC4'; var $const_namespace = 'RC4';
@ -135,7 +120,7 @@ class Crypt_RC4 extends Crypt_Base
* The mcrypt specific name of the cipher * The mcrypt specific name of the cipher
* *
* @see Crypt_Base::cipher_name_mcrypt * @see Crypt_Base::cipher_name_mcrypt
* @var String * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'arcfour'; var $cipher_name_mcrypt = 'arcfour';
@ -152,17 +137,17 @@ class Crypt_RC4 extends Crypt_Base
/** /**
* The Key * The Key
* *
* @see Crypt_RC4::setKey() * @see self::setKey()
* @var String * @var string
* @access private * @access private
*/ */
var $key = "\0"; var $key;
/** /**
* The Key Stream for decryption and encryption * The Key Stream for decryption and encryption
* *
* @see Crypt_RC4::setKey() * @see self::setKey()
* @var Array * @var array
* @access private * @access private
*/ */
var $stream; var $stream;
@ -176,9 +161,55 @@ class Crypt_RC4 extends Crypt_Base
* @return Crypt_RC4 * @return Crypt_RC4
* @access public * @access public
*/ */
function __construct()
{
parent::__construct(CRYPT_MODE_STREAM);
}
/**
* PHP4 compatible Default Constructor.
*
* @see self::__construct()
* @access public
*/
function Crypt_RC4() function Crypt_RC4()
{ {
parent::Crypt_Base(CRYPT_MODE_STREAM); $this->__construct();
}
/**
* Test for engine validity
*
* This is mainly just a wrapper to set things up for Crypt_Base::isValidEngine()
*
* @see Crypt_Base::Crypt_Base()
* @param int $engine
* @access public
* @return bool
*/
function isValidEngine($engine)
{
if ($engine == CRYPT_ENGINE_OPENSSL) {
if (version_compare(PHP_VERSION, '5.3.7') >= 0) {
$this->cipher_name_openssl = 'rc4-40';
} else {
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;
}
}
}
return parent::isValidEngine($engine);
} }
/** /**
@ -196,8 +227,8 @@ class Crypt_RC4 extends Crypt_Base
* {@link http://www.rsa.com/rsalabs/node.asp?id=2009 http://www.rsa.com/rsalabs/node.asp?id=2009} * {@link http://www.rsa.com/rsalabs/node.asp?id=2009 http://www.rsa.com/rsalabs/node.asp?id=2009}
* {@link http://en.wikipedia.org/wiki/Related_key_attack http://en.wikipedia.org/wiki/Related_key_attack} * {@link http://en.wikipedia.org/wiki/Related_key_attack http://en.wikipedia.org/wiki/Related_key_attack}
* *
* @param String $iv * @param string $iv
* @see Crypt_RC4::setKey() * @see self::setKey()
* @access public * @access public
*/ */
function setIV($iv) function setIV($iv)
@ -205,32 +236,38 @@ class Crypt_RC4 extends Crypt_Base
} }
/** /**
* Sets the key. * Sets the key length
* *
* Keys can be between 1 and 256 bytes long. If they are longer then 256 bytes, the first 256 bytes will * Keys can be between 1 and 256 bytes long.
* be used. If no key is explicitly set, it'll be assumed to be a single null byte.
* *
* @access public * @access public
* @see Crypt_Base::setKey() * @param int $length
* @param String $key
*/ */
function setKey($key) function setKeyLength($length)
{ {
parent::setKey(substr($key, 0, 256)); if ($length < 8) {
$this->key_length = 1;
} elseif ($length > 2048) {
$this->key_length = 256;
} else {
$this->key_length = $length >> 3;
}
parent::setKeyLength($length);
} }
/** /**
* Encrypts a message. * Encrypts a message.
* *
* @see Crypt_Base::decrypt() * @see Crypt_Base::decrypt()
* @see Crypt_RC4::_crypt() * @see self::_crypt()
* @access public * @access public
* @param String $plaintext * @param string $plaintext
* @return String $ciphertext * @return string $ciphertext
*/ */
function encrypt($plaintext) function encrypt($plaintext)
{ {
if ($this->engine == CRYPT_MODE_MCRYPT) { if ($this->engine != CRYPT_ENGINE_INTERNAL) {
return parent::encrypt($plaintext); return parent::encrypt($plaintext);
} }
return $this->_crypt($plaintext, CRYPT_RC4_ENCRYPT); return $this->_crypt($plaintext, CRYPT_RC4_ENCRYPT);
@ -243,14 +280,14 @@ class Crypt_RC4 extends Crypt_Base
* At least if the continuous buffer is disabled. * At least if the continuous buffer is disabled.
* *
* @see Crypt_Base::encrypt() * @see Crypt_Base::encrypt()
* @see Crypt_RC4::_crypt() * @see self::_crypt()
* @access public * @access public
* @param String $ciphertext * @param string $ciphertext
* @return String $plaintext * @return string $plaintext
*/ */
function decrypt($ciphertext) function decrypt($ciphertext)
{ {
if ($this->engine == CRYPT_MODE_MCRYPT) { if ($this->engine != CRYPT_ENGINE_INTERNAL) {
return parent::decrypt($ciphertext); return parent::decrypt($ciphertext);
} }
return $this->_crypt($ciphertext, CRYPT_RC4_DECRYPT); return $this->_crypt($ciphertext, CRYPT_RC4_DECRYPT);
@ -287,12 +324,12 @@ class Crypt_RC4 extends Crypt_Base
/** /**
* Encrypts or decrypts a message. * Encrypts or decrypts a message.
* *
* @see Crypt_RC4::encrypt() * @see self::encrypt()
* @see Crypt_RC4::decrypt() * @see self::decrypt()
* @access private * @access private
* @param String $text * @param string $text
* @param Integer $mode * @param int $mode
* @return String $text * @return string $text
*/ */
function _crypt($text, $mode) function _crypt($text, $mode)
{ {

554
rainloop/v/0.0.0/app/libraries/phpseclib/Crypt/RSA.php Normal file → Executable file

File diff suppressed because it is too large Load diff

View file

@ -61,17 +61,20 @@ if (!function_exists('crypt_random_string')) {
* microoptimizations because this function has the potential of being called a huge number of times. * microoptimizations because this function has the potential of being called a huge number of times.
* eg. for RSA key generation. * eg. for RSA key generation.
* *
* @param Integer $length * @param int $length
* @return String * @return string
* @access public * @access public
*/ */
function crypt_random_string($length) function crypt_random_string($length)
{ {
if (!$length) {
return '';
}
if (CRYPT_RANDOM_IS_WINDOWS) { if (CRYPT_RANDOM_IS_WINDOWS) {
// method 1. prior to PHP 5.3 this would call rand() on windows hence the function_exists('class_alias') call. // method 1. prior to PHP 5.3, mcrypt_create_iv() would call rand() on windows
// ie. class_alias is a function that was introduced in PHP 5.3 if (extension_loaded('mcrypt') && version_compare(PHP_VERSION, '5.3.0', '>=')) {
if (function_exists('mcrypt_create_iv') && function_exists('class_alias')) { return @mcrypt_create_iv($length);
return mcrypt_create_iv($length);
} }
// method 2. openssl_random_pseudo_bytes was introduced in PHP 5.3.0 but prior to PHP 5.3.4 there was, // method 2. openssl_random_pseudo_bytes was introduced in PHP 5.3.0 but prior to PHP 5.3.4 there was,
// to quote <http://php.net/ChangeLog-5.php#5.3.4>, "possible blocking behavior". as of 5.3.4 // to quote <http://php.net/ChangeLog-5.php#5.3.4>, "possible blocking behavior". as of 5.3.4
@ -86,12 +89,12 @@ if (!function_exists('crypt_random_string')) {
// https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/win32/winutil.c#L80 // https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/win32/winutil.c#L80
// //
// we're calling it, all the same, in the off chance that the mcrypt extension is not available // we're calling it, all the same, in the off chance that the mcrypt extension is not available
if (function_exists('openssl_random_pseudo_bytes') && version_compare(PHP_VERSION, '5.3.4', '>=')) { if (extension_loaded('openssl') && version_compare(PHP_VERSION, '5.3.4', '>=')) {
return openssl_random_pseudo_bytes($length); return openssl_random_pseudo_bytes($length);
} }
} else { } else {
// method 1. the fastest // method 1. the fastest
if (function_exists('openssl_random_pseudo_bytes')) { if (extension_loaded('openssl') && version_compare(PHP_VERSION, '5.3.0', '>=')) {
return openssl_random_pseudo_bytes($length); return openssl_random_pseudo_bytes($length);
} }
// method 2 // method 2
@ -109,8 +112,8 @@ if (!function_exists('crypt_random_string')) {
// surprisingly slower than method 2. maybe that's because mcrypt_create_iv does a bunch of error checking that we're // surprisingly slower than method 2. maybe that's because mcrypt_create_iv does a bunch of error checking that we're
// not doing. regardless, this'll only be called if this PHP script couldn't open /dev/urandom due to open_basedir // not doing. regardless, this'll only be called if this PHP script couldn't open /dev/urandom due to open_basedir
// restrictions or some such // restrictions or some such
if (function_exists('mcrypt_create_iv')) { if (extension_loaded('mcrypt')) {
return mcrypt_create_iv($length, MCRYPT_DEV_URANDOM); return @mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
} }
} }
// at this point we have no choice but to use a pure-PHP CSPRNG // at this point we have no choice but to use a pure-PHP CSPRNG
@ -149,13 +152,13 @@ if (!function_exists('crypt_random_string')) {
session_start(); session_start();
$v = $seed = $_SESSION['seed'] = pack('H*', sha1( $v = $seed = $_SESSION['seed'] = pack('H*', sha1(
serialize($_SERVER) . (isset($_SERVER) ? phpseclib_safe_serialize($_SERVER) : '') .
serialize($_POST) . (isset($_POST) ? phpseclib_safe_serialize($_POST) : '') .
serialize($_GET) . (isset($_GET) ? phpseclib_safe_serialize($_GET) : '') .
serialize($_COOKIE) . (isset($_COOKIE) ? phpseclib_safe_serialize($_COOKIE) : '') .
serialize($GLOBALS) . phpseclib_safe_serialize($GLOBALS) .
serialize($_SESSION) . phpseclib_safe_serialize($_SESSION) .
serialize($_OLD_SESSION) phpseclib_safe_serialize($_OLD_SESSION)
)); ));
if (!isset($_SESSION['count'])) { if (!isset($_SESSION['count'])) {
$_SESSION['count'] = 0; $_SESSION['count'] = 0;
@ -261,6 +264,41 @@ if (!function_exists('crypt_random_string')) {
} }
} }
if (!function_exists('phpseclib_safe_serialize')) {
/**
* Safely serialize variables
*
* If a class has a private __sleep() method it'll give a fatal error on PHP 5.2 and earlier.
* PHP 5.3 will emit a warning.
*
* @param mixed $arr
* @access public
*/
function phpseclib_safe_serialize(&$arr)
{
if (is_object($arr)) {
return '';
}
if (!is_array($arr)) {
return serialize($arr);
}
// prevent circular array recursion
if (isset($arr['__phpseclib_marker'])) {
return '';
}
$safearr = array();
$arr['__phpseclib_marker'] = true;
foreach (array_keys($arr) as $key) {
// do not recurse on the '__phpseclib_marker' key itself, for smaller memory usage
if ($key !== '__phpseclib_marker') {
$safearr[$key] = phpseclib_safe_serialize($arr[$key]);
}
}
unset($arr['__phpseclib_marker']);
return serialize($safearr);
}
}
if (!function_exists('phpseclib_resolve_include_path')) { if (!function_exists('phpseclib_resolve_include_path')) {
/** /**
* Resolve filename against the include path. * Resolve filename against the include path.
@ -269,7 +307,7 @@ if (!function_exists('phpseclib_resolve_include_path')) {
* PHP 5.3.2) with fallback implementation for earlier PHP versions. * PHP 5.3.2) with fallback implementation for earlier PHP versions.
* *
* @param string $filename * @param string $filename
* @return mixed Filename (string) on success, false otherwise. * @return string|false
* @access public * @access public
*/ */
function phpseclib_resolve_include_path($filename) function phpseclib_resolve_include_path($filename)

File diff suppressed because it is too large Load diff

View file

@ -59,19 +59,31 @@ if (!class_exists('Crypt_DES')) {
include_once 'DES.php'; include_once 'DES.php';
} }
/**#@+
* @access public
* @see self::Crypt_TripleDES()
*/
/** /**
* Encrypt / decrypt using inner chaining * Encrypt / decrypt using inner chaining
* *
* Inner chaining is used by SSH-1 and is generally considered to be less secure then outer chaining (CRYPT_DES_MODE_CBC3). * Inner chaining is used by SSH-1 and is generally considered to be less secure then outer chaining (CRYPT_DES_MODE_CBC3).
*/ */
define('CRYPT_MODE_3CBC', -2);
/**
* BC version of the above.
*/
define('CRYPT_DES_MODE_3CBC', -2); define('CRYPT_DES_MODE_3CBC', -2);
/** /**
* Encrypt / decrypt using outer chaining * Encrypt / decrypt using outer chaining
* *
* Outer chaining is used by SSH-2 and when the mode is set to CRYPT_DES_MODE_CBC. * Outer chaining is used by SSH-2 and when the mode is set to CRYPT_DES_MODE_CBC.
*/ */
define('CRYPT_DES_MODE_CBC3', CRYPT_DES_MODE_CBC); define('CRYPT_MODE_CBC3', CRYPT_MODE_CBC);
/**
* BC version of the above.
*/
define('CRYPT_DES_MODE_CBC3', CRYPT_MODE_CBC3);
/**#@-*/
/** /**
* Pure-PHP implementation of Triple DES. * Pure-PHP implementation of Triple DES.
@ -83,22 +95,20 @@ define('CRYPT_DES_MODE_CBC3', CRYPT_DES_MODE_CBC);
class Crypt_TripleDES extends Crypt_DES class Crypt_TripleDES extends Crypt_DES
{ {
/** /**
* The default password key_size used by setPassword() * Key Length (in bytes)
* *
* @see Crypt_DES::password_key_size * @see Crypt_TripleDES::setKeyLength()
* @see Crypt_Base::password_key_size * @var int
* @see Crypt_Base::setPassword()
* @var Integer
* @access private * @access private
*/ */
var $password_key_size = 24; var $key_length = 24;
/** /**
* The default salt used by setPassword() * The default salt used by setPassword()
* *
* @see Crypt_Base::password_default_salt * @see Crypt_Base::password_default_salt
* @see Crypt_Base::setPassword() * @see Crypt_Base::setPassword()
* @var String * @var string
* @access private * @access private
*/ */
var $password_default_salt = 'phpseclib'; var $password_default_salt = 'phpseclib';
@ -108,7 +118,7 @@ class Crypt_TripleDES extends Crypt_DES
* *
* @see Crypt_DES::const_namespace * @see Crypt_DES::const_namespace
* @see Crypt_Base::const_namespace * @see Crypt_Base::const_namespace
* @var String * @var string
* @access private * @access private
*/ */
var $const_namespace = 'DES'; var $const_namespace = 'DES';
@ -118,7 +128,7 @@ class Crypt_TripleDES extends Crypt_DES
* *
* @see Crypt_DES::cipher_name_mcrypt * @see Crypt_DES::cipher_name_mcrypt
* @see Crypt_Base::cipher_name_mcrypt * @see Crypt_Base::cipher_name_mcrypt
* @var String * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'tripledes'; var $cipher_name_mcrypt = 'tripledes';
@ -127,7 +137,7 @@ class Crypt_TripleDES extends Crypt_DES
* Optimizing value while CFB-encrypting * Optimizing value while CFB-encrypting
* *
* @see Crypt_Base::cfb_init_len * @see Crypt_Base::cfb_init_len
* @var Integer * @var int
* @access private * @access private
*/ */
var $cfb_init_len = 750; var $cfb_init_len = 750;
@ -135,17 +145,17 @@ class Crypt_TripleDES extends Crypt_DES
/** /**
* max possible size of $key * max possible size of $key
* *
* @see Crypt_TripleDES::setKey() * @see self::setKey()
* @see Crypt_DES::setKey() * @see Crypt_DES::setKey()
* @var String * @var string
* @access private * @access private
*/ */
var $key_size_max = 24; var $key_length_max = 24;
/** /**
* Internal flag whether using CRYPT_DES_MODE_3CBC or not * Internal flag whether using CRYPT_DES_MODE_3CBC or not
* *
* @var Boolean * @var bool
* @access private * @access private
*/ */
var $mode_3cbc; var $mode_3cbc;
@ -155,7 +165,7 @@ class Crypt_TripleDES extends Crypt_DES
* *
* Used only if $mode_3cbc === true * Used only if $mode_3cbc === true
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $des; var $des;
@ -183,23 +193,23 @@ class Crypt_TripleDES extends Crypt_DES
* *
* @see Crypt_DES::Crypt_DES() * @see Crypt_DES::Crypt_DES()
* @see Crypt_Base::Crypt_Base() * @see Crypt_Base::Crypt_Base()
* @param optional Integer $mode * @param int $mode
* @access public * @access public
*/ */
function Crypt_TripleDES($mode = CRYPT_DES_MODE_CBC) function __construct($mode = CRYPT_MODE_CBC)
{ {
switch ($mode) { switch ($mode) {
// In case of CRYPT_DES_MODE_3CBC, we init as CRYPT_DES_MODE_CBC // In case of CRYPT_DES_MODE_3CBC, we init as CRYPT_DES_MODE_CBC
// and additional flag us internally as 3CBC // and additional flag us internally as 3CBC
case CRYPT_DES_MODE_3CBC: case CRYPT_DES_MODE_3CBC:
parent::Crypt_Base(CRYPT_DES_MODE_CBC); parent::Crypt_Base(CRYPT_MODE_CBC);
$this->mode_3cbc = true; $this->mode_3cbc = true;
// This three $des'es will do the 3CBC work (if $key > 64bits) // This three $des'es will do the 3CBC work (if $key > 64bits)
$this->des = array( $this->des = array(
new Crypt_DES(CRYPT_DES_MODE_CBC), new Crypt_DES(CRYPT_MODE_CBC),
new Crypt_DES(CRYPT_DES_MODE_CBC), new Crypt_DES(CRYPT_MODE_CBC),
new Crypt_DES(CRYPT_DES_MODE_CBC), new Crypt_DES(CRYPT_MODE_CBC),
); );
// we're going to be doing the padding, ourselves, so disable it in the Crypt_DES objects // we're going to be doing the padding, ourselves, so disable it in the Crypt_DES objects
@ -209,10 +219,43 @@ class Crypt_TripleDES extends Crypt_DES
break; break;
// If not 3CBC, we init as usual // If not 3CBC, we init as usual
default: default:
parent::Crypt_Base($mode); parent::__construct($mode);
} }
} }
/**
* PHP4 compatible Default Constructor.
*
* @see self::__construct()
* @param int $mode
* @access public
*/
function Crypt_TripleDES($mode = CRYPT_MODE_CBC)
{
$this->__construct($mode);
}
/**
* Test for engine validity
*
* This is mainly just a wrapper to set things up for Crypt_Base::isValidEngine()
*
* @see Crypt_Base::Crypt_Base()
* @param int $engine
* @access public
* @return bool
*/
function isValidEngine($engine)
{
if ($engine == CRYPT_ENGINE_OPENSSL) {
$this->cipher_name_openssl_ecb = 'des-ede3';
$mode = $this->_openssl_translate_mode();
$this->cipher_name_openssl = $mode == 'ecb' ? 'des-ede3' : 'des-ede3-' . $mode;
}
return parent::isValidEngine($engine);
}
/** /**
* Sets the initialization vector. (optional) * Sets the initialization vector. (optional)
* *
@ -221,7 +264,7 @@ class Crypt_TripleDES extends Crypt_DES
* *
* @see Crypt_Base::setIV() * @see Crypt_Base::setIV()
* @access public * @access public
* @param String $iv * @param string $iv
*/ */
function setIV($iv) function setIV($iv)
{ {
@ -233,6 +276,32 @@ class Crypt_TripleDES extends Crypt_DES
} }
} }
/**
* Sets the key length.
*
* Valid key lengths are 64, 128 and 192
*
* @see Crypt_Base:setKeyLength()
* @access public
* @param int $length
*/
function setKeyLength($length)
{
$length >>= 3;
switch (true) {
case $length <= 8:
$this->key_length = 8;
break;
case $length <= 16:
$this->key_length = 16;
break;
default:
$this->key_length = 24;
}
parent::setKeyLength($length);
}
/** /**
* Sets the key. * Sets the key.
* *
@ -246,16 +315,16 @@ class Crypt_TripleDES extends Crypt_DES
* @access public * @access public
* @see Crypt_DES::setKey() * @see Crypt_DES::setKey()
* @see Crypt_Base::setKey() * @see Crypt_Base::setKey()
* @param String $key * @param string $key
*/ */
function setKey($key) function setKey($key)
{ {
$length = strlen($key); $length = $this->explicit_key_length ? $this->key_length : strlen($key);
if ($length > 8) { if ($length > 8) {
$key = str_pad(substr($key, 0, 24), 24, chr(0)); $key = str_pad(substr($key, 0, 24), 24, chr(0));
// if $key is between 64 and 128-bits, use the first 64-bits as the last, per this: // if $key is between 64 and 128-bits, use the first 64-bits as the last, per this:
// http://php.net/function.mcrypt-encrypt#47973 // http://php.net/function.mcrypt-encrypt#47973
//$key = $length <= 16 ? substr_replace($key, substr($key, 0, 8), 16) : substr($key, 0, 24); $key = $length <= 16 ? substr_replace($key, substr($key, 0, 8), 16) : substr($key, 0, 24);
} else { } else {
$key = str_pad($key, 8, chr(0)); $key = str_pad($key, 8, chr(0));
} }
@ -277,13 +346,13 @@ class Crypt_TripleDES extends Crypt_DES
* *
* @see Crypt_Base::encrypt() * @see Crypt_Base::encrypt()
* @access public * @access public
* @param String $plaintext * @param string $plaintext
* @return String $cipertext * @return string $cipertext
*/ */
function encrypt($plaintext) function encrypt($plaintext)
{ {
// parent::en/decrypt() is able to do all the work for all modes and keylengths, // parent::en/decrypt() is able to do all the work for all modes and keylengths,
// except for: CRYPT_DES_MODE_3CBC (inner chaining CBC) with a key > 64bits // except for: CRYPT_MODE_3CBC (inner chaining CBC) with a key > 64bits
// if the key is smaller then 8, do what we'd normally do // if the key is smaller then 8, do what we'd normally do
if ($this->mode_3cbc && strlen($this->key) > 8) { if ($this->mode_3cbc && strlen($this->key) > 8) {
@ -304,8 +373,8 @@ class Crypt_TripleDES extends Crypt_DES
* *
* @see Crypt_Base::decrypt() * @see Crypt_Base::decrypt()
* @access public * @access public
* @param String $ciphertext * @param string $ciphertext
* @return String $plaintext * @return string $plaintext
*/ */
function decrypt($ciphertext) function decrypt($ciphertext)
{ {
@ -359,7 +428,7 @@ class Crypt_TripleDES extends Crypt_DES
* however, they are also less intuitive and more likely to cause you problems. * however, they are also less intuitive and more likely to cause you problems.
* *
* @see Crypt_Base::enableContinuousBuffer() * @see Crypt_Base::enableContinuousBuffer()
* @see Crypt_TripleDES::disableContinuousBuffer() * @see self::disableContinuousBuffer()
* @access public * @access public
*/ */
function enableContinuousBuffer() function enableContinuousBuffer()
@ -378,7 +447,7 @@ class Crypt_TripleDES extends Crypt_DES
* The default behavior. * The default behavior.
* *
* @see Crypt_Base::disableContinuousBuffer() * @see Crypt_Base::disableContinuousBuffer()
* @see Crypt_TripleDES::enableContinuousBuffer() * @see self::enableContinuousBuffer()
* @access public * @access public
*/ */
function disableContinuousBuffer() function disableContinuousBuffer()
@ -425,4 +494,24 @@ class Crypt_TripleDES extends Crypt_DES
// setup our key // setup our key
parent::_setupKey(); parent::_setupKey();
} }
/**
* Sets the internal crypt engine
*
* @see Crypt_Base::Crypt_Base()
* @see Crypt_Base::setPreferredEngine()
* @param int $engine
* @access public
* @return int
*/
function setPreferredEngine($engine)
{
if ($this->mode_3cbc) {
$this->des[0]->setPreferredEngine($engine);
$this->des[1]->setPreferredEngine($engine);
$this->des[2]->setPreferredEngine($engine);
}
return parent::setPreferredEngine($engine);
}
} }

View file

@ -64,8 +64,8 @@ if (!class_exists('Crypt_Base')) {
/**#@+ /**#@+
* @access public * @access public
* @see Crypt_Twofish::encrypt() * @see self::encrypt()
* @see Crypt_Twofish::decrypt() * @see self::decrypt()
*/ */
/** /**
* Encrypt / decrypt using the Counter mode. * Encrypt / decrypt using the Counter mode.
@ -101,20 +101,6 @@ define('CRYPT_TWOFISH_MODE_CFB', CRYPT_MODE_CFB);
define('CRYPT_TWOFISH_MODE_OFB', CRYPT_MODE_OFB); define('CRYPT_TWOFISH_MODE_OFB', CRYPT_MODE_OFB);
/**#@-*/ /**#@-*/
/**#@+
* @access private
* @see Crypt_Base::Crypt_Base()
*/
/**
* Toggles the internal implementation
*/
define('CRYPT_TWOFISH_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
/**
* Toggles the mcrypt implementation
*/
define('CRYPT_TWOFISH_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
/**#@-*/
/** /**
* Pure-PHP implementation of Twofish. * Pure-PHP implementation of Twofish.
* *
@ -129,7 +115,7 @@ class Crypt_Twofish extends Crypt_Base
* The namespace used by the cipher for its constants. * The namespace used by the cipher for its constants.
* *
* @see Crypt_Base::const_namespace * @see Crypt_Base::const_namespace
* @var String * @var string
* @access private * @access private
*/ */
var $const_namespace = 'TWOFISH'; var $const_namespace = 'TWOFISH';
@ -138,7 +124,7 @@ class Crypt_Twofish extends Crypt_Base
* The mcrypt specific name of the cipher * The mcrypt specific name of the cipher
* *
* @see Crypt_Base::cipher_name_mcrypt * @see Crypt_Base::cipher_name_mcrypt
* @var String * @var string
* @access private * @access private
*/ */
var $cipher_name_mcrypt = 'twofish'; var $cipher_name_mcrypt = 'twofish';
@ -147,7 +133,7 @@ class Crypt_Twofish extends Crypt_Base
* Optimizing value while CFB-encrypting * Optimizing value while CFB-encrypting
* *
* @see Crypt_Base::cfb_init_len * @see Crypt_Base::cfb_init_len
* @var Integer * @var int
* @access private * @access private
*/ */
var $cfb_init_len = 800; var $cfb_init_len = 800;
@ -155,7 +141,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* Q-Table * Q-Table
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $q0 = array( var $q0 = array(
@ -196,7 +182,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* Q-Table * Q-Table
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $q1 = array( var $q1 = array(
@ -237,7 +223,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* M-Table * M-Table
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $m0 = array( var $m0 = array(
@ -278,7 +264,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* M-Table * M-Table
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $m1 = array( var $m1 = array(
@ -319,7 +305,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* M-Table * M-Table
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $m2 = array( var $m2 = array(
@ -360,7 +346,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* M-Table * M-Table
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $m3 = array( var $m3 = array(
@ -401,7 +387,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* The Key Schedule Array * The Key Schedule Array
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $K = array(); var $K = array();
@ -409,7 +395,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* The Key depended S-Table 0 * The Key depended S-Table 0
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $S0 = array(); var $S0 = array();
@ -417,7 +403,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* The Key depended S-Table 1 * The Key depended S-Table 1
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $S1 = array(); var $S1 = array();
@ -425,7 +411,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* The Key depended S-Table 2 * The Key depended S-Table 2
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $S2 = array(); var $S2 = array();
@ -433,7 +419,7 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* The Key depended S-Table 3 * The Key depended S-Table 3
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $S3 = array(); var $S3 = array();
@ -441,41 +427,42 @@ class Crypt_Twofish extends Crypt_Base
/** /**
* Holds the last used key * Holds the last used key
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $kl; var $kl;
/** /**
* Sets the key. * The Key Length (in bytes)
* *
* Keys can be of any length. Twofish, itself, requires the use of a key that's 128, 192 or 256-bits long. * @see Crypt_Twofish::setKeyLength()
* If the key is less than 256-bits we round the length up to the closest valid key length, * @var int
* padding $key with null bytes. If the key is more than 256-bits, we trim the excess bits. * @access private
*/
var $key_length = 16;
/**
* Sets the key length.
* *
* If the key is not explicitly set, it'll be assumed a 128 bits key to be all null bytes. * Valid key lengths are 128, 192 or 256 bits
* *
* @access public * @access public
* @see Crypt_Base::setKey() * @param int $length
* @param String $key
*/ */
function setKey($key) function setKeyLength($length)
{ {
$keylength = strlen($key);
switch (true) { switch (true) {
case $keylength <= 16: case $length <= 128:
$key = str_pad($key, 16, "\0"); $this->key_length = 16;
break; break;
case $keylength <= 24: case $length <= 192:
$key = str_pad($key, 24, "\0"); $this->key_length = 24;
break; break;
case $keylength < 32: default:
$key = str_pad($key, 32, "\0"); $this->key_length = 32;
break;
case $keylength > 32:
$key = substr($key, 0, 32);
} }
parent::setKey($key);
parent::setKeyLength($length);
} }
/** /**
@ -518,8 +505,10 @@ class Crypt_Twofish extends Crypt_Base
$m2[$q1[$q0[$j] ^ $key[15]] ^ $key[7]] ^ $m2[$q1[$q0[$j] ^ $key[15]] ^ $key[7]] ^
$m3[$q1[$q1[$j] ^ $key[16]] ^ $key[8]]; $m3[$q1[$q1[$j] ^ $key[16]] ^ $key[8]];
$B = ($B << 8) | ($B >> 24 & 0xff); $B = ($B << 8) | ($B >> 24 & 0xff);
$K[] = $A+= $B; $A = $this->safe_intval($A + $B);
$K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff); $K[] = $A;
$A = $this->safe_intval($A + $B);
$K[] = ($A << 9 | $A >> 23 & 0x1ff);
} }
for ($i = 0; $i < 256; ++$i) { for ($i = 0; $i < 256; ++$i) {
$S0[$i] = $m0[$q0[$q0[$i] ^ $s4] ^ $s0]; $S0[$i] = $m0[$q0[$q0[$i] ^ $s4] ^ $s0];
@ -542,8 +531,10 @@ class Crypt_Twofish extends Crypt_Base
$m2[$q1[$q0[$q0[$j] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^ $m2[$q1[$q0[$q0[$j] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^
$m3[$q1[$q1[$q0[$j] ^ $key[24]] ^ $key[16]] ^ $key[8]]; $m3[$q1[$q1[$q0[$j] ^ $key[24]] ^ $key[16]] ^ $key[8]];
$B = ($B << 8) | ($B >> 24 & 0xff); $B = ($B << 8) | ($B >> 24 & 0xff);
$K[] = $A+= $B; $A = $this->safe_intval($A + $B);
$K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff); $K[] = $A;
$A = $this->safe_intval($A + $B);
$K[] = ($A << 9 | $A >> 23 & 0x1ff);
} }
for ($i = 0; $i < 256; ++$i) { for ($i = 0; $i < 256; ++$i) {
$S0[$i] = $m0[$q0[$q0[$q1[$i] ^ $s8] ^ $s4] ^ $s0]; $S0[$i] = $m0[$q0[$q0[$q1[$i] ^ $s8] ^ $s4] ^ $s0];
@ -567,8 +558,10 @@ class Crypt_Twofish extends Crypt_Base
$m2[$q1[$q0[$q0[$q0[$j] ^ $key[31]] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^ $m2[$q1[$q0[$q0[$q0[$j] ^ $key[31]] ^ $key[23]] ^ $key[15]] ^ $key[7]] ^
$m3[$q1[$q1[$q0[$q1[$j] ^ $key[32]] ^ $key[24]] ^ $key[16]] ^ $key[8]]; $m3[$q1[$q1[$q0[$q1[$j] ^ $key[32]] ^ $key[24]] ^ $key[16]] ^ $key[8]];
$B = ($B << 8) | ($B >> 24 & 0xff); $B = ($B << 8) | ($B >> 24 & 0xff);
$K[] = $A+= $B; $A = $this->safe_intval($A + $B);
$K[] = (($A+= $B) << 9 | $A >> 23 & 0x1ff); $K[] = $A;
$A = $this->safe_intval($A + $B);
$K[] = ($A << 9 | $A >> 23 & 0x1ff);
} }
for ($i = 0; $i < 256; ++$i) { for ($i = 0; $i < 256; ++$i) {
$S0[$i] = $m0[$q0[$q0[$q1[$q1[$i] ^ $sc] ^ $s8] ^ $s4] ^ $s0]; $S0[$i] = $m0[$q0[$q0[$q1[$q1[$i] ^ $sc] ^ $s8] ^ $s4] ^ $s0];
@ -589,9 +582,9 @@ class Crypt_Twofish extends Crypt_Base
* _mdsrem function using by the twofish cipher algorithm * _mdsrem function using by the twofish cipher algorithm
* *
* @access private * @access private
* @param String $A * @param string $A
* @param String $B * @param string $B
* @return Array * @return array
*/ */
function _mdsrem($A, $B) function _mdsrem($A, $B)
{ {
@ -618,7 +611,9 @@ class Crypt_Twofish extends Crypt_Base
$u^= 0x7fffffff & ($t >> 1); $u^= 0x7fffffff & ($t >> 1);
// Add the modular polynomial on underflow. // Add the modular polynomial on underflow.
if ($t & 0x01) $u^= 0xa6 ; if ($t & 0x01) {
$u^= 0xa6 ;
}
// Remove t * (a + 1/a) * (x^3 + x). // Remove t * (a + 1/a) * (x^3 + x).
$B^= ($u << 24) | ($u << 8); $B^= ($u << 24) | ($u << 8);
@ -635,8 +630,8 @@ class Crypt_Twofish extends Crypt_Base
* Encrypts a block * Encrypts a block
* *
* @access private * @access private
* @param String $in * @param string $in
* @return String * @return string
*/ */
function _encryptBlock($in) function _encryptBlock($in)
{ {
@ -662,9 +657,9 @@ class Crypt_Twofish extends Crypt_Base
$S1[ $R1 & 0xff] ^ $S1[ $R1 & 0xff] ^
$S2[($R1 >> 8) & 0xff] ^ $S2[($R1 >> 8) & 0xff] ^
$S3[($R1 >> 16) & 0xff]; $S3[($R1 >> 16) & 0xff];
$R2^= $t0 + $t1 + $K[++$ki]; $R2^= $this->safe_intval($t0 + $t1 + $K[++$ki]);
$R2 = ($R2 >> 1 & 0x7fffffff) | ($R2 << 31); $R2 = ($R2 >> 1 & 0x7fffffff) | ($R2 << 31);
$R3 = ((($R3 >> 31) & 1) | ($R3 << 1)) ^ ($t0 + ($t1 << 1) + $K[++$ki]); $R3 = ((($R3 >> 31) & 1) | ($R3 << 1)) ^ $this->safe_intval($t0 + ($t1 << 1) + $K[++$ki]);
$t0 = $S0[ $R2 & 0xff] ^ $t0 = $S0[ $R2 & 0xff] ^
$S1[($R2 >> 8) & 0xff] ^ $S1[($R2 >> 8) & 0xff] ^
@ -674,9 +669,9 @@ class Crypt_Twofish extends Crypt_Base
$S1[ $R3 & 0xff] ^ $S1[ $R3 & 0xff] ^
$S2[($R3 >> 8) & 0xff] ^ $S2[($R3 >> 8) & 0xff] ^
$S3[($R3 >> 16) & 0xff]; $S3[($R3 >> 16) & 0xff];
$R0^= ($t0 + $t1 + $K[++$ki]); $R0^= $this->safe_intval($t0 + $t1 + $K[++$ki]);
$R0 = ($R0 >> 1 & 0x7fffffff) | ($R0 << 31); $R0 = ($R0 >> 1 & 0x7fffffff) | ($R0 << 31);
$R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ ($t0 + ($t1 << 1) + $K[++$ki]); $R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ $this->safe_intval($t0 + ($t1 << 1) + $K[++$ki]);
} }
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
@ -691,8 +686,8 @@ class Crypt_Twofish extends Crypt_Base
* Decrypts a block * Decrypts a block
* *
* @access private * @access private
* @param String $in * @param string $in
* @return String * @return string
*/ */
function _decryptBlock($in) function _decryptBlock($in)
{ {
@ -718,9 +713,9 @@ class Crypt_Twofish extends Crypt_Base
$S1[$R1 & 0xff] ^ $S1[$R1 & 0xff] ^
$S2[$R1 >> 8 & 0xff] ^ $S2[$R1 >> 8 & 0xff] ^
$S3[$R1 >> 16 & 0xff]; $S3[$R1 >> 16 & 0xff];
$R3^= $t0 + ($t1 << 1) + $K[--$ki]; $R3^= $this->safe_intval($t0 + ($t1 << 1) + $K[--$ki]);
$R3 = $R3 >> 1 & 0x7fffffff | $R3 << 31; $R3 = $R3 >> 1 & 0x7fffffff | $R3 << 31;
$R2 = ($R2 >> 31 & 0x1 | $R2 << 1) ^ ($t0 + $t1 + $K[--$ki]); $R2 = ($R2 >> 31 & 0x1 | $R2 << 1) ^ $this->safe_intval($t0 + $t1 + $K[--$ki]);
$t0 = $S0[$R2 & 0xff] ^ $t0 = $S0[$R2 & 0xff] ^
$S1[$R2 >> 8 & 0xff] ^ $S1[$R2 >> 8 & 0xff] ^
@ -730,9 +725,9 @@ class Crypt_Twofish extends Crypt_Base
$S1[$R3 & 0xff] ^ $S1[$R3 & 0xff] ^
$S2[$R3 >> 8 & 0xff] ^ $S2[$R3 >> 8 & 0xff] ^
$S3[$R3 >> 16 & 0xff]; $S3[$R3 >> 16 & 0xff];
$R1^= $t0 + ($t1 << 1) + $K[--$ki]; $R1^= $this->safe_intval($t0 + ($t1 << 1) + $K[--$ki]);
$R1 = $R1 >> 1 & 0x7fffffff | $R1 << 31; $R1 = $R1 >> 1 & 0x7fffffff | $R1 << 31;
$R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ ($t0 + $t1 + $K[--$ki]); $R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ $this->safe_intval($t0 + $t1 + $K[--$ki]);
} }
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
@ -754,21 +749,21 @@ class Crypt_Twofish extends Crypt_Base
$lambda_functions =& Crypt_Twofish::_getLambdaFunctions(); $lambda_functions =& Crypt_Twofish::_getLambdaFunctions();
// Max. 10 Ultra-Hi-optimized inline-crypt functions. After that, we'll (still) create very fast code, but not the ultimate fast one. // Max. 10 Ultra-Hi-optimized inline-crypt functions. After that, we'll (still) create very fast code, but not the ultimate fast one.
// (Currently, for Crypt_Twofish, one generated $lambda_function cost on php5.5@32bit ~140kb unfreeable mem and ~240kb on php5.5@64bit)
$gen_hi_opt_code = (bool)(count($lambda_functions) < 10); $gen_hi_opt_code = (bool)(count($lambda_functions) < 10);
switch (true) { // Generation of a unique hash for our generated code
case $gen_hi_opt_code:
$code_hash = md5(str_pad("Crypt_Twofish, {$this->mode}, ", 32, "\0") . $this->key);
break;
default:
$code_hash = "Crypt_Twofish, {$this->mode}"; $code_hash = "Crypt_Twofish, {$this->mode}";
if ($gen_hi_opt_code) {
$code_hash = str_pad($code_hash, 32) . $this->_hashInlineCryptFunction($this->key);
} }
$safeint = $this->safe_intval_inline();
if (!isset($lambda_functions[$code_hash])) { if (!isset($lambda_functions[$code_hash])) {
switch (true) { switch (true) {
case $gen_hi_opt_code: case $gen_hi_opt_code:
$K = $this->K; $K = $this->K;
$init_crypt = ' $init_crypt = '
static $S0, $S1, $S2, $S3; static $S0, $S1, $S2, $S3;
if (!$S0) { if (!$S0) {
@ -786,7 +781,6 @@ class Crypt_Twofish extends Crypt_Base
for ($i = 0; $i < 40; ++$i) { for ($i = 0; $i < 40; ++$i) {
$K[] = '$K_' . $i; $K[] = '$K_' . $i;
} }
$init_crypt = ' $init_crypt = '
$S0 = $self->S0; $S0 = $self->S0;
$S1 = $self->S1; $S1 = $self->S1;
@ -814,9 +808,9 @@ class Crypt_Twofish extends Crypt_Base
$S1[ $R1 & 0xff] ^ $S1[ $R1 & 0xff] ^
$S2[($R1 >> 8) & 0xff] ^ $S2[($R1 >> 8) & 0xff] ^
$S3[($R1 >> 16) & 0xff]; $S3[($R1 >> 16) & 0xff];
$R2^= ($t0 + $t1 + '.$K[++$ki].'); $R2^= ' . sprintf($safeint, '$t0 + $t1 + ' . $K[++$ki]) . ';
$R2 = ($R2 >> 1 & 0x7fffffff) | ($R2 << 31); $R2 = ($R2 >> 1 & 0x7fffffff) | ($R2 << 31);
$R3 = ((($R3 >> 31) & 1) | ($R3 << 1)) ^ ($t0 + ($t1 << 1) + '.$K[++$ki].'); $R3 = ((($R3 >> 31) & 1) | ($R3 << 1)) ^ ' . sprintf($safeint, '($t0 + ($t1 << 1) + ' . $K[++$ki] . ')') . ';
$t0 = $S0[ $R2 & 0xff] ^ $t0 = $S0[ $R2 & 0xff] ^
$S1[($R2 >> 8) & 0xff] ^ $S1[($R2 >> 8) & 0xff] ^
@ -826,9 +820,9 @@ class Crypt_Twofish extends Crypt_Base
$S1[ $R3 & 0xff] ^ $S1[ $R3 & 0xff] ^
$S2[($R3 >> 8) & 0xff] ^ $S2[($R3 >> 8) & 0xff] ^
$S3[($R3 >> 16) & 0xff]; $S3[($R3 >> 16) & 0xff];
$R0^= ($t0 + $t1 + '.$K[++$ki].'); $R0^= ' . sprintf($safeint, '($t0 + $t1 + ' . $K[++$ki] . ')') . ';
$R0 = ($R0 >> 1 & 0x7fffffff) | ($R0 << 31); $R0 = ($R0 >> 1 & 0x7fffffff) | ($R0 << 31);
$R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ ($t0 + ($t1 << 1) + '.$K[++$ki].'); $R1 = ((($R1 >> 31) & 1) | ($R1 << 1)) ^ ' . sprintf($safeint, '($t0 + ($t1 << 1) + ' . $K[++$ki] . ')') . ';
'; ';
} }
$encrypt_block.= ' $encrypt_block.= '
@ -856,9 +850,9 @@ class Crypt_Twofish extends Crypt_Base
$S1[$R1 & 0xff] ^ $S1[$R1 & 0xff] ^
$S2[$R1 >> 8 & 0xff] ^ $S2[$R1 >> 8 & 0xff] ^
$S3[$R1 >> 16 & 0xff]; $S3[$R1 >> 16 & 0xff];
$R3^= $t0 + ($t1 << 1) + '.$K[--$ki].'; $R3^= ' . sprintf($safeint, '$t0 + ($t1 << 1) + ' . $K[--$ki]) . ';
$R3 = $R3 >> 1 & 0x7fffffff | $R3 << 31; $R3 = $R3 >> 1 & 0x7fffffff | $R3 << 31;
$R2 = ($R2 >> 31 & 0x1 | $R2 << 1) ^ ($t0 + $t1 + '.$K[--$ki].'); $R2 = ($R2 >> 31 & 0x1 | $R2 << 1) ^ ' . sprintf($safeint, '($t0 + $t1 + '.$K[--$ki] . ')') . ';
$t0 = $S0[$R2 & 0xff] ^ $t0 = $S0[$R2 & 0xff] ^
$S1[$R2 >> 8 & 0xff] ^ $S1[$R2 >> 8 & 0xff] ^
@ -868,9 +862,9 @@ class Crypt_Twofish extends Crypt_Base
$S1[$R3 & 0xff] ^ $S1[$R3 & 0xff] ^
$S2[$R3 >> 8 & 0xff] ^ $S2[$R3 >> 8 & 0xff] ^
$S3[$R3 >> 16 & 0xff]; $S3[$R3 >> 16 & 0xff];
$R1^= $t0 + ($t1 << 1) + '.$K[--$ki].'; $R1^= ' . sprintf($safeint, '$t0 + ($t1 << 1) + ' . $K[--$ki]) . ';
$R1 = $R1 >> 1 & 0x7fffffff | $R1 << 31; $R1 = $R1 >> 1 & 0x7fffffff | $R1 << 31;
$R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ ($t0 + $t1 + '.$K[--$ki].'); $R0 = ($R0 >> 31 & 0x1 | $R0 << 1) ^ ' . sprintf($safeint, '($t0 + $t1 + '.$K[--$ki] . ')') . ';
'; ';
} }
$decrypt_block.= ' $decrypt_block.= '

353
rainloop/v/0.0.0/app/libraries/phpseclib/File/ANSI.php Normal file → Executable file
View file

@ -48,7 +48,7 @@ class File_ANSI
/** /**
* Max Width * Max Width
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $max_x; var $max_x;
@ -56,7 +56,7 @@ class File_ANSI
/** /**
* Max Height * Max Height
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $max_y; var $max_y;
@ -64,7 +64,7 @@ class File_ANSI
/** /**
* Max History * Max History
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $max_history; var $max_history;
@ -72,7 +72,7 @@ class File_ANSI
/** /**
* History * History
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $history; var $history;
@ -80,7 +80,7 @@ class File_ANSI
/** /**
* History Attributes * History Attributes
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $history_attrs; var $history_attrs;
@ -88,7 +88,7 @@ class File_ANSI
/** /**
* Current Column * Current Column
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $x; var $x;
@ -96,7 +96,7 @@ class File_ANSI
/** /**
* Current Row * Current Row
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $y; var $y;
@ -104,7 +104,7 @@ class File_ANSI
/** /**
* Old Column * Old Column
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $old_x; var $old_x;
@ -112,15 +112,31 @@ class File_ANSI
/** /**
* Old Row * Old Row
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $old_y; var $old_y;
/**
* An empty attribute cell
*
* @var object
* @access private
*/
var $base_attr_cell;
/**
* The current attribute cell
*
* @var object
* @access private
*/
var $attr_cell;
/** /**
* An empty attribute row * An empty attribute row
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $attr_row; var $attr_row;
@ -128,7 +144,7 @@ class File_ANSI
/** /**
* The current screen text * The current screen text
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $screen; var $screen;
@ -136,94 +152,67 @@ class File_ANSI
/** /**
* The current screen attributes * The current screen attributes
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $attrs; var $attrs;
/**
* The current foreground color
*
* @var String
* @access private
*/
var $foreground;
/**
* The current background color
*
* @var String
* @access private
*/
var $background;
/**
* Bold flag
*
* @var Boolean
* @access private
*/
var $bold;
/**
* Underline flag
*
* @var Boolean
* @access private
*/
var $underline;
/**
* Blink flag
*
* @var Boolean
* @access private
*/
var $blink;
/**
* Reverse flag
*
* @var Boolean
* @access private
*/
var $reverse;
/**
* Color flag
*
* @var Boolean
* @access private
*/
var $color;
/** /**
* Current ANSI code * Current ANSI code
* *
* @var String * @var string
* @access private * @access private
*/ */
var $ansi; var $ansi;
/**
* Tokenization
*
* @var array
* @access private
*/
var $tokenization;
/** /**
* Default Constructor. * Default Constructor.
* *
* @return File_ANSI * @return File_ANSI
* @access public * @access public
*/ */
function File_ANSI() function __construct()
{ {
$attr_cell = new stdClass();
$attr_cell->bold = false;
$attr_cell->underline = false;
$attr_cell->blink = false;
$attr_cell->background = 'black';
$attr_cell->foreground = 'white';
$attr_cell->reverse = false;
$this->base_attr_cell = clone($attr_cell);
$this->attr_cell = clone($attr_cell);
$this->setHistory(200); $this->setHistory(200);
$this->setDimensions(80, 24); $this->setDimensions(80, 24);
} }
/**
* PHP4 compatible Default Constructor.
*
* @see self::__construct()
* @access public
*/
function File_ANSI()
{
$this->__construct($mode);
}
/** /**
* Set terminal width and height * Set terminal width and height
* *
* Resets the screen as well * Resets the screen as well
* *
* @param Integer $x * @param int $x
* @param Integer $y * @param int $y
* @access public * @access public
*/ */
function setDimensions($x, $y) function setDimensions($x, $y)
@ -232,25 +221,17 @@ class File_ANSI
$this->max_y = $y - 1; $this->max_y = $y - 1;
$this->x = $this->y = 0; $this->x = $this->y = 0;
$this->history = $this->history_attrs = array(); $this->history = $this->history_attrs = array();
$this->attr_row = array_fill(0, $this->max_x + 1, ''); $this->attr_row = array_fill(0, $this->max_x + 2, $this->base_attr_cell);
$this->screen = array_fill(0, $this->max_y + 1, ''); $this->screen = array_fill(0, $this->max_y + 1, '');
$this->attrs = array_fill(0, $this->max_y + 1, $this->attr_row); $this->attrs = array_fill(0, $this->max_y + 1, $this->attr_row);
$this->foreground = 'white';
$this->background = 'black';
$this->bold = false;
$this->underline = false;
$this->blink = false;
$this->reverse = false;
$this->color = false;
$this->ansi = ''; $this->ansi = '';
} }
/** /**
* Set the number of lines that should be logged past the terminal height * Set the number of lines that should be logged past the terminal height
* *
* @param Integer $x * @param int $x
* @param Integer $y * @param int $y
* @access public * @access public
*/ */
function setHistory($history) function setHistory($history)
@ -261,7 +242,7 @@ class File_ANSI
/** /**
* Load a string * Load a string
* *
* @param String $source * @param string $source
* @access public * @access public
*/ */
function loadString($source) function loadString($source)
@ -273,11 +254,12 @@ class File_ANSI
/** /**
* Appdend a string * Appdend a string
* *
* @param String $source * @param string $source
* @access public * @access public
*/ */
function appendString($source) function appendString($source)
{ {
$this->tokenization = array('');
for ($i = 0; $i < strlen($source); $i++) { for ($i = 0; $i < strlen($source); $i++) {
if (strlen($this->ansi)) { if (strlen($this->ansi)) {
$this->ansi.= $source[$i]; $this->ansi.= $source[$i];
@ -294,6 +276,8 @@ class File_ANSI
default: default:
continue 2; continue 2;
} }
$this->tokenization[] = $this->ansi;
$this->tokenization[] = '';
// http://ascii-table.com/ansi-escape-sequences-vt-100.php // http://ascii-table.com/ansi-escape-sequences-vt-100.php
switch ($this->ansi) { switch ($this->ansi) {
case "\x1B[H": // Move cursor to upper left corner case "\x1B[H": // Move cursor to upper left corner
@ -315,7 +299,7 @@ class File_ANSI
case "\x1B[K": // Clear screen from cursor right case "\x1B[K": // Clear screen from cursor right
$this->screen[$this->y] = substr($this->screen[$this->y], 0, $this->x); $this->screen[$this->y] = substr($this->screen[$this->y], 0, $this->x);
array_splice($this->attrs[$this->y], $this->x + 1); array_splice($this->attrs[$this->y], $this->x + 1, $this->max_x - $this->x, array_fill($this->x, $this->max_x - $this->x - 1, $this->base_attr_cell));
break; break;
case "\x1B[2K": // Clear entire line case "\x1B[2K": // Clear entire line
$this->screen[$this->y] = str_repeat(' ', $this->x); $this->screen[$this->y] = str_repeat(' ', $this->x);
@ -323,6 +307,7 @@ class File_ANSI
break; break;
case "\x1B[?1h": // set cursor key to application case "\x1B[?1h": // set cursor key to application
case "\x1B[?25h": // show the cursor case "\x1B[?25h": // show the cursor
case "\x1B(B": // set united states g0 character set
break; break;
case "\x1BE": // Move to next line case "\x1BE": // Move to next line
$this->_newLine(); $this->_newLine();
@ -330,6 +315,10 @@ class File_ANSI
break; break;
default: default:
switch (true) { switch (true) {
case preg_match('#\x1B\[(\d+)B#', $this->ansi, $match): // Move cursor down n lines
$this->old_y = $this->y;
$this->y+= $match[1];
break;
case preg_match('#\x1B\[(\d+);(\d+)H#', $this->ansi, $match): // Move cursor to screen location v,h case preg_match('#\x1B\[(\d+);(\d+)H#', $this->ansi, $match): // Move cursor to screen location v,h
$this->old_x = $this->x; $this->old_x = $this->x;
$this->old_y = $this->y; $this->old_y = $this->y;
@ -338,65 +327,47 @@ class File_ANSI
break; break;
case preg_match('#\x1B\[(\d+)C#', $this->ansi, $match): // Move cursor right n lines case preg_match('#\x1B\[(\d+)C#', $this->ansi, $match): // Move cursor right n lines
$this->old_x = $this->x; $this->old_x = $this->x;
$x = $match[1] - 1; $this->x+= $match[1];
break;
case preg_match('#\x1B\[(\d+)D#', $this->ansi, $match): // Move cursor left n lines
$this->old_x = $this->x;
$this->x-= $match[1];
if ($this->x < 0) {
$this->x = 0;
}
break; break;
case preg_match('#\x1B\[(\d+);(\d+)r#', $this->ansi, $match): // Set top and bottom lines of a window case preg_match('#\x1B\[(\d+);(\d+)r#', $this->ansi, $match): // Set top and bottom lines of a window
break; break;
case preg_match('#\x1B\[(\d*(?:;\d*)*)m#', $this->ansi, $match): // character attributes case preg_match('#\x1B\[(\d*(?:;\d*)*)m#', $this->ansi, $match): // character attributes
$attr_cell = &$this->attr_cell;
$mods = explode(';', $match[1]); $mods = explode(';', $match[1]);
foreach ($mods as $mod) { foreach ($mods as $mod) {
switch ($mod) { switch ($mod) {
case 0: // Turn off character attributes case 0: // Turn off character attributes
$this->attrs[$this->y][$this->x] = ''; $attr_cell = clone($this->base_attr_cell);
if ($this->bold) $this->attrs[$this->y][$this->x].= '</b>';
if ($this->underline) $this->attrs[$this->y][$this->x].= '</u>';
if ($this->blink) $this->attrs[$this->y][$this->x].= '</blink>';
if ($this->color) $this->attrs[$this->y][$this->x].= '</span>';
if ($this->reverse) {
$temp = $this->background;
$this->background = $this->foreground;
$this->foreground = $temp;
}
$this->bold = $this->underline = $this->blink = $this->color = $this->reverse = false;
break; break;
case 1: // Turn bold mode on case 1: // Turn bold mode on
if (!$this->bold) { $attr_cell->bold = true;
$this->attrs[$this->y][$this->x] = '<b>';
$this->bold = true;
}
break; break;
case 4: // Turn underline mode on case 4: // Turn underline mode on
if (!$this->underline) { $attr_cell->underline = true;
$this->attrs[$this->y][$this->x] = '<u>';
$this->underline = true;
}
break; break;
case 5: // Turn blinking mode on case 5: // Turn blinking mode on
if (!$this->blink) { $attr_cell->blink = true;
$this->attrs[$this->y][$this->x] = '<blink>';
$this->blink = true;
}
break; break;
case 7: // Turn reverse video on case 7: // Turn reverse video on
$this->reverse = !$this->reverse; $attr_cell->reverse = !$attr_cell->reverse;
$temp = $this->background; $temp = $attr_cell->background;
$this->background = $this->foreground; $attr_cell->background = $attr_cell->foreground;
$this->foreground = $temp; $attr_cell->foreground = $temp;
$this->attrs[$this->y][$this->x] = '<span style="color: ' . $this->foreground . '; background: ' . $this->background . '">';
if ($this->color) {
$this->attrs[$this->y][$this->x] = '</span>' . $this->attrs[$this->y][$this->x];
}
$this->color = true;
break; break;
default: // set colors default: // set colors
//$front = $this->reverse ? &$this->background : &$this->foreground; //$front = $attr_cell->reverse ? &$attr_cell->background : &$attr_cell->foreground;
$front = &$this->{ $this->reverse ? 'background' : 'foreground' }; $front = &$attr_cell->{ $attr_cell->reverse ? 'background' : 'foreground' };
//$back = $this->reverse ? &$this->foreground : &$this->background; //$back = $attr_cell->reverse ? &$attr_cell->foreground : &$attr_cell->background;
$back = &$this->{ $this->reverse ? 'foreground' : 'background' }; $back = &$attr_cell->{ $attr_cell->reverse ? 'foreground' : 'background' };
switch ($mod) { switch ($mod) {
// @codingStandardsIgnoreStart
case 30: $front = 'black'; break; case 30: $front = 'black'; break;
case 31: $front = 'red'; break; case 31: $front = 'red'; break;
case 32: $front = 'green'; break; case 32: $front = 'green'; break;
@ -414,30 +385,25 @@ class File_ANSI
case 45: $back = 'magenta'; break; case 45: $back = 'magenta'; break;
case 46: $back = 'cyan'; break; case 46: $back = 'cyan'; break;
case 47: $back = 'white'; break; case 47: $back = 'white'; break;
// @codingStandardsIgnoreEnd
default: default:
user_error('Unsupported attribute: ' . $mod); //user_error('Unsupported attribute: ' . $mod);
$this->ansi = ''; $this->ansi = '';
break 2; break 2;
} }
unset($temp);
$this->attrs[$this->y][$this->x] = '<span style="color: ' . $this->foreground . '; background: ' . $this->background . '">';
if ($this->color) {
$this->attrs[$this->y][$this->x] = '</span>' . $this->attrs[$this->y][$this->x];
}
$this->color = true;
} }
} }
break; break;
default: default:
user_error("{$this->ansi} unsupported\r\n"); //user_error("{$this->ansi} is unsupported\r\n");
} }
} }
$this->ansi = ''; $this->ansi = '';
continue; continue;
} }
$this->tokenization[count($this->tokenization) - 1].= $source[$i];
switch ($source[$i]) { switch ($source[$i]) {
case "\r": case "\r":
$this->x = 0; $this->x = 0;
@ -445,12 +411,32 @@ class File_ANSI
case "\n": case "\n":
$this->_newLine(); $this->_newLine();
break; break;
case "\x08": // backspace
if ($this->x) {
$this->x--;
$this->attrs[$this->y][$this->x] = clone($this->base_attr_cell);
$this->screen[$this->y] = substr_replace(
$this->screen[$this->y],
$source[$i],
$this->x,
1
);
}
break;
case "\x0F": // shift case "\x0F": // shift
break; break;
case "\x1B": // start ANSI escape code case "\x1B": // start ANSI escape code
$this->tokenization[count($this->tokenization) - 1] = substr($this->tokenization[count($this->tokenization) - 1], 0, -1);
//if (!strlen($this->tokenization[count($this->tokenization) - 1])) {
// array_pop($this->tokenization);
//}
$this->ansi.= "\x1B"; $this->ansi.= "\x1B";
break; break;
default: default:
$this->attrs[$this->y][$this->x] = clone($this->attr_cell);
if ($this->x > strlen($this->screen[$this->y])) {
$this->screen[$this->y] = str_repeat(' ', $this->x);
}
$this->screen[$this->y] = substr_replace( $this->screen[$this->y] = substr_replace(
$this->screen[$this->y], $this->screen[$this->y],
$source[$i], $source[$i],
@ -460,7 +446,7 @@ class File_ANSI
if ($this->x > $this->max_x) { if ($this->x > $this->max_x) {
$this->x = 0; $this->x = 0;
$this->y++; $this->_newLine();
} else { } else {
$this->x++; $this->x++;
} }
@ -498,26 +484,84 @@ class File_ANSI
$this->y++; $this->y++;
} }
/**
* Returns the current coordinate without preformating
*
* @access private
* @return string
*/
function _processCoordinate($last_attr, $cur_attr, $char)
{
$output = '';
if ($last_attr != $cur_attr) {
$close = $open = '';
if ($last_attr->foreground != $cur_attr->foreground) {
if ($cur_attr->foreground != 'white') {
$open.= '<span style="color: ' . $cur_attr->foreground . '">';
}
if ($last_attr->foreground != 'white') {
$close = '</span>' . $close;
}
}
if ($last_attr->background != $cur_attr->background) {
if ($cur_attr->background != 'black') {
$open.= '<span style="background: ' . $cur_attr->background . '">';
}
if ($last_attr->background != 'black') {
$close = '</span>' . $close;
}
}
if ($last_attr->bold != $cur_attr->bold) {
if ($cur_attr->bold) {
$open.= '<b>';
} else {
$close = '</b>' . $close;
}
}
if ($last_attr->underline != $cur_attr->underline) {
if ($cur_attr->underline) {
$open.= '<u>';
} else {
$close = '</u>' . $close;
}
}
if ($last_attr->blink != $cur_attr->blink) {
if ($cur_attr->blink) {
$open.= '<blink>';
} else {
$close = '</blink>' . $close;
}
}
$output.= $close . $open;
}
$output.= htmlspecialchars($char);
return $output;
}
/** /**
* Returns the current screen without preformating * Returns the current screen without preformating
* *
* @access private * @access private
* @return String * @return string
*/ */
function _getScreen() function _getScreen()
{ {
$output = ''; $output = '';
$last_attr = $this->base_attr_cell;
for ($i = 0; $i <= $this->max_y; $i++) { for ($i = 0; $i <= $this->max_y; $i++) {
for ($j = 0; $j <= $this->max_x + 1; $j++) { for ($j = 0; $j <= $this->max_x; $j++) {
if (isset($this->attrs[$i][$j])) { $cur_attr = $this->attrs[$i][$j];
$output.= $this->attrs[$i][$j]; $output.= $this->_processCoordinate($last_attr, $cur_attr, isset($this->screen[$i][$j]) ? $this->screen[$i][$j] : '');
} $last_attr = $this->attrs[$i][$j];
if (isset($this->screen[$i][$j])) {
$output.= htmlspecialchars($this->screen[$i][$j]);
}
} }
$output.= "\r\n"; $output.= "\r\n";
} }
$output = substr($output, 0, -2);
// close any remaining open tags
$output.= $this->_processCoordinate($last_attr, $this->base_attr_cell, '');
return rtrim($output); return rtrim($output);
} }
@ -525,35 +569,36 @@ class File_ANSI
* Returns the current screen * Returns the current screen
* *
* @access public * @access public
* @return String * @return string
*/ */
function getScreen() function getScreen()
{ {
return '<pre style="color: white; background: black" width="' . ($this->max_x + 1) . '">' . $this->_getScreen() . '</pre>'; return '<pre width="' . ($this->max_x + 1) . '" style="color: white; background: black">' . $this->_getScreen() . '</pre>';
} }
/** /**
* Returns the current screen and the x previous lines * Returns the current screen and the x previous lines
* *
* @access public * @access public
* @return String * @return string
*/ */
function getHistory() function getHistory()
{ {
$scrollback = ''; $scrollback = '';
$last_attr = $this->base_attr_cell;
for ($i = 0; $i < count($this->history); $i++) { for ($i = 0; $i < count($this->history); $i++) {
for ($j = 0; $j <= $this->max_x + 1; $j++) { for ($j = 0; $j <= $this->max_x + 1; $j++) {
if (isset($this->history_attrs[$i][$j])) { $cur_attr = $this->history_attrs[$i][$j];
$scrollback.= $this->history_attrs[$i][$j]; $scrollback.= $this->_processCoordinate($last_attr, $cur_attr, isset($this->history[$i][$j]) ? $this->history[$i][$j] : '');
} $last_attr = $this->history_attrs[$i][$j];
if (isset($this->history[$i][$j])) {
$scrollback.= htmlspecialchars($this->history[$i][$j]);
}
} }
$scrollback.= "\r\n"; $scrollback.= "\r\n";
} }
$base_attr_cell = $this->base_attr_cell;
$this->base_attr_cell = $last_attr;
$scrollback.= $this->_getScreen(); $scrollback.= $this->_getScreen();
$this->base_attr_cell = $base_attr_cell;
return '<pre style="color: white; background: black" width="' . ($this->max_x + 1) . '">' . $scrollback . '</pre>'; return '<pre width="' . ($this->max_x + 1) . '" style="color: white; background: black">' . $scrollback . '</span></pre>';
} }
} }

301
rainloop/v/0.0.0/app/libraries/phpseclib/File/ASN1.php Normal file → Executable file
View file

@ -119,7 +119,7 @@ class File_ASN1_Element
/** /**
* Raw element value * Raw element value
* *
* @var String * @var string
* @access private * @access private
*/ */
var $element; var $element;
@ -127,13 +127,25 @@ class File_ASN1_Element
/** /**
* Constructor * Constructor
* *
* @param String $encoded * @param string $encoded
* @return File_ASN1_Element * @return File_ASN1_Element
* @access public * @access public
*/ */
function __construct($encoded)
{
$this->element = $encoded;
}
/**
* PHP4 compatible Default Constructor.
*
* @see self::__construct()
* @param int $mode
* @access public
*/
function File_ASN1_Element($encoded) function File_ASN1_Element($encoded)
{ {
$this->element = $encoded; $this->__construct($encoded);
} }
} }
@ -149,7 +161,7 @@ class File_ASN1
/** /**
* ASN.1 object identifier * ASN.1 object identifier
* *
* @var Array * @var array
* @access private * @access private
* @link http://en.wikipedia.org/wiki/Object_identifier * @link http://en.wikipedia.org/wiki/Object_identifier
*/ */
@ -158,7 +170,7 @@ class File_ASN1
/** /**
* Default date format * Default date format
* *
* @var String * @var string
* @access private * @access private
* @link http://php.net/class.datetime * @link http://php.net/class.datetime
*/ */
@ -167,10 +179,10 @@ class File_ASN1
/** /**
* Default date format * Default date format
* *
* @var Array * @var array
* @access private * @access private
* @see File_ASN1::setTimeFormat() * @see self::setTimeFormat()
* @see File_ASN1::asn1map() * @see self::asn1map()
* @link http://php.net/class.datetime * @link http://php.net/class.datetime
*/ */
var $encoded; var $encoded;
@ -180,9 +192,9 @@ class File_ASN1
* *
* If the mapping type is FILE_ASN1_TYPE_ANY what do we actually encode it as? * If the mapping type is FILE_ASN1_TYPE_ANY what do we actually encode it as?
* *
* @var Array * @var array
* @access private * @access private
* @see File_ASN1::_encode_der() * @see self::_encode_der()
*/ */
var $filters; var $filters;
@ -193,7 +205,7 @@ class File_ASN1
* Unambiguous types get the direct mapping (int/real/bool). * Unambiguous types get the direct mapping (int/real/bool).
* Others are mapped as a choice, with an extra indexing level. * Others are mapped as a choice, with an extra indexing level.
* *
* @var Array * @var array
* @access public * @access public
*/ */
var $ANYmap = array( var $ANYmap = array(
@ -227,7 +239,7 @@ class File_ASN1
* Non-convertable types are absent from this table. * Non-convertable types are absent from this table.
* size == 0 indicates variable length encoding. * size == 0 indicates variable length encoding.
* *
* @var Array * @var array
* @access public * @access public
*/ */
var $stringTypeSize = array( var $stringTypeSize = array(
@ -245,7 +257,7 @@ class File_ASN1
* *
* @access public * @access public
*/ */
function File_ASN1() function __construct()
{ {
static $static_init = null; static $static_init = null;
if (!$static_init) { if (!$static_init) {
@ -256,13 +268,24 @@ class File_ASN1
} }
} }
/**
* PHP4 compatible Default Constructor.
*
* @see self::__construct()
* @access public
*/
function File_ASN1()
{
$this->__construct($mode);
}
/** /**
* Parse BER-encoding * Parse BER-encoding
* *
* Serves a similar purpose to openssl's asn1parse * Serves a similar purpose to openssl's asn1parse
* *
* @param String $encoded * @param string $encoded
* @return Array * @return array
* @access public * @access public
*/ */
function decodeBER($encoded) function decodeBER($encoded)
@ -283,16 +306,17 @@ class File_ASN1
* $encoded is passed by reference for the recursive calls done for FILE_ASN1_TYPE_BIT_STRING and * $encoded is passed by reference for the recursive calls done for FILE_ASN1_TYPE_BIT_STRING and
* FILE_ASN1_TYPE_OCTET_STRING. In those cases, the indefinite length is used. * FILE_ASN1_TYPE_OCTET_STRING. In those cases, the indefinite length is used.
* *
* @param String $encoded * @param string $encoded
* @param Integer $start * @param int $start
* @return Array * @param int $encoded_pos
* @return array
* @access private * @access private
*/ */
function _decode_ber($encoded, $start = 0) function _decode_ber($encoded, $start = 0, $encoded_pos = 0)
{ {
$current = array('start' => $start); $current = array('start' => $start);
$type = ord($this->_string_shift($encoded)); $type = ord($encoded[$encoded_pos++]);
$start++; $start++;
$constructed = ($type >> 5) & 1; $constructed = ($type >> 5) & 1;
@ -304,23 +328,24 @@ class File_ASN1
do { do {
$loop = ord($encoded[0]) >> 7; $loop = ord($encoded[0]) >> 7;
$tag <<= 7; $tag <<= 7;
$tag |= ord($this->_string_shift($encoded)) & 0x7F; $tag |= ord($encoded[$encoded_pos++]) & 0x7F;
$start++; $start++;
} while ($loop); } while ($loop);
} }
// Length, as discussed in paragraph 8.1.3 of X.690-0207.pdf#page=13 // Length, as discussed in paragraph 8.1.3 of X.690-0207.pdf#page=13
$length = ord($this->_string_shift($encoded)); $length = ord($encoded[$encoded_pos++]);
$start++; $start++;
if ($length == 0x80) { // indefinite length if ($length == 0x80) { // indefinite length
// "[A sender shall] use the indefinite form (see 8.1.3.6) if the encoding is constructed and is not all // "[A sender shall] use the indefinite form (see 8.1.3.6) if the encoding is constructed and is not all
// immediately available." -- paragraph 8.1.3.2.c // immediately available." -- paragraph 8.1.3.2.c
$length = strlen($encoded); $length = strlen($encoded) - $encoded_pos;
} elseif ($length & 0x80) { // definite length, long form } elseif ($length & 0x80) { // definite length, long form
// technically, the long form of the length can be represented by up to 126 octets (bytes), but we'll only // technically, the long form of the length can be represented by up to 126 octets (bytes), but we'll only
// support it up to four. // support it up to four.
$length&= 0x7F; $length&= 0x7F;
$temp = $this->_string_shift($encoded, $length); $temp = substr($encoded, $encoded_pos, $length);
$encoded_pos += $length;
// tags of indefinte length don't really have a header length; this length includes the tag // tags of indefinte length don't really have a header length; this length includes the tag
$current+= array('headerlength' => $length + 2); $current+= array('headerlength' => $length + 2);
$start+= $length; $start+= $length;
@ -329,7 +354,12 @@ class File_ASN1
$current+= array('headerlength' => 2); $current+= array('headerlength' => 2);
} }
$content = $this->_string_shift($encoded, $length); if ($length > (strlen($encoded) - $encoded_pos)) {
return false;
}
$content = substr($encoded, $encoded_pos, $length);
$content_pos = 0;
// at this point $length can be overwritten. it's only accurate for definite length things as is // at this point $length can be overwritten. it's only accurate for definite length things as is
@ -357,14 +387,24 @@ class File_ASN1
} }
$newcontent = array(); $newcontent = array();
if (strlen($content)) { $remainingLength = $length;
$newcontent = $this->_decode_ber($content, $start); while ($remainingLength > 0) {
$length = $newcontent['length']; $temp = $this->_decode_ber($content, $start, $content_pos);
if (substr($content, $length, 2) == "\0\0") { if ($temp === false) {
break;
}
$length = $temp['length'];
// end-of-content octets - see paragraph 8.1.5
if (substr($content, $content_pos + $length, 2) == "\0\0") {
$length+= 2; $length+= 2;
$start+= $length;
$newcontent[] = $temp;
break;
} }
$start+= $length; $start+= $length;
$newcontent = array($newcontent); $remainingLength-= $length;
$newcontent[] = $temp;
$content_pos += $length;
} }
return array( return array(
@ -388,11 +428,11 @@ class File_ASN1
//if (strlen($content) != 1) { //if (strlen($content) != 1) {
// return false; // return false;
//} //}
$current['content'] = (bool) ord($content[0]); $current['content'] = (bool) ord($content[$content_pos]);
break; break;
case FILE_ASN1_TYPE_INTEGER: case FILE_ASN1_TYPE_INTEGER:
case FILE_ASN1_TYPE_ENUMERATED: case FILE_ASN1_TYPE_ENUMERATED:
$current['content'] = new Math_BigInteger($content, -256); $current['content'] = new Math_BigInteger(substr($content, $content_pos), -256);
break; break;
case FILE_ASN1_TYPE_REAL: // not currently supported case FILE_ASN1_TYPE_REAL: // not currently supported
return false; return false;
@ -401,10 +441,13 @@ class File_ASN1
// the number of unused bits in the final subsequent octet. The number shall be in the range zero to // the number of unused bits in the final subsequent octet. The number shall be in the range zero to
// seven. // seven.
if (!$constructed) { if (!$constructed) {
$current['content'] = $content; $current['content'] = substr($content, $content_pos);
} else { } else {
$temp = $this->_decode_ber($content, $start); $temp = $this->_decode_ber($content, $start, $content_pos);
$length-= strlen($content); if ($temp === false) {
return false;
}
$length-= (strlen($content) - $content_pos);
$last = count($temp) - 1; $last = count($temp) - 1;
for ($i = 0; $i < $last; $i++) { for ($i = 0; $i < $last; $i++) {
// all subtags should be bit strings // all subtags should be bit strings
@ -422,13 +465,16 @@ class File_ASN1
break; break;
case FILE_ASN1_TYPE_OCTET_STRING: case FILE_ASN1_TYPE_OCTET_STRING:
if (!$constructed) { if (!$constructed) {
$current['content'] = $content; $current['content'] = substr($content, $content_pos);
} else { } else {
$current['content'] = ''; $current['content'] = '';
$length = 0; $length = 0;
while (substr($content, 0, 2) != "\0\0") { while (substr($content, $content_pos, 2) != "\0\0") {
$temp = $this->_decode_ber($content, $length + $start); $temp = $this->_decode_ber($content, $length + $start, $content_pos);
$this->_string_shift($content, $temp['length']); if ($temp === false) {
return false;
}
$content_pos += $temp['length'];
// all subtags should be octet strings // all subtags should be octet strings
//if ($temp['type'] != FILE_ASN1_TYPE_OCTET_STRING) { //if ($temp['type'] != FILE_ASN1_TYPE_OCTET_STRING) {
// return false; // return false;
@ -436,7 +482,7 @@ class File_ASN1
$current['content'].= $temp['content']; $current['content'].= $temp['content'];
$length+= $temp['length']; $length+= $temp['length'];
} }
if (substr($content, 0, 2) == "\0\0") { if (substr($content, $content_pos, 2) == "\0\0") {
$length+= 2; // +2 for the EOC $length+= 2; // +2 for the EOC
} }
} }
@ -451,26 +497,31 @@ class File_ASN1
case FILE_ASN1_TYPE_SET: case FILE_ASN1_TYPE_SET:
$offset = 0; $offset = 0;
$current['content'] = array(); $current['content'] = array();
while (strlen($content)) { $content_len = strlen($content);
while ($content_pos < $content_len) {
// if indefinite length construction was used and we have an end-of-content string next // if indefinite length construction was used and we have an end-of-content string next
// see paragraphs 8.1.1.3, 8.1.3.2, 8.1.3.6, 8.1.5, and (for an example) 8.6.4.2 // see paragraphs 8.1.1.3, 8.1.3.2, 8.1.3.6, 8.1.5, and (for an example) 8.6.4.2
if (!isset($current['headerlength']) && substr($content, 0, 2) == "\0\0") { if (!isset($current['headerlength']) && substr($content, $content_pos, 2) == "\0\0") {
$length = $offset + 2; // +2 for the EOC $length = $offset + 2; // +2 for the EOC
break 2; break 2;
} }
$temp = $this->_decode_ber($content, $start + $offset); $temp = $this->_decode_ber($content, $start + $offset, $content_pos);
$this->_string_shift($content, $temp['length']); if ($temp === false) {
return false;
}
$content_pos += $temp['length'];
$current['content'][] = $temp; $current['content'][] = $temp;
$offset+= $temp['length']; $offset+= $temp['length'];
} }
break; break;
case FILE_ASN1_TYPE_OBJECT_IDENTIFIER: case FILE_ASN1_TYPE_OBJECT_IDENTIFIER:
$temp = ord($this->_string_shift($content)); $temp = ord($content[$content_pos++]);
$current['content'] = sprintf('%d.%d', floor($temp / 40), $temp % 40); $current['content'] = sprintf('%d.%d', floor($temp / 40), $temp % 40);
$valuen = 0; $valuen = 0;
// process septets // process septets
while (strlen($content)) { $content_len = strlen($content);
$temp = ord($this->_string_shift($content)); while ($content_pos < $content_len) {
$temp = ord($content[$content_pos++]);
$valuen <<= 7; $valuen <<= 7;
$valuen |= $temp & 0x7F; $valuen |= $temp & 0x7F;
if (~$temp & 0x80) { if (~$temp & 0x80) {
@ -511,11 +562,13 @@ class File_ASN1
case FILE_ASN1_TYPE_UTF8_STRING: case FILE_ASN1_TYPE_UTF8_STRING:
// ???? // ????
case FILE_ASN1_TYPE_BMP_STRING: case FILE_ASN1_TYPE_BMP_STRING:
$current['content'] = $content; $current['content'] = substr($content, $content_pos);
break; break;
case FILE_ASN1_TYPE_UTC_TIME: case FILE_ASN1_TYPE_UTC_TIME:
case FILE_ASN1_TYPE_GENERALIZED_TIME: case FILE_ASN1_TYPE_GENERALIZED_TIME:
$current['content'] = $this->_decodeTime($content, $tag); $current['content'] = class_exists('DateTime') ?
$this->_decodeDateTime(substr($content, $content_pos), $tag) :
$this->_decodeUnixTime(substr($content, $content_pos), $tag);
default: default:
} }
@ -532,10 +585,10 @@ class File_ASN1
* *
* "Special" mappings may be applied on a per tag-name basis via $special. * "Special" mappings may be applied on a per tag-name basis via $special.
* *
* @param Array $decoded * @param array $decoded
* @param Array $mapping * @param array $mapping
* @param Array $special * @param array $special
* @return Array * @return array
* @access public * @access public
*/ */
function asn1map($decoded, $mapping, $special = array()) function asn1map($decoded, $mapping, $special = array())
@ -547,7 +600,7 @@ class File_ASN1
switch (true) { switch (true) {
case $mapping['type'] == FILE_ASN1_TYPE_ANY: case $mapping['type'] == FILE_ASN1_TYPE_ANY:
$intype = $decoded['type']; $intype = $decoded['type'];
if (isset($decoded['constant']) || !isset($this->ANYmap[$intype]) || ($this->encoded[$decoded['start']] & 0x20)) { if (isset($decoded['constant']) || !isset($this->ANYmap[$intype]) || (ord($this->encoded[$decoded['start']]) & 0x20)) {
return new File_ASN1_Element(substr($this->encoded, $decoded['start'], $decoded['length'])); return new File_ASN1_Element(substr($this->encoded, $decoded['start'], $decoded['length']));
} }
$inmap = $this->ANYmap[$intype]; $inmap = $this->ANYmap[$intype];
@ -625,7 +678,7 @@ class File_ASN1
$childClass = $tempClass = FILE_ASN1_CLASS_UNIVERSAL; $childClass = $tempClass = FILE_ASN1_CLASS_UNIVERSAL;
$constant = null; $constant = null;
if (isset($temp['constant'])) { if (isset($temp['constant'])) {
$tempClass = isset($temp['class']) ? $temp['class'] : FILE_ASN1_CLASS_CONTEXT_SPECIFIC; $tempClass = $temp['type'];
} }
if (isset($child['class'])) { if (isset($child['class'])) {
$childClass = $child['class']; $childClass = $child['class'];
@ -688,7 +741,7 @@ class File_ASN1
$temp = $decoded['content'][$i]; $temp = $decoded['content'][$i];
$tempClass = FILE_ASN1_CLASS_UNIVERSAL; $tempClass = FILE_ASN1_CLASS_UNIVERSAL;
if (isset($temp['constant'])) { if (isset($temp['constant'])) {
$tempClass = isset($temp['class']) ? $temp['class'] : FILE_ASN1_CLASS_CONTEXT_SPECIFIC; $tempClass = $temp['type'];
} }
foreach ($mapping['children'] as $key => $child) { foreach ($mapping['children'] as $key => $child) {
@ -749,10 +802,20 @@ class File_ASN1
return isset($this->oids[$decoded['content']]) ? $this->oids[$decoded['content']] : $decoded['content']; return isset($this->oids[$decoded['content']]) ? $this->oids[$decoded['content']] : $decoded['content'];
case FILE_ASN1_TYPE_UTC_TIME: case FILE_ASN1_TYPE_UTC_TIME:
case FILE_ASN1_TYPE_GENERALIZED_TIME: case FILE_ASN1_TYPE_GENERALIZED_TIME:
if (class_exists('DateTime')) {
if (isset($mapping['implicit'])) { if (isset($mapping['implicit'])) {
$decoded['content'] = $this->_decodeTime($decoded['content'], $decoded['type']); $decoded['content'] = $this->_decodeDateTime($decoded['content'], $decoded['type']);
}
if (!$decoded['content']) {
return false;
}
return $decoded['content']->format($this->format);
} else {
if (isset($mapping['implicit'])) {
$decoded['content'] = $this->_decodeUnixTime($decoded['content'], $decoded['type']);
} }
return @date($this->format, $decoded['content']); return @date($this->format, $decoded['content']);
}
case FILE_ASN1_TYPE_BIT_STRING: case FILE_ASN1_TYPE_BIT_STRING:
if (isset($mapping['mapping'])) { if (isset($mapping['mapping'])) {
$offset = ord($decoded['content'][0]); $offset = ord($decoded['content'][0]);
@ -824,10 +887,10 @@ class File_ASN1
* *
* "Special" mappings can be applied via $special. * "Special" mappings can be applied via $special.
* *
* @param String $source * @param string $source
* @param String $mapping * @param string $mapping
* @param Integer $idx * @param int $idx
* @return String * @return string
* @access public * @access public
*/ */
function encodeDER($source, $mapping, $special = array()) function encodeDER($source, $mapping, $special = array())
@ -839,10 +902,10 @@ class File_ASN1
/** /**
* ASN.1 Encode (Helper function) * ASN.1 Encode (Helper function)
* *
* @param String $source * @param string $source
* @param String $mapping * @param string $mapping
* @param Integer $idx * @param int $idx
* @return String * @return string
* @access private * @access private
*/ */
function _encode_der($source, $mapping, $idx = null, $special = array()) function _encode_der($source, $mapping, $idx = null, $special = array())
@ -869,10 +932,10 @@ class File_ASN1
case FILE_ASN1_TYPE_SET: // Children order is not important, thus process in sequence. case FILE_ASN1_TYPE_SET: // Children order is not important, thus process in sequence.
case FILE_ASN1_TYPE_SEQUENCE: case FILE_ASN1_TYPE_SEQUENCE:
$tag|= 0x20; // set the constructed bit $tag|= 0x20; // set the constructed bit
$value = '';
// ignore the min and max // ignore the min and max
if (isset($mapping['min']) && isset($mapping['max'])) { if (isset($mapping['min']) && isset($mapping['max'])) {
$value = array();
$child = $mapping['children']; $child = $mapping['children'];
foreach ($source as $content) { foreach ($source as $content) {
@ -880,13 +943,23 @@ class File_ASN1
if ($temp === false) { if ($temp === false) {
return false; return false;
} }
$value.= $temp; $value[]= $temp;
} }
/* "The encodings of the component values of a set-of value shall appear in ascending order, the encodings being compared
as octet strings with the shorter components being padded at their trailing end with 0-octets.
NOTE - The padding octets are for comparison purposes only and do not appear in the encodings."
-- sec 11.6 of http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf */
if ($mapping['type'] == FILE_ASN1_TYPE_SET) {
sort($value);
}
$value = implode($value, '');
break; break;
} }
$value = '';
foreach ($mapping['children'] as $key => $child) { foreach ($mapping['children'] as $key => $child) {
if (!isset($source[$key])) { if (!array_key_exists($key, $source)) {
if (!isset($child['optional'])) { if (!isset($child['optional'])) {
return false; return false;
} }
@ -991,7 +1064,12 @@ class File_ASN1
case FILE_ASN1_TYPE_GENERALIZED_TIME: case FILE_ASN1_TYPE_GENERALIZED_TIME:
$format = $mapping['type'] == FILE_ASN1_TYPE_UTC_TIME ? 'y' : 'Y'; $format = $mapping['type'] == FILE_ASN1_TYPE_UTC_TIME ? 'y' : 'Y';
$format.= 'mdHis'; $format.= 'mdHis';
if (!class_exists('DateTime')) {
$value = @gmdate($format, strtotime($source)) . 'Z'; $value = @gmdate($format, strtotime($source)) . 'Z';
} else {
$date = new DateTime($source, new DateTimeZone('GMT'));
$value = $date->format($format) . 'Z';
}
break; break;
case FILE_ASN1_TYPE_BIT_STRING: case FILE_ASN1_TYPE_BIT_STRING:
if (isset($mapping['mapping'])) { if (isset($mapping['mapping'])) {
@ -1139,8 +1217,8 @@ class File_ASN1
* {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information. * {@link http://itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#p=13 X.690 paragraph 8.1.3} for more information.
* *
* @access private * @access private
* @param Integer $length * @param int $length
* @return String * @return string
*/ */
function _encodeLength($length) function _encodeLength($length)
{ {
@ -1153,16 +1231,16 @@ class File_ASN1
} }
/** /**
* BER-decode the time * BER-decode the time (using UNIX time)
* *
* Called by _decode_ber() and in the case of implicit tags asn1map(). * Called by _decode_ber() and in the case of implicit tags asn1map().
* *
* @access private * @access private
* @param String $content * @param string $content
* @param Integer $tag * @param int $tag
* @return String * @return string
*/ */
function _decodeTime($content, $tag) function _decodeUnixTime($content, $tag)
{ {
/* UTCTime: /* UTCTime:
http://tools.ietf.org/html/rfc5280#section-4.1.2.5.1 http://tools.ietf.org/html/rfc5280#section-4.1.2.5.1
@ -1173,7 +1251,7 @@ class File_ASN1
http://www.obj-sys.com/asn1tutorial/node14.html */ http://www.obj-sys.com/asn1tutorial/node14.html */
$pattern = $tag == FILE_ASN1_TYPE_UTC_TIME ? $pattern = $tag == FILE_ASN1_TYPE_UTC_TIME ?
'#(..)(..)(..)(..)(..)(..)(.*)#' : '#^(..)(..)(..)(..)(..)(..)?(.*)$#' :
'#(....)(..)(..)(..)(..)(..).*([Z+-].*)$#'; '#(....)(..)(..)(..)(..)(..).*([Z+-].*)$#';
preg_match($pattern, $content, $matches); preg_match($pattern, $content, $matches);
@ -1198,7 +1276,56 @@ class File_ASN1
$timezone = 0; $timezone = 0;
} }
return @$mktime($hour, $minute, $second, $month, $day, $year) + $timezone; return @$mktime((int)$hour, (int)$minute, (int)$second, (int)$month, (int)$day, (int)$year) + $timezone;
}
/**
* BER-decode the time (using DateTime)
*
* Called by _decode_ber() and in the case of implicit tags asn1map().
*
* @access private
* @param string $content
* @param int $tag
* @return string
*/
function _decodeDateTime($content, $tag)
{
/* UTCTime:
http://tools.ietf.org/html/rfc5280#section-4.1.2.5.1
http://www.obj-sys.com/asn1tutorial/node15.html
GeneralizedTime:
http://tools.ietf.org/html/rfc5280#section-4.1.2.5.2
http://www.obj-sys.com/asn1tutorial/node14.html */
$format = 'YmdHis';
if ($tag == FILE_ASN1_TYPE_UTC_TIME) {
// https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#page=28 says "the seconds
// element shall always be present" but none-the-less I've seen X509 certs where it isn't and if the
// browsers parse it phpseclib ought to too
if (preg_match('#^(\d{10})(Z|[+-]\d{4})$#', $content, $matches)) {
$content = $matches[1] . '00' . $matches[2];
}
$prefix = substr($content, 0, 2) >= 50 ? '19' : '20';
$content = $prefix . $content;
} elseif (strpos($content, '.') !== false) {
$format.= '.u';
}
if ($content[strlen($content) - 1] == 'Z') {
$content = substr($content, 0, -1) . '+0000';
}
if (strpos($content, '-') !== false || strpos($content, '+') !== false) {
$format.= 'O';
}
// error supression isn't necessary as of PHP 7.0:
// http://php.net/manual/en/migration70.other-changes.php
return @DateTime::createFromFormat($format, $content);
} }
/** /**
@ -1207,7 +1334,7 @@ class File_ASN1
* Sets the time / date format for asn1map(). * Sets the time / date format for asn1map().
* *
* @access public * @access public
* @param String $format * @param string $format
*/ */
function setTimeFormat($format) function setTimeFormat($format)
{ {
@ -1220,7 +1347,7 @@ class File_ASN1
* Load the relevant OIDs for a particular ASN.1 semantic mapping. * Load the relevant OIDs for a particular ASN.1 semantic mapping.
* *
* @access public * @access public
* @param Array $oids * @param array $oids
*/ */
function loadOIDs($oids) function loadOIDs($oids)
{ {
@ -1233,7 +1360,7 @@ class File_ASN1
* See File_X509, etc, for an example. * See File_X509, etc, for an example.
* *
* @access public * @access public
* @param Array $filters * @param array $filters
*/ */
function loadFilters($filters) function loadFilters($filters)
{ {
@ -1245,9 +1372,9 @@ class File_ASN1
* *
* Inspired by array_shift * Inspired by array_shift
* *
* @param String $string * @param string $string
* @param optional Integer $index * @param int $index
* @return String * @return string
* @access private * @access private
*/ */
function _string_shift(&$string, $index = 1) function _string_shift(&$string, $index = 1)
@ -1263,10 +1390,10 @@ class File_ASN1
* This is a lazy conversion, dealing only with character size. * This is a lazy conversion, dealing only with character size.
* No real conversion table is used. * No real conversion table is used.
* *
* @param String $in * @param string $in
* @param optional Integer $from * @param int $from
* @param optional Integer $to * @param int $to
* @return String * @return string
* @access public * @access public
*/ */
function convert($in, $from = FILE_ASN1_TYPE_UTF8_STRING, $to = FILE_ASN1_TYPE_UTF8_STRING) function convert($in, $from = FILE_ASN1_TYPE_UTF8_STRING, $to = FILE_ASN1_TYPE_UTF8_STRING)

1131
rainloop/v/0.0.0/app/libraries/phpseclib/File/X509.php Normal file → Executable file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

60
rainloop/v/0.0.0/app/libraries/phpseclib/Net/SCP.php Normal file → Executable file
View file

@ -17,7 +17,7 @@
* if (!$ssh->login('username', 'password')) { * if (!$ssh->login('username', 'password')) {
* exit('bad login'); * exit('bad login');
* } * }
*
* $scp = new Net_SCP($ssh); * $scp = new Net_SCP($ssh);
* $scp->put('abcd', str_repeat('x', 1024*1024)); * $scp->put('abcd', str_repeat('x', 1024*1024));
* ?> * ?>
@ -51,7 +51,7 @@
/**#@+ /**#@+
* @access public * @access public
* @see Net_SCP::put() * @see self::put()
*/ */
/** /**
* Reads data from a local file. * Reads data from a local file.
@ -65,8 +65,8 @@ define('NET_SCP_STRING', 2);
/**#@+ /**#@+
* @access private * @access private
* @see Net_SCP::_send() * @see self::_send()
* @see Net_SCP::_receive() * @see self::_receive()
*/ */
/** /**
* SSH1 is being used. * SSH1 is being used.
@ -90,7 +90,7 @@ class Net_SCP
/** /**
* SSH Object * SSH Object
* *
* @var Object * @var object
* @access private * @access private
*/ */
var $ssh; var $ssh;
@ -98,7 +98,7 @@ class Net_SCP
/** /**
* Packet Size * Packet Size
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $packet_size; var $packet_size;
@ -106,7 +106,7 @@ class Net_SCP
/** /**
* Mode * Mode
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $mode; var $mode;
@ -116,13 +116,11 @@ class Net_SCP
* *
* Connects to an SSH server * Connects to an SSH server
* *
* @param String $host * @param Net_SSH1|Net_SSH2 $ssh
* @param optional Integer $port
* @param optional Integer $timeout
* @return Net_SCP * @return Net_SCP
* @access public * @access public
*/ */
function Net_SCP($ssh) function __construct($ssh)
{ {
if (!is_object($ssh)) { if (!is_object($ssh)) {
return; return;
@ -143,6 +141,18 @@ class Net_SCP
$this->ssh = $ssh; $this->ssh = $ssh;
} }
/**
* PHP4 compatible Default Constructor.
*
* @see self::__construct()
* @param Net_SSH1|Net_SSH2 $ssh
* @access public
*/
function Net_SCP($ssh)
{
$this->__construct($ssh);
}
/** /**
* Uploads a file to the SCP server. * Uploads a file to the SCP server.
* *
@ -157,11 +167,11 @@ class Net_SCP
* Currently, only binary mode is supported. As such, if the line endings need to be adjusted, you will need to take * Currently, only binary mode is supported. As such, if the line endings need to be adjusted, you will need to take
* care of that, yourself. * care of that, yourself.
* *
* @param String $remote_file * @param string $remote_file
* @param String $data * @param string $data
* @param optional Integer $mode * @param int $mode
* @param optional Callable $callback * @param callable $callback
* @return Boolean * @return bool
* @access public * @access public
*/ */
function put($remote_file, $data, $mode = NET_SCP_STRING, $callback = null) function put($remote_file, $data, $mode = NET_SCP_STRING, $callback = null)
@ -170,6 +180,11 @@ class Net_SCP
return false; return false;
} }
if (empty($remote_file)) {
user_error('remote_file cannot be blank', E_USER_NOTICE);
return false;
}
if (!$this->ssh->exec('scp -t ' . escapeshellarg($remote_file), false)) { // -t = to if (!$this->ssh->exec('scp -t ' . escapeshellarg($remote_file), false)) { // -t = to
return false; return false;
} }
@ -233,9 +248,9 @@ class Net_SCP
* the operation was unsuccessful. If $local_file is defined, returns true or false depending on the success of the * the operation was unsuccessful. If $local_file is defined, returns true or false depending on the success of the
* operation * operation
* *
* @param String $remote_file * @param string $remote_file
* @param optional String $local_file * @param string $local_file
* @return Mixed * @return mixed
* @access public * @access public
*/ */
function get($remote_file, $local_file = false) function get($remote_file, $local_file = false)
@ -291,7 +306,7 @@ class Net_SCP
/** /**
* Sends a packet to an SSH server * Sends a packet to an SSH server
* *
* @param String $data * @param string $data
* @access private * @access private
*/ */
function _send($data) function _send($data)
@ -309,7 +324,7 @@ class Net_SCP
/** /**
* Receives a packet from an SSH server * Receives a packet from an SSH server
* *
* @return String * @return string
* @access private * @access private
*/ */
function _receive() function _receive()
@ -325,6 +340,9 @@ class Net_SCP
$response = $this->ssh->_get_binary_packet(); $response = $this->ssh->_get_binary_packet();
switch ($response[NET_SSH1_RESPONSE_TYPE]) { switch ($response[NET_SSH1_RESPONSE_TYPE]) {
case NET_SSH1_SMSG_STDOUT_DATA: case NET_SSH1_SMSG_STDOUT_DATA:
if (strlen($response[NET_SSH1_RESPONSE_DATA]) < 4) {
return false;
}
extract(unpack('Nlength', $response[NET_SSH1_RESPONSE_DATA])); extract(unpack('Nlength', $response[NET_SSH1_RESPONSE_DATA]));
return $this->ssh->_string_shift($response[NET_SSH1_RESPONSE_DATA], $length); return $this->ssh->_string_shift($response[NET_SSH1_RESPONSE_DATA], $length);
case NET_SSH1_SMSG_STDERR_DATA: case NET_SSH1_SMSG_STDERR_DATA:

937
rainloop/v/0.0.0/app/libraries/phpseclib/Net/SFTP.php Normal file → Executable file

File diff suppressed because it is too large Load diff

View file

@ -47,14 +47,14 @@ class Net_SFTP_Stream
* *
* Rather than re-create the connection we re-use instances if possible * Rather than re-create the connection we re-use instances if possible
* *
* @var Array * @var array
*/ */
static $instances; static $instances;
/** /**
* SFTP instance * SFTP instance
* *
* @var Object * @var object
* @access private * @access private
*/ */
var $sftp; var $sftp;
@ -62,7 +62,7 @@ class Net_SFTP_Stream
/** /**
* Path * Path
* *
* @var String * @var string
* @access private * @access private
*/ */
var $path; var $path;
@ -70,7 +70,7 @@ class Net_SFTP_Stream
/** /**
* Mode * Mode
* *
* @var String * @var string
* @access private * @access private
*/ */
var $mode; var $mode;
@ -78,7 +78,7 @@ class Net_SFTP_Stream
/** /**
* Position * Position
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $pos; var $pos;
@ -86,7 +86,7 @@ class Net_SFTP_Stream
/** /**
* Size * Size
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $size; var $size;
@ -94,7 +94,7 @@ class Net_SFTP_Stream
/** /**
* Directory entries * Directory entries
* *
* @var Array * @var array
* @access private * @access private
*/ */
var $entries; var $entries;
@ -102,7 +102,7 @@ class Net_SFTP_Stream
/** /**
* EOF flag * EOF flag
* *
* @var Boolean * @var bool
* @access private * @access private
*/ */
var $eof; var $eof;
@ -112,7 +112,7 @@ class Net_SFTP_Stream
* *
* Technically this needs to be publically accessible so PHP can set it directly * Technically this needs to be publically accessible so PHP can set it directly
* *
* @var Resource * @var resource
* @access public * @access public
*/ */
var $context; var $context;
@ -120,7 +120,7 @@ class Net_SFTP_Stream
/** /**
* Notification callback function * Notification callback function
* *
* @var Callable * @var callable
* @access public * @access public
*/ */
var $notification; var $notification;
@ -128,8 +128,8 @@ class Net_SFTP_Stream
/** /**
* Registers this class as a URL wrapper. * Registers this class as a URL wrapper.
* *
* @param optional String $protocol The wrapper name to be registered. * @param string $protocol The wrapper name to be registered.
* @return Boolean True on success, false otherwise. * @return bool True on success, false otherwise.
* @access public * @access public
*/ */
static function register($protocol = 'sftp') static function register($protocol = 'sftp')
@ -146,7 +146,7 @@ class Net_SFTP_Stream
* *
* @access public * @access public
*/ */
function Net_SFTP_Stream() function __construct()
{ {
if (defined('NET_SFTP_STREAM_LOGGING')) { if (defined('NET_SFTP_STREAM_LOGGING')) {
echo "__construct()\r\n"; echo "__construct()\r\n";
@ -165,13 +165,24 @@ class Net_SFTP_Stream
* If "notification" is set as a context parameter the message code for successful login is * If "notification" is set as a context parameter the message code for successful login is
* NET_SSH2_MSG_USERAUTH_SUCCESS. For a failed login it's NET_SSH2_MSG_USERAUTH_FAILURE. * NET_SSH2_MSG_USERAUTH_SUCCESS. For a failed login it's NET_SSH2_MSG_USERAUTH_FAILURE.
* *
* @param String $path * @param string $path
* @return String * @return string
* @access private * @access private
*/ */
function _parse_path($path) function _parse_path($path)
{ {
$orig = $path;
extract(parse_url($path) + array('port' => 22)); extract(parse_url($path) + array('port' => 22));
if (isset($query)) {
$path.= '?' . $query;
} elseif (preg_match('/(\?|\?#)$/', $orig)) {
$path.= '?';
}
if (isset($fragment)) {
$path.= '#' . $fragment;
} elseif ($orig[strlen($orig) - 1] == '#') {
$path.= '#';
}
if (!isset($host)) { if (!isset($host)) {
return false; return false;
@ -186,7 +197,7 @@ class Net_SFTP_Stream
if ($host[0] == '$') { if ($host[0] == '$') {
$host = substr($host, 1); $host = substr($host, 1);
global $$host; global ${$host};
if (!is_object($$host) || get_class($$host) != 'Net_SFTP') { if (!is_object($$host) || get_class($$host) != 'Net_SFTP') {
return false; return false;
} }
@ -257,11 +268,11 @@ class Net_SFTP_Stream
/** /**
* Opens file or URL * Opens file or URL
* *
* @param String $path * @param string $path
* @param String $mode * @param string $mode
* @param Integer $options * @param int $options
* @param String $opened_path * @param string $opened_path
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _stream_open($path, $mode, $options, &$opened_path) function _stream_open($path, $mode, $options, &$opened_path)
@ -280,14 +291,17 @@ class Net_SFTP_Stream
if ($this->size === false) { if ($this->size === false) {
if ($this->mode[0] == 'r') { if ($this->mode[0] == 'r') {
return false; return false;
} else {
$this->sftp->touch($path);
$this->size = 0;
} }
} else { } else {
switch ($this->mode[0]) { switch ($this->mode[0]) {
case 'x': case 'x':
return false; return false;
case 'w': case 'w':
case 'c':
$this->sftp->truncate($path, 0); $this->sftp->truncate($path, 0);
$this->size = 0;
} }
} }
@ -299,8 +313,8 @@ class Net_SFTP_Stream
/** /**
* Read from stream * Read from stream
* *
* @param Integer $count * @param int $count
* @return Mixed * @return mixed
* @access public * @access public
*/ */
function _stream_read($count) function _stream_read($count)
@ -341,8 +355,8 @@ class Net_SFTP_Stream
/** /**
* Write to stream * Write to stream
* *
* @param String $data * @param string $data
* @return Mixed * @return mixed
* @access public * @access public
*/ */
function _stream_write($data) function _stream_write($data)
@ -376,7 +390,7 @@ class Net_SFTP_Stream
/** /**
* Retrieve the current position of a stream * Retrieve the current position of a stream
* *
* @return Integer * @return int
* @access public * @access public
*/ */
function _stream_tell() function _stream_tell()
@ -394,7 +408,7 @@ class Net_SFTP_Stream
* will return false. do fread($fp, 1) and feof() will then return true. do fseek($fp, 10) on ablank file and feof() * will return false. do fread($fp, 1) and feof() will then return true. do fseek($fp, 10) on ablank file and feof()
* will return false. do fread($fp, 1) and feof() will then return true. * will return false. do fread($fp, 1) and feof() will then return true.
* *
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _stream_eof() function _stream_eof()
@ -405,9 +419,9 @@ class Net_SFTP_Stream
/** /**
* Seeks to specific location in a stream * Seeks to specific location in a stream
* *
* @param Integer $offset * @param int $offset
* @param Integer $whence * @param int $whence
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _stream_seek($offset, $whence) function _stream_seek($offset, $whence)
@ -433,10 +447,10 @@ class Net_SFTP_Stream
/** /**
* Change stream options * Change stream options
* *
* @param String $path * @param string $path
* @param Integer $option * @param int $option
* @param Mixed $var * @param mixed $var
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _stream_metadata($path, $option, $var) function _stream_metadata($path, $option, $var)
@ -467,8 +481,8 @@ class Net_SFTP_Stream
/** /**
* Retrieve the underlaying resource * Retrieve the underlaying resource
* *
* @param Integer $cast_as * @param int $cast_as
* @return Resource * @return resource
* @access public * @access public
*/ */
function _stream_cast($cast_as) function _stream_cast($cast_as)
@ -479,8 +493,8 @@ class Net_SFTP_Stream
/** /**
* Advisory file locking * Advisory file locking
* *
* @param Integer $operation * @param int $operation
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _stream_lock($operation) function _stream_lock($operation)
@ -495,9 +509,9 @@ class Net_SFTP_Stream
* If newname exists, it will be overwritten. This is a departure from what Net_SFTP * If newname exists, it will be overwritten. This is a departure from what Net_SFTP
* does. * does.
* *
* @param String $path_from * @param string $path_from
* @param String $path_to * @param string $path_to
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _rename($path_from, $path_to) function _rename($path_from, $path_to)
@ -511,7 +525,7 @@ class Net_SFTP_Stream
$path_from = $this->_parse_path($path_from); $path_from = $this->_parse_path($path_from);
$path_to = parse_url($path_to); $path_to = parse_url($path_to);
if ($path_from == false) { if ($path_from === false) {
return false; return false;
} }
@ -547,9 +561,9 @@ class Net_SFTP_Stream
* string longname * string longname
* ATTRS attrs * ATTRS attrs
* *
* @param String $path * @param string $path
* @param Integer $options * @param int $options
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _dir_opendir($path, $options) function _dir_opendir($path, $options)
@ -566,7 +580,7 @@ class Net_SFTP_Stream
/** /**
* Read entry from directory handle * Read entry from directory handle
* *
* @return Mixed * @return mixed
* @access public * @access public
*/ */
function _dir_readdir() function _dir_readdir()
@ -580,7 +594,7 @@ class Net_SFTP_Stream
/** /**
* Rewind directory handle * Rewind directory handle
* *
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _dir_rewinddir() function _dir_rewinddir()
@ -592,7 +606,7 @@ class Net_SFTP_Stream
/** /**
* Close directory handle * Close directory handle
* *
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _dir_closedir() function _dir_closedir()
@ -605,10 +619,10 @@ class Net_SFTP_Stream
* *
* Only valid $options is STREAM_MKDIR_RECURSIVE * Only valid $options is STREAM_MKDIR_RECURSIVE
* *
* @param String $path * @param string $path
* @param Integer $mode * @param int $mode
* @param Integer $options * @param int $options
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _mkdir($path, $mode, $options) function _mkdir($path, $mode, $options)
@ -629,10 +643,10 @@ class Net_SFTP_Stream
* STREAM_MKDIR_RECURSIVE is supposed to be set. Also, when I try it out with rmdir() I get 8 as * STREAM_MKDIR_RECURSIVE is supposed to be set. Also, when I try it out with rmdir() I get 8 as
* $options. What does 8 correspond to? * $options. What does 8 correspond to?
* *
* @param String $path * @param string $path
* @param Integer $mode * @param int $mode
* @param Integer $options * @param int $options
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _rmdir($path, $options) function _rmdir($path, $options)
@ -650,7 +664,7 @@ class Net_SFTP_Stream
* *
* See <http://php.net/fflush>. Always returns true because Net_SFTP doesn't cache stuff before writing * See <http://php.net/fflush>. Always returns true because Net_SFTP doesn't cache stuff before writing
* *
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _stream_flush() function _stream_flush()
@ -661,7 +675,7 @@ class Net_SFTP_Stream
/** /**
* Retrieve information about a file resource * Retrieve information about a file resource
* *
* @return Mixed * @return mixed
* @access public * @access public
*/ */
function _stream_stat() function _stream_stat()
@ -676,8 +690,8 @@ class Net_SFTP_Stream
/** /**
* Delete a file * Delete a file
* *
* @param String $path * @param string $path
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _unlink($path) function _unlink($path)
@ -697,9 +711,9 @@ class Net_SFTP_Stream
* might be worthwhile to reconstruct bits 12-16 (ie. the file type) if mode doesn't have them but we'll * might be worthwhile to reconstruct bits 12-16 (ie. the file type) if mode doesn't have them but we'll
* cross that bridge when and if it's reached * cross that bridge when and if it's reached
* *
* @param String $path * @param string $path
* @param Integer $flags * @param int $flags
* @return Mixed * @return mixed
* @access public * @access public
*/ */
function _url_stat($path, $flags) function _url_stat($path, $flags)
@ -720,8 +734,8 @@ class Net_SFTP_Stream
/** /**
* Truncate stream * Truncate stream
* *
* @param Integer $new_size * @param int $new_size
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _stream_truncate($new_size) function _stream_truncate($new_size)
@ -742,10 +756,10 @@ class Net_SFTP_Stream
* STREAM_OPTION_WRITE_BUFFER isn't supported for the same reason stream_flush isn't. * STREAM_OPTION_WRITE_BUFFER isn't supported for the same reason stream_flush isn't.
* The other two aren't supported because of limitations in Net_SFTP. * The other two aren't supported because of limitations in Net_SFTP.
* *
* @param Integer $option * @param int $option
* @param Integer $arg1 * @param int $arg1
* @param Integer $arg2 * @param int $arg2
* @return Boolean * @return bool
* @access public * @access public
*/ */
function _stream_set_option($option, $arg1, $arg2) function _stream_set_option($option, $arg1, $arg2)
@ -772,9 +786,9 @@ class Net_SFTP_Stream
* If NET_SFTP_STREAM_LOGGING is defined all calls will be output on the screen and then (regardless of whether or not * If NET_SFTP_STREAM_LOGGING is defined all calls will be output on the screen and then (regardless of whether or not
* NET_SFTP_STREAM_LOGGING is enabled) the parameters will be passed through to the appropriate method. * NET_SFTP_STREAM_LOGGING is enabled) the parameters will be passed through to the appropriate method.
* *
* @param String * @param string
* @param Array * @param array
* @return Mixed * @return mixed
* @access public * @access public
*/ */
function __call($name, $arguments) function __call($name, $arguments)

282
rainloop/v/0.0.0/app/libraries/phpseclib/Net/SSH1.php Normal file → Executable file
View file

@ -67,7 +67,7 @@
/**#@+ /**#@+
* Encryption Methods * Encryption Methods
* *
* @see Net_SSH1::getSupportedCiphers() * @see self::getSupportedCiphers()
* @access public * @access public
*/ */
/** /**
@ -127,7 +127,7 @@ define('NET_SSH1_CIPHER_BLOWFISH', 6);
/**#@+ /**#@+
* Authentication Methods * Authentication Methods
* *
* @see Net_SSH1::getSupportedAuthentications() * @see self::getSupportedAuthentications()
* @access public * @access public
*/ */
/** /**
@ -162,7 +162,7 @@ define('NET_SSH1_TTY_OP_END', 0);
/** /**
* The Response Type * The Response Type
* *
* @see Net_SSH1::_get_binary_packet() * @see self::_get_binary_packet()
* @access private * @access private
*/ */
define('NET_SSH1_RESPONSE_TYPE', 1); define('NET_SSH1_RESPONSE_TYPE', 1);
@ -170,7 +170,7 @@ define('NET_SSH1_RESPONSE_TYPE', 1);
/** /**
* The Response Data * The Response Data
* *
* @see Net_SSH1::_get_binary_packet() * @see self::_get_binary_packet()
* @access private * @access private
*/ */
define('NET_SSH1_RESPONSE_DATA', 2); define('NET_SSH1_RESPONSE_DATA', 2);
@ -178,7 +178,7 @@ define('NET_SSH1_RESPONSE_DATA', 2);
/**#@+ /**#@+
* Execution Bitmap Masks * Execution Bitmap Masks
* *
* @see Net_SSH1::bitmap * @see self::bitmap
* @access private * @access private
*/ */
define('NET_SSH1_MASK_CONSTRUCTOR', 0x00000001); define('NET_SSH1_MASK_CONSTRUCTOR', 0x00000001);
@ -189,7 +189,7 @@ define('NET_SSH1_MASK_SHELL', 0x00000008);
/**#@+ /**#@+
* @access public * @access public
* @see Net_SSH1::getLog() * @see self::getLog()
*/ */
/** /**
* Returns the message numbers * Returns the message numbers
@ -211,7 +211,7 @@ define('NET_SSH1_LOG_REALTIME_FILE', 4);
/**#@+ /**#@+
* @access public * @access public
* @see Net_SSH1::read() * @see self::read()
*/ */
/** /**
* Returns when a string matching $expect exactly is found * Returns when a string matching $expect exactly is found
@ -235,7 +235,7 @@ class Net_SSH1
/** /**
* The SSH identifier * The SSH identifier
* *
* @var String * @var string
* @access private * @access private
*/ */
var $identifier = 'SSH-1.5-phpseclib'; var $identifier = 'SSH-1.5-phpseclib';
@ -243,7 +243,7 @@ class Net_SSH1
/** /**
* The Socket Object * The Socket Object
* *
* @var Object * @var object
* @access private * @access private
*/ */
var $fsock; var $fsock;
@ -251,7 +251,7 @@ class Net_SSH1
/** /**
* The cryptography object * The cryptography object
* *
* @var Object * @var object
* @access private * @access private
*/ */
var $crypto = false; var $crypto = false;
@ -262,7 +262,7 @@ class Net_SSH1
* The bits that are set represent functions that have been called already. This is used to determine * The bits that are set represent functions that have been called already. This is used to determine
* if a requisite function has been successfully executed. If not, an error should be thrown. * if a requisite function has been successfully executed. If not, an error should be thrown.
* *
* @var Integer * @var int
* @access private * @access private
*/ */
var $bitmap = 0; var $bitmap = 0;
@ -272,8 +272,8 @@ class Net_SSH1
* *
* Logged for debug purposes * Logged for debug purposes
* *
* @see Net_SSH1::getServerKeyPublicExponent() * @see self::getServerKeyPublicExponent()
* @var String * @var string
* @access private * @access private
*/ */
var $server_key_public_exponent; var $server_key_public_exponent;
@ -283,8 +283,8 @@ class Net_SSH1
* *
* Logged for debug purposes * Logged for debug purposes
* *
* @see Net_SSH1::getServerKeyPublicModulus() * @see self::getServerKeyPublicModulus()
* @var String * @var string
* @access private * @access private
*/ */
var $server_key_public_modulus; var $server_key_public_modulus;
@ -294,8 +294,8 @@ class Net_SSH1
* *
* Logged for debug purposes * Logged for debug purposes
* *
* @see Net_SSH1::getHostKeyPublicExponent() * @see self::getHostKeyPublicExponent()
* @var String * @var string
* @access private * @access private
*/ */
var $host_key_public_exponent; var $host_key_public_exponent;
@ -305,8 +305,8 @@ class Net_SSH1
* *
* Logged for debug purposes * Logged for debug purposes
* *
* @see Net_SSH1::getHostKeyPublicModulus() * @see self::getHostKeyPublicModulus()
* @var String * @var string
* @access private * @access private
*/ */
var $host_key_public_modulus; var $host_key_public_modulus;
@ -316,8 +316,8 @@ class Net_SSH1
* *
* Logged for debug purposes * Logged for debug purposes
* *
* @see Net_SSH1::getSupportedCiphers() * @see self::getSupportedCiphers()
* @var Array * @var array
* @access private * @access private
*/ */
var $supported_ciphers = array( var $supported_ciphers = array(
@ -335,8 +335,8 @@ class Net_SSH1
* *
* Logged for debug purposes * Logged for debug purposes
* *
* @see Net_SSH1::getSupportedAuthentications() * @see self::getSupportedAuthentications()
* @var Array * @var array
* @access private * @access private
*/ */
var $supported_authentications = array( var $supported_authentications = array(
@ -349,8 +349,8 @@ class Net_SSH1
/** /**
* Server Identification * Server Identification
* *
* @see Net_SSH1::getServerIdentification() * @see self::getServerIdentification()
* @var String * @var string
* @access private * @access private
*/ */
var $server_identification = ''; var $server_identification = '';
@ -358,8 +358,8 @@ class Net_SSH1
/** /**
* Protocol Flags * Protocol Flags
* *
* @see Net_SSH1::Net_SSH1() * @see self::Net_SSH1()
* @var Array * @var array
* @access private * @access private
*/ */
var $protocol_flags = array(); var $protocol_flags = array();
@ -367,8 +367,8 @@ class Net_SSH1
/** /**
* Protocol Flag Log * Protocol Flag Log
* *
* @see Net_SSH1::getLog() * @see self::getLog()
* @var Array * @var array
* @access private * @access private
*/ */
var $protocol_flag_log = array(); var $protocol_flag_log = array();
@ -376,8 +376,8 @@ class Net_SSH1
/** /**
* Message Log * Message Log
* *
* @see Net_SSH1::getLog() * @see self::getLog()
* @var Array * @var array
* @access private * @access private
*/ */
var $message_log = array(); var $message_log = array();
@ -385,8 +385,8 @@ class Net_SSH1
/** /**
* Real-time log file pointer * Real-time log file pointer
* *
* @see Net_SSH1::_append_log() * @see self::_append_log()
* @var Resource * @var resource
* @access private * @access private
*/ */
var $realtime_log_file; var $realtime_log_file;
@ -394,8 +394,8 @@ class Net_SSH1
/** /**
* Real-time log file size * Real-time log file size
* *
* @see Net_SSH1::_append_log() * @see self::_append_log()
* @var Integer * @var int
* @access private * @access private
*/ */
var $realtime_log_size; var $realtime_log_size;
@ -403,8 +403,8 @@ class Net_SSH1
/** /**
* Real-time log file wrap boolean * Real-time log file wrap boolean
* *
* @see Net_SSH1::_append_log() * @see self::_append_log()
* @var Boolean * @var bool
* @access private * @access private
*/ */
var $realtime_log_wrap; var $realtime_log_wrap;
@ -412,8 +412,8 @@ class Net_SSH1
/** /**
* Interactive Buffer * Interactive Buffer
* *
* @see Net_SSH1::read() * @see self::read()
* @var Array * @var array
* @access private * @access private
*/ */
var $interactiveBuffer = ''; var $interactiveBuffer = '';
@ -421,7 +421,7 @@ class Net_SSH1
/** /**
* Timeout * Timeout
* *
* @see Net_SSH1::setTimeout() * @see self::setTimeout()
* @access private * @access private
*/ */
var $timeout; var $timeout;
@ -429,7 +429,7 @@ class Net_SSH1
/** /**
* Current Timeout * Current Timeout
* *
* @see Net_SSH1::_get_channel_packet() * @see self::_get_channel_packet()
* @access private * @access private
*/ */
var $curTimeout; var $curTimeout;
@ -437,7 +437,7 @@ class Net_SSH1
/** /**
* Log Boundary * Log Boundary
* *
* @see Net_SSH1::_format_log * @see self::_format_log()
* @access private * @access private
*/ */
var $log_boundary = ':'; var $log_boundary = ':';
@ -445,7 +445,7 @@ class Net_SSH1
/** /**
* Log Long Width * Log Long Width
* *
* @see Net_SSH1::_format_log * @see self::_format_log()
* @access private * @access private
*/ */
var $log_long_width = 65; var $log_long_width = 65;
@ -453,7 +453,7 @@ class Net_SSH1
/** /**
* Log Short Width * Log Short Width
* *
* @see Net_SSH1::_format_log * @see self::_format_log()
* @access private * @access private
*/ */
var $log_short_width = 16; var $log_short_width = 16;
@ -461,9 +461,9 @@ class Net_SSH1
/** /**
* Hostname * Hostname
* *
* @see Net_SSH1::Net_SSH1() * @see self::Net_SSH1()
* @see Net_SSH1::_connect() * @see self::_connect()
* @var String * @var string
* @access private * @access private
*/ */
var $host; var $host;
@ -471,9 +471,9 @@ class Net_SSH1
/** /**
* Port Number * Port Number
* *
* @see Net_SSH1::Net_SSH1() * @see self::Net_SSH1()
* @see Net_SSH1::_connect() * @see self::_connect()
* @var Integer * @var int
* @access private * @access private
*/ */
var $port; var $port;
@ -486,9 +486,9 @@ class Net_SSH1
* however, is non-optional. There will be a timeout, whether or not you set it. If you don't it'll be * however, is non-optional. There will be a timeout, whether or not you set it. If you don't it'll be
* 10 seconds. It is used by fsockopen() in that function. * 10 seconds. It is used by fsockopen() in that function.
* *
* @see Net_SSH1::Net_SSH1() * @see self::Net_SSH1()
* @see Net_SSH1::_connect() * @see self::_connect()
* @var Integer * @var int
* @access private * @access private
*/ */
var $connectionTimeout; var $connectionTimeout;
@ -496,9 +496,9 @@ class Net_SSH1
/** /**
* Default cipher * Default cipher
* *
* @see Net_SSH1::Net_SSH1() * @see self::Net_SSH1()
* @see Net_SSH1::_connect() * @see self::_connect()
* @var Integer * @var int
* @access private * @access private
*/ */
var $cipher; var $cipher;
@ -508,14 +508,14 @@ class Net_SSH1
* *
* Connects to an SSHv1 server * Connects to an SSHv1 server
* *
* @param String $host * @param string $host
* @param optional Integer $port * @param int $port
* @param optional Integer $timeout * @param int $timeout
* @param optional Integer $cipher * @param int $cipher
* @return Net_SSH1 * @return Net_SSH1
* @access public * @access public
*/ */
function Net_SSH1($host, $port = 22, $timeout = 10, $cipher = NET_SSH1_CIPHER_3DES) function __construct($host, $port = 22, $timeout = 10, $cipher = NET_SSH1_CIPHER_3DES)
{ {
if (!class_exists('Math_BigInteger')) { if (!class_exists('Math_BigInteger')) {
include_once 'Math/BigInteger.php'; include_once 'Math/BigInteger.php';
@ -557,10 +557,25 @@ class Net_SSH1
$this->cipher = $cipher; $this->cipher = $cipher;
} }
/**
* PHP4 compatible Default Constructor.
*
* @see self::__construct()
* @param string $host
* @param int $port
* @param int $timeout
* @param int $cipher
* @access public
*/
function Net_SSH1($host, $port = 22, $timeout = 10, $cipher = NET_SSH1_CIPHER_3DES)
{
$this->__construct($host, $port, $timeout, $cipher);
}
/** /**
* Connect to an SSHv1 server * Connect to an SSHv1 server
* *
* @return Boolean * @return bool
* @access private * @access private
*/ */
function _connect() function _connect()
@ -599,20 +614,32 @@ class Net_SSH1
$this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4); $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4);
if (strlen($response[NET_SSH1_RESPONSE_DATA]) < 2) {
return false;
}
$temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2)); $temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2));
$server_key_public_exponent = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); $server_key_public_exponent = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256);
$this->server_key_public_exponent = $server_key_public_exponent; $this->server_key_public_exponent = $server_key_public_exponent;
if (strlen($response[NET_SSH1_RESPONSE_DATA]) < 2) {
return false;
}
$temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2)); $temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2));
$server_key_public_modulus = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); $server_key_public_modulus = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256);
$this->server_key_public_modulus = $server_key_public_modulus; $this->server_key_public_modulus = $server_key_public_modulus;
$this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4); $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4);
if (strlen($response[NET_SSH1_RESPONSE_DATA]) < 2) {
return false;
}
$temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2)); $temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2));
$host_key_public_exponent = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); $host_key_public_exponent = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256);
$this->host_key_public_exponent = $host_key_public_exponent; $this->host_key_public_exponent = $host_key_public_exponent;
if (strlen($response[NET_SSH1_RESPONSE_DATA]) < 2) {
return false;
}
$temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2)); $temp = unpack('nlen', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 2));
$host_key_public_modulus = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256); $host_key_public_modulus = new Math_BigInteger($this->_string_shift($response[NET_SSH1_RESPONSE_DATA], ceil($temp['len'] / 8)), 256);
$this->host_key_public_modulus = $host_key_public_modulus; $this->host_key_public_modulus = $host_key_public_modulus;
@ -620,6 +647,9 @@ class Net_SSH1
$this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4); $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4);
// get a list of the supported ciphers // get a list of the supported ciphers
if (strlen($response[NET_SSH1_RESPONSE_DATA]) < 4) {
return false;
}
extract(unpack('Nsupported_ciphers_mask', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4))); extract(unpack('Nsupported_ciphers_mask', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4)));
foreach ($this->supported_ciphers as $mask => $name) { foreach ($this->supported_ciphers as $mask => $name) {
if (($supported_ciphers_mask & (1 << $mask)) == 0) { if (($supported_ciphers_mask & (1 << $mask)) == 0) {
@ -628,6 +658,9 @@ class Net_SSH1
} }
// get a list of the supported authentications // get a list of the supported authentications
if (strlen($response[NET_SSH1_RESPONSE_DATA]) < 4) {
return false;
}
extract(unpack('Nsupported_authentications_mask', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4))); extract(unpack('Nsupported_authentications_mask', $this->_string_shift($response[NET_SSH1_RESPONSE_DATA], 4)));
foreach ($this->supported_authentications as $mask => $name) { foreach ($this->supported_authentications as $mask => $name) {
if (($supported_authentications_mask & (1 << $mask)) == 0) { if (($supported_authentications_mask & (1 << $mask)) == 0) {
@ -727,9 +760,9 @@ class Net_SSH1
/** /**
* Login * Login
* *
* @param String $username * @param string $username
* @param optional String $password * @param string $password
* @return Boolean * @return bool
* @access public * @access public
*/ */
function login($username, $password = '') function login($username, $password = '')
@ -800,7 +833,7 @@ class Net_SSH1
* $ssh->exec('ping 127.0.0.1'); on a Linux host will never return and will run indefinitely. setTimeout() makes it so it'll timeout. * $ssh->exec('ping 127.0.0.1'); on a Linux host will never return and will run indefinitely. setTimeout() makes it so it'll timeout.
* Setting $timeout to false or 0 will mean there is no timeout. * Setting $timeout to false or 0 will mean there is no timeout.
* *
* @param Mixed $timeout * @param mixed $timeout
*/ */
function setTimeout($timeout) function setTimeout($timeout)
{ {
@ -821,9 +854,9 @@ class Net_SSH1
* *
* Returns false on failure and the output, otherwise. * Returns false on failure and the output, otherwise.
* *
* @see Net_SSH1::interactiveRead() * @see self::interactiveRead()
* @see Net_SSH1::interactiveWrite() * @see self::interactiveWrite()
* @param String $cmd * @param string $cmd
* @return mixed * @return mixed
* @access public * @access public
*/ */
@ -871,9 +904,9 @@ class Net_SSH1
/** /**
* Creates an interactive shell * Creates an interactive shell
* *
* @see Net_SSH1::interactiveRead() * @see self::interactiveRead()
* @see Net_SSH1::interactiveWrite() * @see self::interactiveWrite()
* @return Boolean * @return bool
* @access private * @access private
*/ */
function _initShell() function _initShell()
@ -915,9 +948,9 @@ class Net_SSH1
/** /**
* Inputs a command into an interactive shell. * Inputs a command into an interactive shell.
* *
* @see Net_SSH1::interactiveWrite() * @see self::interactiveWrite()
* @param String $cmd * @param string $cmd
* @return Boolean * @return bool
* @access public * @access public
*/ */
function write($cmd) function write($cmd)
@ -931,10 +964,10 @@ class Net_SSH1
* $expect can take the form of a string literal or, if $mode == NET_SSH1_READ_REGEX, * $expect can take the form of a string literal or, if $mode == NET_SSH1_READ_REGEX,
* a regular expression. * a regular expression.
* *
* @see Net_SSH1::write() * @see self::write()
* @param String $expect * @param string $expect
* @param Integer $mode * @param int $mode
* @return Boolean * @return bool
* @access public * @access public
*/ */
function read($expect, $mode = NET_SSH1_READ_SIMPLE) function read($expect, $mode = NET_SSH1_READ_SIMPLE)
@ -971,9 +1004,9 @@ class Net_SSH1
/** /**
* Inputs a command into an interactive shell. * Inputs a command into an interactive shell.
* *
* @see Net_SSH1::interactiveRead() * @see self::interactiveRead()
* @param String $cmd * @param string $cmd
* @return Boolean * @return bool
* @access public * @access public
*/ */
function interactiveWrite($cmd) function interactiveWrite($cmd)
@ -1007,8 +1040,8 @@ class Net_SSH1
* does not support ANSI escape sequences in Win32 Console applications", so if you're a Windows user, * does not support ANSI escape sequences in Win32 Console applications", so if you're a Windows user,
* there's not going to be much recourse. * there's not going to be much recourse.
* *
* @see Net_SSH1::interactiveRead() * @see self::interactiveRead()
* @return String * @return string
* @access public * @access public
*/ */
function interactiveRead() function interactiveRead()
@ -1059,7 +1092,7 @@ class Net_SSH1
/** /**
* Disconnect * Disconnect
* *
* @param String $msg * @param string $msg
* @access private * @access private
*/ */
function _disconnect($msg = 'Client Quit') function _disconnect($msg = 'Client Quit')
@ -1096,8 +1129,8 @@ class Net_SSH1
* Also, this function could be improved upon by adding detection for the following exploit: * Also, this function could be improved upon by adding detection for the following exploit:
* http://www.securiteam.com/securitynews/5LP042K3FY.html * http://www.securiteam.com/securitynews/5LP042K3FY.html
* *
* @see Net_SSH1::_send_binary_packet() * @see self::_send_binary_packet()
* @return Array * @return array
* @access private * @access private
*/ */
function _get_binary_packet() function _get_binary_packet()
@ -1124,7 +1157,11 @@ class Net_SSH1
} }
$start = strtok(microtime(), ' ') + strtok(''); // http://php.net/microtime#61838 $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); $padding_length = 8 - ($temp['length'] & 7);
$length = $temp['length'] + $padding_length; $length = $temp['length'] + $padding_length;
@ -1145,6 +1182,9 @@ class Net_SSH1
$type = $raw[$padding_length]; $type = $raw[$padding_length];
$data = substr($raw, $padding_length + 1, -4); $data = substr($raw, $padding_length + 1, -4);
if (strlen($raw) < 4) {
return false;
}
$temp = unpack('Ncrc', substr($raw, -4)); $temp = unpack('Ncrc', substr($raw, -4));
//if ( $temp['crc'] != $this->_crc($padding . $type . $data) ) { //if ( $temp['crc'] != $this->_crc($padding . $type . $data) ) {
@ -1172,9 +1212,9 @@ class Net_SSH1
* *
* Returns true on success, false on failure. * Returns true on success, false on failure.
* *
* @see Net_SSH1::_get_binary_packet() * @see self::_get_binary_packet()
* @param String $data * @param string $data
* @return Boolean * @return bool
* @access private * @access private
*/ */
function _send_binary_packet($data) function _send_binary_packet($data)
@ -1219,10 +1259,10 @@ class Net_SSH1
* we've reimplemented it. A more detailed discussion of the differences can be found after * we've reimplemented it. A more detailed discussion of the differences can be found after
* $crc_lookup_table's initialization. * $crc_lookup_table's initialization.
* *
* @see Net_SSH1::_get_binary_packet() * @see self::_get_binary_packet()
* @see Net_SSH1::_send_binary_packet() * @see self::_send_binary_packet()
* @param String $data * @param string $data
* @return Integer * @return int
* @access private * @access private
*/ */
function _crc($data) function _crc($data)
@ -1317,9 +1357,9 @@ class Net_SSH1
* *
* Inspired by array_shift * Inspired by array_shift
* *
* @param String $string * @param string $string
* @param optional Integer $index * @param int $index
* @return String * @return string
* @access private * @access private
*/ */
function _string_shift(&$string, $index = 1) function _string_shift(&$string, $index = 1)
@ -1336,9 +1376,9 @@ class Net_SSH1
* should be a number with the property that gcd($e, ($p - 1) * ($q - 1)) == 1. Could just make anything that * should be a number with the property that gcd($e, ($p - 1) * ($q - 1)) == 1. Could just make anything that
* calls this call modexp, instead, but I think this makes things clearer, maybe... * calls this call modexp, instead, but I think this makes things clearer, maybe...
* *
* @see Net_SSH1::Net_SSH1() * @see self::Net_SSH1()
* @param Math_BigInteger $m * @param Math_BigInteger $m
* @param Array $key * @param array $key
* @return Math_BigInteger * @return Math_BigInteger
* @access private * @access private
*/ */
@ -1391,7 +1431,7 @@ class Net_SSH1
* named constants from it, using the value as the name of the constant and the index as the value of the constant. * named constants from it, using the value as the name of the constant and the index as the value of the constant.
* If any of the constants that would be defined already exists, none of the constants will be defined. * If any of the constants that would be defined already exists, none of the constants will be defined.
* *
* @param Array $array * @param array $array
* @access private * @access private
*/ */
function _define_array() function _define_array()
@ -1414,7 +1454,7 @@ class Net_SSH1
* Returns a string if NET_SSH1_LOGGING == NET_SSH1_LOG_COMPLEX, an array if NET_SSH1_LOGGING == NET_SSH1_LOG_SIMPLE and false if !defined('NET_SSH1_LOGGING') * Returns a string if NET_SSH1_LOGGING == NET_SSH1_LOG_COMPLEX, an array if NET_SSH1_LOGGING == NET_SSH1_LOG_SIMPLE and false if !defined('NET_SSH1_LOGGING')
* *
* @access public * @access public
* @return String or Array * @return array|false|string
*/ */
function getLog() function getLog()
{ {
@ -1437,10 +1477,10 @@ class Net_SSH1
/** /**
* Formats a log for printing * Formats a log for printing
* *
* @param Array $message_log * @param array $message_log
* @param Array $message_number_log * @param array $message_number_log
* @access private * @access private
* @return String * @return string
*/ */
function _format_log($message_log, $message_number_log) function _format_log($message_log, $message_number_log)
{ {
@ -1473,9 +1513,9 @@ class Net_SSH1
* *
* For use with preg_replace_callback() * For use with preg_replace_callback()
* *
* @param Array $matches * @param array $matches
* @access private * @access private
* @return String * @return string
*/ */
function _format_log_helper($matches) function _format_log_helper($matches)
{ {
@ -1488,8 +1528,8 @@ class Net_SSH1
* Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead, * Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead,
* the raw bytes. This behavior is similar to PHP's md5() function. * the raw bytes. This behavior is similar to PHP's md5() function.
* *
* @param optional Boolean $raw_output * @param bool $raw_output
* @return String * @return string
* @access public * @access public
*/ */
function getServerKeyPublicExponent($raw_output = false) function getServerKeyPublicExponent($raw_output = false)
@ -1503,8 +1543,8 @@ class Net_SSH1
* Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead, * Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead,
* the raw bytes. This behavior is similar to PHP's md5() function. * the raw bytes. This behavior is similar to PHP's md5() function.
* *
* @param optional Boolean $raw_output * @param bool $raw_output
* @return String * @return string
* @access public * @access public
*/ */
function getServerKeyPublicModulus($raw_output = false) function getServerKeyPublicModulus($raw_output = false)
@ -1518,8 +1558,8 @@ class Net_SSH1
* Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead, * Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead,
* the raw bytes. This behavior is similar to PHP's md5() function. * the raw bytes. This behavior is similar to PHP's md5() function.
* *
* @param optional Boolean $raw_output * @param bool $raw_output
* @return String * @return string
* @access public * @access public
*/ */
function getHostKeyPublicExponent($raw_output = false) function getHostKeyPublicExponent($raw_output = false)
@ -1533,8 +1573,8 @@ class Net_SSH1
* Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead, * Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead,
* the raw bytes. This behavior is similar to PHP's md5() function. * the raw bytes. This behavior is similar to PHP's md5() function.
* *
* @param optional Boolean $raw_output * @param bool $raw_output
* @return String * @return string
* @access public * @access public
*/ */
function getHostKeyPublicModulus($raw_output = false) function getHostKeyPublicModulus($raw_output = false)
@ -1549,8 +1589,8 @@ class Net_SSH1
* is set to true, returns, instead, an array of constants. ie. instead of array('Triple-DES in CBC mode'), you'll * is set to true, returns, instead, an array of constants. ie. instead of array('Triple-DES in CBC mode'), you'll
* get array(NET_SSH1_CIPHER_3DES). * get array(NET_SSH1_CIPHER_3DES).
* *
* @param optional Boolean $raw_output * @param bool $raw_output
* @return Array * @return array
* @access public * @access public
*/ */
function getSupportedCiphers($raw_output = false) function getSupportedCiphers($raw_output = false)
@ -1565,8 +1605,8 @@ class Net_SSH1
* is set to true, returns, instead, an array of constants. ie. instead of array('password authentication'), you'll * is set to true, returns, instead, an array of constants. ie. instead of array('password authentication'), you'll
* get array(NET_SSH1_AUTH_PASSWORD). * get array(NET_SSH1_AUTH_PASSWORD).
* *
* @param optional Boolean $raw_output * @param bool $raw_output
* @return Array * @return array
* @access public * @access public
*/ */
function getSupportedAuthentications($raw_output = false) function getSupportedAuthentications($raw_output = false)
@ -1577,7 +1617,7 @@ class Net_SSH1
/** /**
* Return the server identification. * Return the server identification.
* *
* @return String * @return string
* @access public * @access public
*/ */
function getServerIdentification() function getServerIdentification()
@ -1590,7 +1630,7 @@ class Net_SSH1
* *
* Makes sure that only the last 1MB worth of packets will be logged * Makes sure that only the last 1MB worth of packets will be logged
* *
* @param String $data * @param string $data
* @access private * @access private
*/ */
function _append_log($protocol_flags, $message) function _append_log($protocol_flags, $message)

2157
rainloop/v/0.0.0/app/libraries/phpseclib/Net/SSH2.php Normal file → Executable file

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Pure-PHP ssh-agent client. * Pure-PHP ssh-agent client.
* *
@ -65,6 +66,30 @@ define('SYSTEM_SSH_AGENTC_SIGN_REQUEST', 13);
define('SYSTEM_SSH_AGENT_SIGN_RESPONSE', 14); define('SYSTEM_SSH_AGENT_SIGN_RESPONSE', 14);
/**#@-*/ /**#@-*/
/**@+
* Agent forwarding status
*
* @access private
*/
// no forwarding requested and not active
define('SYSTEM_SSH_AGENT_FORWARD_NONE', 0);
// request agent forwarding when opportune
define('SYSTEM_SSH_AGENT_FORWARD_REQUEST', 1);
// forwarding has been request and is active
define('SYSTEM_SSH_AGENT_FORWARD_ACTIVE', 2);
/**#@-*/
/**@+
* Signature Flags
*
* See https://tools.ietf.org/html/draft-miller-ssh-agent-00#section-5.3
*
* @access private
*/
define('SYSTEM_SSH_AGENT_RSA2_256', 2);
define('SYSTEM_SSH_AGENT_RSA2_512', 4);
/**#@-*/
/** /**
* Pure-PHP ssh-agent client identity object * Pure-PHP ssh-agent client identity object
* *
@ -86,40 +111,62 @@ class System_SSH_Agent_Identity
* *
* @var Crypt_RSA * @var Crypt_RSA
* @access private * @access private
* @see System_SSH_Agent_Identity::getPublicKey() * @see self::getPublicKey()
*/ */
var $key; var $key;
/** /**
* Key Blob * Key Blob
* *
* @var String * @var string
* @access private * @access private
* @see System_SSH_Agent_Identity::sign() * @see self::sign()
*/ */
var $key_blob; var $key_blob;
/** /**
* Socket Resource * Socket Resource
* *
* @var Resource * @var resource
* @access private * @access private
* @see System_SSH_Agent_Identity::sign() * @see self::sign()
*/ */
var $fsock; var $fsock;
/**
* Signature flags
*
* @var int
* @access private
* @see self::sign()
* @see self::setHash()
*/
var $flags = 0;
/** /**
* Default Constructor. * Default Constructor.
* *
* @param Resource $fsock * @param resource $fsock
* @return System_SSH_Agent_Identity * @return System_SSH_Agent_Identity
* @access private * @access private
*/ */
function System_SSH_Agent_Identity($fsock) function __construct($fsock)
{ {
$this->fsock = $fsock; $this->fsock = $fsock;
} }
/**
* PHP4 compatible Default Constructor.
*
* @see self::__construct()
* @param resource $fsock
* @access public
*/
function System_SSH_Agent_Identity($fsock)
{
$this->__construct($fsock);
}
/** /**
* Set Public Key * Set Public Key
* *
@ -140,7 +187,7 @@ class System_SSH_Agent_Identity
* Called by System_SSH_Agent::requestIdentities(). The key blob could be extracted from $this->key * Called by System_SSH_Agent::requestIdentities(). The key blob could be extracted from $this->key
* but this saves a small amount of computation. * but this saves a small amount of computation.
* *
* @param String $key_blob * @param string $key_blob
* @access private * @access private
*/ */
function setPublicKeyBlob($key_blob) function setPublicKeyBlob($key_blob)
@ -153,8 +200,8 @@ class System_SSH_Agent_Identity
* *
* Wrapper for $this->key->getPublicKey() * Wrapper for $this->key->getPublicKey()
* *
* @param Integer $format optional * @param int $format optional
* @return Mixed * @return mixed
* @access public * @access public
*/ */
function getPublicKey($format = null) function getPublicKey($format = null)
@ -168,26 +215,51 @@ class System_SSH_Agent_Identity
* Doesn't do anything as ssh-agent doesn't let you pick and choose the signature mode. ie. * Doesn't do anything as ssh-agent doesn't let you pick and choose the signature mode. ie.
* ssh-agent's only supported mode is CRYPT_RSA_SIGNATURE_PKCS1 * ssh-agent's only supported mode is CRYPT_RSA_SIGNATURE_PKCS1
* *
* @param Integer $mode * @param int $mode
* @access public * @access public
*/ */
function setSignatureMode($mode) function setSignatureMode($mode)
{ {
} }
/**
* Set Hash
*
* ssh-agent doesn't support using hashes for RSA other than SHA1
*
* @param string $hash
* @access public
*/
function setHash($hash)
{
$this->flags = 0;
switch ($hash) {
case 'sha1':
break;
case 'sha256':
$this->flags = SYSTEM_SSH_AGENT_RSA2_256;
break;
case 'sha512':
$this->flags = SYSTEM_SSH_AGENT_RSA2_512;
break;
default:
user_error('The only supported hashes for RSA are sha1, sha256 and sha512');
}
}
/** /**
* Create a signature * Create a signature
* *
* See "2.6.2 Protocol 2 private key signature request" * See "2.6.2 Protocol 2 private key signature request"
* *
* @param String $message * @param string $message
* @return String * @return string
* @access public * @access public
*/ */
function sign($message) function sign($message)
{ {
// the last parameter (currently 0) is for flags and ssh-agent only defines one flag (for ssh-dss): SSH_AGENT_OLD_SIGNATURE // the last parameter (currently 0) is for flags and ssh-agent only defines one flag (for ssh-dss): SSH_AGENT_OLD_SIGNATURE
$packet = pack('CNa*Na*N', SYSTEM_SSH_AGENTC_SIGN_REQUEST, strlen($this->key_blob), $this->key_blob, strlen($message), $message, 0); $packet = pack('CNa*Na*N', SYSTEM_SSH_AGENTC_SIGN_REQUEST, strlen($this->key_blob), $this->key_blob, strlen($message), $message, $this->flags);
$packet = pack('Na*', strlen($packet), $packet); $packet = pack('Na*', strlen($packet), $packet);
if (strlen($packet) != fputs($this->fsock, $packet)) { if (strlen($packet) != fputs($this->fsock, $packet)) {
user_error('Connection closed during signing'); user_error('Connection closed during signing');
@ -200,9 +272,35 @@ class System_SSH_Agent_Identity
} }
$signature_blob = fread($this->fsock, $length - 1); $signature_blob = fread($this->fsock, $length - 1);
// the only other signature format defined - ssh-dss - is the same length as ssh-rsa $length = current(unpack('N', $this->_string_shift($signature_blob, 4)));
// the + 12 is for the other various SSH added length fields if ($length != strlen($signature_blob)) {
return substr($signature_blob, strlen('ssh-rsa') + 12); user_error('Malformed signature blob');
}
$length = current(unpack('N', $this->_string_shift($signature_blob, 4)));
if ($length > strlen($signature_blob) + 4) {
user_error('Malformed signature blob');
}
$type = $this->_string_shift($signature_blob, $length);
$this->_string_shift($signature_blob, 4);
return $signature_blob;
}
/**
* String Shift
*
* Inspired by array_shift
*
* @param string $string
* @param int $index
* @return string
* @access private
*/
function _string_shift(&$string, $index = 1)
{
$substr = substr($string, 0, $index);
$string = substr($string, $index);
return $substr;
} }
} }
@ -213,26 +311,50 @@ class System_SSH_Agent_Identity
* *
* @package System_SSH_Agent * @package System_SSH_Agent
* @author Jim Wigginton <terrafrost@php.net> * @author Jim Wigginton <terrafrost@php.net>
* @access internal * @access public
*/ */
class System_SSH_Agent class System_SSH_Agent
{ {
/** /**
* Socket Resource * Socket Resource
* *
* @var Resource * @var resource
* @access private * @access private
*/ */
var $fsock; var $fsock;
/**
* Agent forwarding status
*
* @access private
*/
var $forward_status = SYSTEM_SSH_AGENT_FORWARD_NONE;
/**
* Buffer for accumulating forwarded authentication
* agent data arriving on SSH data channel destined
* for agent unix socket
*
* @access private
*/
var $socket_buffer = '';
/**
* Tracking the number of bytes we are expecting
* to arrive for the agent socket on the SSH data
* channel
*/
var $expected_bytes = 0;
/** /**
* Default Constructor * Default Constructor
* *
* @return System_SSH_Agent * @return System_SSH_Agent
* @access public * @access public
*/ */
function System_SSH_Agent() function __construct($address = null)
{ {
if (!$address) {
switch (true) { switch (true) {
case isset($_SERVER['SSH_AUTH_SOCK']): case isset($_SERVER['SSH_AUTH_SOCK']):
$address = $_SERVER['SSH_AUTH_SOCK']; $address = $_SERVER['SSH_AUTH_SOCK'];
@ -244,6 +366,7 @@ class System_SSH_Agent
user_error('SSH_AUTH_SOCK not found'); user_error('SSH_AUTH_SOCK not found');
return false; return false;
} }
}
$this->fsock = fsockopen('unix://' . $address, 0, $errno, $errstr); $this->fsock = fsockopen('unix://' . $address, 0, $errno, $errstr);
if (!$this->fsock) { if (!$this->fsock) {
@ -251,13 +374,24 @@ class System_SSH_Agent
} }
} }
/**
* PHP4 compatible Default Constructor.
*
* @see self::__construct()
* @access public
*/
function System_SSH_Agent($address = null)
{
$this->__construct($address);
}
/** /**
* Request Identities * Request Identities
* *
* See "2.5.2 Requesting a list of protocol 2 keys" * See "2.5.2 Requesting a list of protocol 2 keys"
* Returns an array containing zero or more System_SSH_Agent_Identity objects * Returns an array containing zero or more System_SSH_Agent_Identity objects
* *
* @return Array * @return array
* @access public * @access public
*/ */
function requestIdentities() function requestIdentities()
@ -269,12 +403,14 @@ class System_SSH_Agent
$packet = pack('NC', 1, SYSTEM_SSH_AGENTC_REQUEST_IDENTITIES); $packet = pack('NC', 1, SYSTEM_SSH_AGENTC_REQUEST_IDENTITIES);
if (strlen($packet) != fputs($this->fsock, $packet)) { if (strlen($packet) != fputs($this->fsock, $packet)) {
user_error('Connection closed while requesting identities'); user_error('Connection closed while requesting identities');
return array();
} }
$length = current(unpack('N', fread($this->fsock, 4))); $length = current(unpack('N', fread($this->fsock, 4)));
$type = ord(fread($this->fsock, 1)); $type = ord(fread($this->fsock, 1));
if ($type != SYSTEM_SSH_AGENT_IDENTITIES_ANSWER) { if ($type != SYSTEM_SSH_AGENT_IDENTITIES_ANSWER) {
user_error('Unable to request identities'); user_error('Unable to request identities');
return array();
} }
$identities = array(); $identities = array();
@ -282,8 +418,11 @@ class System_SSH_Agent
for ($i = 0; $i < $keyCount; $i++) { for ($i = 0; $i < $keyCount; $i++) {
$length = current(unpack('N', fread($this->fsock, 4))); $length = current(unpack('N', fread($this->fsock, 4)));
$key_blob = fread($this->fsock, $length); $key_blob = fread($this->fsock, $length);
$key_str = 'ssh-rsa ' . base64_encode($key_blob);
$length = current(unpack('N', fread($this->fsock, 4))); $length = current(unpack('N', fread($this->fsock, 4)));
$key_comment = fread($this->fsock, $length); if ($length) {
$key_str.= ' ' . fread($this->fsock, $length);
}
$length = current(unpack('N', substr($key_blob, 0, 4))); $length = current(unpack('N', substr($key_blob, 0, 4)));
$key_type = substr($key_blob, 4, $length); $key_type = substr($key_blob, 4, $length);
switch ($key_type) { switch ($key_type) {
@ -292,7 +431,7 @@ class System_SSH_Agent
include_once 'Crypt/RSA.php'; include_once 'Crypt/RSA.php';
} }
$key = new Crypt_RSA(); $key = new Crypt_RSA();
$key->loadKey('ssh-rsa ' . base64_encode($key_blob) . ' ' . $key_comment); $key->loadKey($key_str);
break; break;
case 'ssh-dss': case 'ssh-dss':
// not currently supported // not currently supported
@ -310,4 +449,113 @@ class System_SSH_Agent
return $identities; return $identities;
} }
/**
* Signal that agent forwarding should
* be requested when a channel is opened
*
* @param Net_SSH2 $ssh
* @return bool
* @access public
*/
function startSSHForwarding($ssh)
{
if ($this->forward_status == SYSTEM_SSH_AGENT_FORWARD_NONE) {
$this->forward_status = SYSTEM_SSH_AGENT_FORWARD_REQUEST;
}
}
/**
* Request agent forwarding of remote server
*
* @param Net_SSH2 $ssh
* @return bool
* @access private
*/
function _request_forwarding($ssh)
{
$request_channel = $ssh->_get_open_channel();
if ($request_channel === false) {
return false;
}
$packet = pack(
'CNNa*C',
NET_SSH2_MSG_CHANNEL_REQUEST,
$ssh->server_channels[$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)) {
return false;
}
$response = $ssh->_get_channel_packet($request_channel);
if ($response === false) {
return false;
}
$ssh->channel_status[$request_channel] = NET_SSH2_MSG_CHANNEL_OPEN;
$this->forward_status = SYSTEM_SSH_AGENT_FORWARD_ACTIVE;
return true;
}
/**
* On successful channel open
*
* This method is called upon successful channel
* open to give the SSH Agent an opportunity
* to take further action. i.e. request agent forwarding
*
* @param Net_SSH2 $ssh
* @access private
*/
function _on_channel_open($ssh)
{
if ($this->forward_status == SYSTEM_SSH_AGENT_FORWARD_REQUEST) {
$this->_request_forwarding($ssh);
}
}
/**
* Forward data to SSH Agent and return data reply
*
* @param string $data
* @return data from SSH Agent
* @access private
*/
function _forward_data($data)
{
if ($this->expected_bytes > 0) {
$this->socket_buffer.= $data;
$this->expected_bytes -= strlen($data);
} else {
$agent_data_bytes = current(unpack('N', $data));
$current_data_bytes = strlen($data);
$this->socket_buffer = $data;
if ($current_data_bytes != $agent_data_bytes + 4) {
$this->expected_bytes = ($agent_data_bytes + 4) - $current_data_bytes;
return false;
}
}
if (strlen($this->socket_buffer) != fwrite($this->fsock, $this->socket_buffer)) {
user_error('Connection closed attempting to forward data to SSH agent');
}
$this->socket_buffer = '';
$this->expected_bytes = 0;
$agent_reply_bytes = current(unpack('N', fread($this->fsock, 4)));
$agent_reply_data = fread($this->fsock, $agent_reply_bytes);
$agent_reply_data = current(unpack('a*', $agent_reply_data));
return pack('Na*', $agent_reply_bytes, $agent_reply_data);
}
} }

View file

View file

@ -0,0 +1,16 @@
<?php
/**
* Bootstrapping File for phpseclib
*
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
if (extension_loaded('mbstring')) {
// 2 - MB_OVERLOAD_STRING
if (ini_get('mbstring.func_overload') & 2) {
throw new \UnexpectedValueException(
'Overloading of string functions using mbstring.func_overload ' .
'is not supported by phpseclib.'
);
}
}

0
rainloop/v/0.0.0/app/libraries/phpseclib/openssl.cnf Normal file → Executable file
View file