/** * Check if a file requires encryption * @param string $path * @return bool * * Tests if server side encryption is enabled, and file is allowed by blacklists */ private static function shouldEncrypt($path) { $userId = Helper::getUser($path); if (\OCP\App::isEnabled('files_encryption') === false || Crypt::mode() !== 'server' || strpos($path, '/' . $userId . '/files') !== 0) { return false; } if (is_null(self::$blackList)) { self::$blackList = explode(',', \OCP\Config::getAppValue('files_encryption', 'type_blacklist', '')); } if (Crypt::isCatfileContent($path)) { return true; } $extension = substr($path, strrpos($path, '.') + 1); if (array_search($extension, self::$blackList) === false) { return true; } return false; }
/** * Check if a file requires encryption * @param string $path * @return bool * * Tests if server side encryption is enabled, and file is allowed by blacklists */ private static function shouldEncrypt($path) { if (is_null(self::$enableEncryption)) { if (\OCP\Config::getAppValue('files_encryption', 'enable_encryption', 'true') === 'true' && Crypt::mode() === 'server') { self::$enableEncryption = true; } else { self::$enableEncryption = false; } } if (!self::$enableEncryption) { return false; } if (is_null(self::$blackList)) { self::$blackList = explode(',', \OCP\Config::getAppValue('files_encryption', 'type_blacklist', '')); } if (Crypt::isCatfileContent($path)) { return true; } $extension = substr($path, strrpos($path, '.') + 1); if (array_search($extension, self::$blackList) === false) { return true; } return false; }
/** * remember initial fopen mode because sometimes it gets changed during the request * @param string $path path * @param string $mode type of access */ public function preFopen($path, $mode) { self::$fopenMode[$path] = $mode; self::$enableEncryption = $this->shouldEncrypt($path, $mode); }