use OC\Encryption\Exceptions\DecryptionFailedException; | use OC\Encryption\Exceptions\DecryptionFailedException; | ||||
use OC\Encryption\Exceptions\EncryptionFailedException; | use OC\Encryption\Exceptions\EncryptionFailedException; | ||||
use OC\Encryption\Exceptions\GenericEncryptionException; | |||||
use OCA\Encryption\Exceptions\MultiKeyDecryptException; | use OCA\Encryption\Exceptions\MultiKeyDecryptException; | ||||
use OCA\Encryption\Exceptions\MultiKeyEncryptException; | use OCA\Encryption\Exceptions\MultiKeyEncryptException; | ||||
use OCP\Encryption\Exceptions\GenericEncryptionException; | |||||
use OCP\IConfig; | use OCP\IConfig; | ||||
use OCP\ILogger; | use OCP\ILogger; | ||||
use OCP\IUser; | use OCP\IUser; |
namespace OCA\Encryption\Exceptions; | namespace OCA\Encryption\Exceptions; | ||||
class MultiKeyDecryptException extends \Exception { | |||||
use OCP\Encryption\Exceptions\GenericEncryptionException; | |||||
class MultiKeyDecryptException extends GenericEncryptionException { | |||||
} | } |
namespace OCA\Encryption\Exceptions; | namespace OCA\Encryption\Exceptions; | ||||
class MultiKeyEncryptException extends \Exception { | |||||
use OCP\Encryption\Exceptions\GenericEncryptionException; | |||||
class MultiKeyEncryptException extends GenericEncryptionException { | |||||
} | } |
* | * | ||||
*/ | */ | ||||
namespace OCA\Encryption\Exceptions; | 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"); | |||||
} | |||||
} | } |
<?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"); | |||||
} | |||||
} |
use OC\Encryption\Exceptions\DecryptionFailedException; | use OC\Encryption\Exceptions\DecryptionFailedException; | ||||
use OCA\Encryption\Exceptions\PrivateKeyMissingException; | use OCA\Encryption\Exceptions\PrivateKeyMissingException; | ||||
use OC\Encryption\Exceptions\PublicKeyMissingException; | |||||
use OCA\Encryption\Exceptions\PublicKeyMissingException; | |||||
use OCA\Encryption\Crypto\Crypt; | use OCA\Encryption\Crypto\Crypt; | ||||
use OCP\Encryption\Keys\IStorage; | use OCP\Encryption\Keys\IStorage; | ||||
use OCP\IConfig; | use OCP\IConfig; | ||||
if (strlen($privateKey) !== 0) { | if (strlen($privateKey) !== 0) { | ||||
return $privateKey; | return $privateKey; | ||||
} | } | ||||
throw new PrivateKeyMissingException(); | |||||
throw new PrivateKeyMissingException($userId); | |||||
} | } | ||||
/** | /** | ||||
if (strlen($publicKey) !== 0) { | if (strlen($publicKey) !== 0) { | ||||
return $publicKey; | return $publicKey; | ||||
} | } | ||||
throw new PublicKeyMissingException(); | |||||
throw new PublicKeyMissingException($userId); | |||||
} | } | ||||
public function getPublicShareKeyId() { | public function getPublicShareKeyId() { | ||||
if (!empty($accessList['public'])) { | if (!empty($accessList['public'])) { | ||||
$publicShareKey = $this->getPublicShareKey(); | $publicShareKey = $this->getPublicShareKey(); | ||||
if (empty($publicShareKey)) { | if (empty($publicShareKey)) { | ||||
throw new PublicKeyMissingException(); | |||||
throw new PublicKeyMissingException($this->getPublicShareKeyId()); | |||||
} | } | ||||
$publicKeys[$this->getPublicShareKeyId()] = $publicShareKey; | $publicKeys[$this->getPublicShareKeyId()] = $publicShareKey; | ||||
} | } |
public function getPrivateKey() { | public function getPrivateKey() { | ||||
$key = $this->session->get('privateKey'); | $key = $this->session->get('privateKey'); | ||||
if (is_null($key)) { | 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; | return $key; | ||||
} | } |
namespace OC\Connector\Sabre; | 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 { | class File extends \OC\Connector\Sabre\Node implements \Sabre\DAV\IFile { | ||||
//throw exception if encryption is disabled but files are still encrypted | //throw exception if encryption is disabled but files are still encrypted | ||||
try { | try { | ||||
return $this->fileView->fopen(ltrim($this->path, '/'), 'rb'); | 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()); | throw new \Sabre\DAV\Exception\Forbidden($e->getMessage()); | ||||
} catch (\OCP\Files\StorageNotAvailableException $e) { | } catch (\OCP\Files\StorageNotAvailableException $e) { | ||||
throw new \Sabre\DAV\Exception\ServiceUnavailable("Failed to open file: ".$e->getMessage()); | throw new \Sabre\DAV\Exception\ServiceUnavailable("Failed to open file: ".$e->getMessage()); |
namespace OC\Encryption\Exceptions; | namespace OC\Encryption\Exceptions; | ||||
use OCP\Encryption\Exceptions\GenericEncryptionException; | |||||
class DecryptionFailedException extends GenericEncryptionException { | class DecryptionFailedException extends GenericEncryptionException { | ||||
namespace OC\Encryption\Exceptions; | namespace OC\Encryption\Exceptions; | ||||
use OCP\Encryption\Exceptions\GenericEncryptionException; | |||||
class EmptyEncryptionDataException extends GenericEncryptionException{ | class EmptyEncryptionDataException extends GenericEncryptionException{ | ||||
namespace OC\Encryption\Exceptions; | namespace OC\Encryption\Exceptions; | ||||
use OCP\Encryption\Exceptions\GenericEncryptionException; | |||||
class EncryptionFailedException extends GenericEncryptionException{ | class EncryptionFailedException extends GenericEncryptionException{ | ||||
namespace OC\Encryption\Exceptions; | 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'); | |||||
} | |||||
} | } |
namespace OC\Encryption\Exceptions; | namespace OC\Encryption\Exceptions; | ||||
use OCP\Encryption\Exceptions\GenericEncryptionException; | |||||
class EncryptionHeaderToLargeException extends GenericEncryptionException { | class EncryptionHeaderToLargeException extends GenericEncryptionException { | ||||
public function __construct($key) { | |||||
parent::__construct('max header size exceeded'); | |||||
} | |||||
} | } |
namespace OC\Encryption\Exceptions; | 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 . '"'); | |||||
} | |||||
} | } |
namespace OC\Encryption\Exceptions; | namespace OC\Encryption\Exceptions; | ||||
class ModuleDoesNotExistsException extends \Exception { | |||||
use OCP\Encryption\Exceptions\GenericEncryptionException; | |||||
class ModuleDoesNotExistsException extends GenericEncryptionException { | |||||
} | } |
<?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 { | |||||
} |
<?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 { | |||||
} |
<?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 { | |||||
} |
namespace OC\Encryption\Exceptions; | namespace OC\Encryption\Exceptions; | ||||
use OCP\Encryption\Exceptions\GenericEncryptionException; | |||||
class UnknownCipherException extends GenericEncryptionException{ | |||||
class UnknownCipherException extends GenericEncryptionException { | |||||
} | } |
namespace OC\Encryption\Keys; | namespace OC\Encryption\Keys; | ||||
use OC\Encryption\Exceptions\GenericEncryptionException; | |||||
use OC\Encryption\Util; | use OC\Encryption\Util; | ||||
use OC\Files\View; | use OC\Files\View; | ||||
use OCP\Encryption\Exceptions\GenericEncryptionException; | |||||
class Storage implements \OCP\Encryption\Keys\IStorage { | class Storage implements \OCP\Encryption\Keys\IStorage { | ||||
private function getFileKeyDir($path) { | private function getFileKeyDir($path) { | ||||
if ($this->view->is_dir($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); | list($owner, $filename) = $this->util->getUidAndFilename($path); |
$name = $module->getDisplayName(); | $name = $module->getDisplayName(); | ||||
if (isset($this->encryptionModules[$id])) { | 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(); | $defaultEncryptionModuleId = $this->getDefaultEncryptionModuleId(); |
$header = self::HEADER_START . ':' . self::HEADER_ENCRYPTION_MODULE_KEY . ':' . $encryptionModule->getId() . ':'; | $header = self::HEADER_START . ':' . self::HEADER_ENCRYPTION_MODULE_KEY . ':' . $encryptionModule->getId() . ':'; | ||||
foreach ($headerData as $key => $value) { | foreach ($headerData as $key => $value) { | ||||
if (in_array($key, $this->ocHeaderKeys)) { | if (in_array($key, $this->ocHeaderKeys)) { | ||||
throw new EncryptionHeaderKeyExistsException('header key "'. $key . '" already reserved by ownCloud'); | |||||
throw new EncryptionHeaderKeyExistsException($key); | |||||
} | } | ||||
$header .= $key . ':' . $value . ':'; | $header .= $key . ':' . $value . ':'; | ||||
} | } | ||||
$header .= self::HEADER_END; | $header .= self::HEADER_END; | ||||
if (strlen($header) > $this->getHeaderSize()) { | 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); | $paddedHeader = str_pad($header, $this->headerSize, self::HEADER_PADDING_CHAR, STR_PAD_RIGHT); |
* | * | ||||
*/ | */ | ||||
namespace OC\Encryption\Exceptions; | |||||
namespace OCP\Encryption\Exceptions; | |||||
class GenericEncryptionException extends \Exception { | 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); | |||||
} | |||||
} | } |