/** * {@inheritdoc} */ public function checkElement(DigestDataInterface $digest_data) { $opaque = base64_encode(hash_hmac($this->hash_algorithm, $digest_data->get('nonce') . $digest_data->get('realm'), $this->hash_key, true)); if ($opaque !== $digest_data->get('opaque')) { throw new \InvalidArgumentException('Invalid "opaque" value.'); } }
/** * {@inheritdoc} */ public function checkElement(DigestDataInterface $digest_data) { if (false === $digest_data->has('nonce')) { throw new \InvalidArgumentException('Missing mandatory digest value: "nonce".'); } if (false === ($nonceAsPlainText = base64_decode($digest_data->get('nonce')))) { throw new \InvalidArgumentException(sprintf('Nonce is not encoded in Base64; received nonce "%s".', $digest_data->get('nonce'))); } $nonceTokens = explode(':', $nonceAsPlainText); if (2 !== count($nonceTokens)) { throw new \InvalidArgumentException(sprintf('Nonce should have yielded two tokens but was "%s".', $nonceAsPlainText)); } $nonce_expiry_time = $nonceTokens[0]; $signature = $nonceTokens[1]; $this->checkSignature($nonce_expiry_time, $signature); $this->checkExpired($nonce_expiry_time); }
/** * {@inheritdoc} */ public function checkElement(DigestDataInterface $digest_data) { if (!$digest_data->has('qop')) { return; } if (in_array($digest_data->get('qop'), ['auth', 'auth-int'])) { foreach (['nc', 'cnonce'] as $element) { $this->checkSubElement($digest_data, $element); } } }
private function checkUserHash(DigestDataInterface $digest_data) { if ('true' === $digest_data->get('userhash')) { if (!$digest_data->has('username')) { throw new \InvalidArgumentException('Missing mandatory digest value "username".'); } } else { if (!$digest_data->has('username*')) { throw new \InvalidArgumentException('Missing mandatory digest value "username*".'); } } }
/** * {@inheritdoc} */ public function checkElement(DigestDataInterface $digest_data) { if ($this->realm !== $digest_data->get('realm')) { throw new \InvalidArgumentException(sprintf('Response realm name "%s" does not match system realm name of "%s".', $digest_data->get('realm'), $this->realm)); } }
/** * @param \HttpDigest\DigestDataInterface $digest_data * @param bool $is_sess * * @return \HttpDigest\Algorithm\AlgorithmInterface */ private function getAlgorithm(DigestDataInterface $digest_data, &$is_sess) { $algorithm_name = $digest_data->has('algorithm') ? $digest_data->get('algorithm') : 'MD5'; if ('-sess' === substr($algorithm_name, 0, -5)) { $is_sess = true; $algorithm_name = substr($algorithm_name, 0, strlen($algorithm_name) - 5); } else { $is_sess = false; } return $this->getSchemeAlgorithm($algorithm_name); }