Generate self signed (i.e. "snake oil certs") certificates and RSA key pairs.
$ npm install snake-juice --save
- Simple interface for generating self signed certificates.
- Allows specifying either the commonName or a list of subjectAltNames
- Customize the RSA key size (default 2048)
- Customize the signature algorithm (default SHA-256)
- Customize the duration of the certificate (default 10 years)
- TypeScript declarations for simplified usage
import { SnakeJuice } from 'snake-juice';
interface KeyAndCert {
privateKey: string;
publicKey: string;
certificate: string;
fingerprint: string;
}
const keyAndCert = await SnakeJuice.generate('dummy.example.com');
const keyAndCert = await SnakeJuice.generate([
'a.example.com',
'b.example.com',
'c.example.com',
]);
// Warning: This could take a while (>10 seconds) to run
const keyAndCert = await SnakeJuice.generate([
'a.example.com',
'b.example.com',
'c.example.com',
], 4096);
const keyAndCert = await SnakeJuice.generate({
// Too small for real usage but fine for testing
keySizeInBits: 1024,
// Override to SHA1
digestAlgorithm: 'sha1',
// Custom
validity: {
// Override starting effective date
notBefore: new Date('2018-01-01T12:00:00Z')
// Override number of days that cert will be valid
days: 1000,
},
// Explicit list of subjectAltNames
subjectAltNames: [
{
type: SubjectAltNameType.DNS_NAME,
value: 'a.example.com',
},
{
type: SubjectAltNameType.DNS_NAME,
value: 'b.example.com',
},
{
// Can even specify non-DNS types
type: SubjectAltNameType.IP_ADDRESS,
value: '10.20.30.40',
},
],
});
To build the module run:
$ make
Then, to run the tests run:
$ make test
ISC. See the file LICENSE.
The real lifting is done by node-forge. Also, looking through the code for selfsigned helped out a lot as well.