Merge branch '3.0'

This commit is contained in:
terrafrost 2020-12-13 02:24:20 -06:00
commit 727d337c1d
28 changed files with 298 additions and 200 deletions

View File

@ -9,6 +9,7 @@ php:
- 7.2 - 7.2
- 7.3 - 7.3
- 7.4 - 7.4
- 8.0
- nightly - nightly
before_install: true before_install: true
@ -20,7 +21,7 @@ matrix:
install: install:
- wget http://ftp.gnu.org/gnu/parallel/parallel-20170822.tar.bz2 - wget http://ftp.gnu.org/gnu/parallel/parallel-20170822.tar.bz2
- tar -xvjf parallel* - tar -xvjf parallel*
- cd parallel* - cd parallel-20170822
- ./configure - ./configure
- make - make
- sudo make install - sudo make install

View File

@ -11,6 +11,7 @@
using underscore. --> using underscore. -->
<exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" /> <exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" /> <exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
</rule> </rule>
</ruleset> </ruleset>

View File

@ -51,13 +51,13 @@
} }
], ],
"require": { "require": {
"paragonie/constant_time_encoding": "^1", "paragonie/constant_time_encoding": "^1|^2",
"paragonie/random_compat": "^1.4|^2.0", "paragonie/random_compat": "^1.4|^2.0",
"php": ">=5.6.1" "php": ">=5.6.1"
}, },
"require-dev": { "require-dev": {
"phing/phing": "~2.7", "phing/phing": "~2.7",
"phpunit/phpunit": "^4.8.35|^5.7|^6.0", "phpunit/phpunit": "^4.8.35|^5.7|^6.0|^9.4",
"squizlabs/php_codesniffer": "~2.0" "squizlabs/php_codesniffer": "~2.0"
}, },
"suggest": { "suggest": {

View File

@ -315,19 +315,20 @@ class ANSI
$mods = explode(';', $match[1]); $mods = explode(';', $match[1]);
foreach ($mods as $mod) { foreach ($mods as $mod) {
switch ($mod) { switch ($mod) {
case 0: // Turn off character attributes case '':
case '0': // Turn off character attributes
$attr_cell = clone $this->base_attr_cell; $attr_cell = clone $this->base_attr_cell;
break; break;
case 1: // Turn bold mode on case '1': // Turn bold mode on
$attr_cell->bold = true; $attr_cell->bold = true;
break; break;
case 4: // Turn underline mode on case '4': // Turn underline mode on
$attr_cell->underline = true; $attr_cell->underline = true;
break; break;
case 5: // Turn blinking mode on case '5': // Turn blinking mode on
$attr_cell->blink = true; $attr_cell->blink = true;
break; break;
case 7: // Turn reverse video on case '7': // Turn reverse video on
$attr_cell->reverse = !$attr_cell->reverse; $attr_cell->reverse = !$attr_cell->reverse;
$temp = $attr_cell->background; $temp = $attr_cell->background;
$attr_cell->background = $attr_cell->foreground; $attr_cell->background = $attr_cell->foreground;
@ -340,23 +341,23 @@ class ANSI
$back = &$attr_cell->{ $attr_cell->reverse ? 'foreground' : 'background' }; $back = &$attr_cell->{ $attr_cell->reverse ? 'foreground' : 'background' };
switch ($mod) { switch ($mod) {
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
case 30: $front = 'black'; break; case '30': $front = 'black'; break;
case 31: $front = 'red'; break; case '31': $front = 'red'; break;
case 32: $front = 'green'; break; case '32': $front = 'green'; break;
case 33: $front = 'yellow'; break; case '33': $front = 'yellow'; break;
case 34: $front = 'blue'; break; case '34': $front = 'blue'; break;
case 35: $front = 'magenta'; break; case '35': $front = 'magenta'; break;
case 36: $front = 'cyan'; break; case '36': $front = 'cyan'; break;
case 37: $front = 'white'; break; case '37': $front = 'white'; break;
case 40: $back = 'black'; break; case '40': $back = 'black'; break;
case 41: $back = 'red'; break; case '41': $back = 'red'; break;
case 42: $back = 'green'; break; case '42': $back = 'green'; break;
case 43: $back = 'yellow'; break; case '43': $back = 'yellow'; break;
case 44: $back = 'blue'; break; case '44': $back = 'blue'; break;
case 45: $back = 'magenta'; break; case '45': $back = 'magenta'; break;
case 46: $back = 'cyan'; break; case '46': $back = 'cyan'; break;
case 47: $back = 'white'; break; case '47': $back = 'white'; break;
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
default: default:

View File

@ -16,6 +16,7 @@ class Functional_Net_SFTPLargeFileTest extends Functional_Net_SFTPTestCase
if (!extension_loaded('mcrypt') && !extension_loaded('openssl')) { if (!extension_loaded('mcrypt') && !extension_loaded('openssl')) {
self::markTestSkipped('This test depends on mcrypt or openssl for performance.'); self::markTestSkipped('This test depends on mcrypt or openssl for performance.');
} }
self::ensureConstant('CRYPT_HASH_MODE', 3);
parent::setUpBeforeClass(); parent::setUpBeforeClass();
} }

View File

@ -22,7 +22,7 @@ class Functional_Net_SFTPStreamTest extends Functional_Net_SFTPTestCase
'sftp' => ['session' => $this->sftp], 'sftp' => ['session' => $this->sftp],
]); ]);
$fp = fopen($this->buildUrl('fooo.txt'), 'wb', false, $context); $fp = fopen($this->buildUrl('fooo.txt'), 'wb', false, $context);
$this->assertInternalType('resource', $fp); $this->assertIsResource($fp);
fclose($fp); fclose($fp);
$this->assertSame(0, $this->sftp->filesize('fooo.txt')); $this->assertSame(0, $this->sftp->filesize('fooo.txt'));
} }

View File

@ -29,8 +29,7 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
{ {
$sftp = new SFTP($this->getEnv('SSH_HOSTNAME')); $sftp = new SFTP($this->getEnv('SSH_HOSTNAME'));
$this->assertInternalType( $this->assertIsObject(
'object',
$sftp, $sftp,
'Could not construct NET_SFTP object.' 'Could not construct NET_SFTP object.'
); );
@ -136,6 +135,16 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
return $sftp; return $sftp;
} }
static function demoCallback($length)
{
$r = substr(self::$buffer, 0, $length);
self::$buffer = substr(self::$buffer, $length);
if (strlen($r)) {
return $r;
}
return null;
}
/** /**
* @depends testStatOnDir * @depends testStatOnDir
*/ */
@ -161,16 +170,6 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
return $sftp; return $sftp;
} }
static function callback($length)
{
$r = substr(self::$buffer, 0, $length);
self::$buffer = substr(self::$buffer, $length);
if (strlen($r)) {
return $r;
}
return null;
}
/** /**
* @depends testStatOnDir * @depends testStatOnDir
*/ */
@ -178,7 +177,7 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
{ {
self::$buffer = self::$exampleData; self::$buffer = self::$exampleData;
$this->assertTrue( $this->assertTrue(
$sftp->put('file1.txt', [__CLASS__, 'callback'], $sftp::SOURCE_CALLBACK), $sftp->put('file1.txt', [__CLASS__, 'demoCallback'], $sftp::SOURCE_CALLBACK),
'Failed asserting that example data could be successfully put().' 'Failed asserting that example data could be successfully put().'
); );
@ -440,8 +439,7 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
*/ */
public function testReadlink($sftp) public function testReadlink($sftp)
{ {
$this->assertInternalType( $this->assertIsString(
'string',
$sftp->readlink('symlink'), $sftp->readlink('symlink'),
'Failed asserting that a symlink\'s target could be read' 'Failed asserting that a symlink\'s target could be read'
); );
@ -456,14 +454,12 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
public function testStatOnCWD($sftp) public function testStatOnCWD($sftp)
{ {
$stat = $sftp->stat('.'); $stat = $sftp->stat('.');
$this->assertInternalType( $this->assertIsArray(
'array',
$stat, $stat,
'Failed asserting that stat on . returns an array' 'Failed asserting that stat on . returns an array'
); );
$lstat = $sftp->lstat('.'); $lstat = $sftp->lstat('.');
$this->assertInternalType( $this->assertIsArray(
'array',
$lstat, $lstat,
'Failed asserting that lstat on . returns an array' 'Failed asserting that lstat on . returns an array'
); );
@ -605,8 +601,7 @@ class Functional_Net_SFTPUserStoryTest extends PhpseclibFunctionalTestCase
'Failed asserting that scratch directory could ' . 'Failed asserting that scratch directory could ' .
'be created.' 'be created.'
); );
$this->assertInternalType( $this->assertIsArray(
'array',
$sftp->stat(self::$scratchDir), $sftp->stat(self::$scratchDir),
'Failed asserting that stat on an existent empty directory returns an array' 'Failed asserting that stat on an existent empty directory returns an array'
); );

View File

@ -14,8 +14,7 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase
{ {
$ssh = new SSH2($this->getEnv('SSH_HOSTNAME')); $ssh = new SSH2($this->getEnv('SSH_HOSTNAME'));
$this->assertInternalType( $this->assertIsObject(
'object',
$ssh, $ssh,
'Could not construct NET_SSH2 object.' 'Could not construct NET_SSH2 object.'
); );
@ -125,7 +124,7 @@ class Functional_Net_SSH2Test extends PhpseclibFunctionalTestCase
{ {
$ssh = new SSH2($this->getEnv('SSH_HOSTNAME')); $ssh = new SSH2($this->getEnv('SSH_HOSTNAME'));
$this->assertInternalType('string', $ssh->getServerPublicHostKey()); $this->assertIsString($ssh->getServerPublicHostKey());
} }
public function testOpenSocketConnect() public function testOpenSocketConnect()

View File

@ -117,4 +117,70 @@ abstract class PhpseclibTestCase extends PHPUnit\Framework\TestCase
$method->setAccessible(true); $method->setAccessible(true);
return $method->invokeArgs($obj, $params); return $method->invokeArgs($obj, $params);
} }
// assertIsArray was not introduced until PHPUnit 8
public static function assertIsArray($actual, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertIsArray')) {
parent::assertIsArray($actual, $message);
return;
}
parent::assertInternalType('array', $actual, $message);
}
// assertIsString was not introduced until PHPUnit 8
public static function assertIsString($actual, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertIsString')) {
parent::assertIsString($actual, $message);
return;
}
parent::assertInternalType('string', $actual, $message);
}
// assertIsResource was not introduced until PHPUnit 8
public static function assertIsResource($actual, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertIsResource')) {
parent::assertIsResource($actual, $message);
return;
}
parent::assertInternalType('resource', $actual, $message);
}
// assertIsObject was not introduced until PHPUnit 8
public static function assertIsObject($actual, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertIsObject')) {
parent::assertIsObject($actual, $message);
return;
}
parent::assertInternalType('object', $actual, $message);
}
// assertContains is deprecated for strings in PHPUnit 8
public static function assertStringContainsString($needle, $haystack, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertStringContainsString')) {
parent::assertStringContainsString($needle, $haystack, $message);
return;
}
parent::assertContains($needle, $haystack, $message);
}
// assertNotContains is deprecated for strings in PHPUnit 8
public static function assertStringNotContainsString($needle, $haystack, $message = '')
{
if (method_exists('\PHPUnit\Framework\TestCase', 'assertStringContainsString')) {
parent::assertStringNotContainsString($needle, $haystack, $message);
return;
}
parent::assertNotContains($needle, $haystack, $message);
}
} }

