From fe9a9c326438b9fa7681e27c71b9bfc04242bfe1 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Bj=C3=B6rn=20Schie=C3=9Fle?=
Date: Mon, 3 Jun 2013 15:27:31 +0200
Subject: [PATCH] let user update private key password in case it was changed
from outside, e.g. external auth back-ends
---
.../ajax/updatePrivateKeyPassword.php | 54 +++++++++++++++++++
apps/files_encryption/js/settings-personal.js | 30 +++++++++++
apps/files_encryption/settings-personal.php | 4 ++
.../templates/settings-personal.php | 30 +++++++++++
4 files changed, 118 insertions(+)
create mode 100644 apps/files_encryption/ajax/updatePrivateKeyPassword.php
diff --git a/apps/files_encryption/ajax/updatePrivateKeyPassword.php b/apps/files_encryption/ajax/updatePrivateKeyPassword.php
new file mode 100644
index 00000000000..e0b3d55d8b3
--- /dev/null
+++ b/apps/files_encryption/ajax/updatePrivateKeyPassword.php
@@ -0,0 +1,54 @@
+
+ * This file is licensed under the Affero General Public License version 3 or later.
+ * See the COPYING-README file.
+ *
+ * @brief Script to change recovery key password
+ *
+ */
+
+use OCA\Encryption;
+
+\OCP\JSON::checkLoggedIn();
+\OCP\JSON::checkAppEnabled('files_encryption');
+\OCP\JSON::callCheck();
+
+$l = OC_L10N::get('core');
+
+$return = false;
+
+$oldPassword = $_POST['oldPassword'];
+$newPassword = $_POST['newPassword'];
+
+$view = new \OC\Files\View('/');
+$session = new \OCA\Encryption\Session($view);
+$user = \OCP\User::getUser();
+
+$proxyStatus = \OC_FileProxy::$enabled;
+\OC_FileProxy::$enabled = false;
+
+$keyPath = '/' . $user . '/files_encryption/'.$user.'.private.key';
+
+$encryptedKey = $view->file_get_contents($keyPath);
+$decryptedKey = \OCA\Encryption\Crypt::decryptPrivateKey($encryptedKey, $oldPassword);
+
+if ($decryptedKey) {
+
+ $encryptedKey = \OCA\Encryption\Crypt::symmetricEncryptFileContent($decryptedKey, $newPassword);
+ $view->file_put_contents($keyPath, $encryptedKey);
+
+ $session->getPrivateKey($decryptedKey);
+
+ $return = true;
+}
+
+\OC_FileProxy::$enabled = $proxyStatus;
+
+// success or failure
+if ($return) {
+ \OCP\JSON::success(array('data' => array('message' => $l->t('Private key password successfully updated.'))));
+} else {
+ \OCP\JSON::error(array('data' => array('message' => $l->t('Could not update the private key password. Maybe the old password was not correct.'))));
+}
\ No newline at end of file
diff --git a/apps/files_encryption/js/settings-personal.js b/apps/files_encryption/js/settings-personal.js
index 312b672ad46..46105176c29 100644
--- a/apps/files_encryption/js/settings-personal.js
+++ b/apps/files_encryption/js/settings-personal.js
@@ -57,4 +57,34 @@ $(document).ready(function(){
}
);
+
+ // update private key password
+
+ $('input:password[name="changePrivateKeyPassword"]').keyup(function(event) {
+ var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
+ var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
+ if (newPrivateKeyPassword != '' && oldPrivateKeyPassword != '' ) {
+ $('button:button[name="submitChangePrivateKeyPassword"]').removeAttr("disabled");
+ } else {
+ $('button:button[name="submitChangePrivateKeyPassword"]').attr("disabled", "true");
+ }
+ });
+
+ $('button:button[name="submitChangePrivateKeyPassword"]').click(function() {
+ var oldPrivateKeyPassword = $('input:password[id="oldPrivateKeyPassword"]').val();
+ var newPrivateKeyPassword = $('input:password[id="newPrivateKeyPassword"]').val();
+ OC.msg.startSaving('#encryption .msg');
+ $.post(
+ OC.filePath( 'files_encryption', 'ajax', 'updatePrivateKeyPassword.php' )
+ , { oldPassword: oldPrivateKeyPassword, newPassword: newPrivateKeyPassword }
+ , function( data ) {
+ if (data.status == "error") {
+ OC.msg.finishedSaving('#encryption .msg', data);
+ } else {
+ OC.msg.finishedSaving('#encryption .msg', data);
+ }
+ }
+ );
+ });
+
});
\ No newline at end of file
diff --git a/apps/files_encryption/settings-personal.php b/apps/files_encryption/settings-personal.php
index 3e96565949b..d23a4cfdde3 100644
--- a/apps/files_encryption/settings-personal.php
+++ b/apps/files_encryption/settings-personal.php
@@ -14,6 +14,9 @@ $tmpl = new OCP\Template('files_encryption', 'settings-personal');
$user = \OCP\USER::getUser();
$view = new \OC_FilesystemView('/');
$util = new \OCA\Encryption\Util($view, $user);
+$session = new \OCA\Encryption\Session($view);
+
+$privateKeySet = ($session->getPrivateKey() !== false) ? true : false;
$recoveryAdminEnabled = OC_Appconfig::getValue('files_encryption', 'recoveryAdminEnabled');
$recoveryEnabledForUser = $util->recoveryEnabledForUser();
@@ -23,6 +26,7 @@ $recoveryEnabledForUser = $util->recoveryEnabledForUser();
$tmpl->assign('recoveryEnabled', $recoveryAdminEnabled);
$tmpl->assign('recoveryEnabledForUser', $recoveryEnabledForUser);
+$tmpl->assign("privateKeySet" , $privateKeySet);
return $tmpl->fetchPage();
diff --git a/apps/files_encryption/templates/settings-personal.php b/apps/files_encryption/templates/settings-personal.php
index 04d6e79179e..bacdc133375 100644
--- a/apps/files_encryption/templates/settings-personal.php
+++ b/apps/files_encryption/templates/settings-personal.php
@@ -3,6 +3,35 @@
+
+
+
+
+
+ t( "Set your old private key password to your current log-in password." ) ); ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -28,6 +57,7 @@
t( 'Could not update file recovery' ) ); ?>
+
--
2.39.5