nextcloud/tests/lib
Lukas Reschke 4971015544 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 😉). 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-12-01 11:55:20 +01:00
..
app fix unit tests 2015-11-23 13:13:26 +01:00
appframework Mock DIContainer to not hit the database 2015-11-30 10:55:05 +01:00
archive Make root tests extend the \Test\TestCase 2014-11-19 14:53:51 +01:00
backgroundjob Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
cache Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
command Add code integrity check 2015-12-01 11:55:20 +01:00
contacts Introduce \OCP\IUser::getEMailAddress() 2015-11-25 22:23:34 +01:00
db Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
encryption Adding more DB groups to test suits 2015-11-30 10:55:06 +01:00
files More group DB 2015-11-30 10:55:13 +01:00
group Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
hooks more type hints 2015-06-02 14:07:55 +02:00
http/client Move the helpful method to the TestCase class 2015-06-03 12:33:29 +02:00
integritycheck Add code integrity check 2015-12-01 11:55:20 +01:00
lock Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
log Adding more DB groups to test suits 2015-11-30 10:55:06 +01:00
mail Run test only when idn is available 2015-10-16 11:02:10 +02:00
memcache Fallback to complete Memcached flush if getAllKeys fails 2015-09-05 20:02:49 +01:00
notification Make sure that object id can be a string 2015-11-23 14:18:15 +01:00
ocs Adding more DB groups to test suits 2015-11-30 10:55:06 +01:00
preview Adding more DB groups to test suits 2015-11-30 10:55:06 +01:00
public Test overriding channel 2015-05-15 22:37:14 +03:00
repair Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
security Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
session Write to session in batch at the end of the request 2015-09-09 12:48:37 +02:00
share Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
share20 [Sharing 2.0] Default share provider only generic DI 2015-11-24 10:26:36 +01:00
systemtag Fix phpstorm complains in tests 2015-11-30 13:36:22 +01:00
template Add tests for correct path 2015-04-20 12:31:35 +02:00
traits Move dummy backend to Tests namespace 2015-09-22 11:01:11 +02:00
user Adding more test suites to group DB 2015-11-30 10:55:05 +01:00
util/user Move dummy backend to Tests namespace 2015-09-22 11:01:11 +02:00
activitymanager.php Add test coverage for Activity Event and Manager 2015-08-20 10:25:49 +02:00
allconfig.php Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
api.php Merge pull request #18184 from owncloud/ocs-merge-headers 2015-10-21 10:36:37 +02:00
app.php Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
appconfig.php Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
archive.php change tests back to check for logo-wide, make them pass again 2015-05-28 23:39:55 +02:00
autoloader.php Fix autoloader unit test output 2015-11-09 15:54:40 +01:00
avatar.php Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
cache.php Make remaining files extend the test base 2014-11-19 14:53:59 +01:00
capabilitiesmanager.php Use DI 2015-08-10 10:45:16 +02:00
configtests.php rename config test to prevent autoloader issue 2015-09-28 10:47:49 +02:00
contactsmanager.php Mock interface 2014-12-08 13:18:00 +01:00
datetimeformatter.php Use a fixed timestamp so we dont switch days/years with the getTimestampAgo 2014-12-11 13:22:05 +01:00
db.php Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
dbschema.php Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
errorHandler.php Make root tests extend the \Test\TestCase 2014-11-19 14:53:51 +01:00
files.php Unit test OC_Files::setUploadLimit() 2015-07-20 15:03:09 +01:00
group.php Move dummy backend to Tests namespace 2015-09-22 11:01:11 +02:00
helper.php Merge pull request #20744 from owncloud/oc_helper-getMimeType-cleanup 2015-11-26 12:37:25 +01:00
helperstorage.php Adding more DB groups to test suits 2015-11-30 10:55:06 +01:00
hookhelper.php Fire prehooks when uploading directly to storage 2015-05-13 17:47:04 +02:00
httphelper.php Add connection timeout to default POST options 2015-05-26 11:22:50 +02:00
image.php Fix max preview, some resizing and caching issues and force preview providers to resize their previews properly 2015-06-06 16:25:04 +02:00
installer.php Make root tests extend the \Test\TestCase 2014-11-19 14:53:51 +01:00
l10n.php [l10n] remove unused static methods 2015-10-02 12:51:45 +02:00
largefilehelper.php Make root tests extend the \Test\TestCase 2014-11-19 14:53:51 +01:00
largefilehelpergetfilesize.php Check if open_basedir is set 2014-12-11 00:09:55 +01:00
logger.php Remove passwords from logged exception stack traces 2015-09-24 20:01:30 +02:00
naturalsort.php Add PHPunit test for DefaultCollator 2015-02-24 23:51:08 +01:00
navigationmanagertest.php Add tests for the navigation manager (closure) behaviour 2015-03-16 16:46:17 +01:00
ocsclienttest.php Merge pull request #17222 from owncloud/issue-17101-send-oc-version-to-app-store 2015-06-29 15:07:00 +02:00
preview.php Adding more DB groups to test suits 2015-11-30 10:55:06 +01:00
repair.php Make root tests extend the \Test\TestCase 2014-11-19 14:53:51 +01:00
server.php Adding more DB groups to test suits 2015-11-30 10:55:06 +01:00
setup.php Check for PDO instead of removed function for PHP 7 compatibility 2015-07-30 12:32:22 +02:00
streamwrappers.php Adding more DB groups to test suits 2015-11-30 10:55:06 +01:00
subadmin.php subadmin methods should not return any null user or group 2015-11-05 11:50:57 +01:00
tags.php Apply DB group annotation ... 2015-11-30 10:55:05 +01:00
template.php verify the path in the autoloader 2015-09-01 15:03:28 +02:00
tempmanager.php Unit test getting temp dir from config 2015-08-30 23:34:38 +01:00
testcase.php Don't break app on travis 2015-11-30 10:55:13 +01:00
testmoveablemountpoint.php Keep shared locks in post hooks 2015-06-25 16:33:02 +02:00
updater.php Add code integrity check 2015-12-01 11:55:20 +01:00
urlGenerator.php Add DB group to some files_external tests 2015-11-30 10:55:10 +01:00
user.php Further unit test suite tweats 2015-11-30 10:55:05 +01:00
util.php Further unit test suite tweats 2015-11-30 10:55:05 +01:00
utilcheckserver.php Add DB group to some files_external tests 2015-11-30 10:55:10 +01:00