View File

@ -7,7 +7,7 @@
use phpseclib3\Crypt\Common\BlockCipher; use phpseclib3\Crypt\Common\BlockCipher;
class Unit_Crypt_AES_InternalTest extends Unit_Crypt_AES_TestCase class Unit_Crypt_AES_PurePHPTest extends Unit_Crypt_AES_TestCase
{ {
protected function setUp() protected function setUp()
{ {

View File

@ -8,6 +8,8 @@
use phpseclib3\Crypt\AES; use phpseclib3\Crypt\AES;
use phpseclib3\Crypt\Common\BlockCipher; use phpseclib3\Crypt\Common\BlockCipher;
use phpseclib3\Crypt\Rijndael; use phpseclib3\Crypt\Rijndael;
use phpseclib3\Exception\InconsistentSetupException;
use phpseclib3\Exception\InsufficientSetupException;
abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
{ {
@ -105,10 +107,11 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
/** /**
* @group github451 * @group github451
* @expectedException \LengthException
*/ */
public function testKeyPaddingAES() public function testKeyPaddingAES()
{ {
$this->expectException('LengthException');
// same as the above - just with a different ciphertext // same as the above - just with a different ciphertext
$aes = new AES('cbc'); $aes = new AES('cbc');
@ -347,11 +350,10 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
$this->assertSame($aes->getKeyLength(), 192); $this->assertSame($aes->getKeyLength(), 192);
} }
/**
* @expectedException \phpseclib3\Exception\InconsistentSetupException
*/
public function testSetKeyLengthWithLargerKey() public function testSetKeyLengthWithLargerKey()
{ {
$this->expectException(InconsistentSetupException::class);
$aes = new AES('cbc'); $aes = new AES('cbc');
$aes->setKeyLength(128); $aes->setKeyLength(128);
$aes->setKey(str_repeat('a', 24)); $aes->setKey(str_repeat('a', 24));
@ -362,11 +364,10 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
$this->assertSame($aes->getKeyLength(), 128); $this->assertSame($aes->getKeyLength(), 128);
} }
/**
* @expectedException \phpseclib3\Exception\InconsistentSetupException
*/
public function testSetKeyLengthWithSmallerKey() public function testSetKeyLengthWithSmallerKey()
{ {
$this->expectException(InconsistentSetupException::class);
$aes = new AES('cbc'); $aes = new AES('cbc');
$aes->setKeyLength(256); $aes->setKeyLength(256);
$aes->setKey(str_repeat('a', 16)); $aes->setKey(str_repeat('a', 16));
@ -408,11 +409,10 @@ abstract class Unit_Crypt_AES_TestCase extends PhpseclibTestCase
$this->assertEquals($plaintext, $actual); $this->assertEquals($plaintext, $actual);
} }
/**
* @expectedException \phpseclib3\Exception\InsufficientSetupException
*/
public function testNoKey() public function testNoKey()
{ {
$this->expectException(InsufficientSetupException::class);
$aes = new AES('cbc'); $aes = new AES('cbc');
$aes->setPreferredEngine($this->engine); $aes->setPreferredEngine($this->engine);
$aes->setIV(str_repeat('x', 16)); $aes->setIV(str_repeat('x', 16));

View File

@ -30,7 +30,7 @@ Sgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVtbVHCReSFtXZiXn7G9ExC6aY37WsL
public function testParametersWithInteger() public function testParametersWithInteger()
{ {
$a = DH::createParameters(512); $a = DH::createParameters(512);
$this->assertInternalType('string', "$a"); $this->assertIsString("$a");
} }
public function testParametersWithBigIntegers() public function testParametersWithBigIntegers()
@ -55,8 +55,8 @@ Sgh5jjQE3e+VGbPNOkMbMCsKbfJfFDdP4TVtbVHCReSFtXZiXn7G9ExC6aY37WsL
{ {
$param = DH::createParameters('diffie-hellman-group1-sha1'); $param = DH::createParameters('diffie-hellman-group1-sha1');
$key = DH::createKey($param); $key = DH::createKey($param);
$this->assertInternalType('string', "$key"); $this->assertIsString("$key");
$this->assertInternalType('string', (string) $key->getPublicKey()); $this->assertIsString((string) $key->getPublicKey());
} }
public function testLoadPrivate() public function testLoadPrivate()
@ -119,7 +119,7 @@ i2REGZNPWmF3SRPrtq/4urrDRU0F2eQks7qnTkrauPK1/UvE1gwbqWrWgBko+6L+
Q3ADAIcv9LEmTBnSAOsCs1K9ExAmSv/T2/4+9dW28UYb+p/uV477d1wf+nCWS6VU Q3ADAIcv9LEmTBnSAOsCs1K9ExAmSv/T2/4+9dW28UYb+p/uV477d1wf+nCWS6VU
/gTm /gTm
-----END PUBLIC KEY-----'); -----END PUBLIC KEY-----');
$this->assertInternalType('string', DH::computeSecret($ourPriv, $theirPub)); $this->assertIsString(DH::computeSecret($ourPriv, $theirPub));
} }
public function testComputeSecret() public function testComputeSecret()
@ -130,7 +130,7 @@ Q3ADAIcv9LEmTBnSAOsCs1K9ExAmSv/T2/4+9dW28UYb+p/uV477d1wf+nCWS6VU
foreach ($curves as $curve) { foreach ($curves as $curve) {
$ourPriv = EC::createKey($curve); $ourPriv = EC::createKey($curve);
$theirPub = EC::createKey($curve)->getPublicKey(); $theirPub = EC::createKey($curve)->getPublicKey();
$this->assertInternalType('string', DH::computeSecret($ourPriv, $theirPub)); $this->assertIsString(DH::computeSecret($ourPriv, $theirPub));
} }
} }

View File

@ -53,4 +53,3 @@ class Unit_Crypt_DSA_CreateKeyTest extends PhpseclibTestCase
$this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey()); $this->assertInstanceOf(PublicKey::class, $privatekey->getPublicKey());
} }
} }

View File

