13 #if defined(OSSL_ENGINE_ENABLED)
15 #define WrapEngine(klass, obj, engine) do { \
17 ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
19 (obj) = Data_Wrap_Struct((klass), 0, ENGINE_free, (engine)); \
21 #define GetEngine(obj, engine) do { \
22 Data_Get_Struct((obj), ENGINE, (engine)); \
24 ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
27 #define SafeGetEngine(obj, engine) do { \
28 OSSL_Check_Kind((obj), cEngine); \
29 GetPKCS7((obj), (engine)); \
41 #define OSSL_ENGINE_LOAD_IF_MATCH(x) \
43 if(!strcmp(#x, RSTRING_PTR(name))){\
52 #if !defined(HAVE_ENGINE_LOAD_BUILTIN_ENGINES)
59 ENGINE_load_builtin_engines();
63 #ifndef OPENSSL_NO_STATIC_ENGINE
64 #if HAVE_ENGINE_LOAD_DYNAMIC
65 OSSL_ENGINE_LOAD_IF_MATCH(dynamic);
67 #if HAVE_ENGINE_LOAD_CSWIFT
68 OSSL_ENGINE_LOAD_IF_MATCH(cswift);
70 #if HAVE_ENGINE_LOAD_CHIL
71 OSSL_ENGINE_LOAD_IF_MATCH(chil);
73 #if HAVE_ENGINE_LOAD_ATALLA
74 OSSL_ENGINE_LOAD_IF_MATCH(atalla);
76 #if HAVE_ENGINE_LOAD_NURON
77 OSSL_ENGINE_LOAD_IF_MATCH(nuron);
79 #if HAVE_ENGINE_LOAD_UBSEC
80 OSSL_ENGINE_LOAD_IF_MATCH(ubsec);
82 #if HAVE_ENGINE_LOAD_AEP
83 OSSL_ENGINE_LOAD_IF_MATCH(aep);
85 #if HAVE_ENGINE_LOAD_SUREWARE
86 OSSL_ENGINE_LOAD_IF_MATCH(sureware);
88 #if HAVE_ENGINE_LOAD_4758CCA
89 OSSL_ENGINE_LOAD_IF_MATCH(4758cca);
92 #ifdef HAVE_ENGINE_LOAD_OPENBSD_DEV_CRYPTO
93 OSSL_ENGINE_LOAD_IF_MATCH(openbsd_dev_crypto);
95 OSSL_ENGINE_LOAD_IF_MATCH(openssl);
102 ossl_engine_s_cleanup(
VALUE self)
104 #if defined(HAVE_ENGINE_CLEANUP)
111 ossl_engine_s_engines(
VALUE klass)
117 for(e = ENGINE_get_first(); e; e = ENGINE_get_next(e)){
122 WrapEngine(klass, obj, e);
136 ossl_engine_s_load(1, &
id, klass);
139 WrapEngine(klass, obj, e);
143 ENGINE_ctrl(e, ENGINE_CTRL_SET_PASSWORD_CALLBACK,
151 ossl_engine_s_alloc(
VALUE klass)
156 if (!(e = ENGINE_new())) {
159 WrapEngine(klass, obj, e);
165 ossl_engine_get_id(
VALUE self)
173 ossl_engine_get_name(
VALUE self)
181 ossl_engine_finish(
VALUE self)
186 if(!ENGINE_finish(e))
ossl_raise(eEngineError, NULL);
191 #if defined(HAVE_ENGINE_GET_CIPHER)
193 ossl_engine_get_cipher(
VALUE self,
VALUE name)
196 const EVP_CIPHER *ciph, *tmp;
201 tmp = EVP_get_cipherbyname(s);
202 if(!tmp)
ossl_raise(eEngineError,
"no such cipher `%s'", s);
203 nid = EVP_CIPHER_nid(tmp);
205 ciph = ENGINE_get_cipher(e, nid);
211 #define ossl_engine_get_cipher rb_f_notimplement
214 #if defined(HAVE_ENGINE_GET_DIGEST)
216 ossl_engine_get_digest(
VALUE self,
VALUE name)
219 const EVP_MD *md, *tmp;
224 tmp = EVP_get_digestbyname(s);
225 if(!tmp)
ossl_raise(eEngineError,
"no such digest `%s'", s);
226 nid = EVP_MD_nid(tmp);
228 md = ENGINE_get_digest(e, nid);
234 #define ossl_engine_get_digest rb_f_notimplement
238 ossl_engine_load_privkey(
int argc,
VALUE *argv,
VALUE self)
249 #if OPENSSL_VERSION_NUMBER < 0x00907000L
250 pkey = ENGINE_load_private_key(e, sid, sdata);
252 pkey = ENGINE_load_private_key(e, sid, NULL, sdata);
262 ossl_engine_load_pubkey(
int argc,
VALUE *argv,
VALUE self)
273 #if OPENSSL_VERSION_NUMBER < 0x00907000L
274 pkey = ENGINE_load_public_key(e, sid, sdata);
276 pkey = ENGINE_load_public_key(e, sid, NULL, sdata);
284 ossl_engine_set_default(
VALUE self,
VALUE flag)
290 ENGINE_set_default(e, f);
296 ossl_engine_ctrl_cmd(
int argc,
VALUE *argv,
VALUE self)
314 ossl_engine_cmd_flag_to_name(
int flag)
317 case ENGINE_CMD_FLAG_NUMERIC:
return rb_str_new2(
"NUMERIC");
318 case ENGINE_CMD_FLAG_STRING:
return rb_str_new2(
"STRING");
319 case ENGINE_CMD_FLAG_NO_INPUT:
return rb_str_new2(
"NO_INPUT");
320 case ENGINE_CMD_FLAG_INTERNAL:
return rb_str_new2(
"INTERNAL");
326 ossl_engine_get_cmds(
VALUE self)
329 const ENGINE_CMD_DEFN *defn, *
p;
334 if ((defn = ENGINE_get_cmd_defns(e)) != NULL){
335 for (p = defn; p->cmd_num > 0; p++){
339 rb_ary_push(tmp, ossl_engine_cmd_flag_to_name(p->cmd_flags));
348 ossl_engine_inspect(
VALUE self)
364 #define DefEngineConst(x) rb_define_const(cEngine, #x, INT2NUM(ENGINE_##x))
384 rb_define_method(cEngine,
"load_private_key", ossl_engine_load_privkey, -1);
391 DefEngineConst(METHOD_RSA);
392 DefEngineConst(METHOD_DSA);
393 DefEngineConst(METHOD_DH);
394 DefEngineConst(METHOD_RAND);
395 #ifdef ENGINE_METHOD_BN_MOD_EXP
396 DefEngineConst(METHOD_BN_MOD_EXP);
398 #ifdef ENGINE_METHOD_BN_MOD_EXP_CRT
399 DefEngineConst(METHOD_BN_MOD_EXP_CRT);
401 #ifdef ENGINE_METHOD_CIPHERS
402 DefEngineConst(METHOD_CIPHERS);
404 #ifdef ENGINE_METHOD_DIGESTS
405 DefEngineConst(METHOD_DIGESTS);
407 DefEngineConst(METHOD_ALL);
408 DefEngineConst(METHOD_NONE);