1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/libcrypto/src/crypto/engine/eng_cnf.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,254 @@
1.4 +/* eng_cnf.c */
1.5 +/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
1.6 + * project 2001.
1.7 + */
1.8 +/* ====================================================================
1.9 + * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
1.10 + *
1.11 + * Redistribution and use in source and binary forms, with or without
1.12 + * modification, are permitted provided that the following conditions
1.13 + * are met:
1.14 + *
1.15 + * 1. Redistributions of source code must retain the above copyright
1.16 + * notice, this list of conditions and the following disclaimer.
1.17 + *
1.18 + * 2. Redistributions in binary form must reproduce the above copyright
1.19 + * notice, this list of conditions and the following disclaimer in
1.20 + * the documentation and/or other materials provided with the
1.21 + * distribution.
1.22 + *
1.23 + * 3. All advertising materials mentioning features or use of this
1.24 + * software must display the following acknowledgment:
1.25 + * "This product includes software developed by the OpenSSL Project
1.26 + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
1.27 + *
1.28 + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
1.29 + * endorse or promote products derived from this software without
1.30 + * prior written permission. For written permission, please contact
1.31 + * licensing@OpenSSL.org.
1.32 + *
1.33 + * 5. Products derived from this software may not be called "OpenSSL"
1.34 + * nor may "OpenSSL" appear in their names without prior written
1.35 + * permission of the OpenSSL Project.
1.36 + *
1.37 + * 6. Redistributions of any form whatsoever must retain the following
1.38 + * acknowledgment:
1.39 + * "This product includes software developed by the OpenSSL Project
1.40 + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
1.41 + *
1.42 + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
1.43 + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.44 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1.45 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
1.46 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1.47 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1.48 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1.49 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.50 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1.51 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1.52 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
1.53 + * OF THE POSSIBILITY OF SUCH DAMAGE.
1.54 + * ====================================================================
1.55 + *
1.56 + * This product includes cryptographic software written by Eric Young
1.57 + * (eay@cryptsoft.com). This product includes software written by Tim
1.58 + * Hudson (tjh@cryptsoft.com).
1.59 + *
1.60 + */
1.61 + /*
1.62 + © Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
1.63 + */
1.64 +
1.65 +
1.66 +
1.67 +#include "eng_int.h"
1.68 +#include <openssl/conf.h>
1.69 +#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
1.70 +#include "libcrypto_wsd_macros.h"
1.71 +#include "libcrypto_wsd.h"
1.72 +#endif
1.73 +
1.74 +
1.75 +/* #define ENGINE_CONF_DEBUG */
1.76 +
1.77 +/* ENGINE config module */
1.78 +
1.79 +static char *skip_dot(char *name)
1.80 + {
1.81 + char *p;
1.82 + p = strchr(name, '.');
1.83 + if (p)
1.84 + return p + 1;
1.85 + return name;
1.86 + }
1.87 +
1.88 +#ifndef EMULATOR
1.89 +static STACK_OF(ENGINE) *initialized_engines = NULL;
1.90 +#else
1.91 +GET_STATIC_VAR_FROM_TLS(initialized_engines,eng_cnf,STACK_OF(ENGINE) *)
1.92 +#define initialized_engines (*GET_WSD_VAR_NAME(initialized_engines,eng_cnf, s)())
1.93 +#endif
1.94 +
1.95 +static int int_engine_init(ENGINE *e)
1.96 + {
1.97 + if (!ENGINE_init(e))
1.98 + return 0;
1.99 + if (!initialized_engines)
1.100 + initialized_engines = sk_ENGINE_new_null();
1.101 + if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e))
1.102 + {
1.103 + ENGINE_finish(e);
1.104 + return 0;
1.105 + }
1.106 + return 1;
1.107 + }
1.108 +
1.109 +
1.110 +static int int_engine_configure(char *name, char *value, const CONF *cnf)
1.111 + {
1.112 + int i;
1.113 + int ret = 0;
1.114 + long do_init = -1;
1.115 + STACK_OF(CONF_VALUE) *ecmds;
1.116 + CONF_VALUE *ecmd;
1.117 + char *ctrlname, *ctrlvalue;
1.118 + ENGINE *e = NULL;
1.119 + name = skip_dot(name);
1.120 +#ifdef ENGINE_CONF_DEBUG
1.121 + fprintf(stderr, "Configuring engine %s\n", name);
1.122 +#endif
1.123 + /* Value is a section containing ENGINE commands */
1.124 + ecmds = NCONF_get_section(cnf, value);
1.125 +
1.126 + if (!ecmds)
1.127 + {
1.128 + ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_ENGINE_SECTION_ERROR);
1.129 + return 0;
1.130 + }
1.131 +
1.132 + for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++)
1.133 + {
1.134 + ecmd = sk_CONF_VALUE_value(ecmds, i);
1.135 + ctrlname = skip_dot(ecmd->name);
1.136 + ctrlvalue = ecmd->value;
1.137 +#ifdef ENGINE_CONF_DEBUG
1.138 + fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", ctrlname, ctrlvalue);
1.139 +#endif
1.140 +
1.141 + /* First handle some special pseudo ctrls */
1.142 +
1.143 + /* Override engine name to use */
1.144 + if (!strcmp(ctrlname, "engine_id"))
1.145 + name = ctrlvalue;
1.146 + /* Load a dynamic ENGINE */
1.147 + else if (!strcmp(ctrlname, "dynamic_path"))
1.148 + {
1.149 + e = ENGINE_by_id("dynamic");
1.150 + if (!e)
1.151 + goto err;
1.152 + if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", ctrlvalue, 0))
1.153 + goto err;
1.154 + if (!ENGINE_ctrl_cmd_string(e, "LIST_ADD", "2", 0))
1.155 + goto err;
1.156 + if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))
1.157 + goto err;
1.158 + }
1.159 + /* ... add other pseudos here ... */
1.160 + else
1.161 + {
1.162 + /* At this point we need an ENGINE structural reference
1.163 + * if we don't already have one.
1.164 + */
1.165 + if (!e)
1.166 + {
1.167 + e = ENGINE_by_id(name);
1.168 + if (!e)
1.169 + return 0;
1.170 + }
1.171 + /* Allow "EMPTY" to mean no value: this allows a valid
1.172 + * "value" to be passed to ctrls of type NO_INPUT
1.173 + */
1.174 + if (!strcmp(ctrlvalue, "EMPTY"))
1.175 + ctrlvalue = NULL;
1.176 + if (!strcmp(ctrlname, "init"))
1.177 + {
1.178 + if (!NCONF_get_number_e(cnf, value, "init", &do_init))
1.179 + goto err;
1.180 + if (do_init == 1)
1.181 + {
1.182 + if (!int_engine_init(e))
1.183 + goto err;
1.184 + }
1.185 + else if (do_init != 0)
1.186 + {
1.187 + ENGINEerr(ENGINE_F_INT_ENGINE_CONFIGURE, ENGINE_R_INVALID_INIT_VALUE);
1.188 + goto err;
1.189 + }
1.190 + }
1.191 + else if (!strcmp(ctrlname, "default_algorithms"))
1.192 + {
1.193 + if (!ENGINE_set_default_string(e, ctrlvalue))
1.194 + goto err;
1.195 + }
1.196 + else if (!ENGINE_ctrl_cmd_string(e,
1.197 + ctrlname, ctrlvalue, 0))
1.198 + return 0;
1.199 + }
1.200 +
1.201 +
1.202 +
1.203 + }
1.204 + if (e && (do_init == -1) && !int_engine_init(e))
1.205 + goto err;
1.206 + ret = 1;
1.207 + err:
1.208 + if (e)
1.209 + ENGINE_free(e);
1.210 + return ret;
1.211 + }
1.212 +
1.213 +
1.214 +static int int_engine_module_init(CONF_IMODULE *md, const CONF *cnf)
1.215 + {
1.216 + STACK_OF(CONF_VALUE) *elist;
1.217 + CONF_VALUE *cval;
1.218 + int i;
1.219 +#ifdef ENGINE_CONF_DEBUG
1.220 + fprintf(stderr, "Called engine module: name %s, value %s\n",
1.221 + CONF_imodule_get_name(md), CONF_imodule_get_value(md));
1.222 +#endif
1.223 + /* Value is a section containing ENGINEs to configure */
1.224 + elist = NCONF_get_section(cnf, CONF_imodule_get_value(md));
1.225 +
1.226 + if (!elist)
1.227 + {
1.228 + ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR);
1.229 + return 0;
1.230 + }
1.231 +
1.232 + for (i = 0; i < sk_CONF_VALUE_num(elist); i++)
1.233 + {
1.234 + cval = sk_CONF_VALUE_value(elist, i);
1.235 + if (!int_engine_configure(cval->name, cval->value, cnf))
1.236 + return 0;
1.237 + }
1.238 +
1.239 + return 1;
1.240 + }
1.241 +
1.242 +static void int_engine_module_finish(CONF_IMODULE *md)
1.243 + {
1.244 + ENGINE *e;
1.245 + while ((e = sk_ENGINE_pop(initialized_engines)))
1.246 + ENGINE_finish(e);
1.247 + sk_ENGINE_free(initialized_engines);
1.248 + initialized_engines = NULL;
1.249 + }
1.250 +
1.251 +
1.252 +EXPORT_C void ENGINE_add_conf_module(void)
1.253 + {
1.254 + CONF_module_add("engines",
1.255 + int_engine_module_init,
1.256 + int_engine_module_finish);
1.257 + }