summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2015-03-26 09:58:31 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2015-04-07 13:30:27 +0200
commitc00e728e5f77722bceaa0bba25a02128039d7127 (patch)
treecead55ea6f6d7ab57a4fdac7e3cf8e165e441fe4
parentecb3834554c05c82ea3129299673dca4a0917b30 (diff)
downloadnextcloud-server-c00e728e5f77722bceaa0bba25a02128039d7127.tar.gz
nextcloud-server-c00e728e5f77722bceaa0bba25a02128039d7127.zip
encryption app: remove legacy code, we do only server-side encryption
-rw-r--r--apps/encryption/lib/crypto/crypt.php8
-rw-r--r--apps/encryption/lib/keymanager.php99
2 files changed, 42 insertions, 65 deletions
diff --git a/apps/encryption/lib/crypto/crypt.php b/apps/encryption/lib/crypto/crypt.php
index f9fe4f9bece..9fb93485ef7 100644
--- a/apps/encryption/lib/crypto/crypt.php
+++ b/apps/encryption/lib/crypto/crypt.php
@@ -69,14 +69,6 @@ class Crypt {
}
/**
- * @param null $user
- * @return string
- */
- public function mode($user = null) {
- return 'server';
- }
-
- /**
*
*/
public function createKeyPair() {
diff --git a/apps/encryption/lib/keymanager.php b/apps/encryption/lib/keymanager.php
index 83b24c79b8c..c1c1f9811dc 100644
--- a/apps/encryption/lib/keymanager.php
+++ b/apps/encryption/lib/keymanager.php
@@ -239,78 +239,63 @@ class KeyManager {
*/
public function setPassphrase($params, IUserSession $user, Util $util) {
- // Only attempt to change passphrase if server-side encryption
- // is in use (client-side encryption does not have access to
- // the necessary keys)
- if ($this->crypt->mode() === 'server') {
+ // Get existing decrypted private key
+ $privateKey = self::$cacheFactory->get('privateKey');
- // Get existing decrypted private key
- $privateKey = self::$cacheFactory->get('privateKey');
+ if ($params['uid'] === $user->getUser()->getUID() && $privateKey) {
- if ($params['uid'] === $user->getUser()->getUID() && $privateKey) {
+ // Encrypt private key with new user pwd as passphrase
+ $encryptedPrivateKey = $this->crypt->symmetricEncryptFileContent($privateKey, $params['password']);
- // Encrypt private key with new user pwd as passphrase
- $encryptedPrivateKey = $this->crypt->symmetricEncryptFileContent($privateKey,
- $params['password']);
-
- // Save private key
- if ($encryptedPrivateKey) {
- $this->setPrivateKey($user->getUser()->getUID(),
- $encryptedPrivateKey);
- } else {
- $this->log->error('Encryption could not update users encryption password');
- }
-
- // NOTE: Session does not need to be updated as the
- // private key has not changed, only the passphrase
- // used to decrypt it has changed
-
-
- } else { // admin changed the password for a different user, create new keys and reencrypt file keys
-
- $user = $params['uid'];
- $recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null;
+ // Save private key
+ if ($encryptedPrivateKey) {
+ $this->setPrivateKey($user->getUser()->getUID(), $encryptedPrivateKey);
+ } else {
+ $this->log->error('Encryption could not update users encryption password');
+ }
- // we generate new keys if...
- // ...we have a recovery password and the user enabled the recovery key
- // ...encryption was activated for the first time (no keys exists)
- // ...the user doesn't have any files
- if (($util->recoveryEnabledForUser() && $recoveryPassword)
+ // NOTE: Session does not need to be updated as the
+ // private key has not changed, only the passphrase
+ // used to decrypt it has changed
+ } else { // admin changed the password for a different user, create new keys and reencrypt file keys
+ $user = $params['uid'];
+ $recoveryPassword = isset($params['recoveryPassword']) ? $params['recoveryPassword'] : null;
- || !$this->userHasKeys($user)
- || !$util->userHasFiles($user)
- ) {
+ // we generate new keys if...
+ // ...we have a recovery password and the user enabled the recovery key
+ // ...encryption was activated for the first time (no keys exists)
+ // ...the user doesn't have any files
+ if (($util->recoveryEnabledForUser() && $recoveryPassword) || !$this->userHasKeys($user) || !$util->userHasFiles($user)
+ ) {
- // backup old keys
- $this->backupAllKeys('recovery');
+ // backup old keys
+ $this->backupAllKeys('recovery');
- $newUserPassword = $params['password'];
+ $newUserPassword = $params['password'];
- $keypair = $this->crypt->createKeyPair();
+ $keypair = $this->crypt->createKeyPair();
- // Disable encryption proxy to prevent recursive calls
- $proxyStatus = \OC_FileProxy::$enabled;
- \OC_FileProxy::$enabled = false;
+ // Disable encryption proxy to prevent recursive calls
+ $proxyStatus = \OC_FileProxy::$enabled;
+ \OC_FileProxy::$enabled = false;
- // Save public key
- $this->setPublicKey($user, $keypair['publicKey']);
+ // Save public key
+ $this->setPublicKey($user, $keypair['publicKey']);
- // Encrypt private key with new password
- $encryptedKey = $this->crypt->symmetricEncryptFileContent($keypair['privateKey'],
- $newUserPassword);
+ // Encrypt private key with new password
+ $encryptedKey = $this->crypt->symmetricEncryptFileContent($keypair['privateKey'], $newUserPassword);
- if ($encryptedKey) {
- $this->setPrivateKey($user, $encryptedKey);
+ if ($encryptedKey) {
+ $this->setPrivateKey($user, $encryptedKey);
- if ($recoveryPassword) { // if recovery key is set we can re-encrypt the key files
- $util->recoverUsersFiles($recoveryPassword);
- }
- } else {
- $this->log->error('Encryption Could not update users encryption password');
+ if ($recoveryPassword) { // if recovery key is set we can re-encrypt the key files
+ $util->recoverUsersFiles($recoveryPassword);
}
-
- \OC_FileProxy::$enabled = $proxyStatus;
+ } else {
+ $this->log->error('Encryption Could not update users encryption password');
}
+
+ \OC_FileProxy::$enabled = $proxyStatus;
}
}
}