nextcloud-server/lib/private
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 +07:00
..
activity update licence headers via script 2015-10-05 21:15:52 +07:00
app Always installed apps includes the hardcoded ones from shipped.json 2015-11-19 09:11:14 +07:00
appframework Allow DI the system tag stuff without Application class 2015-11-30 17:08:29 +07:00
archive Fix #19181: Support .bz2 app archives 2015-10-20 21:56:24 +07:00
backgroundjob deduplicate @xenopathic 2015-10-06 09:52:19 +07:00
cache Allow storage wrappers to through a forbidden exception with retry information 2015-11-17 10:39:52 +07:00
command Merge pull request #15129 from owncloud/version-command-bus 2015-03-26 19:55:13 +07:00
console Update license headers 2015-10-26 14:04:01 +07:00
contacts Update license headers 2015-03-26 11:44:36 +07:00
db Merge pull request #20393 from owncloud/querybuilder-select-with-alias 2015-11-26 16:19:20 +07:00
diagnostics Update license headers 2015-03-26 11:44:36 +07:00
encryption cache result from parent folders 2015-11-04 09:27:29 +07:00
files Add DB group to some files_external tests 2015-11-30 10:55:10 +07:00
group Adjust PHPDoc as suggested 2015-11-20 14:38:29 +07:00
hooks update license headers and authors 2015-06-25 14:13:49 +07:00
http/client update licence headers via script 2015-10-05 21:15:52 +07:00
integritycheck Add code integrity check 2015-12-01 11:55:20 +07:00
l10n update licence headers via script 2015-10-05 21:15:52 +07:00
legacy Drop OC_SubAdmin and replace usages 2015-10-29 11:31:18 +07:00
lock Update license headers 2015-10-26 14:04:01 +07:00
log fixes #20538 2015-11-16 16:29:21 +07:00
mail Setup sendmail transport 2015-10-08 16:48:18 +07:00
memcache Handle errors on memcached level - fixes #17397 2015-11-10 15:58:17 +07:00
notification Make sure that object id can be a string 2015-11-23 14:18:15 +07:00
ocs Add a new core capability which tells the clients which url to use 2015-11-03 14:27:36 +07:00
preview deduplicate @xenopathic 2015-10-06 09:52:19 +07:00
route Dont die when we're missing a route 2015-11-27 14:29:06 +07:00
search Scrutinizer Auto-Fixes 2015-05-19 11:23:06 +07:00
security Use native CSPRNG if available 2015-11-09 15:04:22 +07:00
session Delete cookie instead of emptying value 2015-10-19 19:54:12 +07:00
setup Update license headers 2015-10-26 14:04:01 +07:00
share use hooks to auto add server to the list of trusted servers once a federated share was created 2015-11-24 11:34:38 +07:00
share20 [Sharing 2.0] Fix phpdoc etc 2015-11-24 10:26:36 +07:00
systemtag Do not count the entries when we only need to know if it is at least one 2015-11-30 10:20:00 +07:00
tagging Update license headers 2015-03-26 11:44:36 +07:00
template Untangle the linkToDocs method in OC_Helper 2015-11-26 13:58:43 +07:00
user Introduce \OCP\IUser::getEMailAddress() 2015-11-25 22:23:34 +07:00
activitymanager.php update licence headers via script 2015-10-05 21:15:52 +07:00
allconfig.php Move the filtering of sensitive data to the config class 2015-09-25 11:08:33 +07:00
api.php Drop OC_SubAdmin and replace usages 2015-10-29 11:31:18 +07:00
app.php Drop OC_SubAdmin and replace usages 2015-10-29 11:31:18 +07:00
appconfig.php update licence headers via script 2015-10-05 21:15:52 +07:00
apphelper.php update license headers and authors 2015-06-25 14:13:49 +07:00
archive.php Use actual mimetype detection instead of extension 2015-10-31 00:55:37 +07:00
avatar.php cache resized avatars 2015-11-28 17:33:16 +07:00
avatarmanager.php Update license headers 2015-10-26 14:04:01 +07:00
capabilitiesmanager.php Update license headers 2015-10-26 14:04:01 +07:00
config.php Untangle the linkToDocs method in OC_Helper 2015-11-26 13:58:43 +07:00
contactsmanager.php Update license headers 2015-03-26 11:44:36 +07:00
databaseexception.php Update license headers 2015-03-26 11:44:36 +07:00
databasesetupexception.php Update license headers 2015-03-26 11:44:36 +07:00
datetimeformatter.php Update license headers 2015-03-26 11:44:36 +07:00
datetimezone.php When guessing the timezone, the offset might only be valid on a given timestamp 2015-04-07 10:13:06 +07:00
db.php Remove remainings of mssql 2015-07-29 18:19:31 +07:00
defaults.php Revert "make knowledge base url configurable" 2015-08-11 14:20:25 +07:00
eventsource.php update licence headers via script 2015-10-05 21:15:52 +07:00
filechunking.php work directly on storages when doing a chunked upload assembly 2015-09-14 20:35:33 +07:00
files.php Allow storage wrappers to through a forbidden exception with retry information 2015-11-17 10:39:52 +07:00
forbiddenexception.php Update license headers 2015-03-26 11:44:36 +07:00
group.php Adjust PHPDoc as suggested 2015-11-20 14:38:29 +07:00
helper.php Untangle the linkToDocs method in OC_Helper 2015-11-26 13:58:43 +07:00
hintexception.php Update license headers 2015-03-26 11:44:36 +07:00
hook.php Update license headers 2015-10-26 14:04:01 +07:00
httphelper.php Add connection timeout to default POST options 2015-05-26 11:22:50 +07:00
image.php Update license headers 2015-10-26 14:04:01 +07:00
installer.php Remove last occurences of OC_Helper::getMimeType() 2015-11-26 10:18:32 +07:00
json.php Drop OC_SubAdmin and replace usages 2015-10-29 11:31:18 +07:00
l10n.php Add warning for broken l10n json files 2015-10-30 09:10:16 +07:00
largefilehelper.php Update license headers 2015-03-26 11:44:36 +07:00
log.php update licence headers via script 2015-10-05 21:15:52 +07:00
naturalsort.php update licence headers via script 2015-10-05 21:15:52 +07:00
naturalsort_defaultcollator.php Update license headers 2015-03-26 11:44:36 +07:00
navigationmanager.php Update license headers 2015-03-26 11:44:36 +07:00
needsupdateexception.php Update license headers 2015-03-26 11:44:36 +07:00
notsquareexception.php Update license headers 2015-03-26 11:44:36 +07:00
ocs.php update licence headers via script 2015-10-05 21:15:52 +07:00
ocsclient.php Disable app store for EE by default 2015-10-08 14:52:52 +07:00
preview.php Add tests 2015-10-01 13:17:22 +07:00
previewmanager.php update license headers and authors 2015-06-25 14:13:49 +07:00
repair.php Add a repair step that checks for group membership on shares 2015-10-29 09:26:26 +07:00
repairexception.php Update license headers 2015-03-26 11:44:36 +07:00
repairstep.php update license headers and authors 2015-06-25 14:13:49 +07:00
response.php Use getHttpProtocol instead of $_SERVER 2015-10-30 18:05:30 +07:00
search.php Update license headers 2015-03-26 11:44:36 +07:00
server.php Add code integrity check 2015-12-01 11:55:20 +07:00
servernotavailableexception.php update license headers and authors 2015-06-25 14:13:49 +07:00
serviceunavailableexception.php Update license headers 2015-03-26 11:44:36 +07:00
setup.php Check for PDO instead of removed function for PHP 7 compatibility 2015-07-30 12:32:22 +07:00
streamer.php Update license headers 2015-10-26 14:04:01 +07:00
subadmin.php subadmin methods should not return any null user or group 2015-11-05 11:50:57 +07:00
systemconfig.php Deduplicate constant 2015-09-25 13:17:23 +07:00
tagmanager.php Update license headers 2015-03-26 11:44:36 +07:00
tags.php Fix undefined variable $tagId 2015-05-04 16:19:26 +07:00
template.php Now using IE8 workaround of davclient.js for all IE versions 2015-11-22 16:05:52 +07:00
templatelayout.php Add code integrity check 2015-12-01 11:55:20 +07:00
tempmanager.php deduplicate @xenopathic 2015-10-06 09:52:19 +07:00
updater.php Add code integrity check 2015-12-01 11:55:20 +07:00
urlgenerator.php Add DB group to some files_external tests 2015-11-30 10:55:10 +07:00
user.php Update license headers 2015-10-26 14:04:01 +07:00
util.php Untangle the linkToDocs method in OC_Helper 2015-11-26 13:58:43 +07:00