2 * Copyright 2012-2024 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
11 #include <openssl/crypto.h>
12 #include "internal/cryptlib.h"
13 #include <openssl/conf.h>
14 #include <openssl/x509v3.h>
16 /* Multi string module: add table entries from a given section */
18 static int do_tcreate(const char *value, const char *name);
20 static int stbl_module_init(CONF_IMODULE *md, const CONF *cnf)
23 const char *stbl_section;
24 STACK_OF(CONF_VALUE) *sktmp;
27 stbl_section = CONF_imodule_get_value(md);
28 if ((sktmp = NCONF_get_section(cnf, stbl_section)) == NULL) {
29 ERR_raise(ERR_LIB_ASN1, ASN1_R_ERROR_LOADING_SECTION);
32 for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
33 mval = sk_CONF_VALUE_value(sktmp, i);
34 if (!do_tcreate(mval->value, mval->name)) {
35 ERR_raise(ERR_LIB_ASN1, ASN1_R_INVALID_VALUE);
42 static void stbl_module_finish(CONF_IMODULE *md)
44 ASN1_STRING_TABLE_cleanup();
47 void ASN1_add_stable_module(void)
49 CONF_module_add("stbl_section", stbl_module_init, stbl_module_finish);
53 * Create an table entry based on a name value pair. format is oid_name =
54 * n1:v1, n2:v2,... where name is "min", "max", "mask" or "flags".
57 static int do_tcreate(const char *value, const char *name)
61 long tbl_min = -1, tbl_max = -1;
62 unsigned long tbl_mask = 0, tbl_flags = 0;
63 STACK_OF(CONF_VALUE) *lst = NULL;
64 CONF_VALUE *cnf = NULL;
65 nid = OBJ_sn2nid(name);
67 nid = OBJ_ln2nid(name);
70 lst = X509V3_parse_list(value);
73 for (i = 0; i < sk_CONF_VALUE_num(lst); i++) {
74 cnf = sk_CONF_VALUE_value(lst, i);
75 if (cnf->value == NULL)
77 if (strcmp(cnf->name, "min") == 0) {
78 tbl_min = strtoul(cnf->value, &eptr, 0);
81 } else if (strcmp(cnf->name, "max") == 0) {
82 tbl_max = strtoul(cnf->value, &eptr, 0);
85 } else if (strcmp(cnf->name, "mask") == 0) {
86 if (!ASN1_str2mask(cnf->value, &tbl_mask) || !tbl_mask)
88 } else if (strcmp(cnf->name, "flags") == 0) {
89 if (strcmp(cnf->value, "nomask") == 0)
90 tbl_flags = STABLE_NO_MASK;
91 else if (strcmp(cnf->value, "none") == 0)
92 tbl_flags = STABLE_FLAGS_CLEAR;
102 ERR_raise_data(ERR_LIB_ASN1, ASN1_R_INVALID_STRING_TABLE_VALUE,
103 "field=%s, value=%s", cnf->name,
104 cnf->value != NULL ? cnf->value
107 ERR_raise_data(ERR_LIB_ASN1, ASN1_R_INVALID_STRING_TABLE_VALUE,
108 "name=%s, value=%s", name, value);
110 rv = ASN1_STRING_TABLE_add(nid, tbl_min, tbl_max,
111 tbl_mask, tbl_flags);
113 ERR_raise(ERR_LIB_ASN1, ERR_R_MALLOC_FAILURE);
115 sk_CONF_VALUE_pop_free(lst, X509V3_conf_free);