113d40330Schristos=pod 213d40330Schristos 313d40330Schristos=head1 NAME 413d40330Schristos 5b0d17251SchristosPKCS12_create, PKCS12_create_ex - create a PKCS#12 structure 613d40330Schristos 713d40330Schristos=head1 SYNOPSIS 813d40330Schristos 913d40330Schristos #include <openssl/pkcs12.h> 1013d40330Schristos 1113d40330Schristos PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey, 1213d40330Schristos X509 *cert, STACK_OF(X509) *ca, 1313d40330Schristos int nid_key, int nid_cert, int iter, int mac_iter, int keytype); 14b0d17251Schristos PKCS12 *PKCS12_create_ex(const char *pass, const char *name, EVP_PKEY *pkey, 15b0d17251Schristos X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, 16b0d17251Schristos int iter, int mac_iter, int keytype, 17b0d17251Schristos OSSL_LIB_CTX *ctx, const char *propq); 1813d40330Schristos 1913d40330Schristos=head1 DESCRIPTION 2013d40330Schristos 2113d40330SchristosPKCS12_create() creates a PKCS#12 structure. 2213d40330Schristos 23b0d17251SchristosI<pass> is the passphrase to use. I<name> is the B<friendlyName> to use for 24b0d17251Schristosthe supplied certificate and key. I<pkey> is the private key to include in 25b0d17251Schristosthe structure and I<cert> its corresponding certificates. I<ca>, if not B<NULL> 2613d40330Schristosis an optional set of certificates to also include in the structure. 2713d40330Schristos 28b0d17251SchristosI<nid_key> and I<nid_cert> are the encryption algorithms that should be used 2913d40330Schristosfor the key and certificate respectively. The modes 30b0d17251SchristosGCM, CCM, XTS, and OCB are unsupported. I<iter> is the encryption algorithm 31b0d17251Schristositeration count to use and I<mac_iter> is the MAC iteration count to use. 32b0d17251SchristosI<keytype> is the type of key. 33b0d17251Schristos 34b0d17251SchristosPKCS12_create_ex() is identical to PKCS12_create() but allows for a library context 35b0d17251SchristosI<ctx> and property query I<propq> to be used to select algorithm implementations. 3613d40330Schristos 3713d40330Schristos=head1 NOTES 3813d40330Schristos 39b0d17251SchristosThe parameters I<nid_key>, I<nid_cert>, I<iter>, I<mac_iter> and I<keytype> 4013d40330Schristoscan all be set to zero and sensible defaults will be used. 4113d40330Schristos 42b0d17251SchristosThese defaults are: AES password based encryption (PBES2 with PBKDF2 and 43b0d17251SchristosAES-256-CBC) for private keys and certificates, the PBKDF2 and MAC key 44b0d17251Schristosderivation iteration count of B<PKCS12_DEFAULT_ITER> (currently 2048), and 454778aedeSchristosMAC algorithm HMAC with SHA2-256. The MAC key derivation algorithm used 464778aedeSchristosfor the outer PKCS#12 structure is PKCS12KDF. 4713d40330Schristos 4813d40330SchristosThe default MAC iteration count is 1 in order to retain compatibility with 4913d40330Schristosold software which did not interpret MAC iteration counts. If such compatibility 50b0d17251Schristosis not required then I<mac_iter> should be set to PKCS12_DEFAULT_ITER. 5113d40330Schristos 52b0d17251SchristosI<keytype> adds a flag to the store private key. This is a non standard extension 5313d40330Schristosthat is only currently interpreted by MSIE. If set to zero the flag is omitted, 5413d40330Schristosif set to B<KEY_SIG> the key can be used for signing only, if set to B<KEY_EX> 5513d40330Schristosit can be used for signing and encryption. This option was useful for old 5613d40330Schristosexport grade software which could use signing only keys of arbitrary size but 5713d40330Schristoshad restrictions on the permissible sizes of keys which could be used for 5813d40330Schristosencryption. 5913d40330Schristos 60*0e2e28bcSchristosIf I<name> is B<NULL> and I<cert> contains an I<alias> then this will be 61*0e2e28bcSchristosused for the corresponding B<friendlyName> in the PKCS12 structure instead. 62*0e2e28bcSchristosSimilarly, if I<pkey> is NULL and I<cert> contains a I<keyid> then this will be 63*0e2e28bcSchristosused for the corresponding B<localKeyID> in the PKCS12 structure instead of the 64*0e2e28bcSchristosid calculated from the I<pkey>. 65*0e2e28bcSchristos 66*0e2e28bcSchristosFor all certificates in I<ca> then if a certificate contains an I<alias> or 67*0e2e28bcSchristosI<keyid> then this will be used for the corresponding B<friendlyName> or 68*0e2e28bcSchristosB<localKeyID> in the PKCS12 structure. 6913d40330Schristos 70b0d17251SchristosEither I<pkey>, I<cert> or both can be B<NULL> to indicate that no key or 7113d40330Schristoscertificate is required. In previous versions both had to be present or 7213d40330Schristosa fatal error is returned. 7313d40330Schristos 74b0d17251SchristosI<nid_key> or I<nid_cert> can be set to -1 indicating that no encryption 7513d40330Schristosshould be used. 7613d40330Schristos 77b0d17251SchristosI<mac_iter> can be set to -1 and the MAC will then be omitted entirely. 784778aedeSchristosThis can be useful when running with the FIPS provider as the PKCS12KDF 794778aedeSchristosis not a FIPS approvable algorithm. 8013d40330Schristos 8113d40330SchristosPKCS12_create() makes assumptions regarding the encoding of the given pass 8213d40330Schristosphrase. 8313d40330SchristosSee L<passphrase-encoding(7)> for more information. 8413d40330Schristos 8513d40330Schristos=head1 RETURN VALUES 8613d40330Schristos 8713d40330SchristosPKCS12_create() returns a valid B<PKCS12> structure or NULL if an error occurred. 8813d40330Schristos 89b0d17251Schristos=head1 CONFORMING TO 90b0d17251Schristos 91b0d17251SchristosIETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>) 92b0d17251Schristos 9313d40330Schristos=head1 SEE ALSO 9413d40330Schristos 954778aedeSchristosL<EVP_KDF-PKCS12KDF(7)>, 9613d40330SchristosL<d2i_PKCS12(3)>, 974778aedeSchristosL<OSSL_PROVIDER-FIPS(7)>, 9813d40330SchristosL<passphrase-encoding(7)> 9913d40330Schristos 100b0d17251Schristos=head1 HISTORY 101b0d17251Schristos 102b0d17251SchristosPKCS12_create_ex() was added in OpenSSL 3.0. 103b0d17251Schristos 104b0d17251SchristosThe defaults for encryption algorithms, MAC algorithm, and the MAC key 105b0d17251Schristosderivation iteration count were changed in OpenSSL 3.0 to more modern 106b0d17251Schristosstandards. 107b0d17251Schristos 10813d40330Schristos=head1 COPYRIGHT 10913d40330Schristos 110*0e2e28bcSchristosCopyright 2002-2024 The OpenSSL Project Authors. All Rights Reserved. 11113d40330Schristos 112b0d17251SchristosLicensed under the Apache License 2.0 (the "License"). You may not use 11313d40330Schristosthis file except in compliance with the License. You can obtain a copy 11413d40330Schristosin the file LICENSE in the source distribution or at 11513d40330SchristosL<https://www.openssl.org/source/license.html>. 11613d40330Schristos 11713d40330Schristos=cut 118