1 | <?php |
||
27 | class JWSVerifier |
||
28 | { |
||
29 | /** |
||
30 | * @var AlgorithmManager |
||
31 | */ |
||
32 | private $signatureAlgorithmManager; |
||
33 | |||
34 | /** |
||
35 | * JWSVerifier constructor. |
||
36 | */ |
||
37 | public function __construct(AlgorithmManager $signatureAlgorithmManager) |
||
38 | { |
||
39 | $this->signatureAlgorithmManager = $signatureAlgorithmManager; |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Returns the algorithm manager associated to the JWSVerifier. |
||
44 | */ |
||
45 | public function getSignatureAlgorithmManager(): AlgorithmManager |
||
49 | |||
50 | /** |
||
51 | * This method will try to verify the JWS object using the given key and for the given signature. |
||
52 | * It returns true if the signature is verified, otherwise false. |
||
53 | * |
||
54 | * @return bool true if the verification of the signature succeeded, else false |
||
55 | */ |
||
56 | public function verifyWithKey(JWS $jws, JWK $jwk, int $signature, ?string $detachedPayload = null): bool |
||
62 | |||
63 | /** |
||
64 | * This method will try to verify the JWS object using the given key set and for the given signature. |
||
65 | * It returns true if the signature is verified, otherwise false. |
||
66 | * |
||
67 | * @param JWS $jws A JWS object |
||
68 | * @param JWKSet $jwkset The signature will be verified using keys in the key set |
||
69 | * @param JWK $jwk The key used to verify the signature in case of success |
||
70 | * @param null|string $detachedPayload If not null, the value must be the detached payload encoded in Base64 URL safe. If the input contains a payload, throws an exception. |
||
71 | * |
||
72 | * @throws InvalidArgumentException if there is no key in the keyset |
||
73 | * @throws InvalidArgumentException if the token does not contain any signature |
||
74 | * |
||
75 | * @return bool true if the verification of the signature succeeded, else false |
||
76 | */ |
||
77 | public function verifyWithKeySet(JWS $jws, JWKSet $jwkset, int $signatureIndex, ?string $detachedPayload = null, JWK &$jwk = null): bool |
||
90 | |||
91 | private function verifySignature(JWS $jws, JWKSet $jwkset, Signature $signature, ?string $detachedPayload = null, JWK &$successJwk = null): bool |
||
112 | |||
113 | private function getInputToVerify(JWS $jws, Signature $signature, ?string $detachedPayload): string |
||
131 | |||
132 | /** |
||
133 | * @throws InvalidArgumentException if the payload is set when a detached payload is provided or no payload is defined |
||
134 | */ |
||
135 | private function checkPayload(JWS $jws, ?string $detachedPayload = null): void |
||
145 | |||
146 | /** |
||
147 | * @throws InvalidArgumentException if the header parameter "alg" is missing or invalid |
||
148 | * |
||
149 | * @return MacAlgorithm|SignatureAlgorithm |
||
150 | */ |
||
151 | private function getAlgorithm(Signature $signature): Algorithm |
||
165 | |||
166 | private function isPayloadEmpty(?string $payload): bool |
||
170 | } |
||
171 |