welcome back to dyb-tech

This commit is contained in:
Daniel Guzman
2024-05-18 02:28:01 +02:00
parent 9513cdba09
commit 9f30bc98c7
6149 changed files with 668407 additions and 0 deletions
@@ -0,0 +1,43 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\ES256;
use Namshi\JOSE\Test\Signer\SecLib\SecLibTestCase;
class ES256Test extends SecLibTestCase
{
public function setup()
{
parent::setup();
// https://github.com/sebastianbergmann/phpunit/issues/1356
if (defined('HHVM_VERSION')) {
$this->markTestSkipped();
}
$this->privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.es256.key');
$this->public = openssl_pkey_get_public(SSL_KEYS_PATH.'public.es256.key');
$this->signer = new ES256();
}
public function testVerificationWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKey);
$this->assertInternalType('bool', $this->signer->verify($this->public, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->public, $encrypted, 'aaa'));
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Invalid key supplied.
*/
public function testWrongKeyCurve()
{
$privateKey512 = openssl_pkey_get_private(SSL_KEYS_PATH.'private.es512.key');
$this->signer->sign('aaa', $privateKey512);
}
public function testSigningWorksProperly()
{
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey));
}
}
@@ -0,0 +1,33 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\ES384;
use Namshi\JOSE\Test\Signer\SecLib\SecLibTestCase;
class ES384Test extends SecLibTestCase
{
public function setup()
{
parent::setup();
// https://github.com/sebastianbergmann/phpunit/issues/1356
if (defined('HHVM_VERSION')) {
$this->markTestSkipped();
}
$this->privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.es384.key', 'tests');
$this->public = openssl_pkey_get_public(SSL_KEYS_PATH.'public.es384.key');
$this->signer = new ES384();
}
public function testVerificationWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKey);
$this->assertInternalType('bool', $this->signer->verify($this->public, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->public, $encrypted, 'aaa'));
}
public function testSigningWorksProperly()
{
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey));
}
}
@@ -0,0 +1,33 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\ES512;
use Namshi\JOSE\Test\Signer\SecLib\SecLibTestCase;
class ES512Test extends SecLibTestCase
{
public function setup()
{
parent::setup();
// https://github.com/sebastianbergmann/phpunit/issues/1356
if (defined('HHVM_VERSION')) {
$this->markTestSkipped();
}
$this->privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.es512.key');
$this->public = openssl_pkey_get_public(SSL_KEYS_PATH.'public.es512.key');
$this->signer = new ES512();
}
public function testVerificationWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKey);
$this->assertInternalType('bool', $this->signer->verify($this->public, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->public, $encrypted, 'aaa'));
}
public function testSigningWorksProperly()
{
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey));
}
}
@@ -0,0 +1,19 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\HS256;
use PHPUnit_Framework_TestCase as TestCase;
class HS256Test extends TestCase
{
public function testSigningAndVerificationWorkProperly()
{
$signer = new HS256();
$signature = $signer->sign('aaa', 'foo');
$this->assertEquals($signature, base64_decode('P2Pb8e2Ja4P4YnTZ3EF002RKpUpOnfjIy0uLNT0R1J0='));
$this->assertTrue($signer->verify('foo', $signature, 'aaa'));
$this->assertFalse($signer->verify('bar', $signature, 'aaa'));
}
}
@@ -0,0 +1,20 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\HS384;
use PHPUnit_Framework_TestCase as TestCase;
class HS384Test extends TestCase
{
public function testSigningAndVerificationWorkProperly()
{
$signer = new HS384();
$signature = $signer->sign('aaa', 'foo');
$this->assertEquals($signature, base64_decode('W6Cd7qZknNYIXOxTrpEWFFwfuX0e2j59hTH4kVFh5o+9rcnfNtphLg4V8YXfkXGF'));
$this->assertTrue($signer->verify('foo', $signature, 'aaa'));
$this->assertFalse($signer->verify('bar', $signature, 'aaa'));
}
}
@@ -0,0 +1,20 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\HS512;
use PHPUnit_Framework_TestCase as TestCase;
class HS512Test extends TestCase
{
public function testSigningAndVerificationWorkProperly()
{
$signer = new HS512();
$signature = $signer->sign('aaa', 'foo');
$this->assertEquals($signature, base64_decode('GysqRX8GoD6BCTrI5sJy1ptn9A7vbDlvFOnaAxO/t+BD8KVrVAUVcHMxgM68ZNxnUNkb7kNSq3YxkCV4pBvTjg=='));
$this->assertTrue($signer->verify('foo', $signature, 'aaa'));
$this->assertFalse($signer->verify('bar', $signature, 'aaa'));
}
}
@@ -0,0 +1,67 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\RS256;
use PHPUnit_Framework_TestCase as TestCase;
class KeyFormatTest extends TestCase
{
public function setup()
{
$this->privateKeyResource = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', 'tests');
$this->privateKeyString = "-----BEGIN PRIVATE KEY-----\nMIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAN91kQxBuaze3WjI\nCNjeR/HD8E3kDzp89+Lhtn3tMish4yQxhNl6BEkabuS3pUj3WDP6+AFjBVqA1j3f\nu8Wqu7hRJDPHOs2kCII+LhIqvqQTLx/nvNOUhW2DimKn0HuHnlwJODq0MHFJEq5R\nrJH+mFGsP9yMGz4MxA04E2RVbUJRAgMBAAECgYEAjrDrO3Fo2GvD5Jn/lER0mnxt\nIb/kvYt5WyaYutbRN1u/SKhaVeklfWzkrSZb5DkV2LOE1JXfoEgvBnms1O9OSJXw\nqDrFF7NDebw95g6JzI+SbkIHw0Cb+/E9K92FjvW3Bi8j9PKIa8c/dpwIAIirc/q8\nuhSTf4WoIOHSFbSaQPECQQD1Wi9vynJLI5lShOs0wPomZOwNrXa73Lj8ciZC4oPS\nt6tWjbLnLsP+vTSLUyEYeQGsjdbY+y5siJmAqnV/ShB9AkEA6Sgna9gQw4dXN0jB\nSjOZSjl4S2/H3wHatclrvlYfbJVU6GlIlqWGaUkdFvCuEr9iXJAY4zpEQ4P370EZ\ntsyVZQJBAOZu/X6RNSc9GBNYo0+4rzjAMLPn50wp0dPHogfPlt+hgVqZWx2l3o6y\nRVdVjA/gFqJp1Q+VWdS1tvYRIqmadkECQCVdqQuwgedEHmcewtNod42crjmwvWBx\nBKMTl6/WT4zwVb41eUujVWo0LHRLuCoK//GDqmloIh6L3MU8MqnIGb0CQFWcpD4/\nroCkMblk0hPoQPpyapJexc438x7XuEGFEhyxxauqC5R4YFKCf+KBS2gZgr4GSwBU\nQww+qZ3eRYM7faM=\n-----END PRIVATE KEY-----";
$this->privateKeyFilePath = SSL_KEYS_PATH.'private-ne.key';
$this->publicKeyResource = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
$this->publicKeyString = "-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDfdZEMQbms3t1oyAjY3kfxw/BN\n5A86fPfi4bZ97TIrIeMkMYTZegRJGm7kt6VI91gz+vgBYwVagNY937vFqru4USQz\nxzrNpAiCPi4SKr6kEy8f57zTlIVtg4pip9B7h55cCTg6tDBxSRKuUayR/phRrD/c\njBs+DMQNOBNkVW1CUQIDAQAB\n-----END PUBLIC KEY-----";
$this->publicKeyFilePath = SSL_KEYS_PATH.'public-ne.key';
$this->badPrivateKeyString = "-----BEGIN PRIVATE KEY-----\nfoo\nbar\n-----END PRIVATE KEY-----";
$this->badPrivateKeyFilePath = SSL_KEYS_PATH.'nonexistant.key';
$this->signer = new RS256();
}
public function testStringKeyWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKeyString);
$this->assertInternalType('bool', $this->signer->verify($this->publicKeyString, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->publicKeyString, $encrypted, 'aaa'));
}
public function testFilePathKeyWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKeyFilePath);
$this->assertInternalType('bool', $this->signer->verify($this->publicKeyFilePath, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->publicKeyFilePath, $encrypted, 'aaa'));
}
public function testResourceKeyWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKeyResource);
$this->assertInternalType('bool', $this->signer->verify($this->publicKeyResource, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->publicKeyResource, $encrypted, 'aaa'));
}
/**
* @requires PHPUnit 5.4
*/
public function testBadStringKeyThrowsException()
{
$this->expectException(\RuntimeException::class);
$this->signer->sign('aaa', $this->badPrivateKeyString);
}
/**
* @requires PHPUnit 5.4
*/
public function testFilePathKeyThrowsException()
{
if(defined('HHVM_VERSION')) {
// in HHVM, openssl_pkey_get_(public|private) throws an error when
// passed a file path that cannot be found
$this->expectException('PHPUnit_Framework_Error');
} else {
$this->expectException(\RuntimeException::class);
}
$this->signer->sign('aaa', $this->badPrivateKeyFilePath);
}
}
@@ -0,0 +1,24 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\None;
use PHPUnit_Framework_TestCase as TestCase;
class NoneTest extends TestCase
{
public function testVerificationWorksProperly()
{
$signer = new none();
$this->assertTrue($signer->verify('bar', '', 'aaa'));
}
public function testSigningWorksProperly()
{
$signer = new none();
$signature = $signer->sign('aaa', 'foo');
$this->assertTrue($signature === '');
}
}
@@ -0,0 +1,28 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\RS256;
use PHPUnit_Framework_TestCase as TestCase;
class RS256Test extends TestCase
{
public function setup()
{
$this->privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', 'tests');
$this->public = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
$this->signer = new RS256();
}
public function testVerificationWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKey);
$this->assertInternalType('bool', $this->signer->verify($this->public, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->public, $encrypted, 'aaa'));
}
public function testSigningWorksProperly()
{
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey));
}
}
@@ -0,0 +1,28 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\RS384;
use PHPUnit_Framework_TestCase as TestCase;
class RS384Test extends TestCase
{
public function setup()
{
$this->privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', 'tests');
$this->public = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
$this->signer = new RS384();
}
public function testVerificationWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKey);
$this->assertInternalType('bool', $this->signer->verify($this->public, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->public, $encrypted, 'aaa'));
}
public function testSigningWorksProperly()
{
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey));
}
}
@@ -0,0 +1,28 @@
<?php
namespace Namshi\JOSE\Test\OpenSSL\Signer;
use Namshi\JOSE\Signer\OpenSSL\RS512;
use PHPUnit_Framework_TestCase as TestCase;
class RS512Test extends TestCase
{
public function setup()
{
$this->privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', 'tests');
$this->public = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
$this->signer = new RS512();
}
public function testVerificationWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKey);
$this->assertInternalType('bool', $this->signer->verify($this->public, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->public, $encrypted, 'aaa'));
}
public function testSigningWorksProperly()
{
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey));
}
}
@@ -0,0 +1,30 @@
<?php
namespace Namshi\JOSE\Test\Signer\SecLib;
use Namshi\JOSE\Signer\SecLib\RS256;
class RS256TEST extends SecLibTestCase
{
public function setup()
{
parent::setup();
$this->privateKey = file_get_contents(SSL_KEYS_PATH.'private.key');
$this->public = file_get_contents(SSL_KEYS_PATH.'public.key');
$this->password = 'tests';
$this->signer = new RS256();
}
public function testVerificationWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKey, $this->password);
$this->assertInternalType('bool', $this->signer->verify($this->public, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->public, $encrypted, 'aaa'));
}
public function testSigningWorksProperly()
{
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey, $this->password));
}
}
@@ -0,0 +1,30 @@
<?php
namespace Namshi\JOSE\Test\Signer\SecLib;
use Namshi\JOSE\Signer\SecLib\RS384;
class RS384Test extends SecLibTestCase
{
public function setup()
{
parent::setup();
$this->privateKey = file_get_contents(SSL_KEYS_PATH.'private.key');
$this->public = file_get_contents(SSL_KEYS_PATH.'public.key');
$this->password = 'tests';
$this->signer = new RS384();
}
public function testVerificationWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKey, $this->password);
$this->assertInternalType('bool', $this->signer->verify($this->public, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->public, $encrypted, 'aaa'));
}
public function testSigningWorksProperly()
{
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey, $this->password));
}
}
@@ -0,0 +1,30 @@
<?php
namespace Namshi\JOSE\Test\Signer\SecLib;
use Namshi\JOSE\Signer\SecLib\RS512;
class RS512Test extends SecLibTestCase
{
public function setup()
{
parent::setup();
$this->privateKey = file_get_contents(SSL_KEYS_PATH.'private.key');
$this->public = file_get_contents(SSL_KEYS_PATH.'public.key');
$this->password = 'tests';
$this->signer = new RS512();
}
public function testVerificationWorksProperly()
{
$encrypted = $this->signer->sign('aaa', $this->privateKey, $this->password);
$this->assertInternalType('bool', $this->signer->verify($this->public, $encrypted, 'aaa'));
$this->assertTrue($this->signer->verify($this->public, $encrypted, 'aaa'));
}
public function testSigningWorksProperly()
{
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey, $this->password));
}
}
@@ -0,0 +1,17 @@
<?php
namespace Namshi\JOSE\Test\Signer\SecLib;
use PHPUnit_Framework_TestCase as TestCase;
class SecLibTestCase extends TestCase
{
public function setup()
{
if (version_compare(PHP_VERSION, '7.0.0-dev') >= 0) {
$this->markTestSkipped("phpseclib 1.0.0(LTS), even the latest 2.0.0, doesn't support PHP7 yet");
}
parent::setUp();
}
}