ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
KeyRotationObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
30{
31 private const int KEY_LENGTH = 32;
32 private const int NUMBER_OF_KEYS = 5;
33
34 public function getArtifactName(): string
35 {
36 return "key_rotation";
37 }
38
39 public function build(): Artifact
40 {
41 $current_keys = [];
42 if (is_readable(self::PATH())) {
44 $current_keys = require self::PATH();
45 }
46
47 $new_keys = [];
48 // push one new key to the beginning, drop the oldest key until we have 5 keys
49 for ($i = 0; $i < self::NUMBER_OF_KEYS - 1; $i++) {
50 if ($i === 0) {
51 $new_keys[] = $this->generateRandomString(self::KEY_LENGTH);
52 }
53 $new_keys[] = $current_keys[$i] ?? $this->generateRandomString(self::KEY_LENGTH);
54 }
55
56 return new ArrayArtifact($new_keys);
57 }
58
59 private function generateRandomString(int $length): string
60 {
61 $return = '';
62 for ($i = 0; $i < $length; $i++) {
63 $return .= chr(random_int(33, 125));
64 }
65 return $return;
66 }
67}
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