Development snapshot:

- Added methods for sealing data with multiple keys
- Added method for encrypting data, generating iv and keyfile, and returning both
- Added 6 unit test cases (containing 12 tests) for Crypt class
- Commented out old unit tests for now
This commit is contained in:
Sam Tuke 2012-07-18 18:52:00 +01:00
parent 283561823f
commit d294e77721
6 changed files with 461 additions and 264 deletions

View file

@ -51,7 +51,7 @@ class Crypt {
}
/**
* @brief Symmetrically encrypt a file
* @brief Symmetrically encrypt a string
* @returns encrypted file
*/
public static function encrypt( $plainContent, $iv, $passphrase = '' ) {
@ -62,7 +62,7 @@ class Crypt {
} else {
\OC_Log::write( 'Encrypted storage', 'Encryption (symmetric) of content failed' , \OC_Log::ERROR );
\OC_Log::write( 'Encryption library', 'Encryption (symmetric) of content failed' , \OC_Log::ERROR );
return false;
@ -71,7 +71,7 @@ class Crypt {
}
/**
* @brief Symmetrically decrypt a file
* @brief Symmetrically decrypt a string
* @returns decrypted file
*/
public static function decrypt( $encryptedContent, $iv, $passphrase ) {
@ -83,7 +83,7 @@ class Crypt {
} else {
\OC_Log::write( 'Encrypted storage', 'Decryption (symmetric) of content failed' , \OC_Log::ERROR );
\OC_Log::write( 'Encryption library', 'Decryption (symmetric) of content failed' , \OC_Log::ERROR );
return false;
@ -92,7 +92,7 @@ class Crypt {
}
/**
* @brief Creates symmetric keyfile content
* @brief Symmetrically encrypts a string and returns keyfile content
* @param $plainContent content to be encrypted in keyfile
* @returns encrypted content combined with IV
* @note IV need not be specified, as it will be stored in the returned keyfile
@ -118,7 +118,7 @@ class Crypt {
} else {
\OC_Log::write( 'Encrypted storage', 'Encryption (symmetric) of keyfile content failed' , \OC_Log::ERROR );
\OC_Log::write( 'Encryption library', 'Encryption (symmetric) of keyfile content failed' , \OC_Log::ERROR );
return false;
@ -128,7 +128,7 @@ class Crypt {
/**
* @brief Decrypts keyfile content
* @brief Symmetrically decrypts keyfile content
* @param string $source
* @param string $target
* @param string $key the decryption key
@ -153,7 +153,91 @@ class Crypt {
} else {
\OC_Log::write( 'Encrypted storage', 'Decryption (symmetric) of keyfile content failed' , \OC_Log::ERROR );
\OC_Log::write( 'Encryption library', 'Decryption (symmetric) of keyfile content failed' , \OC_Log::ERROR );
return false;
}
}
/**
* @brief Creates symmetric keyfile content using a generated key
* @param string $plainContent content to be encrypted
* @returns array keys: key, encrypted
* @note symmetricDecryptFileContent() can be used to decrypt files created using this method
*
* This function decrypts a file
*/
public static function symmetricEncryptFileContentKeyfile( $plainContent ) {
$key = self::generateKey();
if( $encryptedContent = self::symmetricEncryptFileContent( $plainContent, $key ) ) {
return array(
'key' => $key
, 'encrypted' => $encryptedContent
);
} else {
return false;
}
}
/**
* @brief Create asymmetrically encrypted keyfile content using a generated key
* @param string $plainContent content to be encrypted
* @returns array keys: key, encrypted
* @note symmetricDecryptFileContent() can be used to decrypt files created using this method
*
* This function decrypts a file
*/
public static function multiKeyEncrypt( $plainContent, array $publicKeys ) {
$envKeys = array();
if( openssl_seal( $plainContent, $sealed, $envKeys, $publicKeys ) ) {
return array(
'keys' => $envKeys
, 'encrypted' => $sealed
);
} else {
return false;
}
}
/**
* @brief Asymmetrically encrypt a file using multiple public keys
* @param string $plainContent content to be encrypted
* @returns array keys: key, encrypted
* @note symmetricDecryptFileContent() can be used to decrypt files created using this method
*
* This function decrypts a file
*/
public static function multiKeyDecrypt( $encryptedContent, $envKey, $privateKey ) {
if ( !$encryptedContent ) {
return false;
}
if ( openssl_open( $encryptedContent, $plainContent, $envKey, $privateKey ) ) {
return $plainContent;
} else {
\OC_Log::write( 'Encryption library', 'Decryption (asymmetric) of sealed content failed' , \OC_Log::ERROR );
return false;
@ -162,7 +246,7 @@ class Crypt {
}
/**
* @brief Asymetrically encrypt a file using a public key
* @brief Asymetrically encrypt a string using a public key
* @returns encrypted file
*/
public static function keyEncrypt( $plainContent, $publicKey ) {
@ -186,14 +270,30 @@ class Crypt {
}
/**
* @brief Generate a random key for symmetric encryption
* @brief Generate a pseudo random 1024kb ASCII key
* @returns $key Generated key
*/
public static function generateKey() {
$key = mt_rand( 10000, 99999 ) . mt_rand( 10000, 99999 ) . mt_rand( 10000, 99999 ) . mt_rand( 10000, 99999 );
// $key = mt_rand( 10000, 99999 ) . mt_rand( 10000, 99999 ) . mt_rand( 10000, 99999 ) . mt_rand( 10000, 99999 );
return $key;
// Generate key
if ( $key = base64_encode( openssl_random_pseudo_bytes( 768000, $strong ) ) ) {
if ( !$strong ) {
// If OpenSSL indicates randomness is insecure, log error
\OC_Log::write( 'Encryption library', 'Insecure symmetric key was generated using openssl_random_pseudo_bytes()' , \OC_Log::WARN );
}
return $key;
} else {
return false;
}
}

View file

@ -22,13 +22,6 @@
*/
class OC_FileProxy_Encryption extends OC_FileProxy {
}
/**
* transparent encryption
*/

View file

@ -114,7 +114,7 @@ class Util {
# TODO: Use proper IV in encryption
// Encrypt private key with user pwd as passphrase
$encryptedPrivateKey = Crypt::createSymmetricKeyfile( $keypair['privateKey'], $passphrase );
$encryptedPrivateKey = Crypt::symmetricEncryptFileContent( $keypair['privateKey'], $passphrase );
// $iv = openssl_random_pseudo_bytes(16);
$this->view->file_put_contents( '/'. 'keypair'. '/' . $privateKeyFileName, $encryptedPrivateKey );

View file

@ -6,67 +6,171 @@
* See the COPYING-README file.
*/
require realpath( dirname(__FILE__).'/../lib/crypt.php' );
class Test_Encryption extends UnitTestCase {
function testEncryption(){
$key=uniqid();
$file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
$source=file_get_contents($file); //nice large text file
$encrypted=OC_Crypt::encrypt($source,$key);
$decrypted=OC_Crypt::decrypt($encrypted,$key);
$decrypted=rtrim($decrypted, "\0");
$this->assertNotEqual($encrypted,$source);
$this->assertEqual($decrypted,$source);
$chunk=substr($source,0,8192);
$encrypted=OC_Crypt::encrypt($chunk,$key);
$this->assertEqual(strlen($chunk),strlen($encrypted));
$decrypted=OC_Crypt::decrypt($encrypted,$key);
$decrypted=rtrim($decrypted, "\0");
$this->assertEqual($decrypted,$chunk);
function setUp() {
$encrypted=OC_Crypt::blockEncrypt($source,$key);
$decrypted=OC_Crypt::blockDecrypt($encrypted,$key);
$this->assertNotEqual($encrypted,$source);
$this->assertEqual($decrypted,$source);
$tmpFileEncrypted=OCP\Files::tmpFile();
OC_Crypt::encryptfile($file,$tmpFileEncrypted,$key);
$encrypted=file_get_contents($tmpFileEncrypted);
$decrypted=OC_Crypt::blockDecrypt($encrypted,$key);
$this->assertNotEqual($encrypted,$source);
$this->assertEqual($decrypted,$source);
$tmpFileDecrypted=OCP\Files::tmpFile();
OC_Crypt::decryptfile($tmpFileEncrypted,$tmpFileDecrypted,$key);
$decrypted=file_get_contents($tmpFileDecrypted);
$this->assertEqual($decrypted,$source);
$file=OC::$SERVERROOT.'/core/img/weather-clear.png';
$source=file_get_contents($file); //binary file
$encrypted=OC_Crypt::encrypt($source,$key);
$decrypted=OC_Crypt::decrypt($encrypted,$key);
$decrypted=rtrim($decrypted, "\0");
$this->assertEqual($decrypted,$source);
$encrypted=OC_Crypt::blockEncrypt($source,$key);
$decrypted=OC_Crypt::blockDecrypt($encrypted,$key);
$this->assertEqual($decrypted,$source);
}
function testBinary(){
$key=uniqid();
// set content for encrypting / decrypting in tests
$this->data = realpath( dirname(__FILE__).'/../lib/crypt.php' );
$file=__DIR__.'/binary';
$source=file_get_contents($file); //binary file
$encrypted=OC_Crypt::encrypt($source,$key);
$decrypted=OC_Crypt::decrypt($encrypted,$key);
$decrypted=rtrim($decrypted, "\0");
$this->assertEqual($decrypted,$source);
$encrypted=OC_Crypt::blockEncrypt($source,$key);
$decrypted=OC_Crypt::blockDecrypt($encrypted,$key,strlen($source));
$this->assertEqual($decrypted,$source);
}
function tearDown(){}
function testGenerateKey() {
# TODO: use more accurate (larger) string length for test confirmation
$key = OCA_Encryption\Crypt::generateKey();
$this->assertTrue( strlen( $key ) > 1000 );
}
function testEncrypt() {
$random = openssl_random_pseudo_bytes( 13 );
$iv = substr( base64_encode( $random ), 0, -4 ); // i.e. E5IG033j+mRNKrht
$crypted = OCA_Encryption\Crypt::encrypt( $this->data, $iv, 'hat' );
$this->assertNotEqual( $this->data, $crypted );
}
function testDecrypt() {
$random = openssl_random_pseudo_bytes( 13 );
$iv = substr( base64_encode( $random ), 0, -4 ); // i.e. E5IG033j+mRNKrht
$crypted = OCA_Encryption\Crypt::encrypt( $this->data, $iv, 'hat' );
$decrypt = OCA_Encryption\Crypt::decrypt( $crypted, $iv, 'hat' );
$this->assertEqual( $this->data, $decrypt );
}
function testSymmetricEncryptFileContent() {
# TODO: search in keyfile for actual content as IV will ensure this test always passes
$keyfileContent = OCA_Encryption\Crypt::symmetricEncryptFileContent( $this->data, 'hat' );
$this->assertNotEqual( $this->data, $keyfileContent );
$decrypt = OCA_Encryption\Crypt::symmetricDecryptFileContent( $keyfileContent, 'hat' );
$this->assertEqual( $this->data, $decrypt );
}
function testSymmetricEncryptFileContentKeyfile() {
# TODO: search in keyfile for actual content as IV will ensure this test always passes
$crypted = OCA_Encryption\Crypt::symmetricEncryptFileContentKeyfile( $this->data );
$this->assertNotEqual( $this->data, $crypted['encrypted'] );
$decrypt = OCA_Encryption\Crypt::symmetricDecryptFileContent( $crypted['encrypted'], $crypted['key'] );
$this->assertEqual( $this->data, $decrypt );
}
function testMultiKeyEncrypt() {
# TODO: search in keyfile for actual content as IV will ensure this test always passes
$pair1 = OCA_Encryption\Crypt::createKeypair();
$this->assertEqual( 2, count( $pair1 ) );
$this->assertTrue( strlen( $pair1['publicKey'] ) > 1 );
$this->assertTrue( strlen( $pair1['privateKey'] ) > 1 );
$crypted = OCA_Encryption\Crypt::multiKeyEncrypt( $this->data, array( $pair1['publicKey'] ) );
$this->assertNotEqual( $this->data, $crypted['encrypted'] );
$decrypt = OCA_Encryption\Crypt::multiKeyDecrypt( $crypted['encrypted'], $crypted['keys'][0], $pair1['privateKey'] );
$this->assertEqual( $this->data, $decrypt );
}
// function testEncryption(){
//
// $key=uniqid();
// $file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
// $source=file_get_contents($file); //nice large text file
// $encrypted=OC_Crypt::encrypt($source,$key);
// $decrypted=OC_Crypt::decrypt($encrypted,$key);
// $decrypted=rtrim($decrypted, "\0");
// $this->assertNotEqual($encrypted,$source);
// $this->assertEqual($decrypted,$source);
//
// $chunk=substr($source,0,8192);
// $encrypted=OC_Crypt::encrypt($chunk,$key);
// $this->assertEqual(strlen($chunk),strlen($encrypted));
// $decrypted=OC_Crypt::decrypt($encrypted,$key);
// $decrypted=rtrim($decrypted, "\0");
// $this->assertEqual($decrypted,$chunk);
//
// $encrypted=OC_Crypt::blockEncrypt($source,$key);
// $decrypted=OC_Crypt::blockDecrypt($encrypted,$key);
// $this->assertNotEqual($encrypted,$source);
// $this->assertEqual($decrypted,$source);
//
// $tmpFileEncrypted=OCP\Files::tmpFile();
// OC_Crypt::encryptfile($file,$tmpFileEncrypted,$key);
// $encrypted=file_get_contents($tmpFileEncrypted);
// $decrypted=OC_Crypt::blockDecrypt($encrypted,$key);
// $this->assertNotEqual($encrypted,$source);
// $this->assertEqual($decrypted,$source);
//
// $tmpFileDecrypted=OCP\Files::tmpFile();
// OC_Crypt::decryptfile($tmpFileEncrypted,$tmpFileDecrypted,$key);
// $decrypted=file_get_contents($tmpFileDecrypted);
// $this->assertEqual($decrypted,$source);
//
// $file=OC::$SERVERROOT.'/core/img/weather-clear.png';
// $source=file_get_contents($file); //binary file
// $encrypted=OC_Crypt::encrypt($source,$key);
// $decrypted=OC_Crypt::decrypt($encrypted,$key);
// $decrypted=rtrim($decrypted, "\0");
// $this->assertEqual($decrypted,$source);
//
// $encrypted=OC_Crypt::blockEncrypt($source,$key);
// $decrypted=OC_Crypt::blockDecrypt($encrypted,$key);
// $this->assertEqual($decrypted,$source);
//
// }
//
// function testBinary(){
// $key=uniqid();
//
// $file=__DIR__.'/binary';
// $source=file_get_contents($file); //binary file
// $encrypted=OC_Crypt::encrypt($source,$key);
// $decrypted=OC_Crypt::decrypt($encrypted,$key);
//
// $decrypted=rtrim($decrypted, "\0");
// $this->assertEqual($decrypted,$source);
//
// $encrypted=OC_Crypt::blockEncrypt($source,$key);
// $decrypted=OC_Crypt::blockDecrypt($encrypted,$key,strlen($source));
// $this->assertEqual($decrypted,$source);
// }
}

View file

@ -6,112 +6,112 @@
* See the COPYING-README file.
*/
class Test_CryptProxy extends UnitTestCase {
private $oldConfig;
private $oldKey;
public function setUp(){
$user=OC_User::getUser();
$this->oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true');
OCP\Config::setAppValue('files_encryption','enable_encryption','true');
$this->oldKey=isset($_SESSION['enckey'])?$_SESSION['enckey']:null;
//set testing key
$_SESSION['enckey']=md5(time());
//clear all proxies and hooks so we can do clean testing
OC_FileProxy::clearProxies();
OC_Hook::clear('OC_Filesystem');
//enable only the encryption hook
OC_FileProxy::register(new OC_FileProxy_Encryption());
//set up temporary storage
OC_Filesystem::clearMounts();
OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/');
OC_Filesystem::init('/'.$user.'/files');
//set up the users home folder in the temp storage
$rootView=new OC_FilesystemView('');
$rootView->mkdir('/'.$user);
$rootView->mkdir('/'.$user.'/files');
}
public function tearDown(){
OCP\Config::setAppValue('files_encryption','enable_encryption',$this->oldConfig);
if(!is_null($this->oldKey)){
$_SESSION['enckey']=$this->oldKey;
}
}
public function testSimple(){
$file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
$original=file_get_contents($file);
OC_Filesystem::file_put_contents('/file',$original);
OC_FileProxy::$enabled=false;
$stored=OC_Filesystem::file_get_contents('/file');
OC_FileProxy::$enabled=true;
$fromFile=OC_Filesystem::file_get_contents('/file');
$this->assertNotEqual($original,$stored);
$this->assertEqual(strlen($original),strlen($fromFile));
$this->assertEqual($original,$fromFile);
}
public function testView(){
$file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
$original=file_get_contents($file);
$rootView=new OC_FilesystemView('');
$view=new OC_FilesystemView('/'.OC_User::getUser());
$userDir='/'.OC_User::getUser().'/files';
$rootView->file_put_contents($userDir.'/file',$original);
OC_FileProxy::$enabled=false;
$stored=$rootView->file_get_contents($userDir.'/file');
OC_FileProxy::$enabled=true;
$this->assertNotEqual($original,$stored);
$fromFile=$rootView->file_get_contents($userDir.'/file');
$this->assertEqual($original,$fromFile);
$fromFile=$view->file_get_contents('files/file');
$this->assertEqual($original,$fromFile);
}
public function testBinary(){
$file=__DIR__.'/binary';
$original=file_get_contents($file);
OC_Filesystem::file_put_contents('/file',$original);
OC_FileProxy::$enabled=false;
$stored=OC_Filesystem::file_get_contents('/file');
OC_FileProxy::$enabled=true;
$fromFile=OC_Filesystem::file_get_contents('/file');
$this->assertNotEqual($original,$stored);
$this->assertEqual(strlen($original),strlen($fromFile));
$this->assertEqual($original,$fromFile);
$file=__DIR__.'/zeros';
$original=file_get_contents($file);
OC_Filesystem::file_put_contents('/file',$original);
OC_FileProxy::$enabled=false;
$stored=OC_Filesystem::file_get_contents('/file');
OC_FileProxy::$enabled=true;
$fromFile=OC_Filesystem::file_get_contents('/file');
$this->assertNotEqual($original,$stored);
$this->assertEqual(strlen($original),strlen($fromFile));
}
}
// class Test_CryptProxy extends UnitTestCase {
// private $oldConfig;
// private $oldKey;
//
// public function setUp(){
// $user=OC_User::getUser();
//
// $this->oldConfig=OCP\Config::getAppValue('files_encryption','enable_encryption','true');
// OCP\Config::setAppValue('files_encryption','enable_encryption','true');
// $this->oldKey=isset($_SESSION['enckey'])?$_SESSION['enckey']:null;
//
//
// //set testing key
// $_SESSION['enckey']=md5(time());
//
// //clear all proxies and hooks so we can do clean testing
// OC_FileProxy::clearProxies();
// OC_Hook::clear('OC_Filesystem');
//
// //enable only the encryption hook
// OC_FileProxy::register(new OC_FileProxy_Encryption());
//
// //set up temporary storage
// OC_Filesystem::clearMounts();
// OC_Filesystem::mount('OC_Filestorage_Temporary',array(),'/');
//
// OC_Filesystem::init('/'.$user.'/files');
//
// //set up the users home folder in the temp storage
// $rootView=new OC_FilesystemView('');
// $rootView->mkdir('/'.$user);
// $rootView->mkdir('/'.$user.'/files');
// }
//
// public function tearDown(){
// OCP\Config::setAppValue('files_encryption','enable_encryption',$this->oldConfig);
// if(!is_null($this->oldKey)){
// $_SESSION['enckey']=$this->oldKey;
// }
// }
//
// public function testSimple(){
// $file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
// $original=file_get_contents($file);
//
// OC_Filesystem::file_put_contents('/file',$original);
//
// OC_FileProxy::$enabled=false;
// $stored=OC_Filesystem::file_get_contents('/file');
// OC_FileProxy::$enabled=true;
//
// $fromFile=OC_Filesystem::file_get_contents('/file');
// $this->assertNotEqual($original,$stored);
// $this->assertEqual(strlen($original),strlen($fromFile));
// $this->assertEqual($original,$fromFile);
//
// }
//
// public function testView(){
// $file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
// $original=file_get_contents($file);
//
// $rootView=new OC_FilesystemView('');
// $view=new OC_FilesystemView('/'.OC_User::getUser());
// $userDir='/'.OC_User::getUser().'/files';
//
// $rootView->file_put_contents($userDir.'/file',$original);
//
// OC_FileProxy::$enabled=false;
// $stored=$rootView->file_get_contents($userDir.'/file');
// OC_FileProxy::$enabled=true;
//
// $this->assertNotEqual($original,$stored);
// $fromFile=$rootView->file_get_contents($userDir.'/file');
// $this->assertEqual($original,$fromFile);
//
// $fromFile=$view->file_get_contents('files/file');
// $this->assertEqual($original,$fromFile);
// }
//
// public function testBinary(){
// $file=__DIR__.'/binary';
// $original=file_get_contents($file);
//
// OC_Filesystem::file_put_contents('/file',$original);
//
// OC_FileProxy::$enabled=false;
// $stored=OC_Filesystem::file_get_contents('/file');
// OC_FileProxy::$enabled=true;
//
// $fromFile=OC_Filesystem::file_get_contents('/file');
// $this->assertNotEqual($original,$stored);
// $this->assertEqual(strlen($original),strlen($fromFile));
// $this->assertEqual($original,$fromFile);
//
// $file=__DIR__.'/zeros';
// $original=file_get_contents($file);
//
// OC_Filesystem::file_put_contents('/file',$original);
//
// OC_FileProxy::$enabled=false;
// $stored=OC_Filesystem::file_get_contents('/file');
// OC_FileProxy::$enabled=true;
//
// $fromFile=OC_Filesystem::file_get_contents('/file');
// $this->assertNotEqual($original,$stored);
// $this->assertEqual(strlen($original),strlen($fromFile));
// }
// }

View file

@ -6,80 +6,80 @@
* See the COPYING-README file.
*/
class Test_CryptStream extends UnitTestCase {
private $tmpFiles=array();
function testStream(){
$stream=$this->getStream('test1','w',strlen('foobar'));
fwrite($stream,'foobar');
fclose($stream);
$stream=$this->getStream('test1','r',strlen('foobar'));
$data=fread($stream,6);
fclose($stream);
$this->assertEqual('foobar',$data);
$file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
$source=fopen($file,'r');
$target=$this->getStream('test2','w',0);
OCP\Files::streamCopy($source,$target);
fclose($target);
fclose($source);
$stream=$this->getStream('test2','r',filesize($file));
$data=stream_get_contents($stream);
$original=file_get_contents($file);
$this->assertEqual(strlen($original),strlen($data));
$this->assertEqual($original,$data);
}
/**
* get a cryptstream to a temporary file
* @param string $id
* @param string $mode
* @param int size
* @return resource
*/
function getStream($id,$mode,$size){
if($id===''){
$id=uniqid();
}
if(!isset($this->tmpFiles[$id])){
$file=OCP\Files::tmpFile();
$this->tmpFiles[$id]=$file;
}else{
$file=$this->tmpFiles[$id];
}
$stream=fopen($file,$mode);
OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream,'size'=>$size);
return fopen('crypt://streams/'.$id,$mode);
}
function testBinary(){
$file=__DIR__.'/binary';
$source=file_get_contents($file);
$stream=$this->getStream('test','w',strlen($source));
fwrite($stream,$source);
fclose($stream);
$stream=$this->getStream('test','r',strlen($source));
$data=stream_get_contents($stream);
fclose($stream);
$this->assertEqual(strlen($data),strlen($source));
$this->assertEqual($source,$data);
$file=__DIR__.'/zeros';
$source=file_get_contents($file);
$stream=$this->getStream('test2','w',strlen($source));
fwrite($stream,$source);
fclose($stream);
$stream=$this->getStream('test2','r',strlen($source));
$data=stream_get_contents($stream);
fclose($stream);
$this->assertEqual(strlen($data),strlen($source));
$this->assertEqual($source,$data);
}
}
// class Test_CryptStream extends UnitTestCase {
// private $tmpFiles=array();
//
// function testStream(){
// $stream=$this->getStream('test1','w',strlen('foobar'));
// fwrite($stream,'foobar');
// fclose($stream);
//
// $stream=$this->getStream('test1','r',strlen('foobar'));
// $data=fread($stream,6);
// fclose($stream);
// $this->assertEqual('foobar',$data);
//
// $file=OC::$SERVERROOT.'/3rdparty/MDB2.php';
// $source=fopen($file,'r');
// $target=$this->getStream('test2','w',0);
// OCP\Files::streamCopy($source,$target);
// fclose($target);
// fclose($source);
//
// $stream=$this->getStream('test2','r',filesize($file));
// $data=stream_get_contents($stream);
// $original=file_get_contents($file);
// $this->assertEqual(strlen($original),strlen($data));
// $this->assertEqual($original,$data);
// }
//
// /**
// * get a cryptstream to a temporary file
// * @param string $id
// * @param string $mode
// * @param int size
// * @return resource
// */
// function getStream($id,$mode,$size){
// if($id===''){
// $id=uniqid();
// }
// if(!isset($this->tmpFiles[$id])){
// $file=OCP\Files::tmpFile();
// $this->tmpFiles[$id]=$file;
// }else{
// $file=$this->tmpFiles[$id];
// }
// $stream=fopen($file,$mode);
// OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream,'size'=>$size);
// return fopen('crypt://streams/'.$id,$mode);
// }
//
// function testBinary(){
// $file=__DIR__.'/binary';
// $source=file_get_contents($file);
//
// $stream=$this->getStream('test','w',strlen($source));
// fwrite($stream,$source);
// fclose($stream);
//
// $stream=$this->getStream('test','r',strlen($source));
// $data=stream_get_contents($stream);
// fclose($stream);
// $this->assertEqual(strlen($data),strlen($source));
// $this->assertEqual($source,$data);
//
// $file=__DIR__.'/zeros';
// $source=file_get_contents($file);
//
// $stream=$this->getStream('test2','w',strlen($source));
// fwrite($stream,$source);
// fclose($stream);
//
// $stream=$this->getStream('test2','r',strlen($source));
// $data=stream_get_contents($stream);
// fclose($stream);
// $this->assertEqual(strlen($data),strlen($source));
// $this->assertEqual($source,$data);
// }
// }