Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set done time after actually done #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 49 additions & 41 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,45 +21,53 @@

$userSession = \OC::$server->getUserSession();
$userSession->listen('\OC\User', 'postLogin', function (\OCP\IUser $user) {
$config = \OC::$server->getConfig();
$logger = \OC::$server->getLogger();
$regenerateKeys = $config->getUserValue($user->getUID(), 'encryption_recovery', 'regenerate');
if ($regenerateKeys === 'on') {
\OC::$server->getConfig()->setUserValue($user->getUID(), 'encryption_recovery', 'regenerate', time());
$logger->debug('Regenerating recovery keys for ' . $user->getUid(), ['app' => 'encryption_recovery']);
$userSession = \OC::$server->getUserSession();
$crypt = new \OCA\Encryption\Crypto\Crypt($logger, $userSession, $config);
$view = new \OC\Files\View();
$recovery = new \OCA\Encryption\Recovery (
$userSession,
$crypt,
\OC::$server->getSecureRandom(),
new \OCA\Encryption\KeyManager(
\OC::$server->getEncryptionKeyStorage(),
$crypt,
$config,
$userSession,
new \OCA\Encryption\Session(\OC::$server->getSession()),
$logger,
new \OCA\Encryption\Util (
$view,
$crypt,
$logger,
$userSession,
$config,
\OC::$server->getUserManager()
)
),
$config,
\OC::$server->getEncryptionKeyStorage(),
\OC::$server->getEncryptionFilesHelper(),
$view
);
// remove script execution time limit
set_time_limit(0);
$recovery->setRecoveryForUser('1'); // sets config and regenerates recovery keys
$logger->info('Regenerated recovery keys for ' . $user->getUid(), ['app' => 'encryption_recovery']);
} else {
$logger->debug('Not regenerating recovery keys for ' . $user->getUid(), ['app' => 'encryption_recovery']);
}
$config = \OC::$server->getConfig();
$logger = \OC::$server->getLogger();
$regenerateKeys = $config->getUserValue($user->getUID(), 'encryption_recovery', 'regenerate');
if ($regenerateKeys === 'on') {
$logger->debug('Regenerating recovery keys for ' . $user->getUid(), ['app' => 'encryption_recovery']);
$userSession = \OC::$server->getUserSession();
$crypt = new \OCA\Encryption\Crypto\Crypt($logger, $userSession, $config);
$view = new \OC\Files\View();
$recovery = new \OCA\Encryption\Recovery (
$userSession,
$crypt,
\OC::$server->getSecureRandom(),
new \OCA\Encryption\KeyManager(
\OC::$server->getEncryptionKeyStorage(),
$crypt,
$config,
$userSession,
new \OCA\Encryption\Session(\OC::$server->getSession()),
$logger,
new \OCA\Encryption\Util (
$view,
$crypt,
$logger,
$userSession,
$config,
\OC::$server->getUserManager()
)
),
$config,
\OC::$server->getEncryptionKeyStorage(),
\OC::$server->getEncryptionFilesHelper(),
$view
);
// remove script execution time limit
set_time_limit(0);
try {
$recovery->setRecoveryForUser('1'); // sets config and regenerates recovery keys
} catch (\Exception $e) {
$logger->logException($e, [
'message' => 'Failed to regenerate recovery keys for ' . $user->getUid(),
'app' => 'encryption_recovery',
]);
return;
}
\OC::$server->getConfig()->setUserValue($user->getUID(), 'encryption_recovery', 'regenerate', time());
$logger->info('Regenerated recovery keys for ' . $user->getUid(), ['app' => 'encryption_recovery']);
} else {
$logger->debug('Not regenerating recovery keys for ' . $user->getUid(), ['app' => 'encryption_recovery']);
}
});