mirror of
https://github.com/nextcloud/passman.git
synced 2025-10-10 21:46:25 +08:00
Merge branch 'fix/642/hash_equals'
This commit is contained in:
commit
ad1e4b8d4a
1 changed files with 6 additions and 15 deletions
|
@ -152,16 +152,16 @@ class EncryptService {
|
||||||
|
|
||||||
list ($cipherKey, $macKey, $iv) = $this->getKeys($salt, $key);
|
list ($cipherKey, $macKey, $iv) = $this->getKeys($salt, $key);
|
||||||
|
|
||||||
if (!$this->hash_equals(hash_hmac('sha512', $enc, $macKey, true), $mac)) {
|
if (hash_equals(hash_hmac('sha512', $enc, $macKey, true), $mac)) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dec = openssl_decrypt($enc, $this->cipher, $cipherKey, true, $iv);
|
$dec = openssl_decrypt($enc, $this->cipher, $cipherKey, true, $iv);
|
||||||
$data = $this->unpad($dec);
|
$data = $this->unpad($dec);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt the supplied data using the supplied key
|
* Encrypt the supplied data using the supplied key
|
||||||
*
|
*
|
||||||
|
@ -206,15 +206,6 @@ class EncryptService {
|
||||||
return array($cipherKey, $macKey, $iv);
|
return array($cipherKey, $macKey, $iv);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function hash_equals($a, $b) {
|
|
||||||
if (function_exists('random_bytes')) {
|
|
||||||
$key = random_bytes(128);
|
|
||||||
} else {
|
|
||||||
$key = openssl_random_pseudo_bytes(128);
|
|
||||||
}
|
|
||||||
return hash_hmac('sha512', $a, $key) === hash_hmac('sha512', $b, $key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stretch the key using the PBKDF2 algorithm
|
* Stretch the key using the PBKDF2 algorithm
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue