<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>
</refsection>
<refsectionid="description">
<title>Description</title>
<para>The PKCS #12 utility, <command>pk12util</command>, enables sharing certificates among any server that supports PKCS#12. The tool can import certificates and keys from PKCS#12 files into security databases, export certificates, and list certificates and keys.</para>
</refsection>
<refsectionid="options">
<title>Options and Arguments</title>
<para><command>Options</command></para>
<variablelist>
<varlistentry>
<term>-i p12file</term>
<listitem><para>Import keys and certificates from a PKCS#12 file into a security database.</para></listitem>
</varlistentry>
<varlistentry>
<term>-l p12file</term>
<listitem><para>List the keys and certificates in PKCS#12 file.</para></listitem>
</varlistentry>
<varlistentry>
<term>-o p12file</term>
<listitem><para>Export keys and certificates from the security database to a PKCS#12 file.</para></listitem>
<listitem><para>Specify the database directory into which to import to or export from certificates and keys.</para>
<para><command>pk12util</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>). If the prefix <command>sql:</command> is not used, then the tool assumes that the given databases are in the old format.</para></listitem>
<listitem><para>Dumps all of the data in raw (binary) form. This must be saved as a DER file. The default is to return information in a pretty-print ASCII format, which displays the information about the certificates and public keys in the p12 file.</para></listitem>
<para> 27 - cert and key Safes creation error</para>
</listitem>
<listitem>
<para> 28 - PKCS12 add cert and key error</para>
</listitem>
<listitem>
<para> 29 - PKCS12 encode error</para>
</listitem>
</itemizedlist>
</refsection>
<refsectionid="examples">
<title>Examples</title>
<para><command>Importing Keys and Certificates</command></para>
<para>The most basic usage of <command>pk12util</command> for importing a certificate or key is the PKCS#12 input file (<option>-i</option>) and some way to specify the security database being accessed (either <option>-d</option> for a directory or <option>-h</option> for a token).
<para><command>Exporting Keys and Certificates</command></para>
<para>Using the <command>pk12util</command> command to export certificates and keys requires both the name of the certificate to extract from the database (<option>-n</option>) and the PKCS#12-formatted output file to write to. There are optional parameters that can be used to encrypt the file to protect the certificate material.
<para><command>Listing Keys and Certificates</command></para>
<para>The information in a <filename>.p12</filename> file are not human-readable. The certificates and keys in the file can be printed (listed) in a human-readable pretty-print format that shows information for every certificate and any public keys in the <filename>.p12</filename> file.
<para>Alternatively, the <option>-r</option> prints the certificates and then exports them into separate DER binary files. This allows the certificates to be fed to another application that supports <filename>.p12</filename> files. Each certificate is written to a sequentially-number file, beginning with <filename>file0001.der</filename> and continuing through <filename>file000N.der</filename>, incrementing the number for every certificate:</para>
<para>PKCS#12 provides for not only the protection of the private keys but also the certificate and meta-data associated with the keys. Password-based encryption is used to protect private keys on export to a PKCS#12 file and, optionally, the entire package. If no algorithm is specified, the tool defaults to using <command>PKCS12 V2 PBE with SHA1 and 3KEY Triple DES-cbc</command> for private key encryption. <command>PKCS12 V2 PBE with SHA1 and 40 Bit RC4</command> is the default for the overall package encryption when not in FIPS mode. When in FIPS mode, there is no package encryption.</para>
<para>The private key is always protected with strong encryption by default.</para>
<para>Several types of ciphers are supported.</para>
<para>With PKCS#12, the crypto provider may be the soft token module or an external hardware module. If the cryptographic module does not support the requested algorithm, then the next best fit will be selected (usually the default). If no suitable replacement for the desired algorithm can be found, the tool returns the error <emphasis>no security module can perform the requested operation</emphasis>.</para>
<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
BerkleyDB. These new databases provide more accessibility and performance:</para>
<itemizedlist>
<listitem>
<para>
cert9.db for certificates
</para>
</listitem>
<listitem>
<para>
key4.db for keys
</para>
</listitem>
<listitem>
<para>
pkcs11.txt, which is listing of all of the PKCS #11 modules contained in a new subdirectory in the security databases directory
</para>
</listitem>
</itemizedlist>
<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/.