]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix for losing private key while being logged in and accessing a public link
authorFlorin Peter <github@florin-peter.de>
Tue, 28 May 2013 07:27:04 +0000 (09:27 +0200)
committerFlorin Peter <github@florin-peter.de>
Tue, 28 May 2013 07:27:04 +0000 (09:27 +0200)
apps/files_encryption/lib/helper.php
apps/files_encryption/lib/session.php
apps/files_encryption/lib/util.php

index 7a2d19eed579c912ba357203fddc166048fb3289..3867a368a9a8c4a0259441099281f09cb30751b5 100755 (executable)
@@ -173,4 +173,20 @@ class Helper
 
                return $return;
        }
+
+
+       /**
+        * @brief checks if access is public/anonymous user
+        * @return bool
+        */
+       public static function isPublicAccess() {
+               if (\OCP\USER::getUser() === false
+                       || (isset($_GET['service']) && $_GET['service'] == 'files'
+                               && isset($_GET['t']))
+               ) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
 }
\ No newline at end of file
index 2ddad0a15dacf188fb21575f45fb9cb3010922a4..1551275c63f5d498ff0db2b06b16f17691d04e30 100644 (file)
@@ -83,17 +83,14 @@ class Session
 
                }
 
-               if ( \OCP\USER::getUser() === false ||
-                       ( isset( $_GET['service'] ) && $_GET['service'] == 'files' &&
-                               isset( $_GET['t'] ) )
-               ) {
+               if (\OCA\Encryption\Helper::isPublicAccess()) {
                        // Disable encryption proxy to prevent recursive calls
                        $proxyStatus = \OC_FileProxy::$enabled;
                        \OC_FileProxy::$enabled = false;
 
                        $encryptedKey = $this->view->file_get_contents( '/owncloud_private_key/' . $publicShareKeyId . '.private.key' );
                        $privateKey = Crypt::symmetricDecryptFileContent( $encryptedKey, '' );
-                       $this->setPrivateKey( $privateKey );
+                       $this->setPublicSharePrivateKey( $privateKey );
 
                        \OC_FileProxy::$enabled = $proxyStatus;
                }
@@ -103,6 +100,8 @@ class Session
         * @brief Sets user private key to session
         * @param string $privateKey
         * @return bool
+        *
+        * @note this should only be set on login
         */
        public function setPrivateKey( $privateKey ) {
 
@@ -113,27 +112,53 @@ class Session
        }
 
        /**
-        * @brief Gets user private key from session
+        * @brief Gets user or public share private key from session
         * @returns string $privateKey The user's plaintext private key
         *
         */
        public function getPrivateKey() {
 
-               if (
-                       isset( $_SESSION['privateKey'] )
-                       && !empty( $_SESSION['privateKey'] )
-               ) {
+               // return the public share private key if this is a public access
+               if (\OCA\Encryption\Helper::isPublicAccess()) {
+                       return $this->getPublicSharePrivateKey();
+               } else {
+                       if (isset($_SESSION['privateKey']) && !empty($_SESSION['privateKey'])) {
+                               return $_SESSION['privateKey'];
+                       } else {
+                               return false;
+                       }
+               }
+       }
+
+       /**
+        * @brief Sets public user private key to session
+        * @param string $privateKey
+        * @return bool
+        */
+       public function setPublicSharePrivateKey($privateKey) {
 
-                       return $_SESSION['privateKey'];
+               $_SESSION['publicSharePrivateKey'] = $privateKey;
 
-               } else {
+               return true;
 
-                       return false;
+       }
+
+       /**
+        * @brief Gets public share private key from session
+        * @returns string $privateKey
+        *
+        */
+       public function getPublicSharePrivateKey() {
 
+               if (isset($_SESSION['publicSharePrivateKey']) && !empty($_SESSION['publicSharePrivateKey'])) {
+                       return $_SESSION['publicSharePrivateKey'];
+               } else {
+                       return false;
                }
 
        }
 
+
        /**
         * @brief Sets user legacy key to session
         * @param $legacyKey
index 4171b7cae5053cc723df65616fd0fd8cd8c99fb4..dba01c4d961e872ac2162ee06002c18e50cbacb0 100644 (file)
@@ -127,9 +127,7 @@ class Util {
                $this->recoveryKeyId = \OC_Appconfig::getValue('files_encryption', 'recoveryKeyId');
 
                // if we are anonymous/public
-               if ($this->userId === false
-                       || (isset($_GET['service']) && $_GET['service'] == 'files' && isset($_GET['t']))
-               ) {
+               if (\OCA\Encryption\Helper::isPublicAccess()) {
                        $this->userId = $this->publicShareKeyId;
 
                        // only handle for files_sharing app