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)
71 STACK_OF(X509) *untrusted_certs;
73 CMPerr(0, CMP_R_NULL_ARGUMENT);
76 if ((untrusted_certs = sk_X509_new_null()) == NULL)
78 if (ossl_cmp_sk_X509_add1_certs(untrusted_certs, certs, 0, 1, 0) != 1)
80 sk_X509_pop_free(ctx->untrusted_certs, X509_free);
81 ctx->untrusted_certs = untrusted_certs;
84 sk_X509_pop_free(untrusted_certs, X509_free);
89 * Allocates and initializes OSSL_CMP_CTX context structure with default values.
90 * Returns new context on success, NULL on error
92 OSSL_CMP_CTX *OSSL_CMP_CTX_new(void)
94 OSSL_CMP_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
99 ctx->log_verbosity = OSSL_CMP_LOG_INFO;
102 ctx->failInfoCode = -1;
104 ctx->serverPort = OSSL_CMP_DEFAULT_PORT;
105 ctx->proxyPort = OSSL_CMP_DEFAULT_PORT;
106 ctx->msgtimeout = 2 * 60;
108 if ((ctx->untrusted_certs = sk_X509_new_null()) == NULL)
112 ctx->pbm_owf = NID_sha256;
113 ctx->pbm_itercnt = 500;
114 ctx->pbm_mac = NID_hmac_sha1;
116 ctx->digest = NID_sha256;
117 ctx->popoMethod = OSSL_CRMF_POPO_SIGNATURE;
118 ctx->revocationReason = CRL_REASON_NONE;
120 /* all other elements are initialized to 0 or NULL, respectively */
124 OSSL_CMP_CTX_free(ctx);
129 * Prepare the OSSL_CMP_CTX for next use, partly re-initializing OSSL_CMP_CTX
131 int OSSL_CMP_CTX_reinit(OSSL_CMP_CTX *ctx)
134 CMPerr(0, CMP_R_NULL_ARGUMENT);
139 ctx->failInfoCode = -1;
141 return ossl_cmp_ctx_set0_statusString(ctx, NULL)
142 && ossl_cmp_ctx_set0_newCert(ctx, NULL)
143 && ossl_cmp_ctx_set1_caPubs(ctx, NULL)
144 && ossl_cmp_ctx_set1_extraCertsIn(ctx, NULL)
145 && ossl_cmp_ctx_set0_validatedSrvCert(ctx, NULL)
146 && OSSL_CMP_CTX_set1_transactionID(ctx, NULL)
147 && OSSL_CMP_CTX_set1_senderNonce(ctx, NULL)
148 && ossl_cmp_ctx_set1_recipNonce(ctx, NULL);
152 * Frees OSSL_CMP_CTX variables allocated in OSSL_CMP_CTX_new()
154 void OSSL_CMP_CTX_free(OSSL_CMP_CTX *ctx)
159 OPENSSL_free(ctx->serverPath);
160 OPENSSL_free(ctx->serverName);
161 OPENSSL_free(ctx->proxyName);
163 X509_free(ctx->srvCert);
164 X509_free(ctx->validatedSrvCert);
165 X509_NAME_free(ctx->expected_sender);
166 X509_STORE_free(ctx->trusted);
167 sk_X509_pop_free(ctx->untrusted_certs, X509_free);
169 X509_free(ctx->clCert);
170 EVP_PKEY_free(ctx->pkey);
171 ASN1_OCTET_STRING_free(ctx->referenceValue);
172 if (ctx->secretValue != NULL)
173 OPENSSL_cleanse(ctx->secretValue->data, ctx->secretValue->length);
174 ASN1_OCTET_STRING_free(ctx->secretValue);
176 X509_NAME_free(ctx->recipient);
177 ASN1_OCTET_STRING_free(ctx->transactionID);
178 ASN1_OCTET_STRING_free(ctx->senderNonce);
179 ASN1_OCTET_STRING_free(ctx->recipNonce);
180 sk_OSSL_CMP_ITAV_pop_free(ctx->geninfo_ITAVs, OSSL_CMP_ITAV_free);
181 sk_X509_pop_free(ctx->extraCertsOut, X509_free);
183 EVP_PKEY_free(ctx->newPkey);
184 X509_NAME_free(ctx->issuer);
185 X509_NAME_free(ctx->subjectName);
186 sk_GENERAL_NAME_pop_free(ctx->subjectAltNames, GENERAL_NAME_free);
187 sk_X509_EXTENSION_pop_free(ctx->reqExtensions, X509_EXTENSION_free);
188 sk_POLICYINFO_pop_free(ctx->policies, POLICYINFO_free);
189 X509_free(ctx->oldCert);
190 X509_REQ_free(ctx->p10CSR);
192 sk_OSSL_CMP_ITAV_pop_free(ctx->genm_ITAVs, OSSL_CMP_ITAV_free);
194 sk_ASN1_UTF8STRING_pop_free(ctx->statusString, ASN1_UTF8STRING_free);
195 X509_free(ctx->newCert);
196 sk_X509_pop_free(ctx->caPubs, X509_free);
197 sk_X509_pop_free(ctx->extraCertsIn, X509_free);
202 int ossl_cmp_ctx_set_status(OSSL_CMP_CTX *ctx, int status)
204 if (!ossl_assert(ctx != NULL))
206 ctx->status = status;
211 * Returns the PKIStatus from the last CertRepMessage
212 * or Revocation Response or error message, -1 on error
214 int OSSL_CMP_CTX_get_status(const OSSL_CMP_CTX *ctx)
217 CMPerr(0, CMP_R_NULL_ARGUMENT);
224 * Returns the statusString from the last CertRepMessage
225 * or Revocation Response or error message, NULL on error
227 OSSL_CMP_PKIFREETEXT *OSSL_CMP_CTX_get0_statusString(const OSSL_CMP_CTX *ctx)
230 CMPerr(0, CMP_R_NULL_ARGUMENT);
233 return ctx->statusString;
236 int ossl_cmp_ctx_set0_statusString(OSSL_CMP_CTX *ctx,
237 OSSL_CMP_PKIFREETEXT *text)
239 if (!ossl_assert(ctx != NULL))
241 sk_ASN1_UTF8STRING_pop_free(ctx->statusString, ASN1_UTF8STRING_free);
242 ctx->statusString = text;
246 int ossl_cmp_ctx_set0_validatedSrvCert(OSSL_CMP_CTX *ctx, X509 *cert)
248 if (!ossl_assert(ctx != NULL))
250 X509_free(ctx->validatedSrvCert);
251 ctx->validatedSrvCert = cert;
256 * Set callback function for checking if the cert is ok or should
258 * Returns 1 on success, 0 on error
260 int OSSL_CMP_CTX_set_certConf_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_certConf_cb_t cb)
263 CMPerr(0, CMP_R_NULL_ARGUMENT);
266 ctx->certConf_cb = cb;
271 * Set argument, respectively a pointer to a structure containing arguments,
272 * optionally to be used by the certConf callback.
273 * Returns 1 on success, 0 on error
275 int OSSL_CMP_CTX_set_certConf_cb_arg(OSSL_CMP_CTX *ctx, void *arg)
278 CMPerr(0, CMP_R_NULL_ARGUMENT);
281 ctx->certConf_cb_arg = arg;
286 * Get argument, respectively the pointer to a structure containing arguments,
287 * optionally to be used by certConf callback.
288 * Returns callback argument set previously (NULL if not set or on error)
290 void *OSSL_CMP_CTX_get_certConf_cb_arg(const OSSL_CMP_CTX *ctx)
293 CMPerr(0, CMP_R_NULL_ARGUMENT);
296 return ctx->certConf_cb_arg;
299 #ifndef OPENSSL_NO_TRACE
300 static size_t ossl_cmp_log_trace_cb(const char *buf, size_t cnt,
301 int category, int cmd, void *vdata)
303 OSSL_CMP_CTX *ctx = vdata;
304 const char *prefix_msg;
305 OSSL_CMP_severity level = -1;
310 if (buf == NULL || cnt == 0 || cmd != OSSL_TRACE_CTRL_WRITE || ctx == NULL)
312 if (ctx->log_cb == NULL)
313 return 1; /* silently drop message */
315 prefix_msg = ossl_cmp_log_parse_metadata(buf, &level, &func, &file, &line);
317 if (level > ctx->log_verbosity) /* excludes the case level is unknown */
318 goto end; /* suppress output since severity is not sufficient */
320 if (!ctx->log_cb(func != NULL ? func : "(no func)",
321 file != NULL ? file : "(no file)",
322 line, level, prefix_msg))
333 * Set a callback function for error reporting and logging messages.
334 * Returns 1 on success, 0 on error
336 int OSSL_CMP_CTX_set_log_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_log_cb_t cb)
339 CMPerr(0, CMP_R_NULL_ARGUMENT);
344 #ifndef OPENSSL_NO_TRACE
345 /* do also in case cb == NULL, to switch off logging output: */
346 if (!OSSL_trace_set_callback(OSSL_TRACE_CATEGORY_CMP,
347 ossl_cmp_log_trace_cb, ctx))
354 /* Print OpenSSL and CMP errors via the log cb of the ctx or ERR_print_errors */
355 void OSSL_CMP_CTX_print_errors(OSSL_CMP_CTX *ctx)
357 OSSL_CMP_print_errors_cb(ctx == NULL ? NULL : ctx->log_cb);
361 * Set or clear the reference value to be used for identification
362 * (i.e., the user name) when using PBMAC.
363 * Returns 1 on success, 0 on error
365 int OSSL_CMP_CTX_set1_referenceValue(OSSL_CMP_CTX *ctx,
366 const unsigned char *ref, int len)
369 CMPerr(0, CMP_R_NULL_ARGUMENT);
372 return ossl_cmp_asn1_octet_string_set1_bytes(&ctx->referenceValue, ref,
377 * Set or clear the password to be used for protecting messages with PBMAC.
378 * Returns 1 on success, 0 on error
380 int OSSL_CMP_CTX_set1_secretValue(OSSL_CMP_CTX *ctx, const unsigned char *sec,
383 ASN1_OCTET_STRING *secretValue = NULL;
385 CMPerr(0, CMP_R_NULL_ARGUMENT);
388 if (ossl_cmp_asn1_octet_string_set1_bytes(&secretValue, sec, len) != 1)
390 if (ctx->secretValue != NULL) {
391 OPENSSL_cleanse(ctx->secretValue->data, ctx->secretValue->length);
392 ASN1_OCTET_STRING_free(ctx->secretValue);
394 ctx->secretValue = secretValue;
399 * Returns the stack of certificates received in a response message.
400 * The stack is duplicated so the caller must handle freeing it!
401 * Returns pointer to created stack on success, NULL on error
403 STACK_OF(X509) *OSSL_CMP_CTX_get1_extraCertsIn(const OSSL_CMP_CTX *ctx)
406 CMPerr(0, CMP_R_NULL_ARGUMENT);
409 if (ctx->extraCertsIn == NULL)
410 return sk_X509_new_null();
411 return X509_chain_up_ref(ctx->extraCertsIn);
415 * Copies any given stack of inbound X509 certificates to extraCertsIn
416 * of the OSSL_CMP_CTX structure so that they may be retrieved later.
417 * Returns 1 on success, 0 on error.
419 int ossl_cmp_ctx_set1_extraCertsIn(OSSL_CMP_CTX *ctx,
420 STACK_OF(X509) *extraCertsIn)
422 if (!ossl_assert(ctx != NULL))
425 sk_X509_pop_free(ctx->extraCertsIn, X509_free);
426 ctx->extraCertsIn = NULL;
427 if (extraCertsIn == NULL)
429 return (ctx->extraCertsIn = X509_chain_up_ref(extraCertsIn)) != NULL;
433 * Duplicate and set the given stack as the new stack of X509
434 * certificates to send out in the extraCerts field.
435 * Returns 1 on success, 0 on error
437 int OSSL_CMP_CTX_set1_extraCertsOut(OSSL_CMP_CTX *ctx,
438 STACK_OF(X509) *extraCertsOut)
441 CMPerr(0, CMP_R_NULL_ARGUMENT);
445 sk_X509_pop_free(ctx->extraCertsOut, X509_free);
446 ctx->extraCertsOut = NULL;
447 if (extraCertsOut == NULL)
449 return (ctx->extraCertsOut = X509_chain_up_ref(extraCertsOut)) != NULL;
453 * Add the given policy info object
454 * to the X509_EXTENSIONS of the requested certificate template.
455 * Returns 1 on success, 0 on error.
457 int OSSL_CMP_CTX_push0_policy(OSSL_CMP_CTX *ctx, POLICYINFO *pinfo)
459 if (ctx == NULL || pinfo == NULL) {
460 CMPerr(0, CMP_R_NULL_ARGUMENT);
464 if (ctx->policies == NULL
465 && (ctx->policies = CERTIFICATEPOLICIES_new()) == NULL)
468 return sk_POLICYINFO_push(ctx->policies, pinfo);
472 * Add an ITAV for geninfo of the PKI message header
474 int OSSL_CMP_CTX_push0_geninfo_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav)
477 CMPerr(0, CMP_R_NULL_ARGUMENT);
480 return OSSL_CMP_ITAV_push0_stack_item(&ctx->geninfo_ITAVs, itav);
484 * Add an itav for the body of outgoing general messages
486 int OSSL_CMP_CTX_push0_genm_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav)
489 CMPerr(0, CMP_R_NULL_ARGUMENT);
492 return OSSL_CMP_ITAV_push0_stack_item(&ctx->genm_ITAVs, itav);
496 * Returns a duplicate of the stack of X509 certificates that
497 * were received in the caPubs field of the last CertRepMessage.
498 * Returns NULL on error
500 STACK_OF(X509) *OSSL_CMP_CTX_get1_caPubs(const OSSL_CMP_CTX *ctx)
503 CMPerr(0, CMP_R_NULL_ARGUMENT);
506 if (ctx->caPubs == NULL)
507 return sk_X509_new_null();
508 return X509_chain_up_ref(ctx->caPubs);
512 * Duplicate and copy the given stack of certificates to the given
513 * OSSL_CMP_CTX structure so that they may be retrieved later.
514 * Returns 1 on success, 0 on error
516 int ossl_cmp_ctx_set1_caPubs(OSSL_CMP_CTX *ctx, STACK_OF(X509) *caPubs)
518 if (!ossl_assert(ctx != NULL))
521 sk_X509_pop_free(ctx->caPubs, X509_free);
525 return (ctx->caPubs = X509_chain_up_ref(caPubs)) != NULL;
528 #define char_dup OPENSSL_strdup
529 #define char_free OPENSSL_free
530 #define DEFINE_OSSL_CMP_CTX_set1(FIELD, TYPE) /* this uses _dup */ \
531 int OSSL_CMP_CTX_set1_##FIELD(OSSL_CMP_CTX *ctx, const TYPE *val) \
533 TYPE *val_dup = NULL; \
536 CMPerr(0, CMP_R_NULL_ARGUMENT); \
540 if (val != NULL && (val_dup = TYPE##_dup(val)) == NULL) \
542 TYPE##_free(ctx->FIELD); \
543 ctx->FIELD = val_dup; \
547 #define DEFINE_OSSL_CMP_CTX_set1_up_ref(FIELD, TYPE) \
548 int OSSL_CMP_CTX_set1_##FIELD(OSSL_CMP_CTX *ctx, TYPE *val) \
551 CMPerr(0, CMP_R_NULL_ARGUMENT); \
555 if (val != NULL && !TYPE##_up_ref(val)) \
557 TYPE##_free(ctx->FIELD); \
563 * Pins the server certificate to be directly trusted (even if it is expired)
564 * for verifying response messages.
565 * Cert pointer is not consumed. It may be NULL to clear the entry.
566 * Returns 1 on success, 0 on error
568 DEFINE_OSSL_CMP_CTX_set1_up_ref(srvCert, X509)
571 * Set the X509 name of the recipient. Set in the PKIHeader.
572 * returns 1 on success, 0 on error
574 DEFINE_OSSL_CMP_CTX_set1(recipient, X509_NAME)
577 * Store the X509 name of the expected sender in the PKIHeader of responses.
578 * Returns 1 on success, 0 on error
580 DEFINE_OSSL_CMP_CTX_set1(expected_sender, X509_NAME)
583 * Set the X509 name of the issuer. Set in the PKIHeader.
584 * Returns 1 on success, 0 on error
586 DEFINE_OSSL_CMP_CTX_set1(issuer, X509_NAME)
589 * Set the subject name that will be placed in the certificate
590 * request. This will be the subject name on the received certificate.
591 * Returns 1 on success, 0 on error
593 DEFINE_OSSL_CMP_CTX_set1(subjectName, X509_NAME)
596 * Set the X.509v3 certificate request extensions to be used in IR/CR/KUR.
597 * Returns 1 on success, 0 on error
599 int OSSL_CMP_CTX_set0_reqExtensions(OSSL_CMP_CTX *ctx, X509_EXTENSIONS *exts)
602 CMPerr(0, CMP_R_NULL_ARGUMENT);
606 if (sk_GENERAL_NAME_num(ctx->subjectAltNames) > 0 && exts != NULL
607 && X509v3_get_ext_by_NID(exts, NID_subject_alt_name, -1) >= 0) {
608 CMPerr(0, CMP_R_MULTIPLE_SAN_SOURCES);
611 sk_X509_EXTENSION_pop_free(ctx->reqExtensions, X509_EXTENSION_free);
612 ctx->reqExtensions = exts;
616 /* returns 1 if ctx contains a Subject Alternative Name extension, else 0 */
617 int OSSL_CMP_CTX_reqExtensions_have_SAN(OSSL_CMP_CTX *ctx)
620 CMPerr(0, CMP_R_NULL_ARGUMENT);
623 /* if one of the following conditions 'fail' this is not an error */
624 return ctx->reqExtensions != NULL
625 && X509v3_get_ext_by_NID(ctx->reqExtensions,
626 NID_subject_alt_name, -1) >= 0;
630 * Add a GENERAL_NAME structure that will be added to the CRMF
631 * request's extensions field to request subject alternative names.
632 * Returns 1 on success, 0 on error
634 int OSSL_CMP_CTX_push1_subjectAltName(OSSL_CMP_CTX *ctx,
635 const GENERAL_NAME *name)
637 GENERAL_NAME *name_dup;
639 if (ctx == NULL || name == NULL) {
640 CMPerr(0, CMP_R_NULL_ARGUMENT);
644 if (OSSL_CMP_CTX_reqExtensions_have_SAN(ctx) == 1) {
645 CMPerr(0, CMP_R_MULTIPLE_SAN_SOURCES);
649 if (ctx->subjectAltNames == NULL
650 && (ctx->subjectAltNames = sk_GENERAL_NAME_new_null()) == NULL)
652 if ((name_dup = GENERAL_NAME_dup(name)) == NULL)
654 if (!sk_GENERAL_NAME_push(ctx->subjectAltNames, name_dup)) {
655 GENERAL_NAME_free(name_dup);
662 * Set our own client certificate, used for example in KUR and when
663 * doing the IR with existing certificate.
664 * Returns 1 on success, 0 on error
666 DEFINE_OSSL_CMP_CTX_set1_up_ref(clCert, X509)
669 * Set the old certificate that we are updating in KUR
670 * or the certificate to be revoked in RR, respectively.
671 * Also used as reference cert (defaulting to clCert) for deriving subject DN
672 * and SANs. Its issuer is used as default recipient in the CMP message header.
673 * Returns 1 on success, 0 on error
675 DEFINE_OSSL_CMP_CTX_set1_up_ref(oldCert, X509)
678 * Set the PKCS#10 CSR to be sent in P10CR.
679 * Returns 1 on success, 0 on error
681 DEFINE_OSSL_CMP_CTX_set1(p10CSR, X509_REQ)
684 * Sets the (newly received in IP/KUP/CP) certificate in the context.
685 * Returns 1 on success, 0 on error
686 * TODO: this only permits for one cert to be enrolled at a time.
688 int ossl_cmp_ctx_set0_newCert(OSSL_CMP_CTX *ctx, X509 *cert)
690 if (!ossl_assert(ctx != NULL))
693 X509_free(ctx->newCert);
699 * Get the (newly received in IP/KUP/CP) client certificate from the context
700 * TODO: this only permits for one client cert to be received...
702 X509 *OSSL_CMP_CTX_get0_newCert(const OSSL_CMP_CTX *ctx)
705 CMPerr(0, CMP_R_NULL_ARGUMENT);
712 * Set the client's current private key.
713 * Returns 1 on success, 0 on error
715 DEFINE_OSSL_CMP_CTX_set1_up_ref(pkey, EVP_PKEY)
718 * Set new key pair. Used e.g. when doing Key Update.
719 * Returns 1 on success, 0 on error
721 int OSSL_CMP_CTX_set0_newPkey(OSSL_CMP_CTX *ctx, int priv, EVP_PKEY *pkey)
724 CMPerr(0, CMP_R_NULL_ARGUMENT);
728 EVP_PKEY_free(ctx->newPkey);
730 ctx->newPkey_priv = priv;
735 * gets the private/public key to use for certificate enrollment, NULL on error
737 EVP_PKEY *OSSL_CMP_CTX_get0_newPkey(const OSSL_CMP_CTX *ctx, int priv)
740 CMPerr(0, CMP_R_NULL_ARGUMENT);
744 if (ctx->newPkey != NULL)
745 return priv && !ctx->newPkey_priv ? NULL : ctx->newPkey;
746 if (ctx->p10CSR != NULL)
747 return priv ? NULL : X509_REQ_get0_pubkey(ctx->p10CSR);
748 return ctx->pkey; /* may be NULL */
752 * Sets the given transactionID to the context.
753 * Returns 1 on success, 0 on error
755 int OSSL_CMP_CTX_set1_transactionID(OSSL_CMP_CTX *ctx,
756 const ASN1_OCTET_STRING *id)
759 CMPerr(0, CMP_R_NULL_ARGUMENT);
762 return ossl_cmp_asn1_octet_string_set1(&ctx->transactionID, id);
766 * sets the given nonce to be used for the recipNonce in the next message to be
768 * returns 1 on success, 0 on error
770 int ossl_cmp_ctx_set1_recipNonce(OSSL_CMP_CTX *ctx,
771 const ASN1_OCTET_STRING *nonce)
773 if (!ossl_assert(ctx != NULL))
775 return ossl_cmp_asn1_octet_string_set1(&ctx->recipNonce, nonce);
779 * Stores the given nonce as the last senderNonce sent out.
780 * Returns 1 on success, 0 on error
782 int OSSL_CMP_CTX_set1_senderNonce(OSSL_CMP_CTX *ctx,
783 const ASN1_OCTET_STRING *nonce)
786 CMPerr(0, CMP_R_NULL_ARGUMENT);
789 return ossl_cmp_asn1_octet_string_set1(&ctx->senderNonce, nonce);
793 * Set the host name of the (HTTP) proxy server to use for all connections
794 * returns 1 on success, 0 on error
796 DEFINE_OSSL_CMP_CTX_set1(proxyName, char)
799 * Set the (HTTP) host name of the CA server.
800 * Returns 1 on success, 0 on error
802 DEFINE_OSSL_CMP_CTX_set1(serverName, char)
805 * Sets the (HTTP) proxy port to be used.
806 * Returns 1 on success, 0 on error
808 int OSSL_CMP_CTX_set_proxyPort(OSSL_CMP_CTX *ctx, int port)
811 CMPerr(0, CMP_R_NULL_ARGUMENT);
814 ctx->proxyPort = port;
819 * sets the http connect/disconnect callback function to be used for HTTP(S)
820 * returns 1 on success, 0 on error
822 int OSSL_CMP_CTX_set_http_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_http_cb_t cb)
825 CMPerr(0, CMP_R_NULL_ARGUMENT);
833 * Set argument optionally to be used by the http connect/disconnect callback.
834 * Returns 1 on success, 0 on error
836 int OSSL_CMP_CTX_set_http_cb_arg(OSSL_CMP_CTX *ctx, void *arg)
839 CMPerr(0, CMP_R_NULL_ARGUMENT);
842 ctx->http_cb_arg = arg;
847 * Get argument optionally to be used by the http connect/disconnect callback
848 * Returns callback argument set previously (NULL if not set or on error)
850 void *OSSL_CMP_CTX_get_http_cb_arg(const OSSL_CMP_CTX *ctx)
853 CMPerr(0, CMP_R_NULL_ARGUMENT);
856 return ctx->http_cb_arg;
860 * Set callback function for sending CMP request and receiving response.
861 * Returns 1 on success, 0 on error
863 int OSSL_CMP_CTX_set_transfer_cb(OSSL_CMP_CTX *ctx, OSSL_cmp_transfer_cb_t cb)
866 CMPerr(0, CMP_R_NULL_ARGUMENT);
869 ctx->transfer_cb = cb;
874 * Set argument optionally to be used by the transfer callback.
875 * Returns 1 on success, 0 on error
877 int OSSL_CMP_CTX_set_transfer_cb_arg(OSSL_CMP_CTX *ctx, void *arg)
880 CMPerr(0, CMP_R_NULL_ARGUMENT);
883 ctx->transfer_cb_arg = arg;
888 * Get argument optionally to be used by the transfer callback.
889 * Returns callback argument set previously (NULL if not set or on error)
891 void *OSSL_CMP_CTX_get_transfer_cb_arg(const OSSL_CMP_CTX *ctx)
894 CMPerr(0, CMP_R_NULL_ARGUMENT);
897 return ctx->transfer_cb_arg;
901 * Sets the (HTTP) server port to be used.
902 * Returns 1 on success, 0 on error
904 int OSSL_CMP_CTX_set_serverPort(OSSL_CMP_CTX *ctx, int port)
907 CMPerr(0, CMP_R_NULL_ARGUMENT);
910 ctx->serverPort = port;
915 * Sets the HTTP path to be used on the server (e.g "pkix/").
916 * Returns 1 on success, 0 on error
918 DEFINE_OSSL_CMP_CTX_set1(serverPath, char)
921 * Set the failInfo error code as bit encoding in OSSL_CMP_CTX.
922 * Returns 1 on success, 0 on error
924 int ossl_cmp_ctx_set_failInfoCode(OSSL_CMP_CTX *ctx, int fail_info)
926 if (!ossl_assert(ctx != NULL))
928 ctx->failInfoCode = fail_info;
933 * Get the failInfo error code in OSSL_CMP_CTX as bit encoding.
934 * Returns bit string as integer on success, -1 on error
936 int OSSL_CMP_CTX_get_failInfoCode(const OSSL_CMP_CTX *ctx)
939 CMPerr(0, CMP_R_NULL_ARGUMENT);
942 return ctx->failInfoCode;
946 * Sets a Boolean or integer option of the context to the "val" arg.
947 * Returns 1 on success, 0 on error
949 int OSSL_CMP_CTX_set_option(OSSL_CMP_CTX *ctx, int opt, int val) {
953 CMPerr(0, CMP_R_NULL_ARGUMENT);
958 case OSSL_CMP_OPT_REVOCATION_REASON:
959 min_val = OCSP_REVOKED_STATUS_NOSTATUS;
961 case OSSL_CMP_OPT_POPOMETHOD:
962 min_val = OSSL_CRMF_POPO_NONE;
969 CMPerr(0, CMP_R_INVALID_ARGS);
974 case OSSL_CMP_OPT_LOG_VERBOSITY:
975 if (val > OSSL_CMP_LOG_DEBUG) {
976 CMPerr(0, CMP_R_INVALID_ARGS);
979 ctx->log_verbosity = val;
981 case OSSL_CMP_OPT_IMPLICITCONFIRM:
982 ctx->implicitConfirm = val;
984 case OSSL_CMP_OPT_DISABLECONFIRM:
985 ctx->disableConfirm = val;
987 case OSSL_CMP_OPT_UNPROTECTED_SEND:
988 ctx->unprotectedSend = val;
990 case OSSL_CMP_OPT_UNPROTECTED_ERRORS:
991 ctx->unprotectedErrors = val;
993 case OSSL_CMP_OPT_VALIDITYDAYS:
996 case OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT:
997 ctx->SubjectAltName_nodefault = val;
999 case OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL:
1000 ctx->setSubjectAltNameCritical = val;
1002 case OSSL_CMP_OPT_POLICIES_CRITICAL:
1003 ctx->setPoliciesCritical = val;
1005 case OSSL_CMP_OPT_IGNORE_KEYUSAGE:
1006 ctx->ignore_keyusage = val;
1008 case OSSL_CMP_OPT_POPOMETHOD:
1009 if (val > OSSL_CRMF_POPO_KEYAGREE) {
1010 CMPerr(0, CMP_R_INVALID_ARGS);
1013 ctx->popoMethod = val;
1015 case OSSL_CMP_OPT_DIGEST_ALGNID:
1018 case OSSL_CMP_OPT_OWF_ALGNID:
1021 case OSSL_CMP_OPT_MAC_ALGNID:
1024 case OSSL_CMP_OPT_MSGTIMEOUT:
1025 ctx->msgtimeout = val;
1027 case OSSL_CMP_OPT_TOTALTIMEOUT:
1028 ctx->totaltimeout = val;
1030 case OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR:
1031 ctx->permitTAInExtraCertsForIR = val;
1033 case OSSL_CMP_OPT_REVOCATION_REASON:
1034 if (val > OCSP_REVOKED_STATUS_AACOMPROMISE) {
1035 CMPerr(0, CMP_R_INVALID_ARGS);
1038 ctx->revocationReason = val;
1041 CMPerr(0, CMP_R_INVALID_ARGS);
1049 * Reads a Boolean or integer option value from the context.
1050 * Returns -1 on error (which is the default OSSL_CMP_OPT_REVOCATION_REASON)
1052 int OSSL_CMP_CTX_get_option(const OSSL_CMP_CTX *ctx, int opt) {
1054 CMPerr(0, CMP_R_NULL_ARGUMENT);
1059 case OSSL_CMP_OPT_LOG_VERBOSITY:
1060 return ctx->log_verbosity;
1061 case OSSL_CMP_OPT_IMPLICITCONFIRM:
1062 return ctx->implicitConfirm;
1063 case OSSL_CMP_OPT_DISABLECONFIRM:
1064 return ctx->disableConfirm;
1065 case OSSL_CMP_OPT_UNPROTECTED_SEND:
1066 return ctx->unprotectedSend;
1067 case OSSL_CMP_OPT_UNPROTECTED_ERRORS:
1068 return ctx->unprotectedErrors;
1069 case OSSL_CMP_OPT_VALIDITYDAYS:
1071 case OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT:
1072 return ctx->SubjectAltName_nodefault;
1073 case OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL:
1074 return ctx->setSubjectAltNameCritical;
1075 case OSSL_CMP_OPT_POLICIES_CRITICAL:
1076 return ctx->setPoliciesCritical;
1077 case OSSL_CMP_OPT_IGNORE_KEYUSAGE:
1078 return ctx->ignore_keyusage;
1079 case OSSL_CMP_OPT_POPOMETHOD:
1080 return ctx->popoMethod;
1081 case OSSL_CMP_OPT_DIGEST_ALGNID:
1083 case OSSL_CMP_OPT_OWF_ALGNID:
1084 return ctx->pbm_owf;
1085 case OSSL_CMP_OPT_MAC_ALGNID:
1086 return ctx->pbm_mac;
1087 case OSSL_CMP_OPT_MSGTIMEOUT:
1088 return ctx->msgtimeout;
1089 case OSSL_CMP_OPT_TOTALTIMEOUT:
1090 return ctx->totaltimeout;
1091 case OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR:
1092 return ctx->permitTAInExtraCertsForIR;
1093 case OSSL_CMP_OPT_REVOCATION_REASON:
1094 return ctx->revocationReason;
1096 CMPerr(0, CMP_R_INVALID_ARGS);