Skip to content

Instantly share code, notes, and snippets.

@compulim
Last active October 8, 2022 00:14
Show Gist options
  • Save compulim/37823cdb6c5345c51dce935b29421896 to your computer and use it in GitHub Desktop.
Save compulim/37823cdb6c5345c51dce935b29421896 to your computer and use it in GitHub Desktop.
Generating self-signed certificate with subject alternate name using `selfsigned`
import { createServer } from 'https';
import { generate } from 'selfsigned';
const certAttrs = [{ name: 'commonName', value: 'www.compulim.com' }];
const certOptions = {
// Options copied from default values
// https://github.com/jfromaniello/selfsigned/blob/master/index.js#L85
extensions: [
{
name: 'subjectAltName',
altNames: ['abc.compulim.com', 'xyz.compulim.com']
},
{
name: 'basicConstraints',
cA: true
},
{
name: 'keyUsage',
keyCertSign: true,
digitalSignature: true,
nonRepudiation: true,
keyEncipherment: true,
dataEncipherment: true
}
]
};
const { cert, private: key } = generate(certAttrs, certOptions);
createServer({ cert, key }).listen(443);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment