fix file sharing, sharing files works now; moved the identification of file owner and the owner path in the keymanager functions so that other functions doesn't have to deal with it

This commit is contained in:
Björn Schießle 2013-04-18 16:34:23 +02:00
parent 7892fddcb9
commit 40905c8941
2 changed files with 13 additions and 17 deletions

View File

@ -107,11 +107,13 @@ class Keymanager {
public static function setFileKey( \OC_FilesystemView $view, $path, $userId, $catfile ) {
\OC_FileProxy::$enabled = false;
$util = new Util($view, $userId);
list($owner, $filename) = $util->getUidAndFilename($path);
$basePath = '/' . $owner . '/files_encryption/keyfiles';
\OC\Files\Filesystem::initMountPoints($userId);
$basePath = '/' . $userId . '/files_encryption/keyfiles';
$targetPath = self::keySetPreparation( $view, $path, $basePath, $userId );
$targetPath = self::keySetPreparation( $view, $filename, $basePath, $owner );
if ( !$view->is_dir( $basePath . '/' . $targetPath ) ) {
@ -166,10 +168,11 @@ class Keymanager {
*/
public static function getFileKey( \OC_FilesystemView $view, $userId, $filePath ) {
\OC\Files\Filesystem::initMountPoints($userId);
$filePath_f = ltrim( $filePath, '/' );
$util = new Util($view, $userId);
list($owner, $filename) = $util->getUidAndFilename($filePath);
$filePath_f = ltrim( $filename, '/' );
$keyfilePath = '/' . $userId . '/files_encryption/keyfiles/' . $filePath_f . '.key';
$keyfilePath = '/' . $owner . '/files_encryption/keyfiles/' . $filePath_f . '.key';
\OC_FileProxy::$enabled = false;

View File

@ -102,7 +102,6 @@ class Proxy extends \OC_FileProxy {
$rootView = new \OC_FilesystemView( '/' );
$util = new Util( $rootView, $userId );
$session = new Session( $rootView );
$fileOwner = \OC\Files\Filesystem::getOwner( $path );
$privateKey = $session->getPrivateKey();
$filePath = $util->stripUserFilesPath( $path );
// Set the filesize for userland, before encrypting
@ -112,7 +111,7 @@ class Proxy extends \OC_FileProxy {
\OC_FileProxy::$enabled = false;
// Check if there is an existing key we can reuse
if ( $encKeyfile = Keymanager::getFileKey( $rootView, $fileOwner, $filePath ) ) {
if ( $encKeyfile = Keymanager::getFileKey( $rootView, $userId, $filePath ) ) {
// Fetch shareKey
$shareKey = Keymanager::getShareKey( $rootView, $userId, $filePath );
@ -153,7 +152,7 @@ class Proxy extends \OC_FileProxy {
$encKey = $multiEncrypted['data'];
// Save keyfile for newly encrypted file in parallel directory tree
Keymanager::setFileKey( $rootView, $filePath, $fileOwner, $encKey );
Keymanager::setFileKey( $rootView, $filePath, $userId, $encKey );
// Replace plain content with encrypted content by reference
$data = $encData;
@ -198,14 +197,8 @@ class Proxy extends \OC_FileProxy {
$session = new Session( $view );
$privateKey = $session->getPrivateKey( $userId );
// Get the file owner so we can retrieve its keyfile
// list( $fileOwner, $ownerPath ) = $util->getUidAndFilename( $relPath );
$fileOwner = \OC\Files\Filesystem::getOwner( $path );
$ownerPath = $util->stripUserFilesPath( $path ); // TODO: Don't trust $path, fetch owner path
// Get the encrypted keyfile
$encKeyfile = Keymanager::getFileKey( $view, $fileOwner, $ownerPath );
$encKeyfile = Keymanager::getFileKey( $view, $userId, $relPath );
// Attempt to fetch the user's shareKey
$shareKey = Keymanager::getShareKey( $view, $userId, $relPath );