1*e0c4386eSCy Schubert /*
2*e0c4386eSCy Schubert * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved.
3*e0c4386eSCy Schubert *
4*e0c4386eSCy Schubert * Licensed under the Apache License 2.0 (the "License"). You may not use
5*e0c4386eSCy Schubert * this file except in compliance with the License. You can obtain a copy
6*e0c4386eSCy Schubert * in the file LICENSE in the source distribution or at
7*e0c4386eSCy Schubert * https://www.openssl.org/source/license.html
8*e0c4386eSCy Schubert */
9*e0c4386eSCy Schubert
10*e0c4386eSCy Schubert #include <openssl/evp.h>
11*e0c4386eSCy Schubert #include "testutil.h"
12*e0c4386eSCy Schubert
13*e0c4386eSCy Schubert static char *config_file = NULL;
14*e0c4386eSCy Schubert
15*e0c4386eSCy Schubert typedef enum OPTION_choice {
16*e0c4386eSCy Schubert OPT_ERR = -1,
17*e0c4386eSCy Schubert OPT_EOF = 0,
18*e0c4386eSCy Schubert OPT_CONFIG_FILE,
19*e0c4386eSCy Schubert OPT_TEST_ENUM
20*e0c4386eSCy Schubert } OPTION_CHOICE;
21*e0c4386eSCy Schubert
test_get_options(void)22*e0c4386eSCy Schubert const OPTIONS *test_get_options(void)
23*e0c4386eSCy Schubert {
24*e0c4386eSCy Schubert static const OPTIONS options[] = {
25*e0c4386eSCy Schubert OPT_TEST_OPTIONS_DEFAULT_USAGE,
26*e0c4386eSCy Schubert { "config", OPT_CONFIG_FILE, '<',
27*e0c4386eSCy Schubert "The configuration file to use for the libctx" },
28*e0c4386eSCy Schubert { NULL }
29*e0c4386eSCy Schubert };
30*e0c4386eSCy Schubert return options;
31*e0c4386eSCy Schubert }
32*e0c4386eSCy Schubert
33*e0c4386eSCy Schubert
34*e0c4386eSCy Schubert /*
35*e0c4386eSCy Schubert * Test that parsing a config file with incorrect stable settings aren't parsed
36*e0c4386eSCy Schubert * and appropriate errors are raised
37*e0c4386eSCy Schubert */
test_asn1_stable_parse(void)38*e0c4386eSCy Schubert static int test_asn1_stable_parse(void)
39*e0c4386eSCy Schubert {
40*e0c4386eSCy Schubert int testret = 0;
41*e0c4386eSCy Schubert unsigned long errcode;
42*e0c4386eSCy Schubert OSSL_LIB_CTX *newctx = OSSL_LIB_CTX_new();
43*e0c4386eSCy Schubert
44*e0c4386eSCy Schubert if (!TEST_ptr(newctx))
45*e0c4386eSCy Schubert goto out;
46*e0c4386eSCy Schubert
47*e0c4386eSCy Schubert if (!TEST_int_eq(OSSL_LIB_CTX_load_config(newctx, config_file), 0))
48*e0c4386eSCy Schubert goto err;
49*e0c4386eSCy Schubert
50*e0c4386eSCy Schubert errcode = ERR_peek_error();
51*e0c4386eSCy Schubert if (ERR_GET_LIB(errcode) != ERR_LIB_ASN1)
52*e0c4386eSCy Schubert goto err;
53*e0c4386eSCy Schubert if (ERR_GET_REASON(errcode) != ASN1_R_INVALID_STRING_TABLE_VALUE)
54*e0c4386eSCy Schubert goto err;
55*e0c4386eSCy Schubert
56*e0c4386eSCy Schubert ERR_clear_error();
57*e0c4386eSCy Schubert
58*e0c4386eSCy Schubert testret = 1;
59*e0c4386eSCy Schubert err:
60*e0c4386eSCy Schubert OSSL_LIB_CTX_free(newctx);
61*e0c4386eSCy Schubert out:
62*e0c4386eSCy Schubert return testret;
63*e0c4386eSCy Schubert }
64*e0c4386eSCy Schubert
setup_tests(void)65*e0c4386eSCy Schubert int setup_tests(void)
66*e0c4386eSCy Schubert {
67*e0c4386eSCy Schubert OPTION_CHOICE o;
68*e0c4386eSCy Schubert
69*e0c4386eSCy Schubert while ((o = opt_next()) != OPT_EOF) {
70*e0c4386eSCy Schubert switch (o) {
71*e0c4386eSCy Schubert case OPT_CONFIG_FILE:
72*e0c4386eSCy Schubert config_file = opt_arg();
73*e0c4386eSCy Schubert break;
74*e0c4386eSCy Schubert default:
75*e0c4386eSCy Schubert return 0;
76*e0c4386eSCy Schubert }
77*e0c4386eSCy Schubert }
78*e0c4386eSCy Schubert
79*e0c4386eSCy Schubert ADD_TEST(test_asn1_stable_parse);
80*e0c4386eSCy Schubert return 1;
81*e0c4386eSCy Schubert }
82