This commit is contained in:
terrafrost 2025-01-24 22:32:09 -06:00
commit 5b04772d8a
22 changed files with 112 additions and 78 deletions

View File

@ -119,7 +119,7 @@ abstract class Strings
// 64-bit floats can be used to get larger numbers then 32-bit signed ints would allow // 64-bit floats can be used to get larger numbers then 32-bit signed ints would allow
// for. sure, you're not gonna get the full precision of 64-bit numbers but just because // for. sure, you're not gonna get the full precision of 64-bit numbers but just because
// you need > 32-bit precision doesn't mean you need the full 64-bit precision // you need > 32-bit precision doesn't mean you need the full 64-bit precision
extract(unpack('Nupper/Nlower', self::shift($data, 8))); ['upper' => $upper, 'lower' => $lower] = unpack('Nupper/Nlower', self::shift($data, 8));
$temp = $upper ? 4294967296 * $upper : 0; $temp = $upper ? 4294967296 * $upper : 0;
$temp += $lower < 0 ? ($lower & 0x7FFFFFFFF) + 0x80000000 : $lower; $temp += $lower < 0 ? ($lower & 0x7FFFFFFFF) + 0x80000000 : $lower;
// $temp = hexdec(bin2hex(self::shift($data, 8))); // $temp = hexdec(bin2hex(self::shift($data, 8)));

View File

