Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

V2.0.x #83

Merged
merged 54 commits into from
Jan 31, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
7a58b62
WIP
Jan 26, 2016
be79950
Bugs fixed
Jan 26, 2016
de999d3
Verifier updated
Jan 26, 2016
0e1d669
Applied fixes from StyleCI
Jan 26, 2016
45cd5b4
Merge pull request #76 from Spomky-Labs/analysis-ze70m4
Spomky Jan 26, 2016
7f25869
Some tests updated
Jan 26, 2016
78a4ce1
Examples updated
Jan 27, 2016
2559486
Merge remote-tracking branch 'origin/v2.0.x' into v2.0.x
Jan 27, 2016
c248378
Some tests fixed
Jan 27, 2016
59a3d44
Some tests fixed
Jan 27, 2016
b06cabe
All tests fixed
Jan 28, 2016
11273c6
Delete HasPayloadConverter.php
Spomky Jan 28, 2016
f488cd4
Update .scrutinizer.yml
Spomky Jan 28, 2016
c41274c
Applied fixes from StyleCI
Jan 28, 2016
29f8a50
Merge pull request #77 from Spomky-Labs/analysis-8jLDnr
Spomky Jan 28, 2016
f68836f
Update Loader.php
Spomky Jan 28, 2016
ce8a641
Delete z
Spomky Jan 28, 2016
359f30b
Scrutinizer Auto-Fixes
scrutinizer-auto-fixer Jan 28, 2016
fd9dbee
Merge pull request #78 from Spomky-Labs/scrutinizer-patch-1
Spomky Jan 28, 2016
92da15e
Update README.md
Spomky Jan 28, 2016
da4f235
Update Loader.php
Spomky Jan 28, 2016
9318b46
Update Encrypter.php
Spomky Jan 28, 2016
44658cb
Update Signature.php
Spomky Jan 28, 2016
7a364a5
Update Signature.php
Spomky Jan 28, 2016
a302c6a
Update README.md
Spomky Jan 28, 2016
8492207
Applied fixes from StyleCI
Jan 28, 2016
15bc11d
Merge pull request #79 from Spomky-Labs/analysis-zGDgvO
Spomky Jan 28, 2016
beb4293
Update phpunit.xml.dist
Spomky Jan 28, 2016
c7c6d18
Update .scrutinizer.yml
Spomky Jan 28, 2016
6644e2f
Code optimization
Jan 28, 2016
1446f5d
Code optimization
Jan 28, 2016
5740fbc
Code optimization
Jan 28, 2016
b316258
Code optimization
Jan 28, 2016
24925ee
Code optimization
Jan 28, 2016
1498022
Code optimization
Jan 28, 2016
dc4bfae
Code optimization
Jan 28, 2016
f44d095
Update Use.md
Spomky Jan 29, 2016
2b2b8e5
Tests added
Jan 29, 2016
21aa402
StringUtil used
Jan 29, 2016
08a44b9
Update HMAC.php
Spomky Jan 29, 2016
c50b734
Applied fixes from StyleCI
Jan 29, 2016
94c9504
Merge pull request #80 from Spomky-Labs/analysis-z3wGL1
Spomky Jan 29, 2016
c407925
Tests added and bugs fixed
Jan 29, 2016
99e97aa
Examples fixed
Jan 29, 2016
b6acc27
Tests added and example updated
Jan 30, 2016
26bd76c
Tests added
Jan 31, 2016
3729e43
Tests added
Jan 31, 2016
03259ab
Tests added
Jan 31, 2016
ec9700b
Tests added
Jan 31, 2016
ae27d3b
Tests added
Jan 31, 2016
9fa7fea
Applied fixes from StyleCI
Jan 31, 2016
8e74ea6
Merge pull request #82 from Spomky-Labs/analysis-zYj29v
Spomky Jan 31, 2016
23a51c0
Bugs fixed
Jan 31, 2016
6e3adab
Bugs fixed
Jan 31, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Code optimization
  • Loading branch information
Florent Morselli committed Jan 28, 2016
commit 24925eec05ac031a64565768670334ff20225fc5
2 changes: 1 addition & 1 deletion src/Decrypter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function decryptUsingKeySet(JWEInterface &$jwe, JWKSetInterface $jwk_set)
if (null !== $cek) {
if (true === $this->decryptPayload($jwe, $cek, $content_encryption_algorithm, $complete_headers)) {
$this->getCheckerManager()->checkJWT($jwe);

return true;
};
}
Expand Down
59 changes: 45 additions & 14 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
use Jose\Object\JWE;
use Jose\Object\JWEInterface;
use Jose\Object\JWS;
use Jose\Object\JWSInterface;
use Jose\Object\Recipient;
use Jose\Object\RecipientInterface;
use Jose\Object\Signature;
use Jose\Object\SignatureInterface;

