From: Thomas Müller Date: Thu, 26 Mar 2015 08:32:08 +0000 (+0100) Subject: fixing obvious bugs while testing X-Git-Tag: v8.1.0alpha1~78^2~111 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ecb3834554c05c82ea3129299673dca4a0917b30;p=nextcloud-server.git fixing obvious bugs while testing --- diff --git a/apps/encryption/appinfo/encryption.php b/apps/encryption/appinfo/encryption.php index 1a4c17eb60a..a3ca8ec5624 100644 --- a/apps/encryption/appinfo/encryption.php +++ b/apps/encryption/appinfo/encryption.php @@ -64,8 +64,8 @@ class Encryption extends \OCP\AppFramework\App { */ public function boot() { $this->registerServices(); - $this->registerHooks(); $this->registerEncryptionModule(); + $this->registerHooks(); $this->registerSettings(); } @@ -96,7 +96,12 @@ class Encryption extends \OCP\AppFramework\App { * */ public function registerEncryptionModule() { - $this->encryptionManager->registerEncryptionModule(new \OCA\Encryption\Crypto\Encryption()); + $container = $this->getContainer(); + $container->registerService('EncryptionModule', function (IAppContainer $c) { + return new \OCA\Encryption\Crypto\Encryption($c->query('Crypt')); + }); + $module = $container->query('EncryptionModule'); + $this->encryptionManager->registerEncryptionModule($module); } /** @@ -117,7 +122,8 @@ class Encryption extends \OCP\AppFramework\App { function (IAppContainer $c) { $server = $c->getServer(); - return new KeyManager($server->getEncryptionKeyStorage('encryption'), + $moduleId = $c->query('EncryptionModule')->getId(); + return new KeyManager($server->getEncryptionKeyStorage($moduleId), $c->query('Crypt'), $server->getConfig(), $server->getUserSession(), @@ -131,13 +137,14 @@ class Encryption extends \OCP\AppFramework\App { function (IAppContainer $c) { $server = $c->getServer(); + $moduleId = $c->query('EncryptionModule')->getId(); return new Recovery( $server->getUserSession(), $c->query('Crypt'), $server->getSecureRandom(), $c->query('KeyManager'), $server->getConfig(), - $server->getEncryptionKeyStorage('encryption')); + $server->getEncryptionKeyStorage($moduleId)); }); $container->registerService('UserSetup', @@ -149,16 +156,6 @@ class Encryption extends \OCP\AppFramework\App { $c->query('KeyManager')); }); - $container->registerService('Migrator', - function (IAppContainer $c) { - $server = $c->getServer(); - - return new Migrator($server->getConfig(), - $server->getUserManager(), - $server->getLogger(), - $c->query('Crypt')); - }); - $container->registerService('Util', function (IAppContainer $c) { $server = $c->getServer(); diff --git a/apps/encryption/hooks/userhooks.php b/apps/encryption/hooks/userhooks.php index 096fd3beb93..e8c5fb8bfb7 100644 --- a/apps/encryption/hooks/userhooks.php +++ b/apps/encryption/hooks/userhooks.php @@ -63,7 +63,6 @@ class UserHooks implements IHook { * @param IUserSession $user * @param OCUtil $ocUtil * @param Util $util - * @internal param Migrator $migrator */ public function __construct( KeyManager $keyManager, ILogger $logger, Setup $userSetup, IUserSession $user, OCUtil $ocUtil, Util $util) { diff --git a/apps/encryption/lib/crypto/Encryption.php b/apps/encryption/lib/crypto/Encryption.php deleted file mode 100644 index b8429d7124e..00000000000 --- a/apps/encryption/lib/crypto/Encryption.php +++ /dev/null @@ -1,129 +0,0 @@ - - * @since 3/6/15, 2:28 PM - * @link http:/www.clarkt.com - * @copyright Clark Tomlinson © 2015 - * - */ - -namespace OCA\Encryption\Crypto; - - -use OCP\Encryption\IEncryptionModule; - -class Encryption extends Crypt implements IEncryptionModule { - - /** - * @return string defining the technical unique id - */ - public function getId() { - return md5($this->getDisplayName()); - } - - /** - * In comparison to getKey() this function returns a human readable (maybe translated) name - * - * @return string - */ - public function getDisplayName() { - return 'ownCloud Default Encryption'; - } - - /** - * start receiving chunks from a file. This is the place where you can - * perform some initial step before starting encrypting/decrypting the - * chunks - * - * @param string $path to the file - * @param array $header contains the header data read from the file - * @param array $accessList who has access to the file contains the key 'users' and 'public' - * - * $return array $header contain data as key-value pairs which should be - * written to the header, in case of a write operation - * or if no additional data is needed return a empty array - */ - public function begin($path, $header, $accessList) { - - // TODO: Implement begin() method. - // return additional header information that needs to be written i.e. cypher used - } - - /** - * last chunk received. This is the place where you can perform some final - * operation and return some remaining data if something is left in your - * buffer. - * - * @param string $path to the file - * @return string remained data which should be written to the file in case - * of a write operation - */ - public function end($path) { - // TODO: Implement end() method. - } - - /** - * encrypt data - * - * @param string $data you want to encrypt - * @return mixed encrypted data - */ - public function encrypt($data) { - // Todo: xxx Update Signature and usages - // passphrase is file key decrypted with user private/share key - $this->symmetricEncryptFileContent($data); - } - - /** - * decrypt data - * - * @param string $data you want to decrypt - * @param string $user decrypt as user (null for public access) - * @return mixed decrypted data - */ - public function decrypt($data, $user) { - // Todo: xxx Update Usages? - $this->symmetricDecryptFileContent($data, $user); - } - - /** - * update encrypted file, e.g. give additional users access to the file - * - * @param string $path path to the file which should be updated - * @param array $accessList who has access to the file contains the key 'users' and 'public' - * @return boolean - */ - public function update($path, $accessList) { - // TODO: Implement update() method. - } - - /** - * should the file be encrypted or not - * - * @param string $path - * @return boolean - */ - public function shouldEncrypt($path) { - // TODO: Implement shouldEncrypt() method. - } - - /** - * calculate unencrypted size - * - * @param string $path to file - * @return integer unencrypted size - */ - public function calculateUnencryptedSize($path) { - // TODO: Implement calculateUnencryptedSize() method. - } - - /** - * get size of the unencrypted payload per block. - * ownCloud read/write files with a block size of 8192 byte - * - * @return integer - */ - public function getUnencryptedBlockSize() { - // TODO: Implement getUnencryptedBlockSize() method. - } -} diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php new file mode 100644 index 00000000000..a29575c11e0 --- /dev/null +++ b/apps/encryption/lib/crypto/encryption.php @@ -0,0 +1,138 @@ + + * @since 3/6/15, 2:28 PM + * @link http:/www.clarkt.com + * @copyright Clark Tomlinson © 2015 + * + */ + +namespace OCA\Encryption\Crypto; + + +use OCP\Encryption\IEncryptionModule; + +class Encryption implements IEncryptionModule { + + /** + * @var Crypt + */ + private $crypt; + + public function __construct(Crypt $crypt) { + $this->crypt = $crypt; + } + + /** + * @return string defining the technical unique id + */ + public function getId() { + // we need to hard code this value + return md5($this->getDisplayName()); + } + + /** + * In comparison to getKey() this function returns a human readable (maybe translated) name + * + * @return string + */ + public function getDisplayName() { + return 'ownCloud Default Encryption'; + } + + /** + * start receiving chunks from a file. This is the place where you can + * perform some initial step before starting encrypting/decrypting the + * chunks + * + * @param string $path to the file + * @param array $header contains the header data read from the file + * @param array $accessList who has access to the file contains the key 'users' and 'public' + * + * $return array $header contain data as key-value pairs which should be + * written to the header, in case of a write operation + * or if no additional data is needed return a empty array + */ + public function begin($path, $header, $accessList) { + + $cipher = $header['']; + } + + /** + * last chunk received. This is the place where you can perform some final + * operation and return some remaining data if something is left in your + * buffer. + * + * @param string $path to the file + * @return string remained data which should be written to the file in case + * of a write operation + */ + public function end($path) { + // TODO: Implement end() method. + } + + /** + * encrypt data + * + * @param string $data you want to encrypt + * @return mixed encrypted data + */ + public function encrypt($data) { + // Todo: xxx Update Signature and usages + // passphrase is file key decrypted with user private/share key + $this->symmetricEncryptFileContent($data); + } + + /** + * decrypt data + * + * @param string $data you want to decrypt + * @param string $user decrypt as user (null for public access) + * @return mixed decrypted data + */ + public function decrypt($data, $user) { + // Todo: xxx Update Usages? + $this->symmetricDecryptFileContent($data, $user); + } + + /** + * update encrypted file, e.g. give additional users access to the file + * + * @param string $path path to the file which should be updated + * @param array $accessList who has access to the file contains the key 'users' and 'public' + * @return boolean + */ + public function update($path, $accessList) { + // TODO: Implement update() method. + } + + /** + * should the file be encrypted or not + * + * @param string $path + * @return boolean + */ + public function shouldEncrypt($path) { + // TODO: Implement shouldEncrypt() method. + } + + /** + * calculate unencrypted size + * + * @param string $path to file + * @return integer unencrypted size + */ + public function calculateUnencryptedSize($path) { + // TODO: Implement calculateUnencryptedSize() method. + } + + /** + * get size of the unencrypted payload per block. + * ownCloud read/write files with a block size of 8192 byte + * + * @return integer + */ + public function getUnencryptedBlockSize() { + // TODO: Implement getUnencryptedBlockSize() method. + } +}