diff options
author | Robin Appelman <robin@icewind.nl> | 2025-05-09 16:34:58 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2025-05-12 11:27:29 +0000 |
commit | 0fe56ce669037938b8124a9ffd5c8decbca6ec4e (patch) | |
tree | 672d941ed4a00f6907a39b139d3acc0f8163409e | |
parent | bb720fc6faa5c59674196c2366a5098b007d00dd (diff) | |
download | nextcloud-server-backport/52706/stable30.tar.gz nextcloud-server-backport/52706/stable30.zip |
feat: add more encryption checks to info:filebackport/52706/stable30
Signed-off-by: Robin Appelman <robin@icewind.nl>
-rw-r--r-- | core/Command/Info/File.php | 10 | ||||
-rw-r--r-- | lib/private/Files/Storage/Wrapper/Encryption.php | 12 |
2 files changed, 22 insertions, 0 deletions
diff --git a/core/Command/Info/File.php b/core/Command/Info/File.php index 2b1daef2470..018bd35fdb6 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 f950a4c2d78..f3ae43b0add 100644 --- a/lib/private/Files/Storage/Wrapper/Encryption.php +++ b/lib/private/Files/Storage/Wrapper/Encryption.php @@ -1060,4 +1060,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); + } } |