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