xref: /onnv-gate/usr/src/common/openssl/doc/apps/pkcs12.pod (revision 2175:b0b2f052a486)
1*2175Sjp161948
2*2175Sjp161948=pod
3*2175Sjp161948
4*2175Sjp161948=head1 NAME
5*2175Sjp161948
6*2175Sjp161948pkcs12 - PKCS#12 file utility
7*2175Sjp161948
8*2175Sjp161948=head1 SYNOPSIS
9*2175Sjp161948
10*2175Sjp161948B<openssl> B<pkcs12>
11*2175Sjp161948[B<-export>]
12*2175Sjp161948[B<-chain>]
13*2175Sjp161948[B<-inkey filename>]
14*2175Sjp161948[B<-certfile filename>]
15*2175Sjp161948[B<-name name>]
16*2175Sjp161948[B<-caname name>]
17*2175Sjp161948[B<-in filename>]
18*2175Sjp161948[B<-out filename>]
19*2175Sjp161948[B<-noout>]
20*2175Sjp161948[B<-nomacver>]
21*2175Sjp161948[B<-nocerts>]
22*2175Sjp161948[B<-clcerts>]
23*2175Sjp161948[B<-cacerts>]
24*2175Sjp161948[B<-nokeys>]
25*2175Sjp161948[B<-info>]
26*2175Sjp161948[B<-des>]
27*2175Sjp161948[B<-des3>]
28*2175Sjp161948[B<-idea>]
29*2175Sjp161948[B<-nodes>]
30*2175Sjp161948[B<-noiter>]
31*2175Sjp161948[B<-maciter>]
32*2175Sjp161948[B<-twopass>]
33*2175Sjp161948[B<-descert>]
34*2175Sjp161948[B<-certpbe>]
35*2175Sjp161948[B<-keypbe>]
36*2175Sjp161948[B<-keyex>]
37*2175Sjp161948[B<-keysig>]
38*2175Sjp161948[B<-password arg>]
39*2175Sjp161948[B<-passin arg>]
40*2175Sjp161948[B<-passout arg>]
41*2175Sjp161948[B<-rand file(s)>]
42*2175Sjp161948
43*2175Sjp161948=head1 DESCRIPTION
44*2175Sjp161948
45*2175Sjp161948The B<pkcs12> command allows PKCS#12 files (sometimes referred to as
46*2175Sjp161948PFX files) to be created and parsed. PKCS#12 files are used by several
47*2175Sjp161948programs including Netscape, MSIE and MS Outlook.
48*2175Sjp161948
49*2175Sjp161948=head1 COMMAND OPTIONS
50*2175Sjp161948
51*2175Sjp161948There are a lot of options the meaning of some depends of whether a PKCS#12 file
52*2175Sjp161948is being created or parsed. By default a PKCS#12 file is parsed a PKCS#12
53*2175Sjp161948file can be created by using the B<-export> option (see below).
54*2175Sjp161948
55*2175Sjp161948=head1 PARSING OPTIONS
56*2175Sjp161948
57*2175Sjp161948=over 4
58*2175Sjp161948
59*2175Sjp161948=item B<-in filename>
60*2175Sjp161948
61*2175Sjp161948This specifies filename of the PKCS#12 file to be parsed. Standard input is used
62*2175Sjp161948by default.
63*2175Sjp161948
64*2175Sjp161948=item B<-out filename>
65*2175Sjp161948
66*2175Sjp161948The filename to write certificates and private keys to, standard output by default.
67*2175Sjp161948They are all written in PEM format.
68*2175Sjp161948
69*2175Sjp161948=item B<-pass arg>, B<-passin arg>
70*2175Sjp161948
71*2175Sjp161948the PKCS#12 file (i.e. input file) password source. For more information about the
72*2175Sjp161948format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
73*2175Sjp161948L<openssl(1)|openssl(1)>.
74*2175Sjp161948
75*2175Sjp161948=item B<-passout arg>
76*2175Sjp161948
77*2175Sjp161948pass phrase source to encrypt any outputed private keys with. For more information
78*2175Sjp161948about the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
79*2175Sjp161948L<openssl(1)|openssl(1)>.
80*2175Sjp161948
81*2175Sjp161948=item B<-noout>
82*2175Sjp161948
83*2175Sjp161948this option inhibits output of the keys and certificates to the output file version
84*2175Sjp161948of the PKCS#12 file.
85*2175Sjp161948
86*2175Sjp161948=item B<-clcerts>
87*2175Sjp161948
88*2175Sjp161948only output client certificates (not CA certificates).
89*2175Sjp161948
90*2175Sjp161948=item B<-cacerts>
91*2175Sjp161948
92*2175Sjp161948only output CA certificates (not client certificates).
93*2175Sjp161948
94*2175Sjp161948=item B<-nocerts>
95*2175Sjp161948
96*2175Sjp161948no certificates at all will be output.
97*2175Sjp161948
98*2175Sjp161948=item B<-nokeys>
99*2175Sjp161948
100*2175Sjp161948no private keys will be output.
101*2175Sjp161948
102*2175Sjp161948=item B<-info>
103*2175Sjp161948
104*2175Sjp161948output additional information about the PKCS#12 file structure, algorithms used and
105*2175Sjp161948iteration counts.
106*2175Sjp161948
107*2175Sjp161948=item B<-des>
108*2175Sjp161948
109*2175Sjp161948use DES to encrypt private keys before outputting.
110*2175Sjp161948
111*2175Sjp161948=item B<-des3>
112*2175Sjp161948
113*2175Sjp161948use triple DES to encrypt private keys before outputting, this is the default.
114*2175Sjp161948
115*2175Sjp161948=item B<-idea>
116*2175Sjp161948
117*2175Sjp161948use IDEA to encrypt private keys before outputting.
118*2175Sjp161948
119*2175Sjp161948=item B<-nodes>
120*2175Sjp161948
121*2175Sjp161948don't encrypt the private keys at all.
122*2175Sjp161948
123*2175Sjp161948=item B<-nomacver>
124*2175Sjp161948
125*2175Sjp161948don't attempt to verify the integrity MAC before reading the file.
126*2175Sjp161948
127*2175Sjp161948=item B<-twopass>
128*2175Sjp161948
129*2175Sjp161948prompt for separate integrity and encryption passwords: most software
130*2175Sjp161948always assumes these are the same so this option will render such
131*2175Sjp161948PKCS#12 files unreadable.
132*2175Sjp161948
133*2175Sjp161948=back
134*2175Sjp161948
135*2175Sjp161948=head1 FILE CREATION OPTIONS
136*2175Sjp161948
137*2175Sjp161948=over 4
138*2175Sjp161948
139*2175Sjp161948=item B<-export>
140*2175Sjp161948
141*2175Sjp161948This option specifies that a PKCS#12 file will be created rather than
142*2175Sjp161948parsed.
143*2175Sjp161948
144*2175Sjp161948=item B<-out filename>
145*2175Sjp161948
146*2175Sjp161948This specifies filename to write the PKCS#12 file to. Standard output is used
147*2175Sjp161948by default.
148*2175Sjp161948
149*2175Sjp161948=item B<-in filename>
150*2175Sjp161948
151*2175Sjp161948The filename to read certificates and private keys from, standard input by default.
152*2175Sjp161948They must all be in PEM format. The order doesn't matter but one private key and
153*2175Sjp161948its corresponding certificate should be present. If additional certificates are
154*2175Sjp161948present they will also be included in the PKCS#12 file.
155*2175Sjp161948
156*2175Sjp161948=item B<-inkey filename>
157*2175Sjp161948
158*2175Sjp161948file to read private key from. If not present then a private key must be present
159*2175Sjp161948in the input file.
160*2175Sjp161948
161*2175Sjp161948=item B<-name friendlyname>
162*2175Sjp161948
163*2175Sjp161948This specifies the "friendly name" for the certificate and private key. This name
164*2175Sjp161948is typically displayed in list boxes by software importing the file.
165*2175Sjp161948
166*2175Sjp161948=item B<-certfile filename>
167*2175Sjp161948
168*2175Sjp161948A filename to read additional certificates from.
169*2175Sjp161948
170*2175Sjp161948=item B<-caname friendlyname>
171*2175Sjp161948
172*2175Sjp161948This specifies the "friendly name" for other certificates. This option may be
173*2175Sjp161948used multiple times to specify names for all certificates in the order they
174*2175Sjp161948appear. Netscape ignores friendly names on other certificates whereas MSIE
175*2175Sjp161948displays them.
176*2175Sjp161948
177*2175Sjp161948=item B<-pass arg>, B<-passout arg>
178*2175Sjp161948
179*2175Sjp161948the PKCS#12 file (i.e. output file) password source. For more information about
180*2175Sjp161948the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
181*2175Sjp161948L<openssl(1)|openssl(1)>.
182*2175Sjp161948
183*2175Sjp161948=item B<-passin password>
184*2175Sjp161948
185*2175Sjp161948pass phrase source to decrypt any input private keys with. For more information
186*2175Sjp161948about the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in
187*2175Sjp161948L<openssl(1)|openssl(1)>.
188*2175Sjp161948
189*2175Sjp161948=item B<-chain>
190*2175Sjp161948
191*2175Sjp161948if this option is present then an attempt is made to include the entire
192*2175Sjp161948certificate chain of the user certificate. The standard CA store is used
193*2175Sjp161948for this search. If the search fails it is considered a fatal error.
194*2175Sjp161948
195*2175Sjp161948=item B<-descert>
196*2175Sjp161948
197*2175Sjp161948encrypt the certificate using triple DES, this may render the PKCS#12
198*2175Sjp161948file unreadable by some "export grade" software. By default the private
199*2175Sjp161948key is encrypted using triple DES and the certificate using 40 bit RC2.
200*2175Sjp161948
201*2175Sjp161948=item B<-keypbe alg>, B<-certpbe alg>
202*2175Sjp161948
203*2175Sjp161948these options allow the algorithm used to encrypt the private key and
204*2175Sjp161948certificates to be selected. Although any PKCS#5 v1.5 or PKCS#12 algorithms
205*2175Sjp161948can be selected it is advisable only to use PKCS#12 algorithms. See the list
206*2175Sjp161948in the B<NOTES> section for more information.
207*2175Sjp161948
208*2175Sjp161948=item B<-keyex|-keysig>
209*2175Sjp161948
210*2175Sjp161948specifies that the private key is to be used for key exchange or just signing.
211*2175Sjp161948This option is only interpreted by MSIE and similar MS software. Normally
212*2175Sjp161948"export grade" software will only allow 512 bit RSA keys to be used for
213*2175Sjp161948encryption purposes but arbitrary length keys for signing. The B<-keysig>
214*2175Sjp161948option marks the key for signing only. Signing only keys can be used for
215*2175Sjp161948S/MIME signing, authenticode (ActiveX control signing)  and SSL client
216*2175Sjp161948authentication, however due to a bug only MSIE 5.0 and later support
217*2175Sjp161948the use of signing only keys for SSL client authentication.
218*2175Sjp161948
219*2175Sjp161948=item B<-nomaciter>, B<-noiter>
220*2175Sjp161948
221*2175Sjp161948these options affect the iteration counts on the MAC and key algorithms.
222*2175Sjp161948Unless you wish to produce files compatible with MSIE 4.0 you should leave
223*2175Sjp161948these options alone.
224*2175Sjp161948
225*2175Sjp161948To discourage attacks by using large dictionaries of common passwords the
226*2175Sjp161948algorithm that derives keys from passwords can have an iteration count applied
227*2175Sjp161948to it: this causes a certain part of the algorithm to be repeated and slows it
228*2175Sjp161948down. The MAC is used to check the file integrity but since it will normally
229*2175Sjp161948have the same password as the keys and certificates it could also be attacked.
230*2175Sjp161948By default both MAC and encryption iteration counts are set to 2048, using
231*2175Sjp161948these options the MAC and encryption iteration counts can be set to 1, since
232*2175Sjp161948this reduces the file security you should not use these options unless you
233*2175Sjp161948really have to. Most software supports both MAC and key iteration counts.
234*2175Sjp161948MSIE 4.0 doesn't support MAC iteration counts so it needs the B<-nomaciter>
235*2175Sjp161948option.
236*2175Sjp161948
237*2175Sjp161948=item B<-maciter>
238*2175Sjp161948
239*2175Sjp161948This option is included for compatibility with previous versions, it used
240*2175Sjp161948to be needed to use MAC iterations counts but they are now used by default.
241*2175Sjp161948
242*2175Sjp161948=item B<-rand file(s)>
243*2175Sjp161948
244*2175Sjp161948a file or files containing random data used to seed the random number
245*2175Sjp161948generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
246*2175Sjp161948Multiple files can be specified separated by a OS-dependent character.
247*2175Sjp161948The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
248*2175Sjp161948all others.
249*2175Sjp161948
250*2175Sjp161948=back
251*2175Sjp161948
252*2175Sjp161948=head1 NOTES
253*2175Sjp161948
254*2175Sjp161948Although there are a large number of options most of them are very rarely
255*2175Sjp161948used. For PKCS#12 file parsing only B<-in> and B<-out> need to be used
256*2175Sjp161948for PKCS#12 file creation B<-export> and B<-name> are also used.
257*2175Sjp161948
258*2175Sjp161948If none of the B<-clcerts>, B<-cacerts> or B<-nocerts> options are present
259*2175Sjp161948then all certificates will be output in the order they appear in the input
260*2175Sjp161948PKCS#12 files. There is no guarantee that the first certificate present is
261*2175Sjp161948the one corresponding to the private key. Certain software which requires
262*2175Sjp161948a private key and certificate and assumes the first certificate in the
263*2175Sjp161948file is the one corresponding to the private key: this may not always
264*2175Sjp161948be the case. Using the B<-clcerts> option will solve this problem by only
265*2175Sjp161948outputting the certificate corresponding to the private key. If the CA
266*2175Sjp161948certificates are required then they can be output to a separate file using
267*2175Sjp161948the B<-nokeys -cacerts> options to just output CA certificates.
268*2175Sjp161948
269*2175Sjp161948The B<-keypbe> and B<-certpbe> algorithms allow the precise encryption
270*2175Sjp161948algorithms for private keys and certificates to be specified. Normally
271*2175Sjp161948the defaults are fine but occasionally software can't handle triple DES
272*2175Sjp161948encrypted private keys, then the option B<-keypbe PBE-SHA1-RC2-40> can
273*2175Sjp161948be used to reduce the private key encryption to 40 bit RC2. A complete
274*2175Sjp161948description of all algorithms is contained in the B<pkcs8> manual page.
275*2175Sjp161948
276*2175Sjp161948=head1 EXAMPLES
277*2175Sjp161948
278*2175Sjp161948Parse a PKCS#12 file and output it to a file:
279*2175Sjp161948
280*2175Sjp161948 openssl pkcs12 -in file.p12 -out file.pem
281*2175Sjp161948
282*2175Sjp161948Output only client certificates to a file:
283*2175Sjp161948
284*2175Sjp161948 openssl pkcs12 -in file.p12 -clcerts -out file.pem
285*2175Sjp161948
286*2175Sjp161948Don't encrypt the private key:
287*2175Sjp161948
288*2175Sjp161948 openssl pkcs12 -in file.p12 -out file.pem -nodes
289*2175Sjp161948
290*2175Sjp161948Print some info about a PKCS#12 file:
291*2175Sjp161948
292*2175Sjp161948 openssl pkcs12 -in file.p12 -info -noout
293*2175Sjp161948
294*2175Sjp161948Create a PKCS#12 file:
295*2175Sjp161948
296*2175Sjp161948 openssl pkcs12 -export -in file.pem -out file.p12 -name "My Certificate"
297*2175Sjp161948
298*2175Sjp161948Include some extra certificates:
299*2175Sjp161948
300*2175Sjp161948 openssl pkcs12 -export -in file.pem -out file.p12 -name "My Certificate" \
301*2175Sjp161948  -certfile othercerts.pem
302*2175Sjp161948
303*2175Sjp161948=head1 BUGS
304*2175Sjp161948
305*2175Sjp161948Some would argue that the PKCS#12 standard is one big bug :-)
306*2175Sjp161948
307*2175Sjp161948Versions of OpenSSL before 0.9.6a had a bug in the PKCS#12 key generation
308*2175Sjp161948routines. Under rare circumstances this could produce a PKCS#12 file encrypted
309*2175Sjp161948with an invalid key. As a result some PKCS#12 files which triggered this bug
310*2175Sjp161948from other implementations (MSIE or Netscape) could not be decrypted
311*2175Sjp161948by OpenSSL and similarly OpenSSL could produce PKCS#12 files which could
312*2175Sjp161948not be decrypted by other implementations. The chances of producing such
313*2175Sjp161948a file are relatively small: less than 1 in 256.
314*2175Sjp161948
315*2175Sjp161948A side effect of fixing this bug is that any old invalidly encrypted PKCS#12
316*2175Sjp161948files cannot no longer be parsed by the fixed version. Under such circumstances
317*2175Sjp161948the B<pkcs12> utility will report that the MAC is OK but fail with a decryption
318*2175Sjp161948error when extracting private keys.
319*2175Sjp161948
320*2175Sjp161948This problem can be resolved by extracting the private keys and certificates
321*2175Sjp161948from the PKCS#12 file using an older version of OpenSSL and recreating the PKCS#12
322*2175Sjp161948file from the keys and certificates using a newer version of OpenSSL. For example:
323*2175Sjp161948
324*2175Sjp161948 old-openssl -in bad.p12 -out keycerts.pem
325*2175Sjp161948 openssl -in keycerts.pem -export -name "My PKCS#12 file" -out fixed.p12
326*2175Sjp161948
327*2175Sjp161948=head1 SEE ALSO
328*2175Sjp161948
329*2175Sjp161948L<pkcs8(1)|pkcs8(1)>
330*2175Sjp161948
331