Skip to content

Commit

Permalink
Merge pull request thephpleague#1446 from lcobucci/prevent-type-errors
Browse files Browse the repository at this point in the history
Avoid type errors when public key is not retrieved
  • Loading branch information
frankdejonge authored Apr 14, 2022
2 parents 24d5142 + ec4d8a8 commit f50ef28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/PhpseclibV2/SftpConnectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 6 additions & 1 deletion src/PhpseclibV3/SftpConnectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,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)) {
Expand Down

0 comments on commit f50ef28

Please sign in to comment.