diff options
Diffstat (limited to 'apps/encryption/lib/crypto')
-rw-r--r-- | apps/encryption/lib/crypto/crypt.php | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/apps/encryption/lib/crypto/crypt.php b/apps/encryption/lib/crypto/crypt.php index eef16e51447..6c4c108f50a 100644 --- a/apps/encryption/lib/crypto/crypt.php +++ b/apps/encryption/lib/crypto/crypt.php @@ -285,12 +285,13 @@ class Crypt { * * @param string $password * @param string $cipher + * @param string $uid only used for user keys * @return string */ - protected function generatePasswordHash($password, $cipher) { + protected function generatePasswordHash($password, $cipher, $uid = '') { $instanceId = $this->config->getSystemValue('instanceid'); $instanceSecret = $this->config->getSystemValue('secret'); - $salt = hash('sha256', $instanceId . $instanceSecret, true); + $salt = hash('sha256', $uid . $instanceId . $instanceSecret, true); $keySize = $this->getKeySize($cipher); if (function_exists('hash_pbkdf2')) { @@ -324,11 +325,12 @@ class Crypt { * * @param string $privateKey * @param string $password + * @param string $uid for regular users, empty for system keys * @return bool|string */ - public function encryptPrivateKey($privateKey, $password) { + public function encryptPrivateKey($privateKey, $password, $uid = '') { $cipher = $this->getCipher(); - $hash = $this->generatePasswordHash($password, $cipher); + $hash = $this->generatePasswordHash($password, $cipher, $uid); $encryptedKey = $this->symmetricEncryptFileContent( $privateKey, $hash @@ -340,9 +342,10 @@ class Crypt { /** * @param string $privateKey * @param string $password + * @param string $uid for regular users, empty for system keys * @return bool|string */ - public function decryptPrivateKey($privateKey, $password = '') { + public function decryptPrivateKey($privateKey, $password = '', $uid = '') { $header = $this->parseHeader($privateKey); @@ -359,7 +362,7 @@ class Crypt { } if ($keyFormat === 'hash') { - $password = $this->generatePasswordHash($password, $cipher); + $password = $this->generatePasswordHash($password, $cipher, $uid); } // If we found a header we need to remove it from the key we want to decrypt |