2012-04-17 22:56:53 +04:00
|
|
|
<?php
|
|
|
|
/**
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Andreas Fischer <bantu@owncloud.com>
|
|
|
|
* @author Björn Schießle <schiessle@owncloud.com>
|
|
|
|
* @author Florin Peter <github@florin-peter.de>
|
|
|
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
|
|
|
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <icewind@owncloud.com>
|
|
|
|
* @author Sam Tuke <mail@samtuke.com>
|
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
2012-04-17 22:56:53 +04:00
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
namespace OCA\Files_Encryption\Tests;
|
2012-08-15 17:52:03 +04:00
|
|
|
|
2013-05-20 00:28:48 +04:00
|
|
|
/**
|
2014-12-03 19:20:04 +03:00
|
|
|
* Class Crypt
|
2013-05-20 00:28:48 +04:00
|
|
|
*/
|
2014-12-03 19:20:04 +03:00
|
|
|
class Crypt extends TestCase {
|
2013-05-26 22:44:15 +04:00
|
|
|
|
|
|
|
const TEST_ENCRYPTION_CRYPT_USER1 = "test-crypt-user1";
|
2013-05-20 00:28:48 +04:00
|
|
|
|
|
|
|
public $userId;
|
|
|
|
public $pass;
|
|
|
|
public $stateFilesTrashbin;
|
|
|
|
public $dataLong;
|
|
|
|
public $dataUrl;
|
|
|
|
public $dataShort;
|
|
|
|
/**
|
2014-12-03 19:20:04 +03:00
|
|
|
* @var \OC\Files\View
|
2013-05-20 00:28:48 +04:00
|
|
|
*/
|
|
|
|
public $view;
|
|
|
|
public $legacyEncryptedData;
|
|
|
|
public $genPrivateKey;
|
|
|
|
public $genPublicKey;
|
|
|
|
|
2014-12-17 13:12:37 +03:00
|
|
|
/** @var \OCP\IConfig */
|
|
|
|
private $config;
|
|
|
|
|
2013-05-26 05:22:16 +04:00
|
|
|
public static function setUpBeforeClass() {
|
2014-11-06 18:53:35 +03:00
|
|
|
parent::setUpBeforeClass();
|
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
// create test user
|
2014-12-03 19:03:11 +03:00
|
|
|
self::loginHelper(self::TEST_ENCRYPTION_CRYPT_USER1, true);
|
2013-05-26 05:22:16 +04:00
|
|
|
}
|
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
protected function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
// set user id
|
2014-12-03 19:03:11 +03:00
|
|
|
self::loginHelper(self::TEST_ENCRYPTION_CRYPT_USER1);
|
|
|
|
$this->userId = self::TEST_ENCRYPTION_CRYPT_USER1;
|
|
|
|
$this->pass = self::TEST_ENCRYPTION_CRYPT_USER1;
|
2013-05-26 22:44:15 +04:00
|
|
|
|
2013-05-20 03:24:36 +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');
|
2012-08-23 19:43:10 +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';
|
|
|
|
$this->legacyEncryptedDataKey = __DIR__ . '/encryption.key';
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->randomKey = \OCA\Files_Encryption\Crypt::generateKey();
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$keypair = \OCA\Files_Encryption\Crypt::createKeypair();
|
2013-05-20 03:24:36 +04:00
|
|
|
$this->genPublicKey = $keypair['publicKey'];
|
2012-11-28 22:39:19 +04:00
|
|
|
$this->genPrivateKey = $keypair['privateKey'];
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-05-12 18:30:39 +04:00
|
|
|
$this->view = new \OC\Files\View('/');
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-17 03:07:26 +04:00
|
|
|
// remember files_trashbin state
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->stateFilesTrashbin = \OC_App::isEnabled('files_trashbin');
|
2013-05-17 03:07:26 +04:00
|
|
|
|
|
|
|
// we don't want to tests with app files_trashbin enabled
|
2013-05-26 22:44:15 +04:00
|
|
|
\OC_App::disable('files_trashbin');
|
2014-12-17 13:12:37 +03:00
|
|
|
|
|
|
|
$this->config = \OC::$server->getConfig();
|
2012-07-18 21:52:00 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
protected function tearDown() {
|
2013-05-17 03:07:26 +04:00
|
|
|
// reset app files_trashbin
|
2013-05-26 22:44:15 +04:00
|
|
|
if ($this->stateFilesTrashbin) {
|
2014-12-03 19:20:04 +03:00
|
|
|
\OC_App::enable('files_trashbin');
|
2013-06-03 20:42:13 +04:00
|
|
|
} else {
|
2014-12-03 19:20:04 +03:00
|
|
|
\OC_App::disable('files_trashbin');
|
2013-05-17 03:07:26 +04:00
|
|
|
}
|
2014-07-16 18:04:56 +04:00
|
|
|
|
|
|
|
$this->assertTrue(\OC_FileProxy::$enabled);
|
2014-12-17 13:12:37 +03:00
|
|
|
$this->config->deleteSystemValue('cipher');
|
2014-11-06 18:53:35 +03:00
|
|
|
|
|
|
|
parent::tearDown();
|
2013-05-20 03:24:36 +04:00
|
|
|
}
|
|
|
|
|
2013-05-26 05:22:16 +04:00
|
|
|
public static function tearDownAfterClass() {
|
2013-05-26 22:44:15 +04:00
|
|
|
// cleanup test user
|
2014-12-03 19:03:11 +03:00
|
|
|
\OC_User::deleteUser(self::TEST_ENCRYPTION_CRYPT_USER1);
|
2014-10-10 17:34:19 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
parent::tearDownAfterClass();
|
2013-05-26 05:22:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testGenerateKey() {
|
2012-07-18 21:52:00 +04:00
|
|
|
|
|
|
|
# TODO: use more accurate (larger) string length for test confirmation
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$key = \OCA\Files_Encryption\Crypt::generateKey();
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(strlen($key) > 16);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2012-07-18 21:52:00 +04:00
|
|
|
}
|
2013-05-20 00:28:48 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testDecryptPrivateKey() {
|
2013-06-03 19:34:43 +04:00
|
|
|
|
|
|
|
// test successful decrypt
|
2014-12-03 19:20:04 +03:00
|
|
|
$crypted = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->genPrivateKey, 'hat');
|
2013-06-03 19:34:43 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$header = \OCA\Files_Encryption\Crypt::generateHeader();
|
2014-07-22 01:36:20 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$decrypted = \OCA\Files_Encryption\Crypt::decryptPrivateKey($header . $crypted, 'hat');
|
2013-06-03 19:34:43 +04:00
|
|
|
|
2013-06-03 19:43:06 +04:00
|
|
|
$this->assertEquals($this->genPrivateKey, $decrypted);
|
2013-06-03 19:34:43 +04:00
|
|
|
|
|
|
|
//test private key decrypt with wrong password
|
2014-12-03 19:20:04 +03:00
|
|
|
$wrongPasswd = \OCA\Files_Encryption\Crypt::decryptPrivateKey($crypted, 'hat2');
|
2013-06-03 19:34:43 +04:00
|
|
|
|
|
|
|
$this->assertEquals(false, $wrongPasswd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-11 17:19:02 +04:00
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testSymmetricEncryptFileContent() {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2012-07-18 21:52:00 +04:00
|
|
|
# TODO: search in keyfile for actual content as IV will ensure this test always passes
|
2012-08-16 22:18:18 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$crypted = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->dataShort, 'hat');
|
2012-08-16 22:18:18 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertNotEquals($this->dataShort, $crypted);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$decrypt = \OCA\Files_Encryption\Crypt::symmetricDecryptFileContent($crypted, 'hat');
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2012-08-16 22:18:18 +04:00
|
|
|
|
|
|
|
}
|
2013-05-20 00:28:48 +04:00
|
|
|
|
2014-07-22 19:22:15 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testSymmetricEncryptFileContentAes128() {
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
# TODO: search in keyfile for actual content as IV will ensure this test always passes
|
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$crypted = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->dataShort, 'hat', 'AES-128-CFB');
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
$this->assertNotEquals($this->dataShort, $crypted);
|
|
|
|
|
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$decrypt = \OCA\Files_Encryption\Crypt::symmetricDecryptFileContent($crypted, 'hat', 'AES-128-CFB');
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testSymmetricStreamEncryptShortFileContent() {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
$filename = 'tmp-' . $this->getUniqueID() . '.test';
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-07-30 16:18:01 +04:00
|
|
|
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/'. $filename, $this->dataShort);
|
2013-04-29 11:12:43 +04:00
|
|
|
|
2012-08-23 22:19:39 +04:00
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-04-29 11:12:43 +04:00
|
|
|
|
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-05-20 03:24:36 +04:00
|
|
|
// Get file contents without using any wrapper to get it's actual contents on disk
|
2013-05-26 22:44:15 +04:00
|
|
|
$retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename);
|
2013-04-30 01:41:49 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Re-enable proxy - our work is done
|
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
2013-04-29 11:12:43 +04:00
|
|
|
|
2012-08-23 22:19:39 +04:00
|
|
|
// Check that the file was encrypted before being written to disk
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertNotEquals($this->dataShort, $retreivedCryptedFile);
|
2013-04-29 11:12:43 +04:00
|
|
|
|
2014-07-22 01:36:20 +04:00
|
|
|
// Get file contents with the encryption wrapper
|
|
|
|
$decrypted = file_get_contents('crypt:///' . $this->userId . '/files/'. $filename);
|
2013-04-29 11:12:43 +04:00
|
|
|
|
2012-12-11 21:12:46 +04:00
|
|
|
// Check that decrypted data matches
|
2014-07-22 01:36:20 +04:00
|
|
|
$this->assertEquals($this->dataShort, $decrypted);
|
2013-04-30 01:41:49 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Teardown
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->view->unlink($this->userId . '/files/' . $filename);
|
2012-04-17 22:56:53 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-07-22 19:22:15 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testSymmetricStreamEncryptShortFileContentAes128() {
|
2014-07-22 19:22:15 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
$filename = 'tmp-' . $this->getUniqueID() . '.test';
|
2014-07-22 19:22:15 +04:00
|
|
|
|
2014-12-17 13:12:37 +03:00
|
|
|
$this->config->setSystemValue('cipher', 'AES-128-CFB');
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/'. $filename, $this->dataShort);
|
|
|
|
|
|
|
|
// Test that data was successfully written
|
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
|
|
|
|
2014-12-17 13:12:37 +03:00
|
|
|
$this->config->deleteSystemValue('cipher');
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
// Disable encryption proxy to prevent recursive calls
|
|
|
|
$proxyStatus = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
|
|
|
|
|
|
|
// Get file contents without using any wrapper to get it's actual contents on disk
|
|
|
|
$retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename);
|
|
|
|
|
|
|
|
// Re-enable proxy - our work is done
|
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
|
|
|
|
|
|
|
// Check that the file was encrypted before being written to disk
|
|
|
|
$this->assertNotEquals($this->dataShort, $retreivedCryptedFile);
|
|
|
|
|
|
|
|
// Get file contents with the encryption wrapper
|
|
|
|
$decrypted = file_get_contents('crypt:///' . $this->userId . '/files/'. $filename);
|
|
|
|
|
|
|
|
// Check that decrypted data matches
|
|
|
|
$this->assertEquals($this->dataShort, $decrypted);
|
|
|
|
|
|
|
|
// Teardown
|
|
|
|
$this->view->unlink($this->userId . '/files/' . $filename);
|
|
|
|
}
|
|
|
|
|
2012-12-11 21:12:46 +04:00
|
|
|
/**
|
2013-06-10 11:31:22 +04:00
|
|
|
* @medium
|
2014-05-19 19:50:53 +04:00
|
|
|
* Test that data that is written by the crypto stream wrapper
|
2012-12-11 21:12:46 +04:00
|
|
|
* @note Encrypted data is manually prepared and decrypted here to avoid dependency on success of stream_read
|
2013-05-20 03:24:36 +04:00
|
|
|
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
|
2012-12-11 21:12:46 +04:00
|
|
|
* reassembly of its data
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testSymmetricStreamEncryptLongFileContent() {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2012-12-11 21:12:46 +04:00
|
|
|
// Generate a a random filename
|
2014-11-06 18:53:35 +03:00
|
|
|
$filename = 'tmp-' . $this->getUniqueID() . '.test';
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2012-12-11 21:12:46 +04:00
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-07-30 16:18:01 +04:00
|
|
|
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2012-12-11 21:12:46 +04:00
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-04-30 01:41:49 +04:00
|
|
|
// Disable encryption proxy to prevent recursive calls
|
2013-05-20 03:24:36 +04:00
|
|
|
$proxyStatus = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
|
|
|
|
|
|
|
// Get file contents without using any wrapper to get it's actual contents on disk
|
2013-05-26 22:44:15 +04:00
|
|
|
$retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename);
|
2013-04-30 01:41:49 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Re-enable proxy - our work is done
|
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
2013-04-30 01:41:49 +04:00
|
|
|
|
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Check that the file was encrypted before being written to disk
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertNotEquals($this->dataLong . $this->dataLong, $retreivedCryptedFile);
|
2013-04-30 01:41:49 +04:00
|
|
|
|
2014-07-22 01:36:20 +04:00
|
|
|
$decrypted = file_get_contents('crypt:///' . $this->userId . '/files/'. $filename);
|
2013-04-30 01:41:49 +04:00
|
|
|
|
2014-07-22 01:36:20 +04:00
|
|
|
$this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2012-12-11 21:12:46 +04:00
|
|
|
// Teardown
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->view->unlink($this->userId . '/files/' . $filename);
|
2012-12-11 21:12:46 +04:00
|
|
|
}
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-07-22 19:22:15 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
* Test that data that is written by the crypto stream wrapper with AES 128
|
|
|
|
* @note Encrypted data is manually prepared and decrypted here to avoid dependency on success of stream_read
|
|
|
|
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
|
|
|
|
* reassembly of its data
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testSymmetricStreamEncryptLongFileContentAes128() {
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
// Generate a a random filename
|
2014-11-06 18:53:35 +03:00
|
|
|
$filename = 'tmp-' . $this->getUniqueID() . '.test';
|
2014-07-22 19:22:15 +04:00
|
|
|
|
2014-12-17 13:12:37 +03:00
|
|
|
$this->config->setSystemValue('cipher', 'AES-128-CFB');
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
// Save long data as encrypted file using stream wrapper
|
|
|
|
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong);
|
|
|
|
|
|
|
|
// Test that data was successfully written
|
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
|
|
|
|
|
|
|
// Disable encryption proxy to prevent recursive calls
|
|
|
|
$proxyStatus = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
|
|
|
|
2014-12-17 13:12:37 +03:00
|
|
|
$this->config->deleteSystemValue('cipher');
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
// Get file contents without using any wrapper to get it's actual contents on disk
|
|
|
|
$retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename);
|
|
|
|
|
|
|
|
// Re-enable proxy - our work is done
|
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
|
|
|
|
|
|
|
|
|
|
|
// Check that the file was encrypted before being written to disk
|
|
|
|
$this->assertNotEquals($this->dataLong . $this->dataLong, $retreivedCryptedFile);
|
|
|
|
|
|
|
|
$decrypted = file_get_contents('crypt:///' . $this->userId . '/files/'. $filename);
|
|
|
|
|
|
|
|
$this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
|
|
|
|
|
|
|
|
// Teardown
|
|
|
|
$this->view->unlink($this->userId . '/files/' . $filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
* Test that data that is written by the crypto stream wrapper with AES 128
|
|
|
|
* @note Encrypted data is manually prepared and decrypted here to avoid dependency on success of stream_read
|
|
|
|
* @note If this test fails with truncate content, check that enough array slices are being rejoined to form $e, as the crypt.php file may have gotten longer and broken the manual
|
|
|
|
* reassembly of its data
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testStreamDecryptLongFileContentWithoutHeader() {
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
// Generate a a random filename
|
2014-11-06 18:53:35 +03:00
|
|
|
$filename = 'tmp-' . $this->getUniqueID() . '.test';
|
2014-07-22 19:22:15 +04:00
|
|
|
|
2014-12-17 13:12:37 +03:00
|
|
|
$this->config->setSystemValue('cipher', 'AES-128-CFB');
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
// Save long data as encrypted file using stream wrapper
|
|
|
|
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong . $this->dataLong);
|
|
|
|
|
2014-12-17 13:12:37 +03:00
|
|
|
$this->config->deleteSystemValue('cipher');
|
2014-07-22 19:22:15 +04:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
|
|
|
|
|
|
|
// Disable encryption proxy to prevent recursive calls
|
|
|
|
$proxyStatus = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
|
|
|
|
|
|
|
// Get file contents without using any wrapper to get it's actual contents on disk
|
|
|
|
$retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename);
|
|
|
|
|
|
|
|
// Check that the file was encrypted before being written to disk
|
|
|
|
$this->assertNotEquals($this->dataLong . $this->dataLong, $retreivedCryptedFile);
|
|
|
|
|
|
|
|
// remove the header to check if we can also decrypt old files without a header,
|
|
|
|
// this files should fall back to AES-128
|
2014-12-03 19:20:04 +03:00
|
|
|
$cryptedWithoutHeader = substr($retreivedCryptedFile, \OCA\Files_Encryption\Crypt::BLOCKSIZE);
|
2014-07-22 19:22:15 +04:00
|
|
|
$this->view->file_put_contents($this->userId . '/files/' . $filename, $cryptedWithoutHeader);
|
|
|
|
|
|
|
|
// Re-enable proxy - our work is done
|
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
|
|
|
|
|
|
|
$decrypted = file_get_contents('crypt:///' . $this->userId . '/files/'. $filename);
|
|
|
|
|
|
|
|
$this->assertEquals($this->dataLong . $this->dataLong, $decrypted);
|
|
|
|
|
|
|
|
// Teardown
|
|
|
|
$this->view->unlink($this->userId . '/files/' . $filename);
|
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testIsEncryptedContent() {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertFalse(\OCA\Files_Encryption\Crypt::isCatfileContent($this->dataUrl));
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertFalse(\OCA\Files_Encryption\Crypt::isCatfileContent($this->legacyEncryptedData));
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$keyfileContent = \OCA\Files_Encryption\Crypt::symmetricEncryptFileContent($this->dataUrl, 'hat', 'AES-128-CFB');
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$this->assertTrue(\OCA\Files_Encryption\Crypt::isCatfileContent($keyfileContent));
|
2013-05-20 03:24:36 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @large
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testMultiKeyEncrypt() {
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2012-07-18 21:52:00 +04:00
|
|
|
# TODO: search in keyfile for actual content as IV will ensure this test always passes
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$pair1 = \OCA\Files_Encryption\Crypt::createKeypair();
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals(2, count($pair1));
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(strlen($pair1['publicKey']) > 1);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(strlen($pair1['privateKey']) > 1);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$crypted = \OCA\Files_Encryption\Crypt::multiKeyEncrypt($this->dataShort, array($pair1['publicKey']));
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertNotEquals($this->dataShort, $crypted['data']);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
|
|
|
|
2014-12-03 19:20:04 +03:00
|
|
|
$decrypt = \OCA\Files_Encryption\Crypt::multiKeyDecrypt($crypted['data'], $crypted['keys'][0], $pair1['privateKey']);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-20 03:24:36 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testRenameFile() {
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
$filename = 'tmp-' . $this->getUniqueID();
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-07-30 16:18:01 +04:00
|
|
|
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-18 00:45:09 +04:00
|
|
|
// Get file decrypted contents
|
2013-07-30 16:18:01 +04:00
|
|
|
$decrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataLong, $decrypt);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
$newFilename = 'tmp-new-' . $this->getUniqueID();
|
2013-05-26 22:44:15 +04:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
|
|
|
$view->rename($filename, $newFilename);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Get file decrypted contents
|
2013-07-30 16:18:01 +04:00
|
|
|
$newDecrypt = file_get_contents('crypt:///'. $this->userId . '/files/' . $newFilename);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataLong, $newDecrypt);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// tear down
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->unlink($newFilename);
|
2013-05-20 03:24:36 +04:00
|
|
|
}
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testMoveFileIntoFolder() {
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
$filename = 'tmp-' . $this->getUniqueID();
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-07-30 16:18:01 +04:00
|
|
|
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Get file decrypted contents
|
2013-07-30 16:18:01 +04:00
|
|
|
$decrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataLong, $decrypt);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
$newFolder = '/newfolder' . $this->getUniqueID();
|
|
|
|
$newFilename = 'tmp-new-' . $this->getUniqueID();
|
2013-05-26 22:44:15 +04:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
|
|
|
$view->mkdir($newFolder);
|
|
|
|
$view->rename($filename, $newFolder . '/' . $newFilename);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// Get file decrypted contents
|
2013-07-30 16:18:01 +04:00
|
|
|
$newDecrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $newFolder . '/' . $newFilename);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataLong, $newDecrypt);
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-05-20 03:24:36 +04:00
|
|
|
// tear down
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->unlink($newFolder);
|
2013-05-20 03:24:36 +04:00
|
|
|
}
|
2013-05-15 04:38:08 +04:00
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testMoveFolder() {
|
2013-05-18 00:16:56 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
2013-05-18 00:16:56 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
$filename = '/tmp-' . $this->getUniqueID();
|
|
|
|
$folder = '/folder' . $this->getUniqueID();
|
2013-05-18 00:16:56 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->mkdir($folder);
|
2013-05-18 00:16:56 +04:00
|
|
|
|
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-07-30 16:18:01 +04:00
|
|
|
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $folder . $filename, $this->dataLong);
|
2013-05-18 00:16:56 +04:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-18 00:16:56 +04:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-07-30 16:18:01 +04:00
|
|
|
$decrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $folder . $filename);
|
2013-05-18 00:16:56 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataLong, $decrypt);
|
2013-05-18 00:16:56 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
$newFolder = '/newfolder/subfolder' . $this->getUniqueID();
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->mkdir('/newfolder');
|
2013-05-16 00:42:22 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->rename($folder, $newFolder);
|
2013-05-16 00:42:22 +04:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-07-30 16:18:01 +04:00
|
|
|
$newDecrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $newFolder . $filename);
|
2013-05-16 00:42:22 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataLong, $newDecrypt);
|
2013-05-16 00:42:22 +04:00
|
|
|
|
|
|
|
// tear down
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->unlink($newFolder);
|
|
|
|
$view->unlink('/newfolder');
|
2013-05-16 00:42:22 +04:00
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testChangePassphrase() {
|
|
|
|
$filename = 'tmp-' . $this->getUniqueID();
|
2013-05-15 23:00:35 +04:00
|
|
|
|
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-07-30 16:18:01 +04:00
|
|
|
$cryptedFile = file_put_contents('crypt:///' . $this->userId . '/files/' . $filename, $this->dataLong);
|
2013-05-15 23:00:35 +04:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 23:00:35 +04:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-07-30 16:18:01 +04:00
|
|
|
$decrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename);
|
2013-05-15 23:00:35 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataLong, $decrypt);
|
2013-05-15 23:00:35 +04:00
|
|
|
|
|
|
|
// change password
|
2013-05-26 22:44:15 +04:00
|
|
|
\OC_User::setPassword($this->userId, 'test', null);
|
2013-05-15 23:00:35 +04:00
|
|
|
|
|
|
|
// relogin
|
|
|
|
$params['uid'] = $this->userId;
|
|
|
|
$params['password'] = 'test';
|
2014-12-03 19:20:04 +03:00
|
|
|
\OCA\Files_Encryption\Hooks::login($params);
|
2013-05-15 23:00:35 +04:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-07-30 16:18:01 +04:00
|
|
|
$newDecrypt = file_get_contents('crypt:///' . $this->userId . '/files/' . $filename);
|
2013-05-15 23:00:35 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataLong, $newDecrypt);
|
2013-05-15 23:00:35 +04:00
|
|
|
|
|
|
|
// tear down
|
|
|
|
// change password back
|
2013-05-26 22:44:15 +04:00
|
|
|
\OC_User::setPassword($this->userId, $this->pass);
|
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
|
|
|
$view->unlink($filename);
|
2013-05-15 23:00:35 +04:00
|
|
|
}
|
2013-05-16 02:36:40 +04:00
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testViewFilePutAndGetContents() {
|
2013-05-16 02:36:40 +04:00
|
|
|
|
2014-11-06 18:53:35 +03:00
|
|
|
$filename = '/tmp-' . $this->getUniqueID();
|
2013-05-26 22:44:15 +04:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Save short data as encrypted file using stream wrapper
|
2013-05-26 22:44:15 +04:00
|
|
|
$cryptedFile = $view->file_put_contents($filename, $this->dataShort);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 22:44:15 +04:00
|
|
|
$decrypt = $view->file_get_contents($filename);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-05-26 22:44:15 +04:00
|
|
|
$cryptedFileLong = $view->file_put_contents($filename, $this->dataLong);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFileLong));
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 22:44:15 +04:00
|
|
|
$decryptLong = $view->file_get_contents($filename);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataLong, $decryptLong);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// tear down
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->unlink($filename);
|
2013-05-16 02:36:40 +04:00
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @large
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testTouchExistingFile() {
|
|
|
|
$filename = '/tmp-' . $this->getUniqueID();
|
2013-05-26 22:44:15 +04:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Save short data as encrypted file using stream wrapper
|
2013-05-26 22:44:15 +04:00
|
|
|
$cryptedFile = $view->file_put_contents($filename, $this->dataShort);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-16 02:36:40 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->touch($filename);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 22:44:15 +04:00
|
|
|
$decrypt = $view->file_get_contents($filename);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// tear down
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->unlink($filename);
|
2013-05-16 02:36:40 +04:00
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testTouchFile() {
|
|
|
|
$filename = '/tmp-' . $this->getUniqueID();
|
2013-05-26 22:44:15 +04:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
2013-05-16 02:44:40 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->touch($filename);
|
2013-05-16 02:44:40 +04:00
|
|
|
|
|
|
|
// Save short data as encrypted file using stream wrapper
|
2013-05-26 22:44:15 +04:00
|
|
|
$cryptedFile = $view->file_put_contents($filename, $this->dataShort);
|
2013-05-16 02:44:40 +04:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-16 02:44:40 +04:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 22:44:15 +04:00
|
|
|
$decrypt = $view->file_get_contents($filename);
|
2013-05-16 02:44:40 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-16 02:44:40 +04:00
|
|
|
|
|
|
|
// tear down
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->unlink($filename);
|
2013-05-16 02:44:40 +04:00
|
|
|
}
|
|
|
|
|
2013-06-10 11:31:22 +04:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2014-11-06 18:53:35 +03:00
|
|
|
public function testFopenFile() {
|
|
|
|
$filename = '/tmp-' . $this->getUniqueID();
|
2013-05-26 22:44:15 +04:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Save short data as encrypted file using stream wrapper
|
2013-05-26 22:44:15 +04:00
|
|
|
$cryptedFile = $view->file_put_contents($filename, $this->dataShort);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-16 02:36:40 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$handle = $view->fopen($filename, 'r');
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 22:44:15 +04:00
|
|
|
$decrypt = fgets($handle);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
2013-05-26 22:44:15 +04:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-16 02:36:40 +04:00
|
|
|
|
|
|
|
// tear down
|
2014-11-06 18:53:35 +03:00
|
|
|
fclose($handle);
|
2013-05-26 22:44:15 +04:00
|
|
|
$view->unlink($filename);
|
2013-05-16 02:36:40 +04:00
|
|
|
}
|
2013-11-21 02:27:42 +04:00
|
|
|
|
2012-04-17 22:56:53 +04:00
|
|
|
}
|