@ -13,14 +13,14 @@ use phpseclib3\Crypt\DSA\Formats\Keys\PKCS1;
use phpseclib3\Crypt\DSA\Formats\Keys\PKCS8; use phpseclib3\Crypt\DSA\Formats\Keys\PKCS8;
use phpseclib3\Crypt\DSA\Formats\Keys\PuTTY; use phpseclib3\Crypt\DSA\Formats\Keys\PuTTY;
use phpseclib3\Math\BigInteger; use phpseclib3\Math\BigInteger;
use phpseclib3\Exception\NoKeyLoadedException;
class Unit_Crypt_DSA_LoadKeyTest extends PhpseclibTestCase class Unit_Crypt_DSA_LoadDSAKeyTest extends PhpseclibTestCase
{ {
/**
* @expectedException \phpseclib3\Exception\NoKeyLoadedException
*/
public function testBadKey() public function testBadKey()
{ {
$this->expectException(NoKeyLoadedException::class);
$key = 'zzzzzzzzzzzzzz'; $key = 'zzzzzzzzzzzzzz';
PublicKeyLoader::load($key); PublicKeyLoader::load($key);
} }
@ -57,9 +57,9 @@ Private-MAC: 62b92ddd8b341b9414d640c24ba6ae929a78e039
$dsa = PublicKeyLoader::load($key); $dsa = PublicKeyLoader::load($key);
$this->assertInstanceOf(PrivateKey::class, $dsa); $this->assertInstanceOf(PrivateKey::class, $dsa);
$this->assertInternalType('string', "$dsa"); $this->assertIsString("$dsa");
$this->assertInternalType('string', $dsa->getPublicKey()->toString('PuTTY')); $this->assertIsString($dsa->getPublicKey()->toString('PuTTY'));
$this->assertInternalType('string', $dsa->getParameters()->toString('PuTTY')); $this->assertIsString($dsa->getParameters()->toString('PuTTY'));
$dsa = $dsa->withPassword('password'); $dsa = $dsa->withPassword('password');
$this->assertGreaterThan(0, strlen("$dsa")); $this->assertGreaterThan(0, strlen("$dsa"));
@ -91,9 +91,9 @@ Eb2s9fDOpnMhj+WqwcQgs18=
$dsa = PublicKeyLoader::load($key); $dsa = PublicKeyLoader::load($key);
$this->assertInstanceOf(PrivateKey::class, $dsa); $this->assertInstanceOf(PrivateKey::class, $dsa);
$this->assertInternalType('string', "$dsa"); $this->assertIsString("$dsa");
$this->assertInternalType('string', $dsa->getPublicKey()->toString('PKCS1')); $this->assertIsString($dsa->getPublicKey()->toString('PKCS1'));
$this->assertInternalType('string', (string) $dsa->getParameters()); $this->assertIsString((string) $dsa->getParameters());
} }
public function testParameters() public function testParameters()
@ -133,7 +133,7 @@ ZpmyOpXM/0opRMIRdmqVW4ardBFNokmlqngwcbaptfRnk9W2cQtx0lmKy6X/vnis
$dsa = PublicKeyLoader::load($key); $dsa = PublicKeyLoader::load($key);
$this->assertInstanceOf(PublicKey::class, $dsa); $this->assertInstanceOf(PublicKey::class, $dsa);
$this->assertInternalType('string', "$dsa"); $this->assertIsString("$dsa");
} }
public function testPKCS8Private() public function testPKCS8Private()
@ -151,16 +151,15 @@ Syea3pSvWdBpVhWzOX4A7qbxs+bhWAQWAhQiF7sFfCtZ7oOgCb2aJ9ySC9sTug==
$dsa = PublicKeyLoader::load($key); $dsa = PublicKeyLoader::load($key);
$this->assertInstanceOf(PrivateKey::class, $dsa); $this->assertInstanceOf(PrivateKey::class, $dsa);
$this->assertInternalType('string', "$dsa"); $this->assertIsString("$dsa");
$this->assertInstanceOf(PublicKey::class, $dsa->getPublicKey()); $this->assertInstanceOf(PublicKey::class, $dsa->getPublicKey());
$this->assertInstanceOf(Parameters::class, $dsa->getParameters()); $this->assertInstanceOf(Parameters::class, $dsa->getParameters());
} }
/**
* @expectedException \phpseclib3\Exception\NoKeyLoadedException
*/
public function testPuTTYBadMAC() public function testPuTTYBadMAC()
{ {
$this->expectException(NoKeyLoadedException::class);
$key = 'PuTTY-User-Key-File-2: ssh-dss $key = 'PuTTY-User-Key-File-2: ssh-dss
Encryption: none Encryption: none
Comment: dsa-key-20161223 Comment: dsa-key-20161223
@ -208,7 +207,7 @@ ZpmyOpXM/0opRMIRdmqVW4ardBFNokmlqngwcbaptfRnk9W2cQtx0lmKy6X/vnis
$dsa = PublicKeyLoader::load($key); $dsa = PublicKeyLoader::load($key);
$xml = $dsa->toString('XML'); $xml = $dsa->toString('XML');
$this->assertContains('DSAKeyValue', $xml); $this->assertStringContainsString('DSAKeyValue', $xml);
$dsa = PublicKeyLoader::load($xml); $dsa = PublicKeyLoader::load($xml);
$pkcs8 = $dsa->toString('PKCS8'); $pkcs8 = $dsa->toString('PKCS8');

View File

@ -14,7 +14,7 @@ use phpseclib3\Crypt\EC\Formats\Keys\XML;
use phpseclib3\Crypt\PublicKeyLoader; use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Crypt\EC\PrivateKey; use phpseclib3\Crypt\EC\PrivateKey;
class Unit_Crypt_EC_LoadKeyTest extends PhpseclibTestCase class Unit_Crypt_EC_KeyTest extends PhpseclibTestCase
{ {
public function testBinaryPKCS1PrivateParameters() public function testBinaryPKCS1PrivateParameters()
{ {
@ -27,7 +27,7 @@ Stf/0U65RhWgBwYFK4EEACKhZANiAASVZJGIs6m/TZhbFoTwBtpvU1JcyixD2YI3
5YnoIx/6Q1oqJg1vrrmUoXaeEpaO6JH8RgItTl9lYMdmOk5309WJka6tI1QAAK3+ 5YnoIx/6Q1oqJg1vrrmUoXaeEpaO6JH8RgItTl9lYMdmOk5309WJka6tI1QAAK3+
Jq9z4moG4whp3JsuiBQG9wnaHVrQPA4= Jq9z4moG4whp3JsuiBQG9wnaHVrQPA4=
-----END EC PRIVATE KEY-----'); -----END EC PRIVATE KEY-----');
$this->assertSame('secp384r1', $key->getCurve()); $this->assertSameNL('secp384r1', $key->getCurve());
} }
// openssl ecparam -name secp256k1 -genkey -noout -out secp256k1.pem // openssl ecparam -name secp256k1 -genkey -noout -out secp256k1.pem
@ -38,9 +38,9 @@ MHQCAQEEIEzUawcXqUsQhaEQ51JLeOIY0ddzlO2nNgwDk32ETqwkoAcGBSuBBAAK
oUQDQgAEFuVcVb9iCUhg2cknHPE+BouHGhQ39ORjMaMI3T4RfRxr6dj5HAXdEqVZ oUQDQgAEFuVcVb9iCUhg2cknHPE+BouHGhQ39ORjMaMI3T4RfRxr6dj5HAXdEqVZ
1W94KMe30ndmTndcJ8BPeT1Dd15FdQ== 1W94KMe30ndmTndcJ8BPeT1Dd15FdQ==
-----END EC PRIVATE KEY-----'); -----END EC PRIVATE KEY-----');
$this->assertSame('secp256k1', $key->getCurve()); $this->assertSameNL('secp256k1', $key->getCurve());
//PKCS1::useNamedCurve(); //PKCS1::useNamedCurve();
$this->assertSame($expected, $key->toString('PKCS1')); $this->assertSameNL($expected, $key->toString('PKCS1'));
} }
// openssl ecparam -name secp256k1 -genkey -noout -out secp256k1.pem -param_enc explicit // openssl ecparam -name secp256k1 -genkey -noout -out secp256k1.pem -param_enc explicit
@ -54,7 +54,7 @@ o8RlXaT7/A4RCKj9F7RIpoVUGZxH0I/7ENS4AiEA/////////////////////rqu
3OavSKA7v9JejNA2QUECAQGhRANCAASCTRhjXqmdbqphSdxNkfTNAOmDW5cZ5fnZ 3OavSKA7v9JejNA2QUECAQGhRANCAASCTRhjXqmdbqphSdxNkfTNAOmDW5cZ5fnZ
ys0Tk4pUv/XdiMZtVCGTNsotGeFbT5X64JkP/BFi3PVqjwy2VhOc ys0Tk4pUv/XdiMZtVCGTNsotGeFbT5X64JkP/BFi3PVqjwy2VhOc
-----END EC PRIVATE KEY-----'); -----END EC PRIVATE KEY-----');
$this->assertSame('secp256k1', $key->getCurve()); $this->assertSameNL('secp256k1', $key->getCurve());
// this key and the above key have a few small differences. // this key and the above key have a few small differences.
// in both keys the coefficient's are 0 and 7. in the above // in both keys the coefficient's are 0 and 7. in the above
@ -75,7 +75,7 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAABwRBBHm+Zn753LusVaBilc6HCwcCm/zbLc4o
E5w= E5w=
-----END EC PRIVATE KEY-----'; -----END EC PRIVATE KEY-----';
PKCS1::useSpecifiedCurve(); PKCS1::useSpecifiedCurve();
$this->assertSame($expected, $key->toString('PKCS1')); $this->assertSameNL($expected, $key->toString('PKCS1'));
} }
// openssl ecparam -name secp256k1 -genkey -noout -out secp256k1.pem // openssl ecparam -name secp256k1 -genkey -noout -out secp256k1.pem
@ -87,8 +87,8 @@ MIGEAgEAMBAGByqGSM49AgEGBSuBBAAKBG0wawIBAQQgAYCXwnhqMT6fCIKIkQ0w
cac7QqHrn4TCQMF9a+im74WhRANCAATwCjyGuP8xQbvVjznqazL36oeAnD32I+X2 cac7QqHrn4TCQMF9a+im74WhRANCAATwCjyGuP8xQbvVjznqazL36oeAnD32I+X2
+wscW3OmyTDpk41HaWYPh+j+BoufsSkCwf8dBRGEQbCieZbbZogy +wscW3OmyTDpk41HaWYPh+j+BoufsSkCwf8dBRGEQbCieZbbZogy
-----END PRIVATE KEY-----'); -----END PRIVATE KEY-----');
$this->assertSame('secp256k1', $key->getCurve()); $this->assertSameNL('secp256k1', $key->getCurve());
$this->assertSame($expected, $key->toString('PKCS8')); $this->assertSameNL($expected, $key->toString('PKCS8'));
} }
// openssl ecparam -name secp256k1 -genkey -noout -out secp256k1.pem -param_enc explicit // openssl ecparam -name secp256k1 -genkey -noout -out secp256k1.pem -param_enc explicit
@ -104,7 +104,7 @@ IKFfw3vfd5pqA5SZOTFtpr7hdJoKP/rmTPMCggkAOA35oUQDQgAEnX66+UCzUW3T
/fkLGIIfZjJm5bIMwAV85LpDom2hI441JRx+/W4WqtGuW+B/LABS6ZHp+qzepThC /fkLGIIfZjJm5bIMwAV85LpDom2hI441JRx+/W4WqtGuW+B/LABS6ZHp+qzepThC
HsjS3Q9Pew== HsjS3Q9Pew==
-----END PRIVATE KEY-----'); -----END PRIVATE KEY-----');
$this->assertSame('secp256k1', $key->getCurve()); $this->assertSameNL('secp256k1', $key->getCurve());
// see testPKCS1PrivateKeySpecifiedCurve for an explanation // see testPKCS1PrivateKeySpecifiedCurve for an explanation
// of how this key and the above key differ // of how this key and the above key differ
@ -119,7 +119,7 @@ AASdfrr5QLNRbdP9+QsYgh9mMmblsgzABXzkukOibaEjjjUlHH79bhaq0a5b4H8s
AFLpken6rN6lOEIeyNLdD097 AFLpken6rN6lOEIeyNLdD097
-----END PRIVATE KEY-----'; -----END PRIVATE KEY-----';
PKCS8::useSpecifiedCurve(); PKCS8::useSpecifiedCurve();
$this->assertSame($expected, $key->toString('PKCS8')); $this->assertSameNL($expected, $key->toString('PKCS8'));
} }
// openssl ecparam -name sect113r1 -genkey -noout -out sect113r1.pem // openssl ecparam -name sect113r1 -genkey -noout -out sect113r1.pem
@ -129,10 +129,10 @@ AFLpken6rN6lOEIeyNLdD097
MEECAQEEDwBZdP4eSzKk/uQa6jdtfKAHBgUrgQQABKEiAyAABAHqCoNb++mK5qvE MEECAQEEDwBZdP4eSzKk/uQa6jdtfKAHBgUrgQQABKEiAyAABAHqCoNb++mK5qvE
c4rCzQEuI19czqvXpEPcAWSXew== c4rCzQEuI19czqvXpEPcAWSXew==
-----END EC PRIVATE KEY-----'); -----END EC PRIVATE KEY-----');
$this->assertSame('sect113r1', $key->getCurve()); $this->assertSameNL('sect113r1', $key->getCurve());
PKCS1::useNamedCurve(); PKCS1::useNamedCurve();
$this->assertSame($expected, $key->toString('PKCS1')); $this->assertSameNL($expected, $key->toString('PKCS1'));
} }
// openssl ecparam -name sect113r1 -genkey -noout -out sect113r1.pem -param_enc explicit // openssl ecparam -name sect113r1 -genkey -noout -out sect113r1.pem -param_enc explicit
@ -145,7 +145,7 @@ AxUAEOcjqxTWluZ2h1YVF1b+v4/LSakEHwQAnXNhbzX0qxQH1zViwQ8ApSgwJ3lY
7oTRMV7TGIYCDwEAAAAAAAAA2czsijnlbwIBAqEiAyAABAFC7c50y7uw+iuHeMCt 7oTRMV7TGIYCDwEAAAAAAAAA2czsijnlbwIBAqEiAyAABAFC7c50y7uw+iuHeMCt
WwCpKNBUcVeiHme609Dv/g== WwCpKNBUcVeiHme609Dv/g==
-----END EC PRIVATE KEY-----'); -----END EC PRIVATE KEY-----');
$this->assertSame('sect113r1', $key->getCurve()); $this->assertSameNL('sect113r1', $key->getCurve());
// this key and the above key have a few small differences. // this key and the above key have a few small differences.
// the above key has the (optional) seed for the verifiably // the above key has the (optional) seed for the verifiably
@ -159,7 +159,7 @@ BACdc2FvNfSrFAfXNWLBDwClKDAneVjuhNExXtMYhgIPAQAAAAAAAADZzOyKOeVv
oSIDIAAEAULtznTLu7D6K4d4wK1bAKko0FRxV6IeZ7rT0O/+ oSIDIAAEAULtznTLu7D6K4d4wK1bAKko0FRxV6IeZ7rT0O/+
-----END EC PRIVATE KEY-----'; -----END EC PRIVATE KEY-----';
PKCS1::useSpecifiedCurve(); PKCS1::useSpecifiedCurve();
$this->assertSame($expected, $key->toString('PKCS1')); $this->assertSameNL($expected, $key->toString('PKCS1'));
} }
// openssl ecparam -name sect113r1 -genkey -noout -out sect113r1.pem // openssl ecparam -name sect113r1 -genkey -noout -out sect113r1.pem
@ -171,10 +171,10 @@ oSIDIAAEAULtznTLu7D6K4d4wK1bAKko0FRxV6IeZ7rT0O/+
MFECAQAwEAYHKoZIzj0CAQYFK4EEAAQEOjA4AgEBBA8A5OuqAY8HYoFOaz9mE6mh MFECAQAwEAYHKoZIzj0CAQYFK4EEAAQEOjA4AgEBBA8A5OuqAY8HYoFOaz9mE6mh
IgMgAAQASF3rOTPXvH0QdRBvsrMBdLMf27yd8AWABrZTxvI= IgMgAAQASF3rOTPXvH0QdRBvsrMBdLMf27yd8AWABrZTxvI=
-----END PRIVATE KEY-----'); -----END PRIVATE KEY-----');
$this->assertSame('sect113r1', $key->getCurve()); $this->assertSameNL('sect113r1', $key->getCurve());
PKCS8::useNamedCurve(); PKCS8::useNamedCurve();
$this->assertSame($expected, $key->toString('PKCS8')); $this->assertSameNL($expected, $key->toString('PKCS8'));
} }
// openssl ecparam -name sect113r1 -genkey -noout -out sect113r1.pem -param_enc explicit // openssl ecparam -name sect113r1 -genkey -noout -out sect113r1.pem -param_enc explicit
@ -188,7 +188,7 @@ AgMCAgEJMDcEDjCIJQym58f+ZJzoWCD3BA7ovuTT4iYHRBiL4OnHIwMVABDnI6sU
Ag8BAAAAAAAAANnM7Io55W8CAQIEOjA4AgEBBA8AXtfDMRsRTx8snPbWHquhIgMg Ag8BAAAAAAAAANnM7Io55W8CAQIEOjA4AgEBBA8AXtfDMRsRTx8snPbWHquhIgMg
AAQA9xdWGJ6vV23+vkdq0C8BLJVg5E3amMyf/5keGa4= AAQA9xdWGJ6vV23+vkdq0C8BLJVg5E3amMyf/5keGa4=
-----END PRIVATE KEY-----'); -----END PRIVATE KEY-----');
$this->assertSame('sect113r1', $key->getCurve()); $this->assertSameNL('sect113r1', $key->getCurve());
// see testBinaryPKCS1PrivateKeySpecifiedCurve() for an // see testBinaryPKCS1PrivateKeySpecifiedCurve() for an
// explanation of the differences between the above key // explanation of the differences between the above key
@ -201,7 +201,7 @@ BA8AXtfDMRsRTx8snPbWHquhIgMgAAQA9xdWGJ6vV23+vkdq0C8BLJVg5E3amMyf
/5keGa4= /5keGa4=
-----END PRIVATE KEY-----'; -----END PRIVATE KEY-----';
PKCS8::useSpecifiedCurve(); PKCS8::useSpecifiedCurve();
$this->assertSame($expected, $key->toString('PKCS8')); $this->assertSameNL($expected, $key->toString('PKCS8'));
} }
// openssl ecparam -name sect131r1 -genkey -noout -out sect131r1.pem -param_enc explicit // openssl ecparam -name sect131r1 -genkey -noout -out sect131r1.pem -param_enc explicit
@ -215,7 +215,7 @@ AhfAVhCIS2O5xscpFnj500EDFQBNaW5naHVhUXWYW9OtutohtDqX4gQjBACBuvkf
35gzxA+cGBNDY4OZB4xufqOMAB9zyBNLG0754VACEQQAAAAAAAAAAjEjlTqUZLVN 35gzxA+cGBNDY4OZB4xufqOMAB9zyBNLG0754VACEQQAAAAAAAAAAjEjlTqUZLVN
AgECoSYDJAAEBEIolGjo5lnsYqNagqYPOaEGOglkllDO2aWPtB6n+x/WXw== AgECoSYDJAAEBEIolGjo5lnsYqNagqYPOaEGOglkllDO2aWPtB6n+x/WXw==
-----END EC PRIVATE KEY-----'); -----END EC PRIVATE KEY-----');
$this->assertSame('sect131r1', $key->getCurve()); $this->assertSameNL('sect131r1', $key->getCurve());
// see testBinaryPKCS1PrivateKeySpecifiedCurve() for an // see testBinaryPKCS1PrivateKeySpecifiedCurve() for an
// explanation of the differences between the above key // explanation of the differences between the above key
@ -228,7 +228,7 @@ SxtO+eFQAhEEAAAAAAAAAAIxI5U6lGS1TaEmAyQABARCKJRo6OZZ7GKjWoKmDzmh
BjoJZJZQztmlj7Qep/sf1l8= BjoJZJZQztmlj7Qep/sf1l8=
-----END EC PRIVATE KEY-----'; -----END EC PRIVATE KEY-----';
PKCS1::useSpecifiedCurve(); PKCS1::useSpecifiedCurve();
$this->assertSame($expected, $key->toString('PKCS1')); $this->assertSameNL($expected, $key->toString('PKCS1'));
} }
// from https://tools.ietf.org/html/draft-ietf-curdle-pkix-07#section-10.1 // from https://tools.ietf.org/html/draft-ietf-curdle-pkix-07#section-10.1
@ -237,7 +237,7 @@ BjoJZJZQztmlj7Qep/sf1l8=
$key = PublicKeyLoader::load('-----BEGIN PUBLIC KEY----- $key = PublicKeyLoader::load('-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE= MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=
-----END PUBLIC KEY-----'); -----END PUBLIC KEY-----');
$this->assertSame('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
// in the above key AlgorithmIdentifier has a single "child". in the // in the above key AlgorithmIdentifier has a single "child". in the
// following key it has two. The second one is ("optional") NULL. // following key it has two. The second one is ("optional") NULL.
@ -246,7 +246,7 @@ MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=
$expected = '-----BEGIN PUBLIC KEY----- $expected = '-----BEGIN PUBLIC KEY-----
MCwwBwYDK2VwBQADIQAZv0QJaYTN/oVBusFn3DuWyFCGqjC2tssMXDitcDFm4Q== MCwwBwYDK2VwBQADIQAZv0QJaYTN/oVBusFn3DuWyFCGqjC2tssMXDitcDFm4Q==
-----END PUBLIC KEY-----'; -----END PUBLIC KEY-----';
$this->assertSame($expected, $key->toString('PKCS8')); $this->assertSameNL($expected, $key->toString('PKCS8'));
} }
// from https://tools.ietf.org/html/draft-ietf-curdle-pkix-07#section-10.3 // from https://tools.ietf.org/html/draft-ietf-curdle-pkix-07#section-10.3
@ -256,8 +256,8 @@ MCwwBwYDK2VwBQADIQAZv0QJaYTN/oVBusFn3DuWyFCGqjC2tssMXDitcDFm4Q==
$key = PublicKeyLoader::load('-----BEGIN PRIVATE KEY----- $key = PublicKeyLoader::load('-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC
-----END PRIVATE KEY-----'); -----END PRIVATE KEY-----');
$this->assertSame('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
$this->assertSame('Ed25519', $key->getPublicKey()->getCurve()); $this->assertSameNL('Ed25519', $key->getPublicKey()->getCurve());
// with public key // with public key
$key = PublicKeyLoader::load('-----BEGIN PRIVATE KEY----- $key = PublicKeyLoader::load('-----BEGIN PRIVATE KEY-----
@ -265,8 +265,8 @@ MHICAQEwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC
oB8wHQYKKoZIhvcNAQkJFDEPDA1DdXJkbGUgQ2hhaXJzgSEAGb9ECWmEzf6FQbrB oB8wHQYKKoZIhvcNAQkJFDEPDA1DdXJkbGUgQ2hhaXJzgSEAGb9ECWmEzf6FQbrB
Z9w7lshQhqowtrbLDFw4rXAxZuE= Z9w7lshQhqowtrbLDFw4rXAxZuE=
-----END PRIVATE KEY-----'); -----END PRIVATE KEY-----');
$this->assertSame('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
$this->assertSame('Ed25519', $key->getPublicKey()->getCurve()); $this->assertSameNL('Ed25519', $key->getPublicKey()->getCurve());
// the above key not only omits NULL - it also includes a // the above key not only omits NULL - it also includes a
// unstructuredName attribute with a value of "Curdle Chairs" // unstructuredName attribute with a value of "Curdle Chairs"
@ -275,12 +275,12 @@ Z9w7lshQhqowtrbLDFw4rXAxZuE=
MFMCAQEwBwYDK2VwBQAEIgQg1O5y2/kTWErVttjx92n4rTr+fCjL8dT74Jeoj0R1 MFMCAQEwBwYDK2VwBQAEIgQg1O5y2/kTWErVttjx92n4rTr+fCjL8dT74Jeoj0R1
WEKBIQAZv0QJaYTN/oVBusFn3DuWyFCGqjC2tssMXDitcDFm4Q== WEKBIQAZv0QJaYTN/oVBusFn3DuWyFCGqjC2tssMXDitcDFm4Q==
-----END PRIVATE KEY-----'; -----END PRIVATE KEY-----';
$this->assertSame($expected, $key->toString('PKCS8')); $this->assertSameNL($expected, $key->toString('PKCS8'));
$expected = EC::createKey('Ed25519')->toString('PKCS8'); $expected = EC::createKey('Ed25519')->toString('PKCS8');
$key = PublicKeyLoader::load($expected); $key = PublicKeyLoader::load($expected);
$this->assertSame('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
$this->assertSame('Ed25519', $key->getPublicKey()->getCurve()); $this->assertSameNL('Ed25519', $key->getPublicKey()->getCurve());
} }
public function testPuTTYnistp256() public function testPuTTYnistp256()
@ -296,16 +296,16 @@ Private-Lines: 1
AAAAIQDwaPlajbXY1SxhuwsUqN1CEZ5g4adsbmJsKm+ZbUVm4g== AAAAIQDwaPlajbXY1SxhuwsUqN1CEZ5g4adsbmJsKm+ZbUVm4g==
Private-MAC: b85ca0eb7c612df5d18af85128821bd53faaa3ef Private-MAC: b85ca0eb7c612df5d18af85128821bd53faaa3ef
'); ');
$this->assertSame('secp256r1', $key->getCurve()); $this->assertSameNL('secp256r1', $key->getCurve());
PuTTY::setComment('ecdsa-key-20181105'); PuTTY::setComment('ecdsa-key-20181105');
$this->assertSame($expected, $key->toString('PuTTY')); $this->assertSameNL($expected, $key->toString('PuTTY'));
$key = PublicKeyLoader::load($expected = 'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJEXCsWA8s18m25MJlVE1urbXPYFi4q8oMbb2H0kE2f5WPxizsKXRmb1J68paXQizryL9fC4FTqICJ1+UnaPfk0= ecdsa-key-20181105'); $key = PublicKeyLoader::load($expected = 'ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBJEXCsWA8s18m25MJlVE1urbXPYFi4q8oMbb2H0kE2f5WPxizsKXRmb1J68paXQizryL9fC4FTqICJ1+UnaPfk0= ecdsa-key-20181105');
$this->assertSame('secp256r1', $key->getCurve()); $this->assertSameNL('secp256r1', $key->getCurve());
OpenSSH::setComment('ecdsa-key-20181105'); OpenSSH::setComment('ecdsa-key-20181105');
$this->assertSame($expected, $key->toString('OpenSSH')); $this->assertSameNL($expected, $key->toString('OpenSSH'));
} }
public function testPuTTYnistp384() public function testPuTTYnistp384()
@ -322,16 +322,16 @@ AAAAMQCEMkGMDg6N7bUqdvLXe0YmY4qBSi8hmAuMvU38RDoVFVmV+R4RYmMueyrX
be9Oyus= be9Oyus=
Private-MAC: 97a990a3d5f6b8f268d4be9c4ab9ebfd8fa79849 Private-MAC: 97a990a3d5f6b8f268d4be9c4ab9ebfd8fa79849
'); ');
$this->assertSame('secp384r1', $key->getCurve()); $this->assertSameNL('secp384r1', $key->getCurve());
PuTTY::setComment('ecdsa-key-20181105'); PuTTY::setComment('ecdsa-key-20181105');
$this->assertSame($expected, $key->toString('PuTTY')); $this->assertSameNL($expected, $key->toString('PuTTY'));
$key = PublicKeyLoader::load($expected = 'ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBOI53wHG3CdcAJZq5PXWZAEAxxsNVFQlQgOX9toWEOgqQF5LbK2nWLKRvaHMzocUXaTYZDccSS0ATZFPT3j1Er1LU9cu4PHpyS07v262jdzkxIvKCPcAeISuV80MC7rHog== ecdsa-key-20181105'); $key = PublicKeyLoader::load($expected = 'ecdsa-sha2-nistp384 AAAAE2VjZHNhLXNoYTItbmlzdHAzODQAAAAIbmlzdHAzODQAAABhBOI53wHG3CdcAJZq5PXWZAEAxxsNVFQlQgOX9toWEOgqQF5LbK2nWLKRvaHMzocUXaTYZDccSS0ATZFPT3j1Er1LU9cu4PHpyS07v262jdzkxIvKCPcAeISuV80MC7rHog== ecdsa-key-20181105');
$this->assertSame('secp384r1', $key->getCurve()); $this->assertSameNL('secp384r1', $key->getCurve());
OpenSSH::setComment('ecdsa-key-20181105'); OpenSSH::setComment('ecdsa-key-20181105');
$this->assertSame($expected, $key->toString('OpenSSH')); $this->assertSameNL($expected, $key->toString('OpenSSH'));
} }
@ -350,16 +350,16 @@ AAAAQgHJl8/dIArolFymdzhagXCfd2l8UF3CQXWGVGDQ0R04nnntlyztYiVdRXXK
r84NnzS7dJcAsR9YaUOZ69NRKNiUAQ== r84NnzS7dJcAsR9YaUOZ69NRKNiUAQ==
Private-MAC: 6d49ce289b85549a43d74422dd8bb3ba8798c72c Private-MAC: 6d49ce289b85549a43d74422dd8bb3ba8798c72c
'); ');
$this->assertSame('secp521r1', $key->getCurve()); $this->assertSameNL('secp521r1', $key->getCurve());
PuTTY::setComment('ecdsa-key-20181105'); PuTTY::setComment('ecdsa-key-20181105');
$this->assertSame($expected, $key->toString('PuTTY')); $this->assertSameNL($expected, $key->toString('PuTTY'));
$key = PublicKeyLoader::load($expected = 'ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBAF1Eg0MjaJwooFj6HCNh4RWbvmQRY+sdczJyBdT3EaTc/6IUcCfW7w7rAeRp2CDdE9RlAVD8IuLqW7DJH06Xeov8wBO5G6jUqXu0rlHsOSiC6VcCxBJuWVNB1IorHnS7PX0f6HdLlIEme73P77drqpn5YY0XLtP6hFrF7H5XfCxpNyaJA== ecdsa-key-20181105'); $key = PublicKeyLoader::load($expected = 'ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBAF1Eg0MjaJwooFj6HCNh4RWbvmQRY+sdczJyBdT3EaTc/6IUcCfW7w7rAeRp2CDdE9RlAVD8IuLqW7DJH06Xeov8wBO5G6jUqXu0rlHsOSiC6VcCxBJuWVNB1IorHnS7PX0f6HdLlIEme73P77drqpn5YY0XLtP6hFrF7H5XfCxpNyaJA== ecdsa-key-20181105');
$this->assertSame('secp521r1', $key->getCurve()); $this->assertSameNL('secp521r1', $key->getCurve());
OpenSSH::setComment('ecdsa-key-20181105'); OpenSSH::setComment('ecdsa-key-20181105');
$this->assertSame($expected, $key->toString('OpenSSH')); $this->assertSameNL($expected, $key->toString('OpenSSH'));
} }
public function testPuTTYed25519() public function testPuTTYed25519()
@ -374,16 +374,16 @@ Private-Lines: 1
AAAAIAHu1uI7dxFzo/SleEI2CekXKmgqlXwOgvfaRWxiX4Jd AAAAIAHu1uI7dxFzo/SleEI2CekXKmgqlXwOgvfaRWxiX4Jd
Private-MAC: 8a06821a1c8b8b40fc40f876e543c4ea3fb81bb9 Private-MAC: 8a06821a1c8b8b40fc40f876e543c4ea3fb81bb9
'); ');
$this->assertSame('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
PuTTY::setComment('ed25519-key-20181105'); PuTTY::setComment('ed25519-key-20181105');
$this->assertSame($expected, $key->toString('PuTTY')); $this->assertSameNL($expected, $key->toString('PuTTY'));
$key = PublicKeyLoader::load($expected = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC6I6RyYAqtBcWXws9EDqGbhFtc5rKG4NMn/G7temQtu ed25519-key-20181105'); $key = PublicKeyLoader::load($expected = 'ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC6I6RyYAqtBcWXws9EDqGbhFtc5rKG4NMn/G7temQtu ed25519-key-20181105');
$this->assertSame('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
OpenSSH::setComment('ed25519-key-20181105'); OpenSSH::setComment('ed25519-key-20181105');
$this->assertSame($expected, $key->toString('OpenSSH')); $this->assertSameNL($expected, $key->toString('OpenSSH'));
} }
public function testlibsodium() public function testlibsodium()
@ -395,12 +395,12 @@ Private-MAC: 8a06821a1c8b8b40fc40f876e543c4ea3fb81bb9
$kp = sodium_crypto_sign_keypair(); $kp = sodium_crypto_sign_keypair();
$key = EC::loadFormat('libsodium', $expected = sodium_crypto_sign_secretkey($kp)); $key = EC::loadFormat('libsodium', $expected = sodium_crypto_sign_secretkey($kp));
$this->assertSame('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
$this->assertSame($expected, $key->toString('libsodium')); $this->assertSameNL($expected, $key->toString('libsodium'));
$key = EC::loadFormat('libsodium', $expected = sodium_crypto_sign_publickey($kp)); $key = EC::loadFormat('libsodium', $expected = sodium_crypto_sign_publickey($kp));
$this->assertSame('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
$this->assertSame($expected, $key->toString('libsodium')); $this->assertSameNL($expected, $key->toString('libsodium'));
} }
// ssh-keygen -t ed25519 // ssh-keygen -t ed25519
@ -413,7 +413,7 @@ eQAAAAtzc2gtZWQyNTUxOQAAACCpm7dS1/WDTW+uuhp2+aFLPKaJle6+oJqDGLXhlQAX4A
AAAEDltCTSbrr42IS4hhkS6ly0W2XItRQwxjLT+03bIyA+V6mbt1LX9YNNb666Gnb5oUs8 AAAEDltCTSbrr42IS4hhkS6ly0W2XItRQwxjLT+03bIyA+V6mbt1LX9YNNb666Gnb5oUs8
pomV7r6gmoMYteGVABfgAAAAD3ZhZ3JhbnRAdmFncmFudAECAwQFBg== pomV7r6gmoMYteGVABfgAAAAD3ZhZ3JhbnRAdmFncmFudAECAwQFBg==
-----END OPENSSH PRIVATE KEY-----'); -----END OPENSSH PRIVATE KEY-----');
$this->assertSame('Ed25519', $key->getCurve()); $this->assertSameNL('Ed25519', $key->getCurve());
// testing this key is a little difficult because of this format's // testing this key is a little difficult because of this format's
// two back to back checkint fields. both fields correspond to the // two back to back checkint fields. both fields correspond to the
@ -423,7 +423,7 @@ pomV7r6gmoMYteGVABfgAAAAD3ZhZ3JhbnRAdmFncmFudAECAwQFBg==
// none-the-less, because of the randomized component we can't easily // none-the-less, because of the randomized component we can't easily
// see if the key string is equal to another known string // see if the key string is equal to another known string
$key2 = PublicKeyLoader::load($key->toString('OpenSSH')); $key2 = PublicKeyLoader::load($key->toString('OpenSSH'));
$this->assertSame('Ed25519', $key2->getCurve()); $this->assertSameNL('Ed25519', $key2->getCurve());
} }
// from https://www.w3.org/TR/xmldsig-core/#sec-RFC4050Compat // from https://www.w3.org/TR/xmldsig-core/#sec-RFC4050Compat
@ -438,7 +438,7 @@ pomV7r6gmoMYteGVABfgAAAAD3ZhZ3JhbnRAdmFncmFudAECAwQFBg==
<Y Value="102403352136827775240910267217779508359028642524881540878079119895764161434936" /> <Y Value="102403352136827775240910267217779508359028642524881540878079119895764161434936" />
</PublicKey> </PublicKey>
</ECDSAKeyValue>'); </ECDSAKeyValue>');
$this->assertSame('secp256r1', $key->getCurve()); $this->assertSameNL('secp256r1', $key->getCurve());
XML::enableRFC4050Syntax(); XML::enableRFC4050Syntax();
@ -452,14 +452,14 @@ pomV7r6gmoMYteGVABfgAAAAD3ZhZ3JhbnRAdmFncmFudAECAwQFBg==
$dom->loadXML($key->toString('XML')); $dom->loadXML($key->toString('XML'));
$actual = $dom->C14N(); $actual = $dom->C14N();
$this->assertSame($expected, $actual); $this->assertSameNL($expected, $actual);
} }
public static function assertSame($expected, $actual, $message = '') public function assertSameNL($expected, $actual, $message = '')
{ {
$expected = str_replace("\r\n", "\n", $expected); $expected = str_replace("\r\n", "\n", $expected);
$actual = str_replace("\r\n", "\n", $actual); $actual = str_replace("\r\n", "\n", $actual);
return parent::assertSame($expected, $actual, $message); $this->assertSame($expected, $actual, $message);
} }
public function testOpenSSHPrivateEC() public function testOpenSSHPrivateEC()

