delete_self_signed_cert

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

The following parameters are optional:

c

the common name (localhost if not given) of the certificate

d

the directory ($PWD if not given) containing the key and certificate; the directory will be also deleted if empty and not $PWD

On macOS, the certificate will be removed from the "login" keychain also.

Chrome and Safari need no further configuration.

For Firefox, the old certificate has to be deleted manually.

Docker needs to be restarted.

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

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

Usage

$ scripts/cert/delete_self_signed_cert.sh
Removing 'localhost' certificate from keychain /Users/example/Library/Keychains/login.keychain-db ...

$ scripts/cert/delete_self_signed_cert.sh -d ~/.local/secrets/certs/localhost
Removing 'localhost' certificate from keychain /Users/example/Library/Keychains/login.keychain-db ...

$ scripts/cert/delete_self_signed_cert.sh -d ~/.local/secrets/certs/https.internal -c https.internal
Removing 'https.internal' certificate from keychain /Users/example/Library/Keychains/login.keychain-db ...

Firefox

You need to delete the certificate via Firefox > Preferences > Privacy & Security > Certificates; click "View Certificates…​":

self signed firefox delete 1

Click on the "Servers" tab:

self signed firefox delete 2

Select the certificate and click "Delete…​".