}
public static function init($login,$password) {
+ $view1=new OC_FilesystemView('/');
+ if(!$view1->file_exists('/'.$login)){
+ $view1->mkdir('/'.$login);
+ }
+
$view=new OC_FilesystemView('/'.$login);
+
OC_FileProxy::$enabled=false;
if(!$view->file_exists('/encryption.key')){// does key exist?
OC_Crypt::createkey($login,$password);
public static function decrypt( $content, $key='') {
$bf = self::getBlowfish($key);
$data=$bf->decrypt($content);
- return rtrim($data, "\0");
+ return $data;
}
/**
while (!feof($handleread)) {
$content = fread($handleread, 8192);
$enccontent=OC_CRYPT::decrypt( $content, $key);
+ if(feof($handleread)){
+ $enccontent=rtrim($enccontent, "\0");
+ }
fwrite($handlewrite, $enccontent);
}
fclose($handlewrite);
$result.=self::decrypt(substr($data,0,8192),$key);
$data=substr($data,8192);
}
- return $result;
+ return rtrim($result, "\0");
}
}
$this->path=self::$sourceStreams[basename($path)]['path'];
}else{
$this->path=$path;
- OCP\Util::writeLog('files_encryption','open encrypted '.$path. ' in '.$mode,OCP\Util::DEBUG);
OC_FileProxy::$enabled=false;//disable fileproxies so we can open the source file
$this->source=self::$rootView->fopen($path,$mode);
OC_FileProxy::$enabled=true;
}else{
$result='';
}
+ if($this->stream_eof()){
+ $result=rtrim($result, "\0");
+ }
return $result;
}
$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);
$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);
$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);
$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);
+ $this->assertEqual($decrypted,$source);
+ }
}
$file=$this->tmpFiles[$id];
}
$stream=fopen($file,$mode);
- OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy','stream'=>$stream);
+ OC_CryptStream::$sourceStreams[$id]=array('path'=>'dummy'.$id,'stream'=>$stream);
return fopen('crypt://streams/'.$id,$mode);
}
+
+ function testBinary(){
+ $file=__DIR__.'/binary';
+ $source=file_get_contents($file);
+
+ $stream=$this->getStream('test','w');
+ fwrite($stream,$source);
+ fclose($stream);
+
+ $stream=$this->getStream('test','r');
+ $data=stream_get_contents($stream);
+ fclose($stream);
+ $this->assertEqual(strlen($data),strlen($source));
+ $this->assertEqual($source,$data);
+ }
}
}
if($run and $storage=$this->getStorage($path)){
if(!is_null($extraParam)){
- $result=$storage->$operation($interalPath,$extraParam);
+ $result=$storage->$operation($internalPath,$extraParam);
}else{
- $result=$storage->$operation($interalPath);
+ $result=$storage->$operation($internalPath);
}
$result=OC_FileProxy::runPostProxies($operation,$this->getAbsolutePath($path),$result);
if(OC_Filesystem::$loaded and $this->fakeRoot==OC_Filesystem::getRoot()){