2015-03-26 16:51:33 +03:00
< ? php
/**
* @ copyright Copyright ( c ) 2015 , ownCloud , Inc .
2019-12-03 21:57:53 +03:00
*
* @ author Bjoern Schiessle < bjoern @ schiessle . org >
* @ author Christoph Wurst < christoph @ winzerhof - wurst . at >
* @ author Daniel Kesselberg < mail @ danielkesselberg . de >
* @ author Joas Schilling < coding @ schilljs . com >
* @ author Kyle Fazzari < kyrofa @ ubuntu . com >
* @ author Lukas Reschke < lukas @ statuscode . ch >
* @ author Michael Weimann < mail @ michael - weimann . eu >
* @ author Morris Jobke < hey @ morrisjobke . de >
* @ author Robin Appelman < robin @ icewind . nl >
* @ author Robin McCorkell < robin @ mccorkell . me . uk >
* @ author Roeland Jago Douma < roeland @ famdouma . nl >
* @ author Sylvia van Os < sylvia @ hackerchick . me >
* @ author Thomas Müller < thomas . mueller @ tmit . eu >
* @ author Timo Förster < tfoerster @ webfoersterei . de >
*
2015-03-26 16:51:33 +03:00
* @ 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 ,
2019-12-03 21:57:53 +03:00
* along with this program . If not , see < http :// www . gnu . org / licenses />
2015-03-26 16:51:33 +03:00
*
*/
2019-09-17 17:33:27 +03:00
namespace OCA\Settings\Tests\Controller ;
2015-03-26 16:51:33 +03:00
2020-08-20 17:35:14 +03:00
use bantu\IniGetWrapper\IniGetWrapper ;
2018-08-09 20:48:19 +03:00
use OC ;
2018-06-13 12:45:49 +03:00
use OC\DB\Connection ;
2019-11-22 22:52:10 +03:00
use OC\IntegrityCheck\Checker ;
2018-08-04 21:39:51 +03:00
use OC\MemoryInfo ;
2018-07-27 12:20:47 +03:00
use OC\Security\SecureRandom ;
2019-09-17 17:33:27 +03:00
use OCA\Settings\Controller\CheckSetupController ;
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
use OCP\AppFramework\Http ;
use OCP\AppFramework\Http\DataDisplayResponse ;
2015-03-26 16:51:33 +03:00
use OCP\AppFramework\Http\DataResponse ;
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
use OCP\AppFramework\Http\RedirectResponse ;
2015-03-26 16:51:33 +03:00
use OCP\Http\Client\IClientService ;
2015-04-07 12:11:31 +03:00
use OCP\IConfig ;
2018-06-13 12:45:49 +03:00
use OCP\IDateTimeFormatter ;
2015-07-27 17:29:05 +03:00
use OCP\IL10N ;
2016-08-15 17:24:56 +03:00
use OCP\ILogger ;
2015-04-07 12:11:31 +03:00
use OCP\IRequest ;
use OCP\IURLGenerator ;
2018-06-13 12:45:49 +03:00
use OCP\Lock\ILockingProvider ;
2018-08-04 21:39:51 +03:00
use PHPUnit\Framework\MockObject\MockObject ;
2018-02-13 16:59:20 +03:00
use Psr\Http\Message\ResponseInterface ;
2019-05-28 20:46:36 +03:00
use Symfony\Component\EventDispatcher\EventDispatcherInterface ;
2015-04-07 12:11:31 +03:00
use Test\TestCase ;
2015-03-26 16:51:33 +03:00
/**
* Class CheckSetupControllerTest
*
2018-08-09 20:48:19 +03:00
* @ backupStaticAttributes
2016-05-19 12:17:01 +03:00
* @ package Tests\Settings\Controller
2015-03-26 16:51:33 +03:00
*/
class CheckSetupControllerTest extends TestCase {
2020-08-11 22:32:18 +03:00
/** @var CheckSetupController | \PHPUnit\Framework\MockObject\MockObject */
2015-03-26 16:51:33 +03:00
private $checkSetupController ;
2020-08-11 22:32:18 +03:00
/** @var IRequest | \PHPUnit\Framework\MockObject\MockObject */
2015-03-26 16:51:33 +03:00
private $request ;
2020-08-11 22:32:18 +03:00
/** @var IConfig | \PHPUnit\Framework\MockObject\MockObject */
2015-03-26 16:51:33 +03:00
private $config ;
2020-08-11 22:32:18 +03:00
/** @var IClientService | \PHPUnit\Framework\MockObject\MockObject*/
2015-03-26 16:51:33 +03:00
private $clientService ;
2020-08-11 22:32:18 +03:00
/** @var IURLGenerator | \PHPUnit\Framework\MockObject\MockObject */
2015-04-07 12:11:31 +03:00
private $urlGenerator ;
2020-08-11 22:32:18 +03:00
/** @var IL10N | \PHPUnit\Framework\MockObject\MockObject */
2015-07-27 17:29:05 +03:00
private $l10n ;
2016-08-15 17:24:56 +03:00
/** @var ILogger */
private $logger ;
2020-08-11 22:32:18 +03:00
/** @var Checker|\PHPUnit\Framework\MockObject\MockObject */
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
private $checker ;
2020-08-11 22:32:18 +03:00
/** @var EventDispatcherInterface|\PHPUnit\Framework\MockObject\MockObject */
2018-06-04 17:20:01 +03:00
private $dispatcher ;
2020-08-11 22:32:18 +03:00
/** @var Connection|\PHPUnit\Framework\MockObject\MockObject */
2018-06-13 12:45:49 +03:00
private $db ;
2020-08-11 22:32:18 +03:00
/** @var ILockingProvider|\PHPUnit\Framework\MockObject\MockObject */
2018-06-13 12:45:49 +03:00
private $lockingProvider ;
2020-08-11 22:32:18 +03:00
/** @var IDateTimeFormatter|\PHPUnit\Framework\MockObject\MockObject */
2018-06-13 12:45:49 +03:00
private $dateTimeFormatter ;
2018-08-04 21:39:51 +03:00
/** @var MemoryInfo|MockObject */
private $memoryInfo ;
2020-08-11 22:32:18 +03:00
/** @var SecureRandom|\PHPUnit\Framework\MockObject\MockObject */
2018-07-27 12:20:47 +03:00
private $secureRandom ;
2020-08-20 17:35:14 +03:00
/** @var IniGetWrapper|\PHPUnit\Framework\MockObject\MockObject */
private $iniGetWrapper ;
2018-08-04 21:39:51 +03:00
2018-08-09 20:48:19 +03:00
/**
* Holds a list of directories created during tests .
*
* @ var array
*/
private $dirsToRemove = [];
2019-11-27 17:27:18 +03:00
protected function setUp () : void {
2015-03-26 16:51:33 +03:00
parent :: setUp ();
2017-10-24 16:26:53 +03:00
$this -> request = $this -> getMockBuilder ( IRequest :: class )
2015-03-26 16:51:33 +03:00
-> disableOriginalConstructor () -> getMock ();
2017-10-24 16:26:53 +03:00
$this -> config = $this -> getMockBuilder ( IConfig :: class )
2015-03-26 16:51:33 +03:00
-> disableOriginalConstructor () -> getMock ();
2017-10-24 16:26:53 +03:00
$this -> clientService = $this -> getMockBuilder ( IClientService :: class )
2015-03-26 16:51:33 +03:00
-> disableOriginalConstructor () -> getMock ();
2017-10-24 16:26:53 +03:00
$this -> urlGenerator = $this -> getMockBuilder ( IURLGenerator :: class )
2015-04-07 12:11:31 +03:00
-> disableOriginalConstructor () -> getMock ();
2017-10-24 16:26:53 +03:00
$this -> l10n = $this -> getMockBuilder ( IL10N :: class )
2015-07-27 17:29:05 +03:00
-> disableOriginalConstructor () -> getMock ();
$this -> l10n -> expects ( $this -> any ())
-> method ( 't' )
2020-04-09 14:53:40 +03:00
-> willReturnCallback ( function ( $message , array $replace ) {
2015-07-27 17:29:05 +03:00
return vsprintf ( $message , $replace );
2020-03-26 00:21:27 +03:00
});
2019-05-28 20:46:36 +03:00
$this -> dispatcher = $this -> getMockBuilder ( EventDispatcherInterface :: class )
2018-06-04 17:20:01 +03:00
-> disableOriginalConstructor () -> getMock ();
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
$this -> checker = $this -> getMockBuilder ( '\OC\IntegrityCheck\Checker' )
-> disableOriginalConstructor () -> getMock ();
2017-10-24 16:26:53 +03:00
$this -> logger = $this -> getMockBuilder ( ILogger :: class ) -> getMock ();
2018-06-13 12:45:49 +03:00
$this -> db = $this -> getMockBuilder ( Connection :: class )
-> disableOriginalConstructor () -> getMock ();
$this -> lockingProvider = $this -> getMockBuilder ( ILockingProvider :: class ) -> getMock ();
$this -> dateTimeFormatter = $this -> getMockBuilder ( IDateTimeFormatter :: class ) -> getMock ();
2018-08-04 21:39:51 +03:00
$this -> memoryInfo = $this -> getMockBuilder ( MemoryInfo :: class )
2018-08-04 22:54:00 +03:00
-> setMethods ([ 'isMemoryLimitSufficient' ,])
2018-08-04 21:39:51 +03:00
-> getMock ();
2018-07-27 12:20:47 +03:00
$this -> secureRandom = $this -> getMockBuilder ( SecureRandom :: class ) -> getMock ();
2020-08-20 17:35:14 +03:00
$this -> iniGetWrapper = $this -> getMockBuilder ( IniGetWrapper :: class ) -> getMock ();
2019-09-17 17:33:27 +03:00
$this -> checkSetupController = $this -> getMockBuilder ( CheckSetupController :: class )
2015-07-27 17:29:05 +03:00
-> setConstructorArgs ([
'settings' ,
$this -> request ,
$this -> config ,
$this -> clientService ,
$this -> urlGenerator ,
$this -> l10n ,
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
$this -> checker ,
2018-06-04 17:20:01 +03:00
$this -> logger ,
$this -> dispatcher ,
2018-06-13 12:45:49 +03:00
$this -> db ,
$this -> lockingProvider ,
$this -> dateTimeFormatter ,
2018-08-04 21:39:51 +03:00
$this -> memoryInfo ,
2018-07-27 12:20:47 +03:00
$this -> secureRandom ,
2020-08-20 17:35:14 +03:00
$this -> iniGetWrapper ,
2020-04-09 10:22:29 +03:00
])
2018-06-19 17:39:51 +03:00
-> setMethods ([
'isReadOnlyConfig' ,
'hasValidTransactionIsolationLevel' ,
'hasFileinfoInstalled' ,
'hasWorkingFileLocking' ,
'getLastCronInfo' ,
'getSuggestedOverwriteCliURL' ,
'getCurlVersion' ,
'isPhpOutdated' ,
'isOpcacheProperlySetup' ,
'hasFreeTypeSupport' ,
'hasMissingIndexes' ,
'isSqliteUsed' ,
2018-12-04 19:58:35 +03:00
'isPHPMailerUsed' ,
2018-07-11 16:31:33 +03:00
'hasOpcacheLoaded' ,
2018-08-09 20:48:19 +03:00
'getAppDirsWithDifferentOwner' ,
2018-12-04 19:05:52 +03:00
'hasRecommendedPHPModules' ,
2018-12-04 20:43:02 +03:00
'hasBigIntConversionPendingColumns' ,
2019-02-27 12:47:57 +03:00
'isMysqlUsedWithoutUTF8MB4' ,
2019-03-08 15:36:11 +03:00
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' ,
2018-06-19 17:39:51 +03:00
]) -> getMock ();
2015-03-26 16:51:33 +03:00
}
2018-08-09 20:48:19 +03:00
/**
* Removes directories created during tests .
*
* @ after
* @ return void
*/
public function removeTestDirectories () {
foreach ( $this -> dirsToRemove as $dirToRemove ) {
rmdir ( $dirToRemove );
}
$this -> dirsToRemove = [];
}
2015-03-26 16:51:33 +03:00
public function testIsInternetConnectionWorkingDisabledViaConfig () {
$this -> config -> expects ( $this -> once ())
-> method ( 'getSystemValue' )
-> with ( 'has_internet_connection' , true )
2020-03-26 00:21:27 +03:00
-> willReturn ( false );
2015-03-26 16:51:33 +03:00
$this -> assertFalse (
2015-06-03 13:03:02 +03:00
self :: invokePrivate (
2015-03-26 16:51:33 +03:00
$this -> checkSetupController ,
2019-06-25 14:37:31 +03:00
'hasInternetConnectivityProblems'
2015-03-26 16:51:33 +03:00
)
);
}
public function testIsInternetConnectionWorkingCorrectly () {
2018-11-22 12:14:27 +03:00
$this -> config -> expects ( $this -> at ( 0 ))
2015-03-26 16:51:33 +03:00
-> method ( 'getSystemValue' )
-> with ( 'has_internet_connection' , true )
2020-04-09 10:22:29 +03:00
-> willReturn ( true );
2018-11-22 12:14:27 +03:00
$this -> config -> expects ( $this -> at ( 1 ))
-> method ( 'getSystemValue' )
-> with ( 'connectivity_check_domains' , [ 'www.nextcloud.com' , 'www.startpage.com' , 'www.eff.org' , 'www.edri.org' ])
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'www.nextcloud.com' , 'www.startpage.com' , 'www.eff.org' , 'www.edri.org' ]);
2015-03-26 16:51:33 +03:00
$client = $this -> getMockBuilder ( '\OCP\Http\Client\IClient' )
-> disableOriginalConstructor () -> getMock ();
2016-08-15 18:36:45 +03:00
$client -> expects ( $this -> any ())
-> method ( 'get' );
2015-03-26 16:51:33 +03:00
$this -> clientService -> expects ( $this -> once ())
-> method ( 'newClient' )
2020-03-26 00:21:27 +03:00
-> willReturn ( $client );
2015-03-26 16:51:33 +03:00
2019-06-25 14:37:31 +03:00
$this -> assertFalse (
2015-06-03 13:03:02 +03:00
self :: invokePrivate (
2015-03-26 16:51:33 +03:00
$this -> checkSetupController ,
2019-06-25 14:37:31 +03:00
'hasInternetConnectivityProblems'
2015-03-26 16:51:33 +03:00
)
);
}
2016-08-15 18:36:45 +03:00
public function testIsInternetConnectionFail () {
2018-11-22 12:14:27 +03:00
$this -> config -> expects ( $this -> at ( 0 ))
2015-03-26 16:51:33 +03:00
-> method ( 'getSystemValue' )
-> with ( 'has_internet_connection' , true )
2020-04-09 10:22:29 +03:00
-> willReturn ( true );
2018-11-22 12:14:27 +03:00
$this -> config -> expects ( $this -> at ( 1 ))
-> method ( 'getSystemValue' )
-> with ( 'connectivity_check_domains' , [ 'www.nextcloud.com' , 'www.startpage.com' , 'www.eff.org' , 'www.edri.org' ])
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'www.nextcloud.com' , 'www.startpage.com' , 'www.eff.org' , 'www.edri.org' ]);
2015-03-26 16:51:33 +03:00
$client = $this -> getMockBuilder ( '\OCP\Http\Client\IClient' )
-> disableOriginalConstructor () -> getMock ();
2016-08-15 18:36:45 +03:00
$client -> expects ( $this -> any ())
2015-03-26 16:51:33 +03:00
-> method ( 'get' )
-> will ( $this -> throwException ( new \Exception ()));
2018-04-05 22:38:54 +03:00
$this -> clientService -> expects ( $this -> exactly ( 4 ))
2015-03-26 16:51:33 +03:00
-> method ( 'newClient' )
2020-03-26 00:21:27 +03:00
-> willReturn ( $client );
2015-03-26 16:51:33 +03:00
2019-06-25 14:37:31 +03:00
$this -> assertTrue (
2015-06-03 13:03:02 +03:00
self :: invokePrivate (
2015-03-26 16:51:33 +03:00
$this -> checkSetupController ,
2019-06-25 14:37:31 +03:00
'hasInternetConnectivityProblems'
2015-03-26 16:51:33 +03:00
)
);
}
public function testIsMemcacheConfiguredFalse () {
$this -> config -> expects ( $this -> once ())
-> method ( 'getSystemValue' )
-> with ( 'memcache.local' , null )
2020-03-26 00:21:27 +03:00
-> willReturn ( null );
2015-03-26 16:51:33 +03:00
$this -> assertFalse (
2015-06-03 13:03:02 +03:00
self :: invokePrivate (
2015-03-26 16:51:33 +03:00
$this -> checkSetupController ,
'isMemcacheConfigured'
)
);
}
public function testIsMemcacheConfiguredTrue () {
$this -> config -> expects ( $this -> once ())
-> method ( 'getSystemValue' )
-> with ( 'memcache.local' , null )
2020-03-26 00:21:27 +03:00
-> willReturn ( 'SomeProvider' );
2015-03-26 16:51:33 +03:00
$this -> assertTrue (
2015-06-03 13:03:02 +03:00
self :: invokePrivate (
2015-03-26 16:51:33 +03:00
$this -> checkSetupController ,
'isMemcacheConfigured'
)
);
}
2015-07-28 11:06:26 +03:00
public function testIsPhpSupportedFalse () {
2016-08-15 18:36:45 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'isPhpOutdated' )
-> willReturn ( true );
2015-07-28 11:06:26 +03:00
$this -> assertEquals (
[ 'eol' => true , 'version' => PHP_VERSION ],
self :: invokePrivate ( $this -> checkSetupController , 'isPhpSupported' )
);
}
public function testIsPhpSupportedTrue () {
2016-08-15 18:36:45 +03:00
$this -> checkSetupController
-> expects ( $this -> exactly ( 2 ))
-> method ( 'isPhpOutdated' )
-> willReturn ( false );
2015-07-28 11:06:26 +03:00
$this -> assertEquals (
[ 'eol' => false , 'version' => PHP_VERSION ],
self :: invokePrivate ( $this -> checkSetupController , 'isPhpSupported' )
);
$this -> assertEquals (
[ 'eol' => false , 'version' => PHP_VERSION ],
self :: invokePrivate ( $this -> checkSetupController , 'isPhpSupported' )
);
2015-07-25 21:18:32 +03:00
}
2018-10-25 23:30:42 +03:00
/**
* @ dataProvider dataForwardedForHeadersWorking
*
* @ param array $trustedProxies
2019-02-17 23:55:55 +03:00
* @ param string $remoteAddrNotForwarded
2018-10-25 23:30:42 +03:00
* @ param string $remoteAddr
* @ param bool $result
*/
2019-02-17 23:55:55 +03:00
public function testForwardedForHeadersWorking ( array $trustedProxies , string $remoteAddrNotForwarded , string $remoteAddr , bool $result ) {
2015-07-25 21:18:32 +03:00
$this -> config -> expects ( $this -> once ())
-> method ( 'getSystemValue' )
-> with ( 'trusted_proxies' , [])
2018-10-25 23:30:42 +03:00
-> willReturn ( $trustedProxies );
2019-02-17 23:55:55 +03:00
$this -> request -> expects ( $this -> atLeastOnce ())
2018-10-25 23:30:42 +03:00
-> method ( 'getHeader' )
2019-02-17 23:55:55 +03:00
-> willReturnMap ([
[ 'REMOTE_ADDR' , $remoteAddrNotForwarded ],
[ 'X-Forwarded-Host' , '' ]
]);
2018-10-25 23:30:42 +03:00
$this -> request -> expects ( $this -> any ())
2015-07-25 21:18:32 +03:00
-> method ( 'getRemoteAddress' )
2018-10-25 23:30:42 +03:00
-> willReturn ( $remoteAddr );
2015-07-25 21:18:32 +03:00
2018-10-25 23:30:42 +03:00
$this -> assertEquals (
$result ,
self :: invokePrivate ( $this -> checkSetupController , 'forwardedForHeadersWorking' )
2015-07-25 21:18:32 +03:00
);
}
2015-07-28 11:06:26 +03:00
2018-10-25 23:30:42 +03:00
public function dataForwardedForHeadersWorking () {
return [
// description => trusted proxies, getHeader('REMOTE_ADDR'), getRemoteAddr, expected result
'no trusted proxies' => [[], '2.2.2.2' , '2.2.2.2' , true ],
'trusted proxy, remote addr not trusted proxy' => [[ '1.1.1.1' ], '2.2.2.2' , '2.2.2.2' , true ],
'trusted proxy, remote addr is trusted proxy, x-forwarded-for working' => [[ '1.1.1.1' ], '1.1.1.1' , '2.2.2.2' , true ],
'trusted proxy, remote addr is trusted proxy, x-forwarded-for not set' => [[ '1.1.1.1' ], '1.1.1.1' , '1.1.1.1' , false ],
];
2015-07-28 11:06:26 +03:00
}
2019-02-17 23:55:55 +03:00
public function testForwardedHostPresentButTrustedProxiesEmpty () {
$this -> config -> expects ( $this -> once ())
-> method ( 'getSystemValue' )
-> with ( 'trusted_proxies' , [])
-> willReturn ([]);
$this -> request -> expects ( $this -> atLeastOnce ())
-> method ( 'getHeader' )
-> willReturnMap ([
[ 'REMOTE_ADDR' , '1.1.1.1' ],
[ 'X-Forwarded-Host' , 'nextcloud.test' ]
]);
$this -> request -> expects ( $this -> any ())
-> method ( 'getRemoteAddress' )
-> willReturn ( '1.1.1.1' );
$this -> assertEquals (
false ,
self :: invokePrivate ( $this -> checkSetupController , 'forwardedForHeadersWorking' )
);
}
2015-03-26 16:51:33 +03:00
public function testCheck () {
$this -> config -> expects ( $this -> at ( 0 ))
2018-06-13 12:45:49 +03:00
-> method ( 'getAppValue' )
-> with ( 'core' , 'cronErrors' )
-> willReturn ( '' );
$this -> config -> expects ( $this -> at ( 2 ))
2018-11-22 12:14:27 +03:00
-> method ( 'getSystemValue' )
-> with ( 'connectivity_check_domains' , [ 'www.nextcloud.com' , 'www.startpage.com' , 'www.eff.org' , 'www.edri.org' ])
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'www.nextcloud.com' , 'www.startpage.com' , 'www.eff.org' , 'www.edri.org' ]);
2018-11-22 12:14:27 +03:00
$this -> config -> expects ( $this -> at ( 3 ))
2015-03-26 16:51:33 +03:00
-> method ( 'getSystemValue' )
-> with ( 'memcache.local' , null )
2020-03-26 00:21:27 +03:00
-> willReturn ( 'SomeProvider' );
2018-11-22 12:14:27 +03:00
$this -> config -> expects ( $this -> at ( 4 ))
2015-10-08 19:23:20 +03:00
-> method ( 'getSystemValue' )
-> with ( 'has_internet_connection' , true )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2018-11-22 12:14:27 +03:00
$this -> config -> expects ( $this -> at ( 5 ))
2015-07-25 21:18:32 +03:00
-> method ( 'getSystemValue' )
2018-06-13 12:45:49 +03:00
-> with ( 'appstoreenabled' , true )
2020-03-26 00:21:27 +03:00
-> willReturn ( false );
2015-07-25 21:18:32 +03:00
2019-02-17 23:55:55 +03:00
$this -> request -> expects ( $this -> atLeastOnce ())
2018-10-25 23:30:42 +03:00
-> method ( 'getHeader' )
2019-02-17 23:55:55 +03:00
-> willReturnMap ([
[ 'REMOTE_ADDR' , '4.3.2.1' ],
[ 'X-Forwarded-Host' , '' ]
]);
2015-03-26 16:51:33 +03:00
$client = $this -> getMockBuilder ( '\OCP\Http\Client\IClient' )
-> disableOriginalConstructor () -> getMock ();
$client -> expects ( $this -> at ( 0 ))
-> method ( 'get' )
2016-08-15 18:36:45 +03:00
-> with ( 'http://www.nextcloud.com/' , [])
-> will ( $this -> throwException ( new \Exception ()));
2015-03-26 16:51:33 +03:00
$client -> expects ( $this -> at ( 1 ))
-> method ( 'get' )
2018-04-05 22:38:54 +03:00
-> with ( 'http://www.startpage.com/' , [])
2015-03-26 16:51:33 +03:00
-> will ( $this -> throwException ( new \Exception ()));
2016-08-15 18:36:45 +03:00
$client -> expects ( $this -> at ( 2 ))
-> method ( 'get' )
2018-04-05 22:38:54 +03:00
-> with ( 'http://www.eff.org/' , [])
2016-08-15 18:36:45 +03:00
-> will ( $this -> throwException ( new \Exception ()));
2018-04-05 22:38:54 +03:00
$client -> expects ( $this -> at ( 3 ))
-> method ( 'get' )
-> with ( 'http://www.edri.org/' , [])
-> will ( $this -> throwException ( new \Exception ()));
$this -> clientService -> expects ( $this -> exactly ( 4 ))
2015-03-26 16:51:33 +03:00
-> method ( 'newClient' )
2020-03-26 00:21:27 +03:00
-> willReturn ( $client );
2016-08-15 18:36:45 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'isPhpOutdated' )
-> willReturn ( true );
2017-04-20 14:17:21 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'isOpcacheProperlySetup' )
-> willReturn ( false );
2017-12-13 14:53:12 +03:00
$this -> checkSetupController
-> method ( 'hasFreeTypeSupport' )
-> willReturn ( false );
2018-06-04 17:20:01 +03:00
$this -> checkSetupController
-> method ( 'hasMissingIndexes' )
-> willReturn ([]);
2018-06-12 17:16:29 +03:00
$this -> checkSetupController
-> method ( 'isSqliteUsed' )
-> willReturn ( false );
2018-06-13 12:45:49 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'isReadOnlyConfig' )
-> willReturn ( false );
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'hasValidTransactionIsolationLevel' )
-> willReturn ( true );
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'hasFileinfoInstalled' )
-> willReturn ( true );
2018-07-11 16:31:33 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'hasOpcacheLoaded' )
-> willReturn ( true );
2018-06-13 12:45:49 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'hasWorkingFileLocking' )
-> willReturn ( true );
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getSuggestedOverwriteCliURL' )
-> willReturn ( '' );
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getLastCronInfo' )
-> willReturn ([
'diffInSeconds' => 123 ,
'relativeTime' => '2 hours ago' ,
'backgroundJobsUrl' => 'https://example.org' ,
]);
2018-06-19 17:39:51 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
2018-12-04 19:58:35 +03:00
-> method ( 'isPHPMailerUsed' )
2018-06-19 17:39:51 +03:00
-> willReturn ( false );
2018-06-19 18:17:34 +03:00
$this -> checker
-> expects ( $this -> once ())
-> method ( 'hasPassedCheck' )
-> willReturn ( true );
2018-08-04 21:39:51 +03:00
$this -> memoryInfo
2018-08-04 22:54:00 +03:00
-> method ( 'isMemoryLimitSufficient' )
-> willReturn ( true );
2015-03-26 16:51:33 +03:00
2018-08-09 20:48:19 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getAppDirsWithDifferentOwner' )
-> willReturn ([]);
2018-12-04 19:05:52 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'hasRecommendedPHPModules' )
-> willReturn ([]);
2018-12-04 20:43:02 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'hasBigIntConversionPendingColumns' )
-> willReturn ([]);
2019-02-27 12:47:57 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'isMysqlUsedWithoutUTF8MB4' )
-> willReturn ( false );
2019-03-08 15:36:11 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' )
-> willReturn ( true );
2019-10-26 16:12:46 +03:00
$this -> urlGenerator -> method ( 'linkToDocs' )
2020-04-09 14:53:40 +03:00
-> willReturnCallback ( function ( string $key ) : string {
2019-10-26 16:12:46 +03:00
if ( $key === 'admin-performance' ) {
return 'http://docs.example.org/server/go.php?to=admin-performance' ;
}
if ( $key === 'admin-security' ) {
return 'https://docs.example.org/server/8.1/admin_manual/configuration_server/hardening.html' ;
}
if ( $key === 'admin-reverse-proxy' ) {
return 'reverse-proxy-doc-link' ;
}
if ( $key === 'admin-code-integrity' ) {
return 'http://docs.example.org/server/go.php?to=admin-code-integrity' ;
}
if ( $key === 'admin-php-opcache' ) {
return 'http://docs.example.org/server/go.php?to=admin-php-opcache' ;
}
if ( $key === 'admin-db-conversion' ) {
return 'http://docs.example.org/server/go.php?to=admin-db-conversion' ;
}
return '' ;
});
$this -> urlGenerator -> method ( 'getAbsoluteURL' )
2020-04-09 14:53:40 +03:00
-> willReturnCallback ( function ( string $url ) : string {
2019-10-26 16:12:46 +03:00
if ( $url === 'index.php/settings/admin' ) {
return 'https://server/index.php/settings/admin' ;
}
if ( $url === 'index.php' ) {
return 'https://server/index.php' ;
}
return '' ;
});
2015-03-26 16:51:33 +03:00
$expected = new DataResponse (
[
2018-06-13 12:45:49 +03:00
'isGetenvServerWorking' => true ,
'isReadOnlyConfig' => false ,
'hasValidTransactionIsolationLevel' => true ,
'hasFileinfoInstalled' => true ,
'hasWorkingFileLocking' => true ,
'suggestedOverwriteCliURL' => '' ,
'cronInfo' => [
'diffInSeconds' => 123 ,
'relativeTime' => '2 hours ago' ,
'backgroundJobsUrl' => 'https://example.org' ,
],
2018-06-19 18:17:34 +03:00
'cronErrors' => [],
2019-06-25 14:37:31 +03:00
'serverHasInternetConnectionProblems' => true ,
2015-03-26 16:51:33 +03:00
'isMemcacheConfigured' => true ,
2017-08-01 12:16:04 +03:00
'memcacheDocs' => 'http://docs.example.org/server/go.php?to=admin-performance' ,
2018-07-27 12:20:47 +03:00
'isRandomnessSecure' => self :: invokePrivate ( $this -> checkSetupController , 'isRandomnessSecure' ),
2017-08-01 12:16:04 +03:00
'securityDocs' => 'https://docs.example.org/server/8.1/admin_manual/configuration_server/hardening.html' ,
2015-07-27 17:29:05 +03:00
'isUsedTlsLibOutdated' => '' ,
2015-07-28 11:06:26 +03:00
'phpSupported' => [
'eol' => true ,
'version' => PHP_VERSION
2015-07-25 21:18:32 +03:00
],
'forwardedForHeadersWorking' => true ,
'reverseProxyDocs' => 'reverse-proxy-doc-link' ,
2015-10-02 17:17:56 +03:00
'isCorrectMemcachedPHPModuleInstalled' => true ,
2018-06-19 18:17:34 +03:00
'hasPassedCodeIntegrityCheck' => true ,
2017-08-01 12:16:04 +03:00
'codeIntegrityCheckerDocumentation' => 'http://docs.example.org/server/go.php?to=admin-code-integrity' ,
2017-02-15 09:40:36 +03:00
'isOpcacheProperlySetup' => false ,
2018-07-11 16:31:33 +03:00
'hasOpcacheLoaded' => true ,
2017-08-01 12:16:04 +03:00
'phpOpcacheDocumentation' => 'http://docs.example.org/server/go.php?to=admin-php-opcache' ,
2017-03-16 14:30:21 +03:00
'isSettimelimitAvailable' => true ,
2017-12-13 14:53:12 +03:00
'hasFreeTypeSupport' => false ,
2018-06-12 17:16:29 +03:00
'isSqliteUsed' => false ,
'databaseConversionDocumentation' => 'http://docs.example.org/server/go.php?to=admin-db-conversion' ,
2018-06-13 12:45:49 +03:00
'missingIndexes' => [],
2020-03-11 14:29:52 +03:00
'missingColumns' => [],
2018-12-04 19:58:35 +03:00
'isPHPMailerUsed' => false ,
2018-06-19 17:39:51 +03:00
'mailSettingsDocumentation' => 'https://server/index.php/settings/admin' ,
2018-08-04 22:54:00 +03:00
'isMemoryLimitSufficient' => true ,
2018-08-09 20:48:19 +03:00
'appDirsWithDifferentOwner' => [],
2018-12-04 19:05:52 +03:00
'recommendedPHPModules' => [],
2018-12-04 20:43:02 +03:00
'pendingBigIntConversionColumns' => [],
2019-02-27 12:47:57 +03:00
'isMysqlUsedWithoutUTF8MB4' => false ,
2019-03-08 15:36:11 +03:00
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => true ,
2019-10-26 16:12:46 +03:00
'reverseProxyGeneratedURL' => 'https://server/index.php' ,
2020-07-25 22:53:39 +03:00
'OCA\Settings\SetupChecks\PhpDefaultCharset' => [ 'pass' => true , 'description' => 'PHP configuration option default_charset should be UTF-8' , 'severity' => 'warning' ],
'OCA\Settings\SetupChecks\PhpOutputBuffering' => [ 'pass' => true , 'description' => 'PHP configuration option output_buffering must be disabled' , 'severity' => 'error' ],
2020-08-12 16:16:33 +03:00
'OCA\Settings\SetupChecks\LegacySSEKeyFormat' => [ 'pass' => true , 'description' => 'The old server-side-encryption format is enabled. We recommend disabling this.' , 'severity' => 'warning' , 'linkToDocumentation' => '' ],
2015-03-26 16:51:33 +03:00
]
);
$this -> assertEquals ( $expected , $this -> checkSetupController -> check ());
}
2015-07-27 17:29:05 +03:00
2018-12-04 19:58:35 +03:00
public function testIsPHPMailerUsed () {
2019-09-17 17:33:27 +03:00
$checkSetupController = $this -> getMockBuilder ( CheckSetupController :: class )
2018-11-14 19:41:38 +03:00
-> setConstructorArgs ([
'settings' ,
$this -> request ,
$this -> config ,
$this -> clientService ,
$this -> urlGenerator ,
$this -> l10n ,
$this -> checker ,
$this -> logger ,
$this -> dispatcher ,
$this -> db ,
$this -> lockingProvider ,
$this -> dateTimeFormatter ,
$this -> memoryInfo ,
$this -> secureRandom ,
2020-08-20 17:35:14 +03:00
$this -> iniGetWrapper ,
2018-11-14 19:41:38 +03:00
])
-> setMethods ( null ) -> getMock ();
$this -> config -> expects ( $this -> at ( 0 ))
-> method ( 'getSystemValue' )
2018-11-19 12:57:51 +03:00
-> with ( 'mail_smtpmode' , 'smtp' )
2020-03-26 00:21:27 +03:00
-> willReturn ( 'php' );
2018-11-14 19:41:38 +03:00
$this -> config -> expects ( $this -> at ( 1 ))
-> method ( 'getSystemValue' )
2018-11-19 12:57:51 +03:00
-> with ( 'mail_smtpmode' , 'smtp' )
2020-03-26 00:21:27 +03:00
-> willReturn ( 'not-php' );
2018-11-14 19:41:38 +03:00
2018-12-04 19:58:35 +03:00
$this -> assertTrue ( $this -> invokePrivate ( $checkSetupController , 'isPHPMailerUsed' ));
$this -> assertFalse ( $this -> invokePrivate ( $checkSetupController , 'isPHPMailerUsed' ));
2018-11-14 19:41:38 +03:00
}
2015-07-27 17:29:05 +03:00
public function testGetCurlVersion () {
2019-09-17 17:33:27 +03:00
$checkSetupController = $this -> getMockBuilder ( CheckSetupController :: class )
2015-07-27 17:29:05 +03:00
-> setConstructorArgs ([
'settings' ,
$this -> request ,
$this -> config ,
$this -> clientService ,
$this -> urlGenerator ,
$this -> l10n ,
2016-08-15 17:24:56 +03:00
$this -> checker ,
2018-06-04 17:20:01 +03:00
$this -> logger ,
$this -> dispatcher ,
2018-06-13 12:45:49 +03:00
$this -> db ,
$this -> lockingProvider ,
$this -> dateTimeFormatter ,
2018-08-04 21:39:51 +03:00
$this -> memoryInfo ,
2018-07-27 12:20:47 +03:00
$this -> secureRandom ,
2020-08-20 17:35:14 +03:00
$this -> iniGetWrapper ,
2015-07-27 17:29:05 +03:00
])
-> setMethods ( null ) -> getMock ();
2015-10-08 19:23:20 +03:00
$this -> assertArrayHasKey ( 'ssl_version' , $this -> invokePrivate ( $checkSetupController , 'getCurlVersion' ));
2015-07-27 17:29:05 +03:00
}
public function testIsUsedTlsLibOutdatedWithAnotherLibrary () {
2015-10-08 19:23:20 +03:00
$this -> config -> expects ( $this -> any ())
-> method ( 'getSystemValue' )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-07-27 17:29:05 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'ssl_version' => 'SSLlib' ]);
2015-07-27 17:29:05 +03:00
$this -> assertSame ( '' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
public function testIsUsedTlsLibOutdatedWithMisbehavingCurl () {
2015-10-08 19:23:20 +03:00
$this -> config -> expects ( $this -> any ())
-> method ( 'getSystemValue' )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-07-27 17:29:05 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([]);
2015-07-27 17:29:05 +03:00
$this -> assertSame ( '' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
public function testIsUsedTlsLibOutdatedWithOlderOpenSsl () {
2015-10-08 19:23:20 +03:00
$this -> config -> expects ( $this -> any ())
2015-09-02 09:16:27 +03:00
-> method ( 'getSystemValue' )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-07-27 17:29:05 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'ssl_version' => 'OpenSSL/1.0.1c' ]);
2015-07-27 17:29:05 +03:00
$this -> assertSame ( 'cURL is using an outdated OpenSSL version (OpenSSL/1.0.1c). Please update your operating system or features such as installing and updating apps via the app store or Federated Cloud Sharing will not work reliably.' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
2015-09-02 09:16:27 +03:00
public function testIsUsedTlsLibOutdatedWithOlderOpenSslAndWithoutAppstore () {
$this -> config
2015-10-08 19:23:20 +03:00
-> expects ( $this -> at ( 0 ))
2015-09-02 09:16:27 +03:00
-> method ( 'getSystemValue' )
2015-10-08 19:23:20 +03:00
-> with ( 'has_internet_connection' , true )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-09-02 09:16:27 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'ssl_version' => 'OpenSSL/1.0.1c' ]);
2015-09-02 09:16:27 +03:00
$this -> assertSame ( 'cURL is using an outdated OpenSSL version (OpenSSL/1.0.1c). Please update your operating system or features such as Federated Cloud Sharing will not work reliably.' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
2015-07-27 17:29:05 +03:00
public function testIsUsedTlsLibOutdatedWithOlderOpenSsl1 () {
2015-10-08 19:23:20 +03:00
$this -> config -> expects ( $this -> any ())
2015-09-02 09:16:27 +03:00
-> method ( 'getSystemValue' )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-07-27 17:29:05 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'ssl_version' => 'OpenSSL/1.0.2a' ]);
2015-07-27 17:29:05 +03:00
$this -> assertSame ( 'cURL is using an outdated OpenSSL version (OpenSSL/1.0.2a). Please update your operating system or features such as installing and updating apps via the app store or Federated Cloud Sharing will not work reliably.' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
public function testIsUsedTlsLibOutdatedWithMatchingOpenSslVersion () {
2015-10-08 19:23:20 +03:00
$this -> config -> expects ( $this -> any ())
-> method ( 'getSystemValue' )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-07-27 17:29:05 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'ssl_version' => 'OpenSSL/1.0.1d' ]);
2020-04-10 15:19:56 +03:00
$this -> assertSame ( '' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
2015-07-27 17:29:05 +03:00
}
public function testIsUsedTlsLibOutdatedWithMatchingOpenSslVersion1 () {
2015-10-08 19:23:20 +03:00
$this -> config -> expects ( $this -> any ())
-> method ( 'getSystemValue' )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-07-27 17:29:05 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'ssl_version' => 'OpenSSL/1.0.2b' ]);
2015-07-27 17:29:05 +03:00
$this -> assertSame ( '' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
2018-08-09 20:48:19 +03:00
/**
* Setups a temp directory and some subdirectories .
* Then calls the 'getAppDirsWithDifferentOwner' method .
* The result is expected to be empty since
* there are no directories with different owners than the current user .
*
* @ return void
*/
public function testAppDirectoryOwnersOk () {
$tempDir = tempnam ( sys_get_temp_dir (), 'apps' ) . 'dir' ;
mkdir ( $tempDir );
mkdir ( $tempDir . DIRECTORY_SEPARATOR . 'app1' );
mkdir ( $tempDir . DIRECTORY_SEPARATOR . 'app2' );
$this -> dirsToRemove [] = $tempDir . DIRECTORY_SEPARATOR . 'app1' ;
$this -> dirsToRemove [] = $tempDir . DIRECTORY_SEPARATOR . 'app2' ;
$this -> dirsToRemove [] = $tempDir ;
OC :: $APPSROOTS = [
[
'path' => $tempDir ,
'url' => '/apps' ,
'writable' => true ,
],
];
$this -> assertSame (
[],
$this -> invokePrivate ( $this -> checkSetupController , 'getAppDirsWithDifferentOwner' )
);
}
2018-08-09 20:48:55 +03:00
/**
* Calls the check for a none existing app root that is marked as not writable .
* It 's expected that no error happens since the check shouldn' t apply .
*
* @ return void
*/
public function testAppDirectoryOwnersNotWritable () {
$tempDir = tempnam ( sys_get_temp_dir (), 'apps' ) . 'dir' ;
OC :: $APPSROOTS = [
[
'path' => $tempDir ,
'url' => '/apps' ,
'writable' => false ,
],
];
$this -> assertSame (
[],
$this -> invokePrivate ( $this -> checkSetupController , 'getAppDirsWithDifferentOwner' )
);
}
2015-07-27 17:29:05 +03:00
public function testIsBuggyNss400 () {
2015-10-08 19:23:20 +03:00
$this -> config -> expects ( $this -> any ())
2015-09-02 09:16:27 +03:00
-> method ( 'getSystemValue' )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-07-27 17:29:05 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'ssl_version' => 'NSS/1.0.2b' ]);
2015-07-27 17:29:05 +03:00
$client = $this -> getMockBuilder ( '\OCP\Http\Client\IClient' )
-> disableOriginalConstructor () -> getMock ();
$exception = $this -> getMockBuilder ( '\GuzzleHttp\Exception\ClientException' )
-> disableOriginalConstructor () -> getMock ();
2018-02-13 16:59:20 +03:00
$response = $this -> getMockBuilder ( ResponseInterface :: class )
2015-07-27 17:29:05 +03:00
-> disableOriginalConstructor () -> getMock ();
$response -> expects ( $this -> once ())
-> method ( 'getStatusCode' )
2020-03-26 00:21:27 +03:00
-> willReturn ( 400 );
2015-07-27 17:29:05 +03:00
$exception -> expects ( $this -> once ())
-> method ( 'getResponse' )
2020-03-26 00:21:27 +03:00
-> willReturn ( $response );
2015-07-27 17:29:05 +03:00
$client -> expects ( $this -> at ( 0 ))
-> method ( 'get' )
2017-10-17 12:24:01 +03:00
-> with ( 'https://nextcloud.com/' , [])
2015-07-27 17:29:05 +03:00
-> will ( $this -> throwException ( $exception ));
$this -> clientService -> expects ( $this -> once ())
-> method ( 'newClient' )
2020-03-26 00:21:27 +03:00
-> willReturn ( $client );
2015-07-27 17:29:05 +03:00
$this -> assertSame ( 'cURL is using an outdated NSS version (NSS/1.0.2b). Please update your operating system or features such as installing and updating apps via the app store or Federated Cloud Sharing will not work reliably.' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
public function testIsBuggyNss200 () {
2015-10-08 19:23:20 +03:00
$this -> config -> expects ( $this -> any ())
-> method ( 'getSystemValue' )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-07-27 17:29:05 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([ 'ssl_version' => 'NSS/1.0.2b' ]);
2015-07-27 17:29:05 +03:00
$client = $this -> getMockBuilder ( '\OCP\Http\Client\IClient' )
-> disableOriginalConstructor () -> getMock ();
$exception = $this -> getMockBuilder ( '\GuzzleHttp\Exception\ClientException' )
-> disableOriginalConstructor () -> getMock ();
2018-02-13 16:59:20 +03:00
$response = $this -> getMockBuilder ( ResponseInterface :: class )
2015-07-27 17:29:05 +03:00
-> disableOriginalConstructor () -> getMock ();
$response -> expects ( $this -> once ())
-> method ( 'getStatusCode' )
2020-03-26 00:21:27 +03:00
-> willReturn ( 200 );
2015-07-27 17:29:05 +03:00
$exception -> expects ( $this -> once ())
-> method ( 'getResponse' )
2020-03-26 00:21:27 +03:00
-> willReturn ( $response );
2015-07-27 17:29:05 +03:00
$client -> expects ( $this -> at ( 0 ))
-> method ( 'get' )
2017-10-17 12:24:01 +03:00
-> with ( 'https://nextcloud.com/' , [])
2015-07-27 17:29:05 +03:00
-> will ( $this -> throwException ( $exception ));
$this -> clientService -> expects ( $this -> once ())
-> method ( 'newClient' )
2020-03-26 00:21:27 +03:00
-> willReturn ( $client );
2015-07-27 17:29:05 +03:00
$this -> assertSame ( '' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
2015-10-08 19:23:20 +03:00
public function testIsUsedTlsLibOutdatedWithInternetDisabled () {
$this -> config
-> expects ( $this -> at ( 0 ))
-> method ( 'getSystemValue' )
-> with ( 'has_internet_connection' , true )
2020-03-26 00:21:27 +03:00
-> willReturn ( false );
2015-10-08 19:23:20 +03:00
$this -> assertSame ( '' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
public function testIsUsedTlsLibOutdatedWithAppstoreDisabledAndServerToServerSharingEnabled () {
$this -> config
-> expects ( $this -> at ( 0 ))
-> method ( 'getSystemValue' )
-> with ( 'has_internet_connection' , true )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-10-08 19:23:20 +03:00
$this -> config
-> expects ( $this -> at ( 1 ))
-> method ( 'getSystemValue' )
2016-09-06 15:11:30 +03:00
-> with ( 'appstoreenabled' , true )
2020-03-26 00:21:27 +03:00
-> willReturn ( false );
2015-10-08 19:23:20 +03:00
$this -> config
-> expects ( $this -> at ( 2 ))
-> method ( 'getAppValue' )
-> with ( 'files_sharing' , 'outgoing_server2server_share_enabled' , 'yes' )
2020-03-26 00:21:27 +03:00
-> willReturn ( 'no' );
2015-10-08 19:23:20 +03:00
$this -> config
-> expects ( $this -> at ( 3 ))
-> method ( 'getAppValue' )
-> with ( 'files_sharing' , 'incoming_server2server_share_enabled' , 'yes' )
2020-03-26 00:21:27 +03:00
-> willReturn ( 'yes' );
2015-10-08 19:23:20 +03:00
$this -> checkSetupController
-> expects ( $this -> once ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([]);
2015-10-08 19:23:20 +03:00
$this -> assertSame ( '' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
public function testIsUsedTlsLibOutdatedWithAppstoreDisabledAndServerToServerSharingDisabled () {
$this -> config
-> expects ( $this -> at ( 0 ))
-> method ( 'getSystemValue' )
-> with ( 'has_internet_connection' , true )
2020-03-26 00:21:27 +03:00
-> willReturn ( true );
2015-10-08 19:23:20 +03:00
$this -> config
-> expects ( $this -> at ( 1 ))
-> method ( 'getSystemValue' )
2016-09-06 15:11:30 +03:00
-> with ( 'appstoreenabled' , true )
2020-03-26 00:21:27 +03:00
-> willReturn ( false );
2015-10-08 19:23:20 +03:00
$this -> config
-> expects ( $this -> at ( 2 ))
-> method ( 'getAppValue' )
-> with ( 'files_sharing' , 'outgoing_server2server_share_enabled' , 'yes' )
2020-03-26 00:21:27 +03:00
-> willReturn ( 'no' );
2015-10-08 19:23:20 +03:00
$this -> config
-> expects ( $this -> at ( 3 ))
-> method ( 'getAppValue' )
-> with ( 'files_sharing' , 'incoming_server2server_share_enabled' , 'yes' )
2020-03-26 00:21:27 +03:00
-> willReturn ( 'no' );
2015-10-08 19:23:20 +03:00
$this -> checkSetupController
-> expects ( $this -> never ())
-> method ( 'getCurlVersion' )
2020-03-26 00:21:27 +03:00
-> willReturn ([]);
2015-10-08 19:23:20 +03:00
$this -> assertSame ( '' , $this -> invokePrivate ( $this -> checkSetupController , 'isUsedTlsLibOutdated' ));
}
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
public function testRescanFailedIntegrityCheck () {
$this -> checker
-> expects ( $this -> once ())
-> method ( 'runInstanceVerification' );
$this -> urlGenerator
-> expects ( $this -> once ())
-> method ( 'linkToRoute' )
2016-08-15 17:24:56 +03:00
-> with ( 'settings.AdminSettings.index' )
2020-03-26 00:21:27 +03:00
-> willReturn ( '/admin' );
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
$expected = new RedirectResponse ( '/admin' );
$this -> assertEquals ( $expected , $this -> checkSetupController -> rescanFailedIntegrityCheck ());
}
2016-02-12 13:11:39 +03:00
public function testGetFailedIntegrityCheckDisabled () {
$this -> checker
-> expects ( $this -> once ())
-> method ( 'isCodeCheckEnforced' )
-> willReturn ( false );
$expected = new DataDisplayResponse ( 'Integrity checker has been disabled. Integrity cannot be verified.' );
$this -> assertEquals ( $expected , $this -> checkSetupController -> getFailedIntegrityCheckFiles ());
}
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
public function testGetFailedIntegrityCheckFilesWithNoErrorsFound () {
2016-02-12 13:11:39 +03:00
$this -> checker
-> expects ( $this -> once ())
-> method ( 'isCodeCheckEnforced' )
-> willReturn ( true );
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
$this -> checker
-> expects ( $this -> once ())
-> method ( 'getResults' )
2020-03-26 00:21:27 +03:00
-> willReturn ([]);
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
$expected = new DataDisplayResponse (
'No errors have been found.' ,
Http :: STATUS_OK ,
[
2020-04-09 10:22:29 +03:00
'Content-Type' => 'text/plain' ,
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
]
);
$this -> assertEquals ( $expected , $this -> checkSetupController -> getFailedIntegrityCheckFiles ());
}
public function testGetFailedIntegrityCheckFilesWithSomeErrorsFound () {
2016-02-12 13:11:39 +03:00
$this -> checker
-> expects ( $this -> once ())
-> method ( 'isCodeCheckEnforced' )
-> willReturn ( true );
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
$this -> checker
-> expects ( $this -> once ())
-> method ( 'getResults' )
2020-04-09 17:07:47 +03:00
-> willReturn ([ 'core' => [ 'EXTRA_FILE' => [ '/testfile' => []], 'INVALID_HASH' => [ '/.idea/workspace.xml' => [ 'expected' => 'f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216' , 'current' => 'ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094' , ], '/lib/private/integritycheck/checker.php' => [ 'expected' => 'c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea' , 'current' => '88a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585' , ], '/settings/controller/checksetupcontroller.php' => [ 'expected' => '3e1de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4' , 'current' => '09563164f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a' , ], ], ], 'bookmarks' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'dav' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'encryption' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'federation' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'files' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'files_antivirus' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'files_drop' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'files_external' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'files_pdfviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'files_sharing' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'files_trashbin' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'files_versions' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'files_videoviewer' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'firstrunwizard' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'gitsmart' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'logreader' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature could not get verified.' , ], ], 'password_policy' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => 'Signature data not found.' , ], ], 'provisioning_api' => [ 'EXCEPTION' => [ 'class' => 'OC\\IntegrityCheck\\Exceptions\\InvalidSignatureException' , 'message' => '
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
$expected = new DataDisplayResponse (
' Technical information
=====================
The following list covers which files have failed the integrity check . Please read
the previous linked documentation to learn more about the errors and how to fix
them .
Results
=======
- core
- EXTRA_FILE
- / testfile
- INVALID_HASH
- /. idea / workspace . xml
- / lib / private / integritycheck / checker . php
- / settings / controller / checksetupcontroller . php
- bookmarks
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- dav
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- encryption
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- external
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- federation
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- files
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- files_antivirus
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- files_drop
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- files_external
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- files_pdfviewer
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- files_sharing
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- files_trashbin
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- files_versions
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- files_videoviewer
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- firstrunwizard
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- gitsmart
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- logreader
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature could not get verified .
- password_policy
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- provisioning_api
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- sketch
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- threatblock
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- two_factor_auth
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- user_ldap
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
- user_shibboleth
- EXCEPTION
- OC\IntegrityCheck\Exceptions\InvalidSignatureException
- Signature data not found .
Raw output
==========
Array
(
[ core ] => Array
(
[ EXTRA_FILE ] => Array
(
[ / testfile ] => Array
(
)
)
[ INVALID_HASH ] => Array
(
[ /. idea / workspace . xml ] => Array
(
[ expected ] => f1c5e2630d784bc9cb02d5a28f55d6f24d06dae2a0fee685f3c2521b050955d9d452769f61454c9ddfa9c308146ade10546cfa829794448eaffbc9a04a29d216
[ current ] => ce08bf30bcbb879a18b49239a9bec6b8702f52452f88a9d32142cad8d2494d5735e6bfa0d8642b2762c62ca5be49f9bf4ec231d4a230559d4f3e2c471d3ea094
)
[ / lib / private / integritycheck / checker . php ] => Array
(
[ expected ] => c5a03bacae8dedf8b239997901ba1fffd2fe51271d13a00cc4b34b09cca5176397a89fc27381cbb1f72855fa18b69b6f87d7d5685c3b45aee373b09be54742ea
[ current ] => 88 a3a92c11db91dec1ac3be0e1c87f862c95ba6ffaaaa3f2c3b8f682187c66f07af3a3b557a868342ef4a271218fe1c1e300c478e6c156c5955ed53c40d06585
)
[ / settings / controller / checksetupcontroller . php ] => Array
(
[ expected ] => 3e1 de26ce93c7bfe0ede7c19cb6c93cadc010340225b375607a7178812e9de163179b0dc33809f451e01f491d93f6f5aaca7929685d21594cccf8bda732327c4
[ current ] => 09563164 f9904a837f9ca0b5f626db56c838e5098e0ccc1d8b935f68fa03a25c5ec6f6b2d9e44a868e8b85764dafd1605522b4af8db0ae269d73432e9a01e63a
)
)
)
[ bookmarks ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ dav ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ encryption ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ external ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ federation ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ files ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ files_antivirus ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ files_drop ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ files_external ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ files_pdfviewer ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ files_sharing ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ files_trashbin ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ files_versions ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ files_videoviewer ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ firstrunwizard ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ gitsmart ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ logreader ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature could not get verified .
)
)
[ password_policy ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ provisioning_api ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ sketch ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ threatblock ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ two_factor_auth ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ user_ldap ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
[ user_shibboleth ] => Array
(
[ EXCEPTION ] => Array
(
[ class ] => OC\IntegrityCheck\Exceptions\InvalidSignatureException
[ message ] => Signature data not found .
)
)
)
' ,
Http :: STATUS_OK ,
[
2020-04-09 10:22:29 +03:00
'Content-Type' => 'text/plain' ,
Add code integrity check
This PR implements the base foundation of the code signing and integrity check. In this PR implemented is the signing and verification logic, as well as commands to sign single apps or the core repository.
Furthermore, there is a basic implementation to display problems with the code integrity on the update screen.
Code signing basically happens the following way:
- There is a ownCloud Root Certificate authority stored `resources/codesigning/root.crt` (in this PR I also ship the private key which we obviously need to change before a release :wink:). This certificate is not intended to be used for signing directly and only is used to sign new certificates.
- Using the `integrity:sign-core` and `integrity:sign-app` commands developers can sign either the core release or a single app. The core release needs to be signed with a certificate that has a CN of `core`, apps need to be signed with a certificate that either has a CN of `core` (shipped apps!) or the AppID.
- The command generates a signature.json file of the following format:
```json
{
"hashes": {
"/filename.php": "2401fed2eea6f2c1027c482a633e8e25cd46701f811e2d2c10dc213fd95fa60e350bccbbebdccc73a042b1a2799f673fbabadc783284cc288e4f1a1eacb74e3d",
"/lib/base.php": "55548cc16b457cd74241990cc9d3b72b6335f2e5f45eee95171da024087d114fcbc2effc3d5818a6d5d55f2ae960ab39fd0414d0c542b72a3b9e08eb21206dd9"
},
"certificate": "-----BEGIN CERTIFICATE-----MIIBvTCCASagAwIBAgIUPvawyqJwCwYazcv7iz16TWxfeUMwDQYJKoZIhvcNAQEF\nBQAwIzEhMB8GA1UECgwYb3duQ2xvdWQgQ29kZSBTaWduaW5nIENBMB4XDTE1MTAx\nNDEzMTcxMFoXDTE2MTAxNDEzMTcxMFowEzERMA8GA1UEAwwIY29udGFjdHMwgZ8w\nDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANoQesGdCW0L2L+a2xITYipixkScrIpB\nkX5Snu3fs45MscDb61xByjBSlFgR4QI6McoCipPw4SUr28EaExVvgPSvqUjYLGps\nfiv0Cvgquzbx/X3mUcdk9LcFo1uWGtrTfkuXSKX41PnJGTr6RQWGIBd1V52q1qbC\nJKkfzyeMeuQfAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAvF/KIhRMQ3tYTmgHWsiM\nwDMgIDb7iaHF0fS+/Nvo4PzoTO/trev6tMyjLbJ7hgdCpz/1sNzE11Cibf6V6dsz\njCE9invP368Xv0bTRObRqeSNsGogGl5ceAvR0c9BG+NRIKHcly3At3gLkS2791bC\niG+UxI/MNcWV0uJg9S63LF8=\n-----END CERTIFICATE-----",
"signature": "U29tZVNpZ25lZERhdGFFeGFtcGxl"
}
```
`hashes` is an array of all files in the folder with their corresponding SHA512 hashes (this is actually quite cheap to calculate), the `certificate` is the certificate used for signing. It has to be issued by the ownCloud Root Authority and it's CN needs to be permitted to perform the required action. The `signature` is then a signature of the `hashes` which can be verified using the `certificate`.
Steps to do in other PRs, this is already a quite huge one:
- Add nag screen in case the code check fails to ensure that administrators are aware of this.
- Add code verification also to OCC upgrade and unify display code more.
- Add enforced code verification to apps shipped from the appstore with a level of "official"
- Add enfocrced code verification to apps shipped from the appstore that were already signed in a previous release
- Add some developer documentation on how devs can request their own certificate
- Check when installing ownCloud
- Add support for CRLs to allow revoking certificates
**Note:** The upgrade checks are only run when the instance has a defined release channel of `stable` (defined in `version.php`). If you want to test this, you need to change the channel thus and then generate the core signature:
```
➜ master git:(add-integrity-checker) ✗ ./occ integrity:sign-core --privateKey=resources/codesigning/core.key --certificate=resources/codesigning/core.crt
Successfully signed "core"
```
Then increase the version and you should see something like the following:
![2015-11-04_12-02-57](https://cloud.githubusercontent.com/assets/878997/10936336/6adb1d14-82ec-11e5-8f06-9a74801c9abf.png)
As you can see a failed code check will not prevent the further update. It will instead just be a notice to the admin. In a next step we will add some nag screen.
For packaging stable releases this requires the following additional steps as a last action before zipping:
1. Run `./occ integrity:sign-core` once
2. Run `./occ integrity:sign-app` _for each_ app. However, this can be simply automated using a simple foreach on the apps folder.
2015-11-03 22:26:06 +03:00
]
);
$this -> assertEquals ( $expected , $this -> checkSetupController -> getFailedIntegrityCheckFiles ());
}
2019-02-27 12:47:57 +03:00
public function dataForIsMysqlUsedWithoutUTF8MB4 () {
return [
[ 'sqlite' , false , false ],
[ 'sqlite' , true , false ],
[ 'postgres' , false , false ],
[ 'postgres' , true , false ],
[ 'oci' , false , false ],
[ 'oci' , true , false ],
[ 'mysql' , false , true ],
[ 'mysql' , true , false ],
];
}
/**
* @ dataProvider dataForIsMysqlUsedWithoutUTF8MB4
*/
public function testIsMysqlUsedWithoutUTF8MB4 ( string $db , bool $useUTF8MB4 , bool $expected ) {
$this -> config -> method ( 'getSystemValue' )
2020-04-09 14:53:40 +03:00
-> willReturnCallback ( function ( $key , $default ) use ( $db , $useUTF8MB4 ) {
2019-02-27 12:47:57 +03:00
if ( $key === 'dbtype' ) {
return $db ;
}
if ( $key === 'mysql.utf8mb4' ) {
return $useUTF8MB4 ;
}
return $default ;
2020-03-26 00:21:27 +03:00
});
2019-02-27 12:47:57 +03:00
$checkSetupController = new CheckSetupController (
'settings' ,
$this -> request ,
$this -> config ,
$this -> clientService ,
$this -> urlGenerator ,
$this -> l10n ,
$this -> checker ,
$this -> logger ,
$this -> dispatcher ,
$this -> db ,
$this -> lockingProvider ,
$this -> dateTimeFormatter ,
$this -> memoryInfo ,
2020-08-20 17:35:14 +03:00
$this -> secureRandom ,
$this -> iniGetWrapper
2019-02-27 12:47:57 +03:00
);
$this -> assertSame ( $expected , $this -> invokePrivate ( $checkSetupController , 'isMysqlUsedWithoutUTF8MB4' ));
}
2019-03-08 15:36:11 +03:00
public function dataForIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed () {
return [
[ 'singlebucket' , 'OC\\Files\\ObjectStore\\Swift' , true ],
[ 'multibucket' , 'OC\\Files\\ObjectStore\\Swift' , true ],
[ 'singlebucket' , 'OC\\Files\\ObjectStore\\Custom' , true ],
[ 'multibucket' , 'OC\Files\\ObjectStore\\Custom' , true ],
[ 'singlebucket' , 'OC\Files\ObjectStore\Swift' , true ],
[ 'multibucket' , 'OC\Files\ObjectStore\Swift' , true ],
[ 'singlebucket' , 'OC\Files\ObjectStore\Custom' , true ],
[ 'multibucket' , 'OC\Files\ObjectStore\Custom' , true ],
];
}
/**
* @ dataProvider dataForIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed
*/
public function testIsEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed ( string $mode , string $className , bool $expected ) {
$this -> config -> method ( 'getSystemValue' )
2020-04-09 14:53:40 +03:00
-> willReturnCallback ( function ( $key , $default ) use ( $mode , $className ) {
2019-03-08 15:36:11 +03:00
if ( $key === 'objectstore' && $mode === 'singlebucket' ) {
return [ 'class' => $className ];
}
if ( $key === 'objectstore_multibucket' && $mode === 'multibucket' ) {
return [ 'class' => $className ];
}
return $default ;
2020-03-26 00:21:27 +03:00
});
2019-03-08 15:36:11 +03:00
$checkSetupController = new CheckSetupController (
'settings' ,
$this -> request ,
$this -> config ,
$this -> clientService ,
$this -> urlGenerator ,
$this -> l10n ,
$this -> checker ,
$this -> logger ,
$this -> dispatcher ,
$this -> db ,
$this -> lockingProvider ,
$this -> dateTimeFormatter ,
$this -> memoryInfo ,
2020-08-20 17:35:14 +03:00
$this -> secureRandom ,
$this -> iniGetWrapper
2019-03-08 15:36:11 +03:00
);
$this -> assertSame ( $expected , $this -> invokePrivate ( $checkSetupController , 'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' ));
}
2015-03-26 16:51:33 +03:00
}