handle new findings of find-doc-nits for certain typedefs
[openssl.git] / doc / man3 / OSSL_CMP_CTX_new.pod
1 =pod
2
3 =head1 NAME
4
5 OSSL_CMP_CTX_new,
6 OSSL_CMP_CTX_free,
7 OSSL_CMP_CTX_reinit,
8 OSSL_CMP_CTX_set_option,
9 OSSL_CMP_CTX_get_option,
10 OSSL_CMP_CTX_set_log_cb,
11 OSSL_CMP_CTX_set_log_verbosity,
12 OSSL_CMP_CTX_print_errors,
13 OSSL_CMP_CTX_set1_serverPath,
14 OSSL_CMP_CTX_set1_serverName,
15 OSSL_CMP_CTX_set_serverPort,
16 OSSL_CMP_CTX_set1_proxyName,
17 OSSL_CMP_CTX_set_proxyPort,
18 OSSL_CMP_DEFAULT_PORT,
19 OSSL_cmp_http_cb_t,
20 OSSL_CMP_CTX_set_http_cb,
21 OSSL_CMP_CTX_set_http_cb_arg,
22 OSSL_CMP_CTX_get_http_cb_arg,
23 OSSL_cmp_transfer_cb_t,
24 OSSL_CMP_CTX_set_transfer_cb,
25 OSSL_CMP_CTX_set_transfer_cb_arg,
26 OSSL_CMP_CTX_get_transfer_cb_arg,
27 OSSL_CMP_CTX_set1_srvCert,
28 OSSL_CMP_CTX_set1_expected_sender,
29 OSSL_CMP_CTX_set0_trustedStore,
30 OSSL_CMP_CTX_get0_trustedStore,
31 OSSL_CMP_CTX_set1_untrusted_certs,
32 OSSL_CMP_CTX_get0_untrusted_certs,
33 OSSL_CMP_CTX_set1_clCert,
34 OSSL_CMP_CTX_set1_pkey,
35 OSSL_CMP_CTX_set1_referenceValue,
36 OSSL_CMP_CTX_set1_secretValue,
37 OSSL_CMP_CTX_set1_recipient,
38 OSSL_CMP_CTX_push0_geninfo_ITAV,
39 OSSL_CMP_CTX_set1_extraCertsOut,
40 OSSL_CMP_CTX_set0_newPkey,
41 OSSL_CMP_CTX_get0_newPkey,
42 OSSL_CMP_CTX_set1_issuer,
43 OSSL_CMP_CTX_set1_subjectName,
44 OSSL_CMP_CTX_push1_subjectAltName,
45 OSSL_CMP_CTX_set0_reqExtensions,
46 OSSL_CMP_CTX_reqExtensions_have_SAN,
47 OSSL_CMP_CTX_push0_policy,
48 OSSL_CMP_CTX_set1_oldCert,
49 OSSL_CMP_CTX_set1_p10CSR,
50 OSSL_CMP_CTX_push0_genm_ITAV,
51 OSSL_cmp_certConf_cb_t,
52 OSSL_CMP_CTX_set_certConf_cb,
53 OSSL_CMP_CTX_set_certConf_cb_arg,
54 OSSL_CMP_CTX_get_certConf_cb_arg,
55 OSSL_CMP_CTX_get_status,
56 OSSL_CMP_CTX_get0_statusString,
57 OSSL_CMP_CTX_get_failInfoCode,
58 OSSL_CMP_CTX_get0_newCert,
59 OSSL_CMP_CTX_get1_caPubs,
60 OSSL_CMP_CTX_get1_extraCertsIn,
61 OSSL_CMP_CTX_set1_transactionID,
62 OSSL_CMP_CTX_set1_senderNonce
63 - functions for managing the CMP client context data structure
64
65 =head1 SYNOPSIS
66
67  #include <openssl/cmp.h>
68
69  OSSL_CMP_CTX *OSSL_CMP_CTX_new(void);
70  void OSSL_CMP_CTX_free(OSSL_CMP_CTX *ctx);
71  int OSSL_CMP_CTX_reinit(OSSL_CMP_CTX *ctx);
72  int OSSL_CMP_CTX_set_option(OSSL_CMP_CTX *ctx, int opt, int val);
73  int OSSL_CMP_CTX_get_option(const OSSL_CMP_CTX *ctx, int opt);
74
75  /* logging and error reporting: */
76  int OSSL_CMP_CTX_set_log_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_log_cb_t cb);
77  #define OSSL_CMP_CTX_set_log_verbosity(ctx, level)
78  void OSSL_CMP_CTX_print_errors(OSSL_CMP_CTX *ctx);
79
80  /* message transfer: */
81  int OSSL_CMP_CTX_set1_serverPath(OSSL_CMP_CTX *ctx, const char *path);
82  int OSSL_CMP_CTX_set1_serverName(OSSL_CMP_CTX *ctx, const char *name);
83  int OSSL_CMP_CTX_set_serverPort(OSSL_CMP_CTX *ctx, int port);
84  int OSSL_CMP_CTX_set1_proxyName(OSSL_CMP_CTX *ctx, const char *name);
85  int OSSL_CMP_CTX_set_proxyPort(OSSL_CMP_CTX *ctx, int port);
86  #define OSSL_CMP_DEFAULT_PORT 80
87  typedef BIO (*OSSL_cmp_http_cb_t) (OSSL_CMP_CTX *ctx, BIO *hbio,
88                                     unsigned long detail);
89  int OSSL_CMP_CTX_set_http_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_http_cb_t cb);
90  int OSSL_CMP_CTX_set_http_cb_arg(OSSL_CMP_CTX *ctx, void *arg);
91  void *OSSL_CMP_CTX_get_http_cb_arg(const OSSL_CMP_CTX *ctx);
92  typedef int (*OSSL_cmp_transfer_cb_t) (OSSL_CMP_CTX *ctx,
93                                         const OSSL_CMP_MSG *req,
94                                         OSSL_CMP_MSG **res);
95  int OSSL_CMP_CTX_set_transfer_cb(OSSL_CMP_CTX *ctx,
96                                   OSSL_cmp_transfer_cb_t cb);
97  int OSSL_CMP_CTX_set_transfer_cb_arg(OSSL_CMP_CTX *ctx, void *arg);
98  void *OSSL_CMP_CTX_get_transfer_cb_arg(const OSSL_CMP_CTX *ctx);
99
100  /* server authentication: */
101  int OSSL_CMP_CTX_set1_srvCert(OSSL_CMP_CTX *ctx, X509 *cert);
102  int OSSL_CMP_CTX_set1_expected_sender(OSSL_CMP_CTX *ctx,
103                                       const X509_NAME *name);
104  int OSSL_CMP_CTX_set0_trustedStore(OSSL_CMP_CTX *ctx, X509_STORE *store);
105  X509_STORE *OSSL_CMP_CTX_get0_trustedStore(const OSSL_CMP_CTX *ctx);
106  int OSSL_CMP_CTX_set1_untrusted_certs(OSSL_CMP_CTX *ctx,
107                                        STACK_OF(X509) *certs);
108  STACK_OF(X509) *OSSL_CMP_CTX_get0_untrusted_certs(const OSSL_CMP_CTX *ctx);
109
110  /* client authentication: */
111  int OSSL_CMP_CTX_set1_clCert(OSSL_CMP_CTX *ctx, X509 *cert);
112  int OSSL_CMP_CTX_set1_pkey(OSSL_CMP_CTX *ctx, EVP_PKEY *pkey);
113  int OSSL_CMP_CTX_set1_referenceValue(OSSL_CMP_CTX *ctx,
114                                       const unsigned char *ref, int len);
115  int OSSL_CMP_CTX_set1_secretValue(OSSL_CMP_CTX *ctx, const unsigned char *sec,
116                                    const int len);
117
118  /* CMP message header and extra certificates: */
119  int OSSL_CMP_CTX_set1_recipient(OSSL_CMP_CTX *ctx, const X509_NAME *name);
120  int OSSL_CMP_CTX_push0_geninfo_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav);
121  int OSSL_CMP_CTX_set1_extraCertsOut(OSSL_CMP_CTX *ctx,
122                                      STACK_OF(X509) *extraCertsOut);
123
124  /* certificate template: */
125  int OSSL_CMP_CTX_set0_newPkey(OSSL_CMP_CTX *ctx, int priv, EVP_PKEY *pkey);
126  EVP_PKEY *OSSL_CMP_CTX_get0_newPkey(const OSSL_CMP_CTX *ctx, int priv);
127  int OSSL_CMP_CTX_set1_issuer(OSSL_CMP_CTX *ctx, const X509_NAME *name);
128  int OSSL_CMP_CTX_set1_subjectName(OSSL_CMP_CTX *ctx, const X509_NAME *name);
129  int OSSL_CMP_CTX_push1_subjectAltName(OSSL_CMP_CTX *ctx,
130                                        const GENERAL_NAME *name);
131  int OSSL_CMP_CTX_set0_reqExtensions(OSSL_CMP_CTX *ctx, X509_EXTENSIONS *exts);
132  int OSSL_CMP_CTX_reqExtensions_have_SAN(OSSL_CMP_CTX *ctx);
133  int OSSL_CMP_CTX_push0_policy(OSSL_CMP_CTX *ctx, POLICYINFO *pinfo);
134  int OSSL_CMP_CTX_set1_oldCert(OSSL_CMP_CTX *ctx, X509 *cert);
135  int OSSL_CMP_CTX_set1_p10CSR(OSSL_CMP_CTX *ctx, const X509_REQ *csr);
136
137  /* misc body contents: */
138  int OSSL_CMP_CTX_push0_genm_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav);
139
140  /* certificate confirmation: */
141  typedef int (*OSSL_cmp_certConf_cb_t) (OSSL_CMP_CTX *ctx, X509 *cert,
142                                         int fail_info, const char **txt);
143  int OSSL_CMP_CTX_set_certConf_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_certConf_cb_t cb);
144  int OSSL_CMP_CTX_set_certConf_cb_arg(OSSL_CMP_CTX *ctx, void *arg);
145  void *OSSL_CMP_CTX_get_certConf_cb_arg(const OSSL_CMP_CTX *ctx);
146
147  /* result fetching: */
148  int OSSL_CMP_CTX_get_status(const OSSL_CMP_CTX *ctx);
149  OSSL_CMP_PKIFREETEXT *OSSL_CMP_CTX_get0_statusString(const OSSL_CMP_CTX *ctx);
150  int OSSL_CMP_CTX_get_failInfoCode(const OSSL_CMP_CTX *ctx);
151
152  X509 *OSSL_CMP_CTX_get0_newCert(const OSSL_CMP_CTX *ctx);
153  STACK_OF(X509) *OSSL_CMP_CTX_get1_caPubs(const OSSL_CMP_CTX *ctx);
154  STACK_OF(X509) *OSSL_CMP_CTX_get1_extraCertsIn(const OSSL_CMP_CTX *ctx);
155
156  /* for test purposes only: */
157  int OSSL_CMP_CTX_set1_transactionID(OSSL_CMP_CTX *ctx,
158                                      const ASN1_OCTET_STRING *id);
159  int OSSL_CMP_CTX_set1_senderNonce(OSSL_CMP_CTX *ctx,
160                                    const ASN1_OCTET_STRING *nonce);
161
162 =head1 DESCRIPTION
163
164 This is the context API for using CMP (Certificate Management Protocol) with
165 OpenSSL.
166
167 OSSL_CMP_CTX_new() allocates and initializes an OSSL_CMP_CTX structure to
168 default values, e.g., proof-of-possession method is set to POPOSigningKey.
169
170 OSSL_CMP_CTX_free() deallocates an OSSL_CMP_CTX structure.
171
172 OSSL_CMP_CTX_reinit() prepares the given B<ctx> for a further transaction by
173 clearing the internal CMP transaction (aka session) status, PKIStatusInfo,
174 and any previous results (newCert, caPubs, and extraCertsIn)
175 from the last executed transaction.
176 All other field values (i.e., CMP options) are retained for potential re-use.
177
178 OSSL_CMP_CTX_set_option() sets the given value for the given option
179 (e.g., OSSL_CMP_OPT_IMPLICITCONFIRM) in the given OSSL_CMP_CTX structure.
180
181 The following options can be set:
182
183 =over 4
184
185 =item B<OSSL_CMP_OPT_LOG_VERBOSITY>
186
187         The level of severity needed for actually outputting log messages
188         due to errors, warnings, general info, debugging, etc.
189         Default is OSSL_CMP_LOG_INFO. See also L<OSSL_CMP_log_open(3)>.
190
191 =item B<OSSL_CMP_OPT_MSGTIMEOUT>
192
193         Number of seconds (or 0 for infinite) a CMP message round trip is
194         allowed to take before a timeout error is returned. Default is 120.
195
196 =item B<OSSL_CMP_OPT_TOTALTIMEOUT>
197
198         Maximum total number of seconds an enrollment (including polling)
199         may take. Default is 0 (infinite).
200
201 =item B<OSSL_CMP_OPT_VALIDITYDAYS>
202
203         Number of days new certificates are asked to be valid for.
204
205 =item B<OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT>
206
207         Do not take default Subject Alternative Names
208         from the reference certificate.
209
210 =item B<OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL>
211
212         Demand that the given Subject Alternative Names are flagged as critical.
213
214 =item B<OSSL_CMP_OPT_POLICIES_CRITICAL>
215
216         Demand that the given policies are flagged as critical.
217
218 =item B<OSSL_CMP_OPT_POPOMETHOD>
219
220         Select the proof of possession method to use. Possible values are:
221
222             OSSL_CRMF_POPO_NONE       - ProofOfPossession field omitted
223             OSSL_CRMF_POPO_RAVERIFIED - assert that the RA has already
224                                         verified the PoPo
225             OSSL_CRMF_POPO_SIGNATURE  - sign a value with private key,
226                                         which is the default.
227             OSSL_CRMF_POPO_KEYENC     - decrypt the encrypted certificate
228                                         ("indirect method")
229
230         Note that a signature-based POPO can only be produced if a private key
231         is provided as the newPkey or client pkey component of the CMP context.
232
233 =item B<OSSL_CMP_OPT_DIGEST_ALGNID>
234
235         The digest algorithm NID to be used in RFC 4210's MSG_SIG_ALG,
236         if applicable used for message protection and Proof-of-Possession.
237         Default is SHA256.
238
239     OSSL_CMP_OPT_OWF_ALGNID
240         The digest algorithm NID to be used as one-way function (OWF)
241         in RFC 4210's MSG_MAC_ALG, if applicable used for message protection.
242         Default is SHA256.
243
244     OSSL_CMP_OPT_MAC_ALGNID
245         The MAC algorithm NID to be used in RFC 4210's MSG_MAC_ALG,
246         if applicable used for message protection. 
247         Default is HMAC-SHA1 as per RFC 4210.
248
249 =item B<OSSL_CMP_OPT_REVOCATION_REASON>
250
251         The reason code to be included in a Revocation Request (RR);
252         values: 0..10 (RFC 5210, 5.3.1) or -1 for none, which is the default.
253
254 =item B<OSSL_CMP_OPT_IMPLICITCONFIRM>
255
256         Request server to enable implicit confirm mode, where the client
257         does not need to send confirmation upon receiving the
258         certificate. If the server does not enable implicit confirmation
259         in the return message, then confirmation is sent anyway.
260
261 =item B<OSSL_CMP_OPT_DISABLECONFIRM>
262
263         Do not confirm enrolled certificates, to cope with broken servers
264         not supporting implicit confirmation correctly.
265 B<WARNING:> This setting leads to unspecified behavior and it is meant
266 exclusively to allow interoperability with server implementations violating
267 RFC 4210.
268
269 =item B<OSSL_CMP_OPT_UNPROTECTED_SEND>
270
271         Send messages without CMP-level protection.
272
273 =item B<OSSL_CMP_OPT_UNPROTECTED_ERRORS>
274
275         Accept unprotected error responses which are either explicitly
276         unprotected or where protection verification failed. Applies to regular
277         error messages as well as certificate responses (IP/CP/KUP) and
278         revocation responses (RP) with rejection.
279 B<WARNING:> This setting leads to unspecified behavior and it is meant
280 exclusively to allow interoperability with server implementations violating
281 RFC 4210.
282
283 =item B<OSSL_CMP_OPT_IGNORE_KEYUSAGE>
284
285         Ignore key usage restrictions in signer certificate when
286         validating signature-based protection in received CMP messages.
287         Else, 'digitalSignature' must be allowed by CMP signer certificates.
288
289 =item B<OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR>
290
291         Allow retrieving a trust anchor from extraCerts and using that
292         to validate the certificate chain of an IP message.
293
294 =back
295
296 OSSL_CMP_CTX_get_option() reads the current value of the given option
297 (e.g., OSSL_CMP_OPT_IMPLICITCONFIRM) from the given OSSL_CMP_CTX structure.
298
299 OSSL_CMP_CTX_set_log_cb() sets in B<ctx> the callback function C<cb>
300 for handling error queue entries and logging messages.
301 When C<cb> is NULL errors are printed to STDERR (if available, else ignored)
302 any log messages are ignored.
303 Alternatively, L<OSSL_CMP_log_open(3)> may be used to direct logging to STDOUT.
304
305 OSSL_CMP_CTX_set_log_verbosity() is a macro setting the
306 OSSL_CMP_OPT_LOG_VERBOSITY context option to the given level.
307
308 OSSL_CMP_CTX_print_errors() outputs any entries in the OpenSSL error queue.
309 It is similar to B<ERR_print_errors_cb()> but uses the CMP log callback function
310 if set in the C<ctx> for uniformity with CMP logging if given. Otherwise it uses
311 B<ERR_print_errors(3)> to print to STDERR (unless OPENSSL_NO_STDIO is defined).
312
313 OSSL_CMP_CTX_set1_serverPath() sets the HTTP path of the CMP server on the host.
314
315 OSSL_CMP_CTX_set1_serverName() sets the given server Address (as IP or name)
316 in the given OSSL_CMP_CTX structure.
317
318 OSSL_CMP_CTX_set_serverPort() sets the port of the CMP server to connect to.
319 Port defaults to OSSL_CMP_DEFAULT_PORT = 80 if not set explicitly.
320
321 OSSL_CMP_CTX_set1_proxyName() sets the hostname of the HTTP proxy to be used
322 for connecting to the CA server.
323
324 OSSL_CMP_CTX_set_proxyPort() sets the port of the HTTP proxy.
325 Port defaults to OSSL_CMP_DEFAULT_PORT = 80 if not set explicitly.
326
327 OSSL_CMP_CTX_set_http_cb() sets the optional http connect/disconnect callback
328 function, which has the prototype
329
330  typedef BIO *(*OSSL_cmp_http_cb_t)(OSSL_CMP_CTX *ctx, BIO *hbio,
331                                     unsigned long detail);
332
333 It may modify the HTTP BIO given in the B<hbio> argument
334 used by OSSL_CMP_MSG_http_perform().
335 On connect the B<detail> argument is 1.
336 On disconnect it is 0 if no error occurred or else the last error code.
337 For instance, on connect a TLS BIO may be prepended to implement HTTPS,
338 and on disconnect some error diagnostics and/or cleanup may be done.
339 The callback function should return NULL to indicate failure.
340 It may make use of a custom defined argument stored in the ctx
341 by means of OSSL_CMP_CTX_set_http_cb_arg(),
342 which may be retrieved again through OSSL_CMP_CTX_get_http_cb_arg().
343
344 OSSL_CMP_CTX_set_http_cb_arg() sets an argument, respectively a pointer to
345 a structure containing arguments,
346 optionally to be used by the http connect/disconnect callback function.
347 B<arg> is not consumed, and it must therefore explicitly be freed when not
348 needed any more. B<arg> may be NULL to clear the entry.
349
350 OSSL_CMP_CTX_get_http_cb_arg() gets the argument, respectively the pointer to a
351 structure containing arguments, previously set by
352 OSSL_CMP_CTX_set_http_cb_arg() or NULL if unset.
353
354 OSSL_CMP_CTX_set_transfer_cb() sets the message transfer callback function,
355 which has the type
356
357  typedef int (*OSSL_cmp_transfer_cb_t)(const OSSL_CMP_CTX *ctx,
358                                        const OSSL_CMP_MSG *req,
359                                        OSSL_CMP_MSG **res);
360 Returns 1 on success, 0 on error.
361
362 Default is NULL, which implies the use of L<OSSL_CMP_MSG_http_perform(3)>.
363 The callback should send the CMP request it obtains via the B<req> parameter
364 and on success place the response in the B<*res> output parameter.
365 The transfer callback may make use of a custom defined argument stored in
366 the ctx by means of OSSL_CMP_CTX_set_transfer_cb_arg(), which may be retrieved
367 again through OSSL_CMP_CTX_get_transfer_cb_arg().
368 On success the cb must return 0, else a CMP error reason code defined in cmp.h.
369
370
371 OSSL_CMP_CTX_set_transfer_cb_arg() sets an argument, respectively a pointer to a
372 structure containing arguments, optionally to be used by the transfer callback.
373 B<arg> is not consumed, and it must therefore explicitly be freed when not
374 needed any more. B<arg> may be NULL to clear the entry.
375
376 OSSL_CMP_CTX_get_transfer_cb_arg() gets the argument, respectively the pointer
377 to a structure containing arguments, previously set by
378 OSSL_CMP_CTX_set_transfer_cb_arg() or NULL if unset.
379
380 OSSL_CMP_CTX_set1_srvCert() pins the server certificate to be directly trusted
381 (even if it is expired) for verifying response messages.
382 The cert pointer is not consumed. It may be NULL to clear the entry.
383
384 OSSL_CMP_CTX_set1_expected_sender() sets the Distinguished Name (DN) expected to
385 be given in the sender response for messages protected with MSG_SIG_ALG. This
386 may be used to enforce that during validation of received messages the given DN
387 matches the sender field of the PKIMessage header, which in turn is used to
388 identify the server certificate.
389 This can be used to ensure that only a particular entity is accepted to act as
390 CMP server, and attackers are not able to use arbitrary certificates of a
391 trusted PKI hierarchy to fraudulently pose as server.
392 This defaults to the subject DN of the certificate set via
393 OSSL_CMP_CTX_set1_srvCert(), if any.
394
395 OSSL_CMP_CTX_set0_trustedStore() sets the X509_STORE type certificate store
396 containing trusted (root) CA certificates. The certificate store may also hold
397 CRLs and a certificate verification callback function used for CMP server
398 authentication. Any already existing store entry is freed. When given a NULL
399 parameter the entry is cleared.
400
401 OSSL_CMP_CTX_get0_trustedStore() returns a pointer to the certificate store
402 containing trusted root CA certificates, which may be empty if unset.
403
404 OSSL_CMP_CTX_set1_untrusted_certs() takes over a list of certificates containing
405 non-trusted intermediate certs used for path construction in authentication
406 of the CMP server and potentially others (TLS server, newly enrolled cert).
407 The reference counts of those certificates handled successfully are increased.
408
409 OSSL_CMP_CTX_get0_untrusted_certs(OSSL_CMP_CTX *ctx) returns a pointer to the
410 list of untrusted certs, which my be empty if unset.
411
412 OSSL_CMP_CTX_set1_clCert() sets the client certificate in the given
413 OSSL_CMP_CTX structure. The client certificate will then be used by the
414 functions to set the "sender" field for outgoing messages and it will be
415 included in the extraCerts field.
416
417 OSSL_CMP_CTX_set1_pkey() sets the private key corresponding to the client
418 certificate set with B<OSSL_CMP_CTX_set1_clCert()> in the given CMP context.
419 Used to create the protection in case of MSG_SIG_ALG.
420
421 OSSL_CMP_CTX_set1_referenceValue() sets the given referenceValue in the given
422 B<ctx> or clears it if the B<ref> argument is NULL.
423
424 OSSL_CMP_CTX_set1_secretValue() sets the B<sec> with the length B<len> in the
425 given B<ctx> or clears it if the B<sec> argument is NULL.
426
427 OSSL_CMP_CTX_set1_recipient() sets the recipient name that will be used in the
428 PKIHeader of a request message, i.e. the X509 name of the (CA) server.
429 Setting is overruled by subject of srvCert if set.
430 If neither srvCert nor recipient are set, the recipient of the PKI message is
431 determined in the following order: issuer, issuer of old cert (oldCert),
432 issuer of client cert (clCert), else NULL-DN.
433 When a response is received, its sender must match the recipient of the request.
434
435 OSSL_CMP_CTX_push0_geninfo_ITAV() adds B<itav> to the stack in the B<ctx> to be
436 added to the GeneralInfo field of the CMP PKIMessage header of a request
437 message sent with this context.  Consumes the pointer to B<itav>.
438
439 OSSL_CMP_CTX_set1_extraCertsOut() sets the stack of extraCerts that will be
440 sent to remote.
441
442 OSSL_CMP_CTX_set0_newPkey() can be used to explicitly set the given EVP_PKEY
443 structure as the private or public key to be certified in the CMP context.
444 The B<priv> parameter must be 0 if and only if the given key is a public key.
445
446 OSSL_CMP_CTX_get0_newPkey() gives the key to use for certificate enrollment
447 dependent on fields of the CMP context structure:
448 the newPkey (which may be a private or public key) if present,
449 else the public key in the p10CSR if present, else the client private key.
450 If the B<priv> parameter is not 0 and the selected key does not have a
451 private component then NULL is returned.
452
453 OSSL_CMP_CTX_set1_issuer() sets the name of the intended issuer that
454 will be set in the CertTemplate, i.e., the X509 name of the CA server.
455
456 OSSL_CMP_CTX_set1_subjectName() sets the subject DN that will be used in
457 the CertTemplate structure when requesting a new cert. For Key Update Requests
458 (KUR), it defaults to the subject DN of the reference certificate,
459 see B<OSSL_CMP_CTX_set1_oldCert()>. This default is used for Initialization
460 Requests (IR) and Certification Requests (CR) only if no SANs are set.
461
462 If clCert is not set (e.g. in case of IR with MSG_MAC_ALG), the subject DN
463 is also used as sender of the PKI message.
464
465 OSSL_CMP_CTX_push1_subjectAltName() adds the given X509 name to the list of
466 alternate names on the certificate template request. This cannot be used if
467 any Subject Alternative Name extension is set via
468 OSSL_CMP_CTX_set0_reqExtensions().
469 By default, unless OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT has been set,
470 the Subject Alternative Names are copied from the reference certificate,
471 see OSSL_CMP_CTX_set1_oldCert().
472
473 If set and the subject DN is not set with OSSL_CMP_CTX_set1_subjectName(), then
474 the certificate template of an IR and CR will not be filled with the default
475 subject DN from the reference certificate (see OSSL_CMP_CTX_set1_oldCert().
476 If a subject DN is desired it needs to be set explicitly with
477 OSSL_CMP_CTX_set1_subjectName().
478
479 OSSL_CMP_CTX_set0_reqExtensions() sets the X.509v3 extensions to be used in
480 IR/CR/KUR.
481
482 OSSL_CMP_CTX_reqExtensions_have_SAN() returns 1 if the context contains
483 a Subject Alternative Name extension, else 0 or -1 on error.
484
485 OSSL_CMP_CTX_push0_policy() adds the certificate policy info object
486 to the X509_EXTENSIONS of the requested certificate template.
487
488 OSSL_CMP_CTX_set1_oldCert() sets the old certificate to be updated in
489 Key Update Requests (KUR) or to be revoked in Revocation Requests (RR).
490 It must be given for RR, else it defaults to B<clCert>.
491 The reference certificate determined in this way, if any, is also used for
492 deriving default subject DN and Subject Alternative Names for IR, CR, and KUR.
493 Its issuer, if any, is used as default recipient in the CMP message header.
494
495 OSSL_CMP_CTX_set1_p10CSR() sets the PKCS#10 CSR to be used in P10CR.
496
497 OSSL_CMP_CTX_push0_genm_ITAV() adds B<itav> to the stack in the B<ctx> which
498 will be the body of a General Message sent with this context.
499 Consumes the pointer to B<itav>.
500
501 OSSL_CMP_CTX_set_certConf_cb() sets the callback used for evaluating the newly
502 enrolled certificate before the library sends, depending on its result,
503 a positive or negative certConf message to the server. The callback has type
504
505  typedef int (*OSSL_cmp_certConf_cb_t) (OSSL_CMP_CTX *ctx, X509 *cert,
506                                         int fail_info, const char **txt);
507
508 and should inspect the certificate it obtains via the B<cert> parameter and may
509 overrule the pre-decision given in the B<fail_info> and B<*txt> parameters.
510 If it accepts the certificate it must return 0, indicating success. Else it must
511 return a bit field reflecting PKIFailureInfo with at least one failure bit and
512 may set the B<*txt> output parameter to point to a string constant with more
513 detail.  The transfer callback may make use of a custom defined argument stored
514 in the B<ctx> by means of OSSL_CMP_CTX_set_certConf_cb_arg(), which may be
515 retrieved again through OSSL_CMP_CTX_get_certConf_cb_arg().
516 Typically, the callback will check at least that the certificate can be verified
517 using a set of trusted certificates.
518 It also could compare the subject DN and other fields of the newly
519 enrolled certificate with the certificate template of the request.
520
521 OSSL_CMP_CTX_set_certConf_cb_arg() sets an argument, respectively a pointer to a
522 structure containing arguments, optionally to be used by the certConf callback.
523 B<arg> is not consumed, and it must therefore explicitly be freed when not
524 needed any more. B<arg> may be NULL to clear the entry.
525
526 OSSL_CMP_CTX_get_certConf_cb_arg() gets the argument, respectively the pointer
527 to a structure containing arguments, previously set by
528 OSSL_CMP_CTX_set_certConf_cb_arg(), or NULL if unset.
529
530 OSSL_CMP_CTX_get_status() returns the PKIstatus from the last received
531 CertRepMessage or Revocation Response or error message, or -1 if unset.
532
533 OSSL_CMP_CTX_get0_statusString() returns the statusString from the last received
534 CertRepMessage or Revocation Response or error message, or NULL if unset.
535
536 OSSL_CMP_CTX_get_failInfoCode() returns the error code from the failInfo field
537 of the last received CertRepMessage or Revocation Response or error message.
538 This is a bit field and the flags for it are specified in the header file
539 F<< <openssl/cmp.h> >>.
540 The flags start with OSSL_CMP_CTX_FAILINFO, for example:
541 OSSL_CMP_CTX_FAILINFO_badAlg. Returns -1 if the failInfoCode field is unset.
542
543 OSSL_CMP_CTX_get0_newCert() returns the pointer to the newly obtained
544 certificate in case it is available, else NULL.
545
546 OSSL_CMP_CTX_get1_caPubs() returns a pointer to a duplicate of the stack of
547 X.509 certificates received in the caPubs field of last received certificate
548 response message IP/CP/KUP.
549
550 OSSL_CMP_CTX_get1_extraCertsIn() returns a pointer to a duplicate of the stack
551 of X.509 certificates received in the last received non-empty extraCerts field.
552 Returns an empty stack if no extraCerts have been received in the current
553 transaction.
554
555 OSSL_CMP_CTX_set1_transactionID() sets the given transaction ID in the given
556 OSSL_CMP_CTX structure.
557
558 OSSL_CMP_CTX_set1_senderNonce() stores the last sent sender B<nonce> in
559 the B<ctx>. This will be used to validate the recipNonce in incoming messages.
560
561 =head1 NOTES
562
563 CMP is defined in RFC 4210 (and CRMF in RFC 4211).
564
565 =head1 RETURN VALUES
566
567 OSSL_CMP_CTX_free() and OSSL_CMP_CTX_print_errors() do not return anything.
568
569 OSSL_CMP_CTX_new(),
570 OSSL_CMP_CTX_get_http_cb_arg(),
571 OSSL_CMP_CTX_get_transfer_cb_arg(),
572 OSSL_CMP_CTX_get0_trustedStore(),
573 OSSL_CMP_CTX_get0_untrusted_certs(),
574 OSSL_CMP_CTX_get0_newPkey(),
575 OSSL_CMP_CTX_get_certConf_cb_arg(),
576 OSSL_CMP_CTX_get0_statusString(),
577 OSSL_CMP_CTX_get0_newCert(),
578 OSSL_CMP_CTX_get1_caPubs(), and
579 OSSL_CMP_CTX_get1_extraCertsIn()
580 return the intended pointer value as described above or NULL on error.
581
582 OSSL_CMP_CTX_get_option(),
583 OSSL_CMP_CTX_reqExtensions_have_SAN(),
584 OSSL_CMP_CTX_get_status(), and
585 OSSL_CMP_CTX_get_failInfoCode()
586 return the intended value as described above or -1 on error.
587
588 All other functions return 1 on success, 0 on error.
589
590 =head1 EXAMPLES
591
592 The following code does an Initialization Request:
593
594         cmp_ctx = OSSL_CMP_CTX_new();
595         OSSL_CMP_CTX_set1_serverName(cmp_ctx, opt_serverName);
596         OSSL_CMP_CTX_set1_referenceValue(cmp_ctx, ref, ref_len);
597         OSSL_CMP_CTX_set1_secretValue(cmp_ctx, sec, sec_len);
598         OSSL_CMP_CTX_set0_newPkey(cmp_ctx, new_pkey, 1);
599         OSSL_CMP_CTX_set1_caCert(cmp_ctx, ca_cert);
600
601         initialClCert = OSSL_CMP_exec_IR_ses(cmp_ctx);
602
603 The following code does an Initialization Request using an
604 external identity certificate (RFC 4210, Appendix E.7):
605
606         cmp_ctx = OSSL_CMP_CTX_new();
607         OSSL_CMP_CTX_set1_serverName(cmp_ctx, sname);
608         OSSL_CMP_CTX_set1_clCert(cmp_ctx, cl_cert);
609         OSSL_CMP_CTX_set1_pkey(cmp_ctx, pkey);
610         OSSL_CMP_CTX_set0_newPkey(cmp_ctx, new_pkey, 1);
611         OSSL_CMP_CTX_set1_caCert(cmp_ctx, ca_cert);
612
613         initialClCert = OSSL_CMP_exec_IR_ses(cmp_ctx);
614
615 Here externalCert is an X509 certificate granted to the EE by another CA
616 which is trusted by the current CA the code will connect to.
617
618
619 The following code does a Key Update Request:
620
621         cmp_ctx = OSSL_CMP_CTX_new();
622         OSSL_CMP_CTX_set1_serverName(cmp_ctx, sname);
623         OSSL_CMP_CTX_set1_pkey(cmp_ctx, pkey);
624         OSSL_CMP_CTX_set0_newPkey(cmp_ctx, new_pkey, 1);
625         OSSL_CMP_CTX_set1_clCert(cmp_ctx, cl_cert);
626         OSSL_CMP_CTX_set1_caCert(cmp_ctx, ca_cert);
627
628         updatedClCert = OSSL_CMP_exec_KUR_ses(cmp_ctx);
629
630 The following code (which omits error handling) sends a General Message
631 including, as an example, the id-it-signKeyPairTypes OID and prints info on
632 the General Response contents.
633
634     cmp_ctx = OSSL_CMP_CTX_new();
635     OSSL_CMP_CTX_set1_serverName(cmp_ctx, sname);
636     OSSL_CMP_CTX_set1_referenceValue(cmp_ctx, ref, ref_len);
637     OSSL_CMP_CTX_set1_secretValue(cmp_ctx, sec, sec_len);
638
639     ASN1_OBJECT *type = OBJ_txt2obj("1.3.6.1.5.5.7.4.2", 1);
640     OSSL_CMP_ITAV *itav = OSSL_CMP_ITAV_new(type, NULL);
641     OSSL_CMP_CTX_push0_genm_ITAV(cmp_ctx, itav);
642
643     STACK_OF(OSSL_CMP_ITAV) *itavs;
644     itavs = OSSL_CMP_exec_GENM_ses(cmp_ctx);
645     print_itavs(itavs);
646     sk_OSSL_CMP_ITAV_pop_free(itavs, OSSL_CMP_ITAV_free);
647
648 =head1 SEE ALSO
649
650 L<OSSL_CMP_exec_IR_ses(3)>, L<OSSL_CMP_exec_KUR_ses(3)>,
651 L<OSSL_CMP_exec_GENM_ses(3)>
652
653 =head1 HISTORY
654
655 The OpenSSL CMP support was added in OpenSSL 3.0.
656
657 =head1 COPYRIGHT
658
659 Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
660
661 Licensed under the Apache License 2.0 (the "License").  You may not use
662 this file except in compliance with the License.  You can obtain a copy
663 in the file LICENSE in the source distribution or at
664 L<https://www.openssl.org/source/license.html>.
665
666 =cut