summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption
diff options
context:
space:
mode:
authorRobin Appelman <icewind@owncloud.com>2012-02-05 21:49:22 +0100
committerRobin Appelman <icewind@owncloud.com>2012-02-21 20:48:48 +0100
commitb3a974d8bbcd88602a54cf32cd472802583ab4aa (patch)
tree0cedf694730dc4be51015fb4906490e4cf92ea4d /apps/files_encryption
parent501678f981cf8e320d11cf1a780aefeae1537050 (diff)
downloadnextcloud-server-b3a974d8bbcd88602a54cf32cd472802583ab4aa.tar.gz
nextcloud-server-b3a974d8bbcd88602a54cf32cd472802583ab4aa.zip
only trigger hooks for the default filesystem view
Diffstat (limited to 'apps/files_encryption')
-rw-r--r--apps/files_encryption/lib/crypt.php41
1 files changed, 20 insertions, 21 deletions
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php
index 4e7739b1d06..0a593b98c4b 100644
--- a/apps/files_encryption/lib/crypt.php
+++ b/apps/files_encryption/lib/crypt.php
@@ -44,19 +44,20 @@ class OC_Crypt {
}
public static function init($login,$password) {
- if(OC_User::isLoggedIn()){
- $view=new OC_FilesystemView('/'.$login);
- if(!$view->file_exists('/encryption.key')){// does key exist?
- OC_Crypt::createkey($password);
- }
- $key=$view->file_get_contents('/encryption.key');
- $_SESSION['enckey']=OC_Crypt::decrypt($key, $password);
+ $view=new OC_FilesystemView('/'.$login);
+ OC_FileProxy::$enabled=false;
+ if(!$view->file_exists('/encryption.key')){// does key exist?
+ OC_Crypt::createkey($login,$password);
}
+ $key=$view->file_get_contents('/encryption.key');
+ OC_FileProxy::$enabled=true;
+ $_SESSION['enckey']=OC_Crypt::decrypt($key, $password);
}
/**
* get the blowfish encryption handeler for a key
* @param string $key (optional)
+ * @return Crypt_Blowfish
*
* if the key is left out, the default handeler will be used
*/
@@ -74,21 +75,19 @@ class OC_Crypt {
}
}
- public static function createkey($passcode) {
- if(OC_User::isLoggedIn()){
- // generate a random key
- $key=mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999);
+ public static function createkey($username,$passcode) {
+ // generate a random key
+ $key=mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999).mt_rand(10000,99999);
- // encrypt the key with the passcode of the user
- $enckey=OC_Crypt::encrypt($key,$passcode);
+ // encrypt the key with the passcode of the user
+ $enckey=OC_Crypt::encrypt($key,$passcode);
- // Write the file
- $username=OC_USER::getUser();
- OC_FileProxy::$enabled=false;
- $view=new OC_FilesystemView('/'.$username);
- $view->file_put_contents('/encryption.key',$enckey);
- OC_FileProxy::$enabled=true;
- }
+ // Write the file
+ $proxyEnabled=OC_FileProxy::$enabled;
+ OC_FileProxy::$enabled=false;
+ $view=new OC_FilesystemView('/'.$username);
+ $view->file_put_contents('/encryption.key',$enckey);
+ OC_FileProxy::$enabled=$proxyEnabled;
}
public static function changekeypasscode($oldPassword, $newPassword) {
@@ -133,7 +132,7 @@ class OC_Crypt {
*/
public static function decrypt( $content, $key='') {
$bf = self::getBlowfish($key);
- return($bf->encrypt($contents));
+ return($bf->decrypt($content));
}
/**