aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/lib')
-rwxr-xr-xapps/files_encryption/lib/helper.php16
-rw-r--r--apps/files_encryption/lib/session.php55
-rw-r--r--apps/files_encryption/lib/util.php6
3 files changed, 57 insertions, 20 deletions
diff --git a/apps/files_encryption/lib/helper.php b/apps/files_encryption/lib/helper.php
index 05172f5a386..1b3e5b1a642 100755
--- a/apps/files_encryption/lib/helper.php
+++ b/apps/files_encryption/lib/helper.php
@@ -170,4 +170,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
diff --git a/apps/files_encryption/lib/session.php b/apps/files_encryption/lib/session.php
index 52dd0b604e9..dbf9a487995 100644
--- a/apps/files_encryption/lib/session.php
+++ b/apps/files_encryption/lib/session.php
@@ -83,18 +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);
+ $encryptedKey = $this->view->file_get_contents( '/owncloud_private_key/' . $publicShareKeyId . '.private.key' );
+ $privateKey = Crypt::symmetricDecryptFileContent( $encryptedKey, '' );
+ $this->setPublicSharePrivateKey( $privateKey );
\OC_FileProxy::$enabled = $proxyStatus;
}
@@ -104,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) {
@@ -114,27 +112,52 @@ 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() {
+ // 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;
+ }
+ }
+ }
- if (
- isset($_SESSION['privateKey'])
- && !empty($_SESSION['privateKey'])
- ) {
+ /**
+ * @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
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 5840b354a22..840e37ddb26 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -127,13 +127,11 @@ 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
- if ($GLOBALS['app'] === 'files_sharing') {
+ if (isset($GLOBALS['app']) && $GLOBALS['app'] === 'files_sharing') {
$this->userDir = '/' . $GLOBALS['fileOwner'];
$this->fileFolderName = 'files';
$this->userFilesDir = '/' . $GLOBALS['fileOwner'] . '/'