summaryrefslogtreecommitdiffstats
path: root/core/Command/Integrity
diff options
context:
space:
mode:
authorLukas Reschke <lukas@owncloud.com>2016-04-06 10:40:55 +0200
committerLukas Reschke <lukas@owncloud.com>2016-04-06 11:00:52 +0200
commita4b19a5b1e4079752e33d6eb75c72a47ce048bde (patch)
treedb63cde4a4c0c69fd7c284331ba84367a93279f6 /core/Command/Integrity
parent046506dd146f823499098d0d2b0042072e436469 (diff)
downloadnextcloud-server-a4b19a5b1e4079752e33d6eb75c72a47ce048bde.tar.gz
nextcloud-server-a4b19a5b1e4079752e33d6eb75c72a47ce048bde.zip
Rename files to be PSR-4 compliant
Diffstat (limited to 'core/Command/Integrity')
-rw-r--r--core/Command/Integrity/CheckApp.php69
-rw-r--r--core/Command/Integrity/CheckCore.php62
-rw-r--r--core/Command/Integrity/SignApp.php107
-rw-r--r--core/Command/Integrity/SignCore.php100
4 files changed, 338 insertions, 0 deletions
diff --git a/core/Command/Integrity/CheckApp.php b/core/Command/Integrity/CheckApp.php
new file mode 100644
index 00000000000..643af5285b4
--- /dev/null
+++ b/core/Command/Integrity/CheckApp.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * @author Victor Dubiniuk <dubiniuk@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+namespace OC\Core\Command\Integrity;
+
+use OC\IntegrityCheck\Checker;
+use OC\Core\Command\Base;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Class CheckApp
+ *
+ * @package OC\Core\Command\Integrity
+ */
+class CheckApp extends Base {
+
+ /**
+ * @var Checker
+ */
+ private $checker;
+
+ public function __construct(Checker $checker) {
+ parent::__construct();
+ $this->checker = $checker;
+ }
+
+ /**
+ * {@inheritdoc }
+ */
+ protected function configure() {
+ parent::configure();
+ $this
+ ->setName('integrity:check-app')
+ ->setDescription('Check integrity of an app using a signature.')
+ ->addArgument('appid', null, InputArgument::REQUIRED, 'Application to check')
+ ->addOption('path', null, InputOption::VALUE_OPTIONAL, 'Path to application. If none is given it will be guessed.');
+ }
+
+ /**
+ * {@inheritdoc }
+ */
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $appid = $input->getArgument('appid');
+ $path = strval($input->getOption('path'));
+ $result = $this->checker->verifyAppSignature($appid, $path);
+ $this->writeArrayInOutputFormat($input, $output, $result);
+ }
+
+}
diff --git a/core/Command/Integrity/CheckCore.php b/core/Command/Integrity/CheckCore.php
new file mode 100644
index 00000000000..460a78e4da7
--- /dev/null
+++ b/core/Command/Integrity/CheckCore.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * @author Victor Dubiniuk <dubiniuk@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Core\Command\Integrity;
+
+use OC\IntegrityCheck\Checker;
+use OC\Core\Command\Base;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Class CheckCore
+ *
+ * @package OC\Core\Command\Integrity
+ */
+class CheckCore extends Base {
+ /**
+ * @var Checker
+ */
+ private $checker;
+
+ public function __construct(Checker $checker) {
+ parent::__construct();
+ $this->checker = $checker;
+ }
+
+ /**
+ * {@inheritdoc }
+ */
+ protected function configure() {
+ parent::configure();
+ $this
+ ->setName('integrity:check-core')
+ ->setDescription('Check integrity of core code using a signature.');
+ }
+
+ /**
+ * {@inheritdoc }
+ */
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $result = $this->checker->verifyCoreSignature();
+ $this->writeArrayInOutputFormat($input, $output, $result);
+ }
+}
diff --git a/core/Command/Integrity/SignApp.php b/core/Command/Integrity/SignApp.php
new file mode 100644
index 00000000000..53df9619c6d
--- /dev/null
+++ b/core/Command/Integrity/SignApp.php
@@ -0,0 +1,107 @@
+<?php
+/**
+ * @author Lukas Reschke <lukas@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Core\Command\Integrity;
+
+use OC\IntegrityCheck\Checker;
+use OC\IntegrityCheck\Helpers\FileAccessHelper;
+use OCP\IURLGenerator;
+use phpseclib\Crypt\RSA;
+use phpseclib\File\X509;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Class SignApp
+ *
+ * @package OC\Core\Command\Integrity
+ */
+class SignApp extends Command {
+ /** @var Checker */
+ private $checker;
+ /** @var FileAccessHelper */
+ private $fileAccessHelper;
+ /** @var IURLGenerator */
+ private $urlGenerator;
+
+ /**
+ * @param Checker $checker
+ * @param FileAccessHelper $fileAccessHelper
+ * @param IURLGenerator $urlGenerator
+ */
+ public function __construct(Checker $checker,
+ FileAccessHelper $fileAccessHelper,
+ IURLGenerator $urlGenerator) {
+ parent::__construct(null);
+ $this->checker = $checker;
+ $this->fileAccessHelper = $fileAccessHelper;
+ $this->urlGenerator = $urlGenerator;
+ }
+
+ protected function configure() {
+ $this
+ ->setName('integrity:sign-app')
+ ->setDescription('Signs an app using a private key.')
+ ->addOption('path', null, InputOption::VALUE_REQUIRED, 'Application to sign')
+ ->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');
+ }
+
+ /**
+ * {@inheritdoc }
+ */
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $path = $input->getOption('path');
+ $privateKeyPath = $input->getOption('privateKey');
+ $keyBundlePath = $input->getOption('certificate');
+ if(is_null($path) || is_null($privateKeyPath) || is_null($keyBundlePath)) {
+ $documentationUrl = $this->urlGenerator->linkToDocs('developer-code-integrity');
+ $output->writeln('This command requires the --path, --privateKey and --certificate.');
+ $output->writeln('Example: ./occ integrity:sign-app --path="/Users/lukasreschke/Programming/myapp/" --privateKey="/Users/lukasreschke/private/myapp.key" --certificate="/Users/lukasreschke/public/mycert.crt"');
+ $output->writeln('For more information please consult the documentation: '. $documentationUrl);
+ return null;
+ }
+
+ $privateKey = $this->fileAccessHelper->file_get_contents($privateKeyPath);
+ $keyBundle = $this->fileAccessHelper->file_get_contents($keyBundlePath);
+
+ if($privateKey === false) {
+ $output->writeln(sprintf('Private key "%s" does not exists.', $privateKeyPath));
+ return null;
+ }
+
+ if($keyBundle === false) {
+ $output->writeln(sprintf('Certificate "%s" does not exists.', $keyBundlePath));
+ return null;
+ }
+
+ $rsa = new RSA();
+ $rsa->loadKey($privateKey);
+ $x509 = new X509();
+ $x509->loadX509($keyBundle);
+ $x509->setPrivateKey($rsa);
+ $this->checker->writeAppSignature($path, $x509, $rsa);
+
+ $output->writeln('Successfully signed "'.$path.'"');
+ }
+}
diff --git a/core/Command/Integrity/SignCore.php b/core/Command/Integrity/SignCore.php
new file mode 100644
index 00000000000..e5c2de73e00
--- /dev/null
+++ b/core/Command/Integrity/SignCore.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * @author Lukas Reschke <lukas@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC\Core\Command\Integrity;
+
+use OC\IntegrityCheck\Checker;
+use OC\IntegrityCheck\Helpers\EnvironmentHelper;
+use OC\IntegrityCheck\Helpers\FileAccessHelper;
+use phpseclib\Crypt\RSA;
+use phpseclib\File\X509;
+use Symfony\Component\Console\Command\Command;
+use OCP\IConfig;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Class SignCore
+ *
+ * @package OC\Core\Command\Integrity
+ */
+class SignCore extends Command {
+ /** @var Checker */
+ private $checker;
+ /** @var FileAccessHelper */
+ private $fileAccessHelper;
+
+ /**
+ * @param Checker $checker
+ * @param FileAccessHelper $fileAccessHelper
+ */
+ public function __construct(Checker $checker,
+ FileAccessHelper $fileAccessHelper) {
+ parent::__construct(null);
+ $this->checker = $checker;
+ $this->fileAccessHelper = $fileAccessHelper;
+ }
+
+ protected function configure() {
+ $this
+ ->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('path', null, InputOption::VALUE_REQUIRED, 'Path of core to sign');
+ }
+
+ /**
+ * {@inheritdoc }
+ */
+ protected function execute(InputInterface $input, OutputInterface $output) {
+ $privateKeyPath = $input->getOption('privateKey');
+ $keyBundlePath = $input->getOption('certificate');
+ $path = $input->getOption('path');
+ if(is_null($privateKeyPath) || is_null($keyBundlePath) || is_null($path)) {
+ $output->writeln('--privateKey, --certificate and --path are required.');
+ return null;
+ }
+
+ $privateKey = $this->fileAccessHelper->file_get_contents($privateKeyPath);
+ $keyBundle = $this->fileAccessHelper->file_get_contents($keyBundlePath);
+
+ if($privateKey === false) {
+ $output->writeln(sprintf('Private key "%s" does not exists.', $privateKeyPath));
+ return null;
+ }
+
+ if($keyBundle === false) {
+ $output->writeln(sprintf('Certificate "%s" does not exists.', $keyBundlePath));
+ return null;
+ }
+
+ $rsa = new RSA();
+ $rsa->loadKey($privateKey);
+ $x509 = new X509();
+ $x509->loadX509($keyBundle);
+ $x509->setPrivateKey($rsa);
+ $this->checker->writeCoreSignature($x509, $rsa, $path);
+
+ $output->writeln('Successfully signed "core"');
+ }
+}