refactor: code

This commit is contained in:
avwo
2017-12-08 23:04:20 +08:00
parent 2d2f263ed1
commit 43ea2a5968
+7 -6
View File
@@ -20,6 +20,8 @@ var customCertDir = config.certDir;
var customPairs = {};
var wildcardPairs = {};
var cachePairs = {};
var LEGAL_CHARS_RE = /[a-z\d-]/i;
var ROOT_KEY, ROOT_CRT;
if (config.ATS) {
@@ -60,17 +62,16 @@ function getCommonName(crt) {
function createCertificate(hostname) {
var wildHost = hostname.substring(hostname.indexOf('.'));
var cert = customPairs[hostname]
|| wildcardPairs[hostname.slice(hostname.indexOf('.'))]
|| wildcardPairs[wildHost]
|| cachePairs[hostname];
if (cert) {
return cert;
}
cert = createCert(pki.setRsaPublicKey(ROOT_KEY.n, ROOT_KEY.e),
crypto.createHash('sha1')
.update(hostname, 'binary')
.digest('hex'));
var serialNumber = crypto.createHash('sha1')
.update(hostname, 'binary').digest('hex');
cert = createCert(pki.setRsaPublicKey(ROOT_KEY.n, ROOT_KEY.e), serialNumber);
cert.setSubject([{
name: 'commonName',