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