Laravel version update
Laravel version update
This commit is contained in:
1
vendor/namshi/jose/.coveralls.yml
vendored
1
vendor/namshi/jose/.coveralls.yml
vendored
@@ -1,3 +1,2 @@
|
||||
service_name: travis-ci
|
||||
src_dir: ./
|
||||
coverage_clover: build/logs/clover.xml
|
||||
|
5
vendor/namshi/jose/.gitignore
vendored
5
vendor/namshi/jose/.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
vendor/
|
||||
build/
|
||||
build
|
||||
composer.lock
|
||||
vendor
|
||||
|
19
vendor/namshi/jose/.travis.yml
vendored
19
vendor/namshi/jose/.travis.yml
vendored
@@ -1,24 +1,17 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- hhvm
|
||||
|
||||
before_script:
|
||||
- curl -s http://getcomposer.org/installer | php
|
||||
- php composer.phar install --dev --no-interaction
|
||||
sudo: false
|
||||
|
||||
phpunit: php vendor/bin/phpunit --prefer-dist --dev
|
||||
install: travis_retry composer install --no-interaction --prefer-source
|
||||
|
||||
script:
|
||||
- mkdir -p build/logs
|
||||
- php vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover ./build/logs/clover.xml
|
||||
before_script: mkdir -p build/logs
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls -v
|
||||
script: php vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover ./build/logs/clover.xml
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: hhvm
|
||||
after_success: php vendor/bin/coveralls -v
|
||||
|
28
vendor/namshi/jose/CHANGELOG.md
vendored
Normal file
28
vendor/namshi/jose/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
### 6.1.0
|
||||
|
||||
- Dropped support for PHP 5.4
|
||||
- phpseclib ~2.0.x
|
||||
|
||||
### 6.0.4
|
||||
|
||||
- Added styleci config, add styleci-php-cs bridge to check formatting
|
||||
- Removed composer.lock
|
||||
- Fix #34: strlen() and substr() can misbehave with mbstring.func_overload
|
||||
- Fix: Don't cast to boolean the result of openssl_verify()
|
||||
- Enhancement: support phpseclib 1.x.x
|
||||
|
||||
### 6.x.x - Not Backwards Compatible
|
||||
|
||||
- Dropped support for PHP 5.3
|
||||
- Don't escape slashes when generating signin input.
|
||||
This may render tokens generated with earlier versions of Jose incompatible.
|
||||
- **DON'T** install version 6.0.2! It's using phpseclib version 2 instead of version 1 and some classes are broken
|
||||
|
||||
### 3.x.x to 4.x.x - Not Backwards Compatible
|
||||
|
||||
Added the ability to set custom properties in the header. Moved automatic inclusion of certain claims into an SimpleJWS class from the base JWS class.
|
||||
|
||||
### 2.x.x to 3.x.x
|
||||
|
||||
Introduced the ability to specify an encryption engine. Added support of PHPSecLib to the existing OpenSSL implementation.
|
||||
|
51
vendor/namshi/jose/README.md
vendored
51
vendor/namshi/jose/README.md
vendored
@@ -1,9 +1,9 @@
|
||||
# NAMSHI | JOSE
|
||||
|
||||
[](https://travis-ci.org/namshi/jose)
|
||||
[](http://hhvm.h4cc.de/package/namshi/jose)
|
||||
|
||||
[](https://insight.sensiolabs.com/projects/4beaf3d1-0bc6-4869-b99f-71dc951a2a05)
|
||||
[](https://travis-ci.org/namshi/jose)
|
||||
[](https://packagist.org/packages/namshi/jose)
|
||||
[](https://packagist.org/packages/namshi/jose)
|
||||
[](https://packagist.org/packages/namshi/jose)
|
||||
|
||||
This library provides a lightweight
|
||||
implementation of the JWS
|
||||
@@ -11,9 +11,9 @@ implementation of the JWS
|
||||
|
||||
## Prerequisites
|
||||
|
||||
This library needs PHP 5.4+ and the library OpenSSL.
|
||||
This library needs PHP 5.5+ and the library OpenSSL.
|
||||
|
||||
It has been tested using `PHP5.4` to `PHP5.6` and `HHVM`.
|
||||
It has been tested using `PHP5.5` to `PHP7.0` and `HHVM`.
|
||||
|
||||
|
||||
## Installation
|
||||
@@ -22,7 +22,7 @@ You can install the library directly from
|
||||
composer / [packagist](https://packagist.org/packages/namshi/jose):
|
||||
|
||||
```
|
||||
"namshi/jose": "5.0.*"
|
||||
"namshi/jose": "7.0.*"
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -80,7 +80,7 @@ $public_key = openssl_pkey_get_public("/path/to/public.key");
|
||||
if ($jws->isValid($public_key, 'RS256')) {
|
||||
$payload = $jws->getPayload();
|
||||
|
||||
echo sprintf("Hey, my JS app just did an action authenticated as user #%s", $payload['id']);
|
||||
echo sprintf("Hey, my JS app just did an action authenticated as user #%s", $payload['uid']);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -90,11 +90,11 @@ if ($jws->isValid($public_key, 'RS256')) {
|
||||
|
||||
### PHPSECLIB For RSA Verification
|
||||
|
||||
You may find that you need to use this library in an environment where
|
||||
[PHP's wrappers for OpenSSL](http://php.net/manual/en/ref.openssl.php)
|
||||
You may find that you need to use this library in an environment where
|
||||
[PHP's wrappers for OpenSSL](http://php.net/manual/en/ref.openssl.php)
|
||||
do not work, or OpenSSL simply is not installed. This library uses
|
||||
OpenSSL to encrypt by default, but you can specify that you want to use [PHPSecLib](http://phpseclib.sourceforge.net/) for a pure PHP
|
||||
implementation of RSA encryption.
|
||||
OpenSSL to encrypt by default, but you can specify that you want to use [PHPSecLib](http://phpseclib.sourceforge.net/) for a pure PHP
|
||||
implementation of RSA encryption.
|
||||
|
||||
In these cases, simply add the optional `'SecLib'` parameter when
|
||||
constructing a JWS:
|
||||
@@ -104,7 +104,7 @@ $jws = new JWS(array('alg' => 'RS256'), 'SecLib');
|
||||
```
|
||||
|
||||
You can now use the PHPSecLib implementation of RSA signing. If you use
|
||||
a password protected private key, you can still submit the private key
|
||||
a password protected private key, you can still submit the private key
|
||||
to use for signing as a string, as long as you pass the password as the
|
||||
second parameter into the `sign` method:
|
||||
|
||||
@@ -172,6 +172,31 @@ Introduced the ability to specify an encryption engine. Added support of PHPSecL
|
||||
|
||||
Added the ability to set custom properties in the header. Moved automatic inclusion of certain claims into an SimpleJWS class from the base JWS class.
|
||||
|
||||
### 6.x.x - Not Backwards Compatible
|
||||
|
||||
#### 6.1.x
|
||||
- Dropped support for PHP 5.4
|
||||
- phpseclib 2.0
|
||||
|
||||
#### 6.0.x
|
||||
- Dropped support for PHP 5.3
|
||||
- Don't escape slashes when generating signin input.
|
||||
This may render tokens generated with earlier versions of Jose incompatible.
|
||||
|
||||
### 7.x.x
|
||||
|
||||
#### 7.0.x
|
||||
|
||||
Moved phpseclib and the openssl extension as suggested dependencies.
|
||||
|
||||
## Tests
|
||||
|
||||
Tests are written using PHPUnit for this library. After doing composer install you can execute the following command to run tests:
|
||||
|
||||
```
|
||||
./vendor/bin/phpunit
|
||||
```
|
||||
|
||||
## Credits
|
||||
|
||||
This library has been inspired by the
|
||||
|
36
vendor/namshi/jose/composer.json
vendored
36
vendor/namshi/jose/composer.json
vendored
@@ -1,26 +1,44 @@
|
||||
{
|
||||
"name": "namshi/jose",
|
||||
"description": "JSON Object Signing and Encryption library for PHP.",
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.5",
|
||||
"satooshi/php-coveralls": "dev-master"
|
||||
},
|
||||
"license": "MIT",
|
||||
"keywords": ["jws", "jwt", "json", "json web token", "json web signature", "token"],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alessandro Nadalin",
|
||||
"email": "alessandro.nadalin@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Alessandro Cinelli (cirpo)",
|
||||
"email": "alessandro.cinelli@gmail.com"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Namshi\\JOSE": "src/"
|
||||
"psr-4": {
|
||||
"Namshi\\JOSE\\": "src/Namshi/JOSE/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Namshi\\JOSE\\Test\\": "test/Namshi/JOSE/Test/"
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3",
|
||||
"lib-openssl": "*",
|
||||
"phpseclib/phpseclib": "~0.3"
|
||||
"ext-date": "*",
|
||||
"ext-hash": "*",
|
||||
"ext-json": "*",
|
||||
"ext-pcre": "*",
|
||||
"ext-spl": "*",
|
||||
"php": ">=5.5",
|
||||
"symfony/polyfill-php56": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.5|^5.0",
|
||||
"satooshi/php-coveralls": "^1.0",
|
||||
"phpseclib/phpseclib": "^2.0"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-openssl": "Allows to use OpenSSL as crypto engine.",
|
||||
"phpseclib/phpseclib": "Allows to use Phpseclib as crypto engine, use version ^2.0."
|
||||
}
|
||||
}
|
||||
|
1535
vendor/namshi/jose/composer.lock
generated
vendored
1535
vendor/namshi/jose/composer.lock
generated
vendored
File diff suppressed because it is too large
Load Diff
42
vendor/namshi/jose/phpunit.xml.dist
vendored
42
vendor/namshi/jose/phpunit.xml.dist
vendored
@@ -1,34 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit
|
||||
backupGlobals="true"
|
||||
strict="false"
|
||||
backupStaticAttributes="false"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
forceCoversAnnotation="false"
|
||||
mapTestClassNameToCoveredClassName="false"
|
||||
processIsolation="false"
|
||||
stopOnFailure="false"
|
||||
stopOnError="false"
|
||||
stopOnIncomplete="false"
|
||||
stopOnSkipped="false"
|
||||
syntaxCheck="false"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
verbose="false"
|
||||
colors="true">
|
||||
<phpunit backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
beStrictAboutTestsThatDoNotTestAnything="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
bootstrap="tests/bootstrap.php"
|
||||
colors="true"
|
||||
convertErrorsToExceptions="true"
|
||||
convertNoticesToExceptions="true"
|
||||
convertWarningsToExceptions="true"
|
||||
processIsolation="false"
|
||||
stopOnError="false"
|
||||
stopOnFailure="false"
|
||||
verbose="true"
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="namshi/jose Test Suite">
|
||||
<testsuite name="JOSE Test Suite">
|
||||
<directory suffix="Test.php">./tests</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">./</directory>
|
||||
<exclude>
|
||||
<directory>./tests</directory>
|
||||
<directory>./vendor</directory>
|
||||
</exclude>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">./src</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
@@ -4,9 +4,9 @@ namespace Namshi\JOSE\Base64;
|
||||
|
||||
class Base64Encoder implements Encoder
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encode($data)
|
||||
@@ -16,11 +16,11 @@ class Base64Encoder implements Encoder
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function decode($data)
|
||||
{
|
||||
return base64_decode($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,7 +4,6 @@ namespace Namshi\JOSE\Base64;
|
||||
|
||||
class Base64UrlSafeEncoder implements Encoder
|
||||
{
|
||||
|
||||
public function encode($data)
|
||||
{
|
||||
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
|
||||
@@ -14,5 +13,4 @@ class Base64UrlSafeEncoder implements Encoder
|
||||
{
|
||||
return base64_decode(strtr($data, '-_', '+/'));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -4,17 +4,17 @@ namespace Namshi\JOSE\Base64;
|
||||
|
||||
interface Encoder
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encode($data);
|
||||
|
||||
/**
|
||||
* @param string $data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function decode($data);
|
||||
|
||||
}
|
||||
|
81
vendor/namshi/jose/src/Namshi/JOSE/JWS.php
vendored
81
vendor/namshi/jose/src/Namshi/JOSE/JWS.php
vendored
@@ -5,8 +5,8 @@ namespace Namshi\JOSE;
|
||||
use InvalidArgumentException;
|
||||
use Namshi\JOSE\Base64\Base64Encoder;
|
||||
use Namshi\JOSE\Base64\Base64UrlSafeEncoder;
|
||||
use Namshi\JOSE\Signer\SignerInterface;
|
||||
use Namshi\JOSE\Base64\Encoder;
|
||||
use Namshi\JOSE\Signer\SignerInterface;
|
||||
|
||||
/**
|
||||
* Class representing a JSON Web Signature.
|
||||
@@ -15,25 +15,33 @@ class JWS extends JWT
|
||||
{
|
||||
protected $signature;
|
||||
protected $isSigned = false;
|
||||
protected $originalToken;
|
||||
protected $encodedSignature;
|
||||
protected $encryptionEngine;
|
||||
protected $supportedEncryptionEngines = array('OpenSSL', 'SecLib');
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $header An associative array of headers. The value can be any type accepted by json_encode or a JSON serializable object
|
||||
*
|
||||
* @see http://php.net/manual/en/function.json-encode.php
|
||||
* @see http://php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
* @see https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-41#section-4
|
||||
*
|
||||
* @param string $encryptionEngine
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
public function __construct($header = array(), $encryptionEngine = "OpenSSL")
|
||||
public function __construct($header = array(), $encryptionEngine = 'OpenSSL')
|
||||
{
|
||||
if (!in_array($encryptionEngine, $this->supportedEncryptionEngines)) {
|
||||
throw new InvalidArgumentException(sprintf("Encryption engine %s is not supported", $encryptionEngine));
|
||||
throw new InvalidArgumentException(sprintf('Encryption engine %s is not supported', $encryptionEngine));
|
||||
}
|
||||
|
||||
if ('SecLib' === $encryptionEngine && version_compare(PHP_VERSION, '7.0.0-dev') >= 0) {
|
||||
throw new InvalidArgumentException("phpseclib 1.0.0(LTS), even the latest 2.0.0, doesn't support PHP7 yet");
|
||||
}
|
||||
|
||||
$this->encryptionEngine = $encryptionEngine;
|
||||
|
||||
parent::__construct(array(), $header);
|
||||
@@ -42,14 +50,15 @@ class JWS extends JWT
|
||||
/**
|
||||
* Signs the JWS signininput.
|
||||
*
|
||||
* @param resource $key
|
||||
* @param resource|string $key
|
||||
* @param optional string $password
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sign($key, $password = null)
|
||||
{
|
||||
$this->signature = $this->getSigner()->sign($this->generateSigninInput(), $key, $password);
|
||||
$this->isSigned = true;
|
||||
$this->isSigned = true;
|
||||
|
||||
return $this->signature;
|
||||
}
|
||||
@@ -65,7 +74,7 @@ class JWS extends JWT
|
||||
return $this->signature;
|
||||
}
|
||||
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,14 +96,19 @@ class JWS extends JWT
|
||||
{
|
||||
$signinInput = $this->generateSigninInput();
|
||||
|
||||
return sprintf("%s.%s", $signinInput, $this->encoder->encode($this->getSignature()));
|
||||
return sprintf('%s.%s', $signinInput, $this->encoder->encode($this->getSignature()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an instance of a JWS from a JWT.
|
||||
*
|
||||
* @param string $jwsTokenString
|
||||
* @param string $jwsTokenString
|
||||
* @param bool $allowUnsecure
|
||||
* @param Encoder $encoder
|
||||
* @param string $encryptionEngine
|
||||
*
|
||||
* @return JWS
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function load($jwsTokenString, $allowUnsecure = false, Encoder $encoder = null, $encryptionEngine = 'OpenSSL')
|
||||
@@ -102,11 +116,11 @@ class JWS extends JWT
|
||||
if ($encoder === null) {
|
||||
$encoder = strpbrk($jwsTokenString, '+/=') ? new Base64Encoder() : new Base64UrlSafeEncoder();
|
||||
}
|
||||
|
||||
|
||||
$parts = explode('.', $jwsTokenString);
|
||||
|
||||
if (count($parts) === 3) {
|
||||
$header = json_decode($encoder->decode($parts[0]), true);
|
||||
$header = json_decode($encoder->decode($parts[0]), true);
|
||||
$payload = json_decode($encoder->decode($parts[1]), true);
|
||||
|
||||
if (is_array($header) && is_array($payload)) {
|
||||
@@ -119,6 +133,7 @@ class JWS extends JWT
|
||||
$jws->setEncoder($encoder)
|
||||
->setHeader($header)
|
||||
->setPayload($payload)
|
||||
->setOriginalToken($jwsTokenString)
|
||||
->setEncodedSignature($parts[2]);
|
||||
|
||||
return $jws;
|
||||
@@ -133,7 +148,8 @@ class JWS extends JWT
|
||||
* signature previously stored (@see JWS::load).
|
||||
*
|
||||
* @param resource|string $key
|
||||
* @param string $algo The algorithms this JWS should be signed with. Use it if you want to restrict which algorithms you want to allow to be validated.
|
||||
* @param string $algo The algorithms this JWS should be signed with. Use it if you want to restrict which algorithms you want to allow to be validated.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function verify($key, $algo = null)
|
||||
@@ -143,11 +159,42 @@ class JWS extends JWT
|
||||
}
|
||||
|
||||
$decodedSignature = $this->encoder->decode($this->getEncodedSignature());
|
||||
$signinInput = $this->generateSigninInput();
|
||||
$signinInput = $this->getSigninInput();
|
||||
|
||||
return $this->getSigner()->verify($key, $decodedSignature, $signinInput);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the original token signin input if it exists, otherwise generate the
|
||||
* signin input for the current JWS
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getSigninInput()
|
||||
{
|
||||
$parts = explode('.', $this->originalToken);
|
||||
|
||||
if (count($parts) >= 2) {
|
||||
return sprintf('%s.%s', $parts[0], $parts[1]);
|
||||
}
|
||||
|
||||
return $this->generateSigninInput();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the original base64 encoded token.
|
||||
*
|
||||
* @param string $originalToken
|
||||
*
|
||||
* @return JWS
|
||||
*/
|
||||
private function setOriginalToken($originalToken)
|
||||
{
|
||||
$this->originalToken = $originalToken;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the base64 encoded signature.
|
||||
*
|
||||
@@ -161,13 +208,14 @@ class JWS extends JWT
|
||||
/**
|
||||
* Sets the base64 encoded signature.
|
||||
*
|
||||
* @param string $encodedSignature
|
||||
* @param string $encodedSignature
|
||||
*
|
||||
* @return JWS
|
||||
*/
|
||||
public function setEncodedSignature($encodedSignature)
|
||||
{
|
||||
$this->encodedSignature = $encodedSignature;
|
||||
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -175,6 +223,7 @@ class JWS extends JWT
|
||||
* Returns the signer responsible to encrypting / decrypting this JWS.
|
||||
*
|
||||
* @return SignerInterface
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
protected function getSigner()
|
||||
|
9
vendor/namshi/jose/src/Namshi/JOSE/JWT.php
vendored
9
vendor/namshi/jose/src/Namshi/JOSE/JWT.php
vendored
@@ -10,7 +10,6 @@ use Namshi\JOSE\Base64\Encoder;
|
||||
*/
|
||||
class JWT
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@@ -27,7 +26,7 @@ class JWT
|
||||
protected $encoder;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $payload
|
||||
* @param array $header
|
||||
@@ -56,10 +55,10 @@ class JWT
|
||||
*/
|
||||
public function generateSigninInput()
|
||||
{
|
||||
$base64payload = $this->encoder->encode(json_encode($this->getPayload()));
|
||||
$base64header = $this->encoder->encode(json_encode($this->getHeader()));
|
||||
$base64payload = $this->encoder->encode(json_encode($this->getPayload(), JSON_UNESCAPED_SLASHES));
|
||||
$base64header = $this->encoder->encode(json_encode($this->getHeader(), JSON_UNESCAPED_SLASHES));
|
||||
|
||||
return sprintf("%s.%s", $base64header, $base64payload);
|
||||
return sprintf('%s.%s', $base64header, $base64payload);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -2,16 +2,22 @@
|
||||
|
||||
namespace Namshi\JOSE\Signer\OpenSSL;
|
||||
|
||||
use \File_ASN1;
|
||||
use phpseclib\File\ASN1;
|
||||
|
||||
/**
|
||||
* Class responsible to sign inputs with the a ECDSA algorithm, after hashing it.
|
||||
*/
|
||||
abstract class ECDSA extends PublicKey
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '7.0.0-dev') >= 0) {
|
||||
throw new \InvalidArgumentException("phpseclib 1.0.0(LTS), even the latest 2.0.0, doesn't support PHP7 yet");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function supportsKey($key)
|
||||
{
|
||||
@@ -26,8 +32,8 @@ abstract class ECDSA extends PublicKey
|
||||
'5.6' => '5.6.0',
|
||||
);
|
||||
|
||||
if (isset($minVersions[PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION]) &&
|
||||
version_compare(PHP_VERSION, $minVersions[PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION], '<')) {
|
||||
if (isset($minVersions[PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION]) &&
|
||||
version_compare(PHP_VERSION, $minVersions[PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION], '<')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -37,9 +43,9 @@ abstract class ECDSA extends PublicKey
|
||||
return false;
|
||||
}
|
||||
$publicKey = trim($matches[1]);
|
||||
$asn1 = new File_ASN1();
|
||||
$asn1 = new ASN1();
|
||||
|
||||
/**
|
||||
/*
|
||||
* http://tools.ietf.org/html/rfc3279#section-2.2.3
|
||||
* AlgorithmIdentifier ::= SEQUENCE {
|
||||
* algorithm OBJECT IDENTIFIER,
|
||||
@@ -51,18 +57,18 @@ abstract class ECDSA extends PublicKey
|
||||
*
|
||||
*/
|
||||
$asnAlgorithmIdentifier = array(
|
||||
'type' => FILE_ASN1_TYPE_SEQUENCE,
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
'children' => array(
|
||||
'ansi-X9-62' => array(
|
||||
'type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER,
|
||||
'type' => ASN1::TYPE_OBJECT_IDENTIFIER,
|
||||
),
|
||||
'id-ecSigType' => array(
|
||||
'type' => FILE_ASN1_TYPE_OBJECT_IDENTIFIER,
|
||||
'type' => ASN1::TYPE_OBJECT_IDENTIFIER,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
/*
|
||||
* http://tools.ietf.org/html/rfc5280#section-4.1
|
||||
* SubjectPublicKeyInfo ::= SEQUENCE {
|
||||
* algorithm AlgorithmIdentifier,
|
||||
@@ -70,11 +76,11 @@ abstract class ECDSA extends PublicKey
|
||||
* }
|
||||
*/
|
||||
$asnSubjectPublicKeyInfo = array(
|
||||
'type' => FILE_ASN1_TYPE_SEQUENCE,
|
||||
'type' => ASN1::TYPE_SEQUENCE,
|
||||
'children' => array(
|
||||
'algorithm' => $asnAlgorithmIdentifier,
|
||||
'subjectPublicKey' => array(
|
||||
'type' => FILE_ASN1_TYPE_BIT_STRING,
|
||||
'type' => ASN1::TYPE_BIT_STRING,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -86,7 +92,7 @@ abstract class ECDSA extends PublicKey
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getSupportedPrivateKeyType()
|
||||
{
|
||||
|
@@ -7,7 +7,6 @@ namespace Namshi\JOSE\Signer\OpenSSL;
|
||||
*/
|
||||
class ES256 extends ECDSA
|
||||
{
|
||||
|
||||
public function getHashingAlgorithm()
|
||||
{
|
||||
return version_compare(phpversion(), '5.4.8', '<') ? 'SHA256' : OPENSSL_ALGO_SHA256;
|
||||
@@ -17,5 +16,4 @@ class ES256 extends ECDSA
|
||||
{
|
||||
return '1.2.840.10045.3.1.7';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ namespace Namshi\JOSE\Signer\OpenSSL;
|
||||
*/
|
||||
class ES384 extends ECDSA
|
||||
{
|
||||
|
||||
public function getHashingAlgorithm()
|
||||
{
|
||||
return version_compare(phpversion(), '5.4.8', '<') ? 'SHA384' : OPENSSL_ALGO_SHA384;
|
||||
@@ -17,5 +16,4 @@ class ES384 extends ECDSA
|
||||
{
|
||||
return '1.3.132.0.34';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ namespace Namshi\JOSE\Signer\OpenSSL;
|
||||
*/
|
||||
class ES512 extends ECDSA
|
||||
{
|
||||
|
||||
public function getHashingAlgorithm()
|
||||
{
|
||||
return version_compare(phpversion(), '5.4.8', '<') ? 'SHA512' : OPENSSL_ALGO_SHA512;
|
||||
@@ -17,5 +16,4 @@ class ES512 extends ECDSA
|
||||
{
|
||||
return '1.3.132.0.35';
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,65 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Namshi\JOSE\Signer\OpenSSL;
|
||||
|
||||
use Namshi\JOSE\Signer\SignerInterface;
|
||||
|
||||
/**
|
||||
* This class is the base of all HMAC Signers
|
||||
* This class is the base of all HMAC Signers.
|
||||
*/
|
||||
abstract class HMAC implements SignerInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function sign($input, $key)
|
||||
{
|
||||
return hash_hmac($this->getHashingAlgorithm(), $input, $key, true);
|
||||
return hash_hmac($this->getHashingAlgorithm(), $input, (string) $key, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* To prevent timing attacks we are using PHP 5.6 native function hash_equals,
|
||||
* in case of PHP < 5.6 a timing safe equals comparison function
|
||||
* in case of PHP < 5.6 a timing safe equals comparison function.
|
||||
*
|
||||
* more info here:
|
||||
* http://blog.ircmaxell.com/2014/11/its-all-about-time.
|
||||
* http://blog.ircmaxell.com/2014/11/its-all-about-time.html
|
||||
*
|
||||
*
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function verify($key, $signature, $input)
|
||||
{
|
||||
$signedInput = $this->sign($input, $key);
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.6.0', '>=')) {
|
||||
return hash_equals($signature, $signedInput);
|
||||
}
|
||||
|
||||
return $this->timingSafeEquals($signature, $signedInput);
|
||||
return $this->timingSafeEquals($signedInput, $signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* A timing safe equals comparison
|
||||
* A timing safe equals comparison.
|
||||
*
|
||||
* @param string $signature the internal signature to be checked
|
||||
* @param string $signature the internal signature to be checked
|
||||
* @param string $signedInput The signed input submitted value
|
||||
*
|
||||
* @return boolean true if the two strings are identical.
|
||||
* @return bool true if the two strings are identical.
|
||||
*/
|
||||
public function timingSafeEquals($signature, $signedInput) {
|
||||
$signatureLength = strlen($signature);
|
||||
$signedInputLength = strlen($signedInput);
|
||||
$result = 0;
|
||||
|
||||
if ($signedInputLength != $signatureLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $signedInputLength; $i++) {
|
||||
$result |= (ord($signature[$i]) ^ ord($signedInput[$i]));
|
||||
}
|
||||
|
||||
return $result === 0;
|
||||
public function timingSafeEquals($known, $input)
|
||||
{
|
||||
return hash_equals($known, $input);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,15 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Namshi\JOSE\Signer\OpenSSL;
|
||||
|
||||
use Namshi\JOSE\Signer\SignerInterface;
|
||||
|
||||
/**
|
||||
* None Signer
|
||||
* None Signer.
|
||||
*/
|
||||
class None implements SignerInterface
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function sign($input, $key)
|
||||
{
|
||||
@@ -17,7 +18,7 @@ class None implements SignerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function verify($key, $signature, $input)
|
||||
{
|
||||
|
@@ -4,15 +4,15 @@ namespace Namshi\JOSE\Signer\OpenSSL;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Namshi\JOSE\Signer\SignerInterface;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Class responsible to sign inputs with the a public key algorithm, after hashing it.
|
||||
*/
|
||||
abstract class PublicKey implements SignerInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function sign($input, $key, $password = null)
|
||||
{
|
||||
@@ -28,7 +28,7 @@ abstract class PublicKey implements SignerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function verify($key, $signature, $input)
|
||||
{
|
||||
@@ -37,28 +37,42 @@ abstract class PublicKey implements SignerInterface
|
||||
throw new InvalidArgumentException('Invalid key supplied.');
|
||||
}
|
||||
|
||||
return (bool) openssl_verify($input, $signature, $keyResource, $this->getHashingAlgorithm());
|
||||
$result = openssl_verify($input, $signature, $keyResource, $this->getHashingAlgorithm());
|
||||
|
||||
if ($result === -1) {
|
||||
throw new RuntimeException('Unknown error during verification.');
|
||||
}
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string representation of a key into an OpenSSL resource
|
||||
* Converts a string representation of a key into an OpenSSL resource.
|
||||
*
|
||||
* @param string|resource $key
|
||||
* @param string $password
|
||||
*
|
||||
* @return resource OpenSSL key resource
|
||||
*/
|
||||
protected function getKeyResource($key, $password = null) {
|
||||
protected function getKeyResource($key, $password = null)
|
||||
{
|
||||
if (is_resource($key)) {
|
||||
return $key;
|
||||
}
|
||||
return openssl_pkey_get_public($key) ? : openssl_pkey_get_private($key, $password);
|
||||
|
||||
$resource = openssl_pkey_get_public($key) ?: openssl_pkey_get_private($key, $password);
|
||||
if ($resource === false) {
|
||||
throw new RuntimeException('Could not read key resource: ' . openssl_error_string());
|
||||
}
|
||||
return $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the key is supported by this signer.
|
||||
*
|
||||
* @param resource $key Public or private key
|
||||
* @return boolean
|
||||
* @param resource $key Public or private key
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function supportsKey($key)
|
||||
{
|
||||
|
@@ -7,13 +7,11 @@ namespace Namshi\JOSE\Signer\OpenSSL;
|
||||
*/
|
||||
abstract class RSA extends PublicKey
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getSupportedPrivateKeyType()
|
||||
{
|
||||
return defined('OPENSSL_KEYTYPE_RSA') ? OPENSSL_KEYTYPE_RSA : false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,7 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Namshi\JOSE\Signer\SecLib;
|
||||
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Namshi\JOSE\Signer\SignerInterface;
|
||||
|
||||
@@ -12,7 +10,7 @@ abstract class PublicKey implements SignerInterface
|
||||
protected $encryptionAlgorithm;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function sign($input, $key, $password = null)
|
||||
{
|
||||
@@ -28,7 +26,7 @@ abstract class PublicKey implements SignerInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function verify($key, $signature, $input)
|
||||
{
|
||||
|
@@ -1,12 +1,11 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Namshi\JOSE\Signer\SecLib;
|
||||
|
||||
|
||||
class RS256 extends RSA
|
||||
{
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->encryptionAlgorithm->setHash('sha256');
|
||||
$this->encryptionAlgorithm->setMGFHash('sha256');
|
||||
|
@@ -1,12 +1,11 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Namshi\JOSE\Signer\SecLib;
|
||||
|
||||
|
||||
class RS384 extends RSA
|
||||
{
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->encryptionAlgorithm->setHash('sha384');
|
||||
$this->encryptionAlgorithm->setMGFHash('sha384');
|
||||
|
@@ -1,12 +1,11 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Namshi\JOSE\Signer\SecLib;
|
||||
|
||||
|
||||
class RS512 extends RSA
|
||||
{
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->encryptionAlgorithm->setHash('sha512');
|
||||
$this->encryptionAlgorithm->setMGFHash('sha512');
|
||||
|
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Namshi\JOSE\Signer\SecLib;
|
||||
|
||||
use phpseclib\Crypt\RSA as CryptRSA;
|
||||
|
||||
class RSA extends PublicKey
|
||||
{
|
||||
public function __construct() {
|
||||
$this->encryptionAlgorithm = new \Crypt_RSA();
|
||||
public function __construct()
|
||||
{
|
||||
$this->encryptionAlgorithm = new CryptRSA();
|
||||
}
|
||||
}
|
||||
|
@@ -7,8 +7,9 @@ interface SignerInterface
|
||||
/**
|
||||
* Signs the $input with the $key, after hashing it.
|
||||
*
|
||||
* @param string $input
|
||||
* @param resource|string $key
|
||||
* @param string $input
|
||||
* @param resource|string $key
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function sign($input, $key);
|
||||
@@ -17,10 +18,11 @@ interface SignerInterface
|
||||
* Verifies that the input correspond to the $signature decrypted with the
|
||||
* given public $key.
|
||||
*
|
||||
* @param resource|string $key
|
||||
* @param string $signature
|
||||
* @param string $input
|
||||
* @return boolean
|
||||
* @param resource|string $key
|
||||
* @param string $signature
|
||||
* @param string $input
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function verify($key, $signature, $input);
|
||||
}
|
||||
|
29
vendor/namshi/jose/src/Namshi/JOSE/SimpleJWS.php
vendored
29
vendor/namshi/jose/src/Namshi/JOSE/SimpleJWS.php
vendored
@@ -8,32 +8,34 @@ namespace Namshi\JOSE;
|
||||
class SimpleJWS extends JWS
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $header An associative array of headers. The value can be any type accepted by json_encode or a JSON serializable object
|
||||
*
|
||||
* @see http://php.net/manual/en/function.json-encode.php
|
||||
* @see http://php.net/manual/en/jsonserializable.jsonserialize.php
|
||||
* @see https://tools.ietf.org/html/draft-ietf-jose-json-web-signature-41#section-4
|
||||
* }
|
||||
*/
|
||||
public function __construct($header = array())
|
||||
public function __construct($header = array(), $encryptionEngine = 'OpenSSL')
|
||||
{
|
||||
if (!isset($header['typ'])) {
|
||||
$header['typ'] = 'JWS';
|
||||
}
|
||||
parent::__construct($header);
|
||||
parent::__construct($header, $encryptionEngine);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the payload of the current JWS with an issued at value in the 'iat' property.
|
||||
*
|
||||
* @param array $payload
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPayload(array $payload)
|
||||
{
|
||||
if (!isset($payload['iat'])) {
|
||||
$now = new \DateTime('now');
|
||||
$payload['iat'] = $now->format('U');
|
||||
$payload['iat'] = time();
|
||||
}
|
||||
|
||||
return parent::setPayload($payload);
|
||||
@@ -44,28 +46,35 @@ class SimpleJWS extends JWS
|
||||
* and the token is not expired.
|
||||
*
|
||||
* @param resource|string $key
|
||||
* @param string $algo The algorithms this JWS should be signed with. Use it if you want to restrict which algorithms you want to allow to be validated.
|
||||
* @param string $algo The algorithms this JWS should be signed with. Use it if you want to restrict which algorithms you want to allow to be validated.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($key, $algo = null)
|
||||
{
|
||||
return $this->verify($key, $algo) && ! $this->isExpired();
|
||||
return $this->verify($key, $algo) && !$this->isExpired();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the token is expired based on the 'exp' value.
|
||||
*it.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isExpired()
|
||||
public function isExpired()
|
||||
{
|
||||
$payload = $this->getPayload();
|
||||
|
||||
if (isset($payload['exp']) && is_numeric($payload['exp'])) {
|
||||
if (isset($payload['exp'])) {
|
||||
$now = new \DateTime('now');
|
||||
|
||||
return ($now->format('U') - $payload['exp']) > 0;
|
||||
if (is_int($payload['exp'])) {
|
||||
return ($now->getTimestamp() - $payload['exp']) > 0;
|
||||
}
|
||||
|
||||
if (is_numeric($payload['exp'])) {
|
||||
return ($now->format('U') - $payload['exp']) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@@ -8,7 +8,7 @@ use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
/**
|
||||
* BC test for base64 url-safe fix
|
||||
* Test that tokens generated the old way (non url-safe) will work with url-safe base64 decoding
|
||||
* Test that tokens generated the old way (non url-safe) will work with url-safe base64 decoding.
|
||||
*/
|
||||
class BCJWSTest extends TestCase
|
||||
{
|
||||
@@ -17,22 +17,21 @@ class BCJWSTest extends TestCase
|
||||
public function testTestBC()
|
||||
{
|
||||
$data = array(
|
||||
array("order_nr" => "ae123123"),
|
||||
array("username" => "asdasdasd"),
|
||||
array("anything" => "!@#$%^&*()_+")
|
||||
array('order_nr' => 'ae123123'),
|
||||
array('username' => 'asdasdasd'),
|
||||
array('anything' => '!@#$%^&*()_+'),
|
||||
);
|
||||
|
||||
foreach ($data as $payload) {
|
||||
$jwsOld = new JWS(array("alg" => "RS256"));
|
||||
$jwsOld = new JWS(array('alg' => 'RS256'));
|
||||
$jwsOld->setEncoder(new Base64Encoder());
|
||||
$jwsOld->setPayload($payload);
|
||||
$jwsOld->sign(openssl_pkey_get_private(SSL_KEYS_PATH . "private.key", self::SSL_KEY_PASSPHRASE));
|
||||
$jwsOld->sign(openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE));
|
||||
|
||||
$t = $jwsOld->getTokenString();
|
||||
|
||||
$jwsNew = JWS::load($t);
|
||||
$this->assertTrue($jwsNew->verify(openssl_pkey_get_public(SSL_KEYS_PATH . "public.key")));
|
||||
$this->assertTrue($jwsNew->verify(openssl_pkey_get_public(SSL_KEYS_PATH.'public.key')));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -2,10 +2,12 @@
|
||||
|
||||
namespace Namshi\JOSE\Test;
|
||||
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
use Namshi\JOSE\JWS;
|
||||
use DateTime;
|
||||
use Namshi\JOSE\JWS;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Namshi\JOSE\Signer\OpenSSL\HS256;
|
||||
use Namshi\JOSE\Base64\Base64UrlSafeEncoder;
|
||||
|
||||
class JWSTest extends TestCase
|
||||
{
|
||||
@@ -13,11 +15,11 @@ class JWSTest extends TestCase
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b'
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
);
|
||||
$this->jws = new JWS(array('alg' => 'RS256'));
|
||||
$this->jws = new JWS(array('alg' => 'RS256'));
|
||||
$this->jws->setPayload($data);
|
||||
}
|
||||
|
||||
@@ -26,37 +28,37 @@ class JWSTest extends TestCase
|
||||
*/
|
||||
public function testLoadingUnsecureJwsWithNoneAlgo()
|
||||
{
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U')
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U'),
|
||||
);
|
||||
$this->jws = new JWS(array('alg' => 'None'));
|
||||
$this->jws = new JWS(array('alg' => 'None'));
|
||||
$this->jws->setPayload($data);
|
||||
$this->jws->sign('111');
|
||||
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$this->assertFalse($jws->verify('111'));
|
||||
|
||||
$payload = $jws->getPayload();
|
||||
$this->assertEquals('b', $payload['a']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testLoadingUnsecureJwsWithLowercaseNone()
|
||||
{
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U')
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U'),
|
||||
);
|
||||
$this->jws = new JWS(array('alg' => 'none'));
|
||||
$this->jws = new JWS(array('alg' => 'none'));
|
||||
$this->jws->setPayload($data);
|
||||
$this->jws->sign('111');
|
||||
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$this->assertFalse($jws->verify('111'));
|
||||
|
||||
$payload = $jws->getPayload();
|
||||
@@ -65,16 +67,16 @@ class JWSTest extends TestCase
|
||||
|
||||
public function testAllowingUnsecureJws()
|
||||
{
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U')
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U'),
|
||||
);
|
||||
$this->jws = new JWS(array('alg' => 'None'));
|
||||
$this->jws = new JWS(array('alg' => 'None'));
|
||||
$this->jws->setPayload($data);
|
||||
$this->jws->sign('111');
|
||||
|
||||
$jws = JWS::load($this->jws->getTokenString(), true);
|
||||
$jws = JWS::load($this->jws->getTokenString(), true);
|
||||
$this->assertTrue($jws->verify('111'));
|
||||
|
||||
$payload = $jws->getPayload();
|
||||
@@ -83,35 +85,35 @@ class JWSTest extends TestCase
|
||||
|
||||
public function testRestrictingTheAlgorithmsKo()
|
||||
{
|
||||
$this->jws = new JWS(array('alg' => 'HS256'));
|
||||
$this->jws = new JWS(array('alg' => 'HS256'));
|
||||
$this->jws->sign('12345');
|
||||
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$this->assertFalse($jws->verify('12345', 'RS256'));
|
||||
}
|
||||
|
||||
public function testRestrictingTheAlgorithmsOk()
|
||||
{
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U')
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U'),
|
||||
);
|
||||
$this->jws = new JWS(array('alg' => 'HS256'));
|
||||
$this->jws = new JWS(array('alg' => 'HS256'));
|
||||
$this->jws->setPayload($data);
|
||||
$this->jws->sign('123');
|
||||
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$this->assertTrue($jws->verify('123', 'HS256'));
|
||||
}
|
||||
|
||||
public function testVerificationRS256()
|
||||
{
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH . "private.key", self::SSL_KEY_PASSPHRASE);
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE);
|
||||
$this->jws->sign($privateKey);
|
||||
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH . "public.key");
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
|
||||
$this->assertTrue($jws->verify($public_key));
|
||||
|
||||
$payload = $jws->getPayload();
|
||||
@@ -120,11 +122,11 @@ class JWSTest extends TestCase
|
||||
|
||||
public function testVerificationRS256KeyAsString()
|
||||
{
|
||||
$privateKey = file_get_contents(TEST_DIR . "/private.key");//, self::SSL_KEY_PASSPHRASE);
|
||||
$privateKey = file_get_contents(TEST_DIR.'/private.key');
|
||||
$this->jws->sign($privateKey, self::SSL_KEY_PASSPHRASE);
|
||||
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH . "public.key");
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
|
||||
$this->assertTrue($jws->verify($public_key));
|
||||
|
||||
$payload = $jws->getPayload();
|
||||
@@ -147,7 +149,7 @@ class JWSTest extends TestCase
|
||||
|
||||
public function testVerificationThatTheJWSIsSigned()
|
||||
{
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH . "private.key", self::SSL_KEY_PASSPHRASE);
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE);
|
||||
$this->jws->sign($privateKey);
|
||||
$this->assertTrue($this->jws->isSigned());
|
||||
}
|
||||
@@ -162,11 +164,11 @@ class JWSTest extends TestCase
|
||||
*/
|
||||
public function testWrongVerificationRS256()
|
||||
{
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH . "private.key", self::SSL_KEY_PASSPHRASE);
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE);
|
||||
$this->jws->sign($privateKey);
|
||||
|
||||
$jws = JWS::load('eyJhbGciOiJ0ZXN0In0=.eyJhbGciOiJ0ZXN0In0=.eyJhbGciOiJ0ZXN0In0=');
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH . "public.key");
|
||||
$jws = JWS::load('eyJhbGciOiJ0ZXN0In0=.eyJhbGciOiJ0ZXN0In0=.eyJhbGciOiJ0ZXN0In0=');
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
|
||||
$this->assertFalse($jws->verify($public_key));
|
||||
}
|
||||
|
||||
@@ -189,31 +191,29 @@ class JWSTest extends TestCase
|
||||
public function testSignAndVerifyWithFalsePublicKey()
|
||||
{
|
||||
$public_key = false;
|
||||
$jwsHMAC = new JWS(array('alg' => 'HS256'));
|
||||
$jwsHMAC = new JWS(array('alg' => 'HS256'));
|
||||
|
||||
$jwsHMAC->sign(false);
|
||||
$jws = JWS::load($jwsHMAC->getTokenString());
|
||||
|
||||
$this->assertFalse($jws->verify($public_key));
|
||||
|
||||
}
|
||||
|
||||
public function testSignAndVerifyWithEmptyStringPublicKey()
|
||||
{
|
||||
$public_key = false;
|
||||
$jwsHMAC = new JWS(array('alg' => 'HS256'));
|
||||
$jwsHMAC = new JWS(array('alg' => 'HS256'));
|
||||
|
||||
$jwsHMAC->sign('');
|
||||
$jws = JWS::load($jwsHMAC->getTokenString());
|
||||
|
||||
$this->assertFalse($jws->verify($public_key));
|
||||
|
||||
}
|
||||
|
||||
public function testLoadingWithAnyOrderOfHeaders()
|
||||
{
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH . "private.key", self::SSL_KEY_PASSPHRASE);
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH . "public.key");
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE);
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
|
||||
|
||||
$this->jws = new JWS(array('alg' => 'RS256', 'custom' => '1'));
|
||||
|
||||
@@ -231,14 +231,18 @@ class JWSTest extends TestCase
|
||||
|
||||
public function testSignAndVerifyWithSecLib()
|
||||
{
|
||||
$jwsRSA = new JWS(array('alg' => 'RS256'), 'SecLib');
|
||||
$data = array('a' => 'b',);
|
||||
if (version_compare(PHP_VERSION, '7.0.0-dev') >= 0) {
|
||||
$this->setExpectedException('InvalidArgumentException');
|
||||
}
|
||||
|
||||
$jwsRSA = new JWS(array('alg' => 'RS256'), 'SecLib');
|
||||
$data = array('a' => 'b');
|
||||
$jwsRSA->setPayload($data);
|
||||
|
||||
$jwsRSA->sign(file_get_contents(SSL_KEYS_PATH . "private.key"), 'tests');
|
||||
$jwsRSA->sign(file_get_contents(SSL_KEYS_PATH.'private.key'), 'tests');
|
||||
$jws = JWS::load($jwsRSA->getTokenString(), false, null, 'SecLib');
|
||||
|
||||
$this->assertTrue($jws->verify(file_get_contents(SSL_KEYS_PATH . "public.key", 'RS256')));
|
||||
$this->assertTrue($jws->verify(file_get_contents(SSL_KEYS_PATH.'public.key', 'RS256')));
|
||||
}
|
||||
|
||||
public function testConstructionFromHeader()
|
||||
@@ -255,14 +259,36 @@ class JWSTest extends TestCase
|
||||
$header['test'] = true;
|
||||
$this->jws->setHeader($header);
|
||||
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH . "private.key", self::SSL_KEY_PASSPHRASE);
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE);
|
||||
$this->jws->sign($privateKey);
|
||||
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH . "public.key");
|
||||
$jws = JWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
|
||||
$headerFromSig = $jws->getHeader();
|
||||
|
||||
$this->assertSame($headerFromSig['test'], true);
|
||||
$this->assertTrue($jws->verify($public_key));
|
||||
}
|
||||
|
||||
public function testVerificationWithJsonThatContainsWhitespace()
|
||||
{
|
||||
$header = '{
|
||||
"alg": "HS256"
|
||||
}';
|
||||
|
||||
$payload = '{
|
||||
"a": "b"
|
||||
}';
|
||||
|
||||
$encoder = new Base64UrlSafeEncoder();
|
||||
$signer = new HS256();
|
||||
|
||||
$token = sprintf('%s.%s', $encoder->encode($header), $encoder->encode($payload));
|
||||
$signature = $encoder->encode($signer->sign($token, '123'));
|
||||
$jwsToken = sprintf('%s.%s', $token, $signature);
|
||||
|
||||
$jws = JWS::load($jwsToken);
|
||||
|
||||
$this->assertTrue($jws->verify('123'));
|
||||
}
|
||||
}
|
||||
|
@@ -3,8 +3,8 @@
|
||||
namespace Namshi\JOSE\Test;
|
||||
|
||||
use Namshi\JOSE\Base64\Base64UrlSafeEncoder;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
use Namshi\JOSE\JWT;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class JWTTest extends TestCase
|
||||
{
|
||||
@@ -15,7 +15,17 @@ class JWTTest extends TestCase
|
||||
$jwt = new JWT($payload, $header);
|
||||
$encoder = new Base64UrlSafeEncoder();
|
||||
|
||||
$this->assertEquals(sprintf("%s.%s", $encoder->encode(json_encode($header)), $encoder->encode(json_encode($payload))), $jwt->generateSigninInput());
|
||||
$this->assertEquals(sprintf('%s.%s', $encoder->encode(json_encode($header)), $encoder->encode(json_encode($payload))), $jwt->generateSigninInput());
|
||||
}
|
||||
|
||||
public function testGenerationOfTheSigninInputCanHandleSlashes()
|
||||
{
|
||||
$encoder = new Base64UrlSafeEncoder();
|
||||
$json_string = '{"a":"/b/"}';
|
||||
$encoded_json_string = $encoder->encode($json_string);
|
||||
$jwt = new JWT(json_decode($json_string, true), json_decode($json_string, true));
|
||||
|
||||
$this->assertEquals(sprintf('%s.%s', $encoded_json_string, $encoded_json_string), $jwt->generateSigninInput());
|
||||
}
|
||||
|
||||
public function testPayload()
|
||||
|
@@ -3,20 +3,20 @@
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use Namshi\JOSE\Signer\OpenSSL\ES256;
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
use Namshi\JOSE\Test\Signer\SecLib\SecLibTestCase;
|
||||
|
||||
class ES256Test extends TestCase
|
||||
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;
|
||||
$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()
|
||||
@@ -32,7 +32,7 @@ class ES256Test extends TestCase
|
||||
*/
|
||||
public function testWrongKeyCurve()
|
||||
{
|
||||
$privateKey512 = openssl_pkey_get_private(SSL_KEYS_PATH . "private.es512.key");
|
||||
$privateKey512 = openssl_pkey_get_private(SSL_KEYS_PATH.'private.es512.key');
|
||||
$this->signer->sign('aaa', $privateKey512);
|
||||
}
|
||||
|
||||
@@ -40,5 +40,4 @@ class ES256Test extends TestCase
|
||||
{
|
||||
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,20 +3,20 @@
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use Namshi\JOSE\Signer\OpenSSL\ES384;
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
use Namshi\JOSE\Test\Signer\SecLib\SecLibTestCase;
|
||||
|
||||
class ES384Test extends TestCase
|
||||
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;
|
||||
$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()
|
||||
@@ -30,5 +30,4 @@ class ES384Test extends TestCase
|
||||
{
|
||||
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,20 +3,20 @@
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use Namshi\JOSE\Signer\OpenSSL\ES512;
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
use Namshi\JOSE\Test\Signer\SecLib\SecLibTestCase;
|
||||
|
||||
class ES512Test extends TestCase
|
||||
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;
|
||||
$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()
|
||||
@@ -30,5 +30,4 @@ class ES512Test extends TestCase
|
||||
{
|
||||
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -3,13 +3,13 @@
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use Namshi\JOSE\Signer\OpenSSL\HS256;
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class HS256Test extends TestCase
|
||||
{
|
||||
public function testSigningAndVerificationWorkProperly()
|
||||
{
|
||||
$signer = new HS256;
|
||||
$signer = new HS256();
|
||||
$signature = $signer->sign('aaa', 'foo');
|
||||
$this->assertEquals($signature, base64_decode('P2Pb8e2Ja4P4YnTZ3EF002RKpUpOnfjIy0uLNT0R1J0='));
|
||||
|
||||
|
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
use Namshi\JOSE\Signer\OpenSSL\HS384;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class HS384Test extends TestCase
|
||||
{
|
||||
public function testSigningAndVerificationWorkProperly()
|
||||
{
|
||||
$signer = new HS384;
|
||||
$signer = new HS384();
|
||||
$signature = $signer->sign('aaa', 'foo');
|
||||
|
||||
$this->assertEquals($signature, base64_decode('W6Cd7qZknNYIXOxTrpEWFFwfuX0e2j59hTH4kVFh5o+9rcnfNtphLg4V8YXfkXGF'));
|
||||
|
@@ -2,14 +2,14 @@
|
||||
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
use Namshi\JOSE\Signer\OpenSSL\HS512;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class HS512Test extends TestCase
|
||||
{
|
||||
public function testSigningAndVerificationWorkProperly()
|
||||
{
|
||||
$signer = new HS512;
|
||||
$signer = new HS512();
|
||||
$signature = $signer->sign('aaa', 'foo');
|
||||
|
||||
$this->assertEquals($signature, base64_decode('GysqRX8GoD6BCTrI5sJy1ptn9A7vbDlvFOnaAxO/t+BD8KVrVAUVcHMxgM68ZNxnUNkb7kNSq3YxkCV4pBvTjg=='));
|
||||
|
@@ -2,20 +2,22 @@
|
||||
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
use Namshi\JOSE\Signer\OpenSSL\RS256;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class PublicKeyTest extends 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->signer = new RS256;
|
||||
$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()
|
||||
@@ -38,4 +40,28 @@ class PublicKeyTest extends TestCase
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
@@ -2,21 +2,21 @@
|
||||
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
use Namshi\JOSE\Signer\OpenSSL\None;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class noneTest extends TestCase
|
||||
class NoneTest extends TestCase
|
||||
{
|
||||
public function testVerificationWorksProperly()
|
||||
{
|
||||
$signer = new none;
|
||||
$signer = new none();
|
||||
|
||||
$this->assertTrue($signer->verify('bar', '', 'aaa'));
|
||||
}
|
||||
|
||||
public function testSigningWorksProperly()
|
||||
{
|
||||
$signer = new none;
|
||||
$signer = new none();
|
||||
$signature = $signer->sign('aaa', 'foo');
|
||||
|
||||
$this->assertTrue($signature === '');
|
||||
|
@@ -2,16 +2,16 @@
|
||||
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
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;
|
||||
$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()
|
||||
|
@@ -2,16 +2,16 @@
|
||||
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
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;
|
||||
$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()
|
||||
|
@@ -2,16 +2,16 @@
|
||||
|
||||
namespace Namshi\JOSE\Test\OpenSSL\Signer;
|
||||
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
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;
|
||||
$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()
|
||||
|
@@ -1,17 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Namshi\JOSE\Test\SecLib\Signer;
|
||||
namespace Namshi\JOSE\Test\Signer\SecLib;
|
||||
|
||||
use Namshi\JOSE\Signer\SecLib\RS256;
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class RS256Test extends TestCase {
|
||||
class RS256TEST extends SecLibTestCase
|
||||
{
|
||||
public function 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();
|
||||
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()
|
||||
@@ -25,5 +27,4 @@ class RS256Test extends TestCase {
|
||||
{
|
||||
$this->assertInternalType('string', $this->signer->sign('aaa', $this->privateKey, $this->password));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,18 +1,19 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Namshi\JOSE\Test\SecLib\Signer;
|
||||
namespace Namshi\JOSE\Test\Signer\SecLib;
|
||||
|
||||
use Namshi\JOSE\Signer\SecLib\RS384;
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class RS384Test extends TestCase {
|
||||
class RS384Test extends SecLibTestCase
|
||||
{
|
||||
public function 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();
|
||||
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()
|
||||
|
@@ -1,18 +1,19 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Namshi\JOSE\Test\SecLib\Signer;
|
||||
namespace Namshi\JOSE\Test\Signer\SecLib;
|
||||
|
||||
use Namshi\JOSE\Signer\SecLib\RS512;
|
||||
use \PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class RS512Test extends TestCase {
|
||||
class RS512Test extends SecLibTestCase
|
||||
{
|
||||
public function 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();
|
||||
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()
|
||||
|
17
vendor/namshi/jose/tests/Namshi/JOSE/Test/Signer/SecLib/SecLibTestCase.php
vendored
Normal file
17
vendor/namshi/jose/tests/Namshi/JOSE/Test/Signer/SecLib/SecLibTestCase.php
vendored
Normal file
@@ -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();
|
||||
}
|
||||
}
|
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Namshi\JOSE\Test;
|
||||
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
use Namshi\JOSE\SimpleJWS;
|
||||
use DateTime;
|
||||
use Namshi\JOSE\SimpleJWS;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class SimpleJWSTest extends TestCase
|
||||
{
|
||||
@@ -12,42 +12,96 @@ class SimpleJWSTest extends TestCase
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U')
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U'),
|
||||
);
|
||||
$this->jws = new SimpleJWS(array('alg' => 'RS256'));
|
||||
$this->jws = new SimpleJWS(array('alg' => 'RS256'));
|
||||
$this->jws->setPayload($data);
|
||||
}
|
||||
|
||||
public function testConstruction()
|
||||
{
|
||||
$this->assertSame($this->jws->getHeader(), array('alg' => 'RS256', 'typ' => 'JWS'));
|
||||
$this->assertRegExp('/^\d+$/', $this->jws->getPayload()['iat'], 'iat property has integer value (from construction)');
|
||||
$this->assertTrue(is_int($this->jws->getPayload()['iat']), 'iat property should be integer value (from construction)');
|
||||
}
|
||||
|
||||
public function testValidationOfAValidSimpleJWS()
|
||||
{
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH . "private.key", self::SSL_KEY_PASSPHRASE);
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE);
|
||||
$this->jws->sign($privateKey);
|
||||
|
||||
$jws = SimpleJWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH . "public.key");
|
||||
$jws = SimpleJWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
|
||||
$this->assertTrue($jws->isValid($public_key, 'RS256'));
|
||||
}
|
||||
|
||||
public function testValidationOfInvalidSimpleJWS()
|
||||
{
|
||||
$date = new DateTime('yesterday');
|
||||
$date = new DateTime('yesterday');
|
||||
$this->jws->setPayload(array(
|
||||
'exp' => $date->format('U')
|
||||
'exp' => $date->format('U'),
|
||||
));
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH . "private.key", self::SSL_KEY_PASSPHRASE);
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE);
|
||||
$this->jws->sign($privateKey);
|
||||
|
||||
$jws = SimpleJWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH . "public.key");
|
||||
$jws = SimpleJWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
|
||||
$this->assertFalse($jws->isValid($public_key, 'RS256'));
|
||||
}
|
||||
|
||||
public function testValidationOfValidSimpleJWSWithStringIat()
|
||||
{
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->format('U'),
|
||||
'iat' => time()
|
||||
);
|
||||
$this->jws->setPayload($data);
|
||||
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE);
|
||||
$this->jws->sign($privateKey);
|
||||
|
||||
$jws = SimpleJWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
|
||||
$this->assertTrue($jws->isValid($public_key, 'RS256'));
|
||||
}
|
||||
|
||||
public function testValidationOfValidSimpleJWSWithExpAsInt()
|
||||
{
|
||||
$date = new DateTime('tomorrow');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->getTimestamp(),
|
||||
'iat' => time()
|
||||
);
|
||||
$this->jws->setPayload($data);
|
||||
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE);
|
||||
$this->jws->sign($privateKey);
|
||||
|
||||
$jws = SimpleJWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
|
||||
$this->assertTrue($jws->isValid($public_key, 'RS256'));
|
||||
}
|
||||
|
||||
public function testValidationOfInvalidSimpleJWSWithExpAsInt()
|
||||
{
|
||||
$date = new DateTime('yesterday');
|
||||
$data = array(
|
||||
'a' => 'b',
|
||||
'exp' => $date->getTimestamp(),
|
||||
'iat' => time()
|
||||
);
|
||||
$this->jws->setPayload($data);
|
||||
|
||||
$privateKey = openssl_pkey_get_private(SSL_KEYS_PATH.'private.key', self::SSL_KEY_PASSPHRASE);
|
||||
$this->jws->sign($privateKey);
|
||||
|
||||
$jws = SimpleJWS::load($this->jws->getTokenString());
|
||||
$public_key = openssl_pkey_get_public(SSL_KEYS_PATH.'public.key');
|
||||
$this->assertFalse($jws->isValid($public_key, 'RS256'));
|
||||
}
|
||||
}
|
||||
|
6
vendor/namshi/jose/tests/bootstrap.php
vendored
6
vendor/namshi/jose/tests/bootstrap.php
vendored
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
$loader = require __DIR__ . '/../vendor/autoload.php';
|
||||
$loader->add("Namshi\\JOSE\\Test", __DIR__);
|
||||
$loader = require __DIR__.'/../vendor/autoload.php';
|
||||
$loader->add('Namshi\\JOSE\\Test', __DIR__);
|
||||
|
||||
define('TEST_DIR', __DIR__);
|
||||
define('SSL_KEYS_PATH', "file://" . TEST_DIR . DIRECTORY_SEPARATOR);
|
||||
define('SSL_KEYS_PATH', 'file://'.TEST_DIR.DIRECTORY_SEPARATOR);
|
||||
|
Reference in New Issue
Block a user