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