@@ -39,8 +39,9 @@ |
||
| 39 | 39 | $kid = null |
| 40 | 40 | ) |
| 41 | 41 | { |
| 42 | - if(!empty($alg) && !in_array($alg, RSAKeysParameters::$valid_algorithms_values)) |
|
| 43 | - throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
|
| 42 | + if(!empty($alg) && !in_array($alg, RSAKeysParameters::$valid_algorithms_values)) { |
|
| 43 | + throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
|
| 44 | + } |
|
| 44 | 45 | |
| 45 | 46 | parent::__construct($alg, $use, $kid); |
| 46 | 47 | } |
@@ -45,8 +45,9 @@ |
||
| 45 | 45 | $use = JSONWebKeyPublicKeyUseValues::Signature |
| 46 | 46 | ) |
| 47 | 47 | { |
| 48 | - if(!in_array($alg, OctetSequenceKeysParameters::$valid_algorithms_values)) |
|
| 49 | - throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
|
| 48 | + if(!in_array($alg, OctetSequenceKeysParameters::$valid_algorithms_values)) { |
|
| 49 | + throw new InvalidJWKAlgorithm(sprintf('alg %s', $alg)); |
|
| 50 | + } |
|
| 50 | 51 | |
| 51 | 52 | parent::__construct($alg, $use); |
| 52 | 53 | |
@@ -53,11 +53,14 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | parent::__construct($headers); |
| 55 | 55 | |
| 56 | - if (count($headers) === 0) return; |
|
| 56 | + if (count($headers) === 0) { |
|
| 57 | + return; |
|
| 58 | + } |
|
| 57 | 59 | |
| 58 | 60 | foreach (RSAKeysParameters::$public_key_params as $p) { |
| 59 | - if (!array_key_exists($p, $headers)) |
|
| 60 | - throw new RSAJWKMissingPublicKeyParamException(); |
|
| 61 | + if (!array_key_exists($p, $headers)) { |
|
| 62 | + throw new RSAJWKMissingPublicKeyParamException(); |
|
| 63 | + } |
|
| 61 | 64 | $this->set[$p] = new Base64urlUInt($headers[$p]); |
| 62 | 65 | } |
| 63 | 66 | |
@@ -74,8 +77,9 @@ discard block |
||
| 74 | 77 | //its has one private param, must have all ... |
| 75 | 78 | if (in_array(RSAKeysParameters::FirstPrimeFactor, $headers)) { |
| 76 | 79 | foreach (RSAKeysParameters::$producers_private_key_params as $p) { |
| 77 | - if (!array_key_exists($p, $headers)) |
|
| 78 | - throw new RSAJWKMissingPrivateKeyParamException(); |
|
| 80 | + if (!array_key_exists($p, $headers)) { |
|
| 81 | + throw new RSAJWKMissingPrivateKeyParamException(); |
|
| 82 | + } |
|
| 79 | 83 | $this->set[$p] = new Base64urlUInt($headers[$p]); |
| 80 | 84 | } |
| 81 | 85 | $this->private_key = RSAFacade::getInstance()->buildPrivateKey( |
@@ -112,11 +116,13 @@ discard block |
||
| 112 | 116 | */ |
| 113 | 117 | static public function fromKeys(KeyPair $keys) |
| 114 | 118 | { |
| 115 | - if(!($keys->getPrivate() instanceof RSAPrivateKey)) |
|
| 116 | - throw new \RuntimeException('Private key of invalid type!'); |
|
| 119 | + if(!($keys->getPrivate() instanceof RSAPrivateKey)) { |
|
| 120 | + throw new \RuntimeException('Private key of invalid type!'); |
|
| 121 | + } |
|
| 117 | 122 | |
| 118 | - if(!($keys->getPublic() instanceof RSAPublicKey)) |
|
| 119 | - throw new \RuntimeException('Public key of invalid type!'); |
|
| 123 | + if(!($keys->getPublic() instanceof RSAPublicKey)) { |
|
| 124 | + throw new \RuntimeException('Public key of invalid type!'); |
|
| 125 | + } |
|
| 120 | 126 | |
| 121 | 127 | $jwk = new RSAJWK(); |
| 122 | 128 | $jwk->public_key = $keys->getPublic(); |
@@ -134,7 +140,9 @@ discard block |
||
| 134 | 140 | */ |
| 135 | 141 | static public function fromPublicKey(PublicKey $public_key) |
| 136 | 142 | { |
| 137 | - if (!($public_key instanceof RSAPublicKey)) throw new InvalidJWKType(); |
|
| 143 | + if (!($public_key instanceof RSAPublicKey)) { |
|
| 144 | + throw new InvalidJWKType(); |
|
| 145 | + } |
|
| 138 | 146 | $jwk = new RSAJWK(); |
| 139 | 147 | $jwk->public_key = $public_key; |
| 140 | 148 | $jwk->set[RSAKeysParameters::Exponent] = Base64urlUInt::fromBigInt($public_key->getPublicExponent()); |
@@ -149,7 +157,9 @@ discard block |
||
| 149 | 157 | */ |
| 150 | 158 | static public function fromPrivateKey(PrivateKey $private_key) |
| 151 | 159 | { |
| 152 | - if (!($private_key instanceof RSAPrivateKey)) throw new InvalidJWKType(); |
|
| 160 | + if (!($private_key instanceof RSAPrivateKey)) { |
|
| 161 | + throw new InvalidJWKType(); |
|
| 162 | + } |
|
| 153 | 163 | $jwk = new RSAJWK(); |
| 154 | 164 | $jwk->private_key = $private_key; |
| 155 | 165 | $jwk->set[RSAKeysParameters::Exponent] = Base64urlUInt::fromBigInt($private_key->getPublicExponent()); |
@@ -63,7 +63,9 @@ discard block |
||
| 63 | 63 | { |
| 64 | 64 | parent::__construct($headers); |
| 65 | 65 | |
| 66 | - if(count($headers) === 0 ) return; |
|
| 66 | + if(count($headers) === 0 ) { |
|
| 67 | + return; |
|
| 68 | + } |
|
| 67 | 69 | |
| 68 | 70 | // certificates |
| 69 | 71 | if(in_array(PublicJSONWebKeyParameters::X_509CertificateChain, $headers) && is_array($headers[PublicJSONWebKeyParameters::X_509CertificateChain])){ |
@@ -109,8 +111,9 @@ discard block |
||
| 109 | 111 | */ |
| 110 | 112 | public function setVisibility($visibility) |
| 111 | 113 | { |
| 112 | - if(!in_array($visibility, JSONWebKeyVisibility::$valid_values)) |
|
| 113 | - throw new InvalidJWKVisibilityException; |
|
| 114 | + if(!in_array($visibility, JSONWebKeyVisibility::$valid_values)) { |
|
| 115 | + throw new InvalidJWKVisibilityException; |
|
| 116 | + } |
|
| 114 | 117 | $this->visibility = $visibility; |
| 115 | 118 | return $this; |
| 116 | 119 | } |
@@ -97,8 +97,9 @@ discard block |
||
| 97 | 97 | protected function __construct(IJWEJOSEHeader $header, IJWSPayloadSpec $payload = null) |
| 98 | 98 | { |
| 99 | 99 | $this->header = $header; |
| 100 | - if(!is_null($payload)) |
|
| 101 | - $this->setPayload($payload); |
|
| 100 | + if(!is_null($payload)) { |
|
| 101 | + $this->setPayload($payload); |
|
| 102 | + } |
|
| 102 | 103 | } |
| 103 | 104 | |
| 104 | 105 | /** |
@@ -154,8 +155,9 @@ discard block |
||
| 154 | 155 | $this->decrypt(); |
| 155 | 156 | } |
| 156 | 157 | |
| 157 | - if (is_null($this->payload)) |
|
| 158 | - $this->payload = JWSPayloadFactory::build(''); |
|
| 158 | + if (is_null($this->payload)) { |
|
| 159 | + $this->payload = JWSPayloadFactory::build(''); |
|
| 160 | + } |
|
| 159 | 161 | |
| 160 | 162 | return ($this->payload instanceof IJWSPayloadRawSpec) ? $this->payload->getRaw():''; |
| 161 | 163 | } |
@@ -208,16 +210,21 @@ discard block |
||
| 208 | 210 | */ |
| 209 | 211 | private function getKeyManagementMode(EncryptionAlgorithm $alg) |
| 210 | 212 | { |
| 211 | - if($alg instanceof KeyEncryption) |
|
| 212 | - return KeyManagementModeValues::KeyEncryption; |
|
| 213 | - if($alg instanceof KeyWrapping) |
|
| 214 | - return KeyManagementModeValues::KeyWrapping; |
|
| 215 | - if($alg instanceof DirectKeyAgreement) |
|
| 216 | - return KeyManagementModeValues::DirectKeyAgreement; |
|
| 217 | - if($alg instanceof KeyAgreementWithKeyWrapping) |
|
| 218 | - return KeyManagementModeValues::KeyAgreementWithKeyWrapping; |
|
| 219 | - if($alg instanceof DirectEncryption) |
|
| 220 | - return KeyManagementModeValues::DirectEncryption; |
|
| 213 | + if($alg instanceof KeyEncryption) { |
|
| 214 | + return KeyManagementModeValues::KeyEncryption; |
|
| 215 | + } |
|
| 216 | + if($alg instanceof KeyWrapping) { |
|
| 217 | + return KeyManagementModeValues::KeyWrapping; |
|
| 218 | + } |
|
| 219 | + if($alg instanceof DirectKeyAgreement) { |
|
| 220 | + return KeyManagementModeValues::DirectKeyAgreement; |
|
| 221 | + } |
|
| 222 | + if($alg instanceof KeyAgreementWithKeyWrapping) { |
|
| 223 | + return KeyManagementModeValues::KeyAgreementWithKeyWrapping; |
|
| 224 | + } |
|
| 225 | + if($alg instanceof DirectEncryption) { |
|
| 226 | + return KeyManagementModeValues::DirectEncryption; |
|
| 227 | + } |
|
| 221 | 228 | } |
| 222 | 229 | |
| 223 | 230 | /** |
@@ -232,11 +239,12 @@ discard block |
||
| 232 | 239 | private function encrypt() |
| 233 | 240 | { |
| 234 | 241 | |
| 235 | - if (is_null($this->jwk)) |
|
| 236 | - throw new JWEInvalidRecipientKeyException; |
|
| 242 | + if (is_null($this->jwk)) { |
|
| 243 | + throw new JWEInvalidRecipientKeyException; |
|
| 244 | + } |
|
| 237 | 245 | |
| 238 | - if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString()) |
|
| 239 | - throw new InvalidJWKAlgorithm |
|
| 246 | + if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString()) { |
|
| 247 | + throw new InvalidJWKAlgorithm |
|
| 240 | 248 | ( |
| 241 | 249 | sprintf |
| 242 | 250 | ( |
@@ -245,16 +253,18 @@ discard block |
||
| 245 | 253 | $this->header->getAlgorithm()->getString() |
| 246 | 254 | ) |
| 247 | 255 | ); |
| 256 | + } |
|
| 248 | 257 | |
| 249 | 258 | $recipient_public_key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::EncryptContent); |
| 250 | 259 | |
| 251 | 260 | $key_management_algorithm = KeyManagementAlgorithms_Registry::getInstance()->get($this->header->getAlgorithm()->getString()); |
| 252 | 261 | |
| 253 | - if (is_null($key_management_algorithm)) |
|
| 254 | - throw new JWEUnsupportedKeyManagementAlgorithmException(sprintf('alg %s', $this->header->getAlgorithm()->getString())); |
|
| 262 | + if (is_null($key_management_algorithm)) { |
|
| 263 | + throw new JWEUnsupportedKeyManagementAlgorithmException(sprintf('alg %s', $this->header->getAlgorithm()->getString())); |
|
| 264 | + } |
|
| 255 | 265 | |
| 256 | - if($key_management_algorithm->getKeyType() !== $recipient_public_key->getAlgorithm()) |
|
| 257 | - throw new InvalidKeyTypeAlgorithmException |
|
| 266 | + if($key_management_algorithm->getKeyType() !== $recipient_public_key->getAlgorithm()) { |
|
| 267 | + throw new InvalidKeyTypeAlgorithmException |
|
| 258 | 268 | ( |
| 259 | 269 | sprintf |
| 260 | 270 | ( |
@@ -263,14 +273,15 @@ discard block |
||
| 263 | 273 | $recipient_public_key->getAlgorithm() |
| 264 | 274 | ) |
| 265 | 275 | ); |
| 276 | + } |
|
| 266 | 277 | |
| 267 | 278 | $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get |
| 268 | 279 | ( |
| 269 | 280 | $this->header->getEncryptionAlgorithm()->getString() |
| 270 | 281 | ); |
| 271 | 282 | |
| 272 | - if (is_null($content_encryption_algorithm)) |
|
| 273 | - throw new JWEUnsupportedContentEncryptionAlgorithmException |
|
| 283 | + if (is_null($content_encryption_algorithm)) { |
|
| 284 | + throw new JWEUnsupportedContentEncryptionAlgorithmException |
|
| 274 | 285 | ( |
| 275 | 286 | sprintf |
| 276 | 287 | ( |
@@ -278,6 +289,7 @@ discard block |
||
| 278 | 289 | $this->header->getEncryptionAlgorithm()->getString() |
| 279 | 290 | ) |
| 280 | 291 | ); |
| 292 | + } |
|
| 281 | 293 | |
| 282 | 294 | $key_management_mode = $this->getKeyManagementMode($key_management_algorithm); |
| 283 | 295 | |
@@ -350,8 +362,8 @@ discard block |
||
| 350 | 362 | $key_management_mode = $this->getKeyManagementMode($alg); |
| 351 | 363 | $recipient_private_key = $this->jwk->getKey(JSONWebKeyKeyOperationsValues::DecryptContentAndValidateDecryption); |
| 352 | 364 | |
| 353 | - if($alg->getKeyType() !== $recipient_private_key->getAlgorithm()) |
|
| 354 | - throw new InvalidKeyTypeAlgorithmException |
|
| 365 | + if($alg->getKeyType() !== $recipient_private_key->getAlgorithm()) { |
|
| 366 | + throw new InvalidKeyTypeAlgorithmException |
|
| 355 | 367 | ( |
| 356 | 368 | sprintf |
| 357 | 369 | ( |
@@ -360,6 +372,7 @@ discard block |
||
| 360 | 372 | $recipient_private_key->getAlgorithm() |
| 361 | 373 | ) |
| 362 | 374 | ); |
| 375 | + } |
|
| 363 | 376 | |
| 364 | 377 | switch($key_management_mode){ |
| 365 | 378 | /** |
@@ -383,14 +396,16 @@ discard block |
||
| 383 | 396 | */ |
| 384 | 397 | case KeyManagementModeValues::DirectEncryption: |
| 385 | 398 | { |
| 386 | - if (!empty($this->enc_cek)) |
|
| 387 | - throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.'); |
|
| 399 | + if (!empty($this->enc_cek)) { |
|
| 400 | + throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.'); |
|
| 401 | + } |
|
| 388 | 402 | return $recipient_private_key; |
| 389 | 403 | } |
| 390 | 404 | case KeyManagementModeValues::DirectKeyAgreement: |
| 391 | 405 | { |
| 392 | - if (!empty($this->enc_cek)) |
|
| 393 | - throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.'); |
|
| 406 | + if (!empty($this->enc_cek)) { |
|
| 407 | + throw new JWEInvalidCompactFormatException('JWE Encrypted Key value is not an empty octetsequence.'); |
|
| 408 | + } |
|
| 394 | 409 | throw new \Exception('unsupported Key Management Mode!'); |
| 395 | 410 | } |
| 396 | 411 | } |
@@ -409,13 +424,16 @@ discard block |
||
| 409 | 424 | */ |
| 410 | 425 | private function decrypt() |
| 411 | 426 | { |
| 412 | - if (is_null($this->jwk)) |
|
| 413 | - throw new JWEInvalidRecipientKeyException(); |
|
| 427 | + if (is_null($this->jwk)) { |
|
| 428 | + throw new JWEInvalidRecipientKeyException(); |
|
| 429 | + } |
|
| 414 | 430 | |
| 415 | - if (!$this->should_decrypt) return $this; |
|
| 431 | + if (!$this->should_decrypt) { |
|
| 432 | + return $this; |
|
| 433 | + } |
|
| 416 | 434 | |
| 417 | - if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString()) |
|
| 418 | - throw new InvalidJWKAlgorithm |
|
| 435 | + if($this->jwk->getAlgorithm()->getValue()!== $this->header->getAlgorithm()->getString()) { |
|
| 436 | + throw new InvalidJWKAlgorithm |
|
| 419 | 437 | ( |
| 420 | 438 | sprintf |
| 421 | 439 | ( |
@@ -424,14 +442,15 @@ discard block |
||
| 424 | 442 | $this->header->getAlgorithm()->getString() |
| 425 | 443 | ) |
| 426 | 444 | ); |
| 445 | + } |
|
| 427 | 446 | |
| 428 | 447 | $key_management_algorithm = KeyManagementAlgorithms_Registry::getInstance()->get |
| 429 | 448 | ( |
| 430 | 449 | $this->header->getAlgorithm()->getString() |
| 431 | 450 | ); |
| 432 | 451 | |
| 433 | - if (is_null($key_management_algorithm)) |
|
| 434 | - throw new JWEUnsupportedKeyManagementAlgorithmException |
|
| 452 | + if (is_null($key_management_algorithm)) { |
|
| 453 | + throw new JWEUnsupportedKeyManagementAlgorithmException |
|
| 435 | 454 | ( |
| 436 | 455 | sprintf |
| 437 | 456 | ( |
@@ -439,14 +458,15 @@ discard block |
||
| 439 | 458 | $this->header->getAlgorithm()->getString() |
| 440 | 459 | ) |
| 441 | 460 | ); |
| 461 | + } |
|
| 442 | 462 | |
| 443 | 463 | $content_encryption_algorithm = ContentEncryptionAlgorithms_Registry::getInstance()->get |
| 444 | 464 | ( |
| 445 | 465 | $this->header->getEncryptionAlgorithm()->getString() |
| 446 | 466 | ); |
| 447 | 467 | |
| 448 | - if (is_null($content_encryption_algorithm)) |
|
| 449 | - throw new JWEUnsupportedContentEncryptionAlgorithmException |
|
| 468 | + if (is_null($content_encryption_algorithm)) { |
|
| 469 | + throw new JWEUnsupportedContentEncryptionAlgorithmException |
|
| 450 | 470 | ( |
| 451 | 471 | sprintf |
| 452 | 472 | ( |
@@ -454,6 +474,7 @@ discard block |
||
| 454 | 474 | $this->header->getEncryptionAlgorithm()->getString() |
| 455 | 475 | ) |
| 456 | 476 | ); |
| 477 | + } |
|
| 457 | 478 | |
| 458 | 479 | $this->cek = $this->decryptJWEEncryptedKey($key_management_algorithm); |
| 459 | 480 | |
@@ -79,8 +79,9 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | parent::__construct($header, $claim_set); |
| 81 | 81 | |
| 82 | - if(!is_null($payload)) |
|
| 83 | - $this->setPayload($payload); |
|
| 82 | + if(!is_null($payload)) { |
|
| 83 | + $this->setPayload($payload); |
|
| 84 | + } |
|
| 84 | 85 | |
| 85 | 86 | $this->signature = $signature; |
| 86 | 87 | } |
@@ -100,8 +101,9 @@ discard block |
||
| 100 | 101 | */ |
| 101 | 102 | public function toCompactSerialization() |
| 102 | 103 | { |
| 103 | - if(!is_null($this->jwk->getId())) |
|
| 104 | - $this->header->addHeader(new JOSEHeaderParam(RegisteredJOSEHeaderNames::KeyID, $this->jwk->getId())); |
|
| 104 | + if(!is_null($this->jwk->getId())) { |
|
| 105 | + $this->header->addHeader(new JOSEHeaderParam(RegisteredJOSEHeaderNames::KeyID, $this->jwk->getId())); |
|
| 106 | + } |
|
| 105 | 107 | |
| 106 | 108 | if($this->jwk instanceof IAsymmetricJWK) |
| 107 | 109 | { |
@@ -134,16 +136,19 @@ discard block |
||
| 134 | 136 | public function sign() |
| 135 | 137 | { |
| 136 | 138 | |
| 137 | - if(is_null($this->jwk)) |
|
| 138 | - throw new JWSInvalidJWKException; |
|
| 139 | + if(is_null($this->jwk)) { |
|
| 140 | + throw new JWSInvalidJWKException; |
|
| 141 | + } |
|
| 139 | 142 | |
| 140 | - if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
| 141 | - throw new JWSInvalidJWKException(sprintf('use %s not supported.', $this->jwk->getKeyUse()->getString())); |
|
| 143 | + if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) { |
|
| 144 | + throw new JWSInvalidJWKException(sprintf('use %s not supported.', $this->jwk->getKeyUse()->getString())); |
|
| 145 | + } |
|
| 142 | 146 | |
| 143 | 147 | $alg = DigitalSignatures_MACs_Registry::getInstance()->get($this->header->getAlgorithm()->getString()); |
| 144 | 148 | |
| 145 | - if(is_null($alg)) |
|
| 146 | - throw new JWSNotSupportedAlgorithm(sprintf('alg %s.',$this->header->getAlgorithm()->getString())); |
|
| 149 | + if(is_null($alg)) { |
|
| 150 | + throw new JWSNotSupportedAlgorithm(sprintf('alg %s.',$this->header->getAlgorithm()->getString())); |
|
| 151 | + } |
|
| 147 | 152 | |
| 148 | 153 | $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header) . IBasicJWT::SegmentSeparator .$this->getEncodedPayload(); |
| 149 | 154 | |
@@ -152,12 +157,10 @@ discard block |
||
| 152 | 157 | if($alg instanceof DigitalSignatureAlgorithm) |
| 153 | 158 | { |
| 154 | 159 | $this->signature = $alg->sign($key, $secured_input_bytes); |
| 155 | - } |
|
| 156 | - else if($alg instanceof MAC_Algorithm ) |
|
| 160 | + } else if($alg instanceof MAC_Algorithm ) |
|
| 157 | 161 | { |
| 158 | 162 | $this->signature = $alg->digest($key, $secured_input_bytes); |
| 159 | - } |
|
| 160 | - else |
|
| 163 | + } else |
|
| 161 | 164 | { |
| 162 | 165 | throw new JWSNotSupportedAlgorithm(sprintf('alg %s.',$this->header->getAlgorithm()->getString())); |
| 163 | 166 | } |
@@ -171,16 +174,16 @@ discard block |
||
| 171 | 174 | */ |
| 172 | 175 | public function getEncodedPayload() |
| 173 | 176 | { |
| 174 | - if(is_null($this->payload)) |
|
| 175 | - throw new JWSInvalidPayloadException('payload is not set!'); |
|
| 177 | + if(is_null($this->payload)) { |
|
| 178 | + throw new JWSInvalidPayloadException('payload is not set!'); |
|
| 179 | + } |
|
| 176 | 180 | |
| 177 | 181 | $enc_payload = ''; |
| 178 | 182 | |
| 179 | 183 | if($this->payload instanceof IJWSPayloadClaimSetSpec) |
| 180 | 184 | { |
| 181 | 185 | $enc_payload = JWTClaimSetSerializer::serialize($this->payload->getClaimSet()); |
| 182 | - } |
|
| 183 | - else if($this->payload instanceof IJWSPayloadRawSpec) |
|
| 186 | + } else if($this->payload instanceof IJWSPayloadRawSpec) |
|
| 184 | 187 | { |
| 185 | 188 | $enc_payload = JWTRawSerializer::serialize($this->payload->getRaw()); |
| 186 | 189 | } |
@@ -234,11 +237,12 @@ discard block |
||
| 234 | 237 | */ |
| 235 | 238 | public function verify($original_alg) |
| 236 | 239 | { |
| 237 | - if(is_null($this->jwk)) |
|
| 238 | - throw new JWSInvalidJWKException; |
|
| 240 | + if(is_null($this->jwk)) { |
|
| 241 | + throw new JWSInvalidJWKException; |
|
| 242 | + } |
|
| 239 | 243 | |
| 240 | - if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) |
|
| 241 | - throw new JWSInvalidJWKException |
|
| 244 | + if($this->jwk->getKeyUse()->getString() !== JSONWebKeyPublicKeyUseValues::Signature) { |
|
| 245 | + throw new JWSInvalidJWKException |
|
| 242 | 246 | ( |
| 243 | 247 | sprintf |
| 244 | 248 | ( |
@@ -246,12 +250,14 @@ discard block |
||
| 246 | 250 | $this->jwk->getKeyUse()->getString() |
| 247 | 251 | ) |
| 248 | 252 | ); |
| 253 | + } |
|
| 249 | 254 | |
| 250 | - if(is_null($this->jwk->getAlgorithm())) |
|
| 251 | - throw new InvalidJWKAlgorithm('algorithm intended for use with the key is not set! '); |
|
| 255 | + if(is_null($this->jwk->getAlgorithm())) { |
|
| 256 | + throw new InvalidJWKAlgorithm('algorithm intended for use with the key is not set! '); |
|
| 257 | + } |
|
| 252 | 258 | |
| 253 | - if(!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue()) |
|
| 254 | - throw new JWSInvalidJWKException |
|
| 259 | + if(!is_null($this->jwk->getId()) && !is_null($this->header->getKeyID()) && $this->header->getKeyID()->getValue() != $this->jwk->getId()->getValue()) { |
|
| 260 | + throw new JWSInvalidJWKException |
|
| 255 | 261 | ( |
| 256 | 262 | sprintf |
| 257 | 263 | ( |
@@ -260,16 +266,18 @@ discard block |
||
| 260 | 266 | $this->jwk->getId()->getValue() |
| 261 | 267 | ) |
| 262 | 268 | ); |
| 269 | + } |
|
| 263 | 270 | |
| 264 | 271 | $alg = DigitalSignatures_MACs_Registry::getInstance()->get($original_alg); |
| 265 | 272 | |
| 266 | - if(is_null($alg)) |
|
| 267 | - throw new JWSNotSupportedAlgorithm(sprintf('algo %s', $original_alg)); |
|
| 273 | + if(is_null($alg)) { |
|
| 274 | + throw new JWSNotSupportedAlgorithm(sprintf('algo %s', $original_alg)); |
|
| 275 | + } |
|
| 268 | 276 | |
| 269 | 277 | $former_alg = $this->header->getAlgorithm()->getString(); |
| 270 | 278 | |
| 271 | - if($former_alg != $original_alg) |
|
| 272 | - throw new JWSNotSupportedAlgorithm |
|
| 279 | + if($former_alg != $original_alg) { |
|
| 280 | + throw new JWSNotSupportedAlgorithm |
|
| 273 | 281 | ( |
| 274 | 282 | sprintf |
| 275 | 283 | ( |
@@ -278,9 +286,10 @@ discard block |
||
| 278 | 286 | $original_alg |
| 279 | 287 | ) |
| 280 | 288 | ); |
| 289 | + } |
|
| 281 | 290 | |
| 282 | - if($this->jwk->getAlgorithm()->getValue() !== $original_alg) |
|
| 283 | - throw new InvalidJWKAlgorithm |
|
| 291 | + if($this->jwk->getAlgorithm()->getValue() !== $original_alg) { |
|
| 292 | + throw new InvalidJWKAlgorithm |
|
| 284 | 293 | ( |
| 285 | 294 | sprintf |
| 286 | 295 | ( |
@@ -289,6 +298,7 @@ discard block |
||
| 289 | 298 | $original_alg |
| 290 | 299 | ) |
| 291 | 300 | ); |
| 301 | + } |
|
| 292 | 302 | |
| 293 | 303 | $secured_input_bytes = JOSEHeaderSerializer::serialize($this->header) . IBasicJWT::SegmentSeparator .$this->getEncodedPayload(); |
| 294 | 304 | |
@@ -38,7 +38,9 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | protected function __construct(array $headers = []){ |
| 40 | 40 | |
| 41 | - if(count($headers) === 0 ) return; |
|
| 41 | + if(count($headers) === 0 ) { |
|
| 42 | + return; |
|
| 43 | + } |
|
| 42 | 44 | |
| 43 | 45 | $alg = @$headers[JSONWebKeyParameters::Algorithm]; |
| 44 | 46 | $this->setAlgorithm($alg); |
@@ -80,8 +82,9 @@ discard block |
||
| 80 | 82 | */ |
| 81 | 83 | public function setId($kid) |
| 82 | 84 | { |
| 83 | - if(!empty($kid)) |
|
| 84 | - $this->set[JSONWebKeyParameters::KeyId] = new JsonValue($kid); |
|
| 85 | + if(!empty($kid)) { |
|
| 86 | + $this->set[JSONWebKeyParameters::KeyId] = new JsonValue($kid); |
|
| 87 | + } |
|
| 85 | 88 | return $this; |
| 86 | 89 | } |
| 87 | 90 | |
@@ -92,8 +95,9 @@ discard block |
||
| 92 | 95 | */ |
| 93 | 96 | public function setAlgorithm($alg) |
| 94 | 97 | { |
| 95 | - if(!in_array($alg, JSONWebSignatureAndEncryptionAlgorithms::$header_location_alg)) |
|
| 96 | - throw new InvalidJWKAlgorithm (sprintf('alg %s', $alg)); |
|
| 98 | + if(!in_array($alg, JSONWebSignatureAndEncryptionAlgorithms::$header_location_alg)) { |
|
| 99 | + throw new InvalidJWKAlgorithm (sprintf('alg %s', $alg)); |
|
| 100 | + } |
|
| 97 | 101 | |
| 98 | 102 | $this->set[JSONWebKeyParameters::Algorithm] = new StringOrURI($alg); |
| 99 | 103 | return $this; |
@@ -106,9 +110,12 @@ discard block |
||
| 106 | 110 | */ |
| 107 | 111 | public function setKeyUse($use) |
| 108 | 112 | { |
| 109 | - if(empty($use)) return $this; |
|
| 110 | - if(!in_array($use, JSONWebKeyPublicKeyUseValues::$valid_uses)) |
|
| 111 | - throw new InvalidJWKUseException(sprintf('use %s', $use)); |
|
| 113 | + if(empty($use)) { |
|
| 114 | + return $this; |
|
| 115 | + } |
|
| 116 | + if(!in_array($use, JSONWebKeyPublicKeyUseValues::$valid_uses)) { |
|
| 117 | + throw new InvalidJWKUseException(sprintf('use %s', $use)); |
|
| 118 | + } |
|
| 112 | 119 | |
| 113 | 120 | $this->set[JSONWebKeyParameters::PublicKeyUse] = new StringOrURI($use); |
| 114 | 121 | return $this; |
@@ -121,8 +128,9 @@ discard block |
||
| 121 | 128 | */ |
| 122 | 129 | public function setType($type) |
| 123 | 130 | { |
| 124 | - if(!in_array($type, JSONWebKeyTypes::$valid_keys_set)) |
|
| 125 | - throw new InvalidJWKType(sprintf('use %s', $type)); |
|
| 131 | + if(!in_array($type, JSONWebKeyTypes::$valid_keys_set)) { |
|
| 132 | + throw new InvalidJWKType(sprintf('use %s', $type)); |
|
| 133 | + } |
|
| 126 | 134 | |
| 127 | 135 | $this->set[JSONWebKeyParameters::KeyType] = new StringOrURI($type); |
| 128 | 136 | return $this; |
@@ -48,7 +48,9 @@ |
||
| 48 | 48 | */ |
| 49 | 49 | static public function deserialize($input){ |
| 50 | 50 | $parts = explode(IBasicJWT::SegmentSeparator, $input); |
| 51 | - if (count($parts) !== 5) throw new JWEInvalidCompactFormatException; |
|
| 51 | + if (count($parts) !== 5) { |
|
| 52 | + throw new JWEInvalidCompactFormatException; |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | $header = JWEJOSEHeaderSerializer::deserialize($parts[0]); |
| 54 | 56 | $enc_cek = JWTRawSerializer::deserialize($parts[1]); |
@@ -39,7 +39,9 @@ |
||
| 39 | 39 | |
| 40 | 40 | $this->file = new X509(); |
| 41 | 41 | $this->info = $this->file->loadX509($pem); |
| 42 | - if($this->info === false) throw new InvalidX509CertificateException($pem); |
|
| 42 | + if($this->info === false) { |
|
| 43 | + throw new InvalidX509CertificateException($pem); |
|
| 44 | + } |
|
| 43 | 45 | $this->original_pem = $pem; |
| 44 | 46 | } |
| 45 | 47 | |