Bug 1881538 [wpt PR 44730] - Convert CSS2 visual tests into reftests where an existin...
[gecko.git] / security / nss / doc / pk12util.xml
blobef1547d5d1255d7672e44c7837126abc8ba5da44
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
4 <!ENTITY date SYSTEM "date.xml">
5 <!ENTITY version SYSTEM "version.xml">
6 ]>
8 <refentry id="pk12util">
10   <refentryinfo>
11     <date>&date;</date>
12     <title>NSS Security Tools</title>
13     <productname>nss-tools</productname>
14     <productnumber>&version;</productnumber>
15   </refentryinfo>
17   <refmeta>
18     <refentrytitle>PK12UTIL</refentrytitle>
19     <manvolnum>1</manvolnum>
20   </refmeta>
22   <refnamediv>
23     <refname>pk12util</refname>
24     <refpurpose>Export and import keys and certificate to or from a PKCS #12 file and the NSS database</refpurpose>
25   </refnamediv>
27   <refsynopsisdiv>
28     <cmdsynopsis>
29       <command>pk12util</command>
30       <arg>-i p12File|-l p12File|-o p12File</arg>
31       <arg>-c keyCipher</arg>
32       <arg>-C certCipher</arg>
33       <arg>-d directory</arg>
34       <arg>-h tokenname</arg>
35       <arg>-m | --key-len  keyLength</arg>
36       <arg>-M hashAlg</arg>
37       <arg>-n certname</arg>
38       <arg>-P dbprefix</arg>
39       <arg>-r</arg>
40       <arg>-v</arg>
41       <arg>--cert-key-len  certKeyLength</arg>
42       <arg>-k slotPasswordFile|-K slotPassword</arg>
43       <arg>-w p12filePasswordFile|-W p12filePassword</arg>
44     </cmdsynopsis>
45   </refsynopsisdiv>
47   <refsection>
48     <title>STATUS</title>
49     <para>This documentation is still work in progress. Please contribute to the initial review in <ulink url="https://bugzilla.mozilla.org/show_bug.cgi?id=836477">Mozilla NSS bug 836477</ulink>
50     </para>
51   </refsection>
53   <refsection id="description">
54     <title>Description</title>
55     <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>
56   </refsection>
57   
58   <refsection id="options">
59     <title>Options and Arguments</title>
60     <para><command>Options</command></para>
61     <variablelist>
62       <varlistentry>
63         <term>-i p12file</term>
64         <listitem><para>Import keys and certificates from a PKCS #12 file into a security database.</para></listitem>
65       </varlistentry>
67       <varlistentry>
68         <term>-l p12file</term>
69         <listitem><para>List the keys and certificates in PKCS #12 file.</para></listitem>
70       </varlistentry>
72       <varlistentry>
73         <term>-o p12file</term>
74         <listitem><para>Export keys and certificates from the security database to a PKCS #12 file.</para></listitem>
75       </varlistentry>
76     </variablelist>
78     <para><command>Arguments</command></para>
79     <variablelist>
80       <varlistentry>
81         <term>-c keyCipher</term>
82         <listitem><para>Specify the key encryption algorithm.</para></listitem>
83       </varlistentry>
85       <varlistentry>
86         <term>-C certCipher</term>
87         <listitem><para>Specify the certiticate encryption algorithm.</para></listitem>
88       </varlistentry>
90       <varlistentry>
91         <term>-d directory</term>
92         <listitem><para>Specify the database directory into which to import to or export from certificates and keys.</para>
93         <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>dbm:</command> is not used, then the tool assumes that the given databases are in the SQLite format.</para></listitem>
94       </varlistentry>
96       <varlistentry>
97         <term>-h tokenname</term>
98         <listitem><para>Specify the name of the token to import into or export from.</para></listitem>
99       </varlistentry>
101       <varlistentry>
102         <term>-k slotPasswordFile</term>
103         <listitem><para>Specify the text file containing the slot's password.</para></listitem>
104       </varlistentry>
106       <varlistentry>
107         <term>-K slotPassword</term>
108         <listitem><para>Specify the slot's password.</para></listitem>
109       </varlistentry>
111       <varlistentry>
112         <term>-m | --key-len  keyLength</term>
113         <listitem><para>Specify the desired length of the symmetric key to be used to encrypt the private key.</para></listitem>
114       </varlistentry>
116       <varlistentry>
117         <term>-M hashAlg</term>
118         <listitem><para>Specify the hash algorithm used in the pkcs #12 mac. This algorithm also specifies the HMAC used in the prf when using pkcs #5 v2.</para></listitem>
119       </varlistentry>
122       <varlistentry>
123         <term>--cert-key-len  certKeyLength</term>
124         <listitem><para>Specify the desired length of the symmetric key to be used to encrypt the certificates and other meta-data.</para></listitem>
125       </varlistentry>
127       <varlistentry>
128         <term>-n certname</term>
129         <listitem><para>Specify the nickname of the cert and private key to export.</para>
130         <para>The nickname can also be a PKCS #11 URI. For example, if you have a certificate named "my-server-cert" on the internal certificate store, it can be unambiguously specified as "pkcs11:token=NSS%20Certificate%20DB;object=my-server-cert". For details about the format, see RFC 7512.</para></listitem>
131       </varlistentry>
133       <varlistentry>
134         <term>-P prefix</term>
135         <listitem><para>Specify the prefix used on the certificate and key databases. This option is provided as a special case. 
136           Changing the names of the certificate and key databases is not recommended.</para></listitem>
137       </varlistentry>
139       <varlistentry>
140         <term>-r</term>
141         <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>
142       </varlistentry>
144       <varlistentry>
145         <term>-v </term>
146         <listitem><para>Enable debug logging when importing.</para></listitem>
147       </varlistentry>
149       <varlistentry>
150         <term>-w p12filePasswordFile</term>
151         <listitem><para>Specify the text file containing the pkcs #12 file password.</para></listitem>
152       </varlistentry>
154       <varlistentry>
155         <term>-W p12filePassword</term>
156         <listitem><para>Specify the pkcs #12 file password.</para></listitem>
157       </varlistentry>
159     </variablelist>
160   </refsection>
162   <refsection id="return-codes">
163     <title>Return Codes</title>
164         <itemizedlist>
165         <listitem>
166         <para> 0 - No error</para>
167         </listitem>
168         <listitem>
169         <para> 1 - User Cancelled</para>
170         </listitem>
171         <listitem>
172         <para> 2 - Usage error</para>
173         </listitem>
174         <listitem>
175         <para> 6 - NLS init error</para>
176         </listitem>
177         <listitem>
178         <para> 8 - Certificate DB open error</para>
179         </listitem>
180         <listitem>
181         <para> 9 - Key DB open error</para>
182         </listitem>
183         <listitem>
184         <para> 10 - File initialization error</para>
185         </listitem>
186         <listitem>
187         <para> 11 - Unicode conversion error</para>
188         </listitem>
189         <listitem>
190         <para> 12 - Temporary file creation error</para>
191         </listitem>
192         <listitem>
193         <para> 13 - PKCS11 get slot error</para>
194         </listitem>
195         <listitem>
196         <para> 14 - PKCS12 decoder start error</para>
197         </listitem>
198         <listitem>
199         <para> 15 - error read from import file</para>
200         </listitem>
201         <listitem>
202         <para> 16 - pkcs12 decode error</para>
203         </listitem>
204         <listitem>
205         <para> 17 - pkcs12 decoder verify error</para>
206         </listitem>
207         <listitem>
208         <para> 18 - pkcs12 decoder validate bags error</para>
209         </listitem>
210         <listitem>
211         <para> 19 - pkcs12 decoder import bags error</para>
212         </listitem>
213         <listitem>
214         <para> 20 - key db conversion version 3 to version 2 error</para>
215         </listitem>
216         <listitem>
217         <para> 21 - cert db conversion version 7 to version 5 error</para>
218         </listitem>
219         <listitem>
220         <para> 22 - cert and key dbs patch error</para>
221         </listitem>
222         <listitem>
223         <para> 23 - get default cert db error</para>
224         </listitem>
225         <listitem>
226         <para> 24 - find cert by nickname error</para>
227         </listitem>
228         <listitem>
229         <para> 25 - create export context error</para>
230         </listitem>
231         <listitem>
232         <para> 26 - PKCS12 add password itegrity error</para>
233         </listitem>
234         <listitem>
235         <para> 27 - cert and key Safes creation error</para>
236         </listitem>
237         <listitem>
238         <para> 28 - PKCS12 add cert and key error</para>
239         </listitem>
240         <listitem>
241         <para> 29 - PKCS12 encode error</para>
242         </listitem>
243         </itemizedlist>
244   </refsection>
246   <refsection id="examples">
247     <title>Examples</title>
248     <para><command>Importing Keys and Certificates</command></para>
249     <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).
250     </para>
251     <para>
252     pk12util -i p12File [-h tokenname] [-v] [-d directory] [-P dbprefix] [-k slotPasswordFile|-K slotPassword] [-w p12filePasswordFile|-W p12filePassword]
253     </para>
254     <para>For example:</para>
255     <para> </para>
256     <programlisting># pk12util -i /tmp/cert-files/users.p12 -d /home/my/sharednssdb
258 Enter a password which will be used to encrypt your keys.
259 The password should be at least 8 characters long,
260 and should contain at least one non-alphabetic character.
262 Enter new password: 
263 Re-enter password: 
264 Enter password for PKCS12 file: 
265 pk12util: PKCS12 IMPORT SUCCESSFUL</programlisting>
267     <para><command>Exporting Keys and Certificates</command></para>
268     <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.
269     </para>
270     <para>pk12util -o p12File -n certname [-c keyCipher] [-C certCipher] [-m|--key_len keyLen] [-n|--cert_key_len certKeyLen] [-d directory] [-P dbprefix] [-k slotPasswordFile|-K slotPassword] [-w p12filePasswordFile|-W p12filePassword]</para>
271     <para>For example:</para>
272     <programlisting># pk12util -o certs.p12 -n Server-Cert -d /home/my/sharednssdb
273 Enter password for PKCS12 file: 
274 Re-enter password: </programlisting>
276     <para><command>Listing Keys and Certificates</command></para>
277     <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.
278     </para>
279     <para>pk12util -l p12File [-h tokenname] [-r] [-d directory] [-P dbprefix] [-k slotPasswordFile|-K slotPassword] [-w p12filePasswordFile|-W p12filePassword]</para>
280     <para>For example, this prints the default ASCII output:</para>
281     <programlisting># pk12util -l certs.p12
283 Enter password for PKCS12 file: 
284 Key(shrouded):
285     Friendly Name: Thawte Freemail Member's Thawte Consulting (Pty) Ltd. ID
287     Encryption algorithm: PKCS #12 V2 PBE With SHA-1 And 3KEY Triple DES-CBC
288         Parameters:
289             Salt:
290                 45:2e:6a:a0:03:4d:7b:a1:63:3c:15:ea:67:37:62:1f
291             Iteration Count: 1 (0x1)
292 Certificate:
293     Data:
294         Version: 3 (0x2)
295         Serial Number: 13 (0xd)
296         Signature Algorithm: PKCS #1 SHA-1 With RSA Encryption
297         Issuer: "E=personal-freemail@thawte.com,CN=Thawte Personal Freemail C
298             A,OU=Certification Services Division,O=Thawte Consulting,L=Cape T
299             own,ST=Western Cape,C=ZA"
300     </programlisting>
301     <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>
302     <programlisting>pk12util -l test.p12 -r
303 Enter password for PKCS12 file: 
304 Key(shrouded):
305     Friendly Name: Thawte Freemail Member's Thawte Consulting (Pty) Ltd. ID
307     Encryption algorithm: PKCS #12 V2 PBE With SHA-1 And 3KEY Triple DES-CBC
308         Parameters:
309             Salt:
310                 45:2e:6a:a0:03:4d:7b:a1:63:3c:15:ea:67:37:62:1f
311             Iteration Count: 1 (0x1)
312 Certificate    Friendly Name: Thawte Personal Freemail Issuing CA - Thawte Consulting
314 Certificate    Friendly Name: Thawte Freemail Member's Thawte Consulting (Pty) Ltd. ID
315     </programlisting>
316   </refsection>
318   <refsection id="encryption">
319     <title>Password Encryption</title>
320     <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 associated certificates. If no algorithm is specified, the tool defaults to using PKCS #12 SHA-1 and 3-key triple DES for private key encryption. When not in FIPS mode, PKCS #12 SHA-1 and 40-bit RC4 is used for certificate encryption. When in FIPS mode, there is no certificate encryption. If certificate encryption is not wanted, specify <userinput>"NONE"</userinput> as the argument of the <option>-C</option> option.</para>
321     <para>The private key is always protected with strong encryption by default.</para>
322     <para>Several types of ciphers are supported.</para>
323     <variablelist>
324     
325       <varlistentry>
326         <term>PKCS #5 password-based encryption</term>
327         <listitem>
328           <itemizedlist>
329             <listitem><para>PBES2 with AES-CBC-Pad as underlying encryption scheme (<userinput>"AES-128-CBC"</userinput>, <userinput>"AES-192-CBC"</userinput>, and <userinput>"AES-256-CBC"</userinput>)</para></listitem>
330           </itemizedlist>
331         </listitem>
332       </varlistentry>
334       <varlistentry>
335         <term>PKCS #12 password-based encryption</term>
336         <listitem>
337           <itemizedlist>
338             <listitem><para>SHA-1 and 128-bit RC4 (<userinput>"PKCS #12 V2 PBE With SHA-1 And 128 Bit RC4"</userinput> or <userinput>"RC4"</userinput>)</para></listitem>
339             <listitem><para>SHA-1 and 40-bit RC4 (<userinput>"PKCS #12 V2 PBE With SHA-1 And 40 Bit RC4"</userinput>) (used by default for certificate encryption in non-FIPS mode)</para></listitem>
340             <listitem><para>SHA-1 and 3-key triple-DES (<userinput>"PKCS #12 V2 PBE With SHA-1 And 3KEY Triple DES-CBC"</userinput> or <userinput>"DES-EDE3-CBC"</userinput>)</para></listitem>
341             <listitem><para>SHA-1 and 128-bit RC2 (<userinput>"PKCS #12 V2 PBE With SHA-1 And 128 Bit RC2 CBC"</userinput> or <userinput>"RC2-CBC"</userinput>)</para></listitem>
342             <listitem><para>SHA-1 and 40-bit RC2 (<userinput>"PKCS #12 V2 PBE With SHA-1 And 40 Bit RC2 CBC"</userinput>)</para></listitem>
343           </itemizedlist>
344         </listitem>
345       </varlistentry>
346     </variablelist>
347     <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>
348   </refsection>
350 <refsection id="databases"><title>NSS Database Types</title>
351 <para>NSS originally used BerkeleyDB databases to store security information. 
352 The last versions of these <emphasis>legacy</emphasis> databases are:</para>
353 <itemizedlist>
354         <listitem>
355                 <para>
356                         cert8.db for certificates
357                 </para>
358         </listitem>
359         <listitem>
360                 <para>
361                         key3.db for keys
362                 </para>
363         </listitem>
364         <listitem>
365                 <para>
366                         secmod.db for PKCS #11 module information
367                 </para>
368         </listitem>
369 </itemizedlist>
371 <para>BerkeleyDB has performance limitations, though, which prevent it from being easily used by multiple applications simultaneously. NSS has 
372 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
373 requires more flexibility to provide a truly shared security database.</para>
375 <para>In 2009, NSS introduced a new set of databases that are SQLite databases rather than 
376 BerkleyDB. These new databases provide more accessibility and performance:</para>
377 <itemizedlist>
378         <listitem>
379                 <para>
380                         cert9.db for certificates
381                 </para>
382         </listitem>
383         <listitem>
384                 <para>
385                         key4.db for keys
386                 </para>
387         </listitem>
388         <listitem>
389                 <para>
390                         pkcs11.txt, which is listing of all of the PKCS #11 modules contained in a new subdirectory in the security databases directory
391                 </para>
392         </listitem>
393 </itemizedlist>
395 <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>
397 <para>By default, the tools (<command>certutil</command>, <command>pk12util</command>, <command>modutil</command>) assume that the given security databases use the SQLite type
398 Using the legacy databases must be manually specified by using the <command>dbm:</command> prefix with the given security directory. For example:</para>
400 <programlisting># pk12util -i /tmp/cert-files/users.p12 -d dbm:/home/my/sharednssdb</programlisting>
402 <para>To set the legacy database type as the default type for the tools, set the <envar>NSS_DEFAULT_DB_TYPE</envar> environment variable to <envar>dbm</envar>:</para>
403 <programlisting>export NSS_DEFAULT_DB_TYPE="dbm"</programlisting>
405 <para>This line can be set added to the <filename>~/.bashrc</filename> file to make the change permanent.</para>
407 <itemizedlist>
408         <listitem>
409                 <para>
410                         https://wiki.mozilla.org/NSS_Shared_DB_Howto</para>
411         </listitem>
412 </itemizedlist>
413 <para>For an engineering draft on the changes in the shared NSS databases, see the NSS project wiki:</para>
414 <itemizedlist>
415         <listitem>
416                 <para>
417                         https://wiki.mozilla.org/NSS_Shared_DB
418                 </para>
419         </listitem>
420 </itemizedlist>
421 </refsection>
423   <refsection id="compatibility">
424     <title>Compatibility Notes</title>
425     <para>The exporting behavior of <command>pk12util</command> has changed over time, while importing files exported with older versions of NSS is still supported.</para>
426     <para>Until the 3.30 release, <command>pk12util</command> used the UTF-16 encoding for the PKCS #5 password-based encryption schemes, while the recommendation is to encode passwords in UTF-8 if the used encryption scheme is defined outside of the PKCS #12 standard.</para>
427     <para>Until the 3.31 release, even when <userinput>"AES-128-CBC"</userinput> or <userinput>"AES-192-CBC"</userinput> is given from the command line, <command>pk12util</command> always used 256-bit AES as the underlying encryption scheme.</para>
428     <para>For historical reasons, <command>pk12util</command> accepts password-based encryption schemes not listed in this document.  However, those schemes are not officially supported and may have issues in interoperability with other tools.</para>
429   </refsection>
431   <refsection id="seealso">
432     <title>See Also</title>
433     <para>certutil (1)</para>
434     <para>modutil (1)</para>
436         <para>The NSS wiki has information on the new database design and how to configure applications to use it.</para>
437 <itemizedlist>
438         <listitem>
439                 <para>
440                         https://wiki.mozilla.org/NSS_Shared_DB_Howto</para>
441         </listitem>
442         <listitem>
443                 <para>
444                         https://wiki.mozilla.org/NSS_Shared_DB
445                 </para>
446         </listitem>
447 </itemizedlist>
448   </refsection>
450 <!-- don't change -->
451   <refsection id="resources">
452     <title>Additional Resources</title>
453         <para>For information about NSS and other tools related to NSS (like JSS), check out the NSS project wiki at <ulink url="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>
454         <para>Mailing lists: https://lists.mozilla.org/listinfo/dev-tech-crypto</para>
455         <para>IRC: Freenode at #dogtag-pki</para>
456   </refsection>
458 <!-- fill in your name first; keep the other names for reference -->
459   <refsection id="authors">
460     <title>Authors</title>
461     <para>The NSS tools were written and maintained by developers with Netscape, Red Hat,  Sun, Oracle, Mozilla, and Google.</para>
462     <para>
463         Authors: Elio Maldonado &lt;emaldona@redhat.com>, Deon Lackey &lt;dlackey@redhat.com>.
464     </para>
465   </refsection>
467 <!-- don't change -->
468   <refsection id="license">
469     <title>LICENSE</title>
470     <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/.
471     </para>
472   </refsection>
474 </refentry>