verify_self_signed_cert

This script will verify a private key key.pem and a self-signed certificate cert.pem.

The following parameter is optional:

d

the directory ($PWD if not given) containing the key and certificate

On macOS, the certificate will be verified in the "login" keychain also.

Copy the script into your Node.js project and add it as a custom script to your package.json file:

package.json
{
...
  "scripts": {
    "cert:verify": "scripts/verify_self_signed_cert.sh -d certs"
  }
}
$ node --run cert:verify

Usage

$ scripts/cert/verify_self_signed_cert.sh
$ scripts/cert/verify_self_signed_cert.sh -d ~/.local/secrets/certs/localhost
keychain: "/Users/example/Library/Keychains/login.keychain-db"
...
    "labl"<blob>="localhost"
...
/Users/example/.local/secrets/certs/localhost/cert.pem
Certificate:
...
        Issuer: CN=localhost
        Validity
            Not Before: Feb 28 11:54:32 2024 GMT
            Not After : Mar 29 11:54:32 2024 GMT
        Subject: CN=localhost
...
            X509v3 Subject Alternative Name:
                DNS:localhost
...

Prerequisites