Skip to content

Commit

Permalink
Use sha256 consistently.
Browse files Browse the repository at this point in the history
The generation and validation sides of Digest authentication were using
different algorithms which results in broken digest authentication.

Refs #11103
  • Loading branch information
markstory committed Nov 22, 2017
1 parent 357d617 commit 07959ee
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Auth/DigestAuthenticate.php
Expand Up @@ -277,7 +277,7 @@ protected function validNonce($nonce)
if ($expires < microtime(true)) {
return false;
}
$check = hash_hmac('sha1', $expires . ':' . $this->getConfig('secret'), $this->getConfig('secret'));
$check = hash_hmac('sha256', $expires . ':' . $this->getConfig('secret'), $this->getConfig('secret'));

return hash_equals($check, $checksum);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Auth/DigestAuthenticateTest.php
Expand Up @@ -515,7 +515,7 @@ protected function generateNonce($secret = null, $expires = 300, $time = null)
$secret = $secret ?: Configure::read('Security.salt');
$time = $time ?: microtime(true);
$expiryTime = $time + $expires;
$signatureValue = hash_hmac('sha1', $expiryTime . ':' . $secret, $secret);
$signatureValue = hash_hmac('sha256', $expiryTime . ':' . $secret, $secret);
$nonceValue = $expiryTime . ':' . $signatureValue;

return base64_encode($nonceValue);
Expand Down

0 comments on commit 07959ee

Please sign in to comment.