PKCS12_create.pod 5.0 KB

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