2012-04-17 18:56:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2012-07-24 16:53:12 +00:00
|
|
|
* Copyright (c) 2012 Sam Tuke <samtuke@owncloud.com>, and
|
|
|
|
* Robin Appelman <icewind@owncloud.com>
|
2012-04-17 18:56:53 +00:00
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
require_once realpath(dirname(__FILE__) . '/../3rdparty/Crypt_Blowfish/Blowfish.php');
|
|
|
|
require_once realpath(dirname(__FILE__) . '/../../../lib/base.php');
|
|
|
|
require_once realpath(dirname(__FILE__) . '/../lib/crypt.php');
|
|
|
|
require_once realpath(dirname(__FILE__) . '/../lib/keymanager.php');
|
|
|
|
require_once realpath(dirname(__FILE__) . '/../lib/proxy.php');
|
|
|
|
require_once realpath(dirname(__FILE__) . '/../lib/stream.php');
|
|
|
|
require_once realpath(dirname(__FILE__) . '/../lib/util.php');
|
|
|
|
require_once realpath(dirname(__FILE__) . '/../lib/helper.php');
|
|
|
|
require_once realpath(dirname(__FILE__) . '/../appinfo/app.php');
|
|
|
|
require_once realpath(dirname(__FILE__) . '/util.php');
|
2012-11-14 15:09:12 +00:00
|
|
|
|
|
|
|
use OCA\Encryption;
|
2012-08-15 13:52:03 +00:00
|
|
|
|
2013-05-19 20:28:48 +00:00
|
|
|
/**
|
|
|
|
* Class Test_Encryption_Crypt
|
|
|
|
*/
|
2013-05-26 18:44:15 +00:00
|
|
|
class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
|
|
|
const TEST_ENCRYPTION_CRYPT_USER1 = "test-crypt-user1";
|
2013-05-19 20:28:48 +00:00
|
|
|
|
|
|
|
public $userId;
|
|
|
|
public $pass;
|
|
|
|
public $stateFilesTrashbin;
|
|
|
|
public $dataLong;
|
|
|
|
public $dataUrl;
|
|
|
|
public $dataShort;
|
|
|
|
/**
|
|
|
|
* @var OC_FilesystemView
|
|
|
|
*/
|
|
|
|
public $view;
|
|
|
|
public $legacyEncryptedData;
|
|
|
|
public $genPrivateKey;
|
|
|
|
public $genPublicKey;
|
|
|
|
|
2013-05-26 01:22:16 +00:00
|
|
|
public static function setUpBeforeClass() {
|
2013-05-19 23:24:36 +00:00
|
|
|
// reset backend
|
|
|
|
\OC_User::clearBackends();
|
2013-05-26 18:44:15 +00:00
|
|
|
\OC_User::useBackend('database');
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-26 01:22:16 +00:00
|
|
|
// Filesystem related hooks
|
|
|
|
\OCA\Encryption\Helper::registerFilesystemHooks();
|
|
|
|
|
|
|
|
// Filesystem related hooks
|
|
|
|
\OCA\Encryption\Helper::registerUserHooks();
|
|
|
|
|
|
|
|
// clear and register hooks
|
|
|
|
\OC_FileProxy::clearProxies();
|
2013-05-26 18:44:15 +00:00
|
|
|
\OC_FileProxy::register(new OCA\Encryption\Proxy());
|
2013-05-26 01:22:16 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
// create test user
|
|
|
|
\Test_Encryption_Util::loginHelper(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1, true);
|
2013-05-26 01:22:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setUp() {
|
2013-05-26 18:44:15 +00:00
|
|
|
// set user id
|
|
|
|
\OC_User::setUserId(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1);
|
|
|
|
$this->userId = \Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1;
|
|
|
|
$this->pass = \Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1;
|
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// set content for encrypting / decrypting in tests
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->dataLong = file_get_contents(realpath(dirname(__FILE__) . '/../lib/crypt.php'));
|
2012-08-23 15:43:10 +00:00
|
|
|
$this->dataShort = 'hats';
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->dataUrl = realpath(dirname(__FILE__) . '/../lib/crypt.php');
|
|
|
|
$this->legacyData = realpath(dirname(__FILE__) . '/legacy-text.txt');
|
|
|
|
$this->legacyEncryptedData = realpath(dirname(__FILE__) . '/legacy-encrypted-text.txt');
|
|
|
|
$this->legacyEncryptedDataKey = realpath(dirname(__FILE__) . '/encryption.key');
|
2012-11-14 15:09:12 +00:00
|
|
|
$this->randomKey = Encryption\Crypt::generateKey();
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-11-28 18:39:19 +00:00
|
|
|
$keypair = Encryption\Crypt::createKeypair();
|
2013-05-19 23:24:36 +00:00
|
|
|
$this->genPublicKey = $keypair['publicKey'];
|
2012-11-28 18:39:19 +00:00
|
|
|
$this->genPrivateKey = $keypair['privateKey'];
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->view = new \OC_FilesystemView('/');
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-16 23:07:26 +00:00
|
|
|
// remember files_trashbin state
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->stateFilesTrashbin = OC_App::isEnabled('files_trashbin');
|
2013-05-16 23:07:26 +00:00
|
|
|
|
|
|
|
// we don't want to tests with app files_trashbin enabled
|
2013-05-26 18:44:15 +00:00
|
|
|
\OC_App::disable('files_trashbin');
|
2012-07-18 17:52:00 +00:00
|
|
|
}
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 01:22:16 +00:00
|
|
|
function tearDown() {
|
2013-05-16 23:07:26 +00:00
|
|
|
// reset app files_trashbin
|
2013-05-26 18:44:15 +00:00
|
|
|
if ($this->stateFilesTrashbin) {
|
|
|
|
OC_App::enable('files_trashbin');
|
2013-06-03 16:42:13 +00:00
|
|
|
} else {
|
2013-05-26 18:44:15 +00:00
|
|
|
OC_App::disable('files_trashbin');
|
2013-05-16 23:07:26 +00:00
|
|
|
}
|
2013-05-19 23:24:36 +00:00
|
|
|
}
|
|
|
|
|
2013-05-26 01:22:16 +00:00
|
|
|
public static function tearDownAfterClass() {
|
2013-05-26 18:44:15 +00:00
|
|
|
// cleanup test user
|
|
|
|
\OC_User::deleteUser(\Test_Encryption_Crypt::TEST_ENCRYPTION_CRYPT_USER1);
|
2013-05-26 01:22:16 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testGenerateKey() {
|
2012-07-18 17:52:00 +00:00
|
|
|
|
|
|
|
# TODO: use more accurate (larger) string length for test confirmation
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-11-14 15:09:12 +00:00
|
|
|
$key = Encryption\Crypt::generateKey();
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(strlen($key) > 16);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-07-18 17:52:00 +00:00
|
|
|
}
|
2013-05-19 20:28:48 +00:00
|
|
|
|
2013-06-03 15:34:43 +00:00
|
|
|
function testDecryptPrivateKey() {
|
|
|
|
|
|
|
|
// test successful decrypt
|
2013-06-03 15:43:06 +00:00
|
|
|
$crypted = Encryption\Crypt::symmetricEncryptFileContent($this->genPrivateKey, 'hat');
|
2013-06-03 15:34:43 +00:00
|
|
|
|
|
|
|
$decrypted = Encryption\Crypt::decryptPrivateKey($crypted, 'hat');
|
|
|
|
|
2013-06-03 15:43:06 +00:00
|
|
|
$this->assertEquals($this->genPrivateKey, $decrypted);
|
2013-06-03 15:34:43 +00:00
|
|
|
|
|
|
|
//test private key decrypt with wrong password
|
|
|
|
$wrongPasswd = Encryption\Crypt::decryptPrivateKey($crypted, 'hat2');
|
|
|
|
|
|
|
|
$this->assertEquals(false, $wrongPasswd);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-11 13:19:02 +00:00
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testSymmetricEncryptFileContent() {
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-07-18 17:52:00 +00:00
|
|
|
# TODO: search in keyfile for actual content as IV will ensure this test always passes
|
2012-08-16 18:18:18 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$crypted = Encryption\Crypt::symmetricEncryptFileContent($this->dataShort, 'hat');
|
2012-08-16 18:18:18 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertNotEquals($this->dataShort, $crypted);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = Encryption\Crypt::symmetricDecryptFileContent($crypted, 'hat');
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2012-08-16 18:18:18 +00:00
|
|
|
|
|
|
|
}
|
2013-05-19 20:28:48 +00:00
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testSymmetricStreamEncryptShortFileContent() {
|
2013-05-19 23:24:36 +00:00
|
|
|
|
|
|
|
$filename = 'tmp-' . time() . '.test';
|
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = file_put_contents('crypt://' . $filename, $this->dataShort);
|
2013-04-29 07:12:43 +00:00
|
|
|
|
2012-08-23 18:19:39 +00:00
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-04-29 07:12:43 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Disable encryption proxy to prevent recursive calls
|
|
|
|
$proxyStatus = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Get file contents without using any wrapper to get it's actual contents on disk
|
2013-05-26 18:44:15 +00:00
|
|
|
$retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Re-enable proxy - our work is done
|
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
2013-04-29 07:12:43 +00:00
|
|
|
|
2012-08-23 18:19:39 +00:00
|
|
|
// Check that the file was encrypted before being written to disk
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertNotEquals($this->dataShort, $retreivedCryptedFile);
|
2013-04-29 07:12:43 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Get the encrypted keyfile
|
2013-05-26 18:44:15 +00:00
|
|
|
$encKeyfile = Encryption\Keymanager::getFileKey($this->view, $this->userId, $filename);
|
2013-04-29 07:12:43 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Attempt to fetch the user's shareKey
|
2013-05-26 18:44:15 +00:00
|
|
|
$shareKey = Encryption\Keymanager::getShareKey($this->view, $this->userId, $filename);
|
2013-04-29 07:12:43 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// get session
|
2013-05-28 15:04:35 +00:00
|
|
|
$session = new \OCA\Encryption\Session($this->view);
|
2013-04-29 07:12:43 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// get private key
|
2013-05-26 18:44:15 +00:00
|
|
|
$privateKey = $session->getPrivateKey($this->userId);
|
2013-04-29 07:12:43 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Decrypt keyfile with shareKey
|
2013-05-26 18:44:15 +00:00
|
|
|
$plainKeyfile = Encryption\Crypt::multiKeyDecrypt($encKeyfile, $shareKey, $privateKey);
|
2013-04-29 07:12:43 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Manually decrypt
|
2013-05-26 18:44:15 +00:00
|
|
|
$manualDecrypt = Encryption\Crypt::symmetricDecryptFileContent($retreivedCryptedFile, $plainKeyfile);
|
2013-04-29 07:12:43 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
// Check that decrypted data matches
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataShort, $manualDecrypt);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Teardown
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->view->unlink($this->userId . '/files/' . $filename);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
Encryption\Keymanager::deleteFileKey($this->view, $this->userId, $filename);
|
2012-04-17 18:56:53 +00:00
|
|
|
}
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
/**
|
2013-06-10 07:31:22 +00:00
|
|
|
* @medium
|
2012-12-11 17:12:46 +00:00
|
|
|
* @brief Test that data that is written by the crypto stream wrapper
|
|
|
|
* @note Encrypted data is manually prepared and decrypted here to avoid dependency on success of stream_read
|
2013-05-19 23:24:36 +00: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 17:12:46 +00:00
|
|
|
* reassembly of its data
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testSymmetricStreamEncryptLongFileContent() {
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
// Generate a a random filename
|
2013-05-19 23:24:36 +00:00
|
|
|
$filename = 'tmp-' . time() . '.test';
|
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = file_put_contents('crypt://' . $filename, $this->dataLong . $this->dataLong);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-04-29 21:41:49 +00:00
|
|
|
// Disable encryption proxy to prevent recursive calls
|
2013-05-19 23:24:36 +00: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 18:44:15 +00:00
|
|
|
$retreivedCryptedFile = $this->view->file_get_contents($this->userId . '/files/' . $filename);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Re-enable proxy - our work is done
|
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
2013-04-29 21:41:49 +00:00
|
|
|
|
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Check that the file was encrypted before being written to disk
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertNotEquals($this->dataLong . $this->dataLong, $retreivedCryptedFile);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
// Manuallly split saved file into separate IVs and encrypted chunks
|
2013-05-26 18:44:15 +00:00
|
|
|
$r = preg_split('/(00iv00.{16,18})/', $retreivedCryptedFile, NULL, PREG_SPLIT_DELIM_CAPTURE);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
//print_r($r);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
// Join IVs and their respective data chunks
|
2013-08-08 11:35:01 +00:00
|
|
|
$e = array();
|
|
|
|
$i = 0;
|
|
|
|
while ($i < count($r)-1) {
|
|
|
|
$e[] = $r[$i] . $r[$i+1];
|
|
|
|
$i = $i + 2;
|
|
|
|
}
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
//print_r($e);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Get the encrypted keyfile
|
2013-05-26 18:44:15 +00:00
|
|
|
$encKeyfile = Encryption\Keymanager::getFileKey($this->view, $this->userId, $filename);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Attempt to fetch the user's shareKey
|
2013-05-26 18:44:15 +00:00
|
|
|
$shareKey = Encryption\Keymanager::getShareKey($this->view, $this->userId, $filename);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// get session
|
2013-05-28 15:04:35 +00:00
|
|
|
$session = new \OCA\Encryption\Session($this->view);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// get private key
|
2013-05-26 18:44:15 +00:00
|
|
|
$privateKey = $session->getPrivateKey($this->userId);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Decrypt keyfile with shareKey
|
2013-05-26 18:44:15 +00:00
|
|
|
$plainKeyfile = Encryption\Crypt::multiKeyDecrypt($encKeyfile, $shareKey, $privateKey);
|
2013-04-29 21:41:49 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
// Set var for reassembling decrypted content
|
|
|
|
$decrypt = '';
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
// Manually decrypt chunk
|
2013-05-26 18:44:15 +00:00
|
|
|
foreach ($e as $chunk) {
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$chunkDecrypt = Encryption\Crypt::symmetricDecryptFileContent($chunk, $plainKeyfile);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
// Assemble decrypted chunks
|
|
|
|
$decrypt .= $chunkDecrypt;
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
}
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong . $this->dataLong, $decrypt);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
// Teardown
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->view->unlink($this->userId . '/files/' . $filename);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
Encryption\Keymanager::deleteFileKey($this->view, $this->userId, $filename);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
}
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-10-16 14:02:51 +00:00
|
|
|
/**
|
2013-06-10 07:31:22 +00:00
|
|
|
* @medium
|
2012-10-16 14:02:51 +00:00
|
|
|
* @brief Test that data that is read by the crypto stream wrapper
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testSymmetricStreamDecryptShortFileContent() {
|
2013-05-19 23:24:36 +00:00
|
|
|
|
|
|
|
$filename = 'tmp-' . time();
|
|
|
|
|
2012-10-16 14:02:51 +00:00
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = file_put_contents('crypt://' . $filename, $this->dataShort);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-10-10 17:40:59 +00:00
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-17 20:45:09 +00:00
|
|
|
// Disable encryption proxy to prevent recursive calls
|
|
|
|
$proxyStatus = \OC_FileProxy::$enabled;
|
|
|
|
\OC_FileProxy::$enabled = false;
|
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(Encryption\Crypt::isEncryptedMeta($filename));
|
2013-05-17 20:45:09 +00:00
|
|
|
|
|
|
|
\OC_FileProxy::$enabled = $proxyStatus;
|
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = file_get_contents('crypt://' . $filename);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// tear down
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->view->unlink($this->userId . '/files/' . $filename);
|
2012-10-16 14:02:51 +00:00
|
|
|
}
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testSymmetricStreamDecryptLongFileContent() {
|
2013-05-19 23:24:36 +00:00
|
|
|
|
|
|
|
$filename = 'tmp-' . time();
|
|
|
|
|
2012-10-16 14:02:51 +00:00
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = file_put_contents('crypt://' . $filename, $this->dataLong);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-10-16 14:02:51 +00:00
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = file_get_contents('crypt://' . $filename);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $decrypt);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// tear down
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->view->unlink($this->userId . '/files/' . $filename);
|
2012-10-10 17:40:59 +00:00
|
|
|
}
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testIsEncryptedContent() {
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertFalse(Encryption\Crypt::isCatfileContent($this->dataUrl));
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertFalse(Encryption\Crypt::isCatfileContent($this->legacyEncryptedData));
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$keyfileContent = Encryption\Crypt::symmetricEncryptFileContent($this->dataUrl, 'hat');
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(Encryption\Crypt::isCatfileContent($keyfileContent));
|
2013-05-19 23:24:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @large
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testMultiKeyEncrypt() {
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-07-18 17:52:00 +00:00
|
|
|
# TODO: search in keyfile for actual content as IV will ensure this test always passes
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-11-14 15:09:12 +00:00
|
|
|
$pair1 = Encryption\Crypt::createKeypair();
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals(2, count($pair1));
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(strlen($pair1['publicKey']) > 1);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(strlen($pair1['privateKey']) > 1);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$crypted = Encryption\Crypt::multiKeyEncrypt($this->dataShort, array($pair1['publicKey']));
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertNotEquals($this->dataShort, $crypted['data']);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = Encryption\Crypt::multiKeyDecrypt($crypted['data'], $crypted['keys'][0], $pair1['privateKey']);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
/**
|
2013-06-10 07:31:22 +00:00
|
|
|
* @medium
|
2012-12-11 17:12:46 +00:00
|
|
|
* @brief test decryption using legacy blowfish method
|
|
|
|
*/
|
2013-08-08 11:35:01 +00:00
|
|
|
function testLegacyDecryptShort() {
|
|
|
|
|
|
|
|
$crypted = $this->legacyEncrypt($this->dataShort, $this->pass);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-27 10:21:39 +00:00
|
|
|
$decrypted = Encryption\Crypt::legacyBlockDecrypt($crypted, $this->pass);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataShort, $decrypted);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
}
|
2012-11-28 18:39:19 +00:00
|
|
|
|
2012-12-11 17:12:46 +00:00
|
|
|
/**
|
2013-06-10 07:31:22 +00:00
|
|
|
* @medium
|
2012-12-11 17:12:46 +00:00
|
|
|
* @brief test decryption using legacy blowfish method
|
|
|
|
*/
|
2013-08-08 11:35:01 +00:00
|
|
|
function testLegacyDecryptLong() {
|
|
|
|
|
|
|
|
$crypted = $this->legacyEncrypt($this->dataLong, $this->pass);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-27 10:21:39 +00:00
|
|
|
$decrypted = Encryption\Crypt::legacyBlockDecrypt($crypted, $this->pass);
|
2013-05-19 23:24:36 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $decrypted);
|
2012-11-28 18:39:19 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testRenameFile() {
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
$filename = 'tmp-' . time();
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = file_put_contents('crypt://' . $filename, $this->dataLong);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-17 20:45:09 +00:00
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = file_get_contents('crypt://' . $filename);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $decrypt);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
$newFilename = 'tmp-new-' . time();
|
2013-05-26 18:44:15 +00:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
|
|
|
$view->rename($filename, $newFilename);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$newDecrypt = file_get_contents('crypt://' . $newFilename);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $newDecrypt);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// tear down
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->unlink($newFilename);
|
2013-05-19 23:24:36 +00:00
|
|
|
}
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testMoveFileIntoFolder() {
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
$filename = 'tmp-' . time();
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = file_put_contents('crypt://' . $filename, $this->dataLong);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = file_get_contents('crypt://' . $filename);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $decrypt);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
$newFolder = '/newfolder' . time();
|
|
|
|
$newFilename = 'tmp-new-' . time();
|
2013-05-26 18:44:15 +00:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
|
|
|
$view->mkdir($newFolder);
|
|
|
|
$view->rename($filename, $newFolder . '/' . $newFilename);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$newDecrypt = file_get_contents('crypt://' . $newFolder . '/' . $newFilename);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $newDecrypt);
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
// tear down
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->unlink($newFolder);
|
2013-05-19 23:24:36 +00:00
|
|
|
}
|
2013-05-15 00:38:08 +00:00
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testMoveFolder() {
|
2013-05-17 20:16:56 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
2013-05-17 20:16:56 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
$filename = '/tmp-' . time();
|
|
|
|
$folder = '/folder' . time();
|
2013-05-17 20:16:56 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->mkdir($folder);
|
2013-05-17 20:16:56 +00:00
|
|
|
|
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = file_put_contents('crypt://' . $folder . $filename, $this->dataLong);
|
2013-05-17 20:16:56 +00:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-17 20:16:56 +00:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = file_get_contents('crypt://' . $folder . $filename);
|
2013-05-17 20:16:56 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $decrypt);
|
2013-05-17 20:16:56 +00:00
|
|
|
|
2013-05-20 21:44:10 +00:00
|
|
|
$newFolder = '/newfolder/subfolder' . time();
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->mkdir('/newfolder');
|
2013-05-15 20:42:22 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->rename($folder, $newFolder);
|
2013-05-15 20:42:22 +00:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$newDecrypt = file_get_contents('crypt://' . $newFolder . $filename);
|
2013-05-15 20:42:22 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $newDecrypt);
|
2013-05-15 20:42:22 +00:00
|
|
|
|
|
|
|
// tear down
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->unlink($newFolder);
|
|
|
|
$view->unlink('/newfolder');
|
2013-05-15 20:42:22 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testChangePassphrase() {
|
|
|
|
$filename = 'tmp-' . time();
|
2013-05-15 19:00:35 +00:00
|
|
|
|
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = file_put_contents('crypt://' . $filename, $this->dataLong);
|
2013-05-15 19:00:35 +00:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 19:00:35 +00:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = file_get_contents('crypt://' . $filename);
|
2013-05-15 19:00:35 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $decrypt);
|
2013-05-15 19:00:35 +00:00
|
|
|
|
|
|
|
// change password
|
2013-05-26 18:44:15 +00:00
|
|
|
\OC_User::setPassword($this->userId, 'test', null);
|
2013-05-15 19:00:35 +00:00
|
|
|
|
|
|
|
// relogin
|
|
|
|
$params['uid'] = $this->userId;
|
|
|
|
$params['password'] = 'test';
|
2013-05-26 18:44:15 +00:00
|
|
|
OCA\Encryption\Hooks::login($params);
|
2013-05-15 19:00:35 +00:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$newDecrypt = file_get_contents('crypt://' . $filename);
|
2013-05-15 19:00:35 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $newDecrypt);
|
2013-05-15 19:00:35 +00:00
|
|
|
|
|
|
|
// tear down
|
|
|
|
// change password back
|
2013-05-26 18:44:15 +00:00
|
|
|
\OC_User::setPassword($this->userId, $this->pass);
|
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
|
|
|
$view->unlink($filename);
|
2013-05-15 19:00:35 +00:00
|
|
|
}
|
2013-05-15 22:36:40 +00:00
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testViewFilePutAndGetContents() {
|
2013-05-15 22:36:40 +00:00
|
|
|
|
2013-05-19 23:24:36 +00:00
|
|
|
$filename = '/tmp-' . time();
|
2013-05-26 18:44:15 +00:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Save short data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = $view->file_put_contents($filename, $this->dataShort);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = $view->file_get_contents($filename);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Save long data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFileLong = $view->file_put_contents($filename, $this->dataLong);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFileLong));
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decryptLong = $view->file_get_contents($filename);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataLong, $decryptLong);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// tear down
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->unlink($filename);
|
2013-05-15 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @large
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testTouchExistingFile() {
|
2013-05-19 23:24:36 +00:00
|
|
|
$filename = '/tmp-' . time();
|
2013-05-26 18:44:15 +00:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Save short data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = $view->file_put_contents($filename, $this->dataShort);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 22:36:40 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->touch($filename);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = $view->file_get_contents($filename);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// tear down
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->unlink($filename);
|
2013-05-15 22:36:40 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testTouchFile() {
|
2013-05-19 23:24:36 +00:00
|
|
|
$filename = '/tmp-' . time();
|
2013-05-26 18:44:15 +00:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
2013-05-15 22:44:40 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->touch($filename);
|
2013-05-15 22:44:40 +00:00
|
|
|
|
|
|
|
// Save short data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = $view->file_put_contents($filename, $this->dataShort);
|
2013-05-15 22:44:40 +00:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 22:44:40 +00:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = $view->file_get_contents($filename);
|
2013-05-15 22:44:40 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-15 22:44:40 +00:00
|
|
|
|
|
|
|
// tear down
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->unlink($filename);
|
2013-05-15 22:44:40 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 07:31:22 +00:00
|
|
|
/**
|
|
|
|
* @medium
|
|
|
|
*/
|
2013-05-26 01:22:16 +00:00
|
|
|
function testFopenFile() {
|
2013-05-19 23:24:36 +00:00
|
|
|
$filename = '/tmp-' . time();
|
2013-05-26 18:44:15 +00:00
|
|
|
$view = new \OC\Files\View('/' . $this->userId . '/files');
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Save short data as encrypted file using stream wrapper
|
2013-05-26 18:44:15 +00:00
|
|
|
$cryptedFile = $view->file_put_contents($filename, $this->dataShort);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Test that data was successfully written
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertTrue(is_int($cryptedFile));
|
2013-05-15 22:36:40 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$handle = $view->fopen($filename, 'r');
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// Get file decrypted contents
|
2013-05-26 18:44:15 +00:00
|
|
|
$decrypt = fgets($handle);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
2013-05-26 18:44:15 +00:00
|
|
|
$this->assertEquals($this->dataShort, $decrypt);
|
2013-05-15 22:36:40 +00:00
|
|
|
|
|
|
|
// tear down
|
2013-05-26 18:44:15 +00:00
|
|
|
$view->unlink($filename);
|
2013-05-15 22:36:40 +00:00
|
|
|
}
|
2013-08-08 11:35:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief ncryption using legacy blowfish method
|
|
|
|
* @param data data to encrypt
|
|
|
|
* @param passwd password
|
|
|
|
*/
|
|
|
|
function legacyEncrypt($data, $passwd) {
|
|
|
|
|
|
|
|
$bf = new \Crypt_Blowfish($passwd);
|
|
|
|
$crypted = $bf->encrypt($data);
|
|
|
|
|
|
|
|
return $crypted;
|
|
|
|
}
|
|
|
|
|
2012-04-17 18:56:53 +00:00
|
|
|
}
|