@@ -70,9 +70,9 @@ class Crypt {
7070 // default cipher from old Nextcloud versions
7171 public const LEGACY_CIPHER = 'AES-128-CFB ' ;
7272
73- public const SUPPORTED_KEY_FORMATS = ['hash ' , 'password ' ];
73+ public const SUPPORTED_KEY_FORMATS = ['hash2 ' , ' hash ' , 'password ' ];
7474 // one out of SUPPORTED_KEY_FORMATS
75- public const DEFAULT_KEY_FORMAT = 'hash ' ;
75+ public const DEFAULT_KEY_FORMAT = 'hash2 ' ;
7676 // default key format, old Nextcloud version encrypted the private key directly
7777 // with the user password
7878 public const LEGACY_KEY_FORMAT = 'password ' ;
@@ -371,22 +371,20 @@ private function addPadding($data) {
371371 * @param string $uid only used for user keys
372372 * @return string
373373 */
374- protected function generatePasswordHash ($ password , $ cipher , $ uid = '' ) {
374+ protected function generatePasswordHash (string $ password , string $ cipher , string $ uid = '' , int $ iterations = 600000 ): string {
375375 $ instanceId = $ this ->config ->getSystemValue ('instanceid ' );
376376 $ instanceSecret = $ this ->config ->getSystemValue ('secret ' );
377377 $ salt = hash ('sha256 ' , $ uid . $ instanceId . $ instanceSecret , true );
378378 $ keySize = $ this ->getKeySize ($ cipher );
379379
380- $ hash = hash_pbkdf2 (
380+ return hash_pbkdf2 (
381381 'sha256 ' ,
382382 $ password ,
383383 $ salt ,
384- 100000 ,
384+ $ iterations ,
385385 $ keySize ,
386386 true
387387 );
388-
389- return $ hash ;
390388 }
391389
392390 /**
@@ -431,8 +429,10 @@ public function decryptPrivateKey($privateKey, $password = '', $uid = '') {
431429 $ keyFormat = self ::LEGACY_KEY_FORMAT ;
432430 }
433431
434- if ($ keyFormat === self ::DEFAULT_KEY_FORMAT ) {
435- $ password = $ this ->generatePasswordHash ($ password , $ cipher , $ uid );
432+ if ($ keyFormat === 'hash ' ) {
433+ $ password = $ this ->generatePasswordHash ($ password , $ cipher , $ uid , 100000 );
434+ } elseif ($ keyFormat === 'hash2 ' ) {
435+ $ password = $ this ->generatePasswordHash ($ password , $ cipher , $ uid , 600000 );
436436 }
437437
438438 $ binaryEncoding = isset ($ header ['encoding ' ]) && $ header ['encoding ' ] === self ::BINARY_ENCODING_FORMAT ;
0 commit comments