1184610Salfred/* 2184610Salfred * Copyright 2023-2024 The OpenSSL Project Authors. All Rights Reserved. 3184610Salfred * 4184610Salfred * Licensed under the Apache License 2.0 (the "License"). You may not use 5184610Salfred * this file except in compliance with the License. You can obtain a copy 6184610Salfred * in the file LICENSE in the source distribution or at 7184610Salfred * https://www.openssl.org/source/license.html 8184610Salfred */ 9184610Salfred 10184610Salfred#include <openssl/evp.h> 11184610Salfred#include "testutil.h" 12184610Salfred 13184610Salfredstatic char *config_file = NULL; 14184610Salfred 15184610Salfredtypedef enum OPTION_choice { 16184610Salfred OPT_ERR = -1, 17184610Salfred OPT_EOF = 0, 18184610Salfred OPT_CONFIG_FILE, 19184610Salfred OPT_TEST_ENUM 20184610Salfred} OPTION_CHOICE; 21184610Salfred 22184610Salfredconst OPTIONS *test_get_options(void) 23184610Salfred{ 24184610Salfred static const OPTIONS options[] = { 25184610Salfred OPT_TEST_OPTIONS_DEFAULT_USAGE, 26184610Salfred { "config", OPT_CONFIG_FILE, '<', 27184610Salfred "The configuration file to use for the libctx" }, 28184610Salfred { NULL } 29184610Salfred }; 30184610Salfred return options; 31184610Salfred} 32184610Salfred 33184610Salfred 34184610Salfred/* 35184610Salfred * Test that parsing a config file with incorrect stable settings aren't parsed 36184610Salfred * and appropriate errors are raised 37184610Salfred */ 38184610Salfredstatic int test_asn1_stable_parse(void) 39184610Salfred{ 40184610Salfred int testret = 0; 41184610Salfred unsigned long errcode; 42184610Salfred OSSL_LIB_CTX *newctx = OSSL_LIB_CTX_new(); 43184610Salfred 44184610Salfred if (!TEST_ptr(newctx)) 45184610Salfred goto out; 46184610Salfred 47184610Salfred if (!TEST_int_eq(OSSL_LIB_CTX_load_config(newctx, config_file), 0)) 48184610Salfred goto err; 49184610Salfred 50184610Salfred errcode = ERR_peek_error(); 51184610Salfred if (ERR_GET_LIB(errcode) != ERR_LIB_ASN1) 52184610Salfred goto err; 53184610Salfred if (ERR_GET_REASON(errcode) != ASN1_R_INVALID_STRING_TABLE_VALUE) 54184610Salfred goto err; 55184610Salfred 56184610Salfred ERR_clear_error(); 57184610Salfred 58184610Salfred testret = 1; 59184610Salfrederr: 60184610Salfred OSSL_LIB_CTX_free(newctx); 61184610Salfredout: 62184610Salfred return testret; 63184610Salfred} 64184610Salfred 65184610Salfredint setup_tests(void) 66184610Salfred{ 67184610Salfred OPTION_CHOICE o; 68184610Salfred 69184610Salfred while ((o = opt_next()) != OPT_EOF) { 70184610Salfred switch (o) { 71184610Salfred case OPT_CONFIG_FILE: 72184610Salfred config_file = opt_arg(); 73184610Salfred break; 74184610Salfred default: 75184610Salfred return 0; 76184610Salfred } 77184610Salfred } 78184610Salfred 79184610Salfred ADD_TEST(test_asn1_stable_parse); 80184610Salfred return 1; 81184610Salfred} 82184610Salfred