]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix shouldEncrypt and don't throw exception id fileKey not present - can happen
authorThomas Müller <thomas.mueller@tmit.eu>
Wed, 1 Apr 2015 13:41:31 +0000 (15:41 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 7 Apr 2015 11:30:30 +0000 (13:30 +0200)
apps/encryption/lib/crypto/encryption.php
apps/encryption/lib/exceptions/filekeymissingexception.php [deleted file]
apps/encryption/lib/keymanager.php

index d8b7f91e2680040fd05147f0357cdfc01cd18918..c3fd3405366f6bdfbaee2c9896d58c9ec4f60ea8 100644 (file)
@@ -10,6 +10,7 @@
 namespace OCA\Encryption\Crypto;
 
 
+use OCA\Encryption\Util;
 use OCP\Encryption\IEncryptionModule;
 use OCA\Encryption\KeyManager;
 
@@ -38,7 +39,7 @@ class Encryption implements IEncryptionModule {
        private $writeCache;
 
        /** @var KeyManager */
-       private $keymanager;
+       private $keyManager;
 
        /** @var array */
        private $accessList;
@@ -46,18 +47,18 @@ class Encryption implements IEncryptionModule {
        /** @var boolean */
        private $isWriteOperation;
 
-       /** @var \OCA\Encryption\Util */
+       /** @var Util */
        private $util;
 
        /**
         *
         * @param \OCA\Encryption\Crypto\Crypt $crypt
-        * @param KeyManager $keymanager
-        * @param \OCA\Encryption\Util $util
+        * @param KeyManager $keyManager
+        * @param Util $util
         */
-       public function __construct(Crypt $crypt, KeyManager $keymanager, \OCA\Encryption\Util $util) {
+       public function __construct(Crypt $crypt, KeyManager $keyManager, Util $util) {
                $this->crypt = $crypt;
-               $this->keymanager = $keymanager;
+               $this->keyManager = $keyManager;
                $this->util = $util;
        }
 
@@ -105,7 +106,7 @@ class Encryption implements IEncryptionModule {
                $this->writeCache = '';
                $this->isWriteOperation = false;
 
-               $this->fileKey = $this->keymanager->getFileKey($path, $this->user);
+               $this->fileKey = $this->keyManager->getFileKey($path, $this->user);
 
                return array('cipher' => $this->cipher);
        }
@@ -128,13 +129,13 @@ class Encryption implements IEncryptionModule {
                        }
                        $publicKeys = array();
                        foreach ($this->accessList['users'] as $uid) {
-                               $publicKeys[$uid] = $this->keymanager->getPublicKey($uid);
+                               $publicKeys[$uid] = $this->keyManager->getPublicKey($uid);
                        }
 
-                       $publicKeys = $this->keymanager->addSystemKeys($this->accessList, $publicKeys);
+                       $publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys);
 
                        $encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys);
-                       $this->keymanager->setAllFileKeys($path, $encryptedKeyfiles);
+                       $this->keyManager->setAllFileKeys($path, $encryptedKeyfiles);
                }
                return $result;
        }
@@ -231,19 +232,19 @@ class Encryption implements IEncryptionModule {
         * @return boolean
         */
        public function update($path, $uid, $accessList) {
-               $fileKey = $this->keymanager->getFileKey($path, $uid);
+               $fileKey = $this->keyManager->getFileKey($path, $uid);
                $publicKeys = array();
                foreach ($accessList['users'] as $user) {
-                       $publicKeys[$user] = $this->keymanager->getPublicKey($user);
+                       $publicKeys[$user] = $this->keyManager->getPublicKey($user);
                }
 
-               $publicKeys = $this->keymanager->addSystemKeys($accessList, $publicKeys);
+               $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys);
 
                $encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys);
 
-               $this->keymanager->deleteAllFileKeys($path);
+               $this->keyManager->deleteAllFileKeys($path);
 
-               $this->keymanager->setAllFileKeys($path, $encryptedFileKey);
+               $this->keyManager->setAllFileKeys($path, $encryptedFileKey);
 
                return true;
        }
@@ -257,13 +258,13 @@ class Encryption implements IEncryptionModule {
         */
        public function addSystemKeys(array $accessList, array $publicKeys) {
                if (!empty($accessList['public'])) {
-                       $publicKeys[$this->keymanager->getPublicShareKeyId()] = $this->keymanager->getPublicShareKey();
+                       $publicKeys[$this->keyManager->getPublicShareKeyId()] = $this->keyManager->getPublicShareKey();
                }
 
-               if ($this->keymanager->recoveryKeyExists() &&
+               if ($this->keyManager->recoveryKeyExists() &&
                        $this->util->recoveryEnabled($this->user)) {
 
-                       $publicKeys[$this->keymanager->getRecoveryKeyId()] = $this->keymanager->getRecoveryKey();
+                       $publicKeys[$this->keyManager->getRecoveryKeyId()] = $this->keyManager->getRecoveryKey();
                }
 
 
@@ -283,10 +284,10 @@ class Encryption implements IEncryptionModule {
                        return false;
                }
 
-               if ($parts[2] == '/files/') {
+               if ($parts[2] == 'files') {
                        return true;
                }
-               if ($parts[2] == '/files_versions/') {
+               if ($parts[2] == 'files_versions') {
                        return true;
                }
 
diff --git a/apps/encryption/lib/exceptions/filekeymissingexception.php b/apps/encryption/lib/exceptions/filekeymissingexception.php
deleted file mode 100644 (file)
index 9eb2d4c..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-<?php
-
-
-namespace OCA\Encryption\Exceptions;
-
-class FileKeyMissingException extends \Exception {
-
-}
index 4c5cb1365eadc5c99b38aeb6c0598e0ff9f14d3d..c7e0f2617f59ca8a51e19dddf83fc32076175fcc 100644 (file)
@@ -1,38 +1,15 @@
 <?php
-/**
- * @author Clark Tomlinson  <clark@owncloud.com>
- * @since 2/19/15, 1:20 PM
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
 
 namespace OCA\Encryption;
 
-
 use OC\Encryption\Exceptions\DecryptionFailedException;
-use OCA\Encryption\Exceptions\FileKeyMissingException;
 use OCA\Encryption\Exceptions\PrivateKeyMissingException;
 use OC\Encryption\Exceptions\PublicKeyMissingException;
 use OCA\Encryption\Crypto\Crypt;
 use OCP\Encryption\Keys\IStorage;
-use OCA\Encryption\Util;
 use OCP\IConfig;
 use OCP\ILogger;
 use OCP\IUserSession;
-use \OCA\Encryption\Session;
 
 class KeyManager {
 
@@ -211,11 +188,11 @@ class KeyManager {
                return false;
        }
 
-               /**
-        * @param string $uid
+       /**
         * @param string $password
         * @param array $keyPair
         * @return bool
+        * @internal param string $uid
         */
        public function setRecoveryKey($password, $keyPair) {
                // Save Public Key
@@ -351,7 +328,7 @@ class KeyManager {
                                $privateKey);
                }
 
-               throw new FileKeyMissingException();
+               return '';
        }
 
        /**
@@ -513,6 +490,7 @@ class KeyManager {
         * @param array $accessList
         * @param array $publicKeys
         * @return array
+        * @throws PublicKeyMissingException
         */
        public function addSystemKeys(array $accessList, array $publicKeys) {
                if (!empty($accessList['public'])) {