ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
DataSigner.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
40
44final class DataSigner
45{
49
50 public function __construct(
51 SecretKeyRotation $key_rotation,
52 ?Algorithm $algorithm = null,
53 ?Compression $compression = null,
54 ?Transport $transport = null
55 ) {
56 $this->salt_factory = new Factory();
57 $compression ??= new DeflateCompression();
58 $transport ??= new URLSafeTransport();
59 $algorithm ??= new ShortenedSHA1();
60
61 $this->signing_serializer = new SigningSerializer(
63 $key_rotation,
64 new HMACSigner(
65 $algorithm
66 ),
68 $algorithm
69 )
70 ),
71 new JSONSerializer(),
72 $compression,
73 $transport
74 );
75
76 $this->payload_builder = new Builder();
77 }
78
79 public function getSignedStreamToken(
80 FileStream $stream,
81 string $filename,
82 Disposition $disposition,
83 int $user_id,
84 ?\DateTimeImmutable $until = null
85 ): string {
86 $payload = $this->payload_builder->shortFile(
87 $stream,
89 );
90
91 if ($until !== null) {
92 $payload->setUntil($until->getTimestamp());
93 }
94
95 return $this->signing_serializer->sign(
97 $this->salt_factory->create('stream')
98 );
99 }
100
101 public function verifyStreamToken(string $token): ?Payload
102 {
103 $data = $this->verify($token, 'stream');
104 if ($data === null) {
105 return null;
106 }
107 return $this->payload_builder->shortFileFromRaw($data);
108 }
109
110 public function sign(
111 array $data,
112 string $salt,
113 ?\DateTimeImmutable $until = null
114 ): string {
116
117 if ($until !== null) {
118 $payload->setUntil($until->getTimestamp());
119 }
120
121 return $this->signing_serializer->sign(
122 $payload,
123 $this->salt_factory->create($salt)
124 );
125 }
126
127 public function verify(
128 string $token,
129 string $salt
130 ): ?array {
131 return $this->signing_serializer->verify(
132 $token,
133 $this->salt_factory->create($salt)
134 )?->get();
135 }
136}
$filename
Definition: buildRTE.php:78
sign(array $data, string $salt, ?\DateTimeImmutable $until=null)
Definition: DataSigner.php:110
__construct(SecretKeyRotation $key_rotation, ?Algorithm $algorithm=null, ?Compression $compression=null, ?Transport $transport=null)
Definition: DataSigner.php:50
getSignedStreamToken(FileStream $stream, string $filename, Disposition $disposition, int $user_id, ?\DateTimeImmutable $until=null)
Definition: DataSigner.php:79
SigningSerializer $signing_serializer
Definition: DataSigner.php:46
verify(string $token, string $salt)
Definition: DataSigner.php:127
Key rotation can provide an extra layer of mitigation against an attacker discovering a secret key.
The salt is combined with the secret key to derive a unique key for distinguishing different contexts...
Definition: Factory.php:38
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
The base interface for all filesystem streams.
Definition: FileStream.php:32
if(count($parts) !=3) $payload
Definition: ltitoken.php:67
get(string $class_name)
$token
Definition: xapitoken.php:70