@@ -67,9 +67,9 @@ class Crypt {
6767 // default cipher from old Nextcloud versions
6868 public const LEGACY_CIPHER = 'AES-128-CFB ' ;
6969
70- public const SUPPORTED_KEY_FORMATS = ['hash ' , 'password ' ];
70+ public const SUPPORTED_KEY_FORMATS = ['hash2 ' , ' hash ' , 'password ' ];
7171 // one out of SUPPORTED_KEY_FORMATS
72- public const DEFAULT_KEY_FORMAT = 'hash ' ;
72+ public const DEFAULT_KEY_FORMAT = 'hash2 ' ;
7373 // default key format, old Nextcloud version encrypted the private key directly
7474 // with the user password
7575 public const LEGACY_KEY_FORMAT = 'password ' ;
@@ -360,22 +360,20 @@ private function addPadding($data) {
360360 * @param string $uid only used for user keys
361361 * @return string
362362 */
363- protected function generatePasswordHash ($ password , $ cipher , $ uid = '' ) {
363+ protected function generatePasswordHash (string $ password , string $ cipher , string $ uid = '' , int $ iterations = 600000 ): string {
364364 $ instanceId = $ this ->config ->getSystemValue ('instanceid ' );
365365 $ instanceSecret = $ this ->config ->getSystemValue ('secret ' );
366366 $ salt = hash ('sha256 ' , $ uid . $ instanceId . $ instanceSecret , true );
367367 $ keySize = $ this ->getKeySize ($ cipher );
368368
369- $ hash = hash_pbkdf2 (
369+ return hash_pbkdf2 (
370370 'sha256 ' ,
371371 $ password ,
372372 $ salt ,
373- 100000 ,
373+ $ iterations ,
374374 $ keySize ,
375375 true
376376 );
377-
378- return $ hash ;
379377 }
380378
381379 /**
@@ -420,8 +418,10 @@ public function decryptPrivateKey($privateKey, $password = '', $uid = '') {
420418 $ keyFormat = self ::LEGACY_KEY_FORMAT ;
421419 }
422420
423- if ($ keyFormat === self ::DEFAULT_KEY_FORMAT ) {
424- $ password = $ this ->generatePasswordHash ($ password , $ cipher , $ uid );
421+ if ($ keyFormat === 'hash ' ) {
422+ $ password = $ this ->generatePasswordHash ($ password , $ cipher , $ uid , 100000 );
423+ } elseif ($ keyFormat === 'hash2 ' ) {
424+ $ password = $ this ->generatePasswordHash ($ password , $ cipher , $ uid , 600000 );
425425 }
426426
427427 // If we found a header we need to remove it from the key we want to decrypt
0 commit comments