Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Serve well-known assetlinks json #44665

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/settings/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
indent_size = 2
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
1 change: 1 addition & 0 deletions apps/settings/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down
12 changes: 12 additions & 0 deletions apps/settings/data/assetlinks-template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"relation": [
"delegate_permission/common.handle_all_urls"
],
"target": {
"namespace": "android_app",
"package_name": "",
"sha256_cert_fingerprints": []
}
}
]
2 changes: 2 additions & 0 deletions apps/settings/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
58 changes: 58 additions & 0 deletions apps/settings/lib/WellKnown/AssetLinksHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

/**
* @copyright 2024 Christopher Ng <chrng8@gmail.com>
*
* @author Christopher Ng <chrng8@gmail.com>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

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));
}
}
18 changes: 18 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Loading