]>
Commit | Line | Data |
---|---|---|
0f113f3e | 1 | /* |
454afd98 | 2 | * Copyright 2012-2020 The OpenSSL Project Authors. All Rights Reserved. |
918e613a | 3 | * |
365a2d99 | 4 | * Licensed under the Apache License 2.0 (the "License"). You may not use |
2039c421 RS |
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 | |
918e613a DSH |
8 | */ |
9 | ||
10 | #include <stdio.h> | |
918e613a | 11 | #include <openssl/crypto.h> |
b39fc560 | 12 | #include "internal/cryptlib.h" |
918e613a DSH |
13 | #include <openssl/conf.h> |
14 | #include <openssl/x509v3.h> | |
15 | ||
0d4fb843 | 16 | /* Multi string module: add table entries from a given section */ |
918e613a | 17 | |
fa3a8442 | 18 | static int do_tcreate(const char *value, const char *name); |
918e613a DSH |
19 | |
20 | static int stbl_module_init(CONF_IMODULE *md, const CONF *cnf) | |
0f113f3e MC |
21 | { |
22 | int i; | |
23 | const char *stbl_section; | |
24 | STACK_OF(CONF_VALUE) *sktmp; | |
25 | CONF_VALUE *mval; | |
75ebbd9a | 26 | |
0f113f3e | 27 | stbl_section = CONF_imodule_get_value(md); |
75ebbd9a | 28 | if ((sktmp = NCONF_get_section(cnf, stbl_section)) == NULL) { |
0f113f3e MC |
29 | ASN1err(ASN1_F_STBL_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); |
30 | return 0; | |
31 | } | |
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 | ASN1err(ASN1_F_STBL_MODULE_INIT, ASN1_R_INVALID_VALUE); | |
36 | return 0; | |
37 | } | |
38 | } | |
39 | return 1; | |
40 | } | |
918e613a DSH |
41 | |
42 | static void stbl_module_finish(CONF_IMODULE *md) | |
0f113f3e MC |
43 | { |
44 | ASN1_STRING_TABLE_cleanup(); | |
45 | } | |
918e613a DSH |
46 | |
47 | void ASN1_add_stable_module(void) | |
0f113f3e MC |
48 | { |
49 | CONF_module_add("stbl_section", stbl_module_init, stbl_module_finish); | |
50 | } | |
918e613a | 51 | |
0f113f3e MC |
52 | /* |
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". | |
918e613a DSH |
55 | */ |
56 | ||
fa3a8442 | 57 | static int do_tcreate(const char *value, const char *name) |
0f113f3e MC |
58 | { |
59 | char *eptr; | |
60 | int nid, i, rv = 0; | |
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); | |
66 | if (nid == NID_undef) | |
67 | nid = OBJ_ln2nid(name); | |
68 | if (nid == NID_undef) | |
69 | goto err; | |
70 | lst = X509V3_parse_list(value); | |
71 | if (!lst) | |
72 | goto err; | |
73 | for (i = 0; i < sk_CONF_VALUE_num(lst); i++) { | |
74 | cnf = sk_CONF_VALUE_value(lst, i); | |
86885c28 | 75 | if (strcmp(cnf->name, "min") == 0) { |
0f113f3e MC |
76 | tbl_min = strtoul(cnf->value, &eptr, 0); |
77 | if (*eptr) | |
78 | goto err; | |
86885c28 | 79 | } else if (strcmp(cnf->name, "max") == 0) { |
0f113f3e MC |
80 | tbl_max = strtoul(cnf->value, &eptr, 0); |
81 | if (*eptr) | |
82 | goto err; | |
86885c28 | 83 | } else if (strcmp(cnf->name, "mask") == 0) { |
0f113f3e MC |
84 | if (!ASN1_str2mask(cnf->value, &tbl_mask) || !tbl_mask) |
85 | goto err; | |
86885c28 RS |
86 | } else if (strcmp(cnf->name, "flags") == 0) { |
87 | if (strcmp(cnf->value, "nomask") == 0) | |
0f113f3e | 88 | tbl_flags = STABLE_NO_MASK; |
86885c28 | 89 | else if (strcmp(cnf->value, "none") == 0) |
0f113f3e MC |
90 | tbl_flags = STABLE_FLAGS_CLEAR; |
91 | else | |
92 | goto err; | |
93 | } else | |
94 | goto err; | |
95 | } | |
96 | rv = 1; | |
97 | err: | |
98 | if (rv == 0) { | |
99 | ASN1err(ASN1_F_DO_TCREATE, ASN1_R_INVALID_STRING_TABLE_VALUE); | |
100 | if (cnf) | |
101 | ERR_add_error_data(4, "field=", cnf->name, | |
102 | ", value=", cnf->value); | |
103 | else | |
104 | ERR_add_error_data(4, "name=", name, ", value=", value); | |
105 | } else { | |
106 | rv = ASN1_STRING_TABLE_add(nid, tbl_min, tbl_max, | |
107 | tbl_mask, tbl_flags); | |
108 | if (!rv) | |
109 | ASN1err(ASN1_F_DO_TCREATE, ERR_R_MALLOC_FAILURE); | |
110 | } | |
efa7dd64 | 111 | sk_CONF_VALUE_pop_free(lst, X509V3_conf_free); |
0f113f3e MC |
112 | return rv; |
113 | } |