2012-08-15 17:01:43 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2012 Sam Tuke <samtuke@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
2013-05-18 23:37:00 +04:00
|
|
|
|
2013-08-21 12:59:31 +04:00
|
|
|
require_once __DIR__ . '/../../../lib/base.php';
|
|
|
|
require_once __DIR__ . '/../lib/crypt.php';
|
|
|
|
require_once __DIR__ . '/../lib/keymanager.php';
|
|
|
|
require_once __DIR__ . '/../lib/proxy.php';
|
|
|
|
require_once __DIR__ . '/../lib/stream.php';
|
|
|
|
require_once __DIR__ . '/../lib/util.php';
|
|
|
|
require_once __DIR__ . '/../lib/helper.php';
|
|
|
|
require_once __DIR__ . '/../appinfo/app.php';
|
|
|
|
require_once __DIR__ . '/util.php';
|
2012-08-15 17:01:43 +04:00
|
|
|
|
2012-11-16 22:31:37 +04:00
|
|
|
use OCA\Encryption;
|
|
|
|
|
2013-05-20 00:28:48 +04:00
|
|
|
/**
|
|
|
|
* Class Test_Encryption_Keymanager
|
|
|
|
*/
|
2013-05-26 22:44:15 +04:00
|
|
|
class Test_Encryption_Keymanager extends \PHPUnit_Framework_TestCase {
|
2013-05-20 00:28:48 +04:00
|
|
|
|
2013-07-19 16:54:10 +04:00
|
|
|
const TEST_USER = "test-keymanager-user";
|
|
|
|
|
2013-05-20 00:28:48 +04:00
|
|
|
public $userId;
|
|
|
|
public $pass;
|
2014-06-26 19:38:06 +04:00
|
|
|
public static $stateFilesTrashbin;
|
2013-05-20 00:28:48 +04:00
|
|
|
/**
|
2014-05-12 18:30:39 +04:00
|
|
|
* @var OC\Files\View
|
2013-05-20 00:28:48 +04:00
|
|
|
*/
|
|
|
|
public $view;
|
|
|
|
public $randomKey;
|
2013-05-22 02:55:16 +04:00
|
|
|
public $dataShort;
|
2013-05-20 00:28:48 +04:00
|
|
|
|
2013-05-26 05:22:16 +04:00
|
|
|
public static function setUpBeforeClass() {
|
2013-05-20 03:24:36 +04:00
|
|
|
// reset backend
|
|
|
|
\OC_User::clearBackends();
|
2013-05-26 22:44:15 +04:00
|
|
|
\OC_User::useBackend('database');
|
2013-04-30 01:41:49 +04:00
|
|
|
|
2013-05-26 05:22:16 +04:00
|
|
|
// Filesystem related hooks
|
|
|
|
\OCA\Encryption\Helper::registerFilesystemHooks();
|
|
|
|
|
|
|
|
// clear and register hooks
|
|
|
|
\OC_FileProxy::clearProxies();
|
2013-05-26 22:44:15 +04:00
|
|
|
\OC_FileProxy::register(new OCA\Encryption\Proxy());
|
2013-05-26 05:22:16 +04:00
|
|
|
|
|
|
|
// disable file proxy by default
|
2012-08-15 17:01:43 +04:00
|
|
|
\OC_FileProxy::$enabled = false;
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-06-26 19:38:06 +04:00
|
|
|
// remember files_trashbin state
|
|
|
|
self::$stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
|
|
|
|
|
|
|
|
// we don't want to tests with app files_trashbin enabled
|
|
|
|
\OC_App::disable('files_trashbin');
|
|
|
|
|
2013-07-19 16:54:10 +04:00
|
|
|
// create test user
|
|
|
|
\OC_User::deleteUser(\Test_Encryption_Keymanager::TEST_USER);
|
|
|
|
\Test_Encryption_Util::loginHelper(\Test_Encryption_Keymanager::TEST_USER, true);
|
2013-05-26 05:22:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setUp() {
|
2013-01-06 22:38:35 +04:00
|
|
|
// set content for encrypting / decrypting in tests
|
2013-08-21 12:59:31 +04:00
|
|
|
$this->dataLong = file_get_contents(__DIR__ . '/../lib/crypt.php');
|
2013-01-06 22:38:35 +04:00
|
|
|
$this->dataShort = 'hats';
|
2013-08-21 12:59:31 +04:00
|
|
|
$this->dataUrl = __DIR__ . '/../lib/crypt.php';
|
|
|
|
$this->legacyData = __DIR__ . '/legacy-text.txt';
|
|
|
|
$this->legacyEncryptedData = __DIR__ . '/legacy-encrypted-text.txt';
|
2013-01-06 22:38:35 +04:00
|
|
|
$this->randomKey = Encryption\Crypt::generateKey();
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-01-06 22:38:35 +04:00
|
|
|
$keypair = Encryption\Crypt::createKeypair();
|
2013-05-20 03:24:36 +04:00
|
|
|
$this->genPublicKey = $keypair['publicKey'];
|
2013-01-06 22:38:35 +04:00
|
|
|
$this->genPrivateKey = $keypair['privateKey'];
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2014-05-12 18:30:39 +04:00
|
|
|
$this->view = new \OC\Files\View('/');
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2014-06-26 19:38:06 +04:00
|
|
|
\Test_Encryption_Util::loginHelper(Test_Encryption_Keymanager::TEST_USER);
|
2013-07-19 16:54:10 +04:00
|
|
|
$this->userId = \Test_Encryption_Keymanager::TEST_USER;
|
|
|
|
$this->pass = \Test_Encryption_Keymanager::TEST_USER;
|
2013-04-30 01:41:49 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$userHome = \OC_User::getHome($this->userId);
|
|
|
|
$this->dataDir = str_replace('/' . $this->userId, '', $userHome);
|
2012-08-15 17:01:43 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 05:22:16 +04:00
|
|
|
function tearDown() {
|
2014-06-26 19:38:06 +04:00
|
|
|
$this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys');
|
|
|
|
$this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles');
|
2012-08-15 17:01:43 +04:00
|
|
|
}
|
|
|
|
|
2013-05-26 05:22:16 +04:00
|
|
|
public static function tearDownAfterClass() {
|
|
|
|
\OC_FileProxy::$enabled = true;
|
2013-07-19 16:54:10 +04:00
|
|
|
|
|
|
|
// cleanup test user
|
|
|
|
\OC_User::deleteUser(\Test_Encryption_Keymanager::TEST_USER);
|
2014-06-26 19:38:06 +04:00
|
|
|
// reset app files_trashbin
|
|
|
|
if (self::$stateFilesTrashbin) {
|
|
|
|
OC_App::enable('files_trashbin');
|
|
|
|
}
|
2013-05-26 05:22:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 05:22:16 +04:00
|
|
|
function testGetPrivateKey() {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$key = Encryption\Keymanager::getPrivateKey($this->view, $this->userId);
|
2013-04-30 03:54:19 +04:00
|
|
|
|
2014-07-22 01:36:20 +04:00
|
|
|
$privateKey = Encryption\Crypt::decryptPrivateKey($key, $this->pass);
|
2013-04-30 03:54:19 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$res = openssl_pkey_get_private($privateKey);
|
2013-04-30 03:54:19 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_resource($res));
|
2013-05-19 00:00:35 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$sslInfo = openssl_pkey_get_details($res);
|
2013-05-19 00:00:35 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertArrayHasKey('key', $sslInfo);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2012-08-15 17:13:03 +04:00
|
|
|
}
|
2013-01-05 21:12:23 +04:00
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 05:22:16 +04:00
|
|
|
function testGetPublicKey() {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$publiceKey = Encryption\Keymanager::getPublicKey($this->view, $this->userId);
|
2013-05-19 00:00:35 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$res = openssl_pkey_get_public($publiceKey);
|
2013-05-19 00:00:35 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_resource($res));
|
2013-05-19 00:00:35 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$sslInfo = openssl_pkey_get_details($res);
|
2013-05-19 00:00:35 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertArrayHasKey('key', $sslInfo);
|
2013-01-05 21:12:23 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-02-03 16:39:05 +04:00
|
|
|
/**
|
|
|
|
* @small
|
|
|
|
*/
|
|
|
|
function testGetFilenameFromShareKey() {
|
|
|
|
$this->assertEquals("file",
|
|
|
|
\TestProtectedKeymanagerMethods::testGetFilenameFromShareKey("file.user.shareKey"));
|
|
|
|
$this->assertEquals("file.name.with.dots",
|
|
|
|
\TestProtectedKeymanagerMethods::testGetFilenameFromShareKey("file.name.with.dots.user.shareKey"));
|
|
|
|
$this->assertFalse(\TestProtectedKeymanagerMethods::testGetFilenameFromShareKey("file.txt"));
|
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 05:22:16 +04:00
|
|
|
function testSetFileKey() {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-08-08 15:35:01 +04:00
|
|
|
$key = $this->randomKey;
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-01-21 19:19:26 +04:00
|
|
|
$file = 'unittest-' . uniqid() . '.txt';
|
2013-04-30 01:41:49 +04:00
|
|
|
|
2013-11-21 03:23:38 +04:00
|
|
|
$util = new Encryption\Util($this->view, $this->userId);
|
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Disable encryption proxy to prevent recursive calls
|
|
|
|
$proxyStatus = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
2013-04-30 01:41:49 +04:00
|
|
|
|
2013-08-08 15:35:01 +04:00
|
|
|
$this->view->file_put_contents($this->userId . '/files/' . $file, $this->dataShort);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-11-27 18:08:09 +04:00
|
|
|
Encryption\Keymanager::setFileKey($this->view, $util, $file, $key);
|
2013-04-30 01:41:49 +04:00
|
|
|
|
2013-08-08 15:35:01 +04:00
|
|
|
$this->assertTrue($this->view->file_exists('/' . $this->userId . '/files_encryption/keyfiles/' . $file . '.key'));
|
2013-05-17 03:07:26 +04:00
|
|
|
|
|
|
|
// cleanup
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->view->unlink('/' . $this->userId . '/files/' . $file);
|
2013-05-17 03:07:26 +04:00
|
|
|
|
2013-05-22 02:55:16 +04:00
|
|
|
// change encryption proxy to previous state
|
2013-05-17 03:07:26 +04:00
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
2012-08-23 19:43:10 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-07-22 19:22:15 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
|
|
|
function testSetPrivateKey() {
|
|
|
|
|
|
|
|
$key = "dummy key";
|
|
|
|
|
|
|
|
Encryption\Keymanager::setPrivateKey($key, 'dummyUser');
|
|
|
|
|
|
|
|
$this->assertTrue($this->view->file_exists('/dummyUser/files_encryption/dummyUser.private.key'));
|
|
|
|
|
|
|
|
//clean up
|
|
|
|
$this->view->deleteAll('/dummyUser');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
|
|
|
function testSetPrivateSystemKey() {
|
|
|
|
|
|
|
|
$key = "dummy key";
|
|
|
|
$keyName = "myDummyKey.private.key";
|
|
|
|
|
|
|
|
Encryption\Keymanager::setPrivateSystemKey($key, $keyName);
|
|
|
|
|
|
|
|
$this->assertTrue($this->view->file_exists('/owncloud_private_key/' . $keyName));
|
|
|
|
|
|
|
|
// clean up
|
|
|
|
$this->view->unlink('/owncloud_private_key/' . $keyName);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 05:22:16 +04:00
|
|
|
function testGetUserKeys() {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$keys = Encryption\Keymanager::getUserKeys($this->view, $this->userId);
|
2013-04-30 03:54:19 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$resPublic = openssl_pkey_get_public($keys['publicKey']);
|
2013-04-30 03:54:19 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_resource($resPublic));
|
2013-04-30 03:54:19 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$sslInfoPublic = openssl_pkey_get_details($resPublic);
|
2013-04-30 03:54:19 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertArrayHasKey('key', $sslInfoPublic);
|
2013-05-19 00:25:47 +04:00
|
|
|
|
2014-07-22 01:36:20 +04:00
|
|
|
$privateKey = Encryption\Crypt::decryptPrivateKey($keys['privateKey'], $this->pass);
|
2013-05-19 00:25:47 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$resPrivate = openssl_pkey_get_private($privateKey);
|
2013-05-19 00:25:47 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_resource($resPrivate));
|
2013-05-19 00:25:47 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$sslInfoPrivate = openssl_pkey_get_details($resPrivate);
|
2013-05-19 00:25:47 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertArrayHasKey('key', $sslInfoPrivate);
|
2013-01-05 21:12:23 +04:00
|
|
|
}
|
2013-05-22 02:55:16 +04:00
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-06-26 19:38:06 +04:00
|
|
|
function testRecursiveDelShareKeysFolder() {
|
|
|
|
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data');
|
2013-05-22 02:55:16 +04:00
|
|
|
|
2014-06-26 19:38:06 +04:00
|
|
|
// create folder structure for some dummy share key files
|
2014-06-23 19:13:56 +04:00
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1');
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder');
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder');
|
|
|
|
|
|
|
|
// create some dummy share keys
|
2014-06-26 19:38:06 +04:00
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user1.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
|
2014-06-23 19:13:56 +04:00
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.user1.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user2.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user3.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/file2.user3.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file1.user1.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user2.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user3.shareKey', 'data');
|
|
|
|
|
|
|
|
// recursive delete share keys from user1 and user2
|
2014-07-04 14:06:23 +04:00
|
|
|
Encryption\Keymanager::delShareKey($this->view, array('user1', 'user2', Test_Encryption_Keymanager::TEST_USER), '/folder1/', Test_Encryption_Keymanager::TEST_USER);
|
2014-06-23 19:13:56 +04:00
|
|
|
|
|
|
|
// check if share keys from user1 and user2 are deleted
|
2014-06-26 19:38:06 +04:00
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.user1.shareKey'));
|
2014-06-23 19:13:56 +04:00
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file1.user1.shareKey'));
|
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user2.shareKey'));
|
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file1.user1.shareKey'));
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertFalse($this->view->file_exists(
|
2014-06-23 19:13:56 +04:00
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user2.shareKey'));
|
2013-05-22 02:55:16 +04:00
|
|
|
|
2014-06-23 19:13:56 +04:00
|
|
|
// check if share keys from user3 still exists
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/file2.user3.shareKey'));
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/subsubfolder/file2.user3.shareKey'));
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/subfolder/file2.user3.shareKey'));
|
2013-05-22 02:55:16 +04:00
|
|
|
|
2014-06-26 19:38:06 +04:00
|
|
|
// owner key from existing file should still exists because the file is still there
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
|
|
|
|
|
2013-05-22 02:55:16 +04:00
|
|
|
// cleanup
|
2014-06-26 19:38:06 +04:00
|
|
|
$this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
|
|
|
function testRecursiveDelShareKeysFile() {
|
|
|
|
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data');
|
|
|
|
|
|
|
|
// create folder structure for some dummy share key files
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1');
|
|
|
|
|
|
|
|
// create some dummy share keys
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user1.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user2.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user3.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
|
|
|
|
|
|
|
|
// recursive delete share keys from user1 and user2
|
2014-07-04 14:06:23 +04:00
|
|
|
Encryption\Keymanager::delShareKey($this->view, array('user1', 'user2', Test_Encryption_Keymanager::TEST_USER), '/folder1/existingFile.txt', Test_Encryption_Keymanager::TEST_USER);
|
2014-06-26 19:38:06 +04:00
|
|
|
|
|
|
|
// check if share keys from user1 and user2 are deleted
|
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.user1.shareKey'));
|
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.user2.shareKey'));
|
|
|
|
|
|
|
|
// check if share keys for user3 and owner
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user3.shareKey'));
|
|
|
|
// cleanup
|
|
|
|
$this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
|
|
|
function testDeleteFileKey() {
|
|
|
|
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data');
|
|
|
|
|
|
|
|
// create folder structure for some dummy file key files
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1');
|
|
|
|
|
|
|
|
// create dummy keyfile
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/dummyFile.txt.key', 'data');
|
|
|
|
|
|
|
|
// recursive delete share keys from user1 and user2
|
|
|
|
$result = Encryption\Keymanager::deleteFileKey($this->view, '/folder1/existingFile.txt');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$result2 = Encryption\Keymanager::deleteFileKey($this->view, '/folder1/dummyFile.txt');
|
|
|
|
$this->assertTrue($result2);
|
|
|
|
|
|
|
|
// check if file key from dummyFile was deleted
|
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/dummyFile.txt.key'));
|
|
|
|
|
|
|
|
// check if file key from existing file still exists
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/existingFile.txt.key'));
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
|
|
|
function testDeleteFileKeyFolder() {
|
|
|
|
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data');
|
|
|
|
|
|
|
|
// create folder structure for some dummy file key files
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1');
|
|
|
|
|
|
|
|
// create dummy keyfile
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/dummyFile.txt.key', 'data');
|
|
|
|
|
|
|
|
// recursive delete share keys from user1 and user2
|
|
|
|
$result = Encryption\Keymanager::deleteFileKey($this->view, '/folder1');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
// all file keys should still exists if we try to delete a folder with keys for which some files still exists
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/dummyFile.txt.key'));
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/existingFile.txt.key'));
|
|
|
|
|
|
|
|
// delete folder
|
|
|
|
$this->view->unlink('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
|
|
|
// create dummy keyfile
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1/dummyFile.txt.key', 'data');
|
|
|
|
|
|
|
|
// now file keys should be deleted since the folder no longer exists
|
|
|
|
$result = Encryption\Keymanager::deleteFileKey($this->view, '/folder1');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/keyfiles/folder1'));
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDelAllShareKeysFile() {
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1/existingFile.txt', 'data');
|
|
|
|
|
|
|
|
// create folder structure for some dummy share key files
|
|
|
|
$this->view->mkdir('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1');
|
|
|
|
|
|
|
|
// create some dummy share keys for the existing file
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user1.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user2.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user3.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
|
|
|
|
|
|
|
|
// create some dummy share keys for a non-existing file
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user1.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user2.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user3.shareKey', 'data');
|
|
|
|
$this->view->file_put_contents('/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey', 'data');
|
|
|
|
|
|
|
|
// try to del all share keys from a existing file, should fail because the file still exists
|
|
|
|
$result = Encryption\Keymanager::delAllShareKeys($this->view, Test_Encryption_Keymanager::TEST_USER, 'folder1/existingFile.txt');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
// check if share keys still exists
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user1.shareKey'));
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user2.shareKey'));
|
|
|
|
$this->assertTrue($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/existingFile.txt.user3.shareKey'));
|
|
|
|
|
|
|
|
// try to del all share keys froma file, should fail because the file still exists
|
|
|
|
$result2 = Encryption\Keymanager::delAllShareKeys($this->view, Test_Encryption_Keymanager::TEST_USER, 'folder1/nonexistingFile.txt');
|
|
|
|
$this->assertTrue($result2);
|
|
|
|
|
|
|
|
// check if share keys are really gone
|
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.' . Test_Encryption_Keymanager::TEST_USER . '.shareKey'));
|
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user1.shareKey'));
|
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user2.shareKey'));
|
|
|
|
$this->assertFalse($this->view->file_exists(
|
|
|
|
'/'.Test_Encryption_Keymanager::TEST_USER.'/files_encryption/share-keys/folder1/nonexistingFile.txt.user3.shareKey'));
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$this->view->deleteAll('/'.Test_Encryption_Keymanager::TEST_USER.'/files/folder1');
|
2013-05-22 02:55:16 +04:00
|
|
|
|
|
|
|
}
|
2014-06-24 12:43:07 +04:00
|
|
|
|
|
|
|
function testKeySetPreperation() {
|
|
|
|
$basePath = '/'.Test_Encryption_Keymanager::TEST_USER.'/files';
|
2014-06-25 14:38:26 +04:00
|
|
|
$path = '/folder1/subfolder/subsubfolder/file.txt';
|
2014-06-24 12:43:07 +04:00
|
|
|
|
|
|
|
$this->assertFalse($this->view->is_dir($basePath . '/testKeySetPreperation'));
|
|
|
|
|
|
|
|
$result = TestProtectedKeymanagerMethods::testKeySetPreperation($this->view, $path, $basePath);
|
|
|
|
|
|
|
|
// return path without leading slash
|
2014-06-25 14:38:26 +04:00
|
|
|
$this->assertSame('folder1/subfolder/subsubfolder/file.txt', $result);
|
2014-06-24 12:43:07 +04:00
|
|
|
|
|
|
|
// check if directory structure was created
|
|
|
|
$this->assertTrue($this->view->is_dir($basePath . '/folder1/subfolder/subsubfolder'));
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
$this->view->deleteAll($basePath . '/folder1');
|
|
|
|
|
|
|
|
}
|
2012-08-15 17:01:43 +04:00
|
|
|
}
|
2014-02-03 16:39:05 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* dummy class to access protected methods of \OCA\Encryption\Keymanager for testing
|
|
|
|
*/
|
|
|
|
class TestProtectedKeymanagerMethods extends \OCA\Encryption\Keymanager {
|
2014-02-06 19:30:58 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $sharekey
|
|
|
|
*/
|
2014-02-03 16:39:05 +04:00
|
|
|
public static function testGetFilenameFromShareKey($sharekey) {
|
|
|
|
return self::getFilenameFromShareKey($sharekey);
|
|
|
|
}
|
2014-06-24 12:43:07 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param \OC\Files\View $view relative to data/
|
|
|
|
* @param string $path
|
|
|
|
* @param string $basePath
|
|
|
|
*/
|
|
|
|
public static function testKeySetPreperation($view, $path, $basePath) {
|
2014-06-23 19:13:56 +04:00
|
|
|
return self::keySetPreparation($view, $path, $basePath);
|
2014-06-24 12:43:07 +04:00
|
|
|
}
|
2014-05-12 18:30:39 +04:00
|
|
|
}
|