]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix app password updating out of bounds 22524/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Mon, 31 Aug 2020 17:45:40 +0000 (19:45 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Thu, 3 Sep 2020 19:13:36 +0000 (21:13 +0200)
When your password changes out of bounds your Nextcloud tokens will
become invalid. There is no real way around that. However we should make
sure that if you successfully log in again your passwords are all
updates

* Added event listener to the PostLoggedInEvent so that we can act on it
  - Only if it is not a token login
* Make sure that we actually reset the invalid state when we update a
  token. Else it keeps being marked invalid and thus not used.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
lib/composer/composer/autoload_classmap.php
lib/composer/composer/autoload_static.php
lib/private/Authentication/Listeners/UserLoggedInListener.php [new file with mode: 0644]
lib/private/Authentication/Token/PublicKeyTokenProvider.php
lib/private/Server.php

index 286c473c30514396d256db2535aa2119010c4787..a217a7044482d70ff78ca3fbd46046adb1bc2575 100644 (file)
@@ -665,6 +665,7 @@ return array(
     'OC\\Authentication\\Listeners\\RemoteWipeNotificationsListener' => $baseDir . '/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php',
     'OC\\Authentication\\Listeners\\UserDeletedStoreCleanupListener' => $baseDir . '/lib/private/Authentication/Listeners/UserDeletedStoreCleanupListener.php',
     'OC\\Authentication\\Listeners\\UserDeletedTokenCleanupListener' => $baseDir . '/lib/private/Authentication/Listeners/UserDeletedTokenCleanupListener.php',
+    'OC\\Authentication\\Listeners\\UserLoggedInListener' => $baseDir . '/lib/private/Authentication/Listeners/UserLoggedInListener.php',
     'OC\\Authentication\\LoginCredentials\\Credentials' => $baseDir . '/lib/private/Authentication/LoginCredentials/Credentials.php',
     'OC\\Authentication\\LoginCredentials\\Store' => $baseDir . '/lib/private/Authentication/LoginCredentials/Store.php',
     'OC\\Authentication\\Login\\ALoginCommand' => $baseDir . '/lib/private/Authentication/Login/ALoginCommand.php',
index b9208db1fd6f0ad8f6f118894013eff9417dc35e..9e46855f1ebc2e2d37a2aa7422e715e3d06cca80 100644 (file)
@@ -694,6 +694,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
         'OC\\Authentication\\Listeners\\RemoteWipeNotificationsListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/RemoteWipeNotificationsListener.php',
         'OC\\Authentication\\Listeners\\UserDeletedStoreCleanupListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/UserDeletedStoreCleanupListener.php',
         'OC\\Authentication\\Listeners\\UserDeletedTokenCleanupListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/UserDeletedTokenCleanupListener.php',
+        'OC\\Authentication\\Listeners\\UserLoggedInListener' => __DIR__ . '/../../..' . '/lib/private/Authentication/Listeners/UserLoggedInListener.php',
         'OC\\Authentication\\LoginCredentials\\Credentials' => __DIR__ . '/../../..' . '/lib/private/Authentication/LoginCredentials/Credentials.php',
         'OC\\Authentication\\LoginCredentials\\Store' => __DIR__ . '/../../..' . '/lib/private/Authentication/LoginCredentials/Store.php',
         'OC\\Authentication\\Login\\ALoginCommand' => __DIR__ . '/../../..' . '/lib/private/Authentication/Login/ALoginCommand.php',
diff --git a/lib/private/Authentication/Listeners/UserLoggedInListener.php b/lib/private/Authentication/Listeners/UserLoggedInListener.php
new file mode 100644 (file)
index 0000000..0347b4f
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Authentication\Listeners;
+
+use OC\Authentication\Token\Manager;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\User\Events\PostLoginEvent;
+
+class UserLoggedInListener implements IEventListener {
+
+       /** @var Manager */
+       private $manager;
+
+       public function __construct(Manager $manager) {
+               $this->manager = $manager;
+       }
+
+       public function handle(Event $event): void {
+               if (!($event instanceof PostLoginEvent)) {
+                       return;
+               }
+
+               // If this is already a token login there is nothing to do
+               if ($event->isTokenLogin()) {
+                       return;
+               }
+
+               $this->manager->updatePasswords($event->getUser()->getUID(), $event->getPassword());
+       }
+}
index 654bf4a8e8b2ba4761aa1fccb08e5cbde741b259..cd2fca5dec80d6907670080a06e53753745427d0 100644 (file)
@@ -420,6 +420,7 @@ class PublicKeyTokenProvider implements IProvider {
                foreach ($tokens as $t) {
                        $publicKey = $t->getPublicKey();
                        $t->setPassword($this->encryptPassword($password, $publicKey));
+                       $t->setPasswordInvalid(false);
                        $this->updateToken($t);
                }
        }
index a83376e5eae9517669c0bf87367b135c791db40e..abb085d0745a55031db6af838605e14c236b2cbf 100644 (file)
@@ -64,6 +64,7 @@ use OC\AppFramework\Utility\SimpleContainer;
 use OC\AppFramework\Utility\TimeFactory;
 use OC\Authentication\Events\LoginFailed;
 use OC\Authentication\Listeners\LoginFailedListener;
+use OC\Authentication\Listeners\UserLoggedInListener;
 use OC\Authentication\LoginCredentials\Store;
 use OC\Authentication\Token\IProvider;
 use OC\Avatar\AvatarManager;
@@ -217,6 +218,7 @@ use OCP\User\Events\BeforeUserLoggedInEvent;
 use OCP\User\Events\BeforeUserLoggedInWithCookieEvent;
 use OCP\User\Events\BeforeUserLoggedOutEvent;
 use OCP\User\Events\PasswordUpdatedEvent;
+use OCP\User\Events\PostLoginEvent;
 use OCP\User\Events\UserChangedEvent;
 use OCP\User\Events\UserCreatedEvent;
 use OCP\User\Events\UserDeletedEvent;
@@ -1403,6 +1405,7 @@ class Server extends ServerContainer implements IServerContainer {
                /** @var IEventDispatcher $eventDispatched */
                $eventDispatched = $this->query(IEventDispatcher::class);
                $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
+               $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
        }
 
        /**