execute file hooks only if server side encryption is enabled

This commit is contained in:
Bjoern Schiessle 2012-08-10 12:27:09 +02:00
parent 12628be38b
commit e4450d1035
3 changed files with 16 additions and 19 deletions

View File

@ -63,7 +63,7 @@ class Hooks {
* @brief update the encryption key of the file uploaded by the client
*/
public static function updateKeyfile( $params ) {
if (Crypt::mode(\OCP\User::getUser()) == 'client')
if (Crypt::mode() == 'client')
if (isset($params['properties']['key'])) {
Keymanager::setFileKey($params['path'], $params['properties']['key']);
} else {

View File

@ -38,9 +38,8 @@ class Keymanager {
$user = \OCP\User::getUser();
$view = new \OC_FilesystemView( '/' . $user . '/' . 'files_encryption' );
$result = $view->file_get_contents( '/' . $user.'.private.key' );
return $result;
return $view->file_get_contents( '/' . $user.'.private.key' );
}
/**
@ -110,9 +109,8 @@ class Keymanager {
}
$view = new \OC_FilesystemView('/'.$user.'/files_encryption/keyfiles/');
$result = $view->file_get_contents($keypath.'.key');
return $result;
return $view->file_get_contents($keypath.'.key');
}
/**
@ -126,9 +124,8 @@ class Keymanager {
$user = \OCP\User::getUser();
$view = new \OC_FilesystemView('/'.$user.'/files_encryption');
if (!$view->file_exists('')) $view->mkdir('');
$result = $view->file_put_contents($user.'.private.key', $key);
return $view->file_put_contents($user.'.private.key', $key);
return $result;
}
@ -142,9 +139,8 @@ class Keymanager {
$view = new \OC_FilesystemView('/public-keys');
if (!$view->file_exists('')) $view->mkdir('');
$result = $view->file_put_contents(\OCP\User::getUser().'.public.key', $key);
return $view->file_put_contents(\OCP\User::getUser().'.public.key', $key);
return $result;
}
/**
@ -186,9 +182,8 @@ class Keymanager {
if ( !$view->file_exists( $path_parts['dirname'] ) ) $view->mkdir( $path_parts['dirname'] );
$result = $view->file_put_contents( '/' . $targetpath . '.key', $key );
return $view->file_put_contents( '/' . $targetpath . '.key', $key );
return $result;
}
/**
@ -199,6 +194,7 @@ class Keymanager {
* @return bool true/false
*/
public static function changePasswd($oldpasswd, $newpasswd) {
if ( \OCP\User::checkPassword(\OCP\User::getUser(), $newpasswd) ) {
$key = Keymanager::getPrivateKey();
if ( ($key = Crypt::symmetricDecryptFileContent($key,$oldpasswd)) ) {
@ -209,6 +205,7 @@ class Keymanager {
}
}
return false;
}
}

View File

@ -40,7 +40,7 @@ class Proxy extends \OC_FileProxy {
* @param string $path
* @return bool
*
* Tests if encryption is enabled, and file is allowed by blacklists
* Tests if server side encryption is enabled, and file is allowed by blacklists
*/
private static function shouldEncrypt( $path ) {
@ -130,7 +130,7 @@ class Proxy extends \OC_FileProxy {
public function postFile_get_contents( $path, $data ) {
if ( Crypt::isEncryptedContent( $data ) ) {
if ( Crypt::mode() == 'server' && Crypt::isEncryptedContent( $data ) ) {
$filePath = explode( '/', $path );
@ -164,7 +164,7 @@ class Proxy extends \OC_FileProxy {
$meta = stream_get_meta_data( $result );
// If file is encrypted, decrypt using crypto protocol
if ( Crypt::isEncryptedContent( $path ) ) {
if ( Crypt::mode() == 'server' && Crypt::isEncryptedContent( $path ) ) {
fclose ( $result );
@ -208,14 +208,14 @@ class Proxy extends \OC_FileProxy {
}
public function postGetMimeType($path,$mime){
if(Crypt::isEncryptedContent($path)){
if( Crypt::isEncryptedContent($path)){
$mime = \OCP\Files::getMimeType('crypt://'.$path,'w');
}
return $mime;
}
public function postStat($path,$data){
if(Crypt::isEncryptedContent($path)){
if( Crypt::isEncryptedContent($path)){
$cached= \OC_FileCache_Cached::get($path,'');
$data['size']=$cached['size'];
}
@ -223,7 +223,7 @@ class Proxy extends \OC_FileProxy {
}
public function postFileSize($path,$size){
if(Crypt::isEncryptedContent($path)){
if( Crypt::isEncryptedContent($path)){
$cached = \OC_FileCache_Cached::get($path,'');
return $cached['size'];
}else{