Merge branch 'master' into file_encryption_external_storage_fixes

Conflicts:
	apps/files_encryption/hooks/hooks.php
This commit is contained in:
Florin Peter 2013-05-30 00:45:29 +02:00
commit 313631edf6
18 changed files with 751 additions and 709 deletions

View File

@ -16,28 +16,44 @@ use OCA\Encryption;
$l = OC_L10N::get('files_encryption');
$return = false;
// Enable recoveryAdmin
$recoveryKeyId = OC_Appconfig::getValue('files_encryption', 'recoveryKeyId');
if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] == 1){
if (isset($_POST['adminEnableRecovery']) && $_POST['adminEnableRecovery'] === '1') {
$return = \OCA\Encryption\Helper::adminEnableRecovery($recoveryKeyId, $_POST['recoveryPassword']);
$action = "enable";
// Return success or failure
if ($return) {
\OCP\JSON::success(array('data' => array('message' => $l->t('Recovery key successfully enabled'))));
} else {
\OCP\JSON::error(array(
'data' => array(
'message' => $l->t(
'Could not enable recovery key. Please check your recovery key password!')
)
));
}
// Disable recoveryAdmin
} elseif (
isset($_POST['adminEnableRecovery'])
&& 0 == $_POST['adminEnableRecovery']
&& '0' === $_POST['adminEnableRecovery']
) {
$return = \OCA\Encryption\Helper::adminDisableRecovery($_POST['recoveryPassword']);
$action = "disable";
}
// Return success or failure
if ($return) {
\OCP\JSON::success(array("data" => array( "message" => $l->t('Recovery key successfully ' . $action.'d'))));
\OCP\JSON::success(array('data' => array('message' => $l->t('Recovery key successfully disabled'))));
} else {
\OCP\JSON::error(array("data" => array( "message" => $l->t('Could not '.$action.' recovery key. Please check your recovery key password!'))));
\OCP\JSON::error(array(
'data' => array(
'message' => $l->t(
'Could not disable recovery key. Please check your recovery key password!')
)
));
}
}

View File

