refactor: Refine generate certificate

This commit is contained in:
avwo
2017-03-12 21:40:24 +08:00
parent cd7f1d0b1e
commit 96b6365cf7
+9 -2
View File
@@ -40,13 +40,13 @@ function getMacAddress() {
}
function createCertificate(hostname) {
var cert = customPairs[hostname]
var cert = customPairs[hostname]
|| wildcardPairs[hostname.slice(hostname.indexOf('.'))]
|| cachePairs[hostname];
if (cert) {
return cert;
}
cert = createCert(pki.setRsaPublicKey(ROOT_KEY.n, ROOT_KEY.e),
crypto.createHash('sha1')
.update(hostname, 'binary')
@@ -58,6 +58,13 @@ crypto.createHash('sha1')
}]);
cert.setIssuer(ROOT_CRT.subject.attributes);
cert.setExtensions([ {
name: 'subjectAltName',
altNames: [{
type: 2,
value: hostname
}]
} ]);
cert.sign(ROOT_KEY, forge.md.sha256.create());
cert = cachePairs[hostname] = {
key: pki.privateKeyToPem(ROOT_KEY),