View File

@ -6,6 +6,7 @@
*/ */
use phpseclib3\Crypt\Hash; use phpseclib3\Crypt\Hash;
use phpseclib3\Exception\UnsupportedAlgorithmException;
class Unit_Crypt_HashTest extends PhpseclibTestCase class Unit_Crypt_HashTest extends PhpseclibTestCase
{ {
@ -373,19 +374,17 @@ class Unit_Crypt_HashTest extends PhpseclibTestCase
$this->assertSame($hash->getHash(), 'sha256'); $this->assertSame($hash->getHash(), 'sha256');
} }
/**
* @expectedException \phpseclib3\Exception\UnsupportedAlgorithmException
*/
public function testConstructorArgumentInvalid() public function testConstructorArgumentInvalid()
{ {
$this->expectException(UnsupportedAlgorithmException::class);
new Hash('abcdefghijklmnopqrst'); new Hash('abcdefghijklmnopqrst');
} }
/**
* @expectedException \phpseclib3\Exception\UnsupportedAlgorithmException
*/
public function testSetHashInvalid() public function testSetHashInvalid()
{ {
$this->expectException(UnsupportedAlgorithmException::class);
$hash = new Hash('md5'); $hash = new Hash('md5');
$hash->setHash('abcdefghijklmnopqrst-96'); $hash->setHash('abcdefghijklmnopqrst-96');
} }

