mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-12-29 04:23:34 +00:00
Merge branch 'jworman'
This commit is contained in:
commit
71fa541c9a
2
AUTHORS
2
AUTHORS
@ -4,4 +4,4 @@ phpseclib Developers: monnerat (Patrick Monnerat)
|
||||
bantu (Andreas Fischer)
|
||||
petrich (Hans-Jürgen Petrich)
|
||||
GrahamCampbell (Graham Campbell)
|
||||
hc-jworman
|
||||
jack-worman (Jack Worman)
|
||||
|
@ -26,7 +26,7 @@ return (new PhpCsFixer\Config())
|
||||
'phpdoc_trim_consecutive_blank_line_separation' => true,
|
||||
'phpdoc_trim' => true,
|
||||
|
||||
'@PHP71Migration:risky' => true,
|
||||
'@PHP73Migration' => true,
|
||||
'@PHP81Migration' => true,
|
||||
'@PHP80Migration:risky' => true,
|
||||
]
|
||||
);
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
<arg name="extensions" value="php"/>
|
||||
<arg name="basepath" value=".."/>
|
||||
<arg name="report" value="emacs"/>
|
||||
<arg name="report" value="diff"/>
|
||||
<arg value="s"/>
|
||||
<arg value="n"/>
|
||||
<arg value="p"/>
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -21,7 +21,7 @@
|
||||
"asn.1",
|
||||
"BigInteger"
|
||||
],
|
||||
"homepage": "http://phpseclib.sourceforge.net",
|
||||
"homepage": "https://phpseclib.com/",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
@ -48,10 +48,16 @@
|
||||
"name": "Graham Campbell",
|
||||
"email": "graham@alt-three.com",
|
||||
"role": "Developer"
|
||||
},
|
||||
{
|
||||
"name": "Jack Worman",
|
||||
"email": "jack.worman@gmail.com",
|
||||
"role": "Developer",
|
||||
"homepage": "https://jackworman.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.3",
|
||||
"php": ">=8.1",
|
||||
"paragonie/constant_time_encoding": "^2"
|
||||
},
|
||||
"require-dev": {
|
||||
|
@ -536,20 +536,13 @@ class Blowfish extends BlockCipher
|
||||
$p[14] ^ $key[14],
|
||||
$p[15] ^ $key[15],
|
||||
$p[16] ^ $key[0],
|
||||
$p[17] ^ $key[1]
|
||||
$p[17] ^ $key[1],
|
||||
];
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
[ $p[0], $p[1]] = self::encryptBlockHelper( 0, 0, $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[ $p[2], $p[3]] = self::encryptBlockHelper($p[ 0], $p[ 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[ $p[4], $p[5]] = self::encryptBlockHelper($p[ 2], $p[ 3], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[ $p[6], $p[7]] = self::encryptBlockHelper($p[ 4], $p[ 5], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[ $p[8], $p[9]] = self::encryptBlockHelper($p[ 6], $p[ 7], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[$p[10], $p[11]] = self::encryptBlockHelper($p[ 8], $p[ 9], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[$p[12], $p[13]] = self::encryptBlockHelper($p[10], $p[11], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[$p[14], $p[15]] = self::encryptBlockHelper($p[12], $p[13], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[$p[16], $p[17]] = self::encryptBlockHelper($p[14], $p[15], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
// @codingStandardsIgnoreEnd
|
||||
[$p[0], $p[1]] = self::encryptBlockHelper(0, 0, $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2; $i < 18; $i += 2) {
|
||||
[$p[$i], $p[$i + 1]] = self::encryptBlockHelper($p[$i - 2], $p[$i - 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
|
||||
[$sbox0[0], $sbox0[1]] = self::encryptBlockHelper($p[16], $p[17], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2; $i < 256; $i += 2) {
|
||||
@ -605,20 +598,13 @@ class Blowfish extends BlockCipher
|
||||
$p[14] ^ $key[14],
|
||||
$p[15] ^ $key[15],
|
||||
$p[16] ^ $key[0],
|
||||
$p[17] ^ $key[1]
|
||||
$p[17] ^ $key[1],
|
||||
];
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
[ $p[0], $p[1]] = self::encryptBlockHelper($data[ 0] , $data[ 1] , $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[ $p[2], $p[3]] = self::encryptBlockHelper($data[ 2] ^ $p[ 0], $data[ 3] ^ $p[ 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[ $p[4], $p[5]] = self::encryptBlockHelper($data[ 4] ^ $p[ 2], $data[ 5] ^ $p[ 3], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[ $p[6], $p[7]] = self::encryptBlockHelper($data[ 6] ^ $p[ 4], $data[ 7] ^ $p[ 5], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[ $p[8], $p[9]] = self::encryptBlockHelper($data[ 8] ^ $p[ 6], $data[ 9] ^ $p[ 7], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[$p[10], $p[11]] = self::encryptBlockHelper($data[10] ^ $p[ 8], $data[11] ^ $p[ 9], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[$p[12], $p[13]] = self::encryptBlockHelper($data[12] ^ $p[10], $data[13] ^ $p[11], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[$p[14], $p[15]] = self::encryptBlockHelper($data[14] ^ $p[12], $data[15] ^ $p[13], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
[$p[16], $p[17]] = self::encryptBlockHelper($data[ 0] ^ $p[14], $data[ 1] ^ $p[15], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
// @codingStandardsIgnoreEnd
|
||||
[$p[0], $p[1]] = self::encryptBlockHelper($data[0], $data[1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2, $j = 2; $i < 18; $i += 2, $j = ($j + 2) % 16) {
|
||||
[$p[$i], $p[$i + 1]] = self::encryptBlockHelper($data[$j] ^ $p[$i - 2], $data[$j + 1] ^ $p[$i - 1], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
}
|
||||
|
||||
[$sbox0[0], $sbox0[1]] = self::encryptBlockHelper($data[2] ^ $p[16], $data[3] ^ $p[17], $sbox0, $sbox1, $sbox2, $sbox3, $p);
|
||||
for ($i = 2, $j = 4; $i < 256; $i += 2, $j = ($j + 2) % 16) { // instead of 16 maybe count($data) would be better?
|
||||
|
@ -15,9 +15,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\Common;
|
||||
|
||||
use phpseclib3\Crypt\DSA;
|
||||
use phpseclib3\Crypt\Hash;
|
||||
use phpseclib3\Crypt\RSA;
|
||||
use phpseclib3\Exception\NoKeyLoadedException;
|
||||
use phpseclib3\Exception\UnsupportedFormatException;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
@ -152,7 +150,7 @@ abstract class AsymmetricKey
|
||||
}
|
||||
|
||||
$components['format'] = $format;
|
||||
$components['secret'] = $components['secret'] ?? '';
|
||||
$components['secret'] ??= '';
|
||||
$comment = $components['comment'] ?? null;
|
||||
$new = static::onLoad($components);
|
||||
$new->format = $format;
|
||||
@ -226,7 +224,7 @@ abstract class AsymmetricKey
|
||||
}
|
||||
|
||||
$components['format'] = $format;
|
||||
$components['secret'] = $components['secret'] ?? '';
|
||||
$components['secret'] ??= '';
|
||||
|
||||
$new = static::onLoad($components);
|
||||
$new->format = $format;
|
||||
|
@ -20,7 +20,6 @@ namespace phpseclib3\Crypt\Common\Formats\Keys;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\AES;
|
||||
use phpseclib3\Crypt\Random;
|
||||
use phpseclib3\Exception\UnsupportedFormatException;
|
||||
|
||||
/**
|
||||
* OpenSSH Formatted RSA Key Handler
|
||||
@ -67,7 +66,7 @@ abstract class OpenSSH
|
||||
// key format is described here:
|
||||
// https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.key?annotate=HEAD
|
||||
|
||||
if (strpos($key, 'BEGIN OPENSSH PRIVATE KEY') !== false) {
|
||||
if (str_contains($key, 'BEGIN OPENSSH PRIVATE KEY')) {
|
||||
$key = preg_replace('#(?:^-.*?-[\r\n]*$)|\s#ms', '', $key);
|
||||
$key = Strings::base64_decode($key);
|
||||
$magic = Strings::shift($key, 15);
|
||||
|
@ -120,7 +120,7 @@ abstract class PuTTY
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
|
||||
}
|
||||
|
||||
if (strpos($key, 'BEGIN SSH2 PUBLIC KEY') !== false) {
|
||||
if (str_contains($key, 'BEGIN SSH2 PUBLIC KEY')) {
|
||||
$lines = preg_split('#[\r\n]+#', $key);
|
||||
switch (true) {
|
||||
case $lines[0] != '---- BEGIN SSH2 PUBLIC KEY ----':
|
||||
@ -129,9 +129,7 @@ abstract class PuTTY
|
||||
throw new \UnexpectedValueException('Key doesn\'t end with ---- END SSH2 PUBLIC KEY ----');
|
||||
}
|
||||
$lines = array_splice($lines, 1, -1);
|
||||
$lines = array_map(function ($line) {
|
||||
return rtrim($line, "\r\n");
|
||||
}, $lines);
|
||||
$lines = array_map(fn ($line) => rtrim($line, "\r\n"), $lines);
|
||||
$data = $current = '';
|
||||
$values = [];
|
||||
$in_value = false;
|
||||
|
@ -66,7 +66,7 @@ abstract class PKCS8 extends Progenitor
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
|
||||
}
|
||||
|
||||
$isPublic = strpos($key, 'PUBLIC') !== false;
|
||||
$isPublic = str_contains($key, 'PUBLIC');
|
||||
|
||||
$key = parent::load($key, $password);
|
||||
|
||||
|
@ -70,7 +70,7 @@ abstract class PKCS8 extends Progenitor
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
|
||||
}
|
||||
|
||||
$isPublic = strpos($key, 'PUBLIC') !== false;
|
||||
$isPublic = str_contains($key, 'PUBLIC');
|
||||
|
||||
$key = parent::load($key, $password);
|
||||
|
||||
|
@ -18,7 +18,6 @@ use phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards;
|
||||
use phpseclib3\Crypt\Hash;
|
||||
use phpseclib3\Crypt\Random;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
use phpseclib3\Math\PrimeField\Integer;
|
||||
|
||||
class Ed25519 extends TwistedEdwards
|
||||
{
|
||||
@ -182,7 +181,7 @@ class Ed25519 extends TwistedEdwards
|
||||
|
||||
return [
|
||||
'dA' => $dA,
|
||||
'secret' => $str
|
||||
'secret' => $str,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ class Ed448 extends TwistedEdwards
|
||||
|
||||
return [
|
||||
'dA' => $dA,
|
||||
'secret' => $str
|
||||
'secret' => $str,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -110,9 +110,7 @@ abstract class OpenSSH extends Progenitor
|
||||
$name = $reflect->getShortName();
|
||||
|
||||
$oid = self::$curveOIDs[$name];
|
||||
$aliases = array_filter(self::$curveOIDs, function ($v) use ($oid) {
|
||||
return $v == $oid;
|
||||
});
|
||||
$aliases = array_filter(self::$curveOIDs, fn ($v) => $v == $oid);
|
||||
$aliases = array_keys($aliases);
|
||||
|
||||
for ($i = 0; $i < count($aliases); $i++) {
|
||||
|
@ -79,7 +79,7 @@ abstract class PKCS8 extends Progenitor
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
|
||||
}
|
||||
|
||||
$isPublic = strpos($key, 'PUBLIC') !== false;
|
||||
$isPublic = str_contains($key, 'PUBLIC');
|
||||
|
||||
$key = parent::load($key, $password);
|
||||
|
||||
|
@ -49,9 +49,9 @@ abstract class PKCS1 extends Progenitor
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
|
||||
}
|
||||
|
||||
if (strpos($key, 'PUBLIC') !== false) {
|
||||
if (str_contains($key, 'PUBLIC')) {
|
||||
$components = ['isPublicKey' => true];
|
||||
} elseif (strpos($key, 'PRIVATE') !== false) {
|
||||
} elseif (str_contains($key, 'PRIVATE')) {
|
||||
$components = ['isPublicKey' => false];
|
||||
} else {
|
||||
$components = [];
|
||||
|
@ -71,9 +71,9 @@ abstract class PKCS8 extends Progenitor
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
|
||||
}
|
||||
|
||||
if (strpos($key, 'PUBLIC') !== false) {
|
||||
if (str_contains($key, 'PUBLIC')) {
|
||||
$components = ['isPublicKey' => true];
|
||||
} elseif (strpos($key, 'PRIVATE') !== false) {
|
||||
} elseif (str_contains($key, 'PRIVATE')) {
|
||||
$components = ['isPublicKey' => false];
|
||||
} else {
|
||||
$components = [];
|
||||
|
@ -103,7 +103,7 @@ abstract class PSS extends Progenitor
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
|
||||
}
|
||||
|
||||
$components = ['isPublicKey' => strpos($key, 'PUBLIC') !== false];
|
||||
$components = ['isPublicKey' => str_contains($key, 'PUBLIC')];
|
||||
|
||||
$key = parent::load($key, $password);
|
||||
|
||||
|
@ -149,15 +149,9 @@ abstract class Raw
|
||||
'e' => clone $e,
|
||||
'n' => clone $n,
|
||||
'd' => clone $d,
|
||||
'primes' => array_map(function ($var) {
|
||||
return clone $var;
|
||||
}, $primes),
|
||||
'exponents' => array_map(function ($var) {
|
||||
return clone $var;
|
||||
}, $exponents),
|
||||
'coefficients' => array_map(function ($var) {
|
||||
return clone $var;
|
||||
}, $coefficients),
|
||||
'primes' => array_map(fn ($var) => clone $var, $primes),
|
||||
'exponents' => array_map(fn ($var) => clone $var, $exponents),
|
||||
'coefficients' => array_map(fn ($var) => clone $var, $coefficients),
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class BadConfigurationException extends \RuntimeException
|
||||
class BadConfigurationException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class BadDecryptionException extends \RuntimeException
|
||||
class BadDecryptionException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class BadModeException extends \RuntimeException
|
||||
class BadModeException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class ConnectionClosedException extends \RuntimeException
|
||||
class ConnectionClosedException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
12
phpseclib/Exception/ExceptionInterface.php
Normal file
12
phpseclib/Exception/ExceptionInterface.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Exception;
|
||||
|
||||
/**
|
||||
* Used to mark exceptions originating from this library.
|
||||
*/
|
||||
interface ExceptionInterface
|
||||
{
|
||||
}
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class FileNotFoundException extends \RuntimeException
|
||||
class FileNotFoundException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class InconsistentSetupException extends \RuntimeException
|
||||
class InconsistentSetupException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class InsufficientSetupException extends \RuntimeException
|
||||
class InsufficientSetupException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class NoKeyLoadedException extends \RuntimeException
|
||||
class NoKeyLoadedException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class NoSupportedAlgorithmsException extends \RuntimeException
|
||||
class NoSupportedAlgorithmsException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
9
phpseclib/Exception/RuntimeException.php
Normal file
9
phpseclib/Exception/RuntimeException.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Exception;
|
||||
|
||||
class RuntimeException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class UnableToConnectException extends \RuntimeException
|
||||
class UnableToConnectException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class UnsupportedAlgorithmException extends \RuntimeException
|
||||
class UnsupportedAlgorithmException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class UnsupportedCurveException extends \RuntimeException
|
||||
class UnsupportedCurveException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class UnsupportedFormatException extends \RuntimeException
|
||||
class UnsupportedFormatException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -20,6 +20,6 @@ namespace phpseclib3\Exception;
|
||||
*
|
||||
* @author Jim Wigginton <terrafrost@php.net>
|
||||
*/
|
||||
class UnsupportedOperationException extends \RuntimeException
|
||||
class UnsupportedOperationException extends \RuntimeException implements ExceptionInterface
|
||||
{
|
||||
}
|
||||
|
@ -1252,7 +1252,7 @@ abstract class ASN1
|
||||
}
|
||||
$prefix = substr($content, 0, 2) >= 50 ? '19' : '20';
|
||||
$content = $prefix . $content;
|
||||
} elseif (strpos($content, '.') !== false) {
|
||||
} elseif (str_contains($content, '.')) {
|
||||
$format .= '.u';
|
||||
}
|
||||
|
||||
@ -1260,7 +1260,7 @@ abstract class ASN1
|
||||
$content = substr($content, 0, -1) . '+0000';
|
||||
}
|
||||
|
||||
if (strpos($content, '-') !== false || strpos($content, '+') !== false) {
|
||||
if (str_contains($content, '-') || str_contains($content, '+')) {
|
||||
$format .= 'O';
|
||||
}
|
||||
|
||||
|
@ -1102,8 +1102,8 @@ class X509
|
||||
if (isset($parts['query'])) {
|
||||
$path .= '?' . $parts['query'];
|
||||
}
|
||||
fputs($fsock, "GET $path HTTP/1.0\r\n");
|
||||
fputs($fsock, "Host: $parts[host]\r\n\r\n");
|
||||
fwrite($fsock, "GET $path HTTP/1.0\r\n");
|
||||
fwrite($fsock, "Host: $parts[host]\r\n\r\n");
|
||||
$line = fgets($fsock, 1024);
|
||||
if (strlen($line) < 3) {
|
||||
return false;
|
||||
@ -1842,9 +1842,7 @@ class X509
|
||||
$value = array_pop($value); // Always strip data type.
|
||||
}
|
||||
} elseif (is_object($value) && $value instanceof Element) {
|
||||
$callback = function ($x) {
|
||||
return '\x' . bin2hex($x[0]);
|
||||
};
|
||||
$callback = fn ($x) => '\x' . bin2hex($x[0]);
|
||||
$value = strtoupper(preg_replace_callback('#[^\x20-\x7E]#', $callback, $value->element));
|
||||
}
|
||||
$output .= $desc . '=' . $value;
|
||||
|
@ -665,9 +665,7 @@ class BigInteger implements \JsonSerializable
|
||||
public static function min(BigInteger ...$nums): BigInteger
|
||||
{
|
||||
$class = self::$mainEngine;
|
||||
$nums = array_map(function ($num) {
|
||||
return $num->value;
|
||||
}, $nums);
|
||||
$nums = array_map(fn ($num) => $num->value, $nums);
|
||||
return new static($class::min(...$nums));
|
||||
}
|
||||
|
||||
@ -677,9 +675,7 @@ class BigInteger implements \JsonSerializable
|
||||
public static function max(BigInteger ...$nums): BigInteger
|
||||
{
|
||||
$class = self::$mainEngine;
|
||||
$nums = array_map(function ($num) {
|
||||
return $num->value;
|
||||
}, $nums);
|
||||
$nums = array_map(fn ($num) => $num->value, $nums);
|
||||
return new static($class::max(...$nums));
|
||||
}
|
||||
|
||||
@ -755,9 +751,7 @@ class BigInteger implements \JsonSerializable
|
||||
public function createRecurringModuloFunction()
|
||||
{
|
||||
$func = $this->value->createRecurringModuloFunction();
|
||||
return function (BigInteger $x) use ($func) {
|
||||
return new static($func($x->value));
|
||||
};
|
||||
return fn (BigInteger $x) => new static($func($x->value));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -769,8 +763,6 @@ class BigInteger implements \JsonSerializable
|
||||
*/
|
||||
public function bitwise_split(int $split): array
|
||||
{
|
||||
return array_map(function ($val) {
|
||||
return new static($val);
|
||||
}, $this->value->bitwise_split($split));
|
||||
return array_map(fn ($val) => new static($val), $this->value->bitwise_split($split));
|
||||
}
|
||||
}
|
||||
|
@ -537,9 +537,7 @@ class GMP extends Engine
|
||||
public function createRecurringModuloFunction(): \Closure
|
||||
{
|
||||
$temp = $this->value;
|
||||
return function (GMP $x) use ($temp) {
|
||||
return new GMP($x->value % $temp);
|
||||
};
|
||||
return fn (GMP $x) => new GMP($x->value % $temp);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ abstract class OpenSSL
|
||||
throw new \UnexpectedValueException(openssl_error_string());
|
||||
}
|
||||
|
||||
$class = get_class($x);
|
||||
$class = $x::class;
|
||||
return new $class($result, 256);
|
||||
}
|
||||
}
|
||||
|
@ -550,7 +550,7 @@ abstract class PHP extends Engine
|
||||
$lhs = new static();
|
||||
$rhs = new static();
|
||||
}
|
||||
if (static::class != get_class($temp)) {
|
||||
if (static::class != $temp::class) {
|
||||
$temp = new static();
|
||||
$lhs = new static();
|
||||
$rhs = new static();
|
||||
|
@ -1027,8 +1027,8 @@ class SFTP extends SSH2
|
||||
}
|
||||
break;
|
||||
case 'mode':
|
||||
$a[$sort] &= 07777;
|
||||
$b[$sort] &= 07777;
|
||||
$a[$sort] &= 0o7777;
|
||||
$b[$sort] &= 0o7777;
|
||||
// fall-through
|
||||
default:
|
||||
if ($a[$sort] === $b[$sort]) {
|
||||
@ -1450,7 +1450,7 @@ class SFTP extends SSH2
|
||||
$filename = $temp;
|
||||
}
|
||||
|
||||
$attr = pack('N2', Attribute::PERMISSIONS, $mode & 07777);
|
||||
$attr = pack('N2', Attribute::PERMISSIONS, $mode & 0o7777);
|
||||
if (!$this->setstat($filename, $attr, $recursive)) {
|
||||
return false;
|
||||
}
|
||||
@ -2183,7 +2183,7 @@ class SFTP extends SSH2
|
||||
} elseif (is_callable($local_file)) {
|
||||
$local_file($temp);
|
||||
} else {
|
||||
fputs($fp, $temp);
|
||||
fwrite($fp, $temp);
|
||||
}
|
||||
if (is_callable($progressCallback)) {
|
||||
call_user_func($progressCallback, $offset);
|
||||
@ -2825,26 +2825,26 @@ class SFTP extends SSH2
|
||||
{
|
||||
// values come from http://lxr.free-electrons.com/source/include/uapi/linux/stat.h#L12
|
||||
// see, also, http://linux.die.net/man/2/stat
|
||||
switch ($mode & 0170000) {// ie. 1111 0000 0000 0000
|
||||
case 0000000: // no file type specified - figure out the file type using alternative means
|
||||
switch ($mode & 0o170000) {// ie. 1111 0000 0000 0000
|
||||
case 0: // no file type specified - figure out the file type using alternative means
|
||||
return false;
|
||||
case 0040000:
|
||||
case 0o040000:
|
||||
return FileType::DIRECTORY;
|
||||
case 0100000:
|
||||
case 0o100000:
|
||||
return FileType::REGULAR;
|
||||
case 0120000:
|
||||
case 0o120000:
|
||||
return FileType::SYMLINK;
|
||||
// new types introduced in SFTPv5+
|
||||
// http://tools.ietf.org/html/draft-ietf-secsh-filexfer-05#section-5.2
|
||||
case 0010000: // named pipe (fifo)
|
||||
case 0o010000: // named pipe (fifo)
|
||||
return FileType::FIFO;
|
||||
case 0020000: // character special
|
||||
case 0o020000: // character special
|
||||
return FileType::CHAR_DEVICE;
|
||||
case 0060000: // block special
|
||||
case 0o060000: // block special
|
||||
return FileType::BLOCK_DEVICE;
|
||||
case 0140000: // socket
|
||||
case 0o140000: // socket
|
||||
return FileType::SOCKET;
|
||||
case 0160000: // whiteout
|
||||
case 0o160000: // whiteout
|
||||
// "SPECIAL should be used for files that are of
|
||||
// a known type which cannot be expressed in the protocol"
|
||||
return FileType::SPECIAL;
|
||||
@ -3030,7 +3030,7 @@ class SFTP extends SSH2
|
||||
*
|
||||
* Makes sure that only the last 1MB worth of packets will be logged
|
||||
*/
|
||||
private function append_log(string $message_number, string $message)
|
||||
private function append_log(string $message_number, string $message): void
|
||||
{
|
||||
$this->append_log_helper(
|
||||
NET_SFTP_LOGGING,
|
||||
|
@ -67,6 +67,7 @@ use phpseclib3\Crypt\Twofish;
|
||||
use phpseclib3\Exception\ConnectionClosedException;
|
||||
use phpseclib3\Exception\InsufficientSetupException;
|
||||
use phpseclib3\Exception\NoSupportedAlgorithmsException;
|
||||
use phpseclib3\Exception\RuntimeException;
|
||||
use phpseclib3\Exception\UnableToConnectException;
|
||||
use phpseclib3\Exception\UnsupportedAlgorithmException;
|
||||
use phpseclib3\Exception\UnsupportedCurveException;
|
||||
@ -155,7 +156,7 @@ class SSH2
|
||||
/**
|
||||
* Outputs the message numbers real-time
|
||||
*/
|
||||
const LOG_SIMPLE_REALTIME = 5;
|
||||
public const LOG_SIMPLE_REALTIME = 5;
|
||||
/**
|
||||
* Make sure that the log never gets larger than this
|
||||
*
|
||||
@ -1172,7 +1173,7 @@ class SSH2
|
||||
$this->identifier = $this->generate_identifier();
|
||||
|
||||
if ($this->send_id_string_first) {
|
||||
fputs($this->fsock, $this->identifier . "\r\n");
|
||||
fwrite($this->fsock, $this->identifier . "\r\n");
|
||||
}
|
||||
|
||||
/* According to the SSH2 specs,
|
||||
@ -1251,7 +1252,7 @@ class SSH2
|
||||
}
|
||||
|
||||
if (!$this->send_id_string_first) {
|
||||
fputs($this->fsock, $this->identifier . "\r\n");
|
||||
fwrite($this->fsock, $this->identifier . "\r\n");
|
||||
}
|
||||
|
||||
if (!$this->send_kex_first) {
|
||||
@ -1500,8 +1501,8 @@ class SSH2
|
||||
|
||||
$exchange_hash_rfc4419 = '';
|
||||
|
||||
if (strpos($this->kex_algorithm, 'curve25519-sha256') === 0 || strpos($this->kex_algorithm, 'ecdh-sha2-nistp') === 0) {
|
||||
$curve = strpos($this->kex_algorithm, 'curve25519-sha256') === 0 ?
|
||||
if (str_starts_with($this->kex_algorithm, 'curve25519-sha256') || str_starts_with($this->kex_algorithm, 'ecdh-sha2-nistp')) {
|
||||
$curve = str_starts_with($this->kex_algorithm, 'curve25519-sha256') ?
|
||||
'Curve25519' :
|
||||
substr($this->kex_algorithm, 10);
|
||||
$ourPrivate = EC::createKey($curve);
|
||||
@ -1509,7 +1510,7 @@ class SSH2
|
||||
$clientKexInitMessage = MessageTypeExtra::KEX_ECDH_INIT;
|
||||
$serverKexReplyMessage = MessageTypeExtra::KEX_ECDH_REPLY;
|
||||
} else {
|
||||
if (strpos($this->kex_algorithm, 'diffie-hellman-group-exchange') === 0) {
|
||||
if (str_starts_with($this->kex_algorithm, 'diffie-hellman-group-exchange')) {
|
||||
$dh_group_sizes_packed = pack(
|
||||
'NNN',
|
||||
$this->kex_dh_group_size_min,
|
||||
@ -3264,18 +3265,18 @@ class SSH2
|
||||
$cmf = ord($payload[0]);
|
||||
$cm = $cmf & 0x0F;
|
||||
if ($cm != 8) { // deflate
|
||||
user_error("Only CM = 8 ('deflate') is supported ($cm)");
|
||||
throw new UnsupportedAlgorithmException("Only CM = 8 ('deflate') is supported ($cm)");
|
||||
}
|
||||
$cinfo = ($cmf & 0xF0) >> 4;
|
||||
if ($cinfo > 7) {
|
||||
user_error("CINFO above 7 is not allowed ($cinfo)");
|
||||
throw new RuntimeException("CINFO above 7 is not allowed ($cinfo)");
|
||||
}
|
||||
$windowSize = 1 << ($cinfo + 8);
|
||||
|
||||
$flg = ord($payload[1]);
|
||||
//$fcheck = $flg && 0x0F;
|
||||
if ((($cmf << 8) | $flg) % 31) {
|
||||
user_error('fcheck failed');
|
||||
throw new RuntimeException('fcheck failed');
|
||||
}
|
||||
$fdict = boolval($flg & 0x20);
|
||||
$flevel = ($flg & 0xC0) >> 6;
|
||||
@ -3930,7 +3931,7 @@ class SSH2
|
||||
$packet .= $this->encrypt && $this->encrypt->usesNonce() ? $this->encrypt->getTag() : $hmac;
|
||||
|
||||
$start = microtime(true);
|
||||
$sent = @fputs($this->fsock, $packet);
|
||||
$sent = @fwrite($this->fsock, $packet);
|
||||
$stop = microtime(true);
|
||||
|
||||
if (defined('NET_SSH2_LOGGING')) {
|
||||
@ -3976,17 +3977,9 @@ class SSH2
|
||||
/**
|
||||
* Logs data packet helper
|
||||
*
|
||||
* @param int $constant
|
||||
* @param string $message_number
|
||||
* @param string $message
|
||||
* @param array &$message_number_log
|
||||
* @param array &$message_log
|
||||
* @param int &$log_size
|
||||
* @param resource &$realtime_log_file
|
||||
* @param bool &$realtime_log_wrap
|
||||
* @param int &$realtime_log_size
|
||||
*/
|
||||
protected function append_log_helper(int $constant, string $message_number, string $message, array &$message_number_log, array &$message_log, int &$log_size, &$realtime_log_file, bool &$realtime_log_wrap, int &$realtime_log_size)
|
||||
protected function append_log_helper(int $constant, string $message_number, string $message, array &$message_number_log, array &$message_log, int &$log_size, &$realtime_log_file, bool &$realtime_log_wrap, int &$realtime_log_size): void
|
||||
{
|
||||
// remove the byte identifying the message type from all but the first two messages (ie. the identification strings)
|
||||
if (strlen($message_number) > 2) {
|
||||
@ -4056,7 +4049,7 @@ class SSH2
|
||||
$realtime_log_size = strlen($entry);
|
||||
$realtime_log_wrap = true;
|
||||
}
|
||||
fputs($realtime_log_file, $entry);
|
||||
fwrite($realtime_log_file, $entry);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4195,9 +4188,7 @@ class SSH2
|
||||
$output .= str_pad(dechex($j), 7, '0', STR_PAD_LEFT) . '0 ';
|
||||
}
|
||||
$fragment = Strings::shift($current_log, $this->log_short_width);
|
||||
$hex = substr(preg_replace_callback('#.#s', function ($matches) {
|
||||
return $this->log_boundary . str_pad(dechex(ord($matches[0])), 2, '0', STR_PAD_LEFT);
|
||||
}, $fragment), strlen($this->log_boundary));
|
||||
$hex = substr(preg_replace_callback('#.#s', fn ($matches) => $this->log_boundary . str_pad(dechex(ord($matches[0])), 2, '0', STR_PAD_LEFT), $fragment), strlen($this->log_boundary));
|
||||
// replace non ASCII printable characters with dots
|
||||
// http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
|
||||
// also replace < with a . since < messes up the output on web browsers
|
||||
|
@ -36,7 +36,6 @@ namespace phpseclib3\System\SSH;
|
||||
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\PublicKeyLoader;
|
||||
use phpseclib3\Crypt\RSA;
|
||||
use phpseclib3\Exception\BadConfigurationException;
|
||||
use phpseclib3\Net\SSH2;
|
||||
use phpseclib3\System\SSH\Agent\Identity;
|
||||
@ -152,7 +151,7 @@ class Agent
|
||||
}
|
||||
|
||||
$packet = pack('NC', 1, self::SSH_AGENTC_REQUEST_IDENTITIES);
|
||||
if (strlen($packet) != fputs($this->fsock, $packet)) {
|
||||
if (strlen($packet) != fwrite($this->fsock, $packet)) {
|
||||
throw new \RuntimeException('Connection closed while requesting identities');
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ class Identity implements PrivateKey
|
||||
$this->flags
|
||||
);
|
||||
$packet = Strings::packSSH2('s', $packet);
|
||||
if (strlen($packet) != fputs($this->fsock, $packet)) {
|
||||
if (strlen($packet) != fwrite($this->fsock, $packet)) {
|
||||
throw new \RuntimeException('Connection closed during signing');
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ class SFTPStreamTest extends SFTPTestCase
|
||||
'sftp' => ['session' => $this->sftp],
|
||||
]);
|
||||
$fp = fopen($this->buildUrl('te#st.txt'), 'wb', false, $context);
|
||||
fputs($fp, 'zzzz');
|
||||
fwrite($fp, 'zzzz');
|
||||
fclose($fp);
|
||||
|
||||
$this->assertContains('te#st.txt', $this->sftp->nlist());
|
||||
|
@ -268,7 +268,7 @@ class SFTPUserStoryTest extends PhpseclibFunctionalTestCase
|
||||
public function testChModOnFile($sftp)
|
||||
{
|
||||
$this->assertNotFalse(
|
||||
$sftp->chmod(0755, 'file1.txt'),
|
||||
$sftp->chmod(0o755, 'file1.txt'),
|
||||
'Failed asserting that chmod() was successful.'
|
||||
);
|
||||
|
||||
@ -717,12 +717,12 @@ class SFTPUserStoryTest extends PhpseclibFunctionalTestCase
|
||||
*/
|
||||
public function testReadableWritable($sftp)
|
||||
{
|
||||
$sftp->chmod(0000, 'offset.txt');
|
||||
$sftp->chmod(0, 'offset.txt');
|
||||
$this->assertFalse($sftp->is_writable('offset.txt'));
|
||||
$this->assertFalse($sftp->is_writeable('offset.txt'));
|
||||
$this->assertFalse($sftp->is_readable('offset.txt'));
|
||||
|
||||
$sftp->chmod(0777, 'offset.txt');
|
||||
$sftp->chmod(0o777, 'offset.txt');
|
||||
$this->assertTrue($sftp->is_writable('offset.txt'));
|
||||
$this->assertTrue($sftp->is_writeable('offset.txt'));
|
||||
$this->assertTrue($sftp->is_readable('offset.txt'));
|
||||
|
@ -82,7 +82,7 @@ abstract class PhpseclibTestCase extends TestCase
|
||||
|
||||
protected static function getVar($obj, $var)
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($obj));
|
||||
$reflection = new \ReflectionClass($obj::class);
|
||||
$prop = $reflection->getProperty($var);
|
||||
$prop->setAccessible(true);
|
||||
return $prop->getValue($obj);
|
||||
@ -90,7 +90,7 @@ abstract class PhpseclibTestCase extends TestCase
|
||||
|
||||
public static function callFunc($obj, $func, $params = [])
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($obj));
|
||||
$reflection = new \ReflectionClass($obj::class);
|
||||
$method = $reflection->getMethod($func);
|
||||
$method->setAccessible(true);
|
||||
return $method->invokeArgs($obj, $params);
|
||||
|
@ -34,7 +34,7 @@ class PsalmBaselineTest extends TestCase
|
||||
/** @var array{level: int, type: string, tag: string, attributes: array{OCCURRENCES?: int}} $element */
|
||||
foreach ($values as $element) {
|
||||
if ($element['level'] === 3 && ($element['type'] === 'open' || $element['type'] === 'complete')) {
|
||||
$errorCounts[$element['tag']] = $errorCounts[$element['tag']] ?? 0;
|
||||
$errorCounts[$element['tag']] ??= 0;
|
||||
$occurrences = $element['attributes']['OCCURRENCES'] ?? 1;
|
||||
$errorCounts[$element['tag']] += $occurrences;
|
||||
}
|
||||
|
@ -178,9 +178,7 @@ abstract class TestCase extends PhpseclibTestCase
|
||||
*/
|
||||
public function continuousBufferBatteryCombosWithoutSingleCombos(): array
|
||||
{
|
||||
return array_filter($this->continuousBufferBatteryCombos(), function (array $continuousBufferBatteryCombo) {
|
||||
return count($continuousBufferBatteryCombo[2]) > 1;
|
||||
});
|
||||
return array_filter($this->continuousBufferBatteryCombos(), fn (array $continuousBufferBatteryCombo) => count($continuousBufferBatteryCombo[2]) > 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -100,7 +100,7 @@ class ChaCha20Test extends PhpseclibTestCase
|
||||
|
||||
$c = new ChaCha20();
|
||||
$c->setPoly1305Key($key);
|
||||
$r = new \ReflectionClass(get_class($c));
|
||||
$r = new \ReflectionClass($c::class);
|
||||
// this unit test is testing Poly1305 independent of ChaCha20, which phpseclib doesn't
|
||||
// really support, hence this hackish approach
|
||||
$m = $r->getMethod('poly1305');
|
||||
@ -128,7 +128,7 @@ class ChaCha20Test extends PhpseclibTestCase
|
||||
$c->setKey($key);
|
||||
$c->setNonce($nonce);
|
||||
|
||||
$r = new \ReflectionClass(get_class($c));
|
||||
$r = new \ReflectionClass($c::class);
|
||||
$m = $r->getMethod('createPoly1305Key');
|
||||
$m->setAccessible(true);
|
||||
$result = $m->invoke($c);
|
||||
|
@ -568,7 +568,7 @@ MIIEDwIBADATBgcqhkjOPQIBBggqhkjOPQMBBwSCA/MwggPvAgEBBIID6P//////
|
||||
$this->assertSameNL($raw, $key->toString('MontgomeryPrivate'));
|
||||
}
|
||||
|
||||
public function testOpenSSHEncryptedCreation()
|
||||
public function testOpenSSHEncryptedCreation(): void
|
||||
{
|
||||
$key = EC::createKey('Ed25519');
|
||||
$key = $key->withPassword('test')->toString('OpenSSH');
|
||||
|
Loading…
Reference in New Issue
Block a user