-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setupfs before access a users keys #26917
Changes from 4 commits
7327fa9
730d6ae
8b669b8
1e1c11f
34461cf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,9 @@ class Storage implements IStorage { | |
/** @var array */ | ||
private $keyCache = []; | ||
|
||
/** @var string */ | ||
private $currentUser = null; | ||
|
||
/** | ||
* @param View $view | ||
* @param Util $util | ||
|
@@ -64,6 +67,11 @@ public function __construct(View $view, Util $util) { | |
$this->encryption_base_dir = '/files_encryption'; | ||
$this->keys_base_dir = $this->encryption_base_dir .'/keys'; | ||
$this->root_dir = $this->util->getKeyStorageRoot(); | ||
|
||
$session = \OC::$server->getUserSession(); | ||
if (!is_null($session) && !is_null($session->getUser())) { | ||
$this->currentUser = $session->getUser()->getUID(); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -170,6 +178,7 @@ protected function constructUserKeyPath($encryptionModuleId, $keyId, $uid) { | |
if ($uid === null) { | ||
$path = $this->root_dir . '/' . $this->encryption_base_dir . '/' . $encryptionModuleId . '/' . $keyId; | ||
} else { | ||
$this->setupUserMounts($uid); | ||
$path = $this->root_dir . '/' . $uid . $this->encryption_base_dir . '/' | ||
. $encryptionModuleId . '/' . $uid . '.' . $keyId; | ||
} | ||
|
@@ -235,6 +244,7 @@ private function getFileKeyDir($encryptionModuleId, $path) { | |
if ($this->util->isSystemWideMountPoint($filename, $owner)) { | ||
$keyPath = $this->root_dir . '/' . $this->keys_base_dir . $filename . '/'; | ||
} else { | ||
$this->setupUserMounts($owner); | ||
$keyPath = $this->root_dir . '/' . $owner . $this->keys_base_dir . $filename . '/'; | ||
} | ||
|
||
|
@@ -298,6 +308,7 @@ protected function getPathToKeys($path) { | |
if ($systemWideMountPoint) { | ||
$systemPath = $this->root_dir . '/' . $this->keys_base_dir . $relativePath . '/'; | ||
} else { | ||
$this->setupUserMounts($owner); | ||
$systemPath = $this->root_dir . '/' . $owner . $this->keys_base_dir . $relativePath . '/'; | ||
} | ||
|
||
|
@@ -323,4 +334,19 @@ protected function keySetPreparation($path) { | |
} | ||
} | ||
|
||
/** | ||
* Setup the mounts of the given user if different than | ||
* the current user. | ||
* | ||
* This is needed because in many cases the keys are stored | ||
* within the user's home storage. | ||
* | ||
* @param string $uid user id | ||
*/ | ||
protected function setupUserMounts($uid) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this function should return something to check the result of the initMountPoint (if any) or to check if the function is ignoring the request because the uid matches the current user or the mount point is already mounted, specially if there are plans to unittest this function. Since it isn't public we might skip testing this. |
||
if (!is_null($uid) && $uid !== '' && $uid !== $this->currentUser) { | ||
\OC\Files\Filesystem::initMountPoints($uid); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,17 +24,29 @@ | |
namespace Test\Encryption\Keys; | ||
|
||
use OC\Encryption\Keys\Storage; | ||
use OC\Encryption\Util; | ||
use OC\Files\View; | ||
use Test\TestCase; | ||
use Test\Traits\UserTrait; | ||
|
||
/** | ||
* Class StorageTest | ||
* | ||
* @group DB | ||
* | ||
* @package Test\Encryption\Keys | ||
*/ | ||
class StorageTest extends TestCase { | ||
|
||
use UserTrait; | ||
|
||
/** @var Storage */ | ||
protected $storage; | ||
|
||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
/** @var \PHPUnit_Framework_MockObject_MockObject | Util */ | ||
protected $util; | ||
|
||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
/** @var \PHPUnit_Framework_MockObject_MockObject | View */ | ||
protected $view; | ||
|
||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
|
@@ -55,6 +67,8 @@ public function setUp() { | |
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->createUser('user1', '123456'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will create a user each time a test runs, which seems wrong. Either you create the users in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I forgot to re-delete the user. Will do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked the code. Apparently |
||
$this->createUser('user2', '123456'); | ||
$this->storage = new Storage($this->view, $this->util); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it would be a pain to inject this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, apparently not. This class is only in one place in server.php, so I'll add it.