cmp_ctx.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  1. /*
  2. * Copyright 2007-2024 The OpenSSL Project Authors. All Rights Reserved.
  3. * Copyright Nokia 2007-2019
  4. * Copyright Siemens AG 2015-2019
  5. *
  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
  10. */
  11. #include <openssl/trace.h>
  12. #include <openssl/bio.h>
  13. #include <openssl/ocsp.h> /* for OCSP_REVOKED_STATUS_* */
  14. #include "cmp_local.h"
  15. /* explicit #includes not strictly needed since implied by the above: */
  16. #include <openssl/cmp.h>
  17. #include <openssl/crmf.h>
  18. #include <openssl/err.h>
  19. #define DEFINE_OSSL_CMP_CTX_get0(FIELD, TYPE) \
  20. DEFINE_OSSL_CMP_CTX_get0_NAME(FIELD, FIELD, TYPE)
  21. #define DEFINE_OSSL_CMP_CTX_get0_NAME(NAME, FIELD, TYPE) \
  22. TYPE *OSSL_CMP_CTX_get0_##NAME(const OSSL_CMP_CTX *ctx) \
  23. { \
  24. if (ctx == NULL) { \
  25. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); \
  26. return NULL; \
  27. } \
  28. return ctx->FIELD; \
  29. }
  30. /*
  31. * Get current certificate store containing trusted root CA certs
  32. */
  33. DEFINE_OSSL_CMP_CTX_get0_NAME(trusted, trusted, X509_STORE)
  34. #define DEFINE_OSSL_set0(PREFIX, FIELD, TYPE) \
  35. DEFINE_OSSL_set0_NAME(PREFIX, FIELD, FIELD, TYPE)
  36. #define DEFINE_OSSL_set0_NAME(PREFIX, NAME, FIELD, TYPE) \
  37. int PREFIX##_set0##_##NAME(OSSL_CMP_CTX *ctx, TYPE *val) \
  38. { \
  39. if (ctx == NULL) { \
  40. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); \
  41. return 0; \
  42. } \
  43. TYPE##_free(ctx->FIELD); \
  44. ctx->FIELD = val; \
  45. return 1; \
  46. }
  47. /*
  48. * Set certificate store containing trusted (root) CA certs and possibly CRLs
  49. * and a cert verification callback function used for CMP server authentication.
  50. * Any already existing store entry is freed. Given NULL, the entry is reset.
  51. */
  52. DEFINE_OSSL_set0_NAME(OSSL_CMP_CTX, trusted, trusted, X509_STORE)
  53. DEFINE_OSSL_CMP_CTX_get0(libctx, OSSL_LIB_CTX)
  54. DEFINE_OSSL_CMP_CTX_get0(propq, const char)
  55. /* Get current list of non-trusted intermediate certs */
  56. DEFINE_OSSL_CMP_CTX_get0(untrusted, STACK_OF(X509))
  57. /*
  58. * Set untrusted certificates for path construction in authentication of
  59. * the CMP server and potentially others (TLS server, newly enrolled cert).
  60. */
  61. int OSSL_CMP_CTX_set1_untrusted(OSSL_CMP_CTX *ctx, STACK_OF(X509) *certs)
  62. {
  63. STACK_OF(X509) *untrusted = NULL;
  64. if (ctx == NULL) {
  65. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  66. return 0;
  67. }
  68. if (!ossl_x509_add_certs_new(&untrusted, certs,
  69. X509_ADD_FLAG_UP_REF | X509_ADD_FLAG_NO_DUP))
  70. goto err;
  71. OSSL_STACK_OF_X509_free(ctx->untrusted);
  72. ctx->untrusted = untrusted;
  73. return 1;
  74. err:
  75. OSSL_STACK_OF_X509_free(untrusted);
  76. return 0;
  77. }
  78. static int cmp_ctx_set_md(OSSL_CMP_CTX *ctx, EVP_MD **pmd, int nid)
  79. {
  80. EVP_MD *md = EVP_MD_fetch(ctx->libctx, OBJ_nid2sn(nid), ctx->propq);
  81. /* fetching in advance to be able to throw error early if unsupported */
  82. if (md == NULL) {
  83. ERR_raise(ERR_LIB_CMP, CMP_R_UNSUPPORTED_ALGORITHM);
  84. return 0;
  85. }
  86. EVP_MD_free(*pmd);
  87. *pmd = md;
  88. return 1;
  89. }
  90. /*
  91. * Allocates and initializes OSSL_CMP_CTX context structure with default values.
  92. * Returns new context on success, NULL on error
  93. */
  94. OSSL_CMP_CTX *OSSL_CMP_CTX_new(OSSL_LIB_CTX *libctx, const char *propq)
  95. {
  96. OSSL_CMP_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
  97. if (ctx == NULL)
  98. goto err;
  99. ctx->libctx = libctx;
  100. if (propq != NULL && (ctx->propq = OPENSSL_strdup(propq)) == NULL)
  101. goto err;
  102. ctx->log_verbosity = OSSL_CMP_LOG_INFO;
  103. ctx->status = OSSL_CMP_PKISTATUS_unspecified;
  104. ctx->failInfoCode = -1;
  105. ctx->keep_alive = 1;
  106. ctx->msg_timeout = -1;
  107. ctx->tls_used = -1; /* default for backward compatibility */
  108. if ((ctx->untrusted = sk_X509_new_null()) == NULL) {
  109. ERR_raise(ERR_LIB_X509, ERR_R_CRYPTO_LIB);
  110. goto err;
  111. }
  112. ctx->pbm_slen = 16;
  113. if (!cmp_ctx_set_md(ctx, &ctx->pbm_owf, NID_sha256))
  114. goto err;
  115. ctx->pbm_itercnt = 500;
  116. ctx->pbm_mac = NID_hmac_sha1;
  117. if (!cmp_ctx_set_md(ctx, &ctx->digest, NID_sha256))
  118. goto err;
  119. ctx->popoMethod = OSSL_CRMF_POPO_SIGNATURE;
  120. ctx->revocationReason = CRL_REASON_NONE;
  121. /* all other elements are initialized to 0 or NULL, respectively */
  122. return ctx;
  123. err:
  124. OSSL_CMP_CTX_free(ctx);
  125. return NULL;
  126. }
  127. #define OSSL_CMP_ITAVs_free(itavs) \
  128. sk_OSSL_CMP_ITAV_pop_free(itavs, OSSL_CMP_ITAV_free);
  129. #define X509_EXTENSIONS_free(exts) \
  130. sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free)
  131. #define OSSL_CMP_PKIFREETEXT_free(text) \
  132. sk_ASN1_UTF8STRING_pop_free(text, ASN1_UTF8STRING_free)
  133. /* Prepare the OSSL_CMP_CTX for next use, partly re-initializing OSSL_CMP_CTX */
  134. int OSSL_CMP_CTX_reinit(OSSL_CMP_CTX *ctx)
  135. {
  136. if (ctx == NULL) {
  137. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  138. return 0;
  139. }
  140. #ifndef OPENSSL_NO_HTTP
  141. if (ctx->http_ctx != NULL) {
  142. (void)OSSL_HTTP_close(ctx->http_ctx, 1);
  143. ossl_cmp_debug(ctx, "disconnected from CMP server");
  144. ctx->http_ctx = NULL;
  145. }
  146. #endif
  147. ctx->status = OSSL_CMP_PKISTATUS_unspecified;
  148. ctx->failInfoCode = -1;
  149. OSSL_CMP_ITAVs_free(ctx->genm_ITAVs);
  150. ctx->genm_ITAVs = NULL;
  151. return ossl_cmp_ctx_set0_statusString(ctx, NULL)
  152. && ossl_cmp_ctx_set0_newCert(ctx, NULL)
  153. && ossl_cmp_ctx_set1_newChain(ctx, NULL)
  154. && ossl_cmp_ctx_set1_caPubs(ctx, NULL)
  155. && ossl_cmp_ctx_set1_extraCertsIn(ctx, NULL)
  156. && ossl_cmp_ctx_set1_validatedSrvCert(ctx, NULL)
  157. && ossl_cmp_ctx_set1_first_senderNonce(ctx, NULL)
  158. && OSSL_CMP_CTX_set1_transactionID(ctx, NULL)
  159. && OSSL_CMP_CTX_set1_senderNonce(ctx, NULL)
  160. && ossl_cmp_ctx_set1_recipNonce(ctx, NULL);
  161. }
  162. /* Frees OSSL_CMP_CTX variables allocated in OSSL_CMP_CTX_new() */
  163. void OSSL_CMP_CTX_free(OSSL_CMP_CTX *ctx)
  164. {
  165. if (ctx == NULL)
  166. return;
  167. #ifndef OPENSSL_NO_HTTP
  168. if (ctx->http_ctx != NULL) {
  169. (void)OSSL_HTTP_close(ctx->http_ctx, 1);
  170. ossl_cmp_debug(ctx, "disconnected from CMP server");
  171. }
  172. #endif
  173. OPENSSL_free(ctx->propq);
  174. OPENSSL_free(ctx->serverPath);
  175. OPENSSL_free(ctx->server);
  176. OPENSSL_free(ctx->proxy);
  177. OPENSSL_free(ctx->no_proxy);
  178. X509_free(ctx->srvCert);
  179. X509_free(ctx->validatedSrvCert);
  180. X509_NAME_free(ctx->expected_sender);
  181. X509_STORE_free(ctx->trusted);
  182. OSSL_STACK_OF_X509_free(ctx->untrusted);
  183. X509_free(ctx->cert);
  184. OSSL_STACK_OF_X509_free(ctx->chain);
  185. EVP_PKEY_free(ctx->pkey);
  186. ASN1_OCTET_STRING_free(ctx->referenceValue);
  187. if (ctx->secretValue != NULL)
  188. OPENSSL_cleanse(ctx->secretValue->data, ctx->secretValue->length);
  189. ASN1_OCTET_STRING_free(ctx->secretValue);
  190. EVP_MD_free(ctx->pbm_owf);
  191. X509_NAME_free(ctx->recipient);
  192. EVP_MD_free(ctx->digest);
  193. ASN1_OCTET_STRING_free(ctx->transactionID);
  194. ASN1_OCTET_STRING_free(ctx->senderNonce);
  195. ASN1_OCTET_STRING_free(ctx->recipNonce);
  196. ASN1_OCTET_STRING_free(ctx->first_senderNonce);
  197. OSSL_CMP_ITAVs_free(ctx->geninfo_ITAVs);
  198. OSSL_STACK_OF_X509_free(ctx->extraCertsOut);
  199. EVP_PKEY_free(ctx->newPkey);
  200. X509_NAME_free(ctx->issuer);
  201. ASN1_INTEGER_free(ctx->serialNumber);
  202. X509_NAME_free(ctx->subjectName);
  203. sk_GENERAL_NAME_pop_free(ctx->subjectAltNames, GENERAL_NAME_free);
  204. X509_EXTENSIONS_free(ctx->reqExtensions);
  205. sk_POLICYINFO_pop_free(ctx->policies, POLICYINFO_free);
  206. X509_free(ctx->oldCert);
  207. X509_REQ_free(ctx->p10CSR);
  208. OSSL_CMP_ITAVs_free(ctx->genm_ITAVs);
  209. OSSL_CMP_PKIFREETEXT_free(ctx->statusString);
  210. X509_free(ctx->newCert);
  211. OSSL_STACK_OF_X509_free(ctx->newChain);
  212. OSSL_STACK_OF_X509_free(ctx->caPubs);
  213. OSSL_STACK_OF_X509_free(ctx->extraCertsIn);
  214. OPENSSL_free(ctx);
  215. }
  216. #define DEFINE_OSSL_set(PREFIX, FIELD, TYPE) \
  217. int PREFIX##_set_##FIELD(OSSL_CMP_CTX *ctx, TYPE val) \
  218. { \
  219. if (ctx == NULL) { \
  220. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); \
  221. return 0; \
  222. } \
  223. ctx->FIELD = val; \
  224. return 1; \
  225. }
  226. DEFINE_OSSL_set(ossl_cmp_ctx, status, int)
  227. #define DEFINE_OSSL_get(PREFIX, FIELD, TYPE, ERR_RET) \
  228. TYPE PREFIX##_get_##FIELD(const OSSL_CMP_CTX *ctx) \
  229. { \
  230. if (ctx == NULL) { \
  231. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); \
  232. return ERR_RET; \
  233. } \
  234. return ctx->FIELD; \
  235. }
  236. /*
  237. * Returns the PKIStatus from the last CertRepMessage
  238. * or Revocation Response or error message, -1 on error
  239. */
  240. DEFINE_OSSL_get(OSSL_CMP_CTX, status, int, -1)
  241. /*
  242. * Returns the statusString from the last CertRepMessage
  243. * or Revocation Response or error message, NULL on error
  244. */
  245. DEFINE_OSSL_CMP_CTX_get0(statusString, OSSL_CMP_PKIFREETEXT)
  246. DEFINE_OSSL_set0(ossl_cmp_ctx, statusString, OSSL_CMP_PKIFREETEXT)
  247. /* Set callback function for checking if the cert is ok or should be rejected */
  248. DEFINE_OSSL_set(OSSL_CMP_CTX, certConf_cb, OSSL_CMP_certConf_cb_t)
  249. /*
  250. * Set argument, respectively a pointer to a structure containing arguments,
  251. * optionally to be used by the certConf callback.
  252. */
  253. DEFINE_OSSL_set(OSSL_CMP_CTX, certConf_cb_arg, void *)
  254. /*
  255. * Get argument, respectively the pointer to a structure containing arguments,
  256. * optionally to be used by certConf callback.
  257. * Returns callback argument set previously (NULL if not set or on error)
  258. */
  259. DEFINE_OSSL_get(OSSL_CMP_CTX, certConf_cb_arg, void *, NULL)
  260. #ifndef OPENSSL_NO_TRACE
  261. static size_t ossl_cmp_log_trace_cb(const char *buf, size_t cnt,
  262. int category, int cmd, void *vdata)
  263. {
  264. OSSL_CMP_CTX *ctx = vdata;
  265. const char *msg;
  266. OSSL_CMP_severity level = -1;
  267. char *func = NULL;
  268. char *file = NULL;
  269. int line = 0;
  270. if (buf == NULL || cnt == 0 || cmd != OSSL_TRACE_CTRL_WRITE || ctx == NULL)
  271. return 0;
  272. if (ctx->log_cb == NULL)
  273. return 1; /* silently drop message */
  274. msg = ossl_cmp_log_parse_metadata(buf, &level, &func, &file, &line);
  275. if (level > ctx->log_verbosity) /* excludes the case level is unknown */
  276. goto end; /* suppress output since severity is not sufficient */
  277. if (!ctx->log_cb(func != NULL ? func : "(no func)",
  278. file != NULL ? file : "(no file)",
  279. line, level, msg))
  280. cnt = 0;
  281. end:
  282. OPENSSL_free(func);
  283. OPENSSL_free(file);
  284. return cnt;
  285. }
  286. #endif
  287. /* Print CMP log messages (i.e., diagnostic info) via the log cb of the ctx */
  288. int ossl_cmp_print_log(OSSL_CMP_severity level, const OSSL_CMP_CTX *ctx,
  289. const char *func, const char *file, int line,
  290. const char *level_str, const char *format, ...)
  291. {
  292. va_list args;
  293. char hugebuf[1024 * 2];
  294. int res = 0;
  295. if (ctx == NULL || ctx->log_cb == NULL)
  296. return 1; /* silently drop message */
  297. if (level > ctx->log_verbosity) /* excludes the case level is unknown */
  298. return 1; /* suppress output since severity is not sufficient */
  299. if (format == NULL)
  300. return 0;
  301. va_start(args, format);
  302. if (func == NULL)
  303. func = "(unset function name)";
  304. if (file == NULL)
  305. file = "(unset file name)";
  306. if (level_str == NULL)
  307. level_str = "(unset level string)";
  308. #ifndef OPENSSL_NO_TRACE
  309. if (OSSL_TRACE_ENABLED(CMP)) {
  310. OSSL_TRACE_BEGIN(CMP) {
  311. int printed =
  312. BIO_snprintf(hugebuf, sizeof(hugebuf),
  313. "%s:%s:%d:" OSSL_CMP_LOG_PREFIX "%s: ",
  314. func, file, line, level_str);
  315. if (printed > 0 && (size_t)printed < sizeof(hugebuf)) {
  316. if (BIO_vsnprintf(hugebuf + printed,
  317. sizeof(hugebuf) - printed, format, args) > 0)
  318. res = BIO_puts(trc_out, hugebuf) > 0;
  319. }
  320. } OSSL_TRACE_END(CMP);
  321. }
  322. #else /* compensate for disabled trace API */
  323. {
  324. if (BIO_vsnprintf(hugebuf, sizeof(hugebuf), format, args) > 0)
  325. res = ctx->log_cb(func, file, line, level, hugebuf);
  326. }
  327. #endif
  328. va_end(args);
  329. return res;
  330. }
  331. /* Set a callback function for error reporting and logging messages */
  332. int OSSL_CMP_CTX_set_log_cb(OSSL_CMP_CTX *ctx, OSSL_CMP_log_cb_t cb)
  333. {
  334. if (ctx == NULL) {
  335. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  336. return 0;
  337. }
  338. ctx->log_cb = cb;
  339. #ifndef OPENSSL_NO_TRACE
  340. /* do also in case cb == NULL, to switch off logging output: */
  341. if (!OSSL_trace_set_callback(OSSL_TRACE_CATEGORY_CMP,
  342. ossl_cmp_log_trace_cb, ctx))
  343. return 0;
  344. #endif
  345. return 1;
  346. }
  347. /* Print OpenSSL and CMP errors via the log cb of the ctx or ERR_print_errors */
  348. void OSSL_CMP_CTX_print_errors(const OSSL_CMP_CTX *ctx)
  349. {
  350. if (ctx != NULL && OSSL_CMP_LOG_ERR > ctx->log_verbosity)
  351. return; /* suppress output since severity is not sufficient */
  352. OSSL_CMP_print_errors_cb(ctx == NULL ? NULL : ctx->log_cb);
  353. }
  354. /*
  355. * Set or clear the reference value to be used for identification
  356. * (i.e., the user name) when using PBMAC.
  357. */
  358. int OSSL_CMP_CTX_set1_referenceValue(OSSL_CMP_CTX *ctx,
  359. const unsigned char *ref, int len)
  360. {
  361. if (ctx == NULL) {
  362. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  363. return 0;
  364. }
  365. return
  366. ossl_cmp_asn1_octet_string_set1_bytes(&ctx->referenceValue, ref, len);
  367. }
  368. /* Set or clear the password to be used for protecting messages with PBMAC */
  369. int OSSL_CMP_CTX_set1_secretValue(OSSL_CMP_CTX *ctx,
  370. const unsigned char *sec, int len)
  371. {
  372. ASN1_OCTET_STRING *secretValue = NULL;
  373. if (ctx == NULL) {
  374. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  375. return 0;
  376. }
  377. if (ossl_cmp_asn1_octet_string_set1_bytes(&secretValue, sec, len) != 1)
  378. return 0;
  379. if (ctx->secretValue != NULL) {
  380. OPENSSL_cleanse(ctx->secretValue->data, ctx->secretValue->length);
  381. ASN1_OCTET_STRING_free(ctx->secretValue);
  382. }
  383. ctx->secretValue = secretValue;
  384. return 1;
  385. }
  386. #define DEFINE_OSSL_CMP_CTX_get1_certs(FIELD) \
  387. STACK_OF(X509) *OSSL_CMP_CTX_get1_##FIELD(const OSSL_CMP_CTX *ctx) \
  388. { \
  389. if (ctx == NULL) { \
  390. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); \
  391. return NULL; \
  392. } \
  393. return X509_chain_up_ref(ctx->FIELD); \
  394. }
  395. /* Returns the cert chain computed by OSSL_CMP_certConf_cb(), NULL on error */
  396. DEFINE_OSSL_CMP_CTX_get1_certs(newChain)
  397. #define DEFINE_OSSL_set1_certs(PREFIX, FIELD) \
  398. int PREFIX##_set1_##FIELD(OSSL_CMP_CTX *ctx, STACK_OF(X509) *certs) \
  399. { \
  400. if (ctx == NULL) { \
  401. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); \
  402. return 0; \
  403. } \
  404. OSSL_STACK_OF_X509_free(ctx->FIELD); \
  405. ctx->FIELD = NULL; \
  406. return certs == NULL || (ctx->FIELD = X509_chain_up_ref(certs)) != NULL; \
  407. }
  408. /*
  409. * Copies any given stack of inbound X509 certificates to newChain
  410. * of the OSSL_CMP_CTX structure so that they may be retrieved later.
  411. */
  412. DEFINE_OSSL_set1_certs(ossl_cmp_ctx, newChain)
  413. /* Returns the stack of extraCerts received in CertRepMessage, NULL on error */
  414. DEFINE_OSSL_CMP_CTX_get1_certs(extraCertsIn)
  415. /*
  416. * Copies any given stack of inbound X509 certificates to extraCertsIn
  417. * of the OSSL_CMP_CTX structure so that they may be retrieved later.
  418. */
  419. DEFINE_OSSL_set1_certs(ossl_cmp_ctx, extraCertsIn)
  420. /*
  421. * Copies any given stack as the new stack of X509
  422. * certificates to send out in the extraCerts field.
  423. */
  424. DEFINE_OSSL_set1_certs(OSSL_CMP_CTX, extraCertsOut)
  425. /*
  426. * Add the given policy info object
  427. * to the X509_EXTENSIONS of the requested certificate template.
  428. */
  429. int OSSL_CMP_CTX_push0_policy(OSSL_CMP_CTX *ctx, POLICYINFO *pinfo)
  430. {
  431. if (ctx == NULL || pinfo == NULL) {
  432. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  433. return 0;
  434. }
  435. if (ctx->policies == NULL
  436. && (ctx->policies = CERTIFICATEPOLICIES_new()) == NULL)
  437. return 0;
  438. return sk_POLICYINFO_push(ctx->policies, pinfo);
  439. }
  440. /* Add an ITAV for geninfo of the PKI message header */
  441. int OSSL_CMP_CTX_push0_geninfo_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav)
  442. {
  443. if (ctx == NULL) {
  444. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  445. return 0;
  446. }
  447. return OSSL_CMP_ITAV_push0_stack_item(&ctx->geninfo_ITAVs, itav);
  448. }
  449. int OSSL_CMP_CTX_reset_geninfo_ITAVs(OSSL_CMP_CTX *ctx)
  450. {
  451. if (ctx == NULL) {
  452. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  453. return 0;
  454. }
  455. OSSL_CMP_ITAVs_free(ctx->geninfo_ITAVs);
  456. ctx->geninfo_ITAVs = NULL;
  457. return 1;
  458. }
  459. DEFINE_OSSL_CMP_CTX_get0(geninfo_ITAVs, STACK_OF(OSSL_CMP_ITAV))
  460. /* Add an itav for the body of outgoing general messages */
  461. int OSSL_CMP_CTX_push0_genm_ITAV(OSSL_CMP_CTX *ctx, OSSL_CMP_ITAV *itav)
  462. {
  463. if (ctx == NULL) {
  464. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  465. return 0;
  466. }
  467. return OSSL_CMP_ITAV_push0_stack_item(&ctx->genm_ITAVs, itav);
  468. }
  469. /*
  470. * Returns a duplicate of the stack of X509 certificates that
  471. * were received in the caPubs field of the last CertRepMessage.
  472. * Returns NULL on error
  473. */
  474. DEFINE_OSSL_CMP_CTX_get1_certs(caPubs)
  475. /*
  476. * Copies any given stack of certificates to the given
  477. * OSSL_CMP_CTX structure so that they may be retrieved later.
  478. */
  479. DEFINE_OSSL_set1_certs(ossl_cmp_ctx, caPubs)
  480. #define char_dup OPENSSL_strdup
  481. #define char_free OPENSSL_free
  482. #define DEFINE_OSSL_CMP_CTX_set1(FIELD, TYPE) /* this uses _dup */ \
  483. int OSSL_CMP_CTX_set1_##FIELD(OSSL_CMP_CTX *ctx, const TYPE *val) \
  484. { \
  485. TYPE *val_dup = NULL; \
  486. \
  487. if (ctx == NULL) { \
  488. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); \
  489. return 0; \
  490. } \
  491. \
  492. if (val != NULL && (val_dup = TYPE##_dup(val)) == NULL) \
  493. return 0; \
  494. TYPE##_free(ctx->FIELD); \
  495. ctx->FIELD = val_dup; \
  496. return 1; \
  497. }
  498. #define X509_invalid(cert) (!ossl_x509v3_cache_extensions(cert))
  499. #define EVP_PKEY_invalid(key) 0
  500. #define DEFINE_OSSL_set1_up_ref(PREFIX, FIELD, TYPE) \
  501. int PREFIX##_set1_##FIELD(OSSL_CMP_CTX *ctx, TYPE *val) \
  502. { \
  503. if (ctx == NULL) { \
  504. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); \
  505. return 0; \
  506. } \
  507. \
  508. /* prevent misleading error later on malformed cert or provider issue */ \
  509. if (val != NULL && TYPE##_invalid(val)) { \
  510. ERR_raise(ERR_LIB_CMP, CMP_R_POTENTIALLY_INVALID_CERTIFICATE); \
  511. return 0; \
  512. } \
  513. if (val != NULL && !TYPE##_up_ref(val)) \
  514. return 0; \
  515. TYPE##_free(ctx->FIELD); \
  516. ctx->FIELD = val; \
  517. return 1; \
  518. }
  519. DEFINE_OSSL_set1_up_ref(ossl_cmp_ctx, validatedSrvCert, X509)
  520. /*
  521. * Pins the server certificate to be directly trusted (even if it is expired)
  522. * for verifying response messages.
  523. * Cert pointer is not consumed. It may be NULL to clear the entry.
  524. */
  525. DEFINE_OSSL_set1_up_ref(OSSL_CMP_CTX, srvCert, X509)
  526. /* Set the X509 name of the recipient to be placed in the PKIHeader */
  527. DEFINE_OSSL_CMP_CTX_set1(recipient, X509_NAME)
  528. /* Store the X509 name of the expected sender in the PKIHeader of responses */
  529. DEFINE_OSSL_CMP_CTX_set1(expected_sender, X509_NAME)
  530. /* Set the X509 name of the issuer to be placed in the certTemplate */
  531. DEFINE_OSSL_CMP_CTX_set1(issuer, X509_NAME)
  532. /* Set the ASN1_INTEGER serial to be placed in the certTemplate for rr */
  533. DEFINE_OSSL_CMP_CTX_set1(serialNumber, ASN1_INTEGER)
  534. /*
  535. * Set the subject name that will be placed in the certificate
  536. * request. This will be the subject name on the received certificate.
  537. */
  538. DEFINE_OSSL_CMP_CTX_set1(subjectName, X509_NAME)
  539. /* Set the X.509v3 certificate request extensions to be used in IR/CR/KUR */
  540. int OSSL_CMP_CTX_set0_reqExtensions(OSSL_CMP_CTX *ctx, X509_EXTENSIONS *exts)
  541. {
  542. if (ctx == NULL) {
  543. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  544. return 0;
  545. }
  546. if (sk_GENERAL_NAME_num(ctx->subjectAltNames) > 0 && exts != NULL
  547. && X509v3_get_ext_by_NID(exts, NID_subject_alt_name, -1) >= 0) {
  548. ERR_raise(ERR_LIB_CMP, CMP_R_MULTIPLE_SAN_SOURCES);
  549. return 0;
  550. }
  551. X509_EXTENSIONS_free(ctx->reqExtensions);
  552. ctx->reqExtensions = exts;
  553. return 1;
  554. }
  555. /* returns 1 if ctx contains a Subject Alternative Name extension, else 0 */
  556. int OSSL_CMP_CTX_reqExtensions_have_SAN(OSSL_CMP_CTX *ctx)
  557. {
  558. if (ctx == NULL) {
  559. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  560. return -1;
  561. }
  562. /* if one of the following conditions 'fail' this is not an error */
  563. return ctx->reqExtensions != NULL
  564. && X509v3_get_ext_by_NID(ctx->reqExtensions,
  565. NID_subject_alt_name, -1) >= 0;
  566. }
  567. /*
  568. * Add a GENERAL_NAME structure that will be added to the CRMF
  569. * request's extensions field to request subject alternative names.
  570. */
  571. int OSSL_CMP_CTX_push1_subjectAltName(OSSL_CMP_CTX *ctx,
  572. const GENERAL_NAME *name)
  573. {
  574. GENERAL_NAME *name_dup;
  575. if (ctx == NULL || name == NULL) {
  576. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  577. return 0;
  578. }
  579. if (OSSL_CMP_CTX_reqExtensions_have_SAN(ctx) == 1) {
  580. ERR_raise(ERR_LIB_CMP, CMP_R_MULTIPLE_SAN_SOURCES);
  581. return 0;
  582. }
  583. if (ctx->subjectAltNames == NULL
  584. && (ctx->subjectAltNames = sk_GENERAL_NAME_new_null()) == NULL)
  585. return 0;
  586. if ((name_dup = GENERAL_NAME_dup(name)) == NULL)
  587. return 0;
  588. if (!sk_GENERAL_NAME_push(ctx->subjectAltNames, name_dup)) {
  589. GENERAL_NAME_free(name_dup);
  590. return 0;
  591. }
  592. return 1;
  593. }
  594. /*
  595. * Set our own client certificate, used for example in KUR and when
  596. * doing the IR with existing certificate.
  597. */
  598. DEFINE_OSSL_set1_up_ref(OSSL_CMP_CTX, cert, X509)
  599. int OSSL_CMP_CTX_build_cert_chain(OSSL_CMP_CTX *ctx, X509_STORE *own_trusted,
  600. STACK_OF(X509) *candidates)
  601. {
  602. STACK_OF(X509) *chain;
  603. if (ctx == NULL) {
  604. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  605. return 0;
  606. }
  607. if (!ossl_x509_add_certs_new(&ctx->untrusted, candidates,
  608. X509_ADD_FLAG_UP_REF | X509_ADD_FLAG_NO_DUP))
  609. return 0;
  610. ossl_cmp_debug(ctx, "trying to build chain for own CMP signer cert");
  611. chain = X509_build_chain(ctx->cert, ctx->untrusted, own_trusted, 0,
  612. ctx->libctx, ctx->propq);
  613. if (chain == NULL) {
  614. ERR_raise(ERR_LIB_CMP, CMP_R_FAILED_BUILDING_OWN_CHAIN);
  615. return 0;
  616. }
  617. ossl_cmp_debug(ctx, "success building chain for own CMP signer cert");
  618. ctx->chain = chain;
  619. return 1;
  620. }
  621. /*
  622. * Set the old certificate that we are updating in KUR
  623. * or the certificate to be revoked in RR, respectively.
  624. * Also used as reference cert (defaulting to cert) for deriving subject DN
  625. * and SANs. Its issuer is used as default recipient in the CMP message header.
  626. */
  627. DEFINE_OSSL_set1_up_ref(OSSL_CMP_CTX, oldCert, X509)
  628. /* Set the PKCS#10 CSR to be sent in P10CR */
  629. DEFINE_OSSL_CMP_CTX_set1(p10CSR, X509_REQ)
  630. /*
  631. * Set the (newly received in IP/KUP/CP) certificate in the context.
  632. * This only permits for one cert to be enrolled at a time.
  633. */
  634. DEFINE_OSSL_set0(ossl_cmp_ctx, newCert, X509)
  635. /* Get successfully validated server cert, if any, of current transaction */
  636. DEFINE_OSSL_CMP_CTX_get0(validatedSrvCert, X509)
  637. /*
  638. * Get the (newly received in IP/KUP/CP) client certificate from the context
  639. * This only permits for one client cert to be received...
  640. */
  641. DEFINE_OSSL_CMP_CTX_get0(newCert, X509)
  642. /* Set the client's current private key */
  643. DEFINE_OSSL_set1_up_ref(OSSL_CMP_CTX, pkey, EVP_PKEY)
  644. /* Set new key pair. Used e.g. when doing Key Update */
  645. int OSSL_CMP_CTX_set0_newPkey(OSSL_CMP_CTX *ctx, int priv, EVP_PKEY *pkey)
  646. {
  647. if (ctx == NULL) {
  648. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  649. return 0;
  650. }
  651. EVP_PKEY_free(ctx->newPkey);
  652. ctx->newPkey = pkey;
  653. ctx->newPkey_priv = priv;
  654. return 1;
  655. }
  656. /* Get the private/public key to use for cert enrollment, or NULL on error */
  657. /* In case |priv| == 0, better use ossl_cmp_ctx_get0_newPubkey() below */
  658. EVP_PKEY *OSSL_CMP_CTX_get0_newPkey(const OSSL_CMP_CTX *ctx, int priv)
  659. {
  660. if (ctx == NULL) {
  661. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  662. return NULL;
  663. }
  664. if (ctx->newPkey != NULL)
  665. return priv && !ctx->newPkey_priv ? NULL : ctx->newPkey;
  666. if (ctx->p10CSR != NULL)
  667. return priv ? NULL : X509_REQ_get0_pubkey(ctx->p10CSR);
  668. return ctx->pkey; /* may be NULL */
  669. }
  670. EVP_PKEY *ossl_cmp_ctx_get0_newPubkey(const OSSL_CMP_CTX *ctx)
  671. {
  672. if (!ossl_assert(ctx != NULL))
  673. return NULL;
  674. if (ctx->newPkey != NULL)
  675. return ctx->newPkey;
  676. if (ctx->p10CSR != NULL)
  677. return X509_REQ_get0_pubkey(ctx->p10CSR);
  678. if (ctx->oldCert != NULL)
  679. return X509_get0_pubkey(ctx->oldCert);
  680. if (ctx->cert != NULL)
  681. return X509_get0_pubkey(ctx->cert);
  682. return ctx->pkey;
  683. }
  684. #define DEFINE_set1_ASN1_OCTET_STRING(PREFIX, FIELD) \
  685. int PREFIX##_set1_##FIELD(OSSL_CMP_CTX *ctx, const ASN1_OCTET_STRING *id) \
  686. { \
  687. if (ctx == NULL) { \
  688. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT); \
  689. return 0; \
  690. } \
  691. return ossl_cmp_asn1_octet_string_set1(&ctx->FIELD, id); \
  692. }
  693. /* Set the given transactionID to the context */
  694. DEFINE_set1_ASN1_OCTET_STRING(OSSL_CMP_CTX, transactionID)
  695. /* Set the nonce to be used for the recipNonce in the message created next */
  696. DEFINE_set1_ASN1_OCTET_STRING(ossl_cmp_ctx, recipNonce)
  697. /* Stores the given nonce as the last senderNonce sent out */
  698. DEFINE_set1_ASN1_OCTET_STRING(OSSL_CMP_CTX, senderNonce)
  699. /* store the first req sender nonce for verifying delayed delivery */
  700. DEFINE_set1_ASN1_OCTET_STRING(ossl_cmp_ctx, first_senderNonce)
  701. /* Set the proxy server to use for HTTP(S) connections */
  702. DEFINE_OSSL_CMP_CTX_set1(proxy, char)
  703. /* Set the (HTTP) hostname of the CMP server */
  704. DEFINE_OSSL_CMP_CTX_set1(server, char)
  705. /* Set the server exclusion list of the HTTP proxy server */
  706. DEFINE_OSSL_CMP_CTX_set1(no_proxy, char)
  707. #ifndef OPENSSL_NO_HTTP
  708. /* Set the http connect/disconnect callback function to be used for HTTP(S) */
  709. DEFINE_OSSL_set(OSSL_CMP_CTX, http_cb, OSSL_HTTP_bio_cb_t)
  710. /* Set argument optionally to be used by the http connect/disconnect callback */
  711. DEFINE_OSSL_set(OSSL_CMP_CTX, http_cb_arg, void *)
  712. /*
  713. * Get argument optionally to be used by the http connect/disconnect callback
  714. * Returns callback argument set previously (NULL if not set or on error)
  715. */
  716. DEFINE_OSSL_get(OSSL_CMP_CTX, http_cb_arg, void *, NULL)
  717. #endif
  718. /* Set callback function for sending CMP request and receiving response */
  719. DEFINE_OSSL_set(OSSL_CMP_CTX, transfer_cb, OSSL_CMP_transfer_cb_t)
  720. /* Set argument optionally to be used by the transfer callback */
  721. DEFINE_OSSL_set(OSSL_CMP_CTX, transfer_cb_arg, void *)
  722. /*
  723. * Get argument optionally to be used by the transfer callback.
  724. * Returns callback argument set previously (NULL if not set or on error)
  725. */
  726. DEFINE_OSSL_get(OSSL_CMP_CTX, transfer_cb_arg, void *, NULL)
  727. /** Set the HTTP server port to be used */
  728. DEFINE_OSSL_set(OSSL_CMP_CTX, serverPort, int)
  729. /* Set the HTTP path to be used on the server (e.g "pkix/") */
  730. DEFINE_OSSL_CMP_CTX_set1(serverPath, char)
  731. /* Set the failInfo error code as bit encoding in OSSL_CMP_CTX */
  732. DEFINE_OSSL_set(ossl_cmp_ctx, failInfoCode, int)
  733. /*
  734. * Get the failInfo error code in OSSL_CMP_CTX as bit encoding.
  735. * Returns bit string as integer on success, -1 on error
  736. */
  737. DEFINE_OSSL_get(OSSL_CMP_CTX, failInfoCode, int, -1)
  738. /* Set a Boolean or integer option of the context to the "val" arg */
  739. int OSSL_CMP_CTX_set_option(OSSL_CMP_CTX *ctx, int opt, int val)
  740. {
  741. int min_val;
  742. if (ctx == NULL) {
  743. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  744. return 0;
  745. }
  746. switch (opt) {
  747. case OSSL_CMP_OPT_REVOCATION_REASON:
  748. min_val = OCSP_REVOKED_STATUS_NOSTATUS;
  749. break;
  750. case OSSL_CMP_OPT_POPO_METHOD:
  751. min_val = OSSL_CRMF_POPO_NONE;
  752. break;
  753. default:
  754. min_val = 0;
  755. break;
  756. }
  757. if (val < min_val) {
  758. ERR_raise(ERR_LIB_CMP, CMP_R_VALUE_TOO_SMALL);
  759. return 0;
  760. }
  761. switch (opt) {
  762. case OSSL_CMP_OPT_LOG_VERBOSITY:
  763. if (val > OSSL_CMP_LOG_MAX) {
  764. ERR_raise(ERR_LIB_CMP, CMP_R_VALUE_TOO_LARGE);
  765. return 0;
  766. }
  767. ctx->log_verbosity = val;
  768. break;
  769. case OSSL_CMP_OPT_IMPLICIT_CONFIRM:
  770. ctx->implicitConfirm = val;
  771. break;
  772. case OSSL_CMP_OPT_DISABLE_CONFIRM:
  773. ctx->disableConfirm = val;
  774. break;
  775. case OSSL_CMP_OPT_UNPROTECTED_SEND:
  776. ctx->unprotectedSend = val;
  777. break;
  778. case OSSL_CMP_OPT_UNPROTECTED_ERRORS:
  779. ctx->unprotectedErrors = val;
  780. break;
  781. case OSSL_CMP_OPT_NO_CACHE_EXTRACERTS:
  782. ctx->noCacheExtraCerts = val;
  783. break;
  784. case OSSL_CMP_OPT_VALIDITY_DAYS:
  785. ctx->days = val;
  786. break;
  787. case OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT:
  788. ctx->SubjectAltName_nodefault = val;
  789. break;
  790. case OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL:
  791. ctx->setSubjectAltNameCritical = val;
  792. break;
  793. case OSSL_CMP_OPT_POLICIES_CRITICAL:
  794. ctx->setPoliciesCritical = val;
  795. break;
  796. case OSSL_CMP_OPT_IGNORE_KEYUSAGE:
  797. ctx->ignore_keyusage = val;
  798. break;
  799. case OSSL_CMP_OPT_POPO_METHOD:
  800. if (val > OSSL_CRMF_POPO_KEYAGREE) {
  801. ERR_raise(ERR_LIB_CMP, CMP_R_VALUE_TOO_LARGE);
  802. return 0;
  803. }
  804. ctx->popoMethod = val;
  805. break;
  806. case OSSL_CMP_OPT_DIGEST_ALGNID:
  807. if (!cmp_ctx_set_md(ctx, &ctx->digest, val))
  808. return 0;
  809. break;
  810. case OSSL_CMP_OPT_OWF_ALGNID:
  811. if (!cmp_ctx_set_md(ctx, &ctx->pbm_owf, val))
  812. return 0;
  813. break;
  814. case OSSL_CMP_OPT_MAC_ALGNID:
  815. ctx->pbm_mac = val;
  816. break;
  817. case OSSL_CMP_OPT_KEEP_ALIVE:
  818. ctx->keep_alive = val;
  819. break;
  820. case OSSL_CMP_OPT_MSG_TIMEOUT:
  821. ctx->msg_timeout = val;
  822. break;
  823. case OSSL_CMP_OPT_TOTAL_TIMEOUT:
  824. ctx->total_timeout = val;
  825. break;
  826. case OSSL_CMP_OPT_USE_TLS:
  827. ctx->tls_used = val;
  828. break;
  829. case OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR:
  830. ctx->permitTAInExtraCertsForIR = val;
  831. break;
  832. case OSSL_CMP_OPT_REVOCATION_REASON:
  833. if (val > OCSP_REVOKED_STATUS_AACOMPROMISE) {
  834. ERR_raise(ERR_LIB_CMP, CMP_R_VALUE_TOO_LARGE);
  835. return 0;
  836. }
  837. ctx->revocationReason = val;
  838. break;
  839. default:
  840. ERR_raise(ERR_LIB_CMP, CMP_R_INVALID_OPTION);
  841. return 0;
  842. }
  843. return 1;
  844. }
  845. /*
  846. * Reads a Boolean or integer option value from the context.
  847. * Returns -1 on error (which is the default OSSL_CMP_OPT_REVOCATION_REASON)
  848. */
  849. int OSSL_CMP_CTX_get_option(const OSSL_CMP_CTX *ctx, int opt)
  850. {
  851. if (ctx == NULL) {
  852. ERR_raise(ERR_LIB_CMP, CMP_R_NULL_ARGUMENT);
  853. return -1;
  854. }
  855. switch (opt) {
  856. case OSSL_CMP_OPT_LOG_VERBOSITY:
  857. return ctx->log_verbosity;
  858. case OSSL_CMP_OPT_IMPLICIT_CONFIRM:
  859. return ctx->implicitConfirm;
  860. case OSSL_CMP_OPT_DISABLE_CONFIRM:
  861. return ctx->disableConfirm;
  862. case OSSL_CMP_OPT_UNPROTECTED_SEND:
  863. return ctx->unprotectedSend;
  864. case OSSL_CMP_OPT_UNPROTECTED_ERRORS:
  865. return ctx->unprotectedErrors;
  866. case OSSL_CMP_OPT_NO_CACHE_EXTRACERTS:
  867. return ctx->noCacheExtraCerts;
  868. case OSSL_CMP_OPT_VALIDITY_DAYS:
  869. return ctx->days;
  870. case OSSL_CMP_OPT_SUBJECTALTNAME_NODEFAULT:
  871. return ctx->SubjectAltName_nodefault;
  872. case OSSL_CMP_OPT_SUBJECTALTNAME_CRITICAL:
  873. return ctx->setSubjectAltNameCritical;
  874. case OSSL_CMP_OPT_POLICIES_CRITICAL:
  875. return ctx->setPoliciesCritical;
  876. case OSSL_CMP_OPT_IGNORE_KEYUSAGE:
  877. return ctx->ignore_keyusage;
  878. case OSSL_CMP_OPT_POPO_METHOD:
  879. return ctx->popoMethod;
  880. case OSSL_CMP_OPT_DIGEST_ALGNID:
  881. return EVP_MD_get_type(ctx->digest);
  882. case OSSL_CMP_OPT_OWF_ALGNID:
  883. return EVP_MD_get_type(ctx->pbm_owf);
  884. case OSSL_CMP_OPT_MAC_ALGNID:
  885. return ctx->pbm_mac;
  886. case OSSL_CMP_OPT_KEEP_ALIVE:
  887. return ctx->keep_alive;
  888. case OSSL_CMP_OPT_MSG_TIMEOUT:
  889. return ctx->msg_timeout;
  890. case OSSL_CMP_OPT_TOTAL_TIMEOUT:
  891. return ctx->total_timeout;
  892. case OSSL_CMP_OPT_USE_TLS:
  893. return ctx->tls_used;
  894. case OSSL_CMP_OPT_PERMIT_TA_IN_EXTRACERTS_FOR_IR:
  895. return ctx->permitTAInExtraCertsForIR;
  896. case OSSL_CMP_OPT_REVOCATION_REASON:
  897. return ctx->revocationReason;
  898. default:
  899. ERR_raise(ERR_LIB_CMP, CMP_R_INVALID_OPTION);
  900. return -1;
  901. }
  902. }