Added unit tests for legacy encryption methods
Improvements to documentation
This commit is contained in:
parent
637891b771
commit
5328aae8a8
|
@ -452,8 +452,8 @@ class Crypt {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Encrypts content symmetrically and generated keyfile asymmetrically
|
||||
* @returns array keys: data, key
|
||||
* @brief Encrypts content symmetrically and generates keyfile asymmetrically
|
||||
* @returns array keys: encrypted, key
|
||||
* @note this method is a wrapper for combining other crypt class methods
|
||||
*/
|
||||
public static function keyEncryptKeyfile( $plainContent, $publicKey ) {
|
||||
|
@ -469,7 +469,8 @@ class Crypt {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Encrypts content symmetrically and generated keyfile asymmetrically
|
||||
* @brief Takes encrypted data, encrypted catfile, and private key, and
|
||||
* performs decryption
|
||||
* @returns decrypted content
|
||||
* @note this method is a wrapper for combining other crypt class methods
|
||||
*/
|
||||
|
|
|
@ -341,10 +341,22 @@ class Util {
|
|||
|
||||
$bf = $this->getBlowfish( $passphrase );
|
||||
|
||||
$data = $bf->decrypt( $content );
|
||||
$decrypted = $bf->decrypt( $content );
|
||||
|
||||
return $data;
|
||||
$trimmed = rtrim( $decrypted, "\0" );
|
||||
|
||||
return $trimmed;
|
||||
|
||||
}
|
||||
|
||||
public function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKey, $newPassphrase ) {
|
||||
|
||||
$decrypted = $this->legacyDecrypt( $legacyEncryptedContent, $legacyPassphrase );
|
||||
|
||||
$recrypted = Crypt::keyEncryptKeyfile( $decrypted, $publicKey );
|
||||
|
||||
return $recrypted;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -354,7 +366,7 @@ class Util {
|
|||
*
|
||||
* This function decrypts an content
|
||||
*/
|
||||
public function legacyRecrypt( $legacyContent ) {
|
||||
public function legacyRecrypt( $legacyContent, $legacyPassphrase, $newPassphrase ) {
|
||||
|
||||
# TODO: write me
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
require_once "PHPUnit/Framework/TestCase.php";
|
||||
require_once realpath( dirname(__FILE__).'/../../../lib/base.php' );
|
||||
require_once realpath( dirname(__FILE__).'/../../../3rdparty/Crypt_Blowfish/Blowfish.php' );
|
||||
require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery.php' );
|
||||
require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Container.php' );
|
||||
require_once realpath( dirname(__FILE__).'/../../../3rdparty/mockery/Mockery/Generator.php' );
|
||||
|
@ -29,12 +30,20 @@ class Test_Util extends \PHPUnit_Framework_TestCase {
|
|||
function setUp() {
|
||||
|
||||
// set content for encrypting / decrypting in tests
|
||||
$this->data = realpath( dirname(__FILE__).'/../lib/crypt.php' );
|
||||
$this->dataUrl = realpath( dirname(__FILE__).'/../lib/crypt.php' );
|
||||
$this->dataShort = 'hats';
|
||||
$this->dataLong = file_get_contents( realpath( dirname(__FILE__).'/../lib/crypt.php' ) );
|
||||
$this->legacyData = realpath( dirname(__FILE__).'/legacy-text.txt' );
|
||||
$this->legacyEncryptedData = realpath( dirname(__FILE__).'/legacy-encrypted-text.txt' );
|
||||
|
||||
$this->userId = 'admin';
|
||||
$this->pass = 'admin';
|
||||
|
||||
$keypair = Encryption\Crypt::createKeypair();
|
||||
|
||||
$this->genPublicKey = $keypair['publicKey'];
|
||||
$this->genPrivateKey = $keypair['privateKey'];
|
||||
|
||||
$this->publicKeyDir = '/' . 'public-keys';
|
||||
$this->encryptionDir = '/' . $this->userId . '/' . 'files_encryption';
|
||||
$this->keyfilesPath = $this->encryptionDir . '/' . 'keyfiles';
|
||||
|
@ -42,6 +51,9 @@ class Test_Util extends \PHPUnit_Framework_TestCase {
|
|||
$this->privateKeyPath = $this->encryptionDir . '/' . $this->userId . '.private.key'; // e.g. data/admin/admin.private.key
|
||||
|
||||
$this->view = new OC_FilesystemView( '/admin' );
|
||||
|
||||
$this->mockView = m::mock('OC_FilesystemView');
|
||||
$this->util = new Encryption\Util( $this->mockView, $this->userId );
|
||||
|
||||
}
|
||||
|
||||
|
@ -137,6 +149,91 @@ class Test_Util extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief test encryption using legacy blowfish method
|
||||
*/
|
||||
function testLegacyEncryptShort() {
|
||||
|
||||
$crypted = $this->util->legacyEncrypt( $this->dataShort, $this->pass );
|
||||
|
||||
$this->assertNotEquals( $this->dataShort, $crypted );
|
||||
|
||||
# TODO: search inencrypted text for actual content to ensure it
|
||||
# genuine transformation
|
||||
|
||||
return $crypted;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief test decryption using legacy blowfish method
|
||||
* @depends testLegacyEncryptShort
|
||||
*/
|
||||
function testLegacyDecryptShort( $crypted ) {
|
||||
|
||||
$decrypted = $this->util->legacyDecrypt( $crypted, $this->pass );
|
||||
|
||||
$this->assertEquals( $this->dataShort, $decrypted );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief test encryption using legacy blowfish method
|
||||
*/
|
||||
function testLegacyEncryptLong() {
|
||||
|
||||
$crypted = $this->util->legacyEncrypt( $this->dataLong, $this->pass );
|
||||
|
||||
$this->assertNotEquals( $this->dataLong, $crypted );
|
||||
|
||||
# TODO: search inencrypted text for actual content to ensure it
|
||||
# genuine transformation
|
||||
|
||||
return $crypted;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief test decryption using legacy blowfish method
|
||||
* @depends testLegacyEncryptLong
|
||||
*/
|
||||
function testLegacyDecryptLong( $crypted ) {
|
||||
|
||||
$decrypted = $this->util->legacyDecrypt( $crypted, $this->pass );
|
||||
|
||||
$this->assertEquals( $this->dataLong, $decrypted );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief test decryption using legacy blowfish method
|
||||
* @depends testLegacyEncryptLong
|
||||
*/
|
||||
function testLegacyKeyRecryptKeyfileEncrypt( $crypted ) {
|
||||
|
||||
$recrypted = $this->util->LegacyKeyRecryptKeyfile( $crypted, $this->pass, $this->genPublicKey, $this->pass );
|
||||
|
||||
$this->assertNotEquals( $this->dataLong, $recrypted['data'] );
|
||||
|
||||
return $recrypted;
|
||||
|
||||
# TODO: search inencrypted text for actual content to ensure it
|
||||
# genuine transformation
|
||||
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @brief test decryption using legacy blowfish method
|
||||
// * @depends testLegacyEncryptLong
|
||||
// */
|
||||
// function testLegacyKeyRecryptKeyfileDecrypt( $recrypted ) {
|
||||
//
|
||||
// $decrypted = Encryption\Crypt::keyDecryptKeyfile( $recrypted['data'], $recrypted['key'], $this->genPrivateKey );
|
||||
//
|
||||
// $this->assertEquals( $this->dataLong, $decrypted );
|
||||
//
|
||||
// }
|
||||
|
||||
// // Cannot use this test for now due to hidden dependencies in OC_FileCache
|
||||
// function testIsLegacyEncryptedContent() {
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue