]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow specifing the signing path
authorLukas Reschke <lukas@owncloud.com>
Wed, 3 Feb 2016 18:56:38 +0000 (19:56 +0100)
committerLukas Reschke <lukas@owncloud.com>
Wed, 3 Feb 2016 19:08:40 +0000 (20:08 +0100)
core/command/integrity/signcore.php
lib/private/integritycheck/checker.php
lib/private/integritycheck/iterator/excludefoldersbypathfilteriterator.php
tests/lib/command/integrity/SignCoreTest.php
tests/lib/integritycheck/checkertest.php

index 531a4d33aa33404da3e4ec5f8a1a8656b26067ff..e5c2de73e002a286d7e20faf77510633a3174809 100644 (file)
@@ -59,7 +59,8 @@ class SignCore extends Command {
                        ->setName('integrity:sign-core')
                        ->setDescription('Sign core using a private key.')
                        ->addOption('privateKey', null, InputOption::VALUE_REQUIRED, 'Path to private key to use for signing')
-                       ->addOption('certificate', null, InputOption::VALUE_REQUIRED, 'Path to certificate to use for signing');
+                       ->addOption('certificate', null, InputOption::VALUE_REQUIRED, 'Path to certificate to use for signing')
+                       ->addOption('path', null, InputOption::VALUE_REQUIRED, 'Path of core to sign');
        }
 
        /**
@@ -68,8 +69,9 @@ class SignCore extends Command {
        protected function execute(InputInterface $input, OutputInterface $output) {
                $privateKeyPath = $input->getOption('privateKey');
                $keyBundlePath = $input->getOption('certificate');
-               if(is_null($privateKeyPath) || is_null($keyBundlePath)) {
-                       $output->writeln('--privateKey and --certificate are required.');
+               $path = $input->getOption('path');
+               if(is_null($privateKeyPath) || is_null($keyBundlePath) || is_null($path)) {
+                       $output->writeln('--privateKey, --certificate and --path are required.');
                        return null;
                }
 
@@ -91,7 +93,7 @@ class SignCore extends Command {
                $x509 = new X509();
                $x509->loadX509($keyBundle);
                $x509->setPrivateKey($rsa);
-               $this->checker->writeCoreSignature($x509, $rsa);
+               $this->checker->writeCoreSignature($x509, $rsa, $path);
 
                $output->writeln('Successfully signed "core"');
        }
index c256fe66d32d736b8bd46f8075c893625b3b670b..352b18f672e458f8515cabfc96c004805413e2be 100644 (file)
@@ -113,16 +113,22 @@ class Checker {
         * Enumerates all files belonging to the folder. Sensible defaults are excluded.
         *
         * @param string $folderToIterate
+        * @param string $root
         * @return \RecursiveIteratorIterator
         * @throws \Exception
         */
