Reformat code
This commit is contained in:
parent
aa90e66b7c
commit
88e3470f1f
1 changed files with 9 additions and 11 deletions
18
src/sni.js
18
src/sni.js
|
|
@ -1,8 +1,8 @@
|
|||
import tls from "tls";
|
||||
import { Client, writeKeyToFile } from "./certnode/lib/index.js";
|
||||
import {Client, writeKeyToFile} from "./certnode/lib/index.js";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { md5, ensureDir } from "./util.js";
|
||||
import {md5, ensureDir} from "./util.js";
|
||||
import AsyncLock from 'async-lock';
|
||||
|
||||
const lock = new AsyncLock();
|
||||
|
|
@ -55,11 +55,10 @@ async function buildCache(host) {
|
|||
key,
|
||||
expire
|
||||
};
|
||||
}
|
||||
catch (error) {
|
||||
} catch (error) {
|
||||
// only one process can generate certificate at a time
|
||||
return await lock.acquire('cert', async () => {
|
||||
const { certificate, privateKeyData } = await client.generateCertificate(host);
|
||||
const {certificate, privateKeyData} = await client.generateCertificate(host);
|
||||
await fs.promises.writeFile(certP, certificate);
|
||||
await writeKeyToFile(keyP, privateKeyData, '');
|
||||
const expire = (Date.now() + 45 * 86400 * 1000);
|
||||
|
|
@ -100,22 +99,21 @@ async function SniListener(servername, ctx) {
|
|||
// Generate fresh account keys for Let's Encrypt
|
||||
try {
|
||||
ctx(null, tls.createSecureContext(await getKeyCert(servername)));
|
||||
}
|
||||
catch (error) {
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
ctx(error, undefined);
|
||||
}
|
||||
}
|
||||
|
||||
const SniPrepare = async () => {
|
||||
await ensureDir(certsDir);
|
||||
await ensureDir(accountDir);
|
||||
if (fs.existsSync(path.join(accountDir, 'privateKey.pem')) &&
|
||||
fs.existsSync(path.join(accountDir, 'publicKey.pem'))) {
|
||||
await client.importAccountKeyPair(accountDir, '');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
await client.generateAccountKeyPair();
|
||||
await client.exportAccountKeyPair(accountDir, '');
|
||||
}
|
||||
};
|
||||
export { SniListener, SniPrepare, client };
|
||||
export {SniListener, SniPrepare, client};
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue