[Pkg-owncloud-commits] [owncloud] 101/258: create backup from all keys before recovery
David Prévot
taffit at moszumanska.debian.org
Sat Oct 11 17:22:25 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository owncloud.
commit a2e905683226ca393529383de15e3d543d5f39e0
Author: Bjoern Schiessle <schiessle at owncloud.com>
Date: Tue Sep 16 15:16:27 2014 +0200
create backup from all keys before recovery
---
apps/files_encryption/hooks/hooks.php | 3 +++
apps/files_encryption/lib/util.php | 16 +++++++++++++
apps/files_encryption/tests/util.php | 42 +++++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+)
diff --git a/apps/files_encryption/hooks/hooks.php b/apps/files_encryption/hooks/hooks.php
index d514bce..ee08af3 100644
--- a/apps/files_encryption/hooks/hooks.php
+++ b/apps/files_encryption/hooks/hooks.php
@@ -242,6 +242,9 @@ class Hooks {
|| !$util->userKeysExists()
|| !$view->file_exists($user . '/files')) {
+ // backup old keys
+ $util->backupAllKeys('recovery');
+
$newUserPassword = $params['password'];
// make sure that the users home is mounted
diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php
index f434b67..7cd4b95 100644
--- a/apps/files_encryption/lib/util.php
+++ b/apps/files_encryption/lib/util.php
@@ -1526,6 +1526,22 @@ class Util {
}
/**
+ * create a backup of all keys from the user
+ *
+ * @param string $purpose (optional) define the purpose of the backup, will be part of the backup folder
+ */
+ public function backupAllKeys($purpose = '') {
+ $this->userId;
+ $backupDir = $this->encryptionDir . '/backup.';
+ $backupDir .= ($purpose === '') ? date("Y-m-d_H-i-s") . '/' : $purpose . '.' . date("Y-m-d_H-i-s") . '/';
+ $this->view->mkdir($backupDir);
+ $this->view->copy($this->shareKeysPath, $backupDir . 'share-keys/');
+ $this->view->copy($this->keyfilesPath, $backupDir . 'keyfiles/');
+ $this->view->copy($this->privateKeyPath, $backupDir . $this->userId . '.private.key');
+ $this->view->copy($this->publicKeyPath, $backupDir . $this->userId . '.public.key');
+ }
+
+ /**
* check if the file is stored on a system wide mount point
* @param string $path relative to /data/user with leading '/'
* @return boolean
diff --git a/apps/files_encryption/tests/util.php b/apps/files_encryption/tests/util.php
index d069f4c..8213890 100755
--- a/apps/files_encryption/tests/util.php
+++ b/apps/files_encryption/tests/util.php
@@ -426,6 +426,48 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
}
+ /**
+ * test if all keys get moved to the backup folder correctly
+ */
+ function testBackupAllKeys() {
+ self::loginHelper(self::TEST_ENCRYPTION_UTIL_USER1);
+
+ // create some dummy key files
+ $encPath = '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '/files_encryption';
+ $this->view->file_put_contents($encPath . '/keyfiles/foo.key', 'key');
+ $this->view->file_put_contents($encPath . '/share-keys/foo.user1.shareKey', 'share key');
+
+ $util = new \OCA\Encryption\Util($this->view, self::TEST_ENCRYPTION_UTIL_USER1);
+
+ $util->backupAllKeys('testing');
+
+ $encFolderContent = $this->view->getDirectoryContent($encPath);
+
+ $backupPath = '';
+ foreach ($encFolderContent as $c) {
+ $name = $c['name'];
+ if (substr($name, 0, strlen('backup')) === 'backup') {
+ $backupPath = $encPath . '/'. $c['name'];
+ break;
+ }
+ }
+
+ $this->assertTrue($backupPath !== '');
+
+ // check backupDir Content
+ $this->assertTrue($this->view->is_dir($backupPath . '/keyfiles'));
+ $this->assertTrue($this->view->is_dir($backupPath . '/share-keys'));
+ $this->assertTrue($this->view->file_exists($backupPath . '/keyfiles/foo.key'));
+ $this->assertTrue($this->view->file_exists($backupPath . '/share-keys/foo.user1.shareKey'));
+ $this->assertTrue($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.private.key'));
+ $this->assertTrue($this->view->file_exists($backupPath . '/' . self::TEST_ENCRYPTION_UTIL_USER1 . '.public.key'));
+
+ //cleanup
+ $this->view->deleteAll($backupPath);
+ $this->view->unlink($encPath . '/keyfiles/foo.key', 'key');
+ $this->view->unlink($encPath . '/share-keys/foo.user1.shareKey', 'share key');
+ }
+
function testDescryptAllWithBrokenFiles() {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list