Mimetype list integrity check should not fail if it's changed (#15810)

Mimetype list integrity check should not fail if it's changed
This commit is contained in:
John Molakvoæ 2019-07-07 20:01:58 +02:00 committed by GitHub
commit 5a03189ce7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 532 additions and 77 deletions

View File

@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2019 Xheni Myrtaj <xheni@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Core\Command\Maintenance\Mimetype;
class GenerateMimetypeFileBuilder
{
/**
* Generate mime type list file
* @param $aliases
* @return string
*/
public function generateFile(array $aliases): string {
// Remove comments
$keys = array_filter(array_keys($aliases), function($k) {
return $k[0] === '_';
});
foreach($keys as $key) {
unset($aliases[$key]);
}
// Fetch all files
$dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes');
$files = [];
foreach($dir as $fileInfo) {
if ($fileInfo->isFile()) {
$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
$files[] = $file;
}
}
//Remove duplicates
$files = array_values(array_unique($files));
sort($files);
// Fetch all themes!
$themes = [];
$dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/');
foreach($dirs as $dir) {
//Valid theme dir
if ($dir->isFile() || $dir->isDot()) {
continue;
}
$theme = $dir->getFilename();
$themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/';
// Check if this theme has its own filetype icons
if (!file_exists($themeDir)) {
continue;
}
$themes[$theme] = [];
// Fetch all the theme icons!
$themeIt = new \DirectoryIterator($themeDir);
foreach ($themeIt as $fileInfo) {
if ($fileInfo->isFile()) {
$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
$themes[$theme][] = $file;
}
}
//Remove Duplicates
$themes[$theme] = array_values(array_unique($themes[$theme]));
sort($themes[$theme]);
}
//Generate the JS
return '/**
* This file is automatically generated
* DO NOT EDIT MANUALLY!
*
* You can update the list of MimeType Aliases in config/mimetypealiases.json
* The list of files is fetched from core/img/filetypes
* To regenerate this file run ./occ maintenance:mimetype:update-js
*/
OC.MimeTypeList={
aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ',
files: ' . json_encode($files, JSON_PRETTY_PRINT) . ',
themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . '
};
';
}
}

View File

@ -53,78 +53,9 @@ class UpdateJS extends Command {
// Fetch all the aliases
$aliases = $this->mimetypeDetector->getAllAliases();
// Remove comments
$keys = array_filter(array_keys($aliases), function($k) {
return $k[0] === '_';
});
foreach($keys as $key) {
unset($aliases[$key]);
}
// Fetch all files
$dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes');
$files = [];
foreach($dir as $fileInfo) {
if ($fileInfo->isFile()) {
$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
$files[] = $file;
}
}
//Remove duplicates
$files = array_values(array_unique($files));
sort($files);
// Fetch all themes!
$themes = [];
$dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/');
foreach($dirs as $dir) {
//Valid theme dir
if ($dir->isFile() || $dir->isDot()) {
continue;
}
$theme = $dir->getFilename();
$themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/';
// Check if this theme has its own filetype icons
if (!file_exists($themeDir)) {
continue;
}
$themes[$theme] = [];
// Fetch all the theme icons!
$themeIt = new \DirectoryIterator($themeDir);
foreach ($themeIt as $fileInfo) {
if ($fileInfo->isFile()) {
$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
$themes[$theme][] = $file;
}
}
//Remove Duplicates
$themes[$theme] = array_values(array_unique($themes[$theme]));
sort($themes[$theme]);
}
//Generate the JS
$js = '/**
* This file is automatically generated
* DO NOT EDIT MANUALLY!
*
* You can update the list of MimeType Aliases in config/mimetypealiases.json
* The list of files is fetched from core/img/filetypes
* To regenerate this file run ./occ maintenance:mimetype:update-js
*/
OC.MimeTypeList={
aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ',
files: ' . json_encode($files, JSON_PRETTY_PRINT) . ',
themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . '
};
';
// Output the JS
file_put_contents(\OC::$SERVERROOT.'/core/js/mimetypelist.js', $js);
$generatedMimetypeFile = new GenerateMimetypeFileBuilder();
file_put_contents(\OC::$SERVERROOT.'/core/js/mimetypelist.js', $generatedMimetypeFile->generateFile($aliases));
$output->writeln('<info>mimetypelist.js is updated');
}

View File

