diff --git a/apps/settings/.editorconfig b/apps/settings/.editorconfig index 442058331bbfa..a12fda74f9ad3 100644 --- a/apps/settings/.editorconfig +++ b/apps/settings/.editorconfig @@ -7,6 +7,6 @@ end_of_line = lf insert_final_newline = true trim_trailing_whitespace = true -[{package.json,.travis.yml,webpack.config.js}] +[{package.json,.travis.yml,webpack.config.js,assetlinks-template.json}] indent_style = space -indent_size = 2 \ No newline at end of file +indent_size = 2 diff --git a/apps/settings/composer/composer/autoload_classmap.php b/apps/settings/composer/composer/autoload_classmap.php index 17e47f62a7d8b..b2a4e525aa6ce 100644 --- a/apps/settings/composer/composer/autoload_classmap.php +++ b/apps/settings/composer/composer/autoload_classmap.php @@ -126,6 +126,7 @@ 'OCA\\Settings\\SetupChecks\\Woff2Loading' => $baseDir . '/../lib/SetupChecks/Woff2Loading.php', 'OCA\\Settings\\UserMigration\\AccountMigrator' => $baseDir . '/../lib/UserMigration/AccountMigrator.php', 'OCA\\Settings\\UserMigration\\AccountMigratorException' => $baseDir . '/../lib/UserMigration/AccountMigratorException.php', + 'OCA\\Settings\\WellKnown\\AssetLinksHandler' => $baseDir . '/../lib/WellKnown/AssetLinksHandler.php', 'OCA\\Settings\\WellKnown\\ChangePasswordHandler' => $baseDir . '/../lib/WellKnown/ChangePasswordHandler.php', 'OCA\\Settings\\WellKnown\\SecurityTxtHandler' => $baseDir . '/../lib/WellKnown/SecurityTxtHandler.php', ); diff --git a/apps/settings/composer/composer/autoload_static.php b/apps/settings/composer/composer/autoload_static.php index 1dccc69b923a5..4cc8834ccbec3 100644 --- a/apps/settings/composer/composer/autoload_static.php +++ b/apps/settings/composer/composer/autoload_static.php @@ -141,6 +141,7 @@ class ComposerStaticInitSettings 'OCA\\Settings\\SetupChecks\\Woff2Loading' => __DIR__ . '/..' . '/../lib/SetupChecks/Woff2Loading.php', 'OCA\\Settings\\UserMigration\\AccountMigrator' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigrator.php', 'OCA\\Settings\\UserMigration\\AccountMigratorException' => __DIR__ . '/..' . '/../lib/UserMigration/AccountMigratorException.php', + 'OCA\\Settings\\WellKnown\\AssetLinksHandler' => __DIR__ . '/..' . '/../lib/WellKnown/AssetLinksHandler.php', 'OCA\\Settings\\WellKnown\\ChangePasswordHandler' => __DIR__ . '/..' . '/../lib/WellKnown/ChangePasswordHandler.php', 'OCA\\Settings\\WellKnown\\SecurityTxtHandler' => __DIR__ . '/..' . '/../lib/WellKnown/SecurityTxtHandler.php', ); diff --git a/apps/settings/data/assetlinks-template.json b/apps/settings/data/assetlinks-template.json new file mode 100644 index 0000000000000..77bc0d9521fcc --- /dev/null +++ b/apps/settings/data/assetlinks-template.json @@ -0,0 +1,12 @@ +[ + { + "relation": [ + "delegate_permission/common.handle_all_urls" + ], + "target": { + "namespace": "android_app", + "package_name": "", + "sha256_cert_fingerprints": [] + } + } +] diff --git a/apps/settings/lib/AppInfo/Application.php b/apps/settings/lib/AppInfo/Application.php index 9f7ec3036f43f..b645cf350a399 100644 --- a/apps/settings/lib/AppInfo/Application.php +++ b/apps/settings/lib/AppInfo/Application.php @@ -94,6 +94,7 @@ use OCA\Settings\SetupChecks\WellKnownUrls; use OCA\Settings\SetupChecks\Woff2Loading; use OCA\Settings\UserMigration\AccountMigrator; +use OCA\Settings\WellKnown\AssetLinksHandler; use OCA\Settings\WellKnown\ChangePasswordHandler; use OCA\Settings\WellKnown\SecurityTxtHandler; use OCP\AppFramework\App; @@ -136,6 +137,7 @@ public function register(IRegistrationContext $context): void { // Register well-known handlers $context->registerWellKnownHandler(SecurityTxtHandler::class); $context->registerWellKnownHandler(ChangePasswordHandler::class); + $context->registerWellKnownHandler(AssetLinksHandler::class); /** * Core class wrappers diff --git a/apps/settings/lib/WellKnown/AssetLinksHandler.php b/apps/settings/lib/WellKnown/AssetLinksHandler.php new file mode 100644 index 0000000000000..ae521b35becbd --- /dev/null +++ b/apps/settings/lib/WellKnown/AssetLinksHandler.php @@ -0,0 +1,58 @@ + + * + * @author Christopher Ng + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Settings\WellKnown; + +use OCP\AppFramework\Http\JSONResponse; +use OCP\Http\WellKnown\GenericResponse; +use OCP\Http\WellKnown\IHandler; +use OCP\Http\WellKnown\IRequestContext; +use OCP\Http\WellKnown\IResponse; +use OCP\IConfig; + +class AssetLinksHandler implements IHandler { + + public function __construct( + private IConfig $config, + ) { + } + + public function handle(string $service, IRequestContext $context, ?IResponse $previousResponse): ?IResponse { + if ($service !== 'assetlinks.json') { + return $previousResponse; + } + + $data = json_decode(file_get_contents(__DIR__ . '/../../data/assetlinks-template.json'), true); + $data[0]['target']['package_name'] = $this->config->getSystemValueString('assetlinks_package_name', 'com.nextcloud.client'); + $data[0]['target']['sha256_cert_fingerprints'] = $this->config->getSystemValue( + 'assetlinks_sha256_cert_fingerprints', + [ + '59:BF:BB:8A:5C:17:53:D6:69:AE:C0:D8:CC:D0:DA:82:76:FE:8E:AC:81:A4:45:22:AE:68:0E:A7:74:81:A3:32', + ], + ); + return new GenericResponse(new JSONResponse($data)); + } +} diff --git a/config/config.sample.php b/config/config.sample.php index 280334477a6a7..48add3c292f33 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -1121,6 +1121,24 @@ 'https://itunes.apple.com/us/app/nextcloud/id1125420102?mt=8', 'customclient_ios_appid' => '1125420102', + +/** + * This configures the package name in assetlinks.json for the Android client. + * + * Defaults to ``com.nextcloud.client`` + */ +'assetlinks_package_name' => 'com.nextcloud.client', + +/** + * This configures the sha256 certificate fingerprints in assetlinks.json for the Android client. + * + * Defaults to an array with: + * - ``59:BF:BB:8A:5C:17:53:D6:69:AE:C0:D8:CC:D0:DA:82:76:FE:8E:AC:81:A4:45:22:AE:68:0E:A7:74:81:A3:32`` + */ +'assetlinks_sha256_cert_fingerprints' => [ + '59:BF:BB:8A:5C:17:53:D6:69:AE:C0:D8:CC:D0:DA:82:76:FE:8E:AC:81:A4:45:22:AE:68:0E:A7:74:81:A3:32', +], + /** * Apps *