openssl-pkcs12.pod.in 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. =pod
  2. {- OpenSSL::safe::output_do_not_edit_headers(); -}
  3. =head1 NAME
  4. openssl-pkcs12 - PKCS#12 file command
  5. =head1 SYNOPSIS
  6. B<openssl> B<pkcs12>
  7. [B<-help>]
  8. [B<-passin> I<arg>]
  9. [B<-passout> I<arg>]
  10. [B<-password> I<arg>]
  11. [B<-twopass>]
  12. [B<-in> I<filename>|I<uri>]
  13. [B<-out> I<filename>]
  14. [B<-nokeys>]
  15. [B<-nocerts>]
  16. [B<-noout>]
  17. [B<-legacy>]
  18. {- $OpenSSL::safe::opt_engine_synopsis -}{- $OpenSSL::safe::opt_provider_synopsis -}
  19. {- $OpenSSL::safe::opt_r_synopsis -}
  20. PKCS#12 input (parsing) options:
  21. [B<-info>]
  22. [B<-nomacver>]
  23. [B<-clcerts>]
  24. [B<-cacerts>]
  25. [B<-aes128>]
  26. [B<-aes192>]
  27. [B<-aes256>]
  28. [B<-aria128>]
  29. [B<-aria192>]
  30. [B<-aria256>]
  31. [B<-camellia128>]
  32. [B<-camellia192>]
  33. [B<-camellia256>]
  34. [B<-des>]
  35. [B<-des3>]
  36. [B<-idea>]
  37. [B<-noenc>]
  38. [B<-nodes>]
  39. PKCS#12 output (export) options:
  40. [B<-export>]
  41. [B<-inkey> I<filename>|I<uri>]
  42. [B<-certfile> I<filename>]
  43. [B<-passcerts> I<arg>]
  44. [B<-chain>]
  45. [B<-untrusted> I<filename>]
  46. {- $OpenSSL::safe::opt_trust_synopsis -}
  47. [B<-name> I<name>]
  48. [B<-caname> I<name>]
  49. [B<-CSP> I<name>]
  50. [B<-LMK>]
  51. [B<-keyex>]
  52. [B<-keysig>]
  53. [B<-keypbe> I<cipher>]
  54. [B<-certpbe> I<cipher>]
  55. [B<-descert>]
  56. [B<-macalg> I<digest>]
  57. [B<-iter> I<count>]
  58. [B<-noiter>]
  59. [B<-nomaciter>]
  60. [B<-maciter>]
  61. [B<-macsaltlen>]
  62. [B<-nomac>]
  63. [B<-jdktrust> I<usage>]
  64. =head1 DESCRIPTION
  65. This command allows PKCS#12 files (sometimes referred to as
  66. PFX files) to be created and parsed. PKCS#12 files are used by several
  67. programs including Netscape, MSIE and MS Outlook.
  68. =head1 OPTIONS
  69. There are a lot of options the meaning of some depends of whether a PKCS#12 file
  70. is being created or parsed. By default a PKCS#12 file is parsed.
  71. A PKCS#12 file can be created by using the B<-export> option (see below).
  72. The PKCS#12 export encryption and MAC options such as B<-certpbe> and B<-iter>
  73. and many further options such as B<-chain> are relevant only with B<-export>.
  74. Conversely, the options regarding encryption of private keys when outputting
  75. PKCS#12 input are relevant only when the B<-export> option is not given.
  76. The default encryption algorithm is AES-256-CBC with PBKDF2 for key derivation.
  77. When encountering problems loading legacy PKCS#12 files that involve,
  78. for example, RC2-40-CBC,
  79. try using the B<-legacy> option and, if needed, the B<-provider-path> option.
  80. =over 4
  81. =item B<-help>
  82. Print out a usage message.
  83. =item B<-passin> I<arg>
  84. The password source for the input, and for encrypting any private keys that
  85. are output.
  86. For more information about the format of B<arg>
  87. see L<openssl-passphrase-options(1)>.
  88. =item B<-passout> I<arg>
  89. The password source for output files.
  90. =item B<-password> I<arg>
  91. With B<-export>, B<-password> is equivalent to B<-passout>,
  92. otherwise it is equivalent to B<-passin>.
  93. =item B<-twopass>
  94. Prompt for separate integrity and encryption passwords: most software
  95. always assumes these are the same so this option will render such
  96. PKCS#12 files unreadable. Cannot be used in combination with the options
  97. B<-password>, B<-passin> if importing from PKCS#12, or B<-passout> if exporting.
  98. =item B<-nokeys>
  99. No private keys will be output.
  100. =item B<-nocerts>
  101. No certificates will be output.
  102. =item B<-noout>
  103. This option inhibits all credentials output,
  104. and so the input is just verified.
  105. =item B<-legacy>
  106. Use legacy mode of operation and automatically load the legacy provider.
  107. If OpenSSL is not installed system-wide,
  108. it is necessary to also use, for example, C<-provider-path ./providers>
  109. or to set the environment variable B<OPENSSL_MODULES>
  110. to point to the directory where the providers can be found.
  111. In the legacy mode, the default algorithm for certificate encryption
  112. is RC2_CBC or 3DES_CBC depending on whether the RC2 cipher is enabled
  113. in the build. The default algorithm for private key encryption is 3DES_CBC.
  114. If the legacy option is not specified, then the legacy provider is not loaded
  115. and the default encryption algorithm for both certificates and private keys is
  116. AES_256_CBC with PBKDF2 for key derivation.
  117. {- $OpenSSL::safe::opt_engine_item -}
  118. {- $OpenSSL::safe::opt_provider_item -}
  119. {- $OpenSSL::safe::opt_r_item -}
  120. =back
  121. =head2 PKCS#12 input (parsing) options
  122. =over 4
  123. =item B<-in> I<filename>|I<uri>
  124. This specifies the input filename or URI.
  125. Standard input is used by default.
  126. Without the B<-export> option this must be PKCS#12 file to be parsed.
  127. For use with the B<-export> option
  128. see the L</PKCS#12 output (export) options> section.
  129. =item B<-out> I<filename>
  130. The filename to write certificates and private keys to, standard output by
  131. default. They are all written in PEM format.
  132. =item B<-info>
  133. Output additional information about the PKCS#12 file structure, algorithms
  134. used and iteration counts.
  135. =item B<-nomacver>
  136. Don't attempt to verify the integrity MAC.
  137. =item B<-clcerts>
  138. Only output client certificates (not CA certificates).
  139. =item B<-cacerts>
  140. Only output CA certificates (not client certificates).
  141. =item B<-aes128>, B<-aes192>, B<-aes256>
  142. Use AES to encrypt private keys before outputting.
  143. =item B<-aria128>, B<-aria192>, B<-aria256>
  144. Use ARIA to encrypt private keys before outputting.
  145. =item B<-camellia128>, B<-camellia192>, B<-camellia256>
  146. Use Camellia to encrypt private keys before outputting.
  147. =item B<-des>
  148. Use DES to encrypt private keys before outputting.
  149. =item B<-des3>
  150. Use triple DES to encrypt private keys before outputting.
  151. =item B<-idea>
  152. Use IDEA to encrypt private keys before outputting.
  153. =item B<-noenc>
  154. Don't encrypt private keys at all.
  155. =item B<-nodes>
  156. This option is deprecated since OpenSSL 3.0; use B<-noenc> instead.
  157. =back
  158. =head2 PKCS#12 output (export) options
  159. =over 4
  160. =item B<-export>
  161. This option specifies that a PKCS#12 file will be created rather than
  162. parsed.
  163. =item B<-out> I<filename>
  164. This specifies filename to write the PKCS#12 file to. Standard output is used
  165. by default.
  166. =item B<-in> I<filename>|I<uri>
  167. This specifies the input filename or URI.
  168. Standard input is used by default.
  169. With the B<-export> option this is a file with certificates and a key,
  170. or a URI that refers to a key accessed via an engine.
  171. The order of credentials in a file doesn't matter but one private key and
  172. its corresponding certificate should be present. If additional
  173. certificates are present they will also be included in the PKCS#12 output file.
  174. =item B<-inkey> I<filename>|I<uri>
  175. The private key input for PKCS12 output.
  176. If this option is not specified then the input file (B<-in> argument) must
  177. contain a private key.
  178. If no engine is used, the argument is taken as a file.
  179. If the B<-engine> option is used or the URI has prefix C<org.openssl.engine:>
  180. then the rest of the URI is taken as key identifier for the given engine.
  181. =item B<-certfile> I<filename>
  182. An input file with extra certificates to be added to the PKCS#12 output
  183. if the B<-export> option is given.
  184. =item B<-passcerts> I<arg>
  185. The password source for certificate input such as B<-certfile>
  186. and B<-untrusted>.
  187. For more information about the format of B<arg> see
  188. L<openssl-passphrase-options(1)>.
  189. =item B<-chain>
  190. If this option is present then the certificate chain of the end entity
  191. certificate is built and included in the PKCS#12 output file.
  192. The end entity certificate is the first one read from the B<-in> file
  193. if no key is given, else the first certificate matching the given key.
  194. The standard CA trust store is used for chain building,
  195. as well as any untrusted CA certificates given with the B<-untrusted> option.
  196. =item B<-untrusted> I<filename>
  197. An input file of untrusted certificates that may be used
  198. for chain building, which is relevant only when a PKCS#12 file is created
  199. with the B<-export> option and the B<-chain> option is given as well.
  200. Any certificates that are actually part of the chain are added to the output.
  201. {- $OpenSSL::safe::opt_trust_item -}
  202. =item B<-name> I<friendlyname>
  203. This specifies the "friendly name" for the certificates and private key. This
  204. name is typically displayed in list boxes by software importing the file.
  205. =item B<-caname> I<friendlyname>
  206. This specifies the "friendly name" for other certificates. This option may be
  207. used multiple times to specify names for all certificates in the order they
  208. appear. Netscape ignores friendly names on other certificates whereas MSIE
  209. displays them.
  210. =item B<-CSP> I<name>
  211. Write I<name> as a Microsoft CSP name.
  212. The password source for the input, and for encrypting any private keys that
  213. are output.
  214. For more information about the format of B<arg>
  215. see L<openssl-passphrase-options(1)>.
  216. =item B<-LMK>
  217. Add the "Local Key Set" identifier to the attributes.
  218. =item B<-keyex>|B<-keysig>
  219. Specifies that the private key is to be used for key exchange or just signing.
  220. This option is only interpreted by MSIE and similar MS software. Normally
  221. "export grade" software will only allow 512 bit RSA keys to be used for
  222. encryption purposes but arbitrary length keys for signing. The B<-keysig>
  223. option marks the key for signing only. Signing only keys can be used for
  224. S/MIME signing, authenticode (ActiveX control signing) and SSL client
  225. authentication, however, due to a bug only MSIE 5.0 and later support
  226. the use of signing only keys for SSL client authentication.
  227. =item B<-keypbe> I<alg>, B<-certpbe> I<alg>
  228. These options allow the algorithm used to encrypt the private key and
  229. certificates to be selected. Any PKCS#5 v1.5 or PKCS#12 PBE algorithm name
  230. can be used (see L</NOTES> section for more information). If a cipher name
  231. (as output by C<openssl list -cipher-algorithms>) is specified then it
  232. is used with PKCS#5 v2.0. For interoperability reasons it is advisable to only
  233. use PKCS#12 algorithms.
  234. Special value C<NONE> disables encryption of the private key and certificates.
  235. =item B<-descert>
  236. Encrypt the certificates using triple DES. By default the private
  237. key and the certificates are encrypted using AES-256-CBC unless
  238. the '-legacy' option is used. If '-descert' is used with the '-legacy'
  239. then both, the private key and the certificates are encrypted using triple DES.
  240. =item B<-macalg> I<digest>
  241. Specify the MAC digest algorithm. If not included SHA256 will be used.
  242. =item B<-iter> I<count>
  243. This option specifies the iteration count for the encryption key and MAC. The
  244. default value is 2048.
  245. To discourage attacks by using large dictionaries of common passwords the
  246. algorithm that derives keys from passwords can have an iteration count applied
  247. to it: this causes a certain part of the algorithm to be repeated and slows it
  248. down. The MAC is used to check the file integrity but since it will normally
  249. have the same password as the keys and certificates it could also be attacked.
  250. =item B<-noiter>, B<-nomaciter>
  251. By default both encryption and MAC iteration counts are set to 2048, using
  252. these options the MAC and encryption iteration counts can be set to 1, since
  253. this reduces the file security you should not use these options unless you
  254. really have to. Most software supports both MAC and encryption iteration counts.
  255. MSIE 4.0 doesn't support MAC iteration counts so it needs the B<-nomaciter>
  256. option.
  257. =item B<-maciter>
  258. This option is included for compatibility with previous versions, it used
  259. to be needed to use MAC iterations counts but they are now used by default.
  260. =item B<-macsaltlen>
  261. This option specifies the salt length in bytes for the MAC. The salt length
  262. should be at least 16 bytes as per NIST SP 800-132. The default value
  263. is 8 bytes for backwards compatibility.
  264. =item B<-nomac>
  265. Do not attempt to provide the MAC integrity. This can be useful with the FIPS
  266. provider as the PKCS12 MAC requires PKCS12KDF which is not an approved FIPS
  267. algorithm and cannot be supported by the FIPS provider.
  268. =item B<-jdktrust>
  269. Export pkcs12 file in a format compatible with Java keystore usage. This option
  270. accepts a string parameter indicating the trust oid name to be granted to the
  271. certificate it is associated with. Currently only "anyExtendedKeyUsage" is
  272. defined. Note that, as Java keystores do not accept PKCS12 files with both
  273. trusted certificates and keypairs, use of this option implies the setting of the
  274. B<-nokeys> option
  275. =back
  276. =head1 NOTES
  277. Although there are a large number of options most of them are very rarely
  278. used. For PKCS#12 file parsing only B<-in> and B<-out> need to be used
  279. for PKCS#12 file creation B<-export> and B<-name> are also used.
  280. If none of the B<-clcerts>, B<-cacerts> or B<-nocerts> options are present
  281. then all certificates will be output in the order they appear in the input
  282. PKCS#12 files. There is no guarantee that the first certificate present is
  283. the one corresponding to the private key.
  284. Certain software which tries to get a private key and the corresponding
  285. certificate might assume that the first certificate in the file is the one
  286. corresponding to the private key, but that may not always be the case.
  287. Using the B<-clcerts> option will solve this problem by only
  288. outputting the certificate corresponding to the private key. If the CA
  289. certificates are required then they can be output to a separate file using
  290. the B<-nokeys> B<-cacerts> options to just output CA certificates.
  291. The B<-keypbe> and B<-certpbe> algorithms allow the precise encryption
  292. algorithms for private keys and certificates to be specified. Normally
  293. the defaults are fine but occasionally software can't handle triple DES
  294. encrypted private keys, then the option B<-keypbe> I<PBE-SHA1-RC2-40> can
  295. be used to reduce the private key encryption to 40 bit RC2. A complete
  296. description of all algorithms is contained in L<openssl-pkcs8(1)>.
  297. Prior 1.1 release passwords containing non-ASCII characters were encoded
  298. in non-compliant manner, which limited interoperability, in first hand
  299. with Windows. But switching to standard-compliant password encoding
  300. poses problem accessing old data protected with broken encoding. For
  301. this reason even legacy encodings is attempted when reading the
  302. data. If you use PKCS#12 files in production application you are advised
  303. to convert the data, because implemented heuristic approach is not
  304. MT-safe, its sole goal is to facilitate the data upgrade with this
  305. command.
  306. =head1 EXAMPLES
  307. Parse a PKCS#12 file and output it to a PEM file:
  308. openssl pkcs12 -in file.p12 -out file.pem
  309. Output only client certificates to a file:
  310. openssl pkcs12 -in file.p12 -clcerts -out file.pem
  311. Don't encrypt the private key:
  312. openssl pkcs12 -in file.p12 -out file.pem -noenc
  313. Print some info about a PKCS#12 file:
  314. openssl pkcs12 -in file.p12 -info -noout
  315. Print some info about a PKCS#12 file in legacy mode:
  316. openssl pkcs12 -in file.p12 -info -noout -legacy
  317. Create a PKCS#12 file from a PEM file that may contain a key and certificates:
  318. openssl pkcs12 -export -in file.pem -out file.p12 -name "My PSE"
  319. Include some extra certificates:
  320. openssl pkcs12 -export -in file.pem -out file.p12 -name "My PSE" \
  321. -certfile othercerts.pem
  322. Export a PKCS#12 file with data from a certificate PEM file and from a further
  323. PEM file containing a key, with default algorithms as in the legacy provider:
  324. openssl pkcs12 -export -in cert.pem -inkey key.pem -out file.p12 -legacy
  325. =head1 SEE ALSO
  326. L<openssl(1)>,
  327. L<openssl-pkcs8(1)>,
  328. L<ossl_store-file(7)>
  329. =head1 HISTORY
  330. The B<-engine> option was deprecated in OpenSSL 3.0.
  331. The B<-nodes> option was deprecated in OpenSSL 3.0, too; use B<-noenc> instead.
  332. =head1 COPYRIGHT
  333. Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.
  334. Licensed under the Apache License 2.0 (the "License"). You may not use
  335. this file except in compliance with the License. You can obtain a copy
  336. in the file LICENSE in the source distribution or at
  337. L<https://www.openssl.org/source/license.html>.
  338. =cut