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