aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2025-05-09 16:34:58 +0200
committerRobin Appelman <robin@icewind.nl>2025-05-09 16:35:31 +0200
commitd9c53ef748350de0c5a229fa2d8aef0cd038e568 (patch)
treeaaaa84e56f8c206fb0bab4e2ec606d39e10474d9
parentc7430d5cb806ac2cf84d2e6e7ae1da3f50375828 (diff)
downloadnextcloud-server-d9c53ef748350de0c5a229fa2d8aef0cd038e568.tar.gz
nextcloud-server-d9c53ef748350de0c5a229fa2d8aef0cd038e568.zip
feat: add more encryption checks to info:fileinfo-file-more-encryption-checks
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r--core/Command/Info/File.php10
-rw-r--r--lib/private/Files/Storage/Wrapper/Encryption.php12
2 files changed, 22 insertions, 0 deletions
diff --git a/core/Command/Info/File.php b/core/Command/Info/File.php
index a081d1d13e1..c21c2e666fb 100644
--- a/core/Command/Info/File.php
+++ b/core/Command/Info/File.php
@@ -8,6 +8,7 @@ declare(strict_types=1);
namespace OC\Core\Command\Info;
use OC\Files\ObjectStore\ObjectStoreStorage;
+use OC\Files\Storage\Wrapper\Encryption;
use OC\Files\View;
use OCA\Files_External\Config\ExternalMountPoint;
use OCA\GroupFolders\Mount\GroupMountPoint;
@@ -71,6 +72,15 @@ class File extends Command {
} else {
$output->writeln(' <error>encryption key not found</error> should be located at: ' . $keyPath);
}
+ $storage = $node->getStorage();
+ if ($storage->instanceOfStorage(Encryption::class)) {
+ /** @var Encryption $storage */
+ if (!$storage->hasValidHeader($node->getInternalPath())) {
+ $output->writeln(' <error>file doesn\'t have a valid encryption header</error>');
+ }
+ } else {
+ $output->writeln(' <error>file is marked as encrypted, but encryption doesn\'t seem to be setup</error>');
+ }
}
if ($node instanceof Folder && $node->isEncrypted() || $node instanceof OCPFile && $node->getParent()->isEncrypted()) {
diff --git a/lib/private/Files/Storage/Wrapper/Encryption.php b/lib/private/Files/Storage/Wrapper/Encryption.php
index ba23f3c43ec..427ec06c2bb 100644
--- a/lib/private/Files/Storage/Wrapper/Encryption.php
+++ b/lib/private/Files/Storage/Wrapper/Encryption.php
@@ -894,4 +894,16 @@ class Encryption extends Wrapper {
public function setEnabled(bool $enabled): void {
$this->enabled = $enabled;
}
+
+ /**
+ * Check if the on-disk data for a file has a valid encrypted header
+ *
+ * @param string $path
+ * @return bool
+ */
+ public function hasValidHeader(string $path): bool {
+ $firstBlock = $this->readFirstBlock($path);
+ $header = $this->util->parseRawHeader($firstBlock);
+ return (count($header) > 0);
+ }
}