class SigningKeyRepository

Constants

protected LOCK_SECONDS

protected LOCK_WAIT_SECONDS

Methods

__construct(Factory $cache, Repository $config, KeyGenerator $generator, ServerFactory $servers)

Create the signing-key store and its mutation dependencies.

all()

Get the stored keys, newest first, from the writer.

array
serverKeys()

Project keys for server settings without decrypting retired private keys.

SigningKey|null
create(int $length = KeyGenerator::DEFAULT_LENGTH)

Provision the first key without replacing an existing key set.

rotate(int $length = KeyGenerator::DEFAULT_LENGTH)

Publish a replacement, retaining any key already waiting to activate.

void
rotateDueKeys(int $length = KeyGenerator::DEFAULT_LENGTH)

Rotate an overdue signing key and prune keys whose retention has passed.

import(string $privateKey)

Queue a supplied private key after every key already published for activation.

importFiles(DateTimeInterface|null $retainUntil = null)

Import file keys while retaining every token already signed by them.

bool
revoke(string $keyId, int $length = KeyGenerator::DEFAULT_LENGTH)

Remove a compromised key, replacing it immediately if it is signing.

static int
lifetimeInSeconds(DateInterval $lifetime)

Convert a lifetime to a conservative retention bound, including long months and leap years.

void
prune()

Prune replaced keys after their retention deadlines.

void
pruneKeys()

Recompute retention under the set lock and compare before deleting.

SigningKey|null
waitingKey()

Get the newest private key already waiting to activate.

CarbonInterface
nextActivation()

Leave a full publication interval after the newest waiting key.

SigningKey|null
activeKey(Collection $keys)

Get the newest active private key from a newest-first key set.

SigningKey|null
findByKeyId(Collection $keys, string $keyId)

Find a stored key by its public JWK thumbprint.

storeKey(array $material, CarbonInterface $activatesAt, CarbonInterface|null $retainUntil = null, int $maxTokenLifetime = 0)

Store key material and fail if an observer cancels the mutation.

void
deleteKey(SigningKey $key)

Delete a key through its model so key-set observers run atomically.

string
keySetName()

Name the key set whose mutations share a lock.

void
ensureNoTransaction()

Prevent a caller's transaction from outliving the key-set lock.

mixed
mutate(Closure $callback)

Serialize a key-set mutation and commit it before releasing the lock.

Details

at line 35
__construct(Factory $cache, Repository $config, KeyGenerator $generator, ServerFactory $servers)

Create the signing-key store and its mutation dependencies.

Parameters

Factory $cache
Repository $config
KeyGenerator $generator
ServerFactory $servers

at line 48
Collection all()

Get the stored keys, newest first, from the writer.

Return Value

Collection

at line 59
array serverKeys()

Project keys for server settings without decrypting retired private keys.

Return Value

array

at line 88
SigningKey|null create(int $length = KeyGenerator::DEFAULT_LENGTH)

Provision the first key without replacing an existing key set.

Parameters

int $length

Return Value

SigningKey|null

at line 110
SigningKey rotate(int $length = KeyGenerator::DEFAULT_LENGTH)

Publish a replacement, retaining any key already waiting to activate.

Parameters

int $length

Return Value

SigningKey

at line 139
void rotateDueKeys(int $length = KeyGenerator::DEFAULT_LENGTH)

Rotate an overdue signing key and prune keys whose retention has passed.

Parameters

int $length

Return Value

void

at line 155
SigningKey import(string $privateKey)

Queue a supplied private key after every key already published for activation.

Parameters

string $privateKey

Return Value

SigningKey

at line 179
Collection importFiles(DateTimeInterface|null $retainUntil = null)

Import file keys while retaining every token already signed by them.

Parameters

DateTimeInterface|null $retainUntil

Return Value

Collection

at line 245
bool revoke(string $keyId, int $length = KeyGenerator::DEFAULT_LENGTH)

Remove a compromised key, replacing it immediately if it is signing.

Parameters

string $keyId
int $length

Return Value

bool

at line 295
static int lifetimeInSeconds(DateInterval $lifetime)

internal  shared by key imports and signing-time retention
 

Convert a lifetime to a conservative retention bound, including long months and leap years.

Parameters

DateInterval $lifetime

Return Value

int

at line 306
void prune()

Prune replaced keys after their retention deadlines.

Return Value

void

at line 314
protected void pruneKeys()

Recompute retention under the set lock and compare before deleting.

Return Value

void

at line 350
protected SigningKey|null waitingKey()

Get the newest private key already waiting to activate.

Return Value

SigningKey|null

at line 359
protected CarbonInterface nextActivation()

Leave a full publication interval after the newest waiting key.

Return Value

CarbonInterface

at line 371
protected SigningKey|null activeKey(Collection $keys)

Get the newest active private key from a newest-first key set.

Parameters

Collection $keys

Return Value

SigningKey|null

at line 383
protected SigningKey|null findByKeyId(Collection $keys, string $keyId)

Find a stored key by its public JWK thumbprint.

Parameters

Collection $keys
string $keyId

Return Value

SigningKey|null

at line 393
protected SigningKey storeKey(array $material, CarbonInterface $activatesAt, CarbonInterface|null $retainUntil = null, int $maxTokenLifetime = 0)

Store key material and fail if an observer cancels the mutation.

Parameters

array $material
CarbonInterface $activatesAt
CarbonInterface|null $retainUntil
int $maxTokenLifetime

Return Value

SigningKey

at line 410
protected void deleteKey(SigningKey $key)

Delete a key through its model so key-set observers run atomically.

Parameters

SigningKey $key

Return Value

void

at line 420
protected string keySetName()

Name the key set whose mutations share a lock.

Return Value

string

at line 428
protected void ensureNoTransaction()

Prevent a caller's transaction from outliving the key-set lock.

Return Value

void

at line 442
protected mixed mutate(Closure $callback)

Serialize a key-set mutation and commit it before releasing the lock.

Parameters

Closure $callback

Return Value

mixed