Content-type: text/html
The PKCS #12 utility, pk12util , 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.
Options
Arguments
* 0 - No error
* 1 - User Cancelled
* 2 - Usage error
* 6 - NLS init error
* 8 - Certificate DB open error
* 9 - Key DB open error
* 10 - File initialization error
* 11 - Unicode conversion error
* 12 - Temporary file creation error
* 13 - PKCS11 get slot error
* 14 - PKCS12 decoder start error
* 15 - error read from import file
* 16 - pkcs12 decode error
* 17 - pkcs12 decoder verify error
* 18 - pkcs12 decoder validate bags error
* 19 - pkcs12 decoder import bags error
* 20 - key db conversion version 3 to version 2 error
* 21 - cert db conversion version 7 to version 5 error
* 22 - cert and key dbs patch error
* 23 - get default cert db error
* 24 - find cert by nickname error
* 25 - create export context error
* 26 - PKCS12 add password itegrity error
* 27 - cert and key Safes creation error
* 28 - PKCS12 add cert and key error
Importing Keys and Certificates
The most basic usage of
pk12util
for importing a certificate or key is the PKCS#12 input file (
-i
) and some way to specify the security database being accessed (either
-d
for a directory or
-h
for a token).
pk12util -i p12File [-h tokenname] [-v] [-d dir] [-P dbprefix] [-k slotPasswordFile|-K slotPassword] [-w p12filePasswordFile|-W p12filePassword]
For example:
# pk12util -i /tmp/cert-files/users.p12 -d /etc/pki/nssdb/ Enter a password which will be used to encrypt your keys. The password should be at least 8 characters long, and should contain at least one non-alphabetic character. Enter new password: Re-enter password: Enter password for PKCS12 file: pk12util: PKCS12 IMPORT SUCCESSFUL
Exporting Keys and Certificates
Using the
pk12util
command to export certificates and keys requires both the name of the certificate to extract from the database (
-n
) 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.
pk12util -o p12File -n certname [-c keyCipher] [-C certCipher] [-m|--key_len keyLen] [-n|--cert_key_len certKeyLen] [-d dir] [-P dbprefix] [-k slotPasswordFile|-K slotPassword] [-w p12filePasswordFile|-W p12filePassword]
For example:
# pk12util -o certs.p12 -n Server-Cert -d /etc/pki/nssdb/ Enter password for PKCS12 file: Re-enter password:
Listing Keys and Certificates
The information in a
.p12
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
.p12
file. Alternatively, the
-r
is used to print the certificates and then export them into separate DER binary files, with one certificate in each file. This allows the certificates to be fed to another application, like OpenSSL.
pk12util -l p12File [-h tokenname] [-r] [-d dir] [-P dbprefix] [-k slotPasswordFile|-K slotPassword] [-w p12filePasswordFile|-W p12filePassword]
For example, this prints the default ASCII output:
# pk12util -l certs.p12 Enter password for PKCS12 file: Key(shrouded): Friendly Name: Thawte Freemail Member's Thawte Consulting (Pty) Ltd. ID Encryption algorithm: PKCS #12 V2 PBE With SHA-1 And 3KEY Triple DES-CBC Parameters: Salt: 45:2e:6a:a0:03:4d:7b:a1:63:3c:15:ea:67:37:62:1f Iteration Count: 1 (0x1) Certificate: Data: Version: 3 (0x2) Serial Number: 13 (0xd) Signature Algorithm: PKCS #1 SHA-1 With RSA Encryption Issuer: "E=personal-freemail@thawte.com,CN=Thawte Personal Freemail C A,OU=Certification Services Division,O=Thawte Consulting,L=Cape T own,ST=Western Cape,C=ZA"
For example, this uses the -r argument to output the DER information. Each certificate is also written to a sequentially-number file, beginning with file0001.der and continuing through file000N.der , incrementing the number for every certificate:
# pk12util -l test.p12 -r Enter password for PKCS12 file: Key(shrouded): Friendly Name: Thawte Freemail Member's Thawte Consulting (Pty) Ltd. ID Encryption algorithm: PKCS #12 V2 PBE With SHA-1 And 3KEY Triple DES-CBC Parameters: Salt: 45:2e:6a:a0:03:4d:7b:a1:63:3c:15:ea:67:37:62:1f Iteration Count: 1 (0x1) Certificate Friendly Name: Thawte Personal Freemail Issuing CA - Thawte Consulting Certificate Friendly Name: Thawte Freemail Member's Thawte Consulting (Pty) Ltd. ID
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 PKCS12 V2 PBE with SHA1 and 3KEY Triple DES-cbc for private key encryption. PKCS12 V2 PBE with SHA1 and 40 Bit RC4 is the default for the overall package encryption when not in FIPS mode. When in FIPS mode, there is no package encryption.
The private key is always protected with strong encryption by default.
Several types of ciphers are supported.
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 no security module can perform the requested operation
certutil (1)
NSS is maintained in conjunction with PKI and security-related projects through Mozilla dn Fedora. The most closely-related project is Dogtag PKI, with a project wiki at http://pki.fedoraproject.org/wiki/.
For information specifically about NSS, the NSS project wiki is located at http://www.mozilla.org/projects/security/pki/nss/. The NSS site relates directly to NSS code changes and releases.
Mailing lists: pki-devel@redhat.com and pki-users@redhat.com
The NSS tools were written and maintained by developers with Netscape and now with Red Hat.
Authors: Elio Maldonado <emaldona@redhat.com>, Deon Lackey <dlackey@redhat.com>.
(c) 2010, Red Hat, Inc. Licensed under the GNU Public License version 2.