diff options
author | Clark Tomlinson <fallen013@gmail.com> | 2015-02-24 13:05:19 -0500 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-07 13:30:27 +0200 |
commit | 39733c8da1c12cc79b7d650edf2ea1074330ee5f (patch) | |
tree | 9d072f0ebd7c0a185c5d6afeb345b5d0ae55295e /lib | |
parent | 63e7fe608a5f507c5d2b417c45cf26589d091ebc (diff) | |
download | nextcloud-server-39733c8da1c12cc79b7d650edf2ea1074330ee5f.tar.gz nextcloud-server-39733c8da1c12cc79b7d650edf2ea1074330ee5f.zip |
Initial commit
Diffstat (limited to 'lib')
12 files changed, 339 insertions, 27 deletions
diff --git a/lib/private/encryption/exceptions/decryptionfailedexception.php b/lib/private/encryption/exceptions/decryptionfailedexception.php new file mode 100644 index 00000000000..43fea90fed8 --- /dev/null +++ b/lib/private/encryption/exceptions/decryptionfailedexception.php @@ -0,0 +1,28 @@ +<?php + /** + * @author Clark Tomlinson <clark@owncloud.com> + * @since 2/25/15, 9:38 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 DecryptionFailedException extends GenericEncryptionException { + +} diff --git a/lib/private/encryption/exceptions/emptyencryptiondataexception.php b/lib/private/encryption/exceptions/emptyencryptiondataexception.php new file mode 100644 index 00000000000..ea181809856 --- /dev/null +++ b/lib/private/encryption/exceptions/emptyencryptiondataexception.php @@ -0,0 +1,28 @@ +<?php + /** + * @author Clark Tomlinson <clark@owncloud.com> + * @since 2/25/15, 9:38 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 EmptyEncryptionDataException extends GenericEncryptionException{ + +} diff --git a/lib/private/encryption/exceptions/encryptionfailedexception.php b/lib/private/encryption/exceptions/encryptionfailedexception.php new file mode 100644 index 00000000000..9e6648f7bf5 --- /dev/null +++ b/lib/private/encryption/exceptions/encryptionfailedexception.php @@ -0,0 +1,28 @@ +<?php + /** + * @author Clark Tomlinson <clark@owncloud.com> + * @since 2/25/15, 9:37 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 EncryptionFailedException extends GenericEncryptionException{ + +} diff --git a/lib/private/encryption/exceptions/encryptionheadertolargeexception.php b/lib/private/encryption/exceptions/encryptionheadertolargeexception.php new file mode 100644 index 00000000000..cc980aa4beb --- /dev/null +++ b/lib/private/encryption/exceptions/encryptionheadertolargeexception.php @@ -0,0 +1,28 @@ +<?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; + + +class EncryptionHeaderToLargeException extends GenericEncryptionException { + +} diff --git a/lib/private/encryption/exceptions/genericencryptionexception.php b/lib/private/encryption/exceptions/genericencryptionexception.php new file mode 100644 index 00000000000..608e5e6010a --- /dev/null +++ b/lib/private/encryption/exceptions/genericencryptionexception.php @@ -0,0 +1,27 @@ +<?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 { + +} diff --git a/lib/private/encryption/exceptions/privatekeymissingexception.php b/lib/private/encryption/exceptions/privatekeymissingexception.php new file mode 100644 index 00000000000..878b83d240c --- /dev/null +++ b/lib/private/encryption/exceptions/privatekeymissingexception.php @@ -0,0 +1,28 @@ +<?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 PrivateKeyMissingException extends GenericEncryptionException{ + +} diff --git a/lib/private/encryption/exceptions/publickeymissingexception.php b/lib/private/encryption/exceptions/publickeymissingexception.php new file mode 100644 index 00000000000..d5f2aae42cc --- /dev/null +++ b/lib/private/encryption/exceptions/publickeymissingexception.php @@ -0,0 +1,28 @@ +<?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 new file mode 100644 index 00000000000..799d08e6bab --- /dev/null +++ b/lib/private/encryption/exceptions/unexpectedblocksizeexception.php @@ -0,0 +1,28 @@ +<?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 new file mode 100644 index 00000000000..04f65cf7626 --- /dev/null +++ b/lib/private/encryption/exceptions/unexpectedendofencryptionheaderexception.php @@ -0,0 +1,28 @@ +<?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 { + +} diff --git a/lib/private/encryption/exceptions/unknowncipherexception.php b/lib/private/encryption/exceptions/unknowncipherexception.php new file mode 100644 index 00000000000..5177af6106b --- /dev/null +++ b/lib/private/encryption/exceptions/unknowncipherexception.php @@ -0,0 +1,28 @@ +<?php + /** + * @author Clark Tomlinson <clark@owncloud.com> + * @since 2/25/15, 9:36 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 UnknownCipherException extends GenericEncryptionException{ + +} diff --git a/lib/private/encryption/keystorage.php b/lib/private/encryption/keystorage.php index 5b56f6af4e7..fbc427edf0f 100644 --- a/lib/private/encryption/keystorage.php +++ b/lib/private/encryption/keystorage.php @@ -23,25 +23,29 @@ namespace OC\Encryption; +use OC\Encryption\Util; +use OC\Files\View; +use OCA\Files_Encryption\Exception\EncryptionException; + class KeyStorage implements \OCP\Encryption\IKeyStorage { - /** @var \OC\Files\View */ + /** @var View */ private $view; - /** @var \OC\Encryption\Util */ + /** @var Util */ private $util; // base dir where all the file related keys are stored private static $keys_base_dir = '/files_encryption/keys/'; private static $encryption_base_dir = '/files_encryption'; - private static $key_cache = array(); // cache keys + private $keyCache = array(); /** - * @param \OC\Files\View $view - * @param \OC\Encryption\Util $util + * @param View $view + * @param Util $util */ - public function __construct(\OC\Files\View $view, \OC\Encryption\Util $util) { + public function __construct(View $view, Util $util) { $this->view = $view; $this->util = $util; } @@ -50,14 +54,13 @@ class KeyStorage implements \OCP\Encryption\IKeyStorage { * get user specific key * * @param string $uid ID if the user for whom we want the key - * @param string $keyid id of the key + * @param string $keyId id of the key * * @return mixed key */ - public function getUserKey($uid, $keyid) { - $path = '/' . $uid . self::$encryption_base_dir . '/' . $uid . '.' . $keyid; + public function getUserKey($uid, $keyId) { + $path = '/' . $uid . self::$encryption_base_dir . '/' . $uid . '.' . $keyId; return $this->getKey($path); - } /** @@ -135,8 +138,8 @@ class KeyStorage implements \OCP\Encryption\IKeyStorage { $key = ''; - if (isset(self::$key_cache[$path])) { - $key = self::$key_cache[$path]; + if (isset($this->keyCache[$path])) { + $key = $this->keyCache[$path]; } else { /** @var \OCP\Files\Storage $storage */ @@ -144,7 +147,7 @@ class KeyStorage implements \OCP\Encryption\IKeyStorage { if ($storage->file_exists($internalPath)) { $key = $storage->file_get_contents($internalPath); - self::$key_cache[$path] = $key; + $this->keyCache[$path] = $key; } } @@ -168,7 +171,7 @@ class KeyStorage implements \OCP\Encryption\IKeyStorage { $result = $storage->file_put_contents($internalPath, $key); if (is_int($result) && $result > 0) { - self::$key_cache[$path] = $key; + $this->keyCache[$path] = $key; return true; } @@ -180,11 +183,16 @@ class KeyStorage implements \OCP\Encryption\IKeyStorage { * * @param string $path path to the file, relative to the users file directory * @return string + * @throws EncryptionException + * @internal param string $keyId */ private function getFileKeyDir($path) { + // + // TODO: NO DEPRICATED API !!! + // if ($this->view->is_dir('/' . \OCP\User::getUser() . '/' . $path)) { - throw new Exception\EncryptionException('file was expected but directoy was given', Exception\EncryptionException::GENERIC); + throw new EncryptionException('file was expected but directory was given', EncryptionException::GENERIC); } list($owner, $filename) = $this->util->getUidAndFilename($path); @@ -220,4 +228,23 @@ class KeyStorage implements \OCP\Encryption\IKeyStorage { } } + /** + * Check if encryption system is ready to begin encrypting + * all the things + * + * @return bool + */ + public function ready() { + $paths = [ + self::$encryption_base_dir, + self::$keys_base_dir + ]; + foreach ($paths as $path) { + if (!$this->view->file_exists($path)) { + return false; + } + } + return true; + } + } diff --git a/lib/public/encryption/ikeystorage.php b/lib/public/encryption/ikeystorage.php index cf94d56e59b..2ab5048709e 100644 --- a/lib/public/encryption/ikeystorage.php +++ b/lib/public/encryption/ikeystorage.php @@ -29,59 +29,65 @@ interface IKeyStorage { * get user specific key * * @param string $uid ID if the user for whom we want the key - * @param string $keyid id of the key + * @param string $keyId id of the key * * @return mixed key */ - public function getUserKey($uid, $keyid); + public function getUserKey($uid, $keyId); /** * get file specific key * * @param string $path path to file - * @param string $keyid id of the key + * @param string $keyId id of the key * * @return mixed key */ - public function getFileKey($path, $keyid); + public function getFileKey($path, $keyId); /** * get system-wide encryption keys not related to a specific user, * e.g something like a key for public link shares * - * @param string $keyid id of the key + * @param string $keyId id of the key * * @return mixed key */ - public function getSystemUserKey($uid, $keyid); + public function getSystemUserKey($keyId); /** * set user specific key * * @param string $uid ID if the user for whom we want the key - * @param string $keyid id of the key + * @param string $keyId id of the key * @param mixed $key */ - public function setUserKey($uid, $keyid, $key); + public function setUserKey($uid, $keyId, $key); /** * set file specific key * * @param string $path path to file - * @param string $keyid id of the key + * @param string $keyId id of the key * @param mixed $key */ - public function setFileKey($path, $keyid, $key); + public function setFileKey($path, $keyId, $key); /** * set system-wide encryption keys not related to a specific user, * e.g something like a key for public link shares * - * @param string $keyid id of the key + * @param string $keyId id of the key * @param mixed $key * * @return mixed key */ - public function setSystemUserKey($uid, $keyid, $key); + public function setSystemUserKey($keyId, $key); + /** + * Return if encryption is setup and ready encrypt things + * + * @return bool + */ + public function ready(); } |