opensslssl-certificatecertutil

SEC_ERROR_ADDING_CERT: Error adding certificate to database


While trying to configure a valid SSL certificate for localhost on Ubuntu, I got the following error:

certutil -d sql:$HOME/.pki/nssdb -A -t "CT,c,c" -n "localhost" -i localhost.crt

certutil: could not add certificate to token or database: SEC_ERROR_ADDING_CERT: Error adding certificate to database.

This certificate will be used in Nginx configuration, my goal is to avoid any errors in Google Chrome (ERR_SSL_PROTOCOL_ERROR) as the certificate authority is untrusted.


Solution

  • This error occurred because the certificate was already registered using certutil previously.

    Solution

    1. Delete the existing record

      certutil -n localhost -D localhost.crt

    2. Then, create a new record

      certutil -d sql:$HOME/.pki/nssdb -A -t "CT,c,c" -n "localhost" -i localhost.crt