@ -28,7 +28,7 @@ $result = $util->checkRecoveryPassword($oldPassword);
if ($result) {
$keyId = $util->getRecoveryKeyId();
$keyPath = '/owncloud_private_key/' . $keyId . ".private.key";
$keyPath = '/owncloud_private_key/' . $keyId . '.private.key';
$view = new \OC\Files\View('/');
$proxyStatus = \OC_FileProxy::$enabled;
@ -46,7 +46,7 @@ if ($result) {
// success or failure
if ($return) {
\OCP\JSON::success(array("data" => array( "message" => $l->t('Password successfully changed.'))));
\OCP\JSON::success(array('data' => array('message' => $l->t('Password successfully changed.'))));
} else {
\OCP\JSON::error(array("data" => array( "message" => $l->t('Could not change the password. Maybe the old password was not correct.'))));
\OCP\JSON::error(array('data' => array('message' => $l->t('Could not change the password. Maybe the old password was not correct.'))));
}

View File

@ -15,7 +15,7 @@ use OCA\Encryption;
if (
isset($_POST['userEnableRecovery'])
&& ( 0 == $_POST['userEnableRecovery'] || 1 == $_POST['userEnableRecovery'] )
&& (0 == $_POST['userEnableRecovery'] || '1' === $_POST['userEnableRecovery'])
) {
$userId = \OCP\USER::getUser();
@ -25,7 +25,7 @@ if (
// Save recovery preference to DB
$return = $util->setRecoveryForUser($_POST['userEnableRecovery']);
if ($_POST['userEnableRecovery'] == "1") {
if ($_POST['userEnableRecovery'] === '1') {
$util->addRecoveryKeys();
} else {
$util->removeRecoveryKeys();

View File

@ -145,9 +145,9 @@ class Hooks {
// Only attempt to change passphrase if server-side encryption
// is in use (client-side encryption does not have access to
// the necessary keys)
if (Crypt::mode() == 'server') {
if (Crypt::mode() === 'server') {
if ($params['uid'] == \OCP\User::getUser()) {
if ($params['uid'] === \OCP\User::getUser()) {
$view = new \OC_FilesystemView('/');
@ -191,7 +191,8 @@ class Hooks {
$encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], $newUserPassword);
// Save private key
$view->file_put_contents( '/'.$user.'/files_encryption/'.$user.'.private.key', $encryptedPrivateKey );
$view->file_put_contents(
'/' . $user . '/files_encryption/' . $user . '.private.key', $encryptedPrivateKey);
if ($recoveryPassword) { // if recovery key is set we can re-encrypt the key files
$util = new Util($view, $user);
@ -231,10 +232,11 @@ class Hooks {
}
}
if($error)
// Set flag var 'run' to notify emitting
if ($error) // Set flag var 'run' to notify emitting
// script that hook execution failed
{
$params['run']->run = false;
}
// TODO: Make sure files_sharing provides user
// feedback on failed share
}
@ -273,7 +275,7 @@ class Hooks {
$share = $util->getParentFromShare($params['id']);
//if parent is set, then this is a re-share action
if ($share['parent'] != null) {
if ($share['parent'] !== null) {
// get the parent from current share
$parent = $util->getShareParent($params['parent']);
@ -399,13 +401,15 @@ class Hooks {
}
// for group shares get a list of the group members
if ( $params['shareType'] == \OCP\Share::SHARE_TYPE_GROUP ) {
if ($params['shareType'] === \OCP\Share::SHARE_TYPE_GROUP) {
$userIds = \OC_Group::usersInGroup($params['shareWith']);
} else if ( $params['shareType'] == \OCP\Share::SHARE_TYPE_LINK ){
} else {
if ($params['shareType'] === \OCP\Share::SHARE_TYPE_LINK) {
$userIds = array($util->getPublicShareKeyId());
} else {
$userIds = array($params['shareWith']);
}
}
// if we unshare a folder we need a list of all (sub-)files
if ( $params['itemType'] === 'folder' ) {
@ -456,8 +460,10 @@ class Hooks {
$util = new Util($view, $userId);
// Format paths to be relative to user files dir
$oldKeyfilePath = \OC\Files\Filesystem::normalizePath($userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['oldpath']);
$newKeyfilePath = \OC\Files\Filesystem::normalizePath($userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['newpath']);
$oldKeyfilePath = \OC\Files\Filesystem::normalizePath(
$userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['oldpath']);
$newKeyfilePath = \OC\Files\Filesystem::normalizePath(
$userId . '/' . 'files_encryption' . '/' . 'keyfiles' . '/' . $params['newpath']);
// add key ext if this is not an folder
if (!$view->is_dir($oldKeyfilePath)) {
@ -480,8 +486,10 @@ class Hooks {
} else {
// handle share-keys folders
$oldShareKeyfilePath = \OC\Files\Filesystem::normalizePath($userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['oldpath']);
$newShareKeyfilePath = \OC\Files\Filesystem::normalizePath($userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['newpath']);
$oldShareKeyfilePath = \OC\Files\Filesystem::normalizePath(
$userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['oldpath']);
$newShareKeyfilePath = \OC\Files\Filesystem::normalizePath(
$userId . '/' . 'files_encryption' . '/' . 'share-keys' . '/' . $params['newpath']);
// create destination folder if not exists
if (!$view->file_exists(dirname($newShareKeyfilePath))) {

View File

@ -32,8 +32,7 @@ require_once realpath( dirname( __FILE__ ) . '/../3rdparty/Crypt_Blowfish/Blowfi
* Class for common cryptography functionality
*/
class Crypt
{
class Crypt {
/**
* @brief return encryption mode client or server side encryption
@ -62,7 +61,10 @@ class Crypt
$publicKey = $publicKey['key'];
return ( array( 'publicKey' => $publicKey, 'privateKey' => $privateKey ) );
return (array(
'publicKey' => $publicKey,
'privateKey' => $privateKey
));
}
@ -90,7 +92,7 @@ class Crypt
*/
public static function removePadding($padded) {
if ( substr( $padded, -2 ) == 'xx' ) {
if (substr($padded, -2) === 'xx') {
$data = substr($padded, 0, -2);
@ -130,7 +132,7 @@ class Crypt
// Fetch identifier from start of metadata
$identifier = substr($meta, 0, 6);
if ( $identifier == '00iv00' ) {
if ($identifier === '00iv00') {
return true;
@ -155,7 +157,7 @@ class Crypt
$metadata = \OC\Files\Filesystem::getFileInfo($path);
// Return encryption status
return isset( $metadata['encrypted'] ) and ( bool )$metadata['encrypted'];
return isset($metadata['encrypted']) && ( bool )$metadata['encrypted'];
}
@ -174,10 +176,9 @@ class Crypt
// If a file is flagged with encryption in DB, but isn't a
// valid content + IV combination, it's probably using the
// legacy encryption system
if (
isset( $metadata['encrypted'] )
and $metadata['encrypted'] === true
and !self::isCatfileContent( $data )
if (isset($metadata['encrypted'])
&& $metadata['encrypted'] === true
&& !self::isCatfileContent($data)
) {
return true;
@ -205,7 +206,7 @@ class Crypt
} else {
\OC_Log::write( 'Encryption library', 'Encryption (symmetric) of content failed', \OC_Log::ERROR );
\OCP\Util::writeLog('Encryption library', 'Encryption (symmetric) of content failed', \OCP\Util::ERROR);
return false;
@ -266,8 +267,8 @@ class Crypt
$encrypted = substr($catFile, 0, -22);
$split = array(
'encrypted' => $encrypted
, 'iv' => $iv
'encrypted' => $encrypted,
'iv' => $iv
);
return $split;
@ -304,7 +305,7 @@ class Crypt
} else {
\OC_Log::write( 'Encryption library', 'Encryption (symmetric) of keyfile content failed', \OC_Log::ERROR );
\OCP\Util::writeLog('Encryption library', 'Encryption (symmetric) of keyfile content failed', \OCP\Util::ERROR);
return false;
@ -451,7 +452,7 @@ class Crypt
} else {
\OC_Log::write( 'Encryption library', 'Decryption (asymmetric) of sealed content failed', \OC_Log::ERROR );
\OCP\Util::writeLog('Encryption library', 'Decryption (asymmetric) of sealed content failed', \OCP\Util::ERROR);
return false;
@ -461,6 +462,8 @@ class Crypt
/**
* @brief Asymetrically encrypt a string using a public key
* @param $plainContent
* @param $publicKey
* @return string encrypted file
*/
public static function keyEncrypt($plainContent, $publicKey) {
@ -473,6 +476,8 @@ class Crypt
/**
* @brief Asymetrically decrypt a file using a private key
* @param $encryptedContent
* @param $privatekey
* @return string decrypted file
*/
public static function keyDecrypt($encryptedContent, $privatekey) {
@ -498,7 +503,7 @@ class Crypt
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 );
\OCP\Util::writeLog('Encryption library', 'Insecure symmetric key was generated using openssl_random_pseudo_bytes()', \OCP\Util::WARN);
}
@ -545,7 +550,7 @@ class Crypt
/**
* @brief Get the blowfish encryption handeler for a key
* @param $key string (optional)
* @return Crypt_Blowfish blowfish object
* @return \Crypt_Blowfish blowfish object
*
* if the key is left out, the default handeler will be used
*/
@ -583,8 +588,6 @@ class Crypt
* @brief encrypts content using legacy blowfish system
* @param string $content the cleartext message you want to encrypt
* @param string $passphrase
* @return
* @internal param \OCA\Encryption\the $key encryption key (optional)
* @returns string encrypted content
*
* This function encrypts an content
@ -601,8 +604,6 @@ class Crypt
* @brief decrypts content using legacy blowfish system
* @param string $content the cleartext message you want to decrypt
* @param string $passphrase
* @return string
* @internal param \OCA\Encryption\the $key encryption key (optional)
* @return string cleartext content
*
* This function decrypts an content
@ -614,7 +615,6 @@ class Crypt
$decrypted = $bf->decrypt($content);
return $decrypted;
}
/**
@ -624,6 +624,7 @@ class Crypt
* @return string
*/
public static function legacyBlockDecrypt($data, $key = '', $maxLength = 0) {
$result = '';
while (strlen($data)) {
$result .= self::legacyDecrypt(substr($data, 0, 8192), $key);
@ -640,11 +641,9 @@ class Crypt
* @param $legacyEncryptedContent
* @param $legacyPassphrase
* @param $publicKeys
* @param $newPassphrase
* @param $path
* @return array
*/
public static function legacyKeyRecryptKeyfile( $legacyEncryptedContent, $legacyPassphrase, $publicKeys, $newPassphrase, $path ) {
public static function legacyKeyRecryptKeyfile($legacyEncryptedContent, $legacyPassphrase, $publicKeys) {
$decrypted = self::legacyBlockDecrypt($legacyEncryptedContent, $legacyPassphrase);
@ -654,7 +653,11 @@ class Crypt
// Encrypt plain keyfile to multiple sharefiles
$multiEncrypted = Crypt::multiKeyEncrypt($cryptedData['key'], $publicKeys);
return array( 'data' => $cryptedData['encrypted'], 'filekey' => $multiEncrypted['data'], 'sharekeys' => $multiEncrypted['keys'] );
return array(
'data' => $cryptedData['encrypted'],
'filekey' => $multiEncrypted['data'],
'sharekeys' => $multiEncrypted['keys']
);
}

View File

@ -25,13 +25,9 @@ namespace OCA\Encryption;
/**
* @brief Class to manage registration of hooks an various helper methods
*/
/**
* Class Helper
* @package OCA\Encryption
*/
class Helper
{
class Helper {
/**
* @brief register share related hooks
@ -76,7 +72,8 @@ class Helper
// Check files_encryption infrastructure is ready for action
if (!$util->ready()) {
\OC_Log::write( 'Encryption library', 'User account "' . $util->getUserId() . '" is not ready for encryption; configuration started', \OC_Log::DEBUG );
\OCP\Util::writeLog('Encryption library', 'User account "' . $util->getUserId()
. '" is not ready for encryption; configuration started', \OCP\Util::DEBUG);
if (!$util->setupServerSide($password)) {
return false;

View File

@ -27,8 +27,7 @@ namespace OCA\Encryption;
* @brief Class to manage storage and retrieval of encryption keys
* @note Where a method requires a view object, it's root must be '/'
*/
class Keymanager
{
class Keymanager {
/**
* @brief retrieve the ENCRYPTED private key from a user
@ -80,8 +79,8 @@ class Keymanager
public static function getUserKeys(\OC_FilesystemView $view, $userId) {
return array(
'publicKey' => self::getPublicKey( $view, $userId )
, 'privateKey' => self::getPrivateKey( $view, $userId )
'publicKey' => self::getPublicKey($view, $userId),
'privateKey' => self::getPrivateKey($view, $userId)
);
}
@ -147,7 +146,8 @@ class Keymanager
// try reusing key file if part file
if (self::isPartialFilePath($targetPath)) {
$result = $view->file_put_contents( $basePath . '/' . self::fixPartialFilePath( $targetPath ) . '.key', $catfile );
$result = $view->file_put_contents(
$basePath . '/' . self::fixPartialFilePath($targetPath) . '.key', $catfile);
} else {
@ -275,15 +275,18 @@ class Keymanager
$result = $view->unlink($keyPath);
} else if ( $view->file_exists( $keyPath . '.key' ) ) {
} else {
if ($view->file_exists($keyPath . '.key')) {
$result = $view->unlink($keyPath . '.key');
}
}
if (!$result) {
\OC_Log::write( 'Encryption library', 'Could not delete keyfile; does not exist: "' . $keyPath, \OC_Log::ERROR );
\OCP\Util::writeLog('Encryption library',
'Could not delete keyfile; does not exist: "' . $keyPath, \OCP\Util::ERROR);
}
@ -437,7 +440,8 @@ class Keymanager
$util = new Util($view, \OCP\User::getUser());
list($owner, $filename) = $util->getUidAndFilename($filePath);
$shareKeyPath = \OC\Files\Filesystem::normalizePath( '/' . $owner . '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey' );
$shareKeyPath = \OC\Files\Filesystem::normalizePath(
'/' . $owner . '/files_encryption/share-keys/' . $filename . '.' . $userId . '.shareKey');
if ($view->file_exists($shareKeyPath)) {
@ -471,7 +475,8 @@ class Keymanager
foreach ($matches as $ma) {
$result = unlink($ma);
if (!$result) {
\OC_Log::write( 'Encryption library', 'Keyfile or shareKey could not be deleted for file "' . $filePath . '"', \OC_Log::ERROR );
\OCP\Util::writeLog('Encryption library',
'Keyfile or shareKey could not be deleted for file "' . $filePath . '"', \OCP\Util::ERROR);
}
}
}
@ -502,7 +507,9 @@ class Keymanager
foreach ($userIds as $userId) {
if (!$view->unlink($shareKeyPath . '.' . $userId . '.shareKey')) {
\OC_Log::write( 'Encryption library', 'Could not delete shareKey; does not exist: "' . $shareKeyPath . '.' . $userId . '.shareKey"', \OC_Log::ERROR );
\OCP\Util::writeLog('Encryption library',
'Could not delete shareKey; does not exist: "' . $shareKeyPath . '.' . $userId
. '.shareKey"', \OCP\Util::ERROR);
}
}
@ -524,7 +531,8 @@ class Keymanager
/** @var $matches array */
foreach ($matches as $ma) {
if (!unlink($ma)) {
\OC_Log::write( 'Encryption library', 'Could not delete shareKey; does not exist: "' . $ma . '"', \OC_Log::ERROR );
\OCP\Util::writeLog('Encryption library',
'Could not delete shareKey; does not exist: "' . $ma . '"', \OCP\Util::ERROR);
}
}
$subdirs = $directories = glob(preg_quote($dir) . '/*', GLOB_ONLYDIR);

View File

@ -34,8 +34,7 @@ namespace OCA\Encryption;
* Class Proxy
* @package OCA\Encryption
*/
class Proxy extends \OC_FileProxy
{
class Proxy extends \OC_FileProxy {
private static $blackList = null; //mimetypes blacklisted from encryption
@ -53,8 +52,8 @@ class Proxy extends \OC_FileProxy
if (is_null(self::$enableEncryption)) {
if (
\OCP\Config::getAppValue( 'files_encryption', 'enable_encryption', 'true' ) == 'true'
&& Crypt::mode() == 'server'
\OCP\Config::getAppValue('files_encryption', 'enable_encryption', 'true') === 'true'
&& Crypt::mode() === 'server'
) {
self::$enableEncryption = true;
@ -168,7 +167,11 @@ class Proxy extends \OC_FileProxy
$data = $encData;
// Update the file cache with file info
\OC\Files\Filesystem::putFileInfo( $filePath, array( 'encrypted' => true, 'size' => strlen( $data ), 'unencrypted_size' => $size ), '' );
\OC\Files\Filesystem::putFileInfo($filePath, array(
'encrypted' => true,
'size' => strlen($data),
'unencrypted_size' => $size
), '');
// Re-enable proxy - our work is done
\OC_FileProxy::$enabled = $proxyStatus;
@ -201,7 +204,7 @@ class Proxy extends \OC_FileProxy
// If data is a catfile
if (
Crypt::mode() == 'server'
Crypt::mode() === 'server'
&& Crypt::isCatfileContent($data)
) {
@ -265,7 +268,8 @@ class Proxy extends \OC_FileProxy
// Delete keyfile & shareKey so it isn't orphaned
if (!Keymanager::deleteFileKey($view, $owner, $ownerPath)) {
\OC_Log::write( 'Encryption library', 'Keyfile or shareKey could not be deleted for file "' . $ownerPath . '"', \OC_Log::ERROR );
\OCP\Util::writeLog('Encryption library',
'Keyfile or shareKey could not be deleted for file "' . $ownerPath . '"', \OCP\Util::ERROR);
}
Keymanager::delAllShareKeys($view, $owner, $ownerPath);
@ -306,7 +310,7 @@ class Proxy extends \OC_FileProxy
$path_f = implode('/', array_slice($path_split, 3));
// FIXME: handling for /userId/cache used by webdav for chunking. The cache chunks are NOT encrypted
if ( count($path_split) >= 2 && $path_split[2] == 'cache' ) {
if (isset($path_split) && $path_split[2] === 'cache') {
return $result;
}
@ -322,7 +326,7 @@ class Proxy extends \OC_FileProxy
// If file is already encrypted, decrypt using crypto protocol
if (
Crypt::mode() == 'server'
Crypt::mode() === 'server'
&& $util->isEncryptedPath($path)
) {
@ -335,8 +339,8 @@ class Proxy extends \OC_FileProxy
} elseif (
self::shouldEncrypt($path)
and $meta ['mode'] != 'r'
and $meta['mode'] != 'rb'
and $meta ['mode'] !== 'r'
and $meta['mode'] !== 'rb'
) {
$result = fopen('crypt://' . $path_f, $meta['mode']);
}
@ -448,7 +452,7 @@ class Proxy extends \OC_FileProxy
$path_f = implode('/', array_slice($path_split, 3));
// only if file is on 'files' folder fix file size and sharing
if ( count($path_split) >= 2 && $path_split[2] == 'files' && $util->fixFileSize( $path ) ) {
if (isset($path_split) && $path_split[2] === 'files' && $util->fixFileSize($path)) {
// get sharing app state
$sharingEnabled = \OCP\Share::isEnabled();

View File

@ -26,8 +26,7 @@ namespace OCA\Encryption;
* Class for handling encryption related session data
*/
class Session
{
class Session {
private $view;
@ -77,7 +76,8 @@ class Session
$encryptedPrivateKey = Crypt::symmetricEncryptFileContent($keypair['privateKey'], '');
// Save private key
$this->view->file_put_contents( '/owncloud_private_key/' . $publicShareKeyId . '.private.key', $encryptedPrivateKey );
$this->view->file_put_contents(
'/owncloud_private_key/' . $publicShareKeyId . '.private.key', $encryptedPrivateKey);
\OC_FileProxy::$enabled = $proxyStatus;
@ -117,7 +117,6 @@ class Session
*
*/
public function getPrivateKey() {
// return the public share private key if this is a public access
if (\OCA\Encryption\Helper::isPublicAccess()) {
return $this->getPublicSharePrivateKey();

View File

@ -48,8 +48,7 @@ namespace OCA\Encryption;
* previous version deleted, this is handled by OC\Files\View, and thus the
* encryption proxies are used and keyfiles deleted.
*/
class Stream
{
class Stream {
private $plainKey;
private $encKeyfiles;
@ -98,10 +97,10 @@ class Stream
\OC_FileProxy::$enabled = false;
if (
$mode == 'w'
or $mode == 'w+'
or $mode == 'wb'
or $mode == 'wb+'
$mode === 'w'
or $mode === 'w+'
or $mode === 'wb'
or $mode === 'wb+'
) {
// We're writing a new file so start write counter with 0 bytes
@ -153,7 +152,7 @@ class Stream
$this->writeCache = '';
if ( $count != 8192 ) {
if ($count !== 8192) {
// $count will always be 8192 https://bugs.php.net/bug.php?id=21641
// This makes this function a lot simpler, but will break this class if the above 'bug' gets 'fixed'
@ -173,7 +172,8 @@ class Stream
if (!$this->getKey()) {
// Error! We don't have a key to decrypt the file with
throw new \Exception( 'Encryption key not found for "' . $this->rawPath . '" during attempted read via stream' );
throw new \Exception(
'Encryption key not found for "' . $this->rawPath . '" during attempted read via stream');
}
@ -425,8 +425,8 @@ class Stream
$this->flush();
if (
$this->meta['mode'] != 'r'
and $this->meta['mode'] != 'rb'
$this->meta['mode'] !== 'r'
and $this->meta['mode'] !== 'rb'
and $this->size > 0
) {
// Disable encryption proxy to prevent recursive calls

View File

@ -382,7 +382,7 @@ class Util {
// we handle them
\OC_FileProxy::$enabled = false;
if ($found == false) {
if ($found === false) {
$found = array(
'plain' => array(),
'encrypted' => array(),
@ -398,8 +398,8 @@ class Util {
while (false !== ($file = readdir($handle))) {
if (
$file != "."
&& $file != ".."
$file !== "."
&& $file !== ".."
) {
$filePath = $directory . '/' . $this->view->getRelativePath('/' . $file);
@ -569,7 +569,7 @@ class Util {
$pathSplit = explode('/', $path);
$pathRelative = implode('/', array_slice($pathSplit, 3));
if ($pathSplit[2] == 'files' && $this->view->file_exists($path) && $this->isEncryptedPath($path)) {
if (isset($pathSplit[2]) && $pathSplit[2] === 'files' && $this->view->file_exists($path) && $this->isEncryptedPath($path)) {
// get the size from filesystem
$fullPath = $this->view->getLocalFile($path);
@ -663,7 +663,7 @@ class Util {
$trimmed = ltrim($path, '/');
$split = explode('/', $trimmed);
if ($split[2] == "Shared") {
if (isset($split[2]) && $split[2] === 'Shared') {
return true;
@ -745,7 +745,7 @@ class Util {
$publicKeys = Keymanager::getPublicKeys($this->view, $uniqueUserIds);
// Recrypt data, generate catfile
$recrypted = Crypt::legacyKeyRecryptKeyfile($legacyData, $legacyPassphrase, $publicKeys, $newPassphrase, $legacyFile['path']);
$recrypted = Crypt::legacyKeyRecryptKeyfile( $legacyData, $legacyPassphrase, $publicKeys );
$rawPath = $legacyFile['path'];
$relPath = $this->stripUserFilesPath($rawPath);
@ -869,8 +869,8 @@ class Util {
// Check that the user is encryption capable, or is the
// public system user 'ownCloud' (for public shares)
if (
$user == $this->publicShareKeyId
or $user == $this->recoveryKeyId
$user === $this->publicShareKeyId
or $user === $this->recoveryKeyId
or $util->ready()
) {
@ -918,7 +918,7 @@ class Util {
// We need to decrypt the keyfile
// Has the file been shared yet?
if (
$this->userId == $fileOwner
$this->userId === $fileOwner
&& !Keymanager::getShareKey($this->view, $this->userId, $filePath) // NOTE: we can't use isShared() here because it's a post share hook so it always returns true
) {
@ -1049,7 +1049,7 @@ class Util {
}
// add current user if given
if ($currentUserId != false) {
if ($currentUserId !== false) {
$userIds[] = $currentUserId;
@ -1166,7 +1166,7 @@ class Util {
\OC\Files\Filesystem::initMountPoints($fileOwnerUid);
// If the file owner is the currently logged in user
if ($fileOwnerUid == $this->userId) {
if ($fileOwnerUid === $this->userId) {
// Assume the path supplied is correct
$filename = $path;
@ -1228,7 +1228,7 @@ class Util {
$path = $dir . $path;
if ($c['type'] === "dir") {
if ($c['type'] === 'dir') {
$result = array_merge($result, $this->getAllFiles($path));
@ -1417,11 +1417,12 @@ class Util {
foreach ($dirContent as $item) {
// get relative path from files_encryption/keyfiles/
$filePath = substr($item['path'], strlen('files_encryption/keyfiles'));
if ($item['type'] == 'dir') {
if ($item['type'] === 'dir') {
$this->addRecoveryKeys($filePath . '/');
} else {
$session = new \OCA\Encryption\Session(new \OC_FilesystemView('/'));
$sharingEnabled = \OCP\Share::isEnabled();
// remove '.key' extension from path e.g. 'file.txt.key' to 'file.txt'
$file = substr($filePath, 0, -4);
$usersSharing = $this->getSharingUsersArray($sharingEnabled, $file);
$this->setSharedFileKeyfiles($session, $usersSharing, $file);
@ -1437,9 +1438,10 @@ class Util {
foreach ($dirContent as $item) {
// get relative path from files_encryption/keyfiles
$filePath = substr($item['path'], strlen('files_encryption/keyfiles'));
if ($item['type'] == 'dir') {
if ($item['type'] === 'dir') {
$this->removeRecoveryKeys($filePath . '/');
} else {
// remove '.key' extension from path e.g. 'file.txt.key' to 'file.txt'
$file = substr($filePath, 0, -4);
$this->view->unlink($this->shareKeysPath . '/' . $file . '.' . $this->recoveryKeyId . '.shareKey');
}
@ -1502,10 +1504,12 @@ class Util {
private function recoverAllFiles($path, $privateKey) {
$dirContent = $this->view->getDirectoryContent($this->keyfilesPath . $path);
foreach ($dirContent as $item) {
$filePath = substr($item['path'], 25);
if ($item['type'] == 'dir') {
// get relative path from files_encryption/keyfiles
$filePath = substr($item['path'], strlen('files_encryption/keyfiles'));
if ($item['type'] === 'dir') {
$this->recoverAllFiles($filePath . '/', $privateKey);
} else {
// remove '.key' extension from path e.g. 'file.txt.key' to 'file.txt'
$file = substr($filePath, 0, -4);
$this->recoverFile($file, $privateKey);
}

View File

@ -575,7 +575,7 @@ class Test_Encryption_Crypt extends \PHPUnit_Framework_TestCase {
*/
function testLegacyKeyRecryptKeyfileEncrypt($crypted) {
$recrypted = Encryption\Crypt::LegacyKeyRecryptKeyfile($crypted, $this->pass, array($this->genPublicKey), $this->pass, '');
$recrypted = Encryption\Crypt::LegacyKeyRecryptKeyfile($crypted, $this->pass, array($this->genPublicKey));
$this->assertNotEquals($this->dataLong, $recrypted['data']);

View File

@ -120,7 +120,7 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase {
$_SERVER['REQUEST_METHOD'] = 'PUT';
$_SERVER['REQUEST_URI'] = '/remote.php/webdav' . $filename;
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic YWRtaW46YWRtaW4=';
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic dGVzdC13ZWJkYXYtdXNlcjE6dGVzdC13ZWJkYXYtdXNlcjE=';
$_SERVER['CONTENT_TYPE'] = 'application/octet-stream';
$_SERVER['PATH_INFO'] = '/webdav' . $filename;
$_SERVER['CONTENT_LENGTH'] = strlen($this->dataShort);
@ -172,7 +172,7 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase {
// set server vars
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/remote.php/webdav' . $filename;
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic YWRtaW46YWRtaW4=';
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic dGVzdC13ZWJkYXYtdXNlcjE6dGVzdC13ZWJkYXYtdXNlcjE=';
$_SERVER['PATH_INFO'] = '/webdav' . $filename;
// handle webdav request
@ -193,7 +193,7 @@ class Test_Encryption_Webdav extends \PHPUnit_Framework_TestCase {
// set server vars
$_SERVER['REQUEST_METHOD'] = 'DELETE';
$_SERVER['REQUEST_URI'] = '/remote.php/webdav' . $filename;
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic YWRtaW46YWRtaW4=';
$_SERVER['HTTP_AUTHORIZATION'] = 'Basic dGVzdC13ZWJkYXYtdXNlcjE6dGVzdC13ZWJkYXYtdXNlcjE=';
$_SERVER['PATH_INFO'] = '/webdav' . $filename;
// handle webdav request

View File

@ -78,19 +78,22 @@ class Scanner {
$this->scanFile($parent);
}
}
$newData = $data;
if ($cacheData = $this->cache->get($file)) {
if ($checkExisting && $data['size'] === -1) {
$data['size'] = $cacheData['size'];
}
if ($data['mtime'] === $cacheData['mtime'] &&
$data['size'] === $cacheData['size']) {
$data['etag'] = $cacheData['etag'];
}
// Only update metadata that has changed
$newData = array_diff($data, $cacheData);
}
if ($checkExisting and $cacheData) {
if ($data['size'] === -1) {
$data['size'] = $cacheData['size'];
if (!empty($newData)) {
$this->cache->put($file, $newData);
}
}
$this->cache->put($file, $data);
}
return $data;
}
return null;