Skip to main content

PkiKeyring

@webda/core


Class: PkiKeyring

Defined in: packages/core/src/services/pki.encrypter.ts:139

Public and private keys of the pki encrypter

The keys are loaded lazily and cached by kid.

Constructors​

Constructor​

new PkiKeyring(options?, appPath?): PkiKeyring

Defined in: packages/core/src/services/pki.encrypter.ts:159

Parameters​

options?​

PkiEncrypterOptions = {}

the encrypter options

appPath?​

string = ...

the application path, relative directories resolve against it

Returns​

PkiKeyring

Properties​

activeKey?​

readonly optional activeKey?: string

Defined in: packages/core/src/services/pki.encrypter.ts:143

Key id used to encrypt


privateKeys​

protected privateKeys: Map<string, KeyObject>

Defined in: packages/core/src/services/pki.encrypter.ts:153


privateKeysDir​

readonly privateKeysDir: string

Defined in: packages/core/src/services/pki.encrypter.ts:151

Absolute directory of the private keys


publicKeys​

protected publicKeys: Map<string, KeyObject>

Defined in: packages/core/src/services/pki.encrypter.ts:152


publicKeysDir​

readonly publicKeysDir: string

Defined in: packages/core/src/services/pki.encrypter.ts:147

Absolute directory of the public keys

Methods​

findPrivateKey()​

protected findPrivateKey(kid): object

Defined in: packages/core/src/services/pki.encrypter.ts:250

Find the source of a private key

Parameters​

kid​

string

the key id

Returns​

object

the environment variable or file name, undefined if not found

env?​

optional env?: string

file?​

optional file?: string


getPrivateKey()​

getPrivateKey(kid): KeyObject

Defined in: packages/core/src/services/pki.encrypter.ts:281

Get the private key of a kid

From WEBDA_PKI_PRIVATE_KEY_<KID>, then <privateKeys>/<kid>.pem or <privateKeys>/<kid>. The passphrase, if any, is read from WEBDA_PKI_PASSPHRASE.

Parameters​

kid​

string

the key id

Returns​

KeyObject

the private key


getPublicKey()​

getPublicKey(kid): KeyObject

Defined in: packages/core/src/services/pki.encrypter.ts:224

Get the public key of a kid

From <publicKeys>/<kid>.pub.pem, or derived from its private key when it is available

Parameters​

kid​

string

the key id

Returns​

KeyObject

the public key


hasPrivateKey()​

hasPrivateKey(kid): boolean

Defined in: packages/core/src/services/pki.encrypter.ts:268

Check if the private key of a kid is available

Parameters​

kid​

string

the key id

Returns​

boolean

true if available


listKids()​

listKids(): string[]

Defined in: packages/core/src/services/pki.encrypter.ts:204

List the kids having a public key

Returns​

string[]

the kids


listPrivateKids()​

listPrivateKids(): string[]

Defined in: packages/core/src/services/pki.encrypter.ts:212

List the kids having a private key file

Returns​

string[]

the kids


listDir()​

protected static listDir(dir, suffix, optionalSuffix): string[]

Defined in: packages/core/src/services/pki.encrypter.ts:177

List the kids of a directory

Parameters​

dir​

string

the directory

suffix​

string

the file suffix

optionalSuffix​

boolean

also accept files without the suffix

Returns​

string[]

the sorted kids