159191Skris 259191Skris=pod 359191Skris 459191Skris=head1 NAME 559191Skris 659191Skrispkcs12 - PKCS#12 file utility 759191Skris 859191Skris=head1 SYNOPSIS 959191Skris 1059191SkrisB<openssl> B<pkcs12> 1159191Skris[B<-export>] 1259191Skris[B<-chain>] 1359191Skris[B<-inkey filename>] 1459191Skris[B<-certfile filename>] 1559191Skris[B<-name name>] 1659191Skris[B<-caname name>] 1759191Skris[B<-in filename>] 1859191Skris[B<-out filename>] 1959191Skris[B<-noout>] 2059191Skris[B<-nomacver>] 2159191Skris[B<-nocerts>] 2259191Skris[B<-clcerts>] 2359191Skris[B<-cacerts>] 2459191Skris[B<-nokeys>] 2559191Skris[B<-info>] 26238405Sjkim[B<-des | -des3 | -idea | -aes128 | -aes192 | -aes256 | -camellia128 | -camellia192 | -camellia256 | -nodes>] 2759191Skris[B<-noiter>] 28238405Sjkim[B<-maciter | -nomaciter | -nomac>] 2959191Skris[B<-twopass>] 3059191Skris[B<-descert>] 31238405Sjkim[B<-certpbe cipher>] 32238405Sjkim[B<-keypbe cipher>] 33238405Sjkim[B<-macalg digest>] 3459191Skris[B<-keyex>] 3559191Skris[B<-keysig>] 3659191Skris[B<-password arg>] 3759191Skris[B<-passin arg>] 3859191Skris[B<-passout arg>] 3959191Skris[B<-rand file(s)>] 40238405Sjkim[B<-CAfile file>] 41238405Sjkim[B<-CApath dir>] 42238405Sjkim[B<-CSP name>] 4359191Skris 4459191Skris=head1 DESCRIPTION 4559191Skris 4659191SkrisThe B<pkcs12> command allows PKCS#12 files (sometimes referred to as 4759191SkrisPFX files) to be created and parsed. PKCS#12 files are used by several 4859191Skrisprograms including Netscape, MSIE and MS Outlook. 4959191Skris 5059191Skris=head1 COMMAND OPTIONS 5159191Skris 5259191SkrisThere are a lot of options the meaning of some depends of whether a PKCS#12 file 53238405Sjkimis being created or parsed. By default a PKCS#12 file is parsed. A PKCS#12 5459191Skrisfile can be created by using the B<-export> option (see below). 5559191Skris 5659191Skris=head1 PARSING OPTIONS 5759191Skris 5859191Skris=over 4 5959191Skris 6059191Skris=item B<-in filename> 6159191Skris 6259191SkrisThis specifies filename of the PKCS#12 file to be parsed. Standard input is used 6359191Skrisby default. 6459191Skris 6559191Skris=item B<-out filename> 6659191Skris 67238405SjkimThe filename to write certificates and private keys to, standard output by 68238405Sjkimdefault. They are all written in PEM format. 6959191Skris 70264331Sjkim=item B<-passin arg> 7159191Skris 72238405Sjkimthe PKCS#12 file (i.e. input file) password source. For more information about 73238405Sjkimthe format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in 7459191SkrisL<openssl(1)|openssl(1)>. 7559191Skris 7659191Skris=item B<-passout arg> 7759191Skris 78264331Sjkimpass phrase source to encrypt any outputted private keys with. For more 79238405Sjkiminformation about the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section 80238405Sjkimin L<openssl(1)|openssl(1)>. 8159191Skris 82264331Sjkim=item B<-password arg> 83264331Sjkim 84264331SjkimWith -export, -password is equivalent to -passout. 85264331SjkimOtherwise, -password is equivalent to -passin. 86264331Sjkim 8759191Skris=item B<-noout> 8859191Skris 89238405Sjkimthis option inhibits output of the keys and certificates to the output file 90238405Sjkimversion of the PKCS#12 file. 9159191Skris 9259191Skris=item B<-clcerts> 9359191Skris 9459191Skrisonly output client certificates (not CA certificates). 9559191Skris 9659191Skris=item B<-cacerts> 9759191Skris 9859191Skrisonly output CA certificates (not client certificates). 9959191Skris 10059191Skris=item B<-nocerts> 10159191Skris 10259191Skrisno certificates at all will be output. 10359191Skris 10459191Skris=item B<-nokeys> 10559191Skris 10659191Skrisno private keys will be output. 10759191Skris 10859191Skris=item B<-info> 10959191Skris 11059191Skrisoutput additional information about the PKCS#12 file structure, algorithms used and 11159191Skrisiteration counts. 11259191Skris 11359191Skris=item B<-des> 11459191Skris 11559191Skrisuse DES to encrypt private keys before outputting. 11659191Skris 11759191Skris=item B<-des3> 11859191Skris 11959191Skrisuse triple DES to encrypt private keys before outputting, this is the default. 12059191Skris 12159191Skris=item B<-idea> 12259191Skris 12359191Skrisuse IDEA to encrypt private keys before outputting. 12459191Skris 125238405Sjkim=item B<-aes128>, B<-aes192>, B<-aes256> 126238405Sjkim 127238405Sjkimuse AES to encrypt private keys before outputting. 128238405Sjkim 129238405Sjkim=item B<-camellia128>, B<-camellia192>, B<-camellia256> 130238405Sjkim 131238405Sjkimuse Camellia to encrypt private keys before outputting. 132238405Sjkim 13359191Skris=item B<-nodes> 13459191Skris 13559191Skrisdon't encrypt the private keys at all. 13659191Skris 13759191Skris=item B<-nomacver> 13859191Skris 13959191Skrisdon't attempt to verify the integrity MAC before reading the file. 14059191Skris 14159191Skris=item B<-twopass> 14259191Skris 14359191Skrisprompt for separate integrity and encryption passwords: most software 14459191Skrisalways assumes these are the same so this option will render such 14559191SkrisPKCS#12 files unreadable. 14659191Skris 14759191Skris=back 14859191Skris 14959191Skris=head1 FILE CREATION OPTIONS 15059191Skris 15159191Skris=over 4 15259191Skris 15359191Skris=item B<-export> 15459191Skris 15559191SkrisThis option specifies that a PKCS#12 file will be created rather than 15659191Skrisparsed. 15759191Skris 15859191Skris=item B<-out filename> 15959191Skris 16059191SkrisThis specifies filename to write the PKCS#12 file to. Standard output is used 16159191Skrisby default. 16259191Skris 16359191Skris=item B<-in filename> 16459191Skris 165238405SjkimThe filename to read certificates and private keys from, standard input by 166238405Sjkimdefault. They must all be in PEM format. The order doesn't matter but one 167238405Sjkimprivate key and its corresponding certificate should be present. If additional 168238405Sjkimcertificates are present they will also be included in the PKCS#12 file. 16959191Skris 17059191Skris=item B<-inkey filename> 17159191Skris 17259191Skrisfile to read private key from. If not present then a private key must be present 17359191Skrisin the input file. 17459191Skris 17559191Skris=item B<-name friendlyname> 17659191Skris 177238405SjkimThis specifies the "friendly name" for the certificate and private key. This 178238405Sjkimname is typically displayed in list boxes by software importing the file. 17959191Skris 18059191Skris=item B<-certfile filename> 18159191Skris 18259191SkrisA filename to read additional certificates from. 18359191Skris 18459191Skris=item B<-caname friendlyname> 18559191Skris 18659191SkrisThis specifies the "friendly name" for other certificates. This option may be 18759191Skrisused multiple times to specify names for all certificates in the order they 18859191Skrisappear. Netscape ignores friendly names on other certificates whereas MSIE 18959191Skrisdisplays them. 19059191Skris 19159191Skris=item B<-pass arg>, B<-passout arg> 19259191Skris 19359191Skristhe PKCS#12 file (i.e. output file) password source. For more information about 19459191Skristhe format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in 19559191SkrisL<openssl(1)|openssl(1)>. 19659191Skris 19759191Skris=item B<-passin password> 19859191Skris 19959191Skrispass phrase source to decrypt any input private keys with. For more information 20059191Skrisabout the format of B<arg> see the B<PASS PHRASE ARGUMENTS> section in 20159191SkrisL<openssl(1)|openssl(1)>. 20259191Skris 20359191Skris=item B<-chain> 20459191Skris 20559191Skrisif this option is present then an attempt is made to include the entire 20659191Skriscertificate chain of the user certificate. The standard CA store is used 20759191Skrisfor this search. If the search fails it is considered a fatal error. 20859191Skris 20959191Skris=item B<-descert> 21059191Skris 21159191Skrisencrypt the certificate using triple DES, this may render the PKCS#12 21259191Skrisfile unreadable by some "export grade" software. By default the private 21359191Skriskey is encrypted using triple DES and the certificate using 40 bit RC2. 21459191Skris 21559191Skris=item B<-keypbe alg>, B<-certpbe alg> 21659191Skris 21759191Skristhese options allow the algorithm used to encrypt the private key and 218238405Sjkimcertificates to be selected. Any PKCS#5 v1.5 or PKCS#12 PBE algorithm name 219238405Sjkimcan be used (see B<NOTES> section for more information). If a a cipher name 220238405Sjkim(as output by the B<list-cipher-algorithms> command is specified then it 221238405Sjkimis used with PKCS#5 v2.0. For interoperability reasons it is advisable to only 222238405Sjkimuse PKCS#12 algorithms. 22359191Skris 22459191Skris=item B<-keyex|-keysig> 22559191Skris 22659191Skrisspecifies that the private key is to be used for key exchange or just signing. 22759191SkrisThis option is only interpreted by MSIE and similar MS software. Normally 22859191Skris"export grade" software will only allow 512 bit RSA keys to be used for 22959191Skrisencryption purposes but arbitrary length keys for signing. The B<-keysig> 23059191Skrisoption marks the key for signing only. Signing only keys can be used for 23159191SkrisS/MIME signing, authenticode (ActiveX control signing) and SSL client 23259191Skrisauthentication, however due to a bug only MSIE 5.0 and later support 23359191Skristhe use of signing only keys for SSL client authentication. 23459191Skris 235238405Sjkim=item B<-macalg digest> 236238405Sjkim 237238405Sjkimspecify the MAC digest algorithm. If not included them SHA1 will be used. 238238405Sjkim 23959191Skris=item B<-nomaciter>, B<-noiter> 24059191Skris 24159191Skristhese options affect the iteration counts on the MAC and key algorithms. 24259191SkrisUnless you wish to produce files compatible with MSIE 4.0 you should leave 24359191Skristhese options alone. 24459191Skris 24559191SkrisTo discourage attacks by using large dictionaries of common passwords the 24659191Skrisalgorithm that derives keys from passwords can have an iteration count applied 24759191Skristo it: this causes a certain part of the algorithm to be repeated and slows it 24859191Skrisdown. The MAC is used to check the file integrity but since it will normally 24959191Skrishave the same password as the keys and certificates it could also be attacked. 25059191SkrisBy default both MAC and encryption iteration counts are set to 2048, using 25159191Skristhese options the MAC and encryption iteration counts can be set to 1, since 25259191Skristhis reduces the file security you should not use these options unless you 25359191Skrisreally have to. Most software supports both MAC and key iteration counts. 25459191SkrisMSIE 4.0 doesn't support MAC iteration counts so it needs the B<-nomaciter> 25559191Skrisoption. 25659191Skris 25759191Skris=item B<-maciter> 25859191Skris 25959191SkrisThis option is included for compatibility with previous versions, it used 26059191Skristo be needed to use MAC iterations counts but they are now used by default. 26159191Skris 262238405Sjkim=item B<-nomac> 263238405Sjkim 264238405Sjkimdon't attempt to provide the MAC integrity. 265238405Sjkim 26659191Skris=item B<-rand file(s)> 26759191Skris 26859191Skrisa file or files containing random data used to seed the random number 26959191Skrisgenerator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>). 27059191SkrisMultiple files can be specified separated by a OS-dependent character. 27168651SkrisThe separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for 27259191Skrisall others. 27359191Skris 274238405Sjkim=item B<-CAfile file> 275238405Sjkim 276238405SjkimCA storage as a file. 277238405Sjkim 278238405Sjkim=item B<-CApath dir> 279238405Sjkim 280238405SjkimCA storage as a directory. This directory must be a standard certificate 281238405Sjkimdirectory: that is a hash of each subject name (using B<x509 -hash>) should be 282238405Sjkimlinked to each certificate. 283238405Sjkim 284238405Sjkim=item B<-CSP name> 285238405Sjkim 286238405Sjkimwrite B<name> as a Microsoft CSP name. 287238405Sjkim 28859191Skris=back 28959191Skris 29059191Skris=head1 NOTES 29159191Skris 29259191SkrisAlthough there are a large number of options most of them are very rarely 29359191Skrisused. For PKCS#12 file parsing only B<-in> and B<-out> need to be used 29459191Skrisfor PKCS#12 file creation B<-export> and B<-name> are also used. 29559191Skris 29659191SkrisIf none of the B<-clcerts>, B<-cacerts> or B<-nocerts> options are present 29759191Skristhen all certificates will be output in the order they appear in the input 29859191SkrisPKCS#12 files. There is no guarantee that the first certificate present is 29959191Skristhe one corresponding to the private key. Certain software which requires 30059191Skrisa private key and certificate and assumes the first certificate in the 30159191Skrisfile is the one corresponding to the private key: this may not always 30259191Skrisbe the case. Using the B<-clcerts> option will solve this problem by only 303109998Smarkmoutputting the certificate corresponding to the private key. If the CA 30459191Skriscertificates are required then they can be output to a separate file using 30559191Skristhe B<-nokeys -cacerts> options to just output CA certificates. 30659191Skris 30759191SkrisThe B<-keypbe> and B<-certpbe> algorithms allow the precise encryption 30859191Skrisalgorithms for private keys and certificates to be specified. Normally 30959191Skristhe defaults are fine but occasionally software can't handle triple DES 31059191Skrisencrypted private keys, then the option B<-keypbe PBE-SHA1-RC2-40> can 31159191Skrisbe used to reduce the private key encryption to 40 bit RC2. A complete 31259191Skrisdescription of all algorithms is contained in the B<pkcs8> manual page. 31359191Skris 31459191Skris=head1 EXAMPLES 31559191Skris 31659191SkrisParse a PKCS#12 file and output it to a file: 31759191Skris 31859191Skris openssl pkcs12 -in file.p12 -out file.pem 31959191Skris 32059191SkrisOutput only client certificates to a file: 32159191Skris 32259191Skris openssl pkcs12 -in file.p12 -clcerts -out file.pem 32359191Skris 32459191SkrisDon't encrypt the private key: 32559191Skris 32659191Skris openssl pkcs12 -in file.p12 -out file.pem -nodes 32759191Skris 32859191SkrisPrint some info about a PKCS#12 file: 32959191Skris 33059191Skris openssl pkcs12 -in file.p12 -info -noout 33159191Skris 33259191SkrisCreate a PKCS#12 file: 33359191Skris 33459191Skris openssl pkcs12 -export -in file.pem -out file.p12 -name "My Certificate" 33559191Skris 33659191SkrisInclude some extra certificates: 33759191Skris 33859191Skris openssl pkcs12 -export -in file.pem -out file.p12 -name "My Certificate" \ 33959191Skris -certfile othercerts.pem 34059191Skris 34159191Skris=head1 BUGS 34259191Skris 34359191SkrisSome would argue that the PKCS#12 standard is one big bug :-) 34459191Skris 34576866SkrisVersions of OpenSSL before 0.9.6a had a bug in the PKCS#12 key generation 34676866Skrisroutines. Under rare circumstances this could produce a PKCS#12 file encrypted 34776866Skriswith an invalid key. As a result some PKCS#12 files which triggered this bug 34876866Skrisfrom other implementations (MSIE or Netscape) could not be decrypted 34976866Skrisby OpenSSL and similarly OpenSSL could produce PKCS#12 files which could 35076866Skrisnot be decrypted by other implementations. The chances of producing such 35176866Skrisa file are relatively small: less than 1 in 256. 35276866Skris 35376866SkrisA side effect of fixing this bug is that any old invalidly encrypted PKCS#12 35476866Skrisfiles cannot no longer be parsed by the fixed version. Under such circumstances 35576866Skristhe B<pkcs12> utility will report that the MAC is OK but fail with a decryption 35676866Skriserror when extracting private keys. 35776866Skris 35876866SkrisThis problem can be resolved by extracting the private keys and certificates 35976866Skrisfrom the PKCS#12 file using an older version of OpenSSL and recreating the PKCS#12 36076866Skrisfile from the keys and certificates using a newer version of OpenSSL. For example: 36176866Skris 36276866Skris old-openssl -in bad.p12 -out keycerts.pem 36376866Skris openssl -in keycerts.pem -export -name "My PKCS#12 file" -out fixed.p12 36476866Skris 36559191Skris=head1 SEE ALSO 36659191Skris 36759191SkrisL<pkcs8(1)|pkcs8(1)> 36859191Skris 369