alanmburr / self-signed-tls-generator
Quick & dirty library to generate your own TLS certificates from your CA.
Requires
- margusk/openssl-wrapper: dev-master
- ramsey/uuid: 5.x-dev
Requires (Dev)
- phpunit/phpunit: ^11
README
This library depends on a dev package. You may have to set your "minimim-stability" to "dev" in composer.json.
-
Install and update Composer dependencies…
composer install
thencomposer update
-
Use…
- First, create a DistinguishedName class…
$dn = new DistinguishedName("US", "Virginia", "Richmond", "org", false, "mynewawesometlsdomain.local", false);
-
Create a new CaInformation class…
-
Inputs:
-
Full file path to the CA (the certificate must be in PEM format)
-
Full file path to the CA key
-
Password for the CA key (in plaintext, only)
-
-
$ca = new CaInformation(__DIR__."/ca.crt", __DIR__."/ca.key", "123abc");
-
Create a new SelfSignedTlsGenerator class…
-
Inputs:
-
DistinguishedName (required)
-
OpenSSL Configuration (optional)
- Leave null or pass in null to use the default config.
-
Per-domain OpenSSL Configuration (optional)
- If left blank, the class will generate a UUID (gen 5) from the Common Name portion of the Distinguished Name.
-
Vendor OpenSSL Config Filename (optional)
- Defaults to
VendorConfig.cnf
. Pass in a full path if you have a custom config.
- Defaults to
-
-
$tlsgen = new SelfSignedTlsGenerator($dn);
-
Run the generateFromDN function of the SelfSignedTlsGenerator class…
-
Inputs:
-
CaInformation (required)
-
Private Key bits (defaults to 2048)
-
Days valid (defaults to 3650 (10 years), capped at 10 years)
- Capped at 10y because some browsers reject certificates that are valid for more than a decade. I haven't encountered this, and it seems like neither have other people, but it's a theoretical limitation to be aware of.
-
-
Returns:
-
An array of strings:
-
The Private Key for the new certificate
-
The Certificate contents.
-
-
-
$crt = $tlsgen->generateFromDN($ca); print_r($crt);