/**
* Class able to load JWS or JWE.
Expand Down Expand Up @@ -55,31 +57,60 @@ public static function load($input)
private static function loadSerializedJsonJWS(array $data)
{
$jws = new JWS();
if (array_key_exists('payload', $data)) {
$payload = Base64Url::decode($data['payload']);
$json = json_decode($payload, true);
if (null !== $json && !empty($payload)) {
$payload = $json;
}
$jws = $jws->withPayload($payload);
}

self::populatePayload($jws, $data);

foreach ($data['signatures'] as $signature) {
$object = new Signature();
$object = $object->withSignature(Base64Url::decode($signature['signature']));
if (array_key_exists('protected', $signature)) {
$object = $object->withEncodedProtectedHeaders($signature['protected']);
}
if (array_key_exists('header', $signature)) {
$object = $object->withHeaders($signature['header']);
}

self::populateProtectedHeaders($object, $signature);
self::populateHeaders($object, $signature);

$jws = $jws->addSignature($object);
}

return $jws;
}

/**
* @param \Jose\Object\SignatureInterface $signature
* @param array $data
*/
private static function populateProtectedHeaders(SignatureInterface &$signature, array $data)
{
if (array_key_exists('protected', $data)) {
$signature = $signature->withEncodedProtectedHeaders($data['protected']);
}
}

/**
* @param \Jose\Object\SignatureInterface $signature
* @param array $data
*/
private static function populateHeaders(SignatureInterface &$signature, array $data)
{
if (array_key_exists('header', $data)) {
$signature = $signature->withHeaders($data['header']);
}
}

/**
* @param \Jose\Object\JWSInterface $jws
* @param array $data
*/
private static function populatePayload(JWSInterface &$jws, array $data)
{
if (array_key_exists('payload', $data)) {
$payload = Base64Url::decode($data['payload']);
$json = json_decode($payload, true);
if (null !== $json && !empty($payload)) {
$payload = $json;
}
$jws = $jws->withPayload($payload);
}
}

/**
* @param array $data
*
Expand Down
42 changes: 33 additions & 9 deletions src/Object/JWE.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,9 @@ public function toCompactJSON($id)
{
$recipient = $this->getRecipient($id);

if (empty($this->getSharedProtectedHeaders())) {
throw new \InvalidArgumentException('This JWE does not have shared protected headers and cannot be converted into Compact JSON.');
}
if (!empty($this->getSharedHeaders()) || !empty($this->getRecipient($id)->getHeaders())) {
throw new \InvalidArgumentException('This JWE has shared headers or recipient headers and cannot be converted into Compact JSON.');
}
if (!empty($this->getAAD())) {
throw new \InvalidArgumentException('This JWE has AAD and cannot be converted into Compact JSON.');
}
$this->checkHasNoAAD();
$this->checkHasSharedProtectedHeaders();
$this->checkRecipientHasNoHeaders($id);

return sprintf(
'%s.%s.%s.%s.%s',
Expand All @@ -324,6 +318,36 @@ public function toCompactJSON($id)
);
}

/**
*
*/
private function checkHasNoAAD()
{
if (!empty($this->getAAD())) {
throw new \InvalidArgumentException('This JWE has AAD and cannot be converted into Compact JSON.');
}
}

/**
* @param int $id
*/
private function checkRecipientHasNoHeaders($id)
{
if (!empty($this->getSharedHeaders()) || !empty($this->getRecipient($id)->getHeaders())) {
throw new \InvalidArgumentException('This JWE has shared headers or recipient headers and cannot be converted into Compact JSON.');
}
}

/**
*
*/
private function checkHasSharedProtectedHeaders()
{
if (empty($this->getSharedProtectedHeaders())) {
throw new \InvalidArgumentException('This JWE does not have shared protected headers and cannot be converted into Compact JSON.');
}
}

/**
* {@inheritdoc}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function checkJWKSet(JWKSetInterface $jwk_set)

/**
* @param \Jose\Object\JWSInterface $jws
* @param null $detached_payload
* @param null|string $detached_payload
*/
private function checkPayload(JWSInterface $jws, $detached_payload = null)
{
Expand Down