From b07738814e37ac039715f04577b55bf43bbefb88 Mon Sep 17 00:00:00 2001 From: danieljankowski Date: Tue, 4 May 2021 11:02:29 +0200 Subject: [PATCH 1/2] ASN1: fix timezone issue when non-utc time is given --- phpseclib/File/ASN1.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/phpseclib/File/ASN1.php b/phpseclib/File/ASN1.php index 1419c097..a9f20e05 100644 --- a/phpseclib/File/ASN1.php +++ b/phpseclib/File/ASN1.php @@ -1093,7 +1093,10 @@ class File_ASN1 if (!class_exists('DateTime')) { $value = @gmdate($format, strtotime($source)) . 'Z'; } else { + // if $source does _not_ include timezone information within it then assume that the timezone is GMT $date = new DateTime($source, new DateTimeZone('GMT')); + // if $source _does_ include timezone information within it then convert the time to GMT + $date->setTimezone(new DateTimeZone('GMT')); $value = $date->format($format) . 'Z'; } break; From 9c47b0a6964832860e5354603f61e239829d3929 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Tue, 11 May 2021 20:20:46 -0500 Subject: [PATCH 2/2] SFTP: reopen channel on channel closure --- phpseclib/Net/SFTP.php | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/phpseclib/Net/SFTP.php b/phpseclib/Net/SFTP.php index dbc14ede..f2d017d6 100644 --- a/phpseclib/Net/SFTP.php +++ b/phpseclib/Net/SFTP.php @@ -310,6 +310,16 @@ class Net_SFTP extends Net_SSH2 */ var $preserveTime = false; + /** + * Was the last packet due to the channels being closed or not? + * + * @see self::get() + * @see self::get_sftp_packet() + * @var bool + * @access private + */ + var $channel_close = false; + /** * Default Constructor. * @@ -484,6 +494,17 @@ class Net_SFTP extends Net_SSH2 return false; } + return $this->_init_sftp_connection(); + } + + /** + * (Re)initializes the SFTP channel + * + * @return bool + * @access private + */ + function _init_sftp_connection() + { $this->window_size_server_to_client[NET_SFTP_CHANNEL] = $this->window_size; $packet = pack( @@ -2354,7 +2375,13 @@ class Net_SFTP extends Net_SSH2 if ($fclose_check) { fclose($fp); } - user_error('Expected SSH_FX_DATA or SSH_FXP_STATUS'); + // maybe the file was successfully transferred, maybe it wasn't + if ($this->channel_close) { + $this->_init_sftp_connection(); + return false; + } else { + user_error('Expected SSH_FX_DATA or SSH_FXP_STATUS'); + } } $response = null; } @@ -3116,6 +3143,8 @@ class Net_SFTP extends Net_SSH2 */ function _get_sftp_packet($request_id = null) { + $this->channel_close = false; + if (isset($request_id) && isset($this->requestBuffer[$request_id])) { $this->packet_type = $this->requestBuffer[$request_id]['packet_type']; $temp = $this->requestBuffer[$request_id]['packet']; @@ -3132,7 +3161,10 @@ class Net_SFTP extends Net_SSH2 // SFTP packet length while (strlen($this->packet_buffer) < 4) { $temp = $this->_get_channel_packet(NET_SFTP_CHANNEL, true); - if (is_bool($temp)) { + if ($temp === true) { + if ($this->channel_status[NET_SFTP_CHANNEL] === NET_SSH2_MSG_CHANNEL_CLOSE) { + $this->channel_close = true; + } $this->packet_type = false; $this->packet_buffer = ''; return false;