|
<?php
|
|
/***************************************************************
|
|
* Copyright notice
|
|
*
|
|
* (c) Marcus Krause (marcus#exp2009@t3sec.info)
|
|
* All rights reserved
|
|
*
|
|
* This script is part of the TYPO3 project. The TYPO3 project is
|
|
* free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* The GNU General Public License can be found at
|
|
* http://www.gnu.org/copyleft/gpl.html.
|
|
* A copy is found in the textfile GPL.txt and important notices to the license
|
|
* from the author is found in LICENSE.txt distributed with these scripts.
|
|
*
|
|
*
|
|
* This script 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 General Public License for more details.
|
|
*
|
|
* This copyright notice MUST APPEAR in all copies of the script!
|
|
***************************************************************/
|
|
/**
|
|
* General helper methods library.
|
|
*
|
|
* $Id: class.tx_nawreferertracking_refobject_testcase.php 164 2009-03-08 01:06:27Z mkrause $
|
|
*
|
|
* @author Marcus Krause <marcus#exp2009@t3sec.info>
|
|
*/
|
|
|
|
|
|
require_once PATH_t3lib . 'security/class.t3lib_symencryption.php';
|
|
|
|
|
|
/**
|
|
* Class implementing unit test(s) for extension t3sec_saltedpw, in detail
|
|
* covering implementation of the Portable PHP password hashing framework.
|
|
*
|
|
* Intended to be used with unit test extension phpunit.
|
|
*
|
|
* @author Marcus Krause <marcus#exp2009@t3sec.info>
|
|
*
|
|
* @since 2009-03-03
|
|
* @package TYPO3
|
|
* @subpackage t3lib
|
|
*/
|
|
final class t3lib_symencryption_testcase extends tx_phpunit_testcase {
|
|
|
|
/**
|
|
* Keeps absolute path to this extension.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $extPath = '';
|
|
|
|
/**
|
|
* Keeps key of this extension.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $extKey = 't3sec_testseclibrary';
|
|
|
|
/**
|
|
* Keeps instance of t3lib_encryption.
|
|
*
|
|
* @var t3lib_encryption
|
|
*/
|
|
protected $fixture;
|
|
|
|
/**
|
|
* Keeps default secret key to be used.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $secretKey;
|
|
|
|
/**
|
|
* Keeps default secret message to be encrypted.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $secretMsg;
|
|
|
|
|
|
/**
|
|
* Class constructor.
|
|
*/
|
|
public function __construct () {
|
|
$this->secretKey = 'secret key';
|
|
$this->secretMsg = 'secret message';
|
|
}
|
|
|
|
/**
|
|
* Sets up the fixture.
|
|
*/
|
|
public function setUp () {
|
|
$this->fixture = t3lib_div::makeInstance('t3lib_symencryption');
|
|
}
|
|
|
|
/**
|
|
* Tests if fixture is instance of correct object.
|
|
*
|
|
* @test
|
|
*/
|
|
public function fixture () {
|
|
$failureMsg = 'This test will fail for an existing t3lib_encryption XCLASS.'
|
|
. 'If there no XCLASS, it\'s a serious failure. Is MCRYPT library available? '
|
|
. 'Are default cipher and mode usable? Please report back!';
|
|
//$this->assertType('t3lib_symencryption', $this->fixture, $failureMsg);
|
|
}
|
|
|
|
/**
|
|
* Tests if all default settings are usable.
|
|
*
|
|
* @test
|
|
*/
|
|
public function defaultSettings () {
|
|
$this->assertNotNull($this->fixture->getCurrentCipher());
|
|
$this->assertNotNull($this->fixture->getCurrentMode());
|
|
$this->assertEquals($this->fixture->getDefaultCipher(), $this->fixture->getCurrentCipher());
|
|
$this->assertEquals($this->fixture->getDefaultMode(), $this->fixture->getCurrentMode());
|
|
}
|
|
|
|
/**
|
|
* Tests default encryption.
|
|
*
|
|
* @test
|
|
*/
|
|
public function defaultEncryption() {
|
|
$encMsg = $this->fixture->encrypt($this->secretKey, $this->secretMsg);
|
|
$this->assertNotNull($encMsg);
|
|
$iv = $this->fixture->setIV($this->fixture->getCurrentIV());
|
|
$decMsg = $this->fixture->decrypt($this->secretKey, $encMsg);
|
|
//print_r($decMsg);
|
|
$this->assertEquals($this->secretMsg, $decMsg);
|
|
}
|
|
|
|
/**
|
|
* Tests if all as supported reported ciphers are actually usable.
|
|
*
|
|
* @test
|
|
*/
|
|
public function validSupportedCiphers () {
|
|
foreach ($this->fixture->getSupportedCiphers() as $cipher) {
|
|
$this->assertTrue($this->fixture->setCipher( $cipher ));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Tests if the default cipher is actually usable.
|
|
*
|
|
* @test
|
|
*/
|
|
public function defaultCipher () {
|
|
$this->assertTrue($this->fixture->setCipher( $this->fixture->getDefaultCipher() ), 'Default cipher not usable on your machine. Please report back!');
|
|
}
|
|
|
|
/**
|
|
* Tests if a blacklisted cipher is recognized as not usable.
|
|
*
|
|
* @test
|
|
*/
|
|
public function blacklistedCipher () {
|
|
$this->assertFalse($this->fixture->setCipher( MCRYPT_RIJNDAEL_128 ));
|
|
}
|
|
|
|
/**
|
|
* Tests if an invalid cipher is recognized as not usable.
|
|
*
|
|
* @test
|
|
*/
|
|
public function invalidCipher () {
|
|
$this->assertFalse($this->fixture->setCipher( 'INVALID_CIPHER' ));
|
|
}
|
|
|
|
/**
|
|
* Tests if all as supported reported ciphers are actually usable.
|
|
*
|
|
* @test
|
|
*/
|
|
public function validSupportedModes () {
|
|
foreach ($this->fixture->getSupportedModes() as $mode) {
|
|
$this->assertTrue($this->fixture->setMode( $mode ));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Tests if the default mode is actually usable.
|
|
*
|
|
* @test
|
|
*/
|
|
public function defaultMode () {
|
|
$this->fixture->setCipher( $this->fixture->getDefaultCipher() );
|
|
$this->assertTrue($this->fixture->setMode( $this->fixture->getDefaultMode() ), 'Default mode for default cipher not usable on your machine. Please report back!');
|
|
}
|
|
|
|
/**
|
|
* Tests if a blacklisted mode is recognized as not usable.
|
|
*
|
|
* @test
|
|
*/
|
|
public function blacklistedMode () {
|
|
$this->assertFalse($this->fixture->setMode( MCRYPT_MODE_OFB ));
|
|
}
|
|
|
|
/**
|
|
* Tests if an invalid mode is recognized as not usable.
|
|
*
|
|
* @test
|
|
*/
|
|
public function invalidMode () {
|
|
$this->assertFalse($this->fixture->setMode( 'INVALID_CIPHER' ));
|
|
}
|
|
|
|
/**
|
|
* Tears down fixture.
|
|
*/
|
|
public function tearDown() {
|
|
unset($this->fixture);
|
|
}
|
|
}
|
|
?>
|