Skip to content

Commit

Permalink
Update to d3js 5.9.7 and phpseclib 1.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
sonertari committed Aug 13, 2019
1 parent 7b24568 commit fe71c5b
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/View/lib/d3.min.js

Large diffs are not rendered by default.

132 changes: 131 additions & 1 deletion src/View/lib/phpseclib/Crypt/RSA.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@
* PKCS#8 formatted private key
*/
define('CRYPT_RSA_PRIVATE_FORMAT_PKCS8', 8);
/**
* OpenSSH formatted private key
*/
define('CRYPT_RSA_PRIVATE_FORMAT_OPENSSH', 9);
/**#@-*/

/**#@+
Expand Down Expand Up @@ -878,6 +882,58 @@ function _convertPrivateKey($n, $e, $d, $primes, $exponents, $coefficients)
$key.= 'Private-MAC: ' . bin2hex($hash->hash($source)) . "\r\n";

return $key;
case CRYPT_RSA_PRIVATE_FORMAT_OPENSSH:
if ($num_primes != 2) {
return false;
}
$publicKey = pack('Na*Na*Na*', strlen('ssh-rsa'), 'ssh-rsa', strlen($raw['publicExponent']), $raw['publicExponent'], strlen($raw['modulus']), $raw['modulus']);
$privateKey = pack(
'Na*Na*Na*Na*Na*Na*Na*',
strlen('ssh-rsa'),
'ssh-rsa',
strlen($raw['modulus']),
$raw['modulus'],
strlen($raw['publicExponent']),
$raw['publicExponent'],
strlen($raw['privateExponent']),
$raw['privateExponent'],
strlen($raw['coefficient']),
$raw['coefficient'],
strlen($raw['prime1']),
$raw['prime1'],
strlen($raw['prime2']),
$raw['prime2']
);
$checkint = crypt_random_string(4);
$paddedKey = pack(
'a*Na*',
$checkint . $checkint . $privateKey,
strlen($this->comment),
$this->comment
);
$paddingLength = (7 * strlen($paddedKey)) % 8;
for ($i = 1; $i <= $paddingLength; $i++) {
$paddedKey.= chr($i);
}
$key = pack(
'Na*Na*Na*NNa*Na*',
strlen('none'),
'none',
strlen('none'),
'none',
0,
'',
1,
strlen($publicKey),
$publicKey,
strlen($paddedKey),
$paddedKey
);
$key = "openssh-key-v1\0$key";

return "-----BEGIN OPENSSH PRIVATE KEY-----\r\n" .
chunk_split(base64_encode($key), 70) .
"-----END OPENSSH PRIVATE KEY-----";
default: // eg. CRYPT_RSA_PRIVATE_FORMAT_PKCS1
$components = array();
foreach ($raw as $name => $value) {
Expand Down Expand Up @@ -1497,6 +1553,75 @@ function. As is, the definitive authority on this encoding scheme isn't the IET
}
$components['coefficients'] = array(2 => new Math_BigInteger($this->_string_shift($private, $length), -256));

return $components;
case CRYPT_RSA_PRIVATE_FORMAT_OPENSSH:
$components = array();
$decoded = $this->_extractBER($key);
$magic = $this->_string_shift($decoded, 15);
if ($magic !== "openssh-key-v1\0") {
return false;
}
$options = $this->_string_shift($decoded, 24);
// \0\0\0\4none = ciphername
// \0\0\0\4none = kdfname
// \0\0\0\0 = kdfoptions
// \0\0\0\1 = numkeys
if ($options != "\0\0\0\4none\0\0\0\4none\0\0\0\0\0\0\0\1") {
return false;
}
extract(unpack('Nlength', $this->_string_shift($decoded, 4)));
if (strlen($decoded) < $length) {
return false;
}
$publicKey = $this->_string_shift($decoded, $length);
extract(unpack('Nlength', $this->_string_shift($decoded, 4)));
if (strlen($decoded) < $length) {
return false;
}
$paddedKey = $this->_string_shift($decoded, $length);

if ($this->_string_shift($publicKey, 11) !== "\0\0\0\7ssh-rsa") {
return false;
}

$checkint1 = $this->_string_shift($paddedKey, 4);
$checkint2 = $this->_string_shift($paddedKey, 4);
if (strlen($checkint1) != 4 || $checkint1 !== $checkint2) {
return false;
}

if ($this->_string_shift($paddedKey, 11) !== "\0\0\0\7ssh-rsa") {
return false;
}

$values = array(
&$components['modulus'],
&$components['publicExponent'],
&$components['privateExponent'],
&$components['coefficients'][2],
&$components['primes'][1],
&$components['primes'][2]
);

foreach ($values as &$value) {
extract(unpack('Nlength', $this->_string_shift($paddedKey, 4)));
if (strlen($paddedKey) < $length) {
return false;
}
$value = new Math_BigInteger($this->_string_shift($paddedKey, $length), -256);
}

extract(unpack('Nlength', $this->_string_shift($paddedKey, 4)));
if (strlen($paddedKey) < $length) {
return false;
}
$components['comment'] = $this->_string_shift($decoded, $length);

$temp = $components['primes'][1]->subtract($this->one);
$components['exponents'] = array(1 => $components['publicExponent']->modInverse($temp));
$temp = $components['primes'][2]->subtract($this->one);
$components['exponents'][] = $components['publicExponent']->modInverse($temp);

return $components;
}
}
Expand Down Expand Up @@ -1653,7 +1778,8 @@ function loadKey($key, $type = false)
CRYPT_RSA_PRIVATE_FORMAT_PKCS1,
CRYPT_RSA_PRIVATE_FORMAT_XML,
CRYPT_RSA_PRIVATE_FORMAT_PUTTY,
CRYPT_RSA_PUBLIC_FORMAT_OPENSSH
CRYPT_RSA_PUBLIC_FORMAT_OPENSSH,
CRYPT_RSA_PRIVATE_FORMAT_OPENSSH
);
foreach ($types as $type) {
$components = $this->_parseKey($key, $type);
Expand Down Expand Up @@ -2301,6 +2427,10 @@ function _blind($x, $r, $i)
*/
function _equals($x, $y)
{
if (function_exists('hash_equals')) {
return hash_equals($x, $y);
}

if (strlen($x) != strlen($y)) {
return false;
}
Expand Down
148 changes: 107 additions & 41 deletions src/View/lib/phpseclib/File/ASN1.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,10 @@ function _decode_ber($encoded, $start = 0, $encoded_pos = 0)
$tag = 0;
// process septets (since the eighth bit is ignored, it's not an octet)
do {
$loop = ord($encoded[0]) >> 7;
$temp = ord($encoded[$encoded_pos++]);
$loop = $temp >> 7;
$tag <<= 7;
$tag |= ord($encoded[$encoded_pos++]) & 0x7F;
$tag |= $temp & 0x7F;
$start++;
} while ($loop);
}
Expand Down Expand Up @@ -515,24 +516,7 @@ function _decode_ber($encoded, $start = 0, $encoded_pos = 0)
}
break;
case FILE_ASN1_TYPE_OBJECT_IDENTIFIER:
$temp = ord($content[$content_pos++]);
$current['content'] = sprintf('%d.%d', floor($temp / 40), $temp % 40);
$valuen = 0;
// process septets
$content_len = strlen($content);
while ($content_pos < $content_len) {
$temp = ord($content[$content_pos++]);
$valuen <<= 7;
$valuen |= $temp & 0x7F;
if (~$temp & 0x80) {
$current['content'].= ".$valuen";
$valuen = 0;
}
}
// the eighth bit of the last byte should not be 1
//if ($temp >> 7) {
// return false;
//}
$current['content'] = $this->_decodeOID(substr($content, $content_pos));
break;
/* Each character string type shall be encoded as if it had been declared:
[UNIVERSAL x] IMPLICIT OCTET STRING
Expand Down Expand Up @@ -1111,27 +1095,7 @@ function _encode_der($source, $mapping, $idx = null, $special = array())
$value = base64_decode($source);
break;
case FILE_ASN1_TYPE_OBJECT_IDENTIFIER:
$oid = preg_match('#(?:\d+\.)+#', $source) ? $source : array_search($source, $this->oids);
if ($oid === false) {
user_error('Invalid OID');
return false;
}
$value = '';
$parts = explode('.', $oid);
$value = chr(40 * $parts[0] + $parts[1]);
for ($i = 2; $i < count($parts); $i++) {
$temp = '';
if (!$parts[$i]) {
$temp = "\0";
} else {
while ($parts[$i]) {
$temp = chr(0x80 | ($parts[$i] & 0x7F)) . $temp;
$parts[$i] >>= 7;
}
$temp[strlen($temp) - 1] = $temp[strlen($temp) - 1] & chr(0x7F);
}
$value.= $temp;
}
$value = $this->_encodeOID($source);
break;
case FILE_ASN1_TYPE_ANY:
$loc = $this->location;
Expand Down Expand Up @@ -1230,6 +1194,108 @@ function _encodeLength($length)
return pack('Ca*', 0x80 | strlen($temp), $temp);
}

/**
* BER-decode the OID
*
* Called by _decode_ber()
*
* @access private
* @param string $content
* @return string
*/
function _decodeOID($content)
{
static $eighty;
if (!$eighty) {
$eighty = new Math_BigInteger(80);
}

$oid = array();
$pos = 0;
$len = strlen($content);
$n = new Math_BigInteger();
while ($pos < $len) {
$temp = ord($content[$pos++]);
$n = $n->bitwise_leftShift(7);
$n = $n->bitwise_or(new Math_BigInteger($temp & 0x7F));
if (~$temp & 0x80) {
$oid[] = $n;
$n = new Math_BigInteger();
}
}
$part1 = array_shift($oid);
$first = floor(ord($content[0]) / 40);
/*
"This packing of the first two object identifier components recognizes that only three values are allocated from the root
node, and at most 39 subsequent values from nodes reached by X = 0 and X = 1."
-- https://www.itu.int/ITU-T/studygroups/com17/languages/X.690-0207.pdf#page=22
*/
if ($first <= 2) { // ie. 0 <= ord($content[0]) < 120 (0x78)
array_unshift($oid, ord($content[0]) % 40);
array_unshift($oid, $first);
} else {
array_unshift($oid, $part1->subtract($eighty));
array_unshift($oid, 2);
}

return implode('.', $oid);
}

/**
* DER-encode the OID
*
* Called by _encode_der()
*
* @access private
* @param string $content
* @return string
*/
function _encodeOID($source)
{
static $mask, $zero, $forty;
if (!$mask) {
$mask = new Math_BigInteger(0x7F);
$zero = new Math_BigInteger();
$forty = new Math_BigInteger(40);
}

$oid = preg_match('#(?:\d+\.)+#', $source) ? $source : array_search($source, $this->oids);
if ($oid === false) {
user_error('Invalid OID');
return false;
}
$parts = explode('.', $oid);
$part1 = array_shift($parts);
$part2 = array_shift($parts);

$first = new Math_BigInteger($part1);
$first = $first->multiply($forty);
$first = $first->add(new Math_BigInteger($part2));

array_unshift($parts, $first->toString());

$value = '';
foreach ($parts as $part) {
if (!$part) {
$temp = "\0";
} else {
$temp = '';
$part = new Math_BigInteger($part);
while (!$part->equals($zero)) {
$submask = $part->bitwise_and($mask);
$submask->setPrecision(8);
$temp = (chr(0x80) | $submask->toBytes()) . $temp;
$part = $part->bitwise_rightShift(7);
}
$temp[strlen($temp) - 1] = $temp[strlen($temp) - 1] & chr(0x7F);
}
$value.= $temp;
}

return $value;
}

