]> source.dussan.org Git - nextcloud-server.git/commitdiff
encryption error messages, distinguish between a re-enabled encryption app and a...
authorBjoern Schiessle <schiessle@owncloud.com>
Mon, 2 Sep 2013 09:26:11 +0000 (11:26 +0200)
committerBjoern Schiessle <schiessle@owncloud.com>
Mon, 2 Sep 2013 09:26:11 +0000 (11:26 +0200)
apps/files_encryption/appinfo/database.xml
apps/files_encryption/hooks/hooks.php
apps/files_encryption/lib/helper.php
apps/files_encryption/lib/session.php
apps/files_encryption/lib/stream.php
apps/files_encryption/lib/util.php
apps/files_encryption/settings-personal.php
apps/files_encryption/templates/settings-personal.php
settings/ajax/changepassword.php
settings/templates/personal.php

index cd5434b8c27145d3f0733bc85e70e55f57602d0e..4587930da0a3c25fb3eecbb4c39afebf9de866ec 100644 (file)
                                <default>0</default>
                                <comments>Whether encryption migration has been performed</comments>
                        </field>
-                       <field>
-                               <name>initialized</name>
-                               <type>integer</type>
-                               <notnull>true</notnull>
-                               <default>0</default>
-                               <comments>Did the user initialized the encryption app at least once</comments>
-                       </field>
                </declaration>
        </table>
 </database>