View File

@ -34,7 +34,7 @@ class Unit_Crypt_RSA_CreateKeyTest extends PhpseclibTestCase
{ {
list($publickey, $privatekey) = $args; list($publickey, $privatekey) = $args;
$ciphertext = $publickey->encrypt('zzz'); $ciphertext = $publickey->encrypt('zzz');
$this->assertInternalType('string', $ciphertext); $this->assertIsString($ciphertext);
$plaintext = $privatekey->decrypt($ciphertext); $plaintext = $privatekey->decrypt($ciphertext);
$this->assertSame($plaintext, 'zzz'); $this->assertSame($plaintext, 'zzz');
} }

View File

@ -15,6 +15,8 @@ use phpseclib3\Crypt\RSA\Formats\Keys\PuTTY;
use phpseclib3\Crypt\RSA\Formats\Keys\OpenSSH; use phpseclib3\Crypt\RSA\Formats\Keys\OpenSSH;
use phpseclib3\Crypt\RSA\Formats\Keys\PSS; use phpseclib3\Crypt\RSA\Formats\Keys\PSS;
use phpseclib3\Math\BigInteger; use phpseclib3\Math\BigInteger;
use phpseclib3\Exception\UnsupportedFormatException;
use phpseclib3\Exception\NoKeyLoadedException;
class Unit_Crypt_RSA_LoadKeyTest extends PhpseclibTestCase class Unit_Crypt_RSA_LoadKeyTest extends PhpseclibTestCase
{ {
@ -24,11 +26,10 @@ class Unit_Crypt_RSA_LoadKeyTest extends PhpseclibTestCase
OpenSSH::setComment('phpseclib-generated-key'); OpenSSH::setComment('phpseclib-generated-key');
} }
/**
* @expectedException \phpseclib3\Exception\NoKeyLoadedException
*/
public function testBadKey() public function testBadKey()
{ {
$this->expectException(NoKeyLoadedException::class);
$key = 'zzzzzzzzzzzzzz'; $key = 'zzzzzzzzzzzzzz';
PublicKeyLoader::load($key); PublicKeyLoader::load($key);
} }
@ -52,7 +53,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
$rsa = PublicKeyLoader::load($key); $rsa = PublicKeyLoader::load($key);
$this->assertInstanceOf(PrivateKey::class, $rsa); $this->assertInstanceOf(PrivateKey::class, $rsa);
$this->assertInternalType('string', "$rsa"); $this->assertIsString("$rsa");
} }
public function testPKCS1SpacesKey() public function testPKCS1SpacesKey()
@ -75,7 +76,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
$rsa = PublicKeyLoader::load($key); $rsa = PublicKeyLoader::load($key);
$this->assertInstanceOf(PrivateKey::class, $rsa); $this->assertInstanceOf(PrivateKey::class, $rsa);
$this->assertInternalType('string', "$rsa"); $this->assertIsString("$rsa");
} }
public function testPKCS1NoHeaderKey() public function testPKCS1NoHeaderKey()
@ -95,7 +96,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
$rsa = PublicKeyLoader::load($key); $rsa = PublicKeyLoader::load($key);
$this->assertInstanceOf(PrivateKey::class, $rsa); $this->assertInstanceOf(PrivateKey::class, $rsa);
$this->assertInternalType('string', "$rsa"); $this->assertIsString("$rsa");
} }
public function testPKCS1NoWhitespaceNoHeaderKey() public function testPKCS1NoWhitespaceNoHeaderKey()
@ -115,7 +116,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
$rsa = PublicKeyLoader::load($key); $rsa = PublicKeyLoader::load($key);
$this->assertInstanceOf(PrivateKey::class, $rsa); $this->assertInstanceOf(PrivateKey::class, $rsa);
$this->assertInternalType('string', "$rsa"); $this->assertIsString("$rsa");
} }
public function testRawPKCS1Key() public function testRawPKCS1Key()
@ -136,7 +137,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
$rsa = PublicKeyLoader::load($key); $rsa = PublicKeyLoader::load($key);
$this->assertInstanceOf(PrivateKey::class, $rsa); $this->assertInstanceOf(PrivateKey::class, $rsa);
$this->assertInternalType('string', "$rsa"); $this->assertIsString("$rsa");
} }
public function testLoadPKCS8PrivateKey() public function testLoadPKCS8PrivateKey()
@ -174,7 +175,7 @@ xryZaRDVmtMuf/OZBQ==
$rsa = PublicKeyLoader::load($key, 'password'); $rsa = PublicKeyLoader::load($key, 'password');
$this->assertInstanceOf(PrivateKey::class, $rsa); $this->assertInstanceOf(PrivateKey::class, $rsa);
$this->assertInternalType('string', "$rsa"); $this->assertIsString("$rsa");
} }
public function testSavePKCS8PrivateKey() public function testSavePKCS8PrivateKey()
@ -247,7 +248,7 @@ Ao8eayMp6FcvNucIpUndo1X8dKMv3Y26ZQIDAQAB
$rsa = PublicKeyLoader::load($key)->asPrivateKey(); $rsa = PublicKeyLoader::load($key)->asPrivateKey();
$this->assertInstanceOf(PrivateKey::class, $rsa); $this->assertInstanceOf(PrivateKey::class, $rsa);
$this->assertInternalType('string', $rsa->sign('zzz')); $this->assertIsString($rsa->sign('zzz'));
} }
public function testSSHPubKey() public function testSSHPubKey()
@ -1016,11 +1017,10 @@ YYFw8pfGesIFoEuVth4HKyF8k1y4mRUnYHP1XNMNMJl1JcEArC2asV8sHf6zSPVffozZ
$this->assertInstanceOf(PublicKey::class, $key); $this->assertInstanceOf(PublicKey::class, $key);
} }
/**
* @expectedException \phpseclib3\Exception\UnsupportedFormatException
*/
public function testSavePasswordXML() public function testSavePasswordXML()
{ {
$this->expectException(UnsupportedFormatException::class);
$key = '-----BEGIN RSA PRIVATE KEY----- $key = '-----BEGIN RSA PRIVATE KEY-----
MIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu MIIBOgIBAAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf9Cnzj4p4WGeKLs1Pt8Qu
KUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQJAIJLixBy2qpFoS4DSmoEm KUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQJAIJLixBy2qpFoS4DSmoEm
@ -1043,6 +1043,6 @@ n9dyFZYXxil/cgFG/PDMnuXy1Wcl8hb8iwQag4Y7ohiLXVTJa/0BAgMBAAE=
-----END RSA PRIVATE KEY-----'; -----END RSA PRIVATE KEY-----';
$key = PublicKeyLoader::load($key); $key = PublicKeyLoader::load($key);
$result = $key->toString('PKCS1'); $result = $key->toString('PKCS1');
$this->assertInternalType('string', $result); $this->assertIsString($result);
} }
} }

