-
Notifications
You must be signed in to change notification settings - Fork 148
NSS Database
To create NSS database without a password:
$ mkdir -p nssdb $ certutil -N -d nssdb --empty-password
To create NSS database with a password:
$ mkdir -p nssdb $ echo Secret.123 > password.internal $ certutil -N -d nssdb -f password.internal
To change NSS database password:
$ certutil -W -d nssdb -f oldpassword.txt [email protected]
See NSS Modules.
To export a certificate in PEM format:
$ certutil -L -d nssdb -n testcert -a > testcert.crt
To export a certificate in DER format:
$ certutil -L -d nssdb -n testcert -r > testcert.crt
$ certutil -L -d nssdb -n testcert -r | dumpasn1
To add a certificate into the internal token:
$ certutil -A -d nssdb -n testcert -i testcert.pem -t "CT,C,C"
To add a certificate into both the internal token and the HSM:
$ certutil -A -d nssdb -h HSM -f password.HSM -n testcert -i testcert.pem -t "CT,C,C"
To add a certificate only to the HSM:
$ certutil -A -d nssdb -h HSM -f password.HSM -P HSM -n testcert -i testcert.pem -t "CT,C,C"
Do NOT execute the following command, it will mess up the database:
$ certutil -A -d nssdb -h HSM -f password.HSM -n HSM:testcert -i testcert.pem -t "CT,C,C"
In FIPS mode, the certificate has to be added separately into internal token and HSM (see bug #1393668):
$ certutil -A -d nssdb -h HSM -f password.HSM -n testcert -i testcert.pem -t "" $ certutil -A -d nssdb -f password.internal -n testcert -i testcert.pem -t "CT,C,C"
Export each certificate in the certificate chain (see Exporting Certificate), then create a PKCS #7 file:
$ openssl crl2pkcs7 -nocrl -certfile ca1.crt -certfile ca2.crt ... -out cert_chain.p7b
Verify with the following command:
$ openssl pkcs7 -print_certs -in cert_chain.p7b
Each certificate in the certificate chain can be imported individually:
$ certutil -A -d nssdb -a -i -n testcert -i testcert.pem -t CT,C,C
Alternatively, the entire certificate chain can be imported as a PKCS #7 file:
$ openssl pkcs7 -print_certs -in /tmp/cert_chain.p7b -out /tmp/cert_chain.pem $ openssl pkcs12 -export -nokeys -in /tmp/cert_chain.pem -out /tmp/cert_chain.p12 -passout file:password.txt $ pk12util -d nssdb -k password.txt -i /tmp/cert_chain.p12 -w password.txt $ certutil -M -d nssdb -n <nickname> -t CT,C,C
To export a single certificate:
$ pk12util -d nssdb -k password.internal -n nickname -o output.p12 -w output.password
To export the all keys and certificates in the database:
$ PKCS12Export -d nssdb -p password.internal -o output.p12 -w output.password
$ pk12util -d nssdb -k password.internal -i input.p12 -w input.password
Export Cert from a PKCS #12 file:
$ openssl pkcs12 -in path.p12 -out newfile.crt.pem -clcerts -nokeys
Export encrypted RSA key from a pkics#12 (.p12) file:
$ openssl pkcs12 -in path.p12 -out newfile.key.pem -nocerts -nodes
Convert encrypted RSA key to unencrypted (pkcs#1):
$ openssl rsa -in newfile.key.pem -out newfile.key.pkcs1
Convert unencrypted RSA private key (pkcs#1) to pkcs#8 key:
$ openssl pkcs8 -topk8 -inform PEM -outform PEM -nocrypt -in newfile.key.pkcs1 -out newfile.key
openssl pkey -in privateKey.key -pubout -outform pem | sha256sum openssl x509 -in certificate.crt -pubkey -noout -outform pem | sha256sum
The output from both commands must match.
To modifying a certificate’s trust attribute in internal token:
$ certutil -M -d nssdb -n testcert -t "CT,C,C"
To modifying a certificate’s trust attribute in HSM:
$ certutil -M -d nssdb -h HSM -f password.HSM -n HSM:testcert -t "CT,C,C"
This command modifies the trust attributes both in internal token and HSM. This command ignores the -f parameter, so the password must be entered manually
To rename a certificate:
-
export the certificate into a file
-
delete the certificate from NSS database
-
reimport the certificate with a new nickname
See also NSS Bug 448738.
To validate a certificate in internal token:
$ certutil -O -d nssdb -n testcert
To validate a certificate in HSM:
$ certutil -O -d nssdb -h HSM -f password.txt -n HSM:testcert
This command deletes a certificate in the internal token:
$ certutil -D -d nssdb -n testcert
If the certificate is also in HSM, the certificate will not be deleted from HSM, but the trust attribute will change to "u,u,u".
This command deletes a certificate in HSM:
$ certutil -D -d nssdb -h HSM -f password.HSM -n HSM:testcert
This command deletes the certificate in HSM. This command ignores the -f parameter, so the password must be entered manually.
In any case, if the certificate has a key in the token, the key will be orphaned.
These commands do not work:
$ certutil -D -d nssdb -P HSM -n testcert $ certutil -D -d nssdb -h HSM -f password.HSM -P HSM -n testcert
To delete a certificate and its key in internal token:
$ certutil -F -d nssdb -f password.internal -n testcert
To delete a key in internal token:
$ certutil -F -d nssdb -f password.internal -k <key ID>
To delete a certificate and its key in HSM:
$ pki -d nssdb --token HSM -C password.HSM client-cert-del HSM:testcert
The certutil command does not work:
$ certutil -F -d nssdb -h HSM -f password.HSM -n HSM:testcert Incorrect password/PIN entered. certutil: could not authenticate to token NSS Certificate DB.: SEC_ERROR_BAD_PASSWORD: The security password entered is incorrect.
To clone an NSS database, export all certificates:
$ certutil -L -d nssdb -h HSM -n testcert -a > testcert.pem
Create the new database with the HSM modules if applicable:
$ mkdir clone $ certutil -N -d nssdb
Then reimport all certificates:
$ certutil -A -d nssdb -h HSM -f password.HSM -n testcert -i testcert.pem -t "CT,C,C"
Generate a key pair with the following command:
$ openssl rand -out noise.bin 2048 $ certutil -G -d nssdb -h internal -f password.internal -z nssdb/noise.bin Generating key. This may take a few moments...
Generate a CSR with the following command:
$ certutil -R \ -d nssdb \ -h internal \ -f password.internal \ -s "UID=testuser,O=EXAMPLE" \ -z noise.bin \ -o testuser.csr.der $ BtoA testuser.csr.der testuser.csr.pem $ echo "-----BEGIN NEW CERTIFICATE REQUEST-----" > testuser.csr $ cat testuser.csr.pem >> testuser.csr $ echo "-----END NEW CERTIFICATE REQUEST-----" >> testuser.csr $ rm testuser.csr.der $ rm testuser.csr.pem
|
Tip
|
To find a page in the Wiki, enter the keywords in search field, press Enter, then click Wikis. |