summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorSam Tuke <samtuke@owncloud.com>2012-11-22 19:36:48 +0000
committerSam Tuke <samtuke@owncloud.com>2012-11-22 19:36:48 +0000
commit5f78f9d64276806f392f24784c1594b285554c7e (patch)
tree08447790f3b406603dee56bb06dc40dd51ce7c6d /apps
parent13d93fb416709f9dca5660752eefb78a7c3dc1f7 (diff)
downloadnextcloud-server-5f78f9d64276806f392f24784c1594b285554c7e.tar.gz
nextcloud-server-5f78f9d64276806f392f24784c1594b285554c7e.zip
Development snapshot
Diffstat (limited to 'apps')
-rw-r--r--apps/files_encryption/lib/proxy.php68
-rw-r--r--apps/files_encryption/lib/util.php4
2 files changed, 30 insertions, 42 deletions
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index f021eb4c92e..45890287aeb 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -137,11 +137,8 @@ class Proxy extends \OC_FileProxy {
if ( Crypt::mode() == 'server' && Crypt::isEncryptedContent( $data ) ) {
- $filePath = explode( '/', $path );
-
- $filePath = array_slice( $filePath, 3 );
-
- $filePath = '/' . implode( '/', $filePath );
+ $path_split = explode( '/', $path );
+ $path_f = implode( array_slice( $path_split, 3 ) );
$cached = \OC_FileCache_Cached::get( $path, '' );
@@ -161,7 +158,7 @@ class Proxy extends \OC_FileProxy {
}
public function postFopen( $path, &$result ){
- trigger_error(var_export($path));
+
if ( !$result ) {
return $result;
@@ -173,67 +170,54 @@ class Proxy extends \OC_FileProxy {
$meta = stream_get_meta_data( $result );
+ // Reformat path for use with OC_FSV
+ $path_split = explode( '/', $path );
+ $path_f = implode( array_slice( $path_split, 3 ) );
+
+// trigger_error("\$meta(result) = ".var_export($meta, 1));
+
$view = new \OC_FilesystemView( '' );
$util = new Util( $view, \OCP\USER::getUser());
- // If file is encrypted, decrypt using crypto protocol
+ // If file is already encrypted, decrypt using crypto protocol
if ( Crypt::mode() == 'server' && $util->isEncryptedPath( $path ) ) {
-
- $tmp = fopen( 'php://temp' );
-
- \OCP\Files::streamCopy( $result, $tmp );
+ // Close the original encrypted file
fclose( $result );
- $encrypted = $view->file_get_contents( $path );
-
- // Replace the contents of
- \OC_Filesystem::file_put_contents( $path, $tmp );
-
- fclose( $tmp );
-
+ // Open the file using the crypto protocol and let
+ // it do the decryption work instead
$result = fopen( 'crypt://' . $path, $meta['mode'] );
-
-// $keyFile = Keymanager::getFileKey( $filePath );
-//
-// $tmp = tmpfile();
-//
-// fclose ( $result );
-//
-// $result = fopen( $tmp );
+
} elseif (
self::shouldEncrypt( $path )
and $meta ['mode'] != 'r'
and $meta['mode'] != 'rb'
) {
+ // If the file should be encrypted and has been opened for
+ // reading only
- # TODO: figure out what this does
-
- if (
- $view->file_exists( $path )
- and $view->filesize( $path ) > 0
+ if (
+ \OC_Filesystem::file_exists( $path_f )
+ and \OC_Filesystem::filesize( $path_f ) > 0
) {
- //first encrypt the target file so we don't end up with a half encrypted file
- \OCP\Util::writeLog( 'files_encryption', 'Decrypting '.$path.' before writing', \OCP\Util::DEBUG );
+ trigger_error("BAT");
+ $tmp = tmpfile();
- $tmp = fopen( 'php://temp' );
+ \OCP\Files::streamCopy($result, $tmp);
- // Make a temporary copy of the original file
- \OCP\Files::streamCopy( $result, $tmp );
+ fclose($result);
- // Close the original stream, we'll return another one
- fclose( $result );
+ \OC_Filesystem::file_put_contents($path_f, $tmp);
- \OC_Filesystem::file_put_contents( $path, $tmp );
+ fclose($tmp);
- fclose( $tmp );
-
}
- $result = fopen( 'crypt://'.$path, $meta['mode'] );
+ $result = fopen( 'crypt://' . $path_f, $meta['mode'] );
}
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index a1a2dddf43b..af13dbe3f84 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -68,6 +68,10 @@ class Util {
# TODO: test new encryption with proxies
# NOTE: Curretly code on line 206 onwards in lib/proxy.php needs work. This code is executed when webdav writes take place, and appears to need to convert streams into fopen resources. Currently code within the if statement on 215 is not executing. Investigate the paths (handled there (which appear to be blank), and whether oc_fsv is borking them during processing.
+
+ # NOTE: When files are written via webdav, they are encrypted and saved on the server, though they are not readable via web ui or webdav. proof of this is the changing length of content. When read in web ui, text reads "false", persumably because decryption failed. Why no error in
+
+ # NOTE: for some reason file_get_contents is not working in proxy class postfopen. The same line works in sscce, but always returns an empty string in proxy.php. this is the same regardless of whether oc_fs, oc_fsv, or direct use of phps file_get_contents is used
private $view; // OC_FilesystemView object for filesystem operations
private $pwd; // User Password