2 * Copyright 2007-2019 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright Nokia 2007-2019
4 * Copyright Siemens AG 2015-2019
6 * Licensed under the Apache License 2.0 (the "License"). You may not use
7 * this file except in compliance with the License. You can obtain a copy
8 * in the file LICENSE in the source distribution or at
9 * https://www.openssl.org/source/license.html
12 #include <openssl/trace.h>
13 #include <openssl/bio.h>
14 #include <openssl/ocsp.h> /* for OCSP_REVOKED_STATUS_* */
16 #include "cmp_local.h"
18 /* explicit #includes not strictly needed since implied by the above: */
19 #include <openssl/cmp.h>
20 #include <openssl/crmf.h>
21 #include <openssl/err.h>
24 * Get current certificate store containing trusted root CA certs
26 X509_STORE *OSSL_CMP_CTX_get0_trustedStore(const OSSL_CMP_CTX *ctx)
29 CMPerr(0, CMP_R_NULL_ARGUMENT);
36 * Set certificate store containing trusted (root) CA certs and possibly CRLs
37 * and a cert verification callback function used for CMP server authentication.
38 * Any already existing store entry is freed. Given NULL, the entry is reset.
39 * returns 1 on success, 0 on error
41 int OSSL_CMP_CTX_set0_trustedStore(OSSL_CMP_CTX *ctx, X509_STORE *store)
44 CMPerr(0, CMP_R_NULL_ARGUMENT);
47 X509_STORE_free(ctx->trusted);
53 * Get current list of non-trusted intermediate certs
55 STACK_OF(X509) *OSSL_CMP_CTX_get0_untrusted_certs(const OSSL_CMP_CTX *ctx)
58 CMPerr(0, CMP_R_NULL_ARGUMENT);
61 return ctx->untrusted_certs;
65 * Set untrusted certificates for path construction in authentication of
66 * the CMP server and potentially others (TLS server, newly enrolled cert).
67 * returns 1 on success, 0 on error
69 int OSSL_CMP_CTX_set1_untrusted_certs(OSSL_CMP_CTX *ctx, STACK_OF(X509) *certs)
72 CMPerr(0, CMP_R_NULL_ARGUMENT);
75 sk_X509_pop_free(ctx->untrusted_certs, X509_free);
76 if ((ctx->untrusted_certs = sk_X509_new_null()) == NULL)
78 return ossl_cmp_sk_X509_add1_certs(ctx->untrusted_certs, certs, 0, 1, 0);
82 * Allocates and initializes OSSL_CMP_CTX context structure with default values.
83 * Returns new context on success, NULL on error
85 OSSL_CMP_CTX *OSSL_CMP_CTX_new(void)
87 OSSL_CMP_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
92 ctx->log_verbosity = OSSL_CMP_LOG_INFO;
95 ctx->failInfoCode = -1;
97 ctx->serverPort = OSSL_CMP_DEFAULT_PORT;
98 ctx->proxyPort = OSSL_CMP_DEFAULT_PORT;
99 ctx->msgtimeout = 2 * 60;
101 if ((ctx->untrusted_certs = sk_X509_new_null()) == NULL)
105 ctx->pbm_owf = NID_sha256;
106 ctx->pbm_itercnt = 500;
107 ctx->pbm_mac = NID_hmac_sha1;
109 ctx->digest = NID_sha256;
110 ctx->popoMethod = OSSL_CRMF_POPO_SIGNATURE;
111 ctx->revocationReason = CRL_REASON_NONE;
113 /* all other elements are initialized to 0 or NULL, respectively */
117 OSSL_CMP_CTX_free(ctx);
122 * Prepare the OSSL_CMP_CTX for next use, partly re-initializing OSSL_CMP_CTX
124 int OSSL_CMP_CTX_reinit(OSSL_CMP_CTX *ctx)
127 CMPerr(0, CMP_R_NULL_ARGUMENT);
132 ctx->failInfoCode = -1;
134 return ossl_cmp_ctx_set0_statusString(ctx, NULL)
135 && ossl_cmp_ctx_set0_newCert(ctx, NULL)
136 && ossl_cmp_ctx_set1_caPubs(ctx, NULL)
137 && ossl_cmp_ctx_set1_extraCertsIn(ctx, NULL)
138 && ossl_cmp_ctx_set0_validatedSrvCert(ctx, NULL)
139 && OSSL_CMP_CTX_set1_transactionID(ctx, NULL)
140 && OSSL_CMP_CTX_set1_senderNonce(ctx, NULL)
141 && ossl_cmp_ctx_set1_recipNonce(ctx, NULL);
145 * Frees OSSL_CMP_CTX variables allocated in OSSL_CMP_CTX_new()
147 void OSSL_CMP_CTX_free(OSSL_CMP_CTX *ctx)
152 OPENSSL_free(ctx->serverPath);
153 OPENSSL_free(ctx->serverName);
154 OPENSSL_free(ctx->proxyName);
156 X509_free(ctx->srvCert);
157 X509_free(ctx->validatedSrvCert);
158 X509_NAME_free(ctx->expected_sender);
159 X509_STORE_free(ctx->trusted);
160 sk_X509_pop_free(ctx->untrusted_certs, X509_free);
162 X509_free(ctx->clCert);
163 EVP_PKEY_free(ctx->pkey);
164 ASN1_OCTET_STRING_free(ctx->referenceValue);
165 if (ctx->secretValue != NULL)
166 OPENSSL_cleanse(ctx->secretValue->data, ctx->secretValue->length);
167 ASN1_OCTET_STRING_free(ctx->secretValue);
169 X509_NAME_free(ctx->recipient);
170 ASN1_OCTET_STRING_free(ctx->transactionID);
171 ASN1_OCTET_STRING_free(ctx->senderNonce);
172 ASN1_OCTET_STRING_free(ctx->recipNonce);
173 sk_OSSL_CMP_ITAV_pop_free(ctx->geninfo_ITAVs, OSSL_CMP_ITAV_free);
174 sk_X509_pop_free(ctx->extraCertsOut, X509_free);
176 EVP_PKEY_free(ctx->newPkey);
177 X509_NAME_free(ctx->issuer);
178 X509_NAME_free(ctx->subjectName);
179 sk_GENERAL_NAME_pop_free(ctx->subjectAltNames, GENERAL_NAME_free);
180 sk_X509_EXTENSION_pop_free(ctx->reqExtensions, X509_EXTENSION_free);
181 sk_POLICYINFO_pop_free(ctx->policies, POLICYINFO_free);
182 X509_free(ctx->oldCert);
183 X509_REQ_free(ctx->p10CSR);
185 sk_OSSL_CMP_ITAV_pop_free(ctx->genm_ITAVs, OSSL_CMP_ITAV_free);
187 sk_ASN1_UTF8STRING_pop_free(ctx->statusString, ASN1_UTF8STRING_free);
188 X509_free(ctx->newCert);
189 sk_X509_pop_free(ctx->caPubs, X509_free);
190 sk_X509_pop_free(ctx->extraCertsIn, X509_free);
195 int ossl_cmp_ctx_set_status(OSSL_CMP_CTX *ctx, int status)
197 if (!ossl_assert(ctx != NULL))
199 ctx->status = status;
204 * Returns the PKIStatus from the last CertRepMessage
205 * or Revocation Response or error message, -1 on error
207 int OSSL_CMP_CTX_get_status(const OSSL_CMP_CTX *ctx)
210 CMPerr(0, CMP_R_NULL_ARGUMENT);
217 * Returns the statusString from the last CertRepMessage
218 * or Revocation Response or error message, NULL on error
220 OSSL_CMP_PKIFREETEXT *OSSL_CMP_CTX_get0_statusString(const OSSL_CMP_CTX *ctx)
223 CMPerr(0, CMP_R_NULL_ARGUMENT);
226 return ctx->statusString;
229 int ossl_cmp_ctx_set0_statusString(OSSL_CMP_CTX *ctx,
230 OSSL_CMP_PKIFREETEXT *text)
232 if (!ossl_assert(ctx != NULL))
234 sk_ASN1_UTF8STRING_pop_free(ctx->statusString, ASN1_UTF8STRING_free);
235 ctx->statusString = text;
239 int ossl_cmp_ctx_set0_validatedSrvCert(OSSL_CMP_CTX *ctx, X509 *cert)
241 if (!ossl_assert(ctx != NULL))
243 X509_free(ctx->validatedSrvCert);
244 ctx->validatedSrvCert = cert;
249 * Set callback function for checking if the cert is ok or should
251 * Returns 1 on success, 0 on error
253 int OSSL_CMP_CTX_set_certConf_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_certConf_cb_t cb)
256 CMPerr(0, CMP_R_NULL_ARGUMENT);
259 ctx->certConf_cb = cb;
264 * Set argument, respectively a pointer to a structure containing arguments,
265 * optionally to be used by the certConf callback.
266 * Returns 1 on success, 0 on error
268 int OSSL_CMP_CTX_set_certConf_cb_arg(OSSL_CMP_CTX *ctx, void *arg)
271 CMPerr(0, CMP_R_NULL_ARGUMENT);
274 ctx->certConf_cb_arg = arg;
279 * Get argument, respectively the pointer to a structure containing arguments,
280 * optionally to be used by certConf callback.
281 * Returns callback argument set previously (NULL if not set or on error)
283 void *OSSL_CMP_CTX_get_certConf_cb_arg(const OSSL_CMP_CTX *ctx)
286 CMPerr(0, CMP_R_NULL_ARGUMENT);
289 return ctx->certConf_cb_arg;
292 #ifndef OPENSSL_NO_TRACE
293 static size_t ossl_cmp_log_trace_cb(const char *buf, size_t cnt,
294 int category, int cmd, void *vdata)
296 OSSL_CMP_CTX *ctx = vdata;
297 const char *prefix_msg;
298 OSSL_CMP_severity level = -1;
303 if (buf == NULL || cnt == 0 || cmd != OSSL_TRACE_CTRL_WRITE || ctx == NULL)
305 if (ctx->log_cb == NULL)
306 return 1; /* silently drop message */
308 prefix_msg = ossl_cmp_log_parse_metadata(buf, &level, &func, &file, &line);
310 if (level > ctx->log_verbosity) /* excludes the case level is unknown */
311 goto end; /* suppress output since severity is not sufficient */
313 if (!ctx->log_cb(func != NULL ? func : "(no func)",
314 file != NULL ? file : "(no file)",
315 line, level, prefix_msg))
326 * Set a callback function for error reporting and logging messages.
327 * Returns 1 on success, 0 on error
329 int OSSL_CMP_CTX_set_log_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_log_cb_t cb)
332 CMPerr(0, CMP_R_NULL_ARGUMENT);
337 #ifndef OPENSSL_NO_TRACE
338 /* do also in case cb == NULL, to switch off logging output: */
339 if (!OSSL_trace_set_callback(OSSL_TRACE_CATEGORY_CMP,
340 ossl_cmp_log_trace_cb, ctx))
347 /* Print OpenSSL and CMP errors via the log cb of the ctx or ERR_print_errors */
348 void OSSL_CMP_CTX_print_errors(OSSL_CMP_CTX *ctx)
350 OSSL_CMP_print_errors_cb(ctx == NULL ? NULL : ctx->log_cb);
354 * Set or clear the reference value to be used for identification
355 * (i.e., the user name) when using PBMAC.
356 * Returns 1 on success, 0 on error
358 int OSSL_CMP_CTX_set1_referenceValue(OSSL_CMP_CTX *ctx,
359 const unsigned char *ref, int len)
362 CMPerr(0, CMP_R_NULL_ARGUMENT);
365 return ossl_cmp_asn1_octet_string_set1_bytes(&ctx->referenceValue, ref,
370 * Set or clear the password to be used for protecting messages with PBMAC.
371 * Returns 1 on success, 0 on error
373 int OSSL_CMP_CTX_set1_secretValue(OSSL_CMP_CTX *ctx, const unsigned char *sec,
377 CMPerr(0, CMP_R_NULL_ARGUMENT);
380 if (ctx->secretValue != NULL)
381 OPENSSL_cleanse(ctx->secretValue->data, ctx->secretValue->length);
382 return ossl_cmp_asn1_octet_string_set1_bytes(&ctx->secretValue, sec, len);
386 * Returns the stack of certificates received in a response message.
387 * The stack is duplicated so the caller must handle freeing it!
388 * Returns pointer to created stack on success, NULL on error
390 STACK_OF(X509) *OSSL_CMP_CTX_get1_extraCertsIn(const OSSL_CMP_CTX *ctx)
393 CMPerr(0, CMP_R_NULL_ARGUMENT);
396 if (ctx->extraCertsIn == NULL)
397 return sk_X509_new_null();
398 return X509_chain_up_ref(ctx->extraCertsIn);
402 * Copies any given stack of inbound X509 certificates to extraCertsIn
403 * of the OSSL_CMP_CTX structure so that they may be retrieved later.
404 * Returns 1 on success, 0 on error.
406 int ossl_cmp_ctx_set1_extraCertsIn(OSSL_CMP_CTX *ctx,
407 STACK_OF(X509) *extraCertsIn)
409 if (!ossl_assert(ctx != NULL))
412 sk_X509_pop_free(ctx->extraCertsIn, X509_free);
413 ctx->extraCertsIn = NULL;
414 if (extraCertsIn == NULL)
416 return (ctx->extraCertsIn = X509_chain_up_ref(extraCertsIn)) != NULL;
420 * Duplicate and set the given stack as the new stack of X509
421 * certificates to send out in the extraCerts field.
422 * Returns 1 on success, 0 on error
424 int OSSL_CMP_CTX_set1_extraCertsOut(OSSL_CMP_CTX *ctx,
425 STACK_OF(X509) *extraCertsOut)
428 CMPerr(0, CMP_R_NULL_ARGUMENT);
432 sk_X509_pop_free(ctx->extraCertsOut, X509_free);
433 ctx->extraCertsOut = NULL;
434 if (extraCertsOut == NULL)
436 return (ctx->extraCertsOut = X509_chain_up_ref(extraCertsOut)) != NULL;
440 * Add the given policy info object
441 * to the X509_EXTENSIONS of the requested certificate template.
442 * Returns 1 on success, 0 on error.
444 int OSSL_CMP_CTX_push0_policy(OSSL_CMP_CTX *ctx, POLICYINFO *pinfo)
446 if (ctx == NULL || pinfo == NULL) {
447 CMPerr(0, CMP_R_NULL_ARGUMENT);
451 if (ctx->policies == NULL
452 && (ctx->policies = CERTIFICATEPOLICIES_new()) == NULL)
455 return sk_POLICYINFO_push(ctx->policies, pinfo);
459 * Add an ITAV for geninfo of the PKI message header
461 int OSSL_CMP_CTX_push0_geninfo_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav)
464 CMPerr(0, CMP_R_NULL_ARGUMENT);
467 return OSSL_CMP_ITAV_push0_stack_item(&ctx->geninfo_ITAVs, itav);
471 * Add an itav for the body of outgoing general messages
473 int OSSL_CMP_CTX_push0_genm_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav)
476 CMPerr(0, CMP_R_NULL_ARGUMENT);
479 return OSSL_CMP_ITAV_push0_stack_item(&ctx->genm_ITAVs, itav);
483 * Returns a duplicate of the stack of X509 certificates that
484 * were received in the caPubs field of the last CertRepMessage.
485 * Returns NULL on error
487 STACK_OF(X509) *OSSL_CMP_CTX_get1_caPubs(const OSSL_CMP_CTX *ctx)
490 CMPerr(0, CMP_R_NULL_ARGUMENT);
493 if (ctx->caPubs == NULL)
494 return sk_X509_new_null();
495 return X509_chain_up_ref(ctx->caPubs);
499 * Duplicate and copy the given stack of certificates to the given
500 * OSSL_CMP_CTX structure so that they may be retrieved later.
501 * Returns 1 on success, 0 on error
503 int ossl_cmp_ctx_set1_caPubs(OSSL_CMP_CTX *ctx, STACK_OF(X509) *caPubs)
505 if (!ossl_assert(ctx != NULL))
508 sk_X509_pop_free(ctx->caPubs, X509_free);
512 return (ctx->caPubs = X509_chain_up_ref(caPubs)) != NULL;
515 #define char_dup OPENSSL_strdup
516 #define char_free OPENSSL_free
517 #define DEFINE_OSSL_CMP_CTX_set1(FIELD, TYPE) /* this uses _dup */ \
518 int OSSL_CMP_CTX_set1_##FIELD(OSSL_CMP_CTX *ctx, const TYPE *val) \
520 TYPE *val_dup = NULL; \
523 CMPerr(0, CMP_R_NULL_ARGUMENT); \
527 if (val != NULL && (val_dup = TYPE##_dup(val)) == NULL) \
529 TYPE##_free(ctx->FIELD); \
530 ctx->FIELD = val_dup; \
534 #define DEFINE_OSSL_CMP_CTX_set1_up_ref(FIELD, TYPE) \
535 int OSSL_CMP_CTX_set1_##FIELD(OSSL_CMP_CTX *ctx, TYPE *val) \
538 CMPerr(0, CMP_R_NULL_ARGUMENT); \
542 if (val != NULL && !TYPE##_up_ref(val)) \
544 TYPE##_free(ctx->FIELD); \
550 * Pins the server certificate to be directly trusted (even if it is expired)
551 * for verifying response messages.
552 * Cert pointer is not consumed. It may be NULL to clear the entry.
553 * Returns 1 on success, 0 on error
555 DEFINE_OSSL_CMP_CTX_set1_up_ref(srvCert, X509)
558 * Set the X509 name of the recipient. Set in the PKIHeader.
559 * returns 1 on success, 0 on error
561 DEFINE_OSSL_CMP_CTX_set1(recipient, X509_NAME)
564 * Store the X509 name of the expected sender in the PKIHeader of responses.
565 * Returns 1 on success, 0 on error
567 DEFINE_OSSL_CMP_CTX_set1(expected_sender, X509_NAME)
570 * Set the X509 name of the issuer. Set in the PKIHeader.
571 * Returns 1 on success, 0 on error
573 DEFINE_OSSL_CMP_CTX_set1(issuer, X509_NAME)
576 * Set the subject name that will be placed in the certificate
577 * request. This will be the subject name on the received certificate.
578 * Returns 1 on success, 0 on error
580 DEFINE_OSSL_CMP_CTX_set1(subjectName, X509_NAME)
583 * Set the X.509v3 certificate request extensions to be used in IR/CR/KUR.
584 * Returns 1 on success, 0 on error
586 int OSSL_CMP_CTX_set0_reqExtensions(OSSL_CMP_CTX *ctx, X509_EXTENSIONS *exts)
589 CMPerr(0, CMP_R_NULL_ARGUMENT);
593 if (sk_GENERAL_NAME_num(ctx->subjectAltNames) > 0 && exts != NULL
594 && X509v3_get_ext_by_NID(exts, NID_subject_alt_name, -1) >= 0) {
595 CMPerr(0, CMP_R_MULTIPLE_SAN_SOURCES);
598 sk_X509_EXTENSION_pop_free(ctx->reqExtensions, X509_EXTENSION_free);
599 ctx->reqExtensions = exts;
603 /* returns 1 if ctx contains a Subject Alternative Name extension, else 0 */
604 int OSSL_CMP_CTX_reqExtensions_have_SAN(OSSL_CMP_CTX *ctx)
607 CMPerr(0, CMP_R_NULL_ARGUMENT);
610 /* if one of the following conditions 'fail' this is not an error */
611 return ctx->reqExtensions != NULL
612 && X509v3_get_ext_by_NID(ctx->reqExtensions,
613 NID_subject_alt_name, -1) >= 0;
617 * Add a GENERAL_NAME structure that will be added to the CRMF
618 * request's extensions field to request subject alternative names.
619 * Returns 1 on success, 0 on error
621 int OSSL_CMP_CTX_push1_subjectAltName(OSSL_CMP_CTX *ctx,
622 const GENERAL_NAME *name)
624 GENERAL_NAME *name_dup;
626 if (ctx == NULL || name == NULL) {
627 CMPerr(0, CMP_R_NULL_ARGUMENT);
631 if (OSSL_CMP_CTX_reqExtensions_have_SAN(ctx) == 1) {
632 CMPerr(0, CMP_R_MULTIPLE_SAN_SOURCES);
636 if (ctx->subjectAltNames == NULL
637 && (ctx->subjectAltNames = sk_GENERAL_NAME_new_null()) == NULL)
639 if ((name_dup = GENERAL_NAME_dup(name)) == NULL)
641 if (!sk_GENERAL_NAME_push(ctx->subjectAltNames, name_dup)) {
642 GENERAL_NAME_free(name_dup);
649 * Set our own client certificate, used for example in KUR and when
650 * doing the IR with existing certificate.
651 * Returns 1 on success, 0 on error
653 DEFINE_OSSL_CMP_CTX_set1_up_ref(clCert, X509)
656 * Set the old certificate that we are updating in KUR
657 * or the certificate to be revoked in RR, respectively.
658 * Also used as reference cert (defaulting to clCert) for deriving subject DN
659 * and SANs. Its issuer is used as default recipient in the CMP message header.
660 * Returns 1 on success, 0 on error
662 DEFINE_OSSL_CMP_CTX_set1_up_ref(oldCert, X509)
665 * Set the PKCS#10 CSR to be sent in P10CR.
666 * Returns 1 on success, 0 on error
668 DEFINE_OSSL_CMP_CTX_set1(p10CSR, X509_REQ)
671 * Sets the (newly received in IP/KUP/CP) certificate in the context.
672 * Returns 1 on success, 0 on error
673 * TODO: this only permits for one cert to be enrolled at a time.
675 int ossl_cmp_ctx_set0_newCert(OSSL_CMP_CTX *ctx, X509 *cert)
677 if (!ossl_assert(ctx != NULL))
680 X509_free(ctx->newCert);
686 * Get the (newly received in IP/KUP/CP) client certificate from the context
687 * TODO: this only permits for one client cert to be received...
689 X509 *OSSL_CMP_CTX_get0_newCert(const OSSL_CMP_CTX *ctx)
692 CMPerr(0, CMP_R_NULL_ARGUMENT);
699 * Set the client's current private key.
700 * Returns 1 on success, 0 on error
702 DEFINE_OSSL_CMP_CTX_set1_up_ref(pkey, EVP_PKEY)
705 * Set new key pair. Used e.g. when doing Key Update.
706 * Returns 1 on success, 0 on error
708 int OSSL_CMP_CTX_set0_newPkey(OSSL_CMP_CTX *ctx, int priv, EVP_PKEY *pkey)
711 CMPerr(0, CMP_R_NULL_ARGUMENT);
715 EVP_PKEY_free(ctx->newPkey);
717 ctx->newPkey_priv = priv;
722 * gets the private/public key to use for certificate enrollment, NULL on error
724 EVP_PKEY *OSSL_CMP_CTX_get0_newPkey(const OSSL_CMP_CTX *ctx, int priv)
727 CMPerr(0, CMP_R_NULL_ARGUMENT);
731 if (ctx->newPkey != NULL)
732 return priv && !ctx->newPkey_priv ? NULL : ctx->newPkey;
733 if (ctx->p10CSR != NULL)
734 return priv ? NULL : X509_REQ_get0_pubkey(ctx->p10CSR);
735 return ctx->pkey; /* may be NULL */
739 * Sets the given transactionID to the context.
740 * Returns 1 on success, 0 on error
742 int OSSL_CMP_CTX_set1_transactionID(OSSL_CMP_CTX *ctx,
743 const ASN1_OCTET_STRING *id)
746 CMPerr(0, CMP_R_NULL_ARGUMENT);
749 return ossl_cmp_asn1_octet_string_set1(&ctx->transactionID, id);
753 * sets the given nonce to be used for the recipNonce in the next message to be
755 * returns 1 on success, 0 on error
757 int ossl_cmp_ctx_set1_recipNonce(OSSL_CMP_CTX *ctx,
758 const ASN1_OCTET_STRING *nonce)
760 if (!ossl_assert(ctx != NULL))
762 return ossl_cmp_asn1_octet_string_set1(&ctx->recipNonce, nonce);
766 * Stores the given nonce as the last senderNonce sent out.
767 * Returns 1 on success, 0 on error
769 int OSSL_CMP_CTX_set1_senderNonce(OSSL_CMP_CTX *ctx,
770 const ASN1_OCTET_STRING *nonce)
773 CMPerr(0, CMP_R_NULL_ARGUMENT);
776 return ossl_cmp_asn1_octet_string_set1(&ctx->senderNonce, nonce);
780 * Set the host name of the (HTTP) proxy server to use for all connections
781 * returns 1 on success, 0 on error
783 DEFINE_OSSL_CMP_CTX_set1(proxyName, char)
786 * Set the (HTTP) host name of the CA server.
787 * Returns 1 on success, 0 on error
789 DEFINE_OSSL_CMP_CTX_set1(serverName, char)
792 * Sets the (HTTP) proxy port to be used.
793 * Returns 1 on success, 0 on error
795 int OSSL_CMP_CTX_set_proxyPort(OSSL_CMP_CTX *ctx, int port)
798 CMPerr(0, CMP_R_NULL_ARGUMENT);
801 ctx->proxyPort = port;
806 * sets the http connect/disconnect callback function to be used for HTTP(S)
807 * returns 1 on success, 0 on error
809 int OSSL_CMP_CTX_set_http_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_http_cb_t cb)
812 CMPerr(0, CMP_R_NULL_ARGUMENT);
820 * Set argument optionally to be used by the http connect/disconnect callback.
821 * Returns 1 on success, 0 on error
823 int OSSL_CMP_CTX_set_http_cb_arg(OSSL_CMP_CTX *ctx, void *arg)
826 CMPerr(0, CMP_R_NULL_ARGUMENT);
829 ctx->http_cb_arg = arg;
834 * Get argument optionally to be used by the http connect/disconnect callback
835 * Returns callback argument set previously (NULL if not set or on error)
837 void *OSSL_CMP_CTX_get_http_cb_arg(const OSSL_CMP_CTX *ctx)
840 CMPerr(0, CMP_R_NULL_ARGUMENT);
843 return ctx->http_cb_arg;
847 * Set callback function for sending CMP request and receiving response.
848 * Returns 1 on success, 0 on error
850 int OSSL_CMP_CTX_set_transfer_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_transfer_cb_t cb)
853 CMPerr(0, CMP_R_NULL_ARGUMENT);
856 ctx->transfer_cb = cb;
861 * Set argument optionally to be used by the transfer callback.
862 * Returns 1 on success, 0 on error
864 int OSSL_CMP_CTX_set_transfer_cb_arg(OSSL_CMP_CTX *ctx, void *arg)
867 CMPerr(0, CMP_R_NULL_ARGUMENT);
870 ctx->transfer_cb_arg = arg;
875 * Get argument optionally to be used by the transfer callback.
876 * Returns callback argument set previously (NULL if not set or on error)
878 void *OSSL_CMP_CTX_get_transfer_cb_arg(const OSSL_CMP_CTX *ctx)
881 CMPerr(0, CMP_R_NULL_ARGUMENT);
884 return ctx->transfer_cb_arg;
888 * Sets the (HTTP) server port to be used.
889 * Returns 1 on success, 0 on error
891 int OSSL_CMP_CTX_set_serverPort(OSSL_CMP_CTX *ctx, int port)
894 CMPerr(0, CMP_R_NULL_ARGUMENT);
897 ctx->serverPort = port;
902 * Sets the HTTP path to be used on the server (e.g "pkix/").
903 * Returns 1 on success, 0 on error
905 DEFINE_OSSL_CMP_CTX_set1(serverPath, char)
908 * Set the failInfo error code as bit encoding in OSSL_CMP_CTX.
909 * Returns 1 on success, 0 on error
911 int ossl_cmp_ctx_set_failInfoCode(OSSL_CMP_CTX *ctx, int fail_info)
913 if (!ossl_assert(ctx != NULL))
915 ctx->failInfoCode = fail_info;
920 * Get the failInfo error code in OSSL_CMP_CTX as bit encoding.
921 * Returns bit string as integer on success, -1 on error
923 int OSSL_CMP_CTX_get_failInfoCode(const OSSL_CMP_CTX *ctx)
926 CMPerr(0, CMP_R_NULL_ARGUMENT);
929 return ctx->failInfoCode;
933 * Sets a Boolean or integer option of the context to the "val" arg.
934 * Returns 1 on success, 0 on error
936 int OSSL_CMP_CTX_set_option(OSSL_CMP_CTX *ctx, int opt, int val) {
940 CMPerr(0, CMP_R_NULL_ARGUMENT);
945 case OSSL_CMP_OPT_REVOCATION_REASON:
946 min_val = OCSP_REVOKED_STATUS_NOSTATUS;
948 case OSSL_CMP_OPT_POPOMETHOD:
949 min_val = OSSL_CRMF_POPO_NONE;
956 CMPerr(0, CMP_R_INVALID_ARGS);
961 case OSSL_CMP_OPT_LOG_VERBOSITY:
962 if (val > OSSL_CMP_LOG_DEBUG) {
963 CMPerr(0, CMP_R_INVALID_ARGS);
966 ctx->log_verbosity = val;
968 case OSSL_CMP_OPT_IMPLICITCONFIRM:
969 ctx->implicitConfirm = val;
971 case OSSL_CMP_OPT_DISABLECONFIRM:
972 ctx->disableConfirm = val;
974 case OSSL_CMP_OPT_UNPROTECTED_SEND:
975 ctx->unprotectedSend = val;
977 case OSSL_CMP_OPT_UNPROTECTED_ERRORS:
978 ctx->unprotectedErrors = val;
980 case OSSL_CMP_OPT_VALIDITYDAYS:
983 case OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT:
984 ctx->SubjectAltName_nodefault = val;
986 case OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL:
987 ctx->setSubjectAltNameCritical = val;
989 case OSSL_CMP_OPT_POLICIES_CRITICAL:
990 ctx->setPoliciesCritical = val;
992 case OSSL_CMP_OPT_IGNORE_KEYUSAGE:
993 ctx->ignore_keyusage = val;
995 case OSSL_CMP_OPT_POPOMETHOD:
996 if (val > OSSL_CRMF_POPO_KEYAGREE) {
997 CMPerr(0, CMP_R_INVALID_ARGS);
1000 ctx->popoMethod = val;
1002 case OSSL_CMP_OPT_DIGEST_ALGNID:
1005 case OSSL_CMP_OPT_OWF_ALGNID:
1008 case OSSL_CMP_OPT_MAC_ALGNID:
1011 case OSSL_CMP_OPT_MSGTIMEOUT:
1012 ctx->msgtimeout = val;
1014 case OSSL_CMP_OPT_TOTALTIMEOUT:
1015 ctx->totaltimeout = val;
1017 case OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR:
1018 ctx->permitTAInExtraCertsForIR = val;
1020 case OSSL_CMP_OPT_REVOCATION_REASON:
1021 if (val > OCSP_REVOKED_STATUS_AACOMPROMISE) {
1022 CMPerr(0, CMP_R_INVALID_ARGS);
1025 ctx->revocationReason = val;
1028 CMPerr(0, CMP_R_INVALID_ARGS);
1036 * Reads a Boolean or integer option value from the context.
1037 * Returns -1 on error (which is the default OSSL_CMP_OPT_REVOCATION_REASON)
1039 int OSSL_CMP_CTX_get_option(const OSSL_CMP_CTX *ctx, int opt) {
1041 CMPerr(0, CMP_R_NULL_ARGUMENT);
1046 case OSSL_CMP_OPT_LOG_VERBOSITY:
1047 return ctx->log_verbosity;
1048 case OSSL_CMP_OPT_IMPLICITCONFIRM:
1049 return ctx->implicitConfirm;
1050 case OSSL_CMP_OPT_DISABLECONFIRM:
1051 return ctx->disableConfirm;
1052 case OSSL_CMP_OPT_UNPROTECTED_SEND:
1053 return ctx->unprotectedSend;
1054 case OSSL_CMP_OPT_UNPROTECTED_ERRORS:
1055 return ctx->unprotectedErrors;
1056 case OSSL_CMP_OPT_VALIDITYDAYS:
1058 case OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT:
1059 return ctx->SubjectAltName_nodefault;
1060 case OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL:
1061 return ctx->setSubjectAltNameCritical;
1062 case OSSL_CMP_OPT_POLICIES_CRITICAL:
1063 return ctx->setPoliciesCritical;
1064 case OSSL_CMP_OPT_IGNORE_KEYUSAGE:
1065 return ctx->ignore_keyusage;
1066 case OSSL_CMP_OPT_POPOMETHOD:
1067 return ctx->popoMethod;
1068 case OSSL_CMP_OPT_DIGEST_ALGNID:
1070 case OSSL_CMP_OPT_OWF_ALGNID:
1071 return ctx->pbm_owf;
1072 case OSSL_CMP_OPT_MAC_ALGNID:
1073 return ctx->pbm_mac;
1074 case OSSL_CMP_OPT_MSGTIMEOUT:
1075 return ctx->msgtimeout;
1076 case OSSL_CMP_OPT_TOTALTIMEOUT:
1077 return ctx->totaltimeout;
1078 case OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR:
1079 return ctx->permitTAInExtraCertsForIR;
1080 case OSSL_CMP_OPT_REVOCATION_REASON:
1081 return ctx->revocationReason;
1083 CMPerr(0, CMP_R_INVALID_ARGS);