Decrypts/validates JWS, returning related data.
@param string $jws raw JWS input.
@return array JWS underlying data.
@throws HttpException on invalid JWS signature.
972254
protected function loadJws($jws)
    {
        try {
            $jwkSet = JWKFactory::createFromJKU($this->getConfigParam('jwks_uri'));
            $loader = new Loader();
            return $loader->loadAndVerifySignatureUsingKeySet($jws, $jwkSet, $this->allowedJwsAlgorithms)->getPayload();
        } catch (\Exception $e) {
            $message = YII_DEBUG ? 'Unable to verify JWS: ' . $e->getMessage() : 'Invalid JWS';
            throw new HttpException(400, $message, $e->getCode(), $e);
        }
    }
745159
private function decryptAssertion(Object\JWEInterface $jwe, Object\JWKSetInterface $encryption_key_set)
    {
        $this->decrypter->decryptUsingKeySet($jwe, $encryption_key_set);

        $jws = $this->loader->load($jwe->getPayload());
        Assertion::isInstanceOf($jws, Object\JWSInterface::class, 'The encrypted assertion does not contain a JWS.');

        return $jws;
    }
365772
public function create(string $payload, array $signatures, string $jws_serialization_mode, array $jweSharedProtectedHeader, array $jweSharedHeader, array $recipients, string $jwe_serialization_mode, ?string $aad = null): string
    {
        $jws = $this->jwsBuilder->create()->withPayload($payload);
        foreach ($signatures as $signature) {
            if (!\is_array($signature) || !\array_key_exists('key', $signature)) {
                throw new \InvalidArgumentException('The signatures must be an array of arrays containing a key, a protected header and a header');
            }
            $signature['protected_header'] = \array_key_exists('protected_header', $signature) ? $signature['protected_header'] : [];
            $signature['header'] = \array_key_exists('header', $signature) ? $signature['header'] : [];
            $jws = $jws->addSignature($signature['key'], $signature['protected_header'], $signature['header']);
        }
        $jws = $jws->build();
        $token = $this->jwsSerializerManager->serialize($jws_serialization_mode, $jws);

        $jweSharedProtectedHeader['cty'] = 'JWT';

        $jwe = $this->jweBuilder
            ->create()
            ->withPayload($token)
            ->withSharedProtectedHeader($jweSharedProtectedHeader)
            ->withSharedHeader($jweSharedHeader)
            ->withAAD($aad);
        foreach ($recipients as $recipient) {
            if (!\is_array($recipient) || !\array_key_exists('key', $recipient)) {
                throw new \InvalidArgumentException('The recipients must be an array of arrays containing a key and a header');
            }
            $recipient['header'] = \array_key_exists('header', $recipient) ? $recipient['header'] : [];
            $jwe = $jwe->addRecipient($recipient['key'], $recipient['header']);
        }
        $jwe = $jwe->build();
        $token = $this->jweSerializerManager->serialize($jwe_serialization_mode, $jwe);

        return $token;
    }
1211882
private function getInputToVerify(Object\JWSInterface $jws, Object\SignatureInterface $signature, $detached_payload)
    {
        $encoded_protected_headers = $signature->getEncodedProtectedHeaders();
        if (!$signature->hasProtectedHeader('b64') || true === $signature->getProtectedHeader('b64')) {
            if (null !== $jws->getEncodedPayload($signature)) {
                return sprintf('%s.%s', $encoded_protected_headers, $jws->getEncodedPayload($signature));
            }

            $payload = empty($jws->getPayload()) ? $detached_payload : $jws->getPayload();
            $payload = is_string($payload) ? $payload : json_encode($payload);

            return sprintf('%s.%s', $encoded_protected_headers, Base64Url::encode($payload));
        }

        $payload = empty($jws->getPayload()) ? $detached_payload : $jws->getPayload();
        $payload = is_string($payload) ? $payload : json_encode($payload);

        return sprintf('%s.%s', $encoded_protected_headers, $payload);
    }
319438
public static function parse($raw)
    {
        self::$parsed = [];
        list($headings, $data) = self::parseRawData($raw);

        if (!is_array($headings)) {
            // @codeCoverageIgnoreStart
            return self::$parsed;
            // @codeCoverageIgnoreEnd
        }

        foreach ($headings as $heading) {
            for ($i = 0, $j = count($heading); $i < $j; $i++) {
                self::populateEntries($heading, $data, $i);
            }
        };

        unset($headings, $data);

        return array_reverse(self::$parsed);
    }
435272
public function decrypt($payload)
    {
        try {
            $decrypted = $this->encrypter->decrypt($payload);
        } catch (IlluminateDecryptException $exception) {
            throw new DecryptException('Decryption failed.', 0, $exception);
        }

        return $decrypted;
    }
