2015-02-24 13:05:19 -05:00
|
|
|
<?php
|
2024-05-28 10:42:42 -04:00
|
|
|
|
2015-02-24 13:05:19 -05:00
|
|
|
/**
|
2024-05-28 10:42:42 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2015-02-24 13:05:19 -05:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Encryption\AppInfo;
|
|
|
|
|
|
2024-09-24 17:37:18 -04:00
|
|
|
use OC\Core\Events\BeforePasswordResetEvent;
|
|
|
|
|
use OC\Core\Events\PasswordResetEvent;
|
2015-02-24 13:05:19 -05:00
|
|
|
use OCA\Encryption\Crypto\Crypt;
|
2015-08-24 06:03:53 -04:00
|
|
|
use OCA\Encryption\Crypto\DecryptAll;
|
2015-08-24 09:56:04 -04:00
|
|
|
use OCA\Encryption\Crypto\EncryptAll;
|
2015-04-14 10:48:39 -04:00
|
|
|
use OCA\Encryption\Crypto\Encryption;
|
2015-02-24 13:05:19 -05:00
|
|
|
use OCA\Encryption\KeyManager;
|
2024-09-24 17:37:18 -04:00
|
|
|
use OCA\Encryption\Listeners\UserEventsListener;
|
2015-04-16 07:47:27 -04:00
|
|
|
use OCA\Encryption\Session;
|
2015-02-24 13:05:19 -05:00
|
|
|
use OCA\Encryption\Users\Setup;
|
2015-03-24 17:29:10 -04:00
|
|
|
use OCA\Encryption\Util;
|
2024-06-27 05:33:21 -04:00
|
|
|
use OCP\AppFramework\App;
|
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
|
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
2015-02-24 13:05:19 -05:00
|
|
|
use OCP\Encryption\IManager;
|
2024-09-24 17:37:18 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2015-02-24 13:05:19 -05:00
|
|
|
use OCP\IConfig;
|
2024-09-24 17:37:18 -04:00
|
|
|
use OCP\IL10N;
|
|
|
|
|
use OCP\IUserSession;
|
|
|
|
|
use OCP\User\Events\BeforePasswordUpdatedEvent;
|
|
|
|
|
use OCP\User\Events\PasswordUpdatedEvent;
|
|
|
|
|
use OCP\User\Events\UserCreatedEvent;
|
|
|
|
|
use OCP\User\Events\UserDeletedEvent;
|
2025-03-06 11:22:51 -05:00
|
|
|
use OCP\User\Events\UserLoggedInEvent;
|
2025-04-01 18:06:10 -04:00
|
|
|
use OCP\User\Events\UserLoggedInWithCookieEvent;
|
2025-03-06 11:22:51 -05:00
|
|
|
use OCP\User\Events\UserLoggedOutEvent;
|
2023-06-29 09:41:40 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2015-02-24 13:05:19 -05:00
|
|
|
|
2024-06-27 05:33:21 -04:00
|
|
|
class Application extends App implements IBootstrap {
|
|
|
|
|
public const APP_ID = 'encryption';
|
|
|
|
|
|
|
|
|
|
public function __construct(array $urlParams = []) {
|
|
|
|
|
parent::__construct(self::APP_ID, $urlParams);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function register(IRegistrationContext $context): void {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function boot(IBootContext $context): void {
|
|
|
|
|
\OCP\Util::addScript(self::APP_ID, 'encryption');
|
|
|
|
|
|
2024-09-20 11:38:36 -04:00
|
|
|
$context->injectFn(function (IManager $encryptionManager) use ($context): void {
|
2024-06-27 05:33:21 -04:00
|
|
|
if (!($encryptionManager instanceof \OC\Encryption\Manager)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$encryptionManager->isReady()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$context->injectFn($this->registerEncryptionModule(...));
|
2024-09-24 17:37:18 -04:00
|
|
|
$context->injectFn($this->registerEventListeners(...));
|
2024-06-27 05:33:21 -04:00
|
|
|
$context->injectFn($this->setUp(...));
|
|
|
|
|
});
|
2017-05-30 06:54:58 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-22 16:09:09 -05:00
|
|
|
public function setUp(IManager $encryptionManager) {
|
|
|
|
|
if ($encryptionManager->isEnabled()) {
|
2016-03-02 07:58:06 -05:00
|
|
|
/** @var Setup $setup */
|
2024-09-24 17:37:18 -04:00
|
|
|
$setup = $this->getContainer()->get(Setup::class);
|
2016-03-02 07:58:06 -05:00
|
|
|
$setup->setupSystem();
|
|
|
|
|
}
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
|
|
|
|
|
2025-06-16 09:44:05 -04:00
|
|
|
public function registerEventListeners(
|
|
|
|
|
IConfig $config,
|
|
|
|
|
IEventDispatcher $eventDispatcher,
|
|
|
|
|
IManager $encryptionManager,
|
|
|
|
|
Util $util,
|
|
|
|
|
): void {
|
2024-09-24 17:37:18 -04:00
|
|
|
if (!$encryptionManager->isEnabled()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-02-24 13:05:19 -05:00
|
|
|
|
2024-09-24 17:37:18 -04:00
|
|
|
if ($config->getSystemValueBool('maintenance')) {
|
2015-02-24 13:05:19 -05:00
|
|
|
// Logout user if we are in maintenance to force re-login
|
2024-09-24 17:37:18 -04:00
|
|
|
$this->getContainer()->get(IUserSession::class)->logout();
|
|
|
|
|
return;
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
2024-09-24 17:37:18 -04:00
|
|
|
|
|
|
|
|
// No maintenance so register all events
|
2025-03-06 11:22:51 -05:00
|
|
|
$eventDispatcher->addServiceListener(UserLoggedInEvent::class, UserEventsListener::class);
|
2025-04-01 18:06:10 -04:00
|
|
|
$eventDispatcher->addServiceListener(UserLoggedInWithCookieEvent::class, UserEventsListener::class);
|
2025-03-06 11:22:51 -05:00
|
|
|
$eventDispatcher->addServiceListener(UserLoggedOutEvent::class, UserEventsListener::class);
|
2025-06-16 09:44:05 -04:00
|
|
|
if (!$util->isMasterKeyEnabled()) {
|
|
|
|
|
// Only make sense if no master key is used
|
|
|
|
|
$eventDispatcher->addServiceListener(UserCreatedEvent::class, UserEventsListener::class);
|
|
|
|
|
$eventDispatcher->addServiceListener(UserDeletedEvent::class, UserEventsListener::class);
|
|
|
|
|
$eventDispatcher->addServiceListener(BeforePasswordUpdatedEvent::class, UserEventsListener::class);
|
|
|
|
|
$eventDispatcher->addServiceListener(PasswordUpdatedEvent::class, UserEventsListener::class);
|
|
|
|
|
$eventDispatcher->addServiceListener(BeforePasswordResetEvent::class, UserEventsListener::class);
|
|
|
|
|
$eventDispatcher->addServiceListener(PasswordResetEvent::class, UserEventsListener::class);
|
|
|
|
|
}
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
|
|
|
|
|
2025-06-16 09:44:05 -04:00
|
|
|
public function registerEncryptionModule(
|
|
|
|
|
IManager $encryptionManager,
|
|
|
|
|
) {
|
2015-03-26 04:32:08 -04:00
|
|
|
$container = $this->getContainer();
|
2015-04-14 10:48:39 -04:00
|
|
|
|
2020-11-22 16:09:09 -05:00
|
|
|
$encryptionManager->registerEncryptionModule(
|
2015-04-14 10:48:39 -04:00
|
|
|
Encryption::ID,
|
|
|
|
|
Encryption::DISPLAY_NAME,
|
2020-04-09 07:53:40 -04:00
|
|
|
function () use ($container) {
|
2020-04-10 08:19:56 -04:00
|
|
|
return new Encryption(
|
2024-09-24 17:37:18 -04:00
|
|
|
$container->get(Crypt::class),
|
|
|
|
|
$container->get(KeyManager::class),
|
|
|
|
|
$container->get(Util::class),
|
|
|
|
|
$container->get(Session::class),
|
|
|
|
|
$container->get(EncryptAll::class),
|
|
|
|
|
$container->get(DecryptAll::class),
|
|
|
|
|
$container->get(LoggerInterface::class),
|
|
|
|
|
$container->get(IL10N::class),
|
2023-06-29 09:41:40 -04:00
|
|
|
);
|
2020-04-10 08:19:56 -04:00
|
|
|
});
|
2015-02-24 13:05:19 -05:00
|
|
|
}
|
|
|
|
|
}
|