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