Coverage Report

Created: 2025-12-04 06:33

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