@ -343,7 +343,10 @@ abstract class PKCS8 extends PKCS
if (!$temp) { if (!$temp) {
throw new RuntimeException('Unable to decode BER'); throw new RuntimeException('Unable to decode BER');
} }
extract(ASN1::asn1map($temp[0], Maps\PBEParameter::MAP)); [
'salt' => $salt,
'iterationCount' => $iterationCount
] = ASN1::asn1map($temp[0], Maps\PBEParameter::MAP);
$iterationCount = (int) $iterationCount->toString(); $iterationCount = (int) $iterationCount->toString();
$cipher->setPassword($password, $kdf, $hash, $salt, $iterationCount); $cipher->setPassword($password, $kdf, $hash, $salt, $iterationCount);
$key = $cipher->decrypt($decrypted['encryptedData']); $key = $cipher->decrypt($decrypted['encryptedData']);
@ -361,7 +364,10 @@ abstract class PKCS8 extends PKCS
throw new RuntimeException('Unable to decode BER'); throw new RuntimeException('Unable to decode BER');
} }
$temp = ASN1::asn1map($temp[0], Maps\PBES2params::MAP); $temp = ASN1::asn1map($temp[0], Maps\PBES2params::MAP);
extract($temp); [
'keyDerivationFunc' => $keyDerivationFunc,
'encryptionScheme' => $encryptionScheme
] = $temp;
$cipher = self::getPBES2EncryptionObject($encryptionScheme['algorithm']); $cipher = self::getPBES2EncryptionObject($encryptionScheme['algorithm']);
$meta['meta']['cipher'] = $encryptionScheme['algorithm']; $meta['meta']['cipher'] = $encryptionScheme['algorithm'];
@ -371,7 +377,10 @@ abstract class PKCS8 extends PKCS
throw new RuntimeException('Unable to decode BER'); throw new RuntimeException('Unable to decode BER');
} }
$temp = ASN1::asn1map($temp[0], Maps\PBES2params::MAP); $temp = ASN1::asn1map($temp[0], Maps\PBES2params::MAP);
extract($temp); [
'keyDerivationFunc' => $keyDerivationFunc,
'encryptionScheme' => $encryptionScheme
] = $temp;
if (!$cipher instanceof RC2) { if (!$cipher instanceof RC2) {
$cipher->setIV($encryptionScheme['parameters']['octetString']); $cipher->setIV($encryptionScheme['parameters']['octetString']);
@ -380,7 +389,10 @@ abstract class PKCS8 extends PKCS
if (!$temp) { if (!$temp) {
throw new RuntimeException('Unable to decode BER'); throw new RuntimeException('Unable to decode BER');
} }
extract(ASN1::asn1map($temp[0], Maps\RC2CBCParameter::MAP)); [
'rc2ParametersVersion' => $rc2ParametersVersion,
'iv' => $iv
] = ASN1::asn1map($temp[0], Maps\RC2CBCParameter::MAP);
$effectiveKeyLength = (int) $rc2ParametersVersion->toString(); $effectiveKeyLength = (int) $rc2ParametersVersion->toString();
switch ($effectiveKeyLength) { switch ($effectiveKeyLength) {
case 160: case 160:
@ -405,9 +417,15 @@ abstract class PKCS8 extends PKCS
if (!$temp) { if (!$temp) {
throw new RuntimeException('Unable to decode BER'); throw new RuntimeException('Unable to decode BER');
} }
$prf = ['algorithm' => 'id-hmacWithSHA1'];
$params = ASN1::asn1map($temp[0], Maps\PBKDF2params::MAP); $params = ASN1::asn1map($temp[0], Maps\PBKDF2params::MAP);
extract($params); if (empty($params['prf'])) {
$params['prf'] = ['algorithm' => 'id-hmacWithSHA1'];
}
[
'salt' => $salt,
'iterationCount' => $iterationCount,
'prf' => $prf
] = $params;
$meta['meta']['prf'] = $prf['algorithm']; $meta['meta']['prf'] = $prf['algorithm'];
$hash = str_replace('-', '/', substr($prf['algorithm'], 11)); $hash = str_replace('-', '/', substr($prf['algorithm'], 11));
$params = [ $params = [

View File

@ -186,7 +186,7 @@ abstract class PuTTY
$source = Strings::packSSH2('ssss', $type, $encryption, $components['comment'], $public); $source = Strings::packSSH2('ssss', $type, $encryption, $components['comment'], $public);
extract(unpack('Nlength', Strings::shift($public, 4))); ['length' => $length] = unpack('Nlength', Strings::shift($public, 4));
$newtype = Strings::shift($public, $length); $newtype = Strings::shift($public, $length);
if ($newtype != $type) { if ($newtype != $type) {
throw new RuntimeException('The binary type does not match the human readable type field'); throw new RuntimeException('The binary type does not match the human readable type field');
@ -214,7 +214,11 @@ abstract class PuTTY
$parallelism = trim(preg_replace('#Argon2-Parallelism: (\d+)#', '$1', $key[$offset++])); $parallelism = trim(preg_replace('#Argon2-Parallelism: (\d+)#', '$1', $key[$offset++]));
$salt = Strings::hex2bin(trim(preg_replace('#Argon2-Salt: ([0-9a-f]+)#', '$1', $key[$offset++]))); $salt = Strings::hex2bin(trim(preg_replace('#Argon2-Salt: ([0-9a-f]+)#', '$1', $key[$offset++])));
extract(self::generateV3Key($password, $flavour, (int)$memory, (int)$passes, $salt)); [
'symkey' => $symkey,
'symiv' => $symiv,
'hashkey' => $hashkey
] = self::generateV3Key($password, $flavour, (int)$memory, (int)$passes, $salt);
break; break;
case 2: case 2:
@ -306,7 +310,11 @@ abstract class PuTTY
$key .= "Argon2-Passes: 13\r\n"; $key .= "Argon2-Passes: 13\r\n";
$key .= "Argon2-Parallelism: 1\r\n"; $key .= "Argon2-Parallelism: 1\r\n";
$key .= "Argon2-Salt: " . Strings::bin2hex($salt) . "\r\n"; $key .= "Argon2-Salt: " . Strings::bin2hex($salt) . "\r\n";
extract(self::generateV3Key($password, 'Argon2id', 8192, 13, $salt)); [
'symkey' => $symkey,
'symiv' => $symiv,
'hashkey' => $hashkey
] = self::generateV3Key($password, 'Argon2id', 8192, 13, $salt);
$hash = new Hash('sha256'); $hash = new Hash('sha256');
$hash->setKey($hashkey); $hash->setKey($hashkey);

View File

@ -59,7 +59,12 @@ abstract class PuTTY extends Progenitor
if (!isset($components['private'])) { if (!isset($components['private'])) {
return $components; return $components;
} }
extract($components); [
'type' => $type,
'comment' => $comment,
'public' => $public,
'private' => $private
] = $components;
unset($components['public'], $components['private']); unset($components['public'], $components['private']);
[$p, $q, $g, $y] = Strings::unpackSSH2('iiii', $public); [$p, $q, $g, $y] = Strings::unpackSSH2('iiii', $public);

View File

@ -88,7 +88,7 @@ final class PrivateKey extends DSA implements Common\PrivateKey
return $signature; return $signature;
} }
extract(ASN1Signature::load($signature)); ['r' => $r, 's' => $s] = ASN1Signature::load($signature);
return $format::save($r, $s); return $format::save($r, $s);
} }

View File

@ -41,7 +41,7 @@ final class PublicKey extends DSA implements Common\PublicKey
if ($params === false || count($params) != 2) { if ($params === false || count($params) != 2) {
return false; return false;
} }
extract($params); ['r' => $r, 's' => $s] = $params;
if (self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods())) { if (self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods())) {
$sig = $format != 'ASN1' ? ASN1Signature::save($r, $s) : $signature; $sig = $format != 'ASN1' ? ASN1Signature::save($r, $s) : $signature;

View File

@ -156,7 +156,7 @@ final class PrivateKey extends EC implements Common\PrivateKey
return $signature; return $signature;
} }
extract(ASN1Signature::load($signature)); ['r' => $r, 's' => $s] = ASN1Signature::load($signature);
return $this->formatSignature($r, $s); return $this->formatSignature($r, $s);
} }

