-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsecure.js
34 lines (30 loc) · 904 Bytes
/
secure.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module.exports = function secure(app) {
if (secured[app.domain]) return secured[app.domain]
try {
child_process.execSync(`security delete-certificate -c ${app.domain}`, { silent: true })
} catch (err) {
}
const s = createCSR({ commonName: app.domain })
.then(sig =>
createCertificate({
clientKey: sig.clientKey,
csr: sig.csr,
days: 30,
selfSigned: true
})
).then(keys => {
const tmp = `${process.cwd()}/.${app.domain}.crt.tmp`
fs.writeFileSync(tmp, keys.certificate)
child_process.execSync(`security add-trusted-cert -d -r trustRoot -k "/Library/Keychains/System.keychain" ${tmp}`)
fs.unlinkSync(tmp)
APPS[app.domain] = {
app,
ctx: tls.createSecureContext({
cert: keys.certificate,
key: keys.serviceKey
})
}
})
secured[app.domain] = s
return s
}