2
0

PKCS12_create.pod 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. The MAC key derivation algorithm used
  45. for the outer PKCS#12 structure is PKCS12KDF.
  46. The default MAC iteration count is 1 in order to retain compatibility with
  47. old software which did not interpret MAC iteration counts. If such compatibility
  48. is not required then I<mac_iter> should be set to PKCS12_DEFAULT_ITER.
  49. I<keytype> adds a flag to the store private key. This is a non standard extension
  50. that is only currently interpreted by MSIE. If set to zero the flag is omitted,
  51. if set to B<KEY_SIG> the key can be used for signing only, if set to B<KEY_EX>
  52. it can be used for signing and encryption. This option was useful for old
  53. export grade software which could use signing only keys of arbitrary size but
  54. had restrictions on the permissible sizes of keys which could be used for
  55. encryption.
  56. If I<name> is B<NULL> and I<cert> contains an I<alias> then this will be
  57. used for the corresponding B<friendlyName> in the PKCS12 structure instead.
  58. Similarly, if I<pkey> is NULL and I<cert> contains a I<keyid> then this will be
  59. used for the corresponding B<localKeyID> in the PKCS12 structure instead of the
  60. id calculated from the I<pkey>.
  61. For all certificates in I<ca> then if a certificate contains an I<alias> or
  62. I<keyid> then this will be used for the corresponding B<friendlyName> or
  63. B<localKeyID> in the PKCS12 structure.
  64. Either I<pkey>, I<cert> or both can be B<NULL> to indicate that no key or
  65. certificate is required. In previous versions both had to be present or
  66. a fatal error is returned.
  67. I<nid_key> or I<nid_cert> can be set to -1 indicating that no encryption
  68. should be used.
  69. I<mac_iter> can be set to -1 and the MAC will then be omitted entirely.
  70. This can be useful when running with the FIPS provider as the PKCS12KDF
  71. is not a FIPS approvable algorithm.
  72. PKCS12_create() makes assumptions regarding the encoding of the given pass
  73. phrase.
  74. See L<passphrase-encoding(7)> for more information.
  75. If I<cb> is specified, then it should return 1 for success and -1 for a fatal error.
  76. A return of 0 is intended to mean to not add the bag after all.
  77. =head1 RETURN VALUES
  78. PKCS12_create() returns a valid B<PKCS12> structure or NULL if an error occurred.
  79. =head1 CONFORMING TO
  80. IETF RFC 7292 (L<https://tools.ietf.org/html/rfc7292>)
  81. =head1 SEE ALSO
  82. L<EVP_KDF-PKCS12KDF(7)>,
  83. L<d2i_PKCS12(3)>,
  84. L<OSSL_PROVIDER-FIPS(7)>,
  85. L<passphrase-encoding(7)>
  86. =head1 HISTORY
  87. PKCS12_create_ex() was added in OpenSSL 3.0.
  88. PKCS12_create_ex2() was added in OpenSSL 3.2.
  89. The defaults for encryption algorithms, MAC algorithm, and the MAC key
  90. derivation iteration count were changed in OpenSSL 3.0 to more modern
  91. standards.
  92. =head1 COPYRIGHT
  93. Copyright 2002-2024 The OpenSSL Project Authors. All Rights Reserved.
  94. Licensed under the Apache License 2.0 (the "License"). You may not use
  95. this file except in compliance with the License. You can obtain a copy
  96. in the file LICENSE in the source distribution or at
  97. L<https://www.openssl.org/source/license.html>.
  98. =cut