@@ -31,19 +31,19 @@ |
||
| 31 | 31 | |
| 32 | 32 | class AddClenupLoginFlowV2BackgroundJob implements IRepairStep { |
| 33 | 33 | |
| 34 | - /** @var IJobList */ |
|
| 35 | - private $jobList; |
|
| 34 | + /** @var IJobList */ |
|
| 35 | + private $jobList; |
|
| 36 | 36 | |
| 37 | - public function __construct(IJobList $jobList) { |
|
| 38 | - $this->jobList = $jobList; |
|
| 39 | - } |
|
| 37 | + public function __construct(IJobList $jobList) { |
|
| 38 | + $this->jobList = $jobList; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - public function getName(): string { |
|
| 42 | - return 'Add background job to cleanup login flow v2 tokens'; |
|
| 43 | - } |
|
| 41 | + public function getName(): string { |
|
| 42 | + return 'Add background job to cleanup login flow v2 tokens'; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function run(IOutput $output) { |
|
| 46 | - $this->jobList->add(CleanupLoginFlowV2::class); |
|
| 47 | - } |
|
| 45 | + public function run(IOutput $output) { |
|
| 46 | + $this->jobList->add(CleanupLoginFlowV2::class); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | } |
@@ -62,177 +62,177 @@ |
||
| 62 | 62 | |
| 63 | 63 | class Repair implements IOutput { |
| 64 | 64 | |
| 65 | - /** @var IRepairStep[] */ |
|
| 66 | - private $repairSteps; |
|
| 67 | - |
|
| 68 | - /** @var EventDispatcherInterface */ |
|
| 69 | - private $dispatcher; |
|
| 70 | - |
|
| 71 | - /** @var string */ |
|
| 72 | - private $currentStep; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Creates a new repair step runner |
|
| 76 | - * |
|
| 77 | - * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 78 | - * @param EventDispatcherInterface $dispatcher |
|
| 79 | - */ |
|
| 80 | - public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) { |
|
| 81 | - $this->repairSteps = $repairSteps; |
|
| 82 | - $this->dispatcher = $dispatcher; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Run a series of repair steps for common problems |
|
| 87 | - */ |
|
| 88 | - public function run() { |
|
| 89 | - if (count($this->repairSteps) === 0) { |
|
| 90 | - $this->emit('\OC\Repair', 'info', array('No repair steps available')); |
|
| 91 | - |
|
| 92 | - return; |
|
| 93 | - } |
|
| 94 | - // run each repair step |
|
| 95 | - foreach ($this->repairSteps as $step) { |
|
| 96 | - $this->currentStep = $step->getName(); |
|
| 97 | - $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 98 | - $step->run($this); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Add repair step |
|
| 104 | - * |
|
| 105 | - * @param IRepairStep|string $repairStep repair step |
|
| 106 | - * @throws \Exception |
|
| 107 | - */ |
|
| 108 | - public function addStep($repairStep) { |
|
| 109 | - if (is_string($repairStep)) { |
|
| 110 | - try { |
|
| 111 | - $s = \OC::$server->query($repairStep); |
|
| 112 | - } catch (QueryException $e) { |
|
| 113 | - if (class_exists($repairStep)) { |
|
| 114 | - $s = new $repairStep(); |
|
| 115 | - } else { |
|
| 116 | - throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if ($s instanceof IRepairStep) { |
|
| 121 | - $this->repairSteps[] = $s; |
|
| 122 | - } else { |
|
| 123 | - throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 124 | - } |
|
| 125 | - } else { |
|
| 126 | - $this->repairSteps[] = $repairStep; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Returns the default repair steps to be run on the |
|
| 132 | - * command line or after an upgrade. |
|
| 133 | - * |
|
| 134 | - * @return IRepairStep[] |
|
| 135 | - */ |
|
| 136 | - public static function getRepairSteps() { |
|
| 137 | - return [ |
|
| 138 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 139 | - new RepairMimeTypes(\OC::$server->getConfig()), |
|
| 140 | - new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 141 | - new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 142 | - new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()), |
|
| 143 | - new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 144 | - new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 145 | - new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 146 | - new AddLogRotateJob(\OC::$server->getJobList()), |
|
| 147 | - new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), |
|
| 148 | - new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), |
|
| 149 | - new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), |
|
| 150 | - new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), |
|
| 151 | - new RepairPendingCronJobs(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 152 | - new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getLogger()), |
|
| 153 | - new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), |
|
| 154 | - new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), |
|
| 155 | - ]; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Returns expensive repair steps to be run on the |
|
| 160 | - * command line with a special option. |
|
| 161 | - * |
|
| 162 | - * @return IRepairStep[] |
|
| 163 | - */ |
|
| 164 | - public static function getExpensiveRepairSteps() { |
|
| 165 | - return [ |
|
| 166 | - new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()) |
|
| 167 | - ]; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Returns the repair steps to be run before an |
|
| 172 | - * upgrade. |
|
| 173 | - * |
|
| 174 | - * @return IRepairStep[] |
|
| 175 | - */ |
|
| 176 | - public static function getBeforeUpgradeRepairSteps() { |
|
| 177 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 178 | - $config = \OC::$server->getConfig(); |
|
| 179 | - $steps = [ |
|
| 180 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
| 181 | - new SqliteAutoincrement($connection), |
|
| 182 | - new SaveAccountsTableData($connection, $config), |
|
| 183 | - new DropAccountTermsTable($connection) |
|
| 184 | - ]; |
|
| 185 | - |
|
| 186 | - return $steps; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * @param string $scope |
|
| 191 | - * @param string $method |
|
| 192 | - * @param array $arguments |
|
| 193 | - */ |
|
| 194 | - public function emit($scope, $method, array $arguments = []) { |
|
| 195 | - if (!is_null($this->dispatcher)) { |
|
| 196 | - $this->dispatcher->dispatch("$scope::$method", |
|
| 197 | - new GenericEvent("$scope::$method", $arguments)); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - public function info($string) { |
|
| 202 | - // for now just emit as we did in the past |
|
| 203 | - $this->emit('\OC\Repair', 'info', array($string)); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * @param string $message |
|
| 208 | - */ |
|
| 209 | - public function warning($message) { |
|
| 210 | - // for now just emit as we did in the past |
|
| 211 | - $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * @param int $max |
|
| 216 | - */ |
|
| 217 | - public function startProgress($max = 0) { |
|
| 218 | - // for now just emit as we did in the past |
|
| 219 | - $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * @param int $step |
|
| 224 | - * @param string $description |
|
| 225 | - */ |
|
| 226 | - public function advance($step = 1, $description = '') { |
|
| 227 | - // for now just emit as we did in the past |
|
| 228 | - $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * @param int $max |
|
| 233 | - */ |
|
| 234 | - public function finishProgress() { |
|
| 235 | - // for now just emit as we did in the past |
|
| 236 | - $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 237 | - } |
|
| 65 | + /** @var IRepairStep[] */ |
|
| 66 | + private $repairSteps; |
|
| 67 | + |
|
| 68 | + /** @var EventDispatcherInterface */ |
|
| 69 | + private $dispatcher; |
|
| 70 | + |
|
| 71 | + /** @var string */ |
|
| 72 | + private $currentStep; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Creates a new repair step runner |
|
| 76 | + * |
|
| 77 | + * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 78 | + * @param EventDispatcherInterface $dispatcher |
|
| 79 | + */ |
|
| 80 | + public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) { |
|
| 81 | + $this->repairSteps = $repairSteps; |
|
| 82 | + $this->dispatcher = $dispatcher; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Run a series of repair steps for common problems |
|
| 87 | + */ |
|
| 88 | + public function run() { |
|
| 89 | + if (count($this->repairSteps) === 0) { |
|
| 90 | + $this->emit('\OC\Repair', 'info', array('No repair steps available')); |
|
| 91 | + |
|
| 92 | + return; |
|
| 93 | + } |
|
| 94 | + // run each repair step |
|
| 95 | + foreach ($this->repairSteps as $step) { |
|
| 96 | + $this->currentStep = $step->getName(); |
|
| 97 | + $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 98 | + $step->run($this); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Add repair step |
|
| 104 | + * |
|
| 105 | + * @param IRepairStep|string $repairStep repair step |
|
| 106 | + * @throws \Exception |
|
| 107 | + */ |
|
| 108 | + public function addStep($repairStep) { |
|
| 109 | + if (is_string($repairStep)) { |
|
| 110 | + try { |
|
| 111 | + $s = \OC::$server->query($repairStep); |
|
| 112 | + } catch (QueryException $e) { |
|
| 113 | + if (class_exists($repairStep)) { |
|
| 114 | + $s = new $repairStep(); |
|
| 115 | + } else { |
|
| 116 | + throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if ($s instanceof IRepairStep) { |
|
| 121 | + $this->repairSteps[] = $s; |
|
| 122 | + } else { |
|
| 123 | + throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 124 | + } |
|
| 125 | + } else { |
|
| 126 | + $this->repairSteps[] = $repairStep; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Returns the default repair steps to be run on the |
|
| 132 | + * command line or after an upgrade. |
|
| 133 | + * |
|
| 134 | + * @return IRepairStep[] |
|
| 135 | + */ |
|
| 136 | + public static function getRepairSteps() { |
|
| 137 | + return [ |
|
| 138 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 139 | + new RepairMimeTypes(\OC::$server->getConfig()), |
|
| 140 | + new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 141 | + new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 142 | + new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()), |
|
| 143 | + new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 144 | + new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 145 | + new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 146 | + new AddLogRotateJob(\OC::$server->getJobList()), |
|
| 147 | + new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), |
|
| 148 | + new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), |
|
| 149 | + new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), |
|
| 150 | + new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), |
|
| 151 | + new RepairPendingCronJobs(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 152 | + new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getLogger()), |
|
| 153 | + new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), |
|
| 154 | + new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), |
|
| 155 | + ]; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Returns expensive repair steps to be run on the |
|
| 160 | + * command line with a special option. |
|
| 161 | + * |
|
| 162 | + * @return IRepairStep[] |
|
| 163 | + */ |
|
| 164 | + public static function getExpensiveRepairSteps() { |
|
| 165 | + return [ |
|
| 166 | + new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()) |
|
| 167 | + ]; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Returns the repair steps to be run before an |
|
| 172 | + * upgrade. |
|
| 173 | + * |
|
| 174 | + * @return IRepairStep[] |
|
| 175 | + */ |
|
| 176 | + public static function getBeforeUpgradeRepairSteps() { |
|
| 177 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 178 | + $config = \OC::$server->getConfig(); |
|
| 179 | + $steps = [ |
|
| 180 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
| 181 | + new SqliteAutoincrement($connection), |
|
| 182 | + new SaveAccountsTableData($connection, $config), |
|
| 183 | + new DropAccountTermsTable($connection) |
|
| 184 | + ]; |
|
| 185 | + |
|
| 186 | + return $steps; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * @param string $scope |
|
| 191 | + * @param string $method |
|
| 192 | + * @param array $arguments |
|
| 193 | + */ |
|
| 194 | + public function emit($scope, $method, array $arguments = []) { |
|
| 195 | + if (!is_null($this->dispatcher)) { |
|
| 196 | + $this->dispatcher->dispatch("$scope::$method", |
|
| 197 | + new GenericEvent("$scope::$method", $arguments)); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + public function info($string) { |
|
| 202 | + // for now just emit as we did in the past |
|
| 203 | + $this->emit('\OC\Repair', 'info', array($string)); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * @param string $message |
|
| 208 | + */ |
|
| 209 | + public function warning($message) { |
|
| 210 | + // for now just emit as we did in the past |
|
| 211 | + $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * @param int $max |
|
| 216 | + */ |
|
| 217 | + public function startProgress($max = 0) { |
|
| 218 | + // for now just emit as we did in the past |
|
| 219 | + $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * @param int $step |
|
| 224 | + * @param string $description |
|
| 225 | + */ |
|
| 226 | + public function advance($step = 1, $description = '') { |
|
| 227 | + // for now just emit as we did in the past |
|
| 228 | + $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * @param int $max |
|
| 233 | + */ |
|
| 234 | + public function finishProgress() { |
|
| 235 | + // for now just emit as we did in the past |
|
| 236 | + $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 237 | + } |
|
| 238 | 238 | } |
@@ -26,22 +26,22 @@ |
||
| 26 | 26 | |
| 27 | 27 | class LoginFlowV2Tokens { |
| 28 | 28 | |
| 29 | - /** @var string */ |
|
| 30 | - private $loginToken; |
|
| 31 | - /** @var string */ |
|
| 32 | - private $pollToken; |
|
| 29 | + /** @var string */ |
|
| 30 | + private $loginToken; |
|
| 31 | + /** @var string */ |
|
| 32 | + private $pollToken; |
|
| 33 | 33 | |
| 34 | - public function __construct(string $loginToken, string $pollToken) { |
|
| 35 | - $this->loginToken = $loginToken; |
|
| 36 | - $this->pollToken = $pollToken; |
|
| 37 | - } |
|
| 34 | + public function __construct(string $loginToken, string $pollToken) { |
|
| 35 | + $this->loginToken = $loginToken; |
|
| 36 | + $this->pollToken = $pollToken; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - public function getPollToken(): string { |
|
| 40 | - return $this->pollToken; |
|
| 39 | + public function getPollToken(): string { |
|
| 40 | + return $this->pollToken; |
|
| 41 | 41 | |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - public function getLoginToken(): string { |
|
| 45 | - return $this->loginToken; |
|
| 46 | - } |
|
| 44 | + public function getLoginToken(): string { |
|
| 45 | + return $this->loginToken; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -25,47 +25,47 @@ |
||
| 25 | 25 | namespace OC\Core\Data; |
| 26 | 26 | |
| 27 | 27 | class LoginFlowV2Credentials implements \JsonSerializable { |
| 28 | - /** @var string */ |
|
| 29 | - private $server; |
|
| 30 | - /** @var string */ |
|
| 31 | - private $loginName; |
|
| 32 | - /** @var string */ |
|
| 33 | - private $appPassword; |
|
| 28 | + /** @var string */ |
|
| 29 | + private $server; |
|
| 30 | + /** @var string */ |
|
| 31 | + private $loginName; |
|
| 32 | + /** @var string */ |
|
| 33 | + private $appPassword; |
|
| 34 | 34 | |
| 35 | - public function __construct(string $server, string $loginName, string $appPassword) { |
|
| 36 | - $this->server = $server; |
|
| 37 | - $this->loginName = $loginName; |
|
| 38 | - $this->appPassword = $appPassword; |
|
| 39 | - } |
|
| 35 | + public function __construct(string $server, string $loginName, string $appPassword) { |
|
| 36 | + $this->server = $server; |
|
| 37 | + $this->loginName = $loginName; |
|
| 38 | + $this->appPassword = $appPassword; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @return string |
|
| 43 | - */ |
|
| 44 | - public function getServer(): string { |
|
| 45 | - return $this->server; |
|
| 46 | - } |
|
| 41 | + /** |
|
| 42 | + * @return string |
|
| 43 | + */ |
|
| 44 | + public function getServer(): string { |
|
| 45 | + return $this->server; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function getLoginName(): string { |
|
| 52 | - return $this->loginName; |
|
| 53 | - } |
|
| 48 | + /** |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function getLoginName(): string { |
|
| 52 | + return $this->loginName; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @return string |
|
| 57 | - */ |
|
| 58 | - public function getAppPassword(): string { |
|
| 59 | - return $this->appPassword; |
|
| 60 | - } |
|
| 55 | + /** |
|
| 56 | + * @return string |
|
| 57 | + */ |
|
| 58 | + public function getAppPassword(): string { |
|
| 59 | + return $this->appPassword; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function jsonSerialize(): array { |
|
| 63 | - return [ |
|
| 64 | - 'server' => $this->server, |
|
| 65 | - 'loginName' => $this->loginName, |
|
| 66 | - 'appPassword' => $this->appPassword, |
|
| 67 | - ]; |
|
| 68 | - } |
|
| 62 | + public function jsonSerialize(): array { |
|
| 63 | + return [ |
|
| 64 | + 'server' => $this->server, |
|
| 65 | + 'loginName' => $this->loginName, |
|
| 66 | + 'appPassword' => $this->appPassword, |
|
| 67 | + ]; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | |
| 71 | 71 | } |
@@ -31,9 +31,9 @@ |
||
| 31 | 31 | <h2><?php p($l->t('Account access')) ?></h2> |
| 32 | 32 | <p class="info"> |
| 33 | 33 | <?php print_unescaped($l->t('You are about to grant %1$s access to your %2$s account.', [ |
| 34 | - '<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>', |
|
| 35 | - \OCP\Util::sanitizeHTML($_['instanceName']) |
|
| 36 | - ])) ?> |
|
| 34 | + '<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>', |
|
| 35 | + \OCP\Util::sanitizeHTML($_['instanceName']) |
|
| 36 | + ])) ?> |
|
| 37 | 37 | </p> |
| 38 | 38 | |
| 39 | 39 | <br/> |
@@ -31,7 +31,7 @@ |
||
| 31 | 31 | <h2><?php p($l->t('Account access')) ?></h2> |
| 32 | 32 | <p class="info"> |
| 33 | 33 | <?php print_unescaped($l->t('You are about to grant %1$s access to your %2$s account.', [ |
| 34 | - '<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>', |
|
| 34 | + '<strong>'.\OCP\Util::sanitizeHTML($_['client']).'</strong>', |
|
| 35 | 35 | \OCP\Util::sanitizeHTML($_['instanceName']) |
| 36 | 36 | ])) ?> |
| 37 | 37 | </p> |
@@ -31,9 +31,9 @@ |
||
| 31 | 31 | <h2><?php p($l->t('Connect to your account')) ?></h2> |
| 32 | 32 | <p class="info"> |
| 33 | 33 | <?php print_unescaped($l->t('Please log in before granting %1$s access to your %2$s account.', [ |
| 34 | - '<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>', |
|
| 35 | - \OCP\Util::sanitizeHTML($_['instanceName']) |
|
| 36 | - ])) ?> |
|
| 34 | + '<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>', |
|
| 35 | + \OCP\Util::sanitizeHTML($_['instanceName']) |
|
| 36 | + ])) ?> |
|
| 37 | 37 | </p> |
| 38 | 38 | |
| 39 | 39 | <br/> |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | <h2><?php p($l->t('Connect to your account')) ?></h2> |
| 31 | 31 | <p class="info"> |
| 32 | 32 | <?php print_unescaped($l->t('Please log in before granting %1$s access to your %2$s account.', [ |
| 33 | - '<strong>' . \OCP\Util::sanitizeHTML($_['client']) . '</strong>', |
|
| 33 | + '<strong>'.\OCP\Util::sanitizeHTML($_['client']).'</strong>', |
|
| 34 | 34 | \OCP\Util::sanitizeHTML($_['instanceName']) |
| 35 | 35 | ])) ?> |
| 36 | 36 | </p> |
@@ -42,219 +42,219 @@ |
||
| 42 | 42 | |
| 43 | 43 | class LoginFlowV2Service { |
| 44 | 44 | |
| 45 | - /** @var LoginFlowV2Mapper */ |
|
| 46 | - private $mapper; |
|
| 47 | - /** @var ISecureRandom */ |
|
| 48 | - private $random; |
|
| 49 | - /** @var ITimeFactory */ |
|
| 50 | - private $time; |
|
| 51 | - /** @var IConfig */ |
|
| 52 | - private $config; |
|
| 53 | - /** @var ICrypto */ |
|
| 54 | - private $crypto; |
|
| 55 | - /** @var ILogger */ |
|
| 56 | - private $logger; |
|
| 57 | - /** @var IProvider */ |
|
| 58 | - private $tokenProvider; |
|
| 59 | - |
|
| 60 | - public function __construct(LoginFlowV2Mapper $mapper, |
|
| 61 | - ISecureRandom $random, |
|
| 62 | - ITimeFactory $time, |
|
| 63 | - IConfig $config, |
|
| 64 | - ICrypto $crypto, |
|
| 65 | - ILogger $logger, |
|
| 66 | - IProvider $tokenProvider) { |
|
| 67 | - $this->mapper = $mapper; |
|
| 68 | - $this->random = $random; |
|
| 69 | - $this->time = $time; |
|
| 70 | - $this->config = $config; |
|
| 71 | - $this->crypto = $crypto; |
|
| 72 | - $this->logger = $logger; |
|
| 73 | - $this->tokenProvider = $tokenProvider; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param string $pollToken |
|
| 78 | - * @return LoginFlowV2Credentials |
|
| 79 | - * @throws LoginFlowV2NotFoundException |
|
| 80 | - */ |
|
| 81 | - public function poll(string $pollToken): LoginFlowV2Credentials { |
|
| 82 | - try { |
|
| 83 | - $data = $this->mapper->getByPollToken($this->hashToken($pollToken)); |
|
| 84 | - } catch (DoesNotExistException $e) { |
|
| 85 | - throw new LoginFlowV2NotFoundException('Invalid token'); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $loginName = $data->getLoginName(); |
|
| 89 | - $server = $data->getServer(); |
|
| 90 | - $appPassword = $data->getAppPassword(); |
|
| 91 | - |
|
| 92 | - if ($loginName === null || $server === null || $appPassword === null) { |
|
| 93 | - throw new LoginFlowV2NotFoundException('Token not yet ready'); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - // Remove the data from the DB |
|
| 97 | - $this->mapper->delete($data); |
|
| 98 | - |
|
| 99 | - try { |
|
| 100 | - // Decrypt the apptoken |
|
| 101 | - $privateKey = $this->crypto->decrypt($data->getPrivateKey(), $pollToken); |
|
| 102 | - $appPassword = $this->decryptPassword($data->getAppPassword(), $privateKey); |
|
| 103 | - } catch (\Exception $e) { |
|
| 104 | - throw new LoginFlowV2NotFoundException('Apptoken could not be decrypted'); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return new LoginFlowV2Credentials($server, $loginName, $appPassword); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param string $loginToken |
|
| 112 | - * @return LoginFlowV2 |
|
| 113 | - * @throws LoginFlowV2NotFoundException |
|
| 114 | - */ |
|
| 115 | - public function getByLoginToken(string $loginToken): LoginFlowV2 { |
|
| 116 | - try { |
|
| 117 | - return $this->mapper->getByLoginToken($loginToken); |
|
| 118 | - } catch (DoesNotExistException $e) { |
|
| 119 | - throw new LoginFlowV2NotFoundException('Login token invalid'); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @param string $loginToken |
|
| 125 | - * @return bool returns true if the start was successfull. False if not. |
|
| 126 | - */ |
|
| 127 | - public function startLoginFlow(string $loginToken): bool { |
|
| 128 | - try { |
|
| 129 | - $data = $this->mapper->getByLoginToken($loginToken); |
|
| 130 | - } catch (DoesNotExistException $e) { |
|
| 131 | - return false; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if ($data->getStarted() !== 0) { |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $data->setStarted(1); |
|
| 139 | - $this->mapper->update($data); |
|
| 140 | - |
|
| 141 | - return true; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param string $loginToken |
|
| 146 | - * @param string $sessionId |
|
| 147 | - * @param string $server |
|
| 148 | - * @param string $userId |
|
| 149 | - * @return bool true if the flow was successfully completed false otherwise |
|
| 150 | - */ |
|
| 151 | - public function flowDone(string $loginToken, string $sessionId, string $server, string $userId): bool { |
|
| 152 | - try { |
|
| 153 | - $data = $this->mapper->getByLoginToken($loginToken); |
|
| 154 | - } catch (DoesNotExistException $e) { |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - try { |
|
| 159 | - $sessionToken = $this->tokenProvider->getToken($sessionId); |
|
| 160 | - $loginName = $sessionToken->getLoginName(); |
|
| 161 | - try { |
|
| 162 | - $password = $this->tokenProvider->getPassword($sessionToken, $sessionId); |
|
| 163 | - } catch (PasswordlessTokenException $ex) { |
|
| 164 | - $password = null; |
|
| 165 | - } |
|
| 166 | - } catch (InvalidTokenException $ex) { |
|
| 167 | - return false; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $appPassword = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS); |
|
| 171 | - $this->tokenProvider->generateToken( |
|
| 172 | - $appPassword, |
|
| 173 | - $userId, |
|
| 174 | - $loginName, |
|
| 175 | - $password, |
|
| 176 | - $data->getClientName(), |
|
| 177 | - IToken::PERMANENT_TOKEN, |
|
| 178 | - IToken::DO_NOT_REMEMBER |
|
| 179 | - ); |
|
| 180 | - |
|
| 181 | - $data->setLoginName($loginName); |
|
| 182 | - $data->setServer($server); |
|
| 183 | - |
|
| 184 | - // Properly encrypt |
|
| 185 | - $data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey())); |
|
| 186 | - |
|
| 187 | - $this->mapper->update($data); |
|
| 188 | - return true; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - public function createTokens(string $userAgent): LoginFlowV2Tokens { |
|
| 192 | - $flow = new LoginFlowV2(); |
|
| 193 | - $pollToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER); |
|
| 194 | - $loginToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER); |
|
| 195 | - $flow->setPollToken($this->hashToken($pollToken)); |
|
| 196 | - $flow->setLoginToken($loginToken); |
|
| 197 | - $flow->setStarted(0); |
|
| 198 | - $flow->setTimestamp($this->time->getTime()); |
|
| 199 | - $flow->setClientName($userAgent); |
|
| 200 | - |
|
| 201 | - [$publicKey, $privateKey] = $this->getKeyPair(); |
|
| 202 | - $privateKey = $this->crypto->encrypt($privateKey, $pollToken); |
|
| 203 | - |
|
| 204 | - $flow->setPublicKey($publicKey); |
|
| 205 | - $flow->setPrivateKey($privateKey); |
|
| 206 | - |
|
| 207 | - $this->mapper->insert($flow); |
|
| 208 | - |
|
| 209 | - return new LoginFlowV2Tokens($loginToken, $pollToken); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - private function hashToken(string $token): string { |
|
| 213 | - $secret = $this->config->getSystemValue('secret'); |
|
| 214 | - return hash('sha512', $token . $secret); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - private function getKeyPair(): array { |
|
| 218 | - $config = array_merge([ |
|
| 219 | - 'digest_alg' => 'sha512', |
|
| 220 | - 'private_key_bits' => 2048, |
|
| 221 | - ], $this->config->getSystemValue('openssl', [])); |
|
| 222 | - |
|
| 223 | - // Generate new key |
|
| 224 | - $res = openssl_pkey_new($config); |
|
| 225 | - if ($res === false) { |
|
| 226 | - $this->logOpensslError(); |
|
| 227 | - throw new \RuntimeException('Could not initialize keys'); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - openssl_pkey_export($res, $privateKey); |
|
| 231 | - |
|
| 232 | - // Extract the public key from $res to $pubKey |
|
| 233 | - $publicKey = openssl_pkey_get_details($res); |
|
| 234 | - $publicKey = $publicKey['key']; |
|
| 235 | - |
|
| 236 | - return [$publicKey, $privateKey]; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - private function logOpensslError(): void { |
|
| 240 | - $errors = []; |
|
| 241 | - while ($error = openssl_error_string()) { |
|
| 242 | - $errors[] = $error; |
|
| 243 | - } |
|
| 244 | - $this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors)); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - private function encryptPassword(string $password, string $publicKey): string { |
|
| 248 | - openssl_public_encrypt($password, $encryptedPassword, $publicKey, OPENSSL_PKCS1_OAEP_PADDING); |
|
| 249 | - $encryptedPassword = base64_encode($encryptedPassword); |
|
| 250 | - |
|
| 251 | - return $encryptedPassword; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - private function decryptPassword(string $encryptedPassword, string $privateKey): string { |
|
| 255 | - $encryptedPassword = base64_decode($encryptedPassword); |
|
| 256 | - openssl_private_decrypt($encryptedPassword, $password, $privateKey, OPENSSL_PKCS1_OAEP_PADDING); |
|
| 257 | - |
|
| 258 | - return $password; |
|
| 259 | - } |
|
| 45 | + /** @var LoginFlowV2Mapper */ |
|
| 46 | + private $mapper; |
|
| 47 | + /** @var ISecureRandom */ |
|
| 48 | + private $random; |
|
| 49 | + /** @var ITimeFactory */ |
|
| 50 | + private $time; |
|
| 51 | + /** @var IConfig */ |
|
| 52 | + private $config; |
|
| 53 | + /** @var ICrypto */ |
|
| 54 | + private $crypto; |
|
| 55 | + /** @var ILogger */ |
|
| 56 | + private $logger; |
|
| 57 | + /** @var IProvider */ |
|
| 58 | + private $tokenProvider; |
|
| 59 | + |
|
| 60 | + public function __construct(LoginFlowV2Mapper $mapper, |
|
| 61 | + ISecureRandom $random, |
|
| 62 | + ITimeFactory $time, |
|
| 63 | + IConfig $config, |
|
| 64 | + ICrypto $crypto, |
|
| 65 | + ILogger $logger, |
|
| 66 | + IProvider $tokenProvider) { |
|
| 67 | + $this->mapper = $mapper; |
|
| 68 | + $this->random = $random; |
|
| 69 | + $this->time = $time; |
|
| 70 | + $this->config = $config; |
|
| 71 | + $this->crypto = $crypto; |
|
| 72 | + $this->logger = $logger; |
|
| 73 | + $this->tokenProvider = $tokenProvider; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param string $pollToken |
|
| 78 | + * @return LoginFlowV2Credentials |
|
| 79 | + * @throws LoginFlowV2NotFoundException |
|
| 80 | + */ |
|
| 81 | + public function poll(string $pollToken): LoginFlowV2Credentials { |
|
| 82 | + try { |
|
| 83 | + $data = $this->mapper->getByPollToken($this->hashToken($pollToken)); |
|
| 84 | + } catch (DoesNotExistException $e) { |
|
| 85 | + throw new LoginFlowV2NotFoundException('Invalid token'); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $loginName = $data->getLoginName(); |
|
| 89 | + $server = $data->getServer(); |
|
| 90 | + $appPassword = $data->getAppPassword(); |
|
| 91 | + |
|
| 92 | + if ($loginName === null || $server === null || $appPassword === null) { |
|
| 93 | + throw new LoginFlowV2NotFoundException('Token not yet ready'); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + // Remove the data from the DB |
|
| 97 | + $this->mapper->delete($data); |
|
| 98 | + |
|
| 99 | + try { |
|
| 100 | + // Decrypt the apptoken |
|
| 101 | + $privateKey = $this->crypto->decrypt($data->getPrivateKey(), $pollToken); |
|
| 102 | + $appPassword = $this->decryptPassword($data->getAppPassword(), $privateKey); |
|
| 103 | + } catch (\Exception $e) { |
|
| 104 | + throw new LoginFlowV2NotFoundException('Apptoken could not be decrypted'); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return new LoginFlowV2Credentials($server, $loginName, $appPassword); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param string $loginToken |
|
| 112 | + * @return LoginFlowV2 |
|
| 113 | + * @throws LoginFlowV2NotFoundException |
|
| 114 | + */ |
|
| 115 | + public function getByLoginToken(string $loginToken): LoginFlowV2 { |
|
| 116 | + try { |
|
| 117 | + return $this->mapper->getByLoginToken($loginToken); |
|
| 118 | + } catch (DoesNotExistException $e) { |
|
| 119 | + throw new LoginFlowV2NotFoundException('Login token invalid'); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @param string $loginToken |
|
| 125 | + * @return bool returns true if the start was successfull. False if not. |
|
| 126 | + */ |
|
| 127 | + public function startLoginFlow(string $loginToken): bool { |
|
| 128 | + try { |
|
| 129 | + $data = $this->mapper->getByLoginToken($loginToken); |
|
| 130 | + } catch (DoesNotExistException $e) { |
|
| 131 | + return false; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if ($data->getStarted() !== 0) { |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $data->setStarted(1); |
|
| 139 | + $this->mapper->update($data); |
|
| 140 | + |
|
| 141 | + return true; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param string $loginToken |
|
| 146 | + * @param string $sessionId |
|
| 147 | + * @param string $server |
|
| 148 | + * @param string $userId |
|
| 149 | + * @return bool true if the flow was successfully completed false otherwise |
|
| 150 | + */ |
|
| 151 | + public function flowDone(string $loginToken, string $sessionId, string $server, string $userId): bool { |
|
| 152 | + try { |
|
| 153 | + $data = $this->mapper->getByLoginToken($loginToken); |
|
| 154 | + } catch (DoesNotExistException $e) { |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + try { |
|
| 159 | + $sessionToken = $this->tokenProvider->getToken($sessionId); |
|
| 160 | + $loginName = $sessionToken->getLoginName(); |
|
| 161 | + try { |
|
| 162 | + $password = $this->tokenProvider->getPassword($sessionToken, $sessionId); |
|
| 163 | + } catch (PasswordlessTokenException $ex) { |
|
| 164 | + $password = null; |
|
| 165 | + } |
|
| 166 | + } catch (InvalidTokenException $ex) { |
|
| 167 | + return false; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $appPassword = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS); |
|
| 171 | + $this->tokenProvider->generateToken( |
|
| 172 | + $appPassword, |
|
| 173 | + $userId, |
|
| 174 | + $loginName, |
|
| 175 | + $password, |
|
| 176 | + $data->getClientName(), |
|
| 177 | + IToken::PERMANENT_TOKEN, |
|
| 178 | + IToken::DO_NOT_REMEMBER |
|
| 179 | + ); |
|
| 180 | + |
|
| 181 | + $data->setLoginName($loginName); |
|
| 182 | + $data->setServer($server); |
|
| 183 | + |
|
| 184 | + // Properly encrypt |
|
| 185 | + $data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey())); |
|
| 186 | + |
|
| 187 | + $this->mapper->update($data); |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + public function createTokens(string $userAgent): LoginFlowV2Tokens { |
|
| 192 | + $flow = new LoginFlowV2(); |
|
| 193 | + $pollToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER); |
|
| 194 | + $loginToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER); |
|
| 195 | + $flow->setPollToken($this->hashToken($pollToken)); |
|
| 196 | + $flow->setLoginToken($loginToken); |
|
| 197 | + $flow->setStarted(0); |
|
| 198 | + $flow->setTimestamp($this->time->getTime()); |
|
| 199 | + $flow->setClientName($userAgent); |
|
| 200 | + |
|
| 201 | + [$publicKey, $privateKey] = $this->getKeyPair(); |
|
| 202 | + $privateKey = $this->crypto->encrypt($privateKey, $pollToken); |
|
| 203 | + |
|
| 204 | + $flow->setPublicKey($publicKey); |
|
| 205 | + $flow->setPrivateKey($privateKey); |
|
| 206 | + |
|
| 207 | + $this->mapper->insert($flow); |
|
| 208 | + |
|
| 209 | + return new LoginFlowV2Tokens($loginToken, $pollToken); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + private function hashToken(string $token): string { |
|
| 213 | + $secret = $this->config->getSystemValue('secret'); |
|
| 214 | + return hash('sha512', $token . $secret); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + private function getKeyPair(): array { |
|
| 218 | + $config = array_merge([ |
|
| 219 | + 'digest_alg' => 'sha512', |
|
| 220 | + 'private_key_bits' => 2048, |
|
| 221 | + ], $this->config->getSystemValue('openssl', [])); |
|
| 222 | + |
|
| 223 | + // Generate new key |
|
| 224 | + $res = openssl_pkey_new($config); |
|
| 225 | + if ($res === false) { |
|
| 226 | + $this->logOpensslError(); |
|
| 227 | + throw new \RuntimeException('Could not initialize keys'); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + openssl_pkey_export($res, $privateKey); |
|
| 231 | + |
|
| 232 | + // Extract the public key from $res to $pubKey |
|
| 233 | + $publicKey = openssl_pkey_get_details($res); |
|
| 234 | + $publicKey = $publicKey['key']; |
|
| 235 | + |
|
| 236 | + return [$publicKey, $privateKey]; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + private function logOpensslError(): void { |
|
| 240 | + $errors = []; |
|
| 241 | + while ($error = openssl_error_string()) { |
|
| 242 | + $errors[] = $error; |
|
| 243 | + } |
|
| 244 | + $this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors)); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + private function encryptPassword(string $password, string $publicKey): string { |
|
| 248 | + openssl_public_encrypt($password, $encryptedPassword, $publicKey, OPENSSL_PKCS1_OAEP_PADDING); |
|
| 249 | + $encryptedPassword = base64_encode($encryptedPassword); |
|
| 250 | + |
|
| 251 | + return $encryptedPassword; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + private function decryptPassword(string $encryptedPassword, string $privateKey): string { |
|
| 255 | + $encryptedPassword = base64_decode($encryptedPassword); |
|
| 256 | + openssl_private_decrypt($encryptedPassword, $password, $privateKey, OPENSSL_PKCS1_OAEP_PADDING); |
|
| 257 | + |
|
| 258 | + return $password; |
|
| 259 | + } |
|
| 260 | 260 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | private function hashToken(string $token): string { |
| 213 | 213 | $secret = $this->config->getSystemValue('secret'); |
| 214 | - return hash('sha512', $token . $secret); |
|
| 214 | + return hash('sha512', $token.$secret); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | private function getKeyPair(): array { |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | while ($error = openssl_error_string()) { |
| 242 | 242 | $errors[] = $error; |
| 243 | 243 | } |
| 244 | - $this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors)); |
|
| 244 | + $this->logger->critical('Something is wrong with your openssl setup: '.implode(', ', $errors)); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | private function encryptPassword(string $password, string $publicKey): string { |
@@ -30,17 +30,17 @@ |
||
| 30 | 30 | |
| 31 | 31 | class CleanupLoginFlowV2 extends TimedJob { |
| 32 | 32 | |
| 33 | - /** @var LoginFlowV2Mapper */ |
|
| 34 | - private $loginFlowV2Mapper; |
|
| 33 | + /** @var LoginFlowV2Mapper */ |
|
| 34 | + private $loginFlowV2Mapper; |
|
| 35 | 35 | |
| 36 | - public function __construct(ITimeFactory $time, LoginFlowV2Mapper $loginFlowV2Mapper) { |
|
| 37 | - parent::__construct($time); |
|
| 38 | - $this->loginFlowV2Mapper = $loginFlowV2Mapper; |
|
| 36 | + public function __construct(ITimeFactory $time, LoginFlowV2Mapper $loginFlowV2Mapper) { |
|
| 37 | + parent::__construct($time); |
|
| 38 | + $this->loginFlowV2Mapper = $loginFlowV2Mapper; |
|
| 39 | 39 | |
| 40 | - $this->setInterval(3600); |
|
| 41 | - } |
|
| 40 | + $this->setInterval(3600); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - protected function run($argument) { |
|
| 44 | - $this->loginFlowV2Mapper->cleanup(); |
|
| 45 | - } |
|
| 43 | + protected function run($argument) { |
|
| 44 | + $this->loginFlowV2Mapper->cleanup(); |
|
| 45 | + } |
|
| 46 | 46 | } |
@@ -31,71 +31,71 @@ |
||
| 31 | 31 | use OCP\Migration\IOutput; |
| 32 | 32 | |
| 33 | 33 | class Version16000Date20190212081545 extends SimpleMigrationStep { |
| 34 | - /** |
|
| 35 | - * @param IOutput $output |
|
| 36 | - * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 37 | - * @param array $options |
|
| 38 | - * @return null|ISchemaWrapper |
|
| 39 | - */ |
|
| 40 | - public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper { |
|
| 41 | - /** @var ISchemaWrapper $schema */ |
|
| 42 | - $schema = $schemaClosure(); |
|
| 34 | + /** |
|
| 35 | + * @param IOutput $output |
|
| 36 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
| 37 | + * @param array $options |
|
| 38 | + * @return null|ISchemaWrapper |
|
| 39 | + */ |
|
| 40 | + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper { |
|
| 41 | + /** @var ISchemaWrapper $schema */ |
|
| 42 | + $schema = $schemaClosure(); |
|
| 43 | 43 | |
| 44 | - $table = $schema->createTable('login_flow_v2'); |
|
| 45 | - $table->addColumn('id', Type::BIGINT, [ |
|
| 46 | - 'autoincrement' => true, |
|
| 47 | - 'notnull' => true, |
|
| 48 | - 'length' => 20, |
|
| 49 | - 'unsigned' => true, |
|
| 50 | - ]); |
|
| 51 | - $table->addColumn('timestamp', Type::BIGINT, [ |
|
| 52 | - 'notnull' => true, |
|
| 53 | - 'length' => 20, |
|
| 54 | - 'unsigned' => true, |
|
| 55 | - ]); |
|
| 56 | - $table->addColumn('started', Type::SMALLINT, [ |
|
| 57 | - 'notnull' => true, |
|
| 58 | - 'length' => 1, |
|
| 59 | - 'unsigned' => true, |
|
| 60 | - 'default' => 0, |
|
| 61 | - ]); |
|
| 62 | - $table->addColumn('poll_token', Type::STRING, [ |
|
| 63 | - 'notnull' => true, |
|
| 64 | - 'length' => 255, |
|
| 65 | - ]); |
|
| 66 | - $table->addColumn('login_token', Type::STRING, [ |
|
| 67 | - 'notnull' => true, |
|
| 68 | - 'length' => 255, |
|
| 69 | - ]); |
|
| 70 | - $table->addColumn('public_key', Type::TEXT, [ |
|
| 71 | - 'notnull' => true, |
|
| 72 | - 'length' => 32768, |
|
| 73 | - ]); |
|
| 74 | - $table->addColumn('private_key', Type::TEXT, [ |
|
| 75 | - 'notnull' => true, |
|
| 76 | - 'length' => 32768, |
|
| 77 | - ]); |
|
| 78 | - $table->addColumn('client_name', Type::STRING, [ |
|
| 79 | - 'notnull' => true, |
|
| 80 | - 'length' => 255, |
|
| 81 | - ]); |
|
| 82 | - $table->addColumn('login_name', Type::STRING, [ |
|
| 83 | - 'notnull' => false, |
|
| 84 | - 'length' => 255, |
|
| 85 | - ]); |
|
| 86 | - $table->addColumn('server', Type::STRING, [ |
|
| 87 | - 'notnull' => false, |
|
| 88 | - 'length' => 255, |
|
| 89 | - ]); |
|
| 90 | - $table->addColumn('app_password', Type::STRING, [ |
|
| 91 | - 'notnull' => false, |
|
| 92 | - 'length' => 1024, |
|
| 93 | - ]); |
|
| 94 | - $table->setPrimaryKey(['id']); |
|
| 95 | - $table->addUniqueIndex(['poll_token']); |
|
| 96 | - $table->addUniqueIndex(['login_token']); |
|
| 97 | - $table->addIndex(['timestamp']); |
|
| 44 | + $table = $schema->createTable('login_flow_v2'); |
|
| 45 | + $table->addColumn('id', Type::BIGINT, [ |
|
| 46 | + 'autoincrement' => true, |
|
| 47 | + 'notnull' => true, |
|
| 48 | + 'length' => 20, |
|
| 49 | + 'unsigned' => true, |
|
| 50 | + ]); |
|
| 51 | + $table->addColumn('timestamp', Type::BIGINT, [ |
|
| 52 | + 'notnull' => true, |
|
| 53 | + 'length' => 20, |
|
| 54 | + 'unsigned' => true, |
|
| 55 | + ]); |
|
| 56 | + $table->addColumn('started', Type::SMALLINT, [ |
|
| 57 | + 'notnull' => true, |
|
| 58 | + 'length' => 1, |
|
| 59 | + 'unsigned' => true, |
|
| 60 | + 'default' => 0, |
|
| 61 | + ]); |
|
| 62 | + $table->addColumn('poll_token', Type::STRING, [ |
|
| 63 | + 'notnull' => true, |
|
| 64 | + 'length' => 255, |
|
| 65 | + ]); |
|
| 66 | + $table->addColumn('login_token', Type::STRING, [ |
|
| 67 | + 'notnull' => true, |
|
| 68 | + 'length' => 255, |
|
| 69 | + ]); |
|
| 70 | + $table->addColumn('public_key', Type::TEXT, [ |
|
| 71 | + 'notnull' => true, |
|
| 72 | + 'length' => 32768, |
|
| 73 | + ]); |
|
| 74 | + $table->addColumn('private_key', Type::TEXT, [ |
|
| 75 | + 'notnull' => true, |
|
| 76 | + 'length' => 32768, |
|
| 77 | + ]); |
|
| 78 | + $table->addColumn('client_name', Type::STRING, [ |
|
| 79 | + 'notnull' => true, |
|
| 80 | + 'length' => 255, |
|
| 81 | + ]); |
|
| 82 | + $table->addColumn('login_name', Type::STRING, [ |
|
| 83 | + 'notnull' => false, |
|
| 84 | + 'length' => 255, |
|
| 85 | + ]); |
|
| 86 | + $table->addColumn('server', Type::STRING, [ |
|
| 87 | + 'notnull' => false, |
|
| 88 | + 'length' => 255, |
|
| 89 | + ]); |
|
| 90 | + $table->addColumn('app_password', Type::STRING, [ |
|
| 91 | + 'notnull' => false, |
|
| 92 | + 'length' => 1024, |
|
| 93 | + ]); |
|
| 94 | + $table->setPrimaryKey(['id']); |
|
| 95 | + $table->addUniqueIndex(['poll_token']); |
|
| 96 | + $table->addUniqueIndex(['login_token']); |
|
| 97 | + $table->addIndex(['timestamp']); |
|
| 98 | 98 | |
| 99 | - return $schema; |
|
| 100 | - } |
|
| 99 | + return $schema; |
|
| 100 | + } |
|
| 101 | 101 | } |