* @brief get all users with access to the file and encrypt the file key to each of them\r
*/\r
public static function postShared( $params ) {\r
-\r
- // NOTE: $params is an array with these keys:\r
+ \r
+ // NOTE: $params has keys:\r
+ // [itemType] => file\r
// itemSource -> int, filecache file ID\r
+ // [parent] => \r
+ // [itemTarget] => /13\r
// shareWith -> string, uid of user being shared to\r
// fileTarget -> path of file being shared\r
// uidOwner -> owner of the original file being shared\r
+ // [shareType] => 0\r
+ // [shareWith] => test1\r
+ // [uidOwner] => admin\r
+ // [permissions] => 17\r
+ // [fileSource] => 13\r
+ // [fileTarget] => /test8\r
+ // [id] => 10\r
+ // [token] => \r
\r
- $view = new \OC_FilesystemView( '/' );\r
- $session = new Session();\r
- $userId = \OCP\User::getUser();\r
- $util = new Util( $view, $userId );\r
- $path = $util->fileIdToPath( $params['itemSource'] );\r
- \r
- $usersSharing = \OCP\Share::getUsersSharingFile( $path, true );\r
- \r
- $allPaths = $util->getPaths( $path );\r
+ // TODO: Should other kinds of item be encrypted too?\r
+ if ( $params['itemType'] === 'file' ) {\r
\r
- $failed = array();\r
- \r
- foreach ( $allPaths as $path ) {\r
- \r
- if ( ! $util->setSharedFileKeyfiles( $session, $usersSharing, $path ) ) {\r
+ $view = new \OC_FilesystemView( '/' );\r
+ $session = new Session();\r
+ $userId = \OCP\User::getUser();\r
+ $util = new Util( $view, $userId );\r
+ $path = $util->fileIdToPath( $params['itemSource'] );\r
+ \r
+ $usersSharing = \OCP\Share::getUsersSharingFile( $path, true );\r
+ \r
+ $allPaths = $util->getPaths( $path );\r
+ \r
+ $failed = array();\r
\r
- $failed[] = $path;\r
+ foreach ( $allPaths as $path ) {\r
+ \r
+ if ( ! $util->setSharedFileKeyfiles( $session, $usersSharing, $path ) ) {\r
+ \r
+ $failed[] = $path;\r
+ \r
+ }\r
\r
}\r
\r
- }\r
- \r
- // If no attempts to set keyfiles failed\r
- if ( empty( $failed ) ) {\r
- \r
- return true;\r
+ // If no attempts to set keyfiles failed\r
+ if ( empty( $failed ) ) {\r
\r
- } else {\r
- \r
- return false;\r
+ return true;\r
+ \r
+ } else {\r
\r
+ return false;\r
+ \r
+ }\r
+ \r
}\r
\r
}\r
* @brief \r
*/\r
public static function postUnshare( $params ) {\r
+ \r
+ // NOTE: $params has keys:\r
+ // [itemType] => file\r
+ // [itemSource] => 13\r
+ // [shareType] => 0\r
+ // [shareWith] => test1\r
\r
-// $view = new \OC_FilesystemView( '/' );\r
-// $session = new Session();\r
-// $userId = \OCP\User::getUser();\r
-// $util = new Util( $view, $userId );\r
-// $path = $util->fileIdToPath( $params['itemSource'] );\r
-// \r
-// return Crypt::updateKeyfile( $view, $util, $session, $userId, $path );\r
+ // TODO: Should other kinds of item be encrypted too?\r
+ if ( $params['itemType'] === 'file' ) {\r
+ \r
+ $view = new \OC_FilesystemView( '/' );\r
+ $session = new Session();\r
+ $userId = \OCP\User::getUser();\r
+ $util = new Util( $view, $userId );\r
+ $path = $util->fileIdToPath( $params['itemSource'] );\r
\r
+ $allPaths = $util->getPaths( $path );\r
+ \r
+ foreach ( $allPaths as $path ) {\r
+ \r
+ if ( ! Keymanager::delShareKey( $view, $userId, $path ) ) {\r
+ \r
+ $failed[] = $path;\r
+ \r
+ }\r
+ \r
+ }\r
+ \r
+ // If no attempts to set keyfiles failed\r
+ if ( empty( $failed ) ) {\r
+ \r
+ return true;\r
+ \r
+ } else {\r
+ \r
+ return false;\r
+ \r
+ }\r
+\r
+ }\r
+\r
}\r
\r
/**\r
\r
}\r
\r
+ /**\r
+ * @brief Delete a single user's shareKey for a single file\r
+ */\r
+ public static function delShareKey( \OC_FilesystemView $view, $userId, $filePath ) {\r
+ \r
+ $trimmed = ltrim( $filePath, '/' );\r
+ $shareKeyPath = '/' . $userId . '/files_encryption/share-keys/' . $trimmed . '.shareKey';\r
+ \r
+ // Unlink doesn't tell us if file was deleted (not found returns\r
+ // true), so we perform our own test\r
+ if ( $view->file_exists( $shareKeyPath ) ) {\r
+ \r
+ return $view->unlink( $shareKeyPath );\r
+ \r
+ } else {\r
+ \r
+ \OC_Log::write( 'Encryption library', 'Could not delete shareKey; does not exist: "' . $shareKeyPath, \OC_Log::ERROR );\r
+ \r
+ return false;\r
+ \r
+ }\r
+ \r
+ }\r
+ \r
/**\r
* @brief Make preparations to vars and filesystem for saving a keyfile\r
*/\r