2 * Copyright 2012-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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
12 #include <openssl/crypto.h>
13 #include "internal/cryptlib.h"
14 #include <openssl/conf.h>
15 #include <openssl/x509v3.h>
17 /* Multi string module: add table entries from a given section */
19 static int do_tcreate(const char *value, const char *name);
21 static int stbl_module_init(CONF_IMODULE *md, const CONF *cnf)
24 const char *stbl_section;
25 STACK_OF(CONF_VALUE) *sktmp;
28 stbl_section = CONF_imodule_get_value(md);
29 if ((sktmp = NCONF_get_section(cnf, stbl_section)) == NULL) {
30 ASN1err(ASN1_F_STBL_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
33 for (i = 0; i < sk_CONF_VALUE_num(sktmp); i++) {
34 mval = sk_CONF_VALUE_value(sktmp, i);
35 if (!do_tcreate(mval->value, mval->name)) {
36 ASN1err(ASN1_F_STBL_MODULE_INIT, ASN1_R_INVALID_VALUE);
43 static void stbl_module_finish(CONF_IMODULE *md)
45 ASN1_STRING_TABLE_cleanup();
48 void ASN1_add_stable_module(void)
50 CONF_module_add("stbl_section", stbl_module_init, stbl_module_finish);
54 * Create an table entry based on a name value pair. format is oid_name =
55 * n1:v1, n2:v2,... where name is "min", "max", "mask" or "flags".
58 static int do_tcreate(const char *value, const char *name)
62 long tbl_min = -1, tbl_max = -1;
63 unsigned long tbl_mask = 0, tbl_flags = 0;
64 STACK_OF(CONF_VALUE) *lst = NULL;
65 CONF_VALUE *cnf = NULL;
66 nid = OBJ_sn2nid(name);
68 nid = OBJ_ln2nid(name);
71 lst = X509V3_parse_list(value);
74 for (i = 0; i < sk_CONF_VALUE_num(lst); i++) {
75 cnf = sk_CONF_VALUE_value(lst, i);
76 if (strcmp(cnf->name, "min") == 0) {
77 tbl_min = strtoul(cnf->value, &eptr, 0);
80 } else if (strcmp(cnf->name, "max") == 0) {
81 tbl_max = strtoul(cnf->value, &eptr, 0);
84 } else if (strcmp(cnf->name, "mask") == 0) {
85 if (!ASN1_str2mask(cnf->value, &tbl_mask) || !tbl_mask)
87 } else if (strcmp(cnf->name, "flags") == 0) {
88 if (strcmp(cnf->value, "nomask") == 0)
89 tbl_flags = STABLE_NO_MASK;
90 else if (strcmp(cnf->value, "none") == 0)
91 tbl_flags = STABLE_FLAGS_CLEAR;
100 ASN1err(ASN1_F_DO_TCREATE, ASN1_R_INVALID_STRING_TABLE_VALUE);
102 ERR_add_error_data(4, "field=", cnf->name,
103 ", value=", cnf->value);
105 ERR_add_error_data(4, "name=", name, ", value=", value);
107 rv = ASN1_STRING_TABLE_add(nid, tbl_min, tbl_max,
108 tbl_mask, tbl_flags);
110 ASN1err(ASN1_F_DO_TCREATE, ERR_R_MALLOC_FAILURE);
112 sk_CONF_VALUE_pop_free(lst, X509V3_conf_free);