/**
* BER-decode the time (using UNIX time)
*
Expand Down
12 changes: 11 additions & 1 deletion src/View/lib/phpseclib/Math/BigInteger.php
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,9 @@ function __construct($x = 0, $base = 10)
// (?<=^|-)0*: find any 0's that are preceded by the start of the string or by a - (ie. octals)
// [^-0-9].*: find any non-numeric characters and then any characters that follow that
$x = preg_replace('#(?<!^)(?:-).*|(?<=^|-)0*|[^-0-9].*#', '', $x);
if (!strlen($x) || $x == '-') {
$x = '0';
}

switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP:
Expand Down Expand Up @@ -2724,7 +2727,14 @@ function compare($y)
{
switch (MATH_BIGINTEGER_MODE) {
case MATH_BIGINTEGER_MODE_GMP:
return gmp_cmp($this->value, $y->value);
$r = gmp_cmp($this->value, $y->value);
if ($r < -1) {
$r = -1;
}
if ($r > 1) {
$r = 1;
}
return $r;
case MATH_BIGINTEGER_MODE_BCMATH:
return bccomp($this->value, $y->value, 0);
}
Expand Down
8 changes: 6 additions & 2 deletions src/View/lib/phpseclib/Net/SSH2.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@
*/
define('NET_SSH2_READ_REGEX', 2);
/**
* Returns when a string matching the regular expression $expect is found
* Returns whenever a data packet is received.
*
* Some data packets may only contain a single character so it may be necessary
* to call read() multiple times when using this option
*/
define('NET_SSH2_READ_NEXT', 3);
/**#@-*/
Expand Down Expand Up @@ -3412,7 +3415,7 @@ function _reconnect()
return false;
}
foreach ($this->auth as $auth) {
$result = call_user_func_array(array(&$this, 'parent::login'), $auth);
$result = call_user_func_array(array(&$this, 'login'), $auth);
}
return $result;
}
Expand Down Expand Up @@ -3816,6 +3819,7 @@ function _get_channel_packet($client_channel, $skip_extended = false)
// on windows this returns a "Warning: Invalid CRT parameters detected" error
if (!@stream_select($read, $write, $except, $sec, $usec) && !count($read)) {
$this->is_timeout = true;
$this->_close_channel($client_channel);
return true;
}
$elapsed = strtok(microtime(), ' ') + strtok('') - $start;
Expand Down

0 comments on commit fe71c5b

Please sign in to comment.