Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ protected function setupUser($name, $password): View {
$this->loginWithEncryption($name);
return new View('/' . $name . '/files');
}

protected function tearDown(): void {
$this->tearDownEncryptionTrait();
parent::tearDown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ protected function setupUser($name, $password): View {
$this->loginWithEncryption($name);
return new View('/' . $name . '/files');
}

protected function tearDown(): void {
$this->tearDownEncryptionTrait();
parent::tearDown();
}
}
5 changes: 5 additions & 0 deletions apps/encryption/tests/Command/FixEncryptedVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,9 @@ public function testExecuteWithNoMasterKey(): void {

$this->assertStringContainsString('only works with master key', $output);
}

protected function tearDown(): void {
$this->tearDownEncryptionTrait();
parent::tearDown();
}
}
5 changes: 5 additions & 0 deletions apps/encryption/tests/EncryptedStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ public function testMoveFromEncrypted(): void {
$this->assertEquals('bar', $unencryptedStorage->file_get_contents('foo.txt'));
$this->assertFalse($unencryptedCache->get('foo.txt')->isEncrypted());
}

protected function tearDown(): void {
$this->tearDownEncryptionTrait();
parent::tearDown();
}
}
5 changes: 5 additions & 0 deletions apps/files_sharing/tests/EncryptedSizePropagationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ protected function loginHelper($user, $create = false, $password = false) {
$this->setupForUser($user, $password);
parent::loginHelper($user, $create, $password);
}

protected function tearDown(): void {
$this->tearDownEncryptionTrait();
parent::tearDown();
}
}
67 changes: 42 additions & 25 deletions lib/private/Encryption/EncryptionWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace OC\Encryption;

use OC\Files\Filesystem;
use OC\Files\Mount\HomeMountPoint;
use OC\Files\Storage\Wrapper\Encryption;
use OC\Files\View;
use OC\Memcache\ArrayCache;
Expand Down Expand Up @@ -62,32 +63,48 @@ public function wrapStorage(string $mountPoint, IStorage $storage, IMountPoint $
'mount' => $mount
];

if ($force || (!$storage->instanceOfStorage(IDisableEncryptionStorage::class) && $mountPoint !== '/')) {
$user = \OC::$server->getUserSession()->getUser();
$mountManager = Filesystem::getMountManager();
$uid = $user ? $user->getUID() : null;
$fileHelper = \OC::$server->get(IFile::class);
$keyStorage = \OC::$server->get(EncryptionKeysStorage::class);
// Only evaluate other conditions if not forced
if (!$force) {
// If a disabled storage medium, return basic storage
if ($storage->instanceOfStorage(IDisableEncryptionStorage::class)) {
return $storage;
}

$util = new Util(
new View(),
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
\OC::$server->getConfig()
);
return new Encryption(
$parameters,
$this->manager,
$util,
$this->logger,
$fileHelper,
$uid,
$keyStorage,
$mountManager,
$this->arrayCache
);
} else {
return $storage;
// Root mount point handling: skip encryption wrapper
if ($mountPoint === '/') {
return $storage;
}

// Skip encryption for home mounts if encryptHomeStorage is disabled
if ($mount instanceof HomeMountPoint
&& \OC::$server->getConfig()->getAppValue('encryption', 'encryptHomeStorage', '1') !== '1') {
return $storage;
}
}

// Apply encryption wrapper
$user = \OC::$server->getUserSession()->getUser();
$mountManager = Filesystem::getMountManager();
$uid = $user ? $user->getUID() : null;
$fileHelper = \OC::$server->get(IFile::class);
$keyStorage = \OC::$server->get(EncryptionKeysStorage::class);

$util = new Util(
new View(),
\OC::$server->getUserManager(),
\OC::$server->getGroupManager(),
\OC::$server->getConfig()
);
return new Encryption(
$parameters,
$this->manager,
$util,
$this->logger,
$fileHelper,
$uid,
$keyStorage,
$mountManager,
$this->arrayCache
);
}
}
2 changes: 1 addition & 1 deletion lib/private/Files/Cache/CacheEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function __clone() {
}

public function getUnencryptedSize(): int {
if ($this->data['encrypted'] && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
if ($this->data['encrypted'] && isset($this->data['unencrypted_size'])) {
return $this->data['unencrypted_size'];
} else {
return $this->data['size'] ?? 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function getSize($includeMounts = true) {
if ($includeMounts) {
$this->updateEntryFromSubMounts();

if ($this->isEncrypted() && isset($this->data['unencrypted_size']) && $this->data['unencrypted_size'] > 0) {
if ($this->isEncrypted() && isset($this->data['unencrypted_size'])) {
return $this->data['unencrypted_size'];
} else {
return isset($this->data['size']) ? 0 + $this->data['size'] : 0;
Expand Down
1 change: 1 addition & 0 deletions lib/private/Files/Storage/Wrapper/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ protected function verifyUnencryptedSize(string $path, int $unencryptedSize): in
if ($unencryptedSize < 0
|| ($size > 0 && $unencryptedSize === $size)
|| $unencryptedSize > $size
|| ($unencryptedSize === 0 && $size > 0)
) {
// check if we already calculate the unencrypted size for the
// given path to avoid recursions
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Files/Stream/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Encryption extends Wrapper {
protected string $cache;
protected ?int $size = null;
protected int $position;
protected ?int $unencryptedSize = null;
protected int|float|null $unencryptedSize = null;
protected int $headerSize;
protected int $unencryptedBlockSize;
protected array $header;
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/Encryption/EncryptionWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function testWrapStorage($expectedWrapped, $wrappedStorages): void {
->disableOriginalConstructor()
->getMock();

// Mock encryption being enabled for tests that expect wrapping
$this->manager->expects($this->any())
->method('isEnabled')
->willReturn($expectedWrapped);

$returnedStorage = $this->instance->wrapStorage('mountPoint', $storage, $mount);

$this->assertEquals(
Expand Down
Loading
Loading