From fe404065f17c231744db3c6bcc88a138abf093a0 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 5 Dec 2015 10:27:51 -0600 Subject: [PATCH 1/4] update identifier to current version --- phpseclib/Net/SSH2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 7cde0875..b393eb72 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -1134,7 +1134,7 @@ class Net_SSH2 */ function _generate_identifier() { - $identifier = 'SSH-2.0-phpseclib_0.3'; + $identifier = 'SSH-2.0-phpseclib_1.0'; $ext = array(); if (extension_loaded('openssl')) { From 57063f36046fd24e80dc334f35f70a1c8cf3538b Mon Sep 17 00:00:00 2001 From: terrafrost Date: Tue, 15 Dec 2015 19:08:17 -0600 Subject: [PATCH 2/4] SSH2: add isAuthenticated() method --- phpseclib/Net/SSH2.php | 11 ++++++++++ tests/Functional/Net/SSH2Test.php | 35 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index b393eb72..d3d340ce 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2964,6 +2964,17 @@ class Net_SSH2 return (bool) ($this->bitmap & NET_SSH2_MASK_CONNECTED); } + /** + * Have you successfully been logged in? + * + * @return bool + * @access public + */ + function isAuthenticated() + { + return (bool) ($this->bitmap & NET_SSH2_MASK_LOGIN); + } + /** * Gets Binary Packets * diff --git a/tests/Functional/Net/SSH2Test.php b/tests/Functional/Net/SSH2Test.php index c8917de5..968df276 100644 --- a/tests/Functional/Net/SSH2Test.php +++ b/tests/Functional/Net/SSH2Test.php @@ -32,6 +32,11 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase 'Failed asserting that SSH2 is not connected after construction.' ); + $this->assertFalse( + $ssh->isAuthenticated(), + 'Failed asserting that SSH2 is not authenticated after construction.' + ); + $this->assertNotEmpty( $ssh->getServerPublicHostKey(), 'Failed asserting that a non-empty public host key was fetched.' @@ -53,6 +58,31 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase /** * @depends testPreLogin */ + public function testBadPassword($ssh) + { + $username = $this->getEnv('SSH_USERNAME'); + $password = $this->getEnv('SSH_PASSWORD'); + $this->assertFalse( + $ssh->login($username, 'zzz' . $password), + 'SSH2 login using password succeeded.' + ); + + $this->assertTrue( + $ssh->isConnected(), + 'Failed asserting that SSH2 is connected after bad login attempt.' + ); + + $this->assertFalse( + $ssh->isAuthenticated(), + 'Failed asserting that SSH2 is not authenticated after bad login attempt.' + ); + + return $ssh; + } + + /** + * @depends testBadPassword + */ public function testPasswordLogin($ssh) { $username = $this->getEnv('SSH_USERNAME'); @@ -62,6 +92,11 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase 'SSH2 login using password failed.' ); + $this->assertTrue( + $ssh->isAuthenticated(), + 'Failed asserting that SSH2 is authenticated after good login attempt.' + ); + return $ssh; } From 600f9c4e4b53fcded16d92d5f04e43805bd25c52 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 16 Dec 2015 09:21:37 -0600 Subject: [PATCH 3/4] SSH2: update isAuthenticated to work with 2.0 / master branches --- phpseclib/Net/SSH2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Net/SSH2.php b/phpseclib/Net/SSH2.php index 914ca436..0f7c8318 100644 --- a/phpseclib/Net/SSH2.php +++ b/phpseclib/Net/SSH2.php @@ -2870,7 +2870,7 @@ class SSH2 */ function isAuthenticated() { - return (bool) ($this->bitmap & NET_SSH2_MASK_LOGIN); + return (bool) ($this->bitmap & self::MASK_LOGIN); } /** From 1be0ac9f7fe7e6c0543848283f3eb76ed79a4c06 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Wed, 23 Dec 2015 07:41:30 -0600 Subject: [PATCH 4/4] SFTP/Stream: fix issue with filenames with hash in them --- phpseclib/Net/SFTP/Stream.php | 11 +++++++++++ tests/Functional/Net/SFTPStreamTest.php | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/phpseclib/Net/SFTP/Stream.php b/phpseclib/Net/SFTP/Stream.php index 250c44e4..e374b9b9 100644 --- a/phpseclib/Net/SFTP/Stream.php +++ b/phpseclib/Net/SFTP/Stream.php @@ -171,7 +171,18 @@ class Net_SFTP_Stream */ function _parse_path($path) { + $orig = $path; extract(parse_url($path) + array('port' => 22)); + if (isset($query)) { + $path.= '?' . $query; + } elseif (preg_match('/(\?|\?#)$/', $orig)) { + $path.= '?'; + } + if (isset($fragment)) { + $path.= '#' . $fragment; + } elseif ($orig[strlen($orig) - 1] == '#') { + $path.= '#'; + } if (!isset($host)) { return false; diff --git a/tests/Functional/Net/SFTPStreamTest.php b/tests/Functional/Net/SFTPStreamTest.php index 6d731449..55115603 100644 --- a/tests/Functional/Net/SFTPStreamTest.php +++ b/tests/Functional/Net/SFTPStreamTest.php @@ -22,6 +22,21 @@ class Functional_Net_SFTPStreamTest extends Functional_Net_SFTPTestCase $this->assertSame(0, $this->sftp->size('fooo.txt')); } + /** + * @group github778 + */ + public function testFilenameWithHash() + { + $context = stream_context_create(array( + 'sftp' => array('session' => $this->sftp), + )); + $fp = fopen($this->buildUrl('te#st.txt'), 'wb', false, $context); + fputs($fp, 'zzzz'); + fclose($fp); + + $this->assertTrue(in_array('te#st.txt', $this->sftp->nlist())); + } + protected function buildUrl($suffix) { return sprintf(