remember signature version and only set it on update to make sure that other
apps like files_versions still get the old signature version
This commit is contained in:
parent
43ed86313c
commit
9dc759b4dc
|
@ -57,9 +57,6 @@ class Encryption implements IEncryptionModule {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $path;
|
private $path;
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
private $realPath;
|
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
|
@ -108,6 +105,9 @@ class Encryption implements IEncryptionModule {
|
||||||
/** @var int Current version of the file */
|
/** @var int Current version of the file */
|
||||||
private $version = 0;
|
private $version = 0;
|
||||||
|
|
||||||
|
/** @var array remember encryption signature version */
|
||||||
|
private static $rememberVersion = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -172,7 +172,6 @@ class Encryption implements IEncryptionModule {
|
||||||
*/
|
*/
|
||||||
public function begin($path, $user, $mode, array $header, array $accessList) {
|
public function begin($path, $user, $mode, array $header, array $accessList) {
|
||||||
$this->path = $this->getPathToRealFile($path);
|
$this->path = $this->getPathToRealFile($path);
|
||||||
$this->realPath = $path;
|
|
||||||
$this->accessList = $accessList;
|
$this->accessList = $accessList;
|
||||||
$this->user = $user;
|
$this->user = $user;
|
||||||
$this->isWriteOperation = false;
|
$this->isWriteOperation = false;
|
||||||
|
@ -191,7 +190,7 @@ class Encryption implements IEncryptionModule {
|
||||||
// always use the version from the original file, also part files
|
// always use the version from the original file, also part files
|
||||||
// need to have a correct version number if they get moved over to the
|
// need to have a correct version number if they get moved over to the
|
||||||
// final location
|
// final location
|
||||||
$this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($this->realPath), new View());
|
$this->version = (int)$this->keyManager->getVersion($this->stripPartFileExtension($path), new View());
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$mode === 'w'
|
$mode === 'w'
|
||||||
|
@ -241,7 +240,14 @@ class Encryption implements IEncryptionModule {
|
||||||
public function end($path, $position = 0) {
|
public function end($path, $position = 0) {
|
||||||
$result = '';
|
$result = '';
|
||||||
if ($this->isWriteOperation) {
|
if ($this->isWriteOperation) {
|
||||||
$this->keyManager->setVersion($this->path, $this->version+1, new View());
|
$this->keyManager->setVersion($path, $this->version + 1, new View());
|
||||||
|
// in case of a part file we remember the new signature versions
|
||||||
|
// the version will be set later on update.
|
||||||
|
// This way we make sure that other apps listening to the pre-hooks
|
||||||
|
// still get the old version which should be the correct value for them
|
||||||
|
if (Scanner::isPartialFile($path)) {
|
||||||
|
self::$rememberVersion[$this->stripPartFileExtension($path)] = $this->version + 1;
|
||||||
|
}
|
||||||
if (!empty($this->writeCache)) {
|
if (!empty($this->writeCache)) {
|
||||||
$result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $this->version + 1, $position);
|
$result = $this->crypt->symmetricEncryptFileContent($this->writeCache, $this->fileKey, $this->version + 1, $position);
|
||||||
$this->writeCache = '';
|
$this->writeCache = '';
|
||||||
|
@ -367,11 +373,16 @@ class Encryption implements IEncryptionModule {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function update($path, $uid, array $accessList) {
|
public function update($path, $uid, array $accessList) {
|
||||||
$fileKey = $this->keyManager->getFileKey($path, $uid);
|
|
||||||
if(empty($this->realPath)) {
|
if (empty($accessList)) {
|
||||||
$this->realPath = $path;
|
if (isset(self::$rememberVersion[$path])) {
|
||||||
|
$this->keyManager->setVersion($path, self::$rememberVersion[$path], new View());
|
||||||
|
unset(self::$rememberVersion[$path]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
$version = $this->keyManager->getVersion($this->realPath, new View());
|
|
||||||
|
$fileKey = $this->keyManager->getFileKey($path, $uid);
|
||||||
|
|
||||||
if (!empty($fileKey)) {
|
if (!empty($fileKey)) {
|
||||||
|
|
||||||
|
@ -392,8 +403,6 @@ class Encryption implements IEncryptionModule {
|
||||||
|
|
||||||
$this->keyManager->setAllFileKeys($path, $encryptedFileKey);
|
$this->keyManager->setAllFileKeys($path, $encryptedFileKey);
|
||||||
|
|
||||||
$this->keyManager->setVersion($path, $version, new View());
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->logger->debug('no file key found, we assume that the file "{file}" is not encrypted',
|
$this->logger->debug('no file key found, we assume that the file "{file}" is not encrypted',
|
||||||
array('file' => $path, 'app' => 'encryption'));
|
array('file' => $path, 'app' => 'encryption'));
|
||||||
|
|
|
@ -298,6 +298,9 @@ class EncryptionTest extends TestCase {
|
||||||
return $publicKeys;
|
return $publicKeys;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->keyManagerMock->expects($this->never())->method('getVersion');
|
||||||
|
$this->keyManagerMock->expects($this->never())->method('setVersion');
|
||||||
|
|
||||||
$this->assertSame($expected,
|
$this->assertSame($expected,
|
||||||
$this->instance->update('path', 'user1', ['users' => ['user1']])
|
$this->instance->update('path', 'user1', ['users' => ['user1']])
|
||||||
);
|
);
|
||||||
|
@ -311,6 +314,22 @@ class EncryptionTest extends TestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdateNoUsers() {
|
||||||
|
|
||||||
|
$this->invokePrivate($this->instance, 'rememberVersion', [['path' => 2]]);
|
||||||
|
|
||||||
|
$this->keyManagerMock->expects($this->never())->method('getFileKey');
|
||||||
|
$this->keyManagerMock->expects($this->never())->method('getPublicKey');
|
||||||
|
$this->keyManagerMock->expects($this->never())->method('addSystemKeys');
|
||||||
|
$this->keyManagerMock->expects($this->once())->method('setVersion')
|
||||||
|
->willReturnCallback(function($path, $version, $view) {
|
||||||
|
$this->assertSame('path', $path);
|
||||||
|
$this->assertSame(2, $version);
|
||||||
|
$this->assertTrue($view instanceof \OC\Files\View);
|
||||||
|
});
|
||||||
|
$this->instance->update('path', 'user1', []);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* by default the encryption module should encrypt regular files, files in
|
* by default the encryption module should encrypt regular files, files in
|
||||||
* files_versions and files in files_trashbin
|
* files_versions and files in files_trashbin
|
||||||
|
|
|
@ -260,6 +260,10 @@ class Encryption extends Wrapper {
|
||||||
$this->unencryptedSize[$target] = $this->unencryptedSize[$source];
|
$this->unencryptedSize[$target] = $this->unencryptedSize[$source];
|
||||||
}
|
}
|
||||||
$this->keyStorage->renameKeys($source, $target);
|
$this->keyStorage->renameKeys($source, $target);
|
||||||
|
$module = $this->getEncryptionModule($path2);
|
||||||
|
if ($module) {
|
||||||
|
$module->update($target, $this->uid, []);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue