delete_self_signed_cert

This script will delete the private key key.pem and the self-signed certificate cert.pem from the given directory ($PWD if not given).

If the given directory is not $PWD and is empty after the removal it will be removed as well.

The optional second parameter is the common name (localhost if not given) of the certificate to be removed.

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 certs"
  }
}
$ npm 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 ~/.local/secrets/certs/localhost
Removing 'localhost' certificate from keychain /Users/example/Library/Keychains/login.keychain-db ...
$ scripts/cert/delete_self_signed_cert.sh ~/.local/secrets/certs/https.internal 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…​".