Last active
October 8, 2022 00:14
-
-
Save compulim/37823cdb6c5345c51dce935b29421896 to your computer and use it in GitHub Desktop.
Generating self-signed certificate with subject alternate name using `selfsigned`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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