From: Bjoern Schiessle Date: Tue, 17 Dec 2013 14:53:25 +0000 (+0100) Subject: reliable detect encrypted files X-Git-Tag: v7.0.0alpha2~1020^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=69b89454a4070c0ae3e7e8b6e37f310a2ee28e73;p=nextcloud-server.git reliable detect encrypted files --- diff --git a/apps/files_encryption/lib/util.php b/apps/files_encryption/lib/util.php index bf7c49504a2..d4aa4d31649 100644 --- a/apps/files_encryption/lib/util.php +++ b/apps/files_encryption/lib/util.php @@ -464,20 +464,22 @@ class Util { */ public function isEncryptedPath($path) { - $relPath = Helper::getPathToRealFile($path); - - if ($relPath === false) { - $relPath = Helper::stripUserFilesPath($path); - } - - $fileKey = Keymanager::getFileKey($this->view, $this, $relPath); + // Disable encryption proxy so data retrieved is in its + // original form + $proxyStatus = \OC_FileProxy::$enabled; + \OC_FileProxy::$enabled = false; - if ($fileKey === false) { - return false; + // we only need 24 byte from the last chunk + $data = ''; + $handle = $this->view->fopen($path, 'r'); + if (is_resource($handle) && !fseek($handle, -24, SEEK_END)) { + $data = fgets($handle); } - return true; + // re-enable proxy + \OC_FileProxy::$enabled = $proxyStatus; + return Crypt::isCatfileContent($data); } /**