diff --git a/CHANGELOG.md b/CHANGELOG.md index c45b93bc9..95e419b34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -127,6 +127,13 @@ * FilesystemAdapter::directoryExists to check for directory existence * FilesystemAdapter::fileExists to check for file existence +## 2.4.4 - 2022-04-14 + +### Fixed + +- [SFTP v2] Avoid type errors when public key is not retrieved (#1446) +- [SFTP v3] Avoid type errors when public key is not retrieved (#1446) + ## 2.4.3 - 2022-02-16 ### Fixed diff --git a/src/PhpseclibV2/SftpConnectionProvider.php b/src/PhpseclibV2/SftpConnectionProvider.php index efd8ab5d1..c04a12ede 100644 --- a/src/PhpseclibV2/SftpConnectionProvider.php +++ b/src/PhpseclibV2/SftpConnectionProvider.php @@ -143,7 +143,12 @@ private function checkFingerprint(SFTP $connection): void return; } - $publicKey = $connection->getServerPublicHostKey() ?: 'no-public-key'; + $publicKey = $connection->getServerPublicHostKey(); + + if ($publicKey === false) { + throw UnableToEstablishAuthenticityOfHost::becauseTheAuthenticityCantBeEstablished($this->host); + } + $fingerprint = $this->getFingerprintFromPublicKey($publicKey); if (0 !== strcasecmp($this->hostFingerprint, $fingerprint)) { diff --git a/src/PhpseclibV3/SftpConnectionProvider.php b/src/PhpseclibV3/SftpConnectionProvider.php index 095085d21..ee843ba85 100644 --- a/src/PhpseclibV3/SftpConnectionProvider.php +++ b/src/PhpseclibV3/SftpConnectionProvider.php @@ -158,7 +158,12 @@ private function checkFingerprint(SFTP $connection): void return; } - $publicKey = $connection->getServerPublicHostKey() ?: 'no-public-key'; + $publicKey = $connection->getServerPublicHostKey(); + + if ($publicKey === false) { + throw UnableToEstablishAuthenticityOfHost::becauseTheAuthenticityCantBeEstablished($this->host); + } + $fingerprint = $this->getFingerprintFromPublicKey($publicKey); if (0 !== strcasecmp($this->hostFingerprint, $fingerprint)) {