View File

@ -67,11 +67,10 @@ p0GbMJDyR4e9T04ZZwIDAQAB
$this->assertTrue($rsa->verify('zzzz', $sig)); $this->assertTrue($rsa->verify('zzzz', $sig));
} }
/**
* @expectedException \LengthException
*/
public function testSmallModulo() public function testSmallModulo()
{ {
$this->expectException('LengthException');
$plaintext = 'x'; $plaintext = 'x';
$key = PKCS8::savePublicKey( $key = PKCS8::savePublicKey(

View File

@ -78,7 +78,7 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
$decoded = ASN1::decodeBER(base64_decode($str)); $decoded = ASN1::decodeBER(base64_decode($str));
$result = ASN1::asn1map($decoded[0], $AS_REP); $result = ASN1::asn1map($decoded[0], $AS_REP);
$this->assertInternalType('array', $result); $this->assertIsArray($result);
} }
/** /**
@ -229,7 +229,7 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
$decoded = ASN1::decodeBER(base64_decode($str)); $decoded = ASN1::decodeBER(base64_decode($str));
$result = ASN1::asn1map($decoded[0], $AS_REP); $result = ASN1::asn1map($decoded[0], $AS_REP);
$this->assertInternalType('array', $result); $this->assertIsArray($result);
} }
/** /**
@ -271,7 +271,7 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
public function testContextSpecificNonConstructed() public function testContextSpecificNonConstructed()
{ {
$decoded = ASN1::decodeBER(base64_decode('MBaAFJtUo7c00HsI5EPZ4bkICfkOY2Pv')); $decoded = ASN1::decodeBER(base64_decode('MBaAFJtUo7c00HsI5EPZ4bkICfkOY2Pv'));
$this->assertInternalType('string', $decoded[0]['content'][0]['content']); $this->assertIsString($decoded[0]['content'][0]['content']);
} }
/** /**
@ -280,7 +280,7 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
public function testEmptyContextTag() public function testEmptyContextTag()
{ {
$decoded = ASN1::decodeBER("\xa0\x00"); $decoded = ASN1::decodeBER("\xa0\x00");
$this->assertInternalType('array', $decoded); $this->assertIsArray($decoded);
$this->assertCount(0, $decoded[0]['content']); $this->assertCount(0, $decoded[0]['content']);
} }
@ -390,6 +390,6 @@ class Unit_File_ASN1Test extends PhpseclibTestCase
$a = ASN1::decodeBER($a); $a = ASN1::decodeBER($a);
$a = ASN1::asn1map($a[0], $map); $a = ASN1::asn1map($a[0], $map);
$this->assertInternalType('array', $a); $this->assertIsArray($a);
} }
} }

View File

@ -28,7 +28,7 @@ v5RwaQHmQEzHofTzF7I+
$spkac = $x509->loadCSR($test); $spkac = $x509->loadCSR($test);
$this->assertInternalType('array', $spkac); $this->assertIsArray($spkac);
} }
public function testCSRWithAttributes() public function testCSRWithAttributes()
@ -68,7 +68,7 @@ draiRBZruwMPwPIP
$csr = $x509->loadCSR($test); $csr = $x509->loadCSR($test);
$this->assertInternalType('array', $csr); $this->assertIsArray($csr);
} }
public function testCSRDER() public function testCSRDER()
@ -93,7 +93,7 @@ draiRBZruwMPwPIP
$csr = $x509->loadCSR($csr); $csr = $x509->loadCSR($csr);
$this->assertInternalType('array', $csr); $this->assertIsArray($csr);
} }
// on PHP 7.1, with older versions of phpseclib, this would produce a "A non-numeric value encountered" warning // on PHP 7.1, with older versions of phpseclib, this would produce a "A non-numeric value encountered" warning

View File

@ -28,11 +28,11 @@ class Unit_File_X509_SPKACTest extends PhpseclibTestCase
$spkac = $x509->loadSPKAC($test); $spkac = $x509->loadSPKAC($test);
$this->assertInternalType('array', $spkac); $this->assertIsArray($spkac);
$spkac = $x509->loadSPKAC('SPKAC=' . $test); $spkac = $x509->loadSPKAC('SPKAC=' . $test);
$this->assertInternalType('array', $spkac); $this->assertIsArray($spkac);
$this->assertTrue( $this->assertTrue(
$x509->validateSignature(), $x509->validateSignature(),
@ -41,7 +41,7 @@ class Unit_File_X509_SPKACTest extends PhpseclibTestCase
$pubKey = $x509->getPublicKey(); $pubKey = $x509->getPublicKey();
$this->assertInternalType('string', "$pubKey"); $this->assertIsString("$pubKey");
} }
public function testSaveSPKAC() public function testSaveSPKAC()
@ -55,17 +55,17 @@ class Unit_File_X509_SPKACTest extends PhpseclibTestCase
$x509->setChallenge('...'); $x509->setChallenge('...');
$spkac = $x509->signSPKAC(); $spkac = $x509->signSPKAC();
$this->assertInternalType('array', $spkac); $this->assertIsArray($spkac);
$this->assertInternalType('string', $x509->saveSPKAC($spkac)); $this->assertIsString($x509->saveSPKAC($spkac));
$x509 = new X509(); $x509 = new X509();
$x509->setPrivateKey($privatekey); $x509->setPrivateKey($privatekey);
$spkac = $x509->signSPKAC(); $spkac = $x509->signSPKAC();
$this->assertInternalType('array', $spkac); $this->assertIsArray($spkac);
$this->assertInternalType('string', $x509->saveSPKAC($spkac)); $this->assertIsString($x509->saveSPKAC($spkac));
} }
public function testBadSignatureSPKAC() public function testBadSignatureSPKAC()

View File

@ -59,7 +59,7 @@ k6m17mi63YW/+iPCGOWZ2qXmY5HPEyyF2L4L4IDryFJ+8xLyw3pH9/yp5aHZDtp6
$cert = $x509->loadX509($test); $cert = $x509->loadX509($test);
$this->assertInternalType('array', $cert['tbsCertificate']['extensions'][3]['extnValue']); $this->assertIsArray($cert['tbsCertificate']['extensions'][3]['extnValue']);
} }
public function testLoadUnsupportedExtension() public function testLoadUnsupportedExtension()
@ -865,7 +865,7 @@ uhPlgkgknwIgdDqqKIAF60ouiynsbU53ERS0TwpjeFiYGA48SwYW3Nk=
$result = $x509->sign($issuer, $subject); $result = $x509->sign($issuer, $subject);
$result = $x509->saveX509($result); $result = $x509->saveX509($result);
$this->assertInternalType('string', $result); $this->assertIsString($result);
$r = $x509->loadX509($result); $r = $x509->loadX509($result);
$this->assertSame('id-dsa-with-sha256', $r['tbsCertificate']['signature']['algorithm']); $this->assertSame('id-dsa-with-sha256', $r['tbsCertificate']['signature']['algorithm']);
@ -896,7 +896,7 @@ wkwhE/JaQAEHq2PHnEmvwyBiJcHSdLXkcLzYlg19Ho0BPqVKdulx8GAk
$result = $x509->sign($issuer, $subject); $result = $x509->sign($issuer, $subject);
$result = $x509->saveX509($result); $result = $x509->saveX509($result);
$this->assertInternalType('string', $result); $this->assertIsString($result);
$r = $x509->loadX509($result); $r = $x509->loadX509($result);
$this->assertSame('ecdsa-with-SHA256', $r['tbsCertificate']['signature']['algorithm']); $this->assertSame('ecdsa-with-SHA256', $r['tbsCertificate']['signature']['algorithm']);
@ -935,7 +935,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
$result = $x509->sign($issuer, $subject); $result = $x509->sign($issuer, $subject);
$result = $x509->saveX509($result); $result = $x509->saveX509($result);
$this->assertInternalType('string', $result); $this->assertIsString($result);
$r = $x509->loadX509($result); $r = $x509->loadX509($result);
$this->assertSame('id-RSASSA-PSS', $r['tbsCertificate']['signature']['algorithm']); $this->assertSame('id-RSASSA-PSS', $r['tbsCertificate']['signature']['algorithm']);
@ -979,7 +979,7 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ
$result = $x509->sign($issuer, $subject); $result = $x509->sign($issuer, $subject);
$result = $x509->saveX509($result); $result = $x509->saveX509($result);
$this->assertInternalType('string', $result); $this->assertIsString($result);
$r = $x509->loadX509($result); $r = $x509->loadX509($result);
$this->assertSame('sha256WithRSAEncryption', $r['tbsCertificate']['signature']['algorithm']); $this->assertSame('sha256WithRSAEncryption', $r['tbsCertificate']['signature']['algorithm']);

View File

@ -7,11 +7,13 @@
use \phpseclib3\Math\BigInteger\Engines\PHP64; use \phpseclib3\Math\BigInteger\Engines\PHP64;
class Unit_Math_BigInteger_PHP64OpenSSLTest extends Unit_Math_BigInteger_PHP64Test class Unit_Math_BigInteger_PHP64OpenSSLTest extends Unit_Math_BigInteger_TestCase
{ {
public static function setUpBeforeClass() public static function setUpBeforeClass()
{ {
parent::setUpBeforeClass(); if (!PHP64::isValidEngine()) {
self::markTestSkipped('64-bit integers are not available.');
}
try { try {
PHP64::setModExpEngine('OpenSSL'); PHP64::setModExpEngine('OpenSSL');
@ -19,4 +21,22 @@ class Unit_Math_BigInteger_PHP64OpenSSLTest extends Unit_Math_BigInteger_PHP64Te
self::markTestSkipped('openssl_public_encrypt() function is not available.'); self::markTestSkipped('openssl_public_encrypt() function is not available.');
} }
} }
public function getInstance($x = 0, $base = 10)
{
return new PHP64($x, $base);
}
public function testInternalRepresentation()
{
$x = new PHP64('FFFFFFFFFFFFFFFFC90FDA', 16);
$y = new PHP64("$x");
$this->assertSame(self::getVar($x, 'value'), self::getVar($y, 'value'));
}
public static function getStaticClass()
{
return 'phpseclib3\Math\BigInteger\Engines\PHP64';
}
} }

View File

@ -384,7 +384,7 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase
{ {
$num = $this->getInstance(50); $num = $this->getInstance(50);
$str = print_r($num, true); $str = print_r($num, true);
$this->assertContains('[value] => 0x32', $str); $this->assertStringContainsString('[value] => 0x32', $str);
} }
public function testPrecision() public function testPrecision()

View File

@ -7,7 +7,7 @@
use phpseclib3\Net\SFTP\Stream; use phpseclib3\Net\SFTP\Stream;
class Unit_Net_SFTPStreamTest extends PhpseclibTestCase class Unit_Net_SFTPStreamUnitTest extends PhpseclibTestCase
{ {
public function testRegisterWithoutArgument() public function testRegisterWithoutArgument()
{ {

View File

@ -6,7 +6,7 @@
* @license http://www.opensource.org/licenses/mit-license.html MIT License * @license http://www.opensource.org/licenses/mit-license.html MIT License
*/ */
class Unit_Net_SSH2Test extends PhpseclibTestCase class Unit_Net_SSH2UnitTest extends PhpseclibTestCase
{ {
public function formatLogDataProvider() public function formatLogDataProvider()
{ {
@ -41,30 +41,30 @@ class Unit_Net_SSH2Test extends PhpseclibTestCase
$identifier = self::callFunc($this->createSSHMock(), 'generate_identifier'); $identifier = self::callFunc($this->createSSHMock(), 'generate_identifier');
$this->assertStringStartsWith('SSH-2.0-phpseclib_3.0', $identifier); $this->assertStringStartsWith('SSH-2.0-phpseclib_3.0', $identifier);
if (function_exists('\\Sodium\\library_version_major')) { if (function_exists('sodium_crypto_sign_keypair')) {
$this->assertContains('libsodium', $identifier); $this->assertStringContainsString('libsodium', $identifier);
} }
if (extension_loaded('openssl')) { if (extension_loaded('openssl')) {
$this->assertContains('openssl', $identifier); $this->assertStringContainsString('openssl', $identifier);
$this->assertNotContains('mcrypt', $identifier); $this->assertStringNotContainsString('mcrypt', $identifier);
} elseif (extension_loaded('mcrypt')) { } elseif (extension_loaded('mcrypt')) {
$this->assertNotContains('openssl', $identifier); $this->assertStringNotContainsString('openssl', $identifier);
$this->assertContains('mcrypt', $identifier); $this->assertStringContainsString('mcrypt', $identifier);
} else { } else {
$this->assertNotContains('openssl', $identifier); $this->assertStringNotContainsString('openssl', $identifier);
$this->assertNotContains('mcrypt', $identifier); $this->assertStringNotContainsString('mcrypt', $identifier);
} }
if (extension_loaded('gmp')) { if (extension_loaded('gmp')) {
$this->assertContains('gmp', $identifier); $this->assertStringContainsString('gmp', $identifier);
$this->assertNotContains('bcmath', $identifier); $this->assertStringNotContainsString('bcmath', $identifier);
} elseif (extension_loaded('bcmath')) { } elseif (extension_loaded('bcmath')) {
$this->assertNotContains('gmp', $identifier); $this->assertStringNotContainsString('gmp', $identifier);
$this->assertContains('bcmath', $identifier); $this->assertStringContainsString('bcmath', $identifier);
} else { } else {
$this->assertNotContains('gmp', $identifier); $this->assertStringNotContainsString('gmp', $identifier);
$this->assertNotContains('bcmath', $identifier); $this->assertStringNotContainsString('bcmath', $identifier);
} }
} }

View File

@ -20,6 +20,24 @@ then
PHPUNIT_ARGS="$PHPUNIT_ARGS -d zend.enable_gc=0" PHPUNIT_ARGS="$PHPUNIT_ARGS -d zend.enable_gc=0"
fi fi
if [ `php -r "echo (int) version_compare(PHP_VERSION, '7.3', '>=');"` = "1" ]
then
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/n setUpBeforeClass()/n setUpBeforeClass(): void/g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/n setUp()/n setUp(): void/g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/n tearDown()/n tearDown(): void/g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/\(n assertIsArray([^)]*)\)/\1: void/g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/\(n assertIsString([^)]*)\)/\1: void/g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/\(n assertIsResource([^)]*)\)/\1: void/g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/\(n assertIsObject([^)]*)\)/\1: void/g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/\(n assertStringContainsString([^)]*)\)/\1: void/g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/\(n assertStringNotContainsString([^)]*)\)/\1: void/g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/^class Unit_Crypt_\(AES\|DSA\|EC\|RSA\)_/class /g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/^class Unit_File_\(X509\)_/class /g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/^class Unit_Math_\(BigInteger\)_/class /g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/^class Unit_\(Crypt\|File\|Math\|Net\)_/class /g'
find tests -type f -name "*.php" -print0 | xargs -0 sed -i 's/^class Functional_Net_/class /g'
fi
if [ "$TRAVIS_PHP_VERSION" = 'hhvm' -o `php -r "echo (int) version_compare(PHP_VERSION, '7.0', '>=');"` = "1" ] if [ "$TRAVIS_PHP_VERSION" = 'hhvm' -o `php -r "echo (int) version_compare(PHP_VERSION, '7.0', '>=');"` = "1" ]
then then
find tests -type f -name "*Test.php" | \ find tests -type f -name "*Test.php" | \