@@ -72,14 +72,14 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | $claim_set = null; |
| 74 | 74 | |
| 75 | - if(!is_null($payload) && $payload->isClaimSet() && $payload instanceof IJWSPayloadClaimSetSpec) { |
|
| 75 | + if (!is_null($payload) && $payload->isClaimSet() && $payload instanceof IJWSPayloadClaimSetSpec) { |
|
| 76 | 76 | $header->addHeader(new JOSEHeaderParam(RegisteredJOSEHeaderNames::Type, new StringOrURI('JWT'))); |
| 77 | 77 | $claim_set = $payload->getClaimSet(); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | parent::__construct($header, $claim_set); |
| 81 | 81 | |
| 82 | - if(!is_null($payload)) |
|
| 82 | + if (!is_null($payload)) |
|
| 83 | 83 | $this->setPayload($payload); |
| 84 | 84 | |
| 85 | 85 | $this->signature = $signature; |
@@ -100,21 +100,18 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function toCompactSerialization() |
| 102 | 102 | { |
| 103 | - if(!is_null($this->jwk->getId())) |
|
| 103 | + if (!is_null($this->jwk->getId())) |
|
| 104 | 104 | $this->header->addHeader(new JOSEHeaderParam(RegisteredJOSEHeaderNames::KeyID, $this->jwk->getId())); |
| 105 | 105 | |
| 106 | - if($this->jwk instanceof IAsymmetricJWK) |
|
| 106 | + if ($this->jwk instanceof IAsymmetricJWK) |
|
| 107 | 107 | { |
| 108 | 108 | // we should add the public key on the header |
| 109 | 109 | $public_key = clone $this->jwk; |
| 110 | 110 | |
| 111 | - $this->header->addHeader |
|
| 112 | - ( |
|
| 113 | - new JOSEHeaderParam |
|
| 114 | - ( |
|
| 111 | + $this->header->addHeader( |
|
| 112 | + new JOSEHeaderParam( |
|
| 115 | 113 | RegisteredJOSEHeaderNames::JSONWebKey, |
| 116 | - new JsonValue |
|
| 117 | - ( |
|
| 114 | + new JsonValue( |
|
| 118 | 115 | $public_key->setVisibility(JSONWebKeyVisibility::PublicOnly) |
| 119 | 116 | ) |
| 120 | 117 | ) |
@@ -134,32 +131,32 @@ discard block |
||
| 134 | 131 | public function sign() |
| 135 | 132 | { |
| 136 | 133 | |
| 137 | - if(is_null($this->jwk)) |
|
| 134 | + if (is_null($this->jwk)) |
|
| 138 | 135 | throw new JWSInvalidJWKException; |
| 139 | 136 | |
| 140 | - if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
| 137 | + if ($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
| 141 | 138 | throw new JWSInvalidJWKException(sprintf('use %s not supported.', $this->jwk->getKeyUse()->getString())); |
| 142 | 139 | |
| 143 | 140 | $alg = DigitalSignatures_MACs_Registry::getInstance()->get($this->header->getAlgorithm()->getString()); |
| 144 | 141 | |
| 145 | - if(is_null($alg)) |
|
| 146 | - throw new JWSNotSupportedAlgorithm(sprintf('alg %s.',$this->header->getAlgorithm()->getString())); |
|
| 142 | + if (is_null($alg)) |
|
| 143 | + throw new JWSNotSupportedAlgorithm(sprintf('alg %s.', $this->header->getAlgorithm()->getString())); |
|
| 147 | 144 | |
| 148 | - $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header) . IBasicJWT::SegmentSeparator .$this->getEncodedPayload(); |
|
| 145 | + $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header).IBasicJWT::SegmentSeparator.$this->getEncodedPayload(); |
|
| 149 | 146 | |
| 150 | - $key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::ComputeDigitalSignatureOrMAC); |
|
| 147 | + $key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::ComputeDigitalSignatureOrMAC); |
|
| 151 | 148 | |
| 152 | - if($alg instanceof DigitalSignatureAlgorithm) |
|
| 149 | + if ($alg instanceof DigitalSignatureAlgorithm) |
|
| 153 | 150 | { |
| 154 | 151 | $this->signature = $alg->sign($key, $secured_input_bytes); |
| 155 | 152 | } |
| 156 | - else if($alg instanceof MAC_Algorithm ) |
|
| 153 | + else if ($alg instanceof MAC_Algorithm) |
|
| 157 | 154 | { |
| 158 | 155 | $this->signature = $alg->digest($key, $secured_input_bytes); |
| 159 | 156 | } |
| 160 | 157 | else |
| 161 | 158 | { |
| 162 | - throw new JWSNotSupportedAlgorithm(sprintf('alg %s.',$this->header->getAlgorithm()->getString())); |
|
| 159 | + throw new JWSNotSupportedAlgorithm(sprintf('alg %s.', $this->header->getAlgorithm()->getString())); |
|
| 163 | 160 | } |
| 164 | 161 | |
| 165 | 162 | return $this; |
@@ -171,11 +168,11 @@ discard block |
||
| 171 | 168 | */ |
| 172 | 169 | public function getEncodedPayload() |
| 173 | 170 | { |
| 174 | - if(is_null($this->payload)) |
|
| 171 | + if (is_null($this->payload)) |
|
| 175 | 172 | throw new JWSInvalidPayloadException('payload is not set!'); |
| 176 | 173 | |
| 177 | 174 | $enc_payload = ''; |
| 178 | - if($this->payload->isClaimSet() && $this->payload instanceof IJWSPayloadClaimSetSpec) |
|
| 175 | + if ($this->payload->isClaimSet() && $this->payload instanceof IJWSPayloadClaimSetSpec) |
|
| 179 | 176 | { |
| 180 | 177 | $enc_payload = JWTClaimSetSerializer::serialize($this->payload->getClaimSet()); |
| 181 | 178 | } |
@@ -233,27 +230,23 @@ discard block |
||
| 233 | 230 | */ |
| 234 | 231 | public function verify($original_alg) |
| 235 | 232 | { |
| 236 | - if(is_null($this->jwk)) |
|
| 233 | + if (is_null($this->jwk)) |
|
| 237 | 234 | throw new JWSInvalidJWKException; |
| 238 | 235 | |
| 239 | - if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
| 240 | - throw new JWSInvalidJWKException |
|
| 241 | - ( |
|
| 242 | - sprintf |
|
| 243 | - ( |
|
| 236 | + if ($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
| 237 | + throw new JWSInvalidJWKException( |
|
| 238 | + sprintf( |
|
| 244 | 239 | 'use %s not supported ', |
| 245 | 240 | $this->jwk->getKeyUse()->getString() |
| 246 | 241 | ) |
| 247 | 242 | ); |
| 248 | 243 | |
| 249 | - if(is_null($this->jwk->getAlgorithm())) |
|
| 244 | + if (is_null($this->jwk->getAlgorithm())) |
|
| 250 | 245 | throw new InvalidJWKAlgorithm('algorithm intended for use with the key is not set! '); |
| 251 | 246 | |
| 252 | - if(!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue()) |
|
| 253 | - throw new JWSInvalidJWKException |
|
| 254 | - ( |
|
| 255 | - sprintf |
|
| 256 | - ( |
|
| 247 | + if (!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue()) |
|
| 248 | + throw new JWSInvalidJWKException( |
|
| 249 | + sprintf( |
|
| 257 | 250 | 'original kid %s - current kid %s', |
| 258 | 251 | $this->header->getKeyID()->getValue(), |
| 259 | 252 | $this->jwk->getId()->getValue() |
@@ -262,34 +255,30 @@ discard block |
||
| 262 | 255 | |
| 263 | 256 | $alg = DigitalSignatures_MACs_Registry::getInstance()->get($original_alg); |
| 264 | 257 | |
| 265 | - if(is_null($alg)) |
|
| 258 | + if (is_null($alg)) |
|
| 266 | 259 | throw new JWSNotSupportedAlgorithm(sprintf('algo %s', $original_alg)); |
| 267 | 260 | |
| 268 | 261 | $former_alg = $this->header->getAlgorithm()->getString(); |
| 269 | 262 | |
| 270 | - if($former_alg != $original_alg) |
|
| 271 | - throw new JWSNotSupportedAlgorithm |
|
| 272 | - ( |
|
| 273 | - sprintf |
|
| 274 | - ( |
|
| 263 | + if ($former_alg != $original_alg) |
|
| 264 | + throw new JWSNotSupportedAlgorithm( |
|
| 265 | + sprintf( |
|
| 275 | 266 | 'former alg %s - original alg %s', |
| 276 | 267 | $former_alg, |
| 277 | 268 | $original_alg |
| 278 | 269 | ) |
| 279 | 270 | ); |
| 280 | 271 | |
| 281 | - if($this->jwk->getAlgorithm()->getValue() !== $original_alg) |
|
| 282 | - throw new InvalidJWKAlgorithm |
|
| 283 | - ( |
|
| 284 | - sprintf |
|
| 285 | - ( |
|
| 272 | + if ($this->jwk->getAlgorithm()->getValue() !== $original_alg) |
|
| 273 | + throw new InvalidJWKAlgorithm( |
|
| 274 | + sprintf( |
|
| 286 | 275 | 'mismatch between algorithm intended for use with the key %s and the cryptographic algorithm used to secure the JWS %s', |
| 287 | 276 | $this->jwk->getAlgorithm()->getValue(), |
| 288 | 277 | $original_alg |
| 289 | 278 | ) |
| 290 | 279 | ); |
| 291 | 280 | |
| 292 | - $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header) . IBasicJWT::SegmentSeparator .$this->getEncodedPayload(); |
|
| 281 | + $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header).IBasicJWT::SegmentSeparator.$this->getEncodedPayload(); |
|
| 293 | 282 | |
| 294 | 283 | // use public key / secret |
| 295 | 284 | $key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::VerifyDigitalSignatureOrMAC); |
@@ -310,9 +299,9 @@ discard block |
||
| 310 | 299 | * @param string $signature |
| 311 | 300 | * @return IJWS |
| 312 | 301 | */ |
| 313 | - static public function fromHeaderClaimsAndSignature(IJOSEHeader $header, IJWSPayloadSpec $payload = null , $signature = '') |
|
| 302 | + static public function fromHeaderClaimsAndSignature(IJOSEHeader $header, IJWSPayloadSpec $payload = null, $signature = '') |
|
| 314 | 303 | { |
| 315 | - return new JWS($header, $payload, $signature ); |
|
| 304 | + return new JWS($header, $payload, $signature); |
|
| 316 | 305 | } |
| 317 | 306 | |
| 318 | 307 | /** |
@@ -320,10 +309,9 @@ discard block |
||
| 320 | 309 | */ |
| 321 | 310 | public function take() |
| 322 | 311 | { |
| 323 | - $payload = $this->payload->isClaimSet() ? $this->claim_set : $this->payload->getRaw(); |
|
| 312 | + $payload = $this->payload->isClaimSet() ? $this->claim_set : $this->payload->getRaw(); |
|
| 324 | 313 | |
| 325 | - return array |
|
| 326 | - ( |
|
| 314 | + return array( |
|
| 327 | 315 | $this->header, |
| 328 | 316 | $payload, |
| 329 | 317 | $this->signature |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | * @param mixed $content |
| 30 | 30 | * @return IJWSPayloadSpec |
| 31 | 31 | */ |
| 32 | - public static function build($content){ |
|
| 32 | + public static function build($content) { |
|
| 33 | 33 | |
| 34 | - if($content instanceof IJWTClaimSet){ |
|
| 34 | + if ($content instanceof IJWTClaimSet) { |
|
| 35 | 35 | return new _JWSPayloadClaimSetSpec($content); |
| 36 | 36 | } |
| 37 | - else{ |
|
| 37 | + else { |
|
| 38 | 38 | return new _JWSPayloadRawSpec($content); |
| 39 | 39 | } |
| 40 | 40 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | /** |
| 57 | 57 | * @param IJWTClaimSet $claim_set |
| 58 | 58 | */ |
| 59 | - public function __construct(IJWTClaimSet $claim_set){ |
|
| 59 | + public function __construct(IJWTClaimSet $claim_set) { |
|
| 60 | 60 | $this->claim_set = $claim_set; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | /** |
| 102 | 102 | * @param string $raw |
| 103 | 103 | */ |
| 104 | - public function __construct($raw){ |
|
| 104 | + public function __construct($raw) { |
|
| 105 | 105 | $this->raw = $raw; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -72,5 +72,5 @@ |
||
| 72 | 72 | * @param string $signature |
| 73 | 73 | * @return IJWS |
| 74 | 74 | */ |
| 75 | - static public function fromHeaderClaimsAndSignature(IJOSEHeader $header, IJWSPayloadSpec $payload = null , $signature = ''); |
|
| 75 | + static public function fromHeaderClaimsAndSignature(IJOSEHeader $header, IJWSPayloadSpec $payload = null, $signature = ''); |
|
| 76 | 76 | } |
| 77 | 77 | \ No newline at end of file |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | public function invoke() |
| 31 | 31 | { |
| 32 | - if(func_num_args() <= 0) throw new \RuntimeException('you must pass len as arg!'); |
|
| 32 | + if (func_num_args() <= 0) throw new \RuntimeException('you must pass len as arg!'); |
|
| 33 | 33 | $byte_len = func_get_arg(0); |
| 34 | 34 | return ByteUtil::randomBytes($byte_len); |
| 35 | 35 | } |
@@ -32,18 +32,18 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | private $services = array(); |
| 34 | 34 | |
| 35 | - private function __construct(){ |
|
| 35 | + private function __construct() { |
|
| 36 | 36 | |
| 37 | 37 | $this->services[self::RandomNumberGeneratorService] = new RandomNumberGeneratorService; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - private function __clone(){} |
|
| 40 | + private function __clone() {} |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * @return Utils_Registry |
| 44 | 44 | */ |
| 45 | - public static function getInstance(){ |
|
| 46 | - if(!is_object(self::$instance)){ |
|
| 45 | + public static function getInstance() { |
|
| 46 | + if (!is_object(self::$instance)) { |
|
| 47 | 47 | self::$instance = new Utils_Registry(); |
| 48 | 48 | } |
| 49 | 49 | return self::$instance; |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | * @param string $service_name |
| 54 | 54 | * @return null|IService |
| 55 | 55 | */ |
| 56 | - public function get($service_name){ |
|
| 57 | - if(!array_key_exists($service_name, $this->services)) |
|
| 56 | + public function get($service_name) { |
|
| 57 | + if (!array_key_exists($service_name, $this->services)) |
|
| 58 | 58 | throw new \InvalidArgumentException('unknown service!'); |
| 59 | 59 | |
| 60 | 60 | return $this->services[$service_name]; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @param IService $service |
| 66 | 66 | * @return $this |
| 67 | 67 | */ |
| 68 | - public function add($service_name, IService $service){ |
|
| 68 | + public function add($service_name, IService $service) { |
|
| 69 | 69 | $this->services[$service_name] = $service; |
| 70 | 70 | return $this; |
| 71 | 71 | } |
@@ -42,18 +42,18 @@ |
||
| 42 | 42 | $segments = explode(IBasicJWT::SegmentSeparator, $compact_serialization); |
| 43 | 43 | // JWSs have three segments separated by two period ('.') characters. |
| 44 | 44 | // JWEs have five segments separated by four period ('.') characters. |
| 45 | - switch(count($segments)) |
|
| 45 | + switch (count($segments)) |
|
| 46 | 46 | { |
| 47 | 47 | case 3: |
| 48 | 48 | // JWS or unsecured one |
| 49 | 49 | $header = JOSEHeaderSerializer::deserialize($segments[0]); |
| 50 | - if($header->getAlgorithm()->getString() === 'none' && empty($segments[2])) |
|
| 50 | + if ($header->getAlgorithm()->getString() === 'none' && empty($segments[2])) |
|
| 51 | 51 | return UnsecuredJWT::fromCompactSerialization($compact_serialization); |
| 52 | - return JWSFactory::build( new JWS_CompactFormatSpecification($compact_serialization) ); |
|
| 52 | + return JWSFactory::build(new JWS_CompactFormatSpecification($compact_serialization)); |
|
| 53 | 53 | break; |
| 54 | 54 | case 5: |
| 55 | 55 | // JWE |
| 56 | - return JWEFactory::build( new JWE_CompactFormatSpecification($compact_serialization) ); |
|
| 56 | + return JWEFactory::build(new JWE_CompactFormatSpecification($compact_serialization)); |
|
| 57 | 57 | break; |
| 58 | 58 | default: |
| 59 | 59 | throw new InvalidCompactSerializationException; |
@@ -29,14 +29,14 @@ |
||
| 29 | 29 | /** |
| 30 | 30 | * @param int|string|array|bool|IJsonObject $value |
| 31 | 31 | */ |
| 32 | - public function __construct($value){ |
|
| 32 | + public function __construct($value) { |
|
| 33 | 33 | $this->value = $value; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * @return int|string|array|bool|IJsonObject |
| 38 | 38 | */ |
| 39 | - public function getValue(){ |
|
| 39 | + public function getValue() { |
|
| 40 | 40 | return $this->value; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | class StringOrURI extends JsonValue { |
| 27 | 27 | |
| 28 | - public function getString(){ |
|
| 28 | + public function getString() { |
|
| 29 | 29 | return (string)$this->value; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * @throws \RuntimeException |
| 34 | 34 | * @return string |
| 35 | 35 | */ |
| 36 | - public function getUri(){ |
|
| 36 | + public function getUri() { |
|
| 37 | 37 | |
| 38 | - if($this->isString()) |
|
| 38 | + if ($this->isString()) |
|
| 39 | 39 | throw new \RuntimeException('current value is not an uri!'); |
| 40 | - if(filter_var($this->value, FILTER_VALIDATE_URL) === false) |
|
| 40 | + if (filter_var($this->value, FILTER_VALIDATE_URL) === false) |
|
| 41 | 41 | throw new \RuntimeException('current value is not an uri!'); |
| 42 | 42 | |
| 43 | 43 | return (string)$this->value; |
@@ -46,21 +46,21 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * @return bool |
| 48 | 48 | */ |
| 49 | - public function isString(){ |
|
| 49 | + public function isString() { |
|
| 50 | 50 | return !$this->isUri(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
| 54 | 54 | * @return bool |
| 55 | 55 | */ |
| 56 | - public function isUri(){ |
|
| 56 | + public function isUri() { |
|
| 57 | 57 | return !(strstr($this->value, ':') === false); |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | - public function getValue(){ |
|
| 63 | + public function getValue() { |
|
| 64 | 64 | return $this->isUri() ? $this->getUri() : $this->getString(); |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | 67 | \ No newline at end of file |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class JsonArray extends JsonValue implements \ArrayAccess { |
| 22 | 22 | |
| 23 | - public function __construct(array $values){ |
|
| 23 | + public function __construct(array $values) { |
|
| 24 | 24 | parent::__construct($values); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | unset($this->value[$offset]); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - public function append($value){ |
|
| 48 | + public function append($value) { |
|
| 49 | 49 | array_push($this->value, $value); |
| 50 | 50 | } |
| 51 | 51 | |