\Drupal\strata\Crypto KeyMaker

Creates the key entity Strata seals frames with.

Encryption ships on with no key, so the shipped state of a fresh install is "every flush refuses". Getting out of it meant knowing that the fix lives in another module, that the key type is encryption, that the size is 256 bits and that the value has to be exactly 32 bytes - four facts an operator setting up a backup has no reason to know. This turns all four into one button.

The value is stored in configuration, which means it is exported with the site's configuration and captured into the store it protects. A site that loses its config export loses the key and with it every frame ever written. A deployment that keeps secrets out of config points the key entity at the file or env provider instead, which is the key module's own job and needs no help from here.

Summary

Methods
Properties
Constants
__construct
available
create
No public properties found
DEFAULT_ID
No protected methods found
No protected properties found
No protected constants found
freeId
entities
ATTEMPTS

Constant

DEFAULT_ID

DEFAULT_ID = 'strata_backup'

Machine name a generated key takes when nothing else is asked for.

ATTEMPTS

ATTEMPTS = 100

Most ids tried before giving up on finding a free one.

Properties

$entities

$entities : \Drupal\Core\Entity\EntityTypeManagerInterface

Type

EntityTypeManagerInterface

Methods

__construct()

__construct(\Drupal\Core\Entity\EntityTypeManagerInterface  $entities) : mixed

Constructs the maker.

Parameters

\Drupal\Core\Entity\EntityTypeManagerInterface $entities

Where the key entity is saved. Cheap to take: nothing here assembles a store.

Returns

mixed —

available()

available() : bool

Whether a key can be created on this site at all.

The key module is a hard dependency, so this is FALSE only where the module list and the container disagree - which is the state the 1.0.2 install bug left sites in.

Returns

bool —

TRUE when the key entity type is installed.

create()

create(string  $wanted = \self::DEFAULT_ID) : string

Creates a key holding fresh random bytes.

Parameters

string $wanted

The machine name to prefer. A suffix is added when it is taken, so calling this twice makes two keys rather than overwriting the first - the value inside an existing key is the only copy of it, and replacing one would make everything it sealed unreadable.

Throws

\RuntimeException

When the key entity type is not installed, or every candidate id is taken.

Returns

string —

The machine name the key was actually saved under.

freeId()

freeId(string  $wanted) : string

The first machine name in the series that no key holds.

Parameters

string $wanted

The preferred name.

Throws

\RuntimeException

When every candidate is taken.

Returns

string —

A free machine name.