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)
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);
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);
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);
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)
357 #define DefEngineConst(x) rb_define_const(cEngine, #x, INT2NUM(ENGINE_##x))
384 DefEngineConst(METHOD_RSA);
385 DefEngineConst(METHOD_DSA);
386 DefEngineConst(METHOD_DH);
387 DefEngineConst(METHOD_RAND);
388 #ifdef ENGINE_METHOD_BN_MOD_EXP
389 DefEngineConst(METHOD_BN_MOD_EXP);
391 #ifdef ENGINE_METHOD_BN_MOD_EXP_CRT
392 DefEngineConst(METHOD_BN_MOD_EXP_CRT);
394 #ifdef ENGINE_METHOD_CIPHERS
395 DefEngineConst(METHOD_CIPHERS);
397 #ifdef ENGINE_METHOD_DIGESTS
398 DefEngineConst(METHOD_DIGESTS);
400 DefEngineConst(METHOD_ALL);
401 DefEngineConst(METHOD_NONE);
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
VALUE rb_ary_push(VALUE ary, VALUE item)
#define RSTRING_PTR(string)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
VALUE ossl_pkey_new(EVP_PKEY *pkey)
void rb_undef_method(VALUE klass, const char *name)
VALUE ossl_cipher_new(const EVP_CIPHER *cipher)
#define OSSL_PKEY_SET_PRIVATE(obj)
int rb_block_given_p(void)
RUBY_EXTERN VALUE rb_cObject
VALUE ossl_digest_new(const EVP_MD *md)
VALUE rb_sprintf(const char *format,...)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
#define RB_OBJ_CLASSNAME(obj)
void ossl_raise(VALUE exc, const char *fmt,...)
#define StringValuePtr(v)
int ossl_pem_passwd_cb(char *buf, int max_len, int flag, void *pwd)
void rb_warning(const char *fmt,...)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_new2(const char *)