\ No newline at end of file
index aefb274e1c471c9630ae66b8a8c5f56109171827..4c6122b7c2b693b51f78be3e175fc6dd1b43a97f 100644 (file)
@@ -70,8 +70,6 @@ class Hooks {
                // If migration not yet done\r
                if ($ready) {\r
 \r
-                       $util->setInitialized(Util::ENCRYPTION_INITIALIZED);\r
-\r
                        $userView = new \OC_FilesystemView('/' . $params['uid']);\r
 \r
                        // Set legacy encryption key if it exists, to support\r
@@ -145,7 +143,6 @@ class Hooks {
         * @brief If the password can't be changed within ownCloud, than update the key password in advance.\r
         */\r
        public static function preSetPassphrase($params) {\r
-               return true;\r
                if ( ! \OC_User::canUserChangePassword($params['uid']) ) {\r
                        self::setPassphrase($params);\r
                }\r
@@ -156,7 +153,6 @@ class Hooks {
         * @param array $params keys: uid, password\r
         */\r
        public static function setPassphrase($params) {\r
-               return true;\r
                // Only attempt to change passphrase if server-side encryption\r
                // is in use (client-side encryption does not have access to\r
                // the necessary keys)\r
@@ -550,8 +546,8 @@ class Hooks {
                        $setMigrationStatus = \OC_DB::prepare('UPDATE `*PREFIX*encryption` SET `migration_status`=0');\r
                        $setMigrationStatus->execute();\r
 \r
-                       $setInitStatus = \OC_DB::prepare('UPDATE `*PREFIX*encryption` SET `initialized`=0');\r
-                       $setInitStatus->execute();\r
+                       $session = new \OCA\Encryption\Session(new \OC\Files\View('/'));\r
+                       $session->setInitialized(false);\r
                }\r
        }\r
 \r
index 105c5357e9612dcae9e4443b5f751e738902bb04..7d466b88523a51f1a194e8927fb33f783e0f8bda 100755 (executable)
@@ -235,11 +235,11 @@ class Helper {
        /**
         * @brief redirect to a error page
         */
-       public static function redirectToErrorPage($util) {
+       public static function redirectToErrorPage($session) {
 
                $l = \OC_L10N::get('files_encryption');
 
-               if ($util->getInitialized() === false) {
+               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.');
index 1911386cd12f06832d2406071a4092942191c7d7..f5ce7083af054f194095039a7c5e6e2286720c20 100644 (file)
@@ -112,6 +112,33 @@ class Session {
 
        }
 
+       /**
+        * @brief Sets status if we tried to initialize the encyption app
+        * @param bool $privateKey true=initialized false=not initialized
+        * @return bool
+        */
+       public function setInitialized($init) {
+
+               \OC::$session->set('encryptionInitialized', $init);
+
+               return true;
+
+       }
+
+
+       /**
+        * @brief Gets status if we already tried to initialize the encryption app
+        * @returns bool
+        *
+        */
+       public function getInitialized() {
+               if (!is_null(\OC::$session->get('encryptionInitialized'))) {
+                       return \OC::$session->get('encryptionInitialized');
+               } else {
+                       return false;
+               }
+       }
+
        /**
         * @brief Gets user or public share private key from session
         * @returns string $privateKey The user's plaintext private key
index 87b8dc3ee2f8e08d034c5bd7746b1999f7d8aeb5..9215352aa785d719369be161c3ecc2e785fb91fb 100644 (file)
@@ -131,7 +131,7 @@ class Stream {
 
                        if($this->privateKey === false) {
                                // if private key is not valid redirect user to a error page
-                               \OCA\Encryption\Helper::redirectToErrorPage($util);
+                               \OCA\Encryption\Helper::redirectToErrorPage($this->session);
                        }
 
                        $this->size = $this->rootView->filesize($this->rawPath, $mode);
index edb9564e73abd33ed8762bbe10274c7b5c3cdd65..17096a787f2be22f03e0af306de359f42cc9715a 100644 (file)
@@ -37,9 +37,6 @@ class Util {
        const MIGRATION_IN_PROGRESS = -1; // migration is running
        const MIGRATION_OPEN = 0;         // user still needs to be migrated
 
-       const ENCRYPTION_INITIALIZED = 1;
-       const ENCRYPTION_NOT_INITIALIZED = 0;
-
        private $view; // OC_FilesystemView object for filesystem operations
        private $userId; // ID of the currently logged-in user
        private $client; // Client side encryption mode flag
@@ -1218,56 +1215,6 @@ class Util {
                return $return;
        }
 
-       /**
-        * set remember if the encryption app was already initialized or not
-        * @param type $status
-        */
-       public function setInitialized($status) {
-               $sql = 'UPDATE `*PREFIX*encryption` SET `initialized` = ? WHERE `uid` = ?';
-               $args = array($status, $this->userId);
-               $query = \OCP\DB::prepare($sql);
-               $query->execute($args);
-       }
-
-       /**
-        * set remember if the encryption app was already initialized or not
-        */
-       public function getInitialized() {
-               $sql = 'SELECT `initialized` FROM `*PREFIX*encryption` WHERE `uid` = ?';
-               $args = array($this->userId);
-               $query = \OCP\DB::prepare($sql);
-
-               $result = $query->execute($args);
-               $initializedStatus = null;
-
-               if (\OCP\DB::isError($result)) {
-                       \OCP\Util::writeLog('Encryption library', \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
-               } else {
-                       if ($result->numRows() > 0) {
-                               $row = $result->fetchRow();
-                               if (isset($row['initialized'])) {
-                                       $initializedStatus = (int)$row['initialized'];
-                               }
-                       }
-               }
-
-               // If no record is found
-               if (empty($initializedStatus)) {
-                       \OCP\Util::writeLog('Encryption library', "Could not get initialized status for " . $this->userId . ", no record found", \OCP\Util::ERROR);
-                       return false;
-                       // If a record is found
-               } else {
-                       return (bool)$initializedStatus;
-               }
-
-
-
-               $sql = 'UPDATE `*PREFIX*encryption` SET `initialized` = ? WHERE `uid` = ?';
-               $args = array($status, $this->userId);
-               $query = \OCP\DB::prepare($sql);
-               $query->execute($args);
-       }
-
        /**
         * @brief close migration mode after users data has been encrypted successfully
         * @return boolean
@@ -1774,6 +1721,11 @@ class Util {
         */
        public function initEncryption($params) {
 
+               $session = new \OCA\Encryption\Session($this->view);
+
+               // we tried to initialize the encryption app for this session
+               $session->setInitialized(true);
+
                $encryptedKey = Keymanager::getPrivateKey($this->view, $params['uid']);
 
                $privateKey = Crypt::decryptPrivateKey($encryptedKey, $params['password']);
@@ -1784,8 +1736,6 @@ class Util {
                        return false;
                }
 
-               $session = new \OCA\Encryption\Session($this->view);
-
                $session->setPrivateKey($privateKey);
 
                return $session;
index 589219f32ada5c05fcc112140861fe535ae62ce9..c0c91bdf6521bd2b0c2a5bcbcb939720556e6fd4 100644 (file)
@@ -16,7 +16,9 @@ $view = new \OC_FilesystemView('/');
 $util = new \OCA\Encryption\Util($view, $user);\r
 $session = new \OCA\Encryption\Session($view);\r
 \r
-$privateKeySet = $session->getPrivateKey() !== false;
+$privateKeySet = $session->getPrivateKey() !== false;\r
+// was the key successfully initialized during log-in\r
+$initialized = $session->getInitialized();\r
 \r
 $recoveryAdminEnabled = OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled');\r
 $recoveryEnabledForUser = $util->recoveryEnabledForUser();\r
@@ -31,6 +33,7 @@ if ($recoveryAdminEnabled || !$privateKeySet) {
        $tmpl->assign('recoveryEnabled', $recoveryAdminEnabled);\r
        $tmpl->assign('recoveryEnabledForUser', $recoveryEnabledForUser);\r
        $tmpl->assign('privateKeySet', $privateKeySet);\r
+       $tmpl->assign('initialized', $initialized);\r
 \r
        $result = $tmpl->fetchPage();\r
 }\r
index 38512453207a0af2ab836589d427f1abc394ef16..ff04556dd53ef9e9d5e104e6aa05fc6db857562c 100644 (file)
@@ -4,7 +4,7 @@
                        <?php p( $l->t( 'Encryption' ) ); ?>\r
                </legend>\r
 \r
-               <?php if ( ! $_["privateKeySet"] ): ?>\r
+               <?php if ( ! $_["privateKeySet"] && $_["initialized"] ): ?>\r
                        <p>\r
                                <a name="changePKPasswd" />\r
                                <label for="changePrivateKeyPasswd">\r
                <?php endif; ?>\r
 \r
                <br />\r
-               \r
+\r
                <?php if ( $_["recoveryEnabled"] && $_["privateKeySet"] ): ?>\r
                        <p>\r
                                <label for="userEnableRecovery"><?php p( $l->t( "Enable password recovery:" ) ); ?></label>\r
                                <br />\r
                                <em><?php p( $l->t( "Enabling this option will allow you to reobtain access to your encrypted files in case of password loss" ) ); ?></em>\r
                                <br />\r
-                               <input \r
+                               <input\r
                                type='radio'\r
                                name='userEnableRecovery'\r
                                value='1'\r
                                <?php echo ( $_["recoveryEnabledForUser"] == 1 ? 'checked="checked"' : '' ); ?> />\r
                                <?php p( $l->t( "Enabled" ) ); ?>\r
                                <br />\r
-                               \r
-                               <input \r
+\r
+                               <input\r
                                type='radio'\r
                                name='userEnableRecovery'\r
                                value='0'\r
index 47ceb5ab87379956fe5b5419f4f880e7958b3cab..d409904ebc72ee1703b2b1280cf24942aec8d196 100644 (file)
@@ -8,7 +8,7 @@ OC_JSON::checkLoggedIn();
 OC_APP::loadApps();
 
 $username = isset($_POST['username']) ? $_POST['username'] : OC_User::getUser();
-$password = isset($_POST['personal-password']) ? $_POST['personal-password'] : null;
+$password = isset($_POST['password']) ? $_POST['password'] : null;
 $oldPassword = isset($_POST['oldpassword']) ? $_POST['oldpassword'] : '';
 $recoveryPassword = isset($_POST['recoveryPassword']) ? $_POST['recoveryPassword'] : null;
 
index 63e1258b958e692cabbd83b0820afe8e8f9f78f1..bad88142da9fb7526788f866dc5c72c16728865a 100644 (file)
@@ -40,7 +40,7 @@ if($_['passwordChangeSupported']) {
                <div id="passwordchanged"><?php echo $l->t('Your password was changed');?></div>
                <div id="passworderror"><?php echo $l->t('Unable to change your password');?></div>
                <input type="password" id="pass1" name="oldpassword" placeholder="<?php echo $l->t('Current password');?>" />
-               <input type="password" id="pass2" name="personal-password"
+               <input type="password" id="pass2" name="password"
                        placeholder="<?php echo $l->t('New password');?>" data-typetoggle="#personal-show" />
                <input type="checkbox" id="personal-show" name="show" /><label for="personal-show"></label>
                <input id="passwordbutton" type="submit" value="<?php echo $l->t('Change password');?>" />