1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5b077aed3SPierre ProncheryPKCS12_create, PKCS12_create_ex - create a PKCS#12 structure 6e71b7053SJung-uk Kim 7e71b7053SJung-uk Kim=head1 SYNOPSIS 8e71b7053SJung-uk Kim 9e71b7053SJung-uk Kim #include <openssl/pkcs12.h> 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey, 12e71b7053SJung-uk Kim X509 *cert, STACK_OF(X509) *ca, 13e71b7053SJung-uk Kim int nid_key, int nid_cert, int iter, int mac_iter, int keytype); 14b077aed3SPierre Pronchery PKCS12 *PKCS12_create_ex(const char *pass, const char *name, EVP_PKEY *pkey, 15b077aed3SPierre Pronchery X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, 16b077aed3SPierre Pronchery int iter, int mac_iter, int keytype, 17b077aed3SPierre Pronchery OSSL_LIB_CTX *ctx, const char *propq); 18e71b7053SJung-uk Kim 19e71b7053SJung-uk Kim=head1 DESCRIPTION 20e71b7053SJung-uk Kim 21e71b7053SJung-uk KimPKCS12_create() creates a PKCS#12 structure. 22e71b7053SJung-uk Kim 23b077aed3SPierre ProncheryI<pass> is the passphrase to use. I<name> is the B<friendlyName> to use for 24b077aed3SPierre Proncherythe supplied certificate and key. I<pkey> is the private key to include in 25b077aed3SPierre Proncherythe structure and I<cert> its corresponding certificates. I<ca>, if not B<NULL> 26e71b7053SJung-uk Kimis an optional set of certificates to also include in the structure. 27e71b7053SJung-uk Kim 28b077aed3SPierre ProncheryI<nid_key> and I<nid_cert> are the encryption algorithms that should be used 29e71b7053SJung-uk Kimfor the key and certificate respectively. The modes 30b077aed3SPierre ProncheryGCM, CCM, XTS, and OCB are unsupported. I<iter> is the encryption algorithm 31b077aed3SPierre Proncheryiteration count to use and I<mac_iter> is the MAC iteration count to use. 32b077aed3SPierre ProncheryI<keytype> is the type of key. 33b077aed3SPierre Pronchery 34b077aed3SPierre ProncheryPKCS12_create_ex() is identical to PKCS12_create() but allows for a library context 35b077aed3SPierre ProncheryI<ctx> and property query I<propq> to be used to select algorithm implementations. 36e71b7053SJung-uk Kim 37e71b7053SJung-uk Kim=head1 NOTES 38e71b7053SJung-uk Kim 39b077aed3SPierre ProncheryThe parameters I<nid_key>, I<nid_cert>, I<iter>, I<mac_iter> and I<keytype> 40e71b7053SJung-uk Kimcan all be set to zero and sensible defaults will be used. 41e71b7053SJung-uk Kim 42b077aed3SPierre ProncheryThese defaults are: AES password based encryption (PBES2 with PBKDF2 and 43b077aed3SPierre ProncheryAES-256-CBC) for private keys and certificates, the PBKDF2 and MAC key 44b077aed3SPierre Proncheryderivation iteration count of B<PKCS12_DEFAULT_ITER> (currently 2048), and 456f1af0d7SPierre ProncheryMAC algorithm HMAC with SHA2-256. The MAC key derivation algorithm used 466f1af0d7SPierre Proncheryfor the outer PKCS#12 structure is PKCS12KDF. 47e71b7053SJung-uk Kim 48e71b7053SJung-uk KimThe default MAC iteration count is 1 in order to retain compatibility with 49e71b7053SJung-uk Kimold software which did not interpret MAC iteration counts. If such compatibility 50b077aed3SPierre Proncheryis not required then I<mac_iter> should be set to PKCS12_DEFAULT_ITER. 51e71b7053SJung-uk Kim 52b077aed3SPierre ProncheryI<keytype> adds a flag to the store private key. This is a non standard extension 53e71b7053SJung-uk Kimthat is only currently interpreted by MSIE. If set to zero the flag is omitted, 54e71b7053SJung-uk Kimif set to B<KEY_SIG> the key can be used for signing only, if set to B<KEY_EX> 55e71b7053SJung-uk Kimit can be used for signing and encryption. This option was useful for old 56e71b7053SJung-uk Kimexport grade software which could use signing only keys of arbitrary size but 57e71b7053SJung-uk Kimhad restrictions on the permissible sizes of keys which could be used for 58e71b7053SJung-uk Kimencryption. 59e71b7053SJung-uk Kim 60*e0c4386eSCy SchubertIf I<name> is B<NULL> and I<cert> contains an I<alias> then this will be 61*e0c4386eSCy Schubertused for the corresponding B<friendlyName> in the PKCS12 structure instead. 62*e0c4386eSCy SchubertSimilarly, if I<pkey> is NULL and I<cert> contains a I<keyid> then this will be 63*e0c4386eSCy Schubertused for the corresponding B<localKeyID> in the PKCS12 structure instead of the 64*e0c4386eSCy Schubertid calculated from the I<pkey>. 65*e0c4386eSCy Schubert 66*e0c4386eSCy SchubertFor all certificates in I<ca> then if a certificate contains an I<alias> or 67*e0c4386eSCy SchubertI<keyid> then this will be used for the corresponding B<friendlyName> or 68*e0c4386eSCy SchubertB<localKeyID> in the PKCS12 structure. 69e71b7053SJung-uk Kim 70b077aed3SPierre ProncheryEither I<pkey>, I<cert> or both can be B<NULL> to indicate that no key or 71e71b7053SJung-uk Kimcertificate is required. In previous versions both had to be present or 72e71b7053SJung-uk Kima fatal error is returned. 73e71b7053SJung-uk Kim 74b077aed3SPierre ProncheryI<nid_key> or I<nid_cert> can be set to -1 indicating that no encryption 75e71b7053SJung-uk Kimshould be used. 76e71b7053SJung-uk Kim 77b077aed3SPierre ProncheryI<mac_iter> can be set to -1 and the MAC will then be omitted entirely. 786f1af0d7SPierre ProncheryThis can be useful when running with the FIPS provider as the PKCS12KDF 796f1af0d7SPierre Proncheryis not a FIPS approvable algorithm. 80e71b7053SJung-uk Kim 81e71b7053SJung-uk KimPKCS12_create() makes assumptions regarding the encoding of the given pass 82e71b7053SJung-uk Kimphrase. 83e71b7053SJung-uk KimSee L<passphrase-encoding(7)> for more information. 84e71b7053SJung-uk Kim 85e71b7053SJung-uk Kim=head1 RETURN VALUES 86e71b7053SJung-uk Kim 87e71b7053SJung-uk KimPKCS12_create() returns a valid B<PKCS12> structure or NULL if an error occurred. 88e71b7053SJung-uk Kim 89b077aed3SPierre Pronchery=head1 CONFORMING TO 90b077aed3SPierre Pronchery 91b077aed3SPierre ProncheryIETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>) 92b077aed3SPierre Pronchery 93e71b7053SJung-uk Kim=head1 SEE ALSO 94e71b7053SJung-uk Kim 956f1af0d7SPierre ProncheryL<EVP_KDF-PKCS12KDF(7)>, 96e71b7053SJung-uk KimL<d2i_PKCS12(3)>, 976f1af0d7SPierre ProncheryL<OSSL_PROVIDER-FIPS(7)>, 98e71b7053SJung-uk KimL<passphrase-encoding(7)> 99e71b7053SJung-uk Kim 100b077aed3SPierre Pronchery=head1 HISTORY 101b077aed3SPierre Pronchery 102b077aed3SPierre ProncheryPKCS12_create_ex() was added in OpenSSL 3.0. 103b077aed3SPierre Pronchery 104b077aed3SPierre ProncheryThe defaults for encryption algorithms, MAC algorithm, and the MAC key 105b077aed3SPierre Proncheryderivation iteration count were changed in OpenSSL 3.0 to more modern 106b077aed3SPierre Proncherystandards. 107b077aed3SPierre Pronchery 108e71b7053SJung-uk Kim=head1 COPYRIGHT 109e71b7053SJung-uk Kim 110*e0c4386eSCy SchubertCopyright 2002-2024 The OpenSSL Project Authors. All Rights Reserved. 111e71b7053SJung-uk Kim 112b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (the "License"). You may not use 113e71b7053SJung-uk Kimthis file except in compliance with the License. You can obtain a copy 114e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at 115e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>. 116e71b7053SJung-uk Kim 117e71b7053SJung-uk Kim=cut 118