|
|
|
|
@ -479,15 +479,33 @@ class Crypt {
|
|
|
|
|
* keys: data, key
|
|
|
|
|
* @note this method is a wrapper for combining other crypt class methods
|
|
|
|
|
*/
|
|
|
|
|
public static function keyEncryptKeyfile( $plainContent, $publicKey ) {
|
|
|
|
|
|
|
|
|
|
public static function keyEncryptKeyfile( $plainContent, $publicKey, $path ) {
|
|
|
|
|
|
|
|
|
|
$user = \OCP\User::getUser();
|
|
|
|
|
$view = new \OC_FilesystemView('/');
|
|
|
|
|
$util = new Util($view, $user);
|
|
|
|
|
|
|
|
|
|
// Encrypt plain data, generate keyfile & encrypted file
|
|
|
|
|
$cryptedData = self::symmetricEncryptFileContentKeyfile( $plainContent );
|
|
|
|
|
|
|
|
|
|
// Encrypt keyfile
|
|
|
|
|
$cryptedKey = self::keyEncrypt( $cryptedData['key'], $publicKey );
|
|
|
|
|
|
|
|
|
|
return array( 'data' => $cryptedData['encrypted'], 'key' => $cryptedKey );
|
|
|
|
|
|
|
|
|
|
$sharingEnabled = \OCP\Share::isEnabled();
|
|
|
|
|
|
|
|
|
|
// if file exists try to get sharing users
|
|
|
|
|
if($view->file_exists($path)) {
|
|
|
|
|
$uniqueUserIds = $util->getSharingUsersArray( $sharingEnabled, $path, $user );
|
|
|
|
|
} else {
|
|
|
|
|
$uniqueUserIds[] = $user;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch public keys for all users who will share the file
|
|
|
|
|
$publicKeys = Keymanager::getPublicKeys( $view, $uniqueUserIds );
|
|
|
|
|
|
|
|
|
|
// Encrypt plain keyfile to multiple sharefiles
|
|
|
|
|
$multiEncrypted = Crypt::multiKeyEncrypt( $cryptedData['key'], $publicKeys );
|
|
|
|
|
|
|
|
|
|
return array( 'data' => $cryptedData['encrypted'], 'filekey' => $multiEncrypted['data'], 'sharekeys' => $multiEncrypted['keys'] );
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -725,11 +743,11 @@ class Crypt {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKey, $newPassphrase ) {
|
|
|
|
|
public static function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKey, $newPassphrase, $path ) {
|
|
|
|
|
|
|
|
|
|
$decrypted = self::legacyDecrypt( $legacyEncryptedContent, $legacyPassphrase );
|
|
|
|
|
|
|
|
|
|
$recrypted = self::keyEncryptKeyfile( $decrypted, $publicKey );
|
|
|
|
|
$recrypted = self::keyEncryptKeyfile( $decrypted, $publicKey, $path );
|
|
|
|
|
|
|
|
|
|
return $recrypted;
|
|
|
|
|
|
|
|
|
|
|