PKCS12_create.pod 3.9 KB

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