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