From 9f0f8fd7e5721edc7737ded3f1faf290e25dd8ee Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Sun, 29 Nov 2015 18:44:21 +0100 Subject: [PATCH 01/13] Correct indentation on pvno array definition. --- tests/Unit/File/ASN1Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/File/ASN1Test.php b/tests/Unit/File/ASN1Test.php index 2a6c4d63..fe0e01b4 100644 --- a/tests/Unit/File/ASN1Test.php +++ b/tests/Unit/File/ASN1Test.php @@ -18,7 +18,7 @@ class Unit_File_ASN1Test extends PhpseclibTestCase $KDC_REP = array( 'type' => FILE_ASN1_TYPE_SEQUENCE, 'children' => array( - 'pvno' => array( + 'pvno' => array( 'constant' => 0, 'optional' => true, 'explicit' => true, From ee0f45fea6e979cd1e873c3cba5a6a21fb2f7bef Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 5 Dec 2015 10:27:51 -0600 Subject: [PATCH 02/13] 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 c0632bb8af58f780505b6031ed0de8340aceb4c5 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 6 Dec 2015 23:30:37 -0600 Subject: [PATCH 03/13] Travis: compile GNU Parallel --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9a402e4a..d1fa0e07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,13 @@ env: before_install: true install: - - sudo apt-get install parallel + - wget http://ftp.gnu.org/gnu/parallel/parallel-20120522.tar.bz2 + - tar -xvjf parallel* + - cd parallel* + - ./configure + - make + - sudo make install + - cd .. - eval `ssh-agent -s` - travis/setup-secure-shell.sh - sh -c "if [ '$TRAVIS_PHP_VERSION' != 'hhvm' ]; then travis/install-php-extensions.sh; fi" From fe6e60c5bd6f2563ccf075503808fca59c962ec9 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 7 Dec 2015 15:00:17 -0600 Subject: [PATCH 04/13] Travis: rm hhvm --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index d1fa0e07..125406fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ php: - 5.5.9 - 5.5 - 5.6 - - hhvm env: global: From c655b16f7529a9d3ceee5224cdaaed72443f7996 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Tue, 1 Dec 2015 19:30:49 -0600 Subject: [PATCH 05/13] BigInteger: add engine to __debugInfo output and add unit test --- phpseclib/Math/BigInteger.php | 23 ++++++++++++++++++++++- tests/Unit/Math/BigInteger/TestCase.php | 11 +++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 4ba64240..98ec4a93 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -820,7 +820,28 @@ class Math_BigInteger */ function __debugInfo() { - return array('value' => '0x' . $this->toHex(true)); + $opts = array(); + switch (MATH_BIGINTEGER_MODE) { + case MATH_BIGINTEGER_MODE_GMP: + $engine = 'gmp'; + break; + case MATH_BIGINTEGER_MODE_BCMATH: + $engine = 'bcmath'; + break; + case MATH_BIGINTEGER_MODE_INTERNAL: + $engine = 'internal'; + $opts[] = PHP_INT_SIZE == 8 ? '64-bit' : '32-bit'; + } + if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_GMP && defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) { + $opts[] = 'OpenSSL'; + } + if (!empty($opts)) { + $engine.= ' (' . implode($opts, ', ') . ')'; + } + return array( + 'value' => '0x' . $this->toHex(true), + 'engine' => $engine + ); } /** diff --git a/tests/Unit/Math/BigInteger/TestCase.php b/tests/Unit/Math/BigInteger/TestCase.php index 10eacc66..827b2b90 100644 --- a/tests/Unit/Math/BigInteger/TestCase.php +++ b/tests/Unit/Math/BigInteger/TestCase.php @@ -358,4 +358,15 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase 'Failed asserting that Alice and Bob share the same BigInteger.' ); } + + /** + * @requires PHP 5.6 + */ + public function testDebugInfo() + { + $num = new Math_BigInteger(50); + $str = print_r($num, true); + $this->assertContains('[value] => 0x32', $str); + return $str; + } } From d8b74a7ee0575caeffdbffd2d5ccaf08a8ec91ed Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 7 Dec 2015 22:02:02 -0600 Subject: [PATCH 06/13] SSH2: update unit test --- tests/Unit/Net/SSH2Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Net/SSH2Test.php b/tests/Unit/Net/SSH2Test.php index 95361625..e13b54a3 100644 --- a/tests/Unit/Net/SSH2Test.php +++ b/tests/Unit/Net/SSH2Test.php @@ -39,7 +39,7 @@ class Unit_Net_SSH2Test extends PhpseclibTestCase public function testGenerateIdentifier() { $identifier = $this->createSSHMock()->_generate_identifier(); - $this->assertStringStartsWith('SSH-2.0-phpseclib_0.3', $identifier); + $this->assertStringStartsWith('SSH-2.0-phpseclib_1.0', $identifier); if (extension_loaded('openssl')) { $this->assertContains('openssl', $identifier); From 1c9ee4ef281dbcc90bf83ec59a7dadd3232becbb Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 7 Dec 2015 23:53:09 -0600 Subject: [PATCH 07/13] RSA: fix PKCS8 key handling (again) --- phpseclib/Crypt/RSA.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Crypt/RSA.php b/phpseclib/Crypt/RSA.php index 5e55917f..ba2a8d83 100644 --- a/phpseclib/Crypt/RSA.php +++ b/phpseclib/Crypt/RSA.php @@ -188,7 +188,7 @@ class RSA /** * PKCS#8 formatted private key */ - const PRIVATE_FORMAT_PKCS8 = 3; + const PRIVATE_FORMAT_PKCS8 = 8; /**#@-*/ /**#@+ From b9ce54aae9d7b4cefd03464a46071303f53ce66d Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 13 Dec 2015 16:02:17 -0600 Subject: [PATCH 08/13] Travis: re-add hhvm and use zenovich github repo only --- .travis.yml | 1 + travis/install-php-extensions.sh | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 125406fb..d1fa0e07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ php: - 5.5.9 - 5.5 - 5.6 + - hhvm env: global: diff --git a/travis/install-php-extensions.sh b/travis/install-php-extensions.sh index 2acfdfd7..5244261c 100755 --- a/travis/install-php-extensions.sh +++ b/travis/install-php-extensions.sh @@ -21,10 +21,5 @@ function install_php_extension } # runkit -if [ "$TRAVIS_PHP_VERSION" == "5.6" ] -then - git clone https://github.com/adrianguenter/runkit.git -else - git clone https://github.com/zenovich/runkit.git -fi +git clone https://github.com/zenovich/runkit.git install_php_extension 'runkit' From 2d2f359300743768d136109045d1063114f1ab12 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 14 Dec 2015 13:03:07 -0600 Subject: [PATCH 09/13] Tests/BigInteger: fix for 2.0 branch --- tests/Unit/Math/BigInteger/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Math/BigInteger/TestCase.php b/tests/Unit/Math/BigInteger/TestCase.php index 1992fb8d..eb2ec2d4 100644 --- a/tests/Unit/Math/BigInteger/TestCase.php +++ b/tests/Unit/Math/BigInteger/TestCase.php @@ -361,7 +361,7 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase */ public function testDebugInfo() { - $num = new Math_BigInteger(50); + $num = new BigInteger(50); $str = print_r($num, true); $this->assertContains('[value] => 0x32', $str); return $str; From cae579a19bec98216a4b7af207ab313eae8fc7a5 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 14 Dec 2015 13:26:56 -0600 Subject: [PATCH 10/13] Tests/BigInteger: update testDebugInfo test --- tests/Unit/Math/BigInteger/TestCase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/Math/BigInteger/TestCase.php b/tests/Unit/Math/BigInteger/TestCase.php index 827b2b90..7f7473b9 100644 --- a/tests/Unit/Math/BigInteger/TestCase.php +++ b/tests/Unit/Math/BigInteger/TestCase.php @@ -364,7 +364,7 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase */ public function testDebugInfo() { - $num = new Math_BigInteger(50); + $num = $this->getInstance(50); $str = print_r($num, true); $this->assertContains('[value] => 0x32', $str); return $str; From eac8613c75491fda9c1017126f8f9e7b5efe276a Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 14 Dec 2015 13:56:07 -0600 Subject: [PATCH 11/13] BigInteger: 2.0 specific updates for __debuginfo --- phpseclib/Math/BigInteger.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 9744275d..6befb591 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -814,17 +814,17 @@ class BigInteger { $opts = array(); switch (MATH_BIGINTEGER_MODE) { - case MATH_BIGINTEGER_MODE_GMP: + case self::MODE_GMP: $engine = 'gmp'; break; - case MATH_BIGINTEGER_MODE_BCMATH: + case self::MODE_BCMATH: $engine = 'bcmath'; break; - case MATH_BIGINTEGER_MODE_INTERNAL: + case self::MODE_INTERNAL: $engine = 'internal'; $opts[] = PHP_INT_SIZE == 8 ? '64-bit' : '32-bit'; } - if (MATH_BIGINTEGER_MODE != MATH_BIGINTEGER_MODE_GMP && defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) { + if (MATH_BIGINTEGER_MODE != self::MODE_GMP && defined('MATH_BIGINTEGER_OPENSSL_ENABLED')) { $opts[] = 'OpenSSL'; } if (!empty($opts)) { From 57063f36046fd24e80dc334f35f70a1c8cf3538b Mon Sep 17 00:00:00 2001 From: terrafrost Date: Tue, 15 Dec 2015 19:08:17 -0600 Subject: [PATCH 12/13] 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 13/13] 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); } /**