mirror of
https://github.com/avwo/whistle.git
synced 2026-10-26 03:53:03 +08:00
refactor: code
This commit is contained in:
+7
-6
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user