fix mimetypes of encrypted files
This commit is contained in:
parent
cc2bfd313d
commit
5c3ea14819
|
@ -33,6 +33,7 @@ class OC_CryptStream{
|
||||||
private $path;
|
private $path;
|
||||||
private $readBuffer;//for streams that dont support seeking
|
private $readBuffer;//for streams that dont support seeking
|
||||||
private $meta=array();//header/meta for source stream
|
private $meta=array();//header/meta for source stream
|
||||||
|
private $count;
|
||||||
|
|
||||||
public function stream_open($path, $mode, $options, &$opened_path){
|
public function stream_open($path, $mode, $options, &$opened_path){
|
||||||
$path=str_replace('crypt://','',$path);
|
$path=str_replace('crypt://','',$path);
|
||||||
|
@ -92,16 +93,6 @@ class OC_CryptStream{
|
||||||
$data=substr($block,0,$currentPos%8192).$data;
|
$data=substr($block,0,$currentPos%8192).$data;
|
||||||
}
|
}
|
||||||
while(strlen($data)>0){
|
while(strlen($data)>0){
|
||||||
if(strlen($data)<8192){
|
|
||||||
//fetch the current data in that block and append it to the input so we always write entire blocks
|
|
||||||
$oldPos=ftell($this->source);
|
|
||||||
$encryptedBlock=fread($this->source,8192);
|
|
||||||
fseek($this->source,$oldPos);
|
|
||||||
if($encryptedBlock){
|
|
||||||
$block=OC_Crypt::decrypt($encryptedBlock);
|
|
||||||
$data.=substr($block,strlen($data));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$encrypted=OC_Crypt::encrypt(substr($data,0,8192));
|
$encrypted=OC_Crypt::encrypt(substr($data,0,8192));
|
||||||
fwrite($this->source,$encrypted);
|
fwrite($this->source,$encrypted);
|
||||||
$data=substr($data,8192);
|
$data=substr($data,8192);
|
||||||
|
@ -139,7 +130,9 @@ class OC_CryptStream{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function stream_close(){
|
public function stream_close(){
|
||||||
OC_FileCache::put($this->path,array('encrypted'=>true));
|
if($this->meta['mode']!='r' and $this->meta['mode']!='rb'){
|
||||||
|
OC_FileCache::put($this->path,array('encrypted'=>true));
|
||||||
|
}
|
||||||
return fclose($this->source);
|
return fclose($this->source);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
class OC_FileProxy_Encryption extends OC_FileProxy{
|
class OC_FileProxy_Encryption extends OC_FileProxy{
|
||||||
private static $blackList=null; //mimetypes blacklisted from encryption
|
private static $blackList=null; //mimetypes blacklisted from encryption
|
||||||
private static $metaData=array(); //metadata cache
|
|
||||||
private static $enableEncryption=null;
|
private static $enableEncryption=null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,13 +59,8 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private static function isEncrypted($path){
|
private static function isEncrypted($path){
|
||||||
if(isset(self::$metaData[$path])){
|
$metadata=OC_FileCache::getCached($path);
|
||||||
$metadata=self::$metaData[$path];
|
return isset($metadata['encrypted']) and (bool)$metadata['encrypted'];
|
||||||
}else{
|
|
||||||
$metadata=OC_FileCache::getCached($path);
|
|
||||||
self::$metaData[$path]=$metadata;
|
|
||||||
}
|
|
||||||
return (bool)$metadata['encrypted'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function preFile_put_contents($path,&$data){
|
public function preFile_put_contents($path,&$data){
|
||||||
|
@ -98,12 +92,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{
|
||||||
//first encrypt the target file so we don't end up with a half encrypted file
|
//first encrypt the target file so we don't end up with a half encrypted file
|
||||||
OC_Log::write('files_encryption','Decrypting '.$path.' before writing',OC_Log::DEBUG);
|
OC_Log::write('files_encryption','Decrypting '.$path.' before writing',OC_Log::DEBUG);
|
||||||
$tmp=fopen('php://temp');
|
$tmp=fopen('php://temp');
|
||||||
while(!feof($result)){
|
OC_Helper::streamCopy($result,$tmp);
|
||||||
$chunk=fread($result,8192);
|
|
||||||
if($chunk){
|
|
||||||
fwrite($tmp,$chunk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fclose($result);
|
fclose($result);
|
||||||
OC_Filesystem::file_put_contents($path,$tmp);
|
OC_Filesystem::file_put_contents($path,$tmp);
|
||||||
fclose($tmp);
|
fclose($tmp);
|
||||||
|
|
Loading…
Reference in New Issue