How to check your HTTPS/SSL certificate validity
In this guide we will use Skybear.NET to check the HTTPS/SSL certificate expiration date and ensure we get notified if it expires in less than 15 days.
Even though the superpower of Skybear.NET is complex API assertions, it still thrives for such simple use-cases too.👌
Certificate validitity script
The above script (see script in Open Editor) does a request to our domain, asserts an HTTP 200
response status code, and then asserts the actual certificate properties.
The Expire-Date
property is what we care about mostly and the assertion ensures that we have at least 15 days before it expires.
We use the daysAfterNow
filter (see docs) that compares a given date in the future with the present.
The property Subject
is recommended to be checked as well, making sure the certificate has the right Common Name (CK), that represents the website/server protected by the SSL certificate.
When the script runs and notices that the certificate expires in less than 15 days, it will fail with an error similar to below:
This error clarifies that we expected at least 15 days, but we actually only have 14 remaining.
Scheduled runs
Now that we have a script to check our HTTPS/SSL certificate expiration, we can create a scheduled cron trigger to make sure it runs continuously every day and sends us an email when it is close to expiration.
After you create the Skybear.NET script with the above content, navigate to its Settings tab, and configure a Scheduled Cron trigger with the cron expression 0 1 * * *
so that it runs every day at 01:00.