2015-03-26 16:51:33 +03:00
< ? php
/**
2016-07-21 18:07:57 +03:00
* @ copyright Copyright ( c ) 2016 , ownCloud , Inc .
*
2017-11-06 17:56:42 +03:00
* @ author Arthur Schiwon < blizzz @ arthur - schiwon . de >
* @ author Bjoern Schiessle < bjoern @ schiessle . org >
* @ author Derek < derek . kelly27 @ gmail . com >
2016-07-21 18:07:57 +03:00
* @ author Joas Schilling < coding @ schilljs . com >
2017-11-06 17:56:42 +03:00
* @ author Ko - < k . stoffelen @ cs . ru . nl >
2016-05-26 20:56:05 +03:00
* @ author Lukas Reschke < lukas @ statuscode . ch >
2015-06-25 12:43:55 +03:00
* @ author Morris Jobke < hey @ morrisjobke . de >
2016-01-12 17:02:16 +03:00
* @ author Robin McCorkell < robin @ mccorkell . me . uk >
2016-07-21 18:07:57 +03:00
* @ author Roeland Jago Douma < roeland @ famdouma . nl >
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 ,
* along with this program . If not , see < http :// www . gnu . org / licenses />
*
*/
namespace OC\Settings\Controller ;
2017-02-15 09:40:36 +03:00
use bantu\IniGetWrapper\IniGetWrapper ;
2018-08-09 20:47:55 +03:00
use DirectoryIterator ;
2018-06-13 12:45:49 +03:00
use Doctrine\DBAL\DBALException ;
use Doctrine\DBAL\Platforms\SqlitePlatform ;
2018-12-04 20:43:02 +03:00
use Doctrine\DBAL\Types\Type ;
2015-07-27 17:29:05 +03:00
use GuzzleHttp\Exception\ClientException ;
2018-08-09 20:47:55 +03:00
use OC ;
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 OC\AppFramework\Http ;
2018-06-13 12:45:49 +03:00
use OC\DB\Connection ;
2018-06-04 17:20:01 +03:00
use OC\DB\MissingIndexInformation ;
2018-12-04 20:43:02 +03:00
use OC\DB\SchemaWrapper ;
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 OC\IntegrityCheck\Checker ;
2018-06-13 12:45:49 +03:00
use OC\Lock\NoopLockingProvider ;
2018-08-04 21:39:39 +03:00
use OC\MemoryInfo ;
2015-03-26 16:51:33 +03:00
use OCP\AppFramework\Controller ;
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\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 ;
use OCP\IConfig ;
2018-06-13 12:45:49 +03:00
use OCP\IDateTimeFormatter ;
2018-06-04 17:20:01 +03:00
use OCP\IDBConnection ;
2015-07-27 17:29:05 +03:00
use OCP\IL10N ;
2016-07-26 11:03:31 +03:00
use OCP\ILogger ;
2015-03-26 16:51:33 +03:00
use OCP\IRequest ;
2015-04-07 12:11:31 +03:00
use OCP\IURLGenerator ;
2018-06-13 12:45:49 +03:00
use OCP\Lock\ILockingProvider ;
2018-07-30 18:28:08 +03:00
use OCP\Security\ISecureRandom ;
2018-06-04 17:20:01 +03:00
use Symfony\Component\EventDispatcher\EventDispatcherInterface ;
use Symfony\Component\EventDispatcher\GenericEvent ;
2015-03-26 16:51:33 +03:00
/**
* @ package OC\Settings\Controller
*/
class CheckSetupController extends Controller {
/** @var IConfig */
private $config ;
/** @var IClientService */
private $clientService ;
2015-04-07 12:11:31 +03:00
/** @var IURLGenerator */
private $urlGenerator ;
2015-07-27 17:29:05 +03:00
/** @var IL10N */
private $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
/** @var Checker */
private $checker ;
2016-07-26 11:03:31 +03:00
/** @var ILogger */
private $logger ;
2018-06-04 17:20:01 +03:00
/** @var EventDispatcherInterface */
private $dispatcher ;
2018-06-13 12:45:49 +03:00
/** @var IDBConnection|Connection */
private $db ;
/** @var ILockingProvider */
private $lockingProvider ;
/** @var IDateTimeFormatter */
private $dateTimeFormatter ;
2018-08-04 21:39:39 +03:00
/** @var MemoryInfo */
private $memoryInfo ;
2018-07-30 18:28:08 +03:00
/** @var ISecureRandom */
2018-07-27 12:20:47 +03:00
private $secureRandom ;
2015-03-26 16:51:33 +03:00
public function __construct ( $AppName ,
IRequest $request ,
IConfig $config ,
IClientService $clientService ,
2015-04-07 12:11:31 +03:00
IURLGenerator $urlGenerator ,
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
IL10N $l10n ,
2016-07-26 11:03:31 +03:00
Checker $checker ,
2018-06-04 17:20:01 +03:00
ILogger $logger ,
2018-06-13 12:45:49 +03:00
EventDispatcherInterface $dispatcher ,
IDBConnection $db ,
ILockingProvider $lockingProvider ,
2018-08-04 21:39:39 +03:00
IDateTimeFormatter $dateTimeFormatter ,
2018-07-27 12:20:47 +03:00
MemoryInfo $memoryInfo ,
2018-07-30 18:28:08 +03:00
ISecureRandom $secureRandom ) {
2015-03-26 16:51:33 +03:00
parent :: __construct ( $AppName , $request );
$this -> config = $config ;
$this -> clientService = $clientService ;
2015-04-07 12:11:31 +03:00
$this -> urlGenerator = $urlGenerator ;
2015-07-27 17:29:05 +03:00
$this -> l10n = $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 = $checker ;
2016-07-26 11:03:31 +03:00
$this -> logger = $logger ;
2018-06-04 17:20:01 +03:00
$this -> dispatcher = $dispatcher ;
2018-06-13 12:45:49 +03:00
$this -> db = $db ;
$this -> lockingProvider = $lockingProvider ;
$this -> dateTimeFormatter = $dateTimeFormatter ;
2018-08-04 21:39:39 +03:00
$this -> memoryInfo = $memoryInfo ;
2018-07-27 12:20:47 +03:00
$this -> secureRandom = $secureRandom ;
2015-03-26 16:51:33 +03:00
}
/**
2018-02-15 12:21:31 +03:00
* Checks if the server can connect to the internet using HTTPS and HTTP
2015-03-26 16:51:33 +03:00
* @ return bool
*/
2019-06-25 14:37:31 +03:00
private function hasInternetConnectivityProblems () : bool {
2015-03-26 16:51:33 +03:00
if ( $this -> config -> getSystemValue ( 'has_internet_connection' , true ) === false ) {
return false ;
}
2018-11-22 12:14:27 +03:00
$siteArray = $this -> config -> getSystemValue ( 'connectivity_check_domains' , [
'www.nextcloud.com' , 'www.startpage.com' , 'www.eff.org' , 'www.edri.org'
]);
2016-07-12 02:24:57 +03:00
foreach ( $siteArray as $site ) {
if ( $this -> isSiteReachable ( $site )) {
2019-06-25 14:37:31 +03:00
return false ;
2016-07-12 02:24:57 +03:00
}
}
2019-06-25 14:37:31 +03:00
return true ;
2016-07-12 02:24:57 +03:00
}
/**
2018-04-05 22:38:54 +03:00
* Checks if the Nextcloud server can connect to a specific URL using both HTTPS and HTTP
2016-07-12 02:24:57 +03:00
* @ return bool
*/
private function isSiteReachable ( $sitename ) {
$httpSiteName = 'http://' . $sitename . '/' ;
$httpsSiteName = 'https://' . $sitename . '/' ;
2015-03-26 16:51:33 +03:00
try {
$client = $this -> clientService -> newClient ();
2016-07-12 02:24:57 +03:00
$client -> get ( $httpSiteName );
$client -> get ( $httpsSiteName );
2015-03-26 16:51:33 +03:00
} catch ( \Exception $e ) {
2016-07-26 11:03:31 +03:00
$this -> logger -> logException ( $e , [ 'app' => 'internet_connection_check' ]);
2015-03-26 16:51:33 +03:00
return false ;
}
2016-07-12 02:24:57 +03:00
return true ;
2015-03-26 16:51:33 +03:00
}
/**
* Checks whether a local memcache is installed or not
* @ return bool
*/
private function isMemcacheConfigured () {
return $this -> config -> getSystemValue ( 'memcache.local' , null ) !== null ;
}
2015-05-26 15:11:38 +03:00
/**
2018-07-27 12:20:47 +03:00
* Whether PHP can generate " secure " pseudorandom integers
2015-05-26 15:11:38 +03:00
*
* @ return bool
*/
2018-07-27 12:20:47 +03:00
private function isRandomnessSecure () {
try {
$this -> secureRandom -> generate ( 1 );
} catch ( \Exception $ex ) {
return false ;
2015-05-26 15:11:38 +03:00
}
2018-07-27 12:20:47 +03:00
return true ;
2015-05-26 15:11:38 +03:00
}
2015-07-27 17:29:05 +03:00
/**
* Public for the sake of unit - testing
*
* @ return array
*/
2015-10-08 19:23:20 +03:00
protected function getCurlVersion () {
2015-07-27 17:29:05 +03:00
return curl_version ();
}
/**
* Check if the used SSL lib is outdated . Older OpenSSL and NSS versions do
* have multiple bugs which likely lead to problems in combination with
2015-07-25 21:18:32 +03:00
* functionality required by ownCloud such as SNI .
2015-07-27 17:29:05 +03:00
*
* @ link https :// github . com / owncloud / core / issues / 17446 #issuecomment-122877546
* @ link https :// bugzilla . redhat . com / show_bug . cgi ? id = 1241172
* @ return string
*/
private function isUsedTlsLibOutdated () {
2015-10-08 19:23:20 +03:00
// Don't run check when:
// 1. Server has `has_internet_connection` set to false
// 2. AppStore AND S2S is disabled
if ( ! $this -> config -> getSystemValue ( 'has_internet_connection' , true )) {
return '' ;
}
2016-09-06 15:11:30 +03:00
if ( ! $this -> config -> getSystemValue ( 'appstoreenabled' , true )
2015-10-08 19:23:20 +03:00
&& $this -> config -> getAppValue ( 'files_sharing' , 'outgoing_server2server_share_enabled' , 'yes' ) === 'no'
&& $this -> config -> getAppValue ( 'files_sharing' , 'incoming_server2server_share_enabled' , 'yes' ) === 'no' ) {
return '' ;
}
2015-07-27 17:29:05 +03:00
$versionString = $this -> getCurlVersion ();
if ( isset ( $versionString [ 'ssl_version' ])) {
$versionString = $versionString [ 'ssl_version' ];
} else {
return '' ;
}
$features = ( string ) $this -> l10n -> t ( 'installing and updating apps via the app store or Federated Cloud Sharing' );
2016-09-06 15:11:30 +03:00
if ( ! $this -> config -> getSystemValue ( 'appstoreenabled' , true )) {
2015-07-27 17:29:05 +03:00
$features = ( string ) $this -> l10n -> t ( 'Federated Cloud Sharing' );
}
// Check if at least OpenSSL after 1.01d or 1.0.2b
if ( strpos ( $versionString , 'OpenSSL/' ) === 0 ) {
$majorVersion = substr ( $versionString , 8 , 5 );
$patchRelease = substr ( $versionString , 13 , 6 );
if (( $majorVersion === '1.0.1' && ord ( $patchRelease ) < ord ( 'd' )) ||
( $majorVersion === '1.0.2' && ord ( $patchRelease ) < ord ( 'b' ))) {
2018-10-09 15:32:14 +03:00
return $this -> l10n -> t ( 'cURL is using an outdated %1$s version (%2$s). Please update your operating system or features such as %3$s will not work reliably.' , [ 'OpenSSL' , $versionString , $features ]);
2015-07-27 17:29:05 +03:00
}
}
// Check if NSS and perform heuristic check
if ( strpos ( $versionString , 'NSS/' ) === 0 ) {
try {
$firstClient = $this -> clientService -> newClient ();
2017-10-17 12:24:01 +03:00
$firstClient -> get ( 'https://nextcloud.com/' );
2015-07-27 17:29:05 +03:00
$secondClient = $this -> clientService -> newClient ();
2017-10-17 12:24:01 +03:00
$secondClient -> get ( 'https://nextcloud.com/' );
2015-07-27 17:29:05 +03:00
} catch ( ClientException $e ) {
if ( $e -> getResponse () -> getStatusCode () === 400 ) {
2018-10-09 15:32:14 +03:00
return $this -> l10n -> t ( 'cURL is using an outdated %1$s version (%2$s). Please update your operating system or features such as %3$s will not work reliably.' , [ 'NSS' , $versionString , $features ]);
2015-07-27 17:29:05 +03:00
}
}
}
return '' ;
}
2015-10-20 23:45:27 +03:00
2016-08-15 18:36:45 +03:00
/**
* Whether the version is outdated
*
* @ return bool
*/
protected function isPhpOutdated () {
2018-12-04 17:40:40 +03:00
if ( version_compare ( PHP_VERSION , '7.1.0' , '<' )) {
2016-08-15 18:36:45 +03:00
return true ;
}
return false ;
}
2015-10-08 18:30:40 +03:00
/**
2015-07-28 11:06:26 +03:00
* Whether the php version is still supported ( at time of release )
* according to : https :// secure . php . net / supported - versions . php
*
* @ return array
*/
private function isPhpSupported () {
2016-08-15 18:36:45 +03:00
return [ 'eol' => $this -> isPhpOutdated (), 'version' => PHP_VERSION ];
2015-07-28 11:06:26 +03:00
}
2015-07-27 17:29:05 +03:00
2015-10-08 18:30:40 +03:00
/**
2015-07-25 21:18:32 +03:00
* Check if the reverse proxy configuration is working as expected
*
* @ return bool
*/
private function forwardedForHeadersWorking () {
$trustedProxies = $this -> config -> getSystemValue ( 'trusted_proxies' , []);
2018-10-25 23:30:42 +03:00
$remoteAddress = $this -> request -> getHeader ( 'REMOTE_ADDR' );
2015-07-25 21:18:32 +03:00
2019-03-20 21:59:32 +03:00
if ( empty ( $trustedProxies ) && $this -> request -> getHeader ( 'X-Forwarded-Host' ) !== '' ) {
2019-02-17 23:55:55 +03:00
return false ;
}
if ( \is_array ( $trustedProxies ) && \in_array ( $remoteAddress , $trustedProxies , true )) {
2018-10-25 23:30:42 +03:00
return $remoteAddress !== $this -> request -> getRemoteAddress ();
2015-07-25 21:18:32 +03:00
}
2019-02-17 23:55:55 +03:00
2015-07-25 21:18:32 +03:00
// either not enabled or working correctly
return true ;
}
2015-10-02 17:17:56 +03:00
/**
* Checks if the correct memcache module for PHP is installed . Only
* fails if memcached is configured and the working module is not installed .
*
* @ return bool
*/
private function isCorrectMemcachedPHPModuleInstalled () {
if ( $this -> config -> getSystemValue ( 'memcache.distributed' , null ) !== '\OC\Memcache\Memcached' ) {
return true ;
}
// there are two different memcached modules for PHP
// we only support memcached and not memcache
// https://code.google.com/p/memcached/wiki/PHPClientComparison
2015-10-20 23:45:27 +03:00
return ! ( ! extension_loaded ( 'memcached' ) && extension_loaded ( 'memcache' ));
2015-10-02 17:17:56 +03:00
}
2017-03-16 13:48:28 +03:00
/**
* Checks if set_time_limit is not disabled .
*
* @ return bool
*/
private function isSettimelimitAvailable () {
if ( function_exists ( 'set_time_limit' )
&& strpos ( @ ini_get ( 'disable_functions' ), 'set_time_limit' ) === false ) {
return true ;
}
return false ;
}
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
/**
* @ return RedirectResponse
*/
public function rescanFailedIntegrityCheck () {
$this -> checker -> runInstanceVerification ();
return new RedirectResponse (
2016-08-09 00:31:26 +03:00
$this -> urlGenerator -> linkToRoute ( 'settings.AdminSettings.index' )
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
);
}
/**
* @ NoCSRFRequired
* @ return DataResponse
*/
public function getFailedIntegrityCheckFiles () {
2016-02-12 13:11:39 +03:00
if ( ! $this -> checker -> isCodeCheckEnforced ()) {
return new DataDisplayResponse ( 'Integrity checker has been disabled. Integrity cannot be verified.' );
}
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
$completeResults = $this -> checker -> getResults ();
if ( ! empty ( $completeResults )) {
$formattedTextResponse = ' 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
=======
' ;
foreach ( $completeResults as $context => $contextResult ) {
$formattedTextResponse .= " - $context\n " ;
foreach ( $contextResult as $category => $result ) {
$formattedTextResponse .= " \t - $category\n " ;
if ( $category !== 'EXCEPTION' ) {
foreach ( $result as $key => $results ) {
$formattedTextResponse .= " \t \t - $key\n " ;
}
} else {
foreach ( $result as $key => $results ) {
$formattedTextResponse .= " \t \t - $results\n " ;
}
}
}
}
$formattedTextResponse .= '
Raw output
==========
' ;
$formattedTextResponse .= print_r ( $completeResults , true );
} else {
$formattedTextResponse = 'No errors have been found.' ;
}
$response = new DataDisplayResponse (
$formattedTextResponse ,
Http :: STATUS_OK ,
[
'Content-Type' => 'text/plain' ,
]
);
return $response ;
}
2017-02-15 09:40:36 +03:00
/**
* Checks whether a PHP opcache is properly set up
* @ return bool
*/
2017-04-20 14:17:21 +03:00
protected function isOpcacheProperlySetup () {
2017-02-15 09:40:36 +03:00
$iniWrapper = new IniGetWrapper ();
if ( ! $iniWrapper -> getBool ( 'opcache.enable' )) {
2018-05-07 21:46:19 +03:00
return false ;
2017-02-15 09:40:36 +03:00
}
if ( ! $iniWrapper -> getBool ( 'opcache.save_comments' )) {
2018-05-07 21:46:19 +03:00
return false ;
2017-02-15 09:40:36 +03:00
}
if ( $iniWrapper -> getNumeric ( 'opcache.max_accelerated_files' ) < 10000 ) {
2018-05-07 21:46:19 +03:00
return false ;
2017-02-15 09:40:36 +03:00
}
if ( $iniWrapper -> getNumeric ( 'opcache.memory_consumption' ) < 128 ) {
2018-05-07 21:46:19 +03:00
return false ;
2017-02-15 09:40:36 +03:00
}
if ( $iniWrapper -> getNumeric ( 'opcache.interned_strings_buffer' ) < 8 ) {
2018-05-07 21:46:19 +03:00
return false ;
2017-02-15 09:40:36 +03:00
}
2018-05-07 21:46:19 +03:00
return true ;
2017-02-15 09:40:36 +03:00
}
2017-12-13 14:36:48 +03:00
/**
* Check if the required FreeType functions are present
* @ return bool
*/
protected function hasFreeTypeSupport () {
return function_exists ( 'imagettfbbox' ) && function_exists ( 'imagettftext' );
}
2018-06-13 00:43:29 +03:00
protected function hasMissingIndexes () : array {
2018-06-04 17:20:01 +03:00
$indexInfo = new MissingIndexInformation ();
// Dispatch event so apps can also hint for pending index updates if needed
$event = new GenericEvent ( $indexInfo );
$this -> dispatcher -> dispatch ( IDBConnection :: CHECK_MISSING_INDEXES_EVENT , $event );
return $indexInfo -> getListOfMissingIndexes ();
}
2018-06-12 17:16:29 +03:00
protected function isSqliteUsed () {
return strpos ( $this -> config -> getSystemValue ( 'dbtype' ), 'sqlite' ) !== false ;
}
2018-06-13 12:45:49 +03:00
protected function isReadOnlyConfig () : bool {
return \OC_Helper :: isReadOnlyConfigEnabled ();
}
protected function hasValidTransactionIsolationLevel () : bool {
try {
if ( $this -> db -> getDatabasePlatform () instanceof SqlitePlatform ) {
return true ;
}
return $this -> db -> getTransactionIsolation () === Connection :: TRANSACTION_READ_COMMITTED ;
} catch ( DBALException $e ) {
// ignore
}
return true ;
}
protected function hasFileinfoInstalled () : bool {
return \OC_Util :: fileInfoLoaded ();
}
protected function hasWorkingFileLocking () : bool {
return ! ( $this -> lockingProvider instanceof NoopLockingProvider );
}
protected function getSuggestedOverwriteCliURL () : string {
$suggestedOverwriteCliUrl = '' ;
if ( $this -> config -> getSystemValue ( 'overwrite.cli.url' , '' ) === '' ) {
$suggestedOverwriteCliUrl = $this -> request -> getServerProtocol () . '://' . $this -> request -> getInsecureServerHost () . \OC :: $WEBROOT ;
if ( ! $this -> config -> getSystemValue ( 'config_is_read_only' , false )) {
// Set the overwrite URL when it was not set yet.
$this -> config -> setSystemValue ( 'overwrite.cli.url' , $suggestedOverwriteCliUrl );
$suggestedOverwriteCliUrl = '' ;
}
}
return $suggestedOverwriteCliUrl ;
}
protected function getLastCronInfo () : array {
$lastCronRun = $this -> config -> getAppValue ( 'core' , 'lastcron' , 0 );
return [
'diffInSeconds' => time () - $lastCronRun ,
'relativeTime' => $this -> dateTimeFormatter -> formatTimeSpan ( $lastCronRun ),
'backgroundJobsUrl' => $this -> urlGenerator -> linkToRoute ( 'settings.AdminSettings.index' , [ 'section' => 'server' ]) . '#backgroundjobs' ,
];
}
2018-06-19 17:26:06 +03:00
protected function getCronErrors () {
$errors = json_decode ( $this -> config -> getAppValue ( 'core' , 'cronErrors' , '' ), true );
if ( is_array ( $errors )) {
return $errors ;
}
return [];
}
2018-12-04 19:58:35 +03:00
protected function isPHPMailerUsed () : bool {
2018-11-19 12:57:51 +03:00
return $this -> config -> getSystemValue ( 'mail_smtpmode' , 'smtp' ) === 'php' ;
2018-06-19 17:39:51 +03:00
}
2018-07-11 16:31:33 +03:00
protected function hasOpcacheLoaded () : bool {
2018-07-11 17:05:31 +03:00
return function_exists ( 'opcache_get_status' );
2018-07-11 16:31:33 +03:00
}
2018-08-09 20:47:55 +03:00
/**
* Iterates through the configured app roots and
* tests if the subdirectories are owned by the same user than the current user .
*
* @ return array
*/
protected function getAppDirsWithDifferentOwner () : array {
2018-09-06 15:04:06 +03:00
$currentUser = posix_getuid ();
2018-08-30 21:52:43 +03:00
$appDirsWithDifferentOwner = [[]];
2018-08-09 20:47:55 +03:00
foreach ( OC :: $APPSROOTS as $appRoot ) {
2018-08-09 20:48:55 +03:00
if ( $appRoot [ 'writable' ] === true ) {
2018-08-30 21:52:43 +03:00
$appDirsWithDifferentOwner [] = $this -> getAppDirsWithDifferentOwnerForAppRoot ( $currentUser , $appRoot );
2018-08-09 20:47:55 +03:00
}
}
2018-08-30 21:52:43 +03:00
$appDirsWithDifferentOwner = array_merge ( ... $appDirsWithDifferentOwner );
2018-08-09 20:47:55 +03:00
sort ( $appDirsWithDifferentOwner );
2018-08-30 21:52:43 +03:00
2018-08-09 20:47:55 +03:00
return $appDirsWithDifferentOwner ;
}
2018-08-09 20:48:55 +03:00
/**
* Tests if the directories for one apps directory are writable by the current user .
*
2018-09-06 15:04:06 +03:00
* @ param int $currentUser The current user
2018-08-09 20:48:55 +03:00
* @ param array $appRoot The app root config
* @ return string [] The none writable directory paths inside the app root
*/
2018-09-12 16:05:17 +03:00
private function getAppDirsWithDifferentOwnerForAppRoot ( int $currentUser , array $appRoot ) : array {
2018-08-09 20:48:55 +03:00
$appDirsWithDifferentOwner = [];
$appsPath = $appRoot [ 'path' ];
$appsDir = new DirectoryIterator ( $appRoot [ 'path' ]);
foreach ( $appsDir as $fileInfo ) {
if ( $fileInfo -> isDir () && ! $fileInfo -> isDot ()) {
$absAppPath = $appsPath . DIRECTORY_SEPARATOR . $fileInfo -> getFilename ();
2018-09-06 15:04:06 +03:00
$appDirUser = fileowner ( $absAppPath );
2018-08-09 20:48:55 +03:00
if ( $appDirUser !== $currentUser ) {
2018-08-30 21:52:43 +03:00
$appDirsWithDifferentOwner [] = $absAppPath ;
2018-08-09 20:48:55 +03:00
}
}
}
return $appDirsWithDifferentOwner ;
}
2018-12-04 19:05:52 +03:00
/**
* Checks for potential PHP modules that would improve the instance
*
* @ return string [] A list of PHP modules that is recommended
*/
protected function hasRecommendedPHPModules () : array {
$recommendedPHPModules = [];
2019-04-21 22:55:50 +03:00
if ( ! extension_loaded ( 'intl' )) {
2018-12-04 19:05:52 +03:00
$recommendedPHPModules [] = 'intl' ;
}
if ( $this -> config -> getAppValue ( 'theming' , 'enabled' , 'no' ) === 'yes' ) {
if ( ! extension_loaded ( 'imagick' )) {
$recommendedPHPModules [] = 'imagick' ;
}
}
return $recommendedPHPModules ;
}
2019-02-27 12:47:57 +03:00
protected function isMysqlUsedWithoutUTF8MB4 () : bool {
return ( $this -> config -> getSystemValue ( 'dbtype' , 'sqlite' ) === 'mysql' ) && ( $this -> config -> getSystemValue ( 'mysql.utf8mb4' , false ) === false );
}
2018-12-04 20:43:02 +03:00
protected function hasBigIntConversionPendingColumns () : array {
// copy of ConvertFilecacheBigInt::getColumnsByTable()
$tables = [
'activity' => [ 'activity_id' , 'object_id' ],
'activity_mq' => [ 'mail_id' ],
'filecache' => [ 'fileid' , 'storage' , 'parent' , 'mimetype' , 'mimepart' , 'mtime' , 'storage_mtime' ],
'mimetypes' => [ 'id' ],
'storages' => [ 'numeric_id' ],
];
$schema = new SchemaWrapper ( $this -> db );
$isSqlite = $this -> db -> getDatabasePlatform () instanceof SqlitePlatform ;
$pendingColumns = [];
foreach ( $tables as $tableName => $columns ) {
if ( ! $schema -> hasTable ( $tableName )) {
continue ;
}
$table = $schema -> getTable ( $tableName );
foreach ( $columns as $columnName ) {
$column = $table -> getColumn ( $columnName );
$isAutoIncrement = $column -> getAutoincrement ();
$isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement ;
if ( $column -> getType () -> getName () !== Type :: BIGINT && ! $isAutoIncrementOnSqlite ) {
$pendingColumns [] = $tableName . '.' . $columnName ;
}
}
}
return $pendingColumns ;
}
2019-03-08 15:36:11 +03:00
protected function isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed () : bool {
$objectStore = $this -> config -> getSystemValue ( 'objectstore' , null );
$objectStoreMultibucket = $this -> config -> getSystemValue ( 'objectstore_multibucket' , null );
if ( ! isset ( $objectStoreMultibucket ) && ! isset ( $objectStore )) {
return true ;
}
if ( isset ( $objectStoreMultibucket [ 'class' ]) && $objectStoreMultibucket [ 'class' ] !== 'OC\\Files\\ObjectStore\\S3' ) {
return true ;
}
if ( isset ( $objectStore [ 'class' ]) && $objectStore [ 'class' ] !== 'OC\\Files\\ObjectStore\\S3' ) {
return true ;
}
$tempPath = sys_get_temp_dir ();
if ( ! is_dir ( $tempPath )) {
$this -> logger -> error ( 'Error while checking the temporary PHP path - it was not properly set to a directory. value: ' . $tempPath );
return false ;
}
$freeSpaceInTemp = disk_free_space ( $tempPath );
if ( $freeSpaceInTemp === false ) {
$this -> logger -> error ( 'Error while checking the available disk space of temporary PHP path - no free disk space returned. temporary path: ' . $tempPath );
return false ;
}
$freeSpaceInTempInGB = $freeSpaceInTemp / 1024 / 1024 / 1024 ;
if ( $freeSpaceInTempInGB > 50 ) {
return true ;
}
$this -> logger -> warning ( 'Checking the available space in the temporary path resulted in ' . round ( $freeSpaceInTempInGB , 1 ) . ' GB instead of the recommended 50GB. Path: ' . $tempPath );
return false ;
}
2015-03-26 16:51:33 +03:00
/**
* @ return DataResponse
*/
public function check () {
return new DataResponse (
[
2018-06-13 12:45:49 +03:00
'isGetenvServerWorking' => ! empty ( getenv ( 'PATH' )),
'isReadOnlyConfig' => $this -> isReadOnlyConfig (),
'hasValidTransactionIsolationLevel' => $this -> hasValidTransactionIsolationLevel (),
'hasFileinfoInstalled' => $this -> hasFileinfoInstalled (),
'hasWorkingFileLocking' => $this -> hasWorkingFileLocking (),
'suggestedOverwriteCliURL' => $this -> getSuggestedOverwriteCliURL (),
'cronInfo' => $this -> getLastCronInfo (),
2018-06-19 17:26:06 +03:00
'cronErrors' => $this -> getCronErrors (),
2019-06-25 14:37:31 +03:00
'serverHasInternetConnectionProblems' => $this -> hasInternetConnectivityProblems (),
2015-03-26 16:51:33 +03:00
'isMemcacheConfigured' => $this -> isMemcacheConfigured (),
2015-04-07 12:11:31 +03:00
'memcacheDocs' => $this -> urlGenerator -> linkToDocs ( 'admin-performance' ),
2018-07-27 12:20:47 +03:00
'isRandomnessSecure' => $this -> isRandomnessSecure (),
2015-05-26 15:11:38 +03:00
'securityDocs' => $this -> urlGenerator -> linkToDocs ( 'admin-security' ),
2015-07-27 17:29:05 +03:00
'isUsedTlsLibOutdated' => $this -> isUsedTlsLibOutdated (),
2015-07-28 11:06:26 +03:00
'phpSupported' => $this -> isPhpSupported (),
2015-07-25 21:18:32 +03:00
'forwardedForHeadersWorking' => $this -> forwardedForHeadersWorking (),
'reverseProxyDocs' => $this -> urlGenerator -> linkToDocs ( 'admin-reverse-proxy' ),
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
'isCorrectMemcachedPHPModuleInstalled' => $this -> isCorrectMemcachedPHPModuleInstalled (),
'hasPassedCodeIntegrityCheck' => $this -> checker -> hasPassedCheck (),
'codeIntegrityCheckerDocumentation' => $this -> urlGenerator -> linkToDocs ( 'admin-code-integrity' ),
2017-02-15 09:40:36 +03:00
'isOpcacheProperlySetup' => $this -> isOpcacheProperlySetup (),
2018-07-11 16:31:33 +03:00
'hasOpcacheLoaded' => $this -> hasOpcacheLoaded (),
2017-02-15 09:40:36 +03:00
'phpOpcacheDocumentation' => $this -> urlGenerator -> linkToDocs ( 'admin-php-opcache' ),
2017-03-16 13:48:28 +03:00
'isSettimelimitAvailable' => $this -> isSettimelimitAvailable (),
2017-12-13 14:36:48 +03:00
'hasFreeTypeSupport' => $this -> hasFreeTypeSupport (),
2018-06-13 12:45:49 +03:00
'missingIndexes' => $this -> hasMissingIndexes (),
2018-06-12 17:16:29 +03:00
'isSqliteUsed' => $this -> isSqliteUsed (),
'databaseConversionDocumentation' => $this -> urlGenerator -> linkToDocs ( 'admin-db-conversion' ),
2018-12-04 19:58:35 +03:00
'isPHPMailerUsed' => $this -> isPHPMailerUsed (),
2018-08-04 21:39:39 +03:00
'mailSettingsDocumentation' => $this -> urlGenerator -> getAbsoluteURL ( 'index.php/settings/admin' ),
2018-08-04 22:53:50 +03:00
'isMemoryLimitSufficient' => $this -> memoryInfo -> isMemoryLimitSufficient (),
2018-08-09 20:47:55 +03:00
'appDirsWithDifferentOwner' => $this -> getAppDirsWithDifferentOwner (),
2018-12-04 19:05:52 +03:00
'recommendedPHPModules' => $this -> hasRecommendedPHPModules (),
2018-12-04 20:43:02 +03:00
'pendingBigIntConversionColumns' => $this -> hasBigIntConversionPendingColumns (),
2019-02-27 12:47:57 +03:00
'isMysqlUsedWithoutUTF8MB4' => $this -> isMysqlUsedWithoutUTF8MB4 (),
2019-03-08 15:36:11 +03:00
'isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed' => $this -> isEnoughTempSpaceAvailableIfS3PrimaryStorageIsUsed (),
2015-03-26 16:51:33 +03:00
]
);
}
}