-
Notifications
You must be signed in to change notification settings - Fork 0
/
testssl.js
45 lines (42 loc) · 1.33 KB
/
testssl.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
const https = require('https');
async function testSsl(host, ip, port) {
return new Promise((resolve, reject) => {
port = port || 443;
let result = null;
let hostName = port === 443 ? host : `${host}:${port}`;
https
.get(
`https://${ip}:${port}`,
{
headers: {
host: hostName,
},
servername: hostName,
},
(resp) => {
result = {
suc: true,
error: null,
errMsg: resp.statusMessage,
status: resp.statusCode,
};
resolve(result);
}
)
.on('error', (error) => {
result = {
suc: !!error?.response?.status,
error: error.code,
errMsg: error?.response?.status ? null : error + '',
status: error?.response?.status,
};
resolve(result);
})
.end();
});
}
// uncomment to run the simple test
//testSsl('incomplete-chain.badssl.com', '104.154.89.105').then((x) => console.log(x));
module.exports = {
testSsl: testSsl,
};