summaryrefslogtreecommitdiffstats
path: root/apps/encryption/lib
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-02-08 20:35:33 +0100
committerLukas Reschke <lukas@owncloud.com>2016-02-09 23:43:27 +0100
commit5ccb9dfa7e35d78d61d7a973ee2a5fddfda7d766 (patch)
treec0d45ac7af479ba32dc2fdbd492999489fa62a94 /apps/encryption/lib
parent3badf5caf579f8ff10c9917f62cb41cd9b0c68f8 (diff)
downloadnextcloud-server-5ccb9dfa7e35d78d61d7a973ee2a5fddfda7d766.tar.gz
nextcloud-server-5ccb9dfa7e35d78d61d7a973ee2a5fddfda7d766.zip
Use database for keeping track of the version
Diffstat (limited to 'apps/encryption/lib')
-rw-r--r--apps/encryption/lib/crypto/encryption.php11
-rw-r--r--apps/encryption/lib/keymanager.php25
2 files changed, 31 insertions, 5 deletions
diff --git a/apps/encryption/lib/crypto/encryption.php b/apps/encryption/lib/crypto/encryption.php
index d4e8087c4b0..b640f9a7a03 100644
--- a/apps/encryption/lib/crypto/encryption.php
+++ b/apps/encryption/lib/crypto/encryption.php
@@ -56,6 +56,9 @@ class Encryption implements IEncryptionModule {
private $path;
/** @var string */
+ private $realPath;
+
+ /** @var string */
private $user;
/** @var string */
@@ -167,6 +170,7 @@ class Encryption implements IEncryptionModule {
*/
public function begin($path, $user, $mode, array $header, array $accessList) {
$this->path = $this->getPathToRealFile($path);
+ $this->realPath = $this->path;
$this->accessList = $accessList;
$this->user = $user;
$this->isWriteOperation = false;
@@ -182,7 +186,7 @@ class Encryption implements IEncryptionModule {
$this->fileKey = $this->keyManager->getFileKey($this->path, $this->user);
}
- $this->version = (int)$this->keyManager->getVersion($this->path);
+ $this->version = (int)$this->keyManager->getVersion($this->realPath);
if (
$mode === 'w'
@@ -360,7 +364,10 @@ class Encryption implements IEncryptionModule {
*/
public function update($path, $uid, array $accessList) {
$fileKey = $this->keyManager->getFileKey($path, $uid);
- $version = $this->keyManager->getVersion($path);
+ if(empty($this->realPath)) {
+ $this->realPath = $path;
+ }
+ $version = $this->keyManager->getVersion($this->realPath);
if (!empty($fileKey)) {
diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php
index 4cbb377a43c..7d8bd8485e6 100644
--- a/apps/encryption/lib/keymanager.php
+++ b/apps/encryption/lib/keymanager.php
@@ -25,12 +25,14 @@
namespace OCA\Encryption;
use OC\Encryption\Exceptions\DecryptionFailedException;
+use OC\Files\View;
use OCA\Encryption\Crypto\Encryption;
use OCA\Encryption\Exceptions\PrivateKeyMissingException;
use OCA\Encryption\Exceptions\PublicKeyMissingException;
use OCA\Encryption\Crypto\Crypt;
use OCP\Encryption\Keys\IStorage;
use OCP\IConfig;
+use OCP\IDBConnection;
use OCP\ILogger;
use OCP\IUserSession;
@@ -416,18 +418,35 @@ class KeyManager {
* Get the current version of a file
*
* @param string $path
- * @return mixed
+ * @return int
*/
public function getVersion($path) {
- return $this->keyStorage->getFileKey($path, 'version', Encryption::ID);
+ $view = new \OC\Files\View();
+ $fileInfo = $view->getFileInfo($path);
+ if($fileInfo === false) {
+ return 0;
+ }
+ return $fileInfo->getEncryptedVersion();
}
/**
+ * Set the current version of a file
+ *
* @param string $path
* @param string $version
*/
public function setVersion($path, $version) {
- $this->keyStorage->setFileKey($path, 'version', $version, Encryption::ID);
+ $view = new \OC\Files\View();
+ $fileInfo= $view->getFileInfo($path);
+
+ if($fileInfo !== false) {
+ $fileId = $fileInfo->getId();
+ $qb = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $qb->update('filecache')
+ ->set('encrypted', $qb->createNamedParameter($version))
+ ->where($qb->expr()->eq('fileid', $qb->createNamedParameter($fileId)))
+ ->execute();
+ }
}
/**