Skip to content

Commit 7c6c50d

Browse files
committed
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 <kano@sunet.se>
1 parent cca09d2 commit 7c6c50d

3 files changed

Lines changed: 73 additions & 2 deletions

File tree

lib/private/OCM/Model/OCMProvider.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*/
2222
class OCMProvider implements IOCMProvider {
2323
private bool $enabled = false;
24+
private bool $removePublicKey = false;
25+
private bool $removeVersion = false;
2426
private string $apiVersion = '';
2527
private string $inviteAcceptDialog = '';
2628
private array $capabilities = [];
@@ -326,6 +328,22 @@ private function looksValid(): bool {
326328
return ($this->getApiVersion() !== '' && $this->getEndPoint() !== '');
327329
}
328330

331+
/**
332+
* @since 35.0.0
333+
*/
334+
#[\Override]
335+
public function removePublicKey(): void {
336+
$this->removePublicKey = true;
337+
}
338+
339+
/**
340+
* @since 35.0.0
341+
*/
342+
#[\Override]
343+
public function removeVersion(): void {
344+
$this->removeVersion = true;
345+
}
346+
329347
/**
330348
* @since 28.0.0
331349
*/
@@ -346,6 +364,15 @@ public function jsonSerialize(): array {
346364
'resourceTypes' => $resourceTypes
347365
];
348366

367+
if ($this->removeVersion) {
368+
$response['apiVersion'] = $this->getApiVersion();
369+
unset($response['version']);
370+
}
371+
372+
if ($this->removePublicKey) {
373+
unset($response['publicKey']);
374+
}
375+
349376
if ($this->capabilities !== []) {
350377
$response['capabilities'] = $this->capabilities;
351378
}

lib/public/OCM/Events/LocalOCMDiscoveryEvent.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,34 @@ public function registerResourceType(string $name, array $shareTypes, array $pro
5454
->setProtocols($protocols);
5555
$this->provider->addResourceType($resourceType);
5656
}
57+
58+
/**
59+
* Remove the non-standard publicKey field from OCM discovery
60+
*
61+
* @since 35.0.0
62+
*/
63+
public function removePublicKey(): void {
64+
$this->provider->removePublicKey();
65+
}
66+
67+
/**
68+
* Remove the non-standard version field from OCM discovery
69+
*
70+
* @since 35.0.0
71+
*/
72+
public function removeVersion(): void {
73+
$this->provider->removeVersion();
74+
}
75+
76+
/**
77+
* Set the apiVersion
78+
*
79+
* @param string $version
80+
*
81+
* @since 35.0.0
82+
*/
83+
public function setApiVersion(string $version): void {
84+
$this->provider->setApiVersion($version);
85+
}
86+
5787
}

lib/public/OCM/IOCMProvider.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ public function setApiVersion(string $apiVersion): static;
5757
*/
5858
public function getApiVersion(): string;
5959

60+
/**
61+
* Remove the non-standard publicKey field from OCM discovery
62+
*
63+
* @since 35.0.0
64+
*/
65+
public function removePublicKey(): void;
66+
67+
/**
68+
* Remove the non-standard version field from OCM discovery
69+
*
70+
* @since 35.0.0
71+
*/
72+
public function removeVersion(): void;
73+
6074
/**
6175
* configure endpoint
6276
*
@@ -219,7 +233,7 @@ public function import(array $data): static;
219233
/**
220234
* @return array{
221235
* enabled: bool,
222-
* apiVersion: '1.0-proposal1',
236+
* apiVersion: string,
223237
* endPoint: string,
224238
* publicKey?: array{
225239
* keyId: string,
@@ -230,7 +244,7 @@ public function import(array $data): static;
230244
* shareTypes: list<string>,
231245
* protocols: array<string, string>
232246
* }>,
233-
* version: string
247+
* version?: string
234248
* }
235249
* @since 28.0.0
236250
*/

0 commit comments

Comments
 (0)