no longer enforce log out, but provide useful errors/warnings instead

This commit is contained in:
Bjoern Schiessle 2013-09-06 12:27:40 +02:00
parent 69b1625f0e
commit fb462e83cc
11 changed files with 42 additions and 48 deletions

View File

@ -124,8 +124,12 @@ if ($needUpgrade) {
$storageInfo=OC_Helper::getStorageInfo($dir);
$maxUploadFilesize=OCP\Util::maxUploadFilesize($dir);
$publicUploadEnabled = \OC_Appconfig::getValue('core', 'shareapi_allow_public_upload', 'yes');
// if the encryption app is disabled, than everything is fine
$encryptionInitStatus = \OCA\Encryption\Session::INIT_SUCCESSFUL;
if (OC_App::isEnabled('files_encryption')) {
$publicUploadEnabled = 'no';
$session = new \OCA\Encryption\Session(new \OC\Files\View('/'));
$encryptionInitStatus = $session->getInitialized();
}
$trashEnabled = \OCP\App::isEnabled('files_trashbin');
@ -133,7 +137,7 @@ if ($needUpgrade) {
if ($trashEnabled) {
$trashEmpty = \OCA\Files_Trashbin\Trashbin::isEmpty($user);
}
OCP\Util::addscript('files', 'fileactions');
OCP\Util::addscript('files', 'files');
OCP\Util::addscript('files', 'keyboardshortcuts');
@ -153,5 +157,6 @@ if ($needUpgrade) {
$tmpl->assign('isPublic', false);
$tmpl->assign('publicUploadEnabled', $publicUploadEnabled);
$tmpl->assign("encryptedFiles", \OCP\Util::encryptedFiles());
$tmpl->assign("encryptionInitStatus", $encryptionInitStatus);
$tmpl->printPage();
}

View File

@ -90,6 +90,15 @@ Files={
}
var encryptedFiles = $('#encryptedFiles').val();
var initStatus = $('#encryptionInitStatus').val();
if (initStatus === '0') { // enc not initialized, but should be
OC.Notification.show(t('files_encryption', 'Encryption App is enabled but your keys are not initialized, please log-out and log-in again'));
return;
}
if (initStatus === '1') { // encryption tried to init but failed
OC.Notification.show(t('files_encryption', 'Your private key is not valid! Likely your password was changed outside the ownCloud system (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.'));
return;
}
if (encryptedFiles === '1') {
OC.Notification.show(t('files_encryption', 'Encryption was disabled but your files are still encrypted. Please go to your personal settings to decrypt your files.'));
return;

View File

@ -123,3 +123,4 @@
<input type="hidden" name="allowZipDownload" id="allowZipDownload" value="<?php p($_['allowZipDownload']); ?>" />
<input type="hidden" name="usedSpacePercent" id="usedSpacePercent" value="<?php p($_['usedSpacePercent']); ?>" />
<input type="hidden" name="encryptedFiles" id="encryptedFiles" value="<?php $_['encryptedFiles'] ? p('1') : p('0'); ?>" />
<input type="hidden" name="encryptedFiles" id="encryptionInitStatus" value="<?php p($_['encryptionInitStatus']) ?>" />

View File

@ -48,6 +48,7 @@ if ($decryptedKey) {
// success or failure
if ($return) {
$session->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL);
\OCP\JSON::success(array('data' => array('message' => $l->t('Private key password successfully updated.'))));
} else {
\OCP\JSON::error(array('data' => array('message' => $l->t('Could not update the private key password. Maybe the old password was not correct.'))));

View File

@ -41,23 +41,6 @@ if (!OC_Config::getValue('maintenance', false)) {
if($sessionReady) {
$session = new \OCA\Encryption\Session($view);
}
$user = \OCP\USER::getUser();
// check if user has a private key
if ($sessionReady === false
|| (!$view->file_exists('/' . $user . '/files_encryption/' . $user . '.private.key')
&& OCA\Encryption\Crypt::mode() === 'server')
) {
// Force the user to log-in again if the encryption key isn't unlocked
// (happens when a user is logged in before the encryption app is
// enabled)
OCP\User::logout();
header("Location: " . OC::$WEBROOT . '/');
exit();
}
}
} else {
// logout user if we are in maintenance to force re-login

View File

@ -547,7 +547,7 @@ class Hooks {
$setMigrationStatus->execute();
$session = new \OCA\Encryption\Session(new \OC\Files\View('/'));
$session->setInitialized(false);
$session->setInitialized(\OCA\Encryption\Session::NOT_INITIALIZED);
}
}

View File

@ -237,28 +237,15 @@ class Helper {
*/
public static function redirectToErrorPage($session) {
$l = \OC_L10N::get('files_encryption');
if ($session->getInitialized() === false) {
$errorMsg = $l->t('Encryption app not initialized! Maybe the encryption app was re-enabled during your session. Please try to log out and log back in to initialize the encryption app.');
} else {
$errorMsg = $l->t('Your private key is not valid! Likely your password was changed outside the ownCloud system (e.g. your corporate directory). You can update your private key password in your personal settings to recover access to your encrypted files.');
}
$init = $session->getInitialized();
$location = \OC_Helper::linkToAbsolute('apps/files_encryption/files', 'error.php');
$post = 0;
if(count($_POST) > 0) {
header('HTTP/1.0 404 ' . $errorMsg);
}
// check if ajax request
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
\OCP\JSON::error(array('data' => array('message' => $errorMsg)));
} else {
header('HTTP/1.0 404 ' . $errorMsg);
$tmpl = new OC_Template('files_encryption', 'invalid_private_key', 'guest');
$tmpl->printPage();
}
exit;
$post = 1;
}
header('Location: ' . $location . '?p=' . $post . '&i=' . $init);
exit();
}
/**

View File

@ -30,6 +30,11 @@ class Session {
private $view;
const NOT_INITIALIZED = '0';
const INIT_EXECUTED = '1';
const INIT_SUCCESSFUL = '2';
/**
* @brief if session is started, check if ownCloud key pair is set up, if not create it
* @param \OC_FilesystemView $view
@ -113,10 +118,10 @@ class Session {
}
/**
* @brief Sets status if we tried to initialize the encyption app
* @param bool $privateKey true=initialized false=not initialized
* @brief Sets status of encryption app
* @param string $init INIT_SUCCESSFUL, INIT_EXECUTED, NOT_INOITIALIZED
* @return bool
*
*
* @note this doesn not indicate of the init was successful, we just remeber the try!
*/
public function setInitialized($init) {
@ -130,7 +135,7 @@ class Session {
/**
* @brief Gets status if we already tried to initialize the encryption app
* @returns bool
* @returns init status INIT_SUCCESSFUL, INIT_EXECUTED, NOT_INOITIALIZED
*
* @note this doesn not indicate of the init was successful, we just remeber the try!
*/
@ -138,7 +143,7 @@ class Session {
if (!is_null(\OC::$session->get('encryptionInitialized'))) {
return \OC::$session->get('encryptionInitialized');
} else {
return false;
return self::NOT_INITIALIZED;
}
}

View File

@ -128,7 +128,7 @@ class Stream {
$this->unencryptedSize = 0;
} else {
\OCA\Encryption\Helper::redirectToErrorPage($this->session);
if($this->privateKey === false) {
// if private key is not valid redirect user to a error page
\OCA\Encryption\Helper::redirectToErrorPage($this->session);

View File

@ -1724,7 +1724,7 @@ class Util {
$session = new \OCA\Encryption\Session($this->view);
// we tried to initialize the encryption app for this session
$session->setInitialized(true);
$session->setInitialized(\OCA\Encryption\Session::INIT_EXECUTED);
$encryptedKey = Keymanager::getPrivateKey($this->view, $params['uid']);
@ -1737,6 +1737,7 @@ class Util {
}
$session->setPrivateKey($privateKey);
$session->setInitialized(\OCA\Encryption\Session::INIT_SUCCESSFUL);
return $session;
}

View File

@ -2,9 +2,11 @@
<li class='error'>
<?php $location = \OC_Helper::linkToRoute( "settings_personal" ).'#changePKPasswd' ?>
<?php p($l->t('Your private key is not valid! Maybe the your password was changed from outside.')); ?>
<?php p($_['message']); ?>
<br/>
<?php p($l->t('You can unlock your private key in your ')); ?> <a href="<?php echo $location?>"><?php p($l->t('personal settings')); ?>.</a>
<?php if($_['init']): ?>
<?php>p($l->t('Go directly to your ')); ?> <a href="<?php echo $location?>"><?php p($l->t('personal settings')); ?>.</a>
<?php endif; ?>
<br/>
</li>
</ul>