You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2383 lines
74 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
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.
10 years ago
10 years ago
12 years ago
Add public API to give developers the possibility to adjust the global CSP defaults Allows to inject something into the default content policy. This is for example useful when you're injecting Javascript code into a view belonging to another controller and cannot modify its Content-Security-Policy itself. Note that the adjustment is only applied to applications that use AppFramework controllers. To use this from your `app.php` use `\OC::$server->getContentSecurityPolicyManager()->addDefaultPolicy($policy)`, $policy has to be of type `\OCP\AppFramework\Http\ContentSecurityPolicy`. To test this add something like the following into an `app.php` of any enabled app: ``` $manager = \OC::$server->getContentSecurityPolicyManager(); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('asdf'); $policy->addAllowedScriptDomain('yolo.com'); $policy->allowInlineScript(false); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFontDomain('yolo.com'); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('banana.com'); $manager->addDefaultPolicy($policy); ``` If you now open the files app the policy should be: ``` Content-Security-Policy:default-src 'none';script-src yolo.com 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src yolo.com 'self';connect-src 'self';media-src 'self';frame-src asdf banana.com 'self' ```
10 years ago
10 years ago
10 years ago
10 years ago
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.
10 years ago
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.
10 years ago
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.
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
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.
10 years ago
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.
10 years ago
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.
10 years ago
Add public API to give developers the possibility to adjust the global CSP defaults Allows to inject something into the default content policy. This is for example useful when you're injecting Javascript code into a view belonging to another controller and cannot modify its Content-Security-Policy itself. Note that the adjustment is only applied to applications that use AppFramework controllers. To use this from your `app.php` use `\OC::$server->getContentSecurityPolicyManager()->addDefaultPolicy($policy)`, $policy has to be of type `\OCP\AppFramework\Http\ContentSecurityPolicy`. To test this add something like the following into an `app.php` of any enabled app: ``` $manager = \OC::$server->getContentSecurityPolicyManager(); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('asdf'); $policy->addAllowedScriptDomain('yolo.com'); $policy->allowInlineScript(false); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFontDomain('yolo.com'); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('banana.com'); $manager->addDefaultPolicy($policy); ``` If you now open the files app the policy should be: ``` Content-Security-Policy:default-src 'none';script-src yolo.com 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src yolo.com 'self';connect-src 'self';media-src 'self';frame-src asdf banana.com 'self' ```
10 years ago
Add public API to give developers the possibility to adjust the global CSP defaults Allows to inject something into the default content policy. This is for example useful when you're injecting Javascript code into a view belonging to another controller and cannot modify its Content-Security-Policy itself. Note that the adjustment is only applied to applications that use AppFramework controllers. To use this from your `app.php` use `\OC::$server->getContentSecurityPolicyManager()->addDefaultPolicy($policy)`, $policy has to be of type `\OCP\AppFramework\Http\ContentSecurityPolicy`. To test this add something like the following into an `app.php` of any enabled app: ``` $manager = \OC::$server->getContentSecurityPolicyManager(); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('asdf'); $policy->addAllowedScriptDomain('yolo.com'); $policy->allowInlineScript(false); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFontDomain('yolo.com'); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('banana.com'); $manager->addDefaultPolicy($policy); ``` If you now open the files app the policy should be: ``` Content-Security-Policy:default-src 'none';script-src yolo.com 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src yolo.com 'self';connect-src 'self';media-src 'self';frame-src asdf banana.com 'self' ```
10 years ago
Add public API to give developers the possibility to adjust the global CSP defaults Allows to inject something into the default content policy. This is for example useful when you're injecting Javascript code into a view belonging to another controller and cannot modify its Content-Security-Policy itself. Note that the adjustment is only applied to applications that use AppFramework controllers. To use this from your `app.php` use `\OC::$server->getContentSecurityPolicyManager()->addDefaultPolicy($policy)`, $policy has to be of type `\OCP\AppFramework\Http\ContentSecurityPolicy`. To test this add something like the following into an `app.php` of any enabled app: ``` $manager = \OC::$server->getContentSecurityPolicyManager(); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('asdf'); $policy->addAllowedScriptDomain('yolo.com'); $policy->allowInlineScript(false); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFontDomain('yolo.com'); $manager->addDefaultPolicy($policy); $policy = new \OCP\AppFramework\Http\ContentSecurityPolicy(false); $policy->addAllowedFrameDomain('banana.com'); $manager->addDefaultPolicy($policy); ``` If you now open the files app the policy should be: ``` Content-Security-Policy:default-src 'none';script-src yolo.com 'self' 'unsafe-eval';style-src 'self' 'unsafe-inline';img-src 'self' data: blob:;font-src yolo.com 'self';connect-src 'self';media-src 'self';frame-src asdf banana.com 'self' ```
10 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. * @copyright Copyright (c) 2016, Lukas Reschke <lukas@statuscode.ch>
  5. *
  6. * @author Arne Hamann <kontakt+github@arne.email>
  7. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  8. * @author Bart Visscher <bartv@thisnet.nl>
  9. * @author Bernhard Posselt <dev@bernhard-posselt.com>
  10. * @author Bernhard Reiter <ockham@raz.or.at>
  11. * @author Bjoern Schiessle <bjoern@schiessle.org>
  12. * @author Björn Schießle <bjoern@schiessle.org>
  13. * @author Christopher Schäpers <kondou@ts.unde.re>
  14. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  15. * @author Damjan Georgievski <gdamjan@gmail.com>
  16. * @author Daniel Kesselberg <mail@danielkesselberg.de>
  17. * @author Georg Ehrke <oc.list@georgehrke.com>
  18. * @author Joas Schilling <coding@schilljs.com>
  19. * @author John Molakvoæ <skjnldsv@protonmail.com>
  20. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  21. * @author Julius Haertl <jus@bitgrid.net>
  22. * @author Julius Härtl <jus@bitgrid.net>
  23. * @author Lionel Elie Mamane <lionel@mamane.lu>
  24. * @author Lukas Reschke <lukas@statuscode.ch>
  25. * @author Maxence Lange <maxence@artificial-owl.com>
  26. * @author Michael Weimann <mail@michael-weimann.eu>
  27. * @author Morris Jobke <hey@morrisjobke.de>
  28. * @author Piotr Mrówczyński <mrow4a@yahoo.com>
  29. * @author Robin Appelman <robin@icewind.nl>
  30. * @author Robin McCorkell <robin@mccorkell.me.uk>
  31. * @author Roeland Jago Douma <roeland@famdouma.nl>
  32. * @author root <root@localhost.localdomain>
  33. * @author Thomas Müller <thomas.mueller@tmit.eu>
  34. * @author Thomas Tanghus <thomas@tanghus.net>
  35. * @author Tobia De Koninck <tobia@ledfan.be>
  36. * @author Vincent Petry <vincent@nextcloud.com>
  37. *
  38. * @license AGPL-3.0
  39. *
  40. * This code is free software: you can redistribute it and/or modify
  41. * it under the terms of the GNU Affero General Public License, version 3,
  42. * as published by the Free Software Foundation.
  43. *
  44. * This program is distributed in the hope that it will be useful,
  45. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  46. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  47. * GNU Affero General Public License for more details.
  48. *
  49. * You should have received a copy of the GNU Affero General Public License, version 3,
  50. * along with this program. If not, see <http://www.gnu.org/licenses/>
  51. *
  52. */
  53. namespace OC;
  54. use bantu\IniGetWrapper\IniGetWrapper;
  55. use OC\Accounts\AccountManager;
  56. use OC\App\AppManager;
  57. use OC\App\AppStore\Bundles\BundleFetcher;
  58. use OC\App\AppStore\Fetcher\AppFetcher;
  59. use OC\App\AppStore\Fetcher\CategoryFetcher;
  60. use OC\AppFramework\Bootstrap\Coordinator;
  61. use OC\AppFramework\Http\Request;
  62. use OC\AppFramework\Http\RequestId;
  63. use OC\AppFramework\Utility\TimeFactory;
  64. use OC\Authentication\Events\LoginFailed;
  65. use OC\Authentication\Listeners\LoginFailedListener;
  66. use OC\Authentication\Listeners\UserLoggedInListener;
  67. use OC\Authentication\LoginCredentials\Store;
  68. use OC\Authentication\Token\IProvider;
  69. use OC\Avatar\AvatarManager;
  70. use OC\Collaboration\Collaborators\GroupPlugin;
  71. use OC\Collaboration\Collaborators\MailPlugin;
  72. use OC\Collaboration\Collaborators\RemoteGroupPlugin;
  73. use OC\Collaboration\Collaborators\RemotePlugin;
  74. use OC\Collaboration\Collaborators\UserPlugin;
  75. use OC\Collaboration\Reference\ReferenceManager;
  76. use OC\Command\CronBus;
  77. use OC\Comments\ManagerFactory as CommentsManagerFactory;
  78. use OC\Contacts\ContactsMenu\ActionFactory;
  79. use OC\Contacts\ContactsMenu\ContactsStore;
  80. use OC\Dashboard\DashboardManager;
  81. use OC\DB\Connection;
  82. use OC\DB\ConnectionAdapter;
  83. use OC\Diagnostics\EventLogger;
  84. use OC\Diagnostics\QueryLogger;
  85. use OC\EventDispatcher\SymfonyAdapter;
  86. use OC\Federation\CloudFederationFactory;
  87. use OC\Federation\CloudFederationProviderManager;
  88. use OC\Federation\CloudIdManager;
  89. use OC\Files\Config\UserMountCache;
  90. use OC\Files\Config\UserMountCacheListener;
  91. use OC\Files\Lock\LockManager;
  92. use OC\Files\Mount\CacheMountProvider;
  93. use OC\Files\Mount\LocalHomeMountProvider;
  94. use OC\Files\Mount\ObjectHomeMountProvider;
  95. use OC\Files\Mount\ObjectStorePreviewCacheMountProvider;
  96. use OC\Files\Mount\RootMountProvider;
  97. use OC\Files\Node\HookConnector;
  98. use OC\Files\Node\LazyRoot;
  99. use OC\Files\Node\Root;
  100. use OC\Files\SetupManager;
  101. use OC\Files\Storage\StorageFactory;
  102. use OC\Files\Template\TemplateManager;
  103. use OC\Files\Type\Loader;
  104. use OC\Files\View;
  105. use OC\FullTextSearch\FullTextSearchManager;
  106. use OC\Http\Client\ClientService;
  107. use OC\Http\Client\DnsPinMiddleware;
  108. use OC\Http\Client\LocalAddressChecker;
  109. use OC\Http\Client\NegativeDnsCache;
  110. use OC\IntegrityCheck\Checker;
  111. use OC\IntegrityCheck\Helpers\AppLocator;
  112. use OC\IntegrityCheck\Helpers\EnvironmentHelper;
  113. use OC\IntegrityCheck\Helpers\FileAccessHelper;
  114. use OC\LDAP\NullLDAPProviderFactory;
  115. use OC\KnownUser\KnownUserService;
  116. use OC\Lock\DBLockingProvider;
  117. use OC\Lock\MemcacheLockingProvider;
  118. use OC\Lock\NoopLockingProvider;
  119. use OC\Lockdown\LockdownManager;
  120. use OC\Log\LogFactory;
  121. use OC\Log\PsrLoggerAdapter;
  122. use OC\Mail\Mailer;
  123. use OC\Memcache\ArrayCache;
  124. use OC\Memcache\Factory;
  125. use OC\Metadata\Capabilities as MetadataCapabilities;
  126. use OC\Metadata\IMetadataManager;
  127. use OC\Metadata\MetadataManager;
  128. use OC\Notification\Manager;
  129. use OC\OCS\DiscoveryService;
  130. use OC\Preview\GeneratorHelper;
  131. use OC\Remote\Api\ApiFactory;
  132. use OC\Remote\InstanceFactory;
  133. use OC\RichObjectStrings\Validator;
  134. use OC\Route\Router;
  135. use OC\Security\Bruteforce\Throttler;
  136. use OC\Security\CertificateManager;
  137. use OC\Security\CredentialsManager;
  138. use OC\Security\Crypto;
  139. use OC\Security\CSP\ContentSecurityPolicyManager;
  140. use OC\Security\CSP\ContentSecurityPolicyNonceManager;
  141. use OC\Security\CSRF\CsrfTokenManager;
  142. use OC\Security\CSRF\TokenStorage\SessionStorage;
  143. use OC\Security\Hasher;
  144. use OC\Security\SecureRandom;
  145. use OC\Security\TrustedDomainHelper;
  146. use OC\Security\VerificationToken\VerificationToken;
  147. use OC\Session\CryptoWrapper;
  148. use OC\Share20\ProviderFactory;
  149. use OC\Share20\ShareHelper;
  150. use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
  151. use OC\Tagging\TagMapper;
  152. use OC\Talk\Broker;
  153. use OC\Template\JSCombiner;
  154. use OC\User\DisplayNameCache;
  155. use OC\User\Listeners\BeforeUserDeletedListener;
  156. use OC\User\Listeners\UserChangedListener;
  157. use OC\User\Session;
  158. use OCA\Theming\ImageManager;
  159. use OCA\Theming\ThemingDefaults;
  160. use OCA\Theming\Util;
  161. use OCP\Accounts\IAccountManager;
  162. use OCP\App\IAppManager;
  163. use OCP\Authentication\LoginCredentials\IStore;
  164. use OCP\BackgroundJob\IJobList;
  165. use OCP\Collaboration\AutoComplete\IManager;
  166. use OCP\Collaboration\Reference\IReferenceManager;
  167. use OCP\Command\IBus;
  168. use OCP\Comments\ICommentsManager;
  169. use OCP\Contacts\ContactsMenu\IActionFactory;
  170. use OCP\Contacts\ContactsMenu\IContactsStore;
  171. use OCP\Dashboard\IDashboardManager;
  172. use OCP\Defaults;
  173. use OCP\Diagnostics\IEventLogger;
  174. use OCP\Diagnostics\IQueryLogger;
  175. use OCP\Encryption\IFile;
  176. use OCP\Encryption\Keys\IStorage;
  177. use OCP\EventDispatcher\IEventDispatcher;
  178. use OCP\Federation\ICloudFederationFactory;
  179. use OCP\Federation\ICloudFederationProviderManager;
  180. use OCP\Federation\ICloudIdManager;
  181. use OCP\Files\Config\IMountProviderCollection;
  182. use OCP\Files\Config\IUserMountCache;
  183. use OCP\Files\IMimeTypeDetector;
  184. use OCP\Files\IMimeTypeLoader;
  185. use OCP\Files\IRootFolder;
  186. use OCP\Files\Lock\ILockManager;
  187. use OCP\Files\Mount\IMountManager;
  188. use OCP\Files\Storage\IStorageFactory;
  189. use OCP\Files\Template\ITemplateManager;
  190. use OCP\FullTextSearch\IFullTextSearchManager;
  191. use OCP\GlobalScale\IConfig;
  192. use OCP\Group\Events\BeforeGroupCreatedEvent;
  193. use OCP\Group\Events\BeforeGroupDeletedEvent;
  194. use OCP\Group\Events\BeforeUserAddedEvent;
  195. use OCP\Group\Events\BeforeUserRemovedEvent;
  196. use OCP\Group\Events\GroupCreatedEvent;
  197. use OCP\Group\Events\GroupDeletedEvent;
  198. use OCP\Group\Events\UserAddedEvent;
  199. use OCP\Group\Events\UserRemovedEvent;
  200. use OCP\Group\ISubAdmin;
  201. use OCP\Http\Client\IClientService;
  202. use OCP\IAppConfig;
  203. use OCP\IAvatarManager;
  204. use OCP\ICache;
  205. use OCP\ICacheFactory;
  206. use OCP\ICertificateManager;
  207. use OCP\IBinaryFinder;
  208. use OCP\IDateTimeFormatter;
  209. use OCP\IDateTimeZone;
  210. use OCP\IDBConnection;
  211. use OCP\IGroupManager;
  212. use OCP\IInitialStateService;
  213. use OCP\IL10N;
  214. use OCP\ILogger;
  215. use OCP\INavigationManager;
  216. use OCP\IPreview;
  217. use OCP\IRequest;
  218. use OCP\IRequestId;
  219. use OCP\ISearch;
  220. use OCP\IServerContainer;
  221. use OCP\ISession;
  222. use OCP\ITagManager;
  223. use OCP\ITempManager;
  224. use OCP\IURLGenerator;
  225. use OCP\IUserManager;
  226. use OCP\IUserSession;
  227. use OCP\L10N\IFactory;
  228. use OCP\LDAP\ILDAPProvider;
  229. use OCP\LDAP\ILDAPProviderFactory;
  230. use OCP\Lock\ILockingProvider;
  231. use OCP\Lockdown\ILockdownManager;
  232. use OCP\Log\ILogFactory;
  233. use OCP\Mail\IMailer;
  234. use OCP\Remote\Api\IApiFactory;
  235. use OCP\Remote\IInstanceFactory;
  236. use OCP\RichObjectStrings\IValidator;
  237. use OCP\Route\IRouter;
  238. use OCP\Security\Bruteforce\IThrottler;
  239. use OCP\Security\IContentSecurityPolicyManager;
  240. use OCP\Security\ICredentialsManager;
  241. use OCP\Security\ICrypto;
  242. use OCP\Security\IHasher;
  243. use OCP\Security\ISecureRandom;
  244. use OCP\Security\ITrustedDomainHelper;
  245. use OCP\Security\VerificationToken\IVerificationToken;
  246. use OCP\Share\IShareHelper;
  247. use OCP\SystemTag\ISystemTagManager;
  248. use OCP\SystemTag\ISystemTagObjectMapper;
  249. use OCP\Talk\IBroker;
  250. use OCP\User\Events\BeforePasswordUpdatedEvent;
  251. use OCP\User\Events\BeforeUserDeletedEvent;
  252. use OCP\User\Events\BeforeUserLoggedInEvent;
  253. use OCP\User\Events\BeforeUserLoggedInWithCookieEvent;
  254. use OCP\User\Events\BeforeUserLoggedOutEvent;
  255. use OCP\User\Events\PasswordUpdatedEvent;
  256. use OCP\User\Events\PostLoginEvent;
  257. use OCP\User\Events\UserChangedEvent;
  258. use OCP\User\Events\UserLoggedInEvent;
  259. use OCP\User\Events\UserLoggedInWithCookieEvent;
  260. use OCP\User\Events\UserLoggedOutEvent;
  261. use Psr\Container\ContainerExceptionInterface;
  262. use Psr\Container\ContainerInterface;
  263. use Psr\Log\LoggerInterface;
  264. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  265. use Symfony\Component\EventDispatcher\GenericEvent;
  266. use OCA\Files_External\Service\UserStoragesService;
  267. use OCA\Files_External\Service\UserGlobalStoragesService;
  268. use OCA\Files_External\Service\GlobalStoragesService;
  269. use OCA\Files_External\Service\BackendService;
  270. use OCP\Profiler\IProfiler;
  271. use OC\Profiler\Profiler;
  272. /**
  273. * Class Server
  274. *
  275. * @package OC
  276. *
  277. * TODO: hookup all manager classes
  278. */
  279. class Server extends ServerContainer implements IServerContainer {
  280. /** @var string */
  281. private $webRoot;
  282. /**
  283. * @param string $webRoot
  284. * @param \OC\Config $config
  285. */
  286. public function __construct($webRoot, \OC\Config $config) {
  287. parent::__construct();
  288. $this->webRoot = $webRoot;
  289. // To find out if we are running from CLI or not
  290. $this->registerParameter('isCLI', \OC::$CLI);
  291. $this->registerParameter('serverRoot', \OC::$SERVERROOT);
  292. $this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
  293. return $c;
  294. });
  295. $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
  296. return $c;
  297. });
  298. $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
  299. /** @deprecated 19.0.0 */
  300. $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
  301. $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
  302. /** @deprecated 19.0.0 */
  303. $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
  304. $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
  305. /** @deprecated 19.0.0 */
  306. $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
  307. $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
  308. /** @deprecated 19.0.0 */
  309. $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
  310. $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
  311. $this->registerAlias(ITemplateManager::class, TemplateManager::class);
  312. $this->registerAlias(IActionFactory::class, ActionFactory::class);
  313. $this->registerService(View::class, function (Server $c) {
  314. return new View();
  315. }, false);
  316. $this->registerService(IPreview::class, function (ContainerInterface $c) {
  317. return new PreviewManager(
  318. $c->get(\OCP\IConfig::class),
  319. $c->get(IRootFolder::class),
  320. new \OC\Preview\Storage\Root(
  321. $c->get(IRootFolder::class),
  322. $c->get(SystemConfig::class)
  323. ),
  324. $c->get(SymfonyAdapter::class),
  325. $c->get(GeneratorHelper::class),
  326. $c->get(ISession::class)->get('user_id'),
  327. $c->get(Coordinator::class),
  328. $c->get(IServerContainer::class),
  329. $c->get(IBinaryFinder::class)
  330. );
  331. });
  332. /** @deprecated 19.0.0 */
  333. $this->registerDeprecatedAlias('PreviewManager', IPreview::class);
  334. $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
  335. return new \OC\Preview\Watcher(
  336. new \OC\Preview\Storage\Root(
  337. $c->get(IRootFolder::class),
  338. $c->get(SystemConfig::class)
  339. )
  340. );
  341. });
  342. $this->registerService(IProfiler::class, function (Server $c) {
  343. return new Profiler($c->get(SystemConfig::class));
  344. });
  345. $this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager {
  346. $view = new View();
  347. $util = new Encryption\Util(
  348. $view,
  349. $c->get(IUserManager::class),
  350. $c->get(IGroupManager::class),
  351. $c->get(\OCP\IConfig::class)
  352. );
  353. return new Encryption\Manager(
  354. $c->get(\OCP\IConfig::class),
  355. $c->get(LoggerInterface::class),
  356. $c->getL10N('core'),
  357. new View(),
  358. $util,
  359. new ArrayCache()
  360. );
  361. });
  362. /** @deprecated 19.0.0 */
  363. $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
  364. /** @deprecated 21.0.0 */
  365. $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class);
  366. $this->registerService(IFile::class, function (ContainerInterface $c) {
  367. $util = new Encryption\Util(
  368. new View(),
  369. $c->get(IUserManager::class),
  370. $c->get(IGroupManager::class),
  371. $c->get(\OCP\IConfig::class)
  372. );
  373. return new Encryption\File(
  374. $util,
  375. $c->get(IRootFolder::class),
  376. $c->get(\OCP\Share\IManager::class)
  377. );
  378. });
  379. /** @deprecated 21.0.0 */
  380. $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class);
  381. $this->registerService(IStorage::class, function (ContainerInterface $c) {
  382. $view = new View();
  383. $util = new Encryption\Util(
  384. $view,
  385. $c->get(IUserManager::class),
  386. $c->get(IGroupManager::class),
  387. $c->get(\OCP\IConfig::class)
  388. );
  389. return new Encryption\Keys\Storage(
  390. $view,
  391. $util,
  392. $c->get(ICrypto::class),
  393. $c->get(\OCP\IConfig::class)
  394. );
  395. });
  396. /** @deprecated 20.0.0 */
  397. $this->registerDeprecatedAlias('TagMapper', TagMapper::class);
  398. $this->registerAlias(\OCP\ITagManager::class, TagManager::class);
  399. /** @deprecated 19.0.0 */
  400. $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
  401. $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
  402. /** @var \OCP\IConfig $config */
  403. $config = $c->get(\OCP\IConfig::class);
  404. $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
  405. return new $factoryClass($this);
  406. });
  407. $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
  408. return $c->get('SystemTagManagerFactory')->getManager();
  409. });
  410. /** @deprecated 19.0.0 */
  411. $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
  412. $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
  413. return $c->get('SystemTagManagerFactory')->getObjectMapper();
  414. });
  415. $this->registerService('RootFolder', function (ContainerInterface $c) {
  416. $manager = \OC\Files\Filesystem::getMountManager(null);
  417. $view = new View();
  418. $root = new Root(
  419. $manager,
  420. $view,
  421. null,
  422. $c->get(IUserMountCache::class),
  423. $this->get(LoggerInterface::class),
  424. $this->get(IUserManager::class),
  425. $this->get(IEventDispatcher::class),
  426. );
  427. $previewConnector = new \OC\Preview\WatcherConnector(
  428. $root,
  429. $c->get(SystemConfig::class)
  430. );
  431. $previewConnector->connectWatcher();
  432. return $root;
  433. });
  434. $this->registerService(HookConnector::class, function (ContainerInterface $c) {
  435. return new HookConnector(
  436. $c->get(IRootFolder::class),
  437. new View(),
  438. $c->get(\OC\EventDispatcher\SymfonyAdapter::class),
  439. $c->get(IEventDispatcher::class)
  440. );
  441. });
  442. /** @deprecated 19.0.0 */
  443. $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
  444. $this->registerService(IRootFolder::class, function (ContainerInterface $c) {
  445. return new LazyRoot(function () use ($c) {
  446. return $c->get('RootFolder');
  447. });
  448. });
  449. /** @deprecated 19.0.0 */
  450. $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
  451. /** @deprecated 19.0.0 */
  452. $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
  453. $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
  454. $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) {
  455. return $c->get(\OC\User\Manager::class)->getDisplayNameCache();
  456. });
  457. $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
  458. $groupManager = new \OC\Group\Manager(
  459. $this->get(IUserManager::class),
  460. $c->get(SymfonyAdapter::class),
  461. $this->get(LoggerInterface::class)
  462. );
  463. $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
  464. /** @var IEventDispatcher $dispatcher */
  465. $dispatcher = $this->get(IEventDispatcher::class);
  466. $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
  467. });
  468. $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
  469. /** @var IEventDispatcher $dispatcher */
  470. $dispatcher = $this->get(IEventDispatcher::class);
  471. $dispatcher->dispatchTyped(new GroupCreatedEvent($group));
  472. });
  473. $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
  474. /** @var IEventDispatcher $dispatcher */
  475. $dispatcher = $this->get(IEventDispatcher::class);
  476. $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
  477. });
  478. $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
  479. /** @var IEventDispatcher $dispatcher */
  480. $dispatcher = $this->get(IEventDispatcher::class);
  481. $dispatcher->dispatchTyped(new GroupDeletedEvent($group));
  482. });
  483. $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  484. /** @var IEventDispatcher $dispatcher */
  485. $dispatcher = $this->get(IEventDispatcher::class);
  486. $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
  487. });
  488. $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  489. /** @var IEventDispatcher $dispatcher */
  490. $dispatcher = $this->get(IEventDispatcher::class);
  491. $dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
  492. });
  493. $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  494. /** @var IEventDispatcher $dispatcher */
  495. $dispatcher = $this->get(IEventDispatcher::class);
  496. $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
  497. });
  498. $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
  499. /** @var IEventDispatcher $dispatcher */
  500. $dispatcher = $this->get(IEventDispatcher::class);
  501. $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
  502. });
  503. return $groupManager;
  504. });
  505. /** @deprecated 19.0.0 */
  506. $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
  507. $this->registerService(Store::class, function (ContainerInterface $c) {
  508. $session = $c->get(ISession::class);
  509. if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
  510. $tokenProvider = $c->get(IProvider::class);
  511. } else {
  512. $tokenProvider = null;
  513. }
  514. $logger = $c->get(LoggerInterface::class);
  515. return new Store($session, $logger, $tokenProvider);
  516. });
  517. $this->registerAlias(IStore::class, Store::class);
  518. $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
  519. $this->registerService(\OC\User\Session::class, function (Server $c) {
  520. $manager = $c->get(IUserManager::class);
  521. $session = new \OC\Session\Memory('');
  522. $timeFactory = new TimeFactory();
  523. // Token providers might require a working database. This code
  524. // might however be called when Nextcloud is not yet setup.
  525. if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
  526. $provider = $c->get(IProvider::class);
  527. } else {
  528. $provider = null;
  529. }
  530. $legacyDispatcher = $c->get(SymfonyAdapter::class);
  531. $userSession = new \OC\User\Session(
  532. $manager,
  533. $session,
  534. $timeFactory,
  535. $provider,
  536. $c->get(\OCP\IConfig::class),
  537. $c->get(ISecureRandom::class),
  538. $c->getLockdownManager(),
  539. $c->get(LoggerInterface::class),
  540. $c->get(IEventDispatcher::class)
  541. );
  542. /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
  543. $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
  544. \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
  545. });
  546. /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
  547. $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
  548. /** @var \OC\User\User $user */
  549. \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
  550. });
  551. /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
  552. $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
  553. /** @var \OC\User\User $user */
  554. \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
  555. $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
  556. });
  557. /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
  558. $userSession->listen('\OC\User', 'postDelete', function ($user) {
  559. /** @var \OC\User\User $user */
  560. \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
  561. });
  562. $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
  563. /** @var \OC\User\User $user */
  564. \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
  565. /** @var IEventDispatcher $dispatcher */
  566. $dispatcher = $this->get(IEventDispatcher::class);
  567. $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
  568. });
  569. $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
  570. /** @var \OC\User\User $user */
  571. \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
  572. /** @var IEventDispatcher $dispatcher */
  573. $dispatcher = $this->get(IEventDispatcher::class);
  574. $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
  575. });
  576. $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
  577. \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
  578. /** @var IEventDispatcher $dispatcher */
  579. $dispatcher = $this->get(IEventDispatcher::class);
  580. $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
  581. });
  582. $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
  583. /** @var \OC\User\User $user */
  584. \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
  585. /** @var IEventDispatcher $dispatcher */
  586. $dispatcher = $this->get(IEventDispatcher::class);
  587. $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
  588. });
  589. $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
  590. /** @var IEventDispatcher $dispatcher */
  591. $dispatcher = $this->get(IEventDispatcher::class);
  592. $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
  593. });
  594. $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
  595. /** @var \OC\User\User $user */
  596. \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
  597. /** @var IEventDispatcher $dispatcher */
  598. $dispatcher = $this->get(IEventDispatcher::class);
  599. $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
  600. });
  601. $userSession->listen('\OC\User', 'logout', function ($user) {
  602. \OC_Hook::emit('OC_User', 'logout', []);
  603. /** @var IEventDispatcher $dispatcher */
  604. $dispatcher = $this->get(IEventDispatcher::class);
  605. $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
  606. });
  607. $userSession->listen('\OC\User', 'postLogout', function ($user) {
  608. /** @var IEventDispatcher $dispatcher */
  609. $dispatcher = $this->get(IEventDispatcher::class);
  610. $dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
  611. });
  612. $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
  613. /** @var \OC\User\User $user */
  614. \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
  615. /** @var IEventDispatcher $dispatcher */
  616. $dispatcher = $this->get(IEventDispatcher::class);
  617. $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
  618. });
  619. return $userSession;
  620. });
  621. $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
  622. /** @deprecated 19.0.0 */
  623. $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
  624. $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
  625. $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
  626. /** @deprecated 19.0.0 */
  627. $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
  628. /** @deprecated 19.0.0 */
  629. $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
  630. $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
  631. $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
  632. return new \OC\SystemConfig($config);
  633. });
  634. /** @deprecated 19.0.0 */
  635. $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
  636. /** @deprecated 19.0.0 */
  637. $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
  638. $this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
  639. $this->registerService(IFactory::class, function (Server $c) {
  640. return new \OC\L10N\Factory(
  641. $c->get(\OCP\IConfig::class),
  642. $c->getRequest(),
  643. $c->get(IUserSession::class),
  644. \OC::$SERVERROOT
  645. );
  646. });
  647. /** @deprecated 19.0.0 */
  648. $this->registerDeprecatedAlias('L10NFactory', IFactory::class);
  649. $this->registerAlias(IURLGenerator::class, URLGenerator::class);
  650. /** @deprecated 19.0.0 */
  651. $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
  652. /** @deprecated 19.0.0 */
  653. $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
  654. /** @deprecated 19.0.0 */
  655. $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
  656. $this->registerService(ICache::class, function ($c) {
  657. return new Cache\File();
  658. });
  659. /** @deprecated 19.0.0 */
  660. $this->registerDeprecatedAlias('UserCache', ICache::class);
  661. $this->registerService(Factory::class, function (Server $c) {
  662. $profiler = $c->get(IProfiler::class);
  663. $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(LoggerInterface::class),
  664. $profiler,
  665. ArrayCache::class,
  666. ArrayCache::class,
  667. ArrayCache::class
  668. );
  669. /** @var \OCP\IConfig $config */
  670. $config = $c->get(\OCP\IConfig::class);
  671. if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  672. if (!$config->getSystemValueBool('log_query')) {
  673. $v = \OC_App::getAppVersions();
  674. } else {
  675. // If the log_query is enabled, we can not get the app versions
  676. // as that does a query, which will be logged and the logging
  677. // depends on redis and here we are back again in the same function.
  678. $v = [
  679. 'log_query' => 'enabled',
  680. ];
  681. }
  682. $v['core'] = implode(',', \OC_Util::getVersion());
  683. $version = implode(',', $v);
  684. $instanceId = \OC_Util::getInstanceId();
  685. $path = \OC::$SERVERROOT;
  686. $prefix = md5($instanceId . '-' . $version . '-' . $path);
  687. return new \OC\Memcache\Factory($prefix,
  688. $c->get(LoggerInterface::class),
  689. $profiler,
  690. $config->getSystemValue('memcache.local', null),
  691. $config->getSystemValue('memcache.distributed', null),
  692. $config->getSystemValue('memcache.locking', null),
  693. $config->getSystemValueString('redis_log_file')
  694. );
  695. }
  696. return $arrayCacheFactory;
  697. });
  698. /** @deprecated 19.0.0 */
  699. $this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
  700. $this->registerAlias(ICacheFactory::class, Factory::class);
  701. $this->registerService('RedisFactory', function (Server $c) {
  702. $systemConfig = $c->get(SystemConfig::class);
  703. return new RedisFactory($systemConfig, $c->getEventLogger());
  704. });
  705. $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
  706. $l10n = $this->get(IFactory::class)->get('lib');
  707. return new \OC\Activity\Manager(
  708. $c->getRequest(),
  709. $c->get(IUserSession::class),
  710. $c->get(\OCP\IConfig::class),
  711. $c->get(IValidator::class),
  712. $l10n
  713. );
  714. });
  715. /** @deprecated 19.0.0 */
  716. $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
  717. $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
  718. return new \OC\Activity\EventMerger(
  719. $c->getL10N('lib')
  720. );
  721. });
  722. $this->registerAlias(IValidator::class, Validator::class);
  723. $this->registerService(AvatarManager::class, function (Server $c) {
  724. return new AvatarManager(
  725. $c->get(IUserSession::class),
  726. $c->get(\OC\User\Manager::class),
  727. $c->getAppDataDir('avatar'),
  728. $c->getL10N('lib'),
  729. $c->get(LoggerInterface::class),
  730. $c->get(\OCP\IConfig::class),
  731. $c->get(IAccountManager::class),
  732. $c->get(KnownUserService::class)
  733. );
  734. });
  735. $this->registerAlias(IAvatarManager::class, AvatarManager::class);
  736. /** @deprecated 19.0.0 */
  737. $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
  738. $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
  739. $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
  740. $this->registerService(\OC\Log::class, function (Server $c) {
  741. $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
  742. $factory = new LogFactory($c, $this->get(SystemConfig::class));
  743. $logger = $factory->get($logType);
  744. $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
  745. return new Log($logger, $this->get(SystemConfig::class), null, $registry);
  746. });
  747. $this->registerAlias(ILogger::class, \OC\Log::class);
  748. /** @deprecated 19.0.0 */
  749. $this->registerDeprecatedAlias('Logger', \OC\Log::class);
  750. // PSR-3 logger
  751. $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
  752. $this->registerService(ILogFactory::class, function (Server $c) {
  753. return new LogFactory($c, $this->get(SystemConfig::class));
  754. });
  755. $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
  756. /** @deprecated 19.0.0 */
  757. $this->registerDeprecatedAlias('JobList', IJobList::class);
  758. $this->registerService(Router::class, function (Server $c) {
  759. $cacheFactory = $c->get(ICacheFactory::class);
  760. $logger = $c->get(LoggerInterface::class);
  761. if ($cacheFactory->isLocalCacheAvailable()) {
  762. $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
  763. } else {
  764. $router = new \OC\Route\Router($logger);
  765. }
  766. return $router;
  767. });
  768. $this->registerAlias(IRouter::class, Router::class);
  769. /** @deprecated 19.0.0 */
  770. $this->registerDeprecatedAlias('Router', IRouter::class);
  771. $this->registerAlias(ISearch::class, Search::class);
  772. /** @deprecated 19.0.0 */
  773. $this->registerDeprecatedAlias('Search', ISearch::class);
  774. $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
  775. $cacheFactory = $c->get(ICacheFactory::class);
  776. if ($cacheFactory->isAvailable()) {
  777. $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend(
  778. $this->get(ICacheFactory::class),
  779. new \OC\AppFramework\Utility\TimeFactory()
  780. );
  781. } else {
  782. $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend(
  783. $c->get(IDBConnection::class),
  784. new \OC\AppFramework\Utility\TimeFactory()
  785. );
  786. }
  787. return $backend;
  788. });
  789. $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
  790. /** @deprecated 19.0.0 */
  791. $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
  792. $this->registerAlias(IVerificationToken::class, VerificationToken::class);
  793. $this->registerAlias(ICrypto::class, Crypto::class);
  794. /** @deprecated 19.0.0 */
  795. $this->registerDeprecatedAlias('Crypto', ICrypto::class);
  796. $this->registerAlias(IHasher::class, Hasher::class);
  797. /** @deprecated 19.0.0 */
  798. $this->registerDeprecatedAlias('Hasher', IHasher::class);
  799. $this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
  800. /** @deprecated 19.0.0 */
  801. $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
  802. $this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
  803. $this->registerService(Connection::class, function (Server $c) {
  804. $systemConfig = $c->get(SystemConfig::class);
  805. $factory = new \OC\DB\ConnectionFactory($systemConfig);
  806. $type = $systemConfig->getValue('dbtype', 'sqlite');
  807. if (!$factory->isValidType($type)) {
  808. throw new \OC\DatabaseException('Invalid database type');
  809. }
  810. $connectionParams = $factory->createConnectionParams();
  811. $connection = $factory->getConnection($type, $connectionParams);
  812. return $connection;
  813. });
  814. /** @deprecated 19.0.0 */
  815. $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
  816. $this->registerAlias(ICertificateManager::class, CertificateManager::class);
  817. $this->registerAlias(IClientService::class, ClientService::class);
  818. $this->registerService(LocalAddressChecker::class, function (ContainerInterface $c) {
  819. return new LocalAddressChecker(
  820. $c->get(LoggerInterface::class),
  821. );
  822. });
  823. $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) {
  824. return new NegativeDnsCache(
  825. $c->get(ICacheFactory::class),
  826. );
  827. });
  828. $this->registerService(DnsPinMiddleware::class, function (ContainerInterface $c) {
  829. return new DnsPinMiddleware(
  830. $c->get(NegativeDnsCache::class),
  831. $c->get(LocalAddressChecker::class)
  832. );
  833. });
  834. $this->registerDeprecatedAlias('HttpClientService', IClientService::class);
  835. $this->registerService(IEventLogger::class, function (ContainerInterface $c) {
  836. return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class));
  837. });
  838. /** @deprecated 19.0.0 */
  839. $this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
  840. $this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
  841. $queryLogger = new QueryLogger();
  842. if ($c->get(SystemConfig::class)->getValue('debug', false)) {
  843. // In debug mode, module is being activated by default
  844. $queryLogger->activate();
  845. }
  846. return $queryLogger;
  847. });
  848. /** @deprecated 19.0.0 */
  849. $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
  850. /** @deprecated 19.0.0 */
  851. $this->registerDeprecatedAlias('TempManager', TempManager::class);
  852. $this->registerAlias(ITempManager::class, TempManager::class);
  853. $this->registerService(AppManager::class, function (ContainerInterface $c) {
  854. // TODO: use auto-wiring
  855. return new \OC\App\AppManager(
  856. $c->get(IUserSession::class),
  857. $c->get(\OCP\IConfig::class),
  858. $c->get(\OC\AppConfig::class),
  859. $c->get(IGroupManager::class),
  860. $c->get(ICacheFactory::class),
  861. $c->get(SymfonyAdapter::class),
  862. $c->get(LoggerInterface::class)
  863. );
  864. });
  865. /** @deprecated 19.0.0 */
  866. $this->registerDeprecatedAlias('AppManager', AppManager::class);
  867. $this->registerAlias(IAppManager::class, AppManager::class);
  868. $this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
  869. /** @deprecated 19.0.0 */
  870. $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
  871. $this->registerService(IDateTimeFormatter::class, function (Server $c) {
  872. $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
  873. return new DateTimeFormatter(
  874. $c->get(IDateTimeZone::class)->getTimeZone(),
  875. $c->getL10N('lib', $language)
  876. );
  877. });
  878. /** @deprecated 19.0.0 */
  879. $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
  880. $this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
  881. $mountCache = new UserMountCache(
  882. $c->get(IDBConnection::class),
  883. $c->get(IUserManager::class),
  884. $c->get(LoggerInterface::class)
  885. );
  886. $listener = new UserMountCacheListener($mountCache);
  887. $listener->listen($c->get(IUserManager::class));
  888. return $mountCache;
  889. });
  890. /** @deprecated 19.0.0 */
  891. $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
  892. $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
  893. $loader = \OC\Files\Filesystem::getLoader();
  894. $mountCache = $c->get(IUserMountCache::class);
  895. $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
  896. // builtin providers
  897. $config = $c->get(\OCP\IConfig::class);
  898. $logger = $c->get(LoggerInterface::class);
  899. $manager->registerProvider(new CacheMountProvider($config));
  900. $manager->registerHomeProvider(new LocalHomeMountProvider());
  901. $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
  902. $manager->registerRootProvider(new RootMountProvider($config, $c->get(LoggerInterface::class)));
  903. $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
  904. return $manager;
  905. });
  906. /** @deprecated 19.0.0 */
  907. $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
  908. /** @deprecated 20.0.0 */
  909. $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
  910. $this->registerService(IBus::class, function (ContainerInterface $c) {
  911. $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus');
  912. if ($busClass) {
  913. [$app, $class] = explode('::', $busClass, 2);
  914. if ($c->get(IAppManager::class)->isInstalled($app)) {
  915. \OC_App::loadApp($app);
  916. return $c->get($class);
  917. } else {
  918. throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
  919. }
  920. } else {
  921. $jobList = $c->get(IJobList::class);
  922. return new CronBus($jobList);
  923. }
  924. });
  925. $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
  926. /** @deprecated 20.0.0 */
  927. $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class);
  928. $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class);
  929. /** @deprecated 19.0.0 */
  930. $this->registerDeprecatedAlias('Throttler', Throttler::class);
  931. $this->registerAlias(IThrottler::class, Throttler::class);
  932. $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {
  933. // IConfig and IAppManager requires a working database. This code
  934. // might however be called when ownCloud is not yet setup.
  935. if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
  936. $config = $c->get(\OCP\IConfig::class);
  937. $appManager = $c->get(IAppManager::class);
  938. } else {
  939. $config = null;
  940. $appManager = null;
  941. }
  942. return new Checker(
  943. new EnvironmentHelper(),
  944. new FileAccessHelper(),
  945. new AppLocator(),
  946. $config,
  947. $c->get(ICacheFactory::class),
  948. $appManager,
  949. $c->get(IMimeTypeDetector::class)
  950. );
  951. });
  952. $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
  953. if (isset($this['urlParams'])) {
  954. $urlParams = $this['urlParams'];
  955. } else {
  956. $urlParams = [];
  957. }
  958. if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
  959. && in_array('fakeinput', stream_get_wrappers())
  960. ) {
  961. $stream = 'fakeinput://data';
  962. } else {
  963. $stream = 'php://input';
  964. }
  965. return new Request(
  966. [
  967. 'get' => $_GET,
  968. 'post' => $_POST,
  969. 'files' => $_FILES,
  970. 'server' => $_SERVER,
  971. 'env' => $_ENV,
  972. 'cookies' => $_COOKIE,
  973. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  974. ? $_SERVER['REQUEST_METHOD']
  975. : '',
  976. 'urlParams' => $urlParams,
  977. ],
  978. $this->get(IRequestId::class),
  979. $this->get(\OCP\IConfig::class),
  980. $this->get(CsrfTokenManager::class),
  981. $stream
  982. );
  983. });
  984. /** @deprecated 19.0.0 */
  985. $this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
  986. $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId {
  987. return new RequestId(
  988. $_SERVER['UNIQUE_ID'] ?? '',
  989. $this->get(ISecureRandom::class)
  990. );
  991. });
  992. $this->registerService(IMailer::class, function (Server $c) {
  993. return new Mailer(
  994. $c->get(\OCP\IConfig::class),
  995. $c->get(LoggerInterface::class),
  996. $c->get(Defaults::class),
  997. $c->get(IURLGenerator::class),
  998. $c->getL10N('lib'),
  999. $c->get(IEventDispatcher::class),
  1000. $c->get(IFactory::class)
  1001. );
  1002. });
  1003. /** @deprecated 19.0.0 */
  1004. $this->registerDeprecatedAlias('Mailer', IMailer::class);
  1005. /** @deprecated 21.0.0 */
  1006. $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class);
  1007. $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
  1008. $config = $c->get(\OCP\IConfig::class);
  1009. $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
  1010. if (is_null($factoryClass) || !class_exists($factoryClass)) {
  1011. return new NullLDAPProviderFactory($this);
  1012. }
  1013. /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
  1014. return new $factoryClass($this);
  1015. });
  1016. $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
  1017. $factory = $c->get(ILDAPProviderFactory::class);
  1018. return $factory->getLDAPProvider();
  1019. });
  1020. $this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
  1021. $ini = $c->get(IniGetWrapper::class);
  1022. $config = $c->get(\OCP\IConfig::class);
  1023. $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
  1024. if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
  1025. /** @var \OC\Memcache\Factory $memcacheFactory */
  1026. $memcacheFactory = $c->get(ICacheFactory::class);
  1027. $memcache = $memcacheFactory->createLocking('lock');
  1028. if (!($memcache instanceof \OC\Memcache\NullCache)) {
  1029. return new MemcacheLockingProvider($memcache, $ttl);
  1030. }
  1031. return new DBLockingProvider(
  1032. $c->get(IDBConnection::class),
  1033. new TimeFactory(),
  1034. $ttl,
  1035. !\OC::$CLI
  1036. );
  1037. }
  1038. return new NoopLockingProvider();
  1039. });
  1040. /** @deprecated 19.0.0 */
  1041. $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
  1042. $this->registerService(ILockManager::class, function (Server $c): LockManager {
  1043. return new LockManager();
  1044. });
  1045. $this->registerAlias(ILockdownManager::class, 'LockdownManager');
  1046. $this->registerService(SetupManager::class, function ($c) {
  1047. // create the setupmanager through the mount manager to resolve the cyclic dependency
  1048. return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager();
  1049. });
  1050. $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
  1051. /** @deprecated 19.0.0 */
  1052. $this->registerDeprecatedAlias('MountManager', IMountManager::class);
  1053. $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
  1054. return new \OC\Files\Type\Detection(
  1055. $c->get(IURLGenerator::class),
  1056. $c->get(LoggerInterface::class),
  1057. \OC::$configDir,
  1058. \OC::$SERVERROOT . '/resources/config/'
  1059. );
  1060. });
  1061. /** @deprecated 19.0.0 */
  1062. $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
  1063. $this->registerAlias(IMimeTypeLoader::class, Loader::class);
  1064. /** @deprecated 19.0.0 */
  1065. $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
  1066. $this->registerService(BundleFetcher::class, function () {
  1067. return new BundleFetcher($this->getL10N('lib'));
  1068. });
  1069. $this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
  1070. /** @deprecated 19.0.0 */
  1071. $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
  1072. $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
  1073. $manager = new CapabilitiesManager($c->get(LoggerInterface::class));
  1074. $manager->registerCapability(function () use ($c) {
  1075. return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
  1076. });
  1077. $manager->registerCapability(function () use ($c) {
  1078. return $c->get(\OC\Security\Bruteforce\Capabilities::class);
  1079. });
  1080. $manager->registerCapability(function () use ($c) {
  1081. return $c->get(MetadataCapabilities::class);
  1082. });
  1083. return $manager;
  1084. });
  1085. /** @deprecated 19.0.0 */
  1086. $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
  1087. $this->registerService(ICommentsManager::class, function (Server $c) {
  1088. $config = $c->get(\OCP\IConfig::class);
  1089. $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
  1090. /** @var \OCP\Comments\ICommentsManagerFactory $factory */
  1091. $factory = new $factoryClass($this);
  1092. $manager = $factory->getManager();
  1093. $manager->registerDisplayNameResolver('user', function ($id) use ($c) {
  1094. $manager = $c->get(IUserManager::class);
  1095. $userDisplayName = $manager->getDisplayName($id);
  1096. if ($userDisplayName === null) {
  1097. $l = $c->get(IFactory::class)->get('core');
  1098. return $l->t('Unknown user');
  1099. }
  1100. return $userDisplayName;
  1101. });
  1102. return $manager;
  1103. });
  1104. /** @deprecated 19.0.0 */
  1105. $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
  1106. $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
  1107. $this->registerService('ThemingDefaults', function (Server $c) {
  1108. /*
  1109. * Dark magic for autoloader.
  1110. * If we do a class_exists it will try to load the class which will
  1111. * make composer cache the result. Resulting in errors when enabling
  1112. * the theming app.
  1113. */
  1114. $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
  1115. if (isset($prefixes['OCA\\Theming\\'])) {
  1116. $classExists = true;
  1117. } else {
  1118. $classExists = false;
  1119. }
  1120. if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
  1121. return new ThemingDefaults(
  1122. $c->get(\OCP\IConfig::class),
  1123. $c->getL10N('theming'),
  1124. $c->get(IUserSession::class),
  1125. $c->get(IURLGenerator::class),
  1126. $c->get(ICacheFactory::class),
  1127. new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')),
  1128. new ImageManager(
  1129. $c->get(\OCP\IConfig::class),
  1130. $c->getAppDataDir('theming'),
  1131. $c->get(IURLGenerator::class),
  1132. $this->get(ICacheFactory::class),
  1133. $this->get(ILogger::class),
  1134. $this->get(ITempManager::class)
  1135. ),
  1136. $c->get(IAppManager::class),
  1137. $c->get(INavigationManager::class)
  1138. );
  1139. }
  1140. return new \OC_Defaults();
  1141. });
  1142. $this->registerService(JSCombiner::class, function (Server $c) {
  1143. return new JSCombiner(
  1144. $c->getAppDataDir('js'),
  1145. $c->get(IURLGenerator::class),
  1146. $this->get(ICacheFactory::class),
  1147. $c->get(SystemConfig::class),
  1148. $c->get(LoggerInterface::class)
  1149. );
  1150. });
  1151. $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
  1152. /** @deprecated 19.0.0 */
  1153. $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
  1154. $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
  1155. $this->registerService('CryptoWrapper', function (ContainerInterface $c) {
  1156. // FIXME: Instantiated here due to cyclic dependency
  1157. $request = new Request(
  1158. [
  1159. 'get' => $_GET,
  1160. 'post' => $_POST,
  1161. 'files' => $_FILES,
  1162. 'server' => $_SERVER,
  1163. 'env' => $_ENV,
  1164. 'cookies' => $_COOKIE,
  1165. 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
  1166. ? $_SERVER['REQUEST_METHOD']
  1167. : null,
  1168. ],
  1169. $c->get(IRequestId::class),
  1170. $c->get(\OCP\IConfig::class)
  1171. );
  1172. return new CryptoWrapper(
  1173. $c->get(\OCP\IConfig::class),
  1174. $c->get(ICrypto::class),
  1175. $c->get(ISecureRandom::class),
  1176. $request
  1177. );
  1178. });
  1179. /** @deprecated 19.0.0 */
  1180. $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
  1181. $this->registerService(SessionStorage::class, function (ContainerInterface $c) {
  1182. return new SessionStorage($c->get(ISession::class));
  1183. });
  1184. $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
  1185. /** @deprecated 19.0.0 */
  1186. $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
  1187. $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
  1188. $config = $c->get(\OCP\IConfig::class);
  1189. $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
  1190. /** @var \OCP\Share\IProviderFactory $factory */
  1191. $factory = new $factoryClass($this);
  1192. $manager = new \OC\Share20\Manager(
  1193. $c->get(LoggerInterface::class),
  1194. $c->get(\OCP\IConfig::class),
  1195. $c->get(ISecureRandom::class),
  1196. $c->get(IHasher::class),
  1197. $c->get(IMountManager::class),
  1198. $c->get(IGroupManager::class),
  1199. $c->getL10N('lib'),
  1200. $c->get(IFactory::class),
  1201. $factory,
  1202. $c->get(IUserManager::class),
  1203. $c->get(IRootFolder::class),
  1204. $c->get(SymfonyAdapter::class),
  1205. $c->get(IMailer::class),
  1206. $c->get(IURLGenerator::class),
  1207. $c->get('ThemingDefaults'),
  1208. $c->get(IEventDispatcher::class),
  1209. $c->get(IUserSession::class),
  1210. $c->get(KnownUserService::class)
  1211. );
  1212. return $manager;
  1213. });
  1214. /** @deprecated 19.0.0 */
  1215. $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
  1216. $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
  1217. $instance = new Collaboration\Collaborators\Search($c);
  1218. // register default plugins
  1219. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
  1220. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
  1221. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
  1222. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
  1223. $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
  1224. return $instance;
  1225. });
  1226. /** @deprecated 19.0.0 */
  1227. $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
  1228. $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
  1229. $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
  1230. $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
  1231. $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
  1232. $this->registerAlias(IReferenceManager::class, ReferenceManager::class);
  1233. $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
  1234. $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
  1235. $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
  1236. return new \OC\Files\AppData\Factory(
  1237. $c->get(IRootFolder::class),
  1238. $c->get(SystemConfig::class)
  1239. );
  1240. });
  1241. $this->registerService('LockdownManager', function (ContainerInterface $c) {
  1242. return new LockdownManager(function () use ($c) {
  1243. return $c->get(ISession::class);
  1244. });
  1245. });
  1246. $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
  1247. return new DiscoveryService(
  1248. $c->get(ICacheFactory::class),
  1249. $c->get(IClientService::class)
  1250. );
  1251. });
  1252. $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
  1253. return new CloudIdManager(
  1254. $c->get(\OCP\Contacts\IManager::class),
  1255. $c->get(IURLGenerator::class),
  1256. $c->get(IUserManager::class),
  1257. $c->get(ICacheFactory::class),
  1258. $c->get(IEventDispatcher::class),
  1259. );
  1260. });
  1261. $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
  1262. $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
  1263. return new CloudFederationProviderManager(
  1264. $c->get(IAppManager::class),
  1265. $c->get(IClientService::class),
  1266. $c->get(ICloudIdManager::class),
  1267. $c->get(LoggerInterface::class)
  1268. );
  1269. });
  1270. $this->registerService(ICloudFederationFactory::class, function (Server $c) {
  1271. return new CloudFederationFactory();
  1272. });
  1273. $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
  1274. /** @deprecated 19.0.0 */
  1275. $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
  1276. $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
  1277. /** @deprecated 19.0.0 */
  1278. $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
  1279. $this->registerService(Defaults::class, function (Server $c) {
  1280. return new Defaults(
  1281. $c->getThemingDefaults()
  1282. );
  1283. });
  1284. /** @deprecated 19.0.0 */
  1285. $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
  1286. $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
  1287. return $c->get(\OCP\IUserSession::class)->getSession();
  1288. }, false);
  1289. $this->registerService(IShareHelper::class, function (ContainerInterface $c) {
  1290. return new ShareHelper(
  1291. $c->get(\OCP\Share\IManager::class)
  1292. );
  1293. });
  1294. $this->registerService(Installer::class, function (ContainerInterface $c) {
  1295. return new Installer(
  1296. $c->get(AppFetcher::class),
  1297. $c->get(IClientService::class),
  1298. $c->get(ITempManager::class),
  1299. $c->get(LoggerInterface::class),
  1300. $c->get(\OCP\IConfig::class),
  1301. \OC::$CLI
  1302. );
  1303. });
  1304. $this->registerService(IApiFactory::class, function (ContainerInterface $c) {
  1305. return new ApiFactory($c->get(IClientService::class));
  1306. });
  1307. $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
  1308. $memcacheFactory = $c->get(ICacheFactory::class);
  1309. return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
  1310. });
  1311. $this->registerAlias(IContactsStore::class, ContactsStore::class);
  1312. $this->registerAlias(IAccountManager::class, AccountManager::class);
  1313. $this->registerAlias(IStorageFactory::class, StorageFactory::class);
  1314. $this->registerAlias(IDashboardManager::class, DashboardManager::class);
  1315. $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
  1316. $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
  1317. $this->registerAlias(ISubAdmin::class, SubAdmin::class);
  1318. $this->registerAlias(IInitialStateService::class, InitialStateService::class);
  1319. $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class);
  1320. $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
  1321. $this->registerAlias(IBroker::class, Broker::class);
  1322. $this->registerAlias(IMetadataManager::class, MetadataManager::class);
  1323. $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class);
  1324. $this->registerAlias(IBinaryFinder::class, BinaryFinder::class);
  1325. $this->connectDispatcher();
  1326. }
  1327. public function boot() {
  1328. /** @var HookConnector $hookConnector */
  1329. $hookConnector = $this->get(HookConnector::class);
  1330. $hookConnector->viewToNode();
  1331. }
  1332. /**
  1333. * @return \OCP\Calendar\IManager
  1334. * @deprecated 20.0.0
  1335. */
  1336. public function getCalendarManager() {
  1337. return $this->get(\OC\Calendar\Manager::class);
  1338. }
  1339. /**
  1340. * @return \OCP\Calendar\Resource\IManager
  1341. * @deprecated 20.0.0
  1342. */
  1343. public function getCalendarResourceBackendManager() {
  1344. return $this->get(\OC\Calendar\Resource\Manager::class);
  1345. }
  1346. /**
  1347. * @return \OCP\Calendar\Room\IManager
  1348. * @deprecated 20.0.0
  1349. */
  1350. public function getCalendarRoomBackendManager() {
  1351. return $this->get(\OC\Calendar\Room\Manager::class);
  1352. }
  1353. private function connectDispatcher(): void {
  1354. /** @var IEventDispatcher $eventDispatcher */
  1355. $eventDispatcher = $this->get(IEventDispatcher::class);
  1356. $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class);
  1357. $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
  1358. $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class);
  1359. $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class);
  1360. }
  1361. /**
  1362. * @return \OCP\Contacts\IManager
  1363. * @deprecated 20.0.0
  1364. */
  1365. public function getContactsManager() {
  1366. return $this->get(\OCP\Contacts\IManager::class);
  1367. }
  1368. /**
  1369. * @return \OC\Encryption\Manager
  1370. * @deprecated 20.0.0
  1371. */
  1372. public function getEncryptionManager() {
  1373. return $this->get(\OCP\Encryption\IManager::class);
  1374. }
  1375. /**
  1376. * @return \OC\Encryption\File
  1377. * @deprecated 20.0.0
  1378. */
  1379. public function getEncryptionFilesHelper() {
  1380. return $this->get(IFile::class);
  1381. }
  1382. /**
  1383. * @return \OCP\Encryption\Keys\IStorage
  1384. * @deprecated 20.0.0
  1385. */
  1386. public function getEncryptionKeyStorage() {
  1387. return $this->get(IStorage::class);
  1388. }
  1389. /**
  1390. * The current request object holding all information about the request
  1391. * currently being processed is returned from this method.
  1392. * In case the current execution was not initiated by a web request null is returned
  1393. *
  1394. * @return \OCP\IRequest
  1395. * @deprecated 20.0.0
  1396. */
  1397. public function getRequest() {
  1398. return $this->get(IRequest::class);
  1399. }
  1400. /**
  1401. * Returns the preview manager which can create preview images for a given file
  1402. *
  1403. * @return IPreview
  1404. * @deprecated 20.0.0
  1405. */
  1406. public function getPreviewManager() {
  1407. return $this->get(IPreview::class);
  1408. }
  1409. /**
  1410. * Returns the tag manager which can get and set tags for different object types
  1411. *
  1412. * @see \OCP\ITagManager::load()
  1413. * @return ITagManager
  1414. * @deprecated 20.0.0
  1415. */
  1416. public function getTagManager() {
  1417. return $this->get(ITagManager::class);
  1418. }
  1419. /**
  1420. * Returns the system-tag manager
  1421. *
  1422. * @return ISystemTagManager
  1423. *
  1424. * @since 9.0.0
  1425. * @deprecated 20.0.0
  1426. */
  1427. public function getSystemTagManager() {
  1428. return $this->get(ISystemTagManager::class);
  1429. }
  1430. /**
  1431. * Returns the system-tag object mapper
  1432. *
  1433. * @return ISystemTagObjectMapper
  1434. *
  1435. * @since 9.0.0
  1436. * @deprecated 20.0.0
  1437. */
  1438. public function getSystemTagObjectMapper() {
  1439. return $this->get(ISystemTagObjectMapper::class);
  1440. }
  1441. /**
  1442. * Returns the avatar manager, used for avatar functionality
  1443. *
  1444. * @return IAvatarManager
  1445. * @deprecated 20.0.0
  1446. */
  1447. public function getAvatarManager() {
  1448. return $this->get(IAvatarManager::class);
  1449. }
  1450. /**
  1451. * Returns the root folder of ownCloud's data directory
  1452. *
  1453. * @return IRootFolder
  1454. * @deprecated 20.0.0
  1455. */
  1456. public function getRootFolder() {
  1457. return $this->get(IRootFolder::class);
  1458. }
  1459. /**
  1460. * Returns the root folder of ownCloud's data directory
  1461. * This is the lazy variant so this gets only initialized once it
  1462. * is actually used.
  1463. *
  1464. * @return IRootFolder
  1465. * @deprecated 20.0.0
  1466. */
  1467. public function getLazyRootFolder() {
  1468. return $this->get(IRootFolder::class);
  1469. }
  1470. /**
  1471. * Returns a view to ownCloud's files folder
  1472. *
  1473. * @param string $userId user ID
  1474. * @return \OCP\Files\Folder|null
  1475. * @deprecated 20.0.0
  1476. */
  1477. public function getUserFolder($userId = null) {
  1478. if ($userId === null) {
  1479. $user = $this->get(IUserSession::class)->getUser();
  1480. if (!$user) {
  1481. return null;
  1482. }
  1483. $userId = $user->getUID();
  1484. }
  1485. $root = $this->get(IRootFolder::class);
  1486. return $root->getUserFolder($userId);
  1487. }
  1488. /**
  1489. * @return \OC\User\Manager
  1490. * @deprecated 20.0.0
  1491. */
  1492. public function getUserManager() {
  1493. return $this->get(IUserManager::class);
  1494. }
  1495. /**
  1496. * @return \OC\Group\Manager
  1497. * @deprecated 20.0.0
  1498. */
  1499. public function getGroupManager() {
  1500. return $this->get(IGroupManager::class);
  1501. }
  1502. /**
  1503. * @return \OC\User\Session
  1504. * @deprecated 20.0.0
  1505. */
  1506. public function getUserSession() {
  1507. return $this->get(IUserSession::class);
  1508. }
  1509. /**
  1510. * @return \OCP\ISession
  1511. * @deprecated 20.0.0
  1512. */
  1513. public function getSession() {
  1514. return $this->get(Session::class)->getSession();
  1515. }
  1516. /**
  1517. * @param \OCP\ISession $session
  1518. */
  1519. public function setSession(\OCP\ISession $session) {
  1520. $this->get(SessionStorage::class)->setSession($session);
  1521. $this->get(Session::class)->setSession($session);
  1522. $this->get(Store::class)->setSession($session);
  1523. }
  1524. /**
  1525. * @return \OC\Authentication\TwoFactorAuth\Manager
  1526. * @deprecated 20.0.0
  1527. */
  1528. public function getTwoFactorAuthManager() {
  1529. return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class);
  1530. }
  1531. /**
  1532. * @return \OC\NavigationManager
  1533. * @deprecated 20.0.0
  1534. */
  1535. public function getNavigationManager() {
  1536. return $this->get(INavigationManager::class);
  1537. }
  1538. /**
  1539. * @return \OCP\IConfig
  1540. * @deprecated 20.0.0
  1541. */
  1542. public function getConfig() {
  1543. return $this->get(AllConfig::class);
  1544. }
  1545. /**
  1546. * @return \OC\SystemConfig
  1547. * @deprecated 20.0.0
  1548. */
  1549. public function getSystemConfig() {
  1550. return $this->get(SystemConfig::class);
  1551. }
  1552. /**
  1553. * Returns the app config manager
  1554. *
  1555. * @return IAppConfig
  1556. * @deprecated 20.0.0
  1557. */
  1558. public function getAppConfig() {
  1559. return $this->get(IAppConfig::class);
  1560. }
  1561. /**
  1562. * @return IFactory
  1563. * @deprecated 20.0.0
  1564. */
  1565. public function getL10NFactory() {
  1566. return $this->get(IFactory::class);
  1567. }
  1568. /**
  1569. * get an L10N instance
  1570. *
  1571. * @param string $app appid
  1572. * @param string $lang
  1573. * @return IL10N
  1574. * @deprecated 20.0.0
  1575. */
  1576. public function getL10N($app, $lang = null) {
  1577. return $this->get(IFactory::class)->get($app, $lang);
  1578. }
  1579. /**
  1580. * @return IURLGenerator
  1581. * @deprecated 20.0.0
  1582. */
  1583. public function getURLGenerator() {
  1584. return $this->get(IURLGenerator::class);
  1585. }
  1586. /**
  1587. * @return AppFetcher
  1588. * @deprecated 20.0.0
  1589. */
  1590. public function getAppFetcher() {
  1591. return $this->get(AppFetcher::class);
  1592. }
  1593. /**
  1594. * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
  1595. * getMemCacheFactory() instead.
  1596. *
  1597. * @return ICache
  1598. * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
  1599. */
  1600. public function getCache() {
  1601. return $this->get(ICache::class);
  1602. }
  1603. /**
  1604. * Returns an \OCP\CacheFactory instance
  1605. *
  1606. * @return \OCP\ICacheFactory
  1607. * @deprecated 20.0.0
  1608. */
  1609. public function getMemCacheFactory() {
  1610. return $this->get(ICacheFactory::class);
  1611. }
  1612. /**
  1613. * Returns an \OC\RedisFactory instance
  1614. *
  1615. * @return \OC\RedisFactory
  1616. * @deprecated 20.0.0
  1617. */
  1618. public function getGetRedisFactory() {
  1619. return $this->get('RedisFactory');
  1620. }
  1621. /**
  1622. * Returns the current session
  1623. *
  1624. * @return \OCP\IDBConnection
  1625. * @deprecated 20.0.0
  1626. */
  1627. public function getDatabaseConnection() {
  1628. return $this->get(IDBConnection::class);
  1629. }
  1630. /**
  1631. * Returns the activity manager
  1632. *
  1633. * @return \OCP\Activity\IManager
  1634. * @deprecated 20.0.0
  1635. */
  1636. public function getActivityManager() {
  1637. return $this->get(\OCP\Activity\IManager::class);
  1638. }
  1639. /**
  1640. * Returns an job list for controlling background jobs
  1641. *
  1642. * @return IJobList
  1643. * @deprecated 20.0.0
  1644. */
  1645. public function getJobList() {
  1646. return $this->get(IJobList::class);
  1647. }
  1648. /**
  1649. * Returns a logger instance
  1650. *
  1651. * @return ILogger
  1652. * @deprecated 20.0.0
  1653. */
  1654. public function getLogger() {
  1655. return $this->get(ILogger::class);
  1656. }
  1657. /**
  1658. * @return ILogFactory
  1659. * @throws \OCP\AppFramework\QueryException
  1660. * @deprecated 20.0.0
  1661. */
  1662. public function getLogFactory() {
  1663. return $this->get(ILogFactory::class);
  1664. }
  1665. /**
  1666. * Returns a router for generating and matching urls
  1667. *
  1668. * @return IRouter
  1669. * @deprecated 20.0.0
  1670. */
  1671. public function getRouter() {
  1672. return $this->get(IRouter::class);
  1673. }
  1674. /**
  1675. * Returns a search instance
  1676. *
  1677. * @return ISearch
  1678. * @deprecated 20.0.0
  1679. */
  1680. public function getSearch() {
  1681. return $this->get(ISearch::class);
  1682. }
  1683. /**
  1684. * Returns a SecureRandom instance
  1685. *
  1686. * @return \OCP\Security\ISecureRandom
  1687. * @deprecated 20.0.0
  1688. */
  1689. public function getSecureRandom() {
  1690. return $this->get(ISecureRandom::class);
  1691. }
  1692. /**
  1693. * Returns a Crypto instance
  1694. *
  1695. * @return ICrypto
  1696. * @deprecated 20.0.0
  1697. */
  1698. public function getCrypto() {
  1699. return $this->get(ICrypto::class);
  1700. }
  1701. /**
  1702. * Returns a Hasher instance
  1703. *
  1704. * @return IHasher
  1705. * @deprecated 20.0.0
  1706. */
  1707. public function getHasher() {
  1708. return $this->get(IHasher::class);
  1709. }
  1710. /**
  1711. * Returns a CredentialsManager instance
  1712. *
  1713. * @return ICredentialsManager
  1714. * @deprecated 20.0.0
  1715. */
  1716. public function getCredentialsManager() {
  1717. return $this->get(ICredentialsManager::class);
  1718. }
  1719. /**
  1720. * Get the certificate manager
  1721. *
  1722. * @return \OCP\ICertificateManager
  1723. */
  1724. public function getCertificateManager() {
  1725. return $this->get(ICertificateManager::class);
  1726. }
  1727. /**
  1728. * Returns an instance of the HTTP client service
  1729. *
  1730. * @return IClientService
  1731. * @deprecated 20.0.0
  1732. */
  1733. public function getHTTPClientService() {
  1734. return $this->get(IClientService::class);
  1735. }
  1736. /**
  1737. * Create a new event source
  1738. *
  1739. * @return \OCP\IEventSource
  1740. * @deprecated 20.0.0
  1741. */
  1742. public function createEventSource() {
  1743. return new \OC_EventSource();
  1744. }
  1745. /**
  1746. * Get the active event logger
  1747. *
  1748. * The returned logger only logs data when debug mode is enabled
  1749. *
  1750. * @return IEventLogger
  1751. * @deprecated 20.0.0
  1752. */
  1753. public function getEventLogger() {
  1754. return $this->get(IEventLogger::class);
  1755. }
  1756. /**
  1757. * Get the active query logger
  1758. *
  1759. * The returned logger only logs data when debug mode is enabled
  1760. *
  1761. * @return IQueryLogger
  1762. * @deprecated 20.0.0
  1763. */
  1764. public function getQueryLogger() {
  1765. return $this->get(IQueryLogger::class);
  1766. }
  1767. /**
  1768. * Get the manager for temporary files and folders
  1769. *
  1770. * @return \OCP\ITempManager
  1771. * @deprecated 20.0.0
  1772. */
  1773. public function getTempManager() {
  1774. return $this->get(ITempManager::class);
  1775. }
  1776. /**
  1777. * Get the app manager
  1778. *
  1779. * @return \OCP\App\IAppManager
  1780. * @deprecated 20.0.0
  1781. */
  1782. public function getAppManager() {
  1783. return $this->get(IAppManager::class);
  1784. }
  1785. /**
  1786. * Creates a new mailer
  1787. *
  1788. * @return IMailer
  1789. * @deprecated 20.0.0
  1790. */
  1791. public function getMailer() {
  1792. return $this->get(IMailer::class);
  1793. }
  1794. /**
  1795. * Get the webroot
  1796. *
  1797. * @return string
  1798. * @deprecated 20.0.0
  1799. */
  1800. public function getWebRoot() {
  1801. return $this->webRoot;
  1802. }
  1803. /**
  1804. * @return \OC\OCSClient
  1805. * @deprecated 20.0.0
  1806. */
  1807. public function getOcsClient() {
  1808. return $this->get('OcsClient');
  1809. }
  1810. /**
  1811. * @return IDateTimeZone
  1812. * @deprecated 20.0.0
  1813. */
  1814. public function getDateTimeZone() {
  1815. return $this->get(IDateTimeZone::class);
  1816. }
  1817. /**
  1818. * @return IDateTimeFormatter
  1819. * @deprecated 20.0.0
  1820. */
  1821. public function getDateTimeFormatter() {
  1822. return $this->get(IDateTimeFormatter::class);
  1823. }
  1824. /**
  1825. * @return IMountProviderCollection
  1826. * @deprecated 20.0.0
  1827. */
  1828. public function getMountProviderCollection() {
  1829. return $this->get(IMountProviderCollection::class);
  1830. }
  1831. /**
  1832. * Get the IniWrapper
  1833. *
  1834. * @return IniGetWrapper
  1835. * @deprecated 20.0.0
  1836. */
  1837. public function getIniWrapper() {
  1838. return $this->get(IniGetWrapper::class);
  1839. }
  1840. /**
  1841. * @return \OCP\Command\IBus
  1842. * @deprecated 20.0.0
  1843. */
  1844. public function getCommandBus() {
  1845. return $this->get(IBus::class);
  1846. }
  1847. /**
  1848. * Get the trusted domain helper
  1849. *
  1850. * @return TrustedDomainHelper
  1851. * @deprecated 20.0.0
  1852. */
  1853. public function getTrustedDomainHelper() {
  1854. return $this->get(TrustedDomainHelper::class);
  1855. }
  1856. /**
  1857. * Get the locking provider
  1858. *
  1859. * @return ILockingProvider
  1860. * @since 8.1.0
  1861. * @deprecated 20.0.0
  1862. */
  1863. public function getLockingProvider() {
  1864. return $this->get(ILockingProvider::class);
  1865. }
  1866. /**
  1867. * @return IMountManager
  1868. * @deprecated 20.0.0
  1869. **/
  1870. public function getMountManager() {
  1871. return $this->get(IMountManager::class);
  1872. }
  1873. /**
  1874. * @return IUserMountCache
  1875. * @deprecated 20.0.0
  1876. */
  1877. public function getUserMountCache() {
  1878. return $this->get(IUserMountCache::class);
  1879. }
  1880. /**
  1881. * Get the MimeTypeDetector
  1882. *
  1883. * @return IMimeTypeDetector
  1884. * @deprecated 20.0.0
  1885. */
  1886. public function getMimeTypeDetector() {
  1887. return $this->get(IMimeTypeDetector::class);
  1888. }
  1889. /**
  1890. * Get the MimeTypeLoader
  1891. *
  1892. * @return IMimeTypeLoader
  1893. * @deprecated 20.0.0
  1894. */
  1895. public function getMimeTypeLoader() {
  1896. return $this->get(IMimeTypeLoader::class);
  1897. }
  1898. /**
  1899. * Get the manager of all the capabilities
  1900. *
  1901. * @return CapabilitiesManager
  1902. * @deprecated 20.0.0
  1903. */
  1904. public function getCapabilitiesManager() {
  1905. return $this->get(CapabilitiesManager::class);
  1906. }
  1907. /**
  1908. * Get the EventDispatcher
  1909. *
  1910. * @return EventDispatcherInterface
  1911. * @since 8.2.0
  1912. * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
  1913. */
  1914. public function getEventDispatcher() {
  1915. return $this->get(\OC\EventDispatcher\SymfonyAdapter::class);
  1916. }
  1917. /**
  1918. * Get the Notification Manager
  1919. *
  1920. * @return \OCP\Notification\IManager
  1921. * @since 8.2.0
  1922. * @deprecated 20.0.0
  1923. */
  1924. public function getNotificationManager() {
  1925. return $this->get(\OCP\Notification\IManager::class);
  1926. }
  1927. /**
  1928. * @return ICommentsManager
  1929. * @deprecated 20.0.0
  1930. */
  1931. public function getCommentsManager() {
  1932. return $this->get(ICommentsManager::class);
  1933. }
  1934. /**
  1935. * @return \OCA\Theming\ThemingDefaults
  1936. * @deprecated 20.0.0
  1937. */
  1938. public function getThemingDefaults() {
  1939. return $this->get('ThemingDefaults');
  1940. }
  1941. /**
  1942. * @return \OC\IntegrityCheck\Checker
  1943. * @deprecated 20.0.0
  1944. */
  1945. public function getIntegrityCodeChecker() {
  1946. return $this->get('IntegrityCodeChecker');
  1947. }
  1948. /**
  1949. * @return \OC\Session\CryptoWrapper
  1950. * @deprecated 20.0.0
  1951. */
  1952. public function getSessionCryptoWrapper() {
  1953. return $this->get('CryptoWrapper');
  1954. }
  1955. /**
  1956. * @return CsrfTokenManager
  1957. * @deprecated 20.0.0
  1958. */
  1959. public function getCsrfTokenManager() {
  1960. return $this->get(CsrfTokenManager::class);
  1961. }
  1962. /**
  1963. * @return Throttler
  1964. * @deprecated 20.0.0
  1965. */
  1966. public function getBruteForceThrottler() {
  1967. return $this->get(Throttler::class);
  1968. }
  1969. /**
  1970. * @return IContentSecurityPolicyManager
  1971. * @deprecated 20.0.0
  1972. */
  1973. public function getContentSecurityPolicyManager() {
  1974. return $this->get(ContentSecurityPolicyManager::class);
  1975. }
  1976. /**
  1977. * @return ContentSecurityPolicyNonceManager
  1978. * @deprecated 20.0.0
  1979. */
  1980. public function getContentSecurityPolicyNonceManager() {
  1981. return $this->get(ContentSecurityPolicyNonceManager::class);
  1982. }
  1983. /**
  1984. * Not a public API as of 8.2, wait for 9.0
  1985. *
  1986. * @return \OCA\Files_External\Service\BackendService
  1987. * @deprecated 20.0.0
  1988. */
  1989. public function getStoragesBackendService() {
  1990. return $this->get(BackendService::class);
  1991. }
  1992. /**
  1993. * Not a public API as of 8.2, wait for 9.0
  1994. *
  1995. * @return \OCA\Files_External\Service\GlobalStoragesService
  1996. * @deprecated 20.0.0
  1997. */
  1998. public function getGlobalStoragesService() {
  1999. return $this->get(GlobalStoragesService::class);
  2000. }
  2001. /**
  2002. * Not a public API as of 8.2, wait for 9.0
  2003. *
  2004. * @return \OCA\Files_External\Service\UserGlobalStoragesService
  2005. * @deprecated 20.0.0
  2006. */
  2007. public function getUserGlobalStoragesService() {
  2008. return $this->get(UserGlobalStoragesService::class);
  2009. }
  2010. /**
  2011. * Not a public API as of 8.2, wait for 9.0
  2012. *
  2013. * @return \OCA\Files_External\Service\UserStoragesService
  2014. * @deprecated 20.0.0
  2015. */
  2016. public function getUserStoragesService() {
  2017. return $this->get(UserStoragesService::class);
  2018. }
  2019. /**
  2020. * @return \OCP\Share\IManager
  2021. * @deprecated 20.0.0
  2022. */
  2023. public function getShareManager() {
  2024. return $this->get(\OCP\Share\IManager::class);
  2025. }
  2026. /**
  2027. * @return \OCP\Collaboration\Collaborators\ISearch
  2028. * @deprecated 20.0.0
  2029. */
  2030. public function getCollaboratorSearch() {
  2031. return $this->get(\OCP\Collaboration\Collaborators\ISearch::class);
  2032. }
  2033. /**
  2034. * @return \OCP\Collaboration\AutoComplete\IManager
  2035. * @deprecated 20.0.0
  2036. */
  2037. public function getAutoCompleteManager() {
  2038. return $this->get(IManager::class);
  2039. }
  2040. /**
  2041. * Returns the LDAP Provider
  2042. *
  2043. * @return \OCP\LDAP\ILDAPProvider
  2044. * @deprecated 20.0.0
  2045. */
  2046. public function getLDAPProvider() {
  2047. return $this->get('LDAPProvider');
  2048. }
  2049. /**
  2050. * @return \OCP\Settings\IManager
  2051. * @deprecated 20.0.0
  2052. */
  2053. public function getSettingsManager() {
  2054. return $this->get(\OC\Settings\Manager::class);
  2055. }
  2056. /**
  2057. * @return \OCP\Files\IAppData
  2058. * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead
  2059. */
  2060. public function getAppDataDir($app) {
  2061. /** @var \OC\Files\AppData\Factory $factory */
  2062. $factory = $this->get(\OC\Files\AppData\Factory::class);
  2063. return $factory->get($app);
  2064. }
  2065. /**
  2066. * @return \OCP\Lockdown\ILockdownManager
  2067. * @deprecated 20.0.0
  2068. */
  2069. public function getLockdownManager() {
  2070. return $this->get('LockdownManager');
  2071. }
  2072. /**
  2073. * @return \OCP\Federation\ICloudIdManager
  2074. * @deprecated 20.0.0
  2075. */
  2076. public function getCloudIdManager() {
  2077. return $this->get(ICloudIdManager::class);
  2078. }
  2079. /**
  2080. * @return \OCP\GlobalScale\IConfig
  2081. * @deprecated 20.0.0
  2082. */
  2083. public function getGlobalScaleConfig() {
  2084. return $this->get(IConfig::class);
  2085. }
  2086. /**
  2087. * @return \OCP\Federation\ICloudFederationProviderManager
  2088. * @deprecated 20.0.0
  2089. */
  2090. public function getCloudFederationProviderManager() {
  2091. return $this->get(ICloudFederationProviderManager::class);
  2092. }
  2093. /**
  2094. * @return \OCP\Remote\Api\IApiFactory
  2095. * @deprecated 20.0.0
  2096. */
  2097. public function getRemoteApiFactory() {
  2098. return $this->get(IApiFactory::class);
  2099. }
  2100. /**
  2101. * @return \OCP\Federation\ICloudFederationFactory
  2102. * @deprecated 20.0.0
  2103. */
  2104. public function getCloudFederationFactory() {
  2105. return $this->get(ICloudFederationFactory::class);
  2106. }
  2107. /**
  2108. * @return \OCP\Remote\IInstanceFactory
  2109. * @deprecated 20.0.0
  2110. */
  2111. public function getRemoteInstanceFactory() {
  2112. return $this->get(IInstanceFactory::class);
  2113. }
  2114. /**
  2115. * @return IStorageFactory
  2116. * @deprecated 20.0.0
  2117. */
  2118. public function getStorageFactory() {
  2119. return $this->get(IStorageFactory::class);
  2120. }
  2121. /**
  2122. * Get the Preview GeneratorHelper
  2123. *
  2124. * @return GeneratorHelper
  2125. * @since 17.0.0
  2126. * @deprecated 20.0.0
  2127. */
  2128. public function getGeneratorHelper() {
  2129. return $this->get(\OC\Preview\GeneratorHelper::class);
  2130. }
  2131. private function registerDeprecatedAlias(string $alias, string $target) {
  2132. $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
  2133. try {
  2134. /** @var LoggerInterface $logger */
  2135. $logger = $container->get(LoggerInterface::class);
  2136. $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
  2137. } catch (ContainerExceptionInterface $e) {
  2138. // Could not get logger. Continue
  2139. }
  2140. return $container->get($target);
  2141. }, false);
  2142. }
  2143. }