<para>This documentation is still work in progress. Please contribute to the initial review in <ulinkurl="https://bugzilla.mozilla.org/show_bug.cgi?id=836477">Mozilla NSS bug 836477</ulink>
<para>The Certificate Database Tool, <command>certutil</command>, is a command-line utility that can create and modify certificate and key databases. It can specifically list, generate, modify, or delete certificates, create or change the password, generate new public and private key pairs, display the contents of the key database, or delete key pairs within the key database.</para>
<para>Certificate issuance, part of the key and certificate management process, requires that keys and certificates be created in the key database. This document discusses certificate and key database management. For information on the security module database management, see the <command>modutil</command> manpage.</para>
<para>Running <command>certutil</command> always requires one and only one command option to specify the type of certificate operation. Each command option may take zero or more arguments. The command option <option>-H</option> will list all the command options and their relevant arguments.</para>
<listitem><para>Add an existing certificate to a certificate database. The certificate database should already exist; if one is not present, this command option will initialize one by default.</para></listitem>
<listitem><para>Run a series of commands from the specified batch file. This requires the <option>-i</option> argument.</para></listitem>
</varlistentry>
<varlistentry>
<term>-C </term>
<listitem><para>Create a new binary certificate file from a binary certificate request file. Use the <option>-i</option> argument to specify the certificate request file. If this argument is not used, <command>certutil</command> prompts for a filename. </para></listitem>
</varlistentry>
<varlistentry>
<term>-D </term>
<listitem><para>Delete a certificate from the certificate database.</para></listitem>
<listitem><para>Add an email certificate to the certificate database.</para></listitem>
</varlistentry>
<varlistentry>
<term>-F</term>
<listitem><para>Delete a private key from a key database. Specify the key to delete with the -n argument. Specify the database from which to delete the key with the
<option>-d</option> argument. Use the <option>-k</option> argument to specify explicitly whether to delete a DSA, RSA, or ECC key. If you don't use the <option>-k</option> argument, the option looks for an RSA key matching the specified nickname.
</para>
<para>
When you delete keys, be sure to also remove any certificates associated with those keys from the certificate database, by using -D. Some smart cards do not let you remove a public key you have generated. In such a case, only the private key is deleted from the key pair. You can display the public key with the command certutil -K -h tokenname. </para></listitem>
<listitem><para>Generate a new public and private key pair within a key database. The key database should already exist; if one is not present, this command option will initialize one by default. Some smart cards can store only one key pair. If you create a new key pair for such a card, the previous pair is overwritten.</para></listitem>
<listitem><para>List the key ID of keys in the key database. A key ID is the modulus of the RSA key or the publicValue of the DSA key. IDs are displayed in hexadecimal ("0x" is not shown).</para></listitem>
</varlistentry>
<varlistentry>
<term>-L </term>
<listitem><para>List all the certificates, or display information about a named certificate, in a certificate database.
Use the -h tokenname argument to specify the certificate database on a particular hardware or software token.</para></listitem>
</varlistentry>
<varlistentry>
<term>-M </term>
<listitem><para>Modify a certificate's trust attributes using the values of the -t argument.</para></listitem>
</varlistentry>
<varlistentry>
<term>-N</term>
<listitem><para>Create new certificate and key databases.</para></listitem>
</varlistentry>
<varlistentry>
<term>-O </term>
<listitem><para>Print the certificate chain.</para></listitem>
<listitem><para>Create a certificate request file that can be submitted to a Certificate Authority (CA) for processing into a finished certificate. Output defaults to standard out unless you use -o output-file argument.
<listitem><para>Upgrade an old database and merge it into a new database. This is used to migrate legacy NSS databases (<filename>cert8.db</filename> and <filename>key3.db</filename>) into the newer SQLite databases (<filename>cert9.db</filename> and <filename>key4.db</filename>).</para></listitem>
</varlistentry>
</variablelist>
<para><command>Arguments</command></para>
<para>Arguments modify a command option and are usually lower case, numbers, or symbols.</para>
<variablelist>
<varlistentry>
<term>-a</term>
<listitem><para>Use ASCII format or allow the use of ASCII format for input or output. This formatting follows RFC 1113.
For certificate requests, ASCII output defaults to standard output unless redirected.</para></listitem>
</varlistentry>
<varlistentry>
<term>-b validity-time</term>
<listitem><para>Specify a time at which a certificate is required to be valid. Use when checking certificate validity with the <option>-V</option> option. The format of the <emphasis>validity-time</emphasis> argument is <emphasis>YYMMDDHHMMSS[+HHMM|-HHMM|Z]</emphasis>, which allows offsets to be set relative to the validity end time. Specifying seconds (<emphasis>SS</emphasis>) is optional. When specifying an explicit time, use a Z at the end of the term, <emphasis>YYMMDDHHMMSSZ</emphasis>, to close it. When specifying an offset time, use <emphasis>YYMMDDHHMMSS+HHMM</emphasis> or <emphasis>YYMMDDHHMMSS-HHMM</emphasis> for adding or subtracting time, respectively.
</para>
<para>
If this option is not used, the validity check defaults to the current system time.</para></listitem>
</varlistentry>
<varlistentry>
<term>-c issuer</term>
<listitem><para>Identify the certificate of the CA from which a new certificate will derive its authenticity.
Use the exact nickname or alias of the CA certificate, or use the CA's email address. Bracket the issuer string
with quotation marks if it contains spaces. </para></listitem>
</varlistentry>
<varlistentry>
<term>-d [prefix]directory</term>
<listitem>
<para>Specify the database directory containing the certificate and key database files.</para>
<para><command>certutil</command> supports two types of databases: the legacy security databases (<filename>cert8.db</filename>, <filename>key3.db</filename>, and <filename>secmod.db</filename>) and new SQLite databases (<filename>cert9.db</filename>, <filename>key4.db</filename>, and <filename>pkcs11.txt</filename>). </para>
<para>If no prefix is specified the default type is retrieved from NSS_DEFAULT_DB_TYPE. If NSS_DEFAULT_DB_TYPE is not set then <command>dbm:</command> is the default.</para>
<listitem><para>Set a key size to use when generating new public and private key pairs. The minimum is 512 bits and the maximum is 16384 bits. The default is 2048 bits. Any size between the minimum and maximum is allowed.</para></listitem>
<listitem><para>Pass an input file to the command. Depending on the command option, an input file can be a specific certificate, a certificate request file, or a batch file of commands.</para></listitem>
<listitem><para>Assign a unique serial number to a certificate being created. This operation should be performed by a CA. If no serial number is provided a default serial number is made from the current time. Serial numbers are limited to integers </para></listitem>
<listitem><para>Specify the nickname of a certificate or key to list, create, add to a database, modify, or validate. Bracket the nickname string with quotation marks if it contains spaces.</para></listitem>
</varlistentry>
<varlistentry>
<term>-o output-file</term>
<listitem><para>Specify the output file name for new certificates or binary certificate requests. Bracket the output-file string with quotation marks if it contains spaces. If this argument is not used the output destination defaults to standard output.</para></listitem>
</varlistentry>
<varlistentry>
<term>-P dbPrefix</term>
<listitem><para>Specify the prefix used on the certificate and key database file. This argument is provided to support legacy servers. Most applications do not use a database prefix.</para></listitem>
</varlistentry>
<varlistentry>
<term>-p phone</term>
<listitem><para>Specify a contact telephone number to include in new certificates or certificate requests. Bracket this string with quotation marks if it contains spaces.</para></listitem>
</varlistentry>
<varlistentry>
<term>-q pqgfile or curve-name</term>
<listitem>
<para>Read an alternate PQG value from the specified file when generating DSA key pairs. If this argument is not used, <command>certutil</command> generates its own PQG value. PQG files are created with a separate DSA utility.</para>
<para>Elliptic curve name is one of the ones from SUITE B: nistp256, nistp384, nistp521</para>
<para>
If NSS has been compiled with support curves outside of SUITE B:
<listitem><para>Display a certificate's binary DER encoding when listing information about that certificate with the -L option.</para></listitem>
</varlistentry>
<varlistentry>
<term>-s subject</term>
<listitem><para>Identify a particular certificate owner for new certificates or certificate requests. Bracket this string with quotation marks if it contains spaces. The subject identification format follows RFC #1485.</para></listitem>
</varlistentry>
<varlistentry>
<term>-t trustargs</term>
<listitem><para>Specify the trust attributes to modify in an existing certificate or to apply to a certificate when creating it or adding it to a database. There are three available trust categories for each certificate, expressed in the order <emphasis>SSL, email, object signing</emphasis> for each trust setting. In each category position, use none, any, or all
<para><command>S</command> (as an email signer)</para>
</listitem>
<listitem>
<para><command>R</command> (as an email recipient)</para>
</listitem>
<listitem>
<para><command>O</command> (as an OCSP status responder)</para>
</listitem>
<listitem>
<para><command>J</command> (as an object signer)</para>
</listitem>
</itemizedlist></listitem>
</varlistentry>
<varlistentry>
<term>-v valid-months</term>
<listitem><para>Set the number of months a new certificate will be valid. The validity period begins at the current system time unless an offset is added or subtracted with the <option>-w</option> option. If this argument is not used, the default validity period is three months. </para></listitem>
</varlistentry>
<varlistentry>
<term>-w offset-months</term>
<listitem><para>Set an offset from the current system time, in months,
for the beginning of a certificate's validity period. Use when creating
the certificate or adding it to a database. Express the offset in integers,
using a minus sign (-) to indicate a negative offset. If this argument is
not used, the validity period begins at the current system time. The length
of the validity period is set with the -v argument. </para></listitem>
</varlistentry>
<varlistentry>
<term>-X </term>
<listitem><para>Force the key and certificate database to open in read-write mode. This is used with the <option>-U</option> and <option>-L</option> command options.</para></listitem>
</varlistentry>
<varlistentry>
<term>-x </term>
<listitem><para>Use <command>certutil</command> to generate the signature for a certificate being created or added to a database, rather than obtaining a signature from a separate CA.</para></listitem>
</varlistentry>
<varlistentry>
<term>-y exp</term>
<listitem><para>Set an alternate exponent value to use in generating a new RSA public key for the database, instead of the default value of 65537. The available alternate values are 3 and 17.</para></listitem>
</varlistentry>
<varlistentry>
<term>-z noise-file</term>
<listitem><para>Read a seed value from the specified file to generate a new private and public key pair. This argument makes it possible to use hardware-generated seed values or manually create a value from the keyboard. The minimum file size is 20 bytes.</para></listitem>
<listitem><para>Add a basic constraint extension to a certificate that is being created or added to a database. This extension supports the certificate chain verification process. <command>certutil</command> prompts for the certificate constraint extension to select.</para>
<para>X.509 certificate extensions are described in RFC 5280.</para></listitem>
</varlistentry>
<varlistentry>
<term>-3 </term>
<listitem><para>Add an authority key ID extension to a certificate that is being created or added to a database. This extension supports the identification of a particular certificate, from among multiple certificates associated with one subject name, as the correct issuer of a certificate. The Certificate Database Tool will prompt you to select the authority key ID extension.</para>
<para>X.509 certificate extensions are described in RFC 5280.</para></listitem>
</varlistentry>
<varlistentry>
<term>-4 </term>
<listitem><para>Add a CRL distribution point extension to a certificate that is being created or added to a database. This extension identifies the URL of a certificate's associated certificate revocation list (CRL). <command>certutil</command> prompts for the URL.</para>
<para>X.509 certificate extensions are described in RFC 5280.</para></listitem>
<listitem><para>Add an X.509 V3 certificate type extension to a certificate that is being created or added to the database. There are several available keywords:</para>
<para>X.509 certificate extensions are described in RFC 5280.</para></listitem>
</varlistentry>
<varlistentry>
<term>-6 | --extKeyUsage keyword,keyword</term>
<listitem><para>Add an extended key usage extension to a certificate that is being created or added to the database. Several keywords are available:</para>
<itemizedlist>
<listitem>
<para>
serverAuth
</para>
</listitem>
<listitem>
<para>
clientAuth
</para>
</listitem>
<listitem>
<para>
codeSigning
</para>
</listitem>
<listitem>
<para>
emailProtection
</para>
</listitem>
<listitem>
<para>
timeStamp
</para>
</listitem>
<listitem>
<para>
ocspResponder
</para>
</listitem>
<listitem>
<para>
stepUp
</para>
</listitem>
<listitem>
<para>
msTrustListSign
</para>
</listitem>
<listitem>
<para>
critical
</para>
</listitem>
</itemizedlist>
<para>X.509 certificate extensions are described in RFC 5280.</para></listitem>
</varlistentry>
<varlistentry>
<term>-7 emailAddrs</term>
<listitem><para>Add a comma-separated list of email addresses to the subject alternative name extension of a certificate or certificate request that is being created or added to the database. Subject alternative name extensions are described in Section 4.2.1.7 of RFC 3280.</para></listitem>
</varlistentry>
<varlistentry>
<term>-8 dns-names</term>
<listitem><para>Add a comma-separated list of DNS names to the subject alternative name extension of a certificate or certificate request that is being created or added to the database. Subject alternative name extensions are described in Section 4.2.1.7 of RFC 3280.</para></listitem>
</varlistentry>
<varlistentry>
<term>--extAIA</term>
<listitem><para>Add the Authority Information Access extension to the certificate. X.509 certificate extensions are described in RFC 5280.</para></listitem>
</varlistentry>
<varlistentry>
<term>--extSIA</term>
<listitem><para>Add the Subject Information Access extension to the certificate. X.509 certificate extensions are described in RFC 5280.</para></listitem>
</varlistentry>
<varlistentry>
<term>--extCP</term>
<listitem><para>Add the Certificate Policies extension to the certificate. X.509 certificate extensions are described in RFC 5280.</para></listitem>
</varlistentry>
<varlistentry>
<term>--extPM</term>
<listitem><para>Add the Policy Mappings extension to the certificate. X.509 certificate extensions are described in RFC 5280.</para></listitem>
</varlistentry>
<varlistentry>
<term>--extPC</term>
<listitem><para>Add the Policy Constraints extension to the certificate. X.509 certificate extensions are described in RFC 5280.</para></listitem>
</varlistentry>
<varlistentry>
<term>--extIA</term>
<listitem><para>Add the Inhibit Any Policy Access extension to the certificate. X.509 certificate extensions are described in RFC 5280.</para></listitem>
</varlistentry>
<varlistentry>
<term>--extSKID</term>
<listitem><para>Add the Subject Key ID extension to the certificate. X.509 certificate extensions are described in RFC 5280.</para></listitem>
PKCS #11 key Attributes. Comma separated list of key attribute flags, selected from the following list of choices: {token | session} {public | private} {sensitive | insensitive} {modifiable | unmodifiable} {extractable | unextractable}</para></listitem>
<listitem><para>Identify the certificate database directory to upgrade.</para></listitem>
</varlistentry>
<varlistentry>
<term>--source-prefix certdir</term>
<listitem><para>Give the prefix of the certificate and key databases to upgrade.</para></listitem>
</varlistentry>
<varlistentry>
<term>--upgrade-id uniqueID</term>
<listitem><para>Give the unique ID of the database to upgrade.</para></listitem>
</varlistentry>
<varlistentry>
<term>--upgrade-token-name name</term>
<listitem><para>Set the name of the token to use while it is being upgraded.</para></listitem>
</varlistentry>
<varlistentry>
<term>-@ pwfile</term>
<listitem><para>Give the name of a password file to use for the database being upgraded.</para></listitem>
</varlistentry>
</variablelist>
</refsection>
<refsectionid="basic-usage">
<title>Usage and Examples</title>
<para>
Most of the command options in the examples listed here have more arguments available. The arguments included in these examples are the most common ones or are used to illustrate a specific scenario. Use the <option>-H</option> option to show the complete list of arguments for each command option.
</para>
<para><command>Creating New Security Databases</command></para>
<para>
Certificates, keys, and security modules related to managing certificates are stored in three related databases:
</para>
<itemizedlist>
<listitem>
<para>
cert8.db or cert9.db
</para>
</listitem>
<listitem>
<para>
key3.db or key4.db
</para>
</listitem>
<listitem>
<para>
secmod.db or pkcs11.txt
</para>
</listitem>
</itemizedlist>
<para>
These databases must be created before certificates or keys can be generated.
<para><command>Creating a Certificate Request</command></para>
<para>
A certificate request contains most or all of the information that is used to generate the final certificate. This request is submitted separately to a certificate authority and is then approved by some mechanism (automatically or by human review). Once the request is approved, then the certificate is generated.
<para><command>Creating a Certificate</command></para>
<para>
A valid certificate must be issued by a trusted CA. This can be done by specifying a CA certificate (<option>-c</option>) that is stored in the certificate database. If a CA key pair is not available, you can create a self-signed certificate using the <option>-x</option> argument with the <option>-S</option> command option.
The series of numbers and <option>--ext*</option> options set certificate extensions that can be added to the certificate when it is generated by the CA. Interactive prompts will result.
<para><command>Generating a Certificate from a Certificate Request</command></para>
<para>
When a certificate request is created, a certificate can be generated by using the request and then referencing a certificate authority signing certificate (the <emphasis>issuer</emphasis> specified in the <option>-c</option> argument). The issuing certificate must be in the certificate database in the specified directory.
The <option>-L</option> command option lists all of the certificates listed in the certificate database. The path to the directory (<option>-d</option>) is required.
CA Administrator of Instance pki-ca1's Example Domain ID u,u,u
TPS Administrator's Example Domain ID u,u,u
Google Internet Authority ,,
Certificate Authority - Example Domain CT,C,C</programlisting>
<para>
Using additional arguments with <option>-L</option> can return and print the information for a single, specific certificate. For example, the <option>-n</option> argument passes the certificate name, while the <option>-a</option> argument prints the certificate in ASCII format:
Keys are the original material used to encrypt certificate data. The keys generated for certificates are stored separately, in the key database.
</para>
<para>
To list all keys in the database, use the <option>-K</option> command option and the (required) <option>-d</option> argument to give the path to the directory.
< 1> rsa 40defeeb522ade11090eacebaaf1196a172127df Example Domain Administrator Cert
< 2> rsa 1d0b06f44f6c03842f7d4f4a1dc78b3bcd1b85a5 John Smith user cert</programlisting>
<para>
There are ways to narrow the keys listed in the search results:
</para>
<itemizedlist>
<listitem>
<para>
To return a specific key, use the <option>-n</option><emphasis>name</emphasis> argument with the name of the key.
</para>
</listitem>
<listitem>
<para>
If there are multiple security devices loaded, then the <option>-h</option><emphasis>tokenname</emphasis> argument can search a specific token or all tokens.
</para>
</listitem>
<listitem>
<para>
If there are multiple key types available, then the <option>-k</option><emphasis>key-type</emphasis> argument can search a specific type of key, like RSA, DSA, or ECC.
The devices that can be used to store certificates -- both internal databases and external devices like smart cards -- are recognized and used by loading security modules. The <option>-U</option> command option lists all of the security modules listed in the <filename>secmod.db</filename> database. The path to the directory (<option>-d</option>) is required.
<para><command>Adding Certificates to the Database</command></para>
<para>
Existing certificates or certificate requests can be added manually to the certificate database, even if they were generated elsewhere. This uses the <option>-A</option> command option.
A related command option, <option>-E</option>, is used specifically to add email certificates to the certificate database. The <option>-E</option> command has the same arguments as the <option>-A</option> command. The trust arguments for certificates have the format <emphasis>SSL,S/MIME,Code-signing</emphasis>, so the middle trust settings relate most to email certificates (though the others can be set). For example:
<para><command>Deleting Certificates to the Database</command></para>
<para>
Certificates can be deleted from a database using the <option>-D</option> option. The only required options are to give the security database directory and to identify the certificate nickname.
A certificate contains an expiration date in itself, and expired certificates are easily rejected. However, certificates can also be revoked before they hit their expiration date. Checking whether a certificate has been revoked requires validating the certificate. Validation can also be used to ensure that the certificate is only used for the purposes it was initially issued for. Validation is carried out by the <option>-V</option> command option.
The trust settings (which relate to the operations that a certificate is allowed to be used for) can be changed after a certificate is created or added to the database. This is especially useful for CA certificates, but it can be performed for any type of certificate.
<para><command>Printing the Certificate Chain</command></para>
<para>
Certificates can be issued in <emphasis>chains</emphasis> because every certificate authority itself has a certificate; when a CA issues a certificate, it essentially stamps that certificate with its own fingerprint. The <option>-O</option> prints the full chain of a certificate, going from the initial CA (the root CA) through ever intermediary CA to the actual certificate. For example, for an email certificate with two CAs in the chain:
The device which stores certificates -- both external hardware devices and internal software databases -- can be blanked and reused. This operation is performed on the device which stores the data, not directly on the security databases, so the location must be referenced through the token name (<option>-h</option>) as well as any directory path. If there is no external token used, the default value is internal.
Many networks have dedicated personnel who handle changes to security tokens (the security officer). This person must supply the password to access the specified token. For example:
<para><command>Upgrading or Merging the Security Databases</command></para>
<para>
Many networks or applications may be using older BerkeleyDB versions of the certificate database (<filename>cert8.db</filename>). Databases can be upgraded to the new SQLite version of the database (<filename>cert9.db</filename>) using the <option>--upgrade-merge</option> command option or existing databases can be merged with the new <filename>cert9.db</filename> databases using the <option>---merge</option> command.
</para>
<para>
The <option>--upgrade-merge</option> command must give information about the original database and then use the standard arguments (like <option>-d</option>) to give the information about the new databases. The command also requires information that the tool uses for the process to upgrade and write over the original database.
</para>
<programlisting>certutil --upgrade-merge -d [sql:]directory [-P dbprefix] --source-dir directory --source-prefix dbprefix --upgrade-id id --upgrade-token-name name [-@ password-file]</programlisting>
The <option>--merge</option> command only requires information about the location of the original database; since it doesn't change the format of the database, it can write over information without performing interim step.
<para><command>Running certutil Commands from a Batch File</command></para>
<para>
A series of commands can be run sequentially from a text file with the <option>-B</option> command option. The only argument for this specifies the input file.
<para>NSS originally used BerkeleyDB databases to store security information.
The last versions of these <emphasis>legacy</emphasis> databases are:</para>
<itemizedlist>
<listitem>
<para>
cert8.db for certificates
</para>
</listitem>
<listitem>
<para>
key3.db for keys
</para>
</listitem>
<listitem>
<para>
secmod.db for PKCS #11 module information
</para>
</listitem>
</itemizedlist>
<para>BerkeleyDB has performance limitations, though, which prevent it from being easily used by multiple applications simultaneously. NSS has
some flexibility that allows applications to use their own, independent database engine while keeping a shared database and working around the access issues. Still, NSS
requires more flexibility to provide a truly shared security database.</para>
<para>In 2009, NSS introduced a new set of databases that are SQLite databases rather than
<para>Because the SQLite databases are designed to be shared, these are the <emphasis>shared</emphasis> database type. The shared database type is preferred; the legacy format is included for backward compatibility.</para>
<para>By default, the tools (<command>certutil</command>, <command>pk12util</command>, <command>modutil</command>) assume that the given security databases follow the more common legacy type.
Using the SQLite databases must be manually specified by using the <command>sql:</command> prefix with the given security directory. For example:</para>
<para>To set the shared database type as the default type for the tools, set the <envar>NSS_DEFAULT_DB_TYPE</envar> environment variable to <envar>sql</envar>:</para>
<para>This line can be set added to the <filename>~/.bashrc</filename> file to make the change permanent.</para>
<para>Most applications do not use the shared database by default, but they can be configured to use them. For example, this how-to article covers how to configure Firefox and Thunderbird to use the new shared NSS databases:</para>
<para>For information about NSS and other tools related to NSS (like JSS), check out the NSS project wiki at <ulinkurl="http://www.mozilla.org/projects/security/pki/nss/">http://www.mozilla.org/projects/security/pki/nss/</ulink>. The NSS site relates directly to NSS code changes and releases.</para>
<para>Licensed under the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.