Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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>-d [sql:]directory</arg>
32 <arg>-h tokenname</arg>
33 <arg>-P dbprefix</arg>
34 <arg>-r</arg>
35 <arg>-v</arg>
36 <arg>-k slotPasswordFile|-K slotPassword</arg>
37 <arg>-w p12filePasswordFile|-W p12filePassword</arg>
38 </cmdsynopsis>
39 </refsynopsisdiv>
41 <refsection>
42 <title>STATUS</title>
43 <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>
44 </para>
45 </refsection>
47 <refsection id="description">
48 <title>Description</title>
49 <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>
50 </refsection>
52 <refsection id="options">
53 <title>Options and Arguments</title>
54 <para><command>Options</command></para>
55 <variablelist>
56 <varlistentry>
57 <term>-i p12file</term>
58 <listitem><para>Import keys and certificates from a PKCS#12 file into a security database.</para></listitem>
59 </varlistentry>
61 <varlistentry>
62 <term>-l p12file</term>
63 <listitem><para>List the keys and certificates in PKCS#12 file.</para></listitem>
64 </varlistentry>
66 <varlistentry>
67 <term>-o p12file</term>
68 <listitem><para>Export keys and certificates from the security database to a PKCS#12 file.</para></listitem>
69 </varlistentry>
70 </variablelist>
72 <para><command>Arguments</command></para>
73 <variablelist>
74 <varlistentry>
75 <term>-c keyCipher</term>
76 <listitem><para>Specify the key encryption algorithm.</para></listitem>
77 </varlistentry>
79 <varlistentry>
80 <term>-C certCipher</term>
81 <listitem><para>Specify the key cert (overall package) encryption algorithm.</para></listitem>
82 </varlistentry>
84 <varlistentry>
85 <term>-d [sql:]directory</term>
86 <listitem><para>Specify the database directory into which to import to or export from certificates and keys.</para>
87 <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>
88 </varlistentry>
90 <varlistentry>
91 <term>-h tokenname</term>
92 <listitem><para>Specify the name of the token to import into or export from.</para></listitem>
93 </varlistentry>
95 <varlistentry>
96 <term>-k slotPasswordFile</term>
97 <listitem><para>Specify the text file containing the slot's password.</para></listitem>
98 </varlistentry>
100 <varlistentry>
101 <term>-K slotPassword</term>
102 <listitem><para>Specify the slot's password.</para></listitem>
103 </varlistentry>
105 <varlistentry>
106 <term>-m | --key-len keyLength</term>
107 <listitem><para>Specify the desired length of the symmetric key to be used to encrypt the private key.</para></listitem>
108 </varlistentry>
110 <varlistentry>
111 <term>-n | --cert-key-len certKeyLength</term>
112 <listitem><para>Specify the desired length of the symmetric key to be used to encrypt the certificates and other meta-data.</para></listitem>
113 </varlistentry>
115 <varlistentry>
116 <term>-n certname</term>
117 <listitem><para>Specify the nickname of the cert and private key to export.</para></listitem>
118 </varlistentry>
120 <varlistentry>
121 <term>-P prefix</term>
122 <listitem><para>Specify the prefix used on the certificate and key databases. This option is provided as a special case.
123 Changing the names of the certificate and key databases is not recommended.</para></listitem>
124 </varlistentry>
126 <varlistentry>
127 <term>-r</term>
128 <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>
129 </varlistentry>
131 <varlistentry>
132 <term>-v </term>
133 <listitem><para>Enable debug logging when importing.</para></listitem>
134 </varlistentry>
136 <varlistentry>
137 <term>-w p12filePasswordFile</term>
138 <listitem><para>Specify the text file containing the pkcs #12 file password.</para></listitem>
139 </varlistentry>
141 <varlistentry>
142 <term>-W p12filePassword</term>
143 <listitem><para>Specify the pkcs #12 file password.</para></listitem>
144 </varlistentry>
146 </variablelist>
147 </refsection>
149 <refsection id="return-codes">
150 <title>Return Codes</title>
151 <itemizedlist>
152 <listitem>
153 <para> 0 - No error</para>
154 </listitem>
155 <listitem>
156 <para> 1 - User Cancelled</para>
157 </listitem>
158 <listitem>
159 <para> 2 - Usage error</para>
160 </listitem>
161 <listitem>
162 <para> 6 - NLS init error</para>
163 </listitem>
164 <listitem>
165 <para> 8 - Certificate DB open error</para>
166 </listitem>
167 <listitem>
168 <para> 9 - Key DB open error</para>
169 </listitem>
170 <listitem>
171 <para> 10 - File initialization error</para>
172 </listitem>
173 <listitem>
174 <para> 11 - Unicode conversion error</para>
175 </listitem>
176 <listitem>
177 <para> 12 - Temporary file creation error</para>
178 </listitem>
179 <listitem>
180 <para> 13 - PKCS11 get slot error</para>
181 </listitem>
182 <listitem>
183 <para> 14 - PKCS12 decoder start error</para>
184 </listitem>
185 <listitem>
186 <para> 15 - error read from import file</para>
187 </listitem>
188 <listitem>
189 <para> 16 - pkcs12 decode error</para>
190 </listitem>
191 <listitem>
192 <para> 17 - pkcs12 decoder verify error</para>
193 </listitem>
194 <listitem>
195 <para> 18 - pkcs12 decoder validate bags error</para>
196 </listitem>
197 <listitem>
198 <para> 19 - pkcs12 decoder import bags error</para>
199 </listitem>
200 <listitem>
201 <para> 20 - key db conversion version 3 to version 2 error</para>
202 </listitem>
203 <listitem>
204 <para> 21 - cert db conversion version 7 to version 5 error</para>
205 </listitem>
206 <listitem>
207 <para> 22 - cert and key dbs patch error</para>
208 </listitem>
209 <listitem>
210 <para> 23 - get default cert db error</para>
211 </listitem>
212 <listitem>
213 <para> 24 - find cert by nickname error</para>
214 </listitem>
215 <listitem>
216 <para> 25 - create export context error</para>
217 </listitem>
218 <listitem>
219 <para> 26 - PKCS12 add password itegrity error</para>
220 </listitem>
221 <listitem>
222 <para> 27 - cert and key Safes creation error</para>
223 </listitem>
224 <listitem>
225 <para> 28 - PKCS12 add cert and key error</para>
226 </listitem>
227 <listitem>
228 <para> 29 - PKCS12 encode error</para>
229 </listitem>
230 </itemizedlist>
231 </refsection>
233 <refsection id="examples">
234 <title>Examples</title>
235 <para><command>Importing Keys and Certificates</command></para>
236 <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).
237 </para>
238 <para>
239 pk12util -i p12File [-h tokenname] [-v] [-d [sql:]directory] [-P dbprefix] [-k slotPasswordFile|-K slotPassword] [-w p12filePasswordFile|-W p12filePassword]
240 </para>
241 <para>For example:</para>
242 <para> </para>
243 <programlisting># pk12util -i /tmp/cert-files/users.p12 -d sql:/home/my/sharednssdb
245 Enter a password which will be used to encrypt your keys.
246 The password should be at least 8 characters long,
247 and should contain at least one non-alphabetic character.
249 Enter new password:
250 Re-enter password:
251 Enter password for PKCS12 file:
252 pk12util: PKCS12 IMPORT SUCCESSFUL</programlisting>
254 <para><command>Exporting Keys and Certificates</command></para>
255 <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.
256 </para>
257 <para>pk12util -o p12File -n certname [-c keyCipher] [-C certCipher] [-m|--key_len keyLen] [-n|--cert_key_len certKeyLen] [-d [sql:]directory] [-P dbprefix] [-k slotPasswordFile|-K slotPassword] [-w p12filePasswordFile|-W p12filePassword]</para>
258 <para>For example:</para>
259 <programlisting># pk12util -o certs.p12 -n Server-Cert -d sql:/home/my/sharednssdb
260 Enter password for PKCS12 file:
261 Re-enter password: </programlisting>
263 <para><command>Listing Keys and Certificates</command></para>
264 <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.
265 </para>
266 <para>pk12util -l p12File [-h tokenname] [-r] [-d [sql:]directory] [-P dbprefix] [-k slotPasswordFile|-K slotPassword] [-w p12filePasswordFile|-W p12filePassword]</para>
267 <para>For example, this prints the default ASCII output:</para>
268 <programlisting># pk12util -l certs.p12
270 Enter password for PKCS12 file:
271 Key(shrouded):
272 Friendly Name: Thawte Freemail Member's Thawte Consulting (Pty) Ltd. ID
274 Encryption algorithm: PKCS #12 V2 PBE With SHA-1 And 3KEY Triple DES-CBC
275 Parameters:
276 Salt:
277 45:2e:6a:a0:03:4d:7b:a1:63:3c:15:ea:67:37:62:1f
278 Iteration Count: 1 (0x1)
279 Certificate:
280 Data:
281 Version: 3 (0x2)
282 Serial Number: 13 (0xd)
283 Signature Algorithm: PKCS #1 SHA-1 With RSA Encryption
284 Issuer: "E=personal-freemail@thawte.com,CN=Thawte Personal Freemail C
285 A,OU=Certification Services Division,O=Thawte Consulting,L=Cape T
286 own,ST=Western Cape,C=ZA"
287 </programlisting>
288 <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>
289 <programlisting>pk12util -l test.p12 -r
290 Enter password for PKCS12 file:
291 Key(shrouded):
292 Friendly Name: Thawte Freemail Member's Thawte Consulting (Pty) Ltd. ID
294 Encryption algorithm: PKCS #12 V2 PBE With SHA-1 And 3KEY Triple DES-CBC
295 Parameters:
296 Salt:
297 45:2e:6a:a0:03:4d:7b:a1:63:3c:15:ea:67:37:62:1f
298 Iteration Count: 1 (0x1)
299 Certificate Friendly Name: Thawte Personal Freemail Issuing CA - Thawte Consulting
301 Certificate Friendly Name: Thawte Freemail Member's Thawte Consulting (Pty) Ltd. ID
302 </programlisting>
303 </refsection>
305 <refsection id="encryption">
306 <title>Password Encryption</title>
307 <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>
308 <para>The private key is always protected with strong encryption by default.</para>
309 <para>Several types of ciphers are supported.</para>
310 <variablelist>
312 <varlistentry>
313 <term>Symmetric CBC ciphers for PKCS#5 V2</term>
314 <listitem>
315 <itemizedlist>
316 <listitem><para>DES-CBC</para></listitem>
317 <listitem><para>RC2-CBC</para></listitem>
318 <listitem><para>RC5-CBCPad</para></listitem>
319 <listitem><para>DES-EDE3-CBC (the default for key encryption)</para></listitem>
320 <listitem><para>AES-128-CBC</para></listitem>
321 <listitem><para>AES-192-CBC</para></listitem>
322 <listitem><para>AES-256-CBC</para></listitem>
323 <listitem><para>CAMELLIA-128-CBC</para></listitem>
324 <listitem><para>CAMELLIA-192-CBC</para></listitem>
325 <listitem><para>CAMELLIA-256-CBC</para></listitem>
326 </itemizedlist>
327 </listitem>
328 </varlistentry>
330 <varlistentry>
331 <term>PKCS#12 PBE ciphers</term>
332 <listitem>
333 <itemizedlist>
334 <listitem><para>PKCS #12 PBE with Sha1 and 128 Bit RC4</para></listitem>
335 <listitem><para>PKCS #12 PBE with Sha1 and 40 Bit RC4</para></listitem>
336 <listitem><para>PKCS #12 PBE with Sha1 and Triple DES CBC</para></listitem>
337 <listitem><para>PKCS #12 PBE with Sha1 and 128 Bit RC2 CBC</para></listitem>
338 <listitem><para>PKCS #12 PBE with Sha1 and 40 Bit RC2 CBC</para></listitem>
339 <listitem><para>PKCS12 V2 PBE with SHA1 and 128 Bit RC4</para></listitem>
340 <listitem><para>PKCS12 V2 PBE with SHA1 and 40 Bit RC4 (the default for non-FIPS mode)</para></listitem>
341 <listitem><para>PKCS12 V2 PBE with SHA1 and 3KEY Triple DES-cbc</para></listitem>
342 <listitem><para>PKCS12 V2 PBE with SHA1 and 2KEY Triple DES-cbc</para></listitem>
343 <listitem><para>PKCS12 V2 PBE with SHA1 and 128 Bit RC2 CBC</para></listitem>
344 <listitem><para>PKCS12 V2 PBE with SHA1 and 40 Bit RC2 CBC</para></listitem>
345 </itemizedlist>
346 </listitem>
347 </varlistentry>
348 <varlistentry><term>PKCS#5 PBE ciphers</term>
349 <listitem>
350 <itemizedlist>
351 <listitem><para>PKCS #5 Password Based Encryption with MD2 and DES CBC</para></listitem>
352 <listitem><para>PKCS #5 Password Based Encryption with MD5 and DES CBC</para></listitem>
353 <listitem><para>PKCS #5 Password Based Encryption with SHA1 and DES CBC</para></listitem>
354 </itemizedlist>
355 </listitem>
356 </varlistentry>
357 </variablelist>
358 <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>
359 </refsection>
361 <refsection id="databases"><title>NSS Database Types</title>
362 <para>NSS originally used BerkeleyDB databases to store security information.
363 The last versions of these <emphasis>legacy</emphasis> databases are:</para>
364 <itemizedlist>
365 <listitem>
366 <para>
367 cert8.db for certificates
368 </para>
369 </listitem>
370 <listitem>
371 <para>
372 key3.db for keys
373 </para>
374 </listitem>
375 <listitem>
376 <para>
377 secmod.db for PKCS #11 module information
378 </para>
379 </listitem>
380 </itemizedlist>
382 <para>BerkeleyDB has performance limitations, though, which prevent it from being easily used by multiple applications simultaneously. NSS has
383 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
384 requires more flexibility to provide a truly shared security database.</para>
386 <para>In 2009, NSS introduced a new set of databases that are SQLite databases rather than
387 BerkleyDB. These new databases provide more accessibility and performance:</para>
388 <itemizedlist>
389 <listitem>
390 <para>
391 cert9.db for certificates
392 </para>
393 </listitem>
394 <listitem>
395 <para>
396 key4.db for keys
397 </para>
398 </listitem>
399 <listitem>
400 <para>
401 pkcs11.txt, which is listing of all of the PKCS #11 modules contained in a new subdirectory in the security databases directory
402 </para>
403 </listitem>
404 </itemizedlist>
406 <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>
408 <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.
409 Using the SQLite databases must be manually specified by using the <command>sql:</command> prefix with the given security directory. For example:</para>
411 <programlisting># pk12util -i /tmp/cert-files/users.p12 -d sql:/home/my/sharednssdb</programlisting>
413 <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>
414 <programlisting>export NSS_DEFAULT_DB_TYPE="sql"</programlisting>
416 <para>This line can be set added to the <filename>~/.bashrc</filename> file to make the change permanent.</para>
418 <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>
419 <itemizedlist>
420 <listitem>
421 <para>
422 https://wiki.mozilla.org/NSS_Shared_DB_Howto</para>
423 </listitem>
424 </itemizedlist>
425 <para>For an engineering draft on the changes in the shared NSS databases, see the NSS project wiki:</para>
426 <itemizedlist>
427 <listitem>
428 <para>
429 https://wiki.mozilla.org/NSS_Shared_DB
430 </para>
431 </listitem>
432 </itemizedlist>
433 </refsection>
435 <refsection id="seealso">
436 <title>See Also</title>
437 <para>certutil (1)</para>
438 <para>modutil (1)</para>
440 <para>The NSS wiki has information on the new database design and how to configure applications to use it.</para>
441 <itemizedlist>
442 <listitem>
443 <para>
444 https://wiki.mozilla.org/NSS_Shared_DB_Howto</para>
445 </listitem>
446 <listitem>
447 <para>
448 https://wiki.mozilla.org/NSS_Shared_DB
449 </para>
450 </listitem>
451 </itemizedlist>
452 </refsection>
454 <!-- don't change -->
455 <refsection id="resources">
456 <title>Additional Resources</title>
457 <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>
458 <para>Mailing lists: https://lists.mozilla.org/listinfo/dev-tech-crypto</para>
459 <para>IRC: Freenode at #dogtag-pki</para>
460 </refsection>
462 <!-- fill in your name first; keep the other names for reference -->
463 <refsection id="authors">
464 <title>Authors</title>
465 <para>The NSS tools were written and maintained by developers with Netscape, Red Hat, Sun, Oracle, Mozilla, and Google.</para>
466 <para>
467 Authors: Elio Maldonado <emaldona@redhat.com>, Deon Lackey <dlackey@redhat.com>.
468 </para>
469 </refsection>
471 <!-- don't change -->
472 <refsection id="license">
473 <title>LICENSE</title>
474 <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/.
475 </para>
476 </refsection>
478 </refentry>