From 421077f45f2cb41aa42d3f9950b3863596a56240 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Thu, 8 Oct 2015 11:15:29 +0200 Subject: [PATCH] Input method implemented --- composer.json | 2 +- lib/JWable.php | 25 +++++++++++++++++++++++++ lib/Loader.php | 21 +++++++++++++-------- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 4a541c80..2cfc0ba2 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "require": { "php": ">=5.6", "lib-openssl": "*", - "spomky-labs/jose-interface": "~2.2.1", + "spomky-labs/jose-interface": "~2.3.0", "spomky-labs/pbkdf2": "~1.0", "mdanter/ecc": "0.3", "spomky-labs/aes-key-wrap": "~2.0", diff --git a/lib/JWable.php b/lib/JWable.php index 34800fd0..61fdea5e 100644 --- a/lib/JWable.php +++ b/lib/JWable.php @@ -21,6 +21,11 @@ trait JWable */ protected $encoded_protected_header = ''; + /** + * @var string + */ + protected $input = null; + /** * @var string */ @@ -49,6 +54,14 @@ public function getEncodedProtectedHeader() return $this->encoded_protected_header; } + /** + * @return string|null + */ + public function getInput() + { + return $this->input; + } + /** * @return string */ @@ -80,6 +93,18 @@ public function getPayload() return $this->payload; } + /** + * @param string $input + * + * @return self + */ + public function setInput($input) + { + $this->input = $input; + + return $this; + } + /** * @param string $encoded_protected_header * diff --git a/lib/Loader.php b/lib/Loader.php index 9625fc19..46c2e2fd 100644 --- a/lib/Loader.php +++ b/lib/Loader.php @@ -59,10 +59,10 @@ public function load($input) $json = Converter::convert($input, JSONSerializationModes::JSON_SERIALIZATION, false); if (is_array($json)) { if (array_key_exists('signatures', $json)) { - return $this->loadSerializedJsonJWS($json); + return $this->loadSerializedJsonJWS($json, $input); } if (array_key_exists('recipients', $json)) { - return $this->loadSerializedJsonJWE($json); + return $this->loadSerializedJsonJWE($json, $input); } } throw new \InvalidArgumentException('Unable to load the input'); @@ -150,11 +150,12 @@ public function verify(JWTInterface $jwt) } /** - * @param array $data + * @param array $data + * @param string $input * * @return \Jose\JWSInterface|\Jose\JWSInterface[] */ - protected function loadSerializedJsonJWS(array $data) + protected function loadSerializedJsonJWS(array $data, $input) { $encoded_payload = isset($data['payload']) ? $data['payload'] : ''; $payload = Base64Url::decode($encoded_payload); @@ -170,7 +171,9 @@ protected function loadSerializedJsonJWS(array $data) } $unprotected_header = isset($signature['header']) ? $signature['header'] : []; - $jws[] = $this->createJWS($encoded_protected_header, $encoded_payload, $protected_header, $unprotected_header, $payload, Base64Url::decode($signature['signature'])); + $result = $this->createJWS($encoded_protected_header, $encoded_payload, $protected_header, $unprotected_header, $payload, Base64Url::decode($signature['signature'])); + $result->setInput($input); + $jws[] = $result; } return count($jws) > 1 ? $jws : current($jws); @@ -281,11 +284,12 @@ public function decryptCEK(JWAInterface $key_encryption_algorithm, ContentEncryp } /** - * @param array $data + * @param array $data + * @param string $input * * @return \Jose\JWEInterface|\Jose\JWEInterface[] */ - protected function loadSerializedJsonJWE(array $data) + protected function loadSerializedJsonJWE(array $data, $input) { $result = []; foreach ($data['recipients'] as $recipient) { @@ -302,7 +306,8 @@ protected function loadSerializedJsonJWE(array $data) ->setTag(array_key_exists('tag', $data) ? Base64Url::decode($data['tag']) : null) ->setProtectedHeader($protected_header) ->setEncodedProtectedHeader($encoded_protected_header) - ->setUnprotectedHeader(array_merge($unprotected_header, $header)); + ->setUnprotectedHeader(array_merge($unprotected_header, $header)) + ->setInput($input); $result[] = $jwe; }