Skip to content

Commit 63329fa

Browse files
Add dummy replay detector
1 parent b13f46b commit 63329fa

File tree

4 files changed

+138
-4
lines changed

4 files changed

+138
-4
lines changed

run-solid-test-suite.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function setup {
2020
}
2121

2222
function runPss {
23-
docker run -d --name server --network=testnet --env-file ./env-vars-for-test-image.list standalone-solid-server
24-
docker run -d --name thirdparty --network=testnet --env-file ./env-vars-for-third-party.list standalone-solid-server
23+
docker run -d --name server --network=testnet --env-file ./env-vars-for-test-image.list -v `pwd`/src:/app/src standalone-solid-server
24+
docker run -d --name thirdparty --network=testnet --env-file ./env-vars-for-third-party.list -v `pwd`/src:/app/src standalone-solid-server
2525

2626
docker run -d --name pubsub --network=testnet pubsub-server
2727

src/Controller/ServerController.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22

33
namespace Pdsinterop\Solid\Controller;
44

5+
use Pdsinterop\Solid\DpopFactoryTrait;
56
use Pdsinterop\Solid\Auth\Config\Client;
67
use Pdsinterop\Solid\Auth\Enum\Authorization;
78
use Pdsinterop\Solid\Auth\Factory\ConfigFactory;
89

910
abstract class ServerController extends AbstractController
1011
{
12+
13+
use DpopFactoryTrait;
14+
1115
protected $authServerConfig;
1216
protected $authServerFactory;
1317
protected $baseUrl;
@@ -24,7 +28,11 @@ public function __construct()
2428

2529
$this->authServerConfig = $this->createAuthServerConfig();
2630
$this->authServerFactory = (new \Pdsinterop\Solid\Auth\Factory\AuthorizationServerFactory($this->authServerConfig))->create();
27-
$this->tokenGenerator = (new \Pdsinterop\Solid\Auth\TokenGenerator($this->authServerConfig));
31+
$this->tokenGenerator = (new \Pdsinterop\Solid\Auth\TokenGenerator(
32+
$this->authServerConfig,
33+
$this->getDpopValidFor(),
34+
$this->getDpop()
35+
));
2836
$this->baseUrl = isset($_ENV['SERVER_ROOT']) ? $_ENV['SERVER_ROOT'] : "https://localhost";
2937
}
3038

@@ -59,7 +67,7 @@ public function getKeys()
5967

6068
public function createAuthServerConfig()
6169
{
62-
$clientId = $_GET['client_id']; // FIXME: No request object here to get the client Id from.
70+
$clientId = ''; // $_GET['client_id']; // FIXME: No request object here to get the client Id from.
6371
$client = $this->getClient($clientId);
6472
$keys = $this->getKeys();
6573

src/DpopFactoryTrait.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Pdsinterop\Solid;
4+
5+
use DateInterval;
6+
// use OCP\IDBConnection;
7+
use Pdsinterop\Solid\Auth\Utils\DPop;
8+
use Pdsinterop\Solid\Auth\Utils\JtiValidator;
9+
10+
trait DpopFactoryTrait
11+
{
12+
////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\
13+
14+
// private IDBConnection $connection;
15+
private DateInterval $validFor;
16+
17+
//////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
18+
19+
final public function getDpop(): DPop
20+
{
21+
$interval = $this->getDpopValidFor();
22+
23+
// $replayDetector = new JtiReplayDetector($interval, $this->connection);
24+
$replayDetector = new JtiReplayDetector($interval, null);
25+
26+
$jtiValidator = new JtiValidator($replayDetector);
27+
28+
return new DPop($jtiValidator);
29+
}
30+
31+
final public function getDpopValidFor(): DateInterval
32+
{
33+
static $validFor;
34+
35+
if ($validFor === null) {
36+
$validFor = new DateInterval('PT10M');
37+
}
38+
39+
return $validFor;
40+
}
41+
42+
final public function setJtiStorage(): void
43+
{
44+
// FIXME
45+
}
46+
47+
////////////////////////////// UTILITY METHODS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
48+
}

src/JtiReplayDetector.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace Pdsinterop\Solid;
4+
5+
use DateInterval;
6+
use DateTime;
7+
// use OCP\DB\QueryBuilder\IQueryBuilder;
8+
// use OCP\IDBConnection;
9+
use Pdsinterop\Solid\Auth\ReplayDetectorInterface;
10+
11+
class JtiReplayDetector implements ReplayDetectorInterface
12+
{
13+
////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\
14+
15+
private string $table = 'solid_jti';
16+
17+
//////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
18+
19+
public function __construct(private DateInterval $interval)
20+
{
21+
}
22+
23+
public function detect(string $jti, string $targetUri): bool
24+
{
25+
$hash = sha1($targetUri);
26+
27+
// @TODO: $this->rotateBuckets();
28+
$has = $this->has($jti, $hash);
29+
30+
if ($has === false) {
31+
$this->store($jti, $hash);
32+
}
33+
34+
return $has;
35+
}
36+
37+
////////////////////////////// UTILITY METHODS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
38+
39+
private function has(string $jti, string $uri): bool
40+
{
41+
$queryBuilder = $this->connection->getQueryBuilder();
42+
43+
$notOlderThan = (new DateTime())->sub($this->interval);
44+
45+
// $cursor = $queryBuilder->select('*')
46+
// ->from($this->table)
47+
// ->where(
48+
// $queryBuilder->expr()->eq('jti', $queryBuilder->createNamedParameter($jti,IQueryBuilder::PARAM_STR))
49+
// )
50+
// ->andWhere(
51+
// $queryBuilder->expr()->eq('uri', $queryBuilder->createNamedParameter($uri, IQueryBuilder::PARAM_STR))
52+
// )
53+
// ->andWhere(
54+
// $queryBuilder->expr()->gt('request_time', $queryBuilder->createParameter('notOlderThan'))
55+
// )->setParameter('notOlderThan', $notOlderThan, 'datetime')
56+
// ->execute()
57+
// ;
58+
59+
// $row = $cursor->fetch();
60+
61+
// $cursor->closeCursor();
62+
63+
return false ; // FIXME! REPLAY PROTECTION DISABLED!! ! empty($row);
64+
}
65+
66+
private function store(string $jti, string $uri): void
67+
{
68+
// $queryBuilder = $this->connection->getQueryBuilder();
69+
70+
// $queryBuilder->insert($this->table)
71+
// ->values([
72+
// 'jti' => $queryBuilder->createNamedParameter($jti),
73+
// 'uri' => $queryBuilder->createNamedParameter($uri),
74+
// ])
75+
// ->executeStatement()
76+
// ;
77+
}
78+
}

0 commit comments

Comments
 (0)