-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
71 lines (61 loc) · 2.27 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const certificate = require('./lib/certificate');
const api = require('./lib/api');
const argv = require('minimist')(process.argv.slice(2));
const usage = function() {
// eslint-disable-next-line no-console
console.log('Usage: node index.js [--urlsfrom file] [url]\n' +
'\t--help This message\n' +
'\t--urlsfrom filename File to read newline separated urls\n' +
'\t--cafile filename Use separate CA file to confirm authority\n' +
'\t--date date Specify the date to check against for ' +
'validity\n' +
'\t--days number If this many days away from expiration, ' +
'warn, default 30\n' +
'\t--json Return info as JSON\n' +
'\t[url] Check this single URL\n\n' +
' Checks each the SSL/TLS certificate for a specified URL\n' +
' or URLs from a file (each new-line separated)\n' +
' The checks determine if the certificate is considered valid\n' +
' Including if the date is considered valid\n' +
' By default, uses the system hosts CA resources but you can\n' +
' specify a custom CA file to determine if the authority of the\n' +
' returned certificates are trusted\n'
);
return;
};
var daysToWarn = 30;
if (argv.days) {
daysToWarn = parseInt(argv.days);
}
var dateToCheck = new Date();
if (argv.date) {
dateToCheck = new Date(argv.date);
}
if (argv.help) {
usage();
return;
}
var urlList = [];
if (argv.urlsfrom) {
urlList = require('fs').readFileSync(argv.urlsfrom).toString().split('\n');
}
urlList.push.apply(urlList, argv._);
urlList.forEach( (target) => {
if (target.length > 0) {
certificate.getCertificate(target, false, (cert) => {
const certInfo =
api.certificateCheck(cert, daysToWarn, dateToCheck);
if (argv.json) {
// eslint-disable-next-line no-console
console.log(api.jsonCertificateCheck(certInfo));
} else {
api.logCertificateCheck(certInfo);
}
});
}
});
exports.checkCertificateAtURL = (target, cb) => {
certificate.getCertificate(target, false, (cert) => {
cb(api.certificateCheck(cert, daysToWarn, dateToCheck));
});
};