]>
Commit | Line | Data |
---|---|---|
5fbb02fc DSH |
1 | =pod |
2 | ||
3 | =head1 NAME | |
4 | ||
e869c867 | 5 | PKCS12_create, PKCS12_create_ex, PKCS12_create_cb, PKCS12_create_ex2 - create a PKCS#12 structure |
5fbb02fc DSH |
6 | |
7 | =head1 SYNOPSIS | |
8 | ||
9 | #include <openssl/pkcs12.h> | |
10 | ||
82af00fb F |
11 | PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey, |
12 | X509 *cert, STACK_OF(X509) *ca, | |
13 | int nid_key, int nid_cert, int iter, int mac_iter, int keytype); | |
b536880c JS |
14 | PKCS12 *PKCS12_create_ex(const char *pass, const char *name, EVP_PKEY *pkey, |
15 | X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, | |
16 | int iter, int mac_iter, int keytype, | |
17 | OSSL_LIB_CTX *ctx, const char *propq); | |
5fbb02fc | 18 | |
e869c867 GW |
19 | typedef int PKCS12_create_cb(PKCS12_SAFEBAG *bag, void *cbarg); |
20 | ||
21 | PKCS12 *PKCS12_create_ex2(const char *pass, const char *name, EVP_PKEY *pkey, | |
22 | X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, | |
23 | int iter, int mac_iter, int keytype, | |
24 | OSSL_LIB_CTX *ctx, const char *propq, | |
25 | PKCS12_create_cb *cb, void *cbarg); | |
5fbb02fc DSH |
26 | =head1 DESCRIPTION |
27 | ||
28 | PKCS12_create() creates a PKCS#12 structure. | |
29 | ||
762970bd TM |
30 | I<pass> is the passphrase to use. I<name> is the B<friendlyName> to use for |
31 | the supplied certificate and key. I<pkey> is the private key to include in | |
b536880c | 32 | the structure and I<cert> its corresponding certificates. I<ca>, if not B<NULL> |
5fbb02fc DSH |
33 | is an optional set of certificates to also include in the structure. |
34 | ||
762970bd | 35 | I<nid_key> and I<nid_cert> are the encryption algorithms that should be used |
49c9c1b3 | 36 | for the key and certificate respectively. The modes |
762970bd TM |
37 | GCM, CCM, XTS, and OCB are unsupported. I<iter> is the encryption algorithm |
38 | iteration count to use and I<mac_iter> is the MAC iteration count to use. | |
39 | I<keytype> is the type of key. | |
5fbb02fc | 40 | |
b536880c JS |
41 | PKCS12_create_ex() is identical to PKCS12_create() but allows for a library context |
42 | I<ctx> and property query I<propq> to be used to select algorithm implementations. | |
43 | ||
e869c867 | 44 | PKCS12_create_ex2() is identical to PKCS12_create_ex() but allows for a user defined |
f02d3311 | 45 | callback I<cb> of type B<PKCS12_create_cb> to be specified and also allows for an |
e869c867 GW |
46 | optional argument I<cbarg> to be passed back to the callback. |
47 | ||
48 | The I<cb> if specified will be called for every safebag added to the | |
49 | PKCS12 structure and allows for optional application processing on the associated | |
50 | safebag. For example one such use could be to add attributes to the safebag. | |
51 | ||
5fbb02fc DSH |
52 | =head1 NOTES |
53 | ||
762970bd | 54 | The parameters I<nid_key>, I<nid_cert>, I<iter>, I<mac_iter> and I<keytype> |
5fbb02fc DSH |
55 | can all be set to zero and sensible defaults will be used. |
56 | ||
762970bd TM |
57 | These defaults are: AES password based encryption (PBES2 with PBKDF2 and |
58 | AES-256-CBC) for private keys and certificates, the PBKDF2 and MAC key | |
59 | derivation iteration count of B<PKCS12_DEFAULT_ITER> (currently 2048), and | |
4ee8c1fb VK |
60 | MAC algorithm HMAC with SHA2-256. The MAC key derivation algorithm used |
61 | for the outer PKCS#12 structure is PKCS12KDF. | |
5fbb02fc | 62 | |
b536880c JS |
63 | The default MAC iteration count is 1 in order to retain compatibility with |
64 | old software which did not interpret MAC iteration counts. If such compatibility | |
65 | is not required then I<mac_iter> should be set to PKCS12_DEFAULT_ITER. | |
66 | ||
762970bd | 67 | I<keytype> adds a flag to the store private key. This is a non standard extension |
5fbb02fc DSH |
68 | that is only currently interpreted by MSIE. If set to zero the flag is omitted, |
69 | if set to B<KEY_SIG> the key can be used for signing only, if set to B<KEY_EX> | |
70 | it can be used for signing and encryption. This option was useful for old | |
71 | export grade software which could use signing only keys of arbitrary size but | |
72 | had restrictions on the permissible sizes of keys which could be used for | |
73 | encryption. | |
74 | ||
3348713a MC |
75 | If I<name> is B<NULL> and I<cert> contains an I<alias> then this will be |
76 | used for the corresponding B<friendlyName> in the PKCS12 structure instead. | |
77 | Similarly, if I<pkey> is NULL and I<cert> contains a I<keyid> then this will be | |
78 | used for the corresponding B<localKeyID> in the PKCS12 structure instead of the | |
79 | id calculated from the I<pkey>. | |
80 | ||
81 | For all certificates in I<ca> then if a certificate contains an I<alias> or | |
82 | I<keyid> then this will be used for the corresponding B<friendlyName> or | |
83 | B<localKeyID> in the PKCS12 structure. | |
8c4b69d3 | 84 | |
b536880c | 85 | Either I<pkey>, I<cert> or both can be B<NULL> to indicate that no key or |
186bb907 | 86 | certificate is required. In previous versions both had to be present or |
5fbb02fc DSH |
87 | a fatal error is returned. |
88 | ||
762970bd | 89 | I<nid_key> or I<nid_cert> can be set to -1 indicating that no encryption |
1bc74519 | 90 | should be used. |
5fbb02fc | 91 | |
762970bd | 92 | I<mac_iter> can be set to -1 and the MAC will then be omitted entirely. |
4ee8c1fb VK |
93 | This can be useful when running with the FIPS provider as the PKCS12KDF |
94 | is not a FIPS approvable algorithm. | |
5fbb02fc | 95 | |
84814344 RL |
96 | PKCS12_create() makes assumptions regarding the encoding of the given pass |
97 | phrase. | |
98 | See L<passphrase-encoding(7)> for more information. | |
99 | ||
e869c867 GW |
100 | If I<cb> is specified, then it should return 1 for success and -1 for a fatal error. |
101 | A return of 0 is intended to mean to not add the bag after all. | |
102 | ||
1f13ad31 PY |
103 | =head1 RETURN VALUES |
104 | ||
105 | PKCS12_create() returns a valid B<PKCS12> structure or NULL if an error occurred. | |
106 | ||
b536880c JS |
107 | =head1 CONFORMING TO |
108 | ||
109 | IETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>) | |
110 | ||
5fbb02fc DSH |
111 | =head1 SEE ALSO |
112 | ||
4ee8c1fb | 113 | L<EVP_KDF-PKCS12KDF(7)>, |
84814344 | 114 | L<d2i_PKCS12(3)>, |
4ee8c1fb | 115 | L<OSSL_PROVIDER-FIPS(7)>, |
84814344 | 116 | L<passphrase-encoding(7)> |
5fbb02fc | 117 | |
762970bd TM |
118 | =head1 HISTORY |
119 | ||
b536880c | 120 | PKCS12_create_ex() was added in OpenSSL 3.0. |
45ada6b9 | 121 | PKCS12_create_ex2() was added in OpenSSL 3.2. |
b536880c | 122 | |
762970bd TM |
123 | The defaults for encryption algorithms, MAC algorithm, and the MAC key |
124 | derivation iteration count were changed in OpenSSL 3.0 to more modern | |
125 | standards. | |
126 | ||
e2f92610 RS |
127 | =head1 COPYRIGHT |
128 | ||
b6461792 | 129 | Copyright 2002-2024 The OpenSSL Project Authors. All Rights Reserved. |
e2f92610 | 130 | |
4746f25a | 131 | Licensed under the Apache License 2.0 (the "License"). You may not use |
e2f92610 RS |
132 | this file except in compliance with the License. You can obtain a copy |
133 | in the file LICENSE in the source distribution or at | |
134 | L<https://www.openssl.org/source/license.html>. | |
135 | ||
136 | =cut |