Skip to content

Commit 4ed6622

Browse files
authored
Merge pull request #11 from newrelic-experimental/tlsconnectoptions
server certificate verification options
2 parents fc03f2d + 4026081 commit 4ed6622

File tree

5 files changed

+33
-18
lines changed

5 files changed

+33
-18
lines changed

copy-paste-example.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readme.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,22 @@ The targets to test are provided by calling the function getTargets(). You can p
2626
"555.666.777.888",
2727
]
2828
},
29+
{
30+
"domain":"self-signed-cert.com",
31+
"allowUnauthorized": true
32+
},
2933
{...}
3034
]
3135
```
3236

33-
* `name`: Optional
34-
* `domain`: Required
35-
* `hosts`: Optional
36-
* `timeout`: Optional
37+
* `name`: Optional - Friendly Name of the site being tested
38+
* `domain`: Required - The domain name to test
39+
* `hosts`: Optional - An array of IP addresses to test, skipping DNS
40+
* `timeout`: Optional - miiliseconds timeout (default 5000)
41+
* `allowUnauthorized`: Optional - if `true` then cert will not be validated against CA (useful for self-signed)
3742

3843

39-
## Getting started (terraform)
44+
## Getting started (Terraform)
4045

4146
1. Checkout the repo
4247
2. Copy `runtf.sh.sample` to `runtf.sh` and add your API keys
@@ -49,11 +54,13 @@ The targets to test are provided by calling the function getTargets(). You can p
4954
* Target Data Sources - `./terraform/main.tf`
5055
* Thresholds and timeouts - `./terraform/modules/sslchecker/modules/sslminion/src/synthetic.js` (built)
5156

57+
The boilerplate example references [static_small.js](./terraform/targetdata/static_small.js) from `main.tf` which is a small java script funciton that defines the SSL (TLS) domains to test. There are some other exmaples here of how to specify these. You can event query an API to drive the configuration as demonstrated in [api-driven.js](./terraform/targetdata/api-driven.js).
58+
5259
### Dashboard
5360

5461
The application comes with a built in dashboard. Set up alerts as you require.
5562

5663
![dashboard-example](dashboard.png)
5764

5865
## Getting started (Copy and Paste)
59-
Simply copy and paste the [`copy-paste-example.js`](./copy-paste-example.js) into a Scripted API synthetic monitor. You will need to provide an ingest API key (prefereably via a secure credential) and define your getTargets() function.
66+
Simply copy and paste the [`copy-paste-example.js`](./copy-paste-example.js) into a Scripted API synthetic monitor. You will need to provide an ingest API key (prefereably via a secure credential) and define your getTargets() function. Refer to the [example scripts](./terraform/targetdata/) for configuration ideas.

terraform/modules/sslchecker/modules/sslminion/package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/modules/sslchecker/modules/sslminion/src/base_script.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
const tls = require('tls');
55

66
const starttime= Date.now()
7-
console.log(`Start time:`,starttime)
8-
7+
let socketErrorTriggered=false;
98
const getSSLExpiration = function(connectionConfig,success,fail) {
109
return new Promise((resolve, reject) => {
11-
const sd = tls.connect(connectionConfig.port,connectionConfig.host, {
12-
servername: connectionConfig.domain,
13-
}, () => {
10+
const sd = tls.connect(connectionConfig.port,connectionConfig.host, {servername: connectionConfig.domain, rejectUnauthorized: connectionConfig.rejectUnauthorized,}, () => {
1411
const certDetails = sd.getPeerCertificate(true);
1512

1613
sd.end();
@@ -35,8 +32,8 @@ const getSSLExpiration = function(connectionConfig,success,fail) {
3532
reject(fail(`Error timeout to ${connectionConfig.host}:${connectionConfig.domain}`));
3633
});
3734
sd.on('error', function (err) {
38-
console.log("Socket error",err);
39-
reject(fail(`Error with connect to ${connectionConfig.host}:${connectionConfig.domain}`));
35+
socketErrorTriggered=true;
36+
reject(fail(`Socket error ${connectionConfig.host}:${connectionConfig.domain} ${err.code? '['+err.code+']' : ''}`));
4037
});
4138
})
4239
}
@@ -56,6 +53,7 @@ async function run() {
5653
host: y,
5754
url: `https://${y}`,
5855
timeout: x.timeout ? x.timeout : DEFAULT_TIMEOUT,
56+
allowUnauthorized: x.allowUnauthorized
5957
}))
6058
} else {
6159
return {
@@ -64,6 +62,7 @@ async function run() {
6462
host: x.domain,
6563
url: `https://${x.domain}`,
6664
timeout: x.timeout ? x.timeout : DEFAULT_TIMEOUT,
65+
allowUnauthorized: x.allowUnauthorized
6766
}
6867
}
6968
}));
@@ -81,7 +80,8 @@ async function run() {
8180
host: target.host,
8281
port: 443,
8382
domain: target.domain,
84-
timeout: target.timeout
83+
timeout: target.timeout,
84+
rejectUnauthorized: target.allowUnauthorized === undefined ? true : target.allowUnauthorized === true ? false : true // allow domain's to be self cert: the server certificate is verified against the list of supplied CAs. An 'error' event is emitted if verification fails; err.code contains the OpenSSL error code. Default: false, will be checked). https://nodejs.org/docs/latest/api/tls.html#tlssocketrenegotiateoptions-callback
8585
}
8686
promises.push(getSSLExpiration(connectionConfig,
8787
(certData)=>{
@@ -110,7 +110,7 @@ async function run() {
110110
(error)=>{
111111
target.error=error
112112
target.state="ERROR"
113-
scriptErrors.push(`Target '${target.name}' (${target.url} failed cert info lookup)`)
113+
scriptErrors.push(`Target '${target.name}' failed cert info lookup: ${target.error}`)
114114
}
115115
))
116116
})
@@ -187,14 +187,16 @@ async function run() {
187187
console.log(`Warnings: ${warningErrors.length}`)
188188
console.log(`Critical: ${criticalErrors.length}`)
189189
console.log("-----------------------")
190-
console.log(`End time:`,Date.now())
191190
console.log(`Duration:`,Date.now()-starttime)
192191

193192
let assertMessage=[]
194193
setAttribute("scriptErrors",scriptErrors.length)
195194
if(scriptErrors.length > 0){
196195
setAttribute("scriptErrorMsg",scriptErrors.join('|'))
197196
console.log("Script errors:",JSON.stringify(scriptErrors))
197+
if(socketErrorTriggered) {
198+
console.log("TIP: Some domains caused a socket error. You may need to consider ignoring authorization, e.g. for self signed certs. This can be configured by providing 'allowUnauthorized:true' option for the target.")
199+
}
198200
assertMessage.push("SSL checker script error or some targets are in ERROR state")
199201
}
200202
setAttribute("criticalErrors",criticalErrors.length)

0 commit comments

Comments
 (0)