From 7dd4c4eb7c316ff585bff90471b38ab3d0949efa Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Thu, 25 Jun 2026 00:32:57 +0200 Subject: [PATCH] feat(OCM): Make it possible to have a spec compliant discovery The current discovery document have non standard elements, which are required for backwards compatibility with old Nextcloud versions. There may however be deployments, that are up to date, and do not require backwards compatibility but instead value spec compliance and adding two new knobs to LocalOCMDiscoveryEvent can make that happen. The new knobs are removeVersion which removes the non standard version field from the discovery and sets the correct apiVersion instead. Nextcloud prior to version 28 had an equality check for apiVersion and the hard coded string `1.0-proposal1` which is not at all the version that Nextcloud actually supports. Along side this change a new function removePublicKey is also added. The publicKey in the discovery document is no longer used with the RFC9421 style http-signatures, and only the old legacy signatures use that key, since version 35 Nextcloud supports RFC9421 signatures, and the legacy publicKey can now be removed from the discovery if you don't require backwards compatibility with older Nextcloud versions. Fixes: #52754 Signed-off-by: Micke Nordin --- lib/private/OCM/Model/OCMProvider.php | 27 +++++++++++++++++ .../OCM/Events/LocalOCMDiscoveryEvent.php | 30 +++++++++++++++++++ lib/public/OCM/IOCMProvider.php | 18 +++++++++-- 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/lib/private/OCM/Model/OCMProvider.php b/lib/private/OCM/Model/OCMProvider.php index 76530353613c4..6b623c66b5512 100644 --- a/lib/private/OCM/Model/OCMProvider.php +++ b/lib/private/OCM/Model/OCMProvider.php @@ -21,6 +21,8 @@ */ class OCMProvider implements IOCMProvider { private bool $enabled = false; + private bool $removePublicKey = false; + private bool $removeVersion = false; private string $apiVersion = ''; private string $inviteAcceptDialog = ''; private array $capabilities = []; @@ -326,6 +328,22 @@ private function looksValid(): bool { return ($this->getApiVersion() !== '' && $this->getEndPoint() !== ''); } + /** + * @since 35.0.0 + */ + #[\Override] + public function removePublicKey(): void { + $this->removePublicKey = true; + } + + /** + * @since 35.0.0 + */ + #[\Override] + public function removeVersion(): void { + $this->removeVersion = true; + } + /** * @since 28.0.0 */ @@ -346,6 +364,15 @@ public function jsonSerialize(): array { 'resourceTypes' => $resourceTypes ]; + if ($this->removeVersion) { + $response['apiVersion'] = $this->getApiVersion(); + unset($response['version']); + } + + if ($this->removePublicKey) { + unset($response['publicKey']); + } + if ($this->capabilities !== []) { $response['capabilities'] = $this->capabilities; } diff --git a/lib/public/OCM/Events/LocalOCMDiscoveryEvent.php b/lib/public/OCM/Events/LocalOCMDiscoveryEvent.php index a6ef943145b17..cb63d0c05060b 100644 --- a/lib/public/OCM/Events/LocalOCMDiscoveryEvent.php +++ b/lib/public/OCM/Events/LocalOCMDiscoveryEvent.php @@ -54,4 +54,34 @@ public function registerResourceType(string $name, array $shareTypes, array $pro ->setProtocols($protocols); $this->provider->addResourceType($resourceType); } + + /** + * Remove the non-standard publicKey field from OCM discovery + * + * @since 35.0.0 + */ + public function removePublicKey(): void { + $this->provider->removePublicKey(); + } + + /** + * Remove the non-standard version field from OCM discovery + * + * @since 35.0.0 + */ + public function removeVersion(): void { + $this->provider->removeVersion(); + } + + /** + * Set the apiVersion + * + * @param string $version + * + * @since 35.0.0 + */ + public function setApiVersion(string $version): void { + $this->provider->setApiVersion($version); + } + } diff --git a/lib/public/OCM/IOCMProvider.php b/lib/public/OCM/IOCMProvider.php index bcda666578438..3cf7f60c09012 100644 --- a/lib/public/OCM/IOCMProvider.php +++ b/lib/public/OCM/IOCMProvider.php @@ -57,6 +57,20 @@ public function setApiVersion(string $apiVersion): static; */ public function getApiVersion(): string; + /** + * Remove the non-standard publicKey field from OCM discovery + * + * @since 35.0.0 + */ + public function removePublicKey(): void; + + /** + * Remove the non-standard version field from OCM discovery + * + * @since 35.0.0 + */ + public function removeVersion(): void; + /** * configure endpoint * @@ -219,7 +233,7 @@ public function import(array $data): static; /** * @return array{ * enabled: bool, - * apiVersion: '1.0-proposal1', + * apiVersion: string, * endPoint: string, * publicKey?: array{ * keyId: string, @@ -230,7 +244,7 @@ public function import(array $data): static; * shareTypes: list, * protocols: array * }>, - * version: string + * version?: string * } * @since 28.0.0 */