summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/lib/stream.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/lib/stream.php')
-rw-r--r--apps/files_encryption/lib/stream.php54
1 files changed, 39 insertions, 15 deletions
diff --git a/apps/files_encryption/lib/stream.php b/apps/files_encryption/lib/stream.php
index 74dff1531a9..ac5fadd4e03 100644
--- a/apps/files_encryption/lib/stream.php
+++ b/apps/files_encryption/lib/stream.php
@@ -59,7 +59,9 @@ class Stream {
private $count;
private $writeCache;
public $size;
+ private $publicKey;
private $keyfile;
+ private $encKeyfile;
private static $view;
public function stream_open( $path, $mode, $options, &$opened_path ) {
@@ -246,7 +248,7 @@ class Stream {
* @param bool $generate if true, a new key will be generated if none can be found
* @return bool true on key found and set, false on key not found and new key generated and set
*/
- public function getKey( $generate = true ) {
+ public function getKey() {
//echo "\n\$this->rawPath = {$this->rawPath}";
@@ -256,23 +258,37 @@ class Stream {
# TODO: add error handling for when file exists but no keyfile
// Fetch existing keyfile
- $this->keyfile = Keymanager::getFileKey( $this->rawPath );
+ $this->encKeyfile = Keymanager::getFileKey( $this->rawPath );
+
+ $this->getUser();
+
+ $session = new Session();
+
+ $this->keyfile = Crypt::keyDecrypt( $this->encKeyfile, $session->getPrivateKey( $this->userId ) );
return true;
} else {
- if ( $generate ) {
-
- // If the data is to be written to a new file, generate a new keyfile
- $this->keyfile = Crypt::generateKey();
-
- return false;
-
- }
-
+ return false;
+
+ }
+
+ }
+
+ public function getuser() {
+
+ // Only get the user again if it isn't already set
+ if ( empty( $this->userId ) ) {
+
+ # TODO: Move this user call out of here - it belongs elsewhere
+ $this->userId = \OCP\User::getUser();
+
}
+ # TODO: Add a method for getting the user in case OCP\User::
+ # getUser() doesn't work (can that scenario ever occur?)
+
}
/**
@@ -306,15 +322,23 @@ class Stream {
//echo "\$pointer = $pointer\n";
- # TODO: Move this user call out of here - it belongs elsewhere
- $user = \OCP\User::getUser();
+ // Make sure the userId is set
+ $this->getuser();
// Get / generate the keyfile for the file we're handling
// If we're writing a new file (not overwriting an existing one), save the newly generated keyfile
if ( ! $this->getKey() ) {
+
+ $this->keyfile = Crypt::generateKey();
+
+ $this->publicKey = Keymanager::getPublicKey( $this->userId );
+
+ $this->encKeyfile = Crypt::keyEncrypt( $this->keyfile, $this->publicKey );
+
+ // Save the new encrypted file key
+ Keymanager::setFileKey( $this->rawPath, $this->encKeyfile, new \OC_FilesystemView( '/' ) );
- // Save keyfile in parallel directory structure
- Keymanager::setFileKey( $this->rawPath, $this->keyfile, new \OC_FilesystemView( '/' ) );
+ # TODO: move this new OCFSV out of here some how, use DI
}