forked from apkrasny/dev-cert-authority
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaths.js
43 lines (33 loc) · 957 Bytes
/
paths.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
35
36
37
38
39
40
41
42
43
const UserHome = require('user-home');
const Path = require('path');
const Fs = require('fs');
const Paths = {
configDir: Path.join(UserHome, '.dev-cert-authority'),
hostsDir: Path.join(UserHome, '.dev-cert-authority', 'hosts'),
};
Paths.caKeyPath = `${Paths.configDir}/rootCA.key`;
Paths.caPemPath = `${Paths.configDir}/rootCA.pem`;
Paths.normalizeHost = function (host) {
return host.replace(/^\*\./, 'wild.');
};
Paths.denormalizeHost = function (host) {
return host.replace(/^wild\./, '*.');
};
Paths.makeCertPaths = function (host) {
host = Paths.normalizeHost(host);
return {
key: `${Paths.hostsDir}/${host}.key`,
csr: `${Paths.hostsDir}/${host}.csr`,
crt: `${Paths.hostsDir}/${host}.crt`,
ext: `${Paths.hostsDir}/${host}.ext`
};
};
Paths.certExists = function (host) {
try {
Fs.statSync(Paths.makeCertPaths(host).key);
return true;
} catch (err) {
return false;
}
};
module.exports = Paths;