mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-16 02:07:09 +00:00
Merge branch 'php5' of https://github.com/phpseclib/phpseclib into NetPackageConstantsFix
Conflicts: phpseclib/Net/SSH2.php
This commit is contained in:
commit
ecb9c32f02
@ -42,9 +42,8 @@ class Random
|
||||
*
|
||||
* @param Integer $length
|
||||
* @return String
|
||||
* @access public
|
||||
*/
|
||||
static function string($length)
|
||||
public static function string($length)
|
||||
{
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
// method 1. prior to PHP 5.3 this would call rand() on windows hence the function_exists('class_alias') call.
|
||||
|
@ -23,72 +23,6 @@
|
||||
|
||||
use \phpseclib\Math\BigInteger;
|
||||
|
||||
/**#@+
|
||||
* Tag Classes
|
||||
*
|
||||
* @access private
|
||||
* @link http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#page=12
|
||||
*/
|
||||
define('FILE_ASN1_CLASS_UNIVERSAL', 0);
|
||||
define('FILE_ASN1_CLASS_APPLICATION', 1);
|
||||
define('FILE_ASN1_CLASS_CONTEXT_SPECIFIC', 2);
|
||||
define('FILE_ASN1_CLASS_PRIVATE', 3);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Tag Classes
|
||||
*
|
||||
* @access private
|
||||
* @link http://www.obj-sys.com/asn1tutorial/node124.html
|
||||
*/
|
||||
define('FILE_ASN1_TYPE_BOOLEAN', 1);
|
||||
define('FILE_ASN1_TYPE_INTEGER', 2);
|
||||
define('FILE_ASN1_TYPE_BIT_STRING', 3);
|
||||
define('FILE_ASN1_TYPE_OCTET_STRING', 4);
|
||||
define('FILE_ASN1_TYPE_NULL', 5);
|
||||
define('FILE_ASN1_TYPE_OBJECT_IDENTIFIER', 6);
|
||||
//define('FILE_ASN1_TYPE_OBJECT_DESCRIPTOR', 7);
|
||||
//define('FILE_ASN1_TYPE_INSTANCE_OF', 8); // EXTERNAL
|
||||
define('FILE_ASN1_TYPE_REAL', 9);
|
||||
define('FILE_ASN1_TYPE_ENUMERATED', 10);
|
||||
//define('FILE_ASN1_TYPE_EMBEDDED', 11);
|
||||
define('FILE_ASN1_TYPE_UTF8_STRING', 12);
|
||||
//define('FILE_ASN1_TYPE_RELATIVE_OID', 13);
|
||||
define('FILE_ASN1_TYPE_SEQUENCE', 16); // SEQUENCE OF
|
||||
define('FILE_ASN1_TYPE_SET', 17); // SET OF
|
||||
/**#@-*/
|
||||
/**#@+
|
||||
* More Tag Classes
|
||||
*
|
||||
* @access private
|
||||
* @link http://www.obj-sys.com/asn1tutorial/node10.html
|
||||
*/
|
||||
define('FILE_ASN1_TYPE_NUMERIC_STRING', 18);
|
||||
define('FILE_ASN1_TYPE_PRINTABLE_STRING', 19);
|
||||
define('FILE_ASN1_TYPE_TELETEX_STRING', 20); // T61String
|
||||
define('FILE_ASN1_TYPE_VIDEOTEX_STRING', 21);
|
||||
define('FILE_ASN1_TYPE_IA5_STRING', 22);
|
||||
define('FILE_ASN1_TYPE_UTC_TIME', 23);
|
||||
define('FILE_ASN1_TYPE_GENERALIZED_TIME', 24);
|
||||
define('FILE_ASN1_TYPE_GRAPHIC_STRING', 25);
|
||||
define('FILE_ASN1_TYPE_VISIBLE_STRING', 26); // ISO646String
|
||||
define('FILE_ASN1_TYPE_GENERAL_STRING', 27);
|
||||
define('FILE_ASN1_TYPE_UNIVERSAL_STRING', 28);
|
||||
//define('FILE_ASN1_TYPE_CHARACTER_STRING', 29);
|
||||
define('FILE_ASN1_TYPE_BMP_STRING', 30);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Tag Aliases
|
||||
*
|
||||
* These tags are kinda place holders for other tags.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
define('FILE_ASN1_TYPE_CHOICE', -1);
|
||||
define('FILE_ASN1_TYPE_ANY', -2);
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Include File_ASN1_Element
|
||||
*/
|
||||
@ -105,6 +39,72 @@ if (!class_exists('File_ASN1_Element')) {
|
||||
*/
|
||||
class File_ASN1
|
||||
{
|
||||
/**#@+
|
||||
* Tag Classes
|
||||
*
|
||||
* @access private
|
||||
* @link http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#page=12
|
||||
*/
|
||||
const CLASS_UNIVERSAL = 0;
|
||||
const CLASS_APPLICATION = 1;
|
||||
const CLASS_CONTEXT_SPECIFIC = 2;
|
||||
const CLASS_PRIVATE = 3;
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Tag Classes
|
||||
*
|
||||
* @access private
|
||||
* @link http://www.obj-sys.com/asn1tutorial/node124.html
|
||||
*/
|
||||
const TYPE_BOOLEAN = 1;
|
||||
const TYPE_INTEGER = 2;
|
||||
const TYPE_BIT_STRING = 3;
|
||||
const TYPE_OCTET_STRING = 4;
|
||||
const TYPE_NULL = 5;
|
||||
const TYPE_OBJECT_IDENTIFIER = 6;
|
||||
//const TYPE_OBJECT_DESCRIPTOR = 7;
|
||||
//const TYPE_INSTANCE_OF = 8; // EXTERNAL
|
||||
const TYPE_REAL = 9;
|
||||
const TYPE_ENUMERATED = 10;
|
||||
//const TYPE_EMBEDDED = 11;
|
||||
const TYPE_UTF8_STRING = 12;
|
||||
//const TYPE_RELATIVE_OID = 13;
|
||||
const TYPE_SEQUENCE = 16; // SEQUENCE OF
|
||||
const TYPE_SET = 17; // SET OF
|
||||
/**#@-*/
|
||||
/**#@+
|
||||
* More Tag Classes
|
||||
*
|
||||
* @access private
|
||||
* @link http://www.obj-sys.com/asn1tutorial/node10.html
|
||||
*/
|
||||
const TYPE_NUMERIC_STRING = 18;
|
||||
const TYPE_PRINTABLE_STRING = 19;
|
||||
const TYPE_TELETEX_STRING = 20; // T61String
|
||||
const TYPE_VIDEOTEX_STRING = 21;
|
||||
const TYPE_IA5_STRING = 22;
|
||||
const TYPE_UTC_TIME = 23;
|
||||
const TYPE_GENERALIZED_TIME = 24;
|
||||
const TYPE_GRAPHIC_STRING = 25;
|
||||
const TYPE_VISIBLE_STRING = 26; // ISO646String
|
||||
const TYPE_GENERAL_STRING = 27;
|
||||
const TYPE_UNIVERSAL_STRING = 28;
|
||||
//const TYPE_CHARACTER_STRING = 29;
|
||||
const TYPE_BMP_STRING = 30;
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Tag Aliases
|
||||
*
|
||||
* These tags are kinda place holders for other tags.
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
const TYPE_CHOICE = -1;
|
||||
const TYPE_ANY = -2;
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* ASN.1 object identifier
|
||||
*
|
||||
@ -137,7 +137,7 @@ class File_ASN1
|
||||
/**
|
||||
* Filters
|
||||
*
|
||||
* If the mapping type is FILE_ASN1_TYPE_ANY what do we actually encode it as?
|
||||
* If the mapping type is self::TYPE_ANY what do we actually encode it as?
|
||||
*
|
||||
* @var Array
|
||||
* @access private
|
||||
@ -148,7 +148,7 @@ class File_ASN1
|
||||
/**
|
||||
* Type mapping table for the ANY type.
|
||||
*
|
||||
* Structured or unknown types are mapped to a FILE_ASN1_Element.
|
||||
* Structured or unknown types are mapped to a File_ASN1_Element.
|
||||
* Unambiguous types get the direct mapping (int/real/bool).
|
||||
* Others are mapped as a choice, with an extra indexing level.
|
||||
*
|
||||
@ -156,28 +156,28 @@ class File_ASN1
|
||||
* @access public
|
||||
*/
|
||||
var $ANYmap = array(
|
||||
FILE_ASN1_TYPE_BOOLEAN => true,
|
||||
FILE_ASN1_TYPE_INTEGER => true,
|
||||
FILE_ASN1_TYPE_BIT_STRING => 'bitString',
|
||||
FILE_ASN1_TYPE_OCTET_STRING => 'octetString',
|
||||
FILE_ASN1_TYPE_NULL => 'null',
|
||||
FILE_ASN1_TYPE_OBJECT_IDENTIFIER => 'objectIdentifier',
|
||||
FILE_ASN1_TYPE_REAL => true,
|
||||
FILE_ASN1_TYPE_ENUMERATED => 'enumerated',
|
||||
FILE_ASN1_TYPE_UTF8_STRING => 'utf8String',
|
||||
FILE_ASN1_TYPE_NUMERIC_STRING => 'numericString',
|
||||
FILE_ASN1_TYPE_PRINTABLE_STRING => 'printableString',
|
||||
FILE_ASN1_TYPE_TELETEX_STRING => 'teletexString',
|
||||
FILE_ASN1_TYPE_VIDEOTEX_STRING => 'videotexString',
|
||||
FILE_ASN1_TYPE_IA5_STRING => 'ia5String',
|
||||
FILE_ASN1_TYPE_UTC_TIME => 'utcTime',
|
||||
FILE_ASN1_TYPE_GENERALIZED_TIME => 'generalTime',
|
||||
FILE_ASN1_TYPE_GRAPHIC_STRING => 'graphicString',
|
||||
FILE_ASN1_TYPE_VISIBLE_STRING => 'visibleString',
|
||||
FILE_ASN1_TYPE_GENERAL_STRING => 'generalString',
|
||||
FILE_ASN1_TYPE_UNIVERSAL_STRING => 'universalString',
|
||||
//FILE_ASN1_TYPE_CHARACTER_STRING => 'characterString',
|
||||
FILE_ASN1_TYPE_BMP_STRING => 'bmpString'
|
||||
self::TYPE_BOOLEAN => true,
|
||||
self::TYPE_INTEGER => true,
|
||||
self::TYPE_BIT_STRING => 'bitString',
|
||||
self::TYPE_OCTET_STRING => 'octetString',
|
||||
self::TYPE_NULL => 'null',
|
||||
self::TYPE_OBJECT_IDENTIFIER => 'objectIdentifier',
|
||||
self::TYPE_REAL => true,
|
||||
self::TYPE_ENUMERATED => 'enumerated',
|
||||
self::TYPE_UTF8_STRING => 'utf8String',
|
||||
self::TYPE_NUMERIC_STRING => 'numericString',
|
||||
self::TYPE_PRINTABLE_STRING => 'printableString',
|
||||
self::TYPE_TELETEX_STRING => 'teletexString',
|
||||
self::TYPE_VIDEOTEX_STRING => 'videotexString',
|
||||
self::TYPE_IA5_STRING => 'ia5String',
|
||||
self::TYPE_UTC_TIME => 'utcTime',
|
||||
self::TYPE_GENERALIZED_TIME => 'generalTime',
|
||||
self::TYPE_GRAPHIC_STRING => 'graphicString',
|
||||
self::TYPE_VISIBLE_STRING => 'visibleString',
|
||||
self::TYPE_GENERAL_STRING => 'generalString',
|
||||
self::TYPE_UNIVERSAL_STRING => 'universalString',
|
||||
//self::TYPE_CHARACTER_STRING => 'characterString',
|
||||
self::TYPE_BMP_STRING => 'bmpString'
|
||||
);
|
||||
|
||||
/**
|
||||
@ -190,13 +190,13 @@ class File_ASN1
|
||||
* @access public
|
||||
*/
|
||||
var $stringTypeSize = array(
|
||||
FILE_ASN1_TYPE_UTF8_STRING => 0,
|
||||
FILE_ASN1_TYPE_BMP_STRING => 2,
|
||||
FILE_ASN1_TYPE_UNIVERSAL_STRING => 4,
|
||||
FILE_ASN1_TYPE_PRINTABLE_STRING => 1,
|
||||
FILE_ASN1_TYPE_TELETEX_STRING => 1,
|
||||
FILE_ASN1_TYPE_IA5_STRING => 1,
|
||||
FILE_ASN1_TYPE_VISIBLE_STRING => 1,
|
||||
self::TYPE_UTF8_STRING => 0,
|
||||
self::TYPE_BMP_STRING => 2,
|
||||
self::TYPE_UNIVERSAL_STRING => 4,
|
||||
self::TYPE_PRINTABLE_STRING => 1,
|
||||
self::TYPE_TELETEX_STRING => 1,
|
||||
self::TYPE_IA5_STRING => 1,
|
||||
self::TYPE_VISIBLE_STRING => 1,
|
||||
);
|
||||
|
||||
/**
|
||||
@ -223,8 +223,8 @@ class File_ASN1
|
||||
* Parse BER-encoding (Helper function)
|
||||
*
|
||||
* Sometimes we want to get the BER encoding of a particular tag. $start lets us do that without having to reencode.
|
||||
* $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.
|
||||
* $encoded is passed by reference for the recursive calls done for self::TYPE_BIT_STRING and
|
||||
* self::TYPE_OCTET_STRING. In those cases, the indefinite length is used.
|
||||
*
|
||||
* @param String $encoded
|
||||
* @param Integer $start
|
||||
@ -287,9 +287,9 @@ class File_ASN1
|
||||
-- http://www.obj-sys.com/asn1tutorial/node12.html */
|
||||
$class = ($type >> 6) & 3;
|
||||
switch ($class) {
|
||||
case FILE_ASN1_CLASS_APPLICATION:
|
||||
case FILE_ASN1_CLASS_PRIVATE:
|
||||
case FILE_ASN1_CLASS_CONTEXT_SPECIFIC:
|
||||
case self::CLASS_APPLICATION:
|
||||
case self::CLASS_PRIVATE:
|
||||
case self::CLASS_CONTEXT_SPECIFIC:
|
||||
if ($constructed) {
|
||||
$newcontent = $this->_decode_ber($content, $start);
|
||||
$length = $newcontent['length'];
|
||||
@ -319,20 +319,20 @@ class File_ASN1
|
||||
|
||||
// decode UNIVERSAL tags
|
||||
switch ($tag) {
|
||||
case FILE_ASN1_TYPE_BOOLEAN:
|
||||
case self::TYPE_BOOLEAN:
|
||||
// "The contents octets shall consist of a single octet." -- paragraph 8.2.1
|
||||
//if (strlen($content) != 1) {
|
||||
// return false;
|
||||
//}
|
||||
$current['content'] = (bool) ord($content[0]);
|
||||
break;
|
||||
case FILE_ASN1_TYPE_INTEGER:
|
||||
case FILE_ASN1_TYPE_ENUMERATED:
|
||||
case self::TYPE_INTEGER:
|
||||
case self::TYPE_ENUMERATED:
|
||||
$current['content'] = new BigInteger($content, -256);
|
||||
break;
|
||||
case FILE_ASN1_TYPE_REAL: // not currently supported
|
||||
case self::TYPE_REAL: // not currently supported
|
||||
return false;
|
||||
case FILE_ASN1_TYPE_BIT_STRING:
|
||||
case self::TYPE_BIT_STRING:
|
||||
// The initial octet shall encode, as an unsigned binary integer with bit 1 as the least significant bit,
|
||||
// the number of unused bits in the final subsequent octet. The number shall be in the range zero to
|
||||
// seven.
|
||||
@ -344,19 +344,19 @@ class File_ASN1
|
||||
$last = count($temp) - 1;
|
||||
for ($i = 0; $i < $last; $i++) {
|
||||
// all subtags should be bit strings
|
||||
//if ($temp[$i]['type'] != FILE_ASN1_TYPE_BIT_STRING) {
|
||||
//if ($temp[$i]['type'] != self::TYPE_BIT_STRING) {
|
||||
// return false;
|
||||
//}
|
||||
$current['content'].= substr($temp[$i]['content'], 1);
|
||||
}
|
||||
// all subtags should be bit strings
|
||||
//if ($temp[$last]['type'] != FILE_ASN1_TYPE_BIT_STRING) {
|
||||
//if ($temp[$last]['type'] != self::TYPE_BIT_STRING) {
|
||||
// return false;
|
||||
//}
|
||||
$current['content'] = $temp[$last]['content'][0] . $current['content'] . substr($temp[$i]['content'], 1);
|
||||
}
|
||||
break;
|
||||
case FILE_ASN1_TYPE_OCTET_STRING:
|
||||
case self::TYPE_OCTET_STRING:
|
||||
if (!$constructed) {
|
||||
$current['content'] = $content;
|
||||
} else {
|
||||
@ -366,7 +366,7 @@ class File_ASN1
|
||||
$temp = $this->_decode_ber($content, $length + $start);
|
||||
$this->_string_shift($content, $temp['length']);
|
||||
// all subtags should be octet strings
|
||||
//if ($temp['type'] != FILE_ASN1_TYPE_OCTET_STRING) {
|
||||
//if ($temp['type'] != self::TYPE_OCTET_STRING) {
|
||||
// return false;
|
||||
//}
|
||||
$current['content'].= $temp['content'];
|
||||
@ -377,14 +377,14 @@ class File_ASN1
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FILE_ASN1_TYPE_NULL:
|
||||
case self::TYPE_NULL:
|
||||
// "The contents octets shall not contain any octets." -- paragraph 8.8.2
|
||||
//if (strlen($content)) {
|
||||
// return false;
|
||||
//}
|
||||
break;
|
||||
case FILE_ASN1_TYPE_SEQUENCE:
|
||||
case FILE_ASN1_TYPE_SET:
|
||||
case self::TYPE_SEQUENCE:
|
||||
case self::TYPE_SET:
|
||||
$offset = 0;
|
||||
$current['content'] = array();
|
||||
while (strlen($content)) {
|
||||
@ -400,7 +400,7 @@ class File_ASN1
|
||||
$offset+= $temp['length'];
|
||||
}
|
||||
break;
|
||||
case FILE_ASN1_TYPE_OBJECT_IDENTIFIER:
|
||||
case self::TYPE_OBJECT_IDENTIFIER:
|
||||
$temp = ord($this->_string_shift($content));
|
||||
$current['content'] = sprintf('%d.%d', floor($temp / 40), $temp % 40);
|
||||
$valuen = 0;
|
||||
@ -426,31 +426,31 @@ class File_ASN1
|
||||
|
||||
Per that, we're not going to do any validation. If there are any illegal characters in the string,
|
||||
we don't really care */
|
||||
case FILE_ASN1_TYPE_NUMERIC_STRING:
|
||||
case self::TYPE_NUMERIC_STRING:
|
||||
// 0,1,2,3,4,5,6,7,8,9, and space
|
||||
case FILE_ASN1_TYPE_PRINTABLE_STRING:
|
||||
case self::TYPE_PRINTABLE_STRING:
|
||||
// Upper and lower case letters, digits, space, apostrophe, left/right parenthesis, plus sign, comma,
|
||||
// hyphen, full stop, solidus, colon, equal sign, question mark
|
||||
case FILE_ASN1_TYPE_TELETEX_STRING:
|
||||
case self::TYPE_TELETEX_STRING:
|
||||
// The Teletex character set in CCITT's T61, space, and delete
|
||||
// see http://en.wikipedia.org/wiki/Teletex#Character_sets
|
||||
case FILE_ASN1_TYPE_VIDEOTEX_STRING:
|
||||
case self::TYPE_VIDEOTEX_STRING:
|
||||
// The Videotex character set in CCITT's T.100 and T.101, space, and delete
|
||||
case FILE_ASN1_TYPE_VISIBLE_STRING:
|
||||
case self::TYPE_VISIBLE_STRING:
|
||||
// Printing character sets of international ASCII, and space
|
||||
case FILE_ASN1_TYPE_IA5_STRING:
|
||||
case self::TYPE_IA5_STRING:
|
||||
// International Alphabet 5 (International ASCII)
|
||||
case FILE_ASN1_TYPE_GRAPHIC_STRING:
|
||||
case self::TYPE_GRAPHIC_STRING:
|
||||
// All registered G sets, and space
|
||||
case FILE_ASN1_TYPE_GENERAL_STRING:
|
||||
case self::TYPE_GENERAL_STRING:
|
||||
// All registered C and G sets, space and delete
|
||||
case FILE_ASN1_TYPE_UTF8_STRING:
|
||||
case self::TYPE_UTF8_STRING:
|
||||
// ????
|
||||
case FILE_ASN1_TYPE_BMP_STRING:
|
||||
case self::TYPE_BMP_STRING:
|
||||
$current['content'] = $content;
|
||||
break;
|
||||
case FILE_ASN1_TYPE_UTC_TIME:
|
||||
case FILE_ASN1_TYPE_GENERALIZED_TIME:
|
||||
case self::TYPE_UTC_TIME:
|
||||
case self::TYPE_GENERALIZED_TIME:
|
||||
$current['content'] = $this->_decodeTime($content, $tag);
|
||||
default:
|
||||
}
|
||||
@ -481,7 +481,7 @@ class File_ASN1
|
||||
}
|
||||
|
||||
switch (true) {
|
||||
case $mapping['type'] == FILE_ASN1_TYPE_ANY:
|
||||
case $mapping['type'] == self::TYPE_ANY:
|
||||
$intype = $decoded['type'];
|
||||
if (isset($decoded['constant']) || !isset($this->ANYmap[$intype]) || ($this->encoded[$decoded['start']] & 0x20)) {
|
||||
return new File_ASN1_Element(substr($this->encoded, $decoded['start'], $decoded['length']));
|
||||
@ -491,14 +491,14 @@ class File_ASN1
|
||||
return array($inmap => $this->asn1map($decoded, array('type' => $intype) + $mapping, $special));
|
||||
}
|
||||
break;
|
||||
case $mapping['type'] == FILE_ASN1_TYPE_CHOICE:
|
||||
case $mapping['type'] == self::TYPE_CHOICE:
|
||||
foreach ($mapping['children'] as $key => $option) {
|
||||
switch (true) {
|
||||
case isset($option['constant']) && $option['constant'] == $decoded['constant']:
|
||||
case !isset($option['constant']) && $option['type'] == $decoded['type']:
|
||||
$value = $this->asn1map($decoded, $option, $special);
|
||||
break;
|
||||
case !isset($option['constant']) && $option['type'] == FILE_ASN1_TYPE_CHOICE:
|
||||
case !isset($option['constant']) && $option['type'] == self::TYPE_CHOICE:
|
||||
$v = $this->asn1map($decoded, $option, $special);
|
||||
if (isset($v)) {
|
||||
$value = $v;
|
||||
@ -520,8 +520,8 @@ class File_ASN1
|
||||
// if $decoded['type'] and $mapping['type'] are both strings, but different types of strings,
|
||||
// let it through
|
||||
switch (true) {
|
||||
case $decoded['type'] < 18: // FILE_ASN1_TYPE_NUMERIC_STRING == 18
|
||||
case $decoded['type'] > 30: // FILE_ASN1_TYPE_BMP_STRING == 30
|
||||
case $decoded['type'] < 18: // self::TYPE_NUMERIC_STRING == 18
|
||||
case $decoded['type'] > 30: // self::TYPE_BMP_STRING == 30
|
||||
case $mapping['type'] < 18:
|
||||
case $mapping['type'] > 30:
|
||||
return null;
|
||||
@ -533,7 +533,7 @@ class File_ASN1
|
||||
}
|
||||
|
||||
switch ($decoded['type']) {
|
||||
case FILE_ASN1_TYPE_SEQUENCE:
|
||||
case self::TYPE_SEQUENCE:
|
||||
$map = array();
|
||||
|
||||
// ignore the min and max
|
||||
@ -556,18 +556,18 @@ class File_ASN1
|
||||
if ($maymatch) {
|
||||
$temp = $decoded['content'][$i];
|
||||
|
||||
if ($child['type'] != FILE_ASN1_TYPE_CHOICE) {
|
||||
if ($child['type'] != self::TYPE_CHOICE) {
|
||||
// Get the mapping and input class & constant.
|
||||
$childClass = $tempClass = FILE_ASN1_CLASS_UNIVERSAL;
|
||||
$childClass = $tempClass = self::CLASS_UNIVERSAL;
|
||||
$constant = null;
|
||||
if (isset($temp['constant'])) {
|
||||
$tempClass = isset($temp['class']) ? $temp['class'] : FILE_ASN1_CLASS_CONTEXT_SPECIFIC;
|
||||
$tempClass = isset($temp['class']) ? $temp['class'] : self::CLASS_CONTEXT_SPECIFIC;
|
||||
}
|
||||
if (isset($child['class'])) {
|
||||
$childClass = $child['class'];
|
||||
$constant = $child['cast'];
|
||||
} elseif (isset($child['constant'])) {
|
||||
$childClass = FILE_ASN1_CLASS_CONTEXT_SPECIFIC;
|
||||
$childClass = self::CLASS_CONTEXT_SPECIFIC;
|
||||
$constant = $child['constant'];
|
||||
}
|
||||
|
||||
@ -576,7 +576,7 @@ class File_ASN1
|
||||
$maymatch = $constant == $temp['constant'] && $childClass == $tempClass;
|
||||
} else {
|
||||
// Can only match if no constant expected and type matches or is generic.
|
||||
$maymatch = !isset($child['constant']) && array_search($child['type'], array($temp['type'], FILE_ASN1_TYPE_ANY, FILE_ASN1_TYPE_CHOICE)) !== false;
|
||||
$maymatch = !isset($child['constant']) && array_search($child['type'], array($temp['type'], self::TYPE_ANY, self::TYPE_CHOICE)) !== false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -605,7 +605,7 @@ class File_ASN1
|
||||
return $i < $n? null: $map;
|
||||
|
||||
// the main diff between sets and sequences is the encapsulation of the foreach in another for loop
|
||||
case FILE_ASN1_TYPE_SET:
|
||||
case self::TYPE_SET:
|
||||
$map = array();
|
||||
|
||||
// ignore the min and max
|
||||
@ -622,9 +622,9 @@ class File_ASN1
|
||||
|
||||
for ($i = 0; $i < count($decoded['content']); $i++) {
|
||||
$temp = $decoded['content'][$i];
|
||||
$tempClass = FILE_ASN1_CLASS_UNIVERSAL;
|
||||
$tempClass = self::CLASS_UNIVERSAL;
|
||||
if (isset($temp['constant'])) {
|
||||
$tempClass = isset($temp['class']) ? $temp['class'] : FILE_ASN1_CLASS_CONTEXT_SPECIFIC;
|
||||
$tempClass = isset($temp['class']) ? $temp['class'] : self::CLASS_CONTEXT_SPECIFIC;
|
||||
}
|
||||
|
||||
foreach ($mapping['children'] as $key => $child) {
|
||||
@ -632,14 +632,14 @@ class File_ASN1
|
||||
continue;
|
||||
}
|
||||
$maymatch = true;
|
||||
if ($child['type'] != FILE_ASN1_TYPE_CHOICE) {
|
||||
$childClass = FILE_ASN1_CLASS_UNIVERSAL;
|
||||
if ($child['type'] != self::TYPE_CHOICE) {
|
||||
$childClass = self::CLASS_UNIVERSAL;
|
||||
$constant = null;
|
||||
if (isset($child['class'])) {
|
||||
$childClass = $child['class'];
|
||||
$constant = $child['cast'];
|
||||
} elseif (isset($child['constant'])) {
|
||||
$childClass = FILE_ASN1_CLASS_CONTEXT_SPECIFIC;
|
||||
$childClass = self::CLASS_CONTEXT_SPECIFIC;
|
||||
$constant = $child['constant'];
|
||||
}
|
||||
|
||||
@ -648,7 +648,7 @@ class File_ASN1
|
||||
$maymatch = $constant == $temp['constant'] && $childClass == $tempClass;
|
||||
} else {
|
||||
// Can only match if no constant expected and type matches or is generic.
|
||||
$maymatch = !isset($child['constant']) && array_search($child['type'], array($temp['type'], FILE_ASN1_TYPE_ANY, FILE_ASN1_TYPE_CHOICE)) !== false;
|
||||
$maymatch = !isset($child['constant']) && array_search($child['type'], array($temp['type'], self::TYPE_ANY, self::TYPE_CHOICE)) !== false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -681,15 +681,15 @@ class File_ASN1
|
||||
}
|
||||
}
|
||||
return $map;
|
||||
case FILE_ASN1_TYPE_OBJECT_IDENTIFIER:
|
||||
case self::TYPE_OBJECT_IDENTIFIER:
|
||||
return isset($this->oids[$decoded['content']]) ? $this->oids[$decoded['content']] : $decoded['content'];
|
||||
case FILE_ASN1_TYPE_UTC_TIME:
|
||||
case FILE_ASN1_TYPE_GENERALIZED_TIME:
|
||||
case self::TYPE_UTC_TIME:
|
||||
case self::TYPE_GENERALIZED_TIME:
|
||||
if (isset($mapping['implicit'])) {
|
||||
$decoded['content'] = $this->_decodeTime($decoded['content'], $decoded['type']);
|
||||
}
|
||||
return @date($this->format, $decoded['content']);
|
||||
case FILE_ASN1_TYPE_BIT_STRING:
|
||||
case self::TYPE_BIT_STRING:
|
||||
if (isset($mapping['mapping'])) {
|
||||
$offset = ord($decoded['content'][0]);
|
||||
$size = (strlen($decoded['content']) - 1) * 8 - $offset;
|
||||
@ -718,26 +718,26 @@ class File_ASN1
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
case FILE_ASN1_TYPE_OCTET_STRING:
|
||||
case self::TYPE_OCTET_STRING:
|
||||
return base64_encode($decoded['content']);
|
||||
case FILE_ASN1_TYPE_NULL:
|
||||
case self::TYPE_NULL:
|
||||
return '';
|
||||
case FILE_ASN1_TYPE_BOOLEAN:
|
||||
case self::TYPE_BOOLEAN:
|
||||
return $decoded['content'];
|
||||
case FILE_ASN1_TYPE_NUMERIC_STRING:
|
||||
case FILE_ASN1_TYPE_PRINTABLE_STRING:
|
||||
case FILE_ASN1_TYPE_TELETEX_STRING:
|
||||
case FILE_ASN1_TYPE_VIDEOTEX_STRING:
|
||||
case FILE_ASN1_TYPE_IA5_STRING:
|
||||
case FILE_ASN1_TYPE_GRAPHIC_STRING:
|
||||
case FILE_ASN1_TYPE_VISIBLE_STRING:
|
||||
case FILE_ASN1_TYPE_GENERAL_STRING:
|
||||
case FILE_ASN1_TYPE_UNIVERSAL_STRING:
|
||||
case FILE_ASN1_TYPE_UTF8_STRING:
|
||||
case FILE_ASN1_TYPE_BMP_STRING:
|
||||
case self::TYPE_NUMERIC_STRING:
|
||||
case self::TYPE_PRINTABLE_STRING:
|
||||
case self::TYPE_TELETEX_STRING:
|
||||
case self::TYPE_VIDEOTEX_STRING:
|
||||
case self::TYPE_IA5_STRING:
|
||||
case self::TYPE_GRAPHIC_STRING:
|
||||
case self::TYPE_VISIBLE_STRING:
|
||||
case self::TYPE_GENERAL_STRING:
|
||||
case self::TYPE_UNIVERSAL_STRING:
|
||||
case self::TYPE_UTF8_STRING:
|
||||
case self::TYPE_BMP_STRING:
|
||||
return $decoded['content'];
|
||||
case FILE_ASN1_TYPE_INTEGER:
|
||||
case FILE_ASN1_TYPE_ENUMERATED:
|
||||
case self::TYPE_INTEGER:
|
||||
case self::TYPE_ENUMERATED:
|
||||
$temp = $decoded['content'];
|
||||
if (isset($mapping['implicit'])) {
|
||||
$temp = new BigInteger($decoded['content'], -256);
|
||||
@ -802,8 +802,8 @@ class File_ASN1
|
||||
$tag = $mapping['type'];
|
||||
|
||||
switch ($tag) {
|
||||
case FILE_ASN1_TYPE_SET: // Children order is not important, thus process in sequence.
|
||||
case FILE_ASN1_TYPE_SEQUENCE:
|
||||
case self::TYPE_SET: // Children order is not important, thus process in sequence.
|
||||
case self::TYPE_SEQUENCE:
|
||||
$tag|= 0x20; // set the constructed bit
|
||||
$value = '';
|
||||
|
||||
@ -851,18 +851,18 @@ class File_ASN1
|
||||
AUTOMATIC TAGS, but the type defined by "Type" is an untagged choice type, an untagged open type, or
|
||||
an untagged "DummyReference" (see ITU-T Rec. X.683 | ISO/IEC 8824-4, 8.3)."
|
||||
*/
|
||||
if (isset($child['explicit']) || $child['type'] == FILE_ASN1_TYPE_CHOICE) {
|
||||
$subtag = chr((FILE_ASN1_CLASS_CONTEXT_SPECIFIC << 6) | 0x20 | $child['constant']);
|
||||
if (isset($child['explicit']) || $child['type'] == self::TYPE_CHOICE) {
|
||||
$subtag = chr((self::CLASS_CONTEXT_SPECIFIC << 6) | 0x20 | $child['constant']);
|
||||
$temp = $subtag . $this->_encodeLength(strlen($temp)) . $temp;
|
||||
} else {
|
||||
$subtag = chr((FILE_ASN1_CLASS_CONTEXT_SPECIFIC << 6) | (ord($temp[0]) & 0x20) | $child['constant']);
|
||||
$subtag = chr((self::CLASS_CONTEXT_SPECIFIC << 6) | (ord($temp[0]) & 0x20) | $child['constant']);
|
||||
$temp = $subtag . substr($temp, 1);
|
||||
}
|
||||
}
|
||||
$value.= $temp;
|
||||
}
|
||||
break;
|
||||
case FILE_ASN1_TYPE_CHOICE:
|
||||
case self::TYPE_CHOICE:
|
||||
$temp = false;
|
||||
|
||||
foreach ($mapping['children'] as $key => $child) {
|
||||
@ -885,11 +885,11 @@ class File_ASN1
|
||||
|
||||
// if isset($child['constant']) is true then isset($child['optional']) should be true as well
|
||||
if (isset($child['constant'])) {
|
||||
if (isset($child['explicit']) || $child['type'] == FILE_ASN1_TYPE_CHOICE) {
|
||||
$subtag = chr((FILE_ASN1_CLASS_CONTEXT_SPECIFIC << 6) | 0x20 | $child['constant']);
|
||||
if (isset($child['explicit']) || $child['type'] == self::TYPE_CHOICE) {
|
||||
$subtag = chr((self::CLASS_CONTEXT_SPECIFIC << 6) | 0x20 | $child['constant']);
|
||||
$temp = $subtag . $this->_encodeLength(strlen($temp)) . $temp;
|
||||
} else {
|
||||
$subtag = chr((FILE_ASN1_CLASS_CONTEXT_SPECIFIC << 6) | (ord($temp[0]) & 0x20) | $child['constant']);
|
||||
$subtag = chr((self::CLASS_CONTEXT_SPECIFIC << 6) | (ord($temp[0]) & 0x20) | $child['constant']);
|
||||
$temp = $subtag . substr($temp, 1);
|
||||
}
|
||||
}
|
||||
@ -904,8 +904,8 @@ class File_ASN1
|
||||
}
|
||||
|
||||
return $temp;
|
||||
case FILE_ASN1_TYPE_INTEGER:
|
||||
case FILE_ASN1_TYPE_ENUMERATED:
|
||||
case self::TYPE_INTEGER:
|
||||
case self::TYPE_ENUMERATED:
|
||||
if (!isset($mapping['mapping'])) {
|
||||
if (is_numeric($source)) {
|
||||
$source = new BigInteger($source);
|
||||
@ -923,13 +923,13 @@ class File_ASN1
|
||||
$value = chr(0);
|
||||
}
|
||||
break;
|
||||
case FILE_ASN1_TYPE_UTC_TIME:
|
||||
case FILE_ASN1_TYPE_GENERALIZED_TIME:
|
||||
$format = $mapping['type'] == FILE_ASN1_TYPE_UTC_TIME ? 'y' : 'Y';
|
||||
case self::TYPE_UTC_TIME:
|
||||
case self::TYPE_GENERALIZED_TIME:
|
||||
$format = $mapping['type'] == self::TYPE_UTC_TIME ? 'y' : 'Y';
|
||||
$format.= 'mdHis';
|
||||
$value = @gmdate($format, strtotime($source)) . 'Z';
|
||||
break;
|
||||
case FILE_ASN1_TYPE_BIT_STRING:
|
||||
case self::TYPE_BIT_STRING:
|
||||
if (isset($mapping['mapping'])) {
|
||||
$bits = array_fill(0, count($mapping['mapping']), 0);
|
||||
$size = 0;
|
||||
@ -961,14 +961,14 @@ class File_ASN1
|
||||
|
||||
break;
|
||||
}
|
||||
case FILE_ASN1_TYPE_OCTET_STRING:
|
||||
case self::TYPE_OCTET_STRING:
|
||||
/* The initial octet shall encode, as an unsigned binary integer with bit 1 as the least significant bit,
|
||||
the number of unused bits in the final subsequent octet. The number shall be in the range zero to seven.
|
||||
|
||||
-- http://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#page=16 */
|
||||
$value = base64_decode($source);
|
||||
break;
|
||||
case FILE_ASN1_TYPE_OBJECT_IDENTIFIER:
|
||||
case self::TYPE_OBJECT_IDENTIFIER:
|
||||
$oid = preg_match('#(?:\d+\.)+#', $source) ? $source : array_search($source, $this->oids);
|
||||
if ($oid === false) {
|
||||
user_error('Invalid OID');
|
||||
@ -991,7 +991,7 @@ class File_ASN1
|
||||
$value.= $temp;
|
||||
}
|
||||
break;
|
||||
case FILE_ASN1_TYPE_ANY:
|
||||
case self::TYPE_ANY:
|
||||
$loc = $this->location;
|
||||
if (isset($idx)) {
|
||||
array_pop($this->location);
|
||||
@ -999,14 +999,14 @@ class File_ASN1
|
||||
|
||||
switch (true) {
|
||||
case !isset($source):
|
||||
return $this->_encode_der(null, array('type' => FILE_ASN1_TYPE_NULL) + $mapping, null, $special);
|
||||
return $this->_encode_der(null, array('type' => self::TYPE_NULL) + $mapping, null, $special);
|
||||
case is_int($source):
|
||||
case $source instanceof \phpseclib\Math\BigInteger:
|
||||
return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_INTEGER) + $mapping, null, $special);
|
||||
return $this->_encode_der($source, array('type' => self::TYPE_INTEGER) + $mapping, null, $special);
|
||||
case is_float($source):
|
||||
return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_REAL) + $mapping, null, $special);
|
||||
return $this->_encode_der($source, array('type' => self::TYPE_REAL) + $mapping, null, $special);
|
||||
case is_bool($source):
|
||||
return $this->_encode_der($source, array('type' => FILE_ASN1_TYPE_BOOLEAN) + $mapping, null, $special);
|
||||
return $this->_encode_der($source, array('type' => self::TYPE_BOOLEAN) + $mapping, null, $special);
|
||||
case is_array($source) && count($source) == 1:
|
||||
$typename = implode('', array_keys($source));
|
||||
$outtype = array_search($typename, $this->ANYmap, true);
|
||||
@ -1028,23 +1028,23 @@ class File_ASN1
|
||||
return false;
|
||||
}
|
||||
return $this->_encode_der($source, $filters + $mapping, null, $special);
|
||||
case FILE_ASN1_TYPE_NULL:
|
||||
case self::TYPE_NULL:
|
||||
$value = '';
|
||||
break;
|
||||
case FILE_ASN1_TYPE_NUMERIC_STRING:
|
||||
case FILE_ASN1_TYPE_TELETEX_STRING:
|
||||
case FILE_ASN1_TYPE_PRINTABLE_STRING:
|
||||
case FILE_ASN1_TYPE_UNIVERSAL_STRING:
|
||||
case FILE_ASN1_TYPE_UTF8_STRING:
|
||||
case FILE_ASN1_TYPE_BMP_STRING:
|
||||
case FILE_ASN1_TYPE_IA5_STRING:
|
||||
case FILE_ASN1_TYPE_VISIBLE_STRING:
|
||||
case FILE_ASN1_TYPE_VIDEOTEX_STRING:
|
||||
case FILE_ASN1_TYPE_GRAPHIC_STRING:
|
||||
case FILE_ASN1_TYPE_GENERAL_STRING:
|
||||
case self::TYPE_NUMERIC_STRING:
|
||||
case self::TYPE_TELETEX_STRING:
|
||||
case self::TYPE_PRINTABLE_STRING:
|
||||
case self::TYPE_UNIVERSAL_STRING:
|
||||
case self::TYPE_UTF8_STRING:
|
||||
case self::TYPE_BMP_STRING:
|
||||
case self::TYPE_IA5_STRING:
|
||||
case self::TYPE_VISIBLE_STRING:
|
||||
case self::TYPE_VIDEOTEX_STRING:
|
||||
case self::TYPE_GRAPHIC_STRING:
|
||||
case self::TYPE_GENERAL_STRING:
|
||||
$value = $source;
|
||||
break;
|
||||
case FILE_ASN1_TYPE_BOOLEAN:
|
||||
case self::TYPE_BOOLEAN:
|
||||
$value = $source ? "\xFF" : "\x00";
|
||||
break;
|
||||
default:
|
||||
@ -1057,7 +1057,7 @@ class File_ASN1
|
||||
}
|
||||
|
||||
if (isset($mapping['cast'])) {
|
||||
if (isset($mapping['explicit']) || $mapping['type'] == FILE_ASN1_TYPE_CHOICE) {
|
||||
if (isset($mapping['explicit']) || $mapping['type'] == self::TYPE_CHOICE) {
|
||||
$value = chr($tag) . $this->_encodeLength(strlen($value)) . $value;
|
||||
$tag = ($mapping['class'] << 6) | 0x20 | $mapping['cast'];
|
||||
} else {
|
||||
@ -1108,7 +1108,7 @@ class File_ASN1
|
||||
http://tools.ietf.org/html/rfc5280#section-4.1.2.5.2
|
||||
http://www.obj-sys.com/asn1tutorial/node14.html */
|
||||
|
||||
$pattern = $tag == FILE_ASN1_TYPE_UTC_TIME ?
|
||||
$pattern = $tag == self::TYPE_UTC_TIME ?
|
||||
'#(..)(..)(..)(..)(..)(..)(.*)#' :
|
||||
'#(....)(..)(..)(..)(..)(..).*([Z+-].*)$#';
|
||||
|
||||
@ -1116,7 +1116,7 @@ class File_ASN1
|
||||
|
||||
list(, $year, $month, $day, $hour, $minute, $second, $timezone) = $matches;
|
||||
|
||||
if ($tag == FILE_ASN1_TYPE_UTC_TIME) {
|
||||
if ($tag == self::TYPE_UTC_TIME) {
|
||||
$year = $year >= 50 ? "19$year" : "20$year";
|
||||
}
|
||||
|
||||
@ -1205,7 +1205,7 @@ class File_ASN1
|
||||
* @return String
|
||||
* @access public
|
||||
*/
|
||||
function convert($in, $from = FILE_ASN1_TYPE_UTF8_STRING, $to = FILE_ASN1_TYPE_UTF8_STRING)
|
||||
function convert($in, $from = self::TYPE_UTF8_STRING, $to = self::TYPE_UTF8_STRING)
|
||||
{
|
||||
if (!isset($this->stringTypeSize[$from]) || !isset($this->stringTypeSize[$to])) {
|
||||
return false;
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -52,6 +52,45 @@ use \phpseclib\Crypt\Random;
|
||||
// Used to do Diffie-Hellman key exchange and DSA/RSA signature verification.
|
||||
use \phpseclib\Math\BigInteger;
|
||||
|
||||
/**#@+
|
||||
* Execution Bitmap Masks
|
||||
*
|
||||
* @see Net_SSH2::bitmap
|
||||
* @access private
|
||||
*/
|
||||
define('NET_SSH2_MASK_CONSTRUCTOR', 0x00000001);
|
||||
define('NET_SSH2_MASK_CONNECTED', 0x00000002);
|
||||
define('NET_SSH2_MASK_LOGIN_REQ', 0x00000004);
|
||||
define('NET_SSH2_MASK_LOGIN', 0x00000008);
|
||||
define('NET_SSH2_MASK_SHELL', 0x00000010);
|
||||
define('NET_SSH2_MASK_WINDOW_ADJUST', 0x00000020);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* Channel constants
|
||||
*
|
||||
* RFC4254 refers not to client and server channels but rather to sender and recipient channels. we don't refer
|
||||
* to them in that way because RFC4254 toggles the meaning. the client sends a SSH_MSG_CHANNEL_OPEN message with
|
||||
* a sender channel and the server sends a SSH_MSG_CHANNEL_OPEN_CONFIRMATION in response, with a sender and a
|
||||
* recepient channel. at first glance, you might conclude that SSH_MSG_CHANNEL_OPEN_CONFIRMATION's sender channel
|
||||
* would be the same thing as SSH_MSG_CHANNEL_OPEN's sender channel, but it's not, per this snipet:
|
||||
* The 'recipient channel' is the channel number given in the original
|
||||
* open request, and 'sender channel' is the channel number allocated by
|
||||
* the other side.
|
||||
*
|
||||
* @see Net_SSH2::_send_channel_packet()
|
||||
* @see Net_SSH2::_get_channel_packet()
|
||||
* @access private
|
||||
*/
|
||||
define('NET_SSH2_CHANNEL_EXEC', 0); // PuTTy uses 0x100
|
||||
define('NET_SSH2_CHANNEL_SHELL', 1);
|
||||
define('NET_SSH2_CHANNEL_SUBSYSTEM', 2);
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
* @access public
|
||||
* @see Net_SSH2::getLog()
|
||||
*/
|
||||
/**
|
||||
* Pure-PHP implementation of SSHv2.
|
||||
*
|
||||
@ -3251,26 +3290,22 @@ class Net_SSH2
|
||||
*/
|
||||
function _send_channel_packet($client_channel, $data)
|
||||
{
|
||||
while (strlen($data)) {
|
||||
if (!$this->window_size_client_to_server[$client_channel]) {
|
||||
$this->bitmap^= self::MASK_WINDOW_ADJUST;
|
||||
// using an invalid channel will let the buffers be built up for the valid channels
|
||||
$this->_get_channel_packet(-1);
|
||||
$this->bitmap^= NET_SSH2_MASK_WINDOW_ADJUST;
|
||||
}
|
||||
|
||||
/* The maximum amount of data allowed is determined by the maximum
|
||||
packet size for the channel, and the current window size, whichever
|
||||
is smaller.
|
||||
|
||||
-- http://tools.ietf.org/html/rfc4254#section-5.2 */
|
||||
$max_size = min(
|
||||
$this->packet_size_client_to_server[$client_channel],
|
||||
$this->window_size_client_to_server[$client_channel]
|
||||
);
|
||||
while (strlen($data) > $max_size) {
|
||||
if (!$this->window_size_client_to_server[$client_channel]) {
|
||||
$this->bitmap^= self::MASK_WINDOW_ADJUST;
|
||||
// using an invalid channel will let the buffers be built up for the valid channels
|
||||
$output = $this->_get_channel_packet(-1);
|
||||
$this->bitmap^= self::MASK_WINDOW_ADJUST;
|
||||
$max_size = min(
|
||||
$this->packet_size_client_to_server[$client_channel],
|
||||
$this->window_size_client_to_server[$client_channel]
|
||||
);
|
||||
}
|
||||
|
||||
$temp = $this->_string_shift($data, $max_size);
|
||||
$packet = pack('CN2a*',
|
||||
@ -3279,27 +3314,13 @@ class Net_SSH2
|
||||
strlen($temp),
|
||||
$temp
|
||||
);
|
||||
|
||||
$this->window_size_client_to_server[$client_channel]-= strlen($temp);
|
||||
|
||||
if (!$this->_send_binary_packet($packet)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($data) >= $this->window_size_client_to_server[$client_channel]) {
|
||||
$this->bitmap^= self::MASK_WINDOW_ADJUST;
|
||||
$this->_get_channel_packet(-1);
|
||||
$this->bitmap^= self::MASK_WINDOW_ADJUST;
|
||||
}
|
||||
|
||||
$this->window_size_client_to_server[$client_channel]-= strlen($data);
|
||||
|
||||
return $this->_send_binary_packet(pack('CN2a*',
|
||||
NET_SSH2_MSG_CHANNEL_DATA,
|
||||
$this->server_channels[$client_channel],
|
||||
strlen($data),
|
||||
$data));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,7 +10,7 @@ abstract class PhpseclibFunctionalTestCase extends PhpseclibTestCase
|
||||
static public function setUpBeforeClass()
|
||||
{
|
||||
if (extension_loaded('runkit')) {
|
||||
self::ensureConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP);
|
||||
self::ensureConstant('MATH_BIGINTEGER_MODE', \phpseclib\Math\BigInteger::MODE_GMP);
|
||||
self::ensureConstant('CRYPT_HASH_MODE', CRYPT_HASH_MODE_HASH);
|
||||
self::reRequireFile('Math/BigInteger.php');
|
||||
self::reRequireFile('Crypt/Hash.php');
|
||||
|
55
tests/Unit/Crypt/RandomTest.php
Normal file
55
tests/Unit/Crypt/RandomTest.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Andreas Fischer <bantu@phpbb.com>
|
||||
* @copyright MMXIV Andreas Fischer
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
*/
|
||||
|
||||
use phpseclib\Crypt\Random;
|
||||
|
||||
class Unit_Crypt_RandomTest extends PhpseclibTestCase
|
||||
{
|
||||
public function stringLengthData()
|
||||
{
|
||||
return array_map(array($this, 'wrap'), array(
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 17, 19, 20, 23, 29, 31, 37,
|
||||
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 111, 128, 1000,
|
||||
1024, 10000, 12345, 100000, 123456
|
||||
));
|
||||
}
|
||||
|
||||
/** @dataProvider stringLengthData */
|
||||
public function testStringLength($length)
|
||||
{
|
||||
$this->assertSame(
|
||||
$length,
|
||||
strlen(Random::string($length)),
|
||||
'Failed asserting that a string of expected length was generated.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes a set of random values of length 128 bits and asserts all taken
|
||||
* values are unique.
|
||||
*/
|
||||
public function testStringUniqueness()
|
||||
{
|
||||
$values = array();
|
||||
for ($i = 0; $i < 10000; ++$i) {
|
||||
$rand = Random::string(16);
|
||||
$this->assertSame(16, strlen($rand));
|
||||
$this->assertArrayNotHasKey(
|
||||
$rand,
|
||||
$values,
|
||||
'Failed asserting that generated value does not exist in set.'
|
||||
);
|
||||
$values[$rand] = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected function wrap($x)
|
||||
{
|
||||
// array() is not a function, but $this->wrap() is.
|
||||
return array($x);
|
||||
}
|
||||
}
|
@ -16,48 +16,48 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
|
||||
public function testAnyString()
|
||||
{
|
||||
$KDC_REP = array(
|
||||
'type' => FILE_ASN1_TYPE_SEQUENCE,
|
||||
'type' => File_ASN1::TYPE_SEQUENCE,
|
||||
'children' => array(
|
||||
'pvno' => array(
|
||||
'constant' => 0,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY),
|
||||
'type' => File_ASN1::TYPE_ANY),
|
||||
'msg-type' => array(
|
||||
'constant' => 1,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY),
|
||||
'type' => File_ASN1::TYPE_ANY),
|
||||
'padata' => array(
|
||||
'constant' => 2,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY),
|
||||
'type' => File_ASN1::TYPE_ANY),
|
||||
'crealm' => array(
|
||||
'constant' => 3,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY),
|
||||
'type' => File_ASN1::TYPE_ANY),
|
||||
'cname' => array(
|
||||
'constant' => 4,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY),
|
||||
'type' => File_ASN1::TYPE_ANY),
|
||||
'ticket' => array(
|
||||
'constant' => 5,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY),
|
||||
'type' => File_ASN1::TYPE_ANY),
|
||||
'enc-part' => array(
|
||||
'constant' => 6,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY)
|
||||
'type' => File_ASN1::TYPE_ANY)
|
||||
)
|
||||
);
|
||||
|
||||
$AS_REP = array(
|
||||
'class' => FILE_ASN1_CLASS_APPLICATION,
|
||||
'class' => File_ASN1::CLASS_APPLICATION,
|
||||
'cast' => 11,
|
||||
'optional' => true,
|
||||
'explicit' => true
|
||||
@ -89,31 +89,31 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
|
||||
public function testIncorrectString()
|
||||
{
|
||||
$PA_DATA = array(
|
||||
'type' => FILE_ASN1_TYPE_SEQUENCE,
|
||||
'type' => File_ASN1::TYPE_SEQUENCE,
|
||||
'children' => array(
|
||||
'padata-type' => array(
|
||||
'constant' => 1,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_INTEGER
|
||||
'type' => File_ASN1::TYPE_INTEGER
|
||||
),
|
||||
'padata-value' => array(
|
||||
'constant' => 2,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_OCTET_STRING
|
||||
'type' => File_ASN1::TYPE_OCTET_STRING
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$PrincipalName = array(
|
||||
'type' => FILE_ASN1_TYPE_SEQUENCE,
|
||||
'type' => File_ASN1::TYPE_SEQUENCE,
|
||||
'children' => array(
|
||||
'name-type' => array(
|
||||
'constant' => 0,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_INTEGER
|
||||
'type' => File_ASN1::TYPE_INTEGER
|
||||
),
|
||||
'name-string' => array(
|
||||
'constant' => 1,
|
||||
@ -121,95 +121,95 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
|
||||
'explicit' => true,
|
||||
'min' => 0,
|
||||
'max' => -1,
|
||||
'type' => FILE_ASN1_TYPE_SEQUENCE,
|
||||
'children' => array('type' => FILE_ASN1_TYPE_IA5_STRING) // should be FILE_ASN1_TYPE_GENERAL_STRING
|
||||
'type' => File_ASN1::TYPE_SEQUENCE,
|
||||
'children' => array('type' => File_ASN1::TYPE_IA5_STRING) // should be File_ASN1::TYPE_GENERAL_STRING
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$Ticket = array(
|
||||
'class' => FILE_ASN1_CLASS_APPLICATION,
|
||||
'class' => File_ASN1::CLASS_APPLICATION,
|
||||
'cast' => 1,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_SEQUENCE,
|
||||
'type' => File_ASN1::TYPE_SEQUENCE,
|
||||
'children' => array(
|
||||
'tkt-vno' => array(
|
||||
'constant' => 0,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_INTEGER
|
||||
'type' => File_ASN1::TYPE_INTEGER
|
||||
),
|
||||
'realm' => array(
|
||||
'constant' => 1,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY
|
||||
'type' => File_ASN1::TYPE_ANY
|
||||
),
|
||||
'sname' => array(
|
||||
'constant' => 2,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY
|
||||
'type' => File_ASN1::TYPE_ANY
|
||||
),
|
||||
'enc-part' => array(
|
||||
'constant' => 3,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY
|
||||
'type' => File_ASN1::TYPE_ANY
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$KDC_REP = array(
|
||||
'type' => FILE_ASN1_TYPE_SEQUENCE,
|
||||
'type' => File_ASN1::TYPE_SEQUENCE,
|
||||
'children' => array(
|
||||
'pvno' => array(
|
||||
'constant' => 0,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_INTEGER),
|
||||
'type' => File_ASN1::TYPE_INTEGER),
|
||||
'msg-type' => array(
|
||||
'constant' => 1,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_INTEGER),
|
||||
'type' => File_ASN1::TYPE_INTEGER),
|
||||
'padata' => array(
|
||||
'constant' => 2,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'min' => 0,
|
||||
'max' => -1,
|
||||
'type' => FILE_ASN1_TYPE_SEQUENCE,
|
||||
'type' => File_ASN1::TYPE_SEQUENCE,
|
||||
'children' => $PA_DATA),
|
||||
'crealm' => array(
|
||||
'constant' => 3,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_OCTET_STRING),
|
||||
'type' => File_ASN1::TYPE_OCTET_STRING),
|
||||
'cname' => array(
|
||||
'constant' => 4,
|
||||
'optional' => true,
|
||||
'explicit' => true) + $PrincipalName,
|
||||
//'type' => FILE_ASN1_TYPE_ANY),
|
||||
//'type' => File_ASN1::TYPE_ANY),
|
||||
'ticket' => array(
|
||||
'constant' => 5,
|
||||
'optional' => true,
|
||||
'implicit' => true,
|
||||
'min' => 0,
|
||||
'max' => 1,
|
||||
'type' => FILE_ASN1_TYPE_SEQUENCE,
|
||||
'type' => File_ASN1::TYPE_SEQUENCE,
|
||||
'children' => $Ticket),
|
||||
'enc-part' => array(
|
||||
'constant' => 6,
|
||||
'optional' => true,
|
||||
'explicit' => true,
|
||||
'type' => FILE_ASN1_TYPE_ANY)
|
||||
'type' => File_ASN1::TYPE_ANY)
|
||||
)
|
||||
);
|
||||
|
||||
$AS_REP = array(
|
||||
'class' => FILE_ASN1_CLASS_APPLICATION,
|
||||
'class' => File_ASN1::CLASS_APPLICATION,
|
||||
'cast' => 11,
|
||||
'optional' => true,
|
||||
'explicit' => true
|
||||
|
@ -15,6 +15,6 @@ class Unit_Math_BigInteger_BCMathTest extends Unit_Math_BigInteger_TestCase
|
||||
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::ensureConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_BCMATH);
|
||||
self::ensureConstant('MATH_BIGINTEGER_MODE', \phpseclib\Math\BigInteger::MODE_BCMATH);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,6 @@ class Unit_Math_BigInteger_GMPTest extends Unit_Math_BigInteger_TestCase
|
||||
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::ensureConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP);
|
||||
self::ensureConstant('MATH_BIGINTEGER_MODE', \phpseclib\Math\BigInteger::MODE_GMP);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,6 @@ class Unit_Math_BigInteger_InternalOpenSSLTest extends Unit_Math_BigInteger_Test
|
||||
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::ensureConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_INTERNAL);
|
||||
self::ensureConstant('MATH_BIGINTEGER_MODE', \phpseclib\Math\BigInteger::MODE_INTERNAL);
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ class Unit_Math_BigInteger_InternalTest extends Unit_Math_BigInteger_TestCase
|
||||
{
|
||||
parent::setUpBeforeClass();
|
||||
|
||||
self::ensureConstant('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_INTERNAL);
|
||||
self::ensureConstant('MATH_BIGINTEGER_MODE', \phpseclib\Math\BigInteger::MODE_INTERNAL);
|
||||
self::ensureConstant('MATH_BIGINTEGER_OPENSSL_DISABLE', true);
|
||||
}
|
||||
|
||||
|
@ -300,7 +300,7 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
|
||||
public function testDiffieHellmanKeyAgreement()
|
||||
{
|
||||
if (getenv('TRAVIS') && PHP_VERSION === '5.3.3'
|
||||
&& MATH_BIGINTEGER_MODE === MATH_BIGINTEGER_MODE_INTERNAL
|
||||
&& MATH_BIGINTEGER_MODE === \phpseclib\Math\BigInteger::MODE_INTERNAL
|
||||
) {
|
||||
$this->markTestIncomplete(
|
||||
'This test hangs on PHP 5.3.3 using internal mode.'
|
||||
|
Loading…
Reference in New Issue
Block a user