From c705e7d9c60061091f4ca29aafdb92b65178e79e Mon Sep 17 00:00:00 2001 From: Sokolovskyy Roman Date: Mon, 4 Dec 2017 11:11:43 +0100 Subject: [PATCH] Add PhpDoc @var for extract() functions --- phpseclib/Crypt/Common/Keys/PuTTY.php | 1 + phpseclib/Crypt/DSA/Keys/PuTTY.php | 6 +- phpseclib/Crypt/RSA.php | 3 + phpseclib/Crypt/RSA/Keys/MSBLOB.php | 11 ++ phpseclib/Crypt/RSA/Keys/PuTTY.php | 6 +- phpseclib/File/ASN1.php | 3 + phpseclib/Math/BigInteger.php | 12 +- phpseclib/Math/BigInteger/Engines/BCMath.php | 3 + phpseclib/Math/BigInteger/Engines/Engine.php | 15 ++- phpseclib/Math/BigInteger/Engines/GMP.php | 2 +- phpseclib/Math/BigInteger/Engines/PHP32.php | 3 +- phpseclib/Math/BigInteger/Engines/PHP64.php | 2 +- phpseclib/Net/SCP.php | 3 + phpseclib/Net/SFTP.php | 85 ++++++++++++++- phpseclib/Net/SSH1.php | 6 + phpseclib/Net/SSH2.php | 109 +++++++++++++++++-- 16 files changed, 247 insertions(+), 23 deletions(-) diff --git a/phpseclib/Crypt/Common/Keys/PuTTY.php b/phpseclib/Crypt/Common/Keys/PuTTY.php index d6618f44..d2357c3b 100644 --- a/phpseclib/Crypt/Common/Keys/PuTTY.php +++ b/phpseclib/Crypt/Common/Keys/PuTTY.php @@ -117,6 +117,7 @@ abstract class PuTTY $source = Strings::packSSH2('ssss', static::TYPE, $encryption, $components['comment'], $public); extract(unpack('Nlength', Strings::shift($public, 4))); + /** @var integer $length */ if (Strings::shift($public, $length) != static::TYPE) { return false; } diff --git a/phpseclib/Crypt/DSA/Keys/PuTTY.php b/phpseclib/Crypt/DSA/Keys/PuTTY.php index 1decb1e5..22e83a79 100644 --- a/phpseclib/Crypt/DSA/Keys/PuTTY.php +++ b/phpseclib/Crypt/DSA/Keys/PuTTY.php @@ -63,16 +63,14 @@ abstract class PuTTY extends Progenitor if ($components === false || !isset($components['private'])) { return $components; } - extract($components); - unset($components['public'], $components['private']); - $result = Strings::unpackSSH2('iiii', $public); + $result = Strings::unpackSSH2('iiii', $components['public']); if ($result === false) { return false; } list($p, $q, $g, $y) = $result; - $result = Strings::unpackSSH2('i', $private); + $result = Strings::unpackSSH2('i', $components['private']); if ($result === false) { return false; } diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 282131ff..0ae17f6d 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -383,6 +383,9 @@ class RSA extends AsymmetricKey $primes[$i] = BigInteger::randomPrime($regSize); } else { extract(BigInteger::minMaxBits($bits)); + /** @var BigInteger $min + * @var BigInteger $max + */ list($min) = $min->divide($n); $min = $min->add(self::$one); list($max) = $max->divide($n); diff --git a/phpseclib/Crypt/RSA/Keys/MSBLOB.php b/phpseclib/Crypt/RSA/Keys/MSBLOB.php index 33500fe7..52223ffd 100644 --- a/phpseclib/Crypt/RSA/Keys/MSBLOB.php +++ b/phpseclib/Crypt/RSA/Keys/MSBLOB.php @@ -88,6 +88,12 @@ abstract class MSBLOB // PUBLICKEYSTRUC publickeystruc // https://msdn.microsoft.com/en-us/library/windows/desktop/aa387453(v=vs.85).aspx extract(unpack('atype/aversion/vreserved/Valgo', Strings::shift($key, 8))); + /** + * @var string $type + * @var string $version + * @var integer $reserved + * @var integer $algo + */ switch (ord($type)) { case self::PUBLICKEYBLOB: case self::PUBLICKEYBLOBEX: @@ -115,6 +121,11 @@ abstract class MSBLOB // https://msdn.microsoft.com/en-us/library/windows/desktop/aa387685(v=vs.85).aspx // could do V for pubexp but that's unsigned 32-bit whereas some PHP installs only do signed 32-bit extract(unpack('Vmagic/Vbitlen/a4pubexp', Strings::shift($key, 12))); + /** + * @var integer $magic + * @var integer $bitlen + * @var string $pubexp + */ switch ($magic) { case self::RSA2: $components['isPublicKey'] = false; diff --git a/phpseclib/Crypt/RSA/Keys/PuTTY.php b/phpseclib/Crypt/RSA/Keys/PuTTY.php index ca9195d0..9813aeb0 100644 --- a/phpseclib/Crypt/RSA/Keys/PuTTY.php +++ b/phpseclib/Crypt/RSA/Keys/PuTTY.php @@ -63,18 +63,16 @@ abstract class PuTTY extends Progenitor if ($components === false || !isset($components['private'])) { return $components; } - extract($components); - unset($components['public'], $components['private']); $isPublicKey = false; - $result = Strings::unpackSSH2('ii', $public); + $result = Strings::unpackSSH2('ii', $components['public']); if ($result === false) { return false; } list($publicExponent, $modulus) = $result; - $result = Strings::unpackSSH2('iiii', $private); + $result = Strings::unpackSSH2('iiii', $components['private']); if ($result === false) { return false; } diff --git a/phpseclib/File/ASN1.php b/phpseclib/File/ASN1.php index 746af033..7145bf59 100644 --- a/phpseclib/File/ASN1.php +++ b/phpseclib/File/ASN1.php @@ -292,6 +292,9 @@ abstract class ASN1 $current+= ['headerlength' => $length + 2]; $start+= $length; extract(unpack('Nlength', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4))); + /** + * @var integer $length + */ } else { $current+= ['headerlength' => 2]; } diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index dabc570e..7008b49a 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -299,12 +299,17 @@ class BigInteger implements \Serializable * Calculates modular inverses. * * Say you have (30 mod 17 * x mod 17) mod 17 == 1. x can be found using modular inverses. - * @return array + * @return BigInteger[] * @param BigInteger $n */ public function extendedGCD(BigInteger $n) { extract($this->value->extendedGCD($n->value)); + /** + * @var BigInteger $gcd + * @var BigInteger $x + * @var BigInteger $y + */ return [ 'gcd' => new static($gcd), 'x' => new static($x), @@ -561,12 +566,15 @@ class BigInteger implements \Serializable * Returns the smallest and largest n-bit number * * @param int $bits - * @return array + * @return BigInteger[] */ public static function minMaxBits($bits) { $class = self::$mainEngine; extract($class::minMaxBits($bits)); + /** @var BigInteger $min + * @var BigInteger $max + */ return [ 'min' => new static($min), 'max' => new static($max) diff --git a/phpseclib/Math/BigInteger/Engines/BCMath.php b/phpseclib/Math/BigInteger/Engines/BCMath.php index 459542a8..18c9cc5f 100644 --- a/phpseclib/Math/BigInteger/Engines/BCMath.php +++ b/phpseclib/Math/BigInteger/Engines/BCMath.php @@ -341,6 +341,9 @@ class BCMath extends Engine public function gcd(BCMath $n) { extract($this->extendedGCD($n)); + /** + * @var BCMath $gcd + */ return $gcd; } diff --git a/phpseclib/Math/BigInteger/Engines/Engine.php b/phpseclib/Math/BigInteger/Engines/Engine.php index 7dda6bac..159f16f3 100644 --- a/phpseclib/Math/BigInteger/Engines/Engine.php +++ b/phpseclib/Math/BigInteger/Engines/Engine.php @@ -18,6 +18,7 @@ namespace phpseclib\Math\BigInteger\Engines; use ParagonIE\ConstantTime\Hex; use phpseclib\Exception\BadConfigurationException; use phpseclib\Crypt\Random; +use phpseclib\Math\BigInteger; /** * Base Engine. @@ -276,6 +277,10 @@ abstract class Engine implements \Serializable } extract($this->extendedGCD($n)); + /** + * @var BigInteger $gcd + * @var BigInteger $x + */ if (!$gcd->equals(static::$one)) { return false; @@ -517,7 +522,7 @@ abstract class Engine implements \Serializable * Returns the smallest and largest n-bit number * * @param int $bits - * @return \phpseclib\Math\BigInteger\Engines\Engine + * @return \phpseclib\Math\BigInteger\Engines\Engine[] */ public static function minMaxBits($bits) { @@ -670,6 +675,10 @@ abstract class Engine implements \Serializable public static function random($size) { extract(static::minMaxBits($size)); + /** + * @var BigInteger $min + * @var BigInteger $max + */ return static::randomRange($min, $max); } @@ -684,6 +693,10 @@ abstract class Engine implements \Serializable public static function randomPrime($size) { extract(static::minMaxBits($size)); + /** + * @var BigInteger $min + * @var BigInteger $max + */ return static::randomRangePrime($min, $max); } diff --git a/phpseclib/Math/BigInteger/Engines/GMP.php b/phpseclib/Math/BigInteger/Engines/GMP.php index 2d965543..cdabbb72 100644 --- a/phpseclib/Math/BigInteger/Engines/GMP.php +++ b/phpseclib/Math/BigInteger/Engines/GMP.php @@ -309,7 +309,7 @@ class GMP extends Engine * {@link http://en.wikipedia.org/wiki/B%C3%A9zout%27s_identity Bezout's identity - Wikipedia} for more information. * * @param \phpseclib\Math\BigInteger\Engines\GMP $n - * @return \phpseclib\Math\BigInteger\Engines\GMP + * @return \phpseclib\Math\BigInteger\Engines\GMP[] */ public function extendedGCD(GMP $n) { diff --git a/phpseclib/Math/BigInteger/Engines/PHP32.php b/phpseclib/Math/BigInteger/Engines/PHP32.php index acf982b1..ee8d8b2e 100644 --- a/phpseclib/Math/BigInteger/Engines/PHP32.php +++ b/phpseclib/Math/BigInteger/Engines/PHP32.php @@ -192,7 +192,8 @@ class PHP32 extends PHP */ public function gcd(PHP32 $n) { - extract($this->extendedGCD($n)); + $gcd = $this->extendedGCD($n)['gcd']; + return $gcd; } diff --git a/phpseclib/Math/BigInteger/Engines/PHP64.php b/phpseclib/Math/BigInteger/Engines/PHP64.php index 61223f65..7fba8042 100644 --- a/phpseclib/Math/BigInteger/Engines/PHP64.php +++ b/phpseclib/Math/BigInteger/Engines/PHP64.php @@ -192,7 +192,7 @@ class PHP64 extends PHP */ public function gcd(PHP64 $n) { - extract($this->extendedGCD($n)); + $gcd=$this->extendedGCD($n)['gcd']; return $gcd; } diff --git a/phpseclib/Net/SCP.php b/phpseclib/Net/SCP.php index 0143a337..e57f3001 100644 --- a/phpseclib/Net/SCP.php +++ b/phpseclib/Net/SCP.php @@ -307,6 +307,9 @@ class SCP return false; } extract(unpack('Nlength', $response[SSH1::RESPONSE_DATA])); + /** + * @var integer $length + */ return Strings::shift($response[SSH1::RESPONSE_DATA], $length); case NET_SSH1_SMSG_STDERR_DATA: break; diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index 401a4ca6..2bc3225f 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -494,17 +494,27 @@ class SFTP extends SSH2 return false; } extract(unpack('Nversion', Strings::shift($response, 4))); + /** + * @var integer $version + */ $this->version = $version; while (!empty($response)) { if (strlen($response) < 4) { return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ $key = Strings::shift($response, $length); if (strlen($response) < 4) { return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + $value = Strings::shift($response, $length); $this->extensions[$key] = $value; } @@ -638,12 +648,19 @@ class SFTP extends SSH2 return; } extract(unpack('Nstatus', Strings::shift($response, 4))); + /** + * @var integer $status + */ } $error = $this->status_codes[$status]; if ($this->version > 2 || strlen($response) < 4) { extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + $this->sftp_errors[] = $error . ': ' . Strings::shift($response, $length); } else { $this->sftp_errors[] = $error; @@ -688,6 +705,10 @@ class SFTP extends SSH2 return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + return Strings::shift($response, $length); case NET_SFTP_STATUS: $this->logError($response); @@ -927,16 +948,28 @@ class SFTP extends SSH2 return false; } extract(unpack('Ncount', Strings::shift($response, 4))); + /** + * @var integer $count + */ + for ($i = 0; $i < $count; $i++) { if (strlen($response) < 4) { return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + $shortname = Strings::shift($response, $length); if (strlen($response) < 4) { return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + $longname = Strings::shift($response, $length); $attributes = $this->parseAttributes($response); if (!isset($attributes['type'])) { @@ -966,6 +999,10 @@ class SFTP extends SSH2 return false; } extract(unpack('Nstatus', Strings::shift($response, 4))); + /** + * @var integer $status + */ + if ($status != NET_SFTP_STATUS_EOF) { $this->logError($response, $status); return false; @@ -1567,6 +1604,9 @@ class SFTP extends SSH2 return false; } extract(unpack('Nstatus', Strings::shift($response, 4))); + /** + * @var integer $status + */ if ($status != NET_SFTP_STATUS_OK) { $this->logError($response, $status); return false; @@ -1683,6 +1723,9 @@ class SFTP extends SSH2 return false; } extract(unpack('Ncount', Strings::shift($response, 4))); + /** + * @var integer $count + */ // the file isn't a symlink if (!$count) { return false; @@ -1692,6 +1735,10 @@ class SFTP extends SSH2 return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + return Strings::shift($response, $length); } @@ -1730,7 +1777,9 @@ class SFTP extends SSH2 return false; } extract(unpack('Nstatus', Strings::shift($response, 4))); - + /** + * @var integer $status + */ if ($status != NET_SFTP_STATUS_OK) { $this->logError($response, $status); return false; @@ -1800,6 +1849,9 @@ class SFTP extends SSH2 return false; } extract(unpack('Nstatus', Strings::shift($response, 4))); + /** + * @var integer $status + */ if ($status != NET_SFTP_STATUS_OK) { $this->logError($response, $status); return false; @@ -1841,6 +1893,9 @@ class SFTP extends SSH2 return false; } extract(unpack('Nstatus', Strings::shift($response, 4))); + /** + * @var integer $status + */ if ($status != NET_SFTP_STATUS_OK) { // presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED? $this->logError($response, $status); @@ -2079,6 +2134,9 @@ class SFTP extends SSH2 return false; } extract(unpack('Nstatus', Strings::shift($response, 4))); + /** + * @var integer $status + */ if ($status != NET_SFTP_STATUS_OK) { $this->logError($response, $status); break; @@ -2114,6 +2172,9 @@ class SFTP extends SSH2 return false; } extract(unpack('Nstatus', Strings::shift($response, 4))); + /** + * @var integer $status + */ if ($status != NET_SFTP_STATUS_OK) { $this->logError($response, $status); return false; @@ -2319,6 +2380,9 @@ class SFTP extends SSH2 return false; } extract(unpack('Nstatus', Strings::shift($response, 4))); + /** + * @var integer $status + */ if ($status != NET_SFTP_STATUS_OK) { $this->logError($response, $status); if (!$recursive) { @@ -2749,6 +2813,9 @@ class SFTP extends SSH2 return false; } extract(unpack('Nstatus', Strings::shift($response, 4))); + /** + * @var integer $status + */ if ($status != NET_SFTP_STATUS_OK) { $this->logError($response, $status); return false; @@ -2780,6 +2847,9 @@ class SFTP extends SSH2 return []; } extract(unpack('Nflags', Strings::shift($response, 4))); + /** + * @var integer $flags + */ // SFTPv4+ have a type field (a byte) that follows the above flag field foreach ($this->attributes as $key => $value) { switch ($flags & $key) { @@ -2826,18 +2896,28 @@ class SFTP extends SSH2 return $attr; } extract(unpack('Ncount', Strings::shift($response, 4))); + /** + * @var integer $count + */ for ($i = 0; $i < $count; $i++) { if (strlen($response) < 4) { //user_error('Malformed file attributes'); return $attr; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ $key = Strings::shift($response, $length); + if (strlen($response) < 4) { //user_error('Malformed file attributes'); return $attr; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ $attr[$key] = Strings::shift($response, $length); } } @@ -2994,6 +3074,9 @@ class SFTP extends SSH2 return false; } extract(unpack('Nlength', Strings::shift($this->packet_buffer, 4))); + /** + * @var integer $length + */ $tempLength = $length; $tempLength-= strlen($this->packet_buffer); diff --git a/phpseclib/Net/SSH1.php b/phpseclib/Net/SSH1.php index ca296dc8..4272ffb5 100644 --- a/phpseclib/Net/SSH1.php +++ b/phpseclib/Net/SSH1.php @@ -614,6 +614,9 @@ class SSH1 return false; } extract(unpack('Nsupported_ciphers_mask', Strings::shift($response[self::RESPONSE_DATA], 4))); + /** + * @var integer $supported_ciphers_mask + */ foreach ($this->supported_ciphers as $mask => $name) { if (($supported_ciphers_mask & (1 << $mask)) == 0) { @@ -626,6 +629,9 @@ class SSH1 return false; } extract(unpack('Nsupported_authentications_mask', Strings::shift($response[self::RESPONSE_DATA], 4))); + /** + * @var integer $supported_authentications_mask + */ foreach ($this->supported_authentications as $mask => $name) { if (($supported_authentications_mask & (1 << $mask)) == 0) { unset($this->supported_authentications[$mask]); diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 3e9a3a6f..e3a2155c 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -1548,7 +1548,7 @@ class SSH2 return false; } extract(unpack('Cfirst_kex_packet_follows', Strings::shift($response, 1))); - + /** @var integer $first_kex_packet_follows */ $first_kex_packet_follows = $first_kex_packet_follows != 0; if (!$this->send_kex_first && !$this->send_binary_packet($kexinit_payload_client)) { @@ -1612,6 +1612,7 @@ class SSH2 return false; } extract(unpack('Ctype', Strings::shift($response, 1))); + /** @var integer $type */ if ($type != NET_SSH2_MSG_KEXDH_GEX_GROUP) { user_error('Expected SSH_MSG_KEX_DH_GEX_GROUP'); return false; @@ -1621,6 +1622,7 @@ class SSH2 return false; } extract(unpack('NprimeLength', Strings::shift($response, 4))); + /** @var integer $primeLength*/ $primeBytes = Strings::shift($response, $primeLength); $prime = new BigInteger($primeBytes, -256); @@ -1628,6 +1630,7 @@ class SSH2 return false; } extract(unpack('NgLength', Strings::shift($response, 4))); + /** @var integer $gLength */ $gBytes = Strings::shift($response, $gLength); $g = new BigInteger($gBytes, -256); @@ -1711,7 +1714,7 @@ class SSH2 return false; } extract(unpack('Ctype', Strings::shift($response, 1))); - + /** @var integer $type */ if ($type != $serverKexReplyMessage) { throw new \UnexpectedValueException('Expected SSH_MSG_KEXDH_REPLY'); } @@ -1816,7 +1819,7 @@ class SSH2 return false; } extract(unpack('Ctype', Strings::shift($response, 1))); - + /** @var integer $type */ if ($type != NET_SSH2_MSG_NEWKEYS) { throw new \UnexpectedValueException('Expected SSH_MSG_NEWKEYS'); } @@ -2183,7 +2186,7 @@ class SSH2 return false; } extract(unpack('Ctype', Strings::shift($response, 1))); - + /** @var integer $type */ if ($type != NET_SSH2_MSG_SERVICE_ACCEPT) { throw new \UnexpectedValueException('Expected SSH_MSG_SERVICE_ACCEPT'); } @@ -2233,7 +2236,7 @@ class SSH2 return false; } extract(unpack('Ctype', Strings::shift($response, 1))); - + /** @var integer $type */ switch ($type) { case NET_SSH2_MSG_USERAUTH_SUCCESS: $this->bitmap |= self::MASK_LOGIN; @@ -2290,7 +2293,7 @@ class SSH2 return false; } extract(unpack('Ctype', Strings::shift($response, 1))); - + /** @var integer $type */ switch ($type) { case NET_SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ: // in theory, the password can be changed if (defined('NET_SSH2_LOGGING')) { @@ -2301,6 +2304,9 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ $this->errors[] = 'SSH_MSG_USERAUTH_PASSWD_CHANGEREQ: ' . utf8_decode(Strings::shift($response, $length)); return $this->disconnect_helper(NET_SSH2_DISCONNECT_AUTH_CANCELLED_BY_USER); @@ -2311,11 +2317,18 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + $auth_methods = explode(',', Strings::shift($response, $length)); if (!strlen($response)) { return false; } extract(unpack('Cpartial_success', Strings::shift($response, 1))); + /** + * @var integer $partial_success + */ $partial_success = $partial_success != 0; if (!$partial_success && in_array('keyboard-interactive', $auth_methods)) { @@ -2391,29 +2404,41 @@ class SSH2 return false; } extract(unpack('Ctype', Strings::shift($response, 1))); - + /** @var integer $type */ switch ($type) { case NET_SSH2_MSG_USERAUTH_INFO_REQUEST: if (strlen($response) < 4) { return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + Strings::shift($response, $length); // name; may be empty if (strlen($response) < 4) { return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + Strings::shift($response, $length); // instruction; may be empty if (strlen($response) < 4) { return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + Strings::shift($response, $length); // language tag; may be empty if (strlen($response) < 4) { return false; } extract(unpack('Nnum_prompts', Strings::shift($response, 4))); - + /** @var integer $num_prompts */ for ($i = 0; $i < count($responses); $i++) { if (is_array($responses[$i])) { foreach ($responses[$i] as $key => $value) { @@ -2430,6 +2455,10 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + // prompt - ie. "Password: "; must not be empty $prompt = Strings::shift($response, $length); //$echo = Strings::shift($response) != chr(0); @@ -2578,6 +2607,7 @@ class SSH2 return false; } extract(unpack('Ctype', Strings::shift($response, 1))); + /** @var integer $type */ switch ($type) { case NET_SSH2_MSG_USERAUTH_FAILURE: @@ -2585,6 +2615,10 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + $this->errors[] = 'SSH_MSG_USERAUTH_FAILURE: ' . Strings::shift($response, $length); return false; @@ -2619,6 +2653,7 @@ class SSH2 return false; } extract(unpack('Ctype', Strings::shift($response, 1))); + /** @var integer $type */ switch ($type) { case NET_SSH2_MSG_USERAUTH_FAILURE: @@ -3240,6 +3275,10 @@ class SSH2 return false; } extract(unpack('Npacket_length/Cpadding_length', Strings::shift($raw, 5))); + /** + * @var integer $packet_length + * @var integer $padding_length + */ $remaining_length = $packet_length + 4 - $this->decrypt_block_size; @@ -3322,6 +3361,11 @@ class SSH2 return false; } extract(unpack('Nreason_code/Nlength', Strings::shift($payload, 8))); + /** + * @var integer $reason_code + * @var integer $length + */ + $this->errors[] = 'SSH_MSG_DISCONNECT: ' . $this->disconnect_reasons[$reason_code] . "\r\n" . utf8_decode(Strings::shift($payload, $length)); $this->bitmap = 0; return false; @@ -3334,6 +3378,10 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($payload, 4))); + /** + * @var integer $length + */ + $this->errors[] = 'SSH_MSG_DEBUG: ' . utf8_decode(Strings::shift($payload, $length)); $payload = $this->get_binary_packet($skip_channel_filter); break; @@ -3356,6 +3404,9 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($payload, 4))); + /** + * @var integer $length + */ $this->banner_message = utf8_decode(Strings::shift($payload, $length)); $payload = $this->get_binary_packet(); } @@ -3379,6 +3430,9 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($payload, 4))); + /** + * @var integer $length + */ $this->errors[] = 'SSH_MSG_GLOBAL_REQUEST: ' . Strings::shift($payload, $length); if (!$this->send_binary_packet(pack('C', NET_SSH2_MSG_REQUEST_FAILURE))) { @@ -3393,11 +3447,15 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($payload, 4))); + /** + * @var integer $length + */ $data = Strings::shift($payload, $length); if (strlen($payload) < 4) { return false; } extract(unpack('Nserver_channel', Strings::shift($payload, 4))); + /** @var integer $server_channel */ switch ($data) { case 'auth-agent': case 'auth-agent@openssh.com': @@ -3408,7 +3466,9 @@ class SSH2 return false; } extract(unpack('Nremote_window_size', Strings::shift($payload, 4))); + /** @var integer $remote_window_size */ extract(unpack('Nremote_maximum_packet_size', Strings::shift($payload, 4))); + /** @var integer $remote_maximum_packet_size*/ $this->packet_size_client_to_server[$new_channel] = $remote_window_size; $this->window_size_server_to_client[$new_channel] = $remote_maximum_packet_size; @@ -3457,7 +3517,9 @@ class SSH2 return false; } extract(unpack('Nchannel', Strings::shift($payload, 4))); + /** @var integer $channel */ extract(unpack('Nwindow_size', Strings::shift($payload, 4))); + /** @var integer $window_size */ $this->window_size_client_to_server[$channel]+= $window_size; @@ -3602,14 +3664,19 @@ class SSH2 return false; } extract(unpack('Ctype', Strings::shift($response, 1))); + /** @var integer $type */ if (strlen($response) < 4) { return false; } if ($type == NET_SSH2_MSG_CHANNEL_OPEN) { extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ } else { extract(unpack('Nchannel', Strings::shift($response, 4))); + /** @var integer $channel */ } // will not be setup yet on incoming channel open request @@ -3636,6 +3703,10 @@ class SSH2 return false; } extract(unpack('Ndata_type_code/Nlength', Strings::shift($response, 8))); + /** + * @var integer $data_type_code + * @var integer $length + */ $data = Strings::shift($response, $length); $this->stdErrorLog.= $data; if ($skip_extended || $this->quiet_mode) { @@ -3660,11 +3731,13 @@ class SSH2 return false; } extract(unpack('Nserver_channel', Strings::shift($response, 4))); + /** @var integer $server_channel */ $this->server_channels[$channel] = $server_channel; if (strlen($response) < 4) { return false; } extract(unpack('Nwindow_size', Strings::shift($response, 4))); + /** @var integer $window_size */ if ($window_size < 0) { $window_size&= 0x7FFFFFFF; @@ -3718,6 +3791,10 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ + $data = Strings::shift($response, $length); if ($channel == self::CHANNEL_AGENT_FORWARD) { @@ -3741,6 +3818,9 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ $value = Strings::shift($response, $length); switch ($value) { case 'exit-signal': @@ -3749,12 +3829,18 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ $this->errors[] = 'SSH_MSG_CHANNEL_REQUEST (exit-signal): ' . Strings::shift($response, $length); if (strlen($response) < 4) { return false; } Strings::shift($response, 1); extract(unpack('Nlength', Strings::shift($response, 4))); + /** + * @var integer $length + */ if ($length) { $this->errors[count($this->errors)].= "\r\n" . Strings::shift($response, $length); } @@ -3770,6 +3856,10 @@ class SSH2 return false; } extract(unpack('Cfalse/Nexit_status', Strings::shift($response, 5))); + /** + * @var integer $false + * @var integer $exit_status + */ $this->exit_status = $exit_status; @@ -4385,6 +4475,9 @@ class SSH2 return false; } extract(unpack('Nlength', Strings::shift($server_public_host_key, 4))); + /** + * @var integer $length + */ Strings::shift($server_public_host_key, $length); if ($this->signature_validated) {