Skip to content

Commit 07959ee

Browse files
committed
Use sha256 consistently.
The generation and validation sides of Digest authentication were using different algorithms which results in broken digest authentication. Refs #11103
1 parent 357d617 commit 07959ee

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/Auth/DigestAuthenticate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ protected function validNonce($nonce)
277277
if ($expires < microtime(true)) {
278278
return false;
279279
}
280-
$check = hash_hmac('sha1', $expires . ':' . $this->getConfig('secret'), $this->getConfig('secret'));
280+
$check = hash_hmac('sha256', $expires . ':' . $this->getConfig('secret'), $this->getConfig('secret'));
281281

282282
return hash_equals($check, $checksum);
283283
}

tests/TestCase/Auth/DigestAuthenticateTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ protected function generateNonce($secret = null, $expires = 300, $time = null)
515515
$secret = $secret ?: Configure::read('Security.salt');
516516
$time = $time ?: microtime(true);
517517
$expiryTime = $time + $expires;
518-
$signatureValue = hash_hmac('sha1', $expiryTime . ':' . $secret, $secret);
518+
$signatureValue = hash_hmac('sha256', $expiryTime . ':' . $secret, $secret);
519519
$nonceValue = $expiryTime . ':' . $signatureValue;
520520

521521
return base64_encode($nonceValue);

0 commit comments

Comments
 (0)