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