mirror of
https://github.com/nextcloud/server.git
synced 2026-04-21 06:08:46 -04:00
Fix shouldEncrypt and don't throw exception id fileKey not present - can happen
This commit is contained in:
parent
a057108c0c
commit
43c0af2580
3 changed files with 25 additions and 54 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace OCA\Encryption\Exceptions;
|
||||
|
||||
class FileKeyMissingException extends \Exception {
|
||||
|
||||
}
|
||||
|
|
@ -1,38 +1,15 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Clark Tomlinson <clark@owncloud.com>
|
||||
* @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 <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
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'])) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue