diff --git a/build/psalm_baseline.xml b/build/psalm_baseline.xml
index c8e51960..997f3e58 100644
--- a/build/psalm_baseline.xml
+++ b/build/psalm_baseline.xml
@@ -14401,57 +14401,32 @@
$longname
$result
-
- chgrp
- chown
- clearStatCache
+
disableArbitraryLengthPackets
disableDatePreservation
disablePathCanonicalization
enableArbitraryLengthPackets
enableDatePreservation
enablePathCanonicalization
- enableStatCache
- file_exists
fileatime
filegroup
filemtime
fileowner
fileperms
filetype
- get
- getLastSFTPError
getNegotiatedVersion
getSFTPErrors
getSFTPLog
getSupportedVersions
- is_dir
- is_file
- is_link
- is_readable
- is_writeable
- rawlist
- readlink
- rename
- rmdir
- setListOrder
setPreferredVersion
- symlink
- touch
- truncate
-
- bool
-
-
+
$defaultVersion
$log_size
$realtime_log_file
$realtime_log_size
$realtime_log_wrap
$version
- SFTP
- SFTP
(int) $ver
@@ -14520,8 +14495,20 @@
false
false
-
+
+ $options & STREAM_MKDIR_RECURSIVE
+ $path
+
+
+ $results
+ $results
+ $this->sftp->fsock
+
+
bool
+ bool
+ bool
+ resource
$var
@@ -14530,7 +14517,8 @@
_dir_readdir
_stream_read
-
+
+ $atime
$host
$host
$host
@@ -14538,10 +14526,12 @@
$pass
$pass
$port
- $result
- $result
+ $time
$user
$user
+ $var
+ $var
+ $var
$context[$scheme]
@@ -14567,18 +14557,13 @@
self::$instances[$host][$port]
self::$instances[$host][$port]
-
+
$argument
$atime
$pass
$pass
- $result
- $result
- $results
- $results
$sftp
$sftp
- $this->entries
$this->notification
$this->pos
$this->sftp
@@ -14586,38 +14571,9 @@
$time
$user
-
- bool
- bool
- bool
- bool
- bool
- resource
+
string
-
- chgrp
- chmod
- chown
- delete
- delete
- filesize
- get
- lstat
- mkdir
- nlist
- put
- rename
- rename
- rmdir
- stat
- stat
- stat
- touch
- touch
- truncate
- truncate
-
$fragment
$path
@@ -14626,30 +14582,29 @@
$path
$query
-
+
$path
$path
- $results
- $results
- $this->sftp->chgrp($path, $var)
- $this->sftp->chown($path, $var)
- $this->sftp->delete($path, false)
- $this->sftp->fsock
- $this->sftp->mkdir($path, $mode, $options & STREAM_MKDIR_RECURSIVE)
- $this->sftp->rmdir($path)
- $this->sftp->touch($path, $time, $atime)
-
+
+ $this->sftp->fsock
+
+
+ $this->size
parse_url($path)
+
+ $this->sftp->nlist($path)
+
+
+ $result
+ $result
+
$path1['path']
$path2['path']
$path_to['path']
-
- $host
-
$this->mode[0]
$this->mode[0]
@@ -14682,6 +14637,9 @@
$sftp
$size
+
+ $host
+
isset($this->notification) && is_callable($this->notification)
isset($this->notification) && is_callable($this->notification)
@@ -14703,15 +14661,13 @@
-
+
$arg instanceof Agent
$arg instanceof PrivateKey || $arg instanceof Agent
$request_channel === false
- $this->session_id === false
is_array($arg)
is_array($arg)
is_array($arg)
- is_null($this->exit_status)
isset($realtime_log_file)
@@ -14730,17 +14686,11 @@
int
string
-
- bool|SSH2
-
-
- $this->curTimeout -= $elapsed
- $this->curTimeout -= $elapsed
- $this->curTimeout -= $elapsed
- $this->curTimeout -= $elapsed
- $this->curTimeout -= $elapsed
-
-
+
+ $temp
+
+
+ array<string, SSH2>
array{Hash, int}|null
string
@@ -14750,16 +14700,12 @@
$password
$responses
-
- $keepAlive
- $quiet_mode
-
connect
get_channel_packet
keyboard_interactive_process
-
+
$a['comp']
$a['crypt']
$a['mac']
@@ -14790,7 +14736,6 @@
$keyBytes
$keyBytes
$length
- $length
$m
$m
$mac_algorithm_in
@@ -14837,7 +14782,6 @@
$skip_channel_filter
$stop - $start
$temp
- $temp
$temp['length']
$theirPublicBytes
$theirPublicBytes
@@ -14846,8 +14790,6 @@
$this->compression_algorithms_server_to_client
$this->encryption_algorithms_client_to_server
$this->encryption_algorithms_server_to_client
- $this->keepAlive
- $this->keepAlive
$this->kex_algorithm
$this->kex_algorithm
$this->kex_algorithm
@@ -14921,7 +14863,7 @@
$this->window_size_server_to_client[$channel]
$this->window_size_server_to_client[$channel]
-
+
$a
$algo
$auth
@@ -14941,7 +14883,6 @@
$kex_algorithms
$key
$keyBytes
- $length
$m
$mac_algorithm_in
$mac_algorithm_out
@@ -14969,8 +14910,6 @@
$server_host_key_algorithms
$signature
$temp
- $temp
- $temp[$key]
$this->auth_methods_to_continue
$this->auth_methods_to_continue
$this->auth_methods_to_continue
@@ -14989,20 +14928,15 @@
$window_size
$window_size
-
- bool
+
bool
bool
boolean
string|bool|null
-
- decrypt
- encrypt
+
getCurve
getEncodedCoordinates
- setNonce
- setNonce
sign
withHash
@@ -15037,27 +14971,23 @@
$window_size
$window_size
-
+
!Strings::is_stringable($password) && !is_array($password) ? false : $this->keyboard_interactive_process($password)
$result
$this->errors[$count - 1]
$this->get_channel_packet($channel)
$this->keyboard_interactive_process($password)
- $this->quiet_mode
-
- $temp
+
$this->errors
- array<string, SSH2>
string[]
-
- self::$connections[$id] instanceof \WeakReference ? self::$connections[$id]->get() : self::$connections[$id]
-
-
+
$data
$logged
$nonce
+ $nonce
+ $nonce
$packet
$packet
$packet
@@ -15081,6 +15011,7 @@
$reconstructed
$tag
$tag
+ $this->hmac_size
$this->server_host_key_algorithms
$this->server_identifier
pack('C', MessageType::REQUEST_FAILURE)
@@ -15128,22 +15059,16 @@
pack('N', $this->send_seq_no)
pack('N', $this->send_seq_no)
-
- $this->hmac_create = false
+
@fsockopen($this->host, $this->port, $errno, $errstr, $this->curTimeout == 0 ? 100000 : $this->curTimeout)
- false
- false
- false
- false
- false
- false
- false
- false
- false
- false
- false
inflate_init(ZLIB_ENCODING_RAW, ['window' => $cinfo + 8])
+
+ decrypt
+ encrypt
+ setNonce
+ setNonce
+
$args
$engine
@@ -15169,7 +15094,8 @@
$args
-
+
+ $this->curTimeout == 0 ? 100000 : $this->curTimeout
$this->decryptInvocationCounter
$this->encryptInvocationCounter
array_shift($message_log)
@@ -15206,9 +15132,6 @@
$this->server_channels[self::CHANNEL_SHELL]
$this->server_channels[self::CHANNEL_SUBSYSTEM]
-
- get
-
$temp['length']
@@ -15250,24 +15173,24 @@
startSubsystem
stopSubsystem
-
- $preferred_signature_format
-
($callback is callable ? bool : string|bool)
-
+
$agent
- $curTimeout
$decompress_context
- $exit_status
+ $decryptFixedPart
+ $decryptInvocationCounter
+ $decryptName
+ $encryptFixedPart
+ $encryptInvocationCounter
+ $encryptName
$hmac_check_etm
$hmac_check_name
$hmac_create_etm
$hmac_create_name
$host
$identifier
- $in_subsystem
$last_packet
$log_size
$port
@@ -15276,13 +15199,13 @@
$realtime_log_wrap
$server_public_host_key
$stdErrorLog
- $timeout
-
- $this->session_id !== false
+
+ isset($this->keyboard_requests_responses)
+
+
Strings::is_stringable($arg)
is_bool($agent_response)
- isset($this->keyboard_requests_responses)
isset($this->realtime_log_file) && is_resource($this->realtime_log_file)
@@ -15503,48 +15426,18 @@
-
+
+ SORT_ASC
+ SORT_DESC
+ SORT_DESC
+
+
$length
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
- $sftp
-
+
$buffer
$exampleData
$exampleDataLength
- $scratchDir
demoCallback
@@ -15583,17 +15476,42 @@
testUploadOffsets
+ $file
$length
+ $sftp::SOURCE_CALLBACK
+ $stat['gid']
+ $stat['uid']
+ self::$buffer
+ self::$exampleData
+ self::$exampleData
+ self::$exampleDataLength - 100
+
+
+ $cur_size
+ $file
+ $last_size
+ self::$buffer
+
+
+ self::$exampleData
+ self::$exampleDataLength
+ self::$exampleDataLength
+
+
+ $fp
+ $fp
+ $fp
+
+
+ $files
+
+
+ $pwd
$pwd
$sftp->pwd()
$sftp->pwd()
- self::$buffer
- self::$exampleData
- self::$scratchDir
- self::$scratchDir
- self::$scratchDir
-
-
+
+
$stat2['gid']
$stat2['uid']
$stat['gid']
@@ -15608,176 +15526,23 @@
$stat['type']
$stat['uid']
$stat['uid']
-
-
- $cur_size
- $dirname
- $file
- $files
- $last_size
- $list
- $list
- $list_cache_disabled
- $list_cache_enabled
- $lstat
- $lstat
- $pwd
- $stat
- $stat
- $stat
- $stat
- $stat
- $stat
- $stat
- $stat
- $stat
- $stat
- $stat
- $stat2
- self::$buffer
-
-
- chdir
- chdir
- chdir
- chdir
- chdir
- chdir
- chdir
- chdir
- chdir
- chgrp
- chmod
- chmod
- chmod
- chown
- clearStatCache
- clearStatCache
- clearStatCache
- delete
- delete
- delete
- disableStatCache
- disableStatCache
- enablePTY
- enableStatCache
- exec
- file_exists
- file_exists
- file_exists
- file_exists
- file_exists
- filesize
- filesize
- filesize
- filesize
- filesize
- filesize
- get
- get
- get
- get
- get
- get
- get
- is_dir
- is_dir
- is_dir
- is_dir
- is_dir
- is_dir
- is_file
- is_file
- is_file
- is_file
- is_file
- is_file
- is_file
- is_link
- is_readable
- is_readable
- is_readable
- is_writable
- is_writable
- is_writable
- is_writeable
- is_writeable
- is_writeable
- login
- lstat
- lstat
- lstat
- lstat
- lstat
- lstat
- mkdir
- mkdir
- mkdir
- mkdir
- mkdir
- mkdir
- mkdir
- mkdir
- mkdir
- nlist
- nlist
- nlist
- nlist
- nlist
- nlist
- put
- put
- put
- put
- put
- put
- put
- put
- put
- pwd
- pwd
- pwd
- pwd
- pwd
- rawlist
- rawlist
- readlink
- rmdir
- rmdir
- setListOrder
- setListOrder
- setListOrder
- stat
- stat
- stat
- stat
- stat
- stat
- stat
- stat
- stat
- stat
- stat
- symlink
- symlink
- symlink
- touch
- touch
- touch
- touch
- truncate
- truncate
-
-
- self::$exampleData
- self::$exampleDataLength
- self::$exampleDataLength
- self::$scratchDir
-
-
- $fp
- $fp
-
+
+
+ $stat2['gid']
+ $stat2['uid']
+ $stat['gid']
+ $stat['gid']
+ $stat['type']
+ $stat['type']
+ $stat['type']
+ $stat['type']
+ $stat['type']
+ $stat['type']
+ $stat['type']
+ $stat['type']
+ $stat['uid']
+ $stat['uid']
+
SFTPUserStoryTest
SFTPUserStoryTest
diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php
index 964b5f95..d9ed3a36 100644
--- a/phpseclib/Net/SFTP.php
+++ b/phpseclib/Net/SFTP.php
@@ -105,10 +105,9 @@ class SFTP extends SSH2
* The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support
* concurrent actions, so it's somewhat academic, here.
*
- * @var boolean
* @see self::_send_sftp_packet()
*/
- private $use_request_id = false;
+ private bool $use_request_id = false;
/**
* The Packet Type
@@ -116,75 +115,66 @@ class SFTP extends SSH2
* The request ID exists in the off chance that a packet is sent out-of-order. Of course, this library doesn't support
* concurrent actions, so it's somewhat academic, here.
*
- * @var int
* @see self::_get_sftp_packet()
*/
- private $packet_type = -1;
+ private int $packet_type = -1;
/**
* Packet Buffer
*
- * @var string
* @see self::_get_sftp_packet()
*/
- private $packet_buffer = '';
+ private string $packet_buffer = '';
/**
* Extensions supported by the server
*
- * @var array
* @see self::_initChannel()
*/
- private $extensions = [];
+ private array $extensions = [];
/**
* Server SFTP version
*
- * @var int
* @see self::_initChannel()
*/
- private $version;
+ private int $version;
/**
* Default Server SFTP version
*
- * @var int
* @see self::_initChannel()
*/
- private $defaultVersion;
+ private int $defaultVersion;
/**
* Preferred SFTP version
*
- * @var int
* @see self::_initChannel()
*/
- private $preferredVersion = 3;
+ private int $preferredVersion = 3;
/**
* Current working directory
*
- * @var string|bool
* @see self::realpath()
* @see self::chdir()
*/
- private $pwd = false;
+ private string|bool $pwd = false;
/**
* Packet Type Log
*
* @see self::getLog()
- * @var array
*/
- private $packet_type_log = [];
+ private array $packet_type_log = [];
/**
* Packet Log
*
* @see self::getLog()
- * @var array
*/
- private $packet_log = [];
+ private array $packet_log = [];
/**
* Real-time log file pointer
@@ -198,35 +188,30 @@ class SFTP extends SSH2
* Real-time log file size
*
* @see self::_append_log()
- * @var int
*/
- private $realtime_log_size;
+ private int $realtime_log_size;
/**
* Real-time log file wrap boolean
*
* @see self::_append_log()
- * @var bool
*/
- private $realtime_log_wrap;
+ private bool $realtime_log_wrap;
/**
* Current log size
*
* Should never exceed self::LOG_MAX_SIZE
- *
- * @var int
*/
- private $log_size;
+ private int $log_size;
/**
* Error information
*
* @see self::getSFTPErrors()
* @see self::getLastSFTPError()
- * @var array
*/
- private $sftp_errors = [];
+ private array $sftp_errors = [];
/**
* Stat Cache
@@ -237,36 +222,32 @@ class SFTP extends SSH2
* @see self::_update_stat_cache()
* @see self::_remove_from_stat_cache()
* @see self::_query_stat_cache()
- * @var array
*/
- private $stat_cache = [];
+ private array $stat_cache = [];
/**
* Max SFTP Packet Size
*
* @see self::__construct()
* @see self::get()
- * @var int
*/
- private $max_sftp_packet;
+ private int $max_sftp_packet;
/**
* Stat Cache Flag
*
* @see self::disableStatCache()
* @see self::enableStatCache()
- * @var bool
*/
- private $use_stat_cache = true;
+ private bool $use_stat_cache = true;
/**
* Sort Options
*
* @see self::_comparator()
* @see self::setListOrder()
- * @var array
*/
- protected $sortOptions = [];
+ private array $sortOptions = [];
/**
* Canonicalization Flag
@@ -277,26 +258,23 @@ class SFTP extends SSH2
* @see self::enablePathCanonicalization()
* @see self::disablePathCanonicalization()
* @see self::realpath()
- * @var bool
*/
- private $canonicalize_paths = true;
+ private bool $canonicalize_paths = true;
/**
* Request Buffers
*
* @see self::_get_sftp_packet()
- * @var array
*/
- private $requestBuffer = [];
+ private array $requestBuffer = [];
/**
* Preserve timestamps on file downloads / uploads
*
* @see self::get()
* @see self::put()
- * @var bool
*/
- private $preserveTime = false;
+ private bool $preserveTime = false;
/**
* Arbitrary Length Packets Flag
@@ -308,30 +286,24 @@ class SFTP extends SSH2
*
* @see self::enableArbitraryLengthPackets()
* @see self::_get_sftp_packet()
- * @var bool
*/
- private $allow_arbitrary_length_packets = false;
+ private bool $allow_arbitrary_length_packets = false;
/**
* Was the last packet due to the channels being closed or not?
*
* @see self::get()
* @see self::get_sftp_packet()
- * @var bool
*/
- private $channel_close = false;
+ private bool $channel_close = false;
/**
* Has the SFTP channel been partially negotiated?
- *
- * @var bool
*/
- private $partial_init = false;
+ private bool $partial_init = false;
- /** @var int */
- private $queueSize = 32;
- /** @var int */
- private $uploadQueueSize = 1024;
+ private int $queueSize = 32;
+ private int $uploadQueueSize = 1024;
/**
* Default Constructor.
diff --git a/phpseclib/Net/SFTP/Stream.php b/phpseclib/Net/SFTP/Stream.php
index 3c330492..8bd71ac8 100644
--- a/phpseclib/Net/SFTP/Stream.php
+++ b/phpseclib/Net/SFTP/Stream.php
@@ -33,59 +33,43 @@ class Stream
* SFTP instances
*
* Rather than re-create the connection we re-use instances if possible
- *
- * @var array
*/
- public static $instances;
+ public static array $instances;
/**
* SFTP instance
- *
- * @var object
*/
- private $sftp;
+ private SFTP $sftp;
/**
* Path
- *
- * @var string
*/
- private $path;
+ private string $path;
/**
* Mode
- *
- * @var string
*/
- private $mode;
+ private string $mode;
/**
* Position
- *
- * @var int
*/
- private $pos;
+ private int $pos;
/**
* Size
- *
- * @var int
*/
- private $size;
+ private int|false $size;
/**
* Directory entries
- *
- * @var array
*/
- private $entries;
+ private array $entries;
/**
* EOF flag
- *
- * @var bool
*/
- private $eof;
+ private bool $eof;
/**
* Context resource
@@ -165,7 +149,7 @@ class Stream
if (preg_match('/^{[a-z0-9]+}$/i', $host)) {
$host = SSH2::getConnectionByResourceId($host);
- if ($host === false) {
+ if ($host === null) {
return false;
}
$this->sftp = $host;
diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php
index 8485bbb6..f3e85b6a 100644
--- a/phpseclib/Net/SSH2.php
+++ b/phpseclib/Net/SSH2.php
@@ -192,10 +192,8 @@ class SSH2
/**
* The SSH identifier
- *
- * @var string
*/
- private $identifier;
+ private string $identifier;
/**
* The Socket Object
@@ -209,147 +207,124 @@ class SSH2
*
* The bits that are set represent functions that have been called already. This is used to determine
* if a requisite function has been successfully executed. If not, an error should be thrown.
- *
- * @var int
*/
- protected $bitmap = 0;
+ protected int $bitmap = 0;
/**
* Error information
*
* @see self::getErrors()
* @see self::getLastError()
- * @var array
*/
- private $errors = [];
+ private array $errors = [];
/**
* Server Identifier
*
* @see self::getServerIdentification()
- * @var string|false
*/
- protected $server_identifier = false;
+ protected string|false $server_identifier = false;
/**
* Key Exchange Algorithms
*
* @see self::getKexAlgorithims()
- * @var array|false
*/
- private $kex_algorithms = false;
+ private array|false $kex_algorithms = false;
/**
* Key Exchange Algorithm
*
* @see self::getMethodsNegotiated()
- * @var string|false
*/
- private $kex_algorithm = false;
+ private string|false $kex_algorithm = false;
/**
* Minimum Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods
*
* @see self::_key_exchange()
- * @var int
*/
- private $kex_dh_group_size_min = 1536;
+ private int $kex_dh_group_size_min = 1536;
/**
* Preferred Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods
*
* @see self::_key_exchange()
- * @var int
*/
- private $kex_dh_group_size_preferred = 2048;
+ private int $kex_dh_group_size_preferred = 2048;
/**
* Maximum Diffie-Hellman Group Bit Size in RFC 4419 Key Exchange Methods
*
* @see self::_key_exchange()
- * @var int
*/
- private $kex_dh_group_size_max = 4096;
+ private int $kex_dh_group_size_max = 4096;
/**
* Server Host Key Algorithms
*
* @see self::getServerHostKeyAlgorithms()
- * @var array|false
*/
- private $server_host_key_algorithms = false;
+ private array|false $server_host_key_algorithms = false;
/**
* Encryption Algorithms: Client to Server
*
* @see self::getEncryptionAlgorithmsClient2Server()
- * @var array|false
*/
- private $encryption_algorithms_client_to_server = false;
+ private array|false $encryption_algorithms_client_to_server = false;
/**
* Encryption Algorithms: Server to Client
*
* @see self::getEncryptionAlgorithmsServer2Client()
- * @var array|false
*/
- private $encryption_algorithms_server_to_client = false;
+ private array|false $encryption_algorithms_server_to_client = false;
/**
* MAC Algorithms: Client to Server
*
* @see self::getMACAlgorithmsClient2Server()
- * @var array|false
*/
- private $mac_algorithms_client_to_server = false;
+ private array|false $mac_algorithms_client_to_server = false;
/**
* MAC Algorithms: Server to Client
*
* @see self::getMACAlgorithmsServer2Client()
- * @var array|false
*/
- private $mac_algorithms_server_to_client = false;
+ private array|false $mac_algorithms_server_to_client = false;
/**
* Compression Algorithms: Client to Server
*
* @see self::getCompressionAlgorithmsClient2Server()
- * @var array|false
*/
- private $compression_algorithms_client_to_server = false;
+ private array|false $compression_algorithms_client_to_server = false;
/**
* Compression Algorithms: Server to Client
*
* @see self::getCompressionAlgorithmsServer2Client()
- * @var array|false
*/
- private $compression_algorithms_server_to_client = false;
+ private array|false $compression_algorithms_server_to_client = false;
/**
* Languages: Server to Client
- *
- * @see self::getLanguagesServer2Client()
- * @var array|false
*/
- private $languages_server_to_client = false;
+ private array|false $languages_server_to_client = false;
/**
* Languages: Client to Server
- *
- * @see self::getLanguagesClient2Server()
- * @var array|false
*/
- private $languages_client_to_server = false;
+ private array|false $languages_client_to_server = false;
/**
* Preferred Algorithms
*
* @see self::setPreferredAlgorithms()
- * @var array
*/
- private $preferred = [];
+ private array $preferred = [];
/**
* Block Size for Server to Client Encryption
@@ -362,145 +337,117 @@ class SSH2
* -- http://tools.ietf.org/html/rfc4253#section-6
*
* @see self::__construct()
- * @see self::_send_binary_packet()
- * @var int
+ * @see self::send_binary_packet()
*/
- private $encrypt_block_size = 8;
+ private int $encrypt_block_size = 8;
/**
* Block Size for Client to Server Encryption
*
* @see self::__construct()
- * @see self::_get_binary_packet()
- * @var int
+ * @see self::get_binary_packet()
*/
- private $decrypt_block_size = 8;
+ private int $decrypt_block_size = 8;
/**
* Server to Client Encryption Object
*
- * @see self::_get_binary_packet()
- * @var SymmetricKey|false
+ * @see self::get_binary_packet()
*/
- private $decrypt = false;
+ private SymmetricKey|false $decrypt = false;
/**
* Decryption Algorithm Name
- *
- * @var string|null
*/
- private $decryptName;
+ private string|null $decryptName;
/**
* Decryption Invocation Counter
*
* Used by GCM
- *
- * @var string|null
*/
- private $decryptInvocationCounter;
+ private string|null $decryptInvocationCounter;
/**
* Fixed Part of Nonce
*
* Used by GCM
- *
- * @var string|null
*/
- private $decryptFixedPart;
+ private string|null $decryptFixedPart;
/**
* Server to Client Length Encryption Object
*
- * @see self::_get_binary_packet()
- * @var object
+ * @see self::get_binary_packet()
*/
- private $lengthDecrypt = false;
+ private SymmetricKey|false $lengthDecrypt = false;
/**
* Client to Server Encryption Object
*
- * @see self::_send_binary_packet()
- * @var SymmetricKey|false
+ * @see self::send_binary_packet()
*/
- private $encrypt = false;
+ private SymmetricKey|false $encrypt = false;
/**
* Encryption Algorithm Name
- *
- * @var string|null
*/
- private $encryptName;
+ private string|null $encryptName;
/**
* Encryption Invocation Counter
*
* Used by GCM
- *
- * @var string|null
*/
- private $encryptInvocationCounter;
+ private string|null $encryptInvocationCounter;
/**
* Fixed Part of Nonce
*
* Used by GCM
- *
- * @var string|null
*/
- private $encryptFixedPart;
+ private string|null $encryptFixedPart;
/**
* Client to Server Length Encryption Object
*
- * @see self::_send_binary_packet()
- * @var object
+ * @see self::send_binary_packet()
*/
- private $lengthEncrypt = false;
+ private SymmetricKey|false $lengthEncrypt = false;
/**
* Client to Server HMAC Object
*
- * @see self::_send_binary_packet()
- * @var object
+ * @see self::send_binary_packet()
*/
- private $hmac_create = false;
+ private Hash|\stdClass|false $hmac_create = false;
/**
* Client to Server HMAC Name
- *
- * @var string|false
*/
- private $hmac_create_name;
+ private string|false $hmac_create_name;
/**
* Client to Server ETM
- *
- * @var int|false
*/
- private $hmac_create_etm;
+ private int|false $hmac_create_etm;
/**
* Server to Client HMAC Object
*
- * @see self::_get_binary_packet()
- * @var object
+ * @see self::get_binary_packet()
*/
- private $hmac_check = false;
+ private Hash|\stdClass|false $hmac_check = false;
/**
* Server to Client HMAC Name
- *
- * @var string|false
*/
- private $hmac_check_name;
+ private string|false $hmac_check_name;
/**
* Server to Client ETM
- *
- * @var int|false
*/
- private $hmac_check_etm;
+ private int|false $hmac_check_etm;
/**
* Size of server to client HMAC
@@ -509,18 +456,16 @@ class SSH2
* For the client to server side, the HMAC object will make the HMAC as long as it needs to be. All we need to do is
* append it.
*
- * @see self::_get_binary_packet()
- * @var int
+ * @see self::get_binary_packet()
*/
- private $hmac_size = false;
+ private int|false $hmac_size = false;
/**
* Server Public Host Key
*
* @see self::getServerPublicHostKey()
- * @var string
*/
- private $server_public_host_key;
+ private string $server_public_host_key;
/**
* Session identifier
@@ -531,40 +476,36 @@ class SSH2
*
* -- http://tools.ietf.org/html/rfc4253#section-7.2
*
- * @see self::_key_exchange()
- * @var string
+ * @see self::key_exchange()
*/
- private $session_id = false;
+ private string|false $session_id = false;
/**
* Exchange hash
*
* The current exchange hash
*
- * @see self::_key_exchange()
- * @var string
+ * @see self::key_exchange()
*/
- private $exchange_hash = false;
+ private string|false $exchange_hash = false;
/**
* Send Sequence Number
*
* See 'Section 6.4. Data Integrity' of rfc4253 for more info.
*
- * @see self::_send_binary_packet()
- * @var int
+ * @see self::send_binary_packet()
*/
- private $send_seq_no = 0;
+ private int $send_seq_no = 0;
/**
* Get Sequence Number
*
* See 'Section 6.4. Data Integrity' of rfc4253 for more info.
*
- * @see self::_get_binary_packet()
- * @var int
+ * @see self::get_binary_packet()
*/
- private $get_seq_no = 0;
+ private int $get_seq_no = 0;
/**
* Server Channels
@@ -573,9 +514,8 @@ class SSH2
*
* @see self::get_channel_packet()
* @see self::exec()
- * @var array
*/
- protected $server_channels = [];
+ protected array $server_channels = [];
/**
* Channel Buffers
@@ -585,9 +525,8 @@ class SSH2
*
* @see self::get_channel_packet()
* @see self::exec()
- * @var array
*/
- private $channel_buffers = [];
+ private array $channel_buffers = [];
/**
* Channel Status
@@ -595,9 +534,8 @@ class SSH2
* Contains the type of the last sent message
*
* @see self::get_channel_packet()
- * @var array
*/
- protected $channel_status = [];
+ protected array $channel_status = [];
/**
* Packet Size
@@ -605,36 +543,32 @@ class SSH2
* Maximum packet size indexed by channel
*
* @see self::send_channel_packet()
- * @var array
*/
- private $packet_size_client_to_server = [];
+ private array $packet_size_client_to_server = [];
/**
* Message Number Log
*
* @see self::getLog()
- * @var array
*/
- private $message_number_log = [];
+ private array $message_number_log = [];
/**
* Message Log
*
* @see self::getLog()
- * @var array
*/
- private $message_log = [];
+ private array $message_log = [];
/**
* The Window Size
*
* Bytes the other party can send before it must wait for the window to be adjusted (0x7FFFFFFF = 2GB)
*
- * @var int
* @see self::send_channel_packet()
* @see self::exec()
*/
- protected $window_size = 0x7FFFFFFF;
+ protected int $window_size = 0x7FFFFFFF;
/**
* What we resize the window to
@@ -643,11 +577,10 @@ class SSH2
* Some SFTP clients (GoAnywhere) don't support adding 0x7FFFFFFF to the window size after the fact so
* we'll just do what PuTTY does
*
- * @var int
* @see self::_send_channel_packet()
* @see self::exec()
*/
- private $window_resize = 0x40000000;
+ private int $window_resize = 0x40000000;
/**
* Window size, server to client
@@ -655,9 +588,8 @@ class SSH2
* Window size indexed by channel
*
* @see self::send_channel_packet()
- * @var array
*/
- protected $window_size_server_to_client = [];
+ protected array $window_size_server_to_client = [];
/**
* Window size, client to server
@@ -665,9 +597,8 @@ class SSH2
* Window size indexed by channel
*
* @see self::get_channel_packet()
- * @var array
*/
- private $window_size_client_to_server = [];
+ private array $window_size_client_to_server = [];
/**
* Server signature
@@ -675,9 +606,8 @@ class SSH2
* Verified against $this->session_id
*
* @see self::getServerPublicHostKey()
- * @var string
*/
- private $signature = '';
+ private string $signature = '';
/**
* Server signature format
@@ -685,17 +615,15 @@ class SSH2
* ssh-rsa or ssh-dss.
*
* @see self::getServerPublicHostKey()
- * @var string
*/
- private $signature_format = '';
+ private string $signature_format = '';
/**
* Interactive Buffer
*
* @see self::read()
- * @var string
*/
- private $interactiveBuffer = '';
+ private string $interactiveBuffer = '';
/**
* Current log size
@@ -704,32 +632,29 @@ class SSH2
*
* @see self::_send_binary_packet()
* @see self::_get_binary_packet()
- * @var int
*/
- private $log_size;
+ private int $log_size;
/**
* Timeout
*
* @see SSH2::setTimeout()
- * @var int
*/
- protected $timeout;
+ protected int|null $timeout = null;
/**
* Current Timeout
*
* @see SSH2::get_channel_packet()
- * @var int
*/
- protected $curTimeout;
+ protected int|float|null $curTimeout = null;
/**
* Keep Alive Interval
*
* @see self::setKeepAlive()
*/
- private $keepAlive;
+ private int|null $keepAlive = null;
/**
* Real-time log file pointer
@@ -743,91 +668,75 @@ class SSH2
* Real-time log file size
*
* @see self::_append_log()
- * @var int
*/
- private $realtime_log_size;
+ private int $realtime_log_size;
/**
* Has the signature been validated?
*
* @see self::getServerPublicHostKey()
- * @var bool
*/
- private $signature_validated = false;
+ private bool $signature_validated = false;
/**
* Real-time log file wrap boolean
*
* @see self::_append_log()
- * @var bool
*/
- private $realtime_log_wrap;
+ private bool $realtime_log_wrap;
/**
* Flag to suppress stderr from output
*
* @see self::enableQuietMode()
*/
- private $quiet_mode = false;
+ private bool $quiet_mode = false;
/**
* Time of first network activity
- *
- * @var float
*/
- private $last_packet;
+ private float $last_packet;
/**
* Exit status returned from ssh if any
- *
- * @var int
*/
- private $exit_status;
+ private int|null $exit_status = null;
/**
* Flag to request a PTY when using exec()
*
- * @var bool
* @see self::enablePTY()
*/
- private $request_pty = false;
+ private bool $request_pty = false;
/**
* Flag set while exec() is running when using enablePTY()
- *
- * @var bool
*/
- private $in_request_pty_exec = false;
+ private bool $in_request_pty_exec = false;
/**
* Flag set after startSubsystem() is called
- *
- * @var bool
*/
- private $in_subsystem;
+ private bool $in_subsystem = false;
/**
* Contents of stdError
- *
- * @var string
*/
- private $stdErrorLog;
+ private string $stdErrorLog;
/**
* The Last Interactive Response
*
* @see self::_keyboard_interactive_process()
- * @var string
*/
- private $last_interactive_response = '';
+ private string $last_interactive_response = '';
/**
* Keyboard Interactive Request / Responses
*
* @see self::_keyboard_interactive_process()
- * @var array
*/
- private $keyboard_requests_responses = [];
+ private array $keyboard_requests_responses = [];
/**
* Banner Message
@@ -837,59 +746,52 @@ class SSH2
*
* @see self::_filter()
* @see self::getBannerMessage()
- * @var string
*/
- private $banner_message = '';
+ private string $banner_message = '';
/**
* Did read() timeout or return normally?
*
* @see self::isTimeout()
- * @var bool
*/
- private $is_timeout = false;
+ private bool $is_timeout = false;
/**
* Log Boundary
*
* @see self::_format_log()
- * @var string
*/
- private $log_boundary = ':';
+ private string $log_boundary = ':';
/**
* Log Long Width
*
* @see self::_format_log()
- * @var int
*/
- private $log_long_width = 65;
+ private int $log_long_width = 65;
/**
* Log Short Width
*
* @see self::_format_log()
- * @var int
*/
- private $log_short_width = 16;
+ private int $log_short_width = 16;
/**
* Hostname
*
* @see self::__construct()
* @see self::_connect()
- * @var string
*/
- private $host;
+ private string $host;
/**
* Port Number
*
* @see self::__construct()
- * @see self::_connect()
- * @var int
+ * @see self::connect()
*/
- private $port;
+ private int $port;
/**
* Number of columns for terminal window size
@@ -897,9 +799,8 @@ class SSH2
* @see self::getWindowColumns()
* @see self::setWindowColumns()
* @see self::setWindowSize()
- * @var int
*/
- private $windowColumns = 80;
+ private int $windowColumns = 80;
/**
* Number of columns for terminal window size
@@ -907,111 +808,81 @@ class SSH2
* @see self::getWindowRows()
* @see self::setWindowRows()
* @see self::setWindowSize()
- * @var int
*/
- private $windowRows = 24;
+ private int $windowRows = 24;
/**
* Crypto Engine
*
* @see self::setCryptoEngine()
* @see self::_key_exchange()
- * @var int
*/
- private static $crypto_engine = false;
+ private static int|false $crypto_engine = false;
/**
* A System_SSH_Agent for use in the SSH2 Agent Forwarding scenario
- *
- * @var Agent
*/
- private $agent;
+ private Agent $agent;
/**
* Connection storage to replicates ssh2 extension functionality:
* {@link http://php.net/manual/en/wrappers.ssh2.php#refsect1-wrappers.ssh2-examples}
*
- * @var array>
+ * @var array>
*/
- private static $connections;
+ private static array $connections;
/**
* Send the identification string first?
- *
- * @var bool
*/
- private $send_id_string_first = true;
+ private bool $send_id_string_first = true;
/**
* Send the key exchange initiation packet first?
- *
- * @var bool
*/
- private $send_kex_first = true;
+ private bool $send_kex_first = true;
/**
* Some versions of OpenSSH incorrectly calculate the key size
- *
- * @var bool
*/
- private $bad_key_size_fix = false;
+ private bool $bad_key_size_fix = false;
/**
* Should we try to re-connect to re-establish keys?
- *
- * @var bool
*/
- private $retry_connect = false;
+ private bool $retry_connect = false;
/**
* Binary Packet Buffer
- *
- * @var string|false
*/
- private $binary_packet_buffer = false;
-
- /**
- * Preferred Signature Format
- *
- * @var string|false
- */
- protected $preferred_signature_format = false;
+ private string|false $binary_packet_buffer = false;
/**
* Authentication Credentials
- *
- * @var array
*/
- protected $auth = [];
+ protected array $auth = [];
/**
* Terminal
- *
- * @var string
*/
- private $term = 'vt100';
+ private string $term = 'vt100';
/**
* The authentication methods that may productively continue authentication.
*
* @see https://tools.ietf.org/html/rfc4252#section-5.1
- * @var array|null
*/
- private $auth_methods_to_continue = null;
+ private array|null $auth_methods_to_continue = null;
/**
* Compression method
- *
- * @var int
*/
- private $compress = self::NET_SSH2_COMPRESSION_NONE;
+ private int $compress = self::NET_SSH2_COMPRESSION_NONE;
/**
* Decompression method
- *
- * @var int
*/
- private $decompress = self::NET_SSH2_COMPRESSION_NONE;
+ private int $decompress = self::NET_SSH2_COMPRESSION_NONE;
/**
* Compression context
@@ -1029,24 +900,18 @@ class SSH2
/**
* Regenerate Compression Context
- *
- * @var bool
*/
- private $regenerate_compression_context = false;
+ private bool $regenerate_compression_context = false;
/**
* Regenerate Decompression Context
- *
- * @var bool
*/
- private $regenerate_decompression_context = false;
+ private bool $regenerate_decompression_context = false;
/**
* Smart multi-factor authentication flag
- *
- * @var bool
*/
- private $smartMFA = true;
+ private bool $smartMFA = true;
/**
* Default Constructor.
@@ -1057,13 +922,7 @@ class SSH2
*/
public function __construct($host, int $port = 22, int $timeout = 10)
{
- /**
- * Typehint is required due to a bug in Psalm: https://github.com/vimeo/psalm/issues/7508
- * @var \WeakReference|SSH2
- */
- self::$connections[$this->getResourceId()] = class_exists('WeakReference')
- ? \WeakReference::create($this)
- : $this;
+ self::$connections[$this->getResourceId()] = \WeakReference::create($this);
if (is_resource($host)) {
$this->fsock = $host;
@@ -4787,17 +4646,17 @@ class SSH2
return '{' . spl_object_hash($this) . '}';
}
- /**
- * Return existing connection
- *
- * @return bool|SSH2 will return false if no such connection
- */
- public static function getConnectionByResourceId(string $id)
+ public static function getConnectionByResourceId(string $id): SSH2|null
{
- if (isset(self::$connections[$id])) {
- return self::$connections[$id] instanceof \WeakReference ? self::$connections[$id]->get() : self::$connections[$id];
+ if (array_key_exists($id, self::$connections)) {
+ /**
+ * @psalm-ignore-var
+ * @var SSH2|null $ssh2
+ */
+ $ssh2 = self::$connections[$id]->get();
+ return $ssh2;
}
- return false;
+ return null;
}
/**