-
Notifications
You must be signed in to change notification settings - Fork 1
/
tls-check.js
61 lines (49 loc) · 1.71 KB
/
tls-check.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
#!/usr/bin/env node
/*
* Copyright (c) 2020 by Jonas Friedmann. Please see the
* LICENSE file for more information. All Rights Reserved.
*/
var cmdr = require('commander'),
helpers = require('./lib/helper'),
openssl = require('openssl-cert-tools');
/* Logic */
// Setup sub command options
cmdr
.option('-H, --hostname <host[:port]>', 'use certificate from remote hostname')
.parse(process.argv);
// Declare variables
var haystack;
// If "--hostname" is set
if (cmdr.hostname) {
var socketName = cmdr.hostname,
socketArray = socketName.split(':');
// Extract hostname from socketArray
var hostName = socketArray[0];
// If socketArray > 1 then it contains a port
if (socketArray.length > 1){
var hostPort = socketArray[1];
} else {
var hostPort = '443';
}
openssl.getCertificateChain(hostName, hostPort, function(err, crt){
if(err){
helpers.die('Error: received the following response from "getCertificateChain()":\n\n' + err);
}
helpers.resolveCertificateChain(crt[0], function(repairResponse){
crt.splice(0, 1);
if(crt.join('\n').trim() == repairResponse.trim()){
helpers.success('Intermediate chain "' + hostName + ':' + hostPort + '" seems to be complete/correct');
helpers.quit(0);
} else {
helpers.error('Intermediate chain for "' + hostName + ':' + hostPort + '" seems to be incomplete');
console.log(' For detailed information, please check using SSLlabs: \n');
console.log(' https://www.ssllabs.com/ssltest/analyze.html?d=' + hostName + ':' + hostPort + '&latest');
helpers.quit(1);
}
});
});
// otherwise check clipboard...
} else {
helpers.error('No option passed');
cmdr.help();
}