From c89fd49870e3bdd66b73ab6d8d64895e870de260 Mon Sep 17 00:00:00 2001 From: Sam Tuke Date: Tue, 19 Mar 2013 19:53:15 +0100 Subject: [PATCH] Improved folder creation code Created stub method for checking user pwd recovery preference from db Added pwd recovery column to db Added comments --- apps/files_encryption/appinfo/database.xml | 8 +++ apps/files_encryption/hooks/hooks.php | 6 +- apps/files_encryption/lib/util.php | 68 ++++++++++------------ 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/apps/files_encryption/appinfo/database.xml b/apps/files_encryption/appinfo/database.xml index d294c35d63..b144b6cb2a 100644 --- a/apps/files_encryption/appinfo/database.xml +++ b/apps/files_encryption/appinfo/database.xml @@ -18,6 +18,14 @@ text true 64 + What client-side / server-side configuration is used + + + recovery + boolean + true + 0 + Whether encryption key recovery is enabled diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 590ba7b1b9..8db7539706 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -29,9 +29,6 @@ namespace OCA\Encryption; class Hooks { - // TODO: use passphrase for encrypting private key that is separate to - // the login password - /** * @brief Startup encryption backend upon user login * @note This method should never be called for users using client side encryption @@ -196,12 +193,15 @@ class Hooks { $usersSharing = \OCP\Share::getUsersSharingFile( $path, true ); + // Recursively expand path to include subfiles $allPaths = $util->getPaths( $path ); $failed = array(); + // Loop through all subfiles foreach ( $allPaths as $path ) { + // Attempt to set shareKey if ( ! $util->setSharedFileKeyfiles( $session, $usersSharing, $path ) ) { $failed[] = $path; diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index e8b5be2de1..a80da73a4b 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -153,45 +153,24 @@ class Util { */ public function setupServerSide( $passphrase = null ) { - // Create user dir - if( !$this->view->file_exists( $this->userDir ) ) { + // Set directories to check / create + $setUpDirs = array( + $this->userDir + , $this->userFilesDir + , $this->publicKeyDir + , $this->encryptionDir + , $this->keyfilesPath + , $this->shareKeysPath + ); - $this->view->mkdir( $this->userDir ); + // Check / create all necessary dirs + foreach ( $setUpDirs as $dirPath ) { - } - - // Create user files dir - if( !$this->view->file_exists( $this->userFilesDir ) ) { - - $this->view->mkdir( $this->userFilesDir ); - - } - - // Create shared public key directory - if( !$this->view->file_exists( $this->publicKeyDir ) ) { - - $this->view->mkdir( $this->publicKeyDir ); - - } - - // Create encryption app directory - if( !$this->view->file_exists( $this->encryptionDir ) ) { - - $this->view->mkdir( $this->encryptionDir ); - - } - - // Create mirrored keyfile directory - if( !$this->view->file_exists( $this->keyfilesPath ) ) { - - $this->view->mkdir( $this->keyfilesPath ); - - } - - // Create mirrored share env keys directory - if( !$this->view->file_exists( $this->shareKeysPath ) ) { - - $this->view->mkdir( $this->shareKeysPath ); + if( !$this->view->file_exists( $dirPath ) ) { + + $this->view->mkdir( $dirPath ); + + } } @@ -223,6 +202,20 @@ class Util { } + public function recoveryEnabled( ) { + + $sql = 'SELECT * FROM `*PREFIX*myusers` WHERE id = ?'; + $args = array(1); + + $query = \OCP\DB::prepare($sql); + $result = $query->execute($args); + + while($row = $result->fetchRow()) { + $userName = $row['username']; + } + + } + /** * @brief Find all files and their encryption status within a directory * @param string $directory The path of the parent directory to search @@ -737,6 +730,7 @@ class Util { $fileOwner = \OC\Files\Filesystem::getOwner( $filePath ); + // Decrypt keyfile $plainKeyfile = $this->decryptUnknownKeyfile( $filePath, $fileOwner, $privateKey ); // Re-enc keyfile to (additional) sharekeys