diff options
-rw-r--r-- | apps/files_encryption/appinfo/app.php | 2 | ||||
-rw-r--r-- | apps/files_encryption/hooks/hooks.php | 9 | ||||
-rwxr-xr-x | apps/files_encryption/lib/crypt.php | 24 | ||||
-rw-r--r-- | apps/files_encryption/lib/util.php | 14 | ||||
-rw-r--r-- | lib/hook.php | 22 | ||||
-rw-r--r-- | settings/ajax/changepassword.php | 3 |
6 files changed, 32 insertions, 42 deletions
diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index e426f237bbe..f83109a18ea 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -12,7 +12,7 @@ OC_FileProxy::register( new OCA\Encryption\Proxy() ); // User-related hooks OCP\Util::connectHook( 'OC_User', 'post_login', 'OCA\Encryption\Hooks', 'login' ); -OCP\Util::connectHook( 'OC_User', 'post_setPassword','OCA\Encryption\Hooks', 'setPassphrase' ); +OCP\Util::connectHook( 'OC_User', 'pre_setPassword','OCA\Encryption\Hooks', 'setPassphrase' ); // Sharing-related hooks OCP\Util::connectHook( 'OCP\Share', 'post_shared', 'OCA\Encryption\Hooks', 'postShared' ); diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php index 065ef9d2410..8bdeee0937b 100644 --- a/apps/files_encryption/hooks/hooks.php +++ b/apps/files_encryption/hooks/hooks.php @@ -38,12 +38,15 @@ class Hooks { */
public static function login( $params ) {
+ // Manually initialise Filesystem{} singleton with correct
+ // fake root path, in order to avoid fatal webdav errors
\OC\Files\Filesystem::init( $params['uid'] . '/' . 'files' . '/' );
$view = new \OC_FilesystemView( '/' );
$util = new Util( $view, $params['uid'] );
+ // Check files_encryption infrastructure is ready for action
if ( ! $util->ready() ) {
\OC_Log::write( 'Encryption library', 'User account "' . $params['uid'] . '" is not ready for encryption; configuration started', \OC_Log::DEBUG );
@@ -104,14 +107,16 @@ class Hooks { * @param array $params keys: uid, password
*/
public static function setPassphrase( $params ) {
-
+
// Only attempt to change passphrase if server-side encryption
// is in use (client-side encryption does not have access to
// the necessary keys)
if ( Crypt::mode() == 'server' ) {
+ $session = new Session();
+
// Get existing decrypted private key
- $privateKey = $_SESSION['privateKey'];
+ $privateKey = $session->getPrivateKey();
// Encrypt private key with new user pwd as passphrase
$encryptedPrivateKey = Crypt::symmetricEncryptFileContent( $privateKey, $params['password'] );
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index e3ffacabc9a..d00f71b6141 100755 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -45,24 +45,6 @@ class Crypt { * @return string 'client' or 'server'
*/
public static function mode( $user = null ) {
-
-// $mode = \OC_Appconfig::getValue( 'files_encryption', 'mode', 'none' );
-//
-// if ( $mode == 'user') {
-// if ( !$user ) {
-// $user = \OCP\User::getUser();
-// }
-// $mode = 'none';
-// if ( $user ) {
-// $query = \OC_DB::prepare( "SELECT mode FROM *PREFIX*encryption WHERE uid = ?" );
-// $result = $query->execute(array($user));
-// if ($row = $result->fetchRow()){
-// $mode = $row['mode'];
-// }
-// }
-// }
-//
-// return $mode;
return 'server';
@@ -133,12 +115,6 @@ class Crypt { * @note see also OCA\Encryption\Util->isEncryptedPath()
*/
public static function isCatfile( $content ) {
-
- if ( !$content ) {
-
- return false;
-
- }
$noPadding = self::removePadding( $content );
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index 355ffb90ef0..52bc74db27a 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -69,11 +69,6 @@ class Util { //// DONE: add method to fetch legacy key //// DONE: add method to decrypt legacy encrypted data - //// TODO: add method to encrypt all user files using new system - //// TODO: add method to decrypt all user files using new system - //// TODO: add method to encrypt all user files using old system - //// TODO: add method to decrypt all user files using old system - // Admin UI: @@ -93,7 +88,6 @@ class Util { // Integration testing: - //// TODO: test new encryption with webdav //// TODO: test new encryption with versioning //// TODO: test new encryption with sharing //// TODO: test new encryption with proxies @@ -278,7 +272,7 @@ class Util { // will eat server resources :( if ( Keymanager::getFileKey( $this->view, $this->userId, $file ) - && Crypt::isCatfile( $filePath ) + && Crypt::isCatfile( $data ) ) { $found['encrypted'][] = array( 'name' => $file, 'path' => $filePath ); @@ -391,7 +385,6 @@ class Util { } - // FIXME: Legacy recrypting here isn't finished yet // Encrypt legacy encrypted files if ( ! empty( $legacyPassphrase ) @@ -437,6 +430,11 @@ class Util { } + /** + * @brief Return important encryption related paths + * @param string $pathName Name of the directory to return the path of + * @return string path + */ public function getPath( $pathName ) { switch ( $pathName ) { diff --git a/lib/hook.php b/lib/hook.php index 4da331bb5d8..e30aefb5e18 100644 --- a/lib/hook.php +++ b/lib/hook.php @@ -20,19 +20,22 @@ class OC_Hook{ * TODO: write example */ static public function connect( $signalclass, $signalname, $slotclass, $slotname ) { - // Create the data structure + // If we're trying to connect to an emitting class that isn't + // yet registered, register it if( !array_key_exists( $signalclass, self::$registered )) { self::$registered[$signalclass] = array(); } - if( !array_key_exists( $signalname, self::$registered[$signalclass] )) { + // If we're trying to connect to an emitting method that isn't + // yet registered, register it with the emitting class + if( !array_key_exists( $signalname, self::$registered[$signalclass] )) { self::$registered[$signalclass][$signalname] = array(); } - - // register hook + + // Connect the hook handler to the requested emitter self::$registered[$signalclass][$signalname][] = array( "class" => $slotclass, "name" => $slotname ); - + // No chance for failure ;-) return true; } @@ -49,14 +52,19 @@ class OC_Hook{ * TODO: write example */ static public function emit( $signalclass, $signalname, $params = array()) { - // Return false if there are no slots + + // Return false if no hook handlers are listening to this + // emitting class if( !array_key_exists( $signalclass, self::$registered )) { return false; } + + // Return false if no hook handlers are listening to this + // emitting method if( !array_key_exists( $signalname, self::$registered[$signalclass] )) { return false; } - + // Call all slots foreach( self::$registered[$signalclass][$signalname] as $i ) { try { diff --git a/settings/ajax/changepassword.php b/settings/ajax/changepassword.php index c1ff0a63701..ceb4bbeecb0 100644 --- a/settings/ajax/changepassword.php +++ b/settings/ajax/changepassword.php @@ -4,6 +4,9 @@ OCP\JSON::callCheck(); OC_JSON::checkLoggedIn(); +// Manually load apps to ensure hooks work correctly (workaround for issue 1503) +OC_APP::loadApps(); + $username = isset($_POST["username"]) ? $_POST["username"] : OC_User::getUser(); $password = $_POST["password"]; $oldPassword=isset($_POST["oldpassword"])?$_POST["oldpassword"]:''; |