| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "PKCS12_CREATE 3SSL" |
| 58 |
.TH PKCS12_CREATE 3SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
PKCS12_create, PKCS12_create_ex, PKCS12_create_cb, PKCS12_create_ex2 \- create a PKCS#12 structure |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 1 |
| 68 |
\& #include <openssl/pkcs12.h> |
| 69 |
\& |
| 70 |
\& PKCS12 *PKCS12_create(const char *pass, const char *name, EVP_PKEY *pkey, |
| 71 |
\& X509 *cert, STACK_OF(X509) *ca, |
| 72 |
\& int nid_key, int nid_cert, int iter, int mac_iter, int keytype); |
| 73 |
\& PKCS12 *PKCS12_create_ex(const char *pass, const char *name, EVP_PKEY *pkey, |
| 74 |
\& X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, |
| 75 |
\& int iter, int mac_iter, int keytype, |
| 76 |
\& OSSL_LIB_CTX *ctx, const char *propq); |
| 77 |
\& |
| 78 |
\& typedef int PKCS12_create_cb(PKCS12_SAFEBAG *bag, void *cbarg); |
| 79 |
\& |
| 80 |
\& PKCS12 *PKCS12_create_ex2(const char *pass, const char *name, EVP_PKEY *pkey, |
| 81 |
\& X509 *cert, STACK_OF(X509) *ca, int nid_key, int nid_cert, |
| 82 |
\& int iter, int mac_iter, int keytype, |
| 83 |
\& OSSL_LIB_CTX *ctx, const char *propq, |
| 84 |
\& PKCS12_create_cb *cb, void *cbarg); |
| 85 |
\&=head1 DESCRIPTION |
| 86 |
.Ve |
| 87 |
.PP |
| 88 |
\&\fBPKCS12_create()\fR creates a PKCS#12 structure. |
| 89 |
.PP |
| 90 |
\&\fIpass\fR is the passphrase to use. \fIname\fR is the \fBfriendlyName\fR to use for |
| 91 |
the supplied certificate and key. \fIpkey\fR is the private key to include in |
| 92 |
the structure and \fIcert\fR its corresponding certificates. \fIca\fR, if not \fBNULL\fR |
| 93 |
is an optional set of certificates to also include in the structure. |
| 94 |
.PP |
| 95 |
\&\fInid_key\fR and \fInid_cert\fR are the encryption algorithms that should be used |
| 96 |
for the key and certificate respectively. The modes |
| 97 |
GCM, CCM, XTS, and OCB are unsupported. \fIiter\fR is the encryption algorithm |
| 98 |
iteration count to use and \fImac_iter\fR is the MAC iteration count to use. |
| 99 |
\&\fIkeytype\fR is the type of key. |
| 100 |
.PP |
| 101 |
\&\fBPKCS12_create_ex()\fR is identical to \fBPKCS12_create()\fR but allows for a library context |
| 102 |
\&\fIctx\fR and property query \fIpropq\fR to be used to select algorithm implementations. |
| 103 |
.PP |
| 104 |
\&\fBPKCS12_create_ex2()\fR is identical to \fBPKCS12_create_ex()\fR but allows for a user defined |
| 105 |
callback \fIcb\fR of type \fBPKCS12_create_cb\fR to be specified and also allows for an |
| 106 |
optional argument \fIcbarg\fR to be passed back to the callback. |
| 107 |
.PP |
| 108 |
The \fIcb\fR if specified will be called for every safebag added to the |
| 109 |
PKCS12 structure and allows for optional application processing on the associated |
| 110 |
safebag. For example one such use could be to add attributes to the safebag. |
| 111 |
.SH NOTES |
| 112 |
.IX Header "NOTES" |
| 113 |
The parameters \fInid_key\fR, \fInid_cert\fR, \fIiter\fR, \fImac_iter\fR and \fIkeytype\fR |
| 114 |
can all be set to zero and sensible defaults will be used. |
| 115 |
.PP |
| 116 |
These defaults are: AES password based encryption (PBES2 with PBKDF2 and |
| 117 |
AES\-256\-CBC) for private keys and certificates, the PBKDF2 and MAC key |
| 118 |
derivation iteration count of \fBPKCS12_DEFAULT_ITER\fR (currently 2048), and |
| 119 |
MAC algorithm HMAC with SHA2\-256. The MAC key derivation algorithm used |
| 120 |
for the outer PKCS#12 structure is PKCS12KDF. |
| 121 |
.PP |
| 122 |
The default MAC iteration count is 1 in order to retain compatibility with |
| 123 |
old software which did not interpret MAC iteration counts. If such compatibility |
| 124 |
is not required then \fImac_iter\fR should be set to PKCS12_DEFAULT_ITER. |
| 125 |
.PP |
| 126 |
\&\fIkeytype\fR adds a flag to the store private key. This is a non standard extension |
| 127 |
that is only currently interpreted by MSIE. If set to zero the flag is omitted, |
| 128 |
if set to \fBKEY_SIG\fR the key can be used for signing only, if set to \fBKEY_EX\fR |
| 129 |
it can be used for signing and encryption. This option was useful for old |
| 130 |
export grade software which could use signing only keys of arbitrary size but |
| 131 |
had restrictions on the permissible sizes of keys which could be used for |
| 132 |
encryption. |
| 133 |
.PP |
| 134 |
If \fIname\fR is \fBNULL\fR and \fIcert\fR contains an \fIalias\fR then this will be |
| 135 |
used for the corresponding \fBfriendlyName\fR in the PKCS12 structure instead. |
| 136 |
Similarly, if \fIpkey\fR is NULL and \fIcert\fR contains a \fIkeyid\fR then this will be |
| 137 |
used for the corresponding \fBlocalKeyID\fR in the PKCS12 structure instead of the |
| 138 |
id calculated from the \fIpkey\fR. |
| 139 |
.PP |
| 140 |
For all certificates in \fIca\fR then if a certificate contains an \fIalias\fR or |
| 141 |
\&\fIkeyid\fR then this will be used for the corresponding \fBfriendlyName\fR or |
| 142 |
\&\fBlocalKeyID\fR in the PKCS12 structure. |
| 143 |
.PP |
| 144 |
Either \fIpkey\fR, \fIcert\fR or both can be \fBNULL\fR to indicate that no key or |
| 145 |
certificate is required. In previous versions both had to be present or |
| 146 |
a fatal error is returned. |
| 147 |
.PP |
| 148 |
\&\fInid_key\fR or \fInid_cert\fR can be set to \-1 indicating that no encryption |
| 149 |
should be used. |
| 150 |
.PP |
| 151 |
\&\fImac_iter\fR can be set to \-1 and the MAC will then be omitted entirely. |
| 152 |
This can be useful when running with the FIPS provider as the PKCS12KDF |
| 153 |
is not a FIPS approvable algorithm. |
| 154 |
.PP |
| 155 |
\&\fBPKCS12_create()\fR makes assumptions regarding the encoding of the given pass |
| 156 |
phrase. |
| 157 |
See \fBpassphrase\-encoding\fR\|(7) for more information. |
| 158 |
.PP |
| 159 |
If \fIcb\fR is specified, then it should return 1 for success and \-1 for a fatal error. |
| 160 |
A return of 0 is intended to mean to not add the bag after all. |
| 161 |
.SH "RETURN VALUES" |
| 162 |
.IX Header "RETURN VALUES" |
| 163 |
\&\fBPKCS12_create()\fR returns a valid \fBPKCS12\fR structure or NULL if an error occurred. |
| 164 |
.SH "CONFORMING TO" |
| 165 |
.IX Header "CONFORMING TO" |
| 166 |
IETF RFC 7292 (<https://tools.ietf.org/html/rfc7292>) |
| 167 |
.SH "SEE ALSO" |
| 168 |
.IX Header "SEE ALSO" |
| 169 |
\&\fBEVP_KDF\-PKCS12KDF\fR\|(7), |
| 170 |
\&\fBd2i_PKCS12\fR\|(3), |
| 171 |
\&\fBOSSL_PROVIDER\-FIPS\fR\|(7), |
| 172 |
\&\fBpassphrase\-encoding\fR\|(7) |
| 173 |
.SH HISTORY |
| 174 |
.IX Header "HISTORY" |
| 175 |
\&\fBPKCS12_create_ex()\fR was added in OpenSSL 3.0. |
| 176 |
\&\fBPKCS12_create_ex2()\fR was added in OpenSSL 3.2. |
| 177 |
.PP |
| 178 |
The defaults for encryption algorithms, MAC algorithm, and the MAC key |
| 179 |
derivation iteration count were changed in OpenSSL 3.0 to more modern |
| 180 |
standards. |
| 181 |
.SH COPYRIGHT |
| 182 |
.IX Header "COPYRIGHT" |
| 183 |
Copyright 2002\-2024 The OpenSSL Project Authors. All Rights Reserved. |
| 184 |
.PP |
| 185 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 186 |
this file except in compliance with the License. You can obtain a copy |
| 187 |
in the file LICENSE in the source distribution or at |
| 188 |
<https://www.openssl.org/source/license.html>. |