1111use SimpleSAML \SAML2 \Exception \ProtocolViolationException ;
1212use SimpleSAML \Utils ;
1313
14+ use function array_search ;
15+ use function base64_decode ;
16+ use function base64_encode ;
17+ use function explode ;
18+ use function implode ;
19+ use function intval ;
20+ use function is_string ;
21+ use function json_decode ;
22+ use function json_encode ;
23+ use function sha1 ;
24+ use function strlen ;
25+ use function strval ;
26+ use function time ;
27+ use function var_export ;
28+
1429/**
1530 * CDC server class.
1631 *
@@ -82,7 +97,7 @@ public function __construct(string $domain)
8297 /**
8398 * Send a request to this CDC server.
8499 *
85- * @param array $request The CDC request.
100+ * @param array $request<mixed> The CDC request.
86101 */
87102 public function sendRequest (array $ request ): void
88103 {
@@ -97,7 +112,7 @@ public function sendRequest(array $request): void
97112 /**
98113 * Parse and validate response received from a CDC server.
99114 *
100- * @return array|null The response, or NULL if no response is received.
115+ * @return array<mixed> |null The response, or NULL if no response is received.
101116 * @throws \SimpleSAML\Error\Exception
102117 */
103118 public function getResponse (): ?array
@@ -139,22 +154,22 @@ public static function processRequest(): void
139154 /**
140155 * Handle a parsed CDC requst.
141156 *
142- * @param array $request
157+ * @param array<mixed> $request
143158 * @throws \SimpleSAML\Error\Exception
144159 */
145160 private function handleRequest (array $ request ): void
146161 {
147162 if (!isset ($ request ['op ' ])) {
148163 throw new Error \BadRequest ('Missing "op" in CDC request. ' );
149164 }
150- $ op = ( string ) $ request ['op ' ];
165+ $ op = strval ( $ request ['op ' ]) ;
151166
152167 Logger::info ('Received CDC request with "op": ' . var_export ($ op , true ));
153168
154169 if (!isset ($ request ['return ' ])) {
155170 throw new Error \BadRequest ('Missing "return" in CDC request. ' );
156171 }
157- $ return = ( string ) $ request ['return ' ];
172+ $ ret = strval ( $ request ['return ' ]) ;
158173
159174 switch ($ op ) {
160175 case 'append ' :
@@ -178,18 +193,18 @@ private function handleRequest(array $request): void
178193
179194 $ response ['op ' ] = $ op ;
180195 if (isset ($ request ['id ' ])) {
181- $ response ['id ' ] = ( string ) $ request ['id ' ];
196+ $ response ['id ' ] = strval ( $ request ['id ' ]) ;
182197 }
183198 $ response ['domain ' ] = $ this ->domain ;
184199
185- $ this ->send ($ return , 'CDCResponse ' , $ response );
200+ $ this ->send ($ ret , 'CDCResponse ' , $ response );
186201 }
187202
188203
189204 /**
190205 * Handle an append request.
191206 *
192- * @param array $request The request.
207+ * @param array<mixed> $request The request.
193208 * @throws \SimpleSAML\Error\BadRequest
194209 * @return string The response.
195210 */
@@ -217,7 +232,7 @@ private function handleAppend(array $request): string
217232 /**
218233 * Handle a delete request.
219234 *
220- * @param array $request The request.
235+ * @param array<mixed> $request The request.
221236 * @return string The response.
222237 */
223238 private function handleDelete (array $ request ): string
@@ -238,8 +253,8 @@ private function handleDelete(array $request): string
238253 /**
239254 * Handle a read request.
240255 *
241- * @param array $request The request.
242- * @return array The response.
256+ * @param array<mixed> $request The request.
257+ * @return array<mixed> The response.
243258 */
244259 private function handleRead (array $ request ): array
245260 {
@@ -257,7 +272,7 @@ private function handleRead(array $request): array
257272 *
258273 * @param string $parameter The name of the query parameter.
259274 * @throws \SimpleSAML\Error\BadRequest
260- * @return array|null The response, or NULL if no response is received.
275+ * @return array<mixed> |null The response, or NULL if no response is received.
261276 */
262277 private static function get (string $ parameter ): ?array
263278 {
@@ -267,7 +282,7 @@ private static function get(string $parameter): ?array
267282 $ message = (string ) $ _REQUEST [$ parameter ];
268283 Assert::validBase64 ($ message , ProtocolViolationException::class);
269284
270- $ message = @base64_decode ($ message );
285+ $ message = @base64_decode ($ message, true );
271286 if ($ message === false ) {
272287 throw new Error \BadRequest ('Error base64-decoding CDC message. ' );
273288 }
@@ -280,7 +295,7 @@ private static function get(string $parameter): ?array
280295 if (!isset ($ message ['timestamp ' ])) {
281296 throw new Error \BadRequest ('Missing timestamp in CDC message. ' );
282297 }
283- $ timestamp = ( int ) $ message ['timestamp ' ];
298+ $ timestamp = intval ( $ message ['timestamp ' ]) ;
284299
285300 if ($ timestamp + 60 < time ()) {
286301 throw new Error \BadRequest ('CDC signature has expired. ' );
@@ -328,7 +343,7 @@ private function validate(string $parameter): void
328343 *
329344 * @param string $to The URL the message should be delivered to.
330345 * @param string $parameter The query parameter the message should be sent in.
331- * @param array $message The CDC message.
346+ * @param array<mixed> $message The CDC message.
332347 */
333348 private function send (string $ to , string $ parameter , array $ message ): void
334349 {
@@ -368,20 +383,20 @@ private function calcSignature(string $rawMessage): string
368383 /**
369384 * Get the IdP entities saved in the common domain cookie.
370385 *
371- * @return array List of IdP entities.
386+ * @return string[] List of IdP entities.
372387 */
373388 private function getCDC (): array
374389 {
375390 if (!isset ($ _COOKIE ['_saml_idp ' ])) {
376391 return [];
377392 }
378393
379- $ ret = ( string ) $ _COOKIE ['_saml_idp ' ];
394+ $ ret = strval ( $ _COOKIE ['_saml_idp ' ]) ;
380395
381396 $ ret = explode (' ' , $ ret );
382397 foreach ($ ret as &$ idp ) {
383398 Assert::validBase64 ($ idp , ProtocolViolationException::class);
384- $ idp = base64_decode ($ idp );
399+ $ idp = base64_decode ($ idp, true );
385400 if ($ idp === false ) {
386401 // Not properly base64 encoded
387402 Logger::warning ('CDC - Invalid base64-encoding of CDC entry. ' );
0 commit comments