Skip to content

Commit

Permalink
Check for e2e encryption when changing exif data
Browse files Browse the repository at this point in the history
  • Loading branch information
eltos committed Nov 19, 2022
1 parent 1167365 commit 5078d98
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/Controller/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\Encryption\IManager;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
Expand All @@ -48,6 +49,7 @@ class ApiBase extends Controller
protected IUserSession $userSession;
protected IRootFolder $rootFolder;
protected IAppManager $appManager;
protected IManager $encryptionManager;
protected TimelineQuery $timelineQuery;
protected TimelineWrite $timelineWrite;
protected IShareManager $shareManager;
Expand All @@ -60,6 +62,7 @@ public function __construct(
IDBConnection $connection,
IRootFolder $rootFolder,
IAppManager $appManager,
IManager $encryptionManager,
IShareManager $shareManager,
IPreview $preview
) {
Expand All @@ -70,6 +73,7 @@ public function __construct(
$this->connection = $connection;
$this->rootFolder = $rootFolder;
$this->appManager = $appManager;
$this->encryptionManager = $encryptionManager;
$this->shareManager = $shareManager;
$this->previewManager = $preview;
$this->timelineQuery = new TimelineQuery($connection);
Expand Down
5 changes: 5 additions & 0 deletions lib/Controller/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function setExif(string $id): JSONResponse
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}

// Check for end-to-end encryption
if (\OCA\Memories\Util::isEncryptionEnabled($this->encryptionManager)){
return new JSONResponse(['message' => 'Cannot change encrypted file'], Http::STATUS_PRECONDITION_FAILED);
}

// Get original file from body
$exif = $this->request->getParam('raw');
$path = $file->getStorage()->getLocalFile($file->getInternalPath());
Expand Down
13 changes: 13 additions & 0 deletions lib/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,17 @@ public static function isLinkSharingEnabled(&$config): bool

return true;
}

/**
* Check if any encryption is enabled that we can not cope with
* such as end-to-end encryption
*/
public static function isEncryptionEnabled(&$encryptionManager): bool
{
if ($encryptionManager->isEnabled()){
// Server-side encryption (OC_DEFAULT_MODULE) is okay, others like e2e are not
return $encryptionManager->getDefaultEncryptionModuleId() != 'OC_DEFAULT_MODULE';
}
return false;
}
}

0 comments on commit 5078d98

Please sign in to comment.