* keys: data, key\r
* @note this method is a wrapper for combining other crypt class methods\r
*/\r
- public static function keyEncryptKeyfile( $plainContent, $publicKey ) {\r
- \r
+ public static function keyEncryptKeyfile( $plainContent, $publicKey, $path ) {\r
+\r
+ $user = \OCP\User::getUser();\r
+ $view = new \OC_FilesystemView('/');\r
+ $util = new Util($view, $user);\r
+\r
// Encrypt plain data, generate keyfile & encrypted file\r
$cryptedData = self::symmetricEncryptFileContentKeyfile( $plainContent );\r
\r
// Encrypt keyfile\r
- $cryptedKey = self::keyEncrypt( $cryptedData['key'], $publicKey );\r
- \r
- return array( 'data' => $cryptedData['encrypted'], 'key' => $cryptedKey );\r
+\r
+ $sharingEnabled = \OCP\Share::isEnabled();\r
+\r
+ // if file exists try to get sharing users\r
+ if($view->file_exists($path)) {\r
+ $uniqueUserIds = $util->getSharingUsersArray( $sharingEnabled, $path, $user );\r
+ } else {\r
+ $uniqueUserIds[] = $user;\r
+ }\r
+\r
+ // Fetch public keys for all users who will share the file\r
+ $publicKeys = Keymanager::getPublicKeys( $view, $uniqueUserIds );\r
+\r
+ // Encrypt plain keyfile to multiple sharefiles\r
+ $multiEncrypted = Crypt::multiKeyEncrypt( $cryptedData['key'], $publicKeys );\r
+\r
+ return array( 'data' => $cryptedData['encrypted'], 'filekey' => $multiEncrypted['data'], 'sharekeys' => $multiEncrypted['keys'] );\r
\r
}\r
\r
\r
}\r
\r
- public static function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKey, $newPassphrase ) {\r
+ public static function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKey, $newPassphrase, $path ) {\r
\r
$decrypted = self::legacyDecrypt( $legacyEncryptedContent, $legacyPassphrase );\r
\r
- $recrypted = self::keyEncryptKeyfile( $decrypted, $publicKey );\r
+ $recrypted = self::keyEncryptKeyfile( $decrypted, $publicKey, $path );\r
\r
return $recrypted;\r
\r
// Fetch data from file
$legacyData = $this->view->file_get_contents( $legacyFile['path'] );
-
+
// Recrypt data, generate catfile
- $recrypted = Crypt::legacyKeyRecryptKeyfile( $legacyData, $legacyPassphrase, $publicKey, $newPassphrase );
+ $recrypted = Crypt::legacyKeyRecryptKeyfile( $legacyData, $legacyPassphrase, $publicKey, $newPassphrase, $legacyFile['path'] );
- $relPath = $legacyFile['path'];
- $rawPath = $this->userId . '/files/' . $plainFile['path'];
+ $rawPath = $legacyFile['path'];
+ $relPath = $this->stripUserFilesPath($rawPath);
// Save keyfile
- Keymanager::setFileKey( $this->view, $relPath, $this->userId, $recrypted['key'] );
-
+ Keymanager::setFileKey( $this->view, $relPath, $this->userId, $recrypted['filekey'] );
+
+ // Save sharekeys to user folders
+ Keymanager::setShareKeys( $this->view, $relPath, $recrypted['sharekeys'] );
+
// Overwrite the existing file with the encrypted one
$this->view->file_put_contents( $rawPath, $recrypted['data'] );