-       private function getFolderIterator($folderToIterate) {
+       private function getFolderIterator($folderToIterate, $root = '') {
                $dirItr = new \RecursiveDirectoryIterator(
                        $folderToIterate,
                        \RecursiveDirectoryIterator::SKIP_DOTS
                );
+               if($root === '') {
+                       $root = \OC::$SERVERROOT;
+               }
+               $root = rtrim($root, '/');
+
                $excludeGenericFilesIterator = new ExcludeFileByNameFilterIterator($dirItr);
-               $excludeFoldersIterator = new ExcludeFoldersByPathFilterIterator($excludeGenericFilesIterator);
+               $excludeFoldersIterator = new ExcludeFoldersByPathFilterIterator($excludeGenericFilesIterator, $root);
 
                return new \RecursiveIteratorIterator(
                        $excludeFoldersIterator,
@@ -234,14 +240,16 @@ class Checker {
         *
         * @param X509 $certificate
         * @param RSA $rsa
+        * @param string $path
         */
        public function writeCoreSignature(X509 $certificate,
-                                                                          RSA $rsa) {
-               $iterator = $this->getFolderIterator($this->environmentHelper->getServerRoot());
-               $hashes = $this->generateHashes($iterator, $this->environmentHelper->getServerRoot());
+                                                                          RSA $rsa,
+                                                                          $path) {
+               $iterator = $this->getFolderIterator($path, $path);
+               $hashes = $this->generateHashes($iterator, $path);
                $signatureData = $this->createSignatureData($hashes, $certificate, $rsa);
                $this->fileAccessHelper->file_put_contents(
-                               $this->environmentHelper->getServerRoot() . '/core/signature.json',
+                               $path . '/core/signature.json',
                                json_encode($signatureData, JSON_PRETTY_PRINT)
                );
        }
index c3994197fc6055c753dd6e420897fd2695b06fab..67bcd423b68761d11de90fa63634ec0b669766be 100644 (file)
@@ -24,7 +24,7 @@ namespace OC\IntegrityCheck\Iterator;
 class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator {
        private $excludedFolders = [];
 
-       public function __construct(\RecursiveIterator $iterator) {
+       public function __construct(\RecursiveIterator $iterator, $root = '') {
                parent::__construct($iterator);
 
                $appFolders = \OC::$APPSROOTS;
@@ -33,9 +33,10 @@ class ExcludeFoldersByPathFilterIterator extends \RecursiveFilterIterator {
                }
 
                $this->excludedFolders = array_merge([
-                       rtrim(\OC::$server->getConfig()->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'), '/'),
-                       rtrim(\OC::$SERVERROOT.'/themes', '/'),
-                       rtrim(\OC::$SERVERROOT.'/config', '/'),
+                       rtrim($root . '/data', '/'),
+                       rtrim($root .'/themes', '/'),
+                       rtrim($root.'/config', '/'),
+                       rtrim($root.'/apps', '/'),
                ], $appFolders);
        }
 
index 885c6fc664eec087dbf4df21d2ff3bd6def1d45c..ff1f6b23a95ba248a8395cf6f2b5a9db20418c61 100644 (file)
@@ -63,7 +63,7 @@ class SignCoreTest extends TestCase {
                $outputInterface
                        ->expects($this->at(0))
                        ->method('writeln')
-                       ->with('--privateKey and --certificate are required.');
+                       ->with('--privateKey, --certificate and --path are required.');
 
                $this->invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]);
        }
@@ -86,7 +86,7 @@ class SignCoreTest extends TestCase {
                $outputInterface
                        ->expects($this->at(0))
                        ->method('writeln')
-                       ->with('--privateKey and --certificate are required.');
+                       ->with('--privateKey, --certificate and --path are required.');
 
                $this->invokePrivate($this->signCore, 'execute', [$inputInterface, $outputInterface]);
        }
@@ -105,6 +105,11 @@ class SignCoreTest extends TestCase {
                        ->method('getOption')
                        ->with('certificate')
                        ->will($this->returnValue('certificate'));
+               $inputInterface
+                               ->expects($this->at(2))
+                               ->method('getOption')
+                               ->with('path')
+                               ->will($this->returnValue('certificate'));
 
                $this->fileAccessHelper
                        ->expects($this->at(0))
@@ -134,6 +139,11 @@ class SignCoreTest extends TestCase {
                        ->method('getOption')
                        ->with('certificate')
                        ->will($this->returnValue('certificate'));
+               $inputInterface
+                               ->expects($this->at(2))
+                               ->method('getOption')
+                               ->with('path')
+                               ->will($this->returnValue('certificate'));
 
                $this->fileAccessHelper
                        ->expects($this->at(0))
@@ -168,6 +178,11 @@ class SignCoreTest extends TestCase {
                        ->method('getOption')
                        ->with('certificate')
                        ->will($this->returnValue('certificate'));
+               $inputInterface
+                               ->expects($this->at(2))
+                               ->method('getOption')
+                               ->with('path')
+                               ->will($this->returnValue('certificate'));
 
                $this->fileAccessHelper
                        ->expects($this->at(0))
index dec3ea84a64cb6d9e1faf7592455a518fb43a730..fac60b0c123c4cae43e5c0fd125aff448a7a6150 100644 (file)
@@ -465,7 +465,7 @@ class CheckerTest extends TestCase {
                $rsa->loadKey($rsaPrivateKey);
                $x509 = new X509();
                $x509->loadX509($keyBundle);
-               $this->checker->writeCoreSignature($x509, $rsa);
+               $this->checker->writeCoreSignature($x509, $rsa, \OC::$SERVERROOT . '/tests/data/integritycheck/app/');
        }
 
        public function testWriteCoreSignatureWithUnmodifiedHtaccess() {
@@ -495,7 +495,7 @@ class CheckerTest extends TestCase {
                $rsa->loadKey($rsaPrivateKey);
                $x509 = new X509();
                $x509->loadX509($keyBundle);
-               $this->checker->writeCoreSignature($x509, $rsa);
+               $this->checker->writeCoreSignature($x509, $rsa, \OC::$SERVERROOT . '/tests/data/integritycheck/htaccessUnmodified/');
        }
 
        public function testWriteCoreSignatureWithInvalidModifiedHtaccess() {
@@ -506,10 +506,6 @@ class CheckerTest extends TestCase {
     "signature": "qpDddYGgAKNR3TszOgjPXRphUl2P9Ym5OQaetltocgZASGDkOun5D64+1D0QJRKb4SG2+48muxGOHyL2Ngos4NUrrSR+SIkywZacay82YQBCEdr7\/4MjW1WHRPjvboLwEJwViw0EdAjsWRpD68aPnzUGrGsy2BsCo06P5iwjk9cXcHxdjC9R39npvoC3QNvQ2jmNIbh1Lc4U97dbb+CsXEQCLU1OSa9p3q6cEFV98Easwt7uF\/DzHK+CbeZlxVZ0DwLh2\/ylT1PyGou8QC1b3vKAnPjLWMO+UsCPpCKhk3C5pV+5etQ8puGd+0x2t5tEU+qXxLzek91zWNC+rqgC\/WlqLKbwPb\/BCHs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P3XvY9X\r\n-----END CERTIFICATE-----"
 }';
-               $this->environmentHelper
-                               ->expects($this->any())
-                               ->method('getServerRoot')
-                               ->will($this->returnValue(\OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithInvalidModifiedContent/'));
                $this->fileAccessHelper
                                ->expects($this->once())
                                ->method('file_put_contents')
@@ -524,7 +520,7 @@ class CheckerTest extends TestCase {
                $rsa->loadKey($rsaPrivateKey);
                $x509 = new X509();
                $x509->loadX509($keyBundle);
-               $this->checker->writeCoreSignature($x509, $rsa);
+               $this->checker->writeCoreSignature($x509, $rsa, \OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithInvalidModifiedContent/');
        }
 
        public function testWriteCoreSignatureWithValidModifiedHtaccess() {
@@ -554,7 +550,7 @@ class CheckerTest extends TestCase {
                $rsa->loadKey($rsaPrivateKey);
                $x509 = new X509();
                $x509->loadX509($keyBundle);
-               $this->checker->writeCoreSignature($x509, $rsa);
+               $this->checker->writeCoreSignature($x509, $rsa, \OC::$SERVERROOT . '/tests/data/integritycheck/htaccessWithValidModifiedContent');
        }
 
        public function testVerifyCoreSignatureWithoutSignatureData() {