diff options
Diffstat (limited to 'src/lib/libcrypto/engine/eng_cnf.c')
| -rw-r--r-- | src/lib/libcrypto/engine/eng_cnf.c | 158 |
1 files changed, 76 insertions, 82 deletions
diff --git a/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c index afb704e93b..c0c6b3fdc4 100644 --- a/src/lib/libcrypto/engine/eng_cnf.c +++ b/src/lib/libcrypto/engine/eng_cnf.c | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | * are met: | 10 | * are met: |
| 11 | * | 11 | * |
| 12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * | 14 | * |
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer in | 16 | * notice, this list of conditions and the following disclaimer in |
| @@ -63,34 +63,37 @@ | |||
| 63 | 63 | ||
| 64 | /* ENGINE config module */ | 64 | /* ENGINE config module */ |
| 65 | 65 | ||
| 66 | static char *skip_dot(char *name) | 66 | static char * |
| 67 | { | 67 | skip_dot(char *name) |
| 68 | { | ||
| 68 | char *p; | 69 | char *p; |
| 70 | |||
| 69 | p = strchr(name, '.'); | 71 | p = strchr(name, '.'); |
| 70 | if (p) | 72 | if (p) |
| 71 | return p + 1; | 73 | return p + 1; |
| 72 | return name; | 74 | return name; |
| 73 | } | 75 | } |
| 74 | 76 | ||
| 75 | static STACK_OF(ENGINE) *initialized_engines = NULL; | 77 | static STACK_OF(ENGINE) *initialized_engines = NULL; |
| 76 | 78 | ||
| 77 | static int int_engine_init(ENGINE *e) | 79 | static int |
| 78 | { | 80 | int_engine_init(ENGINE *e) |
| 81 | { | ||
| 79 | if (!ENGINE_init(e)) | 82 | if (!ENGINE_init(e)) |
| 80 | return 0; | 83 | return 0; |
| 81 | if (!initialized_engines) | 84 | if (!initialized_engines) |
| 82 | initialized_engines = sk_ENGINE_new_null(); | 85 | initialized_engines = sk_ENGINE_new_null(); |
| 83 | if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e)) | 86 | if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e)) { |
| 84 | { | ||
| 85 | ENGINE_finish(e); | 87 | ENGINE_finish(e); |
| 86 | return 0; | 88 | return 0; |
| 87 | } | ||
| 88 | return 1; | ||
| 89 | } | 89 | } |
| 90 | 90 | return 1; | |
| 91 | } | ||
| 91 | 92 | ||
| 92 | static int int_engine_configure(char *name, char *value, const CONF *cnf) | 93 | |
| 93 | { | 94 | static int |
| 95 | int_engine_configure(char *name, char *value, const CONF *cnf) | ||
| 96 | { | ||
| 94 | int i; | 97 | int i; |
| 95 | int ret = 0; | 98 | int ret = 0; |
| 96 | long do_init = -1; | 99 | long do_init = -1; |
| @@ -107,19 +110,19 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf) | |||
| 107 | /* Value is a section containing ENGINE commands */ | 110 | /* Value is a section containing ENGINE commands */ |
| 108 | ecmds = NCONF_get_section(cnf, value); | 111 | ecmds = NCONF_get_section(cnf, value); |
| 109 | 112 | ||
| 110 | if (!ecmds) | 113 | if (!ecmds) { |
| 111 | { | 114 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, |
| 112 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_SECTION_ERROR); | 115 | ENGINE_R_ENGINE_SECTION_ERROR); |
| 113 | return 0; | 116 | return 0; |
| 114 | } | 117 | } |
| 115 | 118 | ||
| 116 | for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++) | 119 | for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++) { |
| 117 | { | ||
| 118 | ecmd = sk_CONF_VALUE_value(ecmds, i); | 120 | ecmd = sk_CONF_VALUE_value(ecmds, i); |
| 119 | ctrlname = skip_dot(ecmd->name); | 121 | ctrlname = skip_dot(ecmd->name); |
| 120 | ctrlvalue = ecmd->value; | 122 | ctrlvalue = ecmd->value; |
| 121 | #ifdef ENGINE_CONF_DEBUG | 123 | #ifdef ENGINE_CONF_DEBUG |
| 122 | fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", ctrlname, ctrlvalue); | 124 | fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", |
| 125 | ctrlname, ctrlvalue); | ||
| 123 | #endif | 126 | #endif |
| 124 | 127 | ||
| 125 | /* First handle some special pseudo ctrls */ | 128 | /* First handle some special pseudo ctrls */ |
| @@ -130,8 +133,7 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf) | |||
| 130 | else if (!strcmp(ctrlname, "soft_load")) | 133 | else if (!strcmp(ctrlname, "soft_load")) |
| 131 | soft = 1; | 134 | soft = 1; |
| 132 | /* Load a dynamic ENGINE */ | 135 | /* Load a dynamic ENGINE */ |
| 133 | else if (!strcmp(ctrlname, "dynamic_path")) | 136 | else if (!strcmp(ctrlname, "dynamic_path")) { |
| 134 | { | ||
| 135 | e = ENGINE_by_id("dynamic"); | 137 | e = ENGINE_by_id("dynamic"); |
| 136 | if (!e) | 138 | if (!e) |
| 137 | goto err; | 139 | goto err; |
| @@ -141,119 +143,111 @@ static int int_engine_configure(char *name, char *value, const CONF *cnf) | |||
| 141 | goto err; | 143 | goto err; |
| 142 | if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) | 144 | if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) |
| 143 | goto err; | 145 | goto err; |
| 144 | } | 146 | } |
| 145 | /* ... add other pseudos here ... */ | 147 | /* ... add other pseudos here ... */ |
| 146 | else | 148 | else { |
| 147 | { | ||
| 148 | /* At this point we need an ENGINE structural reference | 149 | /* At this point we need an ENGINE structural reference |
| 149 | * if we don't already have one. | 150 | * if we don't already have one. |
| 150 | */ | 151 | */ |
| 151 | if (!e) | 152 | if (!e) { |
| 152 | { | ||
| 153 | e = ENGINE_by_id(name); | 153 | e = ENGINE_by_id(name); |
| 154 | if (!e && soft) | 154 | if (!e && soft) { |
| 155 | { | ||
| 156 | ERR_clear_error(); | 155 | ERR_clear_error(); |
| 157 | return 1; | 156 | return 1; |
| 158 | } | 157 | } |
| 159 | if (!e) | 158 | if (!e) |
| 160 | goto err; | 159 | goto err; |
| 161 | } | 160 | } |
| 162 | /* Allow "EMPTY" to mean no value: this allows a valid | 161 | /* Allow "EMPTY" to mean no value: this allows a valid |
| 163 | * "value" to be passed to ctrls of type NO_INPUT | 162 | * "value" to be passed to ctrls of type NO_INPUT |
| 164 | */ | 163 | */ |
| 165 | if (!strcmp(ctrlvalue, "EMPTY")) | 164 | if (!strcmp(ctrlvalue, "EMPTY")) |
| 166 | ctrlvalue = NULL; | 165 | ctrlvalue = NULL; |
| 167 | if (!strcmp(ctrlname, "init")) | 166 | if (!strcmp(ctrlname, "init")) { |
| 168 | { | 167 | if (!NCONF_get_number_e(cnf, value, "init", |
| 169 | if (!NCONF_get_number_e(cnf, value, "init", &do_init)) | 168 | &do_init)) |
| 170 | goto err; | 169 | goto err; |
| 171 | if (do_init == 1) | 170 | if (do_init == 1) { |
| 172 | { | ||
| 173 | if (!int_engine_init(e)) | 171 | if (!int_engine_init(e)) |
| 174 | goto err; | 172 | goto err; |
| 175 | } | 173 | } else if (do_init != 0) { |
| 176 | else if (do_init != 0) | 174 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, |
| 177 | { | 175 | ENGINE_R_INVALID_INIT_VALUE); |
| 178 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_INVALID_INIT_VALUE); | ||
| 179 | goto err; | 176 | goto err; |
| 180 | } | ||
| 181 | } | 177 | } |
| 182 | else if (!strcmp(ctrlname, "default_algorithms")) | 178 | } |
| 183 | { | 179 | else if (!strcmp(ctrlname, "default_algorithms")) { |
| 184 | if (!ENGINE_set_default_string(e, ctrlvalue)) | 180 | if (!ENGINE_set_default_string(e, ctrlvalue)) |
| 185 | goto err; | 181 | goto err; |
| 186 | } | 182 | } else if (!ENGINE_ctrl_cmd_string(e, |
| 187 | else if (!ENGINE_ctrl_cmd_string(e, | 183 | ctrlname, ctrlvalue, 0)) |
| 188 | ctrlname, ctrlvalue, 0)) | ||
| 189 | goto err; | 184 | goto err; |
| 190 | } | ||
| 191 | |||
| 192 | |||
| 193 | |||
| 194 | } | 185 | } |
| 195 | if (e && (do_init == -1) && !int_engine_init(e)) | 186 | } |
| 196 | { | 187 | if (e && (do_init == -1) && !int_engine_init(e)) { |
| 197 | ecmd = NULL; | 188 | ecmd = NULL; |
| 198 | goto err; | 189 | goto err; |
| 199 | } | 190 | } |
| 200 | ret = 1; | 191 | ret = 1; |
| 201 | err: | 192 | |
| 202 | if (ret != 1) | 193 | err: |
| 203 | { | 194 | if (ret != 1) { |
| 204 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_CONFIGURATION_ERROR); | 195 | ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, |
| 196 | ENGINE_R_ENGINE_CONFIGURATION_ERROR); | ||
| 205 | if (ecmd) | 197 | if (ecmd) |
| 206 | ERR_asprintf_error_data | 198 | ERR_asprintf_error_data |
| 207 | ("section=%s, name=%s, value=%s", | 199 | ("section=%s, name=%s, value=%s", |
| 208 | ecmd->section, ecmd->name, ecmd->value); | 200 | ecmd->section, ecmd->name, ecmd->value); |
| 209 | } | 201 | } |
| 210 | if (e) | 202 | if (e) |
| 211 | ENGINE_free(e); | 203 | ENGINE_free(e); |
| 212 | return ret; | 204 | return ret; |
| 213 | } | 205 | } |
| 214 | 206 | ||
| 215 | 207 | ||
| 216 | static int int_engine_module_init(CONF_IMODULE *md, const CONF *cnf) | 208 | static int |
| 217 | { | 209 | int_engine_module_init(CONF_IMODULE *md, const CONF *cnf) |
| 210 | { | ||
| 218 | STACK_OF(CONF_VALUE) *elist; | 211 | STACK_OF(CONF_VALUE) *elist; |
| 219 | CONF_VALUE *cval; | 212 | CONF_VALUE *cval; |
| 220 | int i; | 213 | int i; |
| 214 | |||
| 221 | #ifdef ENGINE_CONF_DEBUG | 215 | #ifdef ENGINE_CONF_DEBUG |
| 222 | fprintf(stderr, "Called engine module: name %s, value %s\n", | 216 | fprintf(stderr, "Called engine module: name %s, value %s\n", |
| 223 | CONF_imodule_get_name(md), CONF_imodule_get_value(md)); | 217 | CONF_imodule_get_name(md), CONF_imodule_get_value(md)); |
| 224 | #endif | 218 | #endif |
| 225 | /* Value is a section containing ENGINEs to configure */ | 219 | /* Value is a section containing ENGINEs to configure */ |
| 226 | elist = NCONF_get_section(cnf, CONF_imodule_get_value(md)); | 220 | elist = NCONF_get_section(cnf, CONF_imodule_get_value(md)); |
| 227 | 221 | ||
| 228 | if (!elist) | 222 | if (!elist) { |
| 229 | { | 223 | ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, |
| 230 | ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR); | 224 | ENGINE_R_ENGINES_SECTION_ERROR); |
| 231 | return 0; | 225 | return 0; |
| 232 | } | 226 | } |
| 233 | 227 | ||
| 234 | for (i = 0; i < sk_CONF_VALUE_num(elist); i++) | 228 | for (i = 0; i < sk_CONF_VALUE_num(elist); i++) { |
| 235 | { | ||
| 236 | cval = sk_CONF_VALUE_value(elist, i); | 229 | cval = sk_CONF_VALUE_value(elist, i); |
| 237 | if (!int_engine_configure(cval->name, cval->value, cnf)) | 230 | if (!int_engine_configure(cval->name, cval->value, cnf)) |
| 238 | return 0; | 231 | return 0; |
| 239 | } | 232 | } |
| 240 | 233 | ||
| 241 | return 1; | 234 | return 1; |
| 242 | } | 235 | } |
| 243 | 236 | ||
| 244 | static void int_engine_module_finish(CONF_IMODULE *md) | 237 | static void |
| 245 | { | 238 | int_engine_module_finish(CONF_IMODULE *md) |
| 239 | { | ||
| 246 | ENGINE *e; | 240 | ENGINE *e; |
| 241 | |||
| 247 | while ((e = sk_ENGINE_pop(initialized_engines))) | 242 | while ((e = sk_ENGINE_pop(initialized_engines))) |
| 248 | ENGINE_finish(e); | 243 | ENGINE_finish(e); |
| 249 | sk_ENGINE_free(initialized_engines); | 244 | sk_ENGINE_free(initialized_engines); |
| 250 | initialized_engines = NULL; | 245 | initialized_engines = NULL; |
| 251 | } | 246 | } |
| 252 | 247 | ||
| 253 | 248 | void | |
| 254 | void ENGINE_add_conf_module(void) | 249 | ENGINE_add_conf_module(void) |
| 255 | { | 250 | { |
| 256 | CONF_module_add("engines", | 251 | CONF_module_add("engines", int_engine_module_init, |
| 257 | int_engine_module_init, | 252 | int_engine_module_finish); |
| 258 | int_engine_module_finish); | 253 | } |
| 259 | } | ||
