Development snapshot

working on stream handling (large files) in Util->encryptAll()
This commit is contained in:
Sam Tuke 2013-04-23 18:41:01 +02:00
parent c6bfc7315b
commit b7d8da87d0
3 changed files with 28 additions and 26 deletions

View File

@ -106,6 +106,7 @@ class Keymanager {
*/
public static function setFileKey( \OC_FilesystemView $view, $path, $userId, $catfile ) {
$proxyStatus = \OC_FileProxy::$enabled;
\OC_FileProxy::$enabled = false;
//here we need the currently logged in user, while userId can be a different user
@ -129,7 +130,7 @@ class Keymanager {
$result = $view->file_put_contents( $basePath . '/' . $targetPath . '.key', $catfile );
\OC_FileProxy::$enabled = true;
\OC_FileProxy::$enabled = $proxyStatus;
return $result;

View File

@ -142,7 +142,6 @@ class Proxy extends \OC_FileProxy {
$multiEncrypted = Crypt::multiKeyEncrypt( $plainKey, $publicKeys );
// Save sharekeys to user folders
Keymanager::setShareKeys( $rootView, $filePath, $multiEncrypted['keys'] );
// Set encrypted keyfile as common varname

View File

@ -500,37 +500,39 @@ class Util {
// Encrypt unencrypted files
foreach ( $found['plain'] as $plainFile ) {
// Open plain file handle
// Open enc file handle
// Read plain file in chunks
//relative to data/<user>/file
$relPath = $plainFile['path'];
//relative to /data
$rawPath = $this->userId . '/files/' . $plainFile['path'];
// Open handle with for binary reading
$plainHandle = $this->view->fopen( $rawPath, 'rb' );
// Open handle with for binary writing
$encHandle = fopen( 'crypt://' . $relPath . '.tmp', 'wb' );
// Overwrite the existing file with the encrypted one
//$this->view->file_put_contents( $plainFile['path'], $encrypted['data'] );
$size = stream_copy_to_stream( $plainHandle, $encHandle );
$this->view->rename($rawPath . '.tmp', $rawPath);
// Fetch the key that has just been set/updated by the stream
//$encKey = Keymanager::getFileKey( $this->view, $this->userId, $relPath );
// Open plain file handle for binary reading
$plainHandle1 = $this->view->fopen( $rawPath, 'rb' );
// Save keyfile
//Keymanager::setFileKey( $this->view, $relPath, $this->userId, $encKey );
// 2nd handle for moving plain file - view->rename() doesn't work, this is a workaround
$plainHandle2 = $this->view->fopen( $rawPath . '.plaintmp', 'wb' );
// Move plain file to a temporary location
stream_copy_to_stream( $plainHandle1, $plainHandle2 );
// Close access to original file
// $this->view->fclose( $plainHandle1 ); // not implemented in view{}
// Delete original plain file so we can rename enc file later
$this->view->unlink( $rawPath );
// Open enc file handle for binary writing, with same filename as original plain file
$encHandle = fopen( 'crypt://' . $relPath, 'wb' );
// Save data from plain stream to new encrypted file via enc stream
// NOTE: Stream{} will be invoked for handling
// the encryption, and should handle all keys
// and their generation etc. automatically
$size = stream_copy_to_stream( $plainHandle2, $encHandle );
// Delete temporary plain copy of file
$this->view->unlink( $rawPath . '.plaintmp' );
// Add the file to the cache
\OC\Files\Filesystem::putFileInfo( $plainFile['path'], array( 'encrypted'=>true, 'size' => $size ), '' );