1194376
private function determineHeaderStringForSignedResponse(array $headers)
    {
        $signedDataHeaders = [];
        ksort($headers);

        foreach ($headers as $headerName => $headerValue) {
            // All headers with the prefix 'X-Bunq-' except 'Server-Signature' need to be signed.
            $headerName = $this->ensureHeaderIsCorrectlyCased($headerName);

            if ($headerName === self::HEADER_SERVER_SIGNATURE) {
                // Skip this header
            } elseif (strpos($headerName, self::HEADER_PREFIX) === self::HEADER_PREFIX_START) {
                $signedDataHeaders[] = $this->determineHeaderStringLine($headerName, $headerValue);
            }
        }

        return implode(self::NEWLINE, $signedDataHeaders);
    }
624107
private function getDeserializationDefinition(string $serialized): array
    {
        if (\trim($serialized) === '') {
            throw new EventSerializationException('Malformed JSON serialized event: empty string');
        }

        $definition = \json_decode($serialized, true, 512, static::JSON_DECODE_OPTIONS);

        // @codeCoverageIgnoreStart
        if ($definition === null || \json_last_error() !== \JSON_ERROR_NONE) {
            throw new EventSerializationException(\sprintf(
                'Event deserialization failed due to error %s: %s',
                \json_last_error(),
                \lcfirst(\json_last_error_msg())
            ));
        }
        // @codeCoverageIgnoreEnd

        return $definition;
    }
470301
public function decode($token)
    {
        try {
            // Let's never allow insecure tokens
            $jws = $this->jws->load($token, false);
        } catch (InvalidArgumentException $e) {
            throw new TokenInvalidException('Could not decode token: '.$e->getMessage(), $e->getCode(), $e);
        }

        if (! $jws->verify($this->getVerificationKey(), $this->getAlgo())) {
            throw new TokenInvalidException('Token Signature could not be verified.');
        }

        return (array) $jws->getPayload();
    }
1121347
protected function splitJwt($jwt)
    {
        if (!is_string($jwt)) {
            throw new \InvalidArgumentException('The JWT string must have two dots');
        }

        $data = explode('.', $jwt);

        if (count($data) != 3) {
            throw new \InvalidArgumentException('The JWT string must have two dots');
        }

        return $data;
    }
465291
def _is_json_serialized_jws(self, json_jws):
        
        json_ser_keys = {"payload", "signatures"}
        flattened_json_ser_keys = {"payload", "signature"}
        if not json_ser_keys.issubset(
                json_jws.keys()) and not flattened_json_ser_keys.issubset(
                json_jws.keys()):
            return False
        return True
471790
public function getDecodedToken(string $jwt)
    {
        try {
            /** @noinspection PhpUnusedLocalVariableInspection */
            [$headb64, $bodyb64, $cryptob64] = \explode('.', $jwt);
            $decodedToken = \json_decode(JWT::urlsafeB64Decode($bodyb64));

            /** @noinspection NullPointerExceptionInspection */
            JWT::decode($jwt, $this->findTenant($decodedToken->iss)->getSharedSecret(), ['HS256']);

            return $decodedToken;
        } catch (\Throwable $e) {
            throw new AuthenticationException($e->getMessage());
        }
    }
194485
public function decrypt($data) {
        if (is_array($data)) return array_map([$this, __FUNCTION__], $data);
        $raw = base64_decode($data);
        openssl_public_decrypt($raw, $result, $this->key);
        return $result;
    }
642999
public function verifyWithKey(JWSInterface $jws, JWKInterface $jwk, $detached_payload = null, &$recipient_index = null)
    {
        $this->log(LogLevel::DEBUG, 'Trying to verify the JWS with the key', ['jws' => $jws, 'jwk' => $jwk, 'detached_payload' => $detached_payload]);
        $jwk_set = new JWKSet();
        $jwk_set->addKey($jwk);

        $this->verifySignatures($jws, $jwk_set, $detached_payload, $recipient_index);
    }
1049542
public function parse($jwt)
    {
        $data = $this->splitJwt($jwt);
        $header = $this->parseHeader($data[0]);
        $claims = $this->parseClaims($data[1]);
        $signature = $this->parseSignature($header, $data[2]);

        foreach ($claims as $name => $value) {
            if (isset($header[$name])) {
                $header[$name] = $value;
            }
        }

        if ($signature === null) {
            unset($data[2]);
        }

        return new Token($header, $claims, $signature, $data);
    }
540145
public function decode(string $json): array
    {
        $decoded = \json_decode($json, true);
        if (\json_last_error() !== JSON_ERROR_NONE) {
            throw new DecodingException(\json_last_error_msg(), \json_last_error());
        }
        return $decoded;
    }
1262449
public function verify(JWSInterface $jws, JWKSetInterface $signature_key_set, $detached_payload = null)
    {
        Assertion::inArray($jws->getSignature(0)->getProtectedHeader('alg'), $this->getSupportedSignatureAlgorithms(), sprintf('The signature algorithm "%s" is not supported or not allowed.', $jws->getSignature(0)->getProtectedHeader('alg')));

        $index = null;
        $this->verifier->verifyWithKeySet($jws, $signature_key_set, $detached_payload, $index);
        Assertion::notNull($index, 'JWS signature(s) verification failed.');
        $this->checker_manager->checkJWS($jws, $index);

        return $index;
    }