]> source.dussan.org Git - nextcloud-server.git/commitdiff
cleaning up exception mess
authorThomas Müller <thomas.mueller@tmit.eu>
Wed, 1 Apr 2015 14:36:08 +0000 (16:36 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 7 Apr 2015 11:30:30 +0000 (13:30 +0200)
24 files changed:
apps/encryption/lib/crypto/crypt.php
apps/encryption/lib/exceptions/multikeydecryptexception.php
apps/encryption/lib/exceptions/multikeyencryptexception.php
apps/encryption/lib/exceptions/privatekeymissingexception.php
apps/encryption/lib/exceptions/publickeymissingexception.php [new file with mode: 0644]
apps/encryption/lib/keymanager.php
apps/encryption/lib/session.php
lib/private/connector/sabre/file.php
lib/private/encryption/exceptions/decryptionfailedexception.php
lib/private/encryption/exceptions/emptyencryptiondataexception.php
lib/private/encryption/exceptions/encryptionfailedexception.php
lib/private/encryption/exceptions/encryptionheaderkeyexistsexception.php
lib/private/encryption/exceptions/encryptionheadertolargeexception.php
lib/private/encryption/exceptions/genericencryptionexception.php [deleted file]
lib/private/encryption/exceptions/modulealreadyexistsexception.php
lib/private/encryption/exceptions/moduledoesnotexistsexception.php
lib/private/encryption/exceptions/publickeymissingexception.php [deleted file]
lib/private/encryption/exceptions/unexpectedblocksizeexception.php [deleted file]
lib/private/encryption/exceptions/unexpectedendofencryptionheaderexception.php [deleted file]
lib/private/encryption/exceptions/unknowncipherexception.php
lib/private/encryption/keys/storage.php
lib/private/encryption/manager.php
lib/private/encryption/util.php
lib/public/encryption/exceptions/genericencryptionexception.php [new file with mode: 0644]

index 6b79057fe7ee5bde8194cc76748ec1420b1e4a2a..80878b3ddb2bc1cd296dedf66f63d0f47f7a0cac 100644 (file)
@@ -24,9 +24,9 @@ namespace OCA\Encryption\Crypto;
 
 use OC\Encryption\Exceptions\DecryptionFailedException;
 use OC\Encryption\Exceptions\EncryptionFailedException;
-use OC\Encryption\Exceptions\GenericEncryptionException;
 use OCA\Encryption\Exceptions\MultiKeyDecryptException;
 use OCA\Encryption\Exceptions\MultiKeyEncryptException;
+use OCP\Encryption\Exceptions\GenericEncryptionException;
 use OCP\IConfig;
 use OCP\ILogger;
 use OCP\IUser;
index 36a95544e61ea120367238a5624995bad619e3f1..1466d35eda3b755685220fb8445735dfd75f192d 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace OCA\Encryption\Exceptions;
 
-class MultiKeyDecryptException extends \Exception {
+use OCP\Encryption\Exceptions\GenericEncryptionException;
+
+class MultiKeyDecryptException extends GenericEncryptionException {
 
 }
index e518a09d1ccd8b9290485e2ca9c3ba378e203ec9..daf528e2cf7dac373abb746c490419fc573ed3fc 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace OCA\Encryption\Exceptions;
 
-class MultiKeyEncryptException extends \Exception {
+use OCP\Encryption\Exceptions\GenericEncryptionException;
+
+class MultiKeyEncryptException extends GenericEncryptionException {
 
 }
index ddc3d11cdbccf7678ecbba97bbfb3cd3e5035fd7..50d75870b20309f87bcfd3f2901bd7ffb85f16b0 100644 (file)
  *
  */
 
-
 namespace OCA\Encryption\Exceptions;
 
+use OCP\Encryption\Exceptions\GenericEncryptionException;
+
+class PrivateKeyMissingException extends GenericEncryptionException {
 
-class PrivateKeyMissingException extends \Exception{
+       /**
+        * @param string $userId
+        */
+       public function __construct($userId) {
+               if(empty($userId)) {
+                       $userId = "<no-user-id-given>";
+               }
+               parent::__construct("Private Key missing for user: $userId");
+       }
 
 }
diff --git a/apps/encryption/lib/exceptions/publickeymissingexception.php b/apps/encryption/lib/exceptions/publickeymissingexception.php
new file mode 100644 (file)
index 0000000..9638c28
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+
+
+namespace OCA\Encryption\Exceptions;
+
+use OCP\Encryption\Exceptions\GenericEncryptionException;
+
+class PublicKeyMissingException extends GenericEncryptionException {
+
+       /**
+        * @param string $userId
+        */
+       public function __construct($userId) {
+               if(empty($userId)) {
+                       $userId = "<no-user-id-given>";
+               }
+               parent::__construct("Public Key missing for user: $userId");
+       }
+
+}
index c7e0f2617f59ca8a51e19dddf83fc32076175fcc..d2659f55a77d9a85199abec8bb3bb224c5ecaa59 100644 (file)
@@ -4,7 +4,7 @@ namespace OCA\Encryption;
 
 use OC\Encryption\Exceptions\DecryptionFailedException;
 use OCA\Encryption\Exceptions\PrivateKeyMissingException;
-use OC\Encryption\Exceptions\PublicKeyMissingException;
+use OCA\Encryption\Exceptions\PublicKeyMissingException;
 use OCA\Encryption\Crypto\Crypt;
 use OCP\Encryption\Keys\IStorage;
 use OCP\IConfig;
@@ -301,7 +301,7 @@ class KeyManager {
                if (strlen($privateKey) !== 0) {
                        return $privateKey;
                }
-               throw new PrivateKeyMissingException();
+               throw new PrivateKeyMissingException($userId);
        }
 
        /**
@@ -393,7 +393,7 @@ class KeyManager {
                if (strlen($publicKey) !== 0) {
                        return $publicKey;
                }
-               throw new PublicKeyMissingException();
+               throw new PublicKeyMissingException($userId);
        }
 
        public function getPublicShareKeyId() {
@@ -496,7 +496,7 @@ class KeyManager {
                if (!empty($accessList['public'])) {
                        $publicShareKey = $this->getPublicShareKey();
                        if (empty($publicShareKey)) {
-                               throw new PublicKeyMissingException();
+                               throw new PublicKeyMissingException($this->getPublicShareKeyId());
                        }
                        $publicKeys[$this->getPublicShareKeyId()] = $publicShareKey;
                }
index 5e9739137691cef29146c6317220e7b00d3f063a..82c7829ecbd83820e950fd24dbd62cc1abd49509 100644 (file)
@@ -70,7 +70,7 @@ class Session {
        public function getPrivateKey() {
                $key = $this->session->get('privateKey');
                if (is_null($key)) {
-                       throw new Exceptions\PrivateKeyMissingException('no private key stored in session');
+                       throw new Exceptions\PrivateKeyMissingException('no private key stored in session', 0);
                }
                return $key;
        }
index a436973ba913b5bae16216cf4e60658780c52e0f..f6f5daf2074a258080db67a48d3cbc088f8ef956 100644 (file)
@@ -35,7 +35,7 @@
 
 namespace OC\Connector\Sabre;
 
-use OC\Encryption\Exceptions\GenericEncryptionException;
+use OCP\Encryption\Exceptions\GenericEncryptionException;
 
 class File extends \OC\Connector\Sabre\Node implements \Sabre\DAV\IFile {
 
@@ -184,7 +184,7 @@ class File extends \OC\Connector\Sabre\Node implements \Sabre\DAV\IFile {
                //throw exception if encryption is disabled but files are still encrypted
                try {
                        return $this->fileView->fopen(ltrim($this->path, '/'), 'rb');
-               } catch (\OCP\Encryption\Exception\EncryptionException $e) {
+               } catch (\OCP\Encryption\Exceptions\GenericEncryptionException $e) {
                        throw new \Sabre\DAV\Exception\Forbidden($e->getMessage());
                } catch (\OCP\Files\StorageNotAvailableException $e) {
                        throw new \Sabre\DAV\Exception\ServiceUnavailable("Failed to open file: ".$e->getMessage());
index 43fea90fed8403a6919d8acd382fb38626a43589..f8b4fdf07fa3eafa820bc761c7202f1cee82e407 100644 (file)
@@ -22,6 +22,7 @@
 
 namespace OC\Encryption\Exceptions;
 
+use OCP\Encryption\Exceptions\GenericEncryptionException;
 
 class DecryptionFailedException extends GenericEncryptionException {
 
index ea181809856982748efcf7d6b9b443694e4bc051..d3dc92300475b9b9883c978877fbba270d1a53df 100644 (file)
@@ -22,6 +22,7 @@
 
 namespace OC\Encryption\Exceptions;
 
+use OCP\Encryption\Exceptions\GenericEncryptionException;
 
 class EmptyEncryptionDataException extends GenericEncryptionException{
 
index 9e6648f7bf5fd2680e76383d9fddf1d229211507..ac489c7325475eef180cf7339da8767b61362c5c 100644 (file)
@@ -22,6 +22,7 @@
 
 namespace OC\Encryption\Exceptions;
 
+use OCP\Encryption\Exceptions\GenericEncryptionException;
 
 class EncryptionFailedException extends GenericEncryptionException{
 
index 23103b90c4f02fd7b024d4dee88381be9fe53552..5e8e48efd783753395429dbf79c45763f1235e71 100644 (file)
 
 namespace OC\Encryption\Exceptions;
 
+use OCP\Encryption\Exceptions\GenericEncryptionException;
 
-class EncryptionHeaderKeyExistsException extends \Exception {
-
-}
-
-class EncryptionHeaderToLargeException extends \Exception {
+class EncryptionHeaderKeyExistsException extends GenericEncryptionException {
 
+       /**
+        * @param string $key
+        */
+       public function __construct($key) {
+               parent::__construct('header key "'. $key . '" already reserved by ownCloud');
+       }
 }
index cc980aa4beb304989db2559245d13342845e8e5b..94a130d792d6a03c073265c5e6d450a1eeda9903 100644 (file)
 
 namespace OC\Encryption\Exceptions;
 
+use OCP\Encryption\Exceptions\GenericEncryptionException;
 
 class EncryptionHeaderToLargeException extends GenericEncryptionException {
 
+       public function __construct($key) {
+               parent::__construct('max header size exceeded');
+       }
+
 }
diff --git a/lib/private/encryption/exceptions/genericencryptionexception.php b/lib/private/encryption/exceptions/genericencryptionexception.php
deleted file mode 100644 (file)
index 608e5e6..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-  /**
- * @author Clark Tomlinson  <clark@owncloud.com>
- * @since 2/25/15, 9:30 AM
- * @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 OC\Encryption\Exceptions;
-
-
-class GenericEncryptionException extends \Exception {
-
-}
index 41fc0188e24b115ec4cc696925a298492051c21d..fa1e70a5c36ec85c02afa87e13fedb72ae1c9731 100644 (file)
 
 namespace OC\Encryption\Exceptions;
 
-class ModuleAlreadyExistsException extends \Exception {
+use OCP\Encryption\Exceptions\GenericEncryptionException;
+
+class ModuleAlreadyExistsException extends GenericEncryptionException {
+
+       /**
+        * @param string $id
+        * @param string $name
+        */
+       public function __construct($id, $name) {
+               parent::__construct('Id "' . $id . '" already used by encryption module "' . $name . '"');
+       }
 
 }
index 5507bd03daba961b046beddfafe06680213eb6d7..2c699e8dc2da8d566e19b86d56927db73b865812 100644 (file)
@@ -23,6 +23,8 @@
 
 namespace OC\Encryption\Exceptions;
 
-class ModuleDoesNotExistsException extends \Exception {
+use OCP\Encryption\Exceptions\GenericEncryptionException;
+
+class ModuleDoesNotExistsException extends GenericEncryptionException {
 
 }
diff --git a/lib/private/encryption/exceptions/publickeymissingexception.php b/lib/private/encryption/exceptions/publickeymissingexception.php
deleted file mode 100644 (file)
index d5f2aae..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-/**
- * @author Clark Tomlinson  <clark@owncloud.com>
- * @since 2/25/15, 9:39 AM
- * @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 OC\Encryption\Exceptions;
-
-
-class PublicKeyMissingException extends GenericEncryptionException {
-
-}
diff --git a/lib/private/encryption/exceptions/unexpectedblocksizeexception.php b/lib/private/encryption/exceptions/unexpectedblocksizeexception.php
deleted file mode 100644 (file)
index 799d08e..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-  /**
- * @author Clark Tomlinson  <clark@owncloud.com>
- * @since 2/25/15, 9:35 AM
- * @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 OC\Encryption\Exceptions;
-
-
-interface UnexpectedBlockSize {
-
-}
diff --git a/lib/private/encryption/exceptions/unexpectedendofencryptionheaderexception.php b/lib/private/encryption/exceptions/unexpectedendofencryptionheaderexception.php
deleted file mode 100644 (file)
index 04f65cf..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-  /**
- * @author Clark Tomlinson  <clark@owncloud.com>
- * @since 2/25/15, 9:34 AM
- * @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 OC\Encryption\Exceptions;
-
-
-class UnexpectedEndOfEncryptionHeaderException extends GenericEncryptionException {
-
-}
index 5177af6106bf14d3f149c01193ad1fbce626f261..188f74038486cf0b59c691fb17abd30f8471e4cc 100644 (file)
@@ -22,7 +22,8 @@
 
 namespace OC\Encryption\Exceptions;
 
+use OCP\Encryption\Exceptions\GenericEncryptionException;
 
-class UnknownCipherException extends GenericEncryptionException{
+class UnknownCipherException extends GenericEncryptionException {
 
 }
index 82753df1dc762c3254dc825d1aa98776ef9e5f46..e4e3fb084f31902dd6fcd5d47a3b35b94b704c37 100644 (file)
@@ -23,9 +23,9 @@
 
 namespace OC\Encryption\Keys;
 
-use OC\Encryption\Exceptions\GenericEncryptionException;
 use OC\Encryption\Util;
 use OC\Files\View;
+use OCP\Encryption\Exceptions\GenericEncryptionException;
 
 class Storage implements \OCP\Encryption\Keys\IStorage {
 
@@ -259,7 +259,7 @@ class Storage implements \OCP\Encryption\Keys\IStorage {
        private function getFileKeyDir($path) {
 
                if ($this->view->is_dir($path)) {
-                       throw new GenericEncryptionException('file was expected but directory was given');
+                       throw new GenericEncryptionException("file was expected but directory was given: $path");
                }
 
                list($owner, $filename) = $this->util->getUidAndFilename($path);
index 77f02b0c489702c9a8e4313ff04c3f71e6fe7d3e..f8ac174479e700b578db4d60ddcd9b947c98261f 100644 (file)
@@ -70,8 +70,7 @@ class Manager implements \OCP\Encryption\IManager {
                $name = $module->getDisplayName();
 
                if (isset($this->encryptionModules[$id])) {
-                       $message = 'Id "' . $id . '" already used by encryption module "' . $name . '"';
-                       throw new Exceptions\ModuleAlreadyExistsException($message);
+                       throw new Exceptions\ModuleAlreadyExistsException($id, $name);
                }
 
                $defaultEncryptionModuleId = $this->getDefaultEncryptionModuleId();
index 1183e6622bb3a2e007d1834b33f83b805efc1605..e2c7fa26e660e7a2067f2469a16807b75ae73245 100644 (file)
@@ -147,14 +147,14 @@ class Util {
                $header = self::HEADER_START . ':' . self::HEADER_ENCRYPTION_MODULE_KEY . ':' . $encryptionModule->getId() . ':';
                foreach ($headerData as $key => $value) {
                        if (in_array($key, $this->ocHeaderKeys)) {
-                               throw new EncryptionHeaderKeyExistsException('header key "'. $key . '" already reserved by ownCloud');
+                               throw new EncryptionHeaderKeyExistsException($key);
                        }
                        $header .= $key . ':' . $value . ':';
                }
                $header .= self::HEADER_END;
 
                if (strlen($header) > $this->getHeaderSize()) {
-                       throw new EncryptionHeaderToLargeException('max header size exceeded');
+                       throw new EncryptionHeaderToLargeException();
                }
 
                $paddedHeader = str_pad($header, $this->headerSize, self::HEADER_PADDING_CHAR, STR_PAD_RIGHT);
diff --git a/lib/public/encryption/exceptions/genericencryptionexception.php b/lib/public/encryption/exceptions/genericencryptionexception.php
new file mode 100644 (file)
index 0000000..b7addd3
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+  /**
+ * @author Clark Tomlinson  <clark@owncloud.com>
+ * @since 2/25/15, 9:30 AM
+ * @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 OCP\Encryption\Exceptions;
+
+
+class GenericEncryptionException extends \Exception {
+
+       public function __construct($message = "", $code = 0, \Exception $previous = null) {
+               if (empty($message)) {
+                       $message = 'Unspecified encryption exception';
+               }
+               parent::__construct($message, $code, $previous);
+       }
+
+}