node-red-contrib-certificate-grabber
A Node-RED node to capture certificates from TLS/SSL connections
Install
Run the following npm command in your Node-RED user directory (typically ~/.node-red):
npm install node-red-contrib-certificate-grabber
Support my Node-RED developments
Please buy my wife a coffee to keep her happy, while I am busy developing Node-RED stuff for you ...

Node usage
This node can be useful in troubleshooting TLS/SSL issues. For example if you are not sure whether the certificate of your FTPS server is expired, so you simply want to have a look at it.
Example flow
The following example flow shows how to capture the certificate being used to secure your Node-RED installation (in case you have setup https):

[{"id":"a4e22d4eae3350e1","type":"debug","z":"fbee74db83781e91","name":"Certificate info","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":760,"y":320,"wires":[]},{"id":"56706c9888b2a2b2","type":"inject","z":"fbee74db83781e91","name":"Inject host & port","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"host\":\"localhost\",\"port\":1880}","payloadType":"json","x":340,"y":320,"wires":[["fc71b92b91dae266"]]},{"id":"fc71b92b91dae266","type":"certificate-grabber","z":"fbee74db83781e91","name":"","x":550,"y":320,"wires":[["a4e22d4eae3350e1"]]}]
It works like this:
-
Inject a message containing 'localhost' and port 1880.
-
The certificate grabber node wil open a TLS/SSL connection to port 1880 on localhost (where in my case Node-RED is running on https).
-
During the SSL handshake phase, the (Node-RED) server will share its public certificate with this node (that acts as a client).
-
This node will send an output message, containing certificate information in the payload.
Output message
The msg.payload
contains the following information about the certificate:
Moreover the msg.payload
contains some calculated fields for your convenience:
- validFromTimestamp: date until which the certificate is valid as a numeric timestamp.
- validToTimestamp: date from which the certificate is valid as a numeric timestamp.
- daysRemaining: the number of days that the certificate will still be valid.
- daysOverdue: the number of days that the certificate is already invalid
Certificate monitoring
The daysRemaining field could be used for example to monitor how long your Node-RED SSL certificate is still valid:

[{"id":"8303ddce608f147b","type":"inject","z":"fbee74db83781e91","name":"Inject host & port","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"host\":\"localhost\",\"port\":1880}","payloadType":"json","x":280,"y":660,"wires":[["350385c35652f4e0"]]},{"id":"350385c35652f4e0","type":"certificate-grabber","z":"fbee74db83781e91","name":"","timeout":"30","x":490,"y":660,"wires":[["b0898b0e167c4b34"]]},{"id":"b0898b0e167c4b34","type":"switch","z":"fbee74db83781e91","name":"daysRemaining","property":"payload.daysRemaining","propertyType":"msg","rules":[{"t":"btwn","v":"1","vt":"num","v2":"5","v2t":"num"},{"t":"lte","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":700,"y":660,"wires":[["6ed1024f399f7030"],["d4fba32162b7af7e"]],"outputLabels":["going to expire","expired"]},{"id":"6ed1024f399f7030","type":"debug","z":"fbee74db83781e91","name":"Warning","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":640,"wires":[]},{"id":"d4fba32162b7af7e","type":"debug","z":"fbee74db83781e91","name":"Problem","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":680,"wires":[]}]
This flow checks the msg.payload.daysRemaining
property: a value between 1 and 5 days will result in a warning, and a value below 0 will result in an error. That way you have a couple of days time to make sure to order a new certificate from your CA.
Store certificate to file
When you want to store the grabbed certificate into a file (as PEM format), that can implemented very easily using a File-Out node:

[{"id":"b328cde6ea2fff22","type":"inject","z":"fbee74db83781e91","name":"Inject host & port","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"host\":\"localhost\",\"port\":1880}","payloadType":"json","x":280,"y":500,"wires":[["3b663b3f52093e65"]]},{"id":"3b663b3f52093e65","type":"certificate-grabber","z":"fbee74db83781e91","name":"","timeout":"30","x":490,"y":500,"wires":[["b1c8e2e2a03a77a5"]]},{"id":"90d78e269b243a56","type":"file","z":"fbee74db83781e91","name":"","filename":"c:\\temp\\grabbedCert.crt","filenameType":"str","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":970,"y":500,"wires":[[]]},{"id":"b1c8e2e2a03a77a5","type":"change","z":"fbee74db83781e91","name":"get PEM certificate","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.pemCertificate","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":500,"wires":[["90d78e269b243a56"]]}]
Node properties
Timeout
After this timeout (in seconds) the node will stop trying to connect to the specified port on the specified host.