Browse Source

cleaning up exception mess

tags/v8.1.0alpha1
Thomas Müller 9 years ago
parent
commit
664b2bb7af
23 changed files with 91 additions and 111 deletions
  1. 1
    1
      apps/encryption/lib/crypto/crypt.php
  2. 3
    1
      apps/encryption/lib/exceptions/multikeydecryptexception.php
  3. 3
    1
      apps/encryption/lib/exceptions/multikeyencryptexception.php
  4. 12
    2
      apps/encryption/lib/exceptions/privatekeymissingexception.php
  5. 20
    0
      apps/encryption/lib/exceptions/publickeymissingexception.php
  6. 4
    4
      apps/encryption/lib/keymanager.php
  7. 1
    1
      apps/encryption/lib/session.php
  8. 2
    2
      lib/private/connector/sabre/file.php
  9. 1
    0
      lib/private/encryption/exceptions/decryptionfailedexception.php
  10. 1
    0
      lib/private/encryption/exceptions/emptyencryptiondataexception.php
  11. 1
    0
      lib/private/encryption/exceptions/encryptionfailedexception.php
  12. 8
    5
      lib/private/encryption/exceptions/encryptionheaderkeyexistsexception.php
  13. 5
    0
      lib/private/encryption/exceptions/encryptionheadertolargeexception.php
  14. 11
    1
      lib/private/encryption/exceptions/modulealreadyexistsexception.php
  15. 3
    1
      lib/private/encryption/exceptions/moduledoesnotexistsexception.php
  16. 0
    28
      lib/private/encryption/exceptions/publickeymissingexception.php
  17. 0
    28
      lib/private/encryption/exceptions/unexpectedblocksizeexception.php
  18. 0
    28
      lib/private/encryption/exceptions/unexpectedendofencryptionheaderexception.php
  19. 2
    1
      lib/private/encryption/exceptions/unknowncipherexception.php
  20. 2
    2
      lib/private/encryption/keys/storage.php
  21. 1
    2
      lib/private/encryption/manager.php
  22. 2
    2
      lib/private/encryption/util.php
  23. 8
    1
      lib/public/encryption/exceptions/genericencryptionexception.php

+ 1
- 1
apps/encryption/lib/crypto/crypt.php View 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;

+ 3
- 1
apps/encryption/lib/exceptions/multikeydecryptexception.php View File

@@ -2,6 +2,8 @@

namespace OCA\Encryption\Exceptions;

class MultiKeyDecryptException extends \Exception {
use OCP\Encryption\Exceptions\GenericEncryptionException;

class MultiKeyDecryptException extends GenericEncryptionException {

}

+ 3
- 1
apps/encryption/lib/exceptions/multikeyencryptexception.php View File

@@ -2,6 +2,8 @@

namespace OCA\Encryption\Exceptions;

class MultiKeyEncryptException extends \Exception {
use OCP\Encryption\Exceptions\GenericEncryptionException;

class MultiKeyEncryptException extends GenericEncryptionException {

}

+ 12
- 2
apps/encryption/lib/exceptions/privatekeymissingexception.php View File

@@ -19,10 +19,20 @@
*
*/


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");
}

}

+ 20
- 0
apps/encryption/lib/exceptions/publickeymissingexception.php View File

@@ -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");
}

}

+ 4
- 4
apps/encryption/lib/keymanager.php View 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;
}

+ 1
- 1
apps/encryption/lib/session.php View 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;
}

+ 2
- 2
lib/private/connector/sabre/file.php View 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());

+ 1
- 0
lib/private/encryption/exceptions/decryptionfailedexception.php View File

@@ -22,6 +22,7 @@

namespace OC\Encryption\Exceptions;

use OCP\Encryption\Exceptions\GenericEncryptionException;

class DecryptionFailedException extends GenericEncryptionException {


+ 1
- 0
lib/private/encryption/exceptions/emptyencryptiondataexception.php View File

@@ -22,6 +22,7 @@

namespace OC\Encryption\Exceptions;

use OCP\Encryption\Exceptions\GenericEncryptionException;

class EmptyEncryptionDataException extends GenericEncryptionException{


+ 1
- 0
lib/private/encryption/exceptions/encryptionfailedexception.php View File

@@ -22,6 +22,7 @@

namespace OC\Encryption\Exceptions;

use OCP\Encryption\Exceptions\GenericEncryptionException;

class EncryptionFailedException extends GenericEncryptionException{


+ 8
- 5
lib/private/encryption/exceptions/encryptionheaderkeyexistsexception.php View File

@@ -23,11 +23,14 @@

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');
}
}

+ 5
- 0
lib/private/encryption/exceptions/encryptionheadertolargeexception.php View File

@@ -22,7 +22,12 @@

namespace OC\Encryption\Exceptions;

use OCP\Encryption\Exceptions\GenericEncryptionException;

class EncryptionHeaderToLargeException extends GenericEncryptionException {

public function __construct($key) {
parent::__construct('max header size exceeded');
}

}

+ 11
- 1
lib/private/encryption/exceptions/modulealreadyexistsexception.php View File

@@ -23,6 +23,16 @@

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 . '"');
}

}

+ 3
- 1
lib/private/encryption/exceptions/moduledoesnotexistsexception.php View File

@@ -23,6 +23,8 @@

namespace OC\Encryption\Exceptions;

class ModuleDoesNotExistsException extends \Exception {
use OCP\Encryption\Exceptions\GenericEncryptionException;

class ModuleDoesNotExistsException extends GenericEncryptionException {

}

+ 0
- 28
lib/private/encryption/exceptions/publickeymissingexception.php View File

@@ -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 {

}

+ 0
- 28
lib/private/encryption/exceptions/unexpectedblocksizeexception.php View File

@@ -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 {

}

+ 0
- 28
lib/private/encryption/exceptions/unexpectedendofencryptionheaderexception.php View File

@@ -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 {

}

+ 2
- 1
lib/private/encryption/exceptions/unknowncipherexception.php View File

@@ -22,7 +22,8 @@

namespace OC\Encryption\Exceptions;

use OCP\Encryption\Exceptions\GenericEncryptionException;

class UnknownCipherException extends GenericEncryptionException{
class UnknownCipherException extends GenericEncryptionException {

}

+ 2
- 2
lib/private/encryption/keys/storage.php View 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);

+ 1
- 2
lib/private/encryption/manager.php View 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();

+ 2
- 2
lib/private/encryption/util.php View 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);

lib/private/encryption/exceptions/genericencryptionexception.php → lib/public/encryption/exceptions/genericencryptionexception.php View File

@@ -19,9 +19,16 @@
*
*/

namespace OC\Encryption\Exceptions;
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);
}

}

Loading…
Cancel
Save