From 43c0af2580a615f328c0a3a6d0d6256b4e625f3f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20M=C3=BCller?= Date: Wed, 1 Apr 2015 15:41:31 +0200 Subject: [PATCH] Fix shouldEncrypt and don't throw exception id fileKey not present - can happen --- apps/encryption/lib/crypto/encryption.php | 41 ++++++++++--------- .../exceptions/filekeymissingexception.php | 8 ---- apps/encryption/lib/keymanager.php | 30 ++------------ 3 files changed, 25 insertions(+), 54 deletions(-) delete mode 100644 apps/encryption/lib/exceptions/filekeymissingexception.php diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php index d8b7f91e268..c3fd3405366 100644 --- a/apps/encryption/lib/crypto/encryption.php +++ b/apps/encryption/lib/crypto/encryption.php @@ -10,6 +10,7 @@ namespace OCA\Encryption\Crypto; +use OCA\Encryption\Util; use OCP\Encryption\IEncryptionModule; use OCA\Encryption\KeyManager; @@ -38,7 +39,7 @@ class Encryption implements IEncryptionModule { private $writeCache; /** @var KeyManager */ - private $keymanager; + private $keyManager; /** @var array */ private $accessList; @@ -46,18 +47,18 @@ class Encryption implements IEncryptionModule { /** @var boolean */ private $isWriteOperation; - /** @var \OCA\Encryption\Util */ + /** @var Util */ private $util; /** * * @param \OCA\Encryption\Crypto\Crypt $crypt - * @param KeyManager $keymanager - * @param \OCA\Encryption\Util $util + * @param KeyManager $keyManager + * @param Util $util */ - public function __construct(Crypt $crypt, KeyManager $keymanager, \OCA\Encryption\Util $util) { + public function __construct(Crypt $crypt, KeyManager $keyManager, Util $util) { $this->crypt = $crypt; - $this->keymanager = $keymanager; + $this->keyManager = $keyManager; $this->util = $util; } @@ -105,7 +106,7 @@ class Encryption implements IEncryptionModule { $this->writeCache = ''; $this->isWriteOperation = false; - $this->fileKey = $this->keymanager->getFileKey($path, $this->user); + $this->fileKey = $this->keyManager->getFileKey($path, $this->user); return array('cipher' => $this->cipher); } @@ -128,13 +129,13 @@ class Encryption implements IEncryptionModule { } $publicKeys = array(); foreach ($this->accessList['users'] as $uid) { - $publicKeys[$uid] = $this->keymanager->getPublicKey($uid); + $publicKeys[$uid] = $this->keyManager->getPublicKey($uid); } - $publicKeys = $this->keymanager->addSystemKeys($this->accessList, $publicKeys); + $publicKeys = $this->keyManager->addSystemKeys($this->accessList, $publicKeys); $encryptedKeyfiles = $this->crypt->multiKeyEncrypt($this->fileKey, $publicKeys); - $this->keymanager->setAllFileKeys($path, $encryptedKeyfiles); + $this->keyManager->setAllFileKeys($path, $encryptedKeyfiles); } return $result; } @@ -231,19 +232,19 @@ class Encryption implements IEncryptionModule { * @return boolean */ public function update($path, $uid, $accessList) { - $fileKey = $this->keymanager->getFileKey($path, $uid); + $fileKey = $this->keyManager->getFileKey($path, $uid); $publicKeys = array(); foreach ($accessList['users'] as $user) { - $publicKeys[$user] = $this->keymanager->getPublicKey($user); + $publicKeys[$user] = $this->keyManager->getPublicKey($user); } - $publicKeys = $this->keymanager->addSystemKeys($accessList, $publicKeys); + $publicKeys = $this->keyManager->addSystemKeys($accessList, $publicKeys); $encryptedFileKey = $this->crypt->multiKeyEncrypt($fileKey, $publicKeys); - $this->keymanager->deleteAllFileKeys($path); + $this->keyManager->deleteAllFileKeys($path); - $this->keymanager->setAllFileKeys($path, $encryptedFileKey); + $this->keyManager->setAllFileKeys($path, $encryptedFileKey); return true; } @@ -257,13 +258,13 @@ class Encryption implements IEncryptionModule { */ public function addSystemKeys(array $accessList, array $publicKeys) { if (!empty($accessList['public'])) { - $publicKeys[$this->keymanager->getPublicShareKeyId()] = $this->keymanager->getPublicShareKey(); + $publicKeys[$this->keyManager->getPublicShareKeyId()] = $this->keyManager->getPublicShareKey(); } - if ($this->keymanager->recoveryKeyExists() && + if ($this->keyManager->recoveryKeyExists() && $this->util->recoveryEnabled($this->user)) { - $publicKeys[$this->keymanager->getRecoveryKeyId()] = $this->keymanager->getRecoveryKey(); + $publicKeys[$this->keyManager->getRecoveryKeyId()] = $this->keyManager->getRecoveryKey(); } @@ -283,10 +284,10 @@ class Encryption implements IEncryptionModule { return false; } - if ($parts[2] == '/files/') { + if ($parts[2] == 'files') { return true; } - if ($parts[2] == '/files_versions/') { + if ($parts[2] == 'files_versions') { return true; } diff --git a/apps/encryption/lib/exceptions/filekeymissingexception.php b/apps/encryption/lib/exceptions/filekeymissingexception.php deleted file mode 100644 index 9eb2d4c80d4..00000000000 --- a/apps/encryption/lib/exceptions/filekeymissingexception.php +++ /dev/null @@ -1,8 +0,0 @@ - - * @since 2/19/15, 1:20 PM - * @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 - * - */ namespace OCA\Encryption; - use OC\Encryption\Exceptions\DecryptionFailedException; -use OCA\Encryption\Exceptions\FileKeyMissingException; use OCA\Encryption\Exceptions\PrivateKeyMissingException; use OC\Encryption\Exceptions\PublicKeyMissingException; use OCA\Encryption\Crypto\Crypt; use OCP\Encryption\Keys\IStorage; -use OCA\Encryption\Util; use OCP\IConfig; use OCP\ILogger; use OCP\IUserSession; -use \OCA\Encryption\Session; class KeyManager { @@ -211,11 +188,11 @@ class KeyManager { return false; } - /** - * @param string $uid + /** * @param string $password * @param array $keyPair * @return bool + * @internal param string $uid */ public function setRecoveryKey($password, $keyPair) { // Save Public Key @@ -351,7 +328,7 @@ class KeyManager { $privateKey); } - throw new FileKeyMissingException(); + return ''; } /** @@ -513,6 +490,7 @@ class KeyManager { * @param array $accessList * @param array $publicKeys * @return array + * @throws PublicKeyMissingException */ public function addSystemKeys(array $accessList, array $publicKeys) { if (!empty($accessList['public'])) { -- 2.39.5