@@ -6,30 +6,30 @@ |
||
| 6 | 6 | $baseDir = $vendorDir; |
| 7 | 7 | |
| 8 | 8 | return array( |
| 9 | - 'OCA\\Encryption\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', |
|
| 10 | - 'OCA\\Encryption\\Command\\DisableMasterKey' => $baseDir . '/../lib/Command/DisableMasterKey.php', |
|
| 11 | - 'OCA\\Encryption\\Command\\EnableMasterKey' => $baseDir . '/../lib/Command/EnableMasterKey.php', |
|
| 12 | - 'OCA\\Encryption\\Command\\RecoverUser' => $baseDir . '/../lib/Command/RecoverUser.php', |
|
| 13 | - 'OCA\\Encryption\\Controller\\RecoveryController' => $baseDir . '/../lib/Controller/RecoveryController.php', |
|
| 14 | - 'OCA\\Encryption\\Controller\\SettingsController' => $baseDir . '/../lib/Controller/SettingsController.php', |
|
| 15 | - 'OCA\\Encryption\\Controller\\StatusController' => $baseDir . '/../lib/Controller/StatusController.php', |
|
| 16 | - 'OCA\\Encryption\\Crypto\\Crypt' => $baseDir . '/../lib/Crypto/Crypt.php', |
|
| 17 | - 'OCA\\Encryption\\Crypto\\DecryptAll' => $baseDir . '/../lib/Crypto/DecryptAll.php', |
|
| 18 | - 'OCA\\Encryption\\Crypto\\EncryptAll' => $baseDir . '/../lib/Crypto/EncryptAll.php', |
|
| 19 | - 'OCA\\Encryption\\Crypto\\Encryption' => $baseDir . '/../lib/Crypto/Encryption.php', |
|
| 20 | - 'OCA\\Encryption\\Exceptions\\MultiKeyDecryptException' => $baseDir . '/../lib/Exceptions/MultiKeyDecryptException.php', |
|
| 21 | - 'OCA\\Encryption\\Exceptions\\MultiKeyEncryptException' => $baseDir . '/../lib/Exceptions/MultiKeyEncryptException.php', |
|
| 22 | - 'OCA\\Encryption\\Exceptions\\PrivateKeyMissingException' => $baseDir . '/../lib/Exceptions/PrivateKeyMissingException.php', |
|
| 23 | - 'OCA\\Encryption\\Exceptions\\PublicKeyMissingException' => $baseDir . '/../lib/Exceptions/PublicKeyMissingException.php', |
|
| 24 | - 'OCA\\Encryption\\HookManager' => $baseDir . '/../lib/HookManager.php', |
|
| 25 | - 'OCA\\Encryption\\Hooks\\Contracts\\IHook' => $baseDir . '/../lib/Hooks/Contracts/IHook.php', |
|
| 26 | - 'OCA\\Encryption\\Hooks\\UserHooks' => $baseDir . '/../lib/Hooks/UserHooks.php', |
|
| 27 | - 'OCA\\Encryption\\KeyManager' => $baseDir . '/../lib/KeyManager.php', |
|
| 28 | - 'OCA\\Encryption\\Migration\\SetMasterKeyStatus' => $baseDir . '/../lib/Migration/SetMasterKeyStatus.php', |
|
| 29 | - 'OCA\\Encryption\\Recovery' => $baseDir . '/../lib/Recovery.php', |
|
| 30 | - 'OCA\\Encryption\\Session' => $baseDir . '/../lib/Session.php', |
|
| 31 | - 'OCA\\Encryption\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php', |
|
| 32 | - 'OCA\\Encryption\\Settings\\Personal' => $baseDir . '/../lib/Settings/Personal.php', |
|
| 33 | - 'OCA\\Encryption\\Users\\Setup' => $baseDir . '/../lib/Users/Setup.php', |
|
| 34 | - 'OCA\\Encryption\\Util' => $baseDir . '/../lib/Util.php', |
|
| 9 | + 'OCA\\Encryption\\AppInfo\\Application' => $baseDir.'/../lib/AppInfo/Application.php', |
|
| 10 | + 'OCA\\Encryption\\Command\\DisableMasterKey' => $baseDir.'/../lib/Command/DisableMasterKey.php', |
|
| 11 | + 'OCA\\Encryption\\Command\\EnableMasterKey' => $baseDir.'/../lib/Command/EnableMasterKey.php', |
|
| 12 | + 'OCA\\Encryption\\Command\\RecoverUser' => $baseDir.'/../lib/Command/RecoverUser.php', |
|
| 13 | + 'OCA\\Encryption\\Controller\\RecoveryController' => $baseDir.'/../lib/Controller/RecoveryController.php', |
|
| 14 | + 'OCA\\Encryption\\Controller\\SettingsController' => $baseDir.'/../lib/Controller/SettingsController.php', |
|
| 15 | + 'OCA\\Encryption\\Controller\\StatusController' => $baseDir.'/../lib/Controller/StatusController.php', |
|
| 16 | + 'OCA\\Encryption\\Crypto\\Crypt' => $baseDir.'/../lib/Crypto/Crypt.php', |
|
| 17 | + 'OCA\\Encryption\\Crypto\\DecryptAll' => $baseDir.'/../lib/Crypto/DecryptAll.php', |
|
| 18 | + 'OCA\\Encryption\\Crypto\\EncryptAll' => $baseDir.'/../lib/Crypto/EncryptAll.php', |
|
| 19 | + 'OCA\\Encryption\\Crypto\\Encryption' => $baseDir.'/../lib/Crypto/Encryption.php', |
|
| 20 | + 'OCA\\Encryption\\Exceptions\\MultiKeyDecryptException' => $baseDir.'/../lib/Exceptions/MultiKeyDecryptException.php', |
|
| 21 | + 'OCA\\Encryption\\Exceptions\\MultiKeyEncryptException' => $baseDir.'/../lib/Exceptions/MultiKeyEncryptException.php', |
|
| 22 | + 'OCA\\Encryption\\Exceptions\\PrivateKeyMissingException' => $baseDir.'/../lib/Exceptions/PrivateKeyMissingException.php', |
|
| 23 | + 'OCA\\Encryption\\Exceptions\\PublicKeyMissingException' => $baseDir.'/../lib/Exceptions/PublicKeyMissingException.php', |
|
| 24 | + 'OCA\\Encryption\\HookManager' => $baseDir.'/../lib/HookManager.php', |
|
| 25 | + 'OCA\\Encryption\\Hooks\\Contracts\\IHook' => $baseDir.'/../lib/Hooks/Contracts/IHook.php', |
|
| 26 | + 'OCA\\Encryption\\Hooks\\UserHooks' => $baseDir.'/../lib/Hooks/UserHooks.php', |
|
| 27 | + 'OCA\\Encryption\\KeyManager' => $baseDir.'/../lib/KeyManager.php', |
|
| 28 | + 'OCA\\Encryption\\Migration\\SetMasterKeyStatus' => $baseDir.'/../lib/Migration/SetMasterKeyStatus.php', |
|
| 29 | + 'OCA\\Encryption\\Recovery' => $baseDir.'/../lib/Recovery.php', |
|
| 30 | + 'OCA\\Encryption\\Session' => $baseDir.'/../lib/Session.php', |
|
| 31 | + 'OCA\\Encryption\\Settings\\Admin' => $baseDir.'/../lib/Settings/Admin.php', |
|
| 32 | + 'OCA\\Encryption\\Settings\\Personal' => $baseDir.'/../lib/Settings/Personal.php', |
|
| 33 | + 'OCA\\Encryption\\Users\\Setup' => $baseDir.'/../lib/Users/Setup.php', |
|
| 34 | + 'OCA\\Encryption\\Util' => $baseDir.'/../lib/Util.php', |
|
| 35 | 35 | ); |
@@ -6,52 +6,52 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ComposerStaticInitEncryption |
| 8 | 8 | { |
| 9 | - public static $prefixLengthsPsr4 = array ( |
|
| 9 | + public static $prefixLengthsPsr4 = array( |
|
| 10 | 10 | 'O' => |
| 11 | - array ( |
|
| 11 | + array( |
|
| 12 | 12 | 'OCA\\Encryption\\' => 15, |
| 13 | 13 | ), |
| 14 | 14 | ); |
| 15 | 15 | |
| 16 | - public static $prefixDirsPsr4 = array ( |
|
| 16 | + public static $prefixDirsPsr4 = array( |
|
| 17 | 17 | 'OCA\\Encryption\\' => |
| 18 | - array ( |
|
| 19 | - 0 => __DIR__ . '/..' . '/../lib', |
|
| 18 | + array( |
|
| 19 | + 0 => __DIR__.'/..'.'/../lib', |
|
| 20 | 20 | ), |
| 21 | 21 | ); |
| 22 | 22 | |
| 23 | - public static $classMap = array ( |
|
| 24 | - 'OCA\\Encryption\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', |
|
| 25 | - 'OCA\\Encryption\\Command\\DisableMasterKey' => __DIR__ . '/..' . '/../lib/Command/DisableMasterKey.php', |
|
| 26 | - 'OCA\\Encryption\\Command\\EnableMasterKey' => __DIR__ . '/..' . '/../lib/Command/EnableMasterKey.php', |
|
| 27 | - 'OCA\\Encryption\\Command\\RecoverUser' => __DIR__ . '/..' . '/../lib/Command/RecoverUser.php', |
|
| 28 | - 'OCA\\Encryption\\Controller\\RecoveryController' => __DIR__ . '/..' . '/../lib/Controller/RecoveryController.php', |
|
| 29 | - 'OCA\\Encryption\\Controller\\SettingsController' => __DIR__ . '/..' . '/../lib/Controller/SettingsController.php', |
|
| 30 | - 'OCA\\Encryption\\Controller\\StatusController' => __DIR__ . '/..' . '/../lib/Controller/StatusController.php', |
|
| 31 | - 'OCA\\Encryption\\Crypto\\Crypt' => __DIR__ . '/..' . '/../lib/Crypto/Crypt.php', |
|
| 32 | - 'OCA\\Encryption\\Crypto\\DecryptAll' => __DIR__ . '/..' . '/../lib/Crypto/DecryptAll.php', |
|
| 33 | - 'OCA\\Encryption\\Crypto\\EncryptAll' => __DIR__ . '/..' . '/../lib/Crypto/EncryptAll.php', |
|
| 34 | - 'OCA\\Encryption\\Crypto\\Encryption' => __DIR__ . '/..' . '/../lib/Crypto/Encryption.php', |
|
| 35 | - 'OCA\\Encryption\\Exceptions\\MultiKeyDecryptException' => __DIR__ . '/..' . '/../lib/Exceptions/MultiKeyDecryptException.php', |
|
| 36 | - 'OCA\\Encryption\\Exceptions\\MultiKeyEncryptException' => __DIR__ . '/..' . '/../lib/Exceptions/MultiKeyEncryptException.php', |
|
| 37 | - 'OCA\\Encryption\\Exceptions\\PrivateKeyMissingException' => __DIR__ . '/..' . '/../lib/Exceptions/PrivateKeyMissingException.php', |
|
| 38 | - 'OCA\\Encryption\\Exceptions\\PublicKeyMissingException' => __DIR__ . '/..' . '/../lib/Exceptions/PublicKeyMissingException.php', |
|
| 39 | - 'OCA\\Encryption\\HookManager' => __DIR__ . '/..' . '/../lib/HookManager.php', |
|
| 40 | - 'OCA\\Encryption\\Hooks\\Contracts\\IHook' => __DIR__ . '/..' . '/../lib/Hooks/Contracts/IHook.php', |
|
| 41 | - 'OCA\\Encryption\\Hooks\\UserHooks' => __DIR__ . '/..' . '/../lib/Hooks/UserHooks.php', |
|
| 42 | - 'OCA\\Encryption\\KeyManager' => __DIR__ . '/..' . '/../lib/KeyManager.php', |
|
| 43 | - 'OCA\\Encryption\\Migration\\SetMasterKeyStatus' => __DIR__ . '/..' . '/../lib/Migration/SetMasterKeyStatus.php', |
|
| 44 | - 'OCA\\Encryption\\Recovery' => __DIR__ . '/..' . '/../lib/Recovery.php', |
|
| 45 | - 'OCA\\Encryption\\Session' => __DIR__ . '/..' . '/../lib/Session.php', |
|
| 46 | - 'OCA\\Encryption\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php', |
|
| 47 | - 'OCA\\Encryption\\Settings\\Personal' => __DIR__ . '/..' . '/../lib/Settings/Personal.php', |
|
| 48 | - 'OCA\\Encryption\\Users\\Setup' => __DIR__ . '/..' . '/../lib/Users/Setup.php', |
|
| 49 | - 'OCA\\Encryption\\Util' => __DIR__ . '/..' . '/../lib/Util.php', |
|
| 23 | + public static $classMap = array( |
|
| 24 | + 'OCA\\Encryption\\AppInfo\\Application' => __DIR__.'/..'.'/../lib/AppInfo/Application.php', |
|
| 25 | + 'OCA\\Encryption\\Command\\DisableMasterKey' => __DIR__.'/..'.'/../lib/Command/DisableMasterKey.php', |
|
| 26 | + 'OCA\\Encryption\\Command\\EnableMasterKey' => __DIR__.'/..'.'/../lib/Command/EnableMasterKey.php', |
|
| 27 | + 'OCA\\Encryption\\Command\\RecoverUser' => __DIR__.'/..'.'/../lib/Command/RecoverUser.php', |
|
| 28 | + 'OCA\\Encryption\\Controller\\RecoveryController' => __DIR__.'/..'.'/../lib/Controller/RecoveryController.php', |
|
| 29 | + 'OCA\\Encryption\\Controller\\SettingsController' => __DIR__.'/..'.'/../lib/Controller/SettingsController.php', |
|
| 30 | + 'OCA\\Encryption\\Controller\\StatusController' => __DIR__.'/..'.'/../lib/Controller/StatusController.php', |
|
| 31 | + 'OCA\\Encryption\\Crypto\\Crypt' => __DIR__.'/..'.'/../lib/Crypto/Crypt.php', |
|
| 32 | + 'OCA\\Encryption\\Crypto\\DecryptAll' => __DIR__.'/..'.'/../lib/Crypto/DecryptAll.php', |
|
| 33 | + 'OCA\\Encryption\\Crypto\\EncryptAll' => __DIR__.'/..'.'/../lib/Crypto/EncryptAll.php', |
|
| 34 | + 'OCA\\Encryption\\Crypto\\Encryption' => __DIR__.'/..'.'/../lib/Crypto/Encryption.php', |
|
| 35 | + 'OCA\\Encryption\\Exceptions\\MultiKeyDecryptException' => __DIR__.'/..'.'/../lib/Exceptions/MultiKeyDecryptException.php', |
|
| 36 | + 'OCA\\Encryption\\Exceptions\\MultiKeyEncryptException' => __DIR__.'/..'.'/../lib/Exceptions/MultiKeyEncryptException.php', |
|
| 37 | + 'OCA\\Encryption\\Exceptions\\PrivateKeyMissingException' => __DIR__.'/..'.'/../lib/Exceptions/PrivateKeyMissingException.php', |
|
| 38 | + 'OCA\\Encryption\\Exceptions\\PublicKeyMissingException' => __DIR__.'/..'.'/../lib/Exceptions/PublicKeyMissingException.php', |
|
| 39 | + 'OCA\\Encryption\\HookManager' => __DIR__.'/..'.'/../lib/HookManager.php', |
|
| 40 | + 'OCA\\Encryption\\Hooks\\Contracts\\IHook' => __DIR__.'/..'.'/../lib/Hooks/Contracts/IHook.php', |
|
| 41 | + 'OCA\\Encryption\\Hooks\\UserHooks' => __DIR__.'/..'.'/../lib/Hooks/UserHooks.php', |
|
| 42 | + 'OCA\\Encryption\\KeyManager' => __DIR__.'/..'.'/../lib/KeyManager.php', |
|
| 43 | + 'OCA\\Encryption\\Migration\\SetMasterKeyStatus' => __DIR__.'/..'.'/../lib/Migration/SetMasterKeyStatus.php', |
|
| 44 | + 'OCA\\Encryption\\Recovery' => __DIR__.'/..'.'/../lib/Recovery.php', |
|
| 45 | + 'OCA\\Encryption\\Session' => __DIR__.'/..'.'/../lib/Session.php', |
|
| 46 | + 'OCA\\Encryption\\Settings\\Admin' => __DIR__.'/..'.'/../lib/Settings/Admin.php', |
|
| 47 | + 'OCA\\Encryption\\Settings\\Personal' => __DIR__.'/..'.'/../lib/Settings/Personal.php', |
|
| 48 | + 'OCA\\Encryption\\Users\\Setup' => __DIR__.'/..'.'/../lib/Users/Setup.php', |
|
| 49 | + 'OCA\\Encryption\\Util' => __DIR__.'/..'.'/../lib/Util.php', |
|
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | 52 | public static function getInitializer(ClassLoader $loader) |
| 53 | 53 | { |
| 54 | - return \Closure::bind(function () use ($loader) { |
|
| 54 | + return \Closure::bind(function() use ($loader) { |
|
| 55 | 55 | $loader->prefixLengthsPsr4 = ComposerStaticInitEncryption::$prefixLengthsPsr4; |
| 56 | 56 | $loader->prefixDirsPsr4 = ComposerStaticInitEncryption::$prefixDirsPsr4; |
| 57 | 57 | $loader->classMap = ComposerStaticInitEncryption::$classMap; |
@@ -39,80 +39,80 @@ |
||
| 39 | 39 | |
| 40 | 40 | class RecoverUser extends Command { |
| 41 | 41 | |
| 42 | - /** @var Util */ |
|
| 43 | - protected $util; |
|
| 44 | - |
|
| 45 | - /** @var IUserManager */ |
|
| 46 | - protected $userManager; |
|
| 47 | - |
|
| 48 | - /** @var QuestionHelper */ |
|
| 49 | - protected $questionHelper; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @param Util $util |
|
| 53 | - * @param IConfig $config |
|
| 54 | - * @param IUserManager $userManager |
|
| 55 | - * @param QuestionHelper $questionHelper |
|
| 56 | - */ |
|
| 57 | - public function __construct(Util $util, |
|
| 58 | - IConfig $config, |
|
| 59 | - IUserManager $userManager, |
|
| 60 | - QuestionHelper $questionHelper) { |
|
| 61 | - |
|
| 62 | - $this->util = $util; |
|
| 63 | - $this->questionHelper = $questionHelper; |
|
| 64 | - $this->userManager = $userManager; |
|
| 65 | - parent::__construct(); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - protected function configure() { |
|
| 69 | - $this |
|
| 70 | - ->setName('encryption:recover-user') |
|
| 71 | - ->setDescription('Recover user data in case of password lost. This only works if the user enabled the recovery key.'); |
|
| 72 | - |
|
| 73 | - $this->addArgument( |
|
| 74 | - 'user', |
|
| 75 | - InputArgument::REQUIRED, |
|
| 76 | - 'user which should be recovered' |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 81 | - |
|
| 82 | - $isMasterKeyEnabled = $this->util->isMasterKeyEnabled(); |
|
| 83 | - |
|
| 84 | - if($isMasterKeyEnabled) { |
|
| 85 | - $output->writeln('You use the master key, no individual user recovery needed.'); |
|
| 86 | - return; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $uid = $input->getArgument('user'); |
|
| 90 | - $userExists = $this->userManager->userExists($uid); |
|
| 91 | - if ($userExists === false) { |
|
| 92 | - $output->writeln('User "' . $uid . '" unknown.'); |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $recoveryKeyEnabled = $this->util->isRecoveryEnabledForUser($uid); |
|
| 97 | - if($recoveryKeyEnabled === false) { |
|
| 98 | - $output->writeln('Recovery key is not enabled for: ' . $uid); |
|
| 99 | - return; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $question = new Question('Please enter the recovery key password: '); |
|
| 103 | - $question->setHidden(true); |
|
| 104 | - $question->setHiddenFallback(false); |
|
| 105 | - $recoveryPassword = $this->questionHelper->ask($input, $output, $question); |
|
| 106 | - |
|
| 107 | - $question = new Question('Please enter the new login password for the user: '); |
|
| 108 | - $question->setHidden(true); |
|
| 109 | - $question->setHiddenFallback(false); |
|
| 110 | - $newLoginPassword = $this->questionHelper->ask($input, $output, $question); |
|
| 111 | - |
|
| 112 | - $output->write('Start to recover users files... This can take some time...'); |
|
| 113 | - $this->userManager->get($uid)->setPassword($newLoginPassword, $recoveryPassword); |
|
| 114 | - $output->writeln('Done.'); |
|
| 115 | - |
|
| 116 | - } |
|
| 42 | + /** @var Util */ |
|
| 43 | + protected $util; |
|
| 44 | + |
|
| 45 | + /** @var IUserManager */ |
|
| 46 | + protected $userManager; |
|
| 47 | + |
|
| 48 | + /** @var QuestionHelper */ |
|
| 49 | + protected $questionHelper; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @param Util $util |
|
| 53 | + * @param IConfig $config |
|
| 54 | + * @param IUserManager $userManager |
|
| 55 | + * @param QuestionHelper $questionHelper |
|
| 56 | + */ |
|
| 57 | + public function __construct(Util $util, |
|
| 58 | + IConfig $config, |
|
| 59 | + IUserManager $userManager, |
|
| 60 | + QuestionHelper $questionHelper) { |
|
| 61 | + |
|
| 62 | + $this->util = $util; |
|
| 63 | + $this->questionHelper = $questionHelper; |
|
| 64 | + $this->userManager = $userManager; |
|
| 65 | + parent::__construct(); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + protected function configure() { |
|
| 69 | + $this |
|
| 70 | + ->setName('encryption:recover-user') |
|
| 71 | + ->setDescription('Recover user data in case of password lost. This only works if the user enabled the recovery key.'); |
|
| 72 | + |
|
| 73 | + $this->addArgument( |
|
| 74 | + 'user', |
|
| 75 | + InputArgument::REQUIRED, |
|
| 76 | + 'user which should be recovered' |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
| 81 | + |
|
| 82 | + $isMasterKeyEnabled = $this->util->isMasterKeyEnabled(); |
|
| 83 | + |
|
| 84 | + if($isMasterKeyEnabled) { |
|
| 85 | + $output->writeln('You use the master key, no individual user recovery needed.'); |
|
| 86 | + return; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $uid = $input->getArgument('user'); |
|
| 90 | + $userExists = $this->userManager->userExists($uid); |
|
| 91 | + if ($userExists === false) { |
|
| 92 | + $output->writeln('User "' . $uid . '" unknown.'); |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $recoveryKeyEnabled = $this->util->isRecoveryEnabledForUser($uid); |
|
| 97 | + if($recoveryKeyEnabled === false) { |
|
| 98 | + $output->writeln('Recovery key is not enabled for: ' . $uid); |
|
| 99 | + return; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $question = new Question('Please enter the recovery key password: '); |
|
| 103 | + $question->setHidden(true); |
|
| 104 | + $question->setHiddenFallback(false); |
|
| 105 | + $recoveryPassword = $this->questionHelper->ask($input, $output, $question); |
|
| 106 | + |
|
| 107 | + $question = new Question('Please enter the new login password for the user: '); |
|
| 108 | + $question->setHidden(true); |
|
| 109 | + $question->setHiddenFallback(false); |
|
| 110 | + $newLoginPassword = $this->questionHelper->ask($input, $output, $question); |
|
| 111 | + |
|
| 112 | + $output->write('Start to recover users files... This can take some time...'); |
|
| 113 | + $this->userManager->get($uid)->setPassword($newLoginPassword, $recoveryPassword); |
|
| 114 | + $output->writeln('Done.'); |
|
| 115 | + |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | $isMasterKeyEnabled = $this->util->isMasterKeyEnabled(); |
| 83 | 83 | |
| 84 | - if($isMasterKeyEnabled) { |
|
| 84 | + if ($isMasterKeyEnabled) { |
|
| 85 | 85 | $output->writeln('You use the master key, no individual user recovery needed.'); |
| 86 | 86 | return; |
| 87 | 87 | } |
@@ -89,13 +89,13 @@ discard block |
||
| 89 | 89 | $uid = $input->getArgument('user'); |
| 90 | 90 | $userExists = $this->userManager->userExists($uid); |
| 91 | 91 | if ($userExists === false) { |
| 92 | - $output->writeln('User "' . $uid . '" unknown.'); |
|
| 92 | + $output->writeln('User "'.$uid.'" unknown.'); |
|
| 93 | 93 | return; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $recoveryKeyEnabled = $this->util->isRecoveryEnabledForUser($uid); |
| 97 | - if($recoveryKeyEnabled === false) { |
|
| 98 | - $output->writeln('Recovery key is not enabled for: ' . $uid); |
|
| 97 | + if ($recoveryKeyEnabled === false) { |
|
| 98 | + $output->writeln('Recovery key is not enabled for: '.$uid); |
|
| 99 | 99 | return; |
| 100 | 100 | } |
| 101 | 101 | |
@@ -43,306 +43,306 @@ |
||
| 43 | 43 | |
| 44 | 44 | class UserHooks implements IHook { |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * list of user for which we perform a password reset |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - protected static $passwordResetUsers = []; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var KeyManager |
|
| 54 | - */ |
|
| 55 | - private $keyManager; |
|
| 56 | - /** |
|
| 57 | - * @var IUserManager |
|
| 58 | - */ |
|
| 59 | - private $userManager; |
|
| 60 | - /** |
|
| 61 | - * @var ILogger |
|
| 62 | - */ |
|
| 63 | - private $logger; |
|
| 64 | - /** |
|
| 65 | - * @var Setup |
|
| 66 | - */ |
|
| 67 | - private $userSetup; |
|
| 68 | - /** |
|
| 69 | - * @var IUserSession |
|
| 70 | - */ |
|
| 71 | - private $user; |
|
| 72 | - /** |
|
| 73 | - * @var Util |
|
| 74 | - */ |
|
| 75 | - private $util; |
|
| 76 | - /** |
|
| 77 | - * @var Session |
|
| 78 | - */ |
|
| 79 | - private $session; |
|
| 80 | - /** |
|
| 81 | - * @var Recovery |
|
| 82 | - */ |
|
| 83 | - private $recovery; |
|
| 84 | - /** |
|
| 85 | - * @var Crypt |
|
| 86 | - */ |
|
| 87 | - private $crypt; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * UserHooks constructor. |
|
| 91 | - * |
|
| 92 | - * @param KeyManager $keyManager |
|
| 93 | - * @param IUserManager $userManager |
|
| 94 | - * @param ILogger $logger |
|
| 95 | - * @param Setup $userSetup |
|
| 96 | - * @param IUserSession $user |
|
| 97 | - * @param Util $util |
|
| 98 | - * @param Session $session |
|
| 99 | - * @param Crypt $crypt |
|
| 100 | - * @param Recovery $recovery |
|
| 101 | - */ |
|
| 102 | - public function __construct(KeyManager $keyManager, |
|
| 103 | - IUserManager $userManager, |
|
| 104 | - ILogger $logger, |
|
| 105 | - Setup $userSetup, |
|
| 106 | - IUserSession $user, |
|
| 107 | - Util $util, |
|
| 108 | - Session $session, |
|
| 109 | - Crypt $crypt, |
|
| 110 | - Recovery $recovery) { |
|
| 111 | - |
|
| 112 | - $this->keyManager = $keyManager; |
|
| 113 | - $this->userManager = $userManager; |
|
| 114 | - $this->logger = $logger; |
|
| 115 | - $this->userSetup = $userSetup; |
|
| 116 | - $this->user = $user; |
|
| 117 | - $this->util = $util; |
|
| 118 | - $this->session = $session; |
|
| 119 | - $this->recovery = $recovery; |
|
| 120 | - $this->crypt = $crypt; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Connects Hooks |
|
| 125 | - * |
|
| 126 | - * @return null |
|
| 127 | - */ |
|
| 128 | - public function addHooks() { |
|
| 129 | - OCUtil::connectHook('OC_User', 'post_login', $this, 'login'); |
|
| 130 | - OCUtil::connectHook('OC_User', 'logout', $this, 'logout'); |
|
| 131 | - |
|
| 132 | - // this hooks only make sense if no master key is used |
|
| 133 | - if ($this->util->isMasterKeyEnabled() === false) { |
|
| 134 | - OCUtil::connectHook('OC_User', |
|
| 135 | - 'post_setPassword', |
|
| 136 | - $this, |
|
| 137 | - 'setPassphrase'); |
|
| 138 | - |
|
| 139 | - OCUtil::connectHook('OC_User', |
|
| 140 | - 'pre_setPassword', |
|
| 141 | - $this, |
|
| 142 | - 'preSetPassphrase'); |
|
| 143 | - |
|
| 144 | - OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController', |
|
| 145 | - 'post_passwordReset', |
|
| 146 | - $this, |
|
| 147 | - 'postPasswordReset'); |
|
| 148 | - |
|
| 149 | - OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController', |
|
| 150 | - 'pre_passwordReset', |
|
| 151 | - $this, |
|
| 152 | - 'prePasswordReset'); |
|
| 153 | - |
|
| 154 | - OCUtil::connectHook('OC_User', |
|
| 155 | - 'post_createUser', |
|
| 156 | - $this, |
|
| 157 | - 'postCreateUser'); |
|
| 158 | - |
|
| 159 | - OCUtil::connectHook('OC_User', |
|
| 160 | - 'post_deleteUser', |
|
| 161 | - $this, |
|
| 162 | - 'postDeleteUser'); |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Startup encryption backend upon user login |
|
| 169 | - * |
|
| 170 | - * @note This method should never be called for users using client side encryption |
|
| 171 | - * @param array $params |
|
| 172 | - * @return boolean|null |
|
| 173 | - */ |
|
| 174 | - public function login($params) { |
|
| 175 | - // ensure filesystem is loaded |
|
| 176 | - if (!\OC\Files\Filesystem::$loaded) { |
|
| 177 | - $this->setupFS($params['uid']); |
|
| 178 | - } |
|
| 179 | - if ($this->util->isMasterKeyEnabled() === false) { |
|
| 180 | - $this->userSetup->setupUser($params['uid'], $params['password']); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $this->keyManager->init($params['uid'], $params['password']); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * remove keys from session during logout |
|
| 188 | - */ |
|
| 189 | - public function logout() { |
|
| 190 | - $this->session->clear(); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * setup encryption backend upon user created |
|
| 195 | - * |
|
| 196 | - * @note This method should never be called for users using client side encryption |
|
| 197 | - * @param array $params |
|
| 198 | - */ |
|
| 199 | - public function postCreateUser($params) { |
|
| 200 | - $this->userSetup->setupUser($params['uid'], $params['password']); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * cleanup encryption backend upon user deleted |
|
| 205 | - * |
|
| 206 | - * @param array $params : uid, password |
|
| 207 | - * @note This method should never be called for users using client side encryption |
|
| 208 | - */ |
|
| 209 | - public function postDeleteUser($params) { |
|
| 210 | - $this->keyManager->deletePublicKey($params['uid']); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - public function prePasswordReset($params) { |
|
| 214 | - $user = $params['uid']; |
|
| 215 | - self::$passwordResetUsers[$user] = true; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - public function postPasswordReset($params) { |
|
| 219 | - $uid = $params['uid']; |
|
| 220 | - $password = $params['password']; |
|
| 221 | - $this->keyManager->backupUserKeys('passwordReset', $uid); |
|
| 222 | - $this->keyManager->deleteUserKeys($uid); |
|
| 223 | - $this->userSetup->setupUser($uid, $password); |
|
| 224 | - unset(self::$passwordResetUsers[$uid]); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * If the password can't be changed within Nextcloud, than update the key password in advance. |
|
| 229 | - * |
|
| 230 | - * @param array $params : uid, password |
|
| 231 | - * @return boolean|null |
|
| 232 | - */ |
|
| 233 | - public function preSetPassphrase($params) { |
|
| 234 | - $user = $this->userManager->get($params['uid']); |
|
| 235 | - |
|
| 236 | - if ($user && !$user->canChangePassword()) { |
|
| 237 | - $this->setPassphrase($params); |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Change a user's encryption passphrase |
|
| 243 | - * |
|
| 244 | - * @param array $params keys: uid, password |
|
| 245 | - * @return boolean|null |
|
| 246 | - */ |
|
| 247 | - public function setPassphrase($params) { |
|
| 248 | - |
|
| 249 | - // if we are in the process to resetting a user password, we have nothing |
|
| 250 | - // to do here |
|
| 251 | - if (isset(self::$passwordResetUsers[$params['uid']])) { |
|
| 252 | - return true; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // Get existing decrypted private key |
|
| 256 | - $user = $this->user->getUser(); |
|
| 257 | - |
|
| 258 | - // current logged in user changes his own password |
|
| 259 | - if ($user && $params['uid'] === $user->getUID()) { |
|
| 260 | - |
|
| 261 | - $privateKey = $this->session->getPrivateKey(); |
|
| 262 | - |
|
| 263 | - // Encrypt private key with new user pwd as passphrase |
|
| 264 | - $encryptedPrivateKey = $this->crypt->encryptPrivateKey($privateKey, $params['password'], $params['uid']); |
|
| 265 | - |
|
| 266 | - // Save private key |
|
| 267 | - if ($encryptedPrivateKey) { |
|
| 268 | - $this->keyManager->setPrivateKey($this->user->getUser()->getUID(), |
|
| 269 | - $this->crypt->generateHeader() . $encryptedPrivateKey); |
|
| 270 | - } else { |
|
| 271 | - $this->logger->error('Encryption could not update users encryption password'); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // NOTE: Session does not need to be updated as the |
|
| 275 | - // private key has not changed, only the passphrase |
|
| 276 | - // used to decrypt it has changed |
|
| 277 | - } else { // admin changed the password for a different user, create new keys and re-encrypt file keys |
|
| 278 | - $user = $params['uid']; |
|
| 279 | - $this->initMountPoints($user); |
|
| 280 | - $recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null; |
|
| 281 | - |
|
| 282 | - $recoveryKeyId = $this->keyManager->getRecoveryKeyId(); |
|
| 283 | - $recoveryKey = $this->keyManager->getSystemPrivateKey($recoveryKeyId); |
|
| 284 | - try { |
|
| 285 | - $decryptedRecoveryKey = $this->crypt->decryptPrivateKey($recoveryKey, $recoveryPassword); |
|
| 286 | - } catch (\Exception $e) { |
|
| 287 | - $decryptedRecoveryKey = false; |
|
| 288 | - } |
|
| 289 | - if ($decryptedRecoveryKey === false) { |
|
| 290 | - $message = 'Can not decrypt the recovery key. Maybe you provided the wrong password. Try again.'; |
|
| 291 | - throw new GenericEncryptionException($message, $message); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - // we generate new keys if... |
|
| 295 | - // ...we have a recovery password and the user enabled the recovery key |
|
| 296 | - // ...encryption was activated for the first time (no keys exists) |
|
| 297 | - // ...the user doesn't have any files |
|
| 298 | - if ( |
|
| 299 | - ($this->recovery->isRecoveryEnabledForUser($user) && $recoveryPassword) |
|
| 300 | - || !$this->keyManager->userHasKeys($user) |
|
| 301 | - || !$this->util->userHasFiles($user) |
|
| 302 | - ) { |
|
| 303 | - |
|
| 304 | - // backup old keys |
|
| 305 | - //$this->backupAllKeys('recovery'); |
|
| 306 | - |
|
| 307 | - $newUserPassword = $params['password']; |
|
| 308 | - |
|
| 309 | - $keyPair = $this->crypt->createKeyPair(); |
|
| 310 | - |
|
| 311 | - // Save public key |
|
| 312 | - $this->keyManager->setPublicKey($user, $keyPair['publicKey']); |
|
| 313 | - |
|
| 314 | - // Encrypt private key with new password |
|
| 315 | - $encryptedKey = $this->crypt->encryptPrivateKey($keyPair['privateKey'], $newUserPassword, $user); |
|
| 316 | - |
|
| 317 | - if ($encryptedKey) { |
|
| 318 | - $this->keyManager->setPrivateKey($user, $this->crypt->generateHeader() . $encryptedKey); |
|
| 319 | - |
|
| 320 | - if ($recoveryPassword) { // if recovery key is set we can re-encrypt the key files |
|
| 321 | - $this->recovery->recoverUsersFiles($recoveryPassword, $user); |
|
| 322 | - } |
|
| 323 | - } else { |
|
| 324 | - $this->logger->error('Encryption Could not update users encryption password'); |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * init mount points for given user |
|
| 332 | - * |
|
| 333 | - * @param string $user |
|
| 334 | - * @throws \OC\User\NoUserException |
|
| 335 | - */ |
|
| 336 | - protected function initMountPoints($user) { |
|
| 337 | - Filesystem::initMountPoints($user); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * setup file system for user |
|
| 342 | - * |
|
| 343 | - * @param string $uid user id |
|
| 344 | - */ |
|
| 345 | - protected function setupFS($uid) { |
|
| 346 | - \OC_Util::setupFS($uid); |
|
| 347 | - } |
|
| 46 | + /** |
|
| 47 | + * list of user for which we perform a password reset |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + protected static $passwordResetUsers = []; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var KeyManager |
|
| 54 | + */ |
|
| 55 | + private $keyManager; |
|
| 56 | + /** |
|
| 57 | + * @var IUserManager |
|
| 58 | + */ |
|
| 59 | + private $userManager; |
|
| 60 | + /** |
|
| 61 | + * @var ILogger |
|
| 62 | + */ |
|
| 63 | + private $logger; |
|
| 64 | + /** |
|
| 65 | + * @var Setup |
|
| 66 | + */ |
|
| 67 | + private $userSetup; |
|
| 68 | + /** |
|
| 69 | + * @var IUserSession |
|
| 70 | + */ |
|
| 71 | + private $user; |
|
| 72 | + /** |
|
| 73 | + * @var Util |
|
| 74 | + */ |
|
| 75 | + private $util; |
|
| 76 | + /** |
|
| 77 | + * @var Session |
|
| 78 | + */ |
|
| 79 | + private $session; |
|
| 80 | + /** |
|
| 81 | + * @var Recovery |
|
| 82 | + */ |
|
| 83 | + private $recovery; |
|
| 84 | + /** |
|
| 85 | + * @var Crypt |
|
| 86 | + */ |
|
| 87 | + private $crypt; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * UserHooks constructor. |
|
| 91 | + * |
|
| 92 | + * @param KeyManager $keyManager |
|
| 93 | + * @param IUserManager $userManager |
|
| 94 | + * @param ILogger $logger |
|
| 95 | + * @param Setup $userSetup |
|
| 96 | + * @param IUserSession $user |
|
| 97 | + * @param Util $util |
|
| 98 | + * @param Session $session |
|
| 99 | + * @param Crypt $crypt |
|
| 100 | + * @param Recovery $recovery |
|
| 101 | + */ |
|
| 102 | + public function __construct(KeyManager $keyManager, |
|
| 103 | + IUserManager $userManager, |
|
| 104 | + ILogger $logger, |
|
| 105 | + Setup $userSetup, |
|
| 106 | + IUserSession $user, |
|
| 107 | + Util $util, |
|
| 108 | + Session $session, |
|
| 109 | + Crypt $crypt, |
|
| 110 | + Recovery $recovery) { |
|
| 111 | + |
|
| 112 | + $this->keyManager = $keyManager; |
|
| 113 | + $this->userManager = $userManager; |
|
| 114 | + $this->logger = $logger; |
|
| 115 | + $this->userSetup = $userSetup; |
|
| 116 | + $this->user = $user; |
|
| 117 | + $this->util = $util; |
|
| 118 | + $this->session = $session; |
|
| 119 | + $this->recovery = $recovery; |
|
| 120 | + $this->crypt = $crypt; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Connects Hooks |
|
| 125 | + * |
|
| 126 | + * @return null |
|
| 127 | + */ |
|
| 128 | + public function addHooks() { |
|
| 129 | + OCUtil::connectHook('OC_User', 'post_login', $this, 'login'); |
|
| 130 | + OCUtil::connectHook('OC_User', 'logout', $this, 'logout'); |
|
| 131 | + |
|
| 132 | + // this hooks only make sense if no master key is used |
|
| 133 | + if ($this->util->isMasterKeyEnabled() === false) { |
|
| 134 | + OCUtil::connectHook('OC_User', |
|
| 135 | + 'post_setPassword', |
|
| 136 | + $this, |
|
| 137 | + 'setPassphrase'); |
|
| 138 | + |
|
| 139 | + OCUtil::connectHook('OC_User', |
|
| 140 | + 'pre_setPassword', |
|
| 141 | + $this, |
|
| 142 | + 'preSetPassphrase'); |
|
| 143 | + |
|
| 144 | + OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController', |
|
| 145 | + 'post_passwordReset', |
|
| 146 | + $this, |
|
| 147 | + 'postPasswordReset'); |
|
| 148 | + |
|
| 149 | + OCUtil::connectHook('\OC\Core\LostPassword\Controller\LostController', |
|
| 150 | + 'pre_passwordReset', |
|
| 151 | + $this, |
|
| 152 | + 'prePasswordReset'); |
|
| 153 | + |
|
| 154 | + OCUtil::connectHook('OC_User', |
|
| 155 | + 'post_createUser', |
|
| 156 | + $this, |
|
| 157 | + 'postCreateUser'); |
|
| 158 | + |
|
| 159 | + OCUtil::connectHook('OC_User', |
|
| 160 | + 'post_deleteUser', |
|
| 161 | + $this, |
|
| 162 | + 'postDeleteUser'); |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Startup encryption backend upon user login |
|
| 169 | + * |
|
| 170 | + * @note This method should never be called for users using client side encryption |
|
| 171 | + * @param array $params |
|
| 172 | + * @return boolean|null |
|
| 173 | + */ |
|
| 174 | + public function login($params) { |
|
| 175 | + // ensure filesystem is loaded |
|
| 176 | + if (!\OC\Files\Filesystem::$loaded) { |
|
| 177 | + $this->setupFS($params['uid']); |
|
| 178 | + } |
|
| 179 | + if ($this->util->isMasterKeyEnabled() === false) { |
|
| 180 | + $this->userSetup->setupUser($params['uid'], $params['password']); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $this->keyManager->init($params['uid'], $params['password']); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * remove keys from session during logout |
|
| 188 | + */ |
|
| 189 | + public function logout() { |
|
| 190 | + $this->session->clear(); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * setup encryption backend upon user created |
|
| 195 | + * |
|
| 196 | + * @note This method should never be called for users using client side encryption |
|
| 197 | + * @param array $params |
|
| 198 | + */ |
|
| 199 | + public function postCreateUser($params) { |
|
| 200 | + $this->userSetup->setupUser($params['uid'], $params['password']); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * cleanup encryption backend upon user deleted |
|
| 205 | + * |
|
| 206 | + * @param array $params : uid, password |
|
| 207 | + * @note This method should never be called for users using client side encryption |
|
| 208 | + */ |
|
| 209 | + public function postDeleteUser($params) { |
|
| 210 | + $this->keyManager->deletePublicKey($params['uid']); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + public function prePasswordReset($params) { |
|
| 214 | + $user = $params['uid']; |
|
| 215 | + self::$passwordResetUsers[$user] = true; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + public function postPasswordReset($params) { |
|
| 219 | + $uid = $params['uid']; |
|
| 220 | + $password = $params['password']; |
|
| 221 | + $this->keyManager->backupUserKeys('passwordReset', $uid); |
|
| 222 | + $this->keyManager->deleteUserKeys($uid); |
|
| 223 | + $this->userSetup->setupUser($uid, $password); |
|
| 224 | + unset(self::$passwordResetUsers[$uid]); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * If the password can't be changed within Nextcloud, than update the key password in advance. |
|
| 229 | + * |
|
| 230 | + * @param array $params : uid, password |
|
| 231 | + * @return boolean|null |
|
| 232 | + */ |
|
| 233 | + public function preSetPassphrase($params) { |
|
| 234 | + $user = $this->userManager->get($params['uid']); |
|
| 235 | + |
|
| 236 | + if ($user && !$user->canChangePassword()) { |
|
| 237 | + $this->setPassphrase($params); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Change a user's encryption passphrase |
|
| 243 | + * |
|
| 244 | + * @param array $params keys: uid, password |
|
| 245 | + * @return boolean|null |
|
| 246 | + */ |
|
| 247 | + public function setPassphrase($params) { |
|
| 248 | + |
|
| 249 | + // if we are in the process to resetting a user password, we have nothing |
|
| 250 | + // to do here |
|
| 251 | + if (isset(self::$passwordResetUsers[$params['uid']])) { |
|
| 252 | + return true; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // Get existing decrypted private key |
|
| 256 | + $user = $this->user->getUser(); |
|
| 257 | + |
|
| 258 | + // current logged in user changes his own password |
|
| 259 | + if ($user && $params['uid'] === $user->getUID()) { |
|
| 260 | + |
|
| 261 | + $privateKey = $this->session->getPrivateKey(); |
|
| 262 | + |
|
| 263 | + // Encrypt private key with new user pwd as passphrase |
|
| 264 | + $encryptedPrivateKey = $this->crypt->encryptPrivateKey($privateKey, $params['password'], $params['uid']); |
|
| 265 | + |
|
| 266 | + // Save private key |
|
| 267 | + if ($encryptedPrivateKey) { |
|
| 268 | + $this->keyManager->setPrivateKey($this->user->getUser()->getUID(), |
|
| 269 | + $this->crypt->generateHeader() . $encryptedPrivateKey); |
|
| 270 | + } else { |
|
| 271 | + $this->logger->error('Encryption could not update users encryption password'); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // NOTE: Session does not need to be updated as the |
|
| 275 | + // private key has not changed, only the passphrase |
|
| 276 | + // used to decrypt it has changed |
|
| 277 | + } else { // admin changed the password for a different user, create new keys and re-encrypt file keys |
|
| 278 | + $user = $params['uid']; |
|
| 279 | + $this->initMountPoints($user); |
|
| 280 | + $recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null; |
|
| 281 | + |
|
| 282 | + $recoveryKeyId = $this->keyManager->getRecoveryKeyId(); |
|
| 283 | + $recoveryKey = $this->keyManager->getSystemPrivateKey($recoveryKeyId); |
|
| 284 | + try { |
|
| 285 | + $decryptedRecoveryKey = $this->crypt->decryptPrivateKey($recoveryKey, $recoveryPassword); |
|
| 286 | + } catch (\Exception $e) { |
|
| 287 | + $decryptedRecoveryKey = false; |
|
| 288 | + } |
|
| 289 | + if ($decryptedRecoveryKey === false) { |
|
| 290 | + $message = 'Can not decrypt the recovery key. Maybe you provided the wrong password. Try again.'; |
|
| 291 | + throw new GenericEncryptionException($message, $message); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + // we generate new keys if... |
|
| 295 | + // ...we have a recovery password and the user enabled the recovery key |
|
| 296 | + // ...encryption was activated for the first time (no keys exists) |
|
| 297 | + // ...the user doesn't have any files |
|
| 298 | + if ( |
|
| 299 | + ($this->recovery->isRecoveryEnabledForUser($user) && $recoveryPassword) |
|
| 300 | + || !$this->keyManager->userHasKeys($user) |
|
| 301 | + || !$this->util->userHasFiles($user) |
|
| 302 | + ) { |
|
| 303 | + |
|
| 304 | + // backup old keys |
|
| 305 | + //$this->backupAllKeys('recovery'); |
|
| 306 | + |
|
| 307 | + $newUserPassword = $params['password']; |
|
| 308 | + |
|
| 309 | + $keyPair = $this->crypt->createKeyPair(); |
|
| 310 | + |
|
| 311 | + // Save public key |
|
| 312 | + $this->keyManager->setPublicKey($user, $keyPair['publicKey']); |
|
| 313 | + |
|
| 314 | + // Encrypt private key with new password |
|
| 315 | + $encryptedKey = $this->crypt->encryptPrivateKey($keyPair['privateKey'], $newUserPassword, $user); |
|
| 316 | + |
|
| 317 | + if ($encryptedKey) { |
|
| 318 | + $this->keyManager->setPrivateKey($user, $this->crypt->generateHeader() . $encryptedKey); |
|
| 319 | + |
|
| 320 | + if ($recoveryPassword) { // if recovery key is set we can re-encrypt the key files |
|
| 321 | + $this->recovery->recoverUsersFiles($recoveryPassword, $user); |
|
| 322 | + } |
|
| 323 | + } else { |
|
| 324 | + $this->logger->error('Encryption Could not update users encryption password'); |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * init mount points for given user |
|
| 332 | + * |
|
| 333 | + * @param string $user |
|
| 334 | + * @throws \OC\User\NoUserException |
|
| 335 | + */ |
|
| 336 | + protected function initMountPoints($user) { |
|
| 337 | + Filesystem::initMountPoints($user); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * setup file system for user |
|
| 342 | + * |
|
| 343 | + * @param string $uid user id |
|
| 344 | + */ |
|
| 345 | + protected function setupFS($uid) { |
|
| 346 | + \OC_Util::setupFS($uid); |
|
| 347 | + } |
|
| 348 | 348 | } |