From 5f5678126146b151f2e37b2dd459514c3472606c Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 16 Jun 2014 10:19:34 -0500 Subject: [PATCH 1/3] SSH2: make it so you can verify server public host key without logging on --- phpseclib/Net/SSH2.php | 7 +++++++ 1 file changed, 7 insertions(+) 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; From bbce7c4762162e1fc4cb746394ed7bfce637b0c4 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 16 Jun 2014 18:54:26 -0500 Subject: [PATCH 2/3] SSH2: add unit test for getServerPublicHostKey --- tests/Functional/Net/SSH2Test.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/Functional/Net/SSH2Test.php b/tests/Functional/Net/SSH2Test.php index 0f92ca20..2768e500 100644 --- a/tests/Functional/Net/SSH2Test.php +++ b/tests/Functional/Net/SSH2Test.php @@ -58,4 +58,16 @@ 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->assertTrue( + is_object($ssh), + 'Could not construct NET_SSH2 object.' + ); + + $this->assertInternalType('string', $ssh->getServerPublicHostKey()); + } } From 2e06a14a8a5f3c4be1aee193975cbc9e1ff35aae Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 16 Jun 2014 23:58:00 -0500 Subject: [PATCH 3/3] SSH2: rm redundant part of SSH2 unit test --- tests/Functional/Net/SSH2Test.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/Functional/Net/SSH2Test.php b/tests/Functional/Net/SSH2Test.php index 2768e500..22d97703 100644 --- a/tests/Functional/Net/SSH2Test.php +++ b/tests/Functional/Net/SSH2Test.php @@ -63,11 +63,6 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase { $ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME')); - $this->assertTrue( - is_object($ssh), - 'Could not construct NET_SSH2 object.' - ); - $this->assertInternalType('string', $ssh->getServerPublicHostKey()); } }