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.

296 lines
11 KiB

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
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
  1. /*
  2. * Copyright (c) 2014
  3. *
  4. * This file is licensed under the Affero General Public License version 3
  5. * or later.
  6. *
  7. * See the COPYING-README file.
  8. *
  9. */
  10. (function() {
  11. OC.SetupChecks = {
  12. /* Message types */
  13. MESSAGE_TYPE_INFO:0,
  14. MESSAGE_TYPE_WARNING:1,
  15. MESSAGE_TYPE_ERROR:2,
  16. /**
  17. * Check whether the WebDAV connection works.
  18. *
  19. * @return $.Deferred object resolved with an array of error messages
  20. */
  21. checkWebDAV: function() {
  22. var deferred = $.Deferred();
  23. var afterCall = function(xhr) {
  24. var messages = [];
  25. if (xhr.status !== 207 && xhr.status !== 401) {
  26. messages.push({
  27. msg: t('core', 'Your web server is not yet set up properly to allow file synchronization because the WebDAV interface seems to be broken.'),
  28. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  29. });
  30. }
  31. deferred.resolve(messages);
  32. };
  33. $.ajax({
  34. type: 'PROPFIND',
  35. url: OC.linkToRemoteBase('webdav'),
  36. data: '<?xml version="1.0"?>' +
  37. '<d:propfind xmlns:d="DAV:">' +
  38. '<d:prop><d:resourcetype/></d:prop>' +
  39. '</d:propfind>',
  40. complete: afterCall
  41. });
  42. return deferred.promise();
  43. },
  44. /**
  45. * Check whether the .well-known URLs works.
  46. *
  47. * @param url the URL to test
  48. * @param placeholderUrl the placeholder URL - can be found at oc_defaults.docPlaceholderUrl
  49. * @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
  50. * @return $.Deferred object resolved with an array of error messages
  51. */
  52. checkWellKnownUrl: function(url, placeholderUrl, runCheck) {
  53. var deferred = $.Deferred();
  54. if(runCheck === false) {
  55. deferred.resolve([]);
  56. return deferred.promise();
  57. }
  58. var afterCall = function(xhr) {
  59. var messages = [];
  60. if (xhr.status !== 207) {
  61. var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL');
  62. messages.push({
  63. msg: t('core', 'Your web server is not set up properly to resolve "{url}". Further information can be found in our <a target="_blank" href="{docLink}">documentation</a>.', { docLink: docUrl, url: url }),
  64. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  65. });
  66. }
  67. deferred.resolve(messages);
  68. };
  69. $.ajax({
  70. type: 'PROPFIND',
  71. url: url,
  72. complete: afterCall
  73. });
  74. return deferred.promise();
  75. },
  76. /**
  77. * Runs setup checks on the server side
  78. *
  79. * @return $.Deferred object resolved with an array of error messages
  80. */
  81. checkSetup: function() {
  82. var deferred = $.Deferred();
  83. var afterCall = function(data, statusText, xhr) {
  84. var messages = [];
  85. if (xhr.status === 200 && data) {
  86. if (!data.serverHasInternetConnection) {
  87. messages.push({
  88. msg: t('core', 'This server has no working Internet connection. This means that some of the features like mounting external storage, notifications about updates or installation of third-party apps will not work. Accessing files remotely and sending of notification emails might not work, either. We suggest to enable Internet connection for this server if you want to have all features.'),
  89. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  90. });
  91. }
  92. if(!data.isMemcacheConfigured) {
  93. messages.push({
  94. msg: t('core', 'No memory cache has been configured. To enhance your performance please configure a memcache if available. Further information can be found in our <a target="_blank" href="{docLink}">documentation</a>.', {docLink: data.memcacheDocs}),
  95. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  96. });
  97. }
  98. if(!data.isUrandomAvailable) {
  99. messages.push({
  100. msg: t('core', '/dev/urandom is not readable by PHP which is highly discouraged for security reasons. Further information can be found in our <a target="_blank" href="{docLink}">documentation</a>.', {docLink: data.securityDocs}),
  101. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  102. });
  103. }
  104. if(data.isUsedTlsLibOutdated) {
  105. messages.push({
  106. msg: data.isUsedTlsLibOutdated,
  107. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  108. });
  109. }
  110. if(data.phpSupported && data.phpSupported.eol) {
  111. messages.push({
  112. msg: t('core', 'Your PHP version ({version}) is no longer <a target="_blank" href="{phpLink}">supported by PHP</a>. We encourage you to upgrade your PHP version to take advantage of performance and security updates provided by PHP.', {version: data.phpSupported.version, phpLink: 'https://secure.php.net/supported-versions.php'}),
  113. type: OC.SetupChecks.MESSAGE_TYPE_INFO
  114. });
  115. }
  116. if(!data.forwardedForHeadersWorking) {
  117. messages.push({
  118. msg: t('core', 'The reverse proxy headers configuration is incorrect, or you are accessing ownCloud from a trusted proxy. If you are not accessing ownCloud from a trusted proxy, this is a security issue and can allow an attacker to spoof their IP address as visible to ownCloud. Further information can be found in our <a target="_blank" href="{docLink}">documentation</a>.', {docLink: data.reverseProxyDocs}),
  119. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  120. });
  121. }
  122. if(!data.isCorrectMemcachedPHPModuleInstalled) {
  123. messages.push({
  124. msg: t('core', 'Memcached is configured as distributed cache, but the wrong PHP module "memcache" is installed. \\OC\\Memcache\\Memcached only supports "memcached" and not "memcache". See the <a target="_blank" href="{wikiLink}">memcached wiki about both modules</a>.', {wikiLink: 'https://code.google.com/p/memcached/wiki/PHPClientComparison'}),
  125. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  126. });
  127. }
  128. if(!data.hasPassedCodeIntegrityCheck) {
  129. messages.push({
  130. msg: t(
  131. 'core',
  132. 'Some files have not passed the integrity check. Further information on how to resolve this issue can be found in our <a target="_blank" href="{docLink}">documentation</a>. (<a href="{codeIntegrityDownloadEndpoint}">List of invalid files…</a> / <a href="{rescanEndpoint}">Rescan…</a>)',
  133. {
  134. docLink: data.codeIntegrityCheckerDocumentation,
  135. codeIntegrityDownloadEndpoint: OC.generateUrl('/settings/integrity/failed'),
  136. rescanEndpoint: OC.generateUrl('/settings/integrity/rescan?requesttoken={requesttoken}', {'requesttoken': OC.requestToken})
  137. }
  138. ),
  139. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  140. });
  141. }
  142. } else {
  143. messages.push({
  144. msg: t('core', 'Error occurred while checking server setup'),
  145. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  146. });
  147. }
  148. deferred.resolve(messages);
  149. };
  150. $.ajax({
  151. type: 'GET',
  152. url: OC.generateUrl('settings/ajax/checksetup')
  153. }).then(afterCall, afterCall);
  154. return deferred.promise();
  155. },
  156. /**
  157. * Runs generic checks on the server side, the difference to dedicated
  158. * methods is that we use the same XHR object for all checks to save
  159. * requests.
  160. *
  161. * @return $.Deferred object resolved with an array of error messages
  162. */
  163. checkGeneric: function() {
  164. var self = this;
  165. var deferred = $.Deferred();
  166. var afterCall = function(data, statusText, xhr) {
  167. var messages = [];
  168. messages = messages.concat(self._checkSecurityHeaders(xhr));
  169. messages = messages.concat(self._checkSSL(xhr));
  170. deferred.resolve(messages);
  171. };
  172. $.ajax({
  173. type: 'GET',
  174. url: OC.generateUrl('heartbeat')
  175. }).then(afterCall, afterCall);
  176. return deferred.promise();
  177. },
  178. checkDataProtected: function() {
  179. var deferred = $.Deferred();
  180. if(oc_dataURL === false){
  181. return deferred.resolve([]);
  182. }
  183. var afterCall = function(xhr) {
  184. var messages = [];
  185. if (xhr.status !== 403 && xhr.status !== 307 && xhr.status !== 301 && xhr.responseText === '') {
  186. messages.push({
  187. msg: t('core', 'Your data directory and your files are probably accessible from the Internet. The .htaccess file is not working. We strongly suggest that you configure your web server in a way that the data directory is no longer accessible or you move the data directory outside the web server document root.'),
  188. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  189. });
  190. }
  191. deferred.resolve(messages);
  192. };
  193. $.ajax({
  194. type: 'GET',
  195. url: OC.linkTo('', oc_dataURL+'/.ocdata'),
  196. complete: afterCall
  197. });
  198. return deferred.promise();
  199. },
  200. /**
  201. * Runs check for some generic security headers on the server side
  202. *
  203. * @param {Object} xhr
  204. * @return {Array} Array with error messages
  205. */
  206. _checkSecurityHeaders: function(xhr) {
  207. var messages = [];
  208. if (xhr.status === 200) {
  209. var securityHeaders = {
  210. 'X-XSS-Protection': '1; mode=block',
  211. 'X-Content-Type-Options': 'nosniff',
  212. 'X-Robots-Tag': 'none',
  213. 'X-Frame-Options': 'SAMEORIGIN',
  214. 'X-Download-Options': 'noopen',
  215. 'X-Permitted-Cross-Domain-Policies': 'none',
  216. };
  217. for (var header in securityHeaders) {
  218. if(!xhr.getResponseHeader(header) || xhr.getResponseHeader(header).toLowerCase() !== securityHeaders[header].toLowerCase()) {
  219. messages.push({
  220. msg: t('core', 'The "{header}" HTTP header is not configured to equal to "{expected}". This is a potential security or privacy risk and we recommend adjusting this setting.', {header: header, expected: securityHeaders[header]}),
  221. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  222. });
  223. }
  224. }
  225. } else {
  226. messages.push({
  227. msg: t('core', 'Error occurred while checking server setup'),
  228. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  229. });
  230. }
  231. return messages;
  232. },
  233. /**
  234. * Runs check for some SSL configuration issues on the server side
  235. *
  236. * @param {Object} xhr
  237. * @return {Array} Array with error messages
  238. */
  239. _checkSSL: function(xhr) {
  240. var messages = [];
  241. if (xhr.status === 200) {
  242. if(OC.getProtocol() === 'https') {
  243. // Extract the value of 'Strict-Transport-Security'
  244. var transportSecurityValidity = xhr.getResponseHeader('Strict-Transport-Security');
  245. if(transportSecurityValidity !== null && transportSecurityValidity.length > 8) {
  246. var firstComma = transportSecurityValidity.indexOf(";");
  247. if(firstComma !== -1) {
  248. transportSecurityValidity = transportSecurityValidity.substring(8, firstComma);
  249. } else {
  250. transportSecurityValidity = transportSecurityValidity.substring(8);
  251. }
  252. }
  253. var minimumSeconds = 15768000;
  254. if(isNaN(transportSecurityValidity) || transportSecurityValidity <= (minimumSeconds - 1)) {
  255. messages.push({
  256. msg: t('core', 'The "Strict-Transport-Security" HTTP header is not configured to least "{seconds}" seconds. For enhanced security we recommend enabling HSTS as described in our <a href="{docUrl}">security tips</a>.', {'seconds': minimumSeconds, docUrl: '#admin-tips'}),
  257. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  258. });
  259. }
  260. } else {
  261. messages.push({
  262. msg: t('core', 'You are accessing this site via HTTP. We strongly suggest you configure your server to require using HTTPS instead as described in our <a href="{docUrl}">security tips</a>.', {docUrl: '#admin-tips'}),
  263. type: OC.SetupChecks.MESSAGE_TYPE_WARNING
  264. });
  265. }
  266. } else {
  267. messages.push({
  268. msg: t('core', 'Error occurred while checking server setup'),
  269. type: OC.SetupChecks.MESSAGE_TYPE_ERROR
  270. });
  271. }
  272. return messages;
  273. }
  274. };
  275. })();