ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
KeyRotationObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\WebDAV\Setup;
22
26
31{
32 private const int KEY_LENGTH = 32;
33 private const int NUMBER_OF_KEYS = 5;
34
35 public function getArtifactName(): string
36 {
37 return "webdav_key_rotation";
38 }
39
40 public function build(): Artifact
41 {
42 $current_keys = [];
43 if (is_readable(self::PATH())) {
45 $current_keys = require self::PATH();
46 }
47
48 $new_keys = [];
49 // push one new key to the beginning, drop the oldest key until we have 5 keys
50 for ($i = 0; $i < self::NUMBER_OF_KEYS - 1; $i++) {
51 if ($i === 0) {
52 $new_keys[] = $this->generateRandomString(self::KEY_LENGTH);
53 }
54 $new_keys[] = $current_keys[$i] ?? $this->generateRandomString(self::KEY_LENGTH);
55 }
56
57 return new ArrayArtifact($new_keys);
58 }
59
60 private function generateRandomString(int $length): string
61 {
62 $return = '';
63 for ($i = 0; $i < $length; $i++) {
64 $return .= chr(random_int(33, 125));
65 }
66 return $return;
67 }
68}
An array as an artifact.
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:28