View File

@ -116,7 +116,7 @@ final class PublicKey extends EC implements Common\PublicKey
if ($params === false || count($params) != 2) { if ($params === false || count($params) != 2) {
return false; return false;
} }
extract($params); ['r' => $r, 's' => $s] = $params;
if (self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods())) { if (self::$engines['OpenSSL'] && in_array($this->hash->getHash(), openssl_get_md_methods())) {
$sig = $format != 'ASN1' ? ASN1Signature::save($r, $s) : $signature; $sig = $format != 'ASN1' ? ASN1Signature::save($r, $s) : $signature;

View File

@ -352,10 +352,7 @@ abstract class RSA extends AsymmetricKey
if ($i != $num_primes) { if ($i != $num_primes) {
$primes[$i] = BigInteger::randomPrime($regSize); $primes[$i] = BigInteger::randomPrime($regSize);
} else { } else {
extract(BigInteger::minMaxBits($bits)); ['min' => $min, 'max' => $max] = BigInteger::minMaxBits($bits);
/** @var BigInteger $min
* @var BigInteger $max
*/
[$min] = $min->divide($n); [$min] = $min->divide($n);
$min = $min->add(self::$one); $min = $min->add(self::$one);
[$max] = $max->divide($n); [$max] = $max->divide($n);

View File

@ -83,13 +83,12 @@ abstract class MSBLOB
// PUBLICKEYSTRUC publickeystruc // PUBLICKEYSTRUC publickeystruc
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa387453(v=vs.85).aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/aa387453(v=vs.85).aspx
extract(unpack('atype/aversion/vreserved/Valgo', Strings::shift($key, 8))); [
/** 'type' => $type,
* @var string $type 'version' => $version,
* @var string $version 'reserved' => $reserved,
* @var integer $reserved 'algo' => $algo
* @var integer $algo ] = unpack('atype/aversion/vreserved/Valgo', Strings::shift($key, 8));
*/
switch (ord($type)) { switch (ord($type)) {
case self::PUBLICKEYBLOB: case self::PUBLICKEYBLOB:
case self::PUBLICKEYBLOBEX: case self::PUBLICKEYBLOBEX:
@ -116,12 +115,11 @@ abstract class MSBLOB
// RSAPUBKEY rsapubkey // RSAPUBKEY rsapubkey
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa387685(v=vs.85).aspx // 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 // 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))); [
/** 'magic' => $magic,
* @var integer $magic 'bitlen' => $bitlen,
* @var integer $bitlen 'pubexp' => $pubexp
* @var string $pubexp ] = unpack('Vmagic/Vbitlen/a4pubexp', Strings::shift($key, 12));
*/
switch ($magic) { switch ($magic) {
case self::RSA2: case self::RSA2:
$components['isPublicKey'] = false; $components['isPublicKey'] = false;

View File

@ -60,7 +60,12 @@ abstract class PuTTY extends Progenitor
if (!isset($components['private'])) { if (!isset($components['private'])) {
return $components; return $components;
} }
extract($components); [
'type' => $type,
'comment' => $comment,
'public' => $public,
'private' => $private
] = $components;
unset($components['public'], $components['private']); unset($components['public'], $components['private']);
$isPublicKey = false; $isPublicKey = false;

View File

@ -272,8 +272,7 @@ abstract class ASN1
// tags of indefinte length don't really have a header length; this length includes the tag // tags of indefinte length don't really have a header length; this length includes the tag
$current += ['headerlength' => $length + 2]; $current += ['headerlength' => $length + 2];
$start += $length; $start += $length;
extract(unpack('Nlength', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4))); ['length' => $length] = unpack('Nlength', substr(str_pad($temp, 4, chr(0), STR_PAD_LEFT), -4));
/** @var integer $length */
} else { } else {
$current += ['headerlength' => 2]; $current += ['headerlength' => 2];
} }

View File

@ -613,7 +613,11 @@ class X509
$extensions = &$this->subArray($root, $path, !empty($this->extensionValues)); $extensions = &$this->subArray($root, $path, !empty($this->extensionValues));
foreach ($this->extensionValues as $id => $data) { foreach ($this->extensionValues as $id => $data) {
extract($data); [
'critical' => $critical,
'replace' => $replace,
'value' => $value
] = $data;
$newext = [ $newext = [
'extnId' => $id, 'extnId' => $id,
'extnValue' => $value, 'extnValue' => $value,
@ -1787,7 +1791,7 @@ class X509
$dn = $this->getDN(self::DN_CANON, $dn); $dn = $this->getDN(self::DN_CANON, $dn);
$hash = new Hash('sha1'); $hash = new Hash('sha1');
$hash = $hash->hash($dn); $hash = $hash->hash($dn);
extract(unpack('Vhash', $hash)); ['hash' => $hash] = unpack('Vhash', $hash);
return strtolower(Strings::bin2hex(pack('N', $hash))); return strtolower(Strings::bin2hex(pack('N', $hash)));
} }

View File

@ -309,12 +309,7 @@ class BigInteger implements \JsonSerializable
*/ */
public function extendedGCD(BigInteger $n): array public function extendedGCD(BigInteger $n): array
{ {
extract($this->value->extendedGCD($n->value)); ['gcd' => $gcd, 'x' => $x, 'y' => $y] = $this->value->extendedGCD($n->value);
/**
* @var BigInteger $gcd
* @var BigInteger $x
* @var BigInteger $y
*/
return [ return [
'gcd' => new static($gcd), 'gcd' => new static($gcd),
'x' => new static($x), 'x' => new static($x),
@ -550,10 +545,7 @@ class BigInteger implements \JsonSerializable
self::initialize_static_variables(); self::initialize_static_variables();
$class = self::$mainEngine; $class = self::$mainEngine;
extract($class::minMaxBits($bits)); ['min' => $min, 'max' => $max] = $class::minMaxBits($bits);
/** @var BigInteger $min
* @var BigInteger $max
*/
return [ return [
'min' => new static($min), 'min' => new static($min),
'max' => new static($max), 'max' => new static($max),

View File

@ -274,8 +274,7 @@ class BCMath extends Engine
*/ */
public function gcd(BCMath $n): BCMath public function gcd(BCMath $n): BCMath
{ {
extract($this->extendedGCD($n)); ['gcd' => $gcd] = $this->extendedGCD($n);
/** @var BCMath $gcd */
return $gcd; return $gcd;
} }

View File

@ -92,7 +92,10 @@ abstract class Barrett extends Base
'm1' => $m1, // m.length 'm1' => $m1, // m.length
]; ];
} else { } else {
extract($cache[self::DATA][$key]); [
'u' => $u,
'm1' => $m1
] = $cache[self::DATA][$key];
} }
$cutoff = $m_length + ($m_length >> 1); $cutoff = $m_length + ($m_length >> 1);

View File

@ -311,11 +311,7 @@ abstract class Engine implements \JsonSerializable
return $this->normalize($n->subtract($temp)); return $this->normalize($n->subtract($temp));
} }
extract($this->extendedGCD($n)); ['gcd' => $gcd, 'x' => $x] = $this->extendedGCD($n);
/**
* @var Engine $gcd
* @var Engine $x
*/
if (!$gcd->equals(static::$one[static::class])) { if (!$gcd->equals(static::$one[static::class])) {
return false; return false;
@ -706,11 +702,7 @@ abstract class Engine implements \JsonSerializable
*/ */
public static function random(int $size): Engine public static function random(int $size): Engine
{ {
extract(static::minMaxBits($size)); ['min' => $min, 'max' => $max] = static::minMaxBits($size);
/**
* @var BigInteger $min
* @var BigInteger $max
*/
return static::randomRange($min, $max); return static::randomRange($min, $max);
} }
@ -721,11 +713,7 @@ abstract class Engine implements \JsonSerializable
*/ */
public static function randomPrime(int $size): Engine public static function randomPrime(int $size): Engine
{ {
extract(static::minMaxBits($size)); ['min' => $min, 'max' => $max] = static::minMaxBits($size);
/**
* @var static $min
* @var static $max
*/
return static::randomRangePrime($min, $max); return static::randomRangePrime($min, $max);
} }

View File

@ -271,7 +271,11 @@ class GMP extends Engine
*/ */
public function extendedGCD(GMP $n): array public function extendedGCD(GMP $n): array
{ {
extract(gmp_gcdext($this->value, $n->value)); [
'g' => $g,
's' => $s,
't' => $t
] = gmp_gcdext($this->value, $n->value);
return [ return [
'gcd' => $this->normalize(new self($g)), 'gcd' => $this->normalize(new self($g)),

View File

@ -97,7 +97,10 @@ abstract class Barrett extends Base
'm1' => $m1, // m.length 'm1' => $m1, // m.length
]; ];
} else { } else {
extract($cache[self::DATA][$key]); [
'u' => $u,
'm1' => $m1
] = $cache[self::DATA][$key];
} }
$cutoff = $m_length + ($m_length >> 1); $cutoff = $m_length + ($m_length >> 1);

View File

@ -3027,8 +3027,7 @@ class SFTP extends SSH2
if (strlen($this->packet_buffer) < 4) { if (strlen($this->packet_buffer) < 4) {
throw new RuntimeException('Packet is too small'); throw new RuntimeException('Packet is too small');
} }
extract(unpack('Nlength', Strings::shift($this->packet_buffer, 4))); ['length' => $length] = unpack('Nlength', Strings::shift($this->packet_buffer, 4));
/** @var integer $length */
$tempLength = $length; $tempLength = $length;
$tempLength -= strlen($this->packet_buffer); $tempLength -= strlen($this->packet_buffer);
@ -3058,7 +3057,7 @@ class SFTP extends SSH2
$this->packet_type = ord(Strings::shift($this->packet_buffer)); $this->packet_type = ord(Strings::shift($this->packet_buffer));
if ($this->use_request_id) { if ($this->use_request_id) {
extract(unpack('Npacket_id', Strings::shift($this->packet_buffer, 4))); // remove the request id ['packet_id' => $packet_id] = unpack('Npacket_id', Strings::shift($this->packet_buffer, 4)); // remove the request id
$length -= 5; // account for the request id and the packet type $length -= 5; // account for the request id and the packet type
} else { } else {
$length -= 1; // account for the packet type $length -= 1; // account for the packet type

View File

@ -124,7 +124,15 @@ class Stream
protected function parse_path(string $path) protected function parse_path(string $path)
{ {
$orig = $path; $orig = $path;
extract(parse_url($path) + ['port' => 22]); $url = parse_url($path) + ['port' => 22];
$keys = ['scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment'];
foreach ($keys as $key) {
if (isset($url[$key])) {
$$key = $url[$key];
}
}
if (isset($query)) { if (isset($query)) {
$path .= '?' . $query; $path .= '?' . $query;
} elseif (preg_match('/(\?|\?#)$/', $orig)) { } elseif (preg_match('/(\?|\?#)$/', $orig)) {

View File

@ -3408,7 +3408,7 @@ class SSH2
} }
$padding_length = 0; $padding_length = 0;
$payload = $packet->plain; $payload = $packet->plain;
extract(unpack('Cpadding_length', Strings::shift($payload, 1))); ['padding_length' => $padding_length] = unpack('Cpadding_length', Strings::shift($payload, 1));
if ($padding_length > 0) { if ($padding_length > 0) {
Strings::pop($payload, $padding_length); Strings::pop($payload, $padding_length);
} }
@ -3500,13 +3500,13 @@ class SSH2
switch ($this->decryptName) { switch ($this->decryptName) {
case 'aes128-gcm@openssh.com': case 'aes128-gcm@openssh.com':
case 'aes256-gcm@openssh.com': case 'aes256-gcm@openssh.com':
extract(unpack('Npacket_length', substr($packet->raw, 0, $packet_length_header_size))); ['packet_length' => $packet_length] = unpack('Npacket_length', substr($packet->raw, 0, $packet_length_header_size));
$packet->size = $packet_length_header_size + $packet_length + $this->decrypt_block_size; // expect tag $packet->size = $packet_length_header_size + $packet_length + $this->decrypt_block_size; // expect tag
break; break;
case 'chacha20-poly1305@openssh.com': case 'chacha20-poly1305@openssh.com':
$this->lengthDecrypt->setNonce(pack('N2', 0, $this->get_seq_no)); $this->lengthDecrypt->setNonce(pack('N2', 0, $this->get_seq_no));
$packet_length_header = $this->lengthDecrypt->decrypt(substr($packet->raw, 0, $packet_length_header_size)); $packet_length_header = $this->lengthDecrypt->decrypt(substr($packet->raw, 0, $packet_length_header_size));
extract(unpack('Npacket_length', $packet_length_header)); ['packet_length' => $packet_length] = unpack('Npacket_length', $packet_length_header);
$packet->size = $packet_length_header_size + $packet_length + 16; // expect tag $packet->size = $packet_length_header_size + $packet_length + 16; // expect tag
break; break;
default: default:
@ -3515,17 +3515,17 @@ class SSH2
return; return;
} }
$packet->plain = $this->decrypt->decrypt(substr($packet->raw, 0, $this->decrypt_block_size)); $packet->plain = $this->decrypt->decrypt(substr($packet->raw, 0, $this->decrypt_block_size));
extract(unpack('Npacket_length', Strings::shift($packet->plain, $packet_length_header_size))); ['packet_length' => $packet_length] = unpack('Npacket_length', Strings::shift($packet->plain, $packet_length_header_size));
$packet->size = $packet_length_header_size + $packet_length; $packet->size = $packet_length_header_size + $packet_length;
$added_validation_length = $packet_length_header_size; $added_validation_length = $packet_length_header_size;
} else { } else {
extract(unpack('Npacket_length', substr($packet->raw, 0, $packet_length_header_size))); ['packet_length' => $packet_length] = unpack('Npacket_length', substr($packet->raw, 0, $packet_length_header_size));
$packet->size = $packet_length_header_size + $packet_length; $packet->size = $packet_length_header_size + $packet_length;
} }
break; break;
} }
} else { } else {
extract(unpack('Npacket_length', substr($packet->raw, 0, $packet_length_header_size))); ['packet_length' => $packet_length] = unpack('Npacket_length', substr($packet->raw, 0, $packet_length_header_size));
$packet->size = $packet_length_header_size + $packet_length; $packet->size = $packet_length_header_size + $packet_length;
$added_validation_length = $packet_length_header_size; $added_validation_length = $packet_length_header_size;
} }
@ -3621,7 +3621,11 @@ class SSH2
switch (ord($payload[0])) { switch (ord($payload[0])) {
case MessageType::CHANNEL_REQUEST: case MessageType::CHANNEL_REQUEST:
if (strlen($payload) == 31) { if (strlen($payload) == 31) {
extract(unpack('cpacket_type/Nchannel/Nlength', $payload)); [
'packet_type' => $packet_type,
'channel' => $channel,
'length' => $length
] = unpack('cpacket_type/Nchannel/Nlength', $payload);
if (substr($payload, 9, $length) == 'keepalive@openssh.com' && isset($this->server_channels[$channel])) { if (substr($payload, 9, $length) == 'keepalive@openssh.com' && isset($this->server_channels[$channel])) {
if (ord(substr($payload, 9 + $length))) { // want reply if (ord(substr($payload, 9 + $length))) { // want reply
$this->send_binary_packet(pack('CN', MessageType::CHANNEL_SUCCESS, $this->server_channels[$channel])); $this->send_binary_packet(pack('CN', MessageType::CHANNEL_SUCCESS, $this->server_channels[$channel]));