Skip to main content

PkiKeyring

@webda/core


Class: PkiKeyring

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

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:175

Create a new PkiKeyring instance

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:152

Key id used to encrypt


privateKeys​

protected privateKeys: Map<string, KeyObject>

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

Private keys


privateKeysDir​

readonly privateKeysDir: string

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

Absolute directory of the private keys


publicKeys​

protected publicKeys: Map<string, KeyObject>

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

Public keys


publicKeysDir​

readonly publicKeysDir: string

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

Absolute directory of the public keys

Methods​

findPrivateKey()​

protected findPrivateKey(kid): object

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

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:297

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:240

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:284

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:220

List the kids having a public key

Returns​

string[]

the kids


listPrivateKids()​

listPrivateKids(): string[]

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

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:193

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