-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUserPage.php
More file actions
85 lines (80 loc) · 2.53 KB
/
Copy pathUserPage.php
File metadata and controls
85 lines (80 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types=1);
namespace FediE2EE\PKDServer\RequestHandlers\ActivityPub;
use FediE2EE\PKD\Crypto\Exceptions\{
CryptoException,
NotImplementedException
};
use JsonException;
use FediE2EE\PKDServer\{
Exceptions\DependencyException,
Meta\Route,
Traits\ActivityStreamsTrait,
Traits\ReqTrait
};
use Override;
use ParagonIE\PQCrypto\Exception\{
MLDSAInternalException,
PQCryptoCompatException
};
use Psr\Http\Server\RequestHandlerInterface;
use Random\RandomException;
use Psr\Http\Message\{
ServerRequestInterface,
ResponseInterface
};
use SodiumException;
class UserPage implements RequestHandlerInterface
{
use ActivityStreamsTrait;
use ReqTrait;
/**
* @throws CryptoException
* @throws DependencyException
* @throws JsonException
* @throws MLDSAInternalException
* @throws NotImplementedException
* @throws PQCryptoCompatException
* @throws RandomException
* @throws SodiumException
*/
#[Route("/users/{user_id}")]
#[Override]
public function handle(ServerRequestInterface $request): ResponseInterface
{
$params = $this->config()->getParams();
$requested = $request->getAttribute('user_id');
if (!is_string($requested) || !hash_equals($params->actorUsername, $requested)) {
return $this->error('User not found', 404);
}
$publicKey = $this->config()->getSigningKeys()->publicKey;
$actorUrl = 'https://' . $params->hostname . '/users/' . $params->actorUsername;
return $this->json(
[
'@context' => [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
],
'id' => $actorUrl,
'type' => 'Service',
'preferredUsername' => $params->actorUsername,
'inbox' => $actorUrl . '/inbox',
'assertionMethod' => [
[
'type' => 'Multikey',
'id' => $actorUrl . '#main-key',
'controller' => $actorUrl,
'publicKeyMultibase' => $publicKey->toMultibase(),
],
],
'publicKey' => [
'id' => $actorUrl . '#main-key',
'owner' => $actorUrl,
'publicKeyPem' => $publicKey->encodePem(),
],
],
200,
['Content-Type' => 'application/activity+json']
);
}
}