diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 49382177..a0312416 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -3625,6 +3625,13 @@ class Net_SSH2 */ function getServerPublicHostKey() { + if (!($this->bitmap & NET_SSH2_MASK_CONSTRUCTOR)) { + $this->bitmap |= NET_SSH2_MASK_CONSTRUCTOR; + if (!$this->_connect()) { + return false; + } + } + $signature = $this->signature; $server_public_host_key = $this->server_public_host_key; diff --git a/tests/Functional/Net/SSH2Test.php b/tests/Functional/Net/SSH2Test.php index 0f92ca20..22d97703 100644 --- a/tests/Functional/Net/SSH2Test.php +++ b/tests/Functional/Net/SSH2Test.php @@ -58,4 +58,11 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase ->will($this->returnValue(true)); $ssh->exec('pwd', array($callbackObject, 'callbackMethod')); } + + public function testGetServerPublicHostKey() + { + $ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME')); + + $this->assertInternalType('string', $ssh->getServerPublicHostKey()); + } }