ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
KeyRotationObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\FileDelivery\Setup;
22 
24 use ILIAS\Setup;
25 
30 {
31  public const KEY_LENGTH = 32;
32  private const NUMBER_OF_KEYS = 5;
33  public function getArtifactName(): string
34  {
35  return "key_rotation";
36  }
37 
38 
39  public function build(): Setup\Artifact
40  {
41  $current_keys = null;
42  if (is_readable(self::PATH())) {
44  $current_keys = require self::PATH();
45  }
46 
47  $new_keys = [];
48 
49  if (is_array($current_keys)) {
50  // drop the first key
51  $current_keys = array_slice($current_keys, 1);
52  $new_keys = $current_keys;
53  }
54  // $push a new key to the array at first position
55  while (count($new_keys) < self::NUMBER_OF_KEYS) {
56  $new_keys[] = $this->generateRandomString(self::KEY_LENGTH);
57  }
58  // keep only the first 5 keys
59  $new_keys = array_slice($new_keys, 0, self::NUMBER_OF_KEYS);
60 
61  return new Setup\Artifact\ArrayArtifact($new_keys);
62  }
63 
64  private function generateRandomString(int $length): string
65  {
66  $return = '';
67  for ($i = 0; $i < $length; $i++) {
68  $return .= chr(random_int(33, 125));
69  }
70  return $return;
71  }
72 }
build()
Build the artifact based.
This is an objective to build some artifact.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An artifact is some file that is build on demand per installation and is not shipped with the ILIAS s...
Definition: Artifact.php:27