summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2012-08-09 13:47:27 +0200
committerBjoern Schiessle <schiessle@owncloud.com>2012-08-09 13:47:27 +0200
commit800942ece74ac336c4a9213228f14406d7e494f7 (patch)
treeb717c18b91245041f211ae96d670d7d4d41c5d4f /apps/files_encryption
parent5a261b5b8ffd01c34ce009a431a5587c548fa9a7 (diff)
downloadnextcloud-server-800942ece74ac336c4a9213228f14406d7e494f7.tar.gz
nextcloud-server-800942ece74ac336c4a9213228f14406d7e494f7.zip
change key password when user switches from client to server side encryption.
make use of the keymanager class in changekeypasscode()
Diffstat (limited to 'apps/files_encryption')
-rw-r--r--apps/files_encryption/ajax/mode.php1
-rw-r--r--apps/files_encryption/js/settings-personal.js6
-rw-r--r--apps/files_encryption/lib/crypt.php22
-rw-r--r--apps/files_encryption/lib/keymanager.php9
4 files changed, 21 insertions, 17 deletions
diff --git a/apps/files_encryption/ajax/mode.php b/apps/files_encryption/ajax/mode.php
index c81d4947956..f1a026ca431 100644
--- a/apps/files_encryption/ajax/mode.php
+++ b/apps/files_encryption/ajax/mode.php
@@ -32,6 +32,7 @@ if ($result->fetchRow()){
} else {
$query = OC_DB::prepare( 'INSERT INTO *PREFIX*encryption ( mode, uid ) VALUES( ?, ? )' );
}
+
if ( (!$changePasswd || $passwdChanged) && $query->execute(array($mode, \OCP\User::getUser())) ) {
OCP\JSON::success();
} else {
diff --git a/apps/files_encryption/js/settings-personal.js b/apps/files_encryption/js/settings-personal.js
index fad077a8dd7..f335cf7f880 100644
--- a/apps/files_encryption/js/settings-personal.js
+++ b/apps/files_encryption/js/settings-personal.js
@@ -18,14 +18,12 @@ $(document).ready(function(){
}
} else if (server) {
if (prevmode == 'client') {
- OC.dialogs.form([{text:'login password', name:'newpasswd', type:'password'},{text:'Encryption password used on the client', name:'oldpasswd', type:'password'}],t('encryption', 'Please enter your passwords'), function(data) {
+ OC.dialogs.form([{text:'login password', name:'newpasswd', type:'password'},{text:'Encryption password used on the client', name:'oldpasswd', type:'password'}],t('encryption', 'Change encryption password to login password'), function(data) {
$.post(OC.filePath('files_encryption', 'ajax', 'mode.php'), { mode: 'server', newpasswd: data[0].value, oldpasswd: data[1].value }, function(result) {
if (result.status != 'success') {
- console.log("change selection back to " + prevmode+'_encryption');
document.getElementById(prevmode+'_encryption').checked = true;
- } else {
+ OC.dialogs.alert(t('encryption', 'Please check your passwords and try again'), t('encryption', 'Could not change encryption password to login password'))
}
-
});
});
} else {
diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php
index 64bbc17ec11..1fa7013776a 100644
--- a/apps/files_encryption/lib/crypt.php
+++ b/apps/files_encryption/lib/crypt.php
@@ -412,21 +412,23 @@ class Crypt {
}
public static function changekeypasscode($oldPassword, $newPassword) {
- if(OCP\User::isLoggedIn()){
- $username=OCP\USER::getUser();
- $view=new OC_FilesystemView('/'.$username);
+ if(\OCP\User::isLoggedIn()){
+ $username = \OCP\USER::getUser();
+ $view = new \OC_FilesystemView('/'.$username);
// read old key
- $key=$view->file_get_contents('/encryption.key');
+ $key = Keymanager::getPrivateKey();
// decrypt key with old passcode
- $key=OC_Crypt::decrypt($key, $oldPassword);
+ if ( ($key = self::decrypt($key, $oldPassword)) ) {
+ // encrypt again with new passcode
+ $key = self::encrypt($key, $newPassword);
- // encrypt again with new passcode
- $key=OC_Crypt::encrypt($key, $newPassword);
-
- // store the new key
- $view->file_put_contents('/encryption.key', $key );
+ // store the new key
+ return Keymanager::setPrivateKey($key);
+ } else {
+ return false;
+ }
}
}
diff --git a/apps/files_encryption/lib/keymanager.php b/apps/files_encryption/lib/keymanager.php
index e546ba825e4..4c30c163957 100644
--- a/apps/files_encryption/lib/keymanager.php
+++ b/apps/files_encryption/lib/keymanager.php
@@ -200,9 +200,12 @@ class Keymanager {
}
public static function changePasswd($oldpasswd, $newpasswd) {
- //TODO change password of private key
- error_log("password changed from '$oldpasswd' to '$newpasswd'");
- return true;
+ if ( \OCP\User::checkPassword(\OCP\User::getUser(), $newpasswd) ) {
+ return Crypt::changekeypasscode($oldpasswd, $newpasswd);
+ } else {
+ return false;
+ }
+
}
} \ No newline at end of file