]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix app password updating out of bounds 22570/head
authorRoeland Jago Douma <roeland@famdouma.nl>
Mon, 31 Aug 2020 17:45:40 +0000 (19:45 +0200)
committerRoeland Jago Douma <roeland@famdouma.nl>
Fri, 4 Sep 2020 07:18:00 +0000 (09:18 +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 92c2dd94b2b9e7d679a6657120f106955682b42a..ad7bda7083ffcf70087f89d9545793f30aaf4c38 100644 (file)
@@ -606,6 +606,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 e24ce4c1c2de937f81f7bc00238a59e060a3dc59..057add5a4b8ae852914a750d072888fd971c1037 100644 (file)
@@ -635,6 +635,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 664440fe6bb929c4d6fe482cd6a7e1627e1e91c6..17d6a351c8ee8e76a0bc4c0d255861d34cce73d6 100644 (file)
@@ -419,6 +419,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 acc96f98a55932b5b355f91ce983879c2e32251d..400389177e4d53ad7b5b7a3c53a0c3320d9b7e7d 100644 (file)
@@ -62,6 +62,7 @@ use OC\App\AppStore\Fetcher\CategoryFetcher;
 use OC\AppFramework\Http\Request;
 use OC\AppFramework\Utility\SimpleContainer;
 use OC\AppFramework\Utility\TimeFactory;
+use OC\Authentication\Listeners\UserLoggedInListener;
 use OC\Authentication\LoginCredentials\Store;
 use OC\Authentication\Token\IProvider;
 use OC\Avatar\AvatarManager;
@@ -181,6 +182,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;
@@ -1378,6 +1380,10 @@ class Server extends ServerContainer implements IServerContainer {
                                // no avatar to remove
                        }
                });
+
+               /** @var IEventDispatcher $eventDispatched */
+               $eventDispatched = $this->query(IEventDispatcher::class);
+               $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
        }
 
        /**