summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/lib
diff options
context:
space:
mode:
authorSam Tuke <samtuke@owncloud.com>2012-08-15 18:49:53 +0100
committerSam Tuke <samtuke@owncloud.com>2012-08-15 18:49:53 +0100
commitf11f524dfa17071dbabb2f950680966867f262a6 (patch)
tree4c7af641f96585d7d76066cc54e13db0626868d8 /apps/files_encryption/lib
parentb883bb6b42ab64792fa6d9c299dd2aa0f652fb3a (diff)
downloadnextcloud-server-f11f524dfa17071dbabb2f950680966867f262a6.tar.gz
nextcloud-server-f11f524dfa17071dbabb2f950680966867f262a6.zip
working on streaming decrypted content
applied some dependency injection to keymanager.php
Diffstat (limited to 'apps/files_encryption/lib')
-rw-r--r--apps/files_encryption/lib/keymanager.php10
-rw-r--r--apps/files_encryption/lib/proxy.php14
-rw-r--r--apps/files_encryption/lib/util.php4
3 files changed, 17 insertions, 11 deletions
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index ea6e4872d4b..b06226397e8 100644
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -30,14 +30,14 @@ class Keymanager {
# TODO: make all dependencies (including static classes) explicit, such as ocfsview objects, by adding them as method arguments (dependency injection)
/**
- * @brief retrieve private key from a user
+ * @brief retrieve the ENCRYPTED private key from a user
*
* @return string private key or false
+ * @note the key returned by this method must be decrypted before use
*/
- public static function getPrivateKey() {
+ public static function getPrivateKey( $user, $view ) {
- $user = \OCP\User::getUser();
- $view = new \OC_FilesystemView( '/' . $user . '/' . 'files_encryption' );
+ $view->chroot( '/' . $user . '/' . 'files_encryption' );
return $view->file_get_contents( '/' . $user.'.private.key' );
}
@@ -121,7 +121,7 @@ class Keymanager {
* @return string file key or false
*/
public static function getFileKey( $path ) {
- trigger_error("div ".$path);
+
$keypath = ltrim( $path, '/' );
$user = \OCP\User::getUser();
diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php
index 51ed889d129..5b0369bde9b 100644
--- a/apps/files_encryption/lib/proxy.php
+++ b/apps/files_encryption/lib/proxy.php
@@ -135,6 +135,8 @@ class Proxy extends \OC_FileProxy {
public function postFile_get_contents( $path, $data ) {
+ # TODO: Use dependency injection to add required args for view and user etc. to this method
+
if ( Crypt::mode() == 'server' && Crypt::isEncryptedContent( $data ) ) {
$filePath = explode( '/', $path );
@@ -150,9 +152,7 @@ class Proxy extends \OC_FileProxy {
$keyFile = Keymanager::getFileKey( $filePath );
- $privateKey = Keymanager::getPrivateKey();
-
- $data = Crypt::keyDecryptKeyfile( $data, $keyFile, $privateKey );
+ $data = Crypt::keyDecryptKeyfile( $data, $keyFile, $_SESSION['enckey'] );
\OC_FileProxy::$enabled = true;
@@ -175,9 +175,15 @@ class Proxy extends \OC_FileProxy {
// If file is encrypted, decrypt using crypto protocol
if ( Crypt::mode() == 'server' && Crypt::isEncryptedContent( $path ) ) {
+ $keyFile = Keymanager::getFileKey( $filePath );
+
+ $tmp = tmpfile();
+
+ file_put_contents( $tmp, Crypt::keyDecryptKeyfile( $result, $keyFile, $_SESSION['enckey'] ) );
+
fclose ( $result );
- $result = fopen( 'crypt://'.$path, $meta['mode'] );
+ $result = fopen( $tmp );
} elseif (
self::shouldEncrypt( $path )
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index 609f7871241..b919c56a2eb 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -222,9 +222,9 @@ class Util {
}
- public function encryptAll( OC_FilesystemView $view ) {
+ public function encryptAll( $directory ) {
- $plainFiles = $this->findPlainFiles( $view );
+ $plainFiles = $this->findFiles( $this->view, 'plain' );
if ( $this->encryptFiles( $plainFiles ) ) {