aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2024-01-17 17:47:01 +0100
committerRobin Appelman <robin@icewind.nl>2024-01-17 17:47:01 +0100
commit7bf82fc312acb775bf150ce506d16a05989cd43e (patch)
tree54548cd8f76e267c720604bb38854effd0082a39 /lib
parent5de3028f667afb807d1c682238340208e56d6b91 (diff)
downloadnextcloud-server-7bf82fc312acb775bf150ce506d16a05989cd43e.tar.gz
nextcloud-server-7bf82fc312acb775bf150ce506d16a05989cd43e.zip
add key location to info:file output
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Encryption/Keys/Storage.php30
-rw-r--r--lib/private/Encryption/Util.php21
2 files changed, 26 insertions, 25 deletions
diff --git a/lib/private/Encryption/Keys/Storage.php b/lib/private/Encryption/Keys/Storage.php
index e88c305eeec..cc7ed2f1f7b 100644
--- a/lib/private/Encryption/Keys/Storage.php
+++ b/lib/private/Encryption/Keys/Storage.php
@@ -98,14 +98,14 @@ class Storage implements IStorage {
*/
public function getFileKey($path, $keyId, $encryptionModuleId) {
$realFile = $this->util->stripPartialFileExtension($path);
- $keyDir = $this->getFileKeyDir($encryptionModuleId, $realFile);
+ $keyDir = $this->util->getFileKeyDir($encryptionModuleId, $realFile);
$key = $this->getKey($keyDir . $keyId)['key'];
if ($key === '' && $realFile !== $path) {
// Check if the part file has keys and use them, if no normal keys
// exist. This is required to fix copyBetweenStorage() when we
// rename a .part file over storage borders.
- $keyDir = $this->getFileKeyDir($encryptionModuleId, $path);
+ $keyDir = $this->util->getFileKeyDir($encryptionModuleId, $path);
$key = $this->getKey($keyDir . $keyId)['key'];
}
@@ -135,7 +135,7 @@ class Storage implements IStorage {
* @inheritdoc
*/
public function setFileKey($path, $keyId, $key, $encryptionModuleId) {
- $keyDir = $this->getFileKeyDir($encryptionModuleId, $path);
+ $keyDir = $this->util->getFileKeyDir($encryptionModuleId, $path);
return $this->setKey($keyDir . $keyId, [
'key' => base64_encode($key),
]);
@@ -177,7 +177,7 @@ class Storage implements IStorage {
* @inheritdoc
*/
public function deleteFileKey($path, $keyId, $encryptionModuleId) {
- $keyDir = $this->getFileKeyDir($encryptionModuleId, $path);
+ $keyDir = $this->util->getFileKeyDir($encryptionModuleId, $path);
return !$this->view->file_exists($keyDir . $keyId) || $this->view->unlink($keyDir . $keyId);
}
@@ -185,7 +185,7 @@ class Storage implements IStorage {
* @inheritdoc
*/
public function deleteAllFileKeys($path) {
- $keyDir = $this->getFileKeyDir('', $path);
+ $keyDir = $this->util->getFileKeyDir('', $path);
return !$this->view->file_exists($keyDir) || $this->view->deleteAll($keyDir);
}
@@ -356,26 +356,6 @@ class Storage implements IStorage {
}
/**
- * get path to key folder for a given file
- *
- * @param string $encryptionModuleId
- * @param string $path path to the file, relative to data/
- * @return string
- */
- private function getFileKeyDir($encryptionModuleId, $path) {
- [$owner, $filename] = $this->util->getUidAndFilename($path);
-
- // in case of system wide mount points the keys are stored directly in the data directory
- if ($this->util->isSystemWideMountPoint($filename, $owner)) {
- $keyPath = $this->root_dir . '/' . $this->keys_base_dir . $filename . '/';
- } else {
- $keyPath = $this->root_dir . '/' . $owner . $this->keys_base_dir . $filename . '/';
- }
-
- return Filesystem::normalizePath($keyPath . $encryptionModuleId . '/', false);
- }
-
- /**
* move keys if a file was renamed
*
* @param string $source
diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php
index a828483265b..bd27d71c40e 100644
--- a/lib/private/Encryption/Util.php
+++ b/lib/private/Encryption/Util.php
@@ -385,4 +385,25 @@ class Util {
return $result;
}
+
+ /**
+ * get path to key folder for a given file
+ *
+ * @param string $encryptionModuleId
+ * @param string $path path to the file, relative to data/
+ * @return string
+ */
+ public function getFileKeyDir(string $encryptionModuleId, string $path): string {
+ [$owner, $filename] = $this->getUidAndFilename($path);
+ $root = $this->getKeyStorageRoot();
+
+ // in case of system-wide mount points the keys are stored directly in the data directory
+ if ($this->isSystemWideMountPoint($filename, $owner)) {
+ $keyPath = $root . '/' . '/files_encryption/keys' . $filename . '/';
+ } else {
+ $keyPath = $root . '/' . $owner . '/files_encryption/keys' . $filename . '/';
+ }
+
+ return Filesystem::normalizePath($keyPath . $encryptionModuleId . '/', false);
+ }
}