keboola/key-generator

Common key/certificate generators for Keboola services

Maintainers

Package info

github.com/keboola/php-key-generator

pkg:composer/keboola/key-generator

Transparency log

Statistics

Installs: 17 084

Dependents: 4

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2025-04-25 14:26 UTC

README

Generates RSA key pairs for Keboola services — currently used for Snowflake key-pair authentication of Connection workspaces (see keboola/staging-provider).

Requires ext-openssl.

Installation

composer require keboola/key-generator

Usage

use Keboola\KeyGenerator\PemKeyCertificateGenerator;

$generator = new PemKeyCertificateGenerator();

// Unencrypted private key
$pair = $generator->createPemKeyCertificate(null);

// Private key encrypted with a passphrase
$pair = $generator->createPemKeyCertificate('my-passphrase');

$pair->privateKey; // PEM-encoded 2048-bit RSA private key
$pair->publicKey;  // PEM-encoded public key

createPemKeyCertificate() returns a PemKeyCertificatePair with exactly two values — despite the name, no certificate is returned. Internally it also builds a certificate signing request from CertificateSigningRequest::createDefault() (hard-coded Keboola company details) and self-signs it, but that certificate is currently discarded. Exposing it would require changing the return type and making the CSR subject caller-supplied.

The generated key pair is not persisted anywhere; storing it is the caller's responsibility. PemKeyCertificatePair::$privateKey and the $password argument are marked #[SensitiveParameter] so they are redacted from stack traces.

Failures at any OpenSSL step throw a RuntimeException.

Development

Run everything through the library's Docker Compose service:

docker compose run --rm dev-key-generator composer install
docker compose run --rm dev-key-generator composer ci   # validate + phpcs + phpstan + tests

No environment variables are required.

License

MIT licensed, see LICENSE file.