Skip to content

Commit 30b8eef

Browse files
committed
chore(cloud_federation_api): move jwks
Move from .well-known/jwks.json to the TokenController Signed-off-by: Micke Nordin <kano@sunet.se>
1 parent 5b01932 commit 30b8eef

14 files changed

Lines changed: 45 additions & 215 deletions

File tree

apps/cloud_federation_api/appinfo/routes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
*/
99
return [
1010
'routes' => [
11+
[
12+
'name' => 'Token#jwks',
13+
'url' => '/api/v1/jwks',
14+
'verb' => 'GET',
15+
],
1116
[
1217
'name' => 'RequestHandler#addShare',
1318
'url' => '/shares',

apps/cloud_federation_api/lib/Controller/TokenController.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
1919
use OCP\AppFramework\Http\Attribute\PublicPage;
2020
use OCP\AppFramework\Http\DataResponse;
21+
use OCP\AppFramework\Http\JSONResponse;
2122
use OCP\AppFramework\Utility\ITimeFactory;
2223
use OCP\Authentication\Exceptions\ExpiredTokenException;
2324
use OCP\Authentication\Exceptions\InvalidTokenException;
@@ -135,6 +136,27 @@ private function resolveJwtSigningKey(string $privateKeyPem): array {
135136
throw new \RuntimeException('Unsupported signatory key type for JWT access token');
136137
}
137138

139+
/**
140+
* Serve the local JWK Set
141+
*
142+
* @return JSONResponse<Http::STATUS_OK, array{keys: list<array<string, string>>}, array{}>
143+
*
144+
* 200: JWK Set returned
145+
*/
146+
#[PublicPage]
147+
#[NoCSRFRequired]
148+
public function jwks(): JSONResponse {
149+
$keys = [];
150+
try {
151+
foreach ($this->signatoryManager->getLocalJwks() as $jwk) {
152+
$keys[] = $jwk;
153+
}
154+
} catch (\Throwable $e) {
155+
$this->logger->warning('failed to build local JWKs', ['exception' => $e]);
156+
}
157+
return new JSONResponse(['keys' => $keys]);
158+
}
159+
138160
/**
139161
* Exchange a refresh token for a short-lived access token
140162
*

apps/cloud_federation_api/openapi.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,13 @@
323323
}
324324
},
325325
"tags": [
326-
{
327-
"name": "request_handler",
328-
"description": "Open-Cloud-Mesh-API"
329-
},
330326
{
331327
"name": "token",
332328
"description": "Controller for the /token endpoint Exchanges long-lived refresh tokens for short-lived access tokens"
329+
},
330+
{
331+
"name": "request_handler",
332+
"description": "Open-Cloud-Mesh-API"
333333
}
334334
]
335335
}

core/AppInfo/Application.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
use OC\DirectEditing\Listeners\UserDeletedTokenCleanupListener as UserDeletedDirectEditingTokenCleanupListener;
4242
use OC\DirectEditing\Listeners\UserDisabledTokenCleanupListener as UserDisabledDirectEditingTokenCleanupListener;
4343
use OC\OCM\OCMDiscoveryHandler;
44-
use OC\OCM\OCMJwksHandler;
4544
use OC\TagManager;
4645
use OCP\AppFramework\App;
4746
use OCP\AppFramework\Bootstrap\IBootContext;
@@ -113,7 +112,6 @@ public function register(IRegistrationContext $context): void {
113112
$context->registerConfigLexicon(ConfigLexicon::class);
114113

115114
$context->registerWellKnownHandler(OCMDiscoveryHandler::class);
116-
$context->registerWellKnownHandler(OCMJwksHandler::class);
117115
$context->registerCapability(Capabilities::class);
118116

119117
$context->registerEventListener(RestrictInteractionEvent::class, RestrictInteractionListener::class);

lib/composer/composer/autoload_classmap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,6 @@
20562056
'OC\\OCM\\Model\\OCMResource' => $baseDir . '/lib/private/OCM/Model/OCMResource.php',
20572057
'OC\\OCM\\OCMDiscoveryHandler' => $baseDir . '/lib/private/OCM/OCMDiscoveryHandler.php',
20582058
'OC\\OCM\\OCMDiscoveryService' => $baseDir . '/lib/private/OCM/OCMDiscoveryService.php',
2059-
'OC\\OCM\\OCMJwksHandler' => $baseDir . '/lib/private/OCM/OCMJwksHandler.php',
20602059
'OC\\OCM\\OCMSignatoryManager' => $baseDir . '/lib/private/OCM/OCMSignatoryManager.php',
20612060
'OC\\OCM\\Rfc9421SignatoryManager' => $baseDir . '/lib/private/OCM/Rfc9421SignatoryManager.php',
20622061
'OC\\OCS\\ApiHelper' => $baseDir . '/lib/private/OCS/ApiHelper.php',

lib/composer/composer/autoload_static.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2097,7 +2097,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
20972097
'OC\\OCM\\Model\\OCMResource' => __DIR__ . '/../../..' . '/lib/private/OCM/Model/OCMResource.php',
20982098
'OC\\OCM\\OCMDiscoveryHandler' => __DIR__ . '/../../..' . '/lib/private/OCM/OCMDiscoveryHandler.php',
20992099
'OC\\OCM\\OCMDiscoveryService' => __DIR__ . '/../../..' . '/lib/private/OCM/OCMDiscoveryService.php',
2100-
'OC\\OCM\\OCMJwksHandler' => __DIR__ . '/../../..' . '/lib/private/OCM/OCMJwksHandler.php',
21012100
'OC\\OCM\\OCMSignatoryManager' => __DIR__ . '/../../..' . '/lib/private/OCM/OCMSignatoryManager.php',
21022101
'OC\\OCM\\Rfc9421SignatoryManager' => __DIR__ . '/../../..' . '/lib/private/OCM/Rfc9421SignatoryManager.php',
21032102
'OC\\OCS\\ApiHelper' => __DIR__ . '/../../..' . '/lib/private/OCS/ApiHelper.php',

lib/private/OCM/OCMJwksHandler.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

lib/private/OCM/OCMSignatoryManager.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,9 @@ private function signatoryFromPool(int $poolId): ?Signatory {
375375
return $signatory;
376376
}
377377

378-
/**
379-
* Absolute URL of the local JWK Set, advertised as `jwksUri` in the
380-
* discovery response.
381-
*
382-
* @throws IdentityNotFoundException
383-
*/
378+
/** Absolute URL of the local JWK Set, advertised as `jwksUri`. */
384379
public function getLocalJwksUri(): string {
385-
return $this->buildLocalUrl('/.well-known/jwks.json');
380+
return $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.Token.jwks');
386381
}
387382

388383
/**

lib/private/Security/Signature/Model/Rfc9421IncomingSignedRequest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Rfc9421IncomingSignedRequest extends SignedRequest implements
4747
* The `Date` header is deliberately not part of the required set:
4848
* freshness is anchored on the `created` signature parameter.
4949
*/
50-
private const DEFAULT_REQUIRED_COMPONENTS = [
50+
public const REQUIRED_COMPONENTS = [
5151
'@method',
5252
'@target-uri',
5353
'content-digest',
@@ -244,7 +244,7 @@ public function verify(): void {
244244
/** @throws IncomingRequestException if the signature doesn't cover the OCM-required components */
245245
private function verifyRequiredComponents(): void {
246246
/** @var list<string> $required */
247-
$required = $this->options['rfc9421.requiredComponents'] ?? self::DEFAULT_REQUIRED_COMPONENTS;
247+
$required = $this->options['rfc9421.requiredComponents'] ?? self::REQUIRED_COMPONENTS;
248248
$missing = array_values(array_diff($required, $this->components));
249249
if ($missing !== []) {
250250
throw new IncomingRequestException(

lib/private/Security/Signature/Model/Rfc9421OutgoingSignedRequest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@
3535
class Rfc9421OutgoingSignedRequest extends SignedRequest implements
3636
IOutgoingSignedRequest,
3737
JsonSerializable {
38-
/**
39-
* Covered components mandated by the OCM spec. The `Date` header is
40-
* deliberately not covered: intermediaries may rewrite it, and freshness
41-
* is anchored on the `created` signature parameter.
42-
*/
43-
private const DEFAULT_COMPONENTS = ['@method', '@target-uri', 'content-digest', 'content-length'];
4438

4539
private string $host = '';
4640
private array $headers = [];
@@ -70,7 +64,7 @@ public function __construct(
7064
$this->signingAlgorithm = (string)($options['rfc9421.signingAlgorithm'] ?? 'ecdsa-p256-sha256');
7165
$contentDigestAlgorithm = (string)($options['rfc9421.contentDigestAlgorithm'] ?? ContentDigest::ALGO_SHA256);
7266
/** @var list<string> $components */
73-
$components = $options['rfc9421.coveredComponents'] ?? self::DEFAULT_COMPONENTS;
67+
$components = $options['rfc9421.coveredComponents'] ?? Rfc9421IncomingSignedRequest::REQUIRED_COMPONENTS;
7468
$includeAlg = (bool)($options['rfc9421.includeAlgParameter'] ?? false);
7569
$dateHeaderFormat = (string)($options['dateHeader'] ?? SignatureManager::DATE_HEADER);
7670

0 commit comments

Comments
 (0)