@ -675,6 +675,7 @@ return array(
'OC\\Core\\Command\\Log\\Manage' => $baseDir . '/core/Command/Log/Manage.php',
'OC\\Core\\Command\\Maintenance\\DataFingerprint' => $baseDir . '/core/Command/Maintenance/DataFingerprint.php',
'OC\\Core\\Command\\Maintenance\\Install' => $baseDir . '/core/Command/Maintenance/Install.php',
'OC\\Core\\Command\\Maintenance\\Mimetype\\GenerateMimetypeFileBuilder' => $baseDir . '/core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php',
'OC\\Core\\Command\\Maintenance\\Mimetype\\UpdateDB' => $baseDir . '/core/Command/Maintenance/Mimetype/UpdateDB.php',
'OC\\Core\\Command\\Maintenance\\Mimetype\\UpdateJS' => $baseDir . '/core/Command/Maintenance/Mimetype/UpdateJS.php',
'OC\\Core\\Command\\Maintenance\\Mode' => $baseDir . '/core/Command/Maintenance/Mode.php',

View File

@ -709,6 +709,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Core\\Command\\Log\\Manage' => __DIR__ . '/../../..' . '/core/Command/Log/Manage.php',
'OC\\Core\\Command\\Maintenance\\DataFingerprint' => __DIR__ . '/../../..' . '/core/Command/Maintenance/DataFingerprint.php',
'OC\\Core\\Command\\Maintenance\\Install' => __DIR__ . '/../../..' . '/core/Command/Maintenance/Install.php',
'OC\\Core\\Command\\Maintenance\\Mimetype\\GenerateMimetypeFileBuilder' => __DIR__ . '/../../..' . '/core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php',
'OC\\Core\\Command\\Maintenance\\Mimetype\\UpdateDB' => __DIR__ . '/../../..' . '/core/Command/Maintenance/Mimetype/UpdateDB.php',
'OC\\Core\\Command\\Maintenance\\Mimetype\\UpdateJS' => __DIR__ . '/../../..' . '/core/Command/Maintenance/Mimetype/UpdateJS.php',
'OC\\Core\\Command\\Maintenance\\Mode' => __DIR__ . '/../../..' . '/core/Command/Maintenance/Mode.php',

View File

@ -133,6 +133,12 @@ class Detection implements IMimeTypeDetector {
return $this->mimeTypeAlias;
}
public function getOnlyDefaultAliases() {
$this->loadMappings();
$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
return $this->mimeTypeAlias;
}
/**
* Add mimetype mappings if they are not yet present
*/

View File

@ -27,6 +27,7 @@ declare(strict_types=1);
namespace OC\IntegrityCheck;
use OC\Core\Command\Maintenance\Mimetype\GenerateMimetypeFileBuilder;
use OC\IntegrityCheck\Exceptions\InvalidSignatureException;
use OC\IntegrityCheck\Helpers\AppLocator;
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
@ -34,6 +35,7 @@ use OC\IntegrityCheck\Helpers\FileAccessHelper;
use OC\IntegrityCheck\Iterator\ExcludeFileByNameFilterIterator;
use OC\IntegrityCheck\Iterator\ExcludeFoldersByPathFilterIterator;
use OCP\App\IAppManager;
use OCP\Files\IMimeTypeDetector;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
@ -67,6 +69,8 @@ class Checker {
private $appManager;
/** @var ITempManager */
private $tempManager;
/** @var IMimeTypeDetector */
private $mimeTypeDetector;
/**
* @param EnvironmentHelper $environmentHelper
@ -76,6 +80,7 @@ class Checker {
* @param ICacheFactory $cacheFactory
* @param IAppManager $appManager
* @param ITempManager $tempManager
* @param IMimeTypeDetector $mimeTypeDetector
*/
public function __construct(EnvironmentHelper $environmentHelper,
FileAccessHelper $fileAccessHelper,
@ -83,7 +88,8 @@ class Checker {
IConfig $config = null,
ICacheFactory $cacheFactory,
IAppManager $appManager = null,
ITempManager $tempManager) {
ITempManager $tempManager,
IMimeTypeDetector $mimeTypeDetector) {
$this->environmentHelper = $environmentHelper;
$this->fileAccessHelper = $fileAccessHelper;
$this->appLocator = $appLocator;
@ -91,6 +97,7 @@ class Checker {
$this->cache = $cacheFactory->createDistributed(self::CACHE_KEY);
$this->appManager = $appManager;
$this->tempManager = $tempManager;
$this->mimeTypeDetector = $mimeTypeDetector;
}
/**
@ -193,6 +200,14 @@ class Checker {
continue;
}
}
if ($filename === $this->environmentHelper->getServerRoot() . '/core/js/mimetypelist.js') {
$oldMimetypeList = new GenerateMimetypeFileBuilder();
$newFile = $oldMimetypeList->generateFile($this->mimeTypeDetector->getAllAliases());
if($newFile === file_get_contents($filename)) {
$hashes[$relativeFileName] = hash('sha512', $oldMimetypeList->generateFile($this->mimeTypeDetector->getOnlyDefaultAliases()));
continue;
}
}
$hashes[$relativeFileName] = hash_file('sha512', $filename);
}

View File

@ -790,7 +790,8 @@ class Server extends ServerContainer implements IServerContainer {
$config,
$c->getMemCacheFactory(),
$appManager,
$c->getTempManager()
$c->getTempManager(),
$c->getMimeTypeDetector()
);
});
$this->registerService(\OCP\IRequest::class, function ($c) {

View File

@ -100,6 +100,7 @@
"text/x-ldif": "text/code",
"text/x-python": "text/code",
"text/x-shellscript": "text/code",
"web": "text/code"
"web": "text/code",
"application/internet-shortcut": "link"
}

View File

@ -0,0 +1,133 @@
/**
* This file is automatically generated
* DO NOT EDIT MANUALLY!
*
* You can update the list of MimeType Aliases in config/mimetypealiases.json
* The list of files is fetched from core/img/filetypes
* To regenerate this file run ./occ maintenance:mimetype:update-js
*/
OC.MimeTypeList={
aliases: {
"application/coreldraw": "image",
"application/test": "image",
"application/epub+zip": "text",
"application/font-sfnt": "image",
"application/font-woff": "image",
"application/gpx+xml": "location",
"application/illustrator": "image",
"application/javascript": "text/code",
"application/json": "text/code",
"application/msaccess": "file",
"application/msexcel": "x-office/spreadsheet",
"application/msonenote": "x-office/document",
"application/mspowerpoint": "x-office/presentation",
"application/msword": "x-office/document",
"application/octet-stream": "file",
"application/postscript": "image",
"application/rss+xml": "application/xml",
"application/vnd.android.package-archive": "package/x-generic",
"application/vnd.lotus-wordpro": "x-office/document",
"application/vnd.garmin.tcx+xml": "location",
"application/vnd.google-earth.kml+xml": "location",
"application/vnd.google-earth.kmz": "location",
"application/vnd.ms-excel": "x-office/spreadsheet",
"application/vnd.ms-excel.addin.macroEnabled.12": "x-office/spreadsheet",
"application/vnd.ms-excel.sheet.binary.macroEnabled.12": "x-office/spreadsheet",
"application/vnd.ms-excel.sheet.macroEnabled.12": "x-office/spreadsheet",
"application/vnd.ms-excel.template.macroEnabled.12": "x-office/spreadsheet",
"application/vnd.ms-fontobject": "image",
"application/vnd.ms-powerpoint": "x-office/presentation",
"application/vnd.ms-powerpoint.addin.macroEnabled.12": "x-office/presentation",
"application/vnd.ms-powerpoint.presentation.macroEnabled.12": "x-office/presentation",
"application/vnd.ms-powerpoint.slideshow.macroEnabled.12": "x-office/presentation",
"application/vnd.ms-powerpoint.template.macroEnabled.12": "x-office/presentation",
"application/vnd.ms-visio.drawing.macroEnabled.12": "application/vnd.visio",
"application/vnd.ms-visio.drawing": "application/vnd.visio",
"application/vnd.ms-visio.stencil.macroEnabled.12": "application/vnd.visio",
"application/vnd.ms-visio.stencil": "application/vnd.visio",
"application/vnd.ms-visio.template.macroEnabled.12": "application/vnd.visio",
"application/vnd.ms-visio.template": "application/vnd.visio",
"application/vnd.ms-word.document.macroEnabled.12": "x-office/document",
"application/vnd.ms-word.template.macroEnabled.12": "x-office/document",
"application/vnd.oasis.opendocument.presentation": "x-office/presentation",
"application/vnd.oasis.opendocument.presentation-template": "x-office/presentation",
"application/vnd.oasis.opendocument.spreadsheet": "x-office/spreadsheet",
"application/vnd.oasis.opendocument.spreadsheet-template": "x-office/spreadsheet",
"application/vnd.oasis.opendocument.text": "x-office/document",
"application/vnd.oasis.opendocument.text-master": "x-office/document",
"application/vnd.oasis.opendocument.text-template": "x-office/document",
"application/vnd.oasis.opendocument.text-web": "x-office/document",
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "x-office/presentation",
"application/vnd.openxmlformats-officedocument.presentationml.slideshow": "x-office/presentation",
"application/vnd.openxmlformats-officedocument.presentationml.template": "x-office/presentation",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "x-office/spreadsheet",
"application/vnd.openxmlformats-officedocument.spreadsheetml.template": "x-office/spreadsheet",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "x-office/document",
"application/vnd.openxmlformats-officedocument.wordprocessingml.template": "x-office/document",
"application/vnd.visio": "x-office/document",
"application/vnd.wordperfect": "x-office/document",
"application/x-7z-compressed": "package/x-generic",
"application/x-bzip2": "package/x-generic",
"application/x-cbr": "text",
"application/x-compressed": "package/x-generic",
"application/x-dcraw": "image",
"application/x-deb": "package/x-generic",
"application/x-fictionbook+xml": "text",
"application/x-font": "image",
"application/x-gimp": "image",
"application/x-gzip": "package/x-generic",
"application/x-iwork-keynote-sffkey": "x-office/presentation",
"application/x-iwork-numbers-sffnumbers": "x-office/spreadsheet",
"application/x-iwork-pages-sffpages": "x-office/document",
"application/x-mobipocket-ebook": "text",
"application/x-perl": "text/code",
"application/x-photoshop": "image",
"application/x-php": "text/code",
"application/x-rar-compressed": "package/x-generic",
"application/x-tar": "package/x-generic",
"application/x-tex": "text",
"application/xml": "text/html",
"application/yaml": "text/code",
"application/zip": "package/x-generic",
"database": "file",
"httpd/unix-directory": "dir",
"text/css": "text/code",
"text/csv": "x-office/spreadsheet",
"text/html": "text/code",
"text/x-c": "text/code",
"text/x-c++src": "text/code",
"text/x-h": "text/code",
"text/x-java-source": "text/code",
"text/x-ldif": "text/code",
"text/x-python": "text/code",
"text/x-shellscript": "text/code",
"web": "text/code",
"application/internet-shortcut": "link"
},
files: [
"application",
"application-pdf",
"audio",
"file",
"folder",
"folder-drag-accept",
"folder-encrypted",
"folder-external",
"folder-public",
"folder-shared",
"folder-starred",
"image",
"link",
"location",
"package-x-generic",
"text",
"text-calendar",
"text-code",
"text-vcard",
"video",
"x-office-document",
"x-office-presentation",
"x-office-spreadsheet"
],
themes: []
};

View File

@ -48,6 +48,8 @@ class CheckerTest extends TestCase {
private $cacheFactory;
/** @var IAppManager|\PHPUnit_Framework_MockObject_MockObject */
private $appManager;
/** @var \OC\Files\Type\Detection|\PHPUnit_Framework_MockObject_MockObject */
private $mimeTypeDetector;
public function setUp() {
parent::setUp();
@ -57,6 +59,7 @@ class CheckerTest extends TestCase {
$this->config = $this->createMock(IConfig::class);
$this->cacheFactory = $this->createMock(ICacheFactory::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->mimeTypeDetector = $this->createMock(\OC\Files\Type\Detection::class);
$this->config->method('getAppValue')
->will($this->returnArgument(2));
@ -74,7 +77,8 @@ class CheckerTest extends TestCase {
$this->config,
$this->cacheFactory,
$this->appManager,
\OC::$server->getTempManager()
\OC::$server->getTempManager(),
$this->mimeTypeDetector
);
}
@ -761,6 +765,262 @@ class CheckerTest extends TestCase {
$this->assertSame([], $this->checker->verifyCoreSignature());
}
public function testVerifyCoreSignatureWithModifiedMimetypelistSignatureData() {
$this->environmentHelper
->expects($this->once())
->method('getChannel')
->will($this->returnValue('stable'));
$this->config
->expects($this->any())
->method('getSystemValue')
->with('integrity.check.disabled', false)
->will($this->returnValue(false));
$this->mimeTypeDetector
->expects($this->once())
->method('getOnlyDefaultAliases')
->willReturn(
array (
'_comment' => 'Array of mimetype aliases.',
'_comment2' => 'Any changes you make here will be overwritten on an update of Nextcloud.',
'_comment3' => 'Put any custom mappings in a new file mimetypealiases.json in the config/ folder of Nextcloud',
'_comment4' => 'After any change to mimetypealiases.json run:',
'_comment5' => './occ maintenance:mimetype:update-js',
'_comment6' => 'Otherwise your update won\'t propagate through the system.',
'application/coreldraw' => 'image',
'application/epub+zip' => 'text',
'application/font-sfnt' => 'image',
'application/font-woff' => 'image',
'application/gpx+xml' => 'location',
'application/illustrator' => 'image',
'application/javascript' => 'text/code',
'application/json' => 'text/code',
'application/msaccess' => 'file',
'application/msexcel' => 'x-office/spreadsheet',
'application/msonenote' => 'x-office/document',
'application/mspowerpoint' => 'x-office/presentation',
'application/msword' => 'x-office/document',
'application/octet-stream' => 'file',
'application/postscript' => 'image',
'application/rss+xml' => 'application/xml',
'application/vnd.android.package-archive' => 'package/x-generic',
'application/vnd.lotus-wordpro' => 'x-office/document',
'application/vnd.garmin.tcx+xml' => 'location',
'application/vnd.google-earth.kml+xml' => 'location',
'application/vnd.google-earth.kmz' => 'location',
'application/vnd.ms-excel' => 'x-office/spreadsheet',
'application/vnd.ms-excel.addin.macroEnabled.12' => 'x-office/spreadsheet',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'x-office/spreadsheet',
'application/vnd.ms-excel.sheet.macroEnabled.12' => 'x-office/spreadsheet',
'application/vnd.ms-excel.template.macroEnabled.12' => 'x-office/spreadsheet',
'application/vnd.ms-fontobject' => 'image',
'application/vnd.ms-powerpoint' => 'x-office/presentation',
'application/vnd.ms-powerpoint.addin.macroEnabled.12' => 'x-office/presentation',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => 'x-office/presentation',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'x-office/presentation',
'application/vnd.ms-powerpoint.template.macroEnabled.12' => 'x-office/presentation',
'application/vnd.ms-visio.drawing.macroEnabled.12' => 'application/vnd.visio',
'application/vnd.ms-visio.drawing' => 'application/vnd.visio',
'application/vnd.ms-visio.stencil.macroEnabled.12' => 'application/vnd.visio',
'application/vnd.ms-visio.stencil' => 'application/vnd.visio',
'application/vnd.ms-visio.template.macroEnabled.12' => 'application/vnd.visio',
'application/vnd.ms-visio.template' => 'application/vnd.visio',
'application/vnd.ms-word.document.macroEnabled.12' => 'x-office/document',
'application/vnd.ms-word.template.macroEnabled.12' => 'x-office/document',
'application/vnd.oasis.opendocument.presentation' => 'x-office/presentation',
'application/vnd.oasis.opendocument.presentation-template' => 'x-office/presentation',
'application/vnd.oasis.opendocument.spreadsheet' => 'x-office/spreadsheet',
'application/vnd.oasis.opendocument.spreadsheet-template' => 'x-office/spreadsheet',
'application/vnd.oasis.opendocument.text' => 'x-office/document',
'application/vnd.oasis.opendocument.text-master' => 'x-office/document',
'application/vnd.oasis.opendocument.text-template' => 'x-office/document',
'application/vnd.oasis.opendocument.text-web' => 'x-office/document',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'x-office/presentation',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'x-office/presentation',
'application/vnd.openxmlformats-officedocument.presentationml.template' => 'x-office/presentation',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'x-office/spreadsheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'x-office/spreadsheet',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'x-office/document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'x-office/document',
'application/vnd.visio' => 'x-office/document',
'application/vnd.wordperfect' => 'x-office/document',
'application/x-7z-compressed' => 'package/x-generic',
'application/x-bzip2' => 'package/x-generic',
'application/x-cbr' => 'text',
'application/x-compressed' => 'package/x-generic',
'application/x-dcraw' => 'image',
'application/x-deb' => 'package/x-generic',
'application/x-fictionbook+xml' => 'text',
'application/x-font' => 'image',
'application/x-gimp' => 'image',
'application/x-gzip' => 'package/x-generic',
'application/x-iwork-keynote-sffkey' => 'x-office/presentation',
'application/x-iwork-numbers-sffnumbers' => 'x-office/spreadsheet',
'application/x-iwork-pages-sffpages' => 'x-office/document',
'application/x-mobipocket-ebook' => 'text',
'application/x-perl' => 'text/code',
'application/x-photoshop' => 'image',
'application/x-php' => 'text/code',
'application/x-rar-compressed' => 'package/x-generic',
'application/x-tar' => 'package/x-generic',
'application/x-tex' => 'text',
'application/xml' => 'text/html',
'application/yaml' => 'text/code',
'application/zip' => 'package/x-generic',
'database' => 'file',
'httpd/unix-directory' => 'dir',
'text/css' => 'text/code',
'text/csv' => 'x-office/spreadsheet',
'text/html' => 'text/code',
'text/x-c' => 'text/code',
'text/x-c++src' => 'text/code',
'text/x-h' => 'text/code',
'text/x-java-source' => 'text/code',
'text/x-ldif' => 'text/code',
'text/x-python' => 'text/code',
'text/x-shellscript' => 'text/code',
'web' => 'text/code',
'application/internet-shortcut' => 'link',
));
$this->mimeTypeDetector
->expects($this->once())
->method('getAllAliases')
->willReturn(
array (
'_comment' => 'Array of mimetype aliases.',
'_comment2' => 'Any changes you make here will be overwritten on an update of Nextcloud.',
'_comment3' => 'Put any custom mappings in a new file mimetypealiases.json in the config/ folder of Nextcloud',
'_comment4' => 'After any change to mimetypealiases.json run:',
'_comment5' => './occ maintenance:mimetype:update-js',
'_comment6' => 'Otherwise your update won\'t propagate through the system.',
'application/coreldraw' => 'image',
'application/test' => 'image',
'application/epub+zip' => 'text',
'application/font-sfnt' => 'image',
'application/font-woff' => 'image',
'application/gpx+xml' => 'location',
'application/illustrator' => 'image',
'application/javascript' => 'text/code',
'application/json' => 'text/code',
'application/msaccess' => 'file',
'application/msexcel' => 'x-office/spreadsheet',
'application/msonenote' => 'x-office/document',
'application/mspowerpoint' => 'x-office/presentation',
'application/msword' => 'x-office/document',
'application/octet-stream' => 'file',
'application/postscript' => 'image',
'application/rss+xml' => 'application/xml',
'application/vnd.android.package-archive' => 'package/x-generic',
'application/vnd.lotus-wordpro' => 'x-office/document',
'application/vnd.garmin.tcx+xml' => 'location',
'application/vnd.google-earth.kml+xml' => 'location',
'application/vnd.google-earth.kmz' => 'location',
'application/vnd.ms-excel' => 'x-office/spreadsheet',
'application/vnd.ms-excel.addin.macroEnabled.12' => 'x-office/spreadsheet',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'x-office/spreadsheet',
'application/vnd.ms-excel.sheet.macroEnabled.12' => 'x-office/spreadsheet',
'application/vnd.ms-excel.template.macroEnabled.12' => 'x-office/spreadsheet',
'application/vnd.ms-fontobject' => 'image',
'application/vnd.ms-powerpoint' => 'x-office/presentation',
'application/vnd.ms-powerpoint.addin.macroEnabled.12' => 'x-office/presentation',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => 'x-office/presentation',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'x-office/presentation',
'application/vnd.ms-powerpoint.template.macroEnabled.12' => 'x-office/presentation',
'application/vnd.ms-visio.drawing.macroEnabled.12' => 'application/vnd.visio',
'application/vnd.ms-visio.drawing' => 'application/vnd.visio',
'application/vnd.ms-visio.stencil.macroEnabled.12' => 'application/vnd.visio',
'application/vnd.ms-visio.stencil' => 'application/vnd.visio',
'application/vnd.ms-visio.template.macroEnabled.12' => 'application/vnd.visio',
'application/vnd.ms-visio.template' => 'application/vnd.visio',
'application/vnd.ms-word.document.macroEnabled.12' => 'x-office/document',
'application/vnd.ms-word.template.macroEnabled.12' => 'x-office/document',
'application/vnd.oasis.opendocument.presentation' => 'x-office/presentation',
'application/vnd.oasis.opendocument.presentation-template' => 'x-office/presentation',
'application/vnd.oasis.opendocument.spreadsheet' => 'x-office/spreadsheet',
'application/vnd.oasis.opendocument.spreadsheet-template' => 'x-office/spreadsheet',
'application/vnd.oasis.opendocument.text' => 'x-office/document',
'application/vnd.oasis.opendocument.text-master' => 'x-office/document',
'application/vnd.oasis.opendocument.text-template' => 'x-office/document',
'application/vnd.oasis.opendocument.text-web' => 'x-office/document',
'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'x-office/presentation',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'x-office/presentation',
'application/vnd.openxmlformats-officedocument.presentationml.template' => 'x-office/presentation',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'x-office/spreadsheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'x-office/spreadsheet',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'x-office/document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'x-office/document',
'application/vnd.visio' => 'x-office/document',
'application/vnd.wordperfect' => 'x-office/document',
'application/x-7z-compressed' => 'package/x-generic',
'application/x-bzip2' => 'package/x-generic',
'application/x-cbr' => 'text',
'application/x-compressed' => 'package/x-generic',
'application/x-dcraw' => 'image',
'application/x-deb' => 'package/x-generic',
'application/x-fictionbook+xml' => 'text',
'application/x-font' => 'image',
'application/x-gimp' => 'image',
'application/x-gzip' => 'package/x-generic',
'application/x-iwork-keynote-sffkey' => 'x-office/presentation',
'application/x-iwork-numbers-sffnumbers' => 'x-office/spreadsheet',
'application/x-iwork-pages-sffpages' => 'x-office/document',
'application/x-mobipocket-ebook' => 'text',
'application/x-perl' => 'text/code',
'application/x-photoshop' => 'image',
'application/x-php' => 'text/code',
'application/x-rar-compressed' => 'package/x-generic',
'application/x-tar' => 'package/x-generic',
'application/x-tex' => 'text',
'application/xml' => 'text/html',
'application/yaml' => 'text/code',
'application/zip' => 'package/x-generic',
'database' => 'file',
'httpd/unix-directory' => 'dir',
'text/css' => 'text/code',
'text/csv' => 'x-office/spreadsheet',
'text/html' => 'text/code',
'text/x-c' => 'text/code',
'text/x-c++src' => 'text/code',
'text/x-h' => 'text/code',
'text/x-java-source' => 'text/code',
'text/x-ldif' => 'text/code',
'text/x-python' => 'text/code',
'text/x-shellscript' => 'text/code',
'web' => 'text/code',
'application/internet-shortcut' => 'link',
));
$this->environmentHelper
->expects($this->any())
->method('getServerRoot')
->will($this->returnValue(\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified'));
$signatureDataFile = '{
"hashes": {
"mimetypelist.js": "dc48de7ad4baa030c5e563350c9a80b274bad783f6f5adbf1595ecef6c6a32e52890a24cb26cddb0aa20193ba52c001150c68d8bfb567f0aed566f4029a190a3"
},
"signature": "dtNDyufRB1jOG3e\/\/Ng6O3ZPnX5wgt3rrD9SpRQ66cpWlixwvGaI6knH85MkWm3q1c+hTYBipJ\/o+nJxHWoxydMXm+F6mC5MvXWfESB\/ag4fvKe0fg25yKstzlrpIyWwcnmOhLE\/sd7D8LZOQXk72PXsIJw4vX2YPyf3peHLevlUkVhB+mfYGDQJfrtPHjJII0Do+TV2MA0qm42q7SO\/zf7Ly24nZP3AoY5bYDMewlrczS2xz9tMN2ikZZcDgHvmC2W4RkaFP9E8ZeAZphKVjyQn6HdSu7EDlJgJ1YtoqTetFzNy\/q7+ODiJDB0KUzKocEDcXF2n2cTKXKCrklB6tEhEnjADhhQNxQouq2soc0ouIujifyH2zBL0sawNxGje5wpuchhCPnWcvQnSJbK1oXnv\/0wSGsp0iSslvx9NXAZ+nQbJnIuodLBl7XuTxxPVa8jDwFdJ7mLrs79ZfN2Op4qF10PiFRoz5VztJm4KWcaWnm\/Xqxke\/6yxY+gU2c6aH\/plwzkcxhdDJjNI\/d+G+b6NSadfcrduO+gTeHK\/go68mx0k1XxCln4Qu31nPmJZcboTvAtHvHXoeqZVAzMpT+jrq+vZ3oVAvFfNpvH4CA3eZebfkV13wV4RaSETyz5QNbnBL24C26aAhkzdShKHJc4NSNV9XdFqN74XEzSZGoc=",
"certificate": "-----BEGIN CERTIFICATE-----\r\nMIIEvjCCAqagAwIBAgIUc\/0FxYrsgSs9rDxp03EJmbjN0NwwDQYJKoZIhvcNAQEF\r\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTEw\r\nMzIxMDMzM1oXDTE2MTEwMzIxMDMzM1owDzENMAsGA1UEAwwEY29yZTCCAiIwDQYJ\r\nKoZIhvcNAQEBBQADggIPADCCAgoCggIBALb6EgHpkAqZbO5vRO8XSh7G7XGWHw5s\r\niOf4RwPXR6SE9bWZEm\/b72SfWk\/\/J6AbrD8WiOzBuT\/ODy6k5T1arEdHO+Pux0W1\r\nMxYJJI4kH74KKgMpC0SB0Rt+8WrMqV1r3hhJ46df6Xr\/xolP3oD+eLbShPcblhdS\r\nVtkZEkoev8Sh6L2wDCeHDyPxzvj1w2dTdGVO9Kztn0xIlyfEBakqvBWtcxyi3Ln0\r\nklnxlMx3tPDUE4kqvpia9qNiB1AN2PV93eNr5\/2riAzIssMFSCarWCx0AKYb54+d\r\nxLpcYFyqPJ0ydBCkF78DD45RCZet6PNYkdzgbqlUWEGGomkuDoJbBg4wzgzO0D77\r\nH87KFhYW8tKFFvF1V3AHl\/sFQ9tDHaxM9Y0pZ2jPp\/ccdiqnmdkBxBDqsiRvHvVB\r\nCn6qpb4vWGFC7vHOBfYspmEL1zLlKXZv3ezMZEZw7O9ZvUP3VO\/wAtd2vUW8UFiq\r\ns2v1QnNLN6jNh51obcwmrBvWhJy9vQIdtIjQbDxqWTHh1zUSrw9wrlklCBZ\/zrM0\r\ni8nfCFwTxWRxp3H9KoECzO\/zS5R5KIS7s3\/wq\/w9T2Ie4rcecgXwDizwnn0C\/aKc\r\nbDIjujpL1s9HO05pcD\/V3wKcPZ1izymBkmMyIbL52iRVN5FTVHeZdXPpFuq+CTQJ\r\nQ238lC+A\/KOVAgMBAAEwDQYJKoZIhvcNAQEFBQADggIBAGoKTnh8RfJV4sQItVC2\r\nAvfJagkrIqZ3iiQTUBQGTKBsTnAqE1H7QgUSV9vSd+8rgvHkyZsRjmtyR1e3A6Ji\r\noNCXUbExC\/0iCPUqdHZIVb+Lc\/vWuv4ByFMybGPydgtLoEUX2ZrKFWmcgZFDUSRd\r\n9Uj26vtUhCC4bU4jgu6hIrR9IuxOBLQUxGTRZyAcXvj7obqRAEZwFAKQgFpfpqTb\r\nH+kjcbZSaAlLVSF7vBc1syyI8RGYbqpwvtREqJtl5IEIwe6huEqJ3zPnlP2th\/55\r\ncf3Fovj6JJgbb9XFxrdnsOsDOu\/tpnaRWlvv5ib4+SzG5wWFT5UUEo4Wg2STQiiX\r\nuVSRQxK1LE1yg84bs3NZk9FSQh4B8vZVuRr5FaJsZZkwlFlhRO\/\/+TJtXRbyNgsf\r\noMRZGi8DLGU2SGEAHcRH\/QZHq\/XDUWVzdxrSBYcy7GSpT7UDVzGv1rEJUrn5veP1\r\n0KmauAqtiIaYRm4f6YBsn0INcZxzIPZ0p8qFtVZBPeHhvQtvOt0iXI\/XUxEWOa2F\r\nK2EqhErgMK\/N07U1JJJay5tYZRtvkGq46oP\/5kQG8hYST0MDK6VihJoPpvCmAm4E\r\npEYKQ96x6A4EH9Y9mZlYozH\/eqmxPbTK8n89\/p7Ydun4rI+B2iiLnY8REWWy6+UQ\r\nV204fGUkJqW5CrKy3P3XvY9X\r\n-----END CERTIFICATE-----"
}';
$this->fileAccessHelper
->expects($this->at(0))
->method('file_get_contents')
->with(
\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/core/signature.json'
)
->will($this->returnValue($signatureDataFile));
$this->fileAccessHelper
->expects($this->at(1))
->method('file_get_contents')
->with(
\OC::$SERVERROOT . '/tests/data/integritycheck/mimetypeListModified/resources/codesigning/root.crt'
)
->will($this->returnValue(file_get_contents(__DIR__ .'/../../data/integritycheck/root.crt')));
$this->assertSame([], $this->checker->verifyCoreSignature());
}
public function testVerifyCoreSignatureWithValidSignatureDataAndNotAlphabeticOrder() {
$this->environmentHelper
->expects($this->once())
@ -1014,7 +1274,8 @@ class CheckerTest extends TestCase {
$this->config,
$this->cacheFactory,
$this->appManager,
\OC::$server->getTempManager()
\OC::$server->getTempManager(),
$this->mimeTypeDetector,
])
->setMethods([
'verifyCoreSignature',