fix re-encrypt legacy files
This commit is contained in:
parent
986e9dd362
commit
8e324aad38
|
@ -732,40 +732,28 @@ class Util {
|
||||||
// Fetch data from file
|
// Fetch data from file
|
||||||
$legacyData = $this->view->file_get_contents($legacyFile['path']);
|
$legacyData = $this->view->file_get_contents($legacyFile['path']);
|
||||||
|
|
||||||
$sharingEnabled = \OCP\Share::isEnabled();
|
// decrypt data, generate catfile
|
||||||
|
$decrypted = Crypt::legacyBlockDecrypt($legacyData, $legacyPassphrase);
|
||||||
// if file exists try to get sharing users
|
|
||||||
if ($this->view->file_exists($legacyFile['path'])) {
|
|
||||||
$uniqueUserIds = $this->getSharingUsersArray($sharingEnabled, $legacyFile['path'], $this->userId);
|
|
||||||
} else {
|
|
||||||
$uniqueUserIds[] = $this->userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch public keys for all users who will share the file
|
|
||||||
$publicKeys = Keymanager::getPublicKeys($this->view, $uniqueUserIds);
|
|
||||||
|
|
||||||
// Recrypt data, generate catfile
|
|
||||||
$recrypted = Crypt::legacyKeyRecryptKeyfile( $legacyData, $legacyPassphrase, $publicKeys );
|
|
||||||
|
|
||||||
$rawPath = $legacyFile['path'];
|
$rawPath = $legacyFile['path'];
|
||||||
$relPath = $this->stripUserFilesPath($rawPath);
|
|
||||||
|
|
||||||
// Save keyfile
|
// enable proxy the ensure encryption is handled
|
||||||
Keymanager::setFileKey($this->view, $relPath, $this->userId, $recrypted['filekey']);
|
\OC_FileProxy::$enabled = true;
|
||||||
|
|
||||||
// Save sharekeys to user folders
|
// Open enc file handle for binary writing, with same filename as original plain file
|
||||||
Keymanager::setShareKeys($this->view, $relPath, $recrypted['sharekeys']);
|
$encHandle = $this->view->fopen( $rawPath, 'wb' );
|
||||||
|
|
||||||
// Overwrite the existing file with the encrypted one
|
if (is_resource($encHandle)) {
|
||||||
$this->view->file_put_contents($rawPath, $recrypted['data']);
|
|
||||||
|
|
||||||
$size = strlen($recrypted['data']);
|
// write data to stream
|
||||||
|
fwrite($encHandle, $decrypted);
|
||||||
|
|
||||||
// Add the file to the cache
|
// close stream
|
||||||
\OC\Files\Filesystem::putFileInfo($rawPath, array(
|
fclose($encHandle);
|
||||||
'encrypted' => true,
|
}
|
||||||
'size' => $size
|
|
||||||
), '');
|
// disable proxy to prevent file being encrypted twice
|
||||||
|
\OC_FileProxy::$enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue