mirror of
https://github.com/avwo/whistle.git
synced 2026-10-28 22:59:50 +08:00
feat: Compatible with node v9
This commit is contained in:
+18
-7
@@ -142,10 +142,12 @@ function createRootCA() {
|
||||
if (ROOT_KEY && ROOT_CRT) {
|
||||
return;
|
||||
}
|
||||
|
||||
var rootKey, rootCrt;
|
||||
try {
|
||||
ROOT_KEY = fs.readFileSync(ROOT_KEY_FILE);
|
||||
ROOT_CRT = fs.readFileSync(ROOT_CRT_FILE);
|
||||
rootKey = ROOT_KEY;
|
||||
rootCrt = ROOT_CRT;
|
||||
} catch (e) {
|
||||
ROOT_KEY = ROOT_CRT = null;
|
||||
}
|
||||
@@ -157,14 +159,23 @@ function createRootCA() {
|
||||
var cert = createCACert();
|
||||
ROOT_CRT = cert.cert;
|
||||
ROOT_KEY = cert.key;
|
||||
fs.writeFileSync(ROOT_KEY_FILE, pki.privateKeyToPem(ROOT_KEY).toString());
|
||||
fs.writeFileSync(ROOT_CRT_FILE, pki.certificateToPem(ROOT_CRT).toString());
|
||||
rootKey = pki.privateKeyToPem(ROOT_KEY);
|
||||
rootCrt = pki.certificateToPem(ROOT_CRT);
|
||||
fs.writeFileSync(ROOT_KEY_FILE, rootKey.toString());
|
||||
fs.writeFileSync(ROOT_CRT_FILE, rootCrt.toString());
|
||||
}
|
||||
|
||||
exports.DEFAULT_CERT_CTX = createSecureContext({
|
||||
key: ROOT_KEY,
|
||||
cert: ROOT_CRT
|
||||
});
|
||||
try {
|
||||
exports.DEFAULT_CERT_CTX = createSecureContext({
|
||||
key: ROOT_KEY,
|
||||
cert: ROOT_CRT
|
||||
});
|
||||
} catch (e) {
|
||||
exports.DEFAULT_CERT_CTX = createSecureContext({
|
||||
key: rootKey,
|
||||
cert: rootCrt
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getRandom() {
|
||||
|
||||
